1 | /* poppler-optcontent-private.h: qt interface to poppler |
2 | * |
3 | * Copyright (C) 2007, Brad Hards <bradh@kde.org> |
4 | * Copyright (C) 2008, Pino Toscano <pino@kde.org> |
5 | * Copyright (C) 2016, 2018, 2019, 2021, Albert Astals Cid <aacid@kde.org> |
6 | * Copyright (C) 2017, Hubert Figuière <hub@figuiere.net> |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2, or (at your option) |
11 | * any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
20 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #ifndef POPPLER_OPTCONTENT_PRIVATE_H |
24 | #define POPPLER_OPTCONTENT_PRIVATE_H |
25 | |
26 | #include <QtCore/QMap> |
27 | #include <QtCore/QSet> |
28 | #include <QtCore/QString> |
29 | |
30 | class Array; |
31 | class OCGs; |
32 | class OptionalContentGroup; |
33 | |
34 | class QModelIndex; |
35 | |
36 | namespace Poppler { |
37 | class OptContentItem; |
38 | class OptContentModel; |
39 | class OptContentModelPrivate; |
40 | |
41 | class RadioButtonGroup |
42 | { |
43 | public: |
44 | RadioButtonGroup(OptContentModelPrivate *ocModel, Array *rbarray); |
45 | ~RadioButtonGroup(); |
46 | QSet<OptContentItem *> setItemOn(OptContentItem *itemToSetOn); |
47 | |
48 | private: |
49 | QList<OptContentItem *> itemsInGroup; |
50 | }; |
51 | |
52 | class OptContentItem |
53 | { |
54 | public: |
55 | enum ItemState |
56 | { |
57 | On, |
58 | Off, |
59 | HeadingOnly |
60 | }; |
61 | |
62 | explicit OptContentItem(OptionalContentGroup *group); |
63 | explicit OptContentItem(const QString &label); |
64 | OptContentItem(); |
65 | ~OptContentItem(); |
66 | |
67 | QString name() const { return m_name; } |
68 | ItemState state() const { return m_stateBackup; } |
69 | void setState(ItemState state, bool obeyRadioGroups, QSet<OptContentItem *> &changedItems); |
70 | |
71 | QList<OptContentItem *> childList() { return m_children; } |
72 | |
73 | void setParent(OptContentItem *parent) { m_parent = parent; } |
74 | OptContentItem *parent() { return m_parent; } |
75 | |
76 | void addChild(OptContentItem *child); |
77 | |
78 | void appendRBGroup(RadioButtonGroup *rbgroup); |
79 | |
80 | bool isEnabled() const { return m_enabled; } |
81 | |
82 | QSet<OptContentItem *> recurseListChildren(bool includeMe = false) const; |
83 | |
84 | OptionalContentGroup *group() const { return m_group; } |
85 | |
86 | private: |
87 | OptionalContentGroup *m_group; |
88 | QString m_name; |
89 | ItemState m_state; // true for ON, false for OFF |
90 | ItemState m_stateBackup; |
91 | QList<OptContentItem *> m_children; |
92 | OptContentItem *m_parent; |
93 | QList<RadioButtonGroup *> m_rbGroups; |
94 | bool m_enabled; |
95 | }; |
96 | |
97 | class OptContentModelPrivate |
98 | { |
99 | public: |
100 | OptContentModelPrivate(OptContentModel *qq, OCGs *optContent); |
101 | ~OptContentModelPrivate(); |
102 | |
103 | OptContentModelPrivate(const OptContentModelPrivate &) = delete; |
104 | OptContentModelPrivate &operator=(const OptContentModelPrivate &) = delete; |
105 | |
106 | void parseRBGroupsArray(Array *rBGroupArray); |
107 | OptContentItem *nodeFromIndex(const QModelIndex &index, bool canBeNull = false) const; |
108 | QModelIndex indexFromItem(OptContentItem *node, int column) const; |
109 | |
110 | /** |
111 | Get the OptContentItem corresponding to a given reference value. |
112 | |
113 | \param ref the reference number (e.g. from Object.getRefNum()) to look up |
114 | |
115 | \return the matching optional content item, or null if the reference wasn't found |
116 | */ |
117 | OptContentItem *itemFromRef(const QString &ref) const; |
118 | void setRootNode(OptContentItem *node); |
119 | |
120 | OptContentModel *q; |
121 | |
122 | QMap<QString, OptContentItem *> m_optContentItems; |
123 | QList<OptContentItem *> ; |
124 | QList<RadioButtonGroup *> m_rbgroups; |
125 | OptContentItem *m_rootNode; |
126 | |
127 | private: |
128 | void addChild(OptContentItem *parent, OptContentItem *child); |
129 | void parseOrderArray(OptContentItem *parentNode, Array *orderArray); |
130 | }; |
131 | } |
132 | |
133 | #endif |
134 | |