KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
qtquick/views/View.h
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#ifndef KD_VIEW_QTQUICK_H
13#define KD_VIEW_QTQUICK_H
14
15#pragma once
16
17#include "kddockwidgets/core/Controller.h"
18#include "kddockwidgets/qtcommon/View.h"
19
20#include <QDebug>
21#include <QEvent>
22#include <QResizeEvent>
23#include <QQuickItem>
24#include <QQuickWindow>
25#include <QQuickView>
26#include <QScreen>
27
28#include <memory>
29
30namespace KDDockWidgets::QtQuick {
31
32class MouseEventRedirector;
33
34inline QQuickItem *asQQuickItem(Core::View *view)
35{
36 if (!view)
37 return nullptr;
38
39 return qobject_cast<QQuickItem *>(QtCommon::View_qt::asQObject(view));
40}
41
42inline QQuickItem *asQQuickItem(Core::Controller *controller)
43{
44 if (!controller)
45 return nullptr;
46
47 return asQQuickItem(controller->view());
48}
49
50DOCKS_EXPORT QQmlContext *qmlContextFor(QQuickItem *);
51
52class DOCKS_EXPORT View : public QQuickItem, public QtCommon::View_qt
53{
54 Q_OBJECT
55 Q_PROPERTY(bool isFixedHeight READ isFixedHeight NOTIFY geometryUpdated)
56 Q_PROPERTY(bool isFixedWidth READ isFixedWidth NOTIFY geometryUpdated)
57public:
58 using Core::View::close;
59 using Core::View::height;
60 using Core::View::rect;
61 using Core::View::resize;
62 using Core::View::width;
63
64 explicit View(Core::Controller *controller, Core::ViewType type,
65 QQuickItem *parent = nullptr, Qt::WindowFlags windowFlags = {});
66
67 ~View() override = default;
68
69 QSize minSize() const override;
70 QSize maxSizeHint() const override;
71 QRect geometry() const override;
72 QRect normalGeometry() const override;
73 void setNormalGeometry(QRect geo);
74 void setGeometry(QRect) override;
75 void setMaximumSize(QSize sz) override;
76
77 bool isVisible() const override;
78 bool isExplicitlyHidden() const override;
79 void setVisible(bool is) override;
80
81 void move(int x, int y) override;
82 void setSize(int w, int h) override final;
83
84 void setWidth(int w) override;
85 void setHeight(int h) override;
86 void setFixedWidth(int w) override;
87 void setFixedHeight(int h) override;
88 void setFixedSize(Size);
89 void show() override;
90 void hide() override;
91 void updateGeometry();
92 void update() override;
93 void setParent(Core::View *parent) override;
94 void setParent(QQuickItem *parent);
95 static void raiseAndActivate(QQuickItem *);
96 void raiseAndActivate() override;
97 void activateWindow() override;
98 void raise() override;
99 static bool isRootView(const QQuickItem *);
100 bool isRootView() const override final;
101 QQuickView *quickView() const;
102 QPoint mapToGlobal(QPoint localPt) const override;
103 QPoint mapFromGlobal(QPoint globalPt) const override;
104 QPoint mapTo(Core::View *parent, QPoint pos) const override;
105 void setWindowOpacity(double v) override;
106
107 static bool close(QQuickItem *);
108 bool close() override;
109 void setFlag(Qt::WindowType f, bool on = true) override;
110 void enableAttribute(Qt::WidgetAttribute attr, bool enable = true) override;
111 bool hasAttribute(Qt::WidgetAttribute attr) const override;
112 Qt::WindowFlags flags() const override;
113
114 void setWindowTitle(const QString &title) override;
115 void setWindowIcon(const QIcon &icon) override;
116 bool isActiveWindow() const override;
117
118 Q_INVOKABLE void redirectMouseEvents(QQuickItem *from);
119 Q_INVOKABLE void showNormal() override;
120 Q_INVOKABLE void showMinimized() override;
121 Q_INVOKABLE void showMaximized() override;
122
123 bool isMinimized() const override;
124 bool isMaximized() const override;
125
126 std::shared_ptr<Core::Window> window() const override;
127 std::shared_ptr<Core::View> childViewAt(QPoint p) const override;
128 std::shared_ptr<Core::View> rootView() const override;
129 std::shared_ptr<Core::View> parentView() const override;
130
131 std::shared_ptr<Core::View> asWrapper() override;
132
133 void grabMouse() override;
134 void releaseMouse() override;
135 void releaseKeyboard() override;
136 void setFocus(Qt::FocusReason reason) override;
137 Qt::FocusPolicy focusPolicy() const override;
138 bool hasFocus() const override;
139 void setFocusPolicy(Qt::FocusPolicy) override;
140 QString viewName() const override;
141 void setMinimumSize(QSize sz) override;
142 void render(QPainter *) override;
143 void setCursor(Qt::CursorShape shape) override;
144 void setMouseTracking(bool enable) override;
145 QVector<std::shared_ptr<Core::View>> childViews() const override;
146 int zOrder() const override;
147 void setZOrder(int) override;
148 virtual QQuickItem *visualItem() const;
149
150 void onWindowStateChangeEvent(QWindowStateChangeEvent *);
151
152 bool isFixedWidth() const;
153 bool isFixedHeight() const;
154
156 static void makeItemFillParent(QQuickItem *item);
157
159 static QQuickItem *createItem(QQmlEngine *engine, const QString &filename, QQmlContext *context = nullptr);
160
163 static QQuickItem *createItem(const QString &filename, QQuickItem *parent, QQmlContext *ctx = nullptr);
164
165 static std::shared_ptr<Core::View> parentViewFor(const QQuickItem *);
166 static std::shared_ptr<Core::View> asQQuickWrapper(QQuickItem *item);
167
168Q_SIGNALS:
169 void geometryUpdated(); // similar to QLayout stuff, when size constraints change
170 void itemGeometryChanged(); // emitted when the geometry changes. QQuickItem::geometryChanged()
171 // isn't a signal, so prefixed item
172
173protected:
174 void QQUICKITEMgeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
175 void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override;
176 bool eventFilter(QObject *watched, QEvent *ev) override;
177 bool event(QEvent *) override;
178
180 virtual void onHoverEvent(QHoverEvent *, QPoint /*globalPos*/)
181 {
182 }
183
184private:
185 Q_DISABLE_COPY(View)
186 friend class MouseEventRedirector;
187 void updateNormalGeometry();
188 void sendVisibleChangeEvent();
189 void _setSize(QSize);
190 bool m_inSetParent = false;
191 Qt::WindowFlags m_windowFlags;
192 int m_widgetAttributes = 0; // Qt::WidgetAttribute
193 Qt::FocusPolicy m_focusPolicy = Qt::NoFocus;
194 bool m_mouseTrackingEnabled = false;
195 QRect m_normalGeometry;
196 Qt::WindowStates m_oldWindowState = Qt::WindowState::WindowNoState;
197 MouseEventRedirector *m_mouseEventRedirector = nullptr;
198};
199
200inline View *asView_qtquick(Core::View *view)
201{
202 if (!view)
203 return nullptr;
204 return static_cast<View *>(view);
205}
206
208{
209 if (!controller)
210 return nullptr;
211
212 return static_cast<View *>(controller->view());
213}
214
215inline qreal logicalDpiFactor(const QQuickItem *item)
216{
217#ifndef Q_OS_MACOS
218 if (QQuickWindow *window = item->window()) {
219 if (QScreen *s = window->screen()) {
220 return s->logicalDotsPerInch() / 96.0;
221 }
222 }
223#endif
224
225 // It's always 72 on mac
226 Q_UNUSED(item);
227 return 1;
228}
229
230}
231
232#endif
View * view() const
Returns the view associated with this controller, if any.
static QObject * asQObject(View *)
~View() override=default
DOCKS_EXPORT QQmlContext * qmlContextFor(QQuickItem *)
View * asView_qtquick(Core::View *view)
qreal logicalDpiFactor(const QQuickItem *item)
QQuickItem * asQQuickItem(Core::View *view)
Definition utils.h:161

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8