1 /* This file is part of the KDE project
2  * Copyright (C) 2012 Pierre Stirnweiss <pstirnweiss@googlemail.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef ABSTRACTSTYLESMODEL_H
21 #define ABSTRACTSTYLESMODEL_H
22 
23 #include <QAbstractItemModel>
24 #include <QSize>
25 
26 class KoStyleThumbnailer;
27 
28 class KoCharacterStyle;
29 
30 class QImage;
31 
32 /** This class is used to provide widgets (like the @class StylesCombo) the styles available to the document being worked on.
33  *
34  * This is an abstract class supposed to be inherited only. DO NOT instantiate this class directly.
35  *
36  * On top of the standard QAbstractItemModel methods to re-implement, there are 3 specific methods which need to be re-implemented in order to be used with the styles widgets:
37  * - setStyleThumbnailer: a @class KoStyleThumbnailer is used to layout/draw a preview of the style
38  * - indexOf: for a given character or paragraph style, returns the corresponding QModelIndex
39  * - stylePreview: returns a QImage, preview of the given style (given as row number in the list model)
40  *
41  * Following assumptions are made:
42  * - the AbstractStylesModel derived model is a flat list of items (this also means that "parent" QModelIndexes are always invalid)
43  * - the AbstractStylesModel derived model has only one column
44  * - there is no header in the AbstractStylesModel derived model
45 */
46 
47 class AbstractStylesModel : public QAbstractItemModel
48 {
49     Q_OBJECT
50 public:
51     enum Type {
52         CharacterStyle,
53         ParagraphStyle
54     };
55 
56     enum AdditionalRoles {
57         CharacterStylePointer = Qt::UserRole + 1,
58         ParagraphStylePointer,
59         isModifiedStyle,
60         isTitleRole,
61         TitleString
62     };
63 
64     explicit AbstractStylesModel(QObject *parent = 0);
65 
66     /** Re-implement from QAbstractItemModel.
67      *
68      * No methods are reimplemented there. Subclasses need to reimplement all of QAbstractItemModel's virtual methods.
69      *
70      */
71 
72     /** Specific methods of the AbstractStylesModel */
73 
74     /** Sets the @class KoStyleThumbnailer of the model. It is required that a @param thumbnailer is set before using the model. */
75     virtual void setStyleThumbnailer(KoStyleThumbnailer *thumbnailer) = 0;
76 
77     /** Return a @class QModelIndex for the specified @param style.
78       * @param style may be either a character or paragraph style.
79     */
80     virtual QModelIndex indexOf(const KoCharacterStyle *style) const = 0;
81 
82     /** Returns a QImage which is a preview of the style specified by @param row of the given @param size.
83       * If size isn't specified, the default size of the given @class KoStyleThumbnailer is used.
84     */
85     virtual QImage stylePreview(int row, const QSize &size = QSize()) = 0;
86 //    virtual QImage stylePreview(QModelIndex &index, const QSize &size = QSize()) = 0;
87 
88     /** Returns the type of styles in the model */
89     virtual AbstractStylesModel::Type stylesType() const = 0;
90 
91 protected:
92     KoStyleThumbnailer *m_styleThumbnailer;
93     Type m_modelType;
94 };
95 
96 #endif // ABSTRACTSTYLESMODEL_H
97