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