1 /*********************************************************************
5 Customizable button positions by Karol Szwed <gallium@kde.org>
6 Ported to the kde3.2 API by Luciano Montanaro <mikelima@cirulla.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
26 #include <QAbstractButton>
28 #include <QPaintEvent>
29 #include <QGridLayout>
33 #include <QResizeEvent>
34 #include <QMouseEvent>
37 #include <kdecoration.h>
38 #include <kdecorationfactory.h>
48 class B2Button
: public QAbstractButton
51 explicit B2Button(B2Client
*_client
=0, QWidget
*parent
=0, const QString
& tip
=NULL
, const int realizeBtns
= Qt::LeftButton
);
54 void setBg(const QColor
&c
){bg
= c
;}
55 void setPixmaps(QPixmap
*pix
, QPixmap
*pixDown
, QPixmap
*iPix
,
57 void setPixmaps(int button_id
);
58 void setToggle(){setCheckable(true);}
59 void setActive(bool on
){setChecked(on
);}
60 void setUseMiniIcon(){useMiniIcon
= true;}
61 QSize
sizeHint() const;
62 QSizePolicy
sizePolicy() const;
64 virtual void paintEvent(QPaintEvent
*e
);
66 void mousePressEvent( QMouseEvent
* e
);
67 void mouseReleaseEvent( QMouseEvent
* e
);
69 void enterEvent(QEvent
*e
);
70 void leaveEvent(QEvent
*e
);
74 QColor bg
; //only use one color (the rest is pixmap) so forget QPalette ;)
78 Qt::MouseButtons last_button
;
83 class B2Titlebar
: public QWidget
85 friend class B2Client
;
87 B2Titlebar(B2Client
*parent
);
89 bool isFullyObscured() const {return isfullyobscured
;}
91 QSpacerItem
*captionSpacer
;
93 void paintEvent(QPaintEvent
*e
);
94 bool x11Event(XEvent
*e
);
95 void mouseDoubleClickEvent(QMouseEvent
*e
);
96 void mousePressEvent(QMouseEvent
*e
);
97 void mouseReleaseEvent(QMouseEvent
*e
);
98 void mouseMoveEvent(QMouseEvent
*e
);
99 void resizeEvent(QResizeEvent
*e
);
100 void wheelEvent(QWheelEvent
*e
);
102 void drawTitlebar(QPainter
&p
, bool state
);
109 bool isfullyobscured
;
113 class B2Client
: public KDecoration
116 friend class B2Titlebar
;
118 B2Client(KDecorationBridge
*b
, KDecorationFactory
*f
);
121 void unobscureTitlebar();
122 void titleMoveAbs(int new_ofs
);
123 void titleMoveRel(int xdiff
);
125 virtual bool drawbound(const QRect
& geom
, bool clear
);
127 void resizeEvent( QResizeEvent
* );
128 void paintEvent( QPaintEvent
* );
129 void showEvent( QShowEvent
* );
130 void windowWrapperShowEvent( QShowEvent
* );
131 void captionChange();
132 void desktopChange();
135 void maximizeChange();
138 Position
mousePosition( const QPoint
& p
) const;
139 void resize(const QSize
&);
140 void borders(int &, int &, int &, int &) const;
141 QSize
minimumSize() const;
142 bool eventFilter(QObject
*, QEvent
*);
144 void menuButtonPressed();
146 void maxButtonClicked();
147 void shadeButtonClicked();
148 void resizeButtonPressed();
150 void addButtons(const QString
& s
, const QString tips
[],
151 B2Titlebar
* tb
, QBoxLayout
* titleLayout
);
152 void positionButtons();
153 void calcHiddenButtons();
154 bool mustDrawHandle() const;
156 enum ButtonType
{BtnMenu
=0, BtnSticky
, BtnIconify
, BtnMax
, BtnClose
,
157 BtnHelp
, BtnShade
, BtnResize
, BtnCount
};
158 B2Button
* button
[BtnCount
];
161 QSpacerItem
*topSpacer
;
162 QSpacerItem
*bottomSpacer
;
163 QSpacerItem
*leftSpacer
;
164 QSpacerItem
*rightSpacer
;
165 B2Titlebar
*titlebar
;
172 class B2ClientFactory
: public QObject
, public KDecorationFactory
177 virtual ~B2ClientFactory();
178 virtual KDecoration
*createDecoration(KDecorationBridge
*);
179 virtual bool reset(unsigned long changed
);
180 virtual bool supports( Ability ability
) const;
181 QList
< B2ClientFactory::BorderSize
> borderSizes() const;