]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/dolphinstatusbar.h
SVN_SILENT made messages (.desktop file) - always resolve ours
[dolphin.git] / src / statusbar / dolphinstatusbar.h
1 /*
2 * SPDX-FileCopyrightText: 2006-2012 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINSTATUSBAR_H
8 #define DOLPHINSTATUSBAR_H
9
10 #include "animatedheightwidget.h"
11
12 #include <KMessageWidget>
13
14 #include <QTime>
15
16 class QUrl;
17 class StatusBarSpaceInfo;
18 class QLabel;
19 class QProgressBar;
20 class QToolButton;
21 class QSlider;
22 class QTimer;
23 class KSqueezedTextLabel;
24 class QHBoxLayout;
25
26 /**
27 * @brief Represents the statusbar of a Dolphin view.
28 *
29 * The statusbar allows to show messages, progress
30 * information and space-information of a disk.
31 */
32 class DolphinStatusBar : public AnimatedHeightWidget
33 {
34 Q_OBJECT
35
36 public:
37 explicit DolphinStatusBar(QWidget *parent);
38 ~DolphinStatusBar() override;
39
40 QString text() const;
41
42 enum class CancelLoading {
43 Allowed,
44 Disallowed
45 };
46 /**
47 * Shows progress for a task on the status bar.
48 *
49 * Allows us to inform the user about various tasks progressing in the background.
50 * This method can be called from various places in any order but only the most recent call will be displayed.
51 * @param currentlyRunningTaskTitle The task that is currently progressing.
52 * @param progressPercent The percent value shown in a progress bar next to the @p currentlyRunningTaskTitle.
53 * A negative @p progressPercent value will be interpreted as indeterminate/unknown progress.
54 * The progress is shown delayed by 500 milliseconds: If the progress does reach 100 % within 500 milliseconds,
55 * the progress is not shown at all.
56 * @param cancelLoading Whether a "Stop" button for cancelling the task should be available next to the progress reporting.
57 *
58 * @note Make sure you also hide the progress information by calling this with a @p progressPercent equal or greater than 100.
59 */
60 void showProgress(const QString &currentlyRunningTaskTitle, int progressPercent, CancelLoading cancelLoading = CancelLoading::Allowed);
61 QString progressText() const;
62 int progress() const;
63
64 /**
65 * Replaces the text set by setText() by the text that
66 * has been set by setDefaultText(). DolphinStatusBar::text()
67 * will return an empty string after the reset has been done.
68 */
69 void resetToDefaultText();
70
71 /**
72 * Sets the default text, which is shown if the status bar
73 * is rest by DolphinStatusBar::resetToDefaultText().
74 */
75 void setDefaultText(const QString &text);
76 QString defaultText() const;
77
78 QUrl url() const;
79 int zoomLevel() const;
80
81 /**
82 * Refreshes the status bar to get synchronized with the (updated) Dolphin settings.
83 */
84 void readSettings();
85
86 /**
87 * Refreshes the disk space information.
88 */
89 void updateSpaceInfo();
90
91 /**
92 * Changes the statusbar between disabled, small, and full width
93 * depending on settings enabled.
94 */
95 void updateMode();
96
97 /**
98 * Updates the statusbar width to fit all content.
99 */
100 void updateWidthToContent();
101
102 /**
103 * @return The amount of clipping done to the small statusbar side and bottom.
104 */
105 int clippingAmount() const;
106
107 public Q_SLOTS:
108 void setText(const QString &text);
109 void setUrl(const QUrl &url);
110 void setZoomLevel(int zoomLevel);
111
112 Q_SIGNALS:
113 /**
114 * Is emitted if the stop-button has been pressed during showing a progress.
115 */
116 void stopPressed();
117
118 void zoomLevelChanged(int zoomLevel);
119
120 /**
121 * Requests for @p message with the given @p messageType to be shown to the user in a non-modal way.
122 */
123 void showMessage(const QString &message, KMessageWidget::MessageType messageType);
124
125 /**
126 * Emitted when statusbar mode is changed.
127 */
128 void modeUpdated();
129
130 /**
131 * Emitted when statusbar width is updated to fit content.
132 */
133 void widthUpdated();
134
135 /**
136 * Emitted when statusbar url has changed.
137 */
138 void urlChanged();
139
140 protected:
141 void contextMenuEvent(QContextMenuEvent *event) override;
142 void paintEvent(QPaintEvent *paintEvent) override;
143
144 private Q_SLOTS:
145 void showZoomSliderToolTip(int zoomLevel);
146
147 void updateProgressInfo();
148
149 /**
150 * Updates the text for m_label and does an eliding in
151 * case if the text does not fit into the available width.
152 */
153 void updateLabelText();
154
155 /**
156 * Updates the text of the zoom slider tooltip to show
157 * the currently used size.
158 */
159 void updateZoomSliderToolTip(int zoomLevel);
160
161 private:
162 /**
163 * Makes the space information widget and zoom slider widget
164 * visible, if \a visible is true and the settings allow to show
165 * the widgets. showUnknownProgressIf \a visible is false, it is assured that both
166 * widgets are hidden.
167 */
168 void setExtensionsVisible(bool visible);
169
170 void updateContentsMargins();
171
172 /** @see AnimatedHeightWidget::preferredHeight() */
173 int preferredHeight() const override;
174
175 private:
176 QString m_text;
177 QString m_defaultText;
178 KSqueezedTextLabel *m_label;
179 QLabel *m_zoomLabel;
180 StatusBarSpaceInfo *m_spaceInfo;
181
182 QSlider *m_zoomSlider;
183
184 QLabel *m_progressTextLabel;
185 CancelLoading m_cancelLoading = CancelLoading::Allowed;
186 QProgressBar *m_progressBar;
187 QToolButton *m_stopButton;
188 int m_progress;
189 QTimer *m_showProgressBarTimer;
190
191 QTimer *m_delayUpdateTimer;
192 QTime m_textTimestamp;
193
194 QHBoxLayout *m_topLayout;
195 };
196
197 #endif