~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to kdevdesigner/designer/actiondnd.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
 
3
**
 
4
** This file is part of Qt Designer.
 
5
**
 
6
** This file may be distributed and/or modified under the terms of the
 
7
** GNU General Public License version 2 as published by the Free Software
 
8
** Foundation and appearing in the file LICENSE.GPL included in the
 
9
** packaging of this file.
 
10
**
 
11
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
 
12
** licenses may use this file in accordance with the Qt Commercial License
 
13
** Agreement provided with the Software.
 
14
**
 
15
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
16
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
17
**
 
18
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
19
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
20
**   information about Qt Commercial License Agreements.
 
21
**
 
22
** Contact info@trolltech.com if any conditions of this licensing are
 
23
** not clear to you.
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
#ifndef ACTIONDND_H
 
28
#define ACTIONDND_H
 
29
 
 
30
#include <qaction.h>
 
31
#include <qdragobject.h>
 
32
#include <qmap.h>
 
33
#include <qmenubar.h>
 
34
#include <qpixmap.h>
 
35
#include <qpopupmenu.h>
 
36
#include <qptrlist.h>
 
37
#include <qtoolbar.h>
 
38
#include <qguardedptr.h>
 
39
#include "../shared/widgetdatabase.h"
 
40
 
 
41
//class QDesignerPopupMenu;
 
42
class QDesignerIndicatorWidget;
 
43
class FormWindow;
 
44
class QPopupMenu;
 
45
 
 
46
class QDesignerIndicatorWidget : public QWidget
 
47
{
 
48
    Q_OBJECT
 
49
 
 
50
public:
 
51
    QDesignerIndicatorWidget( QWidget *p )
 
52
        : QWidget( p, "qt_dockwidget_internal" ) {
 
53
            setBackgroundColor( red );
 
54
    }
 
55
 
 
56
};
 
57
 
 
58
class ActionDrag : public QStoredDrag
 
59
{
 
60
    Q_OBJECT
 
61
 
 
62
public:
 
63
    ActionDrag(const QString &type, QAction *action, QWidget *source);
 
64
    ActionDrag(QAction *action, QWidget *source);
 
65
    ActionDrag(QActionGroup *group, QWidget *source);
 
66
 
 
67
    ~ActionDrag();
 
68
 
 
69
    static bool canDecode(QDropEvent *e);
 
70
 
 
71
    static QAction *action()
 
72
    {
 
73
        return the_action;
 
74
    }
 
75
 
 
76
private:
 
77
    static QAction *the_action;
 
78
};
 
79
 
 
80
class QDesignerActionGroup : public QActionGroup
 
81
{
 
82
    Q_OBJECT
 
83
 
 
84
public:
 
85
    QDesignerActionGroup( QObject *parent )
 
86
        : QActionGroup( ::qt_cast<QActionGroup*>(parent) ? parent : 0 ), wid( 0 ), idx( -1 ) { init(); }
 
87
 
 
88
    void init();
 
89
 
 
90
    QWidget *widget() const { return wid; }
 
91
    QWidget *widget( QAction *a ) const { return *widgets.find( a ); }
 
92
    int index() const { return idx; }
 
93
 
 
94
protected:
 
95
#if !defined(Q_NO_USING_KEYWORD)
 
96
    using QActionGroup::addedTo;
 
97
#endif
 
98
    void addedTo( QWidget *w, QWidget * ) {
 
99
        wid = w;
 
100
    }
 
101
    void addedTo( QWidget *w, QWidget *, QAction *a ) {
 
102
        widgets.insert( a, w );
 
103
    }
 
104
    void addedTo( int index, QPopupMenu * ) {
 
105
        idx = index;
 
106
    }
 
107
 
 
108
private:
 
109
    QWidget *wid;
 
110
    QMap<QAction *, QWidget *> widgets;
 
111
    int idx;
 
112
 
 
113
};
 
114
 
 
115
class QDesignerAction : public QAction
 
116
{
 
117
    Q_OBJECT
 
118
 
 
119
public:
 
120
    QDesignerAction( QObject *parent )
 
121
        : QAction( ::qt_cast<QActionGroup*>(parent) ? parent : 0 ), wid( 0 ), idx( -1 ), widgetToInsert( 0 ) { init(); }
 
122
    QDesignerAction( QWidget *w, QObject *parent )
 
123
        : QAction( ::qt_cast<QActionGroup*>(parent) ? parent : 0 ), wid( 0 ), idx( -1 ), widgetToInsert( w ) { init(); }
 
124
 
 
125
    void init();
 
126
 
 
127
    QWidget *widget() const { return wid; }
 
128
    int index() const { return idx; }
 
129
 
 
130
    bool addTo( QWidget *w );
 
131
    bool removeFrom( QWidget *w );
 
132
 
 
133
    void remove();
 
134
    bool supportsMenu() const { return !widgetToInsert; }
 
135
 
 
136
protected:
 
137
    void addedTo( QWidget *w, QWidget * ) {
 
138
        wid = w;
 
139
    }
 
140
    void addedTo( int index, QPopupMenu * ) {
 
141
        idx = index;
 
142
    }
 
143
 
 
144
private:
 
145
    QWidget *wid;
 
146
    int idx;
 
147
    QWidget *widgetToInsert;
 
148
 
 
149
};
 
150
 
 
151
class QDesignerToolBarSeparator : public QWidget
 
152
{
 
153
    Q_OBJECT
 
154
 
 
155
public:
 
156
    QDesignerToolBarSeparator( Orientation, QToolBar *parent, const char* name=0 );
 
157
 
 
158
    QSize sizeHint() const;
 
159
    Orientation orientation() const { return orient; }
 
160
public slots:
 
161
   void setOrientation( Orientation );
 
162
protected:
 
163
    void styleChange( QStyle& );
 
164
    void paintEvent( QPaintEvent * );
 
165
private:
 
166
    Orientation orient;
 
167
};
 
168
 
 
169
 
 
170
class QSeparatorAction : public QAction
 
171
{
 
172
    Q_OBJECT
 
173
 
 
174
public:
 
175
    QSeparatorAction( QObject *parent );
 
176
 
 
177
    bool addTo( QWidget *w );
 
178
    bool removeFrom( QWidget *w );
 
179
    QWidget *widget() const;
 
180
    int index() const;
 
181
 
 
182
private:
 
183
    QWidget *wid;
 
184
    int idx;
 
185
 
 
186
};
 
187
 
 
188
 
 
189
class QDesignerToolBar : public QToolBar
 
190
{
 
191
    Q_OBJECT
 
192
 
 
193
public:
 
194
    QDesignerToolBar( QMainWindow *mw );
 
195
    QDesignerToolBar( QMainWindow *mw, Dock dock );
 
196
    QPtrList<QAction> insertedActions() const { return actionList; }
 
197
    void addAction( QAction *a );
 
198
 
 
199
    void clear();
 
200
    void installEventFilters( QWidget *w );
 
201
    void insertAction( QWidget *w, QAction *a ) { actionMap.insert( w, a ); }
 
202
    void insertAction( int index, QAction *a ) { actionList.insert( index, a ); }
 
203
    void appendAction( QAction *a ) { actionList.append( a ); }
 
204
    void removeAction( QAction *a ) { actionList.remove( a ); }
 
205
    void reInsert();
 
206
    void removeWidget( QWidget *w );
 
207
 
 
208
protected:
 
209
    bool eventFilter( QObject *, QEvent * );
 
210
    void paintEvent( QPaintEvent * );
 
211
#ifndef QT_NO_DRAGANDDROP
 
212
    void dragEnterEvent( QDragEnterEvent * );
 
213
    void dragMoveEvent( QDragMoveEvent * );
 
214
    void dragLeaveEvent( QDragLeaveEvent * );
 
215
    void dropEvent( QDropEvent * );
 
216
#endif
 
217
    void contextMenuEvent( QContextMenuEvent *e );
 
218
    void mousePressEvent( QMouseEvent *e );
 
219
    void mouseReleaseEvent( QMouseEvent *e );
 
220
 
 
221
private slots:
 
222
    void actionRemoved();
 
223
 
 
224
private:
 
225
    void drawIndicator( const QPoint &pos );
 
226
    QPoint calcIndicatorPos( const QPoint &pos );
 
227
    void buttonContextMenuEvent( QContextMenuEvent *e, QObject *o );
 
228
    void buttonMousePressEvent( QMouseEvent *e, QObject *o );
 
229
    void buttonMouseMoveEvent( QMouseEvent *e, QObject *o );
 
230
    void buttonMouseReleaseEvent( QMouseEvent *e, QObject *o );
 
231
    void doInsertWidget( const QPoint &p );
 
232
    void findFormWindow();
 
233
 
 
234
private:
 
235
    QPoint lastIndicatorPos;
 
236
    QWidget *insertAnchor;
 
237
    bool afterAnchor;
 
238
    QPtrList<QAction> actionList;
 
239
    QMap<QWidget*, QAction*> actionMap;
 
240
    QPoint dragStartPos;
 
241
    QDesignerIndicatorWidget *indicator;
 
242
    bool widgetInserting;
 
243
    FormWindow *formWindow;
 
244
 
 
245
};
 
246
 
 
247
#endif