1/*******************************************************************
2* statuswidget.h
3* Copyright 2009,2010 Dario Andres Rodriguez <andresbajotierra@gmail.com>
4*
5* This program is free software; you can redistribute it and/or
6* modify it under the terms of the GNU General Public License as
7* published by the Free Software Foundation; either version 2 of
8* the License, or (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18******************************************************************/
19#ifndef STATUSWIDGET__H
20#define STATUSWIDGET__H
21
22#include <QtCore/QEvent>
23#include <QStackedWidget>
24#include <QLabel>
25#include <QTextDocument>
26
27class WrapLabel;
28class KPixmapSequenceWidget;
29class QHideEvent;
30
31class StatusWidget: public QStackedWidget
32{
33 Q_OBJECT
34public:
35 explicit StatusWidget(QWidget * parent = 0);
36
37 void setBusy(const QString&);
38 void setIdle(const QString&);
39
40 void addCustomStatusWidget(QWidget *);
41
42private:
43 void showEvent(QShowEvent *);
44 void hideEvent(QHideEvent *);
45
46 void setBusyCursor();
47 void setIdleCursor();
48
49 WrapLabel * m_statusLabel;
50
51 KPixmapSequenceWidget * m_throbberWidget;
52 WrapLabel * m_busyLabel;
53
54 QWidget * m_statusPage;
55 QWidget * m_busyPage;
56
57 int m_cursorStackCount;
58 bool m_busy;
59};
60
61//Dummy class to avoid a QLabel+wordWrap height bug
62class WrapLabel: public QLabel
63{
64 Q_OBJECT
65public:
66 explicit WrapLabel(QWidget * parent = 0) : QLabel(parent){
67 setWordWrap(true);
68 }
69
70 void setText(const QString & text) {
71 QLabel::setText(text);
72 adjustHeight();
73 }
74
75 bool event(QEvent * e) {
76 if (e->type() == QEvent::ApplicationFontChange || e->type() == QEvent::Resize) {
77 adjustHeight();
78 }
79 return QLabel::event(e);
80 }
81
82private:
83 void adjustHeight() {
84 QTextDocument document(text());
85 document.setTextWidth(width());
86 setMaximumHeight(document.size().height());
87 }
88
89};
90
91#endif
92