]>
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
) :
47 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
48 this, SLOT(updateSpaceInfoContent(const KUrl
&)));
50 // initialize message label
51 m_messageLabel
= new StatusBarMessageLabel(this);
52 m_messageLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
54 // initialize space information
55 m_spaceInfo
= new StatusBarSpaceInfo(this);
56 m_spaceInfo
->setUrl(m_view
->url());
58 // initialize zoom slider
59 m_zoomSlider
= new QSlider(Qt::Horizontal
, this);
60 m_zoomSlider
->setPageStep(1);
62 const int min
= ZoomLevelInfo::minimumLevel();
63 const int max
= ZoomLevelInfo::maximumLevel();
64 m_zoomSlider
->setRange(min
, max
);
65 m_zoomSlider
->setValue(view
->zoomLevel());
67 connect(m_zoomSlider
, SIGNAL(valueChanged(int)),
68 this, SLOT(setZoomLevel(int)));
69 connect(m_view
, SIGNAL(zoomLevelChanged(int)),
70 m_zoomSlider
, SLOT(setValue(int)));
72 // initialize progress informatino
73 m_progressText
= new QLabel(this);
74 m_progressText
->hide();
76 m_progressBar
= new QProgressBar(this);
77 m_progressBar
->hide();
80 const int contentHeight
= QFontMetrics(m_messageLabel
->font()).height() + 4;
81 const int barHeight
= contentHeight
+ 4;
83 setMinimumHeight(barHeight
);
84 m_messageLabel
->setMinimumTextHeight(barHeight
);
85 m_spaceInfo
->setFixedHeight(contentHeight
);
86 m_progressBar
->setFixedHeight(contentHeight
);
87 m_progressBar
->setMaximumWidth(200);
88 m_zoomSlider
->setMaximumWidth(100);
90 setExtensionsVisible(true);
93 DolphinStatusBar::~DolphinStatusBar()
97 void DolphinStatusBar::setMessage(const QString
& msg
,
100 m_messageLabel
->setMessage(msg
, type
);
102 const int widthGap
= m_messageLabel
->widthGap();
104 m_progressBar
->hide();
105 m_progressText
->hide();
110 DolphinStatusBar::Type
DolphinStatusBar::type() const
112 return m_messageLabel
->type();
115 QString
DolphinStatusBar::message() const
117 return m_messageLabel
->text();
120 void DolphinStatusBar::setProgressText(const QString
& text
)
122 m_progressText
->setText(text
);
125 QString
DolphinStatusBar::progressText() const
127 return m_progressText
->text();
130 void DolphinStatusBar::setProgress(int percent
)
134 } else if (percent
> 100) {
138 m_progress
= percent
;
139 if (m_messageLabel
->type() == Error
) {
140 // don't update any widget or status bar text if an
141 // error message is shown
145 m_progressBar
->setValue(m_progress
);
146 if (!m_progressBar
->isVisible() || (percent
== 100)) {
147 QTimer::singleShot(300, this, SLOT(updateProgressInfo()));
150 const QString
& defaultText
= m_messageLabel
->defaultText();
151 const QString
msg(m_messageLabel
->text());
152 if ((percent
== 0) && !msg
.isEmpty()) {
153 setMessage(QString(), Default
);
154 } else if ((percent
== 100) && (msg
!= defaultText
)) {
155 setMessage(defaultText
, Default
);
159 void DolphinStatusBar::clear()
161 setMessage(m_messageLabel
->defaultText(), Default
);
164 void DolphinStatusBar::setDefaultText(const QString
& text
)
166 m_messageLabel
->setDefaultText(text
);
169 const QString
& DolphinStatusBar::defaultText() const
171 return m_messageLabel
->defaultText();
174 void DolphinStatusBar::refresh()
176 setExtensionsVisible(true);
180 void DolphinStatusBar::resizeEvent(QResizeEvent
* event
)
182 QWidget::resizeEvent(event
);
183 QMetaObject::invokeMethod(this, "assureVisibleText", Qt::QueuedConnection
);
186 void DolphinStatusBar::updateProgressInfo()
188 const bool isErrorShown
= (m_messageLabel
->type() == Error
);
189 if (m_progress
< 100) {
190 // show the progress information and hide the extensions
191 setExtensionsVisible(false);
193 m_progressText
->show();
194 m_progressBar
->show();
197 // hide the progress information and show the extensions
198 m_progressText
->hide();
199 m_progressBar
->hide();
204 void DolphinStatusBar::updateSpaceInfoContent(const KUrl
& url
)
206 m_spaceInfo
->setUrl(url
);
210 void DolphinStatusBar::setZoomLevel(int zoomLevel
)
212 m_view
->setZoomLevel(zoomLevel
);
215 void DolphinStatusBar::assureVisibleText()
217 const int widthGap
= m_messageLabel
->widthGap();
218 const bool isProgressBarVisible
= m_progressBar
->isVisible();
220 const int spaceInfoWidth
= m_spaceInfo
->isVisible() ? m_spaceInfo
->width() : 0;
221 const int zoomSliderWidth
= m_zoomSlider
->isVisible() ? m_zoomSlider
->width() : 0;
222 const int widgetsWidth
= spaceInfoWidth
+ zoomSliderWidth
;
224 if (widgetsWidth
> 0) {
225 // The space information and (or) the zoom slider are (is) shown.
226 // Hide them if the status bar text does not fit into the available width.
228 setExtensionsVisible(false);
230 } else if (!isProgressBarVisible
&& (widthGap
+ widgetsWidth
<= 0)) {
231 setExtensionsVisible(true);
235 void DolphinStatusBar::setExtensionsVisible(bool visible
)
237 bool spaceInfoVisible
= visible
;
238 bool zoomSliderVisible
= visible
;
240 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
241 spaceInfoVisible
= settings
->showSpaceInfo();
242 zoomSliderVisible
= settings
->showZoomSlider();
245 m_spaceInfo
->setVisible(spaceInfoVisible
);
246 m_zoomSlider
->setVisible(zoomSliderVisible
);
249 #include "dolphinstatusbar.moc"