mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Add drag distance for move-by-titlebar to process double click right
This commit is contained in:
parent
a38b4f039a
commit
49e96d857a
2 changed files with 34 additions and 9 deletions
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -231,17 +232,26 @@ void TitleWidgetQt::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
||||||
void TitleWidgetQt::mousePressEvent(QMouseEvent *e) {
|
void TitleWidgetQt::mousePressEvent(QMouseEvent *e) {
|
||||||
if (e->button() == Qt::LeftButton) {
|
if (e->button() == Qt::LeftButton) {
|
||||||
startMove();
|
if ((crl::now() - _pressedForMoveTime)
|
||||||
|
< QApplication::doubleClickInterval()) {
|
||||||
|
if (_maximizedState) {
|
||||||
|
window()->setWindowState(Qt::WindowNoState);
|
||||||
|
} else {
|
||||||
|
window()->setWindowState(Qt::WindowMaximized);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_pressedForMove = true;
|
||||||
|
_pressedForMoveTime = crl::now();
|
||||||
|
_pressedForMovePoint = e->windowPos().toPoint();
|
||||||
|
}
|
||||||
} else if (e->button() == Qt::RightButton) {
|
} else if (e->button() == Qt::RightButton) {
|
||||||
Platform::ShowWindowMenu(window()->windowHandle());
|
Platform::ShowWindowMenu(window()->windowHandle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidgetQt::mouseDoubleClickEvent(QMouseEvent *e) {
|
void TitleWidgetQt::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
if (_maximizedState) {
|
if (e->button() == Qt::LeftButton) {
|
||||||
window()->setWindowState(Qt::WindowNoState);
|
_pressedForMove = false;
|
||||||
} else {
|
|
||||||
window()->setWindowState(Qt::WindowMaximized);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,14 +260,26 @@ bool TitleWidgetQt::eventFilter(QObject *obj, QEvent *e) {
|
||||||
|| e->type() == QEvent::MouseButtonPress) {
|
|| e->type() == QEvent::MouseButtonPress) {
|
||||||
if (window()->isAncestorOf(static_cast<QWidget*>(obj))) {
|
if (window()->isAncestorOf(static_cast<QWidget*>(obj))) {
|
||||||
const auto mouseEvent = static_cast<QMouseEvent*>(e);
|
const auto mouseEvent = static_cast<QMouseEvent*>(e);
|
||||||
const auto edges = edgesFromPos(
|
const auto currentPoint = mouseEvent->windowPos().toPoint();
|
||||||
mouseEvent->windowPos().toPoint());
|
const auto edges = edgesFromPos(currentPoint);
|
||||||
|
const auto dragDistance = QApplication::startDragDistance();
|
||||||
|
|
||||||
if (e->type() == QEvent::MouseMove
|
if (e->type() == QEvent::MouseMove
|
||||||
&& mouseEvent->buttons() == Qt::NoButton) {
|
&& mouseEvent->buttons() == Qt::NoButton) {
|
||||||
|
if (_pressedForMove) {
|
||||||
|
_pressedForMove = false;
|
||||||
|
}
|
||||||
|
|
||||||
updateCursor(edges);
|
updateCursor(edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e->type() == QEvent::MouseMove
|
||||||
|
&& _pressedForMove
|
||||||
|
&& ((currentPoint - _pressedForMovePoint).manhattanLength()
|
||||||
|
>= dragDistance)) {
|
||||||
|
return startMove();
|
||||||
|
}
|
||||||
|
|
||||||
if (e->type() == QEvent::MouseButtonPress
|
if (e->type() == QEvent::MouseButtonPress
|
||||||
&& mouseEvent->button() == Qt::LeftButton
|
&& mouseEvent->button() == Qt::LeftButton
|
||||||
&& !_maximizedState) {
|
&& !_maximizedState) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
bool eventFilter(QObject *obj, QEvent *e) override;
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
||||||
|
|
||||||
|
@ -73,6 +73,9 @@ private:
|
||||||
bool _windowWasFrameless = false;
|
bool _windowWasFrameless = false;
|
||||||
bool _cursorOverriden = false;
|
bool _cursorOverriden = false;
|
||||||
bool _extentsSet = false;
|
bool _extentsSet = false;
|
||||||
|
bool _pressedForMove = false;
|
||||||
|
crl::time _pressedForMoveTime = 0;
|
||||||
|
QPoint _pressedForMovePoint;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue