Subversion Repositories Scribus

Rev

Rev 24048 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7747 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 COLORLISTBOX_H
8
#define COLORLISTBOX_H
9
 
23474 jghali 10
#include <QColor>
21855 jghali 11
#include <QListView>
9874 avox 12
#include <QListWidget>
23474 jghali 13
#include <QPixmap>
10223 cbradney 14
#include <QPointer>
21855 jghali 15
#include <QString>
16
#include <QStringList>
23474 jghali 17
#include <QVariant>
7747 jghali 18
 
21855 jghali 19
#include "colorlistmodel.h"
7747 jghali 20
#include "colorsetmanager.h"
9874 avox 21
#include "commonstrings.h"
21855 jghali 22
#include "sccolor.h"
23
#include "scguardedptr.h"
24
#include "sclistboxpixmap.h"
7747 jghali 25
#include "scribusapi.h"
26
 
27
/*! \brief Very nice list box with color names and samples.
28
It's inherited from QListBox with all its methods and properties.
29
I create it as separate class because it's used now in ColorManager
30
and ColorWheel too. You can see it in Extras/Color Wheel or in
31
Edit/Colors dialogs in action.
32
\author Petr Vanek <petr@yarpen.cz>
33
*/
21855 jghali 34
class SCRIBUS_API ColorListBox : public QListView
7747 jghali 35
{
36
        Q_OBJECT
37
 
38
        public:
39
 
40
                enum PixmapType
41
                {
42
                        smallPixmap,
43
                        widePixmap,
44
                        fancyPixmap
45
                };
46
 
47
                /*! \brief Standard QListBox like constructor.
48
                Just there are initialized pixmaps for icon drawing. */
23880 craig 49
                ColorListBox(QWidget* parent = nullptr);
50
                ColorListBox(ColorListBox::PixmapType type, QWidget* parent = nullptr);
21563 jghali 51
                ~ColorListBox();
21664 jghali 52
 
21855 jghali 53
                /*! Return the current color name */
15662 fschmid 54
                QString currentColor() const;
9874 avox 55
 
21855 jghali 56
                /*! Return the current row */
57
                int currentRow() const;
58
 
59
                /*! Return row count */
60
                int count() const;
61
 
62
                /*! Return model data for the given row and role */
63
                QVariant data(int row, int role) const;
64
 
65
                /*! Finds colors whose name matches the given string name using the given flags. */
66
                QStringList findColors(const QString &name, Qt::MatchFlags flags) const;
67
 
68
                /*! Return if a color is currently selected */
69
                bool hasSelection() const;
70
 
71
                /*! Insert color at specified position */
22603 craig 72
                void insertItem(int row, const ScColor& color, const QString& colorName);
21855 jghali 73
 
74
                /*! Return if none color is shown at beginning oh list */
75
                bool isNoneColorShown() const;
76
 
77
                /*! \brief Retrieve the pixmap type used by this listbox */
78
                ColorListBox::PixmapType pixmapType() const { return m_type; }
79
 
7747 jghali 80
                /*! \brief Fill the list box with values taken from list.
81
                The list is cleared itself. Then is rendered an icon with
82
                color attributes (RGB/CMYK/Spot etc.).
21664 jghali 83
                \param list a ColorList to present. */
84
                void updateBox(ColorList& list);
7747 jghali 85
 
21855 jghali 86
                /*! Remove list item at specified index */
87
                void removeItem(int i);
88
 
89
                /*! Find row index for specified colorname */
22603 craig 90
                int row(const QString& colorName);
21855 jghali 91
 
7850 jghali 92
                /*! \brief Fill the list box with values taken from list.
21855 jghali 93
                The list is cleared itself. Then is rendered an icon with
94
                color attributes (RGB/CMYK/Spot etc.).
21664 jghali 95
                \param list a ColorList to present. */
21855 jghali 96
                void setColors(ColorList& list, bool insertNone);
7850 jghali 97
 
21855 jghali 98
                /*! \brief Set the current color */
99
                void setCurrentColor(QString colorName);
13047 fschmid 100
 
21855 jghali 101
                /*! \brief Set the current row */
102
                void setCurrentRow(int row);
7747 jghali 103
 
21664 jghali 104
                /*! \brief Set the pixmap type used by this listbox */
105
                void setPixmapType(ColorListBox::PixmapType type);
21855 jghali 106
 
107
                //! Set if None color is shown as first item in the list
108
                void setShowNoneColor(bool showNone);
109
 
110
                /*! \brief Return text displayed at specified row */
24736 jghali 111
                QString text(int row) const;
9874 avox 112
 
9575 fschmid 113
                /*! \brief Pointer to the color list displayed by this box */
24736 jghali 114
                ColorList* cList { nullptr };
21855 jghali 115
 
116
        public slots:
117
                void clear();
118
 
15662 fschmid 119
        private slots:
120
                void slotRightClick();
21855 jghali 121
 
16861 jghali 122
        protected slots:
21855 jghali 123
                void emitCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
124
                void emitItemClicked(const QModelIndex &current);
125
                void emitItemDoubleClicked(const QModelIndex &current);
23474 jghali 126
 
127
                virtual void iconSetChange();
16861 jghali 128
                virtual void languageChange();
21855 jghali 129
 
15662 fschmid 130
        signals:
21855 jghali 131
                void currentRowChanged(int currentRow);
132
                void currentTextChanged(const QString &currentText);
21837 jghali 133
                void contextMenuRequested();
21855 jghali 134
                void itemClicked(int currentRow);
135
                void itemDoubleClicked(int currentRow);
136
                void itemSelectionChanged();
137
 
15662 fschmid 138
        protected:
24048 jghali 139
                void changeEvent(QEvent *e) override;
140
                bool viewportEvent(QEvent *event) override;
141
 
15695 fschmid 142
                static int initialized;
143
                static int sortRule;
15662 fschmid 144
                ColorListBox::PixmapType m_type;
7747 jghali 145
};
146
 
147
#endif