Eneboo - Documentación para desarrolladores
|
00001 /********************************************************************** 00002 ** 00003 ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved. 00004 ** 00005 ** This file is part of Qt Designer. 00006 ** 00007 ** This file may be distributed and/or modified under the terms of the 00008 ** GNU General Public License version 2 as published by the Free Software 00009 ** Foundation and appearing in the file LICENSE.GPL included in the 00010 ** packaging of this file. 00011 ** 00012 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00013 ** licenses may use this file in accordance with the Qt Commercial License 00014 ** Agreement provided with the Software. 00015 ** 00016 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00017 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00018 ** 00019 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00020 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00021 ** information about Qt Commercial License Agreements. 00022 ** 00023 ** Contact info@trolltech.com if any conditions of this licensing are 00024 ** not clear to you. 00025 ** 00026 **********************************************************************/ 00027 00028 void MainWindowWizardBase::init() 00029 { 00030 dIface = 0; 00031 dfw = 0; 00032 widget = 0; 00033 setHelpEnabled( menuToolbarPage, FALSE ); 00034 setHelpEnabled( toolbarsPage, FALSE ); 00035 setHelpEnabled( finishPage, FALSE ); 00036 setFinishEnabled( finishPage, TRUE ); 00037 } 00038 00039 void MainWindowWizardBase::destroy() 00040 { 00041 if ( dIface ) 00042 dIface->release(); 00043 } 00044 00045 void MainWindowWizardBase::currentSettingChanged() 00046 { 00047 bool appr = checkFileToolbar->isChecked() || checkEditToolbar->isChecked() || checkHelpToolbar->isChecked(); 00048 setAppropriate( toolbarsPage, appr ); 00049 } 00050 00051 void MainWindowWizardBase::setupToolbarPage() 00052 { 00053 if ( checkFileToolbar->isChecked() ) 00054 comboToolbar->insertItem( tr( "File" ) ); 00055 if ( checkEditToolbar->isChecked() ) 00056 comboToolbar->insertItem( tr( "Edit" ) ); 00057 if ( checkHelpToolbar->isChecked() ) 00058 comboToolbar->insertItem( tr( "Help" ) ); 00059 } 00060 00061 void MainWindowWizardBase::toolbarActionDown() 00062 { 00063 if ( listToolbar->currentItem() < 0 || listToolbar->currentItem() >= (int)listToolbar->count() - 1 ) 00064 return; 00065 00066 int next = listToolbar->currentItem() + 1; 00067 QString tmp = listToolbar->text( next ); 00068 listToolbar->changeItem( listToolbar->text( next - 1 ), next ); 00069 listToolbar->changeItem( tmp, next - 1 ); 00070 listToolbar->setCurrentItem( next ); 00071 } 00072 00073 void MainWindowWizardBase::toolbarActionUp() 00074 { 00075 if ( listToolbar->currentItem() < 1 || listToolbar->currentItem() > (int)listToolbar->count() - 1 ) 00076 return; 00077 00078 int prev = listToolbar->currentItem() - 1; 00079 QString tmp = listToolbar->text( prev ); 00080 listToolbar->changeItem( listToolbar->text( prev + 1 ), prev ); 00081 listToolbar->changeItem( tmp, prev + 1 ); 00082 listToolbar->setCurrentItem( prev ); 00083 } 00084 00085 void MainWindowWizardBase::toolbarAddAction() 00086 { 00087 if ( listToolbarActions->text( listToolbarActions->currentItem() ).isEmpty() ) 00088 return; 00089 listToolbar->insertItem( listToolbarActions->text( listToolbarActions->currentItem() ) ); 00090 listToolbar->setCurrentItem( listToolbar->count() - 1 ); 00091 listToolbarActions->setCurrentItem( listToolbarActions->currentItem() + 1 ); 00092 } 00093 00094 void MainWindowWizardBase::toolbarRemoveAction() 00095 { 00096 listToolbar->removeItem( listToolbar->currentItem() ); 00097 } 00098 00099 static void devNull( QtMsgType, const char * ) 00100 { 00101 } 00102 00103 void MainWindowWizardBase::accept() 00104 { 00105 if ( !dfw || !dIface || !widget ) { 00106 QWizard::accept(); 00107 return; 00108 } 00109 00110 setFinishEnabled( finishPage, FALSE ); 00111 00112 QPixmap pix; 00113 00114 QDict<QAction> actions; 00115 QPtrList<QAction> usedActions; 00116 00117 QtMsgHandler oldMsgHandler = qInstallMsgHandler( devNull ); 00118 00119 getPixmap( "filenew", pix ); 00120 00121 QAction *fileNewAction = dfw->createAction( tr( "New" ), pix, tr( "&New" ), CTRL + Key_N, 0, "fileNewAction" ); 00122 actions.insert( tr( "New" ), fileNewAction ); 00123 getPixmap( "fileopen", pix ); 00124 QAction *fileOpenAction = dfw->createAction( tr( "Open" ), pix, tr( "&Open..." ), CTRL + Key_O, 0, "fileOpenAction" ); 00125 actions.insert( tr( "Open" ), fileOpenAction ); 00126 getPixmap( "filesave", pix ); 00127 QAction *fileSaveAction = dfw->createAction( tr( "Save" ), pix, tr( "&Save" ), CTRL + Key_S, 0, "fileSaveAction" ); 00128 actions.insert( tr( "Save" ), fileSaveAction ); 00129 QAction *fileSaveAsAction = dfw->createAction( tr( "Save As" ), QIconSet(), tr( "Save &As..." ), 0, 0, "fileSaveAsAction" ); 00130 actions.insert( tr( "Save As" ), fileSaveAsAction ); 00131 getPixmap( "print", pix ); 00132 QAction *filePrintAction = dfw->createAction( tr( "Print" ), pix, tr( "&Print..." ), CTRL + Key_P, 0, "filePrintAction" ); 00133 actions.insert( tr( "Print" ), filePrintAction ); 00134 QAction *fileExitAction = dfw->createAction( tr( "Exit" ), QIconSet(), tr( "E&xit" ), 0, 0, "fileExitAction" ); 00135 actions.insert( tr( "Exit" ), fileExitAction ); 00136 00137 getPixmap( "undo", pix ); 00138 QAction *editUndoAction = dfw->createAction( tr( "Undo" ), pix, tr( "&Undo" ), CTRL + Key_Z, 0, "editUndoAction" ); 00139 actions.insert( tr( "Undo" ), editUndoAction ); 00140 getPixmap( "redo", pix ); 00141 QAction *editRedoAction = dfw->createAction( tr( "Redo" ), pix, tr( "&Redo" ), CTRL + Key_Y, 0, "editRedoAction" ); 00142 actions.insert( tr( "Redo" ), editRedoAction ); 00143 getPixmap( "editcut", pix ); 00144 QAction *editCutAction = dfw->createAction( tr( "Cut" ), pix, tr( "Cu&t" ), CTRL + Key_X, 0, "editCutAction" ); 00145 actions.insert( tr( "Cut" ), editCutAction ); 00146 getPixmap( "editcopy", pix ); 00147 QAction *editCopyAction = dfw->createAction( tr( "Copy" ), pix, tr( "&Copy" ), CTRL + Key_C, 0, "editCopyAction" ); 00148 actions.insert( tr( "Copy" ), editCopyAction ); 00149 getPixmap( "editpaste", pix ); 00150 QAction *editPasteAction = dfw->createAction( tr( "Paste" ), pix, tr( "&Paste" ), CTRL + Key_V, 0, "editPasteAction" ); 00151 actions.insert( tr( "Paste" ), editPasteAction ); 00152 getPixmap( "searchfind", pix ); 00153 QAction *editFindAction = dfw->createAction( tr( "Find" ), pix, tr( "&Find..." ), CTRL + Key_F, 0, "editFindAction" ); 00154 actions.insert( tr( "Find" ), editFindAction ); 00155 00156 QAction *helpAboutAction = dfw->createAction( tr( "About" ), QIconSet(), tr( "&About" ), 0, 0, "helpAboutAction" ); 00157 actions.insert( tr( "About" ), helpAboutAction ); 00158 QAction *helpContentsAction = dfw->createAction( tr( "Contents" ), QIconSet(), tr( "&Contents..." ), 0, 0, "helpContentsAction" ); 00159 actions.insert( tr( "Contents" ), helpContentsAction ); 00160 QAction *helpIndexAction = dfw->createAction( tr( "Index" ), QIconSet(), tr( "&Index..." ), 0, 0, "helpIndexAction" ); 00161 actions.insert( tr( "Index" ), helpIndexAction ); 00162 00163 if ( checkFileMenu->isChecked() ) { 00164 dfw->addMenu( "&File", "fileMenu" ); 00165 dfw->addMenuAction( "fileMenu", fileNewAction ); 00166 dfw->addMenuAction( "fileMenu", fileOpenAction ); 00167 dfw->addMenuAction( "fileMenu", fileSaveAction ); 00168 dfw->addMenuAction( "fileMenu", fileSaveAsAction ); 00169 dfw->addMenuSeparator( "fileMenu" ); 00170 dfw->addMenuAction( "fileMenu", filePrintAction ); 00171 dfw->addMenuSeparator( "fileMenu" ); 00172 dfw->addMenuAction( "fileMenu", fileExitAction ); 00173 dfw->addAction( fileNewAction ); 00174 dfw->addAction( fileOpenAction ); 00175 dfw->addAction( fileSaveAction ); 00176 dfw->addAction( fileSaveAsAction ); 00177 dfw->addAction( filePrintAction ); 00178 dfw->addAction( fileExitAction ); 00179 usedActions.append( fileNewAction ); 00180 usedActions.append( fileOpenAction ); 00181 usedActions.append( fileSaveAction ); 00182 usedActions.append( fileSaveAsAction ); 00183 usedActions.append( filePrintAction ); 00184 usedActions.append( fileExitAction ); 00185 } 00186 00187 if ( checkEditMenu->isChecked() ) { 00188 dfw->addMenu( "&Edit", "editMenu" ); 00189 dfw->addMenuAction( "editMenu", editUndoAction ); 00190 dfw->addMenuAction( "editMenu", editRedoAction ); 00191 dfw->addMenuSeparator( "editMenu" ); 00192 dfw->addMenuAction( "editMenu", editCutAction ); 00193 dfw->addMenuAction( "editMenu", editCopyAction ); 00194 dfw->addMenuAction( "editMenu", editPasteAction ); 00195 dfw->addMenuSeparator( "editMenu" ); 00196 dfw->addMenuAction( "editMenu", editFindAction ); 00197 dfw->addAction( editUndoAction ); 00198 dfw->addAction( editRedoAction ); 00199 dfw->addAction( editCutAction ); 00200 dfw->addAction( editCopyAction ); 00201 dfw->addAction( editPasteAction ); 00202 dfw->addAction( editFindAction ); 00203 usedActions.append( editUndoAction ); 00204 usedActions.append( editRedoAction ); 00205 usedActions.append( editCutAction ); 00206 usedActions.append( editCopyAction ); 00207 usedActions.append( editPasteAction ); 00208 usedActions.append( editFindAction ); 00209 } 00210 00211 if ( checkHelpMenu->isChecked() ) { 00212 dfw->addMenu( "&Help", "helpMenu" ); 00213 dfw->addMenuAction( "helpMenu", helpContentsAction ); 00214 dfw->addMenuAction( "helpMenu", helpIndexAction ); 00215 dfw->addMenuSeparator( "helpMenu" ); 00216 dfw->addMenuAction( "helpMenu", helpAboutAction ); 00217 dfw->addAction( helpContentsAction ); 00218 dfw->addAction( helpIndexAction ); 00219 dfw->addAction( helpAboutAction ); 00220 usedActions.append( helpIndexAction ); 00221 usedActions.append( helpContentsAction ); 00222 usedActions.append( helpAboutAction ); 00223 } 00224 00225 if ( listToolbar->count() > 0 && appropriate( toolbarsPage ) ) { 00226 dfw->addToolBar( "Tools", "toolBar" ); 00227 for ( int i = 0; i < (int)listToolbar->count(); ++i ) { 00228 if ( listToolbar->text( i ) == tr( "<Separator>" ) ) { 00229 dfw->addToolBarSeparator( "toolBar" ); 00230 continue; 00231 } 00232 QAction *a = actions.find( listToolbar->text( i ) ); 00233 if ( !a ) 00234 continue; 00235 dfw->addToolBarAction( "toolBar", a ); 00236 dfw->addAction( a ); 00237 if ( usedActions.findRef( a ) == -1 ) 00238 usedActions.append( a ); 00239 } 00240 } 00241 for ( QAction *ac = usedActions.first(); ac; ac = usedActions.next() ) { 00242 if ( QString( ac->name() ).find( "file" ) != -1 && checkCreateConnectionsFile->isChecked() || 00243 QString( ac->name() ).find( "edit" ) != -1 && checkCreateConnectionsEdit->isChecked() || 00244 QString( ac->name() ).find( "help" ) != -1 && checkCreateConnectionsHelp->isChecked() ) { 00245 QString slot = ac->name(); 00246 slot.remove( slot.length() - 6, 6 ); 00247 slot += "()"; 00248 dfw->addFunction( slot.latin1(), "virtual", "public", "slot", dIface->currentProject()->language(), "void" ); 00249 dfw->addConnection( ac, "activated()", widget, slot ); 00250 } 00251 } 00252 00253 qInstallMsgHandler( oldMsgHandler ); 00254 00255 QWizard::accept(); 00256 } 00257 00258 void MainWindowWizardBase::currentToolbarChanged( const QString & s ) 00259 { 00260 if ( s == tr( "File" ) ) { 00261 listToolbarActions->clear(); 00262 listToolbarActions->insertItem( tr( "New" ) ); 00263 listToolbarActions->insertItem( tr( "Open" ) ); 00264 listToolbarActions->insertItem( tr( "Save" ) ); 00265 listToolbarActions->insertItem( tr( "Save As" ) ); 00266 listToolbarActions->insertItem( tr( "Print" ) ); 00267 listToolbarActions->insertItem( tr( "Exit" ) ); 00268 } else if ( s == tr( "Edit" ) ) { 00269 listToolbarActions->clear(); 00270 listToolbarActions->insertItem( tr( "Undo" ) ); 00271 listToolbarActions->insertItem( tr( "Redo" ) ); 00272 listToolbarActions->insertItem( tr( "Cut" ) ); 00273 listToolbarActions->insertItem( tr( "Copy" ) ); 00274 listToolbarActions->insertItem( tr( "Paste" ) ); 00275 listToolbarActions->insertItem( tr( "Find" ) ); 00276 } else if ( s == tr( "Help" ) ) { 00277 listToolbarActions->clear(); 00278 listToolbarActions->insertItem( tr( "Contents" ) ); 00279 listToolbarActions->insertItem( tr( "Index" ) ); 00280 listToolbarActions->insertItem( tr( "About" ) ); 00281 } 00282 listToolbarActions->insertItem( "<Separator>" ); 00283 listToolbarActions->setCurrentItem( 0 ); 00284 } 00285 00286 void MainWindowWizardBase::getPixmap( const QString & n, QPixmap & pix ) 00287 { 00288 QString name = n + ".png"; 00289 pix = QPixmap::fromMimeSource( name ); 00290 DesignerProject *pro = dIface->currentProject(); 00291 if ( !pro || pro->projectName() == "<No Project>" ) 00292 return; 00293 pro->pixmapCollection()->addPixmap( pix, n, FALSE ); 00294 } 00295 00296 void MainWindowWizardBase::pageSelected( const QString & ) 00297 { 00298 if ( currentPage() == toolbarsPage ) { 00299 comboToolbar->clear(); 00300 setupToolbarPage(); 00301 listToolbarActions->clear(); 00302 currentToolbarChanged( comboToolbar->text( comboToolbar->currentItem() ) ); 00303 } 00304 } 00305 00306 void MainWindowWizardBase::setAppInterface( QUnknownInterface * iface, DesignerFormWindow * fw, QWidget * w ) 00307 { 00308 DesignerInterface *d = 0; 00309 iface->queryInterface( IID_Designer, (QUnknownInterface**)&d ); 00310 dIface = d; 00311 dfw = fw; 00312 widget = w; 00313 } 00314