File indexing completed on 2024-05-26 16:14:37
0001 /* 0002 Copyright (c) 2006 Gábor Lehel <illissius@gmail.com> 0003 Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KO_DOCUMENT_SECTION_MODEL_H 0022 #define KO_DOCUMENT_SECTION_MODEL_H 0023 0024 #include <QAbstractItemModel> 0025 #include <QIcon> 0026 #include <QList> 0027 #include <QString> 0028 #include <QVariant> 0029 0030 /** 0031 * Model class for use with KoDocumentSectionView. The document 0032 * sections that an application uses need to inherit from this class 0033 * to be displayable in the KoDocumentSectionView. That would be, 0034 * for instance, pages in Words or Stage, layers in Karbon, 0035 * sheets in Calligra Sheets. 0036 * 0037 * The KoDocumentSectionView will display a thumbnail and a row of 0038 * icon properties for every document section. 0039 * 0040 * KoDocumentSectionModel is separate from the flake hierarchy: 0041 * documents sections are things like layers, sheets or pages, i.e., a 0042 * shape can cover more than one section, and a section can contain 0043 * many shapes or part of shapes.) 0044 * 0045 * See also the Qt documentation for QAbstractItemModel. This class 0046 * only extends that interface to provide a name and set of toggle 0047 * properties (like visible, locked, selected -- let your imagination 0048 * run riot). 0049 * 0050 * See for an example implementation KisLayer. 0051 * 0052 * Your class also needs to implement the following pure abstract 0053 * virtuals from QAbstractItemModel: 0054 @code 0055 0056 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; 0057 0058 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; 0059 0060 virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 0061 0062 virtual QModelIndex parent(const QModelIndex &index) const; 0063 0064 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 0065 0066 virtual Qt::ItemFlags flags(const QModelIndex &index) const; 0067 0068 virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 0069 @endcode 0070 0071 */ 0072 class KoDocumentSectionModel: public QAbstractItemModel 0073 { 0074 public: 0075 0076 explicit KoDocumentSectionModel(QObject *parent = 0) : QAbstractItemModel(parent) {} 0077 0078 /// Extensions to Qt::ItemDataRole. 0079 enum ItemDataRole 0080 { 0081 /// Whether the section is the active one 0082 ActiveRole = Qt::UserRole + 1, 0083 0084 /// A list of properties the part has. 0085 PropertiesRole, 0086 0087 /// The aspect ratio of the section as a floating point value: width divided by height. 0088 AspectRatioRole, 0089 0090 /// Use to communicate a progress report to the section delegate on an action (a value of -1 or a QVariant() disable the progress bar 0091 ProgressRole, 0092 0093 /// Special activation role which is emitted when the user Atl-clicks on a section 0094 /// The item is first activated with ActiveRole, then a separate AlternateActiveRole comes 0095 AlternateActiveRole, 0096 0097 /// This is to ensure that we can extend the data role in the future, since it's not possible to add a role after BeginThumbnailRole (due to "Hack") 0098 ReservedRole = Qt::UserRole + 99, 0099 0100 /** 0101 * For values of BeginThumbnailRole or higher, a thumbnail of the layer of which neither dimension 0102 * is larger than (int) value - (int) BeginThumbnailRole. 0103 * This is a hack to work around the fact that Interview doesn't have a nice way to 0104 * request thumbnails of arbitrary size. 0105 */ 0106 BeginThumbnailRole 0107 0108 }; 0109 0110 /** 0111 * describes a single property of a document section 0112 * 0113 * FIXME: using a QList instead of QMap and not having an untranslated identifier, 0114 * either enum or string, forces applications to rely on the order of properties 0115 * or to compare the translated strings. This makes it hard to robustly extend the 0116 * properties of document section items. 0117 */ 0118 struct Property 0119 { 0120 /** i18n-ed name, suitable for displaying */ 0121 QString name; 0122 0123 /** Whether the property is a boolean (e.g. locked, visible) which can be toggled directly from the widget itself. */ 0124 bool isMutable; 0125 0126 /** Provide these if the property isMutable. */ 0127 QIcon onIcon; 0128 QIcon offIcon; 0129 0130 /** If the property isMutable, provide a boolean. Otherwise, a string suitable for displaying. */ 0131 QVariant state; 0132 0133 /** If the property is mutable, specifies whether it can be put into stasis. When a property 0134 is in stasis, a new state is created, and the old one is stored in stateInStasis. When 0135 stasis ends, the old value is restored and the new one discarded */ 0136 bool canHaveStasis; 0137 0138 /** If the property isMutable and canHaveStasis, indicate whether it is in stasis or not */ 0139 bool isInStasis; 0140 0141 /** If the property isMutable and canHaveStasis, provide this value to store the property's 0142 state while in stasis */ 0143 bool stateInStasis; 0144 0145 /// Default constructor. Use if you want to assign the members manually. 0146 Property(): isMutable( false ) { } 0147 0148 /// Constructor for a mutable property. 0149 Property( const QString &n, const QIcon &on, const QIcon &off, bool isOn ) 0150 : name( n ), isMutable( true ), onIcon( on ), offIcon( off ), state( isOn ), canHaveStasis( false ) { } 0151 0152 /** Constructor for a mutable property accepting stasis */ 0153 Property( const QString &n, const QIcon &on, const QIcon &off, bool isOn, 0154 bool isInStasis, bool stateInStasis ) 0155 : name( n ), isMutable( true ), onIcon( on ), offIcon( off ), state( isOn ), 0156 canHaveStasis( true ), isInStasis( isInStasis ), stateInStasis( stateInStasis ) { } 0157 0158 /// Constructor for a nonmutable property. 0159 Property( const QString &n, const QString &s ) 0160 : name( n ), isMutable( false ), state( s ) { } 0161 }; 0162 0163 /** Return this type for PropertiesRole. */ 0164 typedef QList<Property> PropertyList; 0165 }; 0166 0167 Q_DECLARE_METATYPE( KoDocumentSectionModel::PropertyList ) 0168 0169 #endif