not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / clients / b2 / b2client.h
blob337512dc938f016a1214cdf52dd7e510528c57e5
1 /*********************************************************************
2 B-II KWin Client
4 Changes:
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 *********************************************************************/
22 #ifndef __B2CLIENT_H
23 #define __B2CLIENT_H
25 #include <QDateTime>
26 #include <QAbstractButton>
27 //Added by qt3to4:
28 #include <QPaintEvent>
29 #include <QGridLayout>
30 #include <QEvent>
31 #include <QBoxLayout>
32 #include <QShowEvent>
33 #include <QResizeEvent>
34 #include <QMouseEvent>
35 #include <QBitmap>
36 #include <QPixmap>
37 #include <kdecoration.h>
38 #include <kdecorationfactory.h>
40 class QSpacerItem;
41 class QBoxLayout;
42 class QGridLayout;
44 namespace B2 {
46 class B2Client;
48 class B2Button : public QAbstractButton
50 public:
51 explicit B2Button(B2Client *_client=0, QWidget *parent=0, const QString& tip=NULL, const int realizeBtns = Qt::LeftButton);
52 ~B2Button() {}
54 void setBg(const QColor &c){bg = c;}
55 void setPixmaps(QPixmap *pix, QPixmap *pixDown, QPixmap *iPix,
56 QPixmap *iPixDown);
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;
63 protected:
64 virtual void paintEvent(QPaintEvent *e);
66 void mousePressEvent( QMouseEvent* e );
67 void mouseReleaseEvent( QMouseEvent* e );
68 private:
69 void enterEvent(QEvent *e);
70 void leaveEvent(QEvent *e);
72 bool useMiniIcon;
73 QPixmap *icon[6];
74 QColor bg; //only use one color (the rest is pixmap) so forget QPalette ;)
76 public:
77 B2Client* client;
78 Qt::MouseButtons last_button;
79 int realizeButtons;
80 bool hover;
83 class B2Titlebar : public QWidget
85 friend class B2Client;
86 public:
87 B2Titlebar(B2Client *parent);
88 ~B2Titlebar(){;}
89 bool isFullyObscured() const {return isfullyobscured;}
90 void recalcBuffer();
91 QSpacerItem *captionSpacer;
92 protected:
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);
101 private:
102 void drawTitlebar(QPainter &p, bool state);
104 B2Client *client;
105 QString oldTitle;
106 QPixmap titleBuffer;
107 QPoint moveOffset;
108 bool set_x11mask;
109 bool isfullyobscured;
110 bool shift_move;
113 class B2Client : public KDecoration
115 Q_OBJECT
116 friend class B2Titlebar;
117 public:
118 B2Client(KDecorationBridge *b, KDecorationFactory *f);
119 ~B2Client(){;}
120 void init();
121 void unobscureTitlebar();
122 void titleMoveAbs(int new_ofs);
123 void titleMoveRel(int xdiff);
124 // transparent stuff
125 virtual bool drawbound(const QRect& geom, bool clear);
126 protected:
127 void resizeEvent( QResizeEvent* );
128 void paintEvent( QPaintEvent* );
129 void showEvent( QShowEvent* );
130 void windowWrapperShowEvent( QShowEvent* );
131 void captionChange();
132 void desktopChange();
133 void shadeChange();
134 void activeChange();
135 void maximizeChange();
136 void iconChange();
137 void doShape();
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 *);
143 private slots:
144 void menuButtonPressed();
145 //void slotReset();
146 void maxButtonClicked();
147 void shadeButtonClicked();
148 void resizeButtonPressed();
149 private:
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];
159 QGridLayout *g;
160 // Border spacers
161 QSpacerItem *topSpacer;
162 QSpacerItem *bottomSpacer;
163 QSpacerItem *leftSpacer;
164 QSpacerItem *rightSpacer;
165 B2Titlebar *titlebar;
166 int bar_x_ofs;
167 int in_unobs;
168 QTime time;
169 bool resizable;
172 class B2ClientFactory : public QObject, public KDecorationFactory
174 Q_OBJECT
175 public:
176 B2ClientFactory();
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;
186 #endif