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"
31 class 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;
102 QuickView::~QuickView() =
default;
108 : FloatingWindow(
QRect(), parent)
109 , m_quickWindow(new QuickView(
Config::self().qmlEngine(), this))
114 FloatingWindowQuick::FloatingWindowQuick(Frame *frame,
QRect suggestedGeometry,
MainWindowBase *parent)
115 : FloatingWindow(frame,
QRect(), parent)
116 , m_quickWindow(new QuickView(
Config::self().qmlEngine(), this))
120 setGeometry(suggestedGeometry);
123 FloatingWindowQuick::~FloatingWindowQuick()
128 m_dropArea->setWindowIsBeingDestroyed(
true);
130 QWidgetAdapter::setParent(
nullptr);
131 if (qobject_cast<QQuickView *>(m_quickWindow))
132 delete m_quickWindow;
135 QSize FloatingWindowQuick::minimumSize()
const
139 const int margins = contentsMargins();
140 return multiSplitter()->minimumSize() +
QSize(0, titleBarHeight()) +
QSize(margins * 2, margins * 2);
143 void FloatingWindowQuick::setGeometry(
QRect geo)
148 parentItem()->setSize(geo.
size());
149 m_quickWindow->setGeometry(geo);
152 int FloatingWindowQuick::contentsMargins()
const
154 return m_visualItem->property(
"margins").toInt();
157 int FloatingWindowQuick::titleBarHeight()
const
159 return m_visualItem->property(
"titleBarHeight").toInt();
162 QWindow *FloatingWindowQuick::candidateParentWindow()
const
164 if (
auto mainWindow = qobject_cast<MainWindowBase *>(
QObject::parent())) {
165 return mainWindow->QQuickItem::window();
171 void 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(),
201 Config::self().frameworkWidgetFactory()->floatingWindowFilename().toString());
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"