Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
win: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Nov 13, 2023
1 parent a1b0568 commit 5670a28
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject
bool qpaReady = false;
quint32 qpaWaitTime = 0;
QTimer repaintTimer{};
bool repaintedOnce = false;
};

FRAMELESSHELPER_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject
QSizePolicy savedSizePolicy = {};
quint32 qpaWaitTime = 0;
QTimer repaintTimer{};
bool repaintedOnce = false;
};

FRAMELESSHELPER_END_NAMESPACE
60 changes: 28 additions & 32 deletions src/quick/framelessquickhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE

using namespace Global;

static constexpr const auto kRepaintTimerInterval = 500;
static constexpr const auto kRepaintTimerInterval = 300;

struct FramelessQuickHelperExtraData : public FramelessExtraData
{
Expand Down Expand Up @@ -414,42 +414,38 @@ void FramelessQuickHelperPrivate::repaintAllChildren()
void FramelessQuickHelperPrivate::doRepaintAllChildren()
{
repaintTimer.stop();
if (repaintedOnce) {
Q_Q(const FramelessQuickHelper);
QQuickWindow *window = q->window();
if (!window) {
return;
}
Q_Q(const FramelessQuickHelper);
QQuickWindow *window = q->window();
if (!window) {
return;
}
#if (defined(Q_OS_WINDOWS) && (QT_VERSION != QT_VERSION_CHECK(6, 5, 3)) && (QT_VERSION != QT_VERSION_CHECK(6, 6, 0)))
// Sync the internal window frame margins with the latest DPI, otherwise
// we will get wrong window sizes after the DPI change.
std::ignore = Utils::updateInternalWindowFrameMargins(window, true);
// Sync the internal window frame margins with the latest DPI, otherwise
// we will get wrong window sizes after the DPI change.
std::ignore = Utils::updateInternalWindowFrameMargins(window, true);
#endif // Q_OS_WINDOWS
// No need to repaint the window when it's hidden.
if (!window->isVisible()) {
return;
}
if (!((window->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) || q->isWindowFixedSize())) {
const QSize originalSize = window->size();
static constexpr const auto margins = QMargins{ 1, 1, 1, 1 };
window->resize(originalSize.shrunkBy(margins));
window->resize(originalSize.grownBy(margins));
window->resize(originalSize);
}
window->requestUpdate();
// No need to repaint the window when it's hidden.
if (!window->isVisible()) {
return;
}
if (!((window->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) || q->isWindowFixedSize())) {
const QSize originalSize = window->size();
static constexpr const auto margins = QMargins{ 1, 1, 1, 1 };
window->resize(originalSize.shrunkBy(margins));
window->resize(originalSize.grownBy(margins));
window->resize(originalSize);
}
window->requestUpdate();
#if 0 // Calling QWindow::requestUpdate() should be enough.
const QList<QQuickItem *> items = window->findChildren<QQuickItem *>();
for (auto &&item : std::as_const(items)) {
// Only items with the "QQuickItem::ItemHasContents" flag enabled are allowed to call "update()".
// And don't repaint the item if it's hidden.
if ((item->flags() & QQuickItem::ItemHasContents) && item->isVisible()) {
item->update();
}
const QList<QQuickItem *> items = window->findChildren<QQuickItem *>();
for (auto &&item : std::as_const(items)) {
// Only items with the "QQuickItem::ItemHasContents" flag enabled are allowed to call "update()".
// And don't repaint the item if it's hidden.
if ((item->flags() & QQuickItem::ItemHasContents) && item->isVisible()) {
item->update();
}
#endif
} else {
repaintedOnce = true;
}
#endif
}

quint32 FramelessQuickHelperPrivate::readyWaitTime() const
Expand Down
20 changes: 8 additions & 12 deletions src/widgets/framelesswidgetshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE

using namespace Global;

static constexpr const auto kRepaintTimerInterval = 500;
static constexpr const auto kRepaintTimerInterval = 300;

struct FramelessWidgetsHelperExtraData : public FramelessExtraData
{
Expand Down Expand Up @@ -378,17 +378,13 @@ void FramelessWidgetsHelperPrivate::repaintAllChildren()
void FramelessWidgetsHelperPrivate::doRepaintAllChildren()
{
repaintTimer.stop();
if (repaintedOnce) {
if (!window) {
return;
}
forceWidgetRepaint(window);
const QList<QWidget *> widgets = window->findChildren<QWidget *>();
for (auto &&widget : std::as_const(widgets)) {
forceWidgetRepaint(widget);
}
} else {
repaintedOnce = true;
if (!window) {
return;
}
forceWidgetRepaint(window);
const QList<QWidget *> widgets = window->findChildren<QWidget *>();
for (auto &&widget : std::as_const(widgets)) {
forceWidgetRepaint(widget);
}
}

Expand Down

0 comments on commit 5670a28

Please sign in to comment.