X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0dd0b65bf02f52da0d2e9d270160e69b81a357ca..9f233850beb60168e8773623e0b5ae052c5287e9:/src/statusbar/dolphinstatusbar.h diff --git a/src/statusbar/dolphinstatusbar.h b/src/statusbar/dolphinstatusbar.h index 0b0004e47..b4ddcd95e 100644 --- a/src/statusbar/dolphinstatusbar.h +++ b/src/statusbar/dolphinstatusbar.h @@ -1,27 +1,17 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2006-2012 Peter Penz + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #ifndef DOLPHINSTATUSBAR_H #define DOLPHINSTATUSBAR_H +#include "animatedheightwidget.h" + +#include + #include -#include class QUrl; class StatusBarSpaceInfo; @@ -31,6 +21,7 @@ class QToolButton; class QSlider; class QTimer; class KSqueezedTextLabel; +class QHBoxLayout; /** * @brief Represents the statusbar of a Dolphin view. @@ -38,37 +29,41 @@ class KSqueezedTextLabel; * The statusbar allows to show messages, progress * information and space-information of a disk. */ -class DolphinStatusBar : public QWidget +class DolphinStatusBar : public AnimatedHeightWidget { Q_OBJECT public: - DolphinStatusBar(QWidget* parent); + explicit DolphinStatusBar(QWidget *parent); ~DolphinStatusBar() override; QString text() const; + enum class CancelLoading { + Allowed, + Disallowed + }; /** - * Sets the text for the progress information. - * DolphinStatusBar::setProgress() should be invoked - * afterwards each time the progress changes. + * Shows progress for a task on the status bar. + * + * Allows us to inform the user about various tasks progressing in the background. + * This method can be called from various places in any order but only the most recent call will be displayed. + * @param currentlyRunningTaskTitle The task that is currently progressing. + * @param progressPercent The percent value shown in a progress bar next to the @p currentlyRunningTaskTitle. + * A negative @p progressPercent value will be interpreted as indeterminate/unknown progress. + * The progress is shown delayed by 500 milliseconds: If the progress does reach 100 % within 500 milliseconds, + * the progress is not shown at all. + * @param cancelLoading Whether a "Stop" button for cancelling the task should be available next to the progress reporting. + * + * @note Make sure you also hide the progress information by calling this with a @p progressPercent equal or greater than 100. */ - void setProgressText(const QString& text); + void showProgress(const QString ¤tlyRunningTaskTitle, int progressPercent, CancelLoading cancelLoading = CancelLoading::Allowed); QString progressText() const; - - /** - * Sets the progress in percent (0 - 100). The - * progress is shown delayed by 500 milliseconds: - * If the progress does reach 100 % within 500 milliseconds, - * the progress is not shown at all. - */ - void setProgress(int percent); int progress() const; /** * Replaces the text set by setText() by the text that - * has been set by setDefaultText(). It is assured that the previous - * text will be shown for at least 1 second. DolphinStatusBar::text() + * has been set by setDefaultText(). DolphinStatusBar::text() * will return an empty string after the reset has been done. */ void resetToDefaultText(); @@ -77,7 +72,7 @@ public: * Sets the default text, which is shown if the status bar * is rest by DolphinStatusBar::resetToDefaultText(). */ - void setDefaultText(const QString& text); + void setDefaultText(const QString &text); QString defaultText() const; QUrl url() const; @@ -88,12 +83,33 @@ public: */ void readSettings(); -public slots: - void setText(const QString& text); - void setUrl(const QUrl& url); + /** + * Refreshes the disk space information. + */ + void updateSpaceInfo(); + + /** + * Changes the statusbar between disabled, small, and full width + * depending on settings enabled. + */ + void updateMode(); + + /** + * Updates the statusbar width to fit all content. + */ + void updateWidthToContent(); + + /** + * @return The amount of clipping done to the small statusbar side and bottom. + */ + int clippingAmount() const; + +public Q_SLOTS: + void setText(const QString &text); + void setUrl(const QUrl &url); void setZoomLevel(int zoomLevel); -signals: +Q_SIGNALS: /** * Is emitted if the stop-button has been pressed during showing a progress. */ @@ -101,11 +117,33 @@ signals: void zoomLevelChanged(int zoomLevel); + /** + * Requests for @p message with the given @p messageType to be shown to the user in a non-modal way. + */ + void showMessage(const QString &message, KMessageWidget::MessageType messageType); + + /** + * Emitted when statusbar mode is changed. + */ + void modeUpdated(); + + /** + * Emitted when statusbar width is updated to fit content. + */ + void widthUpdated(); + + /** + * Emitted when statusbar url has changed. + */ + void urlChanged(); + protected: - void contextMenuEvent(QContextMenuEvent* event) override; + void contextMenuEvent(QContextMenuEvent *event) override; + void paintEvent(QPaintEvent *paintEvent) override; -private slots: +private Q_SLOTS: void showZoomSliderToolTip(int zoomLevel); + void updateProgressInfo(); /** @@ -114,14 +152,6 @@ private slots: */ void updateLabelText(); - /** - * Is invoked by m_resetToDefaultTextTimer and clears - * m_text so that the default text will be shown. This - * prevents that information-messages will be cleared - * too fast. - */ - void slotResetToDefaultText(); - /** * Updates the text of the zoom slider tooltip to show * the currently used size. @@ -137,22 +167,31 @@ private: */ void setExtensionsVisible(bool visible); + void updateContentsMargins(); + + /** @see AnimatedHeightWidget::preferredHeight() */ + int preferredHeight() const override; + private: QString m_text; QString m_defaultText; - KSqueezedTextLabel* m_label; - StatusBarSpaceInfo* m_spaceInfo; + KSqueezedTextLabel *m_label; + QLabel *m_zoomLabel; + StatusBarSpaceInfo *m_spaceInfo; - QSlider* m_zoomSlider; + QSlider *m_zoomSlider; - QLabel* m_progressTextLabel; - QProgressBar* m_progressBar; - QToolButton* m_stopButton; + QLabel *m_progressTextLabel; + CancelLoading m_cancelLoading = CancelLoading::Allowed; + QProgressBar *m_progressBar; + QToolButton *m_stopButton; int m_progress; - QTimer* m_showProgressBarTimer; + QTimer *m_showProgressBarTimer; - QTimer* m_resetToDefaultTextTimer; + QTimer *m_delayUpdateTimer; QTime m_textTimestamp; + + QHBoxLayout *m_topLayout; }; #endif