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

0001 /*
0002     SPDX-FileCopyrightText: 2004-2005 Enrico Ros <eros.kde@email.it>
0003 
0004     Work sponsored by the LiMux project of the city of Munich:
0005     SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef _PAGEVIEW_UTILS_H_
0011 #define _PAGEVIEW_UTILS_H_
0012 
0013 #include <QHash>
0014 #include <QIcon>
0015 #include <QRect>
0016 #include <qwidget.h>
0017 
0018 #include "core/area.h"
0019 
0020 class QTimer;
0021 class FormWidgetIface;
0022 class PageView;
0023 class VideoWidget;
0024 
0025 namespace Okular
0026 {
0027 class Movie;
0028 class Page;
0029 }
0030 
0031 /**
0032  * @short PageViewItem represents graphically a page into the PageView.
0033  *
0034  * It has methods for settings Item's geometry and other visual properties such
0035  * as the individual zoom factor.
0036  */
0037 class PageViewItem
0038 {
0039 public:
0040     explicit PageViewItem(const Okular::Page *page);
0041     ~PageViewItem();
0042 
0043     PageViewItem(const PageViewItem &) = delete;
0044     PageViewItem &operator=(const PageViewItem &) = delete;
0045 
0046     const Okular::Page *page() const;
0047     int pageNumber() const;
0048     double zoomFactor() const;
0049     bool isVisible() const;
0050     QSet<FormWidgetIface *> &formWidgets();
0051     QHash<Okular::Movie *, VideoWidget *> &videoWidgets();
0052 
0053     /* The page is cropped as follows: */
0054     const Okular::NormalizedRect &crop() const;
0055 
0056     /* Real geometry into which the cropped page is rendered: */
0057     const QRect &croppedGeometry() const;
0058     int croppedWidth() const;
0059     int croppedHeight() const;
0060 
0061     /* "Uncropped" geometry:
0062      * If the whole page was rendered into the uncropped geometry then the
0063      * cropped page would be rendered into the real geometry.
0064      * (Hence, uncropped always contains cropped, and they are equal only if
0065      * the page is uncropped.) This is just for convenience in calculations.
0066      */
0067     const QRect &uncroppedGeometry() const;
0068     int uncroppedWidth() const;
0069     int uncroppedHeight() const;
0070 
0071     /* Convert absolute geometry coordinates to normalized [0,1] page coordinates: */
0072     double absToPageX(double absX) const;
0073     double absToPageY(double absY) const;
0074 
0075     void setWHZC(int w, int h, double zoom, const Okular::NormalizedRect &c);
0076     void moveTo(int x, int y);
0077     void setVisible(bool visible);
0078     void invalidate();
0079     bool setFormWidgetsVisible(bool visible);
0080     void reloadFormWidgetsState();
0081 
0082 private:
0083     const Okular::Page *m_page;
0084     double m_zoomFactor;
0085     bool m_visible;
0086     bool m_formsVisible;
0087     QRect m_croppedGeometry;
0088     QRect m_uncroppedGeometry;
0089     Okular::NormalizedRect m_crop;
0090     QSet<FormWidgetIface *> m_formWidgets;
0091     QHash<Okular::Movie *, VideoWidget *> m_videoWidgets;
0092 };
0093 
0094 /**
0095  * @short A widget that displays messages in the top-left corner.
0096  *
0097  * This is a widget with thin border and rounded corners that displays a given
0098  * text along as an icon. It's meant to be used for displaying messages to the
0099  * user by placing this above other widgets.
0100  */
0101 class PageViewMessage : public QWidget
0102 {
0103     Q_OBJECT
0104 
0105 public:
0106     explicit PageViewMessage(QWidget *parent);
0107 
0108     enum Icon { None, Info, Warning, Error, Find, Annotation };
0109     void display(const QString &message, const QString &details = QString(), Icon icon = Info, int durationMs = 4000);
0110 
0111 protected:
0112     bool eventFilter(QObject *obj, QEvent *event) override;
0113     void paintEvent(QPaintEvent *e) override;
0114     void mousePressEvent(QMouseEvent *e) override;
0115 
0116 private:
0117     QRect computeTextRect(const QString &message, int extra_width) const;
0118     void computeSizeAndResize();
0119     QString m_message;
0120     QString m_details;
0121     QIcon m_symbol;
0122     QTimer *m_timer;
0123     int m_lineSpacing;
0124 };
0125 
0126 #endif