12#include "FloatingWindowQuick_p.h"
17#include "TitleBarQuick_p.h"
19#include "../Logging_p.h"
20#include "../Utils_p.h"
21#include "../DropArea_p.h"
22#include "../WidgetResizeHandler_p.h"
31class QuickView :
public QQuickView
35 explicit QuickView(QQmlEngine *qmlEngine, FloatingWindow *floatingWindow)
36 : QQuickView(qmlEngine, nullptr)
37 , m_floatingWindow(floatingWindow)
44 connect(m_floatingWindow, &QQuickItem::widthChanged,
this, &QuickView::onRootItemWidthChanged);
45 connect(m_floatingWindow, &QQuickItem::heightChanged,
this, &QuickView::onRootItemHeightChanged);
50 bool event(
QEvent *ev)
override
61 qApp->sendEvent(m_floatingWindow, ev);
65 return QQuickView::event(ev);
68 void onRootItemWidthChanged()
70 setWidth(
int(m_floatingWindow->width()));
73 void onRootItemHeightChanged()
75 setHeight(
int(m_floatingWindow->height()));
80 resize(m_floatingWindow->size());
83 void updateRootItemSize()
85 m_floatingWindow->setSize(size());
89 bool nativeEvent(
const QByteArray &eventType,
void *message, Qt5Qt6Compat::qintptr *result)
override
92 if (!m_floatingWindow->beingDeleted() && WidgetResizeHandler::handleWindowsNativeEvent(m_floatingWindow, eventType, message, result))
99 FloatingWindow *
const m_floatingWindow;
102QuickView::~QuickView() =
default;
107FloatingWindowQuick::FloatingWindowQuick(
MainWindowBase *parent, FloatingWindowFlags flags)
108 : FloatingWindow(
QRect(), parent, flags)
109 , m_quickWindow(new QuickView(
Config::self().qmlEngine(), this))
114FloatingWindowQuick::FloatingWindowQuick(Frame *frame,
QRect suggestedGeometry,
MainWindowBase *parent)
115 : FloatingWindow(frame,
QRect(), parent)
116 , m_quickWindow(new QuickView(
Config::self().qmlEngine(), this))
120 setGeometry(suggestedGeometry);
123FloatingWindowQuick::~FloatingWindowQuick()
128 m_dropArea->setWindowIsBeingDestroyed(
true);
130 QWidgetAdapter::setParent(
nullptr);
131 if (qobject_cast<QQuickView *>(m_quickWindow))
132 delete m_quickWindow;
135QSize FloatingWindowQuick::minimumSize()
const
139 const int margins = contentsMargins();
140 return multiSplitter()->minimumSize() +
QSize(0, titleBarHeight()) +
QSize(margins * 2, margins * 2);
143void FloatingWindowQuick::setGeometry(
QRect geo)
148 parentItem()->setSize(geo.
size());
149 m_quickWindow->setGeometry(geo);
152int FloatingWindowQuick::contentsMargins()
const
154 return m_visualItem->property(
"margins").toInt();
157int FloatingWindowQuick::titleBarHeight()
const
159 return m_visualItem->property(
"titleBarHeight").toInt();
162QWindow *FloatingWindowQuick::candidateParentWindow()
const
164 if (
auto mainWindow = qobject_cast<MainWindowBase *>(
QObject::parent())) {
165 return mainWindow->QQuickItem::window();
171void FloatingWindowQuick::init()
173 connect(
this, &QQuickItem::visibleChanged,
this, [
this] {
174 if (!isVisible() && !beingDeleted()) {
175 scheduleDeleteLater();
185 if (
QWindow *transientParent = candidateParentWindow()) {
186 m_quickWindow->setTransientParent(candidateParentWindow());
189 m_quickWindow->QObject::setParent(transientParent);
190 m_quickWindow->
setObjectName(QStringLiteral(
"Floating QWindow with parent"));
192 m_quickWindow->setObjectName(QStringLiteral(
"Floating QWindow"));
195 QWidgetAdapter::setParent(m_quickWindow->contentItem());
196 WidgetResizeHandler::setupWindow(m_quickWindow);
197 m_quickWindow->installEventFilter(
this);
198 maybeCreateResizeHandler();
200 m_visualItem = createItem(m_quickWindow->engine(),
202 Q_ASSERT(m_visualItem);
205 setSize(size().expandedTo(minimumSize()));
207 m_visualItem->setParent(
this);
208 m_visualItem->setParentItem(
this);
210 m_quickWindow->setFlags(windowFlags());
212 updateTitleAndIcon();
214 m_quickWindow->show();
217#include "FloatingWindowQuick.moc"
Application-wide config to tune certain behaviours of the framework.
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
QEvent::Type type() const const
void setObjectName(const QString &name)
QObject * parent() const const
void setSize(const QSize &size)
QSize expandedTo(const QSize &otherSize) const const
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result)