Eneboo - Documentación para desarrolladores
|
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 MENUBAREDITOR_H 00028 #define MENUBAREDITOR_H 00029 00030 #include <qmenubar.h> 00031 #include <qptrlist.h> 00032 00033 class PopupMenuEditor; 00034 class MenuBarEditor; 00035 class QActionGroup; 00036 00037 class MenuBarEditorItem : public QObject 00038 { 00039 Q_OBJECT 00040 00041 friend class MenuBarEditor; 00042 00043 MenuBarEditorItem( MenuBarEditor * bar = 0, QObject * parent = 0, const char * name = 0 ); 00044 00045 public: 00046 MenuBarEditorItem( PopupMenuEditor * menu, MenuBarEditor * bar, 00047 QObject * parent = 0, const char * name = 0); 00048 MenuBarEditorItem( QActionGroup * actionGroup, MenuBarEditor * bar, 00049 QObject * parent = 0, const char * name = 0); 00050 MenuBarEditorItem( MenuBarEditorItem * item, 00051 QObject * parent = 0, const char * name = 0); 00052 ~MenuBarEditorItem() { }; 00053 00054 PopupMenuEditor * menu() { return popupMenu; } 00055 00056 void setMenuText( const QString t ) { text = t; }; 00057 QString menuText() { return text; } 00058 00059 void setVisible( bool enable ) { visible = enable; } 00060 bool isVisible() { return visible; } 00061 00062 void setRemovable( bool enable ) { removable = enable; } 00063 bool isRemovable() { return removable; } 00064 00065 bool isSeparator() { return separator; } 00066 protected: 00067 void setSeparator( bool enable ) { separator = enable; } 00068 00069 private: 00070 MenuBarEditor * menuBar; 00071 PopupMenuEditor * popupMenu; 00072 QString text; 00073 uint visible : 1; 00074 uint separator : 1; 00075 uint removable : 1; 00076 }; 00077 00078 class QLineEdit; 00079 class FormWindow; 00080 00081 class MenuBarEditor : public QMenuBar 00082 { 00083 Q_OBJECT 00084 00085 public: 00086 MenuBarEditor( FormWindow * fw, QWidget * parent = 0, const char * name = 0 ); 00087 ~MenuBarEditor(); 00088 00089 FormWindow * formWindow(); 00090 00091 MenuBarEditorItem * createItem( int index = -1, bool addToCmdStack = TRUE ); 00092 void insertItem( MenuBarEditorItem * item, int index = -1 ); 00093 void insertItem( QString text, PopupMenuEditor * menu, int index = -1 ); 00094 void insertItem( QString text, QActionGroup * group, int index = -1 ); 00095 00096 void insertSeparator( int index = -1 ); 00097 00098 void removeItemAt( int index ); 00099 void removeItem( MenuBarEditorItem * item ); 00100 00101 int findItem( MenuBarEditorItem * item ); 00102 int findItem( PopupMenuEditor * menu ); 00103 int findItem( QPoint & pos ); 00104 00105 MenuBarEditorItem * item( int index = -1 ); 00106 00107 int count(); 00108 int current(); 00109 00110 void cut( int index ); 00111 void copy( int index ); 00112 void paste( int index ); 00113 void exchange( int a, int b ); 00114 00115 void showLineEdit( int index = -1); 00116 void showItem( int index = -1 ); 00117 void hideItem( int index = -1 ); 00118 void focusItem( int index = -1 ); 00119 void deleteItem( int index = -1 ); 00120 00121 QSize sizeHint() const; 00122 QSize minimumSize() const { return sizeHint(); } 00123 QSize minimumSizeHint() const { return sizeHint(); } 00124 int heightForWidth( int max_width ) const; 00125 00126 void show(); 00127 00128 void checkAccels( QMap<QChar, QWidgetList > &accels ); 00129 00130 public slots: 00131 void cut(); 00132 void copy(); 00133 void paste(); 00134 00135 protected: 00136 bool eventFilter( QObject * o, QEvent * e ); 00137 void paintEvent( QPaintEvent * e ); 00138 void mousePressEvent( QMouseEvent * e ); 00139 void mouseDoubleClickEvent( QMouseEvent * e ); 00140 void mouseMoveEvent( QMouseEvent * e ); 00141 void dragEnterEvent( QDragEnterEvent * e ); 00142 void dragLeaveEvent( QDragLeaveEvent * e ); 00143 void dragMoveEvent( QDragMoveEvent * e ); 00144 void dropEvent( QDropEvent * e ); 00145 void keyPressEvent( QKeyEvent * e ); 00146 void focusOutEvent( QFocusEvent * e ); 00147 void resizeEvent( QResizeEvent * e ) { QFrame::resizeEvent( e ); } 00148 00149 void resizeInternals(); 00150 00151 void drawItems( QPainter & p ); 00152 void drawItem( QPainter & p, MenuBarEditorItem * i, int idx, QPoint & pos ); 00153 void drawSeparator( QPainter & p, QPoint & pos ); 00154 00155 QSize itemSize( MenuBarEditorItem * i ); 00156 void addItemSizeToCoords( MenuBarEditorItem * i, int & x, int & y, int w ); 00157 00158 QPoint itemPos( int index ); 00159 QPoint snapToItem( const QPoint & pos ); 00160 void dropInPlace( MenuBarEditorItem * i, const QPoint & pos ); 00161 00162 void safeDec(); 00163 void safeInc(); 00164 00165 void navigateLeft( bool ctrl ); 00166 void navigateRight( bool ctrl ); 00167 void enterEditMode(); 00168 void leaveEditMode(); 00169 00170 QPixmap createTextPixmap( const QString &text ); 00171 int borderSize() const { return margin() + 4; } // add 4 pixels to the margin 00172 00173 private: 00174 FormWindow * formWnd; 00175 QLineEdit * lineEdit; 00176 QWidget * dropLine; 00177 QPtrList<MenuBarEditorItem> itemList; 00178 MenuBarEditorItem addItem; 00179 MenuBarEditorItem addSeparator; 00180 MenuBarEditorItem * draggedItem; 00181 QPoint mousePressPos; 00182 int currentIndex; 00183 int itemHeight; 00184 int separatorWidth; 00185 bool hideWhenEmpty; 00186 bool hasSeparator; 00187 bool dropConfirmed; 00188 00189 enum ClipboardOperation { 00190 None = 0, 00191 Cut = 1, 00192 Copy = 2 00193 }; 00194 static int clipboardOperation; 00195 static MenuBarEditorItem * clipboardItem; 00196 }; 00197 00198 #endif //MENUBAREDITOR_H