quick: PIMPL refactor
This commit is contained in:
parent
15212abd85
commit
5c8ac2736f
|
@ -13,7 +13,6 @@
|
|||
#include <FramelessHelper/Widgets/standardtitlebar.h>
|
||||
#include <FramelessHelper/Widgets/framelesswidgetshelper.h>
|
||||
#include <FramelessHelper/Widgets/standardsystembutton.h>
|
||||
#include <FramelessHelper/Widgets/private/framelesswidgetshelper_p.h>
|
||||
#include "../shared/settings.h"
|
||||
|
||||
extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
|
@ -138,11 +137,6 @@ void Dialog::setupUi()
|
|||
helper->setSystemButton(titleBar->maximizeButton(), SystemButtonType::Maximize);
|
||||
helper->setSystemButton(titleBar->closeButton(), SystemButtonType::Close);
|
||||
#endif // Q_OS_MACOS
|
||||
// Special hack to disable the overriding of the mouse cursor, it's totally different
|
||||
// with making the window un-resizable: we still want the window be able to resize
|
||||
// programatically, but we also want the user not able to resize the window manually.
|
||||
// So apparently we can't use QWidget::setFixedWidth/Height/Size() here.
|
||||
FramelessWidgetsHelperPrivate::get(helper)->setProperty(kDontOverrideCursorVar, true);
|
||||
}
|
||||
|
||||
void Dialog::waitReady()
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
Q_NODISCARD QColor defaultSystemButtonBackgroundColor() const;
|
||||
Q_NODISCARD QColor defaultSystemCloseButtonBackgroundColor() const;
|
||||
|
||||
Q_NODISCARD Q_INVOKABLE QColor getSystemButtonBackgroundColor(
|
||||
Q_NODISCARD Q_SLOT QColor getSystemButtonBackgroundColor(
|
||||
const QuickGlobal::SystemButtonType button, const QuickGlobal::ButtonState state);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -47,25 +47,9 @@ public:
|
|||
Q_NODISCARD static FramelessQuickApplicationWindowPrivate *get(FramelessQuickApplicationWindow *pub);
|
||||
Q_NODISCARD static const FramelessQuickApplicationWindowPrivate *get(const FramelessQuickApplicationWindow *pub);
|
||||
|
||||
Q_INVOKABLE Q_NODISCARD bool isHidden() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isNormal() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isMinimized() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isMaximized() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isZoomed() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isFullScreen() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void showMinimized2();
|
||||
void toggleMaximized();
|
||||
void toggleFullScreen();
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
FramelessQuickApplicationWindow *q_ptr = nullptr;
|
||||
QuickWindowBorder *m_windowBorder = nullptr;
|
||||
QQuickWindow::Visibility m_savedVisibility = QQuickWindow::Windowed;
|
||||
QuickWindowBorder *windowBorder = nullptr;
|
||||
QQuickWindow::Visibility savedVisibility = QQuickWindow::Windowed;
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -51,33 +51,11 @@ public:
|
|||
Q_NODISCARD static FramelessQuickHelperPrivate *get(FramelessQuickHelper *pub);
|
||||
Q_NODISCARD static const FramelessQuickHelperPrivate *get(const FramelessQuickHelper *pub);
|
||||
|
||||
Q_NODISCARD bool isContentExtendedIntoTitleBar() const;
|
||||
void extendsContentIntoTitleBar(const bool value);
|
||||
|
||||
Q_NODISCARD QQuickItem *getTitleBarItem() const;
|
||||
void setTitleBarItem(QQuickItem *value);
|
||||
|
||||
void attach();
|
||||
void detach();
|
||||
void setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType);
|
||||
void setHitTestVisible(QQuickItem *item, const bool visible = true);
|
||||
void setHitTestVisible(const QRect &rect, const bool visible = true);
|
||||
void setHitTestVisible(QObject *object, const bool visible = true);
|
||||
void showSystemMenu(const QPoint &pos);
|
||||
void windowStartSystemMove2(const QPoint &pos);
|
||||
void windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos);
|
||||
|
||||
void moveWindowToDesktopCenter();
|
||||
void bringWindowToFront();
|
||||
|
||||
Q_NODISCARD bool isWindowFixedSize() const;
|
||||
void setWindowFixedSize(const bool value);
|
||||
|
||||
void emitSignalForAllInstances(const char *signal);
|
||||
|
||||
Q_NODISCARD bool isBlurBehindWindowEnabled() const;
|
||||
void setBlurBehindWindowEnabled(const bool value, const QColor &color);
|
||||
|
||||
void setProperty(const char *name, const QVariant &value);
|
||||
Q_NODISCARD QVariant getProperty(const char *name, const QVariant &defaultValue = {});
|
||||
|
||||
|
@ -86,15 +64,11 @@ public:
|
|||
|
||||
Q_NODISCARD static FramelessQuickHelper *findOrCreateFramelessHelper(QObject *object);
|
||||
|
||||
Q_NODISCARD bool isReady() const;
|
||||
void waitForReady();
|
||||
|
||||
void repaintAllChildren(const quint32 delay = 0) const;
|
||||
|
||||
Q_NODISCARD quint32 readyWaitTime() const;
|
||||
void setReadyWaitTime(const quint32 time);
|
||||
|
||||
private:
|
||||
Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const;
|
||||
Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const;
|
||||
Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const;
|
||||
|
@ -104,14 +78,12 @@ private:
|
|||
Q_NODISCARD FramelessQuickHelperData *getWindowDataMutable() const;
|
||||
void rebindWindow();
|
||||
|
||||
private:
|
||||
FramelessQuickHelper *q_ptr = nullptr;
|
||||
QColor m_savedWindowBackgroundColor = {};
|
||||
bool m_blurBehindWindowEnabled = false;
|
||||
std::optional<bool> m_extendIntoTitleBar = std::nullopt;
|
||||
bool m_destroying = false;
|
||||
bool m_qpaReady = false;
|
||||
quint32 m_qpaWaitTime = 0;
|
||||
QColor savedWindowBackgroundColor = {};
|
||||
bool blurBehindWindowEnabled = false;
|
||||
std::optional<bool> extendIntoTitleBar = std::nullopt;
|
||||
bool qpaReady = false;
|
||||
quint32 qpaWaitTime = 0;
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -47,25 +47,9 @@ public:
|
|||
Q_NODISCARD static FramelessQuickWindowPrivate *get(FramelessQuickWindow *pub);
|
||||
Q_NODISCARD static const FramelessQuickWindowPrivate *get(const FramelessQuickWindow *pub);
|
||||
|
||||
Q_INVOKABLE Q_NODISCARD bool isHidden() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isNormal() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isMinimized() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isMaximized() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isZoomed() const;
|
||||
Q_INVOKABLE Q_NODISCARD bool isFullScreen() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void showMinimized2();
|
||||
void toggleMaximized();
|
||||
void toggleFullScreen();
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
FramelessQuickWindow *q_ptr = nullptr;
|
||||
QuickWindowBorder *m_windowBorder = nullptr;
|
||||
QQuickWindow::Visibility m_savedVisibility = QQuickWindow::Windowed;
|
||||
QuickWindowBorder *windowBorder = nullptr;
|
||||
QQuickWindow::Visibility savedVisibility = QQuickWindow::Windowed;
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -44,13 +44,6 @@ public:
|
|||
Q_NODISCARD static QuickImageItemPrivate *get(QuickImageItem *q);
|
||||
Q_NODISCARD static const QuickImageItemPrivate *get(const QuickImageItem *q);
|
||||
|
||||
void paint(QPainter *painter) const;
|
||||
|
||||
Q_NODISCARD QVariant source() const;
|
||||
void setSource(const QVariant &value);
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
void fromUrl(const QUrl &value, QPainter *painter) const;
|
||||
void fromString(const QString &value, QPainter *painter) const;
|
||||
void fromImage(const QImage &value, QPainter *painter) const;
|
||||
|
@ -58,9 +51,8 @@ private:
|
|||
void fromIcon(const QIcon &value, QPainter *painter) const;
|
||||
Q_NODISCARD QRectF paintArea() const;
|
||||
|
||||
private:
|
||||
QuickImageItem *q_ptr = nullptr;
|
||||
QVariant m_source = {};
|
||||
QVariant source = {};
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -44,19 +44,15 @@ public:
|
|||
Q_NODISCARD static QuickMicaMaterialPrivate *get(QuickMicaMaterial *q);
|
||||
Q_NODISCARD static const QuickMicaMaterialPrivate *get(const QuickMicaMaterial *q);
|
||||
|
||||
public Q_SLOTS:
|
||||
void rebindWindow();
|
||||
void repaint(QPainter *painter);
|
||||
Q_SLOT void rebindWindow();
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
QuickMicaMaterial *q_ptr = nullptr;
|
||||
QMetaObject::Connection m_rootWindowXChangedConnection = {};
|
||||
QMetaObject::Connection m_rootWindowYChangedConnection = {};
|
||||
QMetaObject::Connection m_rootWindowActiveChangedConnection = {};
|
||||
MicaMaterial *m_micaMaterial = nullptr;
|
||||
QMetaObject::Connection rootWindowXChangedConnection = {};
|
||||
QMetaObject::Connection rootWindowYChangedConnection = {};
|
||||
QMetaObject::Connection rootWindowActiveChangedConnection = {};
|
||||
MicaMaterial *micaMaterial = nullptr;
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -44,20 +44,15 @@ public:
|
|||
Q_NODISCARD static QuickWindowBorderPrivate *get(QuickWindowBorder *q);
|
||||
Q_NODISCARD static const QuickWindowBorderPrivate *get(const QuickWindowBorder *q);
|
||||
|
||||
void paint(QPainter *painter) const;
|
||||
Q_SLOT void update();
|
||||
|
||||
public Q_SLOTS:
|
||||
void update();
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
void rebindWindow();
|
||||
|
||||
private:
|
||||
QuickWindowBorder *q_ptr = nullptr;
|
||||
WindowBorderPainter *m_borderPainter = nullptr;
|
||||
QMetaObject::Connection m_activeChangeConnection = {};
|
||||
QMetaObject::Connection m_visibilityChangeConnection = {};
|
||||
WindowBorderPainter *borderPainter = nullptr;
|
||||
QMetaObject::Connection activeChangeConnection = {};
|
||||
QMetaObject::Connection visibilityChangeConnection = {};
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -59,7 +59,6 @@ FramelessQuickApplicationWindowPrivate::FramelessQuickApplicationWindowPrivate(F
|
|||
return;
|
||||
}
|
||||
q_ptr = q;
|
||||
initialize();
|
||||
}
|
||||
|
||||
FramelessQuickApplicationWindowPrivate::~FramelessQuickApplicationWindowPrivate() = default;
|
||||
|
@ -82,156 +81,90 @@ const FramelessQuickApplicationWindowPrivate *FramelessQuickApplicationWindowPri
|
|||
return pub->d_func();
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindowPrivate::isHidden() const
|
||||
{
|
||||
Q_Q(const FramelessQuickApplicationWindow);
|
||||
return (q->visibility() == FramelessQuickApplicationWindow::Hidden);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindowPrivate::isNormal() const
|
||||
{
|
||||
Q_Q(const FramelessQuickApplicationWindow);
|
||||
return (q->visibility() == FramelessQuickApplicationWindow::Windowed);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindowPrivate::isMinimized() const
|
||||
{
|
||||
Q_Q(const FramelessQuickApplicationWindow);
|
||||
return (q->visibility() == FramelessQuickApplicationWindow::Minimized);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindowPrivate::isMaximized() const
|
||||
{
|
||||
Q_Q(const FramelessQuickApplicationWindow);
|
||||
return (q->visibility() == FramelessQuickApplicationWindow::Maximized);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindowPrivate::isZoomed() const
|
||||
{
|
||||
Q_Q(const FramelessQuickApplicationWindow);
|
||||
return (isMaximized() || (q->visibility() == FramelessQuickApplicationWindow::FullScreen));
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindowPrivate::isFullScreen() const
|
||||
{
|
||||
Q_Q(const FramelessQuickApplicationWindow);
|
||||
return (q->visibility() == FramelessQuickApplicationWindow::FullScreen);
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindowPrivate::showMinimized2()
|
||||
{
|
||||
Q_Q(FramelessQuickApplicationWindow);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
// Work-around a QtQuick bug: https://bugreports.qt.io/browse/QTBUG-69711
|
||||
// Don't use "SW_SHOWMINIMIZED" because it will activate the current window
|
||||
// instead of the next window in the Z order, which is not the default behavior
|
||||
// of native Win32 applications.
|
||||
ShowWindow(reinterpret_cast<HWND>(q->winId()), SW_MINIMIZE);
|
||||
#else
|
||||
q->showMinimized();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindowPrivate::toggleMaximized()
|
||||
{
|
||||
Q_Q(FramelessQuickApplicationWindow);
|
||||
if (isMaximized()) {
|
||||
q->showNormal();
|
||||
} else {
|
||||
q->showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindowPrivate::toggleFullScreen()
|
||||
{
|
||||
Q_Q(FramelessQuickApplicationWindow);
|
||||
if (isFullScreen()) {
|
||||
q->setVisibility(m_savedVisibility);
|
||||
} else {
|
||||
m_savedVisibility = q->visibility();
|
||||
q->showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindowPrivate::initialize()
|
||||
{
|
||||
Q_Q(FramelessQuickApplicationWindow);
|
||||
QQuickItem * const rootItem = q->contentItem();
|
||||
FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar();
|
||||
m_windowBorder = new QuickWindowBorder;
|
||||
m_windowBorder->setParent(rootItem);
|
||||
m_windowBorder->setParentItem(rootItem);
|
||||
m_windowBorder->setZ(999); // Make sure it always stays on the top.
|
||||
QQuickItemPrivate::get(m_windowBorder)->anchors()->setFill(rootItem);
|
||||
connect(q, &FramelessQuickApplicationWindow::visibilityChanged, q, [q](){
|
||||
Q_EMIT q->hiddenChanged();
|
||||
Q_EMIT q->normalChanged();
|
||||
Q_EMIT q->minimizedChanged();
|
||||
Q_EMIT q->maximizedChanged();
|
||||
Q_EMIT q->zoomedChanged();
|
||||
Q_EMIT q->fullScreenChanged();
|
||||
});
|
||||
}
|
||||
|
||||
FramelessQuickApplicationWindow::FramelessQuickApplicationWindow(QWindow *parent)
|
||||
: QQuickApplicationWindow(parent), d_ptr(new FramelessQuickApplicationWindowPrivate(this))
|
||||
{
|
||||
QQuickItem * const rootItem = contentItem();
|
||||
FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar();
|
||||
Q_D(FramelessQuickApplicationWindow);
|
||||
d->windowBorder = new QuickWindowBorder;
|
||||
d->windowBorder->setParent(rootItem);
|
||||
d->windowBorder->setParentItem(rootItem);
|
||||
d->windowBorder->setZ(999); // Make sure it always stays on the top.
|
||||
QQuickItemPrivate::get(d->windowBorder)->anchors()->setFill(rootItem);
|
||||
connect(this, &FramelessQuickApplicationWindow::visibilityChanged, this, [this](){
|
||||
Q_EMIT hiddenChanged();
|
||||
Q_EMIT normalChanged();
|
||||
Q_EMIT minimizedChanged();
|
||||
Q_EMIT maximizedChanged();
|
||||
Q_EMIT zoomedChanged();
|
||||
Q_EMIT fullScreenChanged();
|
||||
});
|
||||
}
|
||||
|
||||
FramelessQuickApplicationWindow::~FramelessQuickApplicationWindow() = default;
|
||||
|
||||
bool FramelessQuickApplicationWindow::isHidden() const
|
||||
{
|
||||
Q_D(const FramelessQuickApplicationWindow);
|
||||
return d->isHidden();
|
||||
return (visibility() == FramelessQuickApplicationWindow::Hidden);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindow::isNormal() const
|
||||
{
|
||||
Q_D(const FramelessQuickApplicationWindow);
|
||||
return d->isNormal();
|
||||
return (visibility() == FramelessQuickApplicationWindow::Windowed);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindow::isMinimized() const
|
||||
{
|
||||
Q_D(const FramelessQuickApplicationWindow);
|
||||
return d->isMinimized();
|
||||
return (visibility() == FramelessQuickApplicationWindow::Minimized);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindow::isMaximized() const
|
||||
{
|
||||
Q_D(const FramelessQuickApplicationWindow);
|
||||
return d->isMaximized();
|
||||
return (visibility() == FramelessQuickApplicationWindow::Maximized);
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindow::isZoomed() const
|
||||
{
|
||||
Q_D(const FramelessQuickApplicationWindow);
|
||||
return d->isZoomed();
|
||||
return (isMaximized() || (visibility() == FramelessQuickApplicationWindow::FullScreen));
|
||||
}
|
||||
|
||||
bool FramelessQuickApplicationWindow::isFullScreen() const
|
||||
{
|
||||
Q_D(const FramelessQuickApplicationWindow);
|
||||
return d->isFullScreen();
|
||||
return (visibility() == FramelessQuickApplicationWindow::FullScreen);
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindow::showMinimized2()
|
||||
{
|
||||
Q_D(FramelessQuickApplicationWindow);
|
||||
d->showMinimized2();
|
||||
#ifdef Q_OS_WINDOWS
|
||||
// Work-around a QtQuick bug: https://bugreports.qt.io/browse/QTBUG-69711
|
||||
// Don't use "SW_SHOWMINIMIZED" because it will activate the current window
|
||||
// instead of the next window in the Z order, which is not the default behavior
|
||||
// of native Win32 applications.
|
||||
::ShowWindow(reinterpret_cast<HWND>(winId()), SW_MINIMIZE);
|
||||
#else
|
||||
showMinimized();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindow::toggleMaximized()
|
||||
{
|
||||
Q_D(FramelessQuickApplicationWindow);
|
||||
d->toggleMaximized();
|
||||
if (isMaximized()) {
|
||||
showNormal();
|
||||
} else {
|
||||
showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindow::toggleFullScreen()
|
||||
{
|
||||
Q_D(FramelessQuickApplicationWindow);
|
||||
d->toggleFullScreen();
|
||||
if (isFullScreen()) {
|
||||
setVisibility(d->savedVisibility);
|
||||
} else {
|
||||
d->savedVisibility = visibility();
|
||||
showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickApplicationWindow::classBegin()
|
||||
|
|
|
@ -98,12 +98,7 @@ FramelessQuickHelperPrivate::FramelessQuickHelperPrivate(FramelessQuickHelper *q
|
|||
connect(q_ptr, &FramelessQuickHelper::windowChanged, q_ptr, &FramelessQuickHelper::windowChanged2);
|
||||
}
|
||||
|
||||
FramelessQuickHelperPrivate::~FramelessQuickHelperPrivate()
|
||||
{
|
||||
m_destroying = true;
|
||||
extendsContentIntoTitleBar(false);
|
||||
m_extendIntoTitleBar = std::nullopt;
|
||||
}
|
||||
FramelessQuickHelperPrivate::~FramelessQuickHelperPrivate() = default;
|
||||
|
||||
FramelessQuickHelperPrivate *FramelessQuickHelperPrivate::get(FramelessQuickHelper *pub)
|
||||
{
|
||||
|
@ -123,48 +118,6 @@ const FramelessQuickHelperPrivate *FramelessQuickHelperPrivate::get(const Framel
|
|||
return pub->d_func();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelperPrivate::isContentExtendedIntoTitleBar() const
|
||||
{
|
||||
const FramelessQuickHelperData *data = getWindowData();
|
||||
return (data ? data->ready : false);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::extendsContentIntoTitleBar(const bool value)
|
||||
{
|
||||
if (isContentExtendedIntoTitleBar() == value) {
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
attach();
|
||||
} else {
|
||||
detach();
|
||||
}
|
||||
m_extendIntoTitleBar = value;
|
||||
if (!m_destroying) {
|
||||
emitSignalForAllInstances("extendsContentIntoTitleBarChanged");
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem *FramelessQuickHelperPrivate::getTitleBarItem() const
|
||||
{
|
||||
const FramelessQuickHelperData *data = getWindowData();
|
||||
return (data ? data->titleBarItem : nullptr);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setTitleBarItem(QQuickItem *value)
|
||||
{
|
||||
Q_ASSERT(value);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
FramelessQuickHelperData *data = getWindowDataMutable();
|
||||
if (!data || (data->titleBarItem == value)) {
|
||||
return;
|
||||
}
|
||||
data->titleBarItem = value;
|
||||
emitSignalForAllInstances("titleBarItemChanged");
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::attach()
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
|
@ -188,8 +141,8 @@ void FramelessQuickHelperPrivate::attach()
|
|||
params.getWindowPosition = [window]() -> QPoint { return window->position(); };
|
||||
params.setWindowPosition = [window](const QPoint &pos) -> void { window->setX(pos.x()); window->setY(pos.y()); };
|
||||
params.getWindowScreen = [window]() -> QScreen * { return window->screen(); };
|
||||
params.isWindowFixedSize = [this]() -> bool { return isWindowFixedSize(); };
|
||||
params.setWindowFixedSize = [this](const bool value) -> void { setWindowFixedSize(value); };
|
||||
params.isWindowFixedSize = [q]() -> bool { return q->isWindowFixedSize(); };
|
||||
params.setWindowFixedSize = [q](const bool value) -> void { q->setWindowFixedSize(value); };
|
||||
params.getWindowState = [window]() -> Qt::WindowState { return window->windowState(); };
|
||||
params.setWindowState = [window](const Qt::WindowState state) -> void { window->setWindowState(state); };
|
||||
params.getWindowHandle = [window]() -> QWindow * { return window; };
|
||||
|
@ -208,7 +161,7 @@ void FramelessQuickHelperPrivate::attach()
|
|||
FRAMELESSHELPER_ENUM_CORE_TO_QUICK(ButtonState, state));
|
||||
};
|
||||
params.shouldIgnoreMouseEvents = [this](const QPoint &pos) -> bool { return shouldIgnoreMouseEvents(pos); };
|
||||
params.showSystemMenu = [this](const QPoint &pos) -> void { showSystemMenu(pos); };
|
||||
params.showSystemMenu = [q](const QPoint &pos) -> void { q->showSystemMenu(pos); };
|
||||
params.setProperty = [this](const char *name, const QVariant &value) -> void { setProperty(name, value); };
|
||||
params.getProperty = [this](const char *name, const QVariant &defaultValue) -> QVariant { return getProperty(name, defaultValue); };
|
||||
params.setCursor = [window](const QCursor &cursor) -> void { window->setCursor(cursor); };
|
||||
|
@ -227,13 +180,13 @@ void FramelessQuickHelperPrivate::attach()
|
|||
// we reach here, and all the modifications from the Qt side will be lost
|
||||
// due to QPA will reset the position and size of the window during it's
|
||||
// initialization process.
|
||||
QTimer::singleShot(m_qpaWaitTime, this, [this](){
|
||||
m_qpaReady = true;
|
||||
QTimer::singleShot(qpaWaitTime, this, [this, q](){
|
||||
qpaReady = true;
|
||||
if (FramelessConfig::instance()->isSet(Option::CenterWindowBeforeShow)) {
|
||||
moveWindowToDesktopCenter();
|
||||
q->moveWindowToDesktopCenter();
|
||||
}
|
||||
if (FramelessConfig::instance()->isSet(Option::EnableBlurBehindWindow)) {
|
||||
setBlurBehindWindowEnabled(true, {});
|
||||
q->setBlurBehindWindowEnabled(true);
|
||||
}
|
||||
emitSignalForAllInstances("ready");
|
||||
});
|
||||
|
@ -255,206 +208,6 @@ void FramelessQuickHelperPrivate::detach()
|
|||
FramelessManager::instance()->removeWindow(windowId);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
Q_ASSERT(buttonType != QuickGlobal::SystemButtonType::Unknown);
|
||||
if (!item || (buttonType == QuickGlobal::SystemButtonType::Unknown)) {
|
||||
return;
|
||||
}
|
||||
FramelessQuickHelperData *data = getWindowDataMutable();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
switch (buttonType) {
|
||||
case QuickGlobal::SystemButtonType::WindowIcon:
|
||||
data->windowIconButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Help:
|
||||
data->contextHelpButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Minimize:
|
||||
data->minimizeButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Maximize:
|
||||
case QuickGlobal::SystemButtonType::Restore:
|
||||
data->maximizeButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Close:
|
||||
data->closeButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Unknown:
|
||||
Q_UNREACHABLE_RETURN(static_cast<void>(0));
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setHitTestVisible(QQuickItem *item, const bool visible)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
FramelessQuickHelperData *data = getWindowDataMutable();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (visible) {
|
||||
data->hitTestVisibleItems.append(item);
|
||||
} else {
|
||||
data->hitTestVisibleItems.removeAll(item);
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setHitTestVisible(const QRect &rect, const bool visible)
|
||||
{
|
||||
Q_ASSERT(rect.isValid());
|
||||
if (!rect.isValid()) {
|
||||
return;
|
||||
}
|
||||
FramelessQuickHelperData *data = getWindowDataMutable();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (visible) {
|
||||
data->hitTestVisibleRects.append(rect);
|
||||
} else {
|
||||
data->hitTestVisibleRects.removeAll(rect);
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setHitTestVisible(QObject *object, const bool visible)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
const auto item = qobject_cast<QQuickItem *>(object);
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
setHitTestVisible(item, visible);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::showSystemMenu(const QPoint &pos)
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
const QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
const WId windowId = window->winId();
|
||||
const QPoint nativePos = Utils::toNativeGlobalPosition(window, pos);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
std::ignore = Utils::showSystemMenu(windowId, nativePos, false, &getWindowData()->params);
|
||||
#elif defined(Q_OS_LINUX)
|
||||
Utils::openSystemMenu(windowId, nativePos);
|
||||
#else
|
||||
Q_UNUSED(windowId);
|
||||
Q_UNUSED(nativePos);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::windowStartSystemMove2(const QPoint &pos)
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
std::ignore = Utils::startSystemMove(window, pos);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos)
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
if (edges == Qt::Edges{}) {
|
||||
return;
|
||||
}
|
||||
std::ignore = Utils::startSystemResize(window, edges, pos);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::moveWindowToDesktopCenter()
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
Utils::moveWindowToDesktopCenter(&getWindowData()->params, true);
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::bringWindowToFront()
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
#ifdef Q_OS_WINDOWS
|
||||
std::ignore = Utils::bringWindowToFront(window->winId());
|
||||
#else
|
||||
if (window->visibility() == QQuickWindow::Hidden) {
|
||||
window->show();
|
||||
}
|
||||
if (window->visibility() == QQuickWindow::Minimized) {
|
||||
# if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
window->setWindowStates(window->windowStates() & ~Qt::WindowMinimized);
|
||||
# else
|
||||
window->showNormal();
|
||||
# endif
|
||||
}
|
||||
window->raise();
|
||||
window->requestActivate();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FramelessQuickHelperPrivate::isWindowFixedSize() const
|
||||
{
|
||||
Q_Q(const FramelessQuickHelper);
|
||||
const QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
if (window->flags() & Qt::MSWindowsFixedSizeDialogHint) {
|
||||
return true;
|
||||
}
|
||||
const QSize minSize = window->minimumSize();
|
||||
const QSize maxSize = window->maximumSize();
|
||||
if (!minSize.isEmpty() && !maxSize.isEmpty() && (minSize == maxSize)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setWindowFixedSize(const bool value)
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
if (isWindowFixedSize() == value) {
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
const QSize size = window->size();
|
||||
window->setMinimumSize(size);
|
||||
window->setMaximumSize(size);
|
||||
} else {
|
||||
window->setMinimumSize(kDefaultWindowSize);
|
||||
window->setMaximumSize(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
|
||||
}
|
||||
#ifdef Q_OS_WINDOWS
|
||||
std::ignore = Utils::setAeroSnappingEnabled(window->winId(), !value);
|
||||
#endif
|
||||
emitSignalForAllInstances("windowFixedSizeChanged");
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::emitSignalForAllInstances(const char *signal)
|
||||
{
|
||||
Q_ASSERT(signal);
|
||||
|
@ -479,50 +232,6 @@ void FramelessQuickHelperPrivate::emitSignalForAllInstances(const char *signal)
|
|||
}
|
||||
}
|
||||
|
||||
bool FramelessQuickHelperPrivate::isBlurBehindWindowEnabled() const
|
||||
{
|
||||
return m_blurBehindWindowEnabled;
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setBlurBehindWindowEnabled(const bool value, const QColor &color)
|
||||
{
|
||||
Q_Q(FramelessQuickHelper);
|
||||
QQuickWindow * const window = q->window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
if (m_blurBehindWindowEnabled == value) {
|
||||
return;
|
||||
}
|
||||
if (Utils::isBlurBehindWindowSupported()) {
|
||||
QuickGlobal::BlurMode mode = QuickGlobal::BlurMode::Disable;
|
||||
if (value) {
|
||||
if (!m_savedWindowBackgroundColor.isValid()) {
|
||||
m_savedWindowBackgroundColor = window->color();
|
||||
}
|
||||
window->setColor(kDefaultTransparentColor);
|
||||
mode = QuickGlobal::BlurMode::Default;
|
||||
} else {
|
||||
if (m_savedWindowBackgroundColor.isValid()) {
|
||||
window->setColor(m_savedWindowBackgroundColor);
|
||||
m_savedWindowBackgroundColor = {};
|
||||
}
|
||||
mode = QuickGlobal::BlurMode::Disable;
|
||||
}
|
||||
if (Utils::setBlurBehindWindowEnabled(window->winId(),
|
||||
FRAMELESSHELPER_ENUM_QUICK_TO_CORE(BlurMode, mode), color)) {
|
||||
m_blurBehindWindowEnabled = value;
|
||||
emitSignalForAllInstances("blurBehindWindowEnabledChanged");
|
||||
} else {
|
||||
WARNING << "Failed to enable/disable blur behind window.";
|
||||
}
|
||||
} else {
|
||||
m_blurBehindWindowEnabled = value;
|
||||
findOrCreateMicaMaterial()->setVisible(m_blurBehindWindowEnabled);
|
||||
emitSignalForAllInstances("blurBehindWindowEnabledChanged");
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setProperty(const char *name, const QVariant &value)
|
||||
{
|
||||
Q_ASSERT(name);
|
||||
|
@ -645,30 +354,6 @@ FramelessQuickHelper *FramelessQuickHelperPrivate::findOrCreateFramelessHelper(Q
|
|||
return instance;
|
||||
}
|
||||
|
||||
bool FramelessQuickHelperPrivate::isReady() const
|
||||
{
|
||||
return m_qpaReady;
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::waitForReady()
|
||||
{
|
||||
if (m_qpaReady) {
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
QEventLoop loop;
|
||||
Q_Q(FramelessQuickHelper);
|
||||
const QMetaObject::Connection connection = connect(
|
||||
q, &FramelessQuickHelper::ready, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
disconnect(connection);
|
||||
#else
|
||||
while (!m_qpaReady) {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
|
||||
{
|
||||
Q_Q(const FramelessQuickHelper);
|
||||
|
@ -708,15 +393,15 @@ void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
|
|||
|
||||
quint32 FramelessQuickHelperPrivate::readyWaitTime() const
|
||||
{
|
||||
return m_qpaWaitTime;
|
||||
return qpaWaitTime;
|
||||
}
|
||||
|
||||
void FramelessQuickHelperPrivate::setReadyWaitTime(const quint32 time)
|
||||
{
|
||||
if (m_qpaWaitTime == time) {
|
||||
if (qpaWaitTime == time) {
|
||||
return;
|
||||
}
|
||||
m_qpaWaitTime = time;
|
||||
qpaWaitTime = time;
|
||||
}
|
||||
|
||||
QRect FramelessQuickHelperPrivate::mapItemGeometryToScene(const QQuickItem * const item) const
|
||||
|
@ -918,8 +603,8 @@ void FramelessQuickHelperPrivate::rebindWindow()
|
|||
q->setParent(window);
|
||||
}
|
||||
}
|
||||
if (m_extendIntoTitleBar.value_or(true)) {
|
||||
extendsContentIntoTitleBar(true);
|
||||
if (extendIntoTitleBar.value_or(true)) {
|
||||
q->extendsContentIntoTitleBar(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -948,30 +633,6 @@ FramelessQuickHelper *FramelessQuickHelper::qmlAttachedProperties(QObject *paren
|
|||
return get(parentObject);
|
||||
}
|
||||
|
||||
QQuickItem *FramelessQuickHelper::titleBarItem() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->getTitleBarItem();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isWindowFixedSize() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->isWindowFixedSize();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isBlurBehindWindowEnabled() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->isBlurBehindWindowEnabled();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isContentExtendedIntoTitleBar() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->isContentExtendedIntoTitleBar();
|
||||
}
|
||||
|
||||
QuickMicaMaterial *FramelessQuickHelper::micaMaterial() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
|
@ -984,22 +645,88 @@ QuickWindowBorder *FramelessQuickHelper::windowBorder() const
|
|||
return d->findOrCreateWindowBorder();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isReady() const
|
||||
void FramelessQuickHelper::setHitTestVisible(QQuickItem *item, const bool visible)
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->isReady();
|
||||
setHitTestVisible_item(item, visible);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::waitForReady()
|
||||
void FramelessQuickHelper::setHitTestVisible_item(QQuickItem *item, const bool visible)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->waitForReady();
|
||||
FramelessQuickHelperData *data = d->getWindowDataMutable();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (visible) {
|
||||
data->hitTestVisibleItems.append(item);
|
||||
} else {
|
||||
data->hitTestVisibleItems.removeAll(item);
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setHitTestVisible_rect(const QRect &rect, const bool visible)
|
||||
{
|
||||
Q_ASSERT(rect.isValid());
|
||||
if (!rect.isValid()) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
FramelessQuickHelperData *data = d->getWindowDataMutable();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (visible) {
|
||||
data->hitTestVisibleRects.append(rect);
|
||||
} else {
|
||||
data->hitTestVisibleRects.removeAll(rect);
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setHitTestVisible_object(QObject *object, const bool visible)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
const auto item = qobject_cast<QQuickItem *>(object);
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
setHitTestVisible_item(item, visible);
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isContentExtendedIntoTitleBar() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
const FramelessQuickHelperData *data = d->getWindowData();
|
||||
return (data ? data->ready : false);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::extendsContentIntoTitleBar(const bool value)
|
||||
{
|
||||
if (isContentExtendedIntoTitleBar() == value) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->extendsContentIntoTitleBar(value);
|
||||
if (value) {
|
||||
d->attach();
|
||||
} else {
|
||||
d->detach();
|
||||
}
|
||||
d->extendIntoTitleBar = value;
|
||||
d->emitSignalForAllInstances("extendsContentIntoTitleBarChanged");
|
||||
}
|
||||
|
||||
QQuickItem *FramelessQuickHelper::titleBarItem() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
const FramelessQuickHelperData *data = d->getWindowData();
|
||||
return (data ? data->titleBarItem : nullptr);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setTitleBarItem(QQuickItem *value)
|
||||
|
@ -1009,7 +736,12 @@ void FramelessQuickHelper::setTitleBarItem(QQuickItem *value)
|
|||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setTitleBarItem(value);
|
||||
FramelessQuickHelperData *data = d->getWindowDataMutable();
|
||||
if (!data || (data->titleBarItem == value)) {
|
||||
return;
|
||||
}
|
||||
data->titleBarItem = value;
|
||||
d->emitSignalForAllInstances("titleBarItemChanged");
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType)
|
||||
|
@ -1020,87 +752,212 @@ void FramelessQuickHelper::setSystemButton(QQuickItem *item, const QuickGlobal::
|
|||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setSystemButton(item, buttonType);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setHitTestVisible(QQuickItem *item, const bool visible)
|
||||
{
|
||||
setHitTestVisible_item(item, visible);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setHitTestVisible_rect(const QRect &rect, const bool visible)
|
||||
{
|
||||
Q_ASSERT(rect.isValid());
|
||||
if (!rect.isValid()) {
|
||||
FramelessQuickHelperData *data = d->getWindowDataMutable();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setHitTestVisible(rect, visible);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setHitTestVisible_object(QObject *object, const bool visible)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
if (!object) {
|
||||
return;
|
||||
switch (buttonType) {
|
||||
case QuickGlobal::SystemButtonType::WindowIcon:
|
||||
data->windowIconButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Help:
|
||||
data->contextHelpButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Minimize:
|
||||
data->minimizeButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Maximize:
|
||||
case QuickGlobal::SystemButtonType::Restore:
|
||||
data->maximizeButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Close:
|
||||
data->closeButton = item;
|
||||
break;
|
||||
case QuickGlobal::SystemButtonType::Unknown:
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setHitTestVisible(object, visible);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setHitTestVisible_item(QQuickItem *item, const bool visible)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setHitTestVisible(item, visible);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::showSystemMenu(const QPoint &pos)
|
||||
{
|
||||
const QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
const WId windowId = w->winId();
|
||||
const QPoint nativePos = Utils::toNativeGlobalPosition(w, pos);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->showSystemMenu(pos);
|
||||
std::ignore = Utils::showSystemMenu(windowId, nativePos, false, &d->getWindowData()->params);
|
||||
#elif defined(Q_OS_LINUX)
|
||||
Utils::openSystemMenu(windowId, nativePos);
|
||||
#else
|
||||
Q_UNUSED(windowId);
|
||||
Q_UNUSED(nativePos);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::windowStartSystemMove2(const QPoint &pos)
|
||||
{
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->windowStartSystemMove2(pos);
|
||||
QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
std::ignore = Utils::startSystemMove(w, pos);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos)
|
||||
{
|
||||
QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
if (edges == Qt::Edges{}) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->windowStartSystemResize2(edges, pos);
|
||||
std::ignore = Utils::startSystemResize(w, edges, pos);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::moveWindowToDesktopCenter()
|
||||
{
|
||||
if (!window()) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->moveWindowToDesktopCenter();
|
||||
Utils::moveWindowToDesktopCenter(&d->getWindowData()->params, true);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::bringWindowToFront()
|
||||
{
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->bringWindowToFront();
|
||||
QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
#ifdef Q_OS_WINDOWS
|
||||
std::ignore = Utils::bringWindowToFront(w->winId());
|
||||
#else
|
||||
if (w->visibility() == QQuickWindow::Hidden) {
|
||||
w->show();
|
||||
}
|
||||
if (w->visibility() == QQuickWindow::Minimized) {
|
||||
# if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
w->setWindowStates(w->windowStates() & ~Qt::WindowMinimized);
|
||||
# else
|
||||
w->showNormal();
|
||||
# endif
|
||||
}
|
||||
w->raise();
|
||||
w->requestActivate();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isWindowFixedSize() const
|
||||
{
|
||||
const QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return false;
|
||||
}
|
||||
if (w->flags() & Qt::MSWindowsFixedSizeDialogHint) {
|
||||
return true;
|
||||
}
|
||||
const QSize minSize = w->minimumSize();
|
||||
const QSize maxSize = w->maximumSize();
|
||||
if (!minSize.isEmpty() && !maxSize.isEmpty() && (minSize == maxSize)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setWindowFixedSize(const bool value)
|
||||
{
|
||||
QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
if (isWindowFixedSize() == value) {
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
const QSize size = w->size();
|
||||
w->setMinimumSize(size);
|
||||
w->setMaximumSize(size);
|
||||
} else {
|
||||
w->setMinimumSize(kDefaultWindowSize);
|
||||
w->setMaximumSize(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
|
||||
}
|
||||
#ifdef Q_OS_WINDOWS
|
||||
std::ignore = Utils::setAeroSnappingEnabled(w->winId(), !value);
|
||||
#endif
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setWindowFixedSize(value);
|
||||
d->emitSignalForAllInstances("windowFixedSizeChanged");
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isBlurBehindWindowEnabled() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->blurBehindWindowEnabled;
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setBlurBehindWindowEnabled(const bool value)
|
||||
{
|
||||
QQuickWindow * const w = window();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
Q_D(FramelessQuickHelper);
|
||||
d->setBlurBehindWindowEnabled(value, {});
|
||||
if (d->blurBehindWindowEnabled == value) {
|
||||
return;
|
||||
}
|
||||
if (Utils::isBlurBehindWindowSupported()) {
|
||||
QuickGlobal::BlurMode mode = QuickGlobal::BlurMode::Disable;
|
||||
if (value) {
|
||||
if (!d->savedWindowBackgroundColor.isValid()) {
|
||||
d->savedWindowBackgroundColor = w->color();
|
||||
}
|
||||
w->setColor(kDefaultTransparentColor);
|
||||
mode = QuickGlobal::BlurMode::Default;
|
||||
} else {
|
||||
if (d->savedWindowBackgroundColor.isValid()) {
|
||||
w->setColor(d->savedWindowBackgroundColor);
|
||||
d->savedWindowBackgroundColor = {};
|
||||
}
|
||||
mode = QuickGlobal::BlurMode::Disable;
|
||||
}
|
||||
if (Utils::setBlurBehindWindowEnabled(w->winId(), FRAMELESSHELPER_ENUM_QUICK_TO_CORE(BlurMode, mode), {})) {
|
||||
d->blurBehindWindowEnabled = value;
|
||||
d->emitSignalForAllInstances("blurBehindWindowEnabledChanged");
|
||||
} else {
|
||||
WARNING << "Failed to enable/disable blur behind window.";
|
||||
}
|
||||
} else {
|
||||
d->blurBehindWindowEnabled = value;
|
||||
micaMaterial()->setVisible(d->blurBehindWindowEnabled);
|
||||
d->emitSignalForAllInstances("blurBehindWindowEnabledChanged");
|
||||
}
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::isReady() const
|
||||
{
|
||||
Q_D(const FramelessQuickHelper);
|
||||
return d->qpaReady;
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::waitForReady()
|
||||
{
|
||||
Q_D(FramelessQuickHelper);
|
||||
if (d->qpaReady) {
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
QEventLoop loop{};
|
||||
const QMetaObject::Connection connection = connect(this, &FramelessQuickHelper::ready, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
disconnect(connection);
|
||||
#else
|
||||
while (!d->qpaReady) {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::itemChange(const ItemChange change, const ItemChangeData &value)
|
||||
|
|
|
@ -59,7 +59,6 @@ FramelessQuickWindowPrivate::FramelessQuickWindowPrivate(FramelessQuickWindow *q
|
|||
return;
|
||||
}
|
||||
q_ptr = q;
|
||||
initialize();
|
||||
}
|
||||
|
||||
FramelessQuickWindowPrivate::~FramelessQuickWindowPrivate() = default;
|
||||
|
@ -82,156 +81,90 @@ const FramelessQuickWindowPrivate *FramelessQuickWindowPrivate::get(const Framel
|
|||
return pub->d_func();
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isHidden() const
|
||||
{
|
||||
Q_Q(const FramelessQuickWindow);
|
||||
return (q->visibility() == FramelessQuickWindow::Hidden);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isNormal() const
|
||||
{
|
||||
Q_Q(const FramelessQuickWindow);
|
||||
return (q->visibility() == FramelessQuickWindow::Windowed);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isMinimized() const
|
||||
{
|
||||
Q_Q(const FramelessQuickWindow);
|
||||
return (q->visibility() == FramelessQuickWindow::Minimized);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isMaximized() const
|
||||
{
|
||||
Q_Q(const FramelessQuickWindow);
|
||||
return (q->visibility() == FramelessQuickWindow::Maximized);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isZoomed() const
|
||||
{
|
||||
Q_Q(const FramelessQuickWindow);
|
||||
return (isMaximized() || (q->visibility() == FramelessQuickWindow::FullScreen));
|
||||
}
|
||||
|
||||
bool FramelessQuickWindowPrivate::isFullScreen() const
|
||||
{
|
||||
Q_Q(const FramelessQuickWindow);
|
||||
return (q->visibility() == FramelessQuickWindow::FullScreen);
|
||||
}
|
||||
|
||||
void FramelessQuickWindowPrivate::showMinimized2()
|
||||
{
|
||||
Q_Q(FramelessQuickWindow);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
// Work-around a QtQuick bug: https://bugreports.qt.io/browse/QTBUG-69711
|
||||
// Don't use "SW_SHOWMINIMIZED" because it will activate the current window
|
||||
// instead of the next window in the Z order, which is not the default behavior
|
||||
// of native Win32 applications.
|
||||
ShowWindow(reinterpret_cast<HWND>(q->winId()), SW_MINIMIZE);
|
||||
#else
|
||||
q->showMinimized();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickWindowPrivate::toggleMaximized()
|
||||
{
|
||||
Q_Q(FramelessQuickWindow);
|
||||
if (isMaximized()) {
|
||||
q->showNormal();
|
||||
} else {
|
||||
q->showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickWindowPrivate::toggleFullScreen()
|
||||
{
|
||||
Q_Q(FramelessQuickWindow);
|
||||
if (isFullScreen()) {
|
||||
q->setVisibility(m_savedVisibility);
|
||||
} else {
|
||||
m_savedVisibility = q->visibility();
|
||||
q->showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickWindowPrivate::initialize()
|
||||
{
|
||||
Q_Q(FramelessQuickWindow);
|
||||
QQuickItem * const rootItem = q->contentItem();
|
||||
FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar();
|
||||
m_windowBorder = new QuickWindowBorder;
|
||||
m_windowBorder->setParent(rootItem);
|
||||
m_windowBorder->setParentItem(rootItem);
|
||||
m_windowBorder->setZ(999); // Make sure it always stays on the top.
|
||||
QQuickItemPrivate::get(m_windowBorder)->anchors()->setFill(rootItem);
|
||||
connect(q, &FramelessQuickWindow::visibilityChanged, q, [q](){
|
||||
Q_EMIT q->hiddenChanged();
|
||||
Q_EMIT q->normalChanged();
|
||||
Q_EMIT q->minimizedChanged();
|
||||
Q_EMIT q->maximizedChanged();
|
||||
Q_EMIT q->zoomedChanged();
|
||||
Q_EMIT q->fullScreenChanged();
|
||||
});
|
||||
}
|
||||
|
||||
FramelessQuickWindow::FramelessQuickWindow(QWindow *parent)
|
||||
: QQuickWindowQmlImpl(parent), d_ptr(new FramelessQuickWindowPrivate(this))
|
||||
{
|
||||
QQuickItem * const rootItem = contentItem();
|
||||
FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar();
|
||||
Q_D(FramelessQuickWindow);
|
||||
d->windowBorder = new QuickWindowBorder;
|
||||
d->windowBorder->setParent(rootItem);
|
||||
d->windowBorder->setParentItem(rootItem);
|
||||
d->windowBorder->setZ(999); // Make sure it always stays on the top.
|
||||
QQuickItemPrivate::get(d->windowBorder)->anchors()->setFill(rootItem);
|
||||
connect(this, &FramelessQuickWindow::visibilityChanged, this, [this](){
|
||||
Q_EMIT hiddenChanged();
|
||||
Q_EMIT normalChanged();
|
||||
Q_EMIT minimizedChanged();
|
||||
Q_EMIT maximizedChanged();
|
||||
Q_EMIT zoomedChanged();
|
||||
Q_EMIT fullScreenChanged();
|
||||
});
|
||||
}
|
||||
|
||||
FramelessQuickWindow::~FramelessQuickWindow() = default;
|
||||
|
||||
bool FramelessQuickWindow::isHidden() const
|
||||
{
|
||||
Q_D(const FramelessQuickWindow);
|
||||
return d->isHidden();
|
||||
return (visibility() == FramelessQuickWindow::Hidden);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindow::isNormal() const
|
||||
{
|
||||
Q_D(const FramelessQuickWindow);
|
||||
return d->isNormal();
|
||||
return (visibility() == FramelessQuickWindow::Windowed);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindow::isMinimized() const
|
||||
{
|
||||
Q_D(const FramelessQuickWindow);
|
||||
return d->isMinimized();
|
||||
return (visibility() == FramelessQuickWindow::Minimized);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindow::isMaximized() const
|
||||
{
|
||||
Q_D(const FramelessQuickWindow);
|
||||
return d->isMaximized();
|
||||
return (visibility() == FramelessQuickWindow::Maximized);
|
||||
}
|
||||
|
||||
bool FramelessQuickWindow::isZoomed() const
|
||||
{
|
||||
Q_D(const FramelessQuickWindow);
|
||||
return d->isZoomed();
|
||||
return (isMaximized() || (visibility() == FramelessQuickWindow::FullScreen));
|
||||
}
|
||||
|
||||
bool FramelessQuickWindow::isFullScreen() const
|
||||
{
|
||||
Q_D(const FramelessQuickWindow);
|
||||
return d->isFullScreen();
|
||||
return (visibility() == FramelessQuickWindow::FullScreen);
|
||||
}
|
||||
|
||||
void FramelessQuickWindow::showMinimized2()
|
||||
{
|
||||
Q_D(FramelessQuickWindow);
|
||||
d->showMinimized2();
|
||||
#ifdef Q_OS_WINDOWS
|
||||
// Work-around a QtQuick bug: https://bugreports.qt.io/browse/QTBUG-69711
|
||||
// Don't use "SW_SHOWMINIMIZED" because it will activate the current window
|
||||
// instead of the next window in the Z order, which is not the default behavior
|
||||
// of native Win32 applications.
|
||||
::ShowWindow(reinterpret_cast<HWND>(winId()), SW_MINIMIZE);
|
||||
#else
|
||||
showMinimized();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickWindow::toggleMaximized()
|
||||
{
|
||||
Q_D(FramelessQuickWindow);
|
||||
d->toggleMaximized();
|
||||
if (isMaximized()) {
|
||||
showNormal();
|
||||
} else {
|
||||
showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickWindow::toggleFullScreen()
|
||||
{
|
||||
Q_D(FramelessQuickWindow);
|
||||
d->toggleFullScreen();
|
||||
if (isFullScreen()) {
|
||||
setVisibility(d->savedVisibility);
|
||||
} else {
|
||||
d->savedVisibility = visibility();
|
||||
showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessQuickWindow::classBegin()
|
||||
|
|
|
@ -60,7 +60,6 @@ QuickImageItemPrivate::QuickImageItemPrivate(QuickImageItem *q) : QObject(q)
|
|||
return;
|
||||
}
|
||||
q_ptr = q;
|
||||
initialize();
|
||||
}
|
||||
|
||||
QuickImageItemPrivate::~QuickImageItemPrivate() = default;
|
||||
|
@ -83,71 +82,6 @@ const QuickImageItemPrivate *QuickImageItemPrivate::get(const QuickImageItem *q)
|
|||
return q->d_func();
|
||||
}
|
||||
|
||||
void QuickImageItemPrivate::paint(QPainter *painter) const
|
||||
{
|
||||
Q_ASSERT(painter);
|
||||
if (!painter) {
|
||||
return;
|
||||
}
|
||||
if (!m_source.isValid() || m_source.isNull()) {
|
||||
return;
|
||||
}
|
||||
painter->save();
|
||||
painter->setRenderHints(QPainter::Antialiasing |
|
||||
QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
||||
switch (m_source.userType()) {
|
||||
case QMetaType::QUrl:
|
||||
fromUrl(m_source.toUrl(), painter);
|
||||
break;
|
||||
case QMetaType::QString:
|
||||
fromString(m_source.toString(), painter);
|
||||
break;
|
||||
case QMetaType::QImage:
|
||||
fromImage(qvariant_cast<QImage>(m_source), painter);
|
||||
break;
|
||||
case QMetaType::QPixmap:
|
||||
fromPixmap(qvariant_cast<QPixmap>(m_source), painter);
|
||||
break;
|
||||
case QMetaType::QIcon:
|
||||
fromIcon(qvariant_cast<QIcon>(m_source), painter);
|
||||
break;
|
||||
default:
|
||||
WARNING << "Unsupported type:" << m_source.typeName();
|
||||
break;
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QVariant QuickImageItemPrivate::source() const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
||||
void QuickImageItemPrivate::setSource(const QVariant &value)
|
||||
{
|
||||
Q_ASSERT(value.isValid());
|
||||
Q_ASSERT(!value.isNull());
|
||||
if (!value.isValid() || value.isNull()) {
|
||||
return;
|
||||
}
|
||||
if (m_source == value) {
|
||||
return;
|
||||
}
|
||||
m_source = value;
|
||||
Q_Q(QuickImageItem);
|
||||
q->update();
|
||||
Q_EMIT q->sourceChanged();
|
||||
}
|
||||
|
||||
void QuickImageItemPrivate::initialize()
|
||||
{
|
||||
Q_Q(QuickImageItem);
|
||||
q->setAntialiasing(true);
|
||||
q->setSmooth(true);
|
||||
q->setMipmap(true);
|
||||
q->setClip(true);
|
||||
}
|
||||
|
||||
void QuickImageItemPrivate::fromUrl(const QUrl &value, QPainter *painter) const
|
||||
{
|
||||
Q_ASSERT(value.isValid());
|
||||
|
@ -226,26 +160,70 @@ QRectF QuickImageItemPrivate::paintArea() const
|
|||
QuickImageItem::QuickImageItem(QQuickItem *parent)
|
||||
: QQuickPaintedItem(parent), d_ptr(new QuickImageItemPrivate(this))
|
||||
{
|
||||
setAntialiasing(true);
|
||||
setSmooth(true);
|
||||
setMipmap(true);
|
||||
setClip(true);
|
||||
}
|
||||
|
||||
QuickImageItem::~QuickImageItem() = default;
|
||||
|
||||
void QuickImageItem::paint(QPainter *painter)
|
||||
{
|
||||
Q_ASSERT(painter);
|
||||
if (!painter) {
|
||||
return;
|
||||
}
|
||||
Q_D(QuickImageItem);
|
||||
d->paint(painter);
|
||||
if (!d->source.isValid() || d->source.isNull()) {
|
||||
return;
|
||||
}
|
||||
painter->save();
|
||||
painter->setRenderHints(QPainter::Antialiasing |
|
||||
QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
||||
switch (d->source.userType()) {
|
||||
case QMetaType::QUrl:
|
||||
d->fromUrl(d->source.toUrl(), painter);
|
||||
break;
|
||||
case QMetaType::QString:
|
||||
d->fromString(d->source.toString(), painter);
|
||||
break;
|
||||
case QMetaType::QImage:
|
||||
d->fromImage(qvariant_cast<QImage>(d->source), painter);
|
||||
break;
|
||||
case QMetaType::QPixmap:
|
||||
d->fromPixmap(qvariant_cast<QPixmap>(d->source), painter);
|
||||
break;
|
||||
case QMetaType::QIcon:
|
||||
d->fromIcon(qvariant_cast<QIcon>(d->source), painter);
|
||||
break;
|
||||
default:
|
||||
WARNING << "Unsupported type:" << d->source.typeName();
|
||||
break;
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QVariant QuickImageItem::source() const
|
||||
{
|
||||
Q_D(const QuickImageItem);
|
||||
return d->source();
|
||||
return d->source;
|
||||
}
|
||||
|
||||
void QuickImageItem::setSource(const QVariant &value)
|
||||
{
|
||||
Q_ASSERT(value.isValid());
|
||||
Q_ASSERT(!value.isNull());
|
||||
if (!value.isValid() || value.isNull()) {
|
||||
return;
|
||||
}
|
||||
Q_D(QuickImageItem);
|
||||
d->setSource(value);
|
||||
if (d->source == value) {
|
||||
return;
|
||||
}
|
||||
d->source = value;
|
||||
update();
|
||||
Q_EMIT sourceChanged();
|
||||
}
|
||||
|
||||
void QuickImageItem::classBegin()
|
||||
|
|
|
@ -102,13 +102,13 @@ void QuickMicaMaterialPrivate::initialize()
|
|||
// we don't need it anyway and it can improve the general performance as well.
|
||||
q->setFillColor(QColor{});
|
||||
|
||||
m_micaMaterial = new MicaMaterial(this);
|
||||
connect(m_micaMaterial, &MicaMaterial::tintColorChanged, q, &QuickMicaMaterial::tintColorChanged);
|
||||
connect(m_micaMaterial, &MicaMaterial::tintOpacityChanged, q, &QuickMicaMaterial::tintOpacityChanged);
|
||||
connect(m_micaMaterial, &MicaMaterial::fallbackColorChanged, q, &QuickMicaMaterial::fallbackColorChanged);
|
||||
connect(m_micaMaterial, &MicaMaterial::noiseOpacityChanged, q, &QuickMicaMaterial::noiseOpacityChanged);
|
||||
connect(m_micaMaterial, &MicaMaterial::fallbackEnabledChanged, q, &QuickMicaMaterial::fallbackEnabledChanged);
|
||||
connect(m_micaMaterial, &MicaMaterial::shouldRedraw, q, [q](){ q->update(); });
|
||||
micaMaterial = new MicaMaterial(this);
|
||||
connect(micaMaterial, &MicaMaterial::tintColorChanged, q, &QuickMicaMaterial::tintColorChanged);
|
||||
connect(micaMaterial, &MicaMaterial::tintOpacityChanged, q, &QuickMicaMaterial::tintOpacityChanged);
|
||||
connect(micaMaterial, &MicaMaterial::fallbackColorChanged, q, &QuickMicaMaterial::fallbackColorChanged);
|
||||
connect(micaMaterial, &MicaMaterial::noiseOpacityChanged, q, &QuickMicaMaterial::noiseOpacityChanged);
|
||||
connect(micaMaterial, &MicaMaterial::fallbackEnabledChanged, q, &QuickMicaMaterial::fallbackEnabledChanged);
|
||||
connect(micaMaterial, &MicaMaterial::shouldRedraw, q, [q](){ q->update(); });
|
||||
}
|
||||
|
||||
void QuickMicaMaterialPrivate::rebindWindow()
|
||||
|
@ -125,39 +125,21 @@ void QuickMicaMaterialPrivate::rebindWindow()
|
|||
QQuickItemPrivate::get(q)->anchors()->setFill(rootItem);
|
||||
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE
|
||||
q->setZ(-999); // Make sure we always stays on the bottom most place.
|
||||
if (m_rootWindowXChangedConnection) {
|
||||
disconnect(m_rootWindowXChangedConnection);
|
||||
m_rootWindowXChangedConnection = {};
|
||||
if (rootWindowXChangedConnection) {
|
||||
disconnect(rootWindowXChangedConnection);
|
||||
rootWindowXChangedConnection = {};
|
||||
}
|
||||
if (m_rootWindowYChangedConnection) {
|
||||
disconnect(m_rootWindowYChangedConnection);
|
||||
m_rootWindowYChangedConnection = {};
|
||||
if (rootWindowYChangedConnection) {
|
||||
disconnect(rootWindowYChangedConnection);
|
||||
rootWindowYChangedConnection = {};
|
||||
}
|
||||
if (m_rootWindowActiveChangedConnection) {
|
||||
disconnect(m_rootWindowActiveChangedConnection);
|
||||
m_rootWindowActiveChangedConnection = {};
|
||||
if (rootWindowActiveChangedConnection) {
|
||||
disconnect(rootWindowActiveChangedConnection);
|
||||
rootWindowActiveChangedConnection = {};
|
||||
}
|
||||
m_rootWindowXChangedConnection = connect(window, &QQuickWindow::xChanged, q, [q](){ q->update(); });
|
||||
m_rootWindowYChangedConnection = connect(window, &QQuickWindow::yChanged, q, [q](){ q->update(); });
|
||||
m_rootWindowActiveChangedConnection = connect(window, &QQuickWindow::activeChanged, q, [q](){ q->update(); });
|
||||
}
|
||||
|
||||
void QuickMicaMaterialPrivate::repaint(QPainter *painter)
|
||||
{
|
||||
Q_ASSERT(painter);
|
||||
Q_ASSERT(m_micaMaterial);
|
||||
if (!painter || !m_micaMaterial) {
|
||||
return;
|
||||
}
|
||||
Q_Q(QuickMicaMaterial);
|
||||
const bool isActive = q->window() ? q->window()->isActive() : false;
|
||||
const QPoint originPoint = q->mapToGlobal(QPointF{ 0, 0 }).toPoint();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
const QSize size = q->size().toSize();
|
||||
#else // (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
|
||||
const QSize size = QSizeF{ q->width(), q->height() }.toSize();
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
m_micaMaterial->paint(painter, QRect{ originPoint, size }, isActive);
|
||||
rootWindowXChangedConnection = connect(window, &QQuickWindow::xChanged, q, [q](){ q->update(); });
|
||||
rootWindowYChangedConnection = connect(window, &QQuickWindow::yChanged, q, [q](){ q->update(); });
|
||||
rootWindowActiveChangedConnection = connect(window, &QQuickWindow::activeChanged, q, [q](){ q->update(); });
|
||||
}
|
||||
|
||||
QuickMicaMaterial::QuickMicaMaterial(QQuickItem *parent)
|
||||
|
@ -174,67 +156,74 @@ void QuickMicaMaterial::paint(QPainter *painter)
|
|||
return;
|
||||
}
|
||||
Q_D(QuickMicaMaterial);
|
||||
d->repaint(painter);
|
||||
const bool isActive = window() ? window()->isActive() : false;
|
||||
const QPoint originPoint = mapToGlobal(QPointF{ 0, 0 }).toPoint();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
const QSize s = size().toSize();
|
||||
#else // (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
|
||||
const QSize s = QSizeF{ width(), height() }.toSize();
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
d->micaMaterial->paint(painter, QRect{ originPoint, s }, isActive);
|
||||
}
|
||||
|
||||
QColor QuickMicaMaterial::tintColor() const
|
||||
{
|
||||
Q_D(const QuickMicaMaterial);
|
||||
return d->m_micaMaterial->tintColor();
|
||||
return d->micaMaterial->tintColor();
|
||||
}
|
||||
|
||||
void QuickMicaMaterial::setTintColor(const QColor &value)
|
||||
{
|
||||
Q_D(QuickMicaMaterial);
|
||||
d->m_micaMaterial->setTintColor(value);
|
||||
d->micaMaterial->setTintColor(value);
|
||||
}
|
||||
|
||||
qreal QuickMicaMaterial::tintOpacity() const
|
||||
{
|
||||
Q_D(const QuickMicaMaterial);
|
||||
return d->m_micaMaterial->tintOpacity();
|
||||
return d->micaMaterial->tintOpacity();
|
||||
}
|
||||
|
||||
void QuickMicaMaterial::setTintOpacity(const qreal value)
|
||||
{
|
||||
Q_D(QuickMicaMaterial);
|
||||
d->m_micaMaterial->setTintOpacity(value);
|
||||
d->micaMaterial->setTintOpacity(value);
|
||||
}
|
||||
|
||||
QColor QuickMicaMaterial::fallbackColor() const
|
||||
{
|
||||
Q_D(const QuickMicaMaterial);
|
||||
return d->m_micaMaterial->fallbackColor();
|
||||
return d->micaMaterial->fallbackColor();
|
||||
}
|
||||
|
||||
void QuickMicaMaterial::setFallbackColor(const QColor &value)
|
||||
{
|
||||
Q_D(QuickMicaMaterial);
|
||||
d->m_micaMaterial->setFallbackColor(value);
|
||||
d->micaMaterial->setFallbackColor(value);
|
||||
}
|
||||
|
||||
qreal QuickMicaMaterial::noiseOpacity() const
|
||||
{
|
||||
Q_D(const QuickMicaMaterial);
|
||||
return d->m_micaMaterial->noiseOpacity();
|
||||
return d->micaMaterial->noiseOpacity();
|
||||
}
|
||||
|
||||
void QuickMicaMaterial::setNoiseOpacity(const qreal value)
|
||||
{
|
||||
Q_D(QuickMicaMaterial);
|
||||
d->m_micaMaterial->setNoiseOpacity(value);
|
||||
d->micaMaterial->setNoiseOpacity(value);
|
||||
}
|
||||
|
||||
bool QuickMicaMaterial::isFallbackEnabled() const
|
||||
{
|
||||
Q_D(const QuickMicaMaterial);
|
||||
return d->m_micaMaterial->isFallbackEnabled();
|
||||
return d->micaMaterial->isFallbackEnabled();
|
||||
}
|
||||
|
||||
void QuickMicaMaterial::setFallbackEnabled(const bool value)
|
||||
{
|
||||
Q_D(QuickMicaMaterial);
|
||||
d->m_micaMaterial->setFallbackEnabled(value);
|
||||
d->micaMaterial->setFallbackEnabled(value);
|
||||
}
|
||||
|
||||
void QuickMicaMaterial::itemChange(const ItemChange change, const ItemChangeData &value)
|
||||
|
@ -242,14 +231,14 @@ void QuickMicaMaterial::itemChange(const ItemChange change, const ItemChangeData
|
|||
QQuickPaintedItem::itemChange(change, value);
|
||||
Q_D(QuickMicaMaterial);
|
||||
switch (change) {
|
||||
case ItemDevicePixelRatioHasChanged: {
|
||||
case ItemDevicePixelRatioHasChanged:
|
||||
update(); // Force re-paint immediately.
|
||||
} break;
|
||||
case ItemSceneChange: {
|
||||
break;
|
||||
case ItemSceneChange:
|
||||
if (value.window) {
|
||||
d->rebindWindow();
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -115,21 +115,6 @@ const QuickWindowBorderPrivate *QuickWindowBorderPrivate::get(const QuickWindowB
|
|||
return q->d_func();
|
||||
}
|
||||
|
||||
void QuickWindowBorderPrivate::paint(QPainter *painter) const
|
||||
{
|
||||
Q_ASSERT(painter);
|
||||
if (!painter || !m_borderPainter) {
|
||||
return;
|
||||
}
|
||||
Q_Q(const QuickWindowBorder);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
const QSize size = q->size().toSize();
|
||||
#else
|
||||
const QSize size = QSizeF(q->width(), q->height()).toSize();
|
||||
#endif
|
||||
m_borderPainter->paint(painter, size, (q->window() && q->window()->isActive()));
|
||||
}
|
||||
|
||||
void QuickWindowBorderPrivate::update()
|
||||
{
|
||||
Q_Q(QuickWindowBorder);
|
||||
|
@ -150,18 +135,18 @@ void QuickWindowBorderPrivate::initialize()
|
|||
// some very thin lines that are too fragile.
|
||||
q->setAntialiasing(false);
|
||||
|
||||
m_borderPainter = new WindowBorderPainter(this);
|
||||
connect(m_borderPainter, &WindowBorderPainter::thicknessChanged,
|
||||
borderPainter = new WindowBorderPainter(this);
|
||||
connect(borderPainter, &WindowBorderPainter::thicknessChanged,
|
||||
q, &QuickWindowBorder::thicknessChanged);
|
||||
connect(m_borderPainter, &WindowBorderPainter::edgesChanged,
|
||||
connect(borderPainter, &WindowBorderPainter::edgesChanged,
|
||||
q, &QuickWindowBorder::edgesChanged);
|
||||
connect(m_borderPainter, &WindowBorderPainter::activeColorChanged,
|
||||
connect(borderPainter, &WindowBorderPainter::activeColorChanged,
|
||||
q, &QuickWindowBorder::activeColorChanged);
|
||||
connect(m_borderPainter, &WindowBorderPainter::inactiveColorChanged,
|
||||
connect(borderPainter, &WindowBorderPainter::inactiveColorChanged,
|
||||
q, &QuickWindowBorder::inactiveColorChanged);
|
||||
connect(m_borderPainter, &WindowBorderPainter::nativeBorderChanged,
|
||||
connect(borderPainter, &WindowBorderPainter::nativeBorderChanged,
|
||||
q, &QuickWindowBorder::nativeBorderChanged);
|
||||
connect(m_borderPainter, &WindowBorderPainter::shouldRepaint, q, [q](){ q->update(); });
|
||||
connect(borderPainter, &WindowBorderPainter::shouldRepaint, q, [q](){ q->update(); });
|
||||
}
|
||||
|
||||
void QuickWindowBorderPrivate::rebindWindow()
|
||||
|
@ -178,17 +163,17 @@ void QuickWindowBorderPrivate::rebindWindow()
|
|||
QQuickItemPrivate::get(q)->anchors()->setFill(rootItem);
|
||||
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE
|
||||
q->setZ(999); // Make sure we always stays on the top most place.
|
||||
if (m_activeChangeConnection) {
|
||||
disconnect(m_activeChangeConnection);
|
||||
m_activeChangeConnection = {};
|
||||
if (activeChangeConnection) {
|
||||
disconnect(activeChangeConnection);
|
||||
activeChangeConnection = {};
|
||||
}
|
||||
if (m_visibilityChangeConnection) {
|
||||
disconnect(m_visibilityChangeConnection);
|
||||
m_visibilityChangeConnection = {};
|
||||
if (visibilityChangeConnection) {
|
||||
disconnect(visibilityChangeConnection);
|
||||
visibilityChangeConnection = {};
|
||||
}
|
||||
m_activeChangeConnection = connect(window, &QQuickWindow::activeChanged,
|
||||
activeChangeConnection = connect(window, &QQuickWindow::activeChanged,
|
||||
this, &QuickWindowBorderPrivate::update);
|
||||
m_visibilityChangeConnection = connect(window, &QQuickWindow::visibilityChanged,
|
||||
visibilityChangeConnection = connect(window, &QQuickWindow::visibilityChanged,
|
||||
this, &QuickWindowBorderPrivate::update);
|
||||
}
|
||||
|
||||
|
@ -201,106 +186,115 @@ QuickWindowBorder::~QuickWindowBorder() = default;
|
|||
|
||||
void QuickWindowBorder::paint(QPainter *painter)
|
||||
{
|
||||
Q_ASSERT(painter);
|
||||
if (!painter) {
|
||||
return;
|
||||
}
|
||||
Q_D(QuickWindowBorder);
|
||||
d->paint(painter);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
const QSize s = size().toSize();
|
||||
#else
|
||||
const QSize s = QSizeF{ width(), height() }.toSize();
|
||||
#endif
|
||||
d->borderPainter->paint(painter, s, (window() && window()->isActive()));
|
||||
}
|
||||
|
||||
qreal QuickWindowBorder::thickness() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? 0 : d->m_borderPainter->thickness());
|
||||
return ((d->borderPainter == nullptr) ? 0 : d->borderPainter->thickness());
|
||||
}
|
||||
|
||||
QuickGlobal::WindowEdges QuickWindowBorder::edges() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? QuickGlobal::WindowEdges()
|
||||
: edgesToQuickEdges(d->m_borderPainter->edges()));
|
||||
return ((d->borderPainter == nullptr) ? QuickGlobal::WindowEdges()
|
||||
: edgesToQuickEdges(d->borderPainter->edges()));
|
||||
}
|
||||
|
||||
QColor QuickWindowBorder::activeColor() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? QColor() : d->m_borderPainter->activeColor());
|
||||
return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->activeColor());
|
||||
}
|
||||
|
||||
QColor QuickWindowBorder::inactiveColor() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? QColor() : d->m_borderPainter->inactiveColor());
|
||||
return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->inactiveColor());
|
||||
}
|
||||
|
||||
qreal QuickWindowBorder::nativeThickness() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? 0 : d->m_borderPainter->nativeThickness());
|
||||
return ((d->borderPainter == nullptr) ? 0 : d->borderPainter->nativeThickness());
|
||||
}
|
||||
|
||||
QuickGlobal::WindowEdges QuickWindowBorder::nativeEdges() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? QuickGlobal::WindowEdges()
|
||||
: edgesToQuickEdges(d->m_borderPainter->nativeEdges()));
|
||||
return ((d->borderPainter == nullptr) ? QuickGlobal::WindowEdges()
|
||||
: edgesToQuickEdges(d->borderPainter->nativeEdges()));
|
||||
}
|
||||
|
||||
QColor QuickWindowBorder::nativeActiveColor() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? QColor() : d->m_borderPainter->nativeActiveColor());
|
||||
return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->nativeActiveColor());
|
||||
}
|
||||
|
||||
QColor QuickWindowBorder::nativeInactiveColor() const
|
||||
{
|
||||
Q_D(const QuickWindowBorder);
|
||||
return ((d->m_borderPainter == nullptr) ? QColor() : d->m_borderPainter->nativeInactiveColor());
|
||||
return ((d->borderPainter == nullptr) ? QColor() : d->borderPainter->nativeInactiveColor());
|
||||
}
|
||||
|
||||
void QuickWindowBorder::setThickness(const qreal value)
|
||||
{
|
||||
Q_D(QuickWindowBorder);
|
||||
if (!d->m_borderPainter) {
|
||||
if (!d->borderPainter) {
|
||||
return;
|
||||
}
|
||||
if (qFuzzyCompare(thickness(), value)) {
|
||||
return;
|
||||
}
|
||||
d->m_borderPainter->setThickness(std::round(value));
|
||||
d->borderPainter->setThickness(std::round(value));
|
||||
}
|
||||
|
||||
void QuickWindowBorder::setEdges(const QuickGlobal::WindowEdges value)
|
||||
{
|
||||
Q_D(QuickWindowBorder);
|
||||
if (!d->m_borderPainter) {
|
||||
if (!d->borderPainter) {
|
||||
return;
|
||||
}
|
||||
if (edges() == value) {
|
||||
return;
|
||||
}
|
||||
d->m_borderPainter->setEdges(quickEdgesToEdges(value));
|
||||
d->borderPainter->setEdges(quickEdgesToEdges(value));
|
||||
}
|
||||
|
||||
void QuickWindowBorder::setActiveColor(const QColor &value)
|
||||
{
|
||||
Q_D(QuickWindowBorder);
|
||||
if (!d->m_borderPainter) {
|
||||
if (!d->borderPainter) {
|
||||
return;
|
||||
}
|
||||
if (activeColor() == value) {
|
||||
return;
|
||||
}
|
||||
d->m_borderPainter->setActiveColor(value);
|
||||
d->borderPainter->setActiveColor(value);
|
||||
}
|
||||
|
||||
void QuickWindowBorder::setInactiveColor(const QColor &value)
|
||||
{
|
||||
Q_D(QuickWindowBorder);
|
||||
if (!d->m_borderPainter) {
|
||||
if (!d->borderPainter) {
|
||||
return;
|
||||
}
|
||||
if (inactiveColor() == value) {
|
||||
return;
|
||||
}
|
||||
d->m_borderPainter->setInactiveColor(value);
|
||||
d->borderPainter->setInactiveColor(value);
|
||||
}
|
||||
|
||||
void QuickWindowBorder::itemChange(const ItemChange change, const ItemChangeData &value)
|
||||
|
|
|
@ -909,7 +909,7 @@ void FramelessWidgetsHelperPrivate::setSystemButton(QWidget *widget, const Syste
|
|||
data->closeButton = widget;
|
||||
break;
|
||||
case SystemButtonType::Unknown:
|
||||
Q_UNREACHABLE_RETURN(void(0));
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue