Changeset View
Changeset View
Standalone View
Standalone View
src/statusbar/dolphinstatusbar.cpp
Show All 33 Lines | |||||
34 | #include <QMenu> | 34 | #include <QMenu> | ||
35 | #include <QProgressBar> | 35 | #include <QProgressBar> | ||
36 | #include <QSlider> | 36 | #include <QSlider> | ||
37 | #include <QTextDocument> | 37 | #include <QTextDocument> | ||
38 | #include <QTimer> | 38 | #include <QTimer> | ||
39 | #include <QToolButton> | 39 | #include <QToolButton> | ||
40 | 40 | | |||
41 | namespace { | 41 | namespace { | ||
42 | const int ResetToDefaultTimeout = 1000; | 42 | const int UpdateDelay = 50; | ||
43 | } | 43 | } | ||
44 | 44 | | |||
45 | DolphinStatusBar::DolphinStatusBar(QWidget* parent) : | 45 | DolphinStatusBar::DolphinStatusBar(QWidget* parent) : | ||
46 | QWidget(parent), | 46 | QWidget(parent), | ||
47 | m_text(), | 47 | m_text(), | ||
48 | m_defaultText(), | 48 | m_defaultText(), | ||
49 | m_label(nullptr), | 49 | m_label(nullptr), | ||
50 | m_spaceInfo(nullptr), | 50 | m_spaceInfo(nullptr), | ||
51 | m_zoomSlider(nullptr), | 51 | m_zoomSlider(nullptr), | ||
52 | m_progressBar(nullptr), | 52 | m_progressBar(nullptr), | ||
53 | m_stopButton(nullptr), | 53 | m_stopButton(nullptr), | ||
54 | m_progress(100), | 54 | m_progress(100), | ||
55 | m_showProgressBarTimer(nullptr), | 55 | m_showProgressBarTimer(nullptr), | ||
56 | m_resetToDefaultTextTimer(nullptr), | 56 | m_delayUpdateTimer(nullptr) | ||
57 | m_textTimestamp() | | |||
58 | { | 57 | { | ||
59 | // Initialize text label | 58 | // Initialize text label | ||
60 | m_label = new KSqueezedTextLabel(m_text, this); | 59 | m_label = new KSqueezedTextLabel(m_text, this); | ||
61 | m_label->setWordWrap(true); | 60 | m_label->setWordWrap(true); | ||
62 | m_label->setTextFormat(Qt::PlainText); | 61 | m_label->setTextFormat(Qt::PlainText); | ||
63 | 62 | | |||
64 | // Initialize zoom widget | 63 | // Initialize zoom widget | ||
65 | m_zoomSlider = new QSlider(Qt::Horizontal, this); | 64 | m_zoomSlider = new QSlider(Qt::Horizontal, this); | ||
Show All 24 Lines | |||||
90 | m_progressBar = new QProgressBar(this); | 89 | m_progressBar = new QProgressBar(this); | ||
91 | m_progressBar->hide(); | 90 | m_progressBar->hide(); | ||
92 | 91 | | |||
93 | m_showProgressBarTimer = new QTimer(this); | 92 | m_showProgressBarTimer = new QTimer(this); | ||
94 | m_showProgressBarTimer->setInterval(500); | 93 | m_showProgressBarTimer->setInterval(500); | ||
95 | m_showProgressBarTimer->setSingleShot(true); | 94 | m_showProgressBarTimer->setSingleShot(true); | ||
96 | connect(m_showProgressBarTimer, &QTimer::timeout, this, &DolphinStatusBar::updateProgressInfo); | 95 | connect(m_showProgressBarTimer, &QTimer::timeout, this, &DolphinStatusBar::updateProgressInfo); | ||
97 | 96 | | |||
98 | m_resetToDefaultTextTimer = new QTimer(this); | 97 | // initialize text updater delay timer | ||
99 | m_resetToDefaultTextTimer->setInterval(ResetToDefaultTimeout); | 98 | m_delayUpdateTimer = new QTimer(this); | ||
100 | m_resetToDefaultTextTimer->setSingleShot(true); | 99 | m_delayUpdateTimer->setInterval(UpdateDelay); | ||
101 | connect(m_resetToDefaultTextTimer, &QTimer::timeout, this, &DolphinStatusBar::slotResetToDefaultText); | 100 | m_delayUpdateTimer->setSingleShot(true); | ||
101 | connect(m_delayUpdateTimer, &QTimer::timeout, | ||||
102 | this, &DolphinStatusBar::updateLabelText); | ||||
102 | 103 | | |||
103 | // Initialize top layout and size policies | 104 | // Initialize top layout and size policies | ||
104 | const int fontHeight = QFontMetrics(m_label->font()).height(); | 105 | const int fontHeight = QFontMetrics(m_label->font()).height(); | ||
105 | const int zoomSliderHeight = m_zoomSlider->minimumSizeHint().height(); | 106 | const int zoomSliderHeight = m_zoomSlider->minimumSizeHint().height(); | ||
106 | const int buttonHeight = m_stopButton->height(); | 107 | const int buttonHeight = m_stopButton->height(); | ||
107 | const int contentHeight = qMax(qMax(fontHeight, zoomSliderHeight), buttonHeight); | 108 | const int contentHeight = qMax(qMax(fontHeight, zoomSliderHeight), buttonHeight); | ||
108 | 109 | | |||
109 | QFontMetrics fontMetrics(m_label->font()); | 110 | QFontMetrics fontMetrics(m_label->font()); | ||
Show All 39 Lines | |||||
149 | void DolphinStatusBar::setText(const QString& text) | 150 | void DolphinStatusBar::setText(const QString& text) | ||
150 | { | 151 | { | ||
151 | if (m_text == text) { | 152 | if (m_text == text) { | ||
152 | return; | 153 | return; | ||
153 | } | 154 | } | ||
154 | 155 | | |||
155 | m_textTimestamp = QTime::currentTime(); | 156 | m_textTimestamp = QTime::currentTime(); | ||
156 | 157 | | |||
157 | if (text.isEmpty()) { | | |||
158 | // Assure that the previous set text won't get | | |||
159 | // cleared immediately. | | |||
160 | m_resetToDefaultTextTimer->start(); | | |||
161 | } else { | | |||
162 | m_text = text; | 158 | m_text = text; | ||
163 | 159 | // will update status bar text in 50ms | |||
164 | if (m_resetToDefaultTextTimer->isActive()) { | 160 | m_delayUpdateTimer->start(); | ||
165 | m_resetToDefaultTextTimer->start(); | | |||
166 | } | | |||
167 | | ||||
168 | updateLabelText(); | | |||
169 | } | | |||
170 | } | 161 | } | ||
171 | 162 | | |||
172 | QString DolphinStatusBar::text() const | 163 | QString DolphinStatusBar::text() const | ||
173 | { | 164 | { | ||
174 | return m_text; | 165 | return m_text; | ||
175 | } | 166 | } | ||
176 | 167 | | |||
177 | void DolphinStatusBar::setProgressText(const QString& text) | 168 | void DolphinStatusBar::setProgressText(const QString& text) | ||
Show All 31 Lines | |||||
209 | 200 | | |||
210 | int DolphinStatusBar::progress() const | 201 | int DolphinStatusBar::progress() const | ||
211 | { | 202 | { | ||
212 | return m_progress; | 203 | return m_progress; | ||
213 | } | 204 | } | ||
214 | 205 | | |||
215 | void DolphinStatusBar::resetToDefaultText() | 206 | void DolphinStatusBar::resetToDefaultText() | ||
216 | { | 207 | { | ||
208 | m_text.clear(); | ||||
209 | | ||||
217 | QTime currentTime; | 210 | QTime currentTime; | ||
218 | if (currentTime.msecsTo(m_textTimestamp) < ResetToDefaultTimeout) { | 211 | if (currentTime.msecsTo(m_textTimestamp) < UpdateDelay) { | ||
219 | m_resetToDefaultTextTimer->start(); | 212 | m_delayUpdateTimer->start(); | ||
220 | } else { | 213 | } else { | ||
221 | m_resetToDefaultTextTimer->stop(); | 214 | updateLabelText(); | ||
222 | slotResetToDefaultText(); | | |||
223 | } | 215 | } | ||
224 | } | 216 | } | ||
225 | 217 | | |||
226 | void DolphinStatusBar::setDefaultText(const QString& text) | 218 | void DolphinStatusBar::setDefaultText(const QString& text) | ||
227 | { | 219 | { | ||
228 | m_defaultText = text; | 220 | m_defaultText = text; | ||
229 | updateLabelText(); | 221 | updateLabelText(); | ||
230 | } | 222 | } | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | |||||
320 | } | 312 | } | ||
321 | 313 | | |||
322 | void DolphinStatusBar::updateLabelText() | 314 | void DolphinStatusBar::updateLabelText() | ||
323 | { | 315 | { | ||
324 | const QString text = m_text.isEmpty() ? m_defaultText : m_text; | 316 | const QString text = m_text.isEmpty() ? m_defaultText : m_text; | ||
325 | m_label->setText(text); | 317 | m_label->setText(text); | ||
326 | } | 318 | } | ||
327 | 319 | | |||
328 | void DolphinStatusBar::slotResetToDefaultText() | | |||
329 | { | | |||
330 | m_text.clear(); | | |||
331 | updateLabelText(); | | |||
332 | } | | |||
333 | | ||||
334 | void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel) | 320 | void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel) | ||
335 | { | 321 | { | ||
336 | const int size = ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel); | 322 | const int size = ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel); | ||
337 | m_zoomSlider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); | 323 | m_zoomSlider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); | ||
338 | } | 324 | } | ||
339 | 325 | | |||
340 | void DolphinStatusBar::setExtensionsVisible(bool visible) | 326 | void DolphinStatusBar::setExtensionsVisible(bool visible) | ||
341 | { | 327 | { | ||
Show All 10 Lines |