Eneboo - Documentación para desarrolladores
src/qt/tools/designer/designer/actiondnd.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2007 Trolltech ASA.  All rights reserved.
00003 **
00004 ** This file is part of Qt Designer.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00012 ** licenses may use this file in accordance with the Qt Commercial License
00013 ** Agreement provided with the Software.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00019 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00020 **   information about Qt Commercial License Agreements.
00021 **
00022 ** Contact info@trolltech.com if any conditions of this licensing are
00023 ** not clear to you.
00024 **
00025 **********************************************************************/
00026 
00027 #ifndef ACTIONDND_H
00028 #define ACTIONDND_H
00029 
00030 #include <qaction.h>
00031 #include <qdragobject.h>
00032 #include <qmap.h>
00033 #include <qmenubar.h>
00034 #include <qpixmap.h>
00035 #include <qpopupmenu.h>
00036 #include <qptrlist.h>
00037 #include <qtoolbar.h>
00038 #include <qguardedptr.h>
00039 #include "../shared/widgetdatabase.h"
00040 
00041 //class QDesignerPopupMenu;
00042 class QDesignerIndicatorWidget;
00043 class FormWindow;
00044 class QPopupMenu;
00045 
00046 class ActionDrag : public QStoredDrag
00047 {
00048     Q_OBJECT
00049 
00050 public:
00051     ActionDrag(const QString &type, QAction *action, QWidget *source);
00052     ActionDrag(QAction *action, QWidget *source);
00053     ActionDrag(QActionGroup *group, QWidget *source);
00054 
00055     ~ActionDrag();
00056 
00057     static bool canDecode(QDropEvent *e);
00058 
00059     static QAction *action()
00060     {
00061         return the_action;
00062     }
00063 
00064 private:
00065     static QAction *the_action;
00066 };
00067 
00068 class QDesignerActionGroup : public QActionGroup
00069 {
00070     Q_OBJECT
00071 
00072 public:
00073     QDesignerActionGroup( QObject *parent )
00074         : QActionGroup( ::qt_cast<QActionGroup*>(parent) ? parent : 0 ), wid( 0 ), idx( -1 ) { init(); }
00075 
00076     void init();
00077 
00078     QWidget *widget() const { return wid; }
00079     QWidget *widget( QAction *a ) const { return *widgets.find( a ); }
00080     int index() const { return idx; }
00081 
00082 protected:
00083 #if !defined(Q_NO_USING_KEYWORD)
00084     using QActionGroup::addedTo;
00085 #endif
00086     void addedTo( QWidget *w, QWidget * ) {
00087         wid = w;
00088     }
00089     void addedTo( QWidget *w, QWidget *, QAction *a ) {
00090         widgets.insert( a, w );
00091     }
00092     void addedTo( int index, QPopupMenu * ) {
00093         idx = index;
00094     }
00095 
00096 private:
00097     QWidget *wid;
00098     QMap<QAction *, QWidget *> widgets;
00099     int idx;
00100 
00101 };
00102 
00103 class QDesignerAction : public QAction
00104 {
00105     Q_OBJECT
00106 
00107 public:
00108     QDesignerAction( QObject *parent )
00109         : QAction( ::qt_cast<QActionGroup*>(parent) ? parent : 0 ), wid( 0 ), idx( -1 ), widgetToInsert( 0 ) { init(); }
00110     QDesignerAction( QWidget *w, QObject *parent )
00111         : QAction( ::qt_cast<QActionGroup*>(parent) ? parent : 0 ), wid( 0 ), idx( -1 ), widgetToInsert( w ) { init(); }
00112 
00113     void init();
00114 
00115     QWidget *widget() const { return wid; }
00116     int index() const { return idx; }
00117 
00118     bool addTo( QWidget *w );
00119     bool removeFrom( QWidget *w );
00120 
00121     void remove();
00122     bool supportsMenu() const { return !widgetToInsert; }
00123 
00124 protected:
00125     void addedTo( QWidget *w, QWidget * ) {
00126         wid = w;
00127     }
00128     void addedTo( int index, QPopupMenu * ) {
00129         idx = index;
00130     }
00131 
00132 private:
00133     QWidget *wid;
00134     int idx;
00135     QWidget *widgetToInsert;
00136 
00137 };
00138 
00139 class QDesignerToolBarSeparator : public QWidget
00140 {
00141     Q_OBJECT
00142 
00143 public:
00144     QDesignerToolBarSeparator( Orientation, QToolBar *parent, const char* name=0 );
00145 
00146     QSize sizeHint() const;
00147     Orientation orientation() const { return orient; }
00148 public slots:
00149    void setOrientation( Orientation );
00150 protected:
00151     void styleChange( QStyle& );
00152     void paintEvent( QPaintEvent * );
00153 private:
00154     Orientation orient;
00155 };
00156 
00157 
00158 class QSeparatorAction : public QAction
00159 {
00160     Q_OBJECT
00161 
00162 public:
00163     QSeparatorAction( QObject *parent );
00164 
00165     bool addTo( QWidget *w );
00166     bool removeFrom( QWidget *w );
00167     QWidget *widget() const;
00168     int index() const;
00169 
00170 private:
00171     QWidget *wid;
00172     int idx;
00173 
00174 };
00175 
00176 
00177 class QDesignerToolBar : public QToolBar
00178 {
00179     Q_OBJECT
00180 
00181 public:
00182     QDesignerToolBar( QMainWindow *mw );
00183     QDesignerToolBar( QMainWindow *mw, Dock dock );
00184     QPtrList<QAction> insertedActions() const { return actionList; }
00185     void addAction( QAction *a );
00186 
00187     void clear();
00188     void installEventFilters( QWidget *w );
00189     void insertAction( QWidget *w, QAction *a ) { actionMap.insert( w, a ); }
00190     void insertAction( int index, QAction *a ) { actionList.insert( index, a ); }
00191     void appendAction( QAction *a ) { actionList.append( a ); }
00192     void removeAction( QAction *a ) { actionList.remove( a ); }
00193     void reInsert();
00194     void removeWidget( QWidget *w );
00195 
00196 protected:
00197     bool eventFilter( QObject *, QEvent * );
00198     void paintEvent( QPaintEvent * );
00199 #ifndef QT_NO_DRAGANDDROP
00200     void dragEnterEvent( QDragEnterEvent * );
00201     void dragMoveEvent( QDragMoveEvent * );
00202     void dragLeaveEvent( QDragLeaveEvent * );
00203     void dropEvent( QDropEvent * );
00204 #endif
00205     void contextMenuEvent( QContextMenuEvent *e );
00206     void mousePressEvent( QMouseEvent *e );
00207     void mouseReleaseEvent( QMouseEvent *e );
00208 
00209 private slots:
00210     void actionRemoved();
00211 
00212 private:
00213     void drawIndicator( const QPoint &pos );
00214     QPoint calcIndicatorPos( const QPoint &pos );
00215     void buttonContextMenuEvent( QContextMenuEvent *e, QObject *o );
00216     void buttonMousePressEvent( QMouseEvent *e, QObject *o );
00217     void buttonMouseMoveEvent( QMouseEvent *e, QObject *o );
00218     void buttonMouseReleaseEvent( QMouseEvent *e, QObject *o );
00219     void doInsertWidget( const QPoint &p );
00220     void findFormWindow();
00221 
00222 private:
00223     QPoint lastIndicatorPos;
00224     QWidget *insertAnchor;
00225     bool afterAnchor;
00226     QPtrList<QAction> actionList;
00227     QMap<QWidget*, QAction*> actionMap;
00228     QPoint dragStartPos;
00229     QDesignerIndicatorWidget *indicator;
00230     bool widgetInserting;
00231     FormWindow *formWindow;
00232 
00233 };
00234 
00235 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'