Mercurial > hg > svgui
diff widgets/Panner.cpp @ 173:9c40dc10c88c
* Rename the existing Panner to Overview (big duh!)
* Fixes to the new Panner.
author | Chris Cannam |
---|---|
date | Thu, 19 Oct 2006 09:57:27 +0000 |
parents | d0b95a8cac96 |
children | 96b8a790730a |
line wrap: on
line diff
--- a/widgets/Panner.cpp Wed Oct 18 16:38:30 2006 +0000 +++ b/widgets/Panner.cpp Thu Oct 19 09:57:27 2006 +0000 @@ -27,7 +27,11 @@ m_rectX(0), m_rectY(0), m_rectWidth(1), - m_rectHeight(1) + m_rectHeight(1), + m_defaultCentreX(0), + m_defaultCentreY(0), + m_defaultsSet(false), + m_clicked(false) { } @@ -38,38 +42,81 @@ void Panner::mousePressEvent(QMouseEvent *e) { + if (e->button() == Qt::LeftButton) { + m_clicked = true; + m_clickPos = e->pos(); + m_dragStartX = m_rectX; + m_dragStartY = m_rectY; + } else if (e->button() == Qt::MidButton) { + resetToDefault(); + } } void Panner::mouseDoubleClickEvent(QMouseEvent *e) { + resetToDefault(); } void Panner::mouseMoveEvent(QMouseEvent *e) { + if (!m_clicked) return; + + float dx = float(e->pos().x() - m_clickPos.x()) / float(width()); + float dy = float(e->pos().y() - m_clickPos.y()) / float(height()); + + m_rectX = m_dragStartX + dx; + m_rectY = m_dragStartY + dy; + + normalise(); + emitAndUpdate(); } void Panner::mouseReleaseEvent(QMouseEvent *e) { + if (!m_clicked) return; + + mouseMoveEvent(e); + m_clicked = false; } void Panner::wheelEvent(QWheelEvent *e) { + if (e->delta() > 0) { + m_rectY += 0.1; + } else { + m_rectY -= 0.1; + } + + normalise(); + emitAndUpdate(); } void Panner::paintEvent(QPaintEvent *e) { QPainter paint(this); - paint.fillRect(rect(), palette().background().color()); paint.setRenderHint(QPainter::Antialiasing, false); + + QColor bg(palette().background().color()); + bg.setAlpha(80); + paint.setPen(palette().dark().color()); - paint.setBrush(palette().highlight().color()); - paint.drawRect(QRectF(width() * m_rectX, height() - height() * m_rectY, - width() * m_rectWidth, height() * m_rectHeight)); + paint.setBrush(bg); + paint.drawRect(0, 0, width(), height()); + + QColor hl(palette().highlight().color()); + hl.setAlpha(80); + + paint.setBrush(hl); + + paint.drawRect(lrintf(width() * m_rectX), + lrintf(height() * m_rectY), + lrintf(width() * m_rectWidth), + lrintf(height() * m_rectHeight)); } void @@ -81,13 +128,19 @@ if (m_rectX < 0) m_rectX = 0; if (m_rectY + m_rectHeight > 1.0) m_rectY = 1.0 - m_rectHeight; if (m_rectY < 0) m_rectY = 0; + + if (!m_defaultsSet) { + m_defaultCentreX = centreX(); + m_defaultCentreY = centreY(); + m_defaultsSet = true; + } } void Panner::emitAndUpdate() { emit rectExtentsChanged(m_rectX, m_rectY, m_rectWidth, m_rectHeight); - emit rectCentreMoved(m_rectX + (m_rectWidth/2), m_rectY + (m_rectHeight/2)); + emit rectCentreMoved(centreX(), centreY()); update(); } @@ -100,10 +153,12 @@ m_rectHeight == height) { return; } + m_rectX = x0; m_rectY = y0; m_rectWidth = width; m_rectHeight = height; + normalise(); emitAndUpdate(); } @@ -139,7 +194,7 @@ void Panner::setRectCentreY(float y) { - float y0 = y - m_rectWidth/2; + float y0 = y - m_rectHeight/2; if (y0 == m_rectY) return; m_rectY = y0; normalise(); @@ -152,5 +207,24 @@ return QSize(30, 30); } +void +Panner::setDefaultRectCentre(float cx, float cy) +{ + m_defaultCentreX = cx; + m_defaultCentreY = cy; + m_defaultsSet = true; +} +void +Panner::resetToDefault() +{ + float x0 = m_defaultCentreX - m_rectWidth/2; + float y0 = m_defaultCentreY - m_rectHeight/2; + if (x0 == m_rectX && y0 == m_rectY) return; + m_rectX = x0; + m_rectY = y0; + normalise(); + emitAndUpdate(); +} +