00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "uml.h"
00014
00015
00016 #include <qclipboard.h>
00017 #include <qpopupmenu.h>
00018 #include <qtimer.h>
00019 #include <qwidgetstack.h>
00020 #include <qslider.h>
00021 #include <qregexp.h>
00022 #include <qtoolbutton.h>
00023
00024
00025 #include <kaction.h>
00026 #include <kapplication.h>
00027 #include <kconfig.h>
00028 #include <kcursor.h>
00029 #include <kdebug.h>
00030 #include <kfiledialog.h>
00031 #include <kiconloader.h>
00032 #include <klocale.h>
00033 #include <kprinter.h>
00034 #include <kmenubar.h>
00035 #include <kmessagebox.h>
00036 #include <kstandarddirs.h>
00037 #include <kstatusbar.h>
00038 #include <ktip.h>
00039 #include <ktabwidget.h>
00040 #include <ktoolbarbutton.h>
00041 #include <kpopupmenu.h>
00042
00043
00044 #include "aligntoolbar.h"
00045 #include "codeimport/classimport.h"
00046 #include "docwindow.h"
00047 #include "codegenerator.h"
00048 #include "codegenerationpolicy.h"
00049 #include "codegenerators/codegenfactory.h"
00050 #include "codegenerators/codegenpolicyext.h"
00051 #include "optionstate.h"
00052 #include "widget_utils.h"
00053 #include "umldoc.h"
00054 #include "umllistview.h"
00055 #include "umlviewlist.h"
00056 #include "worktoolbar.h"
00057 #ifdef HAVE_DOT
00058 # include "autolayout/autolayoutdlg.h"
00059 #endif
00060 #include "model_utils.h"
00061 #include "clipboard/umlclipboard.h"
00062 #include "dialogs/classwizard.h"
00063 #include "dialogs/codegenerationwizard.h"
00064 #include "dialogs/codeviewerdialog.h"
00065 #include "dialogs/diagramprintpage.h"
00066
00067 #include "refactoring/refactoringassistant.h"
00068 #include "codegenerators/simplecodegenerator.h"
00069 #include "umlviewimageexporter.h"
00070 #include "umlviewimageexporterall.h"
00071
00072 #include "kplayerslideraction.h"
00073
00074 #include "configurable.h"
00075
00076 #include "cmdlineexportallviewsevent.h"
00077
00078 #include "docgenerators/docbookgenerator.h"
00079 #include "docgenerators/xhtmlgenerator.h"
00080
00081 UMLApp::UMLApp(QWidget* , const char* name):KDockMainWindow(0, name) {
00082 s_instance = this;
00083 m_pDocWindow = 0;
00084 m_config = kapp->config();
00085 m_listView = 0;
00086 m_langSelect = NULL;
00087 m_zoomSelect = NULL;
00088 m_loading = false;
00089 m_clipTimer = 0;
00090 m_copyTimer = 0;
00091 m_codegen = 0;
00092 m_policyext = 0;
00093 m_commoncodegenpolicy = 0;
00094 m_xhtmlGenerator = 0;
00095 m_activeLanguage = Uml::pl_Reserved;
00097
00098 readOptionState();
00099 m_doc = new UMLDoc();
00100 m_doc->init();
00101 initActions();
00102 initView();
00103 initClip();
00104 readOptions();
00106
00107 fileSave->setEnabled(true);
00108 fileSaveAs->setEnabled(true);
00109 enablePrint(false);
00110 editCut->setEnabled(false);
00111 editCopy->setEnabled(false);
00112 editPaste->setEnabled(false);
00113 editUndo->setEnabled(false);
00114 editRedo->setEnabled(false);
00115
00116
00117 QPopupMenu* menu = findMenu( menuBar(), QString("code") );
00118 m_langSelect = findMenu( menu, QString("active_lang_menu") );
00119
00120
00121
00122 if (m_langSelect == NULL) {
00123 m_langSelect = new QPopupMenu(this);
00124 }
00125
00126 menu = findMenu( menuBar(), QString("views") );
00127 m_zoomSelect = findMenu( menu, QString("zoom_menu") );
00128
00129
00130
00131 if (m_zoomSelect == NULL) {
00132 m_zoomSelect = new QPopupMenu(this);
00133 }
00134
00135
00136 m_zoomSelect->setCheckable(true);
00137 connect(m_zoomSelect,SIGNAL(aboutToShow()),this,SLOT(setupZoomMenu()));
00138 connect(m_zoomSelect,SIGNAL(activated(int)),this,SLOT(setZoom(int)));
00139
00140 m_refactoringAssist = 0L;
00141
00142 m_commoncodegenpolicy = new CodeGenerationPolicy(m_config);
00143
00144 m_imageExporterAll = new UMLViewImageExporterAll();
00145 }
00146
00147 UMLApp::~UMLApp() {
00148 delete m_imageExporterAll;
00149
00150 delete m_clipTimer;
00151 delete m_copyTimer;
00152
00153 delete m_statusLabel;
00154 delete m_refactoringAssist;
00155 }
00156
00157 UMLApp* UMLApp::app()
00158 {
00159 return s_instance;
00160 }
00161
00162 void UMLApp::initActions() {
00163 fileNew = KStdAction::openNew(this, SLOT(slotFileNew()), actionCollection());
00164 fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
00165 fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection());
00166 fileSave = KStdAction::save(this, SLOT(slotFileSave()), actionCollection());
00167 fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection());
00168 fileClose = KStdAction::close(this, SLOT(slotFileClose()), actionCollection());
00169 filePrint = KStdAction::print(this, SLOT(slotFilePrint()), actionCollection());
00170 fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
00171 editUndo = KStdAction::undo(this, SLOT(slotEditUndo()), actionCollection());
00172 editRedo = KStdAction::redo(this, SLOT(slotEditRedo()), actionCollection());
00173 editCut = KStdAction::cut(this, SLOT(slotEditCut()), actionCollection());
00174 editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), actionCollection());
00175 editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), actionCollection());
00176 createStandardStatusBarAction();
00177 setStandardToolBarMenuEnabled(true);
00178 selectAll = KStdAction::selectAll(this, SLOT( slotSelectAll() ), actionCollection());
00179 fileExportDocbook = new KAction(i18n("&Export model to DocBook"), 0,
00180 this, SLOT( slotFileExportDocbook() ),
00181 actionCollection(), "file_export_docbook");
00182 fileExportXhtml = new KAction(i18n("&Export model to XHTML"), 0,
00183 this, SLOT( slotFileExportXhtml() ),
00184 actionCollection(), "file_export_xhtml");
00185
00186 classWizard = new KAction(i18n("&New Class Wizard..."),0,this,SLOT(slotClassWizard()),
00187 actionCollection(),"class_wizard");
00188 new KAction(i18n("&Add Default Datatypes for Active Language"), 0, this,
00189 SLOT(slotAddDefaultDatatypes()), actionCollection(), "create_default_datatypes");
00190
00191 preferences = KStdAction::preferences(this, SLOT( slotPrefs() ), actionCollection());
00192
00193 genWizard = new KAction(i18n("&Code Generation Wizard..."),0,this,SLOT(generationWizard()),
00194 actionCollection(),"generation_wizard");
00195 genAll = new KAction(i18n("&Generate All Code"),0,this,SLOT(generateAllCode()),
00196 actionCollection(),"generate_all");
00197
00198 importClasses = new KAction(i18n("&Import Classes..."), SmallIconSet("source_cpp"), 0,
00199 this,SLOT(slotImportClasses()), actionCollection(),"import_class");
00200
00201 fileNew->setToolTip(i18n("Creates a new document"));
00202 fileOpen->setToolTip(i18n("Opens an existing document"));
00203 fileOpenRecent->setToolTip(i18n("Opens a recently used file"));
00204 fileSave->setToolTip(i18n("Saves the document"));
00205 fileSaveAs->setToolTip(i18n("Saves the document as..."));
00206 fileClose->setToolTip(i18n("Closes the document"));
00207 filePrint ->setToolTip(i18n("Prints out the document"));
00208 fileQuit->setToolTip(i18n("Quits the application"));
00209 fileExportDocbook->setToolTip(i18n("Exports the model to the docbook format"));
00210 fileExportXhtml->setToolTip(i18n("Exports the model to the XHTML format"));
00211 editCut->setToolTip(i18n("Cuts the selected section and puts it to the clipboard"));
00212 editCopy->setToolTip(i18n("Copies the selected section to the clipboard"));
00213 editPaste->setToolTip(i18n("Pastes the contents of the clipboard"));
00214 preferences->setToolTip( i18n( "Set the default program preferences") );
00215
00216 deleteSelectedWidget = new KAction( i18n("Delete &Selected"),
00217 SmallIconSet("editdelete"),
00218 KShortcut(Qt::Key_Delete), this,
00219 SLOT( slotDeleteSelectedWidget() ), actionCollection(),
00220 "delete_selected" );
00221
00222
00223 newDiagram = new KActionMenu(0, SmallIconSet("filenew"), actionCollection(), "new_view");
00224 classDiagram = new KAction( i18n( "&Class Diagram..." ), SmallIconSet("umbrello_diagram_class"), 0,
00225 this, SLOT( slotClassDiagram() ), actionCollection(), "new_class_diagram" );
00226
00227 #if defined (HAVE_DOT)
00228 autolayout = new KAction(i18n("&Autolayout..."),0,0,this,SLOT(slotAutolayout()),
00229 actionCollection(),"autolayout");
00230 #endif
00231 sequenceDiagram= new KAction( i18n( "&Sequence Diagram..." ), SmallIconSet("umbrello_diagram_sequence"), 0,
00232 this, SLOT( slotSequenceDiagram() ), actionCollection(), "new_sequence_diagram" );
00233
00234 collaborationDiagram = new KAction( i18n( "C&ollaboration Diagram..." ), SmallIconSet("umbrello_diagram_collaboration"), 0,
00235 this, SLOT( slotCollaborationDiagram() ), actionCollection(), "new_collaboration_diagram" );
00236
00237 useCaseDiagram= new KAction( i18n( "&Use Case Diagram..." ), SmallIconSet("umbrello_diagram_usecase"), 0,
00238 this, SLOT( slotUseCaseDiagram() ), actionCollection(), "new_use_case_diagram" );
00239
00240 stateDiagram= new KAction( i18n( "S&tate Diagram..." ), SmallIconSet("umbrello_diagram_state"), 0,
00241 this, SLOT( slotStateDiagram() ), actionCollection(), "new_state_diagram" );
00242
00243 activityDiagram= new KAction( i18n( "&Activity Diagram..." ), SmallIconSet("umbrello_diagram_activity"), 0,
00244 this, SLOT( slotActivityDiagram() ), actionCollection(), "new_activity_diagram" );
00245
00246 componentDiagram = new KAction( i18n("Co&mponent Diagram..."), SmallIconSet("umbrello_diagram_component"), 0,
00247 this, SLOT( slotComponentDiagram() ), actionCollection(),
00248 "new_component_diagram" );
00249
00250 deploymentDiagram = new KAction( i18n("&Deployment Diagram..."), SmallIconSet("umbrello_diagram_deployment"), 0,
00251 this, SLOT( slotDeploymentDiagram() ), actionCollection(),
00252 "new_deployment_diagram" );
00253
00254 entityRelationshipDiagram = new KAction( i18n("&Entity Relationship Diagram..."), SmallIconSet("umbrello_diagram_entityrelationship"), 0,
00255 this, SLOT( slotEntityRelationshipDiagram() ), actionCollection(),
00256 "new_entityrelationship_diagram" );
00257
00258 viewClearDiagram = new KAction(i18n("&Clear Diagram"), SmallIconSet("editclear"), 0,
00259 this, SLOT( slotCurrentViewClearDiagram() ), actionCollection(), "view_clear_diagram");
00260 viewSnapToGrid = new KToggleAction(i18n("&Snap to Grid"), 0,
00261 this, SLOT( slotCurrentViewToggleSnapToGrid() ), actionCollection(), "view_snap_to_grid");
00262 viewShowGrid = new KToggleAction(i18n("S&how Grid"), 0,
00263 this, SLOT( slotCurrentViewToggleShowGrid() ), actionCollection(), "view_show_grid");
00264 #if (KDE_VERSION_MINOR>=3) && (KDE_VERSION_MAJOR>=3)
00265 viewShowGrid->setCheckedState(i18n("&Hide Grid"));
00266 #endif
00267 deleteDiagram = new KAction(i18n("&Delete"), SmallIconSet("editdelete"), 0,
00268 this, SLOT( slotDeleteDiagram() ), actionCollection(), "view_delete");
00269 viewExportImage = new KAction(i18n("&Export as Picture..."), SmallIconSet("image"), 0,
00270 this, SLOT( slotCurrentViewExportImage() ), actionCollection(), "view_export_image");
00271 viewExportImageAll = new KAction(i18n("Export &All Diagrams as Pictures..."), SmallIconSet("image"), 0,
00272 this, SLOT( slotAllViewsExportImage() ), actionCollection(), "view_export_image_all");
00273 viewProperties = new KAction(i18n("&Properties"), SmallIconSet("info"), 0,
00274 this, SLOT( slotCurrentViewProperties() ), actionCollection(), "view_properties");
00275
00276 viewSnapToGrid->setChecked(false);
00277 viewShowGrid->setChecked(false);
00278
00279 viewClearDiagram->setEnabled(false);
00280 viewSnapToGrid->setEnabled(false);
00281 viewShowGrid->setEnabled(false);
00282 deleteDiagram->setEnabled(false);
00283 viewExportImage->setEnabled(false);
00284 viewProperties->setEnabled(false);
00285
00286 zoomAction = new KPlayerPopupSliderAction(i18n("&Zoom Slider"), "viewmag", Key_F9,
00287 this, SLOT(slotZoomSliderMoved(int)),
00288 actionCollection(), "popup_zoom");
00289 zoom100Action = new KAction(i18n( "Z&oom to 100%" ), "viewmag1", 0,
00290 this, SLOT( slotZoom100() ), actionCollection(),
00291 "zoom100");
00292
00293 KStdAction::tipOfDay( this, SLOT( tipOfTheDay() ), actionCollection() );
00294
00295 QString moveTabLeftString = i18n("&Move Tab Left");
00296 QString moveTabRightString = i18n("&Move Tab Right");
00297 moveTabLeft = new KAction(QApplication::reverseLayout() ? moveTabRightString : moveTabLeftString,
00298 QApplication::reverseLayout() ? "forward" : "back",
00299 QApplication::reverseLayout() ? Qt::CTRL+Qt::SHIFT+Qt::Key_Right : Qt::CTRL+Qt::SHIFT+Qt::Key_Left,
00300 this, SLOT(slotMoveTabLeft()), actionCollection(),
00301 "move_tab_left");
00302 moveTabRight = new KAction(QApplication::reverseLayout() ? moveTabLeftString : moveTabRightString,
00303 QApplication::reverseLayout() ? "back" : "forward",
00304 QApplication::reverseLayout() ? Qt::CTRL+Qt::SHIFT+Qt::Key_Left : Qt::CTRL+Qt::SHIFT+Qt::Key_Right,
00305 this, SLOT(slotMoveTabRight()), actionCollection(),
00306 "move_tab_right");
00307
00308 QString selectTabLeftString = i18n("Select Diagram on Left");
00309 QString selectTabRightString = i18n("Select Diagram on Right");
00310 changeTabLeft = new KAction(QApplication::reverseLayout() ? selectTabRightString : selectTabLeftString,
00311 QApplication::reverseLayout() ? Qt::SHIFT+Qt::Key_Right : Qt::SHIFT+Qt::Key_Left,
00312 this, SLOT(slotChangeTabLeft()), actionCollection(), "previous_tab");
00313 changeTabRight = new KAction(QApplication::reverseLayout() ? selectTabLeftString : selectTabRightString,
00314 QApplication::reverseLayout() ? Qt::SHIFT+Qt::Key_Left : Qt::SHIFT+Qt::Key_Right,
00315 this, SLOT(slotChangeTabRight()), actionCollection(), "next_tab");
00316
00317
00318 initStatusBar();
00319
00320
00321 #if KDE_IS_VERSION(3,2,90)
00322 setupGUI();
00323 #else
00324 createGUI();
00325 #endif
00326 QPopupMenu* menu = findMenu( menuBar(), QString("settings") );
00327 menu->insertItem(i18n("&Windows"), dockHideShowMenu(), -1, 0);
00328 }
00329
00330 void UMLApp::slotZoomSliderMoved(int value) {
00331 int zoom = (int)(value*0.01);
00332 getCurrentView()->setZoom(zoom*zoom);
00333 }
00334
00335 void UMLApp::slotZoom100() {
00336 setZoom(100);
00337 }
00338
00339 void UMLApp::setZoom(int zoom) {
00340 getCurrentView()->setZoom(zoom);
00341 }
00342
00343 void UMLApp::setupZoomMenu() {
00344 m_zoomSelect->clear();
00345
00346
00347 m_zoomSelect->insertItem(i18n(" &33%"),33);
00348 m_zoomSelect->insertItem(i18n(" &50%"),50);
00349 m_zoomSelect->insertItem(i18n(" &75%"),75);
00350 m_zoomSelect->insertItem(i18n("&100%"),100);
00351 m_zoomSelect->insertItem(i18n("1&50%"),150);
00352 m_zoomSelect->insertItem(i18n("&200%"),200);
00353 m_zoomSelect->insertItem(i18n("3&00%"),300);
00354
00355
00356 int zoom = getCurrentView()->currentZoom();
00357
00358
00359 switch(zoom){
00360 case 33:
00361 case 50:
00362 case 75:
00363 case 100:
00364 case 150:
00365 case 200:
00366 case 300:
00367 break;
00368 default:
00369 m_zoomSelect->insertSeparator();
00370 m_zoomSelect->insertItem(QString::number(zoom)+" %",zoom);
00371 }
00372 m_zoomSelect->setItemChecked(zoom, true);
00373 }
00374
00375 void UMLApp::initStatusBar() {
00376 m_statusLabel = new KStatusBarLabel( i18n("Ready."), 0, statusBar() );
00377 m_statusLabel->setFixedHeight( m_statusLabel->sizeHint().height() );
00378
00379 m_statusLabel->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
00380 m_statusLabel->setMargin( 0 );
00381 m_statusLabel->setLineWidth(0);
00382
00383 statusBar()->addWidget( m_statusLabel, 1, false );
00384
00385 m_statusLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00386
00387 connect(m_doc, SIGNAL( sigWriteToStatusBar(const QString &) ), this, SLOT( slotStatusMsg(const QString &) ));
00388 }
00389
00390 void UMLApp::initView() {
00391 setCaption(m_doc->URL().fileName(),false);
00392 m_view = NULL;
00393 toolsbar = new WorkToolBar(this, "");
00394 toolsbar->setLabel(i18n("Diagram Toolbar"));
00395 addToolBar(toolsbar, Qt::DockTop, false);
00396
00397 m_alignToolBar = new AlignToolBar(this, "");
00398 m_alignToolBar->setLabel(i18n("Alignment Toolbar"));
00399 addToolBar(m_alignToolBar, Qt::DockTop, false);
00400
00401 m_mainDock = createDockWidget("maindock", 0L, 0L, "main dock");
00402 m_newSessionButton = NULL;
00403 m_diagramMenu = NULL;
00404 m_closeDiagramButton = NULL;
00405 Settings::OptionState& optionState = Settings::getOptionState();
00406 if (optionState.generalState.tabdiagrams) {
00407 m_viewStack = NULL;
00408 m_tabWidget = new KTabWidget(m_mainDock, "tab_widget");
00409
00410 #if KDE_IS_VERSION(3,3,89)
00411 m_tabWidget->setAutomaticResizeTabs( true );
00412 #endif
00413
00414 m_newSessionButton = new KToolBarButton("tab_new", 0, m_tabWidget);
00415 m_newSessionButton->setIconSet( SmallIcon( "tab_new" ) );
00416 m_newSessionButton->adjustSize();
00417 m_newSessionButton->setAutoRaise(true);
00418 m_diagramMenu = new KPopupMenu(m_newSessionButton);
00419
00420 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_Class), i18n("Class Diagram..."), this, SLOT(slotClassDiagram()) );
00421 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_Sequence), i18n("Sequence Diagram..."), this, SLOT(slotSequenceDiagram()) );
00422 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_Collaboration), i18n("Collaboration Diagram..."), this, SLOT(slotCollaborationDiagram()) );
00423 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_UseCase), i18n("Use Case Diagram..."), this, SLOT(slotUseCaseDiagram()) );
00424 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_State), i18n("State Diagram..."), this, SLOT(slotStateDiagram()) );
00425 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_Activity), i18n("Activity Diagram..."), this, SLOT(slotActivityDiagram()) );
00426 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_Component), i18n("Component Diagram..."), this, SLOT(slotComponentDiagram()) );
00427 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_Deployment), i18n("Deployment Diagram..."), this, SLOT(slotDeploymentDiagram()) );
00428 m_diagramMenu->insertItem(Widget_Utils::iconSet(Uml::dt_EntityRelationship), i18n("Entity Relationship Diagram..."), this, SLOT(slotEntityRelationshipDiagram()) );
00429 m_newSessionButton->setPopup(m_diagramMenu);
00430
00431
00432
00433
00434 m_closeDiagramButton = new QToolButton(m_tabWidget);
00435 m_closeDiagramButton->setIconSet( SmallIcon("tab_remove") );
00436 m_closeDiagramButton->adjustSize();
00437
00438 connect(m_closeDiagramButton, SIGNAL(clicked()), SLOT(slotDeleteDiagram()));
00439 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), SLOT(slotTabChanged(QWidget*)));
00440 connect(m_tabWidget, SIGNAL(contextMenu(QWidget*,const QPoint&)), m_doc, SLOT(slotDiagramPopupMenu(QWidget*,const QPoint&)));
00441 m_tabWidget->setCornerWidget( m_newSessionButton, TopLeft );
00442 m_tabWidget->setCornerWidget( m_closeDiagramButton, TopRight );
00443 m_newSessionButton->installEventFilter(this);
00444
00445 m_mainDock->setWidget(m_tabWidget);
00446 }
00447 else
00448 {
00449 m_tabWidget = NULL;
00450 m_viewStack = new QWidgetStack(m_mainDock, "viewstack");
00451 m_mainDock->setWidget(m_viewStack);
00452 }
00453 m_mainDock->setDockSite(KDockWidget::DockCorner);
00454 m_mainDock->setEnableDocking(KDockWidget::DockNone);
00455 setView(m_mainDock);
00456 setMainDockWidget(m_mainDock);
00457
00458 m_listDock = createDockWidget( "Model", 0L, 0L, i18n("&Tree View") );
00459 m_listView = new UMLListView(m_listDock ,"LISTVIEW");
00460
00461 m_listView->setDocument(m_doc);
00462 m_listView->init();
00463 m_listDock->setWidget(m_listView);
00464 m_listDock->setDockSite(KDockWidget::DockCorner);
00465 m_listDock->manualDock(m_mainDock, KDockWidget::DockLeft, 20);
00466
00467 m_documentationDock = createDockWidget( "Documentation", 0L, 0L, i18n("&Documentation") );
00468 m_pDocWindow = new DocWindow(m_doc, m_documentationDock, "DOCWINDOW");
00469 m_documentationDock->setWidget(m_pDocWindow);
00470 m_documentationDock->setDockSite(KDockWidget::DockCorner);
00471 m_documentationDock->manualDock(m_listDock, KDockWidget::DockBottom, 80);
00472
00473 m_doc->setupSignals();
00474
00475 readDockConfig();
00476 }
00477
00478 void UMLApp::openDocumentFile(const KURL& url) {
00479 slotStatusMsg(i18n("Opening file..."));
00480
00481 m_doc->openDocument( url);
00482 fileOpenRecent->addURL( url );
00483 slotStatusMsg(i18n("Ready."));
00484 setCaption(m_doc->URL().fileName(), false);
00485 enablePrint(true);
00486 }
00487
00488 UMLDoc *UMLApp::getDocument() const {
00489 return m_doc;
00490 }
00491
00492 UMLListView* UMLApp::getListView() {
00493 return m_listView;
00494 }
00495
00496
00497 void UMLApp::saveOptions() {
00498 toolBar("mainToolBar")->saveSettings(m_config, "toolbar");
00499 toolsbar->saveSettings(m_config, "workbar");
00500 m_alignToolBar->saveSettings(m_config, "aligntoolbar");
00501 fileOpenRecent->saveEntries(m_config,"Recent Files");
00502 m_config->setGroup( "General Options" );
00503 m_config->writeEntry( "Geometry", size() );
00504
00505 Settings::OptionState& optionState = Settings::getOptionState();
00506 m_config->writeEntry( "undo", optionState.generalState.undo );
00507 m_config->writeEntry( "tabdiagrams", optionState.generalState.tabdiagrams );
00508 m_config->writeEntry( "newcodegen", optionState.generalState.newcodegen );
00509 m_config->writeEntry( "angularlines", optionState.generalState.angularlines );
00510 m_config->writeEntry( "autosave", optionState.generalState.autosave );
00511 m_config->writeEntry( "time", optionState.generalState.time );
00512 m_config->writeEntry( "autosavetime", optionState.generalState.autosavetime );
00513 m_config->writeEntry( "autosavesuffix", optionState.generalState.autosavesuffix );
00514
00515 m_config->writeEntry( "logo", optionState.generalState.logo );
00516 m_config->writeEntry( "loadlast", optionState.generalState.loadlast );
00517
00518 m_config->writeEntry( "diagram", optionState.generalState.diagram );
00519 if( m_doc->URL().fileName() == i18n( "Untitled" ) ) {
00520 m_config -> writeEntry( "lastFile", "" );
00521 } else {
00522 m_config -> writePathEntry( "lastFile", m_doc -> URL().prettyURL() );
00523 }
00524 m_config->writeEntry( "imageMimeType", getImageMimeType() );
00525
00526 m_config->setGroup( "TipOfDay");
00527 optionState.generalState.tip = m_config -> readBoolEntry( "RunOnStart", true );
00528 m_config->writeEntry( "RunOnStart", optionState.generalState.tip );
00529
00530 m_config->setGroup( "UI Options" );
00531 m_config->writeEntry( "useFillColor", optionState.uiState.useFillColor );
00532 m_config->writeEntry( "fillColor", optionState.uiState.fillColor );
00533 m_config->writeEntry( "lineColor", optionState.uiState.lineColor );
00534 m_config->writeEntry( "lineWidth", optionState.uiState.lineWidth );
00535 m_config->writeEntry( "showDocWindow", m_documentationDock->isVisible() );
00536 m_config->writeEntry( "font", optionState.uiState.font );
00537
00538 m_config->setGroup( "Class Options" );
00539 m_config->writeEntry( "showVisibility", optionState.classState.showVisibility );
00540 m_config->writeEntry( "showAtts", optionState.classState.showAtts);
00541 m_config->writeEntry( "showOps", optionState.classState.showOps );
00542 m_config->writeEntry( "showStereoType", optionState.classState.showStereoType );
00543 m_config->writeEntry( "showAttSig", optionState.classState.showAttSig );
00544 m_config->writeEntry( "ShowOpSig", optionState.classState.showOpSig );
00545 m_config->writeEntry( "showPackage", optionState.classState.showPackage );
00546 m_config->writeEntry( "defaultAttributeScope", optionState.classState.defaultAttributeScope);
00547 m_config->writeEntry( "defaultOperationScope", optionState.classState.defaultOperationScope);
00548
00549 m_config -> setGroup( "Code Viewer Options" );
00550 m_config->writeEntry( "height", optionState.codeViewerState.height );
00551 m_config->writeEntry( "width", optionState.codeViewerState.width);
00552 m_config->writeEntry( "font", optionState.codeViewerState.font);
00553 m_config->writeEntry( "fontColor", optionState.codeViewerState.fontColor);
00554 m_config->writeEntry( "paperColor", optionState.codeViewerState.paperColor);
00555 m_config->writeEntry( "selectedColor", optionState.codeViewerState.selectedColor);
00556 m_config->writeEntry( "editBlockColor", optionState.codeViewerState.editBlockColor);
00557 m_config->writeEntry( "nonEditBlockColor", optionState.codeViewerState.nonEditBlockColor);
00558 m_config->writeEntry( "umlObjectBlockColor", optionState.codeViewerState.umlObjectColor);
00559 m_config->writeEntry( "blocksAreHighlighted", optionState.codeViewerState.blocksAreHighlighted);
00560 m_config->writeEntry( "showHiddenBlocks", optionState.codeViewerState.showHiddenBlocks);
00561 m_config->writeEntry( "hiddenColor", optionState.codeViewerState.hiddenColor);
00562
00563
00564 if (m_policyext)
00565 m_policyext->writeConfig(m_config);
00566
00567
00568 m_commoncodegenpolicy->writeConfig(m_config);
00569
00570
00571 if (m_codegen) {
00572 m_config->setGroup("Code Generation");
00573 m_config->writeEntry("activeLanguage", Model_Utils::progLangToString(m_codegen->getLanguage()));
00574 }
00575 }
00576
00577 void UMLApp::readOptions() {
00578
00579 toolBar("mainToolBar")->applySettings(m_config, "toolbar");
00580
00581 toolsbar->applySettings(m_config, "workbar");
00582 m_alignToolBar->applySettings(m_config, "aligntoolbar");
00583 fileOpenRecent->loadEntries(m_config,"Recent Files");
00584 m_config->setGroup("General Options");
00585 setImageMimeType(m_config->readEntry("imageMimeType","image/png"));
00586 QSize tmpQSize(630,460);
00587 resize( m_config->readSizeEntry("Geometry", & tmpQSize) );
00588 }
00589
00590 void UMLApp::saveProperties(KConfig *_config) {
00591 if(m_doc->URL().fileName()!=i18n("Untitled") && !m_doc->isModified()) {
00592
00593
00594 } else {
00595 KURL url=m_doc->URL();
00596 _config->writePathEntry("filename", url.url());
00597 _config->writeEntry("modified", m_doc->isModified());
00598 QString tempname = kapp->tempSaveName(url.url());
00599 QString tempurl= KURL::encode_string(tempname);
00600
00601 KURL _url(tempurl);
00602 m_doc->saveDocument(_url);
00603 }
00604 }
00605
00606 void UMLApp::readProperties(KConfig* _config) {
00607 QString filename = _config->readPathEntry("filename");
00608 KURL url(filename);
00609 bool modified = _config->readBoolEntry("modified", false);
00610 if(modified) {
00611 bool canRecover;
00612 QString tempname = kapp->checkRecoverFile(filename, canRecover);
00613 KURL _url(tempname);
00614
00615
00616 if(canRecover) {
00617 m_doc->openDocument(_url);
00618 m_doc->setModified();
00619 enablePrint(true);
00620 setCaption(_url.fileName(),true);
00621 QFile::remove
00622 (tempname);
00623 } else {
00624 enablePrint(false);
00625 }
00626 } else {
00627 if(!filename.isEmpty()) {
00628 m_doc->openDocument(url);
00629 enablePrint(true);
00630 setCaption(url.fileName(),false);
00631
00632 } else {
00633 enablePrint(false);
00634 }
00635 }
00636 }
00637
00638 bool UMLApp::queryClose() {
00639 writeDockConfig();
00640 return m_doc->saveModified();
00641 }
00642
00643 bool UMLApp::queryExit() {
00644 saveOptions();
00645 m_doc -> closeDocument();
00646 return true;
00647 }
00648
00649 void UMLApp::slotFileNew() {
00650 slotStatusMsg(i18n("Creating new document..."));
00651 if(m_doc->saveModified()) {
00652 setDiagramMenuItemsState(false);
00653 m_doc->newDocument();
00654 setCaption(m_doc->URL().fileName(), false);
00655 fileOpenRecent->setCurrentItem( -1 );
00656 setModified(false);
00657 enablePrint(false);
00658 }
00659 slotUpdateViews();
00660 slotStatusMsg(i18n("Ready."));
00661 }
00662
00663 void UMLApp::slotFileOpen() {
00664 slotStatusMsg(i18n("Opening file..."));
00665 m_loading = true;
00666
00667 if(!m_doc->saveModified()) {
00668
00669
00670
00671 } else {
00672 KURL url=KFileDialog::getOpenURL(":open-umbrello-file",
00673 i18n("*.xmi *.xmi.tgz *.xmi.tar.bz2 *.mdl|All Supported Files (*.xmi, *.xmi.tgz, *.xmi.tar.bz2, *.mdl)\n"
00674 "*.xmi|Uncompressed XMI Files (*.xmi)\n"
00675 "*.xmi.tgz|Gzip Compressed XMI Files (*.xmi.tgz)\n"
00676 "*.xmi.tar.bz2|Bzip2 Compressed XMI Files (*.xmi.tar.bz2)\n"
00677 "*.mdl|Rose model files"), this, i18n("Open File"));
00678 if(!url.isEmpty()) {
00679 if(m_doc->openDocument(url))
00680 fileOpenRecent->addURL( url );
00681 enablePrint(true);
00682 setCaption(m_doc->URL().fileName(), false);
00683 }
00684
00685 }
00686 slotUpdateViews();
00687 m_loading = false;
00688 slotStatusMsg(i18n("Ready."));
00689 }
00690
00691 void UMLApp::slotFileOpenRecent(const KURL& url) {
00692 slotStatusMsg(i18n("Opening file..."));
00693 m_loading = true;
00694
00695 KURL oldURL = m_doc->URL();
00696
00697 if(!m_doc->saveModified()) {
00698
00699 } else {
00700 if(!m_doc->openDocument(url)) {
00701 fileOpenRecent->removeURL(url);
00702 fileOpenRecent->setCurrentItem( -1 );
00703 } else {
00704 fileOpenRecent->addURL(url);
00705 }
00706 enablePrint(true);
00707 setCaption(m_doc->URL().fileName(), false);
00708 }
00709
00710 m_loading = false;
00711 slotUpdateViews();
00712 slotStatusMsg(i18n("Ready."));
00713 }
00714
00715 void UMLApp::slotFileSave() {
00716 slotStatusMsg(i18n("Saving file..."));
00717 if(m_doc->URL().fileName() == i18n("Untitled"))
00718 slotFileSaveAs();
00719 else
00720 m_doc->saveDocument(m_doc -> URL());
00721
00722 slotStatusMsg(i18n("Ready."));
00723 }
00724
00725 bool UMLApp::slotFileSaveAs()
00726 {
00727 slotStatusMsg(i18n("Saving file with a new filename..."));
00728 bool cont = true;
00729 KURL url;
00730 QString ext;
00731 while(cont) {
00732 url=KFileDialog::getSaveURL(":save-umbrello-file", i18n("*.xmi|XMI File\n*.xmi.tgz|Gzip Compressed XMI File\n*.xmi.tar.bz2|Bzip2 Compressed XMI File\n*|All Files"), this, i18n("Save As"));
00733
00734 if(url.isEmpty())
00735 cont = false;
00736 else {
00737
00738 QString file = url.path(-1);
00739 QFileInfo info(file);
00740 ext = info.extension();
00741 if (ext != "xmi" && ext != "xmi.tgz" && ext != "xmi.tar.bz2")
00742 {
00743 url.setFileName(url.fileName() + ".xmi");
00744 ext = "xmi";
00745 }
00746 QDir d = url.path(-1);
00747
00748 if(QFile::exists(d.path())) {
00749 int want_save = KMessageBox::warningContinueCancel(this, i18n("The file %1 exists.\nDo you wish to overwrite it?").arg(url.path()), i18n("Warning"), i18n("Overwrite"));
00750 if(want_save == KMessageBox::Continue)
00751 cont = false;
00752 } else
00753 cont = false;
00754
00755 }
00756 }
00757 if(!url.isEmpty()) {
00758 bool b = m_doc->saveDocument(url);
00759 if (b) {
00760 fileOpenRecent->addURL(url);
00761 setCaption(url.fileName(),m_doc->isModified());
00762 slotStatusMsg(i18n("Ready."));
00763 }
00764 return b;
00765
00766 } else {
00767 slotStatusMsg(i18n("Ready."));
00768 return false;
00769 }
00770 }
00771
00772 void UMLApp::slotFileClose() {
00773 slotStatusMsg(i18n("Closing file..."));
00774
00775 slotFileNew();
00776
00777 }
00778
00779 void UMLApp::slotFilePrint()
00780 {
00781 slotStatusMsg(i18n("Printing..."));
00782
00783 KPrinter printer;
00784 printer.setFullPage(true);
00785 DiagramPrintPage * selectPage = new DiagramPrintPage(0, m_doc);
00786 printer.addDialogPage(selectPage);
00787 QString msg;
00788 if (printer.setup(this, i18n("Print %1").arg(m_doc->URL().prettyURL()))) {
00789
00790 m_doc -> print(&printer);
00791 }
00792 slotStatusMsg(i18n("Ready."));
00793 }
00794
00795 void UMLApp::slotFileQuit() {
00796 slotStatusMsg(i18n("Exiting..."));
00797 if(m_doc->saveModified()) {
00798 writeDockConfig();
00799 saveOptions();
00800 kapp->quit();
00801 }
00802 slotStatusMsg(i18n("Ready."));
00803 }
00804
00805 void UMLApp::slotFileExportDocbook()
00806 {
00807 DocbookGenerator().generateDocbookForProject();
00808 }
00809
00810 void UMLApp::slotFileExportXhtml()
00811 {
00812 if (m_xhtmlGenerator != 0)
00813 {
00814 return;
00815 }
00816 m_xhtmlGenerator = new XhtmlGenerator();
00817 m_xhtmlGenerator->generateXhtmlForProject();
00818 connect(m_xhtmlGenerator,SIGNAL(finished()),this,SLOT(slotXhtmlDocGenerationFinished()));
00819 }
00820
00821 void UMLApp::slotEditUndo() {
00822 m_doc->loadUndoData();
00823 slotStatusMsg(i18n("Ready."));
00824 }
00825
00826 void UMLApp::slotEditRedo() {
00827 m_doc->loadRedoData();
00828 slotStatusMsg(i18n("Ready."));
00829 }
00830
00831 void UMLApp::slotEditCut() {
00832 slotStatusMsg(i18n("Cutting selection..."));
00833
00834
00835 bool fromview = (getCurrentView() && getCurrentView()->getSelectCount());
00836 if ( editCutCopy(fromview) ) {
00837 emit sigCutSuccessful();
00838 slotDeleteSelectedWidget();
00839 m_doc->setModified(true);
00840 }
00841 slotStatusMsg(i18n("Ready."));
00842 }
00843
00844 void UMLApp::slotEditCopy() {
00845 slotStatusMsg(i18n("Copying selection to clipboard..."));
00846 bool fromview = (getCurrentView() && getCurrentView()->getSelectCount());
00847 editCutCopy( fromview );
00848 slotStatusMsg(i18n("Ready."));
00849 m_doc -> setModified( true );
00850 }
00851
00852 void UMLApp::slotEditPaste() {
00853 slotStatusMsg(i18n("Inserting clipboard contents..."));
00854 QMimeSource* data = QApplication::clipboard()->data();
00855 UMLClipboard clipboard;
00856 setCursor(KCursor::waitCursor());
00857 if(!clipboard.paste(data)) {
00858 KMessageBox::sorry( this, i18n("Umbrello could not paste the clipboard contents. "
00859 "The objects in the clipboard may be of the wrong "
00860 "type to be pasted here."), i18n("Paste Error") );
00861 }
00862 slotStatusMsg(i18n("Ready."));
00863 setCursor(KCursor::arrowCursor());
00864 editPaste->setEnabled(false);
00865 m_doc -> setModified( true );
00866 }
00867
00868
00869
00870
00871 void UMLApp::slotViewToolBar() {
00872 slotStatusMsg(i18n("Toggling toolbar..."));
00873
00875
00876
00877 if(!viewToolBar->isChecked()) {
00878 toolBar("mainToolBar")->hide();
00879 } else {
00880 toolBar("mainToolBar")->show();
00881 }
00882
00883 slotStatusMsg(i18n("Ready."));
00884 }
00885
00886 void UMLApp::slotViewStatusBar() {
00887 slotStatusMsg(i18n("Toggle the statusbar..."));
00889
00890 if(!viewStatusBar->isChecked()) {
00891 statusBar()->hide();
00892 } else {
00893 statusBar()->show();
00894 }
00895
00896 slotStatusMsg(i18n("Ready."));
00897 }
00898
00899
00900
00901 void UMLApp::slotStatusMsg(const QString &text) {
00903
00904 statusBar()->clear();
00905 m_statusLabel->setText( text );
00906
00907 m_statusLabel->repaint();
00908 }
00909
00910 void UMLApp::slotClassDiagram() {
00911 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Logical);
00912 getDocument()->createDiagram(root, Uml::dt_Class);
00913 }
00914
00915
00916 void UMLApp::slotSequenceDiagram() {
00917 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Logical);
00918 m_doc->createDiagram(root, Uml::dt_Sequence);
00919 }
00920
00921 void UMLApp::slotCollaborationDiagram() {
00922 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Logical);
00923 m_doc->createDiagram(root, Uml::dt_Collaboration);
00924 }
00925
00926 void UMLApp::slotUseCaseDiagram() {
00927 UMLFolder *root = m_doc->getRootFolder(Uml::mt_UseCase);
00928 m_doc->createDiagram(root, Uml::dt_UseCase);
00929 }
00930
00931 void UMLApp::slotStateDiagram() {
00932 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Logical);
00933 m_doc->createDiagram(root, Uml::dt_State);
00934 }
00935
00936 void UMLApp::slotActivityDiagram() {
00937 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Logical);
00938 m_doc->createDiagram(root, Uml::dt_Activity);
00939 }
00940
00941 void UMLApp::slotComponentDiagram() {
00942 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Component);
00943 m_doc->createDiagram(root, Uml::dt_Component );
00944 }
00945
00946 void UMLApp::slotDeploymentDiagram() {
00947 UMLFolder *root = m_doc->getRootFolder(Uml::mt_Deployment);
00948 m_doc->createDiagram(root, Uml::dt_Deployment);
00949 }
00950
00951 void UMLApp::slotEntityRelationshipDiagram() {
00952 UMLFolder *root = m_doc->getRootFolder(Uml::mt_EntityRelationship);
00953 m_doc->createDiagram(root, Uml::dt_EntityRelationship);
00954 }
00955
00956 WorkToolBar* UMLApp::getWorkToolBar() {
00957 return toolsbar;
00958 }
00959
00960 void UMLApp::setModified(bool modified) {
00961
00962
00963
00964
00965
00966 if ( m_loading == false && modified == true && getCurrentView() ) {
00967 enablePrint(true);
00968 }
00969
00970 if (m_loading == false) {
00971 setCaption(m_doc->URL().fileName(), modified);
00972 }
00973 }
00974
00975 void UMLApp::enablePrint(bool enable) {
00976 filePrint->setEnabled(enable);
00977 }
00978
00979 void UMLApp::enableUndo(bool enable) {
00980 editUndo->setEnabled(enable);
00981 }
00982
00983 void UMLApp::enableRedo(bool enable) {
00984 editRedo->setEnabled(enable);
00985 }
00986
00988 void UMLApp::initClip() {
00989 QClipboard* clip = QApplication::clipboard();
00990 connect(clip, SIGNAL(dataChanged()), this, SLOT(slotClipDataChanged()));
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001 m_copyTimer = new QTimer(this, "copytimer");
01002 m_copyTimer->start(500, false);
01003 connect(m_copyTimer, SIGNAL(timeout()), this, SLOT(slotCopyChanged()));
01004 }
01005
01006 bool UMLApp::canDecode(const QMimeSource* mimeSource) {
01007 const char* f;
01008 for (int i=0; (f=mimeSource->format(i)); i++) {
01009 if ( !qstrnicmp(f,"application/x-uml-clip", 22) ) {
01010
01011
01012 return true;
01013 }
01014 }
01015 return false;
01016 }
01017
01018 void UMLApp::slotClipDataChanged() {
01019 QMimeSource * data = QApplication::clipboard()->data();
01020
01021
01022 editPaste->setEnabled( data && canDecode(data) );
01023 }
01024
01025 void UMLApp::slotCopyChanged() {
01026 if(m_listView->getSelectedCount() || (getCurrentView() && getCurrentView()->getSelectCount())) {
01027 editCopy->setEnabled(true);
01028 editCut->setEnabled(true);
01029 } else {
01030 editCopy->setEnabled(false);
01031 editCut->setEnabled(false);
01032 }
01033 }
01034
01035 void UMLApp::slotPrefs() {
01036
01037 m_config->setGroup("TipOfDay");
01038 Settings::OptionState& optionState = Settings::getOptionState();
01039 optionState.generalState.tip = m_config->readBoolEntry( "RunOnStart", true );
01040
01041 m_dlg = new SettingsDlg(this, &optionState);
01042 connect(m_dlg, SIGNAL( applyClicked() ), this, SLOT( slotApplyPrefs() ) );
01043
01044 if ( m_dlg->exec() == QDialog::Accepted && m_dlg->getChangesApplied() ) {
01045 slotApplyPrefs();
01046 }
01047
01048 delete m_dlg;
01049 m_dlg = NULL;
01050 }
01051
01052 void UMLApp::slotApplyPrefs() {
01053 if (m_dlg) {
01054
01055 m_config -> setGroup( "TipOfDay");
01056 Settings::OptionState& optionState = Settings::getOptionState();
01057 m_config -> writeEntry( "RunOnStart", optionState.generalState.tip );
01058
01059 m_doc -> settingsChanged( optionState );
01060 const QString plStr = m_dlg->getCodeGenerationLanguage();
01061 Uml::Programming_Language pl = Model_Utils::stringToProgLang(plStr);
01062 setGenerator(pl);
01063 }
01064 }
01065
01066 bool UMLApp::getUndoEnabled() {
01067 return editUndo->isEnabled();
01068 }
01069
01070 bool UMLApp::getRedoEnabled() {
01071 return editRedo->isEnabled();
01072 }
01073
01074 bool UMLApp::getPasteState() {
01075 return editPaste -> isEnabled();
01076 }
01077
01078 bool UMLApp::getCutCopyState() {
01079 return editCopy -> isEnabled();
01080 }
01081
01082 bool UMLApp::editCutCopy( bool bFromView ) {
01083 UMLClipboard clipboard;
01084 QMimeSource * clipdata = 0;
01085
01086 if ((clipdata = clipboard.copy(bFromView)) != 0) {
01087 QClipboard* clip = QApplication::clipboard();
01088 clip->setData(clipdata);
01089 connect(clip, SIGNAL(dataChanged()), this, SLOT(slotClipDataChanged()));
01090 return true;
01091 }
01092 return false;
01093 }
01094
01095 void UMLApp::readOptionState() {
01096 m_config -> setGroup( "General Options" );
01097 Settings::OptionState& optionState = Settings::getOptionState();
01098 optionState.generalState.undo = m_config -> readBoolEntry( "undo", true );
01099 optionState.generalState.tabdiagrams = m_config -> readBoolEntry("tabdiagrams", false);
01100 #if defined (WORK_ON_BUG_126262)
01101 optionState.generalState.newcodegen = m_config -> readBoolEntry("newcodegen", false);
01102 #else
01103 optionState.generalState.newcodegen = false;
01104 #endif
01105 optionState.generalState.angularlines = m_config->readBoolEntry("angularlines", false);
01106 optionState.generalState.autosave = m_config -> readBoolEntry( "autosave", true );
01107 optionState.generalState.time = m_config -> readNumEntry( "time", 0 );
01108 optionState.generalState.autosavetime = m_config -> readNumEntry( "autosavetime", 0 );
01109
01110 if (optionState.generalState.autosavetime == 0) {
01111 switch (optionState.generalState.time) {
01112 case 0: optionState.generalState.autosavetime = 5; break;
01113 case 1: optionState.generalState.autosavetime = 10; break;
01114 case 2: optionState.generalState.autosavetime = 15; break;
01115 case 3: optionState.generalState.autosavetime = 20; break;
01116 case 4: optionState.generalState.autosavetime = 25; break;
01117 default: optionState.generalState.autosavetime = 5; break;
01118 }
01119 }
01120
01121 optionState.generalState.autosavesuffix = m_config -> readEntry( "autosavesuffix", ".xmi" );
01122
01123 optionState.generalState.logo = m_config -> readBoolEntry( "logo", true );
01124 optionState.generalState.loadlast = m_config -> readBoolEntry( "loadlast", true );
01125
01126 optionState.generalState.diagram = (Uml::Diagram_Type) m_config->readNumEntry("diagram", 1);
01127 m_config -> setGroup( "TipOfDay");
01128
01129 optionState.generalState.tip = m_config -> readBoolEntry( "RunOnStart", true );
01130
01131 m_config -> setGroup( "UI Options" );
01132 optionState.uiState.useFillColor = m_config -> readBoolEntry( "useFillColor", true );
01133 QColor defaultYellow = QColor( 255, 255, 192 );
01134 QColor red ( Qt::red );
01135
01136 optionState.uiState.fillColor = m_config -> readColorEntry( "fillColor", &defaultYellow );
01137 optionState.uiState.lineColor = m_config -> readColorEntry( "lineColor", &red );
01138 optionState.uiState.lineWidth = m_config -> readNumEntry( "lineWidth", 0 );
01139 QFont font = ((QWidget *) this)->font() ;
01140 optionState.uiState.font = m_config -> readFontEntry("font", &font );
01141
01142 m_config -> setGroup( "Class Options" );
01143
01144 optionState.classState.showVisibility = m_config -> readBoolEntry("showVisibility", true);
01145 optionState.classState.showAtts = m_config -> readBoolEntry("showAtts", true);
01146 optionState.classState.showOps = m_config -> readBoolEntry("showOps", true);
01147 optionState.classState.showStereoType = m_config -> readBoolEntry("showStereoType", false);
01148 optionState.classState.showAttSig = m_config -> readBoolEntry("showAttSig", true);
01149 optionState.classState.showOpSig = m_config -> readBoolEntry("ShowOpSig", true);
01150 optionState.classState.showPackage = m_config -> readBoolEntry("showPackage", false);
01151 optionState.classState.defaultAttributeScope = (Uml::Visibility::Value) m_config -> readNumEntry("defaultAttributeScope", Uml::Visibility::Private);
01152 optionState.classState.defaultOperationScope = (Uml::Visibility::Value) m_config -> readNumEntry("defaultOperationScope", Uml::Visibility::Public);
01153
01154 m_config -> setGroup( "Code Viewer Options" );
01155
01156 QColor defaultWhite = QColor( "white" );
01157 QColor defaultBlack = QColor( "black" );
01158 QColor defaultPink = QColor( "pink" );
01159 QColor defaultGrey = QColor( "grey" );
01160
01161 optionState.codeViewerState.height = m_config -> readNumEntry( "height", 40 );
01162 optionState.codeViewerState.width = m_config -> readNumEntry( "width", 80 );
01163 optionState.codeViewerState.font = m_config -> readFontEntry("font", &font );
01164 optionState.codeViewerState.showHiddenBlocks = m_config -> readBoolEntry( "showHiddenBlocks", false);
01165 optionState.codeViewerState.blocksAreHighlighted = m_config -> readBoolEntry( "blocksAreHighlighted", false);
01166 optionState.codeViewerState.selectedColor = m_config -> readColorEntry( "selectedColor", &defaultYellow );
01167 optionState.codeViewerState.paperColor = m_config -> readColorEntry( "paperColor", &defaultWhite);
01168 optionState.codeViewerState.fontColor = m_config -> readColorEntry( "fontColor", &defaultBlack);
01169 optionState.codeViewerState.editBlockColor = m_config -> readColorEntry( "editBlockColor", &defaultPink);
01170 optionState.codeViewerState.umlObjectColor = m_config -> readColorEntry( "umlObjectBlockColor", &defaultPink);
01171 optionState.codeViewerState.nonEditBlockColor = m_config -> readColorEntry( "nonEditBlockColor", &defaultGrey);
01172 optionState.codeViewerState.hiddenColor = m_config -> readColorEntry( "hiddenColor", &defaultGrey);
01173
01174 }
01175
01176
01178 void UMLApp::viewCodeDocument(UMLClassifier* classifier) {
01179
01180 CodeGenerator * currentGen = getGenerator();
01181 if(currentGen && classifier) {
01182 if(!dynamic_cast<SimpleCodeGenerator*>(currentGen))
01183 {
01184 CodeDocument *cdoc = currentGen->findCodeDocumentByClassifier(classifier);
01185
01186 if (cdoc) {
01187 Settings::OptionState& optionState = Settings::getOptionState();
01188 CodeViewerDialog * dialog = currentGen->getCodeViewerDialog(this,cdoc,optionState.codeViewerState);
01189 dialog->exec();
01190 optionState.codeViewerState = dialog->getState();
01191 delete dialog;
01192 dialog = NULL;
01193 } else {
01194
01195 KMessageBox::sorry(0, i18n("Cannot view code until you generate some first."),i18n("Cannot View Code"));
01196 }
01197 } else {
01198 KMessageBox::sorry(0, i18n("Cannot view code from simple code writer."),i18n("Cannot View Code"));
01199 }
01200 }
01201
01202 }
01203
01204 void UMLApp::refactor(UMLClassifier* classifier) {
01205 if (!m_refactoringAssist) {
01206 m_refactoringAssist = new RefactoringAssistant( m_doc, 0, 0, "refactoring_assistant" );
01207 }
01208 m_refactoringAssist->refactor(classifier);
01209 m_refactoringAssist->show();
01210 }
01211
01212 CodeGenerationPolicy *UMLApp::getCommonPolicy() {
01213 return m_commoncodegenpolicy;
01214 }
01215
01216 void UMLApp::setPolicyExt(CodeGenPolicyExt *policy) {
01217 m_policyext = policy;
01218 }
01219
01220 CodeGenPolicyExt *UMLApp::getPolicyExt() {
01221 return m_policyext;
01222 }
01223
01224 CodeGenerator *UMLApp::setGenerator(Uml::Programming_Language pl) {
01225 if (pl == Uml::pl_Reserved) {
01226 if (m_codegen) {
01227 delete m_codegen;
01228 m_codegen = NULL;
01229 }
01230 return NULL;
01231 }
01232
01233
01234 if (m_codegen) {
01235 if (m_codegen->getLanguage() == pl)
01236 return m_codegen;
01237 delete m_codegen;
01238 m_codegen = NULL;
01239 }
01240 m_activeLanguage = pl;
01241 m_codegen = CodeGenFactory::createObject(pl);
01242 updateLangSelectMenu(pl);
01243
01244 if (m_policyext)
01245 m_policyext->setDefaults(m_config, false);
01246 return m_codegen;
01247 }
01248
01249 CodeGenerator* UMLApp::getGenerator() {
01250 return m_codegen;
01251 }
01252
01253 void UMLApp::generateAllCode() {
01254 if (m_codegen) {
01255 m_codegen->writeCodeToFile();
01256 }
01257 }
01258
01259 void UMLApp::generationWizard() {
01260 CodeGenerationWizard wizard(0 );
01261 wizard.exec();
01262 }
01263
01264 void UMLApp::setActiveLanguage(int menuId) {
01265
01266
01267 if (!m_langSelect->isItemChecked(menuId))
01268 {
01269 uint index = 0;
01270 for(unsigned int i=0; i < m_langSelect->count(); i++) {
01271 int id = m_langSelect->idAt(i);
01272 m_langSelect->setItemChecked(id, false);
01273 if (id == menuId)
01274 index = i;
01275 }
01276
01277 m_langSelect->setItemChecked(menuId,true);
01278 m_activeLanguage = (Uml::Programming_Language)index;
01279
01280
01281 setGenerator(m_activeLanguage);
01282 }
01283 }
01284
01285 void UMLApp::setActiveLanguage( const QString &activeLanguage ) {
01286
01287 for(unsigned int j=0; j < m_langSelect->count(); j++) {
01288 int id = m_langSelect->idAt(j);
01289
01290 if (m_langSelect->text(id) == activeLanguage &&
01291 m_langSelect->isItemChecked(id))
01292 return;
01293 }
01294
01295 for(unsigned int i=0; i < m_langSelect->count(); i++) {
01296 bool isActiveLang = (m_langSelect->text(m_langSelect->idAt(i)) == activeLanguage);
01297
01298 m_langSelect->setItemChecked(m_langSelect->idAt(i), isActiveLang);
01299 }
01300
01301 setGenerator(Model_Utils::stringToProgLang(activeLanguage));
01302 }
01303
01304 Uml::Programming_Language UMLApp::getActiveLanguage() {
01305 return m_activeLanguage;
01306 }
01307
01308 bool UMLApp::activeLanguageIsCaseSensitive() {
01309 return (m_activeLanguage != Uml::pl_Pascal &&
01310 m_activeLanguage != Uml::pl_Ada &&
01311 m_activeLanguage != Uml::pl_SQL);
01312 }
01313
01314 QString UMLApp::activeLanguageScopeSeparator() {
01315 Uml::Programming_Language pl = getActiveLanguage();
01316 if (pl == Uml::pl_Ada ||
01317 pl == Uml::pl_CSharp ||
01318 pl == Uml::pl_Pascal ||
01319 pl == Uml::pl_Java ||
01320 pl == Uml::pl_JavaScript ||
01321 pl == Uml::pl_Python)
01322 return ".";
01323 return "::";
01324 }
01325
01326 void UMLApp::slotCurrentViewClearDiagram() {
01327 getCurrentView()->clearDiagram();
01328 }
01329
01330 void UMLApp::slotCurrentViewToggleSnapToGrid() {
01331 getCurrentView()->toggleSnapToGrid();
01332 viewSnapToGrid->setChecked( getCurrentView()->getSnapToGrid() );
01333 }
01334
01335 void UMLApp::slotCurrentViewToggleShowGrid() {
01336 getCurrentView()->toggleShowGrid();
01337 viewShowGrid->setChecked( getCurrentView()->getShowSnapGrid() );
01338 }
01339
01340 void UMLApp::slotCurrentViewExportImage() {
01341 getCurrentView()->getImageExporter()->exportView();
01342 }
01343
01344 void UMLApp::slotAllViewsExportImage() {
01345 m_imageExporterAll->exportAllViews();
01346 }
01347
01348 void UMLApp::slotCurrentViewProperties() {
01349 getCurrentView()->showPropDialog();
01350 }
01351
01352 void UMLApp::setDiagramMenuItemsState(bool bState) {
01353 viewClearDiagram->setEnabled( bState );
01354 viewSnapToGrid->setEnabled( bState );
01355 viewShowGrid->setEnabled( bState );
01356 deleteDiagram->setEnabled(bState);
01357 viewExportImage->setEnabled( bState );
01358 viewProperties->setEnabled( bState );
01359 filePrint->setEnabled( bState );
01360 if ( getCurrentView() ) {
01361 viewSnapToGrid->setChecked( getCurrentView()->getSnapToGrid() );
01362 viewShowGrid->setChecked( getCurrentView()->getShowSnapGrid() );
01363 }
01364 }
01365
01366 void UMLApp::slotUpdateViews() {
01367 QPopupMenu* menu = findMenu( menuBar(), QString("views") );
01368 if (!menu) {
01369 kWarning() << "view menu not found" << endl;
01370 return;
01371 }
01372
01373 menu = findMenu( menu, QString("show_view") );
01374 if (!menu) {
01375 kWarning() << "show menu not found" << endl;
01376 return;
01377 }
01378
01379 menu->clear();
01380
01381 UMLViewList views = getDocument()->getViewIterator();
01382 for(UMLView *view = views.first(); view; view = views.next()) {
01383 menu->insertItem( view->getName(), view, SLOT( slotShowView() ) );
01384 view->fileLoaded();
01385 }
01386 }
01387
01388 void UMLApp::slotImportClasses() {
01389 m_doc->setLoading(true);
01390
01391
01392
01393 QString preselectedExtension;
01394 const Uml::Programming_Language pl = m_codegen->getLanguage();
01395 if (pl == Uml::pl_IDL) {
01396 preselectedExtension = i18n("*.idl|IDL Files (*.idl)");
01397 } else if (pl == Uml::pl_Python) {
01398 preselectedExtension = i18n("*.py|Python Files (*.py)");
01399 } else if (pl == Uml::pl_Java) {
01400 preselectedExtension = i18n("*.java|Java Files (*.java)");
01401 } else if (pl == Uml::pl_Pascal) {
01402 preselectedExtension = i18n("*.pas|Pascal Files (*.pas)");
01403 } else if (pl == Uml::pl_Ada) {
01404 preselectedExtension = i18n("*.ads *.ada|Ada Files (*.ads *.ada)");
01405 } else {
01406 preselectedExtension = i18n("*.h *.hh *.hpp *.hxx *.H|Header Files (*.h *.hh *.hpp *.hxx *.H)");
01407 }
01408 preselectedExtension.append("\n*|" + i18n("All Files"));
01409 QStringList fileList = KFileDialog::getOpenFileNames(":import-classes", preselectedExtension,
01410 this, i18n("Select Code to Import") );
01411 const QString& firstFile = fileList.first();
01412 ClassImport *classImporter = ClassImport::createImporterByFileExt(firstFile);
01413 classImporter->importFiles(fileList);
01414 delete classImporter;
01415 m_doc->setLoading(false);
01416
01417
01418
01419
01420 m_doc->setModified(true, false);
01421 }
01422
01423 void UMLApp::slotClassWizard() {
01424 ClassWizard dlg( m_doc );
01425 dlg.exec();
01426 }
01427
01428 void UMLApp::slotAddDefaultDatatypes() {
01429 m_doc->addDefaultDatatypes();
01430 }
01431
01432 void UMLApp::slotCurrentViewChanged() {
01433 UMLView *view = getCurrentView();
01434 if (view) {
01435 connect(view, SIGNAL( sigShowGridToggled(bool) ),
01436 this, SLOT( slotShowGridToggled(bool) ) );
01437 connect(view, SIGNAL( sigSnapToGridToggled(bool) ),
01438 this, SLOT( slotSnapToGridToggled(bool) ) );
01439 }
01440 }
01441 void UMLApp::slotSnapToGridToggled(bool gridOn) {
01442 viewSnapToGrid->setChecked(gridOn);
01443 }
01444
01445 void UMLApp::slotShowGridToggled(bool gridOn) {
01446 viewShowGrid->setChecked(gridOn);
01447 }
01448
01449 void UMLApp::slotSelectAll() {
01450 getCurrentView()->selectAll();
01451 }
01452
01453 void UMLApp::slotDeleteSelectedWidget() {
01454 if ( getCurrentView() ) {
01455 getCurrentView()->deleteSelection();
01456 } else {
01457 kWarning() << " trying to delete widgets when there is no current view (see bug 59774)" << endl;
01458 }
01459 }
01460
01461 void UMLApp::slotDeleteDiagram() {
01462 m_doc->removeDiagram( getCurrentView()->getID() );
01463 }
01464
01465 Uml::Programming_Language UMLApp::getDefaultLanguage() {
01466 m_config->setGroup("Code Generation");
01467 QString activeLanguage = m_config->readEntry("activeLanguage", "C++");
01468 return Model_Utils::stringToProgLang(activeLanguage);
01469 }
01470
01471 void UMLApp::initGenerator() {
01472 if (m_codegen) {
01473 delete m_codegen;
01474 m_codegen = NULL;
01475 }
01476 Uml::Programming_Language defaultLanguage = getDefaultLanguage();
01477 setActiveLanguage(Model_Utils::progLangToString(defaultLanguage));
01478 if (m_codegen == NULL)
01479 setGenerator(defaultLanguage);
01480 updateLangSelectMenu(defaultLanguage);
01481 }
01482
01483 void UMLApp::updateLangSelectMenu(Uml::Programming_Language activeLanguage) {
01484 m_langSelect->clear();
01485 m_langSelect->setCheckable(true);
01486 for (int i = 0; i < Uml::pl_Reserved; i++) {
01487 QString language = Model_Utils::progLangToString((Uml::Programming_Language) i);
01488 int id = m_langSelect->insertItem(language,this,SLOT(setActiveLanguage(int)));
01489 const bool isActiveLanguage = (activeLanguage == i);
01490 m_langSelect->setItemChecked(id, isActiveLanguage);
01491 }
01492 }
01493
01494 void UMLApp::tipOfTheDay()
01495 {
01496 KTipDialog::showTip(this ,QString::null, true);
01497 }
01498
01499 void UMLApp::keyPressEvent(QKeyEvent *e) {
01500 switch(e->key()) {
01501 case Qt::Key_Shift:
01502
01503 e->accept();
01504 break;
01505
01506 default:
01507 e->ignore();
01508 }
01509
01510 }
01511
01512 void UMLApp::customEvent(QCustomEvent* e) {
01513 if (e->type() == CmdLineExportAllViewsEvent::getType()) {
01514 CmdLineExportAllViewsEvent* exportAllViewsEvent = static_cast<CmdLineExportAllViewsEvent*>(e);
01515 exportAllViewsEvent->exportAllViews();
01516 }
01517 }
01518
01519
01520 void UMLApp::handleCursorKeyReleaseEvent(QKeyEvent* e) {
01521
01522
01523 if (m_view == NULL || !m_view->getSelectCount() || e->state() != Qt::AltButton) {
01524 e->ignore();
01525 return;
01526 }
01527 int dx = 0;
01528 int dy = 0;
01529 switch (e->key()) {
01530 case Qt::Key_Left:
01531 dx = -1;
01532 break;
01533 case Qt::Key_Right:
01534 dx = 1;
01535 break;
01536 case Qt::Key_Up:
01537 dy = -1;
01538 break;
01539 case Qt::Key_Down:
01540 dy = 1;
01541 break;
01542 default:
01543 e->ignore();
01544 return;
01545 }
01546 m_view->moveSelectedBy(dx, dy);
01547
01548
01549
01550 if (!e->isAutoRepeat()) {
01551 m_doc->setModified();
01552 }
01553 e->accept();
01554 }
01555
01556 void UMLApp::keyReleaseEvent(QKeyEvent *e) {
01557 switch(e->key()) {
01558 case Qt::Key_Backspace:
01559 if (!m_pDocWindow->isTyping())
01560 toolsbar->setOldTool();
01561 e->accept();
01562 break;
01563 case Qt::Key_Escape:
01564 toolsbar->setDefaultTool();
01565 e->accept();
01566 break;
01567 case Qt::Key_Left:
01568 case Qt::Key_Right:
01569 case Qt::Key_Up:
01570 case Qt::Key_Down:
01571 handleCursorKeyReleaseEvent(e);
01572 break;
01573 default:
01574 e->ignore();
01575 }
01576
01577 }
01578
01579 void UMLApp::newDocument() {
01580 m_doc->newDocument();
01581 Uml::Programming_Language defaultLanguage = getDefaultLanguage();
01582 if (m_codegen) {
01583 defaultLanguage = m_codegen->getLanguage();
01584 delete m_codegen;
01585 m_codegen = NULL;
01586 }
01587 setGenerator(defaultLanguage);
01588 slotUpdateViews();
01589 }
01590
01591 QWidget* UMLApp::getMainViewWidget() {
01592 Settings::OptionState& optionState = Settings::getOptionState();
01593 if (optionState.generalState.tabdiagrams)
01594 return m_tabWidget;
01595 return m_viewStack;
01596 }
01597
01598 void UMLApp::setCurrentView(UMLView* view) {
01599 m_view = view;
01600 if (m_viewStack == NULL) {
01601 kError() << "UMLApp::setCurrentView: m_viewStack is NULL" << endl;
01602 return;
01603 }
01604 if (view == NULL) {
01605 kDebug() << "UMLApp::setCurrentView: view is NULL" << endl;
01606 return;
01607 }
01608 if (m_viewStack->id(view) < 0)
01609 m_viewStack->addWidget(view);
01610 m_viewStack->raiseWidget(view);
01611 slotStatusMsg(view->getName());
01612 UMLListViewItem* lvitem = m_listView->findView(view);
01613 if (lvitem)
01614 m_listView->setCurrentItem(lvitem);
01615 }
01616
01617 UMLView* UMLApp::getCurrentView() {
01618 return m_view;
01619 }
01620
01621 QPopupMenu* UMLApp::findMenu(QMenuData* menu, const QString &name) {
01622
01623 if (menu) {
01624 int menuCount = menu->count();
01625
01626 for (int i=0; i<menuCount; i++) {
01627 int idAt = menu->idAt(i);
01628 QPopupMenu* popupMenu = menu->findItem(idAt)->popup();
01629 if (popupMenu) {
01630 QString menuName = popupMenu->name();
01631 if( menuName == name) {
01632 return popupMenu;
01633 }
01634 }
01635 }
01636 }
01637 return 0;
01638 }
01639
01640 void UMLApp::slotTabChanged(QWidget* view) {
01641 UMLView* umlview = ( UMLView* )view;
01642 m_doc->changeCurrentView( umlview->getID() );
01643 }
01644
01645 void UMLApp::slotChangeTabLeft() {
01646 if (m_tabWidget) {
01647 m_tabWidget->setCurrentPage( m_tabWidget->currentPageIndex() - 1 );
01648 return;
01649 }
01650 UMLViewList views = m_doc->getViewIterator();
01651 UMLView *currView = m_view;
01652 if (views.find(currView) < 0) {
01653 kError() << "UMLApp::slotChangeTabLeft(): currView not found in viewlist" << endl;
01654 return;
01655 }
01656 if ((currView = views.prev()) != NULL)
01657 setCurrentView(currView);
01658 else
01659 setCurrentView(views.last());
01660 }
01661
01662 void UMLApp::slotChangeTabRight() {
01663 if (m_tabWidget) {
01664 m_tabWidget->setCurrentPage( m_tabWidget->currentPageIndex() + 1 );
01665 return;
01666 }
01667 UMLViewList views = m_doc->getViewIterator();
01668 UMLView *currView = m_view;
01669 if (views.find(currView) < 0) {
01670 kError() << "UMLApp::slotChangeTabRight(): currView not found in viewlist" << endl;
01671 return;
01672 }
01673 if ((currView = views.next()) != NULL)
01674 setCurrentView(currView);
01675 else
01676 setCurrentView(views.first());
01677 }
01678
01679 void UMLApp::slotMoveTabLeft() {
01680
01681
01682
01683
01684 }
01685
01686 void UMLApp::slotMoveTabRight() {
01687
01688
01689 }
01690
01691 void UMLApp::slotAutolayout(){
01692 #ifdef HAVE_DOT
01693
01694
01695
01696
01697 #endif
01698 }
01699
01700 void UMLApp::slotXhtmlDocGenerationFinished()
01701 {
01702 delete m_xhtmlGenerator;
01703 m_xhtmlGenerator = 0;
01704 }
01705
01706 KTabWidget* UMLApp::tabWidget() {
01707 return m_tabWidget;
01708 }
01709
01710 QString UMLApp::getStatusBarMsg() {
01711 return m_statusLabel->text();
01712 }
01713
01714
01715 UMLApp* UMLApp::s_instance;
01716
01717 #include "uml.moc"