Subversion Repositories Scribus

Rev

Rev 24209 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21855 jghali 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
#ifndef COLORLISTMODEL_H
8
#define COLORLISTMODEL_H
9
 
10
#include <QAbstractItemModel>
11
#include <QVector>
12
 
13
#include "sccolor.h"
14
#include "scguardedptr.h"
15
#include "scribusapi.h"
16
 
17
class ScribusDoc;
18
 
19
struct SCRIBUS_API ColorPixmapValue
20
{
21
        ScColor m_color;
22
        ScGuardedPtr<ScribusDoc> m_doc;
23
        QString m_name;
24
 
25
        ColorPixmapValue();
24209 jghali 26
        ColorPixmapValue(const ScColor& col, ScribusDoc* doc, const QString& colName);
21855 jghali 27
        ColorPixmapValue(const ColorPixmapValue& other);
28
        ColorPixmapValue& operator= (const ColorPixmapValue& other);
29
};
30
 
31
Q_DECLARE_METATYPE(ColorPixmapValue)
32
 
33
class SCRIBUS_API ColorListModel : public QAbstractItemModel
34
{
35
        Q_OBJECT
36
 
37
public:
38
        //! Constructor
23880 craig 39
        ColorListModel(QObject* parent = nullptr);
21855 jghali 40
 
41
        enum SortRule
42
        {
43
                SortByName,
44
                SortByValues,
45
                SortByType
46
        };
47
 
48
        //! Returns the color list
49
        const QVector<ColorPixmapValue>& colors() const { return m_colors; }
50
 
51
        //! Returns if None color is shown as first item in the list
52
        bool isNoneColorShown() const { return m_isNoneColorShown; }
53
 
54
        //! Remove all colors from list;
55
        void clear();
56
 
57
        //! Reimplement QAbstractItemModel columnCount()
58
        int columnCount(const QModelIndex &parent = QModelIndex()) const;
59
 
60
        //! Reimplement QAbstractItemModel data()
61
        QVariant data(const QModelIndex &index, int role) const;
62
 
63
        //! Reimplement QAbstractItemModel flags()
64
        Qt::ItemFlags flags(const QModelIndex &index) const;
65
 
66
        //! Reimplement QAbstractItemModel index()
67
        QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
68
 
69
        //! Insert an item in the list at specified position
70
        void insert(int i, const ColorPixmapValue& value);
71
 
72
        //! Reimplement QAbstractItemModel parent()
73
        QModelIndex parent(const QModelIndex &child) const;
74
 
75
        //! Reimplement QAbstractItemModel removeRow()
76
        bool removeRow(int row, const QModelIndex& parent = QModelIndex());
77
 
78
        //! Reimplement QAbstractItemModel removeRowz()
79
        bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
80
 
81
        //! Reimplement QAbstractItemModel rowCount()
82
        int rowCount(const QModelIndex &parent = QModelIndex()) const;
83
 
84
        //! Set color list
85
        void setColorList(const ColorList& colorList);
86
 
87
        //! Set color list and None color option at same time
88
        void setColorList(const ColorList& colorList, bool showNone);
89
 
90
        //! Set if None color is shown as first item in the list
91
        void setShowNoneColor(bool showNone);
92
 
93
        //! Set how colors should be sorted
94
        void setSortRule(SortRule sortRule);
95
 
96
protected:
97
        //! If None color is shown as first item in the list
98
        bool m_isNoneColorShown;
99
 
100
        //! The color list
101
        QVector<ColorPixmapValue> m_colors;
102
 
103
        // SortRule m_sortRule
104
        SortRule m_sortRule;
105
 
106
        static bool compareColorNames(const ColorPixmapValue& v1, const ColorPixmapValue& v2);
107
        static bool compareColorValues(const ColorPixmapValue& v1, const ColorPixmapValue& v2);
108
        static bool compareColorTypes(const ColorPixmapValue& v1, const ColorPixmapValue& v2);
109
};
110
 
111
#endif // COLORLISTMODEL_H