summaryrefslogtreecommitdiffstats
path: root/style/polyester.h
blob: 84f11333e311a7fe15b1cba725278fef61467407 (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
/* Polyester widget style for KDE 3
   Copyright (C) 2005 Marco Martin <notmart@gmail.com>

   based on Plastik widget style for KDE 3
   Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>

   based on the KDE style "dotNET":

   Copyright (C) 2001-2002, Chris Lee <clee@kde.org>
                            Carsten Pfeiffer <pfeiffer@kde.org>
                            Karol Szwed <gallium@kde.org>
   Drawing routines completely reimplemented from KDE3 HighColor, which was
   originally based on some stuff from the KDE2 HighColor.

   based on drawing routines of the style "Keramik":

   Copyright (c) 2002 Malte Starostik <malte@kde.org>
             (c) 2002,2003 Maksim Orlovich <mo002j@mail.rochester.edu>
   based on the KDE3 HighColor Style
   Copyright (C) 2001-2002 Karol Szwed      <gallium@kde.org>
             (C) 2001-2002 Fredrik H�lund  <fredrik@kde.org>
   Drawing routines adapted from the KDE2 HCStyle,
   Copyright (C) 2000 Daniel M. Duley       <mosfet@kde.org>
             (C) 2000 Dirk Mueller          <mueller@kde.org>
             (C) 2001 Martijn Klingens      <klingens@kde.org>
   Progressbar code based on TDEStyle,
   Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
 */

#ifndef __POLYESTER_H
#define __POLYESTER_H

#include <tdestyle.h>
#include <tqbitmap.h>
#include <tqintcache.h>

#define u_arrow -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2
#define d_arrow -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1
#define l_arrow 0,-3, 0,3,-1,-2,-1,2,-2,-1,-2,1,-3,0
#define r_arrow -2,-3,-2,3,-1,-2, -1,2,0,-1,0,1,1,0

#define TQCOORDARRLEN(x) sizeof(x)/(sizeof(TQCOORD)*2)

class TQSettings;
class TQTab;
class TQTimer;

//a tiny reimplementation of max...
int max(int a, int b){return (a>b?a:b);}

class PolyesterStyle : public TDEStyle
{
    TQ_OBJECT

public:
    PolyesterStyle();
    virtual ~PolyesterStyle();

    void polish(TQApplication* app );
    void polish(TQWidget* widget );
    void unPolish(TQWidget* widget );

    void drawTDEStylePrimitive(TDEStylePrimitive kpe,
                             TQPainter* p,
                             const TQWidget* widget,
                             const TQRect &r,
                             const TQColorGroup &cg,
                             SFlags flags = Style_Default,
                             const TQStyleOption& = TQStyleOption::Default ) const;

    void drawPrimitive(PrimitiveElement pe,
                       TQPainter *p,
                       const TQRect &r,
                       const TQColorGroup &cg,
                       SFlags flags = Style_Default,
                       const TQStyleOption &opt = TQStyleOption::Default ) const;

    void drawControl(ControlElement element,
                     TQPainter *p,
                     const TQWidget *widget,
                     const TQRect &r,
                     const TQColorGroup &cg,
                     SFlags flags = Style_Default,
                     const TQStyleOption& = TQStyleOption::Default ) const;

    void drawControlMask( ControlElement, TQPainter *, const TQWidget *, const TQRect &, const TQStyleOption &) const;

    void drawComplexControl(ComplexControl control,
                            TQPainter *p,
                            const TQWidget *widget,
                            const TQRect &r,
                            const TQColorGroup &cg,
                            SFlags flags = Style_Default,
                            SCFlags controls = SC_All,
                            SCFlags active = SC_None,
                            const TQStyleOption& = TQStyleOption::Default ) const;

    int pixelMetric(PixelMetric m,
                    const TQWidget *widget = 0 ) const;

    int kPixelMetric(TDEStylePixelMetric kpm, const TQWidget *widget) const;

    TQRect subRect(SubRect r,
                  const TQWidget *widget ) const;

    TQRect querySubControlMetrics(ComplexControl control,
                                 const TQWidget *widget,
                                 SubControl subcontrol,
                                 const TQStyleOption &opt = TQStyleOption::Default ) const;

    void drawComplexControlMask(TQStyle::ComplexControl c,
                                TQPainter *p,
                                const TQWidget *w,
                                const TQRect &r,
                                const TQStyleOption &o=TQStyleOption::Default) const;

    TQSize sizeFromContents(TQStyle::ContentsType t,
                           const TQWidget *w,
                           const TQSize &s,
                           const TQStyleOption &o) const;

    int styleHint(StyleHint, const TQWidget * = 0,
                  const TQStyleOption & = TQStyleOption::Default,
                  TQStyleHintReturn * = 0 ) const;

protected:
    enum TabPosition
    {
        First = 0,
        Middle,
        Last,
        Single // only one tab!
    };

    enum SelectedTab
    {
        ThisTab,
        NextTab,
        PrevTab,
        OtherTab
    };

    enum ColorType
    {
        ButtonContour,
        DragButtonContour,
        DragButtonSurface,
        PanelContour,
        PanelLight,
        PanelLight2,
        PanelDark,
        PanelDark2,
        MouseOverHighlight,
        FocusHighlight,
        CheckMark,
        MenuBarEmphasis
    };

    enum WidgetState
    {
        IsEnabled,
        IsPressed,     // implies IsEnabled
        IsHighlighted, // implies IsEnabled
        IsDisabled
    };

    // the only way i see to provide all these options
    // to renderContour/renderSurface...
    enum SurfaceFlags {
        Draw_Left =          0x00000001,
        Draw_Right =         0x00000002,
        Draw_Top =           0x00000004,
        Draw_Bottom =        0x00000008,
        Highlight_Left =     0x00000010, // surface
        Highlight_Right =    0x00000020, // surface
        Highlight_Top =      0x00000040, // surface
        Highlight_Bottom =   0x00000080, // surface
        Is_Sunken =          0x00000100, // surface
        Is_Horizontal =      0x00000200, // surface
        Is_Highlight =       0x00000400, // surface
        Is_Default =         0x00000800, // surface
        Is_Disabled =        0x00001000,
        Round_UpperLeft =    0x00002000,
        Round_UpperRight =   0x00004000,
        Round_BottomLeft =   0x00008000,
        Round_BottomRight =  0x00010000,
        Draw_AlphaBlend =    0x00020000,
        Sharp_UpperLeft =      0x00040000,
        Sharp_UpperRight =     0x00080000,
        Sharp_BottomLeft =   0x00100000,
        Sharp_BottomRight =  0x00200000
    };

    void renderContour(TQPainter *p,
                       const TQRect &r,
                       const TQColor &backgroundColor,
                       const TQColor &contourColor,
                       const uint flags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
                               Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight) const;

    void renderMask(TQPainter *p,
                    const TQRect &r,
                    const TQColor &color,
                    const uint flags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
                            Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight) const;

    void renderSurface(TQPainter *p,
                        const TQRect &r,
                        const TQColor &backgroundColor,
                        const TQColor &buttonColor,
                        const TQColor &highlightColor,
                        int intensity = 5,
                        const uint flags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
                                Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight|
                                Is_Horizontal) const;

    inline void renderPixel(TQPainter *p,
            const TQPoint &pos,
            const int alpha,
            const TQColor &color,
            const TQColor &background = TQColor(),
            bool fullAlphaBlend = true) const;

    void renderButton(TQPainter *p,
                      const TQRect &r,
                      const TQColorGroup &g,
                      bool sunken = false,
                      bool mouseOver = false,
                      bool horizontal = true,
                      bool enabled = true,
                      bool tdehtmlMode = false,
                      int animFrame = 0,
                      bool isDefault = false) const;

    void renderPanel(TQPainter *p,
                     const TQRect &r,
                     const TQColorGroup &g,
                     const bool pseudo3d = true,
                     const bool sunken = true) const;

    void renderDot(TQPainter *p,
                   const TQPoint &point,
                   const TQColor &baseColor,
                   const bool thick = false,
                   const bool sunken = false) const;

    void renderGradient(TQPainter *p,
                        const TQRect &r,
                        const TQColor &c1,
                        const TQColor &c2,
                        bool horizontal = true) const;

    void renderTab(TQPainter *p,
                   const TQRect &r,
                   const TQColorGroup &g,
                   bool mouseOver = false,
                   const SelectedTab selected = OtherTab,
                   const bool bottom = false,
                   const TabPosition pos = Middle,
                   const bool triangular = false,
                   bool cornerWidget = false) const;

    virtual void renderMenuBlendPixmap( KPixmap& pix, const TQColorGroup& cg, 
                                        const TQPopupMenu* popup ) const;

    bool eventFilter(TQObject *, TQEvent *);

    // what widget has mouse over him?
    TQWidget* hoverWidget;
    // mouse over for listview headers
    int hoverHeaderId;

protected slots:
    void tdehtmlWidgetDestroyed(TQObject* w);

    void sliderThumbMoved(int val);

    //Animation slots.
    void updateProgressPos();
    void progressBarDestroyed(TQObject* bar);
    void animWidgetDestroyed(TQObject* w);
    void animate();

    inline TQColor getColor(const TQColorGroup &cg, const ColorType t, const bool enabled = true)const;
    inline TQColor getColor(const TQColorGroup &cg, const ColorType t, const WidgetState s)const;
private:
// Disable copy constructor and = operator
    PolyesterStyle( const PolyesterStyle & );
    PolyesterStyle& operator=( const PolyesterStyle & );



    bool kickerMode, kornMode;
    mutable bool flatMode;

    int _contrast;
    bool _scrollBarLines;
    TQString _scrollBarStyle;
    int _scrollBarExtent;
    TDEStyle::TDEStyleScrollBarType _scrollBarType;
    bool _useLowerCaseText;
    bool _animateProgressBar;
    bool _animateButton;
    bool _animateButtonToDark;
    bool _lightBorder;
    bool _coloredScrollBar;
    bool _centeredTabBar;
    bool _highLightTab;
    bool _statusBarFrame;
    bool _colorizeSortedHeader;
    int  _menuItemSpacing;
    bool _buttonMenuItem;
    bool _menuBarEmphasis;
    bool _menuBarEmphasisBorder;
    bool _customMenuBarEmphasisColor;
    bool _menuStripe;
    TQColor _menuBarEmphasisColor;
    bool _shadowedMenuBarText;
    bool _shadowedButtonsText;
    bool _drawToolBarSeparator;
    bool _drawToolBarItemSeparator;
    bool _drawFocusRect;
    bool _drawTriangularExpander;
    bool _inputFocusHighlight;
    bool _customOverHighlightColor;
    bool _customFocusHighlightColor;
    bool _customCheckMarkColor;
    TQColor _overHighlightColor;
    TQColor _focusHighlightColor;
    TQColor _checkMarkColor;
    TQString _buttonStyle;

    TQTab *hoverTab;

    // track tdehtml widgets.
    TQMap<const TQWidget*,bool> tdehtmlWidgets;

    //Animation support.
    TQMap<TQWidget*, int> progAnimWidgets;

    // pixmap cache.
    enum CacheEntryType {
        cSurface,
        cGradientTile,
        cAlphaDot
    };
    struct CacheEntry
    {
        CacheEntryType type;
        int width;
        int height;
        TQRgb c1Rgb;
        TQRgb c2Rgb;
        bool horizontal;

        TQPixmap* pixmap;

        CacheEntry(CacheEntryType t, int w, int h, TQRgb c1, TQRgb c2 = 0,
                   bool hor = false, TQPixmap* p = 0 ):
            type(t), width(w), height(h), c1Rgb(c1), c2Rgb(c2), horizontal(hor), pixmap(p)
        {}

        ~CacheEntry()
        {
            delete pixmap;
        }

        int key()
        {
            // create an int key from the properties which is used to refer to entries in the TQIntCache.
            // the result may not be 100% correct as we don't have so much space in one integer -- use
            // == operator after find to make sure we got the right one. :)
            return horizontal ^ (type<<1) ^ (width<<5) ^ (height<<10) ^ (c1Rgb<<19) ^ (c2Rgb<<22);
        }

        bool operator == (const CacheEntry& other)
        {
            bool match = (type == other.type) &&
                        (width   == other.width) &&
                        (height == other.height) &&
                        (c1Rgb == other.c1Rgb) &&
                        (c1Rgb == other.c1Rgb) &&
                        (horizontal = other.horizontal);
//             if(!match) {
//                 tqDebug("operator ==: CacheEntries don't match!");
//                 tqDebug("width: %d\t\tother width: %d", width, other.width);
//                 tqDebug("height: %d\t\tother height: %d", height, other.height);
//                 tqDebug("fgRgb: %d\t\tother fgRgb: %d", fgRgb, other.fgRgb);
//                 tqDebug("bgRgb: %d\t\tother bgRgb: %d", bgRgb, other.bgRgb);
//                 tqDebug("surfaceFlags: %d\t\tother surfaceFlags: %d", surfaceFlags, other.surfaceFlags);
//             }
            return match;
        }
    };
    TQIntCache<CacheEntry> *pixmapCache;
    
    // For renderFocusRect
    mutable TQBitmap *verticalDots;
    mutable TQBitmap *horizontalDots;

    // For KPE_ListViewBranch
    mutable TQBitmap *verticalLine;
    mutable TQBitmap *horizontalLine;

    // For buttons animation
    struct AnimInfo {
        bool active;
        uint animFrame;
    };
    typedef TQMap<TQWidget*, AnimInfo>AnimWidgetMap;
    AnimWidgetMap animWidgets;
    TQTimer *btnAnimTimer;

    typedef TQMap<const TQWidget*, int>SliderValuesMap;
    SliderValuesMap sliderValues;

    // For progress bar animation
    TQTimer *animationTimer;

    //for the semi transparent menu stripe
    TQImage *alphaStripe;
};

#endif // __POLYESTER_H