]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinstatusbar.cpp
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 m_progressBar
->setMaximumWidth(200);
56 setMinimumHeight(size
.height());
57 m_messageLabel
->setMinimumTextHeight(size
.height());
59 connect(parent
, SIGNAL(urlChanged(const KUrl
&)),
60 this, SLOT(updateSpaceInfoContent(const KUrl
&)));
64 DolphinStatusBar::~DolphinStatusBar()
68 void DolphinStatusBar::setMessage(const QString
& msg
,
71 m_messageLabel
->setText(msg
);
72 m_messageLabel
->setType(type
);
74 const int widthGap
= m_messageLabel
->widthGap();
76 m_progressBar
->hide();
77 m_progressText
->hide();
82 DolphinStatusBar::Type
DolphinStatusBar::type() const
84 return m_messageLabel
->type();
87 QString
DolphinStatusBar::message() const
89 return m_messageLabel
->text();
92 void DolphinStatusBar::setProgressText(const QString
& text
)
94 m_progressText
->setText(text
);
97 QString
DolphinStatusBar::progressText() const
99 return m_progressText
->text();
102 void DolphinStatusBar::setProgress(int percent
)
107 else if (percent
> 100) {
111 m_progress
= percent
;
112 if (m_messageLabel
->type() == Error
) {
113 // don't update any widget or status bar text if an
114 // error message is shown
118 m_progressBar
->setValue(m_progress
);
119 if (!m_progressBar
->isVisible() || (percent
== 100)) {
120 QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
123 const QString
msg(m_messageLabel
->text());
124 if ((percent
== 0) && !msg
.isEmpty()) {
125 setMessage(QString::null
, Default
);
127 else if ((percent
== 100) && (msg
!= m_defaultText
)) {
128 setMessage(m_defaultText
, Default
);
132 void DolphinStatusBar::clear()
134 // TODO: check for timeout, so that it's prevented that
135 // a message is cleared too early.
136 setMessage(m_defaultText
, Default
);
139 void DolphinStatusBar::setDefaultText(const QString
& text
)
141 m_defaultText
= text
;
144 void DolphinStatusBar::resizeEvent(QResizeEvent
* event
)
146 QWidget::resizeEvent(event
);
147 QTimer::singleShot(0, this, SLOT(showSpaceInfo()));
150 void DolphinStatusBar::updateProgressInfo()
152 const bool isErrorShown
= (m_messageLabel
->type() == Error
);
153 if (m_progress
< 100) {
154 // show the progress information and hide the space information
157 m_progressText
->show();
158 m_progressBar
->show();
162 // hide the progress information and show the space information
163 m_progressText
->hide();
164 m_progressBar
->hide();
169 void DolphinStatusBar::updateSpaceInfoContent(const KUrl
& url
)
171 m_spaceInfo
->setUrl(url
);
175 void DolphinStatusBar::showSpaceInfo()
177 const int widthGap
= m_messageLabel
->widthGap();
178 const bool isProgressBarVisible
= m_progressBar
->isVisible();
180 if (m_spaceInfo
->isVisible()) {
181 // The space information is shown currently. Hide it
182 // if the progress bar is visible or if the status bar
183 // text does not fit into the available width.
184 const QSize
size(m_progressBar
->sizeHint());
185 if (isProgressBarVisible
|| (widthGap
> 0)) {
189 else if (widthGap
+ m_spaceInfo
->width() <= 0) {
194 #include "dolphinstatusbar.moc"