add more spacing
[personal-kdebase.git] / workspace / kwin / kcmkwin / kwindecoration / buttons.h
blob05411ad4d6bddc7a712eb2319e7d8479fc95ac0c
1 /*
2 This is the new kwindecoration kcontrol module
4 Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
5 Copyright (c) 2001
6 Karol Szwed <gallium@kde.org>
7 http://gallium.n3.net/
9 Supports new kwin configuration plugins, and titlebar button position
10 modification via dnd interface.
12 Based on original "kwintheme" (Window Borders)
13 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #ifndef __BUTTONS_H_
32 #define __BUTTONS_H_
34 #include <QBitmap>
35 #include <QEvent>
36 #include <q3dragobject.h>
37 #include <q3listbox.h>
38 //Added by qt3to4:
39 #include <QDragLeaveEvent>
40 #include <QDragMoveEvent>
41 #include <QFrame>
42 #include <QDropEvent>
43 #include <QList>
44 #include <QResizeEvent>
45 #include <QDragEnterEvent>
46 #include <QMouseEvent>
48 #include <k3listview.h>
50 class KDecorationFactory;
52 /**
53 * This class holds the button data.
55 class Button
57 public:
58 Button();
59 Button(const QString& name, const QBitmap& icon, QChar type, bool duplicate, bool supported);
60 virtual ~Button();
62 QString name;
63 QBitmap icon;
64 QChar type;
65 bool duplicate;
66 bool supported;
69 class ButtonDrag : public Q3StoredDrag
71 public:
72 ButtonDrag( Button btn, QWidget* parent, const char* name=0 );
73 ~ButtonDrag() {}
75 static bool canDecode( QDropEvent* e );
76 static bool decode( QDropEvent* e, Button& btn );
79 /**
80 * This is plugged into ButtonDropSite
82 class ButtonDropSiteItem
84 public:
85 ButtonDropSiteItem(const Button& btn);
86 ~ButtonDropSiteItem();
88 Button button();
90 QRect rect;
91 int width();
92 int height();
94 void draw(QPainter *p, const QPalette& cg, const QRect &rect);
96 private:
97 Button m_button;
101 * This is plugged into ButtonSource
103 class ButtonSourceItem : public Q3ListViewItem
105 public:
106 ButtonSourceItem(Q3ListView * parent, const Button& btn);
107 virtual ~ButtonSourceItem();
109 void paintCell(QPainter *p, const QPalette &cg, int column, int width, int align);
111 void setButton(const Button& btn);
112 Button button() const;
113 private:
114 Button m_button;
115 bool m_dirty;
119 * Implements the button drag source list view
121 class ButtonSource : public K3ListView
123 Q_OBJECT
125 public:
126 ButtonSource(QWidget *parent = 0);
127 virtual ~ButtonSource();
129 QSize sizeHint() const;
131 void hideAllButtons();
132 void showAllButtons();
134 public slots:
135 void hideButton(QChar btn);
136 void showButton(QChar btn);
138 protected:
139 bool acceptDrag(QDropEvent* e) const;
140 virtual Q3DragObject *dragObject();
143 typedef QList<ButtonDropSiteItem*> ButtonList;
146 * This class renders and handles the demo titlebar dropsite
148 class ButtonDropSite: public QFrame
150 Q_OBJECT
152 public:
153 explicit ButtonDropSite( QWidget* parent=0, const char* name=0 );
154 ~ButtonDropSite();
156 // Allow external classes access our buttons - ensure buttons are
157 // not duplicated however.
158 ButtonList buttonsLeft;
159 ButtonList buttonsRight;
160 void clearLeft();
161 void clearRight();
163 signals:
164 void buttonAdded(QChar btn);
165 void buttonRemoved(QChar btn);
166 void changed();
168 public slots:
169 bool removeSelectedButton(); ///< This slot is called after we drop on the item listbox...
170 void recalcItemGeometry(); ///< Call this whenever the item list changes... updates the items' rect property
172 protected:
173 void resizeEvent(QResizeEvent*);
174 void dragEnterEvent( QDragEnterEvent* e );
175 void dragMoveEvent( QDragMoveEvent* e );
176 void dragLeaveEvent( QDragLeaveEvent* e );
177 void dropEvent( QDropEvent* e );
178 void mousePressEvent( QMouseEvent* e ); ///< Starts dragging a button...
180 void paintEvent( QPaintEvent* p );
181 ButtonDropSiteItem *buttonAt(QPoint p);
182 bool removeButton(ButtonDropSiteItem *item);
183 int calcButtonListWidth(const ButtonList& buttons); ///< Computes the total space the buttons will take in the titlebar
184 void drawButtonList(QPainter *p, const ButtonList& buttons, int offset);
186 QRect leftDropArea();
187 QRect rightDropArea();
189 private:
191 * Try to find the item. If found, set its list and index and return true, else return false
193 bool getItemPos(ButtonDropSiteItem *item, ButtonList* &list, int &pos);
195 void cleanDropVisualizer();
196 QRect m_oldDropVisualizer;
198 ButtonDropSiteItem *m_selected;
201 class ButtonPositionWidget : public QWidget
203 Q_OBJECT
205 public:
206 explicit ButtonPositionWidget(QWidget *parent = 0, const char* name = 0);
207 ~ButtonPositionWidget();
210 * set the factory, so the class e.g. knows which buttons are supported by the client
212 void setDecorationFactory(KDecorationFactory *factory);
214 QString buttonsLeft() const;
215 QString buttonsRight() const;
216 void setButtonsLeft(const QString &buttons);
217 void setButtonsRight(const QString &buttons);
219 signals:
220 void changed();
222 private:
223 void clearButtonList(const ButtonList& btns);
224 Button getButton(QChar type, bool& success);
226 ButtonDropSite* m_dropSite;
227 ButtonSource *m_buttonSource;
229 KDecorationFactory *m_factory;
230 QString m_supportedButtons;
234 #endif
235 // vim: ts=4
236 // kate: space-indent off; tab-width 4;