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