diff options
Diffstat (limited to 'muse2/muse/widgets')
-rw-r--r-- | muse2/muse/widgets/meter.cpp | 176 | ||||
-rw-r--r-- | muse2/muse/widgets/meter.h | 1 | ||||
-rw-r--r-- | muse2/muse/widgets/slider.cpp | 100 | ||||
-rw-r--r-- | muse2/muse/widgets/slider.h | 3 | ||||
-rw-r--r-- | muse2/muse/widgets/utils.cpp | 52 | ||||
-rw-r--r-- | muse2/muse/widgets/utils.h | 6 | ||||
-rw-r--r-- | muse2/muse/widgets/verticalmeter.cpp | 143 |
7 files changed, 285 insertions, 196 deletions
diff --git a/muse2/muse/widgets/meter.cpp b/muse2/muse/widgets/meter.cpp index f4d907d1..e316a52a 100644 --- a/muse2/muse/widgets/meter.cpp +++ b/muse2/muse/widgets/meter.cpp @@ -30,6 +30,7 @@ #include <QResizeEvent> #include "meter.h" +#include "utils.h" #include "gconfig.h" #include "fastlog.h" @@ -47,7 +48,8 @@ Meter::Meter(QWidget* parent, MeterType type) setAttribute(Qt::WA_StaticContents); // This is absolutely required for speed! Otherwise painfully slow because we get // full rect paint events even on small scrolls! See help on QPainter::scroll(). - setAttribute(Qt::WA_OpaquePaintEvent); + // Commented out for now. Orcan 20110911 + //setAttribute(Qt::WA_OpaquePaintEvent); //setFrameStyle(QFrame::Raised | QFrame::StyledPanel); mtype = type; @@ -61,6 +63,10 @@ Meter::Meter(QWidget* parent, MeterType type) setLineWidth(0); setMidLineWidth(0); + // rounding radii + xrad = 4; + yrad = 4; + dark_red_end = QColor(0x8e0000); dark_red_begin = QColor(0x8e3800); @@ -176,25 +182,24 @@ void Meter::setRange(double min, double max) // paintEvent //--------------------------------------------------------- -void Meter::paintEvent(QPaintEvent* /*ev*/) +void Meter::paintEvent(QPaintEvent* ev) { // TODO: Could make better use of event rectangle, for speed. QPainter p(this); - //p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::Antialiasing); double range = maxScale - minScale; int fw = frameWidth(); + /* int w = width() - 2*fw; int h = height() - 2*fw; - - // FIXME (Orcan): With the event rectangle we get corruption when we toggle the mono/stereo switch. Why? - /* - QRect rect = ev->rect(); - int w = rect.width(); - int h = rect.height(); */ + + QRect rect = ev->rect(); + int w = rect.width() - 2*fw; + int h = rect.height() - 2*fw; int yv; if(mtype == DBMeter) @@ -215,12 +220,15 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) ymax = maxVal == 0 ? 0 : int(((maxScale - maxVal) * h)/range); p.setPen(peak_color); p.drawLine(0, ymax, w, ymax); - + // Draw the transparent layer on top of everything to give a 3d look + QPainterPath round_path = MusEUtil::roundedPath(0, 0, w, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); maskGrad.setStart(QPointF(0, 0)); maskGrad.setFinalStop(QPointF(w, 0)); - p.fillRect(0, 0, w, h, QBrush(maskGrad)); - + p.fillPath(round_path, QBrush(maskGrad)); + } @@ -250,47 +258,67 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) lightGradRed.setStart(QPointF(0, 0)); lightGradRed.setFinalStop(QPointF(0, y1)); + QPainterPath p_top = MusEUtil::roundedPath(0, 0, w, y1, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + QPainterPath p_bottom = MusEUtil::roundedPath(0, y2, w, h-y2, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + if(yv < y1) { + + QPainterPath p_dark_red = MusEUtil::roundedPath(0, 0, w, yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + p_top = p_top.subtracted(p_dark_red); + // Red section: - p.fillRect(0, 0, w, yv, QBrush(darkGradRed)); // dark red - p.fillRect(0, yv, w, y1-yv, QBrush(lightGradRed)); // light red - + p.fillPath(p_dark_red, QBrush(darkGradRed)); // dark red + p.fillPath(p_top, QBrush(lightGradRed)); // light red + // Yellow section: - p.fillRect(0, y1, w, y2-y1, QBrush(lightGradYellow)); // light yellow - + p.fillRect(0, y1, w, y2-y1, QBrush(lightGradYellow)); // light yellow + // Green section: - p.fillRect(0, y2, w, h-y2, QBrush(lightGradGreen)); // light green + p.fillPath(p_bottom, QBrush(lightGradGreen)); // light green } else if(yv < y2) { // Red section: - p.fillRect(0, 0, w, y1, QBrush(darkGradRed)); // dark red - + p.fillPath(p_top, QBrush(darkGradRed)); // dark red + // Yellow section: - p.fillRect(0, y1, w, yv-y1, QBrush(darkGradYellow)); // dark yellow - p.fillRect(0, yv, w, y2-yv, QBrush(lightGradYellow)); // light yellow - + p.fillRect(0, y1, w, yv-y1, QBrush(darkGradYellow)); // dark yellow + p.fillRect(0, yv, w, y2-yv, QBrush(lightGradYellow)); // light yellow + // Green section: - p.fillRect(0, y2, w, h-y2, QBrush(lightGradGreen)); // light green + p.fillPath(p_bottom, QBrush(lightGradGreen)); // light green } else //if(yv <= y3) { + QPainterPath p_light_green = MusEUtil::roundedPath(0, yv, w, h-yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + p_bottom = p_bottom.subtracted(p_light_green); + // Red section: - p.fillRect(0, 0, w, y1, QBrush(darkGradRed)); // dark red - + p.fillPath(p_top, QBrush(darkGradRed)); // dark red + // Yellow section: - p.fillRect(0, y1, w, y2-y1, QBrush(darkGradYellow)); // dark yellow - + p.fillRect(0, y1, w, y2-y1, QBrush(darkGradYellow)); // dark yellow + // Green section: - p.fillRect(0, y2, w, yv-y2, QBrush(darkGradGreen)); // dark green - p.fillRect(0, yv, w, h-yv, QBrush(lightGradGreen)); // light green + p.fillPath(p_bottom, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light_green, QBrush(lightGradGreen)); // light green } - p.fillRect(0,y1, w, 1, separator_color); - p.fillRect(0,y2, w, 1, separator_color); + p.fillRect(0,y1, w, 1, separator_color); + p.fillRect(0,y2, w, 1, separator_color); } else @@ -301,8 +329,49 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) lightGradGreen.setStart(QPointF(0, 0)); lightGradGreen.setFinalStop(QPointF(0, h)); - p.fillRect(0, 0, w, yv, QBrush(darkGradGreen)); // dark green - p.fillRect(0, yv, w, h-yv, QBrush(lightGradGreen)); // light green + // We need to draw the meter in two parts. The cutoff for upper rectangle can be + // anywhere between yrad and h-yrad. Without loss of generality we pick the lower limit. + int cut = yrad; + + QPainterPath p_top = MusEUtil::roundedPath(0, 0, w, cut, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + QPainterPath p_bottom = MusEUtil::roundedPath(0, cut, w, h-cut, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + + if(yv < cut) + { + + QPainterPath p_dark = MusEUtil::roundedPath(0, 0, w, yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + p_top = p_top.subtracted(p_dark); + + // top section: + p.fillPath(p_dark, QBrush(darkGradGreen)); // dark green + p.fillPath(p_top, QBrush(lightGradGreen)); // light green + + // bottom section: + p.fillPath(p_bottom, QBrush(lightGradGreen)); // light green + } + else + { + QPainterPath p_light = MusEUtil::roundedPath(0, yv, w, h-yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + p_bottom = p_bottom.subtracted(p_light); + + // top section: + p.fillPath(p_top, QBrush(darkGradGreen)); // dark green + + // bottom section: + p.fillPath(p_bottom, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light, QBrush(lightGradGreen)); // light green + } + } } @@ -311,43 +380,8 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) // resizeEvent //--------------------------------------------------------- -void Meter::resizeEvent(QResizeEvent* ev) - { - // Round corners of the widget. - - QSize size = ev->size(); - int w = size.width(); - int h = size.height(); - QPainterPath rounded_rect; - rounded_rect.addRoundedRect(0,0,w,h, w/2.5, w/3); - QRegion maskregion(rounded_rect.toFillPolygon().toPolygon()); - setMask(maskregion); - - /* - // Another method to do the above. I don't know yet which one is more efficient - Orcan - QRect rect(0,0,w,h); - int r = 6; - - QRegion region; - // middle and borders - region += rect.adjusted(r, 0, -r, 0); - region += rect.adjusted(0, r, 0, -r); - // top left - QRect corner(rect.topLeft(), QSize(r*2, r*2)); - region += QRegion(corner, QRegion::Ellipse); - // top right - corner.moveTopRight(rect.topRight()); - region += QRegion(corner, QRegion::Ellipse); - // bottom left - corner.moveBottomLeft(rect.bottomLeft()); - region += QRegion(corner, QRegion::Ellipse); - // bottom right - corner.moveBottomRight(rect.bottomRight()); - region += QRegion(corner, QRegion::Ellipse); - // return region; - setMask(region); - */ - + void Meter::resizeEvent(QResizeEvent* /*ev*/) + { } //--------------------------------------------------------- diff --git a/muse2/muse/widgets/meter.h b/muse2/muse/widgets/meter.h index 62ad3fe0..06f35ca2 100644 --- a/muse2/muse/widgets/meter.h +++ b/muse2/muse/widgets/meter.h @@ -72,6 +72,7 @@ class Meter : public QFrame { QColor separator_color;; QColor peak_color; + int xrad, yrad; private: MeterType mtype; diff --git a/muse2/muse/widgets/slider.cpp b/muse2/muse/widgets/slider.cpp index f50c144a..b9803fca 100644 --- a/muse2/muse/widgets/slider.cpp +++ b/muse2/muse/widgets/slider.cpp @@ -27,6 +27,7 @@ #include <QPainter> #include <QResizeEvent> +#include "utils.h" #include "slider.h" namespace MusEWidget { @@ -168,73 +169,6 @@ void Slider::fontChange(const QFont & /*oldFont*/) } //------------------------------------------------------------ -// -// roundedPath -// Returns a rectangle with rounded corners -// -// roundCorner can be an bitwise-or combination of -// UpperLeft, UpperRight, LowerRight, LowerLeft -//------------------------------------------------------------ -QPainterPath Slider::roundedPath(QRect r, int xrad, int yrad, RoundCorner roundCorner) -{ - return roundedPath(r.x(), r.y(), - r.width(), r.height(), - xrad, yrad, - roundCorner); -} - -QPainterPath Slider::roundedPath(int x, int y, int w, int h, int xrad, int yrad, RoundCorner roundCorner) -{ - QPainterPath rounded_rect; - rounded_rect.addRect(x, y + yrad, w, h - 2 * yrad); - if (roundCorner & UpperLeft) - { - rounded_rect.moveTo(x + xrad, y + yrad); - rounded_rect.arcTo(x, y, xrad*2, yrad*2, 180, -90); - } - else - { - rounded_rect.moveTo(x, y + yrad); - rounded_rect.lineTo(x,y); - rounded_rect.lineTo(x + xrad, y); - } - - rounded_rect.lineTo(x + w - xrad, y); - - if (roundCorner & UpperRight) - rounded_rect.arcTo(x + w - xrad * 2, y, xrad*2, yrad*2, 90, -90); - else - { - rounded_rect.lineTo(x + w, y); - rounded_rect.lineTo(x + w, y + yrad); - } - - if (roundCorner & LowerLeft) - { - rounded_rect.moveTo(x + xrad, y + h - yrad); - rounded_rect.arcTo(x, y + h - yrad*2, xrad*2, yrad*2, 180, 90); - } - else - { - rounded_rect.moveTo(x, y + h - yrad); - rounded_rect.lineTo(x, y + h); - rounded_rect.lineTo(x + xrad, y + h); - } - - rounded_rect.lineTo(x + w - xrad, y + h); - - if (roundCorner & LowerRight) - rounded_rect.arcTo(x + w - xrad*2, y + h - yrad*2, xrad*2, yrad*2, 270, 90); - else - { - rounded_rect.lineTo(x + w, y + h); - rounded_rect.lineTo(x + w, y + h - yrad); - } - - return rounded_rect; -} - -//------------------------------------------------------------ // drawSlider // Draw the slider into the specified rectangle. //------------------------------------------------------------ @@ -315,9 +249,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // // Draw background // - QPainterPath bg_rect = roundedPath(cr, + QPainterPath bg_rect = MusEUtil::roundedPath(cr, xrad, yrad, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); p->fillPath(bg_rect, d_fillColor); @@ -333,9 +267,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) e_mask.setStart(QPointF(0, cr.y())); e_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); - QPainterPath e_rect = roundedPath(ipos + d_thumbLength, cr.y(), + QPainterPath e_rect = MusEUtil::roundedPath(ipos + d_thumbLength, cr.y(), cr.width() - d_thumbLength - dist1, cr.height(), - xrad, yrad, (RoundCorner) (UpperRight | LowerRight) ); + xrad, yrad, (MusEUtil::Corner) (MusEUtil::UpperRight | MusEUtil::LowerRight) ); p->fillPath(e_rect, QBrush(e_mask)); @@ -347,10 +281,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) f_mask.setStart(QPointF(0, cr.y())); f_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); - QPainterPath f_rect = roundedPath(cr.x(), cr.y(), + QPainterPath f_rect = MusEUtil::roundedPath(cr.x(), cr.y(), ipos + 1, cr.height(), xrad, yrad, - (RoundCorner) (LowerLeft | UpperLeft) ); + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::UpperLeft) ); p->fillPath(f_rect, QBrush(f_mask)); @@ -359,10 +293,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // Draw thumb // - QPainterPath thumb_rect = roundedPath(ipos, r.y(), + QPainterPath thumb_rect = MusEUtil::roundedPath(ipos, r.y(), d_thumbLength, r.height(), 2, 2, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); thumbGrad.setStart(QPointF(0, cr.y())); thumbGrad.setFinalStop(QPointF(0, cr.y() + cr.height())); @@ -387,9 +321,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // // Draw background // - QPainterPath bg_rect = roundedPath(cr, + QPainterPath bg_rect = MusEUtil::roundedPath(cr, xrad, yrad, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); p->fillPath(bg_rect, d_fillColor); @@ -405,10 +339,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) e_mask.setStart(QPointF(cr.x(), 0)); e_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); - QPainterPath e_rect = roundedPath(cr.x(), cr.y(), + QPainterPath e_rect = MusEUtil::roundedPath(cr.x(), cr.y(), cr.width(), ipos + 1, xrad, yrad, - (RoundCorner) (UpperLeft | UpperRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight) ); p->fillPath(e_rect, QBrush(e_mask)); @@ -420,9 +354,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) f_mask.setStart(QPointF(cr.x(), 0)); f_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); - QPainterPath f_rect = roundedPath(cr.x(), ipos + d_thumbLength, + QPainterPath f_rect = MusEUtil::roundedPath(cr.x(), ipos + d_thumbLength, cr.width(), cr.height() - d_thumbLength - dist1, - xrad, yrad, (RoundCorner) (LowerLeft | LowerRight) ); + xrad, yrad, (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight) ); p->fillPath(f_rect, QBrush(f_mask)); @@ -431,10 +365,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // Draw thumb // - QPainterPath thumb_rect = roundedPath(r.x(), ipos, + QPainterPath thumb_rect = MusEUtil::roundedPath(r.x(), ipos, r.width(), d_thumbLength, 2, 2, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); thumbGrad.setStart(QPointF(cr.x(), 0)); thumbGrad.setFinalStop(QPointF(cr.x() + cr.width(), 0)); diff --git a/muse2/muse/widgets/slider.h b/muse2/muse/widgets/slider.h index a76c5270..861d8f4b 100644 --- a/muse2/muse/widgets/slider.h +++ b/muse2/muse/widgets/slider.h @@ -42,7 +42,6 @@ class Slider : public SliderBase, public ScaleIf public: enum ScalePos { None, Left, Right, Top, Bottom }; - enum RoundCorner { UpperLeft = 0x1, UpperRight = 0x2, LowerLeft = 0x4, LowerRight = 0x8 }; private: Q_PROPERTY( double lineStep READ lineStep WRITE setLineStep ) @@ -70,8 +69,6 @@ class Slider : public SliderBase, public ScaleIf int d_bgStyle; int markerPos; - QPainterPath roundedPath(int x, int y, int w, int h, int xrad, int yrad, RoundCorner roundCorner); - QPainterPath roundedPath(QRect r, int xrad, int yrad, RoundCorner roundCorner); void drawHsBgSlot(QPainter *, const QRect&, const QRect&,const QBrush&); void drawVsBgSlot(QPainter *, const QRect&, const QRect&,const QBrush&); diff --git a/muse2/muse/widgets/utils.cpp b/muse2/muse/widgets/utils.cpp index e46d265c..1ed9001a 100644 --- a/muse2/muse/widgets/utils.cpp +++ b/muse2/muse/widgets/utils.cpp @@ -404,4 +404,56 @@ QGradient gGradientFromQColor(const QColor& c, const QPointF& start, const QPoin return gradient; } +QPainterPath roundedPath(QRect r, int xrad, int yrad, Corner roundCorner) +{ + return roundedPath(r.x(), r.y(), + r.width(), r.height(), + xrad, yrad, + roundCorner); +} + +QPainterPath roundedPath(int x, int y, int w, int h, int xrad, int yrad, Corner roundCorner) +{ + QPainterPath rounded_rect; + rounded_rect.addRect(x, y, w, h); + + if (roundCorner & UpperLeft) + { + QPainterPath top_left_corner; + top_left_corner.addRect(x, y, xrad, yrad); + top_left_corner.moveTo(x + xrad, y + yrad); + top_left_corner.arcTo(x, y, xrad*2, yrad*2, 180, -90); + rounded_rect = rounded_rect.subtracted(top_left_corner); + } + + if (roundCorner & UpperRight) + { + QPainterPath top_right_corner; + top_right_corner.addRect(x + w - xrad, y, xrad, yrad); + top_right_corner.moveTo(x + w - xrad, y + yrad); + top_right_corner.arcTo(x + w - xrad * 2, y, xrad*2, yrad*2, 90, -90); + rounded_rect = rounded_rect.subtracted(top_right_corner); + } + + if (roundCorner & LowerLeft) + { + QPainterPath bottom_left_corner; + bottom_left_corner.addRect(x, y + h - yrad, xrad, yrad); + bottom_left_corner.moveTo(x + xrad, y + h - yrad); + bottom_left_corner.arcTo(x, y + h - yrad*2, xrad*2, yrad*2, 180, 90); + rounded_rect = rounded_rect.subtracted(bottom_left_corner); + } + + if (roundCorner & LowerRight) + { + QPainterPath bottom_right_corner; + bottom_right_corner.addRect(x + w - xrad, y + h - yrad, xrad, yrad); + bottom_right_corner.moveTo(x + w - xrad, y + h - yrad); + bottom_right_corner.arcTo(x + w - xrad*2, y + h - yrad*2, xrad*2, yrad*2, 270, 90); + rounded_rect = rounded_rect.subtracted(bottom_right_corner); + } + + return rounded_rect; +} + } // namespace MusEUtils diff --git a/muse2/muse/widgets/utils.h b/muse2/muse/widgets/utils.h index b74ba394..c6e1ad6b 100644 --- a/muse2/muse/widgets/utils.h +++ b/muse2/muse/widgets/utils.h @@ -30,9 +30,12 @@ class QGradient; class QCanvas; class QPointF; class QColor; +class QPainterPath; namespace MusEUtil { +enum Corner { UpperLeft = 0x1, UpperRight = 0x2, LowerLeft = 0x4, LowerRight = 0x8 }; + extern QString bitmap2String(int bm); extern int string2bitmap(const QString& str); extern QString u32bitmap2String(unsigned int bm); @@ -46,6 +49,9 @@ extern QFrame* vLine(QWidget* parent); extern void dump(const unsigned char* p, int n); extern double curTime(); +extern QPainterPath roundedPath(QRect r, int xrad, int yrad, Corner roundCorner); +extern QPainterPath roundedPath(int x, int y, int w, int h, int xrad, int yrad, Corner roundCorner); + } // namespace MusEUtils #endif diff --git a/muse2/muse/widgets/verticalmeter.cpp b/muse2/muse/widgets/verticalmeter.cpp index b0e0198f..83baa83b 100644 --- a/muse2/muse/widgets/verticalmeter.cpp +++ b/muse2/muse/widgets/verticalmeter.cpp @@ -31,6 +31,8 @@ #include "verticalmeter.h" #include "gconfig.h" #include "fastlog.h" +#include "mmath.h" +#include "utils.h" namespace MusEWidget { @@ -46,7 +48,8 @@ VerticalMeter::VerticalMeter(QWidget* parent, MeterType type) setAttribute(Qt::WA_StaticContents); // This is absolutely required for speed! Otherwise painfully slow because we get // full rect paint events even on small scrolls! See help on QPainter::scroll(). - setAttribute(Qt::WA_OpaquePaintEvent); + // Commented out for now. Orcan 20110911 + //setAttribute(Qt::WA_OpaquePaintEvent); mtype = type; overflow = false; @@ -56,6 +59,9 @@ VerticalMeter::VerticalMeter(QWidget* parent, MeterType type) maxScale = mtype == DBMeter ? 10.0 : 127.0; yellowScale = -10; redScale = 0; + xrad = 4; + yrad = 4; + setLineWidth(0); setMidLineWidth(0); } @@ -129,18 +135,19 @@ void VerticalMeter::paintEvent(QPaintEvent* ev) // TODO: Could make better use of event rectangle, for speed. QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); double range = maxScale - minScale; - /* int fw = frameWidth(); + /* int w = width() - 2*fw; int h = height() - 2*fw; */ QRect rect = ev->rect(); - int w = rect.width(); - int h = rect.height(); + int w = rect.width() - 2*fw; + int h = rect.height() - 2*fw; int xv; @@ -157,18 +164,23 @@ void VerticalMeter::paintEvent(QPaintEvent* ev) drawVU(p, w, h, xv); // Draw the peak white line. + /* int xcenter; if(mtype == DBMeter) xcenter = maxVal == 0 ? 0 : int(((maxScale - (fast_log10(0) * 20.0)) * w)/range); else - xcenter = maxVal == 0 ? 0 : int(((0) * w)/range); + xcenter = maxVal == 0 ? 0 : int(((maxVal) * w)/range); p.setPen(peak_color); p.drawLine(xcenter, 0, xcenter, h); + */ // Draw the transparent layer on top of everything to give a 3d look + QPainterPath round_path = roundedPath(0, 0, w, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); maskGrad.setStart(QPointF(0, 0)); maskGrad.setFinalStop(QPointF(0, h)); - p.fillRect(0, 0, w, h, QBrush(maskGrad)); + p.fillPath(round_path, QBrush(maskGrad)); } //--------------------------------------------------------- @@ -177,7 +189,7 @@ void VerticalMeter::paintEvent(QPaintEvent* ev) void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) { - if(mtype == DBMeter) + if(mtype == DBMeter) { double range = maxScale - minScale; int x1 = int((maxScale - redScale) * w / range); @@ -197,44 +209,65 @@ void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) lightGradRed.setStart(QPointF(0, 0)); lightGradRed.setFinalStop(QPointF(x1, 0)); + QPainterPath p_left = roundedPath(0, 0, x1, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + QPainterPath p_right = roundedPath(x2, 0, w-x2, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerRight | MusEUtil::UpperRight ) ); if(xv < x1) { - // Red section: - p.fillRect(0, 0, xv, h, QBrush(darkGradRed)); // dark red - p.fillRect(xv, 0, x1-xv, h, QBrush(lightGradRed)); // light red - + + QPainterPath p_light_green = roundedPath(0, 0, xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + p_left = p_left.subtracted(p_light_green); + + // Green section: + p.fillPath(p_light_green, QBrush(lightGradGreen)); // light green + p.fillPath(p_left, QBrush(darkGradGreen)); // dark green + // Yellow section: - p.fillRect(x1, 0, x2-x1, h, QBrush(lightGradYellow)); // light yellow + p.fillRect(x1, 0, x2-x1, h, QBrush(darkGradYellow)); // dark yellow - // Green section: - p.fillRect(x2, 0, w-x2, h, QBrush(lightGradGreen)); // light green + // Red section: + p.fillPath(p_right, QBrush(darkGradRed)); // dark red } else if(xv < x2) { - // Red section: - p.fillRect(0, 0, x1, h, QBrush(darkGradRed)); // dark red + // Green section: + p.fillPath(p_left, QBrush(lightGradGreen)); // light green // Yellow section: - p.fillRect(x1, 0, xv-x1, h, QBrush(darkGradYellow)); // dark yellow - p.fillRect(xv, 0, x2-xv, h, QBrush(lightGradYellow)); // light yellow + p.fillRect(x1, 0, xv-x1, h, QBrush(lightGradYellow)); // light yellow + p.fillRect(xv, 0, x2-xv, h, QBrush(darkGradYellow)); // dark yellow - // Green section: - p.fillRect(x2, 0, w-x2, h, QBrush(lightGradGreen)); // light green + // Red section: + p.fillPath(p_right, QBrush(darkGradRed)); // dark red } else - //if(yv <= y3) + //if(xv <= x3) { - // Red section: - p.fillRect(0, 0, x1, h, QBrush(darkGradRed)); // dark red + QPainterPath p_dark_red = roundedPath(xv, 0, w-xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerRight | MusEUtil::UpperRight ) ); + + p_right = p_right.subtracted(p_dark_red); + + // Green section: + p.fillPath(p_left, QBrush(lightGradGreen)); // light green // Yellow section: - p.fillRect(x1, 0, x2-x1, h, QBrush(darkGradYellow)); // dark yellow + p.fillRect(x1, 0, x2-x1, h, QBrush(lightGradYellow)); // light yellow - // Green section: - p.fillRect(x2, 0, xv-x2, h, QBrush(darkGradGreen)); // dark green - p.fillRect(xv, 0, w-xv, h, QBrush(lightGradGreen)); // light green + // Red section: + p.fillPath(p_right, QBrush(lightGradRed)); // light red + p.fillPath(p_dark_red, QBrush(darkGradRed)); // dark red + } p.fillRect(x1,0, 1, h, separator_color); @@ -249,8 +282,49 @@ void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) lightGradGreen.setStart(QPointF(0, 0)); lightGradGreen.setFinalStop(QPointF(w, 0)); - p.fillRect(0, 0, xv, h, QBrush(lightGradGreen)); // light green - p.fillRect(xv, 0, w-xv, h, QBrush(darkGradGreen)); // dark green + // We need to draw the meter in two parts. The cutoff for the left rectangle can be + // anywhere between xrad and w-xrad. Without loss of generality we pick the lower limit. + int cut = xrad; + + QPainterPath p_left = roundedPath(0, 0, cut, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + QPainterPath p_right = roundedPath(cut, 0, w-cut, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerRight | MusEUtil::UpperRight ) ); + + if(xv < cut) + { + + QPainterPath p_light = roundedPath(0, 0, xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + p_left = p_left.subtracted(p_light); + + // left section: + p.fillPath(p_left, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light, QBrush(lightGradGreen)); // light green + + // bottom section: + p.fillPath(p_right, QBrush(darkGradGreen)); // dark green + } + else + { + QPainterPath p_dark = roundedPath(xv, 0, w-xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperRight | MusEUtil::LowerRight ) ); + p_right = p_right.subtracted(p_dark); + + // left section: + p.fillPath(p_left, QBrush(lightGradGreen)); // light green + + // right section: + p.fillPath(p_dark, QBrush(darkGradGreen)); // dark green + p.fillPath(p_right, QBrush(lightGradGreen)); // light green + } + } } @@ -259,17 +333,8 @@ void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) // resizeEvent //--------------------------------------------------------- -void VerticalMeter::resizeEvent(QResizeEvent* ev) +void VerticalMeter::resizeEvent(QResizeEvent* /*ev*/) { - // Round corners of the widget. - - QSize size = ev->size(); - int w = size.width(); - int h = size.height(); - QPainterPath rounded_rect; - rounded_rect.addRoundedRect(0,0,w,h, h/3, h/2.5); - QRegion maskregion(rounded_rect.toFillPolygon().toPolygon()); - setMask(maskregion); } } // namespace MusEWidget |