]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/statusbar/dolphinstatusbar.h
Build with QT_NO_KEYWORDS
[dolphin.git] / src / statusbar / dolphinstatusbar.h
index a536ea17856efea47bcbc47fa38eefd1bb97363f..7b4434539c47141d1bc424f228d819c0514dea01 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 <khbox.h>
+#include <QTime>
+#include <QWidget>
 
-class DolphinView;
-class KUrl;
-class StatusBarMessageLabel;
+class QUrl;
 class StatusBarSpaceInfo;
 class QLabel;
 class QProgressBar;
 class QToolButton;
 class QSlider;
+class QTimer;
+class KSqueezedTextLabel;
 
 /**
  * @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 KHBox
+class DolphinStatusBar : public QWidget
 {
     Q_OBJECT
 
 public:
-    /**
-     * Describes the type of the message text. Dependent
-     * from the type a corresponding icon and color is
-     * used for the message text.
-     */
-    enum Type {
-        Default,
-        OperationCompleted,
-        Information,
-        Error
-    };
-
-    DolphinStatusBar(QWidget* parent, DolphinView* view);
-
-    virtual ~DolphinStatusBar();
-
-    /**
-     * 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.
-     */
-    void setMessage(const QString& msg, Type type);
-    QString message() const;
+    explicit DolphinStatusBar(QWidget* parent);
+    ~DolphinStatusBar() override;
 
-    Type type() const;
+    QString text() const;
 
     /**
      * Sets the text for the progress information.
-     * The text is shown with a delay of 300 milliseconds:
-     * if the progress set by DolphinStatusBar::setProgress()
-     * does reach 100 % within 300 milliseconds,
-     * the progress text is not shown at all. This assures that
-     * no flickering occurs for showing a progress of fast
-     * operations.
+     * DolphinStatusBar::setProgress() should be invoked
+     * afterwards each time the progress changes.
      */
     void setProgressText(const QString& text);
     QString progressText() const;
 
     /**
      * 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.
+     * 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
-    {
-        return m_progress;
-    }
+    int progress() const;
 
     /**
-     * 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.
+     * 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 clear();
+    void resetToDefaultText();
 
     /**
      * Sets the default text, which is shown if the status bar
-     * is cleared by DolphinStatusBar::clear().
+     * is rest by DolphinStatusBar::resetToDefaultText().
      */
     void setDefaultText(const QString& text);
-    const QString& defaultText() const;
+    QString defaultText() const;
+
+    QUrl url() const;
+    int zoomLevel() const;
 
     /**
      * Refreshes the status bar to get synchronized with the (updated) Dolphin settings.
      */
-    void refresh();
-
-protected:
-    /** @see QWidget::resizeEvent() */
-    virtual void resizeEvent(QResizeEvent* event);
-
-private slots:
-    void updateProgressInfo();
+    void readSettings();
 
     /**
-     * Is invoked, when the URL of the DolphinView, where the
-     * statusbar belongs too, has been changed. The space information
-     * content is updated.
+     * Refreshes the disk space information.
      */
-    void updateSpaceInfoContent(const KUrl& url);
+    void updateSpaceInfo();
 
-    /**
-     * Sets the zoom level of the item view to \a zoomLevel.
-     */
+public Q_SLOTS:
+    void setText(const QString& text);
+    void setUrl(const QUrl& url);
     void setZoomLevel(int zoomLevel);
 
+Q_SIGNALS:
     /**
-     * Assures that the text of the statusbar stays visible by hiding
-     * the space information widget or the zoom slider widget if not
-     * enough width is available.
+     * Is emitted if the stop-button has been pressed during showing a progress.
      */
-    void assureVisibleText();
+    void stopPressed();
+
+    void zoomLevelChanged(int zoomLevel);
 
-    void zoomOut();
-    void zoomIn();
+protected:
+    void contextMenuEvent(QContextMenuEvent* event) override;
+
+private Q_SLOTS:
     void showZoomSliderToolTip(int zoomLevel);
+    void updateProgressInfo();
 
-private:
     /**
-     * Makes the space information widget and zoom slider widget
-     * visible, if \a visible is true and the settings allow to show
-     * the widgets. If \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
@@ -167,18 +112,31 @@ private:
     void updateZoomSliderToolTip(int zoomLevel);
 
 private:
-    DolphinView* m_view;
-    StatusBarMessageLabel* m_messageLabel;
+    /**
+     * 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);
+
+private:
+    QString m_text;
+    QString m_defaultText;
+    KSqueezedTextLabel* m_label;
+    QLabel* m_zoomLabel;
     StatusBarSpaceInfo* m_spaceInfo;
 
-    QWidget* m_zoomWidget;
-    QToolButton* m_zoomOut;
     QSlider* m_zoomSlider;
-    QToolButton* m_zoomIn;
 
-    QLabel* m_progressText;
+    QLabel* m_progressTextLabel;
     QProgressBar* m_progressBar;
+    QToolButton* m_stopButton;
     int m_progress;
+    QTimer* m_showProgressBarTimer;
+
+    QTimer* m_delayUpdateTimer;
+    QTime m_textTimestamp;
 };
 
 #endif