kpColorCells.h 5.64 KB
Newer Older
1 2

/*
3
   Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   1. Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


29 30
#ifndef kpColorCells_H
#define kpColorCells_H
31

32

Christoph Feck's avatar
Christoph Feck committed
33
#include <QUrl>
34

35 36
#include <kpColorCellsBase.h>

37

38
class QDropEvent;
39

40 41
class kpColorCollection;

42
class kpColor;
43

44 45 46 47 48 49 50 51

// This widget consists of rows of 11 cells of colors.  The cells become
// shorter as soon as there are 3 rows.  After that, a vertical scrollbar
// is usually displayed.
//
// By default, it is set to the DefaultColorCollection(), with 2 rows.
//
//
Clarence Dang's avatar
+APIDoc  
Clarence Dang committed
52 53 54 55 56 57 58 59 60 61 62 63
// Cell widgets might not exist for 2 reasons:
//
// 1. The respective colors in the color collection are invalid.
//    An easy way to create this situation is to appendRow().
//
// 2. The number of colors in the color collection is not divisible by
//    the columnCount() [currently fixed at 11], so some cells in the
//    last row might not be linked to colors in the color collection.
//
// Currently, this class always ensures that there is at least one
// visual/table row (which might contain no cell widgets).
//
64 65 66 67 68 69 70 71 72 73
//
// To determine where the color collection came from:
//
// 1. If url() is non-empty, it came from a file.
//
// 2. If url() is empty:
//    a) If name() is non-empty, it came from KDE-managed color collection.
//    b) If name() is empty, it came from DefaultColorCollection().
//
//
Clarence Dang's avatar
Clarence Dang committed
74 75
// See also the API documentation for kpColorCellsBase.
//
76
// TODO: For now, only horizontal orientation is supported.
77
class kpColorCells : public kpColorCellsBase
78 79 80 81
{
Q_OBJECT

public:
82 83 84
    kpColorCells (QWidget *parent,
                  Qt::Orientation o = Qt::Horizontal);
    virtual ~kpColorCells ();
85

86 87
    static kpColorCollection DefaultColorCollection ();

88 89
    Qt::Orientation orientation () const;
    void setOrientation (Qt::Orientation o);
90

91 92 93 94 95
protected:
    void makeCellsMatchColorCollection ();

public:
    bool isModified () const;
96 97 98 99 100
    // (this emits isModifiedChanged() if the modified state changes)
    void setModified (bool yes);
public slots:
    // (this emits isModifiedChanged() if the modified state changes)
    void setModified ();
101

102
public:
103
    // The source URL of the kpColorCollection.  Empty for color
104
    // collections that did not come from files.
Christoph Feck's avatar
Christoph Feck committed
105
    QUrl url () const;
106

107 108
    // The name of the kpColorCollection.  Empty for color collections
    // managed by KDE.
109 110
    QString name () const;

111
    const kpColorCollection *colorCollection () const;
112

113 114 115 116
private:
    // Ensures there's a least one row of cells, to avoid a confusing UI.
    void ensureHaveAtLeastOneRow ();
public:
117
    void setColorCollection (const kpColorCollection &colorCol,
Christoph Feck's avatar
Christoph Feck committed
118
        const QUrl &url = QUrl ());
119

Christoph Feck's avatar
Christoph Feck committed
120 121
    bool openColorCollection (const QUrl &url);
    bool saveColorCollectionAs (const QUrl &url);
122
    bool saveColorCollection ();
123

Clarence Dang's avatar
+APIDoc  
Clarence Dang committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    // These add and delete visual/table rows, independent of whether the number
    // of colors in the color collection is divisible by the columnCount()
    // [currently fixed at 11].
    //
    // For instance, if you only had 15 colors in the color collection, there are
    // visually 2 rows (22 cells in total):
    //
    // 1. appendRow() will add a visual row so that there will be 3 visual rows
    //    (33 cells in total).  (22 - 15) + 11 invalid colors will be added to
    //    the back of the color collection.  Note that invalid colors are not
    //    saved by kpColorCollection, so those new cells not initialized by the
    //    user will not be saved.
    // 2. deleteRow() will delete a visual row so that there will be 1 visual
    //    row (11 cells in total) remaining.  (15 - 11) colors will be deleted
    //    from the back of the color collection.
139 140 141 142
    void appendRow ();
    void deleteLastRow ();

signals:
143 144
    void foregroundColorChanged (const kpColor &color);
    void backgroundColorChanged (const kpColor &color);
145

146 147
    void rowCountChanged (int rowCount);

148
    void nameChanged (const QString &name);
Christoph Feck's avatar
Christoph Feck committed
149
    void urlChanged (const QUrl &url);
150

151 152 153 154 155
    // Emitted when setModified() is called and the modified state changes.
    // It may be called at other times, even when the modified state did
    // not change.
    void isModifiedChanged (bool isModified);

156
protected:
157
    virtual void contextMenuEvent (QContextMenuEvent *e);
158

159
protected slots:
160 161 162
    void slotColorSelected (int cell, const QColor &color, Qt::MouseButton button);
    void slotColorDoubleClicked (int cell, const QColor &color);
    void slotColorChanged (int cell, const QColor &color);
163 164 165

private:
    struct kpColorCellsPrivate * const d;
166 167 168
};


169
#endif  // kpColorCells_H