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;