mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Implement "frameless draggable" windows on Linux
Not yet tested on Mac but should work just the same Fix #472
This commit is contained in:
parent
a105b47a6b
commit
fc0e89edf3
|
@ -254,6 +254,64 @@ void BaseWindow::wheelEvent(QWheelEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void BaseWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
#ifndef Q_OS_WIN
|
||||
if (this->flags_ & FramelessDraggable) {
|
||||
this->movingRelativePos = event->localPos();
|
||||
if (auto widget = this->childAt(event->localPos().x(), event->localPos().y())) {
|
||||
std::function<bool(QWidget *)> recursiveCheckMouseTracking;
|
||||
recursiveCheckMouseTracking = [&](QWidget *widget) {
|
||||
if (widget == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (widget->hasMouseTracking()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return recursiveCheckMouseTracking(widget->parentWidget());
|
||||
};
|
||||
|
||||
if (!recursiveCheckMouseTracking(widget)) {
|
||||
debug::Log("Start moving");
|
||||
this->moving = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BaseWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void BaseWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
#ifndef Q_OS_WIN
|
||||
if (this->flags_ & FramelessDraggable) {
|
||||
if (this->moving) {
|
||||
debug::Log("Stop moving");
|
||||
this->moving = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BaseWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void BaseWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
#ifndef Q_OS_WIN
|
||||
if (this->flags_ & FramelessDraggable) {
|
||||
if (this->moving) {
|
||||
const auto &newPos = event->screenPos() - this->movingRelativePos;
|
||||
this->move(newPos.x(), newPos.y());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BaseWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void BaseWindow::addTitleBarButton(const TitleBarButton::Style &style,
|
||||
std::function<void()> onClicked)
|
||||
{
|
||||
|
@ -588,5 +646,6 @@ void BaseWindow::calcButtonsSizes()
|
|||
this->ui_.exitButton->setScaleIndependantSize(46, 30);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -63,6 +63,12 @@ protected:
|
|||
virtual bool event(QEvent *event) override;
|
||||
virtual void wheelEvent(QWheelEvent *event) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
QPointF movingRelativePos;
|
||||
bool moving{};
|
||||
|
||||
void updateScale();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue