BaseWindow smol refactor

This commit is contained in:
fourtf
2019-09-08 21:45:46 +02:00
parent 3158ed4085
commit 4f356f80cf
14 changed files with 43 additions and 49 deletions
+25 -26
View File
@@ -44,12 +44,12 @@
namespace AB_NAMESPACE {
BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
BaseWindow::BaseWindow(FlagsEnum<Flags> _flags, QWidget *parent)
: BaseWidget(parent,
Qt::Window | ((_flags & TopMost) ? Qt::WindowStaysOnTopHint
: Qt::WindowFlags()))
, enableCustomFrame_(_flags & EnableCustomFrame)
, frameless_(_flags & Frameless)
Qt::Window | (_flags.has(TopMost) ? Qt::WindowStaysOnTopHint
: Qt::WindowFlags()))
, enableCustomFrame_(_flags.has(EnableCustomFrame))
, frameless_(_flags.has(Frameless))
, flags_(_flags)
{
if (this->frameless_)
@@ -74,8 +74,6 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
createWindowShortcut(this, "CTRL+0",
[] { getSettings()->uiScale.setValue(1); });
// QTimer::this->scaleChangedEvent(this->getScale());
this->resize(300, 150);
#ifdef USEWINSDK
@@ -113,11 +111,6 @@ float BaseWindow::qtFontScale() const
return this->scale() / this->nativeScale_;
}
BaseWindow::Flags BaseWindow::getFlags()
{
return this->flags_;
}
void BaseWindow::init()
{
this->setWindowIcon(QIcon(":/images/icon.png"));
@@ -206,7 +199,7 @@ void BaseWindow::init()
#ifdef USEWINSDK
// fourtf: don't ask me why we need to delay this
if (!(this->flags_ & Flags::TopMost))
if (!this->flags_.has(TopMost))
{
QTimer::singleShot(1, this, [this] {
getSettings()->windowTopMost.connect(
@@ -541,6 +534,18 @@ void BaseWindow::closeEvent(QCloseEvent *)
this->closing.invoke();
}
void BaseWindow::showEvent(QShowEvent *)
{
if (this->frameless_)
{
this->moveIntoDesktopRect(this);
qDebug() << "show";
QTimer::singleShot(30, this,
[this] { this->moveIntoDesktopRect(this); });
}
}
void BaseWindow::moveIntoDesktopRect(QWidget *parent)
{
if (!this->stayInScreenRect_)
@@ -649,7 +654,7 @@ void BaseWindow::paintEvent(QPaintEvent *)
void BaseWindow::updateScale()
{
auto scale =
this->nativeScale_ * (this->flags_ & DisableCustomScaling
this->nativeScale_ * (this->flags_.has(DisableCustomScaling)
? 1
: getABSettings()->getClampedUiScale());
@@ -708,17 +713,11 @@ bool BaseWindow::handleDPICHANGED(MSG *msg)
float _scale = dpi / 96.f;
static bool firstResize = true;
if (!firstResize)
{
auto *prcNewWindow = reinterpret_cast<RECT *>(msg->lParam);
SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
prcNewWindow->right - prcNewWindow->left,
prcNewWindow->bottom - prcNewWindow->top,
SWP_NOZORDER | SWP_NOACTIVATE);
}
firstResize = false;
auto *prcNewWindow = reinterpret_cast<RECT *>(msg->lParam);
SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
prcNewWindow->right - prcNewWindow->left,
prcNewWindow->bottom - prcNewWindow->top,
SWP_NOZORDER | SWP_NOACTIVATE);
this->nativeScale_ = _scale;
this->updateScale();
@@ -953,7 +952,7 @@ bool BaseWindow::handleNCHITTEST(MSG *msg, long *result)
return true;
}
else if (this->flags_ & FramelessDraggable)
else if (this->flags_.has(FramelessDraggable))
{
*result = 0;
bool client = false;
+5 -4
View File
@@ -4,6 +4,7 @@
#include <functional>
#include <pajlada/signals/signalholder.hpp>
#include "common/FlagsEnum.hpp"
class QHBoxLayout;
struct tagMSG;
@@ -32,7 +33,8 @@ public:
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);
explicit BaseWindow(FlagsEnum<Flags> flags_ = None,
QWidget *parent = nullptr);
void setInitialBounds(const QRect &bounds);
QRect getBounds();
@@ -54,8 +56,6 @@ public:
virtual float scale() const override;
float qtFontScale() const;
Flags getFlags();
pajlada::Signals::NoArgSignal closing;
static bool supportsCustomWindowFrame();
@@ -72,6 +72,7 @@ protected:
virtual void resizeEvent(QResizeEvent *) override;
virtual void moveEvent(QMoveEvent *) override;
virtual void closeEvent(QCloseEvent *) override;
virtual void showEvent(QShowEvent *) override;
virtual void themeChangedEvent() override;
virtual bool event(QEvent *event) override;
@@ -106,7 +107,7 @@ private:
bool frameless_;
bool stayInScreenRect_ = false;
bool shown_ = false;
Flags flags_;
FlagsEnum<Flags> flags_;
float nativeScale_ = 1;
struct {
+1 -1
View File
@@ -21,7 +21,7 @@ TooltipWidget *TooltipWidget::getInstance()
}
TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow(parent, BaseWindow::TopMost)
: BaseWindow(BaseWindow::TopMost, parent)
, displayImage_(new QLabel())
, displayText_(new QLabel())
{