2018-06-26 14:09:39 +02:00
|
|
|
#include "BaseWindow.hpp"
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-06-11 15:04:54 +02:00
|
|
|
#include "boost/algorithm/algorithm.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "debug/Log.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/PostToThread.hpp"
|
|
|
|
#include "util/WindowsHelper.hpp"
|
|
|
|
#include "widgets/Label.hpp"
|
|
|
|
#include "widgets/TooltipWidget.hpp"
|
2018-08-08 15:35:54 +02:00
|
|
|
#include "widgets/helper/EffectLabel.hpp"
|
2018-06-26 17:06:17 +02:00
|
|
|
#include "widgets/helper/Shortcut.hpp"
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-01-15 01:35:35 +01:00
|
|
|
#include <QApplication>
|
2018-01-14 21:55:36 +01:00
|
|
|
#include <QDebug>
|
2018-01-22 20:52:32 +01:00
|
|
|
#include <QDesktopWidget>
|
2018-01-14 21:55:36 +01:00
|
|
|
#include <QIcon>
|
2018-06-19 19:42:15 +02:00
|
|
|
#include <functional>
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-01-15 01:35:35 +01:00
|
|
|
#ifdef USEWINSDK
|
2018-08-15 22:46:20 +02:00
|
|
|
# include <ObjIdl.h>
|
|
|
|
# include <VersionHelpers.h>
|
|
|
|
# include <Windows.h>
|
|
|
|
# include <dwmapi.h>
|
|
|
|
# include <gdiplus.h>
|
|
|
|
# include <windowsx.h>
|
2018-06-25 12:20:36 +02:00
|
|
|
|
2018-06-25 12:41:55 +02:00
|
|
|
//#include <ShellScalingApi.h>
|
2018-08-15 22:46:20 +02:00
|
|
|
# pragma comment(lib, "Dwmapi.lib")
|
2018-06-25 12:41:55 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
# include <QHBoxLayout>
|
|
|
|
# include <QVBoxLayout>
|
2018-01-15 01:35:35 +01:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
# define WM_DPICHANGED 0x02E0
|
2018-01-15 01:35:35 +01:00
|
|
|
#endif
|
2018-01-14 21:59:45 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/TitlebarButton.hpp"
|
2018-01-15 04:08:48 +01:00
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
namespace chatterino {
|
|
|
|
|
2018-05-24 10:03:07 +02:00
|
|
|
BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
|
|
|
|
: BaseWidget(parent,
|
2018-08-06 21:17:03 +02:00
|
|
|
Qt::Window | ((_flags & TopMost) ? Qt::WindowStaysOnTopHint
|
|
|
|
: Qt::WindowFlags()))
|
2018-06-11 15:04:54 +02:00
|
|
|
, enableCustomFrame_(_flags & EnableCustomFrame)
|
|
|
|
, frameless_(_flags & Frameless)
|
|
|
|
, flags_(_flags)
|
2018-01-14 21:55:36 +01:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->frameless_)
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
this->enableCustomFrame_ = false;
|
2018-05-23 22:27:29 +02:00
|
|
|
this->setWindowFlag(Qt::FramelessWindowHint);
|
|
|
|
}
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
this->init();
|
2018-06-11 15:04:54 +02:00
|
|
|
|
2018-11-03 13:00:07 +01:00
|
|
|
getSettings()->uiScale.connect(
|
|
|
|
[this]() { postToThread([this] { this->updateScale(); }); },
|
|
|
|
this->connections_);
|
2018-06-11 15:04:54 +02:00
|
|
|
|
|
|
|
this->updateScale();
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
createWindowShortcut(this, "CTRL+0",
|
2018-08-12 12:56:28 +02:00
|
|
|
[] { getSettings()->uiScale.setValue(0); });
|
2018-07-04 10:37:53 +02:00
|
|
|
|
|
|
|
// QTimer::this->scaleChangedEvent(this->getScale());
|
2018-01-14 21:55:36 +01:00
|
|
|
}
|
|
|
|
|
2018-06-24 13:32:56 +02:00
|
|
|
float BaseWindow::getScale() const
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
return this->getOverrideScale().value_or(this->scale_);
|
2018-06-24 13:32:56 +02:00
|
|
|
}
|
|
|
|
|
2018-05-24 10:03:07 +02:00
|
|
|
BaseWindow::Flags BaseWindow::getFlags()
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
return this->flags_;
|
2018-05-24 10:03:07 +02:00
|
|
|
}
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
void BaseWindow::init()
|
|
|
|
{
|
|
|
|
this->setWindowIcon(QIcon(":/images/icon.png"));
|
|
|
|
|
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-01-15 01:35:35 +01:00
|
|
|
// CUSTOM WINDOW FRAME
|
2018-01-25 20:49:49 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout();
|
2018-06-24 21:57:03 +02:00
|
|
|
this->ui_.windowLayout = layout;
|
2018-04-08 17:07:40 +02:00
|
|
|
layout->setContentsMargins(0, 1, 0, 0);
|
2018-01-24 15:08:22 +01:00
|
|
|
layout->setSpacing(0);
|
2018-01-15 01:35:35 +01:00
|
|
|
this->setLayout(layout);
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->frameless_)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
QHBoxLayout *buttonLayout = this->ui_.titlebarBox =
|
|
|
|
new QHBoxLayout();
|
2018-05-23 22:27:29 +02:00
|
|
|
buttonLayout->setMargin(0);
|
|
|
|
layout->addLayout(buttonLayout);
|
|
|
|
|
|
|
|
// title
|
2018-06-11 15:04:54 +02:00
|
|
|
Label *title = new Label("Chatterino");
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
this, &QWidget::windowTitleChanged,
|
|
|
|
[title](const QString &text) { title->setText(text); });
|
2018-05-23 22:27:29 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QSizePolicy policy(QSizePolicy::Ignored,
|
|
|
|
QSizePolicy::Preferred);
|
2018-05-23 22:27:29 +02:00
|
|
|
policy.setHorizontalStretch(1);
|
|
|
|
title->setSizePolicy(policy);
|
|
|
|
buttonLayout->addWidget(title);
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.titleLabel = title;
|
2018-05-23 22:27:29 +02:00
|
|
|
|
|
|
|
// buttons
|
|
|
|
TitleBarButton *_minButton = new TitleBarButton;
|
2018-08-11 22:23:06 +02:00
|
|
|
_minButton->setButtonStyle(TitleBarButtonStyle::Minimize);
|
2018-05-23 22:27:29 +02:00
|
|
|
TitleBarButton *_maxButton = new TitleBarButton;
|
2018-08-11 22:23:06 +02:00
|
|
|
_maxButton->setButtonStyle(TitleBarButtonStyle::Maximize);
|
2018-05-23 22:27:29 +02:00
|
|
|
TitleBarButton *_exitButton = new TitleBarButton;
|
2018-08-11 22:23:06 +02:00
|
|
|
_exitButton->setButtonStyle(TitleBarButtonStyle::Close);
|
2018-05-23 22:27:29 +02:00
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(_minButton, &TitleBarButton::leftClicked, this,
|
2018-08-06 21:17:03 +02:00
|
|
|
[this] {
|
|
|
|
this->setWindowState(Qt::WindowMinimized |
|
|
|
|
this->windowState());
|
|
|
|
});
|
2018-10-29 21:12:24 +01:00
|
|
|
QObject::connect(_maxButton, &TitleBarButton::leftClicked, this,
|
|
|
|
[this, _maxButton] {
|
|
|
|
this->setWindowState(
|
|
|
|
_maxButton->getButtonStyle() !=
|
|
|
|
TitleBarButtonStyle::Maximize
|
|
|
|
? Qt::WindowActive
|
|
|
|
: Qt::WindowMaximized);
|
|
|
|
});
|
2018-11-03 13:00:07 +01:00
|
|
|
QObject::connect(_exitButton, &TitleBarButton::leftClicked,
|
|
|
|
this, [this] { this->close(); });
|
2018-05-23 22:27:29 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.minButton = _minButton;
|
|
|
|
this->ui_.maxButton = _maxButton;
|
|
|
|
this->ui_.exitButton = _exitButton;
|
2018-05-23 22:27:29 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.buttons.push_back(_minButton);
|
|
|
|
this->ui_.buttons.push_back(_maxButton);
|
|
|
|
this->ui_.buttons.push_back(_exitButton);
|
2018-05-23 22:27:29 +02:00
|
|
|
|
|
|
|
// buttonLayout->addStretch(1);
|
|
|
|
buttonLayout->addWidget(_minButton);
|
|
|
|
buttonLayout->addWidget(_maxButton);
|
|
|
|
buttonLayout->addWidget(_exitButton);
|
|
|
|
buttonLayout->setSpacing(0);
|
|
|
|
}
|
2018-01-15 01:35:35 +01:00
|
|
|
}
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.layoutBase = new BaseWidget(this);
|
|
|
|
layout->addWidget(this->ui_.layoutBase);
|
2018-01-15 01:35:35 +01:00
|
|
|
}
|
|
|
|
|
2018-06-24 23:58:29 +02:00
|
|
|
// DPI
|
2018-06-26 17:06:17 +02:00
|
|
|
// auto dpi = getWindowDpi(this->winId());
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-06-24 23:58:29 +02:00
|
|
|
// if (dpi) {
|
|
|
|
// this->scale = dpi.value() / 96.f;
|
|
|
|
// }
|
2018-01-14 21:55:36 +01:00
|
|
|
#endif
|
|
|
|
|
2018-05-23 12:31:03 +02:00
|
|
|
#ifdef USEWINSDK
|
2018-05-24 10:03:07 +02:00
|
|
|
// fourtf: don't ask me why we need to delay this
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!(this->flags_ & Flags::TopMost))
|
|
|
|
{
|
2018-05-26 17:11:09 +02:00
|
|
|
QTimer::singleShot(1, this, [this] {
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->windowTopMost.connect(
|
2018-06-25 16:41:18 +02:00
|
|
|
[this](bool topMost, auto) {
|
2018-08-06 21:17:03 +02:00
|
|
|
::SetWindowPos(HWND(this->winId()),
|
|
|
|
topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0,
|
|
|
|
0, 0, 0,
|
|
|
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
2018-06-25 22:27:51 +02:00
|
|
|
},
|
2018-07-06 19:23:47 +02:00
|
|
|
this->managedConnections_);
|
2018-05-26 17:11:09 +02:00
|
|
|
});
|
|
|
|
}
|
2018-05-23 12:31:03 +02:00
|
|
|
#else
|
2018-08-12 12:56:28 +02:00
|
|
|
// if (getSettings()->windowTopMost.getValue()) {
|
2018-05-24 10:03:07 +02:00
|
|
|
// this->setWindowFlag(Qt::WindowStaysOnTopHint);
|
|
|
|
// }
|
2018-05-23 12:31:03 +02:00
|
|
|
#endif
|
2018-06-26 17:06:17 +02:00
|
|
|
}
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-01-22 20:52:32 +01:00
|
|
|
void BaseWindow::setStayInScreenRect(bool value)
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
this->stayInScreenRect_ = value;
|
2018-06-19 18:55:45 +02:00
|
|
|
|
|
|
|
this->moveIntoDesktopRect(this);
|
2018-01-22 20:52:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::getStayInScreenRect() const
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
return this->stayInScreenRect_;
|
2018-01-22 20:52:32 +01:00
|
|
|
}
|
|
|
|
|
2018-07-05 10:34:04 +02:00
|
|
|
void BaseWindow::setActionOnFocusLoss(ActionOnFocusLoss value)
|
|
|
|
{
|
|
|
|
this->actionOnFocusLoss_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseWindow::ActionOnFocusLoss BaseWindow::getActionOnFocusLoss() const
|
|
|
|
{
|
|
|
|
return this->actionOnFocusLoss_;
|
|
|
|
}
|
|
|
|
|
2018-01-15 01:35:35 +01:00
|
|
|
QWidget *BaseWindow::getLayoutContainer()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
return this->ui_.layoutBase;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-15 01:35:35 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::hasCustomWindowFrame()
|
|
|
|
{
|
2018-04-02 11:46:56 +02:00
|
|
|
#ifdef USEWINSDK
|
2018-04-08 17:07:40 +02:00
|
|
|
static bool isWin8 = IsWindows8OrGreater();
|
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
return isWin8 && this->enableCustomFrame_;
|
2018-01-15 01:35:35 +01:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void BaseWindow::themeChangedEvent()
|
2018-01-15 01:35:35 +01:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-02-05 21:33:22 +01:00
|
|
|
QPalette palette;
|
2018-04-08 17:07:40 +02:00
|
|
|
palette.setColor(QPalette::Background, QColor(0, 0, 0, 0));
|
2018-07-06 17:11:37 +02:00
|
|
|
palette.setColor(QPalette::Foreground, this->theme->window.text);
|
2018-02-05 21:33:22 +01:00
|
|
|
this->setPalette(palette);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ui_.titleLabel)
|
|
|
|
{
|
2018-05-23 22:27:29 +02:00
|
|
|
QPalette palette_title;
|
2018-08-06 21:17:03 +02:00
|
|
|
palette_title.setColor(
|
|
|
|
QPalette::Foreground,
|
|
|
|
this->theme->isLightTheme() ? "#333" : "#ccc");
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.titleLabel->setPalette(palette_title);
|
2018-05-23 22:27:29 +02:00
|
|
|
}
|
2018-04-18 18:55:49 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (Button *button : this->ui_.buttons)
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
button->setMouseEffectColor(this->theme->window.text);
|
2018-02-05 21:33:22 +01:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-13 23:41:52 +02:00
|
|
|
QPalette palette;
|
2018-07-06 17:11:37 +02:00
|
|
|
palette.setColor(QPalette::Background, this->theme->window.background);
|
|
|
|
palette.setColor(QPalette::Foreground, this->theme->window.text);
|
2018-04-13 23:41:52 +02:00
|
|
|
this->setPalette(palette);
|
2018-01-24 15:08:22 +01:00
|
|
|
}
|
2018-01-15 01:35:35 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 13:35:06 +02:00
|
|
|
bool BaseWindow::event(QEvent *event)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
if (event->type() ==
|
2018-10-21 13:43:02 +02:00
|
|
|
QEvent::WindowDeactivate /*|| event->type() == QEvent::FocusOut*/)
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
this->onFocusLost();
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
void BaseWindow::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (event->orientation() != Qt::Vertical)
|
|
|
|
{
|
2018-06-19 18:55:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
if (event->delta() > 0)
|
|
|
|
{
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->uiScale.setValue(WindowManager::clampUiScale(
|
|
|
|
getSettings()->uiScale.getValue() + 1));
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->uiScale.setValue(WindowManager::clampUiScale(
|
|
|
|
getSettings()->uiScale.getValue() - 1));
|
2018-06-11 15:04:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 10:34:04 +02:00
|
|
|
void BaseWindow::onFocusLost()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (this->getActionOnFocusLoss())
|
|
|
|
{
|
|
|
|
case Delete:
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
this->deleteLater();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-07-05 10:34:04 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
case Close:
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
this->close();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-07-05 10:34:04 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
case Hide:
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
this->hide();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-07-05 10:34:04 +02:00
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 18:09:11 +02:00
|
|
|
void BaseWindow::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
#ifndef Q_OS_WIN
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->flags_ & FramelessDraggable)
|
|
|
|
{
|
2018-06-24 18:09:11 +02:00
|
|
|
this->movingRelativePos = event->localPos();
|
2018-08-06 21:17:03 +02:00
|
|
|
if (auto widget =
|
2018-10-21 13:43:02 +02:00
|
|
|
this->childAt(event->localPos().x(), event->localPos().y()))
|
|
|
|
{
|
2018-06-24 18:09:11 +02:00
|
|
|
std::function<bool(QWidget *)> recursiveCheckMouseTracking;
|
|
|
|
recursiveCheckMouseTracking = [&](QWidget *widget) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (widget == nullptr)
|
|
|
|
{
|
2018-06-24 18:09:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (widget->hasMouseTracking())
|
|
|
|
{
|
2018-06-24 18:09:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return recursiveCheckMouseTracking(widget->parentWidget());
|
|
|
|
};
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!recursiveCheckMouseTracking(widget))
|
|
|
|
{
|
2018-08-13 20:10:32 +02:00
|
|
|
log("Start moving");
|
2018-06-24 18:09:11 +02:00
|
|
|
this->moving = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BaseWidget::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWindow::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
#ifndef Q_OS_WIN
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->flags_ & FramelessDraggable)
|
|
|
|
{
|
|
|
|
if (this->moving)
|
|
|
|
{
|
2018-08-13 20:10:32 +02:00
|
|
|
log("Stop moving");
|
2018-06-24 18:09:11 +02:00
|
|
|
this->moving = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BaseWidget::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWindow::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
#ifndef Q_OS_WIN
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->flags_ & FramelessDraggable)
|
|
|
|
{
|
|
|
|
if (this->moving)
|
|
|
|
{
|
2018-06-24 18:09:11 +02:00
|
|
|
const auto &newPos = event->screenPos() - this->movingRelativePos;
|
|
|
|
this->move(newPos.x(), newPos.y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BaseWidget::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
TitleBarButton *BaseWindow::addTitleBarButton(const TitleBarButtonStyle &style,
|
|
|
|
std::function<void()> onClicked)
|
2018-01-15 01:35:35 +01:00
|
|
|
{
|
2018-01-24 20:27:56 +01:00
|
|
|
TitleBarButton *button = new TitleBarButton;
|
2018-01-25 21:11:14 +01:00
|
|
|
button->setScaleIndependantSize(30, 30);
|
2018-01-24 20:27:56 +01:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.buttons.push_back(button);
|
|
|
|
this->ui_.titlebarBox->insertWidget(1, button);
|
2018-01-24 20:27:56 +01:00
|
|
|
button->setButtonStyle(style);
|
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(button, &TitleBarButton::leftClicked, this,
|
2018-08-06 21:17:03 +02:00
|
|
|
[onClicked] { onClicked(); });
|
2018-07-04 20:42:51 +02:00
|
|
|
|
|
|
|
return button;
|
2018-01-15 01:35:35 +01:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
EffectLabel *BaseWindow::addTitleBarLabel(std::function<void()> onClicked)
|
2018-02-05 23:32:38 +01:00
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
EffectLabel *button = new EffectLabel;
|
2018-02-05 23:32:38 +01:00
|
|
|
button->setScaleIndependantHeight(30);
|
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.buttons.push_back(button);
|
|
|
|
this->ui_.titlebarBox->insertWidget(1, button);
|
2018-02-05 23:32:38 +01:00
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(button, &EffectLabel::leftClicked, this,
|
2018-08-06 21:17:03 +02:00
|
|
|
[onClicked] { onClicked(); });
|
2018-02-05 23:32:38 +01:00
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
void BaseWindow::changeEvent(QEvent *)
|
|
|
|
{
|
2018-01-22 20:52:32 +01:00
|
|
|
TooltipWidget::getInstance()->hide();
|
2018-01-24 20:27:56 +01:00
|
|
|
|
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ui_.maxButton)
|
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
this->ui_.maxButton->setButtonStyle(
|
|
|
|
this->windowState() & Qt::WindowMaximized
|
|
|
|
? TitleBarButtonStyle::Unmaximize
|
|
|
|
: TitleBarButtonStyle::Maximize);
|
2018-01-24 20:27:56 +01:00
|
|
|
}
|
|
|
|
#endif
|
2018-04-13 22:50:19 +02:00
|
|
|
|
2018-04-13 23:41:52 +02:00
|
|
|
#ifndef Q_OS_WIN
|
2018-04-13 22:50:19 +02:00
|
|
|
this->update();
|
2018-04-13 23:41:52 +02:00
|
|
|
#endif
|
2018-01-14 21:55:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWindow::leaveEvent(QEvent *)
|
|
|
|
{
|
2018-01-22 20:52:32 +01:00
|
|
|
TooltipWidget::getInstance()->hide();
|
|
|
|
}
|
|
|
|
|
2018-05-26 17:11:09 +02:00
|
|
|
void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset)
|
2018-01-22 20:52:32 +01:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (offset)
|
|
|
|
{
|
2018-05-26 17:11:09 +02:00
|
|
|
point.rx() += 16;
|
|
|
|
point.ry() += 16;
|
|
|
|
}
|
2018-01-22 20:52:32 +01:00
|
|
|
|
|
|
|
this->move(point);
|
|
|
|
this->moveIntoDesktopRect(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWindow::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Window resized
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-01-22 20:52:32 +01:00
|
|
|
this->moveIntoDesktopRect(this);
|
2018-04-18 18:10:47 +02:00
|
|
|
|
|
|
|
this->calcButtonsSizes();
|
2018-01-22 20:52:32 +01:00
|
|
|
}
|
|
|
|
|
2018-10-07 18:27:40 +02:00
|
|
|
void BaseWindow::moveEvent(QMoveEvent *event)
|
|
|
|
{
|
|
|
|
// Queue up save because: Window position changed
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
|
|
|
BaseWidget::moveEvent(event);
|
|
|
|
}
|
|
|
|
|
2018-07-05 11:42:40 +02:00
|
|
|
void BaseWindow::closeEvent(QCloseEvent *)
|
|
|
|
{
|
|
|
|
this->closing.invoke();
|
|
|
|
}
|
|
|
|
|
2018-01-22 20:52:32 +01:00
|
|
|
void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->stayInScreenRect_)
|
|
|
|
return;
|
2018-01-22 20:52:32 +01:00
|
|
|
|
|
|
|
// move the widget into the screen geometry if it's not already in there
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
|
2018-06-19 18:55:45 +02:00
|
|
|
QRect s = desktop->availableGeometry(parent);
|
2018-01-22 20:52:32 +01:00
|
|
|
QPoint p = this->pos();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (p.x() < s.left())
|
|
|
|
{
|
2018-01-22 20:52:32 +01:00
|
|
|
p.setX(s.left());
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (p.y() < s.top())
|
|
|
|
{
|
2018-01-22 20:52:32 +01:00
|
|
|
p.setY(s.top());
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (p.x() + this->width() > s.right())
|
|
|
|
{
|
2018-01-22 20:52:32 +01:00
|
|
|
p.setX(s.right() - this->width());
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (p.y() + this->height() > s.bottom())
|
|
|
|
{
|
2018-01-22 20:52:32 +01:00
|
|
|
p.setY(s.bottom() - this->height());
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (p != this->pos())
|
|
|
|
this->move(p);
|
2018-01-14 21:55:36 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,
|
|
|
|
long *result)
|
2018-01-14 21:55:36 +01:00
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
#ifdef USEWINSDK
|
2018-08-15 22:46:20 +02:00
|
|
|
# if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
|
2018-08-09 15:13:11 +02:00
|
|
|
MSG *msg = *reinterpret_cast<MSG **>(message);
|
2018-08-15 22:46:20 +02:00
|
|
|
# else
|
2018-01-14 21:59:45 +01:00
|
|
|
MSG *msg = reinterpret_cast<MSG *>(message);
|
2018-08-15 22:46:20 +02:00
|
|
|
# endif
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-07-04 13:05:54 +02:00
|
|
|
bool returnValue = false;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (msg->message)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
case WM_DPICHANGED:
|
2018-07-04 13:05:54 +02:00
|
|
|
returnValue = handleDPICHANGED(msg);
|
|
|
|
break;
|
2018-06-19 19:42:15 +02:00
|
|
|
|
2018-07-03 13:04:27 +02:00
|
|
|
case WM_SHOWWINDOW:
|
2018-07-04 13:05:54 +02:00
|
|
|
returnValue = this->handleSHOWWINDOW(msg);
|
|
|
|
break;
|
2018-06-19 19:42:15 +02:00
|
|
|
|
2018-07-03 13:04:27 +02:00
|
|
|
case WM_NCCALCSIZE:
|
2018-07-04 13:05:54 +02:00
|
|
|
returnValue = this->handleNCCALCSIZE(msg, result);
|
|
|
|
break;
|
2018-06-19 19:42:15 +02:00
|
|
|
|
2018-07-03 13:04:27 +02:00
|
|
|
case WM_SIZE:
|
2018-07-04 13:05:54 +02:00
|
|
|
returnValue = this->handleSIZE(msg);
|
|
|
|
break;
|
2018-06-19 19:42:15 +02:00
|
|
|
|
2018-07-03 13:04:27 +02:00
|
|
|
case WM_NCHITTEST:
|
2018-07-04 13:05:54 +02:00
|
|
|
returnValue = this->handleNCHITTEST(msg, result);
|
|
|
|
break;
|
2018-06-19 19:42:15 +02:00
|
|
|
|
2018-01-15 01:35:35 +01:00
|
|
|
default:
|
|
|
|
return QWidget::nativeEvent(eventType, message, result);
|
2018-01-14 21:55:36 +01:00
|
|
|
}
|
2018-07-04 13:05:54 +02:00
|
|
|
|
|
|
|
QWidget::nativeEvent(eventType, message, result);
|
|
|
|
|
|
|
|
return returnValue;
|
2018-07-03 16:22:39 +02:00
|
|
|
#else
|
|
|
|
return QWidget::nativeEvent(eventType, message, result);
|
2018-07-03 13:04:27 +02:00
|
|
|
#endif
|
2018-01-15 01:35:35 +01:00
|
|
|
}
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-06-06 10:46:23 +02:00
|
|
|
void BaseWindow::scaleChangedEvent(float)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
#ifdef USEWINSDK
|
2018-06-06 10:46:23 +02:00
|
|
|
this->calcButtonsSizes();
|
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
2018-06-06 10:46:23 +02:00
|
|
|
|
2018-05-26 17:11:09 +02:00
|
|
|
void BaseWindow::paintEvent(QPaintEvent *)
|
2018-01-15 01:35:35 +01:00
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
QPainter painter(this);
|
2018-06-06 10:46:23 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->frameless_)
|
|
|
|
{
|
2018-06-06 10:46:23 +02:00
|
|
|
painter.setPen(QColor("#999"));
|
|
|
|
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
|
|
|
|
}
|
|
|
|
|
2018-07-05 10:34:04 +02:00
|
|
|
this->drawCustomWindowFrame(painter);
|
2018-06-06 10:46:23 +02:00
|
|
|
}
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
void BaseWindow::updateScale()
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto scale =
|
|
|
|
this->nativeScale_ * (this->flags_ & DisableCustomScaling
|
|
|
|
? 1
|
|
|
|
: getApp()->windows->getUiScaleValue());
|
2018-06-24 17:01:45 +02:00
|
|
|
this->setScale(scale);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto child : this->findChildren<BaseWidget *>())
|
|
|
|
{
|
2018-06-24 17:01:45 +02:00
|
|
|
child->setScale(scale);
|
|
|
|
}
|
2018-06-11 15:04:54 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 18:10:47 +02:00
|
|
|
void BaseWindow::calcButtonsSizes()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->shown_)
|
|
|
|
{
|
2018-04-18 18:10:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-03 13:04:27 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if ((this->width() / this->getScale()) < 300)
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
if (this->ui_.minButton)
|
|
|
|
this->ui_.minButton->setScaleIndependantSize(30, 30);
|
|
|
|
if (this->ui_.maxButton)
|
|
|
|
this->ui_.maxButton->setScaleIndependantSize(30, 30);
|
|
|
|
if (this->ui_.exitButton)
|
|
|
|
this->ui_.exitButton->setScaleIndependantSize(30, 30);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
if (this->ui_.minButton)
|
|
|
|
this->ui_.minButton->setScaleIndependantSize(46, 30);
|
|
|
|
if (this->ui_.maxButton)
|
|
|
|
this->ui_.maxButton->setScaleIndependantSize(46, 30);
|
|
|
|
if (this->ui_.exitButton)
|
|
|
|
this->ui_.exitButton->setScaleIndependantSize(46, 30);
|
2018-04-18 18:10:47 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-24 18:09:11 +02:00
|
|
|
|
2018-07-03 13:04:27 +02:00
|
|
|
void BaseWindow::drawCustomWindowFrame(QPainter &painter)
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
QPainter painter(this);
|
2018-07-03 13:04:27 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QColor bg = this->overrideBackgroundColor_.value_or(
|
|
|
|
this->theme->window.background);
|
2018-07-03 16:55:02 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
painter.fillRect(QRect(0, 1, this->width() - 0, this->height() - 0),
|
|
|
|
bg);
|
2018-07-05 10:34:04 +02:00
|
|
|
}
|
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::handleDPICHANGED(MSG *msg)
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
|
|
|
int dpi = HIWORD(msg->wParam);
|
|
|
|
|
|
|
|
float _scale = dpi / 96.f;
|
|
|
|
|
|
|
|
static bool firstResize = true;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!firstResize)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
auto *prcNewWindow = reinterpret_cast<RECT *>(msg->lParam);
|
|
|
|
SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
|
|
|
|
prcNewWindow->right - prcNewWindow->left,
|
2018-08-06 21:17:03 +02:00
|
|
|
prcNewWindow->bottom - prcNewWindow->top,
|
|
|
|
SWP_NOZORDER | SWP_NOACTIVATE);
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
firstResize = false;
|
|
|
|
|
|
|
|
this->nativeScale_ = _scale;
|
|
|
|
this->updateScale();
|
|
|
|
|
|
|
|
return true;
|
2018-07-04 10:41:43 +02:00
|
|
|
#else
|
2018-07-03 13:04:27 +02:00
|
|
|
return false;
|
2018-07-04 10:41:43 +02:00
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::handleSHOWWINDOW(MSG *msg)
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
if (auto dpi = getWindowDpi(msg->hwnd))
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
this->nativeScale_ = dpi.get() / 96.f;
|
|
|
|
this->updateScale();
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->shown_ && this->isVisible() && this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
this->shown_ = true;
|
|
|
|
|
|
|
|
const MARGINS shadow = {8, 8, 8, 8};
|
|
|
|
DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow);
|
|
|
|
}
|
|
|
|
|
2018-07-04 10:37:53 +02:00
|
|
|
this->calcButtonsSizes();
|
|
|
|
|
2018-07-03 13:04:27 +02:00
|
|
|
return true;
|
2018-07-04 10:41:43 +02:00
|
|
|
#else
|
2018-07-03 13:04:27 +02:00
|
|
|
return false;
|
2018-07-04 10:41:43 +02:00
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::handleNCCALCSIZE(MSG *msg, long *result)
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
// int cx = GetSystemMetrics(SM_CXSIZEFRAME);
|
|
|
|
// int cy = GetSystemMetrics(SM_CYSIZEFRAME);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (msg->wParam == TRUE)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
NCCALCSIZE_PARAMS *ncp =
|
|
|
|
(reinterpret_cast<NCCALCSIZE_PARAMS *>(msg->lParam));
|
2018-07-03 13:04:27 +02:00
|
|
|
ncp->lppos->flags |= SWP_NOREDRAW;
|
|
|
|
RECT *clientRect = &ncp->rgrc[0];
|
|
|
|
|
|
|
|
clientRect->left += 1;
|
|
|
|
clientRect->top += 0;
|
|
|
|
clientRect->right -= 1;
|
|
|
|
clientRect->bottom -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-04 10:41:43 +02:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::handleSIZE(MSG *msg)
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ui_.windowLayout)
|
|
|
|
{
|
|
|
|
if (this->frameless_)
|
|
|
|
{
|
2018-07-05 10:34:04 +02:00
|
|
|
//
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (this->hasCustomWindowFrame())
|
|
|
|
{
|
|
|
|
if (msg->wParam == SIZE_MAXIMIZED)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
auto offset = int(this->getScale() * 8);
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.windowLayout->setContentsMargins(offset, offset,
|
|
|
|
offset, offset);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
this->ui_.windowLayout->setContentsMargins(0, 1, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-04 13:05:54 +02:00
|
|
|
return false;
|
2018-07-04 10:41:43 +02:00
|
|
|
#else
|
2018-07-03 13:04:27 +02:00
|
|
|
return false;
|
2018-07-04 10:41:43 +02:00
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseWindow::handleNCHITTEST(MSG *msg, long *result)
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
|
|
|
const LONG border_width = 8; // in pixels
|
|
|
|
RECT winrect;
|
|
|
|
GetWindowRect(HWND(winId()), &winrect);
|
|
|
|
|
|
|
|
long x = GET_X_LPARAM(msg->lParam);
|
|
|
|
long y = GET_Y_LPARAM(msg->lParam);
|
|
|
|
|
|
|
|
QPoint point(x - winrect.left, y - winrect.top);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasCustomWindowFrame())
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
bool resizeWidth = minimumWidth() != maximumWidth();
|
|
|
|
bool resizeHeight = minimumHeight() != maximumHeight();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (resizeWidth)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
// left border
|
2018-10-21 13:43:02 +02:00
|
|
|
if (x < winrect.left + border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTLEFT;
|
|
|
|
}
|
|
|
|
// right border
|
2018-10-21 13:43:02 +02:00
|
|
|
if (x >= winrect.right - border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTRIGHT;
|
|
|
|
}
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (resizeHeight)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
// bottom border
|
2018-10-21 13:43:02 +02:00
|
|
|
if (y >= winrect.bottom - border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTBOTTOM;
|
|
|
|
}
|
|
|
|
// top border
|
2018-10-21 13:43:02 +02:00
|
|
|
if (y < winrect.top + border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTTOP;
|
|
|
|
}
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (resizeWidth && resizeHeight)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
// bottom left corner
|
2018-08-06 21:17:03 +02:00
|
|
|
if (x >= winrect.left && x < winrect.left + border_width &&
|
2018-10-21 13:43:02 +02:00
|
|
|
y < winrect.bottom && y >= winrect.bottom - border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTBOTTOMLEFT;
|
|
|
|
}
|
|
|
|
// bottom right corner
|
2018-08-06 21:17:03 +02:00
|
|
|
if (x < winrect.right && x >= winrect.right - border_width &&
|
2018-10-21 13:43:02 +02:00
|
|
|
y < winrect.bottom && y >= winrect.bottom - border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTBOTTOMRIGHT;
|
|
|
|
}
|
|
|
|
// top left corner
|
2018-08-06 21:17:03 +02:00
|
|
|
if (x >= winrect.left && x < winrect.left + border_width &&
|
2018-10-21 13:43:02 +02:00
|
|
|
y >= winrect.top && y < winrect.top + border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTTOPLEFT;
|
|
|
|
}
|
|
|
|
// top right corner
|
2018-08-06 21:17:03 +02:00
|
|
|
if (x < winrect.right && x >= winrect.right - border_width &&
|
2018-10-21 13:43:02 +02:00
|
|
|
y >= winrect.top && y < winrect.top + border_width)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTTOPRIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (*result == 0)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
bool client = false;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (QWidget *widget : this->ui_.buttons)
|
|
|
|
{
|
|
|
|
if (widget->geometry().contains(point))
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
client = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ui_.layoutBase->geometry().contains(point))
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
client = true;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (client)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTCLIENT;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTCAPTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (this->flags_ & FramelessDraggable)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = 0;
|
|
|
|
bool client = false;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (auto widget = this->childAt(point))
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
std::function<bool(QWidget *)> recursiveCheckMouseTracking;
|
|
|
|
recursiveCheckMouseTracking = [&](QWidget *widget) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (widget == nullptr)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (widget->hasMouseTracking())
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return recursiveCheckMouseTracking(widget->parentWidget());
|
|
|
|
};
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (recursiveCheckMouseTracking(widget))
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
client = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (client)
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTCLIENT;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-03 13:04:27 +02:00
|
|
|
*result = HTCAPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-04 10:41:43 +02:00
|
|
|
#else
|
2018-07-03 13:04:27 +02:00
|
|
|
return false;
|
2018-07-04 10:41:43 +02:00
|
|
|
#endif
|
2018-07-03 13:04:27 +02:00
|
|
|
}
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
} // namespace chatterino
|