]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
f908a24cd733136d93f915651365a1fc8a140ac1
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinstatusbar.h"
22 #include "dolphinview.h"
23 #include "statusbarmessagelabel.h"
24 #include "statusbarspaceinfo.h"
27 #include <QProgressBar>
30 #include <kiconloader.h>
33 DolphinStatusBar::DolphinStatusBar(DolphinView
* parent
) :
42 m_messageLabel
= new StatusBarMessageLabel(this);
43 m_messageLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
45 m_spaceInfo
= new StatusBarSpaceInfo(this);
46 m_spaceInfo
->setUrl(parent
->url());
48 m_progressText
= new QLabel(this);
49 m_progressText
->hide();
51 m_progressBar
= new QProgressBar(this);
52 m_progressBar
->hide();
54 const QSize
size(m_progressBar
->sizeHint());
55 const int barHeight
= size
.height();
57 m_progressBar
->setMaximumWidth(200);
58 setMinimumHeight(barHeight
);
59 m_messageLabel
->setMinimumTextHeight(barHeight
);
60 m_spaceInfo
->setFixedHeight(barHeight
);
62 connect(parent
, SIGNAL(urlChanged(const KUrl
&)),
63 this, SLOT(updateSpaceInfoContent(const KUrl
&)));
67 DolphinStatusBar::~DolphinStatusBar()
71 void DolphinStatusBar::setMessage(const QString
& msg
,
74 m_messageLabel
->setMessage(msg
, type
);
76 const int widthGap
= m_messageLabel
->widthGap();
78 m_progressBar
->hide();
79 m_progressText
->hide();
84 DolphinStatusBar::Type
DolphinStatusBar::type() const
86 return m_messageLabel
->type();
89 QString
DolphinStatusBar::message() const
91 return m_messageLabel
->text();
94 void DolphinStatusBar::setProgressText(const QString
& text
)
96 m_progressText
->setText(text
);
99 QString
DolphinStatusBar::progressText() const
101 return m_progressText
->text();
104 void DolphinStatusBar::setProgress(int percent
)
109 else if (percent
> 100) {
113 m_progress
= percent
;
114 if (m_messageLabel
->type() == Error
) {
115 // don't update any widget or status bar text if an
116 // error message is shown
120 m_progressBar
->setValue(m_progress
);
121 if (!m_progressBar
->isVisible() || (percent
== 100)) {
122 QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
125 const QString
& defaultText
= m_messageLabel
->defaultText();
126 const QString
msg(m_messageLabel
->text());
127 if ((percent
== 0) && !msg
.isEmpty()) {
128 setMessage(QString(), Default
);
130 else if ((percent
== 100) && (msg
!= defaultText
)) {
131 setMessage(defaultText
, Default
);
135 void DolphinStatusBar::clear()
137 setMessage(m_messageLabel
->defaultText(), Default
);
140 void DolphinStatusBar::setDefaultText(const QString
& text
)
142 m_messageLabel
->setDefaultText(text
);
145 const QString
& DolphinStatusBar::defaultText() const
147 return m_messageLabel
->defaultText();
150 void DolphinStatusBar::resizeEvent(QResizeEvent
* event
)
152 QWidget::resizeEvent(event
);
153 QTimer::singleShot(0, this, SLOT(showSpaceInfo()));
156 void DolphinStatusBar::updateProgressInfo()
158 const bool isErrorShown
= (m_messageLabel
->type() == Error
);
159 if (m_progress
< 100) {
160 // show the progress information and hide the space information
163 m_progressText
->show();
164 m_progressBar
->show();
168 // hide the progress information and show the space information
169 m_progressText
->hide();
170 m_progressBar
->hide();
175 void DolphinStatusBar::updateSpaceInfoContent(const KUrl
& url
)
177 m_spaceInfo
->setUrl(url
);
181 void DolphinStatusBar::showSpaceInfo()
183 const int widthGap
= m_messageLabel
->widthGap();
184 const bool isProgressBarVisible
= m_progressBar
->isVisible();
186 if (m_spaceInfo
->isVisible()) {
187 // The space information is shown currently. Hide it
188 // if the progress bar is visible or if the status bar
189 // text does not fit into the available width.
190 const QSize
size(m_progressBar
->sizeHint());
191 if (isProgressBarVisible
|| (widthGap
> 0)) {
195 else if (widthGap
+ m_spaceInfo
->width() <= 0) {
200 #include "dolphinstatusbar.moc"