KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
qtcommon/Window.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 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
13#include "../qtcommon/Screen_p.h"
14#include "../qtcommon/Window_p.h"
15#include "../qtcommon/Platform.h"
16
17#include <QWindow>
18#include <QScreen>
19#include <QVariant>
20
21#include <QtGui/private/qhighdpiscaling_p.h>
22
23using namespace KDDockWidgets;
24using namespace KDDockWidgets::QtCommon;
25
26Window::Window(QWindow *window)
27 : m_window(window)
28{
29 Q_ASSERT(window);
30}
31
32Window::~Window()
33{
34}
35
36void Window::onScreenChanged(QObject *context, WindowScreenChangedCallback callback)
37{
38 // Window_qt can't have a "screenChanged" signal since it's a short-lived object which
39 // just wraps QWindow API. Instead, connects need to be done directly to QWindow
40 QWindow *window = m_window; // copy before "this" is deleted
41 context = context ? context : m_window;
42 QObject::connect(m_window, &QWindow::screenChanged, context, [context, window, callback] {
43 callback(context, Platform_qt::instance()->windowFromQWindow(window));
44 });
45}
46
47void Window::setWindowState(WindowState state)
48{
49 m_window->setWindowState(( Qt::WindowState )state);
50}
51
52WindowState Window::windowState() const
53{
54 return WindowState(m_window->windowState());
55}
56
57QRect Window::geometry() const
58{
59 return m_window->geometry();
60}
61
62void Window::setProperty(const char *name, const QVariant &value)
63{
64 Q_ASSERT(m_window);
65 m_window->setProperty(name, value);
66}
67
68static const char *const s_kddw_hasBeenMinimizedDirectlyFromRestore = "kddw_hasBeenMinimizedDirectlyFromRestore";
69void Window::setHasBeenMinimizedDirectlyFromRestore(bool has)
70{
72}
73
74bool Window::hasBeenMinimizedDirectlyFromRestore() const
75{
76 return property(s_kddw_hasBeenMinimizedDirectlyFromRestore).toBool();
77}
78
79bool Window::isVisible() const
80{
81 return m_window->isVisible();
82}
83
84WId Window::handle() const
85{
86 if (m_window->handle())
87 return m_window->winId();
88 return 0;
89}
90
91QWindow *Window::qtWindow() const
92{
93 return m_window;
94}
95
96bool Window::equals(std::shared_ptr<Core::Window> other) const
97{
98 auto otherQt = static_cast<Window *>(other.get());
99 return other && otherQt->m_window == m_window;
100}
101
102void Window::setFramePosition(QPoint targetPos)
103{
104 m_window->setFramePosition(targetPos);
105}
106
107QRect Window::frameGeometry() const
108{
109 return m_window->frameGeometry();
110}
111
112void Window::resize(int width, int height)
113{
114 m_window->resize(width, height);
115}
116
117bool Window::isActive() const
118{
119 return m_window->isActive();
120}
121
122QPoint Window::mapFromGlobal(QPoint globalPos) const
123{
124 return m_window->mapFromGlobal(globalPos);
125}
126
127QPoint Window::mapToGlobal(QPoint localPos) const
128{
129 return m_window->mapToGlobal(localPos);
130}
131
132Core::Screen::Ptr Window::screen() const
133{
134 return std::make_shared<Screen_qt>(m_window->screen());
135}
136
137void Window::destroy()
138{
139 delete m_window;
140}
141
142QVariant Window::property(const char *name) const
143{
144 return m_window->property(name);
145}
146
147QSize Window::minSize() const
148{
149 return m_window->minimumSize();
150}
151
152QSize Window::maxSize() const
153{
154 return m_window->maximumSize();
155}
156
157QPoint Window::fromNativePixels(QPoint nativePos) const
158{
159 return QHighDpi::fromNativePixels(nativePos, m_window.data());
160}
161
162void Window::startSystemMove()
163{
164 m_window->startSystemMove();
165}
166
167void Window::setGeometry(QRect geo)
168{
169 m_window->setGeometry(geo);
170}
171
172void Window::setVisible(bool is)
173{
174 m_window->setVisible(is);
175}
176
177bool Window::isFullScreen() const
178{
179 return m_window->windowStates() & Qt::WindowFullScreen;
180}
Class to abstract QAction, so code still works with QtQuick and Flutter.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
WindowState
static const char *const s_kddw_hasBeenMinimizedDirectlyFromRestore
void screenChanged(QScreen *screen)

© 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