]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/statusbar/dolphinstatusbar.h
GIT_SILENT Sync po/docbooks with svn
[dolphin.git] / src / statusbar / dolphinstatusbar.h
index 2c1378372b62df2aa9b2bdc3efa47a2ef3f2bc50..b4ddcd95efb273d754a87b616acf1f7359dbd1bf 100644 (file)
-/***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
- *                                                                         *
- *   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 <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #ifndef DOLPHINSTATUSBAR_H
 #define DOLPHINSTATUSBAR_H
 
-#include "konq_statusbarmessagelabel.h"
+#include "animatedheightwidget.h"
+
+#include <KMessageWidget>
+
 #include <QTime>
-#include <QWidget>
 
-class DolphinView;
-class KUrl;
+class QUrl;
 class StatusBarSpaceInfo;
 class QLabel;
 class QProgressBar;
 class QToolButton;
 class QSlider;
+class QTimer;
+class KSqueezedTextLabel;
+class QHBoxLayout;
 
 /**
  * @brief Represents the statusbar of a Dolphin view.
  *
- * The statusbar allows to show messages and progress
- * information.
+ * 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:
+    explicit DolphinStatusBar(QWidget *parent);
+    ~DolphinStatusBar() override;
+
+    QString text() const;
+
+    enum class CancelLoading {
+        Allowed,
+        Disallowed
+    };
     /**
-     * Describes the type of the message text. Dependent
-     * from the type a corresponding icon and color is
-     * used for the message text.
+     * 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.
      */
-    enum Type {
-        Default = KonqStatusBarMessageLabel::Default,
-        OperationCompleted = KonqStatusBarMessageLabel::OperationCompleted,
-        Information = KonqStatusBarMessageLabel::Information,
-        Error = KonqStatusBarMessageLabel::Error
-    };
-
-    explicit DolphinStatusBar(QWidget* parent, DolphinView* view);
+    void showProgress(const QString &currentlyRunningTaskTitle, int progressPercent, CancelLoading cancelLoading = CancelLoading::Allowed);
+    QString progressText() const;
+    int progress() const;
 
-    virtual ~DolphinStatusBar();
+    /**
+     * Replaces the text set by setText() by the text that
+     * has been set by setDefaultText(). DolphinStatusBar::text()
+     * will return an empty string after the reset has been done.
+     */
+    void resetToDefaultText();
 
     /**
-     * Sets the message text to \a msg. Dependant
-     * from the given type \a type an icon is shown and
-     * the color of the text is adjusted. The height of
-     * the statusbar is automatically adjusted in a way,
-     * that the full text fits into the available width.
-     *
-     * If a progress is ongoing and a message
-     * with the type Type::Error is set, the progress
-     * is cleared automatically.
+     * Sets the default text, which is shown if the status bar
+     * is rest by DolphinStatusBar::resetToDefaultText().
      */
-    void setMessage(const QString& msg, Type type);
-    QString message() const;
+    void setDefaultText(const QString &text);
+    QString defaultText() const;
 
-    Type type() const;
+    QUrl url() const;
+    int zoomLevel() const;
 
     /**
-     * Sets the text for the progress information.
-     * DolphinStatusBar::setProgress() should be invoked
-     * afterwards each time the progress changes.
+     * Refreshes the status bar to get synchronized with the (updated) Dolphin settings.
      */
-    void setProgressText(const QString& text);
-    QString progressText() const;
+    void readSettings();
 
     /**
-     * Sets the progress in percent (0 - 100). The
-     * progress is shown with a delay of 300 milliseconds:
-     * if the progress does reach 100 % within 300 milliseconds,
-     * the progress is not shown at all. This assures that
-     * no flickering occurs for showing a progress of fast
-     * operations.
+     * Refreshes the disk space information.
      */
-    void setProgress(int percent);
-    int progress() const;
+    void updateSpaceInfo();
 
     /**
-     * Clears the message text of the status bar by replacing
-     * the message with the default text, which can be set
-     * by DolphinStatusBar::setDefaultText(). The progress
-     * information is not cleared.
+     * Changes the statusbar between disabled, small, and full width
+     * depending on settings enabled.
      */
-    void clear();
+    void updateMode();
 
     /**
-     * Sets the default text, which is shown if the status bar
-     * is cleared by DolphinStatusBar::clear().
+     * Updates the statusbar width to fit all content.
      */
-    void setDefaultText(const QString& text);
-    QString defaultText() const;
+    void updateWidthToContent();
 
     /**
-     * Refreshes the status bar to get synchronized with the (updated) Dolphin settings.
+     * @return The amount of clipping done to the small statusbar side and bottom.
      */
-    void refresh();
+    int clippingAmount() const;
 
-signals:
+public Q_SLOTS:
+    void setText(const QString &text);
+    void setUrl(const QUrl &url);
+    void setZoomLevel(int zoomLevel);
+
+Q_SIGNALS:
     /**
      * Is emitted if the stop-button has been pressed during showing a progress.
      */
     void stopPressed();
 
-protected:
-    /** @see QWidget::contextMenuEvent() */
-    virtual void contextMenuEvent(QContextMenuEvent* event);
+    void zoomLevelChanged(int zoomLevel);
 
-private slots:
     /**
-     * Is invoked, when the URL of the DolphinView, where the
-     * statusbar belongs too, has been changed. The space information
-     * content is updated.
+     * Requests for @p message with the given @p messageType to be shown to the user in a non-modal way.
      */
-    void updateSpaceInfoContent(const KUrl& url);
+    void showMessage(const QString &message, KMessageWidget::MessageType messageType);
 
     /**
-     * Sets the zoom level of the item view to \a zoomLevel.
+     * Emitted when statusbar mode is changed.
      */
-    void setZoomLevel(int zoomLevel);
+    void modeUpdated();
+
+    /**
+     * Emitted when statusbar width is updated to fit content.
+     */
+    void widthUpdated();
+
+    /**
+     * Emitted when statusbar url has changed.
+     */
+    void urlChanged();
 
-    void zoomOut();
-    void zoomIn();
+protected:
+    void contextMenuEvent(QContextMenuEvent *event) override;
+    void paintEvent(QPaintEvent *paintEvent) override;
+
+private Q_SLOTS:
     void showZoomSliderToolTip(int zoomLevel);
 
-private:
     void updateProgressInfo();
 
     /**
-     * Makes the space information widget and zoom slider widget
-     * visible, if \a visible is true and the settings allow to show
-     * the widgets. showUnknownProgressIf \a visible is false, it is assured that both
-     * widgets are hidden.
+     * Updates the text for m_label and does an eliding in
+     * case if the text does not fit into the available width.
      */
-    void setExtensionsVisible(bool visible);
+    void updateLabelText();
 
     /**
      * Updates the text of the zoom slider tooltip to show
@@ -160,24 +159,39 @@ private:
     void updateZoomSliderToolTip(int zoomLevel);
 
 private:
-    DolphinView* m_view;
-    KonqStatusBarMessageLabel* m_messageLabel;
-    StatusBarSpaceInfo* m_spaceInfo;
-
-    QWidget* m_zoomWidget;
-    QToolButton* m_zoomOut;
-    QSlider* m_zoomSlider;
-    QToolButton* m_zoomIn;
-
-    QLabel* m_progressText;
-    QProgressBar* m_progressBar;
-    QToolButton* m_stopButton;
+    /**
+     * Makes the space information widget and zoom slider widget
+     * visible, if \a visible is true and the settings allow to show
+     * the widgets. showUnknownProgressIf \a visible is false, it is assured that both
+     * widgets are hidden.
+     */
+    void setExtensionsVisible(bool visible);
+
+    void updateContentsMargins();
+
+    /** @see AnimatedHeightWidget::preferredHeight() */
+    int preferredHeight() const override;
+
+private:
+    QString m_text;
+    QString m_defaultText;
+    KSqueezedTextLabel *m_label;
+    QLabel *m_zoomLabel;
+    StatusBarSpaceInfo *m_spaceInfo;
+
+    QSlider *m_zoomSlider;
+
+    QLabel *m_progressTextLabel;
+    CancelLoading m_cancelLoading = CancelLoading::Allowed;
+    QProgressBar *m_progressBar;
+    QToolButton *m_stopButton;
     int m_progress;
+    QTimer *m_showProgressBarTimer;
+
+    QTimer *m_delayUpdateTimer;
+    QTime m_textTimestamp;
 
-    // Timestamp when the last message has been set that has not the type
-    // 'Default'. The timestamp is used to prevent that default messages
-    // hide more important messages after a very short delay.
-    QTime m_messageTimeStamp;
+    QHBoxLayout *m_topLayout;
 };
 
 #endif