diff options
-rw-r--r-- | muse/awl/aslider.cpp | 9 | ||||
-rw-r--r-- | muse/awl/aslider.h | 5 | ||||
-rw-r--r-- | muse/awl/knob.cpp | 7 | ||||
-rw-r--r-- | muse/awl/knob.h | 2 | ||||
-rw-r--r-- | muse/awl/midimeter.cpp | 8 | ||||
-rw-r--r-- | muse/awl/midimeter.h | 2 | ||||
-rw-r--r-- | muse/awl/midimslider.cpp | 4 | ||||
-rw-r--r-- | muse/awl/midimslider.h | 2 | ||||
-rw-r--r-- | muse/awl/mslider.cpp | 128 | ||||
-rw-r--r-- | muse/awl/mslider.h | 4 | ||||
-rw-r--r-- | muse/awl/slider.cpp | 4 | ||||
-rw-r--r-- | muse/awl/slider.h | 2 |
12 files changed, 98 insertions, 79 deletions
diff --git a/muse/awl/aslider.cpp b/muse/awl/aslider.cpp index 95151f18..478390e3 100644 --- a/muse/awl/aslider.cpp +++ b/muse/awl/aslider.cpp @@ -103,15 +103,6 @@ void AbstractSlider::setScaleValueColor(const QColor& c) } //--------------------------------------------------------- -// paintEvent -//--------------------------------------------------------- - -void AbstractSlider::paintEvent(QPaintEvent* ev) - { - paint(ev->rect()); - } - -//--------------------------------------------------------- // wheelEvent //--------------------------------------------------------- diff --git a/muse/awl/aslider.h b/muse/awl/aslider.h index 6650aece..79c4b8bd 100644 --- a/muse/awl/aslider.h +++ b/muse/awl/aslider.h @@ -26,7 +26,7 @@ namespace Awl { //--------------------------------------------------------- // AbstractSlider // -//! The AwlAbstractSlider class provides an double value +//! The AwlAbstractSlider class provides an double value //! within a range // //! The class is designed as a common super class for @@ -52,8 +52,6 @@ class AbstractSlider : public QWidget { Q_PROPERTY(double pageStep READ pageStep WRITE setPageStep) Q_PROPERTY(bool log READ log WRITE setLog) - virtual void paint(const QRect&) = 0; - protected: int _id; double _value; @@ -65,7 +63,6 @@ class AbstractSlider : public QWidget { QColor _scaleValueColor; bool _log; - virtual void paintEvent(QPaintEvent*); virtual void wheelEvent(QWheelEvent*); virtual void keyPressEvent(QKeyEvent*); virtual void valueChange(); diff --git a/muse/awl/knob.cpp b/muse/awl/knob.cpp index 4daafdbc..dd45051a 100644 --- a/muse/awl/knob.cpp +++ b/muse/awl/knob.cpp @@ -148,13 +148,12 @@ void Knob::mouseMoveEvent(QMouseEvent* ev) } //--------------------------------------------------------- -// paint -// r - phys coord system +// paintEvent //--------------------------------------------------------- -void Knob::paint(const QRect& r) +void Knob::paintEvent(QPaintEvent* ev) { - QRect rr(r); + QRect rr(ev->rect()); QPainter p(this); p.setRenderHint(QPainter::Antialiasing, true); diff --git a/muse/awl/knob.h b/muse/awl/knob.h index cd9cf693..b7be932b 100644 --- a/muse/awl/knob.h +++ b/muse/awl/knob.h @@ -47,7 +47,7 @@ class Q_DECL_EXPORT Knob : public AbstractSlider { int _border; QPainterPath* points; - virtual void paint(const QRect& r); + virtual void paintEvent(QPaintEvent*); virtual void mousePressEvent(QMouseEvent*); virtual void mouseReleaseEvent(QMouseEvent*); virtual void mouseMoveEvent(QMouseEvent*); diff --git a/muse/awl/midimeter.cpp b/muse/awl/midimeter.cpp index eaae83ee..312e5efe 100644 --- a/muse/awl/midimeter.cpp +++ b/muse/awl/midimeter.cpp @@ -66,10 +66,10 @@ void MidiMeter::mouseDoubleClickEvent(QMouseEvent*) } //--------------------------------------------------------- -// drawScale +// paintEvent //--------------------------------------------------------- -void MidiMeter::paint(const QRect& r) +void MidiMeter::paintEvent(QPaintEvent* ev) { int pixel = height() - sliderSize().height(); double range = maxValue() - minValue(); @@ -77,7 +77,7 @@ void MidiMeter::paint(const QRect& r) if (_invert) ppos = pixel - ppos; - QRect rr(r); + QRect rr(ev->rect()); QPainter p(this); QColor sc(isEnabled() ? _scaleColor : Qt::gray); @@ -85,7 +85,6 @@ void MidiMeter::paint(const QRect& r) p.setBrush(svc); int h = height(); -// int kw = sliderSize().width(); int kh = sliderSize().height(); //--------------------------------------------------- @@ -96,7 +95,6 @@ void MidiMeter::paint(const QRect& r) int x = 0; int y1 = kh / 2; -// int y2 = h - (ppos + y1); int y3 = h - y1; int mh = h - kh; diff --git a/muse/awl/midimeter.h b/muse/awl/midimeter.h index 80f3c52a..2b0d3518 100644 --- a/muse/awl/midimeter.h +++ b/muse/awl/midimeter.h @@ -37,7 +37,7 @@ class MidiMeter : public Slider double meterval; int _meterWidth; - virtual void paint(const QRect& r); + virtual void paintEvent(QPaintEvent*); protected: virtual void mouseDoubleClickEvent(QMouseEvent*); diff --git a/muse/awl/midimslider.cpp b/muse/awl/midimslider.cpp index d8c66f2d..92325d4a 100644 --- a/muse/awl/midimslider.cpp +++ b/muse/awl/midimslider.cpp @@ -69,7 +69,7 @@ void MidiMeterSlider::mouseDoubleClickEvent(QMouseEvent*) // drawScale //--------------------------------------------------------- -void MidiMeterSlider::paint(const QRect& r) +void MidiMeterSlider::paintEvent(QPaintEvent* ev) { int pixel = height() - sliderSize().height(); double range = maxValue() - minValue(); @@ -77,7 +77,7 @@ void MidiMeterSlider::paint(const QRect& r) if (_invert) ppos = pixel - ppos; - QRect rr(r); + QRect rr(ev->rect()); QPainter p(this); QColor sc(isEnabled() ? _scaleColor : Qt::gray); diff --git a/muse/awl/midimslider.h b/muse/awl/midimslider.h index 15533b09..a2a2bdaf 100644 --- a/muse/awl/midimslider.h +++ b/muse/awl/midimslider.h @@ -37,7 +37,7 @@ class MidiMeterSlider : public Slider double meterval; int _meterWidth; - virtual void paint(const QRect& r); + virtual void paintEvent(QPaintEvent*); protected: virtual void mouseDoubleClickEvent(QMouseEvent*); diff --git a/muse/awl/mslider.cpp b/muse/awl/mslider.cpp index adb199ec..67bfa3c9 100644 --- a/muse/awl/mslider.cpp +++ b/muse/awl/mslider.cpp @@ -31,6 +31,7 @@ namespace Awl { MeterSlider::MeterSlider(QWidget* parent) : VolSlider(parent) { + setAttribute(Qt::WA_NoSystemBackground, true); _channel = 0; yellowScale = -16; //-10; redScale = 0; @@ -78,8 +79,11 @@ void MeterSlider::setMeterVal(int channel, double v, double peak) meterPeak[channel] = peak; mustRedraw = true; } - if (mustRedraw) - update(); + if (mustRedraw) { + int kh = sliderSize().height(); + int mh = height() - kh; + update(20, kh / 2, _meterWidth-1, mh); + } } //--------------------------------------------------------- @@ -95,23 +99,77 @@ void MeterSlider::resetPeaks() } //--------------------------------------------------------- -// paint +// resizeEvent +//--------------------------------------------------------- + +void MeterSlider::resizeEvent(QResizeEvent* /*ev*/) + { + int h = height(); + int kh = sliderSize().height(); + int mh = h - kh; + int mw = _meterWidth / _channel; + + onPm = QPixmap(mw, mh); + offPm = QPixmap(mw, mh); + + double range = maxValue() - minValue(); + int h1 = mh - lrint((maxValue() - redScale) * mh / range); + int h2 = mh - lrint((maxValue() - yellowScale) * mh / range); + + QColor yellowRed; + yellowRed.setHsv(QColor(Qt::yellow).hue()-8, + QColor(Qt::yellow).saturation(), + QColor(Qt::yellow).value()); + QColor yellRedRed; + yellRedRed.setHsv(QColor(Qt::yellow).hue()-16, + QColor(Qt::yellow).saturation(), + QColor(Qt::yellow).value()); + + QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, mh)); + linearGrad.setColorAt(0, Qt::red); + linearGrad.setColorAt(1-(double)(h1-5)/(double)mh, yellRedRed); + linearGrad.setColorAt(1-(double)(h1-6)/(double)mh, yellowRed); + linearGrad.setColorAt(1-(double)h2/(double)mh, Qt::yellow); + linearGrad.setColorAt(1, Qt::green); + + QColor darkYellowRed; + darkYellowRed.setHsv(QColor(Qt::darkYellow).hue()-8, + QColor(Qt::darkYellow).saturation(), + QColor(Qt::darkYellow).value()); + QColor darkYellRedRed; + darkYellRedRed.setHsv(QColor(Qt::darkYellow).hue()-16, + QColor(Qt::darkYellow).saturation(), + QColor(Qt::darkYellow).value()); + QLinearGradient linearDarkGrad(QPointF(0, 0), QPointF(0, mh)); + linearDarkGrad.setColorAt(0, Qt::darkRed); + linearDarkGrad.setColorAt(1-(double)(h1-5)/(double)mh, darkYellRedRed); + linearDarkGrad.setColorAt(1-(double)(h1-6)/(double)mh, darkYellowRed); + linearDarkGrad.setColorAt(1-(double)h2/(double)mh, Qt::darkYellow); + linearDarkGrad.setColorAt(1, Qt::darkGreen); + + QPainter p; + p.begin(&onPm); + p.fillRect(0, 0, mw, mh, linearGrad); + p.end(); + p.begin(&offPm); + p.fillRect(0, 0, mw, mh, linearDarkGrad); + p.end(); + } + +//--------------------------------------------------------- +// paintEvent //--------------------------------------------------------- -void MeterSlider::paint(const QRect& r) +void MeterSlider::paintEvent(QPaintEvent* ev) { - int pixel = height() - sliderSize().height(); + int pixel = height() - sliderSize().height(); double range = maxValue() - minValue(); - int ppos = int(pixel * (_value - minValue()) / range); + int ppos = int(pixel * (_value - minValue()) / range); if (_invert) ppos = pixel - ppos; - QRect rr(r); QPainter p(this); - - QColor sc(isEnabled() ? _scaleColor : Qt::gray); - QColor svc(isEnabled() ? _scaleValueColor : Qt::gray); - p.setBrush(svc); + p.setRenderHint(QPainter::Antialiasing, false); int h = height(); int kh = sliderSize().height(); @@ -122,15 +180,10 @@ void MeterSlider::paint(const QRect& r) int mw = _meterWidth / _channel; int x = 20; - int y1 = kh / 2; - int y2 = h - (ppos + y1); int y3 = h - y1; int mh = h - kh; - int h1 = mh - lrint((maxValue() - redScale) * mh / range); - int h2 = mh - lrint((maxValue() - yellowScale) * mh / range); - p.setPen(QPen(Qt::white, 2)); for (int i = 0; i < _channel; ++i) { int h = mh - (lrint(fast_log10(meterval[i]) * -20.0f * mh / range)); @@ -139,38 +192,8 @@ void MeterSlider::paint(const QRect& r) else if (h > mh) h = mh; - QColor yellowRed; - yellowRed.setHsv(QColor(Qt::yellow).hue()-8, - QColor(Qt::yellow).saturation(), - QColor(Qt::yellow).value()); - QColor yellRedRed; - yellRedRed.setHsv(QColor(Qt::yellow).hue()-16, - QColor(Qt::yellow).saturation(), - QColor(Qt::yellow).value()); - QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, mh)); - linearGrad.setColorAt(0, Qt::red); - linearGrad.setColorAt(1-(double)(h1-5)/(double)mh, yellRedRed); - linearGrad.setColorAt(1-(double)(h1-6)/(double)mh, yellowRed); - linearGrad.setColorAt(1-(double)h2/(double)mh, Qt::yellow); - linearGrad.setColorAt(1, Qt::green); - - QColor darkYellowRed; - darkYellowRed.setHsv(QColor(Qt::darkYellow).hue()-8, - QColor(Qt::darkYellow).saturation(), - QColor(Qt::darkYellow).value()); - QColor darkYellRedRed; - darkYellRedRed.setHsv(QColor(Qt::darkYellow).hue()-16, - QColor(Qt::darkYellow).saturation(), - QColor(Qt::darkYellow).value()); - QLinearGradient linearDarkGrad(QPointF(0, 0), QPointF(0, mh)); - linearDarkGrad.setColorAt(0, Qt::darkRed); - linearDarkGrad.setColorAt(1-(double)(h1-5)/(double)mh, darkYellRedRed); - linearDarkGrad.setColorAt(1-(double)(h1-6)/(double)mh, darkYellowRed); - linearDarkGrad.setColorAt(1-(double)h2/(double)mh, Qt::darkYellow); - linearDarkGrad.setColorAt(1, Qt::darkGreen); - - p.fillRect(x, y1, mw, mh, linearGrad); - p.fillRect(x, y1, mw, mh-h, linearDarkGrad); + p.drawPixmap(x, y1+mh-h, mw, h, onPm, 0, y1+mh-h, mw, h); + p.drawPixmap(x, y1, mw, mh-h, offPm, 0, y1, mw, mh-h); //--------------------------------------------------- // draw peak line @@ -185,10 +208,19 @@ void MeterSlider::paint(const QRect& r) x += mw; } + // optimize common case: + if (ev->rect() == QRect(20, kh/2, _meterWidth-1, mh)) + return; + + QColor sc(isEnabled() ? _scaleColor : Qt::gray); + QColor svc(isEnabled() ? _scaleValueColor : Qt::gray); + p.setBrush(svc); + //--------------------------------------------------- // draw scale //--------------------------------------------------- + int y2 = h - (ppos + y1); p.fillRect(x, y1, _scaleWidth, y2-y1, sc); p.fillRect(x, y2, _scaleWidth, y3-y2, svc); diff --git a/muse/awl/mslider.h b/muse/awl/mslider.h index 7f02eee6..4ae888b1 100644 --- a/muse/awl/mslider.h +++ b/muse/awl/mslider.h @@ -41,9 +41,11 @@ class MeterSlider : public VolSlider std::vector<double> meterPeak; int yellowScale, redScale; int _meterWidth; + QPixmap onPm, offPm; // cached pixmap values virtual void mousePressEvent(QMouseEvent*); - virtual void paint(const QRect& r); + virtual void paintEvent(QPaintEvent*); + virtual void resizeEvent(QResizeEvent*); signals: void meterClicked(); diff --git a/muse/awl/slider.cpp b/muse/awl/slider.cpp index 421c2b99..2505349d 100644 --- a/muse/awl/slider.cpp +++ b/muse/awl/slider.cpp @@ -192,7 +192,7 @@ void Slider::mouseMoveEvent(QMouseEvent* ev) // r - phys coord system //--------------------------------------------------------- -void Slider::paint(const QRect& r) +void Slider::paintEvent(QPaintEvent* ev) { int h = height(); int w = width(); @@ -204,7 +204,7 @@ void Slider::paint(const QRect& r) if ((orient == Qt::Vertical && _invert) || (orient == Qt::Horizontal && !_invert)) ppos = pixel - ppos; - QRect rr(r); + QRect rr(ev->rect()); QPainter p(this); QColor sc(isEnabled() ? _scaleColor : Qt::gray); diff --git a/muse/awl/slider.h b/muse/awl/slider.h index fdc67cc2..8d84849d 100644 --- a/muse/awl/slider.h +++ b/muse/awl/slider.h @@ -48,7 +48,7 @@ class Slider : public AbstractSlider { virtual void mouseReleaseEvent(QMouseEvent*); virtual void mouseMoveEvent(QMouseEvent*); - virtual void paint(const QRect& r); + virtual void paintEvent(QPaintEvent*); void init(); void updateKnob(); |