feat: allow dragging frameless window
This commit is contained in:
+43
-2
@@ -12,6 +12,7 @@
|
|||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QMouseEvent>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -19,13 +20,16 @@
|
|||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), m_trayIcon(nullptr), m_authManager(new AuthManager(this)), m_settingsDialog(nullptr),
|
: 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_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);
|
m_authDialog = new AuthDialog(m_authManager, this);
|
||||||
|
|
||||||
ui = new Ui::MainWindow;
|
ui = new Ui::MainWindow;
|
||||||
ui->setupUi(this);
|
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
|
// Style for grey status bar text
|
||||||
QString statusBarLabelStyle = "QLabel { color: #808080; }";
|
QString statusBarLabelStyle = "QLabel { color: #808080; }";
|
||||||
@@ -359,3 +363,40 @@ void MainWindow::updatePingIndicator()
|
|||||||
|
|
||||||
m_pingLabel->setText("connected " + QString::number(currentPing) + "ms");
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ private slots:
|
|||||||
void onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void onParticleSelectionChanged(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:
|
private:
|
||||||
void setupTrayIcon();
|
void setupTrayIcon();
|
||||||
void setupModels();
|
void setupModels();
|
||||||
@@ -70,6 +75,10 @@ private:
|
|||||||
QLabel *m_storageLabel;
|
QLabel *m_storageLabel;
|
||||||
QLabel *m_pingLabel;
|
QLabel *m_pingLabel;
|
||||||
QTimer *m_pingTimer;
|
QTimer *m_pingTimer;
|
||||||
|
|
||||||
|
// Window dragging
|
||||||
|
QPoint m_dragPosition;
|
||||||
|
bool m_isDragging;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LLINK_MAINWINDOW_H
|
#endif // LLINK_MAINWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user