~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to themes/mstyle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=========================================================
2
 
//  MusE
3
 
//  Linux Music Editor
4
 
//  $Id: mstyle.cpp,v 1.1 2002/01/30 14:54:03 muse Exp $
5
 
//
6
 
//  (C) Copyright 2001 Werner Schweer (ws@seh.de)
7
 
//=========================================================
8
 
 
9
 
#include "mstyle.h"
10
 
#include "qapplication.h"
11
 
#include "qcombobox.h"
12
 
#include "qpainter.h"
13
 
#include "qdrawutil.h"
14
 
#include "qpixmap.h"
15
 
#include "qpalette.h"
16
 
#include "qwidget.h"
17
 
#include "qlabel.h"
18
 
#include "qimage.h"
19
 
#include "qpushbutton.h"
20
 
#include "qwidget.h"
21
 
#include "qrangecontrol.h"
22
 
#include "qscrollbar.h"
23
 
#include "qslider.h"
24
 
#include <limits.h>
25
 
 
26
 
#include "stonedark.xpm"
27
 
#include "stone1.xpm"
28
 
#include "marble.xpm"
29
 
 
30
 
MuseStyle::MuseStyle() : QMuseWindowsStyle() { }
31
 
 
32
 
//---------------------------------------------------------
33
 
//   polish
34
 
//---------------------------------------------------------
35
 
 
36
 
void MuseStyle::polish(QApplication *app)
37
 
      {
38
 
      oldPalette = app->palette();
39
 
 
40
 
      // we simply create a nice QColorGroup with a couple of fancy
41
 
      // pixmaps here and apply to it all widgets
42
 
 
43
 
      QFont f("times", app->font().pointSize());
44
 
      f.setBold(true);
45
 
      f.setItalic(true);
46
 
      app->setFont(f, true, "QMenuBar");
47
 
      app->setFont(f, true, "QPopupMenu");
48
 
 
49
 
      //    QPixmap button( stonedark_xpm );
50
 
 
51
 
      QColor gold("#B9B9A5A54040"); //same as topgrad below
52
 
      QPixmap button(1, 1);
53
 
      button.fill( gold );
54
 
 
55
 
      QPixmap background(marble_xpm);
56
 
      QPixmap dark(1, 1);
57
 
      dark.fill(red.dark());
58
 
      QPixmap mid(stone1_xpm);
59
 
      QPixmap light(stone1_xpm );//1, 1 );
60
 
      light.fill(green);
61
 
 
62
 
      QPalette op = app->palette();
63
 
 
64
 
      QColor backCol(227,227,227);
65
 
 
66
 
    // QPalette op(white);
67
 
    QColorGroup active (op.active().foreground(),
68
 
                     QBrush(op.active().button(),button),
69
 
                     QBrush(op.active().light(), light),
70
 
                     QBrush(op.active().dark(), dark),
71
 
                     QBrush(op.active().mid(), mid),
72
 
                     op.active().text(),
73
 
                     Qt::white,
74
 
                     op.active().base(),//                   QColor(236,182,120),
75
 
                     QBrush(backCol, background)
76
 
                     );
77
 
    active.setColor( QColorGroup::ButtonText,  Qt::white  );
78
 
    active.setColor( QColorGroup::Shadow,  Qt::black  );
79
 
    QColorGroup disabled (op.disabled().foreground(),
80
 
                     QBrush(op.disabled().button(),button),
81
 
                     QBrush(op.disabled().light(), light),
82
 
                     op.disabled().dark(),
83
 
                     QBrush(op.disabled().mid(), mid),
84
 
                     op.disabled().text(),
85
 
                     Qt::white,
86
 
                     op.disabled().base(),//                 QColor(236,182,120),
87
 
                     QBrush(backCol, background)
88
 
                     );
89
 
 
90
 
      QPalette newPalette( active, disabled, active );
91
 
      app->setPalette( newPalette, TRUE );
92
 
      }
93
 
 
94
 
//---------------------------------------------------------
95
 
//   unPolish
96
 
//---------------------------------------------------------
97
 
 
98
 
void MuseStyle::unPolish( QApplication *app)
99
 
      {
100
 
      app->setPalette(oldPalette, true);
101
 
      app->setFont(app->font(), true);
102
 
      }
103
 
 
104
 
/*!
105
 
  Reimplementation from QStyle
106
 
 */
107
 
void MuseStyle::polish( QWidget* w)
108
 
{
109
 
 
110
 
   // the polish function sets some widgets to transparent mode and
111
 
    // some to translate background mode in order to get the full
112
 
    // benefit from the nice pixmaps in the color group.
113
 
 
114
 
    if (w->inherits("QPushButton")){
115
 
        w->setBackgroundMode( QWidget::NoBackground );
116
 
        return;
117
 
    }
118
 
 
119
 
    if ( !w->isTopLevel() ) {
120
 
        if ( w->backgroundPixmap() )
121
 
            w->setBackgroundOrigin( QWidget::WindowOrigin );
122
 
    }
123
 
}
124
 
 
125
 
void MuseStyle::unPolish( QWidget* w)
126
 
{
127
 
 
128
 
   // the polish function sets some widgets to transparent mode and
129
 
    // some to translate background mode in order to get the full
130
 
    // benefit from the nice pixmaps in the color group.
131
 
 
132
 
    if (w->inherits("QPushButton")){
133
 
        w->setBackgroundMode( QWidget::PaletteButton );
134
 
        return;
135
 
    }
136
 
    if ( !w->isTopLevel() ) {
137
 
        if ( w->backgroundPixmap() )
138
 
            w->setBackgroundOrigin( QWidget::WidgetOrigin );
139
 
    }
140
 
 
141
 
}
142
 
 
143
 
void MuseStyle::drawPrimitive( PrimitiveElement pe,
144
 
                                QPainter *p,
145
 
                                const QRect &r,
146
 
                                const QColorGroup &cg,
147
 
                                SFlags flags, const QStyleOption& opt ) const
148
 
{
149
 
    switch( pe ) {
150
 
    case PE_HeaderSection:
151
 
        if ( flags & Style_Sunken )
152
 
            flags ^= Style_Sunken | Style_Raised;
153
 
        // fall through
154
 
    case PE_ButtonBevel:
155
 
    case PE_ButtonCommand:
156
 
            drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
157
 
                             (flags & (Style_Sunken|Style_On|Style_Down)),
158
 
                             TRUE, !(flags & Style_Raised) );
159
 
            break;
160
 
    case PE_PanelMenuBar:
161
 
        drawMetalFrame( p, r.x(), r.y(), r.width(), r.height() );
162
 
        break;
163
 
    case PE_ScrollBarAddLine:   
164
 
        drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
165
 
                         flags & Style_Down, !( flags & Style_Horizontal ) );
166
 
        drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowRight :PE_ArrowDown,
167
 
                       p, r, cg, flags, opt );
168
 
        break;
169
 
    case PE_ScrollBarSubLine:
170
 
        drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
171
 
                         flags & Style_Down, !( flags & Style_Horizontal ) );
172
 
        drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp,
173
 
                       p, r, cg, flags, opt );
174
 
        break;
175
 
 
176
 
        
177
 
    case PE_ScrollBarSlider:
178
 
        drawMetalButton( p, r.x(), r.y(), r.width(), r.height(), FALSE,
179
 
                         flags & Style_Horizontal );
180
 
        break;
181
 
    default:
182
 
        QMuseWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt );
183
 
        break;
184
 
    }
185
 
}
186
 
 
187
 
void MuseStyle::drawControl( ControlElement element,
188
 
                              QPainter *p,
189
 
                              const QWidget *widget,
190
 
                              const QRect &r,
191
 
                              const QColorGroup &cg,
192
 
                              SFlags how,
193
 
                              const QStyleOption& opt ) const
194
 
{
195
 
    switch( element ) {
196
 
    case CE_PushButton:
197
 
        {
198
 
            const QPushButton *btn;
199
 
            btn = (const QPushButton*)widget;
200
 
            int x1, y1, x2, y2;
201
 
        
202
 
            r.coords( &x1, &y1, &x2, &y2 );
203
 
        
204
 
            p->setPen( cg.foreground() );
205
 
            p->setBrush( QBrush(cg.button(), NoBrush) );
206
 
 
207
 
        
208
 
            QBrush fill;
209
 
            if ( btn->isDown() )
210
 
                fill = cg.brush( QColorGroup::Mid );
211
 
            else if ( btn->isOn() )
212
 
                fill = QBrush( cg.mid(), Dense4Pattern );
213
 
            else
214
 
                fill = cg.brush( QColorGroup::Button );
215
 
        
216
 
            if ( btn->isDefault() ) {
217
 
                QPointArray a;
218
 
                a.setPoints( 9,
219
 
                             x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
220
 
                             x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
221
 
                p->setPen( Qt::black );
222
 
                p->drawPolyline( a );
223
 
                x1 += 2;
224
 
                y1 += 2;
225
 
                x2 -= 2;
226
 
                y2 -= 2;
227
 
            }
228
 
            SFlags flags = Style_Default;
229
 
            if ( btn->isOn() )
230
 
                flags |= Style_On;
231
 
            if ( btn->isDown() )
232
 
                flags |= Style_Down;
233
 
            if ( !btn->isFlat() && !btn->isDown() )
234
 
                flags |= Style_Raised;
235
 
            drawPrimitive( PE_ButtonCommand, p,
236
 
                           QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1),
237
 
                           cg, flags, opt );
238
 
        
239
 
            if ( btn->isMenuButton() ) {
240
 
                flags = Style_Default;
241
 
                if ( btn->isEnabled() )
242
 
                    flags |= Style_Enabled;
243
 
                
244
 
                int dx = ( y1 - y2 - 4 ) / 3;
245
 
                drawPrimitive( PE_ArrowDown, p,
246
 
                               QRect(x2 - dx, dx, y1, y2 - y1),
247
 
                               cg, flags, opt );
248
 
            }
249
 
            if ( p->brush().style() != NoBrush )
250
 
                p->setBrush( NoBrush );
251
 
            break;
252
 
        }
253
 
    case CE_PushButtonLabel:
254
 
        {
255
 
            const QPushButton *btn;
256
 
            btn = (const QPushButton*)widget;
257
 
            int x, y, w, h;
258
 
            r.rect( &x, &y, &w, &h );
259
 
        
260
 
            int x1, y1, x2, y2;
261
 
            r.coords( &x1, &y1, &x2, &y2 );
262
 
            int dx = 0;
263
 
            int dy = 0;
264
 
            if ( btn->isMenuButton() )
265
 
                dx = ( y2 - y1 ) / 3;
266
 
            if ( btn->isOn() || btn->isDown() ) {
267
 
                dx--;
268
 
                dy--;
269
 
            }
270
 
            if ( dx || dy )
271
 
                p->translate( dx, dy );
272
 
            x += 2;
273
 
            y += 2;
274
 
            w -= 4;
275
 
            h -= 4;
276
 
            drawItem( p, QRect( x, y, w, h ),
277
 
                      AlignCenter|ShowPrefix,
278
 
                      cg, btn->isEnabled(),
279
 
                      btn->pixmap(), btn->text(), -1,
280
 
                      (btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() );
281
 
            if ( dx || dy )
282
 
                p->translate( -dx, -dy );
283
 
            break;
284
 
        }
285
 
    default:
286
 
        QMuseWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
287
 
        break;
288
 
    }
289
 
}
290
 
void MuseStyle::drawComplexControl( ComplexControl cc,
291
 
                                     QPainter *p,
292
 
                                     const QWidget *widget,
293
 
                                     const QRect &r,
294
 
                                     const QColorGroup &cg,
295
 
                                     SFlags how,
296
 
                                     SCFlags sub,
297
 
                                     SCFlags subActive,
298
 
                                     const QStyleOption& opt ) const
299
 
{
300
 
    switch ( cc ) {
301
 
    case CC_Slider:
302
 
        {
303
 
            const QSlider *slider = ( const QSlider* ) widget;
304
 
            QRect handle = querySubControlMetrics( CC_Slider, widget,
305
 
                                                   SC_SliderHandle, opt);
306
 
            if ( sub & SC_SliderGroove )
307
 
                QMuseWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how,
308
 
                                                   SC_SliderGroove, subActive, opt );
309
 
            if ( (sub & SC_SliderHandle) && handle.isValid() )
310
 
                drawMetalButton( p, handle.x(), handle.y(), handle.width(),
311
 
                                 handle.height(), FALSE,
312
 
                                 slider->orientation() == QSlider::Horizontal);
313
 
            break;
314
 
        }
315
 
    case CC_ComboBox:
316
 
        {
317
 
            // not exactly correct...
318
 
            const QComboBox *cmb = ( const QComboBox* ) widget;
319
 
        
320
 
            qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), cg, TRUE,
321
 
                           cmb->isEnabled() ? &cg.brush( QColorGroup::Base ) :
322
 
                                              &cg.brush( QColorGroup::Background ) );
323
 
            drawMetalButton( p, r.x() + r.width() - 2 - 16, r.y() + 2, 16, r.height() - 4,
324
 
                             how & Style_Sunken, TRUE );
325
 
            drawPrimitive( PE_ArrowDown, p,
326
 
                           QRect( r.x() + r.width() - 2 - 16 + 2,
327
 
                                  r.y() + 2 + 2, 16 - 4, r.height() - 4 -4 ),
328
 
                           cg,
329
 
                           cmb->isEnabled() ? Style_Enabled : Style_Default,
330
 
                           opt );
331
 
            break;
332
 
        }
333
 
    default:
334
 
        QMuseWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how, sub, subActive,
335
 
                                           opt );
336
 
        break;
337
 
    }
338
 
}
339
 
                
340
 
 
341
 
/*!
342
 
  Draw a metallic button, sunken if \a sunken is TRUE, horizontal if
343
 
  /a horz is TRUE.
344
 
*/
345
 
 
346
 
void MuseStyle::drawMetalButton( QPainter *p, int x, int y, int w, int h,
347
 
                                  bool sunken, bool horz, bool flat  ) const
348
 
{
349
 
 
350
 
    drawMetalFrame( p, x, y, w, h );
351
 
    drawMetalGradient( p, x, y, w, h, sunken, horz, flat );
352
 
}
353
 
 
354
 
 
355
 
 
356
 
 
357
 
void MuseStyle::drawMetalFrame( QPainter *p, int x, int y, int w, int h ) const
358
 
{
359
 
    QColor top1("#878769691515");
360
 
    QColor top2("#C6C6B4B44949");
361
 
 
362
 
    QColor bot2("#70705B5B1414");
363
 
    QColor bot1("#56564A4A0E0E"); //first from the bottom
364
 
 
365
 
 
366
 
    int x2 = x + w - 1;
367
 
    int y2 = y + h - 1;
368
 
 
369
 
    //frame:
370
 
 
371
 
    p->setPen( top1 );
372
 
    p->drawLine( x, y2, x, y );
373
 
    p->drawLine( x, y, x2-1, y );
374
 
    p->setPen( top2 );
375
 
    p->drawLine( x+1, y2 -1, x+1, y+1 );
376
 
    p->drawLine( x+1, y+1 , x2-2, y+1 );
377
 
 
378
 
    p->setPen( bot1 );
379
 
    p->drawLine( x+1, y2, x2, y2 );
380
 
    p->drawLine( x2, y2, x2, y );
381
 
    p->setPen( bot2 );
382
 
    p->drawLine( x+1, y2-1, x2-1, y2-1 );
383
 
    p->drawLine( x2-1, y2-1, x2-1, y+1 );
384
 
 
385
 
 
386
 
}
387
 
 
388
 
 
389
 
void MuseStyle::drawMetalGradient( QPainter *p, int x, int y, int w, int h,
390
 
                                    bool sunken, bool horz, bool flat  ) const
391
 
 
392
 
{
393
 
    QColor highlight("#E8E8DDDD6565");
394
 
    QColor subh1("#CECEBDBD5151");
395
 
    QColor subh2("#BFBFACAC4545");
396
 
 
397
 
    QColor topgrad("#B9B9A5A54040");
398
 
    QColor botgrad("#89896C6C1A1A");
399
 
 
400
 
 
401
 
 
402
 
    if ( flat && !sunken ) {
403
 
            p->fillRect( x + 2, y + 2, w - 4,h -4, topgrad );
404
 
    } else {
405
 
        // highlight:
406
 
        int i = 0;
407
 
        int x1 = x + 2;
408
 
        int y1 = y + 2;
409
 
        int x2 = x + w - 1;
410
 
        int y2 = y + h - 1;
411
 
        if ( horz )
412
 
            x2 = x2 - 2;
413
 
        else
414
 
            y2 = y2 - 2;
415
 
        
416
 
#define DRAWLINE if (horz) \
417
 
                    p->drawLine( x1, y1+i, x2, y1+i ); \
418
 
                 else \
419
 
                    p->drawLine( x1+i, y1, x1+i, y2 ); \
420
 
                 i++;
421
 
 
422
 
        if ( !sunken ) {
423
 
            p->setPen( highlight );
424
 
            DRAWLINE;
425
 
            DRAWLINE;
426
 
            p->setPen( subh1 );
427
 
            DRAWLINE;
428
 
            p->setPen( subh2 );
429
 
            DRAWLINE;
430
 
        }
431
 
        // gradient:
432
 
        int ng = (horz ? h : w) - 8; // how many lines for the gradient?
433
 
        
434
 
        int h1, h2, s1, s2, v1, v2;
435
 
        if ( !sunken ) {
436
 
            topgrad.hsv( &h1, &s1, &v1 );
437
 
            botgrad.hsv( &h2, &s2, &v2 );
438
 
        } else {
439
 
            botgrad.hsv( &h1, &s1, &v1 );
440
 
            topgrad.hsv( &h2, &s2, &v2 );
441
 
        }
442
 
        
443
 
        if ( ng > 1 ) { 
444
 
            for ( int j =0; j < ng; j++ ) {
445
 
                p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1),
446
 
                                   s1 + ((s2-s1)*j)/(ng-1),
447
 
                                   v1 + ((v2-v1)*j)/(ng-1),  QColor::Hsv ) );
448
 
                DRAWLINE;
449
 
            }
450
 
        } else if ( ng == 1 ) {
451
 
            p->setPen( QColor((h1+h2)/2, (s1+s2)/2, (v1+v2)/2, QColor::Hsv) );
452
 
            DRAWLINE;
453
 
        }
454
 
        if ( sunken ) {
455
 
            p->setPen( subh2 );
456
 
            DRAWLINE;
457
 
        
458
 
            p->setPen( subh1 );
459
 
            DRAWLINE;
460
 
        
461
 
            p->setPen( highlight );
462
 
            DRAWLINE;
463
 
            DRAWLINE;
464
 
        }
465
 
    }
466
 
}
467
 
 
468
 
int MuseStyle::pixelMetric( PixelMetric metric, const QWidget *w ) const
469
 
{
470
 
    switch ( metric ) {
471
 
    case PM_MenuBarFrameWidth:
472
 
        return 2;
473
 
    default:
474
 
        return QMuseWindowsStyle::pixelMetric( metric, w );
475
 
    }
476
 
}