summaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@nokia.com>2010-08-13 17:17:50 +0200
committerThomas Hartmann <Thomas.Hartmann@nokia.com>2010-08-13 17:22:22 +0200
commitb372f9db029fc199c63ddb20d0bf1121331cdd92 (patch)
tree1929d037b96c9fdf4228604c17953cbc3ac4b273 /src/libs
parent36c40b985b63b5cb0a8296e07643554d5aeb5f55 (diff)
downloadqt-creator-b372f9db029fc199c63ddb20d0bf1121331cdd92.tar.gz
QuickToolBar: use absolute positioning for dragging
This resolves several usability bugs.
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/qmleditorwidgets/contextpanewidget.cpp39
-rw-r--r--src/libs/qmleditorwidgets/contextpanewidget.h2
2 files changed, 25 insertions, 16 deletions
diff --git a/src/libs/qmleditorwidgets/contextpanewidget.cpp b/src/libs/qmleditorwidgets/contextpanewidget.cpp
index 267d3854e3..d3b9941aad 100644
--- a/src/libs/qmleditorwidgets/contextpanewidget.cpp
+++ b/src/libs/qmleditorwidgets/contextpanewidget.cpp
@@ -92,7 +92,7 @@ DragWidget::DragWidget(QWidget *parent) : QFrame(parent)
setFrameStyle(QFrame::NoFrame);
setFrameShape(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
- m_oldPos = QPoint(-1, -1);
+ m_startPos = QPoint(-1, -1);
m_pos = QPoint(-1, -1);
m_dropShadowEffect = new QGraphicsDropShadowEffect;
@@ -104,7 +104,7 @@ DragWidget::DragWidget(QWidget *parent) : QFrame(parent)
void DragWidget::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton) {
- m_oldPos = event->globalPos();
+ m_startPos = event->globalPos() - parentWidget()->mapToGlobal((pos()));
m_opacityEffect = new QGraphicsOpacityEffect;
setGraphicsEffect(m_opacityEffect);
event->accept();
@@ -115,7 +115,7 @@ void DragWidget::mousePressEvent(QMouseEvent * event)
void DragWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
- m_oldPos = QPoint(-1, -1);
+ m_startPos = QPoint(-1, -1);
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
@@ -124,26 +124,35 @@ void DragWidget::mouseReleaseEvent(QMouseEvent *event)
QFrame::mouseReleaseEvent(event);
}
+static inline int limit(int a, int min, int max)
+{
+ if (a < min)
+ return min;
+ if (a > max)
+ return max;
+ return a;
+}
+
void DragWidget::mouseMoveEvent(QMouseEvent * event)
{
if (event->buttons() && Qt::LeftButton) {
- if (pos().x() < 10 && event->pos().x() < -20)
- return;
- if (m_oldPos != QPoint(-1, -1)) {
- QPoint diff = event->globalPos() - m_oldPos;
- QPoint newPos = pos() + diff;
- if (newPos.x() > 0 && newPos.y() > 0 && (newPos.x() + width()) < parentWidget()->width() && (newPos.y() + height()) < parentWidget()->height()) {
- if (m_secondaryTarget)
- m_secondaryTarget->move(m_secondaryTarget->pos() + diff);
- move(newPos);
- m_pos = newPos;
+ if (m_startPos != QPoint(-1, -1)) {
+ QPoint newPos = parentWidget()->mapFromGlobal(event->globalPos() - m_startPos);
+
+ newPos.setX(limit(newPos.x(), 20, parentWidget()->width() - 20 - width()));
+ newPos.setY(limit(newPos.y(), 2, parentWidget()->height() - 20 - height()));
+
+ QPoint diff = pos() - newPos;
+ if (m_secondaryTarget)
+ m_secondaryTarget->move(m_secondaryTarget->pos() - diff);
+ move(newPos);
+ if (m_pos != newPos)
protectedMoved();
- }
+ m_pos = newPos;
} else {
m_opacityEffect = new QGraphicsOpacityEffect;
setGraphicsEffect(m_opacityEffect);
}
- m_oldPos = event->globalPos();
event->accept();
}
}
diff --git a/src/libs/qmleditorwidgets/contextpanewidget.h b/src/libs/qmleditorwidgets/contextpanewidget.h
index 129d24a1b7..d7d4d83b47 100644
--- a/src/libs/qmleditorwidgets/contextpanewidget.h
+++ b/src/libs/qmleditorwidgets/contextpanewidget.h
@@ -68,7 +68,7 @@ protected:
private:
QGraphicsDropShadowEffect *m_dropShadowEffect;
QGraphicsOpacityEffect *m_opacityEffect;
- QPoint m_oldPos;
+ QPoint m_startPos;
QWeakPointer<QWidget> m_secondaryTarget;
};