~ubuntu-branches/ubuntu/wily/muse/wily-proposed

« back to all changes in this revision

Viewing changes to muse/widgets/meter.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2011-12-03 17:12:54 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20111203171254-28b1j4lpb46r5jtl
Tags: 2.0~rc1-1
* New upstream RC release.
* Refresh patches, remove those patches not needed anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
//  MusE
3
3
//  Linux Music Editor
4
4
//  $Id: meter.cpp,v 1.4.2.2 2009/05/03 04:14:00 terminator356 Exp $
 
5
//  redesigned by oget on 2011/08/15
5
6
//
6
7
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
 
8
//  (C) Copyright 2011 Orcan Ogetbil (ogetbilo at sf.net)
 
9
//  (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net)
 
10
//
 
11
//  This program is free software; you can redistribute it and/or
 
12
//  modify it under the terms of the GNU General Public License
 
13
//  as published by the Free Software Foundation; version 2 of
 
14
//  the License, or (at your option) any later version.
 
15
//
 
16
//  This program is distributed in the hope that it will be useful,
 
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
//  GNU General Public License for more details.
 
20
//
 
21
//  You should have received a copy of the GNU General Public License
 
22
//  along with this program; if not, write to the Free Software
 
23
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
24
//
7
25
//=========================================================
8
26
 
9
 
#include <stdio.h>
10
27
#include <cmath>
11
28
 
12
29
#include <QMouseEvent>
14
31
#include <QResizeEvent>
15
32
 
16
33
#include "meter.h"
 
34
#include "utils.h"
17
35
#include "gconfig.h"
18
36
#include "fastlog.h"
19
37
 
 
38
// Just an experiment. Some undesirable effects, see below...
 
39
//#define _USE_CLIPPER 1 
 
40
 
 
41
namespace MusEGui {
 
42
 
20
43
//---------------------------------------------------------
21
44
//   Meter
22
45
//---------------------------------------------------------
27
50
      setBackgroundRole(QPalette::NoRole);
28
51
      setAttribute(Qt::WA_NoSystemBackground);
29
52
      setAttribute(Qt::WA_StaticContents);
30
 
      // This is absolutely required for speed! Otherwise painfully slow because we get 
31
 
      //  full rect paint events even on small scrolls! See help on QPainter::scroll().
32
 
      setAttribute(Qt::WA_OpaquePaintEvent);
33
 
      
 
53
      // This is absolutely required for speed! Otherwise painfully slow because of full background 
 
54
      //  filling, even when requesting small udpdates! Background is drawn by us. (Just small corners.)
 
55
      setAttribute(Qt::WA_OpaquePaintEvent);    
 
56
      //setFrameStyle(QFrame::Raised | QFrame::StyledPanel);
 
57
 
34
58
      mtype = type;
35
59
      overflow    = false;
 
60
      cur_yv      = -1;     // Flag as -1 to initialize in paint.
 
61
      last_yv     = 0;
 
62
      cur_ymax    = 0;
 
63
      last_ymax   = 0;
36
64
      val         = 0.0;
37
65
      maxVal      = 0.0;
38
 
      minScale    = mtype == DBMeter ? config.minMeter : 0.0;      // min value in dB or int
 
66
      minScale    = mtype == DBMeter ? MusEGlobal::config.minMeter : 0.0;      // min value in dB or int
39
67
      maxScale    = mtype == DBMeter ? 10.0 : 127.0;
40
68
      yellowScale = -10;
41
69
      redScale    = 0;
42
70
      setLineWidth(0);
43
71
      setMidLineWidth(0);
 
72
 
 
73
      // rounding radii
 
74
      xrad = 4;
 
75
      yrad = 4;
 
76
 
 
77
      dark_red_end = QColor(0x8e0000);
 
78
      dark_red_begin = QColor(0x8e3800);
 
79
 
 
80
      dark_yellow_end = QColor(0x8e6800);
 
81
      dark_yellow_center = QColor(0x8e8e00);
 
82
      dark_yellow_begin = QColor(0x6a8400);
 
83
 
 
84
      dark_green_end = QColor(0x467800);
 
85
      dark_green_begin = QColor(0x007000);
 
86
 
 
87
      light_red_end = QColor(0xff0000);
 
88
      light_red_begin = QColor(0xdd8800);
 
89
 
 
90
      light_yellow_end = QColor(0xddcc00);
 
91
      light_yellow_center = QColor(0xffff00);
 
92
      light_yellow_begin = QColor(0xddff00);
 
93
 
 
94
      light_green_end = QColor(0x88ff00);
 
95
      light_green_begin = QColor(0x00ff00);
 
96
 
 
97
      mask_center = QColor(225, 225, 225, 64);
 
98
      mask_edge = QColor(30, 30, 30, 64);
 
99
 
 
100
      separator_color = QColor(0x666666);
 
101
      peak_color = QColor(0xeeeeee);
 
102
 
 
103
      darkGradGreen.setColorAt(1, dark_green_begin);
 
104
      darkGradGreen.setColorAt(0, dark_green_end);
 
105
 
 
106
      darkGradYellow.setColorAt(1, dark_yellow_begin);
 
107
      darkGradYellow.setColorAt(0.5, dark_yellow_center);
 
108
      darkGradYellow.setColorAt(0, dark_yellow_end);
 
109
 
 
110
      darkGradRed.setColorAt(1, dark_red_begin);
 
111
      darkGradRed.setColorAt(0, dark_red_end);
 
112
 
 
113
      lightGradGreen.setColorAt(1, light_green_begin);
 
114
      lightGradGreen.setColorAt(0, light_green_end);
 
115
 
 
116
      lightGradYellow.setColorAt(1, light_yellow_begin);
 
117
      lightGradYellow.setColorAt(0.5, light_yellow_center);
 
118
      lightGradYellow.setColorAt(0, light_yellow_end);
 
119
 
 
120
      lightGradRed.setColorAt(1, light_red_begin);
 
121
      lightGradRed.setColorAt(0, light_red_end);
 
122
 
 
123
      maskGrad.setColorAt(0, mask_edge);
 
124
      maskGrad.setColorAt(0.5, mask_center);
 
125
      maskGrad.setColorAt(1, mask_edge);
 
126
 
44
127
      }
45
128
 
46
129
//---------------------------------------------------------
70
153
        }
71
154
      }  
72
155
      
 
156
      double range = maxScale - minScale;
 
157
      int fw = frameWidth();
 
158
      int w  = width() - 2*fw;
 
159
      int h  = height() - 2*fw;
 
160
      QRect udRect;
 
161
      bool udPeak = false;
 
162
      
73
163
      if(maxVal != max)
74
164
      {
75
165
        maxVal = max;
 
166
        if(mtype == DBMeter)
 
167
          cur_ymax = maxVal == 0 ? fw : int(((maxScale - (MusECore::fast_log10(maxVal) * 20.0)) * h)/range);
 
168
        else
 
169
          cur_ymax = maxVal == 0 ? fw : int(((maxScale - maxVal) * h)/range);
 
170
        if(cur_ymax > h) cur_ymax = h;
 
171
        // Not using regions. Just lump them together.
 
172
        udRect = QRect(fw, last_ymax, w, 1) | QRect(fw, cur_ymax, w, 1);
 
173
        //printf("Meter::setVal peak cur_ymax:%d last_ymax:%d\n", cur_ymax, last_ymax); 
 
174
        last_ymax = cur_ymax; 
76
175
        ud = true;
 
176
        udPeak = true;
77
177
      }
78
178
      
79
 
      if(ud)
80
 
        update();
 
179
      if(ud)        
 
180
      {
 
181
        if(mtype == DBMeter)
 
182
          cur_yv = val == 0 ? h : int(((maxScale - (MusECore::fast_log10(val) * 20.0)) * h)/range);
 
183
        else
 
184
          cur_yv = val == 0 ? h : int(((maxScale - val) * h)/range);
 
185
        if(cur_yv > h) cur_yv = h;
 
186
 
 
187
        //printf("Meter::setVal cur_yv:%d last_yv:%d\n", cur_yv, last_yv); 
 
188
        int y1, y2;
 
189
        if(last_yv < cur_yv) { y1 = last_yv; y2 = cur_yv; } else { y1 = cur_yv; y2 = last_yv; }
 
190
        last_yv = cur_yv;
 
191
        
 
192
        if(udPeak)
 
193
          update(udRect | QRect(fw, y1, w, y2 - y1 + 1)); 
 
194
          //repaint(udRect | QRect(fw, y1, w, y2 - y1 + 1)); 
 
195
        else
 
196
          update(QRect(fw, y1, w, y2 - y1 + 1)); 
 
197
          //repaint(QRect(fw, y1, w, y2 - y1 + 1)); 
 
198
      }
81
199
    }
 
200
 
82
201
//---------------------------------------------------------
83
202
//   resetPeaks
84
203
//    reset peak and overflow indicator
88
207
      {
89
208
      maxVal   = val;
90
209
      overflow = val > 0.0;
91
 
      update();
 
210
      cur_yv = -1;  // Force re-initialization.
 
211
      update();               
92
212
      }
93
213
 
94
214
//---------------------------------------------------------
99
219
      {
100
220
      minScale = min;
101
221
      maxScale = max;
 
222
      cur_yv = -1;  // Force re-initialization.
102
223
      update();
103
224
      }
104
225
 
106
227
//   paintEvent
107
228
//---------------------------------------------------------
108
229
 
109
 
void Meter::paintEvent(QPaintEvent* /*ev*/)
 
230
void Meter::paintEvent(QPaintEvent* ev)
110
231
      {
111
 
      // TODO: Could make better use of event rectangle, for speed.
112
 
      
 
232
      // For some reason upon resizing we get double calls here and in resizeEvent.
 
233
 
113
234
      QPainter p(this);
114
 
      
 
235
      p.setRenderHint(QPainter::Antialiasing);  
 
236
 
115
237
      double range = maxScale - minScale;
116
 
 
117
238
      int fw = frameWidth();
118
239
      int w  = width() - 2*fw;
119
240
      int h  = height() - 2*fw;
120
 
      int yv;
 
241
      const QRect& rect = ev->rect();
 
242
      //printf("Meter::paintEvent rx:%d ry:%d rw:%d rh:%d w:%d h:%d\n", rect.x(), rect.y(), rect.width(), rect.height(), w, h); 
 
243
 
 
244
      QPainterPath drawingPath, updatePath, finalPath, cornerPath;
 
245
      //bool updFull = false;
121
246
      
122
 
      if(mtype == DBMeter)
123
 
        yv = val == 0 ? h : int(((maxScale - (fast_log10(val) * 20.0)) * h)/range);
 
247
      // Initialize. Can't do in ctor, must be done after layouts have been done. Most reliable to do it here.
 
248
      if(cur_yv == -1) 
 
249
      {
 
250
        if(mtype == DBMeter)
 
251
        {  
 
252
          cur_yv = val == 0 ? h : int(((maxScale - (MusECore::fast_log10(val) * 20.0)) * h)/range);
 
253
          cur_ymax = maxVal == 0 ? fw : int(((maxScale - (MusECore::fast_log10(maxVal) * 20.0)) * h)/range);
 
254
        }  
 
255
        else
 
256
        {  
 
257
          cur_yv = val == 0 ? h : int(((maxScale - val) * h)/range);
 
258
          cur_ymax = maxVal == 0 ? fw : int(((maxScale - maxVal) * h)/range);
 
259
        }  
 
260
        if(cur_yv > h) cur_yv = h;
 
261
        last_yv = cur_yv;
 
262
        if(cur_ymax > h) cur_ymax = h;
 
263
        last_ymax = cur_ymax;
 
264
        //updFull = true;
 
265
        updatePath.addRect(fw, fw, w, h);  // Update the whole thing
 
266
      }
124
267
      else
125
 
        yv = val == 0 ? h : int(((maxScale - val) * h)/range);
126
 
      
127
 
      if(yv > h) yv = h;
 
268
        updatePath.addRect(rect.x(), rect.y(), rect.width(), rect.height());  // Update only the requested rectangle
 
269
      
 
270
      drawingPath.addRoundedRect(fw, fw, w, h, xrad, yrad);  // The actual desired shape of the meter
 
271
      finalPath = drawingPath & updatePath;
 
272
 
 
273
      // Draw corners as normal background colour.
 
274
      cornerPath = updatePath - finalPath;            // Elegantly simple. Path subtraction! Wee...
 
275
      if(!cornerPath.isEmpty())
 
276
        p.fillPath(cornerPath, palette().window());  
 
277
      
 
278
#ifdef _USE_CLIPPER
 
279
      p.setClipPath(finalPath);       //  Meh, nice but not so good. Clips at edge so antialising has no effect! Can it be done ?
 
280
#endif
128
281
      
129
282
      // Draw the red, green, and yellow sections.
130
 
      drawVU(p, w, h, yv);
 
283
      drawVU(p, rect, finalPath, cur_yv);
131
284
      
132
285
      // Draw the peak white line.
133
 
      int ymax;
134
 
      if(mtype == DBMeter)
135
 
        ymax = maxVal == 0 ? 0 : int(((maxScale - (fast_log10(maxVal) * 20.0)) * h)/range);
136
 
      else
137
 
        ymax = maxVal == 0 ? 0 : int(((maxScale - maxVal) * h)/range);
138
 
      p.setPen(Qt::white);
139
 
      p.drawLine(0, ymax, w, ymax);
 
286
      //if(updFull || (cur_ymax >= rect.y() && cur_ymax < rect.height()))
 
287
      {
 
288
        p.setRenderHint(QPainter::Antialiasing, false);  // No antialiasing. Makes the line fuzzy, double height, or not visible at all.
 
289
 
 
290
        //p.setPen(peak_color);
 
291
        //p.drawLine(fw, cur_ymax, w, cur_ymax); // Undesirable. Draws outside the top rounded corners.
 
292
        //
 
293
        //QPainterPath path; path.moveTo(fw, cur_ymax); path.lineTo(w, cur_ymax);  // ? Didn't work. No line at all.
 
294
        //p.drawPath(path & finalPath);
 
295
        QPainterPath path; path.addRect(fw, cur_ymax, w, 1); path &= finalPath;
 
296
        if(!path.isEmpty())
 
297
          p.fillPath(path, QBrush(peak_color));
 
298
      }
 
299
      
 
300
      // Draw the transparent layer on top of everything to give a 3d look
 
301
      p.setRenderHint(QPainter::Antialiasing);  
 
302
      maskGrad.setStart(QPointF(fw, fw));
 
303
      maskGrad.setFinalStop(QPointF(w, fw));
 
304
#ifdef _USE_CLIPPER
 
305
      p.fillRect(rect, QBrush(maskGrad));
 
306
#else
 
307
      //QPainterPath path; path.addRect(fw, fw, w);
 
308
      //p.fillPath(finalPath & path, QBrush(maskGrad));
 
309
      p.fillPath(finalPath, QBrush(maskGrad));
 
310
#endif      
 
311
      
140
312
      }
141
313
 
142
314
//---------------------------------------------------------
143
315
//   drawVU
144
316
//---------------------------------------------------------
145
317
 
146
 
void Meter::drawVU(QPainter& p, int w, int h, int yv)
 
318
void Meter::drawVU(QPainter& p, const QRect& rect, const QPainterPath& drawPath, int yv)
147
319
{
148
 
      if(mtype == DBMeter)
 
320
      int fw = frameWidth();
 
321
      int w  = width() - 2*fw;
 
322
      int h  = height() - 2*fw;
 
323
      
 
324
      // Test OK. We are passed small rectangles on small value changes.
 
325
      //printf("Meter::drawVU rx:%d ry:%d rw:%d rh:%d w:%d h:%d\n", rect.x(), rect.y(), rect.width(), rect.height(), w, h); 
 
326
 
 
327
      QRect pr(0, 0,  w, 0);
 
328
      if(mtype == DBMeter)     // Meter type is dB...
149
329
      {
150
330
        double range = maxScale - minScale;
151
331
        int y1 = int((maxScale - redScale) * h / range);
152
332
        int y2 = int((maxScale - yellowScale) * h / range);
153
 
        
 
333
 
 
334
        darkGradGreen.setStart(QPointF(fw, y2));
 
335
        darkGradGreen.setFinalStop(QPointF(fw, h));
 
336
        darkGradYellow.setStart(QPointF(fw, y1));
 
337
        darkGradYellow.setFinalStop(QPointF(fw, y2));
 
338
        darkGradRed.setStart(QPointF(fw, fw));
 
339
        darkGradRed.setFinalStop(QPointF(fw, y1));
 
340
 
 
341
        lightGradGreen.setStart(QPointF(fw, y2));
 
342
        lightGradGreen.setFinalStop(QPointF(fw, h));
 
343
        lightGradYellow.setStart(QPointF(fw, y1));
 
344
        lightGradYellow.setFinalStop(QPointF(fw, y2));
 
345
        lightGradRed.setStart(QPointF(fw, fw));
 
346
        lightGradRed.setFinalStop(QPointF(fw, y1));
 
347
 
 
348
#ifdef _USE_CLIPPER
154
349
        if(yv < y1)
155
350
        {
156
351
          // Red section:
157
 
          p.fillRect(0, 0,  w, yv,        QBrush(0x8e0000));     // dark red  
158
 
          p.fillRect(0, yv, w, y1-yv,     QBrush(0xff0000));     // light red
 
352
          pr.setTop(fw); pr.setHeight(yv);
 
353
          p.fillRect(pr, QBrush(darkGradRed));     // dark red  
 
354
          pr.setTop(yv); pr.setHeight(y1-yv);
 
355
          p.fillRect(pr & rect, QBrush(lightGradRed));     // light red
159
356
          
160
357
          // Yellow section:
161
 
          p.fillRect(0, y1, w, y2-y1,     QBrush(0xffff00));     // light yellow
 
358
          pr.setTop(y1); pr.setHeight(y2-y1);
 
359
          p.fillRect(pr & rect, QBrush(lightGradYellow));     // light yellow
162
360
          
163
361
          // Green section:
164
 
          p.fillRect(0, y2, w, h-y2,      QBrush(0x00ff00));     // light green
 
362
          pr.setTop(y2); pr.setHeight(h-y2);
 
363
          p.fillRect(pr & rect, QBrush(lightGradGreen));     // light green
165
364
        }
166
365
        else
167
366
        if(yv < y2)
168
367
        {
169
368
          // Red section:
170
 
          p.fillRect(0, 0,  w, y1,        QBrush(0x8e0000));     // dark red  
 
369
          pr.setTop(fw); pr.setHeight(y1);
 
370
          p.fillRect(pr & rect, QBrush(darkGradRed));     // dark red  
171
371
          
172
372
          // Yellow section:
173
 
          p.fillRect(0, y1, w, yv-y1,     QBrush(0x8e8e00));     // dark yellow
174
 
          p.fillRect(0, yv, w, y2-yv,     QBrush(0xffff00));     // light yellow
 
373
          pr.setTop(y1); pr.setHeight(yv-y1);
 
374
          p.fillRect(pr & rect, QBrush(darkGradYellow));     // dark yellow
 
375
          pr.setTop(yv); pr.setHeight(y2-yv);
 
376
          p.fillRect(pr & rect, QBrush(lightGradYellow));     // light yellow
175
377
          
176
378
          // Green section:
177
 
          p.fillRect(0, y2, w, h-y2,      QBrush(0x00ff00));     // light green
 
379
          pr.setTop(y2); pr.setHeight(h-y2);
 
380
          p.fillRect(pr & rect, QBrush(lightGradGreen));     // light green
178
381
        }
179
382
        else
180
383
        //if(yv <= y3)   
181
384
        {
182
385
          // Red section:
183
 
          p.fillRect(0, 0,  w, y1,        QBrush(0x8e0000));     // dark red  
 
386
          pr.setTop(fw); pr.setHeight(y1);
 
387
          p.fillRect(pr & rect, QBrush(darkGradRed));     // dark red  
184
388
          
185
389
          // Yellow section:
186
 
          p.fillRect(0, y1, w, y2-y1,     QBrush(0x8e8e00));     // dark yellow
 
390
          pr.setTop(y1); pr.setHeight(y2-y1);
 
391
          p.fillRect(pr & rect, QBrush(darkGradYellow));     // dark yellow
187
392
          
188
393
          // Green section:
189
 
          p.fillRect(0, y2, w, yv-y2,     QBrush(0x007000));     // dark green
190
 
          p.fillRect(0, yv, w, h-yv,      QBrush(0x00ff00));     // light green
 
394
          pr.setTop(y2); pr.setHeight(yv-y2);
 
395
          p.fillRect(pr & rect, QBrush(darkGradGreen));     // dark green
 
396
          pr.setTop(yv); pr.setHeight(h-yv);
 
397
          p.fillRect(pr & rect, QBrush(lightGradGreen));     // light green
191
398
        }
192
399
      }  
193
 
      else
 
400
      else     // Meter type is linear...
194
401
      {
195
 
        p.fillRect(0, 0,  w, yv,   QBrush(0x007000));   // dark green
196
 
        p.fillRect(0, yv, w, h-yv, QBrush(0x00ff00));   // light green
 
402
        pr.setTop(fw); pr.setHeight(yv);
 
403
        p.fillRect(pr & rect, QBrush(darkGradGreen));   // dark green
 
404
        pr.setTop(yv); pr.setHeight(h-yv);
 
405
        p.fillRect(pr & rect, QBrush(lightGradGreen));   // light green
197
406
      }
 
407
 
 
408
#else   // NOT    _USE_CLIPPER
 
409
 
 
410
        if(yv < y1)
 
411
        {
 
412
          // Red section:
 
413
          {
 
414
            QPainterPath path; path.addRect(fw, fw, w, yv); path &= drawPath;
 
415
            if(!path.isEmpty())
 
416
              p.fillPath(path, QBrush(darkGradRed));       // dark red
 
417
          }
 
418
          {
 
419
            QPainterPath path; path.addRect(fw, yv, w, y1-yv); path &= drawPath;
 
420
            if(!path.isEmpty())
 
421
              p.fillPath(path, QBrush(lightGradRed));       // light red
 
422
          }
 
423
          
 
424
          // Yellow section:
 
425
          {
 
426
            QPainterPath path; path.addRect(fw, y1, w, y2-y1); path &= drawPath;
 
427
            if(!path.isEmpty())
 
428
              p.fillPath(path, QBrush(lightGradYellow));   // light yellow
 
429
          }
 
430
          
 
431
          // Green section:
 
432
          {
 
433
            QPainterPath path; path.addRect(fw, y2, w, h-y2); path &= drawPath;
 
434
            if(!path.isEmpty())
 
435
              p.fillPath(path, QBrush(lightGradGreen));   // light green
 
436
          }
 
437
        }
 
438
        else
 
439
        if(yv < y2)
 
440
        {
 
441
          // Red section:
 
442
          {
 
443
            QPainterPath path; path.addRect(fw, fw, w, y1); path &= drawPath;
 
444
            if(!path.isEmpty())
 
445
              p.fillPath(path, QBrush(darkGradRed));       // dark red
 
446
          }
 
447
          
 
448
          // Yellow section:
 
449
          {
 
450
            QPainterPath path; path.addRect(fw, y1, w, yv-y1); path &= drawPath;
 
451
            if(!path.isEmpty())
 
452
              p.fillPath(path, QBrush(darkGradYellow));   // dark yellow
 
453
          }
 
454
          {
 
455
            QPainterPath path; path.addRect(fw, yv, w, y2-yv); path &= drawPath;
 
456
            if(!path.isEmpty())
 
457
              p.fillPath(path, QBrush(lightGradYellow));   // light yellow
 
458
          }
 
459
          
 
460
          // Green section:
 
461
          {
 
462
            QPainterPath path; path.addRect(fw, y2, w, h-y2); path &= drawPath;
 
463
            if(!path.isEmpty())
 
464
              p.fillPath(path, QBrush(lightGradGreen));   // light green
 
465
          }
 
466
        }
 
467
        else
 
468
        //if(yv <= y3)   
 
469
        {
 
470
          // Red section:
 
471
          {
 
472
            QPainterPath path; path.addRect(fw, fw, w, y1); path &= drawPath;
 
473
            if(!path.isEmpty())
 
474
              p.fillPath(path, QBrush(darkGradRed));       // dark red
 
475
          }
 
476
          
 
477
          // Yellow section:
 
478
          {
 
479
            QPainterPath path; path.addRect(fw, y1, w, y2-y1); path &= drawPath;
 
480
            if(!path.isEmpty())
 
481
              p.fillPath(path, QBrush(darkGradYellow));   // dark yellow
 
482
          }
 
483
          
 
484
          // Green section:
 
485
          {
 
486
            QPainterPath path; path.addRect(fw, y2, w, yv-y2); path &= drawPath;
 
487
            if(!path.isEmpty())
 
488
              p.fillPath(path, QBrush(darkGradGreen));   // dark green
 
489
          }
 
490
          {
 
491
            QPainterPath path; path.addRect(fw, yv, w, h-yv); path &= drawPath;
 
492
            if(!path.isEmpty())
 
493
              p.fillPath(path, QBrush(lightGradGreen));   // light green
 
494
          }
 
495
        }
 
496
 
 
497
        // Separators: 
 
498
        {
 
499
          QRect r(0, y1, w, 1); r &= rect;
 
500
          if(!r.isNull())
 
501
            p.fillRect(r, separator_color);  
 
502
        }  
 
503
        {
 
504
          QRect r(0, y2, w, 1); r &= rect;
 
505
          if(!r.isNull())
 
506
            p.fillRect(r, separator_color);  
 
507
        }  
 
508
      }  
 
509
      else      // Meter type is linear...
 
510
      {
 
511
        darkGradGreen.setStart(QPointF(fw, fw));
 
512
        darkGradGreen.setFinalStop(QPointF(fw, h));
 
513
 
 
514
        lightGradGreen.setStart(QPointF(fw, fw));
 
515
        lightGradGreen.setFinalStop(QPointF(fw, h));
 
516
 
 
517
        {
 
518
          QPainterPath path; path.addRect(fw, fw, w, yv); path &= drawPath;
 
519
          if(!path.isEmpty())
 
520
            p.fillPath(path, QBrush(darkGradGreen));   // dark green
 
521
        }
 
522
        {
 
523
          QPainterPath path; path.addRect(fw, yv, w, h-yv); path &= drawPath;
 
524
          if(!path.isEmpty())
 
525
            p.fillPath(path, QBrush(lightGradGreen));   // light green
 
526
        }
 
527
      }  
 
528
 
 
529
#endif  // NOT   _USE_CLIPPER
 
530
 
198
531
}
199
532
 
200
533
//---------------------------------------------------------
201
534
//   resizeEvent
202
535
//---------------------------------------------------------
203
536
 
204
 
void Meter::resizeEvent(QResizeEvent* /*ev*/)
205
 
    {
206
 
    
 
537
void Meter::resizeEvent(QResizeEvent* ev)
 
538
    {  
 
539
      // For some reason upon resizing we get double calls here and in paintEvent.
 
540
      //printf("Meter::resizeEvent w:%d h:%d\n", ev->size().width(), ev->size().height());  
 
541
      cur_yv = -1;  // Force re-initialization.
 
542
      QFrame::resizeEvent(ev);
 
543
      update();
207
544
    }
208
545
 
209
546
//---------------------------------------------------------
215
552
      emit mousePress();
216
553
      }
217
554
 
 
555
} // namespace MusEGui