QtBase  v6.3.1
main.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include <QtGui>
30 
31 constexpr qreal border = 20;
32 
33 class Window : public QRasterWindow
34 {
35 public:
36  explicit Window(QWindow *parent = nullptr) : QRasterWindow(parent)
37  {
38  resize(300, 200);
40  }
41 protected:
42  void resizeOrMove(const QPointF &p);
43  bool event(QEvent *event) override;
44  void paintEvent(QPaintEvent *event) override;
45 };
46 
48 {
49  Qt::Edges edges;
50  if (p.x() > width() - border)
51  edges |= Qt::RightEdge;
52  if (p.x() < border)
53  edges |= Qt::LeftEdge;
54  if (p.y() < border)
55  edges |= Qt::TopEdge;
56  if (p.y() > height() - border)
57  edges |= Qt::BottomEdge;
58 
59  if (edges != 0) {
60  qDebug() << "startSystemResize" << edges;
61  if (startSystemResize(edges))
62  qDebug() << " -> supported";
63  else
64  qDebug() << " -> not supported";
65  } else {
66  qDebug() << "startSystemMove";
67  if (startSystemMove())
68  qDebug() << " -> supported";
69  else
70  qDebug() << " -> not supported";
71  }
72 }
73 
75 {
76  switch (event->type()) {
78  qDebug() << "Mouse press";
79  resizeOrMove(static_cast<QMouseEvent *>(event)->position());
80  return true;
82  qDebug() << "Touch update";
83  resizeOrMove(static_cast<QTouchEvent *>(event)->points().first().position());
84  return true;
85  case QEvent::TouchBegin:
86  qDebug() << "Touch begin";
87  resizeOrMove(static_cast<QTouchEvent *>(event)->points().first().position());
88  return true;
89  case QEvent::TouchEnd:
90  qDebug() << "Touch end";
91  return true;
92  default:
94  }
95 }
96 
98 {
99  Q_UNUSED(event);
100  QPainter painter(this);
101  QRect fullRect(0, 0, width(), height());
102  QRect innerRect = fullRect.marginsRemoved(QMargins(border, border, border, border));
105  painter.drawText(QRectF(0, 0, width(), height()), Qt::AlignCenter, QStringLiteral("Click mouse or touch to move window\nDrag along the sides to resize."));
106 }
107 
108 int main(int argc, char **argv)
109 {
110  QGuiApplication app(argc, argv);
111  Window window;
112  window.show();
113  return app.exec();
114 }
static int exec()
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
@ MouseButtonPress
Definition: qcoreevent.h:73
@ TouchEnd
Definition: qcoreevent.h:256
@ TouchUpdate
Definition: qcoreevent.h:255
@ TouchBegin
Definition: qcoreevent.h:254
@ NightFade
Definition: qbrush.h:204
@ WarmFlame
Definition: qbrush.h:203
QGraphicsObject * parent
the parent of the item
The QGuiApplication class manages the GUI application's control flow and main settings.
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:52
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
bool event(QEvent *event) override
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
Definition: qevent.h:539
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
void drawText(const QPointF &p, const QString &s)
Definition: qpainter.cpp:5444
void fillRect(const QRectF &, const QBrush &)
Definition: qpainter.cpp:6644
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
QRasterWindow is a convenience class for using QPainter on a QWindow.
Definition: qrasterwindow.h:51
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
constexpr QRect marginsRemoved(const QMargins &margins) const noexcept
Definition: qrect.h:481
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:1020
void setMinimumSize(const QSize &)
Definition: qwidget.h:865
void resize(int w, int h)
Definition: qwidget.h:916
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
int width
the width of the window's geometry
Definition: qwindow.h:118
bool startSystemMove()
Start a system-specific move operation.
Definition: qwindow.cpp:1138
bool startSystemResize(Qt::Edges edges)
Start a system-specific resize operation.
Definition: qwindow.cpp:1100
int height
the height of the window's geometry
Definition: qwindow.h:119
[Window class definition]
Definition: window.h:64
bool event(QEvent *event) override
void resizeOrMove(const QPointF &p)
Definition: main.cpp:47
Window(QWindow *parent=nullptr)
Definition: main.cpp:36
void paintEvent(QPaintEvent *) override
void paintEvent(QPaintEvent *event) override
int main(int argc, char **argv)
Definition: main.cpp:1
@ AlignCenter
Definition: qnamespace.h:188
@ RightEdge
Definition: qnamespace.h:1297
@ TopEdge
Definition: qnamespace.h:1295
@ BottomEdge
Definition: qnamespace.h:1298
@ LeftEdge
Definition: qnamespace.h:1296
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define qDebug
[1]
Definition: qlogging.h:177
GLint GLsizei GLsizei height
GLint GLenum GLsizei GLsizei GLsizei GLint border
GLint GLsizei width
GLint first
struct _cl_event * event
Definition: qopenglext.h:2998
GLfixed GLfixed GLint GLint GLfixed points
Definition: qopenglext.h:5206
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
#define QStringLiteral(str)
Q_UNUSED(salary)
[21]
QApplication app(argc, argv)
[0]
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]