Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtGui/QCursor>
6#include <QtGui/QPainter>
7#include <QtGui/QPainterPath>
8#include <QtGui/QPalette>
9#include <QtGui/QLinearGradient>
10#include <QtGui/QPainterPath>
11
12#include <qpa/qwindowsysteminterface.h>
13
14#include <QtWaylandClient/private/qwaylanddecorationplugin_p.h>
15#include <QtWaylandClient/private/qwaylandabstractdecoration_p.h>
16#include <QtWaylandClient/private/qwaylandwindow_p.h>
17#include <QtWaylandClient/private/qwaylandshellsurface_p.h>
18
19QT_BEGIN_NAMESPACE
20
21namespace QtWaylandClient {
22
23#define BUTTON_SPACING 5
24#define BUTTON_WIDTH 18
25#define BUTTONS_RIGHT_MARGIN 8
26
34
63
64
65
73
75{
79}
80
82{
86}
87
89{
93}
94
96{
98 return QMargins();
99
100 return QMargins(3, 30, 3, 3);
101}
102
104{
105 bool active = window()->handle()->isActive();
108 QRect clips[] =
109 {
114 };
115
116 QRect top = clips[0];
117
122
125
126 // Title bar
129 for (int i = 0; i < 4; ++i) {
130 p.save();
133 p.restore();
134 }
135
136 // Window icon
138 if (!icon.isNull()) {
139 QRectF iconRect(0, 0, 22, 22);
141 margins().left() + BUTTON_SPACING, 4),
143 }
144
145 // Window title
147 if (!windowTitleText.isEmpty()) {
151 }
152
155 (icon.isNull() ? 0 : 22 + BUTTON_SPACING));
157
158 p.save();
162 int dx = (top.width() - size.width()) /2;
163 int dy = (top.height()- size.height()) /2;
164 QFont font = p.font();
165 font.setPixelSize(14);
166 p.setFont(font);
168 top.topLeft().y() + dy);
170 p.restore();
171 }
172
173 QRectF rect;
174
175 // Default pen
177 p.setPen(pen);
178
179 // Close button
180 p.save();
182 qreal crossSize = rect.height() / 2.3;
185 pen.setWidth(2);
186 p.setPen(pen);
189 p.restore();
190
191 // Maximize button
192 p.save();
194 rect = maximizeButtonRect().adjusted(4, 5, -4, -5);
195 if ((window()->windowStates() & Qt::WindowMaximized)) {
196 qreal inset = 2;
197 QRectF rect1 = rect.adjusted(inset, 0, 0, -inset);
198 QRectF rect2 = rect.adjusted(0, inset, -inset, 0);
200 p.setBrush(backgroundColor); // need to cover up some lines from the other rect
202 } else {
203 p.drawRect(rect);
204 p.drawLine(rect.left(), rect.top() + 1, rect.right(), rect.top() + 1);
205 }
206 p.restore();
207
208 // Minimize button
209 p.save();
211 rect = minimizeButtonRect().adjusted(5, 5, -5, -5);
212 pen.setWidth(2);
213 p.setPen(pen);
215 p.restore();
216}
217
219{
220 if (isLeftClicked(b)) {
221 m_clicking = btn;
222 return false;
223 } else if (isLeftReleased(b)) {
224 if (m_clicking == btn) {
226 return true;
227 } else {
229 }
230 }
231 return false;
232}
233
235
236{
238
239 // Figure out what area mouse is in
241 if (local.y() <= margins().top()) {
243 } else if (local.y() >= ss.height() - margins().bottom()) {
245 } else if (local.x() <= margins().left()) {
247 } else if (local.x() >= ss.width() - margins().right()) {
249 } else {
250#if QT_CONFIG(cursor)
252#endif
254 return false;
255 }
256
258 return true;
259}
260
283
285 const QPointF &local,
289{
290#if !QT_CONFIG(cursor)
291 Q_UNUSED(type);
292#endif
293
295 Q_UNUSED(mods);
296 if (local.y() <= margins().bottom()) {
297 if (local.x() <= margins().left()) {
298 //top left bit
299#if QT_CONFIG(cursor)
300 if (type == PointerType::Mouse)
302#endif
304 } else if (local.x() >= ss.width() - margins().right()) {
305 //top right bit
306#if QT_CONFIG(cursor)
307 if (type == PointerType::Mouse)
309#endif
311 } else {
312 //top resize bit
313#if QT_CONFIG(cursor)
314 if (type == PointerType::Mouse)
316#endif
318 }
319 } else if (local.x() <= margins().left()) {
321 } else if (local.x() >= ss.width() - margins().right()) {
323 } else if (isRightClicked(b)) {
325 } else if (closeButtonRect().contains(local)) {
328 } else if (maximizeButtonRect().contains(local)) {
331 } else if (minimizeButtonRect().contains(local)) {
334 } else {
335#if QT_CONFIG(cursor)
336 if (type == PointerType::Mouse)
338#endif
340 }
341}
342
344 const QPointF &local,
348{
349 Q_UNUSED(mods);
350#if !QT_CONFIG(cursor)
351 Q_UNUSED(type);
352#endif
353
355 if (local.x() <= margins().left()) {
356 //bottom left bit
357#if QT_CONFIG(cursor)
358 if (type == PointerType::Mouse)
360#endif
362 } else if (local.x() >= ss.width() - margins().right()) {
363 //bottom right bit
364#if QT_CONFIG(cursor)
365 if (type == PointerType::Mouse)
367#endif
369 } else {
370 //bottom bit
371#if QT_CONFIG(cursor)
372 if (type == PointerType::Mouse)
374#endif
376 }
377}
378
380 const QPointF &local,
384{
386 Q_UNUSED(mods);
387#if QT_CONFIG(cursor)
388 if (type == PointerType::Mouse)
390#else
391 Q_UNUSED(type);
392#endif
394}
395
397 const QPointF &local,
401{
403 Q_UNUSED(mods);
404#if QT_CONFIG(cursor)
405 if (type == PointerType::Mouse)
407#else
408 Q_UNUSED(type);
409#endif
411}
412
414{
415 Q_OBJECT
416 Q_PLUGIN_METADATA(IID QWaylandDecorationFactoryInterface_iid FILE "bradient.json")
417public:
419};
420
421QWaylandAbstractDecoration *QWaylandBradientDecorationPlugin::create(const QString& system, const QStringList& paramList)
422{
423 Q_UNUSED(paramList);
424 Q_UNUSED(system);
425 return new QWaylandBradientDecoration();
426}
427
428}
429
430QT_END_NAMESPACE
431
432#include "main.moc"
#define BUTTON_SPACING
Definition main.cpp:23
#define BUTTONS_RIGHT_MARGIN
Definition main.cpp:25
#define BUTTON_WIDTH
Definition main.cpp:24