summaryrefslogtreecommitdiffstats
path: root/deco/baghiraclient.h
blob: f9ca4b9cab1492a6a31416b63ebf1cacfbcca1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//////////////////////////////////////////////////////////////////////////////
// baghiraclient.h
// -------------------
// Baghira window decoration for KDE
// -------------------
// Copyright (c) 2004, 2005 Thomas Lübking
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////

#ifndef BAGHIRACLIENT_H
#define BAGHIRACLIENT_H

#include <tqcolor.h>
#include <tqbutton.h>
#include <kdecoration.h>
#include <kdecorationfactory.h>
#include <kpixmap.h>
#include <tdeversion.h>
/*
#define BUTTONSIZE 15;
#define MENUBUTTONWIDTH 20;
#define DECOSIZE 8;
#define TITLESIZESMALL 18;
#define MARGIN 4;*/

class TQSpacerItem;
class TQPoint;
class TQBitmap;
class KWinModule;

namespace Baghira {


enum PixmapType {
    TitleBar = 0,
    TitleCenter,
    PixmapTypeCount
};

enum ColorType {
    ColorTitleBar=0,
    ColorTitleBlend,
    ColorTypeCount
};

enum ButtonType{
	MinButton = 0,
	MaxButton,
	CloseButton,
	StickyButton,
	ShadeButton,
   AboveBelowButton,
	MenuButton,
	HelpButton,
	ButtonTypeAmount,
	InactiveButton = ButtonTypeAmount
};

enum ButtonStyle{
	Panther = 0,
	Jaguar,
	Milk,
	NostalgiaButton
};

enum ButtonState{
	ButtonInactive,
	ButtonActive,
	Hovered,
	Pressed,
	ButtonStateAmount
};

enum WindowState{
	WindowInactive,
	WindowActive,
	WindowStateAmount
};

enum TitlebarType{
	Gradient,
	Stipples,
	Nostalgia,
	Glossy,
	Brushed,
	FlatStipples
};

class BaghiraClient;


class ResizeHandle : public TQWidget
{
friend class BaghiraClient;
    TQ_OBJECT
public:
    ResizeHandle(BaghiraClient *parent);
protected:
    virtual void mousePressEvent ( TQMouseEvent * );
    virtual void mouseReleaseEvent ( TQMouseEvent * );
    virtual void paintEvent ( TQPaintEvent * );
    void updateLook(bool rp = FALSE);
private:
    bool eventFilter(TQObject *obj, TQEvent *e);
    void shape();
    BaghiraClient *client;
    TQPixmap pix;
};
// #endif

class DeMaximizer : public TQWidget
{
friend class BaghiraClient;
friend class BaghiraFactory;
    TQ_OBJECT
public:
    DeMaximizer();
    void setClient(BaghiraClient *);
protected:
    void mouseReleaseEvent( TQMouseEvent * e );
    void mousePressEvent ( TQMouseEvent * e );
    void enterEvent ( TQEvent * e );
    void leaveEvent ( TQEvent * e );
    void setPixmap(int i, TQImage &image);
private:
    BaghiraClient *client_;
    TQPixmap pixmap[5];
    void setState(int i);
};

// BaghiraFactory //////////////////////////////////////////////////////////////

class BaghiraFactory: public KDecorationFactory
{
public:
    BaghiraFactory();
    virtual ~BaghiraFactory();
    virtual KDecoration *createDecoration(KDecorationBridge *b);
    virtual bool reset(unsigned long changed);
    virtual TQValueList<BorderSize> borderSizes() const;
    static TQPixmap &ButtonPixmap(Baghira::WindowState wState, Baghira::ButtonType type, Baghira::ButtonState state, int current, bool small);
    TQImage* DecoImage(TQPixmap *pix, int x, int y, int width, int height);

    static TQBitmap helpMask, jaguarDownMask, jaguarMenuDownMask,
            jaguarMenuMask, jaguarMask, milkMenuDownMask,
            milkMenuMask, milkMask, pantherMenuMask, pantherMask, milkDownMask, arrowUp, arrowDown;

    static bool initialized();
    static bool noModalDeco();
    static bool delAppname();
    static TQColor &color(int current, Baghira::ColorType c, bool active=true);
    static KPixmap &pix(int current, PixmapType p, bool active=true, bool small=false);
    static TitlebarType &effect(int current, bool active);
    static ButtonStyle buttonStyle(int current);
    static TQt::AlignmentFlags titleAlign();
    static int borderSize(int current);
    static int contrast();
    static int _3DImpact(int current);
    static int LineImpact(int current);
    static bool bgStipple();
    static bool resizeGrip();
    static uint defaultMode();
    static bool drawComicFrame();
    static bool shapeUL(int current);
    static bool shapeUR(int current);
    static bool shapeLL(int current);
    static bool shapeLR(int current);
    static bool drawIcon(int current);
    static bool showTitle();
    static bool allowEasyClosing();
    static bool addAutoSpacing();
    static bool maxResizable();
    TitlebarType titleEffect();
    static DeMaximizer &deMaximizer();
    static bool fullSpec();
    static TQColor &BrushedMetalColor();

private:
//    bool blend( const TQImage & upper, const TQImage & lower, TQImage & output);
    unsigned long readConfig();
    void createPixmaps();
   void createGradient(KPixmap &pix, const TQColor &light, const TQColor &dark, Baghira::TitlebarType effect);
    void createOS8Buttons(int style);
    TQString indexedString(TQString s, int index);
    TQImage* tintBrush( const TQImage &img, const TQColor &c ) const;
    TQImage* tintGlossy(const TQImage &src, const TQColor &c ) const;

private:
    
    static bool initialized_;
    static bool noModalDeco_;
   static bool delAppname_;
    static bool bgStipple_;
    static bool comicFrame_;
    static bool resizeGrip_;
    static bool shape_ul[5], shape_ur[5], shape_ll[5], shape_lr[5];
    static bool allowEasyClosing_;
    static bool addAutoSpacing_;
    static bool maxResizable_;
    static bool drawIcon_[5];
    static ButtonStyle buttonStyle_[5];
    static TitlebarType effect_[5][2];
    static TQt::AlignmentFlags titlealign_;
    static TQColor colors_[5][ColorTypeCount][2];
    static KPixmap pix_[5][PixmapTypeCount][2][2];
    static TQPixmap ButtonPixmap_[5][WindowStateAmount][ButtonTypeAmount][ButtonStateAmount][2];
    static TQColor ButtonColor_[ButtonTypeAmount+1];
    static TQColor brushedMetalColor;
    static TQPixmap nostalgia_[5][3][2];
    
    static int contrast_;
   static int bordersize_[5];
    static uint defaultMode_;
    static int minimumTitleHeight_;
    static int _3DImpact_[5];
    static int LineImpact_[5];
    
    static bool tintBrush_;
    static bool showTitle_;
    static TQColor brushTint;
    static DeMaximizer deMaximizer_;
    static bool fullSpec_;
    
};

inline bool BaghiraFactory::fullSpec()
    { return fullSpec_; }
inline bool BaghiraFactory::noModalDeco()
{ return noModalDeco_; }
inline bool BaghiraFactory::delAppname()
{ return delAppname_; }

inline DeMaximizer &BaghiraFactory::deMaximizer()
    { return deMaximizer_; }

inline bool BaghiraFactory::shapeUL(int current)
    { return shape_ul[current]; }
inline bool BaghiraFactory::shapeUR(int current)
    { return shape_ur[current]; }
inline bool BaghiraFactory::shapeLL(int current)
    { return shape_ll[current]; }
inline bool BaghiraFactory::shapeLR(int current)
    { return shape_lr[current]; }

inline bool BaghiraFactory::allowEasyClosing()
    { return allowEasyClosing_; }

inline bool BaghiraFactory::addAutoSpacing()
    { return addAutoSpacing_; }
    
inline bool BaghiraFactory::maxResizable()
    { return maxResizable_; }
    
inline bool BaghiraFactory::resizeGrip()
    { return resizeGrip_; }
    
inline uint BaghiraFactory::defaultMode()
    { return defaultMode_; }
    
inline bool BaghiraFactory::drawIcon(int current)
    { return drawIcon_[current]; }

inline bool BaghiraFactory::showTitle()
{ return showTitle_; }

inline int BaghiraFactory::contrast()
    { return contrast_; }
    
inline int BaghiraFactory::_3DImpact(int current)
    { return _3DImpact_[current]; }
    
inline int BaghiraFactory::LineImpact(int current)
    { return LineImpact_[current]; }

inline bool BaghiraFactory::drawComicFrame()
    { return comicFrame_; }
    
inline bool BaghiraFactory::bgStipple()
    { return bgStipple_; }

inline ButtonStyle BaghiraFactory::buttonStyle(int current)
    { return BaghiraFactory::buttonStyle_[current]; } 
    
inline bool BaghiraFactory::initialized()
    { return initialized_; }

inline TQColor &BaghiraFactory::BrushedMetalColor()
    { return brushedMetalColor; }

inline TQColor &BaghiraFactory::color(int current, Baghira::ColorType c, bool active)
    { return colors_[current][c][active]; }

inline KPixmap &BaghiraFactory::pix(int current, PixmapType p, bool active, bool small)
    { return pix_[current][p][active][small]; }

inline Baghira::TitlebarType &BaghiraFactory::effect(int current, bool active)
    { return effect_[current][active]; }

inline TQt::AlignmentFlags BaghiraFactory::titleAlign()
    { return titlealign_; }

inline int BaghiraFactory::borderSize(int current)
{ return bordersize_[current]; }

// BaghiraButton ///////////////////////////////////////////////////////////////

class BaghiraButton : public TQButton
{
   TQ_OBJECT
public:
    BaghiraButton(BaghiraClient *parent=0, const char *name=0, const TQString &tip=NULL, bool small=false, ButtonType type=MinButton, int style=0);
    ~BaghiraButton();

    TQSize sizeHint() const;
    int lastMousePress() const;
    void reset();
    inline void setMasks(TQBitmap *bitmask, TQBitmap *bitmaskDown);
    Baghira::ButtonState state();
    inline void setType(Baghira::ButtonType type)
	{type_ = type; }
    TQBitmap *mask;
    TQBitmap *maskDown;

private:
    void enterEvent(TQEvent *e);
    void leaveEvent(TQEvent *e);
    void mousePressEvent(TQMouseEvent *e);
    void mouseReleaseEvent(TQMouseEvent *e);
    void drawButton(TQPainter *painter);
   
private slots:
   void delayedEnterEvent();

private:
   bool _blocked;
   BaghiraClient *client_;
   ButtonType type_;
   TQBitmap *deco_;
   TQPixmap *pixmap[2][5];
   KPixmap icon_;
   bool small_;
   int lastmouse_;
   bool mouseover_;
   bool down_;
};

inline int BaghiraButton::lastMousePress() const
    { return lastmouse_; }

inline void BaghiraButton::reset()
    { repaint(false); }
    
// BaghiraClient ///////////////////////////////////////////////////////////////

class BaghiraClient : public KDecoration
{
friend class BaghiraButton;
friend class ResizeHandle;
    TQ_OBJECT
public:
   BaghiraClient(KDecorationBridge *b, KDecorationFactory *f);
   virtual ~BaghiraClient();

   virtual void init();
   TQString caption() const;

   virtual void activeChange();
   virtual void desktopChange();
   virtual void captionChange();
   virtual void iconChange();
   virtual void maximizeChange();
   virtual void shadeChange();
   void demaxButtonPressed();

   virtual void borders(int &l, int &r, int &t, int &b) const;
   virtual void resize(const TQSize &size);
   virtual TQSize minimumSize() const;
   virtual Position mousePosition(const TQPoint &point) const;
   uint currentStyle;

signals:
    void hide();

protected:
    bool isTool() const;
    int  titleheight_;

private:
    void addButtons(TQBoxLayout* layout, const TQString& buttons);

    bool eventFilter(TQObject *obj, TQEvent *e);
    void mouseDoubleClickEvent(TQMouseEvent *e);
    void wheelEvent(TQWheelEvent *e);
    void paintEvent(TQPaintEvent *);
    void resizeEvent(TQResizeEvent *);
    void showEvent(TQShowEvent *);

private slots:
    void doShape();
    void maxButtonPressed();
    void menuButtonPressed();
    void aboveBelowButtonPressed();
    void shadeButtonPressed();

private:
    BaghiraButton *button[ButtonTypeAmount];
    
    TQSpacerItem *titlebar_;
    TQPixmap HandlePix;
    int excursion; // skewness because of unequality of left/right buttons - bad for center aligned titles...
    int plusminus;
    bool isFaded;
    bool leftClose;
    bool rightClose;
    bool performEasyClose;
   bool noDeco_;
    TQHBoxLayout *windowlayout;
    int ICONX, ICONY;
    ResizeHandle *grip;
   TQString caption_;
};

} // namespace Baghira

#endif // BAGHIRACLIENT_H