From a348a4529d89695bcd10a7063527373698a7c4e5 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 19 Dec 2010 14:06:51 +0000 Subject: [PATCH] Make the pretty OSD snap to the center of the screen while dragging. Thanks brunciter. --- src/widgets/osdpretty.cpp | 9 +++++++++ src/widgets/osdpretty.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/widgets/osdpretty.cpp b/src/widgets/osdpretty.cpp index 90cdccfee..69f3dee09 100644 --- a/src/widgets/osdpretty.cpp +++ b/src/widgets/osdpretty.cpp @@ -46,6 +46,8 @@ const int OSDPretty::kDropShadowSize = 13; const int OSDPretty::kBorderRadius = 10; const int OSDPretty::kMaxIconSize = 100; +const int OSDPretty::kSnapProximity = 20; + const QRgb OSDPretty::kPresetBlue = qRgb(102, 150, 227); const QRgb OSDPretty::kPresetOrange = qRgb(254, 156, 67); @@ -337,6 +339,13 @@ void OSDPretty::mouseMoveEvent(QMouseEvent* e) { new_pos.setX(qBound(geometry.left(), new_pos.x(), geometry.right() - width())); new_pos.setY(qBound(geometry.top(), new_pos.y(), geometry.bottom() - height())); + // Snap to center + int snap_x = geometry.center().x() - width() / 2; + qDebug() << snap_x << new_pos.x(); + if (new_pos.x() > snap_x - kSnapProximity && new_pos.x() < snap_x + kSnapProximity) { + new_pos.setX(snap_x); + } + move(new_pos); popup_display_ = current_display(); diff --git a/src/widgets/osdpretty.h b/src/widgets/osdpretty.h index f3b9cccb0..fa734b526 100644 --- a/src/widgets/osdpretty.h +++ b/src/widgets/osdpretty.h @@ -42,6 +42,8 @@ class OSDPretty : public QWidget { static const int kBorderRadius; static const int kMaxIconSize; + static const int kSnapProximity; + static const QRgb kPresetBlue; static const QRgb kPresetOrange;