Eneboo - Documentación para desarrolladores
src/qt/tools/designer/designer/popupmenueditor.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002 ** Copyright (C) 2005-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 POPUPMENUEDITOR_H
00028 #define POPUPMENUEDITOR_H
00029 
00030 #include <qwidget.h>
00031 #include <qptrlist.h>
00032 #include <qaction.h>
00033 
00034 class PopupMenuEditor;
00035 class QMenuItem;
00036 
00037 class PopupMenuEditorItem : public QObject
00038 {
00039     Q_OBJECT
00040 
00041     friend class PopupMenuEditor;
00042 
00043     PopupMenuEditorItem( PopupMenuEditor * menu = 0, QObject * parent = 0, const char * name = 0 );
00044 
00045 public:
00046     enum ItemType {
00047         Unknown = -1,
00048         Separator = 0,
00049         Action = 1
00050     };
00051 
00052     PopupMenuEditorItem( QAction * action, PopupMenuEditor * menu,
00053                          QObject * parent = 0, const char * name = 0 );
00054     PopupMenuEditorItem( PopupMenuEditorItem * item, PopupMenuEditor * menu,
00055                          QObject * parent = 0, const char * name = 0 );
00056     ~PopupMenuEditorItem();
00057 
00058     void init();
00059 
00060     ItemType type() const;
00061     QAction * action() const { return a; }
00062 
00063     void setVisible( bool enable );
00064     bool isVisible() const;
00065 
00066     void setSeparator( bool enable ) { separator = enable; }
00067     bool isSeparator() const { return separator; }
00068 
00069     void setRemovable( bool enable ) { removable = enable; }
00070     bool isRemovable() const { return removable; }
00071     
00072     void showMenu( int x, int y );
00073     void hideMenu();
00074     void focusOnMenu();
00075     PopupMenuEditor * subMenu() const { return s; }
00076 
00077     int count() const;
00078 
00079     bool eventFilter( QObject *, QEvent * event );
00080     
00081 public slots:
00082     void selfDestruct();
00083 
00084 protected:
00085 
00086 private:
00087     QAction * a;
00088     PopupMenuEditor * s;
00089     PopupMenuEditor * m;
00090     uint separator : 1;
00091     uint removable : 1;
00092 };
00093 
00094 class FormWindow;
00095 class MainWindow;
00096 class QLineEdit;
00097 
00098 #include <qpopupmenu.h>
00099 
00100 class PopupMenuEditor : public QWidget
00101 {
00102     Q_OBJECT
00103 
00104     friend class PopupMenuEditorItem;
00105     friend class MenuBarEditor;
00106     friend class Resource;
00107 
00108 public:
00109     PopupMenuEditor( FormWindow * fw, QWidget * parent = 0, const char * name = 0 );
00110     PopupMenuEditor( FormWindow * fw, PopupMenuEditor * menu, QWidget * parent, const char * name = 0 );
00111     ~PopupMenuEditor();
00112 
00113     void init();
00114 
00115     void insert( PopupMenuEditorItem * item, int index = -1 );
00116     void insert( QAction * action, int index = -1 );
00117     void insert( QActionGroup * actionGroup, int index = -1 );
00118     int find( const QAction * action );
00119     int find( PopupMenuEditor * menu );
00120     int count();
00121     PopupMenuEditorItem * at( int index );
00122     PopupMenuEditorItem * at( QPoint pos ) { return itemAt( pos.y() ); }
00123     void exchange( int a, int b );
00124 
00125     void cut( int index );
00126     void copy( int index );
00127     void paste( int index );
00128 
00129     void insertedActions( QPtrList<QAction> & list );
00130 
00131     void show();
00132     void choosePixmap( int index = -1 );
00133     void showLineEdit( int index = -1);
00134     void setAccelerator( int key, Qt::ButtonState state, int index = -1 );
00135 
00136     FormWindow * formWindow() { return formWnd; }
00137     bool isCreatingAccelerator() { return ( currentField == 2 ); }
00138 
00139     QPtrList<PopupMenuEditorItem> * items() { return &itemList; }
00140 
00141     QWidget * parentEditor() { return parentMenu; }
00142 
00143 signals:
00144     void inserted( QAction * );
00145     void removed(  QAction * );
00146     
00147 public slots:
00148 
00149     void cut() { cut( currentIndex ); }
00150     void copy() { copy( currentIndex ); }
00151     void paste() { paste( currentIndex ); }
00152 
00153     void remove( int index );
00154     void remove( QAction * a ) { remove( find( a ) ); }
00155 
00156     void resizeToContents();
00157     void showSubMenu();
00158     void hideSubMenu();
00159     void focusOnSubMenu();
00160     
00161 protected:
00162     PopupMenuEditorItem * createItem( QAction * a = 0 );
00163     void removeItem( int index = -1 );
00164     PopupMenuEditorItem * currentItem();
00165     PopupMenuEditorItem * itemAt( int y );
00166     void setFocusAt( const QPoint & pos );
00167 
00168     bool eventFilter( QObject * o, QEvent * e );
00169     void paintEvent( QPaintEvent * e );
00170     void mousePressEvent( QMouseEvent * e );
00171     void mouseDoubleClickEvent( QMouseEvent * e );
00172     void mouseMoveEvent( QMouseEvent * e );
00173     void dragEnterEvent( QDragEnterEvent * e );
00174     void dragLeaveEvent( QDragLeaveEvent * e );
00175     void dragMoveEvent( QDragMoveEvent * e );
00176     void dropEvent( QDropEvent * e );
00177     void keyPressEvent( QKeyEvent * e );
00178     void focusInEvent( QFocusEvent * e );
00179     void focusOutEvent( QFocusEvent * e );
00180 
00181     void drawItems( QPainter * p );
00182     void drawItem( QPainter * p, PopupMenuEditorItem * i, const QRect & r, int f ) const;
00183     void drawWinFocusRect( QPainter * p, const QRect & r ) const;
00184 
00185     QSize contentsSize();
00186     int itemHeight( const PopupMenuEditorItem * item ) const;
00187     int itemPos( const PopupMenuEditorItem * item ) const;
00188     
00189     int snapToItem( int y );
00190     void dropInPlace( PopupMenuEditorItem * i, int y );
00191     void dropInPlace( QActionGroup * g, int y );
00192 
00193     void safeDec();
00194     void safeInc();
00195 
00196     void clearCurrentField();
00197     void navigateUp( bool ctrl );
00198     void navigateDown( bool ctrl );
00199     void navigateLeft();
00200     void navigateRight();
00201     void enterEditMode( QKeyEvent * e );
00202     void leaveEditMode( QKeyEvent * e );
00203 
00204     QString constructName( PopupMenuEditorItem *item );
00205 
00206 private:
00207     FormWindow * formWnd;
00208     QLineEdit * lineEdit;
00209     QWidget * dropLine;
00210     QPtrList<PopupMenuEditorItem> itemList;
00211     PopupMenuEditorItem addItem;
00212     PopupMenuEditorItem addSeparator;
00213     QWidget * parentMenu;
00214 
00215     int iconWidth;
00216     int textWidth;
00217     int accelWidth;
00218     int arrowWidth;
00219     int borderSize;
00220     
00221     int currentField;
00222     int currentIndex;
00223     QPoint mousePressPos;
00224     static PopupMenuEditorItem * draggedItem;
00225 
00226     enum ClipboardOperation {
00227         None = 0,
00228         Cut = 1,
00229         Copy = 2
00230     };
00231     static int clipboardOperation;
00232     static PopupMenuEditorItem * clipboardItem;
00233 };
00234 
00235 #endif //POPUPMENUEDITOR_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'