making user dialog draggable on windows

This commit is contained in:
fourtf 2018-06-19 19:42:15 +02:00
parent 78b20776a8
commit b2be44bbe7
4 changed files with 49 additions and 19 deletions

View file

@ -16,6 +16,7 @@
#include <QDebug> #include <QDebug>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QIcon> #include <QIcon>
#include <functional>
#ifdef USEWINSDK #ifdef USEWINSDK
#include <ObjIdl.h> #include <ObjIdl.h>
@ -393,8 +394,6 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
} }
} break; } break;
case WM_NCHITTEST: { case WM_NCHITTEST: {
if (this->hasCustomWindowFrame()) {
*result = 0;
const LONG border_width = 8; // in pixels const LONG border_width = 8; // in pixels
RECT winrect; RECT winrect;
GetWindowRect(HWND(winId()), &winrect); GetWindowRect(HWND(winId()), &winrect);
@ -402,6 +401,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
long x = GET_X_LPARAM(msg->lParam); long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam); long y = GET_Y_LPARAM(msg->lParam);
QPoint point(x - winrect.left, y - winrect.top);
if (this->hasCustomWindowFrame()) {
*result = 0;
bool resizeWidth = minimumWidth() != maximumWidth(); bool resizeWidth = minimumWidth() != maximumWidth();
bool resizeHeight = minimumHeight() != maximumHeight(); bool resizeHeight = minimumHeight() != maximumHeight();
@ -451,7 +455,6 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
if (*result == 0) { if (*result == 0) {
bool client = false; bool client = false;
QPoint point(x - winrect.left, y - winrect.top);
for (QWidget *widget : this->ui_.buttons) { for (QWidget *widget : this->ui_.buttons) {
if (widget->geometry().contains(point)) { if (widget->geometry().contains(point)) {
client = true; client = true;
@ -469,6 +472,36 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
} }
} }
return true;
} else if (this->flags_ & FramelessDraggable) {
*result = 0;
bool client = false;
if (auto widget = this->childAt(point)) {
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)) {
client = true;
}
}
if (client) {
*result = HTCLIENT;
} else {
*result = HTCAPTION;
}
return true; return true;
} else { } else {
return QWidget::nativeEvent(eventType, message, result); return QWidget::nativeEvent(eventType, message, result);

View file

@ -27,6 +27,7 @@ public:
TopMost = 4, TopMost = 4,
DeleteOnFocusOut = 8, DeleteOnFocusOut = 8,
DisableCustomScaling = 16, DisableCustomScaling = 16,
FramelessDraggable = 32,
}; };
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None); explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);

View file

@ -129,8 +129,8 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
this->dropdownMenu.addSeparator(); this->dropdownMenu.addSeparator();
this->dropdownMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes())); this->dropdownMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
this->dropdownMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect())); this->dropdownMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
this->dropdownMenu.addSeparator(); // this->dropdownMenu.addSeparator();
this->dropdownMenu.addAction("Show changelog", this, SLOT(menuShowChangelog())); // this->dropdownMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
// clang-format on // clang-format on
} }

View file

@ -22,7 +22,8 @@ namespace chatterino {
namespace widgets { namespace widgets {
UserInfoPopup::UserInfoPopup() UserInfoPopup::UserInfoPopup()
: BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless | BaseWindow::DeleteOnFocusOut)) : BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless | BaseWindow::DeleteOnFocusOut |
BaseWindow::FramelessDraggable))
, hack_(new bool) , hack_(new bool)
{ {
this->setStayInScreenRect(true); this->setStayInScreenRect(true);
@ -376,21 +377,16 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
addTimeouts("sec", {{"1", 1}}); addTimeouts("sec", {{"1", 1}});
addTimeouts("min", { addTimeouts("min", {
{"1", 1 * 60}, {"1", 1 * 60}, {"5", 5 * 60}, {"10", 10 * 60},
{"5", 5 * 60},
{"10", 10 * 60},
}); });
addTimeouts("hour", { addTimeouts("hour", {
{"1", 1 * 60 * 60}, {"1", 1 * 60 * 60}, {"4", 4 * 60 * 60},
{"4", 4 * 60 * 60},
}); });
addTimeouts("days", { addTimeouts("days", {
{"1", 1 * 60 * 60 * 24}, {"1", 1 * 60 * 60 * 24}, {"3", 3 * 60 * 60 * 24},
{"3", 3 * 60 * 60 * 24},
}); });
addTimeouts("weeks", { addTimeouts("weeks", {
{"1", 1 * 60 * 60 * 24 * 7}, {"1", 1 * 60 * 60 * 24 * 7}, {"2", 2 * 60 * 60 * 24 * 7},
{"2", 2 * 60 * 60 * 24 * 7},
}); });
addButton(Ban, "ban", getApp()->resources->buttons.ban); addButton(Ban, "ban", getApp()->resources->buttons.ban);