~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/kcmkwin/kwindecoration/buttons.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This is the new kwindecoration kcontrol module
 
3
 
 
4
    Copyright (c) 2009, Urs Wolfer <uwolfer @ kde.org>
 
5
    Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
 
6
    Copyright (c) 2001
 
7
        Karol Szwed <gallium@kde.org>
 
8
        http://gallium.n3.net/
 
9
 
 
10
    Supports new kwin configuration plugins, and titlebar button position
 
11
    modification via dnd interface.
 
12
 
 
13
    Based on original "kwintheme" (Window Borders)
 
14
    Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
 
15
 
 
16
    This program is free software; you can redistribute it and/or modify
 
17
    it under the terms of the GNU General Public License as published by
 
18
    the Free Software Foundation; either version 2 of the License, or
 
19
    (at your option) any later version.
 
20
 
 
21
    This program is distributed in the hope that it will be useful,
 
22
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
    GNU General Public License for more details.
 
25
 
 
26
    You should have received a copy of the GNU General Public License
 
27
    along with this program; if not, write to the Free Software
 
28
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
29
 
 
30
*/
 
31
 
 
32
#ifndef BUTTONS_H
 
33
#define BUTTONS_H
 
34
 
 
35
#include <QBitmap>
 
36
#include <QListWidget>
 
37
#include <QMimeData>
 
38
 
 
39
class KDecorationFactory;
 
40
 
 
41
namespace KWin
 
42
{
 
43
 
 
44
/**
 
45
 * This class holds the button data.
 
46
 */
 
47
class Button
 
48
{
 
49
public:
 
50
    Button();
 
51
    Button(const QString& name, const QBitmap& icon, QChar type, bool duplicate, bool supported);
 
52
    virtual ~Button();
 
53
 
 
54
    QString name;
 
55
    QBitmap icon;
 
56
    QChar type;
 
57
    bool duplicate;
 
58
    bool supported;
 
59
};
 
60
 
 
61
class ButtonDrag : public QMimeData
 
62
{
 
63
public:
 
64
    ButtonDrag(Button btn);
 
65
    ~ButtonDrag() {}
 
66
 
 
67
    static bool canDecode(QDropEvent* e);
 
68
    static bool decode(QDropEvent* e, Button& btn);
 
69
};
 
70
 
 
71
/**
 
72
 * This is plugged into ButtonDropSite
 
73
 */
 
74
class ButtonDropSiteItem
 
75
{
 
76
public:
 
77
    ButtonDropSiteItem(const Button& btn);
 
78
    ~ButtonDropSiteItem();
 
79
 
 
80
    Button button();
 
81
 
 
82
    QRect rect;
 
83
    int width();
 
84
    int height();
 
85
 
 
86
    void draw(QPainter *p, const QPalette& cg, const QRect &rect);
 
87
 
 
88
private:
 
89
    Button m_button;
 
90
};
 
91
 
 
92
/**
 
93
 * This is plugged into ButtonSource
 
94
 */
 
95
class ButtonSourceItem : public QListWidgetItem
 
96
{
 
97
public:
 
98
    ButtonSourceItem(QListWidget * parent, const Button& btn);
 
99
    virtual ~ButtonSourceItem();
 
100
 
 
101
    void setButton(const Button& btn);
 
102
    Button button() const;
 
103
private:
 
104
    Button m_button;
 
105
};
 
106
 
 
107
/**
 
108
 * Implements the button drag source list view
 
109
 */
 
110
class ButtonSource : public QListWidget
 
111
{
 
112
    Q_OBJECT
 
113
 
 
114
public:
 
115
    ButtonSource(QWidget *parent = 0);
 
116
    virtual ~ButtonSource();
 
117
 
 
118
    QSize sizeHint() const;
 
119
 
 
120
    void hideAllButtons();
 
121
    void showAllButtons();
 
122
 
 
123
    void dragMoveEvent(QDragMoveEvent *e);
 
124
    void dragEnterEvent(QDragEnterEvent *e);
 
125
    void dropEvent(QDropEvent *e);
 
126
    void mousePressEvent(QMouseEvent *e);
 
127
 
 
128
signals:
 
129
    void dropped();
 
130
 
 
131
public slots:
 
132
    void hideButton(QChar btn);
 
133
    void showButton(QChar btn);
 
134
};
 
135
 
 
136
typedef QList<ButtonDropSiteItem*> ButtonList;
 
137
 
 
138
/**
 
139
 * This class renders and handles the demo titlebar dropsite
 
140
 */
 
141
class ButtonDropSite: public QFrame
 
142
{
 
143
    Q_OBJECT
 
144
 
 
145
public:
 
146
    explicit ButtonDropSite(QWidget* parent = 0);
 
147
    ~ButtonDropSite();
 
148
 
 
149
    // Allow external classes access our buttons - ensure buttons are
 
150
    // not duplicated however.
 
151
    ButtonList buttonsLeft;
 
152
    ButtonList buttonsRight;
 
153
    void clearLeft();
 
154
    void clearRight();
 
155
 
 
156
    void resizeEvent(QResizeEvent* e);
 
157
    void dragEnterEvent(QDragEnterEvent* e);
 
158
    void dragMoveEvent(QDragMoveEvent* e);
 
159
    void dragLeaveEvent(QDragLeaveEvent* e);
 
160
    void dropEvent(QDropEvent* e);
 
161
    void mousePressEvent(QMouseEvent* e); ///< Starts dragging a button...
 
162
    void paintEvent(QPaintEvent* p);
 
163
 
 
164
signals:
 
165
    void buttonAdded(QChar btn);
 
166
    void buttonRemoved(QChar btn);
 
167
    void changed();
 
168
 
 
169
public slots:
 
170
    bool removeSelectedButton(); ///< This slot is called after we drop on the item listbox...
 
171
    void recalcItemGeometry(); ///< Call this whenever the item list changes... updates the items' rect property
 
172
 
 
173
protected:
 
174
    ButtonDropSiteItem *buttonAt(QPoint p);
 
175
    bool removeButton(ButtonDropSiteItem *item);
 
176
    int calcButtonListWidth(const ButtonList& buttons); ///< Computes the total space the buttons will take in the titlebar
 
177
    void drawButtonList(QPainter *p, const ButtonList& buttons, int offset);
 
178
 
 
179
    QRect leftDropArea();
 
180
    QRect rightDropArea();
 
181
 
 
182
private:
 
183
    /**
 
184
     * Try to find the item. If found, set its list and index and return true, else return false
 
185
     */
 
186
    bool getItemPos(ButtonDropSiteItem *item, ButtonList* &list, int &pos);
 
187
 
 
188
    void cleanDropVisualizer();
 
189
    QRect m_oldDropVisualizer;
 
190
 
 
191
    ButtonDropSiteItem *m_selected;
 
192
};
 
193
 
 
194
class ButtonPositionWidget : public QWidget
 
195
{
 
196
    Q_OBJECT
 
197
 
 
198
public:
 
199
    explicit ButtonPositionWidget(QWidget *parent = 0);
 
200
    ~ButtonPositionWidget();
 
201
 
 
202
    QString buttonsLeft() const;
 
203
    QString buttonsRight() const;
 
204
    void setButtonsLeft(const QString &buttons);
 
205
    void setButtonsRight(const QString &buttons);
 
206
 
 
207
signals:
 
208
    void changed();
 
209
 
 
210
private:
 
211
    void clearButtonList(const ButtonList& btns);
 
212
    Button getButton(QChar type, bool& success);
 
213
 
 
214
    ButtonDropSite* m_dropSite;
 
215
    ButtonSource *m_buttonSource;
 
216
 
 
217
    KDecorationFactory *m_factory;
 
218
    QString m_supportedButtons;
 
219
};
 
220
 
 
221
} // namespace KWin
 
222
 
 
223
#endif
 
224
// vim: ts=4
 
225
// kate: space-indent off; tab-width 4;