File indexing completed on 2024-04-28 15:51:46

0001 /*
0002     SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it>
0003     SPDX-FileCopyrightText: 2006 Albert Astals Cid <aacid@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef _OKULAR_MINIBAR_H_
0009 #define _OKULAR_MINIBAR_H_
0010 
0011 #include "core/observer.h"
0012 #include <KLineEdit>
0013 #include <QSet>
0014 #include <qwidget.h>
0015 
0016 namespace Okular
0017 {
0018 class Document;
0019 }
0020 
0021 class MiniBar;
0022 class HoverButton;
0023 class QIntValidator;
0024 class QLabel;
0025 class QToolBar;
0026 
0027 // [private widget] lineEdit for entering/validating page numbers
0028 class PagesEdit : public KLineEdit
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit PagesEdit(MiniBar *parent);
0034     void setText(const QString &) override;
0035 
0036 protected:
0037     void focusInEvent(QFocusEvent *e) override;
0038     void focusOutEvent(QFocusEvent *e) override;
0039     void mousePressEvent(QMouseEvent *e) override;
0040     void wheelEvent(QWheelEvent *e) override;
0041     bool event(QEvent *e) override;
0042 
0043 private Q_SLOTS:
0044     void updatePalette();
0045 
0046 private:
0047     MiniBar *m_miniBar;
0048     bool m_eatClick;
0049 };
0050 
0051 class PageNumberEdit : public PagesEdit
0052 {
0053     Q_OBJECT
0054 
0055 public:
0056     explicit PageNumberEdit(MiniBar *miniBar);
0057     void setPagesNumber(int pages);
0058 
0059 private:
0060     QIntValidator *m_validator;
0061 };
0062 
0063 class PageLabelEdit : public PagesEdit
0064 {
0065     Q_OBJECT
0066 public:
0067     explicit PageLabelEdit(MiniBar *parent);
0068     void setText(const QString &newText) override;
0069     void setPageLabels(const QVector<Okular::Page *> &pageVector);
0070 
0071 Q_SIGNALS:
0072     void pageNumberChosen(int page);
0073 
0074 private Q_SLOTS:
0075     void pageChosen();
0076 
0077 private:
0078     QString m_lastLabel;
0079     QMap<QString, int> m_labelPageMap;
0080 };
0081 
0082 /**
0083  * @short The object that observes the document and feeds the minibars
0084  */
0085 class MiniBarLogic : public QObject, public Okular::DocumentObserver
0086 {
0087     Q_OBJECT
0088 
0089 public:
0090     MiniBarLogic(QObject *parent, Okular::Document *m_document);
0091     ~MiniBarLogic() override;
0092 
0093     void addMiniBar(MiniBar *miniBar);
0094     void removeMiniBar(MiniBar *miniBar);
0095 
0096     Okular::Document *document() const;
0097     int currentPage() const;
0098 
0099     // [INHERITED] from DocumentObserver
0100     void notifySetup(const QVector<Okular::Page *> &pageVector, int setupFlags) override;
0101     void notifyCurrentPageChanged(int previous, int current) override;
0102 
0103 private:
0104     QSet<MiniBar *> m_miniBars;
0105     Okular::Document *m_document;
0106 };
0107 
0108 /**
0109  * @short A widget to display page number and change current page.
0110  */
0111 class MiniBar : public QWidget
0112 {
0113     Q_OBJECT
0114     friend class MiniBarLogic;
0115 
0116 public:
0117     MiniBar(QWidget *parent, MiniBarLogic *miniBarLogic);
0118     ~MiniBar() override;
0119 
0120     void changeEvent(QEvent *event) override;
0121 
0122 Q_SIGNALS:
0123     void gotoPage();
0124     void prevPage();
0125     void nextPage();
0126     void forwardKeyPressEvent(QKeyEvent *e);
0127 
0128 public Q_SLOTS:
0129     void slotChangePageFromReturn();
0130     void slotChangePage(int page);
0131     void slotEmitNextPage();
0132     void slotEmitPrevPage();
0133     void slotToolBarIconSizeChanged();
0134 
0135 private:
0136     void resizeForPage(int pages, const QString &pagesOrLabelString);
0137     bool eventFilter(QObject *target, QEvent *event) override;
0138 
0139     MiniBarLogic *m_miniBarLogic;
0140     PageNumberEdit *m_pageNumberEdit;
0141     PageLabelEdit *m_pageLabelEdit;
0142     QLabel *m_pageNumberLabel;
0143     HoverButton *m_prevButton;
0144     HoverButton *m_pagesButton;
0145     HoverButton *m_nextButton;
0146     QToolBar *m_oldToolbarParent;
0147 };
0148 
0149 /**
0150  * @short A small progress bar.
0151  */
0152 class ProgressWidget : public QWidget, public Okular::DocumentObserver
0153 {
0154     Q_OBJECT
0155 public:
0156     ProgressWidget(QWidget *parent, Okular::Document *document);
0157     ~ProgressWidget() override;
0158 
0159     // [INHERITED] from DocumentObserver
0160     void notifyCurrentPageChanged(int previous, int current) override;
0161 
0162     void slotGotoNormalizedPage(float index);
0163 
0164 Q_SIGNALS:
0165     void prevPage();
0166     void nextPage();
0167 
0168 protected:
0169     void setProgress(float percentage);
0170 
0171     void mouseMoveEvent(QMouseEvent *e) override;
0172     void mousePressEvent(QMouseEvent *e) override;
0173     void wheelEvent(QWheelEvent *e) override;
0174     void paintEvent(QPaintEvent *e) override;
0175 
0176 private:
0177     Okular::Document *m_document;
0178     float m_progressPercentage;
0179 };
0180 
0181 #endif