2 This is the new kwindecoration kcontrol module
4 Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
6 Karol Szwed <gallium@kde.org>
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.
36 #include <q3dragobject.h>
37 #include <q3listbox.h>
39 #include <QDragLeaveEvent>
40 #include <QDragMoveEvent>
44 #include <QResizeEvent>
45 #include <QDragEnterEvent>
46 #include <QMouseEvent>
48 #include <k3listview.h>
50 class KDecorationFactory
;
53 * This class holds the button data.
59 Button(const QString
& name
, const QBitmap
& icon
, QChar type
, bool duplicate
, bool supported
);
69 class ButtonDrag
: public Q3StoredDrag
72 ButtonDrag( Button btn
, QWidget
* parent
, const char* name
=0 );
75 static bool canDecode( QDropEvent
* e
);
76 static bool decode( QDropEvent
* e
, Button
& btn
);
80 * This is plugged into ButtonDropSite
82 class ButtonDropSiteItem
85 ButtonDropSiteItem(const Button
& btn
);
86 ~ButtonDropSiteItem();
94 void draw(QPainter
*p
, const QPalette
& cg
, const QRect
&rect
);
101 * This is plugged into ButtonSource
103 class ButtonSourceItem
: public Q3ListViewItem
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;
119 * Implements the button drag source list view
121 class ButtonSource
: public K3ListView
126 ButtonSource(QWidget
*parent
= 0);
127 virtual ~ButtonSource();
129 QSize
sizeHint() const;
131 void hideAllButtons();
132 void showAllButtons();
135 void hideButton(QChar btn
);
136 void showButton(QChar btn
);
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
153 explicit ButtonDropSite( QWidget
* parent
=0, const char* name
=0 );
156 // Allow external classes access our buttons - ensure buttons are
157 // not duplicated however.
158 ButtonList buttonsLeft
;
159 ButtonList buttonsRight
;
164 void buttonAdded(QChar btn
);
165 void buttonRemoved(QChar btn
);
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
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();
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
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
);
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
;
236 // kate: space-indent off; tab-width 4;