KDDockWidgets API Documentation 2.0
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
68bool Window::isVisible() const
69{
70 return m_window->isVisible();
71}
72
73WId Window::handle() const
74{
75 if (m_window->handle())
76 return m_window->winId();
77 return 0;
78}
79
80QWindow *Window::qtWindow() const
81{
82 return m_window;
83}
84
85bool Window::equals(std::shared_ptr<Core::Window> other) const
86{
87 auto otherQt = static_cast<Window *>(other.get());
88 return other && otherQt->m_window == m_window;
89}
90
91void Window::setFramePosition(QPoint targetPos)
92{
93 m_window->setFramePosition(targetPos);
94}
95
96QRect Window::frameGeometry() const
97{
98 return m_window->frameGeometry();
99}
100
101void Window::resize(int width, int height)
102{
103 m_window->resize(width, height);
104}
105
106bool Window::isActive() const
107{
108 return m_window->isActive();
109}
110
111QPoint Window::mapFromGlobal(QPoint globalPos) const
112{
113 return m_window->mapFromGlobal(globalPos);
114}
115
116QPoint Window::mapToGlobal(QPoint localPos) const
117{
118 return m_window->mapToGlobal(localPos);
119}
120
121Core::Screen::Ptr Window::screen() const
122{
123 return std::make_shared<Screen_qt>(m_window->screen());
124}
125
126void Window::destroy()
127{
128 delete m_window;
129}
130
131QVariant Window::property(const char *name) const
132{
133 return m_window->property(name);
134}
135
136QSize Window::minSize() const
137{
138 return m_window->minimumSize();
139}
140
141QSize Window::maxSize() const
142{
143 return m_window->maximumSize();
144}
145
146QPoint Window::fromNativePixels(QPoint nativePos) const
147{
148 return QHighDpi::fromNativePixels(nativePos, m_window.data());
149}
150
151void Window::startSystemMove()
152{
153 m_window->startSystemMove();
154}
155
156void Window::setGeometry(QRect geo)
157{
158 m_window->setGeometry(geo);
159}
160
161void Window::setVisible(bool is)
162{
163 m_window->setVisible(is);
164}
165
166bool Window::isFullScreen() const
167{
168 return m_window->windowStates() & Qt::WindowFullScreen;
169}
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
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