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 FORMWINDOW_H 00028 #define FORMWINDOW_H 00029 00030 #include "command.h" 00031 #include "metadatabase.h" 00032 #include "sizehandle.h" 00033 #include "actiondnd.h" 00034 00035 #include <qwidget.h> 00036 #include <qptrdict.h> 00037 #include <qpixmap.h> 00038 #include <qwidgetlist.h> 00039 #include <qmap.h> 00040 00041 class QPaintEvent; 00042 class QMouseEvent; 00043 class QKeyEvent; 00044 class QPainter; 00045 class QLabel; 00046 class MainWindow; 00047 class QTimer; 00048 class QFocusEvent; 00049 class QCloseEvent; 00050 class Resource; 00051 class QResizeEvent; 00052 class BreakLayoutCommand; 00053 class QPixmap; 00054 class QSizeGrip; 00055 class Project; 00056 struct DesignerFormWindow; 00057 class FormFile; 00058 00059 #if defined(Q_CC_MSVC) || defined(Q_FULL_TEMPLATE_INSTANTIATION) 00060 #include "orderindicator.h" 00061 #else 00062 class OrderIndicator; 00063 #endif 00064 00065 class FormWindow : public QWidget 00066 { 00067 Q_OBJECT 00068 Q_PROPERTY( QString fileName READ fileName WRITE setFileName ) 00069 00070 public: 00071 FormWindow( FormFile *f, MainWindow *mw, QWidget *parent, const char *name = 0 ); 00072 FormWindow( FormFile *f, QWidget *parent, const char *name = 0 ); 00073 ~FormWindow(); 00074 00075 void init(); 00076 virtual void setMainWindow( MainWindow *w ); 00077 00078 virtual QString fileName() const; 00079 virtual void setFileName( const QString &fn ); 00080 00081 virtual QPoint grid() const; 00082 virtual QPoint gridPoint( const QPoint &p ); 00083 00084 virtual CommandHistory *commandHistory(); 00085 00086 virtual void undo(); 00087 virtual void redo(); 00088 virtual QString copy(); 00089 virtual void paste( const QString &cb, QWidget *parent ); 00090 virtual void lowerWidgets(); 00091 virtual void raiseWidgets(); 00092 virtual void checkAccels(); 00093 00094 virtual void layoutHorizontal(); 00095 virtual void layoutVertical(); 00096 virtual void layoutHorizontalSplit(); 00097 virtual void layoutVerticalSplit(); 00098 virtual void layoutGrid(); 00099 00100 virtual void layoutHorizontalContainer( QWidget *w ); 00101 virtual void layoutVerticalContainer( QWidget *w ); 00102 virtual void layoutGridContainer( QWidget *w ); 00103 00104 virtual void breakLayout( QWidget *w ); 00105 00106 virtual void selectWidget( QObject *w, bool select = TRUE ); 00107 virtual void selectAll(); 00108 virtual void updateSelection( QWidget *w ); 00109 virtual void raiseSelection( QWidget *w ); 00110 virtual void repaintSelection( QWidget *w ); 00111 virtual void clearSelection( bool changePropertyDisplay = TRUE ); 00112 virtual void selectWidgets(); 00113 bool isWidgetSelected( QObject *w ); 00114 virtual void updateChildSelections( QWidget *w ); 00115 virtual void raiseChildSelections( QWidget *w ); 00116 00117 virtual void emitUpdateProperties( QObject *w ); 00118 virtual void emitShowProperties( QObject *w = 0 ); 00119 virtual void emitSelectionChanged(); 00120 00121 virtual void setPropertyShowingBlocked( bool b ); 00122 bool isPropertyShowingBlocked() const; 00123 00124 virtual QLabel *sizePreview() const; 00125 virtual void checkPreviewGeometry( QRect &r ); 00126 00127 virtual QPtrDict<QWidget> *widgets(); 00128 virtual QWidgetList selectedWidgets() const; 00129 00130 virtual QWidget *designerWidget( QObject *o ) const; 00131 00132 virtual void handleContextMenu( QContextMenuEvent *e, QWidget *w ); 00133 virtual void handleMousePress( QMouseEvent *e, QWidget *w ); 00134 virtual void handleMouseRelease( QMouseEvent *e, QWidget *w ); 00135 virtual void handleMouseDblClick( QMouseEvent *e, QWidget *w ); 00136 virtual void handleMouseMove( QMouseEvent *e, QWidget *w ); 00137 virtual void handleKeyPress( QKeyEvent *e, QWidget *w ); 00138 virtual void handleKeyRelease( QKeyEvent *e, QWidget *w ); 00139 00140 virtual void updateUndoInfo(); 00141 00142 virtual MainWindow *mainWindow() const { return mainwindow; } 00143 00144 bool checkCustomWidgets(); 00145 virtual void insertWidget( QWidget *w, bool checkName = FALSE ); 00146 virtual void removeWidget( QWidget *w ); 00147 virtual void deleteWidgets(); 00148 virtual void editAdjustSize(); 00149 virtual void editConnections(); 00150 00151 virtual int numSelectedWidgets() const; 00152 virtual int numVisibleWidgets() const; 00153 00154 virtual bool hasInsertedChildren( QWidget *w ) const; 00155 00156 virtual QWidget *currentWidget() const { return propertyWidget && propertyWidget->isWidgetType() ? (QWidget*)propertyWidget : 0; } // ##### 00157 virtual bool unify( QObject *w, QString &s, bool changeIt ); 00158 00159 virtual bool isCustomWidgetUsed( MetaDataBase::CustomWidget *w ); 00160 virtual bool isDatabaseWidgetUsed() const; 00161 virtual bool isDatabaseAware() const; 00162 00163 virtual QPoint mapToForm( const QWidget* w, const QPoint& ) const; 00164 00165 bool isMainContainer( QObject *w ) const; 00166 bool isCentralWidget( QObject *w ) const; 00167 QWidget *mainContainer() const { return mContainer; } 00168 void setMainContainer( QWidget *w ); 00169 00170 void paintGrid( QWidget *w, QPaintEvent *e ); 00171 00172 bool savePixmapInline() const; 00173 QString pixmapLoaderFunction() const; 00174 void setSavePixmapInline( bool b ); 00175 void setPixmapLoaderFunction( const QString &func ); 00176 00177 bool savePixmapInProject() const; 00178 void setSavePixmapInProject( bool b ); 00179 00180 void setToolFixed() { toolFixed = TRUE; } 00181 00182 void setActiveObject( QObject *o ); 00183 00184 QPtrList<QAction> &actionList() { return actions; } 00185 QAction *findAction( const QString &name ); 00186 00187 void setProject( Project *pro ); 00188 Project *project() const; 00189 00190 void killAccels( QObject *top ); 00191 00192 DesignerFormWindow *iFace(); 00193 00194 int layoutDefaultSpacing() const; 00195 int layoutDefaultMargin() const; 00196 void setLayoutDefaultSpacing( int s ); 00197 void setLayoutDefaultMargin( int s ); 00198 QString spacingFunction() const; 00199 QString marginFunction() const; 00200 void setSpacingFunction( const QString &func ); 00201 void setMarginFunction( const QString &func ); 00202 bool hasLayoutFunctions() const; 00203 void hasLayoutFunctions( bool b ); 00204 00205 void initSlots(); 00206 FormFile *formFile() const; 00207 void setFormFile( FormFile *f ); 00208 00209 bool isFake() const { return fake; } 00210 bool canBeBuddy( const QWidget* ) const; 00211 00212 public slots: 00213 virtual void widgetChanged( QObject *w ); 00214 virtual void currentToolChanged(); 00215 virtual void visibilityChanged(); 00216 virtual void modificationChanged( bool m ); 00217 00218 signals: 00219 void showProperties( QObject *w ); 00220 void updateProperties( QObject *w ); 00221 void undoRedoChanged( bool undoAvailable, bool redoAvailable, 00222 const QString &undoCmd, const QString &redoCmd ); 00223 void selectionChanged(); 00224 void modificationChanged( bool m, FormWindow *fw ); 00225 void modificationChanged( bool m, const QString &s ); 00226 void fileNameChanged( const QString &s, FormWindow *fw ); 00227 00228 protected: 00229 virtual void closeEvent( QCloseEvent *e ); 00230 virtual void focusInEvent( QFocusEvent *e ); 00231 virtual void focusOutEvent( QFocusEvent *e ); 00232 virtual void resizeEvent( QResizeEvent *e ); 00233 void mouseDoubleClickEvent( QMouseEvent *e ) { handleMouseDblClick( e, mainContainer() ); } 00234 00235 private: 00236 enum RectType { Insert, Rubber }; 00237 00238 void beginUnclippedPainter( bool doNot ); 00239 void endUnclippedPainter(); 00240 void drawConnectionLine(); 00241 void drawSizePreview( const QPoint &pos, const QString& text ); 00242 00243 void insertWidget(); 00244 void moveSelectedWidgets( int dx, int dy ); 00245 00246 void startRectDraw( const QPoint &p, const QPoint &global, QWidget *w, RectType t ); 00247 void continueRectDraw( const QPoint &p, const QPoint &global, QWidget *w, RectType t ); 00248 void endRectDraw(); 00249 00250 void checkSelectionsForMove( QWidget *w ); 00251 BreakLayoutCommand *breakLayoutCommand( QWidget *w ); 00252 00253 bool allowMove( QWidget *w ); 00254 00255 void saveBackground(); 00256 void restoreConnectionLine(); 00257 void restoreRect( const QRect &rect ) ; 00258 00259 void showOrderIndicators(); 00260 void updateOrderIndicators(); 00261 void repositionOrderIndicators(); 00262 void hideOrderIndicators(); 00263 00264 QWidget *containerAt( const QPoint &pos, QWidget *notParentOf ); 00265 00266 private slots: 00267 void invalidCheckedSelections(); 00268 void updatePropertiesTimerDone(); 00269 void showPropertiesTimerDone(); 00270 void selectionChangedTimerDone(); 00271 void windowsRepaintWorkaroundTimerTimeout(); 00272 00273 private: 00274 int currTool; 00275 bool oldRectValid, widgetPressed, drawRubber, checkedSelectionsForMove; 00276 bool validForBuddy; 00277 QRect currRect; 00278 QPoint rectAnchor; 00279 QPainter *unclippedPainter; 00280 QPoint sizePreviewPos; 00281 QPixmap sizePreviewPixmap; 00282 MainWindow *mainwindow; 00283 QPtrList<WidgetSelection> selections; 00284 QPtrDict<WidgetSelection> usedSelections; 00285 QRect widgetGeom, rubber; 00286 QPoint oldPressPos, origPressPos; 00287 CommandHistory commands; 00288 QMap<QWidget*, QPoint> moving; 00289 QWidget *insertParent; 00290 QObject *propertyWidget; 00291 QLabel *sizePreviewLabel; 00292 QTimer *checkSelectionsTimer; 00293 QPtrDict<QWidget> insertedWidgets; 00294 bool propShowBlocked; 00295 QTimer* updatePropertiesTimer, *showPropertiesTimer, *selectionChangedTimer, 00296 *windowsRepaintWorkaroundTimer; 00297 QPoint startPos, currentPos; 00298 QWidget *startWidget, *endWidget; 00299 QPixmap *buffer; 00300 QPtrList<OrderIndicator> orderIndicators; 00301 QWidgetList orderedWidgets; 00302 QWidgetList stackedWidgets; 00303 QWidget *mContainer; 00304 bool pixInline, pixProject; 00305 QString pixLoader; 00306 bool toolFixed; 00307 QPtrList<QAction> actions; 00308 Project *proj; 00309 DesignerFormWindow *iface; 00310 QWidget* targetContainer; 00311 QPalette restorePalette; 00312 bool hadOwnPalette; 00313 int defSpacing, defMargin; 00314 QString spacFunction, margFunction; 00315 bool hasLayoutFunc; 00316 FormFile *ff; 00317 bool fake; 00318 00319 }; 00320 00321 #endif