6#include <QtCore/qtimer.h>
7#include <QtCore/qsettings.h>
8#include <QtCore/qlibraryinfo.h>
10#include <QtGui/qwindow.h>
11#include <QtGui/qguiapplication.h>
12#include <QtQuick/qquickwindow.h>
13#include <QtQuick/qquickitem.h>
14#include <QtQml/qqmlcomponent.h>
16#include <private/qquickpixmapcache_p.h>
17#include <private/qquickview_p.h>
18#include <private/qhighdpiscaling_p.h>
47 m_supportsMultipleWindows = (platformName ==
QStringLiteral(
"windows")
73 qobject_cast<QQuickWindow*>(
obj) == m_currentWindow) {
82 return m_currentRootItem;
97 m_createdObjects.removeAll(
nullptr);
105 m_component.
reset(
nullptr);
108 const int numEngines = m_engines.
size();
109 if (numEngines > 1) {
111 "should load the component.").
arg(numEngines));
113 }
else if (numEngines == 0) {
120 engine->clearComponentCache();
143 if (onStatusChanged(m_component->
status()))
160 m_zoomFactor = newFactor;
164void QQmlPreviewHandler::doZoom()
166 if (!m_currentWindow)
170 "so it will be ignored.").
arg(m_zoomFactor));
174 bool resetZoom =
false;
175 if (m_zoomFactor < 0) {
180 m_currentWindow->
setGeometry(m_currentWindow->geometry());
183 m_currentWindow->destroy();
190 m_currentWindow->
show();
197 m_createdObjects.clear();
198 setCurrentWindow(
nullptr);
217void QQmlPreviewHandler::showObject(
QObject *
object)
220 setCurrentWindow(qobject_cast<QQuickWindow *>(
window));
222 if (
QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(otherWindow)) {
223 if (quickWindow == m_currentWindow)
225 quickWindow->setVisible(
false);
230 setCurrentWindow(
nullptr);
233 if (m_currentWindow !=
nullptr) {
235 "decide which one to use."));
238 setCurrentWindow(quickWindow);
240 window->setVisible(
false);
245 if (m_currentWindow ==
nullptr) {
247 m_createdObjects.append(m_currentWindow.
data());
250 for (
QQuickItem *oldItem : m_currentWindow->contentItem()->childItems())
251 oldItem->setParentItem(m_dummyItem.
data());
255 if (
QQuickView *
view = qobject_cast<QQuickView *>(m_currentWindow))
260 m_currentWindow->resize(
item->size().toSize());
262 m_currentRootItem =
item;
267 if (m_currentWindow) {
279 if (m_currentWindow) {
281 this, &QQmlPreviewHandler::beforeSynchronizing);
282 disconnect(m_currentWindow.
data(), &QQuickWindow::afterSynchronizing,
283 this, &QQmlPreviewHandler::afterSynchronizing);
285 this, &QQmlPreviewHandler::beforeRendering);
287 this, &QQmlPreviewHandler::frameSwapped);
289 m_rendering = FrameTime();
290 m_synchronizing = FrameTime();
295 if (m_currentWindow) {
298 connect(m_currentWindow.
data(), &QQuickWindow::afterSynchronizing,
308void QQmlPreviewHandler::beforeSynchronizing()
310 m_synchronizing.beginFrame();
313void QQmlPreviewHandler::afterSynchronizing()
316 if (m_rendering.elapsed >= 0)
317 m_rendering.endFrame();
318 m_synchronizing.recordFrame();
319 m_synchronizing.endFrame();
322void QQmlPreviewHandler::beforeRendering()
324 m_rendering.beginFrame();
327void QQmlPreviewHandler::frameSwapped()
329 m_rendering.recordFrame();
332void QQmlPreviewHandler::FrameTime::beginFrame()
337void QQmlPreviewHandler::FrameTime::recordFrame()
342void QQmlPreviewHandler::FrameTime::endFrame()
354void QQmlPreviewHandler::FrameTime::reset()
356 min = std::numeric_limits<quint16>::max();
362void QQmlPreviewHandler::fpsTimerHit()
364 const FpsInfo
info = {
365 m_synchronizing.number,
368 m_synchronizing.total,
379 m_synchronizing.reset();
382void QQmlPreviewHandler::tryCreateObject()
384 if (!m_supportsMultipleWindows)
387 m_createdObjects.append(
object);
393#include "moc_qqmlpreviewhandler.cpp"
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static void setQuitLockEnabled(bool enabled)
void setParentItem(QGraphicsItem *parent)
Sets this item's parent item to newParent.
static QWindowList allWindows()
Returns a list of all the windows in the application.
QString platformName
The name of the underlying platform plugin.
Collection of utility functions for UI scaling.
static void updateHighDpiScaling()
qsizetype size() const noexcept
bool removeOne(const AT &t)
void append(parameter_type t)
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
The QQmlComponent class encapsulates a QML component definition.
Status status
\qmlproperty enumeration Component::status
bool isReady() const
Returns true if status() == QQmlComponent::Ready.
Q_INVOKABLE QString errorString() const
\qmlmethod string Component::errorString()
virtual QObject * create(QQmlContext *context=nullptr)
Create an object instance from this component, within the specified context.
void statusChanged(QQmlComponent::Status)
Emitted whenever the component's status changes.
The QQmlEngine class provides an environment for instantiating QML components.
void zoom(qreal newFactor)
QQuickItem * currentRootItem()
bool eventFilter(QObject *obj, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
void fps(const FpsInfo &info)
void removeEngine(QQmlEngine *engine)
void error(const QString &message)
void addEngine(QQmlEngine *engine)
void loadUrl(const QUrl &url)
QQmlPreviewHandler(QObject *parent=nullptr)
void loadWindowPositionSettings(const QUrl &url)
void takePosition(QWindow *window, InitializeState state=PositionInitialized)
void initLastSavedWindowPosition(QWindow *window)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
static QQuickViewPrivate * get(QQuickView *view)
bool setRootObject(QObject *)
The QQuickView class provides a window for displaying a Qt Quick user interface.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
void frameSwapped()
This signal is emitted when a frame has been queued for presenting.
void beforeSynchronizing()
This signal is emitted before the scene graph is synchronized with the QML state.
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
void beforeRendering()
\qmlsignal QtQuick::Window::afterSynchronizing()
T * data() const noexcept
Returns the value of the pointer referenced by this object.
bool isNull() const noexcept
Returns true if this object refers to \nullptr.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
The QScreen class is used to query screen properties. \inmodule QtGui.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void setInterval(int msec)
bool singleShot
whether the timer is a single-shot timer
void stop()
Stops the timer.
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
void show()
Shows the window.
Qt::WindowFlags flags
the window flags of the window
void setGeometry(int posx, int posy, int w, int h)
Sets the geometry of the window, excluding its window frame, to a rectangle constructed from posx,...
void setVisible(bool visible)
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
constexpr const T & min(const T &a, const T &b)
@ WindowMaximizeButtonHint
@ WindowMinimizeButtonHint
bool qFuzzyIsNull(qfloat16 f) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
constexpr const T & qMax(const T &a, const T &b)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QQmlEngine * qmlEngine(const QObject *obj)
static void closeAllWindows()
Qt::WindowFlags fixFlags(Qt::WindowFlags flags)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static double elapsed(qint64 after, qint64 before)
QWindow * qobject_cast< QWindow * >(QObject *o)
QFileInfo info(fileName)
[8]
QUrl url("example.com")
[constructor-url-reference]
myObject disconnect()
[26]
Q_NODISCARD_CTOR QuitLockDisabler()
const bool quitLockEnabled
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent