source: trunk/tools/designer/src/lib/shared/zoomwidget_p.h@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 7.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt Designer of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists for the convenience
47// of Qt Designer. This header
48// file may change from version to version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#ifndef ZOOMWIDGET_H
54#define ZOOMWIDGET_H
55
56#include "shared_global_p.h"
57
58#include <QtGui/QGraphicsView>
59#include <QtGui/QGraphicsProxyWidget>
60#include <QtCore/QList>
61
62QT_BEGIN_NAMESPACE
63
64class QGraphicsScene;
65class QMenu;
66class QAction;
67class QActionGroup;
68
69namespace qdesigner_internal {
70
71// A checkable zoom menu action group. Operates in percent.
72
73class QDESIGNER_SHARED_EXPORT ZoomMenu : public QObject {
74 Q_OBJECT
75 Q_DISABLE_COPY(ZoomMenu)
76
77public:
78 ZoomMenu(QObject *parent = 0);
79 void addActions(QMenu *m);
80
81 int zoom() const;
82
83 // Return a list of available zoom values.
84 static QList<int> zoomValues();
85
86public slots:
87 void setZoom(int percent);
88
89signals:
90 void zoomChanged(int);
91
92private slots:
93 void slotZoomMenu(QAction *);
94
95private:
96 static int zoomOf(const QAction *a);
97
98 QActionGroup *m_menuActions;
99};
100
101/* Zoom view: A QGraphicsView with a zoom menu */
102
103class QDESIGNER_SHARED_EXPORT ZoomView : public QGraphicsView
104{
105 Q_PROPERTY(int zoom READ zoom WRITE setZoom DESIGNABLE true SCRIPTABLE true)
106 Q_PROPERTY(bool zoomContextMenuEnabled READ isZoomContextMenuEnabled WRITE setZoomContextMenuEnabled DESIGNABLE true SCRIPTABLE true)
107 Q_OBJECT
108 Q_DISABLE_COPY(ZoomView)
109public:
110 ZoomView(QWidget *parent = 0);
111
112 /* Zoom in percent (for easily implementing menus) and qreal zoomFactor
113 * in sync */
114 int zoom() const; // in percent
115 qreal zoomFactor() const;
116
117 // Zoom Menu on QGraphicsView.
118 bool isZoomContextMenuEnabled() const;
119 void setZoomContextMenuEnabled(bool e);
120
121 QGraphicsScene &scene() { return *m_scene; }
122 const QGraphicsScene &scene() const { return *m_scene; }
123
124 // Helpers for menu
125 ZoomMenu *zoomMenu();
126
127 QPoint scrollPosition() const;
128 void setScrollPosition(const QPoint& pos);
129 void scrollToOrigin();
130
131public slots:
132 void setZoom(int percent);
133 void showContextMenu(const QPoint &globalPos);
134
135protected:
136 void contextMenuEvent(QContextMenuEvent *event);
137
138 // Overwrite for implementing additional behaviour when doing setZoom();
139 virtual void applyZoom();
140
141private:
142 QGraphicsScene *m_scene;
143 int m_zoom;
144 qreal m_zoomFactor;
145
146 bool m_zoomContextMenuEnabled;
147 bool m_resizeBlocked;
148 ZoomMenu *m_zoomMenu;
149};
150
151/* The proxy widget used in ZoomWidget. It refuses to move away from 0,0,
152 * This behaviour is required for Windows only. */
153
154class QDESIGNER_SHARED_EXPORT ZoomProxyWidget : public QGraphicsProxyWidget {
155 Q_DISABLE_COPY(ZoomProxyWidget)
156public:
157 explicit ZoomProxyWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
158
159protected:
160 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
161};
162
163/* Zoom widget: A QGraphicsView-based container for a widget that allows for
164 * zooming it. Communicates changes in size in the following ways:
165 * 1) Embedded widget wants to resize: Listen for its resize in event filter
166 * and resize
167 * 2) Zoom is changed: resize to fully display the embedded widget
168 * 3) Outer widget changes (by manually resizing the window:
169 * Pass the scaled change on to the embedded widget.
170 * Provides helper functions for a zoom context menu on the widget. */
171
172class QDESIGNER_SHARED_EXPORT ZoomWidget : public ZoomView
173{
174 Q_PROPERTY(bool widgetZoomContextMenuEnabled READ isWidgetZoomContextMenuEnabled WRITE setWidgetZoomContextMenuEnabled DESIGNABLE true SCRIPTABLE true)
175 Q_PROPERTY(bool itemAcceptDrops READ itemAcceptDrops WRITE setItemAcceptDrops DESIGNABLE true SCRIPTABLE true)
176 Q_OBJECT
177 Q_DISABLE_COPY(ZoomWidget)
178
179public:
180 ZoomWidget(QWidget *parent = 0);
181 void setWidget(QWidget *w, Qt::WindowFlags wFlags = 0);
182
183 const QGraphicsProxyWidget *proxy() const { return m_proxy; }
184 QGraphicsProxyWidget *proxy() { return m_proxy; }
185
186 /* Enable the zoom Menu on the Widget (as opposed ZoomView's menu which
187 * is on the canvas). */
188 bool isWidgetZoomContextMenuEnabled() const;
189 void setWidgetZoomContextMenuEnabled(bool e);
190
191 void setItemAcceptDrops(bool);
192 bool itemAcceptDrops() const;
193
194 virtual QSize minimumSizeHint() const;
195 virtual QSize sizeHint() const;
196
197 bool zoomedEventFilter(QObject *watched, QEvent *event);
198
199public slots:
200 // debug state
201 void dump() const;
202
203protected:
204 void resizeEvent(QResizeEvent * event);
205
206 // Overwritten from ZoomView
207 virtual void applyZoom();
208 // Overwrite to actually perform a resize. This is required if we are in a layout. Default does resize().
209 virtual void doResize(const QSize &s);
210
211private:
212 // Factory function for QGraphicsProxyWidgets which can be overwritten. Default creates a ZoomProxyWidget
213 virtual QGraphicsProxyWidget *createProxyWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) const;
214 QSize widgetSizeToViewSize(const QSize &s, bool *ptrToValid = 0) const;
215
216 void resizeToWidgetSize();
217 QSize viewPortMargin() const;
218 QSize widgetSize() const;
219 QSizeF widgetDecorationSizeF() const;
220
221 QGraphicsProxyWidget *m_proxy;
222 bool m_viewResizeBlocked;
223 bool m_widgetResizeBlocked;
224 bool m_widgetZoomContextMenuEnabled;
225};
226
227} // namespace qdesigner_internal
228
229QT_END_NAMESPACE
230
231#endif
Note: See TracBrowser for help on using the repository browser.