summaryrefslogtreecommitdiffstats
path: root/src/widget/ia_ora.h
blob: 1e96ccc0915cd473e2e8787cb7db0c47a1f0aaa6 (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
/*
 * Copyright (C) 2007 Gustavo Pichorim Boiko <[email protected]>
 * Copyright (C) 2006 Laurent Montel<[email protected]>
 *
 * renderGradient() code adapted from the Plastik stype
 * Copyright (C) 2003 Sandro Giessl <[email protected]>
 *
 * based on KDE3 HighColor Style (version 1.0)
 * Copyright (C) 2001-2002 Karol Szwed      <[email protected]>
 *           (C) 2001-2002 Fredrik H�glund  <[email protected]>
 *
 * Drawing routines adapted from the KDE2 HCStyle,
 * Copyright (C) 2000 Daniel M. Duley       <[email protected]>
 *           (C) 2000 Dirk Mueller          <[email protected]>
 *           (C) 2001 Martijn Klingens      <[email protected]>
 *
 * 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 __MANDRIVASTYLE_H
#define __MANDRIVASTYLE_H

#include <qbitmap.h>
#include <qintdict.h>
#include <kdrawutil.h>
#include <kpixmap.h>
#include <kstyle.h>
#include <qintcache.h>

class QPopupMenu;


class MandrivaStyle : public KStyle
{
    Q_OBJECT

public:
    MandrivaStyle();
    virtual ~MandrivaStyle();

    void polish( QWidget* widget );
    void unPolish( QWidget* widget );
    void polish( QApplication *app );
    void renderMenuBlendPixmap( KPixmap& pix, const QColorGroup &cg,
                                const QPopupMenu* popup ) const;

    void drawKStylePrimitive( KStylePrimitive kpe,
                              QPainter* p,
                              const QWidget* widget,
                              const QRect &r,
                              const QColorGroup &cg,
                              SFlags flags = Style_Default,
                              const QStyleOption& = QStyleOption::Default ) const;

    void drawPrimitive( PrimitiveElement pe,
                        QPainter* p,
                        const QRect &r,
                        const QColorGroup &cg,
                        SFlags flags = Style_Default,
                        const QStyleOption& = QStyleOption::Default ) const;

    void drawControl( ControlElement element,
                      QPainter *p,
                      const QWidget *widget,
                      const QRect &r,
                      const QColorGroup &cg,
                      SFlags flags = Style_Default,
                      const QStyleOption& = QStyleOption::Default ) const;

    void drawControlMask( ControlElement element,
                          QPainter *p,
                          const QWidget *widget,
                          const QRect &r,
                          const QStyleOption& = QStyleOption::Default ) const;

    void drawComplexControl( ComplexControl control,
                             QPainter *p,
                             const QWidget *widget,
                             const QRect &r,
                             const QColorGroup &cg,
                             SFlags flags = Style_Default,
                             SCFlags controls = SC_All,
                             SCFlags active = SC_None,
                             const QStyleOption& = QStyleOption::Default ) const;

    void drawComplexControlMask( ComplexControl control,
                                 QPainter *p,
                                 const QWidget *widget,
                                 const QRect &r,
                                 const QStyleOption& = QStyleOption::Default ) const;

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

    QSize sizeFromContents( ContentsType contents,
                            const QWidget *widget,
                            const QSize &contentSize,
                            const QStyleOption& opt ) const;

    QRect subRect( SubRect r,
                   const QWidget *widget ) const;

    // Fix Qt3's wacky image positions
    QPixmap stylePixmap( StylePixmap stylepixmap,
                         const QWidget *widget = 0,
                         const QStyleOption& = QStyleOption::Default ) const;

    QRect querySubControlMetrics( ComplexControl control,
                                  const QWidget* widget,
                                  SubControl subcontrol,
                                  const QStyleOption& opt = QStyleOption::Default ) const;

protected:
    enum Hover
    {
        HoverNone = 0,
        // scrollbar
        HoverScrollBarSlider,
        HoverScrollBarAddLine,
        HoverScrollBarSubLine,
        HoverScrollBarAddPage,
        HoverScrollBarSubPage,
        HoverScrollBarFirst,
        HoverScrollBarLast,
        // combobox
        HoverComboBoxArrow,
        HoverComboBoxEdit
    };


    bool eventFilter( QObject *object, QEvent *event );

    void renderGradient(QPainter* p,
                        const QRect& r,
                        const QColor& ca,
                        const QColor& cb ,
                        bool horizontal) const;

    QWidget    *hoverWidget;
    enum Hover hoverControl;

    struct MandrivaColorData 
    {
        ~MandrivaColorData();
        QRgb spotColor;

        // gradient color
        //rename to grey
        QColor shades[7];
        
        // five blue color
        QColor blueMdkColor[5];

        // button gradients 
        QColor buttonColor[7];
        
        
        QColor radioColor;

        bool isGroup (const QColorGroup &cg) 
        {
            return cg.button() == buttonColor[0] && cg.highlight().rgb() == spotColor;
        }
    };

private:
    enum TabPosition {Single = 0,First,Last, Middle};

    // Disable copy constructor and = operator
    MandrivaStyle( const MandrivaStyle & );
    MandrivaStyle& operator=( const MandrivaStyle & );

    void drawButton( const MandrivaColorData *cdata, 
                     const QRect & r, QPainter *p,
                     const QColorGroup &cg, 
                     SFlags flags) const;

    void drawHandlePoint ( const MandrivaColorData *cdata,
                           QPainter *p, 
                           int x, 
                           int y) const;

    void drawHandle( const MandrivaColorData *cdata, 
                     QPainter *p,
                     const QRect &r,
                     const QColorGroup &cg,
                     SFlags flags, 
                     const QStyleOption& opt, 
                     bool drawBorderAndGradient, 
                     bool drawGradient = false ) const;

    void drawGroupBox(const MandrivaColorData *cdata, 
                      const QColorGroup & cg, 
                      QPainter *p, 
                      const QRect & r, 
                      bool active, 
                      bool sunken )const;

    void drawLineSeparator(const MandrivaColorData *cdata, 
                           const QColorGroup & cg, 
                           QPainter *p, 
                           const QRect & r, 
                           bool horiziontal,
                           bool active, 
                           bool sunken,
                           bool skipOffset = true) const;

    void drawFrame( const MandrivaColorData *cdata, 
                    const QColorGroup & cg, 
                    QPainter *p, 
                    const QRect & r, 
                    bool active) const;

    void drawComboboxArrow( QPainter *p,
                            const QWidget *widget,
                            const QRect &r,
                            const QColorGroup &cg,
                            SFlags flags,
                            SCFlags active)const;

    void drawMandrivaArrow( QPointArray a, QPainter *p,
                            const QRect &r,
                            const QColorGroup &cg,
                            SFlags flags,
                            const QStyleOption& opt ) const;


    MandrivaColorData *realizeData (const QColorGroup &cg) const;
    const MandrivaColorData *lookupData (const QColorGroup &cg) const;
    bool isFormWidget(const QWidget* widget) const;
    bool excludeColor(const QColor &col, bool active) const;
    void getShade (const QColorGroup &cg, int shadenr, QColor &res) const;
    void updateHoverControl(const QPoint &pos);
    QIntCache<MandrivaColorData> m_dataCache;
    static const double shading[8];
    mutable bool formMode;
    bool kickerMode;
    // For KPE_ListViewBranch
    mutable QBitmap *verticalLine;
    mutable QBitmap *horizontalLine;

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

        QPixmap* pixmap;

        CacheEntry(CacheEntryType t, int w, int h, QRgb c1, QRgb c2 = 0,
                   bool hor = false, QPixmap* 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 QIntCache.
            // 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);
            return match;
        }
    };
    QIntCache<CacheEntry> *pixmapCache;

};

#endif

// vim: ts=4 et sw=4