1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
33
// This file is not part of the Qt API. It exists for the convenience
34
// of Qt Designer. This header
35
// file may change from version to version without notice, or even be removed.
41
#ifndef CONNECTIONEDIT_H
42
#define CONNECTIONEDIT_H
44
#include <QtCore/QMultiMap>
45
#include <QtCore/QList>
46
#include <QtCore/QPointer>
48
#include <QtGui/QWidget>
49
#include <QtGui/QPixmap>
50
#include <QtGui/QPolygonF>
53
#include "shared_global_p.h"
55
class QDesignerFormWindowInterface;
60
class QT_SHARED_EXPORT CETypes
63
typedef QList<Connection*> ConnectionList;
64
typedef QMap<Connection*, Connection*> ConnectionSet;
65
typedef QMap<QWidget*, QWidget*> WidgetSet;
69
enum Type { Source, Target };
70
EndPoint(Connection *_con = 0, Type _type = Source) : con(_con), type(_type) {}
71
bool isNull() const { return con == 0; }
72
bool operator == (const EndPoint &other) const { return con == other.con && type == other.type; }
73
bool operator != (const EndPoint &other) const { return !operator == (other); }
77
enum LineDir { UpDir = 0, DownDir, RightDir, LeftDir };
80
class QT_SHARED_EXPORT Connection : public CETypes
83
Connection(ConnectionEdit *edit);
84
Connection(ConnectionEdit *edit, QWidget *source, QWidget *target);
85
virtual ~Connection() {}
87
QWidget *widget(EndPoint::Type type) const
88
{ return type == EndPoint::Source ? m_source : m_target; }
89
QPoint endPointPos(EndPoint::Type type) const;
90
QRect endPointRect(EndPoint::Type) const;
91
void setEndPoint(EndPoint::Type type, QWidget *w, const QPoint &pos)
92
{ type == EndPoint::Source ? setSource(w, pos) : setTarget(w, pos); }
94
bool isVisible() const;
95
virtual void updateVisibility();
96
void setVisible(bool b);
98
virtual QRegion region() const;
99
bool contains(const QPoint &pos) const;
100
virtual void paint(QPainter *p) const;
102
void update(bool update_widgets = true) const;
105
QString label(EndPoint::Type type) const
106
{ return type == EndPoint::Source ? m_source_label : m_target_label; }
107
void setLabel(EndPoint::Type type, const QString &text);
108
QRect labelRect(EndPoint::Type type) const;
109
QPixmap labelPixmap(EndPoint::Type type) const
110
{ return type == EndPoint::Source ? m_source_label_pm : m_target_label_pm; }
112
ConnectionEdit *edit() const { return m_edit; }
114
virtual void inserted() {}
115
virtual void removed() {}
118
QPoint m_source_pos, m_target_pos;
119
QWidget *m_source, *m_target;
120
QList<QPoint> m_knee_list;
121
QPolygonF m_arrow_head;
122
ConnectionEdit *m_edit;
123
QString m_source_label, m_target_label;
124
QPixmap m_source_label_pm, m_target_label_pm;
125
QRect m_source_rect, m_target_rect;
128
void setSource(QWidget *source, const QPoint &pos);
129
void setTarget(QWidget *target, const QPoint &pos);
130
void updateKneeList();
132
void updatePixmap(EndPoint::Type type);
133
LineDir labelDir(EndPoint::Type type) const;
135
QRect groundRect() const;
138
class QT_SHARED_EXPORT ConnectionEdit : public QWidget, public CETypes
142
ConnectionEdit(QWidget *parent, QDesignerFormWindowInterface *form);
144
inline QWidget *background() const { return m_bg_widget; }
146
void setSelected(Connection *con, bool sel);
147
bool selected(const Connection *con) const;
150
int connectionCount() const { return m_con_list.size(); }
151
Connection *connection(int i) const { return m_con_list.at(i); }
152
int indexOfConnection(Connection *con) const { return m_con_list.indexOf(con); }
154
void deleteSelected();
156
virtual void setSource(Connection *con, const QString &obj_name);
157
virtual void setTarget(Connection *con, const QString &obj_name);
159
QtUndoStack *undoStack() const { return m_undo_stack; }
164
void aboutToAddConnection(int idx);
165
void connectionAdded(Connection *con);
166
void aboutToRemoveConnection(Connection *con);
167
void connectionRemoved(int idx);
168
void connectionSelected(Connection *con);
169
void widgetActivated(QWidget *wgt);
170
void connectionChanged(Connection *con);
173
virtual void setBackground(QWidget *background);
174
void updateBackground();
175
void widgetRemoved(QWidget *w);
177
void enableUpdateBackground(bool enable);
180
virtual void paintEvent(QPaintEvent *e);
181
virtual void mouseMoveEvent(QMouseEvent *e);
182
virtual void mousePressEvent(QMouseEvent *e);
183
virtual void mouseReleaseEvent(QMouseEvent *e);
184
virtual void keyPressEvent(QKeyEvent *e);
185
virtual void mouseDoubleClickEvent(QMouseEvent *e);
186
virtual void resizeEvent(QResizeEvent *e);
188
virtual Connection *createConnection(QWidget *source, QWidget *target);
189
virtual void modifyConnection(Connection *con);
191
virtual QWidget *widgetAt(const QPoint &pos) const;
192
QRect widgetRect(QWidget *w) const;
193
void addConnection(Connection *con);
195
enum State { Editing, Connecting, Dragging };
199
QWidget *m_bg_widget;
200
QtUndoStack *m_undo_stack;
202
bool m_enable_update_background;
204
Connection *m_tmp_con; // the connection we are currently editing
205
ConnectionList m_con_list;
206
bool m_start_connection_on_drag;
207
void startConnection(QWidget *source, const QPoint &pos);
208
void continueConnection(QWidget *target, const QPoint &pos);
209
void endConnection(QWidget *target, const QPoint &pos);
210
void abortConnection();
212
void findObjectsUnderMouse(const QPoint &pos);
213
EndPoint m_end_point_under_mouse;
214
QPointer<QWidget> m_widget_under_mouse;
216
EndPoint m_drag_end_point;
217
QPoint m_old_source_pos, m_old_target_pos;
218
void startDrag(const EndPoint &end_point, const QPoint &pos);
219
void continueDrag(const QPoint &pos);
220
void endDrag(const QPoint &pos);
221
void adjustHotSopt(const EndPoint &end_point, const QPoint &pos);
223
Connection *connectionAt(const QPoint &pos) const;
224
EndPoint endPointAt(const QPoint &pos) const;
225
ConnectionSet m_sel_con_set;
227
void paintConnection(QPainter *p, Connection *con,
228
WidgetSet *heavy_highlight_set,
229
WidgetSet *light_highlight_set) const;
230
void paintLabel(QPainter *p, EndPoint::Type type, Connection *con);
232
QColor m_inactive_color, m_active_color;
235
friend class Connection;
236
friend class AddConnectionCommand;
237
friend class DeleteConnectionsCommand;
238
friend class SetEndPointCommand;
241
class QT_SHARED_EXPORT CECommand : public QtCommand, public CETypes
245
CECommand(ConnectionEdit *edit)
246
: m_edit(edit) { setCanMerge(false); }
247
ConnectionEdit *edit() const { return m_edit; }
249
ConnectionEdit *m_edit;
252
class QT_SHARED_EXPORT AddConnectionCommand : public CECommand
256
AddConnectionCommand(ConnectionEdit *edit, Connection *con);
263
class QT_SHARED_EXPORT DeleteConnectionsCommand : public CECommand
266
DeleteConnectionsCommand(ConnectionEdit *edit, const ConnectionList &con_list);
270
ConnectionList m_con_list;
274
#endif // CONNECTIONEDIT_H