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

0001 /*
0002     SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ANNOTATIONPOPUP_H
0008 #define ANNOTATIONPOPUP_H
0009 
0010 #include <QList>
0011 #include <QObject>
0012 #include <QPair>
0013 #include <QPoint>
0014 
0015 class QMenu;
0016 
0017 namespace Okular
0018 {
0019 class Annotation;
0020 class Document;
0021 }
0022 
0023 class AnnotationPopup : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     /**
0029      * Describes the structure of the popup menu.
0030      */
0031     enum MenuMode {
0032         SingleAnnotationMode, ///< The menu shows only entries to manipulate a single annotation, or multiple annotations as a group.
0033         MultiAnnotationMode   ///< The menu shows entries to manipulate multiple annotations.
0034     };
0035 
0036     AnnotationPopup(Okular::Document *document, MenuMode mode, QWidget *parent = nullptr);
0037 
0038     void addAnnotation(Okular::Annotation *annotation, int pageNumber);
0039 
0040     /* You only need to use this if you don't plan on using exec() */
0041     void addActionsToMenu(QMenu *menu);
0042 
0043     void exec(const QPoint point = QPoint());
0044 
0045 Q_SIGNALS:
0046     void openAnnotationWindow(Okular::Annotation *annotation, int pageNumber);
0047 
0048 public:
0049     struct AnnotPagePair {
0050         AnnotPagePair()
0051             : annotation(nullptr)
0052             , pageNumber(-1)
0053         {
0054         }
0055 
0056         AnnotPagePair(Okular::Annotation *a, int pn)
0057             : annotation(a)
0058             , pageNumber(pn)
0059         {
0060         }
0061 
0062         bool operator==(const AnnotPagePair pair) const
0063         {
0064             return annotation == pair.annotation && pageNumber == pair.pageNumber;
0065         }
0066 
0067         Okular::Annotation *annotation;
0068         int pageNumber;
0069     };
0070 
0071 private:
0072     void doCopyAnnotation(AnnotPagePair pair);
0073     void doRemovePageAnnotation(AnnotPagePair pair);
0074     void doOpenAnnotationWindow(AnnotPagePair pair);
0075     void doOpenPropertiesDialog(AnnotPagePair pair);
0076     void doSaveEmbeddedFile(AnnotPagePair pair);
0077 
0078     QWidget *mParent;
0079 
0080     QList<AnnotPagePair> mAnnotations;
0081     Okular::Document *mDocument;
0082     MenuMode mMenuMode;
0083 };
0084 
0085 #endif