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
zoomwidget_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
5//
6// W A R N I N G
7// -------------
8//
9// This file is not part of the Qt API. It exists for the convenience
10// of Qt Designer. This header
11// file may change from version to version without notice, or even be removed.
12//
13// We mean it.
14//
15
16#ifndef ZOOMWIDGET_H
17#define ZOOMWIDGET_H
18
20
21#include <QtWidgets/qgraphicsview.h>
22#include <QtWidgets/qgraphicsproxywidget.h>
23
24#include <QtCore/qlist.h>
25
27
28class QGraphicsScene;
29class QMenu;
30class QAction;
31class QActionGroup;
32
33namespace qdesigner_internal {
34
35// A checkable zoom menu action group. Operates in percent.
36
40
41public:
42 ZoomMenu(QObject *parent = nullptr);
43 void addActions(QMenu *m);
44
45 int zoom() const;
46
47 // Return a list of available zoom values.
48 static QList<int> zoomValues();
49
50public slots:
51 void setZoom(int percent);
52
54 void zoomChanged(int);
55
56private slots:
57 void slotZoomMenu(QAction *);
58
59private:
60 static int zoomOf(const QAction *a);
61
63};
64
65/* Zoom view: A QGraphicsView with a zoom menu */
66
68{
73public:
74 ZoomView(QWidget *parent = nullptr);
75
76 /* Zoom in percent (for easily implementing menus) and qreal zoomFactor
77 * in sync */
78 int zoom() const; // in percent
79 qreal zoomFactor() const;
80
81 // Zoom Menu on QGraphicsView.
82 bool isZoomContextMenuEnabled() const;
84
86 const QGraphicsScene &scene() const { return *m_scene; }
87
88 // Helpers for menu
90
91 QPoint scrollPosition() const;
92 void setScrollPosition(const QPoint& pos);
93 void scrollToOrigin();
94
95public slots:
96 void setZoom(int percent);
97 void showContextMenu(const QPoint &globalPos);
98
99protected:
101
102 // Overwrite for implementing additional behaviour when doing setZoom();
103 virtual void applyZoom();
104
105private:
107 int m_zoom = 100;
109
110 bool m_zoomContextMenuEnabled = false;
111 ZoomMenu *m_zoomMenu = nullptr;
112};
113
114/* The proxy widget used in ZoomWidget. It refuses to move away from 0,0,
115 * This behaviour is required for Windows only. */
116
125
126/* Zoom widget: A QGraphicsView-based container for a widget that allows for
127 * zooming it. Communicates changes in size in the following ways:
128 * 1) Embedded widget wants to resize: Listen for its resize in event filter
129 * and resize
130 * 2) Zoom is changed: resize to fully display the embedded widget
131 * 3) Outer widget changes (by manually resizing the window:
132 * Pass the scaled change on to the embedded widget.
133 * Provides helper functions for a zoom context menu on the widget. */
134
136{
141
142public:
143 ZoomWidget(QWidget *parent = nullptr);
144 void setWidget(QWidget *w, Qt::WindowFlags wFlags = {});
145
146 const QGraphicsProxyWidget *proxy() const { return m_proxy; }
148
149 /* Enable the zoom Menu on the Widget (as opposed ZoomView's menu which
150 * is on the canvas). */
153
154 void setItemAcceptDrops(bool);
155 bool itemAcceptDrops() const;
156
158 QSize sizeHint() const override;
159
161
162public slots:
163 // debug state
164 void dump() const;
165
166protected:
168
169 // Overwritten from ZoomView
170 void applyZoom() override;
171 // Overwrite to actually perform a resize. This is required if we are in a layout. Default does resize().
172 virtual void doResize(const QSize &s);
173
174private:
175 // Factory function for QGraphicsProxyWidgets which can be overwritten. Default creates a ZoomProxyWidget
177 Qt::WindowFlags wFlags = {}) const;
178 QSize widgetSizeToViewSize(const QSize &s, bool *ptrToValid = nullptr) const;
179
180 void resizeToWidgetSize();
181 QSize viewPortMargin() const;
182 QSize widgetSize() const;
184
185 QGraphicsProxyWidget *m_proxy = nullptr;
186 bool m_viewResizeBlocked = false;
187 bool m_widgetResizeBlocked = false;
189};
190
191} // namespace qdesigner_internal
192
193QT_END_NAMESPACE
194
195#endif
friend class QPainter
friend class QWidget
Definition qpainter.h:432
FormEditorOptionsPage(QDesignerFormEditorInterface *core)
void fromSettings(const QDesignerSharedSettings &s)
void toSettings(QDesignerSharedSettings &s) const
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
#define QDESIGNER_SHARED_EXPORT