~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/lib/shared/connectionedit_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
//
 
30
//  W A R N I N G
 
31
//  -------------
 
32
//
 
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.
 
36
//
 
37
// We mean it.
 
38
//
 
39
 
 
40
 
 
41
#ifndef CONNECTIONEDIT_H
 
42
#define CONNECTIONEDIT_H
 
43
 
 
44
#include <QtCore/QMultiMap>
 
45
#include <QtCore/QList>
 
46
#include <QtCore/QPointer>
 
47
 
 
48
#include <QtGui/QWidget>
 
49
#include <QtGui/QPixmap>
 
50
#include <QtGui/QPolygonF>
 
51
 
 
52
#include "qtundo_p.h"
 
53
#include "shared_global_p.h"
 
54
 
 
55
class QDesignerFormWindowInterface;
 
56
class QtUndoStack;
 
57
class Connection;
 
58
class ConnectionEdit;
 
59
 
 
60
class QT_SHARED_EXPORT CETypes
 
61
{
 
62
public:
 
63
    typedef QList<Connection*> ConnectionList;
 
64
    typedef QMap<Connection*, Connection*> ConnectionSet;
 
65
    typedef QMap<QWidget*, QWidget*> WidgetSet;
 
66
 
 
67
    class EndPoint {
 
68
    public:
 
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); }
 
74
        Connection *con;
 
75
        Type type;
 
76
    };
 
77
    enum LineDir { UpDir = 0, DownDir, RightDir, LeftDir };
 
78
};
 
79
 
 
80
class QT_SHARED_EXPORT Connection : public CETypes
 
81
{
 
82
public:
 
83
    Connection(ConnectionEdit *edit);
 
84
    Connection(ConnectionEdit *edit, QWidget *source, QWidget *target);
 
85
    virtual ~Connection() {}
 
86
 
 
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); }
 
93
 
 
94
    bool isVisible() const;
 
95
    virtual void updateVisibility();
 
96
    void setVisible(bool b);
 
97
 
 
98
    virtual QRegion region() const;
 
99
    bool contains(const QPoint &pos) const;
 
100
    virtual void paint(QPainter *p) const;
 
101
 
 
102
    void update(bool update_widgets = true) const;
 
103
    void checkWidgets();
 
104
 
 
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; }
 
111
 
 
112
    ConnectionEdit *edit() const { return m_edit; }
 
113
 
 
114
    virtual void inserted() {}
 
115
    virtual void removed() {}
 
116
 
 
117
private:
 
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;
 
126
    bool m_visible;
 
127
 
 
128
    void setSource(QWidget *source, const QPoint &pos);
 
129
    void setTarget(QWidget *target, const QPoint &pos);
 
130
    void updateKneeList();
 
131
    void trimLine();
 
132
    void updatePixmap(EndPoint::Type type);
 
133
    LineDir labelDir(EndPoint::Type type) const;
 
134
    bool ground() const;
 
135
    QRect groundRect() const;
 
136
};
 
137
 
 
138
class QT_SHARED_EXPORT ConnectionEdit : public QWidget, public CETypes
 
139
{
 
140
    Q_OBJECT
 
141
public:
 
142
    ConnectionEdit(QWidget *parent, QDesignerFormWindowInterface *form);
 
143
 
 
144
    inline QWidget *background() const { return m_bg_widget; }
 
145
 
 
146
    void setSelected(Connection *con, bool sel);
 
147
    bool selected(const Connection *con) const;
 
148
    void selectNone();
 
149
 
 
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); }
 
153
 
 
154
    void deleteSelected();
 
155
 
 
156
    virtual void setSource(Connection *con, const QString &obj_name);
 
157
    virtual void setTarget(Connection *con, const QString &obj_name);
 
158
 
 
159
    QtUndoStack *undoStack() const { return m_undo_stack; }
 
160
 
 
161
    void clear();
 
162
 
 
163
signals:
 
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);
 
171
 
 
172
public slots:
 
173
    virtual void setBackground(QWidget *background);
 
174
    void updateBackground();
 
175
    void widgetRemoved(QWidget *w);
 
176
    void updateLines();
 
177
    void enableUpdateBackground(bool enable);
 
178
 
 
179
protected:
 
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);
 
187
 
 
188
    virtual Connection *createConnection(QWidget *source, QWidget *target);
 
189
    virtual void modifyConnection(Connection *con);
 
190
 
 
191
    virtual QWidget *widgetAt(const QPoint &pos) const;
 
192
    QRect widgetRect(QWidget *w) const;
 
193
    void addConnection(Connection *con);
 
194
 
 
195
    enum State { Editing, Connecting, Dragging };
 
196
    State state() const;
 
197
 
 
198
private:
 
199
    QWidget *m_bg_widget;
 
200
    QtUndoStack *m_undo_stack;
 
201
    QPixmap m_bg_pixmap;
 
202
    bool m_enable_update_background;
 
203
 
 
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();
 
211
 
 
212
    void findObjectsUnderMouse(const QPoint &pos);
 
213
    EndPoint m_end_point_under_mouse;
 
214
    QPointer<QWidget> m_widget_under_mouse;
 
215
 
 
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);
 
222
 
 
223
    Connection *connectionAt(const QPoint &pos) const;
 
224
    EndPoint endPointAt(const QPoint &pos) const;
 
225
    ConnectionSet m_sel_con_set;
 
226
 
 
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);
 
231
 
 
232
    QColor m_inactive_color, m_active_color;
 
233
 
 
234
private:
 
235
    friend class Connection;
 
236
    friend class AddConnectionCommand;
 
237
    friend class DeleteConnectionsCommand;
 
238
    friend class SetEndPointCommand;
 
239
};
 
240
 
 
241
class QT_SHARED_EXPORT CECommand : public QtCommand, public CETypes
 
242
{
 
243
    Q_OBJECT
 
244
public:
 
245
    CECommand(ConnectionEdit *edit)
 
246
        : m_edit(edit) { setCanMerge(false); }
 
247
    ConnectionEdit *edit() const { return m_edit; }
 
248
private:
 
249
    ConnectionEdit *m_edit;
 
250
};
 
251
 
 
252
class QT_SHARED_EXPORT AddConnectionCommand : public CECommand
 
253
{
 
254
    Q_OBJECT
 
255
public:
 
256
    AddConnectionCommand(ConnectionEdit *edit, Connection *con);
 
257
    virtual void redo();
 
258
    virtual void undo();
 
259
private:
 
260
    Connection *m_con;
 
261
};
 
262
 
 
263
class QT_SHARED_EXPORT DeleteConnectionsCommand : public CECommand
 
264
{
 
265
public:
 
266
    DeleteConnectionsCommand(ConnectionEdit *edit, const ConnectionList &con_list);
 
267
    virtual void redo();
 
268
    virtual void undo();
 
269
private:
 
270
    ConnectionList m_con_list;
 
271
};
 
272
 
 
273
 
 
274
#endif // CONNECTIONEDIT_H