]>
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 "dolphinsettings.h"
23 #include "dolphinview.h"
24 #include "dolphin_generalsettings.h"
25 #include "statusbarmessagelabel.h"
26 #include "statusbarspaceinfo.h"
27 #include "zoomlevelinfo.h"
29 #include <QtGui/QLabel>
30 #include <QtGui/QProgressBar>
31 #include <QtCore/QTimer>
33 #include <kiconloader.h>
36 DolphinStatusBar::DolphinStatusBar(QWidget
* parent
, DolphinView
* view
) :
45 m_requestedZoomLevel(0)
49 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
50 this, SLOT(updateSpaceInfoContent(const KUrl
&)));
52 // initialize message label
53 m_messageLabel
= new StatusBarMessageLabel(this);
54 m_messageLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
56 // initialize space information
57 m_spaceInfo
= new StatusBarSpaceInfo(this);
58 m_spaceInfo
->setUrl(m_view
->url());
60 // initialize zoom slider
61 m_zoomSlider
= new QSlider(Qt::Horizontal
, this);
62 m_zoomSlider
->setPageStep(1);
64 const int min
= ZoomLevelInfo::minimumLevel();
65 const int max
= ZoomLevelInfo::maximumLevel();
66 m_zoomSlider
->setRange(min
, max
);
67 m_zoomSlider
->setValue(view
->zoomLevel());
69 connect(m_zoomSlider
, SIGNAL(sliderMoved(int)),
70 this, SLOT(requestZoomLevel(int)));
71 connect(m_view
, SIGNAL(zoomLevelChanged(int)),
72 m_zoomSlider
, SLOT(setValue(int)));
74 m_zoomTimer
= new QTimer(this);
75 m_zoomTimer
->setSingleShot(true);
76 m_zoomTimer
->setInterval(50);
77 connect(m_zoomTimer
, SIGNAL(timeout()),
78 this, SLOT(updateZoomLevel()));
80 // initialize progress informatino
81 m_progressText
= new QLabel(this);
82 m_progressText
->hide();
84 m_progressBar
= new QProgressBar(this);
85 m_progressBar
->hide();
88 const int contentHeight
= QFontMetrics(m_messageLabel
->font()).height() + 4;
89 const int barHeight
= contentHeight
+ 4;
91 setMinimumHeight(barHeight
);
92 m_messageLabel
->setMinimumTextHeight(barHeight
);
93 m_spaceInfo
->setFixedHeight(contentHeight
);
94 m_progressBar
->setFixedHeight(contentHeight
);
95 m_progressBar
->setMaximumWidth(200);
96 m_zoomSlider
->setMaximumWidth(100);
98 setExtensionsVisible(true);
102 DolphinStatusBar::~DolphinStatusBar()
106 void DolphinStatusBar::setMessage(const QString
& msg
,
109 m_messageLabel
->setMessage(msg
, type
);
111 const int widthGap
= m_messageLabel
->widthGap();
113 m_progressBar
->hide();
114 m_progressText
->hide();
119 DolphinStatusBar::Type
DolphinStatusBar::type() const
121 return m_messageLabel
->type();
124 QString
DolphinStatusBar::message() const
126 return m_messageLabel
->text();
129 void DolphinStatusBar::setProgressText(const QString
& text
)
131 m_progressText
->setText(text
);
134 QString
DolphinStatusBar::progressText() const
136 return m_progressText
->text();
139 void DolphinStatusBar::setProgress(int percent
)
143 } else if (percent
> 100) {
147 m_progress
= percent
;
148 if (m_messageLabel
->type() == Error
) {
149 // don't update any widget or status bar text if an
150 // error message is shown
154 m_progressBar
->setValue(m_progress
);
155 if (!m_progressBar
->isVisible() || (percent
== 100)) {
156 QTimer::singleShot(300, this, SLOT(updateProgressInfo()));
159 const QString
& defaultText
= m_messageLabel
->defaultText();
160 const QString
msg(m_messageLabel
->text());
161 if ((percent
== 0) && !msg
.isEmpty()) {
162 setMessage(QString(), Default
);
163 } else if ((percent
== 100) && (msg
!= defaultText
)) {
164 setMessage(defaultText
, Default
);
168 void DolphinStatusBar::clear()
170 setMessage(m_messageLabel
->defaultText(), Default
);
173 void DolphinStatusBar::setDefaultText(const QString
& text
)
175 m_messageLabel
->setDefaultText(text
);
178 const QString
& DolphinStatusBar::defaultText() const
180 return m_messageLabel
->defaultText();
183 void DolphinStatusBar::resizeEvent(QResizeEvent
* event
)
185 QWidget::resizeEvent(event
);
186 QMetaObject::invokeMethod(this, "assureVisibleText", Qt::QueuedConnection
);
189 void DolphinStatusBar::updateProgressInfo()
191 const bool isErrorShown
= (m_messageLabel
->type() == Error
);
192 if (m_progress
< 100) {
193 // show the progress information and hide the extensions
194 setExtensionsVisible(false);
196 m_progressText
->show();
197 m_progressBar
->show();
200 // hide the progress information and show the extensions
201 m_progressText
->hide();
202 m_progressBar
->hide();
207 void DolphinStatusBar::updateSpaceInfoContent(const KUrl
& url
)
209 m_spaceInfo
->setUrl(url
);
213 void DolphinStatusBar::requestZoomLevel(int zoomLevel
)
215 m_requestedZoomLevel
= zoomLevel
;
216 m_zoomTimer
->start();
219 void DolphinStatusBar::updateZoomLevel()
221 m_view
->setZoomLevel(m_requestedZoomLevel
);
224 void DolphinStatusBar::assureVisibleText()
226 const int widthGap
= m_messageLabel
->widthGap();
227 const bool isProgressBarVisible
= m_progressBar
->isVisible();
229 const int spaceInfoWidth
= m_spaceInfo
->isVisible() ? m_spaceInfo
->width() : 0;
230 const int zoomSliderWidth
= m_zoomSlider
->isVisible() ? m_zoomSlider
->width() : 0;
231 const int widgetsWidth
= spaceInfoWidth
+ zoomSliderWidth
;
233 if (widgetsWidth
> 0) {
234 // The space information and (or) the zoom slider are (is) shown.
235 // Hide them if the status bar text does not fit into the available width.
237 setExtensionsVisible(false);
239 } else if (!isProgressBarVisible
&& (widthGap
+ widgetsWidth
<= 0)) {
240 setExtensionsVisible(true);
244 void DolphinStatusBar::setExtensionsVisible(bool visible
)
246 bool spaceInfoVisible
= visible
;
247 bool zoomSliderVisible
= visible
;
249 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
250 spaceInfoVisible
= settings
->showSpaceInfo();
251 zoomSliderVisible
= settings
->showZoomSlider();
254 m_spaceInfo
->setVisible(spaceInfoVisible
);
255 m_zoomSlider
->setVisible(zoomSliderVisible
);
258 #include "dolphinstatusbar.moc"