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

0001 /*
0002     SPDX-FileCopyrightText: 2006 Pino Toscano <pino@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef _ANNOTATIONWIDGETS_H_
0008 #define _ANNOTATIONWIDGETS_H_
0009 
0010 #include <qwidget.h>
0011 
0012 #include "core/annotations.h"
0013 
0014 class QCheckBox;
0015 class QComboBox;
0016 class QDoubleSpinBox;
0017 class QFormLayout;
0018 class QLabel;
0019 class QPushButton;
0020 class QWidget;
0021 class KColorButton;
0022 class QSpinBox;
0023 class KFontRequester;
0024 class AnnotationWidget;
0025 
0026 class PixmapPreviewSelector : public QWidget
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     enum PreviewPosition { Side, Below };
0032 
0033     explicit PixmapPreviewSelector(QWidget *parent = nullptr, PreviewPosition position = Side);
0034     ~PixmapPreviewSelector() override;
0035 
0036     void setIcon(const QString &icon);
0037     QString icon() const;
0038 
0039     void addItem(const QString &item, const QString &id);
0040 
0041     void setPreviewSize(int size);
0042     int previewSize() const;
0043 
0044     void setEditable(bool editable);
0045 
0046 Q_SIGNALS:
0047     void iconChanged(const QString &);
0048 
0049 private Q_SLOTS:
0050     void iconComboChanged(const QString &icon);
0051     void selectCustomStamp();
0052 
0053 private:
0054     QString m_icon;
0055     QPushButton *m_stampPushButton;
0056     QLabel *m_iconLabel;
0057     QComboBox *m_comboItems;
0058     int m_previewSize;
0059     PreviewPosition m_previewPosition;
0060 };
0061 
0062 /**
0063  * A factory to create AnnotationWidget's.
0064  */
0065 class AnnotationWidgetFactory
0066 {
0067 public:
0068     static AnnotationWidget *widgetFor(Okular::Annotation *ann);
0069 };
0070 
0071 class AnnotationWidget : public QObject
0072 {
0073     Q_OBJECT
0074 
0075 public:
0076     explicit AnnotationWidget(Okular::Annotation *ann);
0077     ~AnnotationWidget() override;
0078 
0079     virtual Okular::Annotation::SubType annotationType() const;
0080 
0081     QWidget *appearanceWidget();
0082     QWidget *extraWidget();
0083 
0084     virtual void applyChanges();
0085 
0086     void setAnnotTypeEditable(bool);
0087 
0088 Q_SIGNALS:
0089     void dataChanged();
0090 
0091 protected:
0092     QWidget *createAppearanceWidget();
0093 
0094     virtual void createStyleWidget(QFormLayout *formLayout);
0095     virtual QWidget *createExtraWidget();
0096 
0097     void addColorButton(QWidget *widget, QFormLayout *formlayout);
0098     void addOpacitySpinBox(QWidget *widget, QFormLayout *formlayout);
0099     void addVerticalSpacer(QFormLayout *formlayout);
0100 
0101     bool m_typeEditable;
0102 
0103 private:
0104     Okular::Annotation *m_ann;
0105     QWidget *m_appearanceWidget {nullptr};
0106     QWidget *m_extraWidget {nullptr};
0107     KColorButton *m_colorBn {nullptr};
0108     QSpinBox *m_opacity {nullptr};
0109 };
0110 
0111 class QVBoxLayout;
0112 class QFormLayout;
0113 
0114 class TextAnnotationWidget : public AnnotationWidget
0115 {
0116     Q_OBJECT
0117 
0118 public:
0119     explicit TextAnnotationWidget(Okular::Annotation *ann);
0120 
0121     void applyChanges() override;
0122 
0123 protected:
0124     void createStyleWidget(QFormLayout *formlayout) override;
0125 
0126 private:
0127     void createPopupNoteStyleUi(QWidget *widget, QFormLayout *formlayout);
0128     void createInlineNoteStyleUi(QWidget *widget, QFormLayout *formlayout);
0129     void createTypewriterStyleUi(QWidget *widget, QFormLayout *formlayout);
0130     void addPixmapSelector(QWidget *widget, QFormLayout *formlayout);
0131     void addFontRequester(QWidget *widget, QFormLayout *formlayout);
0132     void addTextColorButton(QWidget *widget, QFormLayout *formlayout);
0133     void addTextAlignComboBox(QWidget *widget, QFormLayout *formlayout);
0134     void addWidthSpinBox(QWidget *widget, QFormLayout *formlayout);
0135 
0136     inline bool isTypewriter() const
0137     {
0138         return (m_textAnn->inplaceIntent() == Okular::TextAnnotation::TypeWriter);
0139     }
0140 
0141     Okular::TextAnnotation *m_textAnn;
0142     PixmapPreviewSelector *m_pixmapSelector {nullptr};
0143     KFontRequester *m_fontReq {nullptr};
0144     KColorButton *m_textColorBn {nullptr};
0145     QComboBox *m_textAlign {nullptr};
0146     QDoubleSpinBox *m_spinWidth {nullptr};
0147 };
0148 
0149 class StampAnnotationWidget : public AnnotationWidget
0150 {
0151     Q_OBJECT
0152 
0153 public:
0154     static const QList<QPair<QString, QString>> &defaultStamps();
0155 
0156     explicit StampAnnotationWidget(Okular::Annotation *ann);
0157 
0158     void applyChanges() override;
0159 
0160 protected:
0161     void createStyleWidget(QFormLayout *formlayout) override;
0162 
0163 private:
0164     Okular::StampAnnotation *m_stampAnn;
0165     PixmapPreviewSelector *m_pixmapSelector;
0166 };
0167 
0168 class LineAnnotationWidget : public AnnotationWidget
0169 {
0170     Q_OBJECT
0171 
0172 public:
0173     explicit LineAnnotationWidget(Okular::Annotation *ann);
0174 
0175     void applyChanges() override;
0176 
0177 protected:
0178     void createStyleWidget(QFormLayout *formlayout) override;
0179 
0180 private:
0181     static QIcon endStyleIcon(Okular::LineAnnotation::TermStyle endStyle, const QColor &lineColor);
0182 
0183     Okular::LineAnnotation *m_lineAnn;
0184     int m_lineType;
0185     QDoubleSpinBox *m_spinLL {nullptr};
0186     QDoubleSpinBox *m_spinLLE {nullptr};
0187     QCheckBox *m_useColor {nullptr};
0188     KColorButton *m_innerColor {nullptr};
0189     QDoubleSpinBox *m_spinSize {nullptr};
0190     QComboBox *m_startStyleCombo {nullptr};
0191     QComboBox *m_endStyleCombo {nullptr};
0192 };
0193 
0194 class HighlightAnnotationWidget : public AnnotationWidget
0195 {
0196     Q_OBJECT
0197 
0198 public:
0199     explicit HighlightAnnotationWidget(Okular::Annotation *ann);
0200 
0201     void applyChanges() override;
0202 
0203 protected:
0204     void createStyleWidget(QFormLayout *formlayout) override;
0205 
0206 private:
0207     Okular::HighlightAnnotation *m_hlAnn;
0208     QComboBox *m_typeCombo;
0209 };
0210 
0211 class GeomAnnotationWidget : public AnnotationWidget
0212 {
0213     Q_OBJECT
0214 
0215 public:
0216     explicit GeomAnnotationWidget(Okular::Annotation *ann);
0217 
0218     void applyChanges() override;
0219 
0220 protected:
0221     void createStyleWidget(QFormLayout *formlayout) override;
0222 
0223 private:
0224     Okular::GeomAnnotation *m_geomAnn;
0225     QComboBox *m_typeCombo;
0226     QCheckBox *m_useColor;
0227     KColorButton *m_innerColor;
0228     QDoubleSpinBox *m_spinSize;
0229 };
0230 
0231 class FileAttachmentAnnotationWidget : public AnnotationWidget
0232 {
0233     Q_OBJECT
0234 
0235 public:
0236     explicit FileAttachmentAnnotationWidget(Okular::Annotation *ann);
0237 
0238     void applyChanges() override;
0239 
0240 protected:
0241     void createStyleWidget(QFormLayout *formlayout) override;
0242     QWidget *createExtraWidget() override;
0243 
0244 private:
0245     Okular::FileAttachmentAnnotation *m_attachAnn;
0246     PixmapPreviewSelector *m_pixmapSelector;
0247 };
0248 
0249 class CaretAnnotationWidget : public AnnotationWidget
0250 {
0251     Q_OBJECT
0252 
0253 public:
0254     explicit CaretAnnotationWidget(Okular::Annotation *ann);
0255 
0256     void applyChanges() override;
0257 
0258 protected:
0259     void createStyleWidget(QFormLayout *formlayout) override;
0260 
0261 private:
0262     Okular::CaretAnnotation *m_caretAnn;
0263     PixmapPreviewSelector *m_pixmapSelector;
0264 };
0265 
0266 class InkAnnotationWidget : public AnnotationWidget
0267 {
0268     Q_OBJECT
0269 
0270 public:
0271     explicit InkAnnotationWidget(Okular::Annotation *ann);
0272 
0273     void applyChanges() override;
0274 
0275 protected:
0276     void createStyleWidget(QFormLayout *formlayout) override;
0277 
0278 private:
0279     Okular::InkAnnotation *m_inkAnn;
0280     QDoubleSpinBox *m_spinSize;
0281 };
0282 
0283 #endif