]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/dolphinstatusbar.h
a620a011783466a990347e18db9b61a00ba6a9c0
[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 { Allowed, Disallowed };
43 /**
44 * Shows progress for a task on the status bar.
45 *
46 * Allows us to inform the user about various tasks progressing in the background.
47 * This method can be called from various places in any order but only the most recent call will be displayed.
48 * @param currentlyRunningTaskTitle The task that is currently progressing.
49 * @param progressPercent The percent value shown in a progress bar next to the @p currentlyRunningTaskTitle.
50 * A negative @p progressPercent value will be interpreted as indeterminate/unknown progress.
51 * The progress is shown delayed by 500 milliseconds: If the progress does reach 100 % within 500 milliseconds,
52 * the progress is not shown at all.
53 * @param cancelLoading Whether a "Stop" button for cancelling the task should be available next to the progress reporting.
54 *
55 * @note Make sure you also hide the progress information by calling this with a @p progressPercent equal or greater than 100.
56 */
57 void showProgress(const QString &currentlyRunningTaskTitle, int progressPercent, CancelLoading cancelLoading = CancelLoading::Allowed);
58 QString progressText() const;
59 int progress() const;
60
61 /**
62 * Replaces the text set by setText() by the text that
63 * has been set by setDefaultText(). DolphinStatusBar::text()
64 * will return an empty string after the reset has been done.
65 */
66 void resetToDefaultText();
67
68 /**
69 * Sets the default text, which is shown if the status bar
70 * is rest by DolphinStatusBar::resetToDefaultText().
71 */
72 void setDefaultText(const QString &text);
73 QString defaultText() const;
74
75 QUrl url() const;
76 int zoomLevel() const;
77
78 /**
79 * Refreshes the status bar to get synchronized with the (updated) Dolphin settings.
80 */
81 void readSettings();
82
83 /**
84 * Refreshes the disk space information.
85 */
86 void updateSpaceInfo();
87
88 public Q_SLOTS:
89 void setText(const QString &text);
90 void setUrl(const QUrl &url);
91 void setZoomLevel(int zoomLevel);
92
93 Q_SIGNALS:
94 /**
95 * Is emitted if the stop-button has been pressed during showing a progress.
96 */
97 void stopPressed();
98
99 void zoomLevelChanged(int zoomLevel);
100
101 /**
102 * Requests for @p message with the given @p messageType to be shown to the user in a non-modal way.
103 */
104 void showMessage(const QString &message, KMessageWidget::MessageType messageType);
105
106 protected:
107 void contextMenuEvent(QContextMenuEvent *event) override;
108 void paintEvent(QPaintEvent *paintEvent) override;
109
110 private Q_SLOTS:
111 void showZoomSliderToolTip(int zoomLevel);
112
113 void updateProgressInfo();
114
115 /**
116 * Updates the text for m_label and does an eliding in
117 * case if the text does not fit into the available width.
118 */
119 void updateLabelText();
120
121 /**
122 * Updates the text of the zoom slider tooltip to show
123 * the currently used size.
124 */
125 void updateZoomSliderToolTip(int zoomLevel);
126
127 private:
128 /**
129 * Makes the space information widget and zoom slider widget
130 * visible, if \a visible is true and the settings allow to show
131 * the widgets. showUnknownProgressIf \a visible is false, it is assured that both
132 * widgets are hidden.
133 */
134 void setExtensionsVisible(bool visible);
135
136 void updateContentsMargins();
137
138 /** @see AnimatedHeightWidget::preferredHeight() */
139 int preferredHeight() const override;
140
141 private:
142 QString m_text;
143 QString m_defaultText;
144 KSqueezedTextLabel *m_label;
145 QLabel *m_zoomLabel;
146 StatusBarSpaceInfo *m_spaceInfo;
147
148 QSlider *m_zoomSlider;
149
150 QLabel *m_progressTextLabel;
151 CancelLoading m_cancelLoading = CancelLoading::Allowed;
152 QProgressBar *m_progressBar;
153 QToolButton *m_stopButton;
154 int m_progress;
155 QTimer *m_showProgressBarTimer;
156
157 QTimer *m_delayUpdateTimer;
158 QTime m_textTimestamp;
159
160 QHBoxLayout *m_topLayout;
161 };
162
163 #endif