Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qhaikuwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qhaikuwindow.h"
5
6#include "private/qguiapplication_p.h"
7
8#include <QCoreApplication>
9#include <QThread>
10#include <QWindow>
11#include <qpa/qwindowsysteminterface.h>
12
13#include <Rect.h>
14#include <Window.h>
15
17
18enum {
21};
22
24 : QObject(parent)
25 , BWindow(BRect(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1),
26 window->title().toUtf8(), B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0)
27 , m_qtCalledZoom(false)
28 , m_zoomInProgress(false)
29{
30}
31
33{
34 Q_EMIT moved(QPoint(pos.x, pos.y));
35}
36
38{
39 Q_EMIT resized(QSize(static_cast<int>(width), static_cast<int>(height)), m_zoomInProgress);
40
41 m_zoomInProgress = false;
42}
43
45{
46 Q_EMIT windowActivated(activated);
47}
48
49void HaikuWindowProxy::Minimize(bool minimize)
50{
51 BWindow::Minimize(minimize);
52
53 Q_EMIT minimized(minimize);
54}
55
56void HaikuWindowProxy::Zoom(BPoint pos, float width, float height)
57{
58 m_zoomInProgress = true;
59 BWindow::Zoom(pos, width, height);
60
61 // Only notify about Zoom invocations from the Haiku windowing system
62 if (!m_qtCalledZoom)
63 Q_EMIT zoomed();
64}
65
67{
69
70 // Return false to prevent Haiku windowing system to clean up
71 // the BWindow and BView instances. We will do that ourself when
72 // Qt invokes the dtor of QHaikuWindow
73 return false;
74}
75
77{
78 m_qtCalledZoom = true;
79 BWindow::Zoom();
80 m_qtCalledZoom = false;
81}
82
85 , m_window(nullptr)
86 , m_windowState(Qt::WindowNoState)
87{
89
90 HaikuWindowProxy *haikuWindow = new HaikuWindowProxy(window, rect, nullptr);
91 connect(haikuWindow, SIGNAL(moved(QPoint)), SLOT(haikuWindowMoved(QPoint)));
92 connect(haikuWindow, SIGNAL(resized(QSize,bool)), SLOT(haikuWindowResized(QSize,bool)));
93 connect(haikuWindow, SIGNAL(windowActivated(bool)), SLOT(haikuWindowActivated(bool)));
94 connect(haikuWindow, SIGNAL(minimized(bool)), SLOT(haikuWindowMinimized(bool)));
95 connect(haikuWindow, SIGNAL(zoomed()), SLOT(haikuWindowZoomed()));
96 connect(haikuWindow, SIGNAL(quitRequested()), SLOT(haikuWindowQuitRequested()), Qt::BlockingQueuedConnection);
97
98 m_window = haikuWindow;
99
100 if (Q_UNLIKELY(!m_window))
101 qFatal("QHaikuWindow: failed to create window");
102
105}
106
108{
109 m_window->LockLooper();
110 m_window->Quit();
111
112 m_window = nullptr;
113}
114
116{
118
119 m_window->MoveTo(rect.x(), rect.y());
120 m_window->ResizeTo(rect.width(), rect.height());
121}
122
124{
125 const BRect decoratorFrame = m_window->DecoratorFrame();
126 const BRect frame = m_window->Frame();
127
128 return QMargins(frame.left - decoratorFrame.left,
129 frame.top - decoratorFrame.top,
130 decoratorFrame.right - frame.right,
131 decoratorFrame.bottom - frame.bottom);
132}
133
134void QHaikuWindow::setVisible(bool visible)
135{
136 if (visible) {
137 m_window->Show();
138
139 window()->requestActivate();
140
142 } else {
143 m_window->Hide();
144 }
145}
146
148{
149 return !m_window->IsHidden();
150}
151
153{
154 return m_window->IsActive();
155}
156
158{
159 return (WId)static_cast<BWindow*>(m_window);
160}
161
163{
164 return m_window;
165}
166
168{
169 m_window->Activate(true);
170}
171
173{
174 if (m_windowState == state)
175 return;
176
177 const Qt::WindowStates oldState = m_windowState;
178
179 m_windowState = state;
180
181 if (m_windowState & Qt::WindowMinimized)
182 m_window->Minimize(true);
183 else if (m_windowState & Qt::WindowMaximized)
185 else if (oldState & Qt::WindowMinimized)
186 m_window->Minimize(false); // undo minimize
187 else if (oldState & Qt::WindowMaximized)
188 m_window->zoomByQt(); // undo zoom
189}
190
192{
193 const Qt::WindowType type = static_cast<Qt::WindowType>(static_cast<int>(flags & Qt::WindowType_Mask));
194
195 const bool isPopup = (type == Qt::Popup);
196 const bool isSplashScreen = (type == Qt::SplashScreen);
197 const bool isDialog = ((type == Qt::Dialog) || (type == Qt::Sheet) || (type == Qt::MSWindowsFixedSizeDialogHint));
198 const bool isTool = ((type == Qt::Tool) || (type == Qt::Drawer));
199 const bool isToolTip = (type == Qt::ToolTip);
200
201 window_look wlook = B_TITLED_WINDOW_LOOK;
202 window_feel wfeel = B_NORMAL_WINDOW_FEEL;
203 uint32 wflag = (B_NO_WORKSPACE_ACTIVATION | B_NOT_ANCHORED_ON_ACTIVATE);
204
205 if (isTool) {
206 wlook = B_FLOATING_WINDOW_LOOK;
207 wflag |= B_WILL_ACCEPT_FIRST_CLICK;
208 }
209
210 if (isSplashScreen) {
211 wlook = B_NO_BORDER_WINDOW_LOOK;
212 }
213
214 if (isPopup) {
215 wlook = B_NO_BORDER_WINDOW_LOOK;
216 wflag |= (B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FRONT | B_AVOID_FOCUS);
218 }
219
220 if (isDialog) {
221 if (window()->modality() == Qt::WindowModal)
222 wfeel = B_MODAL_SUBSET_WINDOW_FEEL;
223 else if (window()->modality() == Qt::ApplicationModal)
224 wfeel = B_MODAL_APP_WINDOW_FEEL;
225 }
226
227 if (isToolTip) {
228 wlook = B_NO_BORDER_WINDOW_LOOK;
229 wflag |= (B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FOCUS);
231 }
232
234 wlook = B_NO_BORDER_WINDOW_LOOK;
235
237 wflag |= (B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
238
241 wflag |= B_NOT_MINIMIZABLE;
243 wflag |= B_NOT_ZOOMABLE;
245 wflag |= B_NOT_CLOSABLE;
246 }
247
249 wfeel = B_FLOATING_ALL_WINDOW_FEEL;
250
251 m_window->SetLook(wlook);
252 m_window->SetFeel(wfeel);
253 m_window->SetFlags(wflag);
254}
255
260
262{
263 m_window->SetSizeLimits(window()->minimumSize().width(),
264 window()->maximumSize().width(),
265 window()->minimumSize().height(),
266 window()->maximumSize().height());
267
268 m_window->SetZoomLimits(window()->maximumSize().width(),
269 window()->maximumSize().height());
270}
271
272void QHaikuWindow::haikuWindowMoved(const QPoint &pos)
273{
274 const QRect newGeometry(pos, geometry().size());
275
277 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), newGeometry.size()));
278}
279
280void QHaikuWindow::haikuWindowResized(const QSize &size, bool zoomInProgress)
281{
282 const QRect newGeometry(geometry().topLeft(), size);
283
285 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), newGeometry.size()));
286
287 if ((m_windowState == Qt::WindowMaximized) && !zoomInProgress) {
288 // the user has resized the window while maximized -> reset maximized flag
289 m_windowState = Qt::WindowNoState;
290
292 }
293}
294
295void QHaikuWindow::haikuWindowActivated(bool activated)
296{
298}
299
300void QHaikuWindow::haikuWindowMinimized(bool minimize)
301{
302 m_windowState = (minimize ? Qt::WindowMinimized : Qt::WindowNoState);
303
305}
306
307void QHaikuWindow::haikuWindowZoomed()
308{
309 m_windowState = (m_windowState == Qt::WindowMaximized ? Qt::WindowNoState : Qt::WindowMaximized);
310
312}
313
314void QHaikuWindow::haikuWindowQuitRequested()
315{
317}
318
319void QHaikuWindow::haikuMouseEvent(const QPoint &localPosition, const QPoint &globalPosition, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
320{
321 QWindowSystemInterface::handleMouseEvent(window(), localPosition, globalPosition,
322 buttons, modifiers, source);
323}
324
325void QHaikuWindow::haikuWheelEvent(const QPoint &localPosition, const QPoint &globalPosition, int delta, Qt::Orientation orientation, Qt::KeyboardModifiers modifiers)
326{
327 QWindowSystemInterface::handleWheelEvent(window(), localPosition, globalPosition, delta, orientation, modifiers);
328}
329
330void QHaikuWindow::haikuKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text)
331{
333}
334
335void QHaikuWindow::haikuEnteredView()
336{
338}
339
340void QHaikuWindow::haikuExitedView()
341{
343}
344
345void QHaikuWindow::haikuDrawRequest(const QRect &rect)
346{
348}
349
void minimized(bool minimize)
void windowActivated(bool activated)
bool QuitRequested() override
void Zoom(BPoint pos, float width, float height) override
void Minimize(bool minimize) override
void resized(const QSize &size, bool zoomInProgress)
void FrameMoved(BPoint pos) override
void WindowActivated(bool activated) override
void FrameResized(float width, float height) override
HaikuWindowProxy(QWindow *window, const QRect &rect, QObject *parent=nullptr)
void moved(const QPoint &pos)
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
bool isExposed() const override
Returns if this window is exposed in the windowing system.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
BWindow * nativeHandle() const
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
virtual ~QHaikuWindow()
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
HaikuWindowProxy * m_window
bool isActive() const override
Returns true if the window should appear active from a style perspective.
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
QHaikuWindow(QWindow *window)
QMargins frameMargins() const override
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
\inmodule QtCore
Definition qmargins.h:24
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPlatformWindow class provides an abstraction for top-level windows.
QWindow * window() const
Returns the window which belongs to the QPlatformWindow.
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or resized using the QWindow API.
virtual QRect geometry() const
Returns the current geometry of a window.
static QRect initialGeometry(const QWindow *w, const QRect &initialGeometry, int defaultWidth, int defaultHeight, const QScreen **resultingScreenReturn=nullptr)
Helper function to get initial geometry on windowing systems which do not do smart positioning and al...
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toLocal8Bit() const &
Definition qstring.h:638
static void handleLeaveEvent(QWindow *window)
static void handleFocusWindowChanged(QWindow *window, Qt::FocusReason r=Qt::OtherFocusReason)
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static bool handleCloseEvent(QWindow *window)
static void handleGeometryChange(QWindow *window, const QRect &newRect)
static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
static bool handleExposeEvent(QWindow *window, const QRegion &region)
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState=-1)
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
Qt::WindowModality modality
the modality of the window
Definition qwindow.h:78
EGLImageKHR int int EGLuint64KHR * modifiers
QString text
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ WindowNoState
Definition qnamespace.h:252
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ WindowModal
@ ApplicationModal
Orientation
Definition qnamespace.h:98
MouseEventSource
@ BlockingQueuedConnection
WindowType
Definition qnamespace.h:205
@ CustomizeWindowHint
Definition qnamespace.h:239
@ FramelessWindowHint
Definition qnamespace.h:225
@ ToolTip
Definition qnamespace.h:213
@ MSWindowsFixedSizeDialogHint
Definition qnamespace.h:221
@ Drawer
Definition qnamespace.h:210
@ Popup
Definition qnamespace.h:211
@ WindowType_Mask
Definition qnamespace.h:220
@ SplashScreen
Definition qnamespace.h:214
@ WindowStaysOnTopHint
Definition qnamespace.h:233
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ WindowMinimizeButtonHint
Definition qnamespace.h:228
@ Dialog
Definition qnamespace.h:208
@ Sheet
Definition qnamespace.h:209
@ Tool
Definition qnamespace.h:212
@ WindowCloseButtonHint
Definition qnamespace.h:241
#define Q_UNLIKELY(x)
@ DefaultWindowHeight
@ DefaultWindowWidth
#define qFatal
Definition qlogging.h:168
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLint GLint GLint GLint GLint x
[0]
GLuint64 key
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble right
GLint GLsizei width
GLenum type
GLint GLint bottom
GLbitfield flags
GLint y
GLsizei GLsizei GLchar * source
#define Q_EMIT
QObject::connect nullptr
QString title
[35]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QFrame frame
[0]