]>
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"
26 #include <QtGui/QLabel>
27 #include <QtGui/QProgressBar>
28 #include <QtCore/QTimer>
30 #include <kiconloader.h>
33 DolphinStatusBar::DolphinStatusBar(QWidget
* parent
, const KUrl
& url
) :
42 m_messageLabel
= new StatusBarMessageLabel(this);
43 m_messageLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
45 m_spaceInfo
= new StatusBarSpaceInfo(this);
46 m_spaceInfo
->setUrl(url
);
48 m_progressText
= new QLabel(this);
49 m_progressText
->hide();
51 m_progressBar
= new QProgressBar(this);
52 m_progressBar
->hide();
54 const int contentHeight
= QFontMetrics(m_messageLabel
->font()).height();
55 const int barHeight
= contentHeight
+ 8;
57 setMinimumHeight(barHeight
);
58 m_messageLabel
->setMinimumTextHeight(barHeight
);
59 m_spaceInfo
->setFixedHeight(contentHeight
);
60 m_progressBar
->setFixedHeight(contentHeight
);
61 m_progressBar
->setMaximumWidth(200);
65 DolphinStatusBar::~DolphinStatusBar()
69 void DolphinStatusBar::setMessage(const QString
& msg
,
72 m_messageLabel
->setMessage(msg
, 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
)
106 } else if (percent
> 100) {
110 m_progress
= percent
;
111 if (m_messageLabel
->type() == Error
) {
112 // don't update any widget or status bar text if an
113 // error message is shown
117 m_progressBar
->setValue(m_progress
);
118 if (!m_progressBar
->isVisible() || (percent
== 100)) {
119 QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
122 const QString
& defaultText
= m_messageLabel
->defaultText();
123 const QString
msg(m_messageLabel
->text());
124 if ((percent
== 0) && !msg
.isEmpty()) {
125 setMessage(QString(), Default
);
126 } else if ((percent
== 100) && (msg
!= defaultText
)) {
127 setMessage(defaultText
, Default
);
131 void DolphinStatusBar::clear()
133 setMessage(m_messageLabel
->defaultText(), Default
);
136 void DolphinStatusBar::setDefaultText(const QString
& text
)
138 m_messageLabel
->setDefaultText(text
);
141 const QString
& DolphinStatusBar::defaultText() const
143 return m_messageLabel
->defaultText();
146 void DolphinStatusBar::resizeEvent(QResizeEvent
* event
)
148 QWidget::resizeEvent(event
);
149 QMetaObject::invokeMethod(this, "showSpaceInfo", Qt::QueuedConnection
);
152 void DolphinStatusBar::updateProgressInfo()
154 const bool isErrorShown
= (m_messageLabel
->type() == Error
);
155 if (m_progress
< 100) {
156 // show the progress information and hide the space information
159 m_progressText
->show();
160 m_progressBar
->show();
163 // hide the progress information and show the space information
164 m_progressText
->hide();
165 m_progressBar
->hide();
170 void DolphinStatusBar::updateSpaceInfoContent(const KUrl
& url
)
172 m_spaceInfo
->setUrl(url
);
176 void DolphinStatusBar::showSpaceInfo()
178 const int widthGap
= m_messageLabel
->widthGap();
179 const bool isProgressBarVisible
= m_progressBar
->isVisible();
181 if (m_spaceInfo
->isVisible()) {
182 // The space information is shown currently. Hide it
183 // if the progress bar is visible or if the status bar
184 // text does not fit into the available width.
185 if (isProgressBarVisible
|| (widthGap
> 0)) {
188 } else if (widthGap
+ m_spaceInfo
->width() <= 0) {
193 #include "dolphinstatusbar.moc"