diff options
-rw-r--r-- | muse2/ChangeLog | 2 | ||||
-rw-r--r-- | muse2/muse/mixer/astrip.cpp | 4 | ||||
-rw-r--r-- | muse2/muse/mixer/mstrip.cpp | 2 | ||||
-rw-r--r-- | muse2/muse/widgets/slider.cpp | 635 | ||||
-rw-r--r-- | muse2/muse/widgets/slider.h | 16 |
5 files changed, 294 insertions, 365 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog index dc528bdb..d1da6267 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,5 @@ +04.09.2011: + - Remodel the Slider (Orcan) 01.09.2011: - Fixed tough old skeleton: Selecting 'previous/next event' in Song::execAutomationCtlPopup now moves cursor with exact frame resolution, all the way through via proper song->setPos > audio->msgSeek rather than diff --git a/muse2/muse/mixer/astrip.cpp b/muse2/muse/mixer/astrip.cpp index 00477a26..a6b66b37 100644 --- a/muse2/muse/mixer/astrip.cpp +++ b/muse2/muse/mixer/astrip.cpp @@ -795,8 +795,8 @@ AudioStrip::AudioStrip(QWidget* parent, AudioTrack* at) sliderGrid->setContentsMargins(0, 0, 0, 0); sliderGrid->setSpacing(0); - slider = new Slider(this, "vol", Qt::Vertical, Slider::None, - Slider::BgTrough | Slider::BgSlot); + slider = new Slider(this, "vol", Qt::Vertical, Slider::None); + slider->setCursorHoming(true); slider->setRange(config.minSlider-0.1, 10.0); slider->setFixedWidth(20); diff --git a/muse2/muse/mixer/mstrip.cpp b/muse2/muse/mixer/mstrip.cpp index ad21916d..618e905a 100644 --- a/muse2/muse/mixer/mstrip.cpp +++ b/muse2/muse/mixer/mstrip.cpp @@ -189,7 +189,7 @@ MidiStrip::MidiStrip(QWidget* parent, MidiTrack* t) int mx = mc->maxVal(); slider = new Slider(this, "vol", Qt::Vertical, Slider::None, - Slider::BgTrough | Slider::BgSlot); + QColor(100, 255, 100)); slider->setCursorHoming(true); slider->setRange(double(mn), double(mx), 1.0); slider->setFixedWidth(20); diff --git a/muse2/muse/widgets/slider.cpp b/muse2/muse/widgets/slider.cpp index 4f68388d..323b1fa3 100644 --- a/muse2/muse/widgets/slider.cpp +++ b/muse2/muse/widgets/slider.cpp @@ -6,6 +6,7 @@ #include "slider.h" + //------------------------------------------------------------- // Slider - The Slider Widget // @@ -32,39 +33,27 @@ // ScalePos scalePos -- Position of the scale. Can be Slider::None, // Slider::Left, Slider::Right, Slider::Top, // or Slider::Bottom. Defaults to Slider::None. -// int bgStyle -- Background style. Slider::BgTrough draws the -// slider button in a trough, Slider::BgSlot draws -// a slot underneath the button. An or-combination of both -// may also be used. The default is Slider::BgTrough. +// QColor fillcolor -- the color used to fill in the full side +// of the Slider //------------------------------------------------------------ Slider::Slider(QWidget *parent, const char *name, - Qt::Orientation orient, ScalePos scalePos, int bgStyle) + Qt::Orientation orient, ScalePos scalePos, QColor fillColor) : SliderBase(parent,name) { - if (bgStyle == BgSlot) { - d_thumbLength = 16; - d_thumbHalf = 8; - d_thumbWidth = 30; - } - else { - d_thumbLength = 30; - d_thumbHalf = 15; - d_thumbWidth = 16; - } + d_thumbLength = 16; + d_thumbHalf = 8; + d_thumbWidth = 16; + - d_borderWidth = 2; d_scaleDist = 4; d_scaleStep = 0.0; d_scalePos = scalePos; d_xMargin = 0; d_yMargin = 0; - d_bgStyle = bgStyle; + d_mMargin = 1; - if (bgStyle & BgTrough) - d_bwTrough = d_borderWidth; - else - d_bwTrough = 0; + d_fillColor = fillColor; d_sliderRect.setRect(0, 0, 8, 8); setOrientation(orient); @@ -81,28 +70,6 @@ Slider::~Slider() { } -//------------------------------------------------------------ -// -//.F Slider::setBorderWidth -// Change the slider's border width -// -//.u Syntax -//.f void Slider::setBorderWidth(int bd) -// -//.u Parameters -//.p int bd -- border width -// -//------------------------------------------------------------ - -void Slider::setBorderWidth(int bd) -{ - d_borderWidth = qwtMin(qwtMax(bd,0),10); - if (d_bgStyle & BgTrough) - d_bwTrough = d_borderWidth; - else - d_bwTrough = 0; -} - //---------------------------------------------------- // //.F Slider::setThumbLength @@ -177,311 +144,284 @@ void Slider::fontChange(const QFont & /*oldFont*/) } //------------------------------------------------------------ -// drawSlider -// Draw the slider into the specified rectangle. -//------------------------------------------------------------ - -void Slider::drawSlider(QPainter *p, const QRect &r) - { - const QPalette& pal = palette(); - QBrush brBack(pal.window()); - QBrush brMid; - QBrush brDark(pal.dark()); - - QRect cr; - - int ipos,dist1; - double rpos; - int lineDist; - - if (d_bwTrough > 0) { - qDrawShadePanel(p, r.x(), r.y(), - r.width(), r.height(), - pal, TRUE, d_bwTrough,0); - cr.setRect(r.x() + d_bwTrough, - r.y() + d_bwTrough, - r.width() - 2*d_bwTrough, - r.height() - 2*d_bwTrough); - brMid = pal.mid(); - } - else { - cr = r; - brMid = brBack; - } - - rpos = (value() - minValue()) / (maxValue() - minValue()); - - lineDist = d_borderWidth - 1; - if (lineDist < 1) lineDist = 1; - - if (d_orient == Qt::Horizontal) - { - - dist1 = int(double(cr.width() - d_thumbLength) * rpos); - ipos = cr.x() + dist1; - markerPos = ipos + d_thumbHalf; - - // - // draw background - // - if (d_bgStyle & BgSlot) - { - drawHsBgSlot(p, cr, QRect(ipos, cr.y(), d_thumbLength, cr.height()), brMid); - } - else - { - p->fillRect(cr.x(),cr.y(),dist1,cr.height(),brMid); - p->fillRect(ipos + d_thumbLength, cr.y(), - cr.width() - d_thumbLength - dist1, cr.height(),brMid); - } - - // - // Draw thumb - // - qDrawShadePanel(p,ipos, cr.y(), d_thumbLength, cr.height(), - pal, FALSE, d_borderWidth, &brBack); - - if (lineDist > 1) - qDrawShadeLine(p,markerPos, cr.y() + lineDist , markerPos, - cr.y() + cr.height() - lineDist, - pal, TRUE, 1); - else - { - p->setPen(pal.dark().color()); - p->drawLine(markerPos -1 , cr.y() + lineDist, markerPos -1, - cr.y() + cr.height() - lineDist - 1); - p->setPen(pal.light().color()); - p->drawLine(markerPos, cr.y() + lineDist, markerPos, - cr.y() + cr.height() - lineDist - 1); - } - - - } - else - { - dist1 = int(double(cr.height() - d_thumbLength) * (1.0 - rpos)); - ipos = cr.y() + dist1; - markerPos = ipos + d_thumbHalf; - - if ( d_bgStyle & BgSlot) - { - drawVsBgSlot(p, cr, QRect(cr.left(), ipos, cr.width(), - d_thumbLength), brMid); - } - else - { - p->fillRect(cr.x(),cr.y(),cr.width(),ipos,brMid); - p->fillRect(cr.x(), ipos + d_thumbLength, cr.width(), - cr.height() - d_thumbLength - dist1, brMid); - } - - qDrawShadePanel(p,cr.x(),ipos , cr.width(), d_thumbLength, - pal,FALSE,d_borderWidth, &brBack); - if (lineDist > 1) - qDrawShadeLine(p, cr.x() + lineDist , markerPos, - cr.x() + cr.width() - lineDist, markerPos, - pal, TRUE, 1); - else { - - p->setPen(pal.dark().color()); - p->drawLine(cr.x() + lineDist, markerPos - 1 , - cr.x() + cr.width() - lineDist - 1, markerPos - 1); - p->setPen(pal.light().color()); - p->drawLine(cr.x() + lineDist, markerPos, - cr.x() + cr.width() - lineDist - 1 , markerPos); - } - } - -} - -//------------------------------------------------------------ -//.- -//.F Slider::drawSlotBg // +// roundedPath +// Returns a rectangle with rounded corners // -//.u Syntax -//.f void Slider::drawSlotBg(QPainter *p, const QRect &rBound, const QRect &rThumb, const QRect &rSlot, const QBrush &brBack) -// -//.u Parameters -//.p QPainter *p, const QRect &rBound, const QRect &rThumb, const QRect &rSlot, const QBrush &brBack -// +// roundCorner can be an bitwise-or combination of +// UpperLeft, UpperRight, LowerRight, LowerLeft //------------------------------------------------------------ -void Slider::drawHsBgSlot(QPainter *p, const QRect &rBound, const QRect &rThumb, const QBrush &brBack) +QPainterPath Slider::roundedPath(QRect r, int xrad, int yrad, RoundCorner roundCorner) { - int ws, ds, dLeft; - int lPos, rPos; - QRect rSlot; - const QPalette& pal = palette(); + return roundedPath(r.x(), r.y(), + r.width(), r.height(), + xrad, yrad, + roundCorner); +} - ws = rBound.height(); - if ((ws / 2) * 2 != ws) - ws = 5; +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 - ws = 4; - - ds = qwtMax(1, d_thumbLength/2 - 4); - dLeft = rThumb.left() - rBound.left(); + { + rounded_rect.moveTo(x, y + yrad); + rounded_rect.lineTo(x,y); + rounded_rect.lineTo(x + xrad, y); + } - rSlot = QRect(rBound.x() + ds, rBound.y() + (rBound.height() - ws) / 2, - rBound.width() - 2 * ds, ws); + rounded_rect.lineTo(x + w - xrad, y); - rPos = qwtMin(rSlot.x(), rThumb.left()); + 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 (rThumb.left() > rBound.x()) - { - p->fillRect(rBound.x(),rBound.y(),dLeft, rSlot.top() - rBound.top(), brBack); - p->fillRect(rBound.x(),rSlot.bottom() + 1,dLeft, - rBound.bottom() - rSlot.bottom(),brBack); - if (rPos > rBound.left()) - p->fillRect(rBound.x(),rSlot.y(), - rPos - rBound.left(),ws,brBack); - - p->setPen(pal.dark().color()); - if (rSlot.x() < rThumb.left()) - p->drawLine(rSlot.x(), rSlot.bottom(), rSlot.x(), rSlot.top()); - if (rSlot.x() < rThumb.left() - 1) - { - p->drawLine(rSlot.x(), rSlot.top(), rThumb.left() - 1, rSlot.top()); - p->setPen(pal.light().color()); - p->drawLine(rSlot.x() + 1, rSlot.bottom(), - rThumb.left() - 1, rSlot.bottom()); - - p->fillRect(rSlot.x() + 1, rSlot.y() + 1, dLeft - ds -1, - rSlot.height() -2, QBrush(pal.currentColorGroup() == QPalette::Disabled ? - pal.color(QPalette::Disabled, QPalette::WindowText) : Qt::black)); - } - } + 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); + } - lPos = qwtMax(rSlot.right(), rThumb.right()) + 1; - if (rThumb.right() < rBound.right()) - { - p->fillRect(rThumb.right() + 1,rBound.y(),rBound.right() - rThumb.right(), - rSlot.top() - rBound.top(), brBack); - p->fillRect(rThumb.right() + 1,rSlot.bottom() + 1, - rBound.right() - rThumb.right(), - rBound.bottom() - rSlot.bottom(),brBack); - if (lPos <= rBound.right()) - p->fillRect(lPos, rSlot.y() , rBound.right() - lPos + 1, ws ,brBack); - - p->setPen(pal.dark().color()); - if (rSlot.right() > rThumb.right()) - { - p->drawLine(rThumb.right() + 1, rSlot.top(), rSlot.right(), rSlot.top()); - p->setPen(pal.light().color()); - p->drawLine(rSlot.right(), rSlot.bottom(), rSlot.right(), rSlot.top() + 1); - } + rounded_rect.lineTo(x + w - xrad, y + h); - if (rSlot.right() > rThumb.right() + 1) - { - p->setPen(pal.light().color()); - p->drawLine(rThumb.right() + 1, rSlot.bottom(), - rSlot.right() -1, rSlot.bottom()); - p->fillRect(rThumb.right() + 1, rSlot.y() + 1, - rSlot.right() - rThumb.right() - 1, - rSlot.height() -2, QBrush(pal.currentColorGroup() == QPalette::Disabled ? - pal.color(QPalette::Disabled, QPalette::WindowText) : Qt::black)); - } - } + 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; } //------------------------------------------------------------ -//.- -//.F Slider::drawVsBgSlot -// -// -//.u Syntax -//.f void Slider::drawVsBgSlot(QPainter *p, const QRect &rBound, const QRect &rThumb, const QBrush &brBack) -// -//.u Parameters -//.p QPainter *p, const QRect &rBound, const QRect &rThumb, const QBrush &brBack -// -//.u Return Value -// -//.u Description -// +// drawSlider +// Draw the slider into the specified rectangle. //------------------------------------------------------------ -void Slider::drawVsBgSlot(QPainter *p, const QRect &rBound, const QRect &rThumb, const QBrush &brBack) + +void Slider::drawSlider(QPainter *p, const QRect &r) { + p->setRenderHint(QPainter::Antialiasing); - int ws, ds, dTop; - int lPos, hPos; - QRect rSlot; const QPalette& pal = palette(); + QBrush brBack(pal.window()); + QBrush brMid(pal.mid()); + QBrush brDark(pal.dark()); - ws = rBound.width(); - if ((ws / 2) * 2 != ws) - ws = 5; + QRect cr; + + int ipos,dist1; + double rpos; + + int xrad = 4; + int yrad = 4; + + // for the empty side + QColor e_mask_edge = pal.mid().color(); + QColor e_mask_center = pal.midlight().color(); + int e_alpha = 215; + e_mask_edge.setAlpha(e_alpha); + e_mask_center.setAlpha(e_alpha); + + QLinearGradient e_mask; + e_mask.setColorAt(0, e_mask_edge); + e_mask.setColorAt(0.5, e_mask_center); + e_mask.setColorAt(1, e_mask_edge); + + // for the full side + rpos = (value() - minValue()) / (maxValue() - minValue()); + + int f_brightness = 155 * rpos + 100; + int f_alpha; + int f_edge; + if (pal.currentColorGroup() == QPalette::Disabled) + { + f_alpha = 185; + f_edge = 100; + } else - ws = 4; - - ds = qwtMax(1, d_thumbLength/2 - 4); - dTop = rThumb.top() - rBound.top(); - - rSlot = QRect(rBound.x() + (rBound.width() - ws) / 2, rBound.y() + ds, - ws, rBound.height() - 2 * ds); - - hPos = qwtMin(rSlot.y(), rThumb.top()); + { + f_alpha = 127; + f_edge = 0; + } + + QColor f_mask_center = QColor(f_brightness, f_brightness, f_brightness, f_alpha); + QColor f_mask_edge = QColor(f_edge, f_edge, f_edge, f_alpha); + QLinearGradient f_mask; + + f_mask.setColorAt(0, f_mask_edge); + f_mask.setColorAt(0.5, f_mask_center); + f_mask.setColorAt(1, f_mask_edge); + + // for the thumb + QLinearGradient thumbGrad; + QColor thumb_edge = pal.dark().color(); + QColor thumb_center = pal.midlight().color(); + + thumbGrad.setColorAt(0, thumb_edge); + thumbGrad.setColorAt(0.5, thumb_center); + thumbGrad.setColorAt(1, thumb_edge); + + + if (d_orient == Qt::Horizontal) + { - if (rThumb.top() > rBound.top()) - { - p->fillRect(rBound.x(),rBound.y(), rSlot.left() - rBound.left(),dTop, brBack); - p->fillRect(rSlot.right() + 1, rBound.y(), - rBound.right() - rSlot.right(), dTop,brBack); - if (hPos > rBound.top()) - p->fillRect(rSlot.x(),rBound.y(), ws, - hPos - rBound.top(),brBack); + cr.setRect(r.x(), + r.y() + d_mMargin, + r.width(), + r.height() - 2*d_mMargin); + + + // + // Draw background + // + QPainterPath bg_rect = roundedPath(cr, + xrad, yrad, + (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + + p->fillPath(bg_rect, d_fillColor); + + dist1 = int(double(cr.width() - d_thumbLength) * rpos); + ipos = cr.x() + dist1; + markerPos = ipos + d_thumbHalf; + + + // + // Draw empty right side + // + + 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(), + cr.width() - d_thumbLength - dist1, cr.height(), + xrad, yrad, (RoundCorner) (UpperRight | LowerRight) ); + + p->fillPath(e_rect, QBrush(e_mask)); + + + // + // Draw full left side + // + + f_mask.setStart(QPointF(0, cr.y())); + f_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); + + QPainterPath f_rect = roundedPath(cr.x(), cr.y(), + ipos + 1, cr.height(), + xrad, yrad, + (RoundCorner) (LowerLeft | UpperLeft) ); + + p->fillPath(f_rect, QBrush(f_mask)); + + + // + // Draw thumb + // + + QPainterPath thumb_rect = roundedPath(ipos, r.y(), + d_thumbLength, r.height(), + 2, 2, + (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + + thumbGrad.setStart(QPointF(0, cr.y())); + thumbGrad.setFinalStop(QPointF(0, cr.y() + cr.height())); + + + p->fillPath(thumb_rect, QBrush(thumbGrad)); + + // center line + p->fillRect(ipos + d_thumbHalf, cr.y(), 1, cr.height(), pal.dark().color()); + - p->setPen(pal.dark().color()); - if (rSlot.top() < rThumb.top()) - p->drawLine(rSlot.left(), rSlot.top(), rSlot.right(), rSlot.top()); + } + else // (d_orient == Qt::Vertical) + { + + cr.setRect(r.x() + d_mMargin, + r.y(), + r.width() - 2*d_mMargin, + r.height()); + + + // + // Draw background + // + QPainterPath bg_rect = roundedPath(cr, + xrad, yrad, + (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + + p->fillPath(bg_rect, d_fillColor); + + dist1 = int(double(cr.height() - d_thumbLength) * (1.0 - rpos)); + ipos = cr.y() + dist1; + markerPos = ipos + d_thumbHalf; - if (rSlot.top() < rThumb.top() - 1) - { - p->drawLine(rSlot.left(), rThumb.top() - 1, rSlot.left(), rSlot.top()); - p->setPen(pal.light().color()); - p->drawLine(rSlot.right(), rSlot.top() + 1, rSlot.right(), - rThumb.top() - 1); - - p->fillRect(rSlot.x() + 1, rSlot.y() + 1, rSlot.width() - 2, - dTop - ds -1, QBrush(pal.currentColorGroup() == QPalette::Disabled ? - pal.color(QPalette::Disabled, QPalette::WindowText) : Qt::black)); - - } - } - - lPos = qwtMax(rSlot.bottom(), rThumb.bottom()) + 1; - if (rThumb.bottom() < rBound.bottom()) - { - p->fillRect(rBound.left(), rThumb.bottom() + 1, - rSlot.left() - rBound.left(), - rBound.bottom() - rThumb.bottom(), brBack); - p->fillRect(rSlot.right() + 1, rThumb.bottom() + 1, - rBound.right() - rSlot.right(), - rBound.bottom() - rThumb.bottom(), brBack); - if (lPos <= rBound.bottom()) - p->fillRect(rSlot.left(), lPos, ws, rBound.bottom() - lPos + 1, brBack); - - p->setPen(pal.dark().color()); - if (rSlot.bottom() > rThumb.bottom()) - { - p->drawLine(rSlot.left(), rThumb.bottom() + 1, rSlot.left(), rSlot.bottom()); - p->setPen(pal.light().color()); - p->drawLine(rSlot.left() * 1, rSlot.bottom(), rSlot.right(), rSlot.bottom()); - } - - if (rSlot.bottom() > rThumb.bottom() + 1) - { - p->setPen(pal.light().color()); - p->drawLine(rSlot.right(), rThumb.bottom() + 1, rSlot.right(), - rSlot.bottom()); - p->fillRect(rSlot.left() + 1, rThumb.bottom() + 1, - rSlot.width() - 2, rSlot.bottom() - rThumb.bottom() - 1, - QBrush(pal.currentColorGroup() == QPalette::Disabled ? - pal.color(QPalette::Disabled, QPalette::WindowText) : Qt::black)); - } - } + // + // Draw empty upper filling + // + + e_mask.setStart(QPointF(cr.x(), 0)); + e_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); + + QPainterPath e_rect = roundedPath(cr.x(), cr.y(), + cr.width(), ipos + 1, + xrad, yrad, + (RoundCorner) (UpperLeft | UpperRight) ); + + p->fillPath(e_rect, QBrush(e_mask)); + + + // + // Draw lower filling mask + // + + 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, + cr.width(), cr.height() - d_thumbLength - dist1, + xrad, yrad, (RoundCorner) (LowerLeft | LowerRight) ); + + p->fillPath(f_rect, QBrush(f_mask)); + + + // + // Draw thumb + // + + QPainterPath thumb_rect = roundedPath(r.x(), ipos, + r.width(), d_thumbLength, + 2, 2, + (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + + thumbGrad.setStart(QPointF(cr.x(), 0)); + thumbGrad.setFinalStop(QPointF(cr.x() + cr.width(), 0)); + + + p->fillPath(thumb_rect, QBrush(thumbGrad)); + + // center line + p->fillRect(cr.x(), ipos + d_thumbHalf, cr.width(), 1, pal.dark().color()); + + } } @@ -506,11 +446,6 @@ double Slider::getValue( const QPoint &p) int pos; QRect r = d_sliderRect; - r.setLeft(r.left() + d_bwTrough); - r.setRight(r.right() - d_bwTrough); - r.setTop(r.top() - d_bwTrough); - r.setBottom(r.bottom() - d_bwTrough); - if (d_orient == Qt::Horizontal) { @@ -579,21 +514,11 @@ void Slider::getScrollMode( QPoint &p, const Qt::MouseButton &button, int &scrol QPoint cp; int ipos,dist1; double rpos; - int lineDist; - - if(d_bwTrough > 0) - cr.setRect(d_sliderRect.x() + d_bwTrough, - d_sliderRect.y() + d_bwTrough, - d_sliderRect.width() - 2*d_bwTrough, - d_sliderRect.height() - 2*d_bwTrough); - else - cr = d_sliderRect; + + cr = d_sliderRect; rpos = (value() - minValue()) / (maxValue() - minValue()); - lineDist = d_borderWidth - 1; - if(lineDist < 1) lineDist = 1; - if(d_orient == Qt::Horizontal) { dist1 = int(double(cr.width() - d_thumbLength) * rpos); @@ -687,7 +612,7 @@ void Slider::resizeEvent(QResizeEvent *e) d_resized = TRUE; QSize s = e->size(); - int sliderWidth = d_thumbWidth + 2 * d_bwTrough; + int sliderWidth = d_thumbWidth; // reposition slider if(d_orient == Qt::Horizontal) @@ -701,9 +626,9 @@ void Slider::resizeEvent(QResizeEvent *e) - d_yMargin - sliderWidth, s.width() - 2 * d_xMargin, sliderWidth); - d_scale.setGeometry(d_sliderRect.x() + d_bwTrough + d_thumbHalf, + d_scale.setGeometry(d_sliderRect.x() + d_thumbHalf, d_sliderRect.y() - d_scaleDist, - d_sliderRect.width() - d_thumbLength - 2*d_bwTrough, + d_sliderRect.width() - d_thumbLength, ScaleDraw::Top); break; @@ -714,9 +639,9 @@ void Slider::resizeEvent(QResizeEvent *e) this->rect().y() + d_yMargin, s.width() - 2*d_xMargin, sliderWidth); - d_scale.setGeometry(d_sliderRect.x() + d_bwTrough + d_thumbHalf, + d_scale.setGeometry(d_sliderRect.x() + d_thumbHalf, d_sliderRect.y() + d_sliderRect.height() + d_scaleDist, - d_sliderRect.width() - d_thumbLength - 2*d_bwTrough, + d_sliderRect.width() - d_thumbLength, ScaleDraw::Bottom); break; @@ -727,7 +652,7 @@ void Slider::resizeEvent(QResizeEvent *e) break; } } - else + else // d_orient == Qt::Vertical { switch(d_scalePos) { @@ -738,8 +663,8 @@ void Slider::resizeEvent(QResizeEvent *e) sliderWidth, s.height() - 2 * d_yMargin); d_scale.setGeometry(d_sliderRect.x() - d_scaleDist, - d_sliderRect.y() + d_thumbHalf + d_bwTrough, - s.height() - d_thumbLength - 2*d_bwTrough, + d_sliderRect.y() + d_thumbHalf, + s.height() - d_thumbLength, ScaleDraw::Left); break; @@ -750,8 +675,8 @@ void Slider::resizeEvent(QResizeEvent *e) s.height() - 2* d_yMargin); d_scale.setGeometry(this->rect().x() + d_sliderRect.width() + d_scaleDist, - d_sliderRect.y() + d_thumbHalf + d_bwTrough, - s.height() - d_thumbLength - 2*d_bwTrough, + d_sliderRect.y() + d_thumbHalf, + s.height() - d_thumbLength, ScaleDraw::Right); break; default: @@ -759,8 +684,8 @@ void Slider::resizeEvent(QResizeEvent *e) s.width(), s.height()); break; } - } + } } //------------------------------------------------------------ @@ -847,20 +772,20 @@ QSize Slider::sizeHint() //const ddskrjo switch(d_orient) { case Qt::Vertical: - w = 2*d_xMargin + d_thumbWidth + 2*d_bwTrough + msWidth + d_scaleDist + 2; + w = 2*d_xMargin + d_thumbWidth + msWidth + d_scaleDist + 2; break; case Qt::Horizontal: - h = 2*d_yMargin + d_thumbWidth + 2*d_bwTrough + msHeight + d_scaleDist; + h = 2*d_yMargin + d_thumbWidth + msHeight + d_scaleDist; break; } } else { // no scale switch(d_orient) { case Qt::Vertical: - w = 16 + 2 * d_bwTrough; + w = 16; break; case Qt::Horizontal: - h = 16 + 2 * d_bwTrough; + h = 16; break; } } diff --git a/muse2/muse/widgets/slider.h b/muse2/muse/widgets/slider.h index 72fcc6ba..0409cb4f 100644 --- a/muse2/muse/widgets/slider.h +++ b/muse2/muse/widgets/slider.h @@ -28,7 +28,7 @@ class Slider : public SliderBase, public ScaleIf public: enum ScalePos { None, Left, Right, Top, Bottom }; - enum { BgTrough = 0x1, BgSlot = 0x2 }; + enum RoundCorner { UpperLeft = 0x1, UpperRight = 0x2, LowerLeft = 0x4, LowerRight = 0x8 }; private: Q_PROPERTY( double lineStep READ lineStep WRITE setLineStep ) @@ -40,11 +40,12 @@ class Slider : public SliderBase, public ScaleIf int d_thumbLength; int d_thumbHalf; int d_thumbWidth; - int d_borderWidth; - int d_bwTrough; int d_scaleDist; int d_xMargin; int d_yMargin; + int d_mMargin; + + QColor d_fillColor; int d_resized; bool d_autoResize; @@ -55,6 +56,8 @@ 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&); @@ -71,9 +74,9 @@ class Slider : public SliderBase, public ScaleIf public: Slider(QWidget *parent, const char *name = 0, - Qt::Orientation orient = Qt::Vertical, - ScalePos scalePos = None, - int bgStyle = BgTrough); + Qt::Orientation orient = Qt::Vertical, + ScalePos scalePos = None, + QColor fillColor = QColor(100, 100, 255)); ~Slider(); void setThumbLength(int l); @@ -88,7 +91,6 @@ class Slider : public SliderBase, public ScaleIf void setLineStep(double); void setPageStep(double); - void setBorderWidth(int bw); void setMargins(int x, int y); QSize sizeHint(); // const; }; |