diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d226a8c..443881e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -19,13 +20,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_trayIcon(nullptr), m_authManager(new AuthManager(this)), m_settingsDialog(nullptr), m_authDialog(nullptr), m_data(nullptr), m_networkStreamModel(nullptr), m_particleListModel(nullptr), - m_selectedParticleRow(-1) + m_selectedParticleRow(-1), m_isDragging(false) { m_authDialog = new AuthDialog(m_authManager, this); ui = new Ui::MainWindow; ui->setupUi(this); - // this->setWindowFlags(Qt::FramelessWindowHint); + + // Enable frameless window for edge-to-edge experience + setWindowFlags(Qt::FramelessWindowHint | Qt::Window); + setAttribute(Qt::WA_TranslucentBackground, false); // Style for grey status bar text QString statusBarLabelStyle = "QLabel { color: #808080; }"; @@ -359,3 +363,40 @@ void MainWindow::updatePingIndicator() m_pingLabel->setText("connected " + QString::number(currentPing) + "ms"); } + +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + // Check if the click is within the top bar widget area + QWidget *topBar = ui->widget; // The top bar widget from the UI + if (topBar && topBar->geometry().contains(event->pos())) + { + m_isDragging = true; + m_dragPosition = event->globalPosition().toPoint() - frameGeometry().topLeft(); + event->accept(); + return; + } + } + QMainWindow::mousePressEvent(event); +} + +void MainWindow::mouseMoveEvent(QMouseEvent *event) +{ + if (m_isDragging && (event->buttons() & Qt::LeftButton)) + { + move(event->globalPosition().toPoint() - m_dragPosition); + event->accept(); + return; + } + QMainWindow::mouseMoveEvent(event); +} + +void MainWindow::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + m_isDragging = false; + } + QMainWindow::mouseReleaseEvent(event); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index e3d5fe9..aa67626 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -42,6 +42,11 @@ private slots: void onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void onParticleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + private: void setupTrayIcon(); void setupModels(); @@ -70,6 +75,10 @@ private: QLabel *m_storageLabel; QLabel *m_pingLabel; QTimer *m_pingTimer; + + // Window dragging + QPoint m_dragPosition; + bool m_isDragging; }; #endif // LLINK_MAINWINDOW_H