1/*******************************************************************
2* statuswidget.cpp
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#include "statuswidget.h"
20
21#include <QApplication>
22#include <QSizePolicy>
23#include <QHBoxLayout>
24
25#include <KPixmapSequenceWidget>
26#include <KPixmapSequence>
27
28StatusWidget::StatusWidget(QWidget * parent) :
29 QStackedWidget(parent),
30 m_cursorStackCount(0),
31 m_busy(false)
32{
33 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
34
35 //Main layout
36 m_statusPage = new QWidget(this);
37 m_busyPage = new QWidget(this);
38
39 addWidget(m_statusPage);
40 addWidget(m_busyPage);
41
42 //Status widget
43 m_statusLabel = new WrapLabel();
44 m_statusLabel->setOpenExternalLinks(true);
45 m_statusLabel->setTextFormat(Qt::RichText);
46 //m_statusLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum));
47
48 QHBoxLayout * statusLayout = new QHBoxLayout();
49 statusLayout->setContentsMargins(0,0,0,0);
50 m_statusPage->setLayout(statusLayout);
51
52 statusLayout->addWidget(m_statusLabel);
53
54 //Busy widget
55 m_throbberWidget = new KPixmapSequenceWidget();
56 m_throbberWidget->setSequence(KPixmapSequence("process-working", 22));
57 m_throbberWidget->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
58
59 m_busyLabel = new WrapLabel();
60 //m_busyLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum));
61
62 QHBoxLayout * busyLayout = new QHBoxLayout();
63 busyLayout->setContentsMargins(0,0,0,0);
64 m_busyPage->setLayout(busyLayout);
65
66 busyLayout->addWidget(m_busyLabel);
67 busyLayout->addWidget(m_throbberWidget);
68 busyLayout->setAlignment(m_throbberWidget,Qt::AlignVCenter);
69}
70
71void StatusWidget::setBusy(const QString& busyMessage)
72{
73 m_statusLabel->clear();
74 m_busyLabel->setText(busyMessage);
75 setCurrentWidget(m_busyPage);
76 setBusyCursor();
77 m_busy = true;
78}
79
80void StatusWidget::setIdle(const QString& idleMessage)
81{
82 m_busyLabel->clear();
83 m_statusLabel->setText(idleMessage);
84 setCurrentWidget(m_statusPage);
85 setIdleCursor();
86 m_busy = false;
87}
88
89void StatusWidget::addCustomStatusWidget(QWidget * widget)
90{
91 QHBoxLayout * statusLayout = static_cast<QHBoxLayout*>(m_statusPage->layout());
92
93 statusLayout->addWidget(widget);
94 statusLayout->setAlignment(widget,Qt::AlignVCenter);
95 widget->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed));
96}
97
98void StatusWidget::setBusyCursor()
99{
100 QApplication::setOverrideCursor(Qt::WaitCursor);
101 m_cursorStackCount++;
102}
103
104void StatusWidget::setIdleCursor()
105{
106 while (m_cursorStackCount!=0) {
107 QApplication::restoreOverrideCursor();
108 m_cursorStackCount--;
109 }
110}
111
112void StatusWidget::hideEvent(QHideEvent *)
113{
114 if (m_busy) {
115 setIdleCursor();
116 }
117}
118
119void StatusWidget::showEvent(QShowEvent *)
120{
121 if (m_busy) {
122 setBusyCursor();
123 }
124}
125