diff --git a/focusoverlay.cpp b/focusoverlay.cpp index 5aa7dbf..4527f9e 100644 --- a/focusoverlay.cpp +++ b/focusoverlay.cpp @@ -2,10 +2,12 @@ #include "ui_focusoverlay.h" #include #include +#include FocusOverlay::FocusOverlay(QWidget *parent) : QWidget(parent), - ui(new Ui::FocusOverlay) + ui(new Ui::FocusOverlay), + m_dragging(false) { ui->setupUi(this); @@ -71,3 +73,28 @@ void FocusOverlay::positionAtBottomCenter() move(x, y); } + +void FocusOverlay::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + m_dragging = true; + m_dragStartPosition = event->globalPosition().toPoint() - frameGeometry().topLeft(); + event->accept(); + } +} + +void FocusOverlay::mouseMoveEvent(QMouseEvent *event) +{ + if (m_dragging && (event->buttons() & Qt::LeftButton)) { + move(event->globalPosition().toPoint() - m_dragStartPosition); + event->accept(); + } +} + +void FocusOverlay::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + m_dragging = false; + event->accept(); + } +} diff --git a/focusoverlay.h b/focusoverlay.h index 58862ca..ab02928 100644 --- a/focusoverlay.h +++ b/focusoverlay.h @@ -26,9 +26,18 @@ private slots: void onResetButtonClicked(); void onEndButtonClicked(); +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + private: Ui::FocusOverlay *ui; void positionAtBottomCenter(); + + // For dragging + bool m_dragging; + QPoint m_dragStartPosition; }; #endif // FOCUSOVERLAY_H diff --git a/focusoverlay.ui b/focusoverlay.ui index c7cc5e8..dd323e5 100644 --- a/focusoverlay.ui +++ b/focusoverlay.ui @@ -6,10 +6,28 @@ 0 0 - 400 - 120 + 350 + 102 + + + 0 + 0 + + + + + 350 + 80 + + + + + 350 + 102 + + Focus Session @@ -41,7 +59,7 @@ QPushButton:pressed { background-color: rgba(60, 60, 60, 255); } - + 10 @@ -58,44 +76,70 @@ QPushButton:pressed { 15 - - - - 14 - 75 - true - - - - Session Oneliner - - - Qt::AlignCenter - + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 14 + true + + + + Session Oneliner + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + + + + + 12 + + + + Elapsed: 00:00:00 + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + - - - - 12 - - - - Elapsed: 00:00:00 - - - Qt::AlignCenter - - - - - + Reset + + true + + + false +