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

0001 /*
0002     SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef _OKULAR_PRESENTATIONWIDGET_H_
0008 #define _OKULAR_PRESENTATIONWIDGET_H_
0009 
0010 #include "core/area.h"
0011 #include "core/observer.h"
0012 #include "core/pagetransition.h"
0013 #include <QDomElement>
0014 #include <QList>
0015 #include <QPixmap>
0016 #include <QStringList>
0017 #include <qwidget.h>
0018 
0019 class QLineEdit;
0020 class QToolBar;
0021 class QTimer;
0022 class QGestureEvent;
0023 class KActionCollection;
0024 class KSelectAction;
0025 class SmoothPathEngine;
0026 struct PresentationFrame;
0027 class PresentationSearchBar;
0028 class DrawingToolActions;
0029 
0030 namespace Okular
0031 {
0032 class Action;
0033 class Annotation;
0034 class Document;
0035 class MovieAction;
0036 class Page;
0037 class RenditionAction;
0038 }
0039 
0040 /**
0041  * @short A widget that shows pages as fullscreen slides (with transitions fx).
0042  *
0043  * This is a fullscreen widget that displays
0044  */
0045 class PresentationWidget : public QWidget, public Okular::DocumentObserver
0046 {
0047     Q_OBJECT
0048 public:
0049     PresentationWidget(QWidget *parent, Okular::Document *doc, DrawingToolActions *drawingToolActions, KActionCollection *collection);
0050     ~PresentationWidget() override;
0051 
0052     // inherited from DocumentObserver
0053     void notifySetup(const QVector<Okular::Page *> &pages, int setupFlags) override;
0054     void notifyViewportChanged(bool smoothMove) override;
0055     void notifyPageChanged(int pageNumber, int changedFlags) override;
0056     bool canUnloadPixmap(int pageNumber) const override;
0057     void notifyCurrentPageChanged(int previous, int current) override;
0058 
0059 public Q_SLOTS:
0060     void slotFind();
0061 
0062 protected:
0063     // widget events
0064     bool event(QEvent *e) override;
0065     void keyPressEvent(QKeyEvent *e) override;
0066     void wheelEvent(QWheelEvent *e) override;
0067     void mousePressEvent(QMouseEvent *e) override;
0068     void mouseReleaseEvent(QMouseEvent *e) override;
0069     void mouseMoveEvent(QMouseEvent *e) override;
0070     void paintEvent(QPaintEvent *e) override;
0071     void resizeEvent(QResizeEvent *e) override;
0072     void enterEvent(QEnterEvent *e) override;
0073     void leaveEvent(QEvent *e) override;
0074     bool gestureEvent(QGestureEvent *e);
0075 
0076     // Catch TabletEnterProximity and TabletLeaveProximity events from the QApplication
0077     bool eventFilter(QObject *o, QEvent *ev) override;
0078 
0079 private:
0080     const void *getObjectRect(Okular::ObjectRect::ObjectType type, QPointF point, QRect *geometry = nullptr) const;
0081     const Okular::Action *getLink(QPointF point, QRect *geometry = nullptr) const;
0082     const Okular::Annotation *getAnnotation(QPointF point, QRect *geometry = nullptr) const;
0083     void testCursorOnLink(QPointF point);
0084     void overlayClick(const QPoint position);
0085     void changePage(int newPage);
0086     void generatePage(bool disableTransition = false);
0087     void generateIntroPage(QPainter &p);
0088     void generateContentsPage(int page, QPainter &p);
0089     void generateOverlay();
0090     void initTransition(const Okular::PageTransition *transition);
0091     const Okular::PageTransition defaultTransition() const;
0092     const Okular::PageTransition defaultTransition(int) const;
0093     QRect routeMouseDrawingEvent(QMouseEvent *);
0094     void startAutoChangeTimer();
0095     /** @returns Configure -> Presentation -> Preferred screen */
0096     QScreen *defaultScreen() const;
0097     void requestPixmaps();
0098     /** @param newScreen must be valid. */
0099     void setScreen(const QScreen *newScreen);
0100     void inhibitPowerManagement();
0101     void allowPowerManagement();
0102     void showTopBar(bool);
0103     // create actions that interact with this widget
0104     void setupActions();
0105     void setPlayPauseIcon();
0106 
0107     // cache stuff
0108     int m_width;
0109     int m_height;
0110     QPixmap m_lastRenderedPixmap;
0111     QPixmap m_lastRenderedOverlay;
0112     QRect m_overlayGeometry;
0113     const Okular::Action *m_pressedLink;
0114     bool m_handCursor;
0115     SmoothPathEngine *m_drawingEngine;
0116     QRect m_drawingRect;
0117     uint m_screenInhibitCookie;
0118     int m_sleepInhibitFd;
0119 
0120     // transition related
0121     QTimer *m_transitionTimer;
0122     QTimer *m_overlayHideTimer;
0123     QTimer *m_nextPageTimer;
0124     int m_transitionDelay;
0125     int m_transitionMul;
0126     int m_transitionSteps;
0127     QList<QRect> m_transitionRects;
0128     Okular::PageTransition m_currentTransition;
0129     QPixmap m_currentPagePixmap;
0130     QPixmap m_previousPagePixmap;
0131     double m_currentPixmapOpacity;
0132 
0133     // misc stuff
0134     QWidget *m_parentWidget;
0135     Okular::Document *m_document;
0136     QVector<PresentationFrame *> m_frames;
0137     int m_frameIndex;
0138     QStringList m_metaStrings;
0139     QToolBar *m_topBar;
0140     QLineEdit *m_pagesEdit;
0141     PresentationSearchBar *m_searchBar;
0142     KActionCollection *m_ac;
0143     KSelectAction *m_screenSelect;
0144     QDomElement m_currentDrawingToolElement;
0145     bool m_isSetup;
0146     bool m_blockNotifications;
0147     bool m_inBlackScreenMode;
0148     bool m_showSummaryView;
0149     bool m_advanceSlides;
0150     bool m_goToPreviousPageOnRelease;
0151     bool m_goToNextPageOnRelease;
0152 
0153     /** TODO Qt6: Just use QWidget::screen() instead of this. */
0154     static inline QScreen *oldQt_screenOf(const QWidget *widget)
0155     {
0156         return widget->screen();
0157     }
0158 
0159 private Q_SLOTS:
0160     void slotNextPage();
0161     void slotPrevPage();
0162     void slotFirstPage();
0163     void slotLastPage();
0164     void slotHideOverlay();
0165     void slotTransitionStep();
0166     void slotDelayedEvents();
0167     void slotPageChanged();
0168     void clearDrawings();
0169     void chooseScreen(QAction *);
0170     void toggleBlackScreenMode(bool);
0171     void slotProcessMovieAction(const Okular::MovieAction *action);
0172     void slotProcessRenditionAction(const Okular::RenditionAction *action);
0173     void slotTogglePlayPause();
0174     void slotChangeDrawingToolEngine(const QDomElement &element);
0175     void slotAddDrawingToolActions();
0176 };
0177 
0178 #endif