insilmaril@0: #include "mainwindow.h" insilmaril@0: insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@93: #include // for random seed insilmaril@0: insilmaril@0: insilmaril@0: #include insilmaril@95: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "version.h" insilmaril@148: #include "aboutdialog.h" insilmaril@0: insilmaril@0: #include "icons/filenew.xpm" insilmaril@0: #include "icons/fileopen.xpm" insilmaril@0: #include "icons/filesave.xpm" insilmaril@0: #include "icons/fileprint.xpm" insilmaril@0: #include "icons/editundo.xpm" insilmaril@0: //#include "icons/editredo.xpm" // TODO insilmaril@0: #include "icons/editcopy.xpm" insilmaril@0: #include "icons/editcut.xpm" insilmaril@0: #include "icons/editpaste.xpm" insilmaril@0: #include "icons/editmoveup.xpm" insilmaril@0: #include "icons/editmovedown.xpm" insilmaril@0: #include "icons/formatcoloritem.xpm" insilmaril@0: #include "icons/formatcolorbranch.xpm" insilmaril@0: #include "icons/formatcolorpicker.xpm" insilmaril@0: #include "icons/viewzoomreset.xpm" insilmaril@0: #include "icons/viewzoomin.xpm" insilmaril@0: #include "icons/viewzoomout.xpm" insilmaril@89: #include "icons/modecolor.xpm" insilmaril@89: #include "icons/modelink.xpm" insilmaril@93: #include "icons/modecopy.xpm" insilmaril@148: //#include "icons/vym-48x48.xpm" insilmaril@0: #include "icons/flag-note.xpm" insilmaril@0: #include "icons/flag-url.xpm" insilmaril@0: #include "icons/flag-vymlink.xpm" insilmaril@0: #include "icons/flag-scrolled-right.xpm" insilmaril@0: insilmaril@0: #include "flagrowobj.h" insilmaril@0: #include "texteditor.h" insilmaril@0: #include "mapeditor.h" insilmaril@0: #include "exporthtmldialog.h" insilmaril@0: #include "exportxhtmldialog.h" insilmaril@0: #include "showtextdialog.h" insilmaril@0: #include "process.h" insilmaril@0: #include "settings.h" insilmaril@0: #include "options.h" insilmaril@0: insilmaril@0: extern TextEditor *textEditor; insilmaril@0: extern Main *mainWindow; insilmaril@0: extern int statusbarTime; insilmaril@0: extern MapEditor *clipboardME; insilmaril@0: extern FlagRowObj* standardFlagsDefault; insilmaril@0: insilmaril@98: extern QPtrList actionListBranches; insilmaril@98: insilmaril@0: extern QAction* actionFileSave; insilmaril@0: extern QAction* actionFilePrint; insilmaril@0: extern QAction* actionEditUndo; insilmaril@0: extern QAction *actionEditCopy; insilmaril@0: extern QAction *actionEditCut; insilmaril@0: extern QAction *actionEditPaste; insilmaril@0: extern QAction *actionEditMoveUp; insilmaril@0: extern QAction *actionEditMoveDown; insilmaril@0: extern QAction *actionEditToggleScroll; insilmaril@0: extern QAction* actionEditOpenURL; insilmaril@0: extern QAction* actionEditURL; insilmaril@0: extern QAction* actionEditHeading2URL; insilmaril@0: extern QAction* actionEditBugzilla2URL; insilmaril@0: extern QAction *actionEditOpenVymLink; insilmaril@0: extern QAction *actionEditVymLink; insilmaril@0: extern QAction *actionEditDeleteVymLink; insilmaril@0: extern QAction *actionEditMapInfo; insilmaril@0: extern QAction *actionEditHeading; insilmaril@0: extern QAction *actionEditDelete; insilmaril@0: extern QAction *actionEditAddBranch; insilmaril@98: extern QAction *actionEditAddBranchHere; insilmaril@0: extern QAction *actionEditAddBranchAbove; insilmaril@0: extern QAction *actionEditAddBranchBelow; insilmaril@98: extern QAction *actionEditRemoveBranchHere; insilmaril@98: extern QAction *actionEditRemoveChilds; insilmaril@0: extern QAction *actionEditImportAdd; insilmaril@0: extern QAction *actionEditImportReplace; insilmaril@0: extern QAction *actionEditSaveBranch; insilmaril@0: extern QAction *actionEditSelectFirst; insilmaril@0: extern QAction *actionEditSelectLast; insilmaril@0: extern QAction *actionEditLoadImage; insilmaril@0: extern QAction *actionEditToggleFloatExport; insilmaril@0: insilmaril@0: extern QAction* actionFormatColor; insilmaril@0: extern QAction* actionFormatPickColor; insilmaril@0: extern QAction* actionFormatColorBranch; insilmaril@0: extern QAction* actionFormatColorSubtree; insilmaril@0: extern QAction* actionFormatLinkColorHint; insilmaril@0: extern QAction* actionFormatBackColor; insilmaril@0: extern QAction* actionFormatLinkColor; insilmaril@0: insilmaril@89: extern QActionGroup* actionGroupModModes; insilmaril@89: extern QAction* actionModModeColor; insilmaril@89: extern QAction* actionModModeLink; insilmaril@93: extern QAction* actionModModeCopy; insilmaril@89: insilmaril@0: extern QActionGroup *actionGroupFormatFrameTypes; insilmaril@0: extern QAction *actionFormatFrameNone; insilmaril@0: extern QAction *actionFormatFrameRectangle; insilmaril@0: insilmaril@0: extern QActionGroup *actionGroupFormatLinkStyles; insilmaril@0: extern QAction *actionFormatLinkStyleLine; insilmaril@0: extern QAction *actionFormatLinkStyleParabel; insilmaril@0: extern QAction *actionFormatLinkStylePolyLine; insilmaril@0: extern QAction *actionFormatLinkStylePolyParabel; insilmaril@0: insilmaril@0: extern QAction *actionViewToggleNoteEditor; insilmaril@0: insilmaril@0: extern QAction* actionSettingsAutoedit; insilmaril@0: extern QAction* actionSettingsAutoselectHeading; insilmaril@0: extern QAction* actionSettingsAutoselectHeading; insilmaril@0: extern QAction* actionSettingsAutoselectText; insilmaril@0: extern QAction* actionSettingsPasteNewHeading; insilmaril@0: extern QAction* actionSettingsUseDelKey; insilmaril@103: extern QAction* actionSettingsUseFlagGroups; insilmaril@0: insilmaril@0: extern QPopupMenu* branchContextMenu; insilmaril@98: extern QPopupMenu* branchAddContextMenu; insilmaril@98: extern QPopupMenu* branchRemoveContextMenu; insilmaril@89: extern QPopupMenu* branchLinksContextMenu; insilmaril@94: extern QPopupMenu* branchLinksContextMenuDup; insilmaril@0: extern QPopupMenu* floatimageContextMenu; insilmaril@0: extern QPopupMenu* saveImageFormatMenu; insilmaril@0: extern QPopupMenu* canvasContextMenu; insilmaril@0: extern QPopupMenu* lastMapsMenu; insilmaril@0: extern QPopupMenu* exportMenu; insilmaril@0: extern QPopupMenu* exportImageFormatMenu; insilmaril@0: insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@0: extern Options options; insilmaril@0: insilmaril@0: #if defined(Q_OS_LINUX) insilmaril@0: extern void qt_wait_for_window_manager( QWidget* w ); insilmaril@0: #endif insilmaril@0: insilmaril@0: Main::Main(QWidget* parent, const char* name, WFlags f) : insilmaril@0: QMainWindow(parent,name,f) insilmaril@0: { insilmaril@0: mainWindow=this; insilmaril@0: insilmaril@0: setCaption ("VYM - View Your Mind"); insilmaril@0: insilmaril@0: // Load window settings insilmaril@0: resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800), insilmaril@0: settings.readNumEntry( "/vym/mainwindow/geometry/height",600)); insilmaril@0: move (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100), insilmaril@0: settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100)); insilmaril@0: insilmaril@0: insilmaril@93: // Set random seed (random used for object IDs) insilmaril@93: QTime t = QTime::currentTime(); // set random seed insilmaril@93: srand( t.hour()*12+t.minute()*60+t.second()*60 ); insilmaril@93: insilmaril@93: insilmaril@0: // Initialize some settings, which are platform dependant insilmaril@0: QString p,s; insilmaril@0: insilmaril@0: // application to open URLs insilmaril@0: p="/vym/mainwindow/readerURL"; insilmaril@0: #if defined(Q_OS_LINUX) insilmaril@0: s=settings.readEntry (p,"konqueror"); insilmaril@0: #else insilmaril@0: #if defined(Q_OS_MACX) insilmaril@104: s=settings.readEntry (p,"/usr/bin/open"); insilmaril@0: #else insilmaril@0: s=settings.readEntry (p,"mozilla"); insilmaril@0: #endif insilmaril@0: #endif insilmaril@0: settings.writeEntry( p,s); insilmaril@0: insilmaril@0: // application to open PDFs insilmaril@0: p="/vym/mainwindow/readerPDF"; insilmaril@0: #if defined(Q_OS_LINUX) insilmaril@0: s=settings.readEntry (p,"acroread"); insilmaril@0: #else insilmaril@0: #if defined(Q_OS_MACX) insilmaril@104: s=settings.readEntry (p,"/usr/bin/open"); insilmaril@0: #else insilmaril@0: s=settings.readEntry (p,"acroread"); insilmaril@0: #endif insilmaril@0: #endif insilmaril@0: settings.writeEntry( p,s); insilmaril@0: insilmaril@0: insilmaril@0: maxLastMaps=9; insilmaril@0: insilmaril@0: // Create tab widget which holds the maps insilmaril@0: tabWidget= new QTabWidget (this); insilmaril@0: connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), insilmaril@0: this, SLOT( editorChanged( QWidget * ) ) ); insilmaril@0: insilmaril@0: setCentralWidget(tabWidget); insilmaril@0: insilmaril@0: setupFileActions(); insilmaril@0: setupEditActions(); insilmaril@0: setupFormatActions(); insilmaril@0: setupViewActions(); insilmaril@89: setupModeActions(); insilmaril@0: setupFlagActions(); insilmaril@0: setupSettingsActions(); insilmaril@0: setupContextMenus(); insilmaril@0: if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions(); insilmaril@0: setupHelpActions(); insilmaril@0: insilmaril@0: // After menu is created, we can enable some actions insilmaril@0: actionFilePrint->setEnabled (true); insilmaril@0: insilmaril@0: statusBar(); insilmaril@0: insilmaril@0: insilmaril@0: // Initialize Find window insilmaril@0: findWindow=new FindWindow(NULL,"findwindow"); insilmaril@0: connect (findWindow, SIGNAL( findButton(QString) ), insilmaril@0: this, SLOT(editFind(QString) ) ); insilmaril@0: connect (findWindow, SIGNAL( somethingChanged() ), insilmaril@0: this, SLOT(editFindChanged() ) ); insilmaril@0: insilmaril@0: updateGeometry(); insilmaril@93: insilmaril@93: // Creating the default map into first tab is done in main.cpp now... insilmaril@0: } insilmaril@0: insilmaril@0: Main::~Main() insilmaril@0: { insilmaril@0: // Save Settings insilmaril@0: settings.writeEntry( "/vym/mainwindow/geometry/width", width() ); insilmaril@0: settings.writeEntry( "/vym/mainwindow/geometry/height", height() ); insilmaril@0: settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() ); insilmaril@0: settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() ); insilmaril@0: insilmaril@0: settings.writeEntry( "/vym/version/version", __VYM_VERSION__ ); insilmaril@0: settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ ); insilmaril@0: insilmaril@0: settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() ); insilmaril@0: settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() ); insilmaril@0: settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() ); insilmaril@0: settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() ); insilmaril@0: settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() ); insilmaril@103: settings.writeEntry( "/vym/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() ); insilmaril@0: insilmaril@0: QString s; insilmaril@0: int maps=lastMaps.count(); insilmaril@0: settings.writeEntry( "/vym/lastMaps/number",maps ); insilmaril@0: for (int i=1;i<=maps;i++) insilmaril@0: { insilmaril@0: QStringList::Iterator it = lastMaps.at(i-1); insilmaril@0: s=QString("/vym/lastMaps/map-%1").arg(i); insilmaril@0: if (!s.isEmpty() && i<=maxLastMaps) insilmaril@0: settings.writeEntry (s, *it); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: // To make the texteditor save its settings, call the destructor insilmaril@0: delete (textEditor); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::loadCmdLine() insilmaril@0: { insilmaril@0: /* TODO draw some kind of splashscreen while loading... insilmaril@0: if (qApp->argc()>1) insilmaril@0: { insilmaril@0: } insilmaril@0: */ insilmaril@0: insilmaril@0: QStringList flist=options.getFileList(); insilmaril@0: QStringList::Iterator it=flist.begin(); insilmaril@0: insilmaril@0: while (it !=flist.end() ) insilmaril@0: { insilmaril@0: fileLoad (*it, NewMap); insilmaril@0: *it++; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void Main::statusMessage(const QString &s) insilmaril@0: { insilmaril@0: statusBar()->message (s); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::closeEvent (QCloseEvent* ) insilmaril@0: { insilmaril@0: fileExitVYM(); insilmaril@0: } insilmaril@0: insilmaril@0: // File Actions insilmaril@0: void Main::setupFileActions() insilmaril@0: { insilmaril@0: QToolBar *tb = new QToolBar( this ); insilmaril@0: tb->setLabel( "File Actions" ); insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&File" ), menu ); insilmaril@0: insilmaril@0: // Keycodes: /usr/lib64/qt3/include/qnamespace.h insilmaril@0: insilmaril@0: QAction *a; insilmaril@91: a = new QAction( tr( "New map","File menu" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@91: a = new QAction( tr( "Open","File menu" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: lastMapsMenu = new QPopupMenu (this); insilmaril@0: insilmaril@0: menu->insertItem (tr("Open Recent"),lastMapsMenu ); insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@0: a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionFileSave=a; insilmaril@0: insilmaril@0: a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@151: a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir"+QString("...") ), 0, this, "export" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: exportMenu = new QPopupMenu (this); insilmaril@0: menu->insertItem (tr("Export"),exportMenu ); insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@0: insilmaril@0: a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionFilePrint=a; insilmaril@0: insilmaril@0: a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: //Edit Actions insilmaril@0: void Main::setupEditActions() insilmaril@0: { insilmaril@0: QToolBar *tb = new QToolBar( this ); insilmaril@0: tb->setLabel( "Edit Actions" ); insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&Edit" ), menu ); insilmaril@0: insilmaril@0: QAction *a; insilmaril@102: QAction *alt; insilmaril@0: a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionEditUndo=a; insilmaril@0: /* insilmaril@0: a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: */ insilmaril@0: menu->insertSeparator(); insilmaril@0: a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionEditCopy=a; insilmaril@0: a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionEditCut=a; insilmaril@0: a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionEditPaste=a; insilmaril@98: insilmaril@0: a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditMoveUp=a; insilmaril@98: insilmaril@0: a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditMoveDown=a; insilmaril@98: insilmaril@0: insilmaril@102: a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) ); insilmaril@102: alt = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_S, this, "scroll" ); insilmaril@102: connect( alt, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) ); insilmaril@102: #if defined(Q_OS_MACX) insilmaril@102: actionEditToggleScroll=alt; insilmaril@102: #else insilmaril@102: actionEditToggleScroll=a; insilmaril@102: #endif insilmaril@102: actionEditToggleScroll->setEnabled (false); insilmaril@102: actionEditToggleScroll->addTo( tb ); insilmaril@102: actionEditToggleScroll->addTo( menu ); insilmaril@102: actionListBranches.append(actionEditToggleScroll); insilmaril@0: insilmaril@0: a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@151: a = new QAction( tr( "Find" ), QPixmap(), tr( "Find"+QString("...") ), CTRL + Key_F, this, "find" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@0: a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->setEnabled (false); insilmaril@0: actionEditOpenURL=a; insilmaril@0: insilmaril@151: a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL"+QString("...") ), SHIFT + CTRL + Key_U, this, "url" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditURL=a; insilmaril@0: insilmaril@0: a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditHeading2URL=a; insilmaril@0: insilmaril@0: a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditBugzilla2URL=a; insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@0: a = new QAction( tr( "Jump to another vym map, if needed load it first" ), QPixmap(flag_vymlink_xpm), tr( "Jump to map" ), 0, this, "jumpMap" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->setEnabled (false); insilmaril@0: actionEditOpenVymLink=a; insilmaril@0: insilmaril@151: a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link"+QString("...") ), 0, this, "editLinkMap" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditVymLink=a; insilmaril@0: insilmaril@0: a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->setEnabled (false); insilmaril@0: actionEditDeleteVymLink=a; insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@151: a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info"+QString("...") ), 0, this, "editMapInfo" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a->setEnabled (true); insilmaril@0: actionEditMapInfo=a; insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: insilmaril@0: // Shortcuts to modify heading: insilmaril@0: a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) ); insilmaril@98: actionListBranches.append(a); insilmaril@0: a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) ); insilmaril@98: actionListBranches.append(a); insilmaril@89: actionEditHeading=a; insilmaril@89: a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_F2, this, "editHeading" ); insilmaril@89: connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) ); insilmaril@102: a->setEnabled (false); insilmaril@102: a->addTo ( menu ); insilmaril@102: actionEditHeading=a; insilmaril@98: actionListBranches.append(a); insilmaril@0: insilmaril@0: // Shortcut to delete selection insilmaril@0: a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo ( menu ); insilmaril@0: actionEditDelete=a; insilmaril@0: insilmaril@0: // Shortcut to add branch insilmaril@102: alt = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_A, this, "newBranch" ); insilmaril@102: connect( alt, SIGNAL( activated() ), this, SLOT( editNewBranch() ) ); insilmaril@0: a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@102: #if defined (Q_OS_MACX) insilmaril@102: actionEditAddBranch=alt; insilmaril@102: #else insilmaril@102: actionEditAddBranch=a; insilmaril@102: #endif insilmaril@0: insilmaril@98: // Add branch by inserting it at selection insilmaril@98: a = new QAction( tr( "Add a branch by inserting and making selection its child" ),tr( "Add branch (insert)" ), ALT + Key_Insert, this, "newBranchHere" ); insilmaril@98: connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchHere() ) ); insilmaril@98: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@98: actionEditAddBranchHere=a; insilmaril@98: insilmaril@0: // Add branch above insilmaril@0: a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditAddBranchAbove=a; insilmaril@0: insilmaril@0: // Add branch below insilmaril@0: a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditAddBranchBelow=a; insilmaril@0: insilmaril@0: // Import at selection (adding to selection) insilmaril@0: a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditImportAdd=a; insilmaril@0: insilmaril@0: // Import at selection (replacing selection) insilmaril@0: a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditImportReplace=a; insilmaril@0: insilmaril@0: // Save selection insilmaril@98: a = new QAction( tr( "Save selection" ),tr( "Save selection" ), 0, this, "saveSelection" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) ); insilmaril@0: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditSaveBranch=a; insilmaril@0: insilmaril@98: // Only remove branch, not its childs insilmaril@98: a = new QAction( tr( "Remove only branch and keep its childs" ),tr( "Remove only branch " ), ALT + Key_Delete, this, "removeBranchHere" ); insilmaril@98: connect( a, SIGNAL( activated() ), this, SLOT( editRemoveBranchHere() ) ); insilmaril@98: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@98: actionEditRemoveBranchHere=a; insilmaril@98: insilmaril@98: // Only remove childs of a branch insilmaril@98: a = new QAction( tr( "Remove childs of branch" ),tr( "Remove childs" ), SHIFT + Key_Delete, this, "removeBranchChilds" ); insilmaril@98: connect( a, SIGNAL( activated() ), this, SLOT( editRemoveChilds() ) ); insilmaril@98: a->setEnabled (false); insilmaril@98: actionListBranches.append(a); insilmaril@98: actionEditRemoveChilds=a; insilmaril@98: insilmaril@0: // Shortcuts for navigating with cursor: insilmaril@0: a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) ); insilmaril@0: a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) ); insilmaril@0: a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) ); insilmaril@0: a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) ); insilmaril@0: a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo ( menu ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditSelectFirst=a; insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) ); insilmaril@0: a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo ( menu ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionEditSelectLast=a; insilmaril@0: insilmaril@151: a = new QAction( tr( "Add Image" ),tr( "Add Image" )+QString("..."), 0, this, "loadImage" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) ); insilmaril@0: actionEditLoadImage=a; insilmaril@89: insilmaril@0: } insilmaril@0: insilmaril@0: // Format Actions insilmaril@0: void Main::setupFormatActions() insilmaril@0: { insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&Format" ), menu ); insilmaril@0: insilmaril@0: QToolBar *tb = new QToolBar( this ); insilmaril@0: QAction *a; insilmaril@0: QPixmap pix( 16,16); insilmaril@0: pix.fill (black); insilmaril@151: actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" )+QString("..."), 0, this, "formatColor" ); insilmaril@0: connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) ); insilmaril@0: actionFormatColor->addTo( tb ); insilmaril@0: actionFormatColor->addTo( menu ); insilmaril@0: a= new QAction( tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ), QPixmap(formatcolorpicker_xpm), tr( "Pic&k color" ), CTRL + Key_K, this, "pickColor" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionFormatPickColor=a; insilmaril@0: a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionFormatColorBranch=a; insilmaril@0: a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) ); insilmaril@0: a->setEnabled (false); insilmaril@0: a->addTo( menu ); insilmaril@0: a->addTo( tb ); insilmaril@98: actionListBranches.append(a); insilmaril@0: actionFormatColorSubtree=a; insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles"); insilmaril@0: actionGroupFormatLinkStyles->setExclusive (true); insilmaril@0: a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) ); insilmaril@0: actionFormatLinkStyleLine=a; insilmaril@0: a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) ); insilmaril@0: actionFormatLinkStyleParabel=a; insilmaril@0: a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) ); insilmaril@0: actionFormatLinkStylePolyLine=a; insilmaril@0: a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) ); insilmaril@0: actionFormatLinkStylePolyParabel=a; insilmaril@0: actionGroupFormatLinkStyles->addTo (menu); insilmaril@0: insilmaril@0: actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes"); insilmaril@0: actionGroupFormatFrameTypes->setExclusive (true); insilmaril@0: a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) ); insilmaril@0: actionFormatFrameNone=a; insilmaril@0: a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) ); insilmaril@0: actionFormatFrameRectangle=a; insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionFormatLinkColorHint=a; insilmaril@0: pix.fill (white); insilmaril@151: actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color"+QString("...") ), 0, this, "formatLinkColor" ); insilmaril@0: connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) ); insilmaril@0: actionFormatLinkColor->addTo( menu ); insilmaril@151: actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" )+QString("..."), 0, this, "formatBackColor" ); insilmaril@0: connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) ); insilmaril@0: actionFormatBackColor->addTo( menu ); insilmaril@0: } insilmaril@0: insilmaril@0: // View Actions insilmaril@0: void Main::setupViewActions() insilmaril@0: { insilmaril@0: QToolBar *tb = new QToolBar( this ); insilmaril@0: tb->setLabel( "View Actions" ); insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&View" ), menu ); insilmaril@0: insilmaril@0: QAction *a; insilmaril@151: a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), CTRL + Key_0, this, "zoomReset" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) ); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) ); insilmaril@0: a->setToggleAction(true); insilmaril@0: if (textEditor->showWithMain()) insilmaril@0: a->setOn(true); insilmaril@0: else insilmaril@0: a->setOn(false); insilmaril@0: a->addTo( tb ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionViewToggleNoteEditor=a; insilmaril@0: a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: } insilmaril@0: insilmaril@89: // Mode Actions insilmaril@89: void Main::setupModeActions() insilmaril@89: { insilmaril@89: //QPopupMenu *menu = new QPopupMenu( this ); insilmaril@89: //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu ); insilmaril@89: insilmaril@89: QToolBar *tb = new QToolBar( this ); insilmaril@91: tb->setLabel( tr ("Modes when using modifiers") ); insilmaril@89: QAction *a; insilmaril@89: actionGroupModModes=new QActionGroup ( this, "formatLinkStyles"); insilmaril@89: actionGroupModModes->setExclusive (true); insilmaril@125: a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), 0, Key_J, actionGroupModModes, "modModeColor" ); insilmaril@89: a->setToggleAction(true); insilmaril@89: a->addTo (tb); insilmaril@89: a->setOn(true); insilmaril@89: actionModModeColor=a; insilmaril@104: insilmaril@125: a= new QAction( tr( "Use modifier to copy" ), QPixmap(modecopy_xpm), 0, Key_K, actionGroupModModes, "modModeCopy" ); insilmaril@104: a->setToggleAction(true); insilmaril@104: a->addTo (tb); insilmaril@104: actionModModeCopy=a; insilmaril@104: insilmaril@125: a= new QAction( tr( "Use modifier to draw xLinks" ), QPixmap(modelink_xpm), 0, Key_L, actionGroupModModes, "modModeLink" ); insilmaril@89: a->setToggleAction(true); insilmaril@89: a->addTo (tb); insilmaril@89: actionModModeLink=a; insilmaril@89: } insilmaril@89: insilmaril@0: // Flag Actions insilmaril@0: void Main::setupFlagActions() insilmaril@0: { insilmaril@0: standardFlagsDefault->makeToolbar(this, "Standard Flags"); insilmaril@0: } insilmaril@0: insilmaril@0: // Settings Actions insilmaril@0: void Main::setupSettingsActions() insilmaril@0: { insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&Settings" ), menu ); insilmaril@0: insilmaril@0: QAction *a; insilmaril@0: insilmaril@0: insilmaril@159: a = new QAction( tr( "Set application to open pdf files"), QPixmap(), tr( "Set application to open pdf files ...") , 0, this, "setPDF" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@159: a = new QAction( tr( "Set application to open external links"), QPixmap(), tr( "Set application to open external links..."), 0, this, "setURL" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: menu->insertSeparator(); insilmaril@0: a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionSettingsAutoedit=a; insilmaril@0: insilmaril@0: a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionSettingsAutoselectHeading=a; insilmaril@0: insilmaril@0: a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionSettingsAutoselectText=a; insilmaril@0: insilmaril@151: a= new QAction( tr( "Pasting into new branch" ), QPixmap(), tr( "pasting into new branch" ), 0, this, "pastenewheading" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionSettingsPasteNewHeading=a; insilmaril@0: insilmaril@151: a= new QAction( tr( "Delete key for deleting branches" ), QPixmap(), tr( "Delete key" ), 0, this, "delkey" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) ); insilmaril@0: a->addTo( menu ); insilmaril@0: actionSettingsUseDelKey=a; insilmaril@103: insilmaril@151: a= new QAction( tr( "Use exclusive flags in flag toolbars" ), QPixmap(), tr( "Exclusive flags" ), 0, this, "flaggroups" ); insilmaril@103: a->setToggleAction(true); insilmaril@103: a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useFlagGroups",true) ); insilmaril@103: a->addTo( menu ); insilmaril@103: actionSettingsUseFlagGroups=a; insilmaril@0: } insilmaril@0: insilmaril@0: // Test Actions insilmaril@0: void Main::setupTestActions() insilmaril@0: { insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&Test" ), menu ); insilmaril@0: insilmaril@0: QAction *a; insilmaril@0: a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: } insilmaril@0: insilmaril@0: // Help Actions insilmaril@0: void Main::setupHelpActions() insilmaril@0: { insilmaril@0: QPopupMenu *menu = new QPopupMenu( this ); insilmaril@0: menuBar()->insertItem( tr( "&Help" ), menu ); insilmaril@0: insilmaril@0: QAction *a; insilmaril@0: a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: insilmaril@0: a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) ); insilmaril@0: a->addTo( menu ); insilmaril@0: } insilmaril@0: insilmaril@0: // Context Menus insilmaril@0: void Main::setupContextMenus() insilmaril@0: { insilmaril@0: QAction*a; insilmaril@0: insilmaril@0: // Context Menu for branch or mapcenter insilmaril@0: branchContextMenu =new QPopupMenu (this); insilmaril@98: insilmaril@98: // Submenu "Add" insilmaril@98: branchAddContextMenu =new QPopupMenu (this); insilmaril@98: actionEditPaste->addTo ( branchAddContextMenu ); insilmaril@98: actionEditAddBranch->addTo ( branchAddContextMenu ); insilmaril@98: actionEditAddBranchHere->addTo ( branchAddContextMenu ); insilmaril@98: actionEditAddBranchAbove->addTo ( branchAddContextMenu ); insilmaril@98: actionEditAddBranchBelow->addTo ( branchAddContextMenu ); insilmaril@98: branchAddContextMenu->insertSeparator(); insilmaril@98: actionEditLoadImage->addTo( branchAddContextMenu ); insilmaril@98: branchAddContextMenu->insertSeparator(); insilmaril@98: actionEditImportAdd->addTo ( branchAddContextMenu ); insilmaril@98: actionEditImportReplace->addTo ( branchAddContextMenu ); insilmaril@98: insilmaril@98: // Submenu "Remove" insilmaril@98: branchRemoveContextMenu =new QPopupMenu (this); insilmaril@98: actionEditCut->addTo ( branchRemoveContextMenu ); insilmaril@98: actionEditDelete->addTo ( branchRemoveContextMenu ); insilmaril@98: actionEditRemoveBranchHere->addTo( branchRemoveContextMenu ); insilmaril@98: actionEditRemoveChilds->addTo( branchRemoveContextMenu ); insilmaril@98: insilmaril@98: branchContextMenu->insertItem (tr("Add"),branchAddContextMenu); insilmaril@98: branchContextMenu->insertItem (tr("Remove"),branchRemoveContextMenu); insilmaril@98: insilmaril@0: actionEditSaveBranch->addTo( branchContextMenu ); insilmaril@98: insilmaril@0: branchContextMenu->insertSeparator(); insilmaril@0: actionEditOpenURL->addTo ( branchContextMenu ); insilmaril@0: actionEditURL->addTo ( branchContextMenu ); insilmaril@0: actionEditHeading2URL->addTo ( branchContextMenu ); insilmaril@0: if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) insilmaril@0: actionEditBugzilla2URL->addTo( branchContextMenu ); insilmaril@98: insilmaril@0: branchContextMenu->insertSeparator(); insilmaril@0: actionEditOpenVymLink->addTo ( branchContextMenu ); insilmaril@0: actionEditVymLink->addTo ( branchContextMenu ); insilmaril@0: actionEditDeleteVymLink->addTo ( branchContextMenu ); insilmaril@98: insilmaril@0: branchContextMenu->insertSeparator(); insilmaril@0: actionGroupFormatFrameTypes->addTo( branchContextMenu ); insilmaril@0: insilmaril@89: // Context Menu for links in a branch menu insilmaril@89: // This will be populated "on demand" in MapEditor::updateActions insilmaril@89: branchContextMenu->insertSeparator(); insilmaril@89: branchLinksContextMenu =new QPopupMenu (this); insilmaril@94: branchLinksContextMenuDup =new QPopupMenu (this); insilmaril@95: branchContextMenu->insertItem (tr("Edit XLink"),branchLinksContextMenuDup); insilmaril@95: connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditXLink(int ) ) ); insilmaril@89: insilmaril@105: branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu); insilmaril@105: connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) ); insilmaril@105: insilmaril@0: // Context menu for floatimage insilmaril@0: floatimageContextMenu =new QPopupMenu (this); insilmaril@0: saveImageFormatMenu=new QPopupMenu (this); insilmaril@0: exportImageFormatMenu=new QPopupMenu (this); insilmaril@0: insilmaril@0: QStrList fmt = QImage::outputFormats(); insilmaril@0: for (const char* f = fmt.first(); f; f = fmt.next()) insilmaril@0: { insilmaril@0: saveImageFormatMenu->insertItem( f ); insilmaril@0: exportImageFormatMenu->insertItem( f ); insilmaril@0: } insilmaril@0: connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) ); insilmaril@0: connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) ); insilmaril@0: floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu ); insilmaril@0: insilmaril@0: floatimageContextMenu->insertSeparator(); insilmaril@0: actionEditCopy->addTo( floatimageContextMenu ); insilmaril@0: actionEditCut->addTo( floatimageContextMenu ); insilmaril@0: insilmaril@0: floatimageContextMenu->insertSeparator(); insilmaril@0: a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" ); insilmaril@0: a->setToggleAction(true); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) ); insilmaril@0: a->addTo( floatimageContextMenu); insilmaril@0: actionEditToggleFloatExport=a; insilmaril@0: insilmaril@0: insilmaril@0: insilmaril@0: // Context menu for exports insilmaril@0: exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu); insilmaril@0: insilmaril@151: a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" +QString("...")), 0, this, "exportASCII" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) ); insilmaril@143: a->addTo( exportMenu ); insilmaril@0: insilmaril@151: a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ), 0, this, "exportXML"+QString("...") ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) ); insilmaril@0: a->addTo( exportMenu ); insilmaril@0: insilmaril@0: if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) insilmaril@0: { insilmaril@151: a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML"+QString("...") ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) ); insilmaril@0: a->addTo( exportMenu ); insilmaril@0: } insilmaril@0: insilmaril@151: a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" )+QString("..."), ALT + Key_X, this, "exportXHTML" ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) ); insilmaril@0: a->addTo( exportMenu ); insilmaril@0: insilmaril@0: insilmaril@0: // Context menu for canvas insilmaril@0: canvasContextMenu =new QPopupMenu (this); insilmaril@0: actionEditMapInfo->addTo( canvasContextMenu ); insilmaril@0: canvasContextMenu->insertSeparator(); insilmaril@0: actionGroupFormatLinkStyles->addTo( canvasContextMenu ); insilmaril@0: canvasContextMenu->insertSeparator(); insilmaril@0: actionFormatLinkColorHint->addTo( canvasContextMenu ); insilmaril@0: actionFormatLinkColor->addTo( canvasContextMenu ); insilmaril@0: actionFormatBackColor->addTo( canvasContextMenu ); insilmaril@0: insilmaril@0: // Menu for last opened files insilmaril@0: // Read settings initially insilmaril@0: QString s; insilmaril@0: int j=settings.readNumEntry( "/vym/lastMaps/number",0); insilmaril@0: for (int i=1;i<=j;i++) insilmaril@0: { insilmaril@0: s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),""); insilmaril@0: if (!s.isEmpty() && j<=maxLastMaps) insilmaril@0: lastMaps.append(s); insilmaril@0: } insilmaril@0: setupLastMapsMenu(); insilmaril@0: connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) ); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::setupLastMapsMenu() insilmaril@0: { insilmaril@0: // Remove double entries insilmaril@0: QStringList::Iterator it=lastMaps.begin(); insilmaril@0: QStringList::Iterator jt; insilmaril@0: while (it!=lastMaps.end() ) insilmaril@0: { insilmaril@0: jt=it; insilmaril@0: ++jt; insilmaril@0: while (jt!=lastMaps.end() ) insilmaril@0: { insilmaril@0: if (*it == *jt) insilmaril@0: jt=lastMaps.remove(jt); insilmaril@0: else insilmaril@0: jt++; insilmaril@0: } insilmaril@0: it++; insilmaril@0: } insilmaril@0: insilmaril@0: // Limit length of list to maxLastMaps insilmaril@0: while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back(); insilmaril@0: insilmaril@0: // build Menu from lastMaps string list insilmaril@0: lastMapsMenu->clear(); insilmaril@0: for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) insilmaril@0: lastMapsMenu->insertItem (*it ); insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: void Main::hideEvent (QHideEvent * ) insilmaril@0: { insilmaril@0: if (!textEditor->isMinimized() ) textEditor->hide(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::showEvent (QShowEvent * ) insilmaril@0: { insilmaril@117: if (textEditor->showWithMain()) textEditor->showNormal(); insilmaril@0: } insilmaril@0: insilmaril@0: bool Main::reallyWriteDirectory(const QString &dir) insilmaril@0: { insilmaril@0: QStringList eList = QDir(dir).entryList(); insilmaril@0: if (eList.first() ==".") eList.pop_front(); // remove "." insilmaril@0: if (eList.first() =="..") eList.pop_front(); // remove "." insilmaril@0: if (!eList.isEmpty()) insilmaril@0: { insilmaril@0: QMessageBox mb( "VYM", insilmaril@159: tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?").arg(dir), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes , insilmaril@0: QMessageBox::Cancel | QMessageBox::Default, insilmaril@0: QMessageBox::QMessageBox::NoButton ); insilmaril@0: insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save insilmaril@0: return true; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: return false; insilmaril@0: } insilmaril@0: } insilmaril@0: return true; insilmaril@0: } insilmaril@0: insilmaril@0: QString Main::browseDirectory (const QString &caption) insilmaril@0: { insilmaril@0: QFileDialog fd(this,caption); insilmaril@0: fd.setMode (QFileDialog::DirectoryOnly); insilmaril@0: fd.setCaption("VYM - "+caption); insilmaril@0: fd.show(); insilmaril@0: insilmaril@0: if ( fd.exec() == QDialog::Accepted ) insilmaril@0: return fd.selectedFile(); insilmaril@0: else insilmaril@0: return ""; insilmaril@0: } insilmaril@0: insilmaril@0: MapEditor* Main::currentMapEditor() const insilmaril@0: { insilmaril@0: if ( tabWidget->currentPage() && insilmaril@0: tabWidget->currentPage()->inherits( "MapEditor" ) ) insilmaril@0: return (MapEditor*)tabWidget->currentPage(); insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: insilmaril@0: //TODO not used now, maybe use this for overview window later insilmaril@0: void Main::newView() insilmaril@0: { insilmaril@0: // Open a new view... have it delete when closed. insilmaril@0: Main *m = new Main(0, 0, WDestructiveClose); insilmaril@0: qApp->setMainWidget(m); insilmaril@0: m->show(); insilmaril@0: qApp->setMainWidget(0); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editorChanged(QWidget *) insilmaril@0: { insilmaril@0: // Unselect all possibly selected objects insilmaril@0: // (Important to update note editor) insilmaril@0: int i; insilmaril@0: MapEditor *me; insilmaril@0: for (i=0;i<=tabWidget->count() -1;i++) insilmaril@0: { insilmaril@0: insilmaril@0: me=(MapEditor*)tabWidget->page(i); insilmaril@0: me->unselect(); insilmaril@0: } insilmaril@0: currentMapEditor()->reselect(); insilmaril@0: insilmaril@0: // Update actions to in menus and toolbars according to editor insilmaril@0: currentMapEditor()->updateActions(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileNew() insilmaril@0: { insilmaril@0: QString fn="unnamed"; insilmaril@0: MapEditor* medit = new MapEditor (tabWidget, true); insilmaril@0: tabWidget->addTab (medit,fn); insilmaril@0: tabWidget->showPage(medit); insilmaril@0: medit->viewport()->setFocus(); insilmaril@0: medit->select("mc:"); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileLoad(QString fn, const LoadMode &lmode) insilmaril@0: { insilmaril@0: // Error codes insilmaril@0: enum errorCode {success,aborted}; insilmaril@0: errorCode err=success; insilmaril@0: insilmaril@0: // fn is usually the archive, mapfile the file after uncompressing insilmaril@0: QString mapfile; insilmaril@0: insilmaril@0: // Make fn absolute (needed for unzip) insilmaril@0: fn=QDir (fn).absPath(); insilmaril@0: insilmaril@0: MapEditor *me; insilmaril@0: insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@0: // Check, if map is already loaded insilmaril@0: int i=0; insilmaril@0: while (i<=tabWidget->count() -1) insilmaril@0: { insilmaril@0: me=(MapEditor*)tabWidget->page(i); insilmaril@0: if (me->getFilePath() == fn) insilmaril@0: { insilmaril@0: // Already there, ask for confirmation insilmaril@0: QMessageBox mb( "VYM", insilmaril@159: tr("The map %1\nis already opened." insilmaril@0: "Opening the same map in multiple editors may lead \n" insilmaril@0: "to confusion when finishing working with vym." insilmaril@159: "Do you want to").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@0: QMessageBox::QMessageBox::NoButton); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Open anyway") ); insilmaril@0: mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // load anyway insilmaril@0: i=tabWidget->count(); insilmaril@0: break; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: i++; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: // Try to load map insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: me = currentMapEditor(); insilmaril@0: int tabIndex=tabWidget->currentPageIndex(); insilmaril@0: // Check first, if mapeditor exists insilmaril@0: // If it is not default AND we want a new map, insilmaril@0: // create a new mapeditor in a new tab insilmaril@0: if ( lmode==NewMap && (!me || !me->isDefault() ) ) insilmaril@0: { insilmaril@0: me = new MapEditor (tabWidget,true); insilmaril@0: tabWidget->addTab (me,fn); insilmaril@0: tabIndex=tabWidget->indexOf (me); insilmaril@0: tabWidget->setCurrentPage (tabIndex); insilmaril@0: } insilmaril@0: insilmaril@0: // Check, if file exists (important for creating new files insilmaril@0: // from command line insilmaril@0: if (!QFile(fn).exists() ) insilmaril@0: { insilmaril@0: QMessageBox mb( "VYM", insilmaril@159: tr("This map does not exist:\n %1\nDo you want to create a new one?").arg(fn), insilmaril@0: QMessageBox::Question, insilmaril@0: QMessageBox::Yes , insilmaril@0: QMessageBox::Cancel | QMessageBox::Default, insilmaril@0: QMessageBox::QMessageBox::NoButton ); insilmaril@0: insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Create")); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // Create new map insilmaril@0: currentMapEditor()->setFilePath(fn); insilmaril@0: tabWidget->setTabLabel (currentMapEditor(), insilmaril@0: currentMapEditor()->getFileName() ); insilmaril@0: statusBar()->message( "Created " + fn , statusbarTime ); insilmaril@0: return; insilmaril@0: insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // don't create new map insilmaril@0: statusBar()->message( "Loading " + fn + " failed!", statusbarTime ); insilmaril@0: fileCloseMap(); insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: //tabWidget->currentPage() won't be NULL here, because of above... insilmaril@0: tabWidget->showPage(me); insilmaril@0: me->viewport()->setFocus(); insilmaril@0: insilmaril@0: // Create temporary directory for packing insilmaril@0: char tmpdir1[]="/tmp/vym-XXXXXX"; insilmaril@0: QString tmpMapDir=mkdtemp(tmpdir1); insilmaril@0: insilmaril@0: // Try to unzip file insilmaril@0: Process *zipProc=new Process (); insilmaril@0: zipProc->clearArguments(); insilmaril@0: zipProc->setWorkingDirectory (QDir(tmpMapDir)); insilmaril@0: zipProc->addArgument ("unzip"); insilmaril@0: zipProc->addArgument (fn ); insilmaril@0: zipProc->addArgument ("-d"); insilmaril@0: zipProc->addArgument (tmpMapDir); insilmaril@0: insilmaril@0: if (!zipProc->start() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@0: tr("Couldn't start unzip to decompress data.")); insilmaril@0: err=aborted; insilmaril@0: insilmaril@0: } else insilmaril@0: { insilmaril@0: zipProc->waitFinished(); insilmaril@0: if (!zipProc->normalExit() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@0: tr("unzip didn't exit normally") + insilmaril@0: zipProc->getErrout() ); insilmaril@0: err=aborted; insilmaril@0: } else insilmaril@0: { insilmaril@0: if (zipProc->exitStatus()>0) insilmaril@0: { insilmaril@0: if (zipProc->exitStatus()==9) insilmaril@0: { insilmaril@0: // no zipped file, but maybe .xml or old version? Try again. insilmaril@0: mapfile=fn; insilmaril@0: me->setZipped(false); insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@0: QString("unzip exit code: %1").arg(zipProc->exitStatus() ) + insilmaril@0: zipProc->getErrout() ); insilmaril@0: err=aborted; insilmaril@0: } insilmaril@0: } else insilmaril@0: { // Uncompressing was successfull, insilmaril@0: // load from uncompressed temporary directory insilmaril@0: insilmaril@0: me->setZipped(true); insilmaril@0: insilmaril@0: insilmaril@0: // Look for mapname.xml insilmaril@0: mapfile= fn.left(fn.findRev(".",-1,true)); insilmaril@0: mapfile=mapfile.section( '/', -1 ); insilmaril@0: QFile file( tmpMapDir + "/" + mapfile + ".xml"); insilmaril@0: if (!file.exists() ) insilmaril@0: { insilmaril@0: // mapname.xml does not exist, well, insilmaril@0: // maybe some renamed the mapname.vym file... insilmaril@0: // Try to find any .xml in the toplevel insilmaril@0: // directory of the .vym file insilmaril@0: QStringList flist=QDir (tmpMapDir).entryList("*.xml"); insilmaril@0: if (flist.count()==1) insilmaril@0: { insilmaril@0: // Only one entry, take this one insilmaril@0: mapfile=tmpMapDir + "/"+flist.first(); insilmaril@0: } else insilmaril@0: { insilmaril@0: for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) insilmaril@0: *it=tmpMapDir + "/" + *it; insilmaril@106: // FIXME Multiple entries, load all (but only the first one into this ME) insilmaril@0: //mainWindow->fileLoadFromTmp (flist); insilmaril@0: //returnCode=1; // Silently forget this attempt to load insilmaril@0: qWarning ("MainWindow::load (fn) multimap found..."); insilmaril@0: } insilmaril@0: insilmaril@0: if (flist.isEmpty() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@0: tr("Couldn't find a map (*.xml) in .vym archive.\n")); insilmaril@0: err=aborted; insilmaril@0: } insilmaril@0: } //file doesn't exist insilmaril@0: else insilmaril@0: mapfile=file.name(); insilmaril@0: } // Uncompressing successfull insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@106: insilmaril@106: // Save existing filename insilmaril@106: QString fn_org=me->getFilePath(); insilmaril@106: insilmaril@0: // Finally load map into mapEditor insilmaril@0: me->setFilePath (mapfile,fn); insilmaril@0: if (me->load(mapfile,lmode)) insilmaril@0: err=aborted; insilmaril@0: insilmaril@106: // Restore old (maybe empty) filepath, if this is an import insilmaril@106: if (lmode!=NewMap) insilmaril@106: me->setFilePath (fn_org); insilmaril@106: insilmaril@0: // Delete tmpDir insilmaril@0: system ( "rm -rf "+tmpMapDir); insilmaril@0: insilmaril@0: // Check for errors insilmaril@0: if (err==success) insilmaril@0: { insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@0: me->setFilePath (fn); insilmaril@0: tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName()); insilmaril@0: lastMaps.prepend(me->getFilePath() ); insilmaril@0: setupLastMapsMenu(); insilmaril@0: actionFilePrint->setEnabled (true); insilmaril@0: } insilmaril@0: statusBar()->message( "Loaded " + fn, statusbarTime ); insilmaril@0: return; insilmaril@0: } else insilmaril@0: { insilmaril@0: if (lmode==NewMap) insilmaril@0: fileCloseMap(); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: } insilmaril@0: statusBar()->message( "Could not load " + fn, statusbarTime ); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void Main::fileLoad(const LoadMode &lmode) insilmaril@0: { insilmaril@0: QFileDialog *fd=new QFileDialog( this); insilmaril@0: if (!lastFileDir.isEmpty()) insilmaril@0: fd->setDir (lastFileDir); insilmaril@0: fd->addFilter ("XML (*.xml)"); insilmaril@0: fd->addFilter ("VYM map (*.vym *.vyp)"); insilmaril@0: switch (lmode) insilmaril@0: { insilmaril@0: case NewMap: insilmaril@0: fd->setCaption(tr("Load vym map")); insilmaril@0: break; insilmaril@0: case ImportAdd: insilmaril@0: fd->setCaption(tr("Import: Add vym map to selection")); insilmaril@0: break; insilmaril@0: case ImportReplace: insilmaril@0: fd->setCaption(tr("Import: Replace selection with vym map")); insilmaril@0: break; insilmaril@0: } insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: lastFileDir=fd->dirPath(); insilmaril@0: fn = fd->selectedFile(); insilmaril@0: fileLoad(fn, lmode); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileLoad() insilmaril@0: { insilmaril@0: fileLoad (NewMap); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileLoadLast(int i) insilmaril@0: { insilmaril@0: fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileSave(const SaveMode &savemode) insilmaril@0: { insilmaril@0: // tmp dir for zipping insilmaril@0: QString tmpMapDir; insilmaril@0: insilmaril@0: // Error codes insilmaril@0: enum errorCode {success,aborted}; insilmaril@0: errorCode err=success; insilmaril@0: insilmaril@0: QString safeFilePath; insilmaril@0: insilmaril@0: bool saveZipped=currentMapEditor()->saveZipped(); insilmaril@0: insilmaril@151: MapEditor * me=currentMapEditor(); insilmaril@151: if (me) insilmaril@0: { insilmaril@151: QString fn=me->getFilePath(); insilmaril@0: // filename=unnamed, filepath="" in constructor... insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: // We have a filepath, go on saving insilmaril@0: // First remove existing file, we insilmaril@0: // don't want to add to old zip archives insilmaril@0: QFile f(fn); insilmaril@0: if (f.exists() ) insilmaril@0: if (!f.remove()) insilmaril@0: QMessageBox::warning( 0, tr( "Save Error" ), insilmaril@0: fn+ tr("\ncould not be removed before saving")); insilmaril@0: insilmaril@0: // Look, if we should zip the data: insilmaril@0: if (!saveZipped) insilmaril@0: { insilmaril@0: QMessageBox mb( "VYM", insilmaril@159: tr("The map %1\ndid not use the compressed " insilmaril@0: "vym file format.\nWriting it uncompressed will also write images \n" insilmaril@0: "and flags and thus may overwrite files in the " insilmaril@159: "given directory\n\nDo you want to write the map").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::No , insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("uncompressed") ); insilmaril@0: mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save compressed (default file format) insilmaril@0: saveZipped=true; insilmaril@0: break; insilmaril@0: case QMessageBox::No: insilmaril@0: // save uncompressed insilmaril@0: saveZipped=false; insilmaril@0: break; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: if (saveZipped) insilmaril@0: { insilmaril@0: char tmpdir1[]="/tmp/vym-XXXXXX"; insilmaril@0: tmpMapDir=mkdtemp(tmpdir1); insilmaril@0: insilmaril@151: safeFilePath=me->getFilePath(); insilmaril@151: me->setFilePath (tmpMapDir+"/"+ insilmaril@151: me->getMapName()+ ".xml", insilmaril@0: safeFilePath); insilmaril@151: me->save (savemode); insilmaril@151: me->setFilePath (safeFilePath); insilmaril@0: insilmaril@0: // zip the temporary directory insilmaril@0: Process *zipProc=new Process (); insilmaril@0: zipProc->clearArguments(); insilmaril@0: zipProc->setWorkingDirectory (QDir(tmpMapDir)); insilmaril@0: zipProc->addArgument ("zip"); insilmaril@0: zipProc->addArgument ("-r"); insilmaril@0: zipProc->addArgument (fn); insilmaril@0: zipProc->addArgument ("."); insilmaril@0: insilmaril@0: if (!zipProc->start() ) insilmaril@0: { insilmaril@0: // zip could not be started insilmaril@0: QMessageBox::critical( 0, tr( "Critical Save Error" ), insilmaril@0: tr("Couldn't start zip to compress data.")); insilmaril@0: err=aborted; insilmaril@0: } else insilmaril@0: { insilmaril@0: // zip could be started insilmaril@0: zipProc->waitFinished(); insilmaril@0: if (!zipProc->normalExit() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Save Error" ), insilmaril@0: tr("zip didn't exit normally")+ insilmaril@0: "\n" + zipProc->getErrout()); insilmaril@0: err=aborted; insilmaril@0: } else insilmaril@0: { insilmaril@0: if (zipProc->exitStatus()>0) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Save Error" ), insilmaril@0: QString("zip exit code: %1").arg(zipProc->exitStatus() )+ insilmaril@0: "\n" + zipProc->getErrout() ); insilmaril@0: err=aborted; insilmaril@0: } insilmaril@0: } insilmaril@0: } // zip could be started insilmaril@0: } // save zipped insilmaril@0: else insilmaril@0: { insilmaril@0: // Save unzipped. insilmaril@151: safeFilePath=me->getFilePath(); insilmaril@151: me->setFilePath (fn, safeFilePath); insilmaril@151: me->save (savemode); insilmaril@151: me->setFilePath (safeFilePath); insilmaril@0: } // save zipped insilmaril@0: } // filepath available insilmaril@0: else insilmaril@0: { insilmaril@0: // We have no filepath yet, insilmaril@0: // call fileSaveAs() now, this will call fileSave() insilmaril@0: // again. insilmaril@0: fileSaveAs(savemode); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@151: if (me->saveZipped()) insilmaril@0: { insilmaril@0: // Delete tmpDir insilmaril@0: system ( "rm -rf "+ tmpMapDir ); insilmaril@0: } insilmaril@0: insilmaril@0: if (err==success) insilmaril@151: { insilmaril@0: statusBar()->message( insilmaril@159: tr("Saved %1").arg(me->getFilePath()), insilmaril@0: statusbarTime ); insilmaril@151: lastMaps.prepend(me->getFilePath() ); insilmaril@151: setupLastMapsMenu(); insilmaril@151: } else insilmaril@0: statusBar()->message( insilmaril@159: tr("Couldn't save ").arg(me->getFilePath()), insilmaril@0: statusbarTime ); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileSave() insilmaril@0: { insilmaril@0: fileSave (CompleteMap); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileSaveAs(const SaveMode& savemode) insilmaril@0: { insilmaril@0: QString tmpMapDir; insilmaril@0: QString fn; insilmaril@0: insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: if (savemode==CompleteMap) insilmaril@0: fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this ); insilmaril@0: else insilmaril@0: fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this ); insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: // Check for existing file insilmaril@0: if (QFile (fn).exists()) insilmaril@0: { insilmaril@0: QMessageBox mb( "VYM", insilmaril@159: tr("The file %1\nexists already. Do you want to").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@0: QMessageBox::QMessageBox::NoButton); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save insilmaril@0: break; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: // New file, add extension to filename, if missing insilmaril@0: // This is always .vym or .vyp, depending on savemode insilmaril@0: if (savemode==CompleteMap) insilmaril@0: { insilmaril@0: if (!fn.contains (".vym") && !fn.contains (".xml")) insilmaril@0: fn +=".vym"; insilmaril@0: } else insilmaril@0: { insilmaril@0: if (!fn.contains (".vyp") && !fn.contains (".xml")) insilmaril@0: fn +=".vyp"; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: insilmaril@0: insilmaril@0: // Save now insilmaril@0: currentMapEditor()->setFilePath(fn); insilmaril@0: fileSave(savemode); insilmaril@0: insilmaril@0: // Set name of tab insilmaril@94: if (savemode==CompleteMap) insilmaril@94: tabWidget->setTabLabel (currentMapEditor(), insilmaril@94: currentMapEditor()->getFileName() ); insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileSaveAs() insilmaril@0: { insilmaril@0: fileSaveAs (CompleteMap); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileImportDir() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->importDir(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileExportXML() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: QString dir=browseDirectory(tr("Export XML to directory")); insilmaril@0: if (dir !="" && reallyWriteDirectory(dir) ) insilmaril@0: currentMapEditor()->exportXML(dir); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileExportHTML() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: ExportHTMLDialog dia(this); insilmaril@0: insilmaril@0: if (dia.exec()==QDialog::Accepted) insilmaril@0: { insilmaril@0: QString dir=dia.getDir(); insilmaril@0: if (reallyWriteDirectory(dir) ) insilmaril@0: { insilmaril@0: currentMapEditor()->exportXML (dia.getDir() ); insilmaril@0: dia.doExport(currentMapEditor()->getMapName() ); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileExportXHTML() insilmaril@0: { insilmaril@0: QString dir; insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: ExportXHTMLDialog dia(this); insilmaril@0: dia.setFilePath (currentMapEditor()->getFilePath() ); insilmaril@0: dia.setMapName (currentMapEditor()->getMapName() ); insilmaril@0: dia.readSettings(); insilmaril@0: insilmaril@0: if (dia.exec()==QDialog::Accepted) insilmaril@0: { insilmaril@0: QString dir=dia.getDir(); insilmaril@0: // Check, if warnings should be used before overwriting insilmaril@0: // the output directory insilmaril@0: bool ok; insilmaril@0: if (dia.warnings()) insilmaril@0: ok=reallyWriteDirectory(dir); insilmaril@0: else insilmaril@0: ok=true; insilmaril@0: insilmaril@0: if (ok) insilmaril@0: { insilmaril@0: currentMapEditor()->exportXML (dia.getDir() ); insilmaril@0: dia.doExport(currentMapEditor()->getMapName() ); insilmaril@0: if (dia.hasChanged()) insilmaril@0: currentMapEditor()->setChanged(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileExportImage(int item) insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: QString fn = QFileDialog::getSaveFileName( QString::null, "Image (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)", insilmaril@0: this ); insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: currentMapEditor()->exportImage(fn,item); insilmaril@0: } else { insilmaril@159: statusBar()->message( tr("Couldn't save %1").arg(fn), statusbarTime ); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileExportASCII() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->exportASCII(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileCloseMap() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: if (currentMapEditor()->hasChanged()) insilmaril@0: { insilmaril@0: QMessageBox mb( "VYM", insilmaril@159: tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::No, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape ); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Discard changes")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save and close insilmaril@0: fileSave(CompleteMap); insilmaril@0: break; insilmaril@0: case QMessageBox::No: insilmaril@0: // close without saving insilmaril@0: break; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: currentMapEditor()->closeMap(); insilmaril@0: tabWidget->removePage(currentMapEditor()); insilmaril@0: if (tabWidget->count()==0) insilmaril@0: actionFilePrint->setEnabled (false); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::filePrint() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->print(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::fileExitVYM() insilmaril@0: { insilmaril@0: // Check if one or more editors have changed insilmaril@0: MapEditor *me; insilmaril@0: int i; insilmaril@0: for (i=0;i<=tabWidget->count() -1;i++) insilmaril@0: { insilmaril@0: insilmaril@0: me=(MapEditor*)tabWidget->page(i); insilmaril@0: insilmaril@0: // If something changed, ask what to do insilmaril@0: if (me->isUnsaved()) insilmaril@0: { insilmaril@0: tabWidget->setCurrentPage(i); insilmaril@0: QMessageBox mb( "VYM", insilmaril@0: tr("This map is not saved yet. Do you want to"), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::No, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape ); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Save map") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Discard changes") ); insilmaril@0: mb.show(); insilmaril@0: // Call undocumented function: setActiveWindow is only insilmaril@0: // possible, if widget is visible. This depends on insilmaril@0: // windowmanager... insilmaril@0: #if defined(Q_OS_LINUX) insilmaril@0: qt_wait_for_window_manager( this); insilmaril@0: #endif insilmaril@0: mb.setActiveWindow(); insilmaril@0: switch( mb.exec() ) { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save (the changed editors) and exit insilmaril@0: fileSave(CompleteMap); insilmaril@0: break; insilmaril@0: case QMessageBox::No: insilmaril@0: // exit without saving insilmaril@0: break; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // don't save and don't exit insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: } // loop over all MEs insilmaril@0: qApp->quit(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editUndo() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->undo(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editRedo() // TODO insilmaril@0: { insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editCopy() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->copy(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editPaste() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->paste(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editCut() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->cut(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editOpenFindWindow() insilmaril@0: { insilmaril@0: findWindow->popup(); insilmaril@0: findWindow->raise(); insilmaril@0: insilmaril@0: // Call undocumented function: setActiveWindow is only insilmaril@0: // possible, if widget is visible. This depends on insilmaril@0: // windowmanager... insilmaril@0: #if defined(Q_OS_LINUX) insilmaril@0: qt_wait_for_window_manager( this); insilmaril@0: #endif insilmaril@0: findWindow->setActiveWindow(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editFind(QString s) insilmaril@0: { insilmaril@0: bool cs=false; insilmaril@0: BranchObj *bo=currentMapEditor()->findText(s, cs); insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: statusBar()->message( "Found: " + bo->getHeading(), statusbarTime ); insilmaril@0: } else insilmaril@0: { insilmaril@0: QMessageBox::information( findWindow, tr( "VYM -Information:" ), insilmaril@159: tr("No matches found for %1").arg(s)); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editFindChanged() insilmaril@0: { // Notify editor, to abort the current find process insilmaril@0: currentMapEditor()->findReset(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editOpenURL() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->openURL(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editURL() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->editURL(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editHeading2URL() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->editHeading2URL(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editBugzilla2URL() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->editBugzilla2URL(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editOpenVymLink() insilmaril@0: { insilmaril@0: // Get current path to map insilmaril@0: QString currentVymLink; insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: currentVymLink=currentMapEditor()->getVymLink(); insilmaril@0: // compare path with already loaded maps insilmaril@0: int index=-1; insilmaril@0: int i; insilmaril@0: MapEditor *me; insilmaril@0: for (i=0;i<=tabWidget->count() -1;i++) insilmaril@0: { insilmaril@0: me=(MapEditor*)tabWidget->page(i); insilmaril@0: if (currentVymLink==me->getFilePath() ) insilmaril@0: { insilmaril@0: index=i; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: if (index<0) insilmaril@0: // Load map insilmaril@0: { insilmaril@0: if (!QFile(currentVymLink).exists() ) insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@159: tr("Couldn't open map %1").arg(currentVymLink)); insilmaril@0: else insilmaril@0: { insilmaril@0: fileLoad (currentVymLink, NewMap); insilmaril@0: tabWidget->setCurrentPage (tabWidget->count()-1); insilmaril@0: } insilmaril@0: } else insilmaril@0: // Go to tab containing the map insilmaril@0: tabWidget->setCurrentPage (index); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editVymLink() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->editVymLink(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editDeleteVymLink() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->deleteVymLink(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editMapInfo() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->editMapInfo(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editMoveUp() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->moveBranchUp(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editMoveDown() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->moveBranchDown(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editToggleScroll() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: currentMapEditor()->toggleScroll(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editUnScrollAll() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: currentMapEditor()->unScrollAll(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editHeading() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->editHeading(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editNewBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->addNewBranch(0); insilmaril@0: } insilmaril@0: insilmaril@98: void Main::editNewBranchHere() insilmaril@98: { insilmaril@98: if (currentMapEditor()) insilmaril@98: currentMapEditor()->addNewBranchHere(); insilmaril@98: } insilmaril@98: insilmaril@0: void Main::editNewBranchAbove() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->addNewBranch(-1); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editNewBranchBelow() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->addNewBranch(1); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editImportAdd() insilmaril@0: { insilmaril@0: fileLoad (ImportAdd); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editImportReplace() insilmaril@0: { insilmaril@0: fileLoad (ImportReplace); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editSaveBranch() insilmaril@0: { insilmaril@0: fileSaveAs (PartOfMap); insilmaril@0: } insilmaril@0: insilmaril@98: void Main::editRemoveBranchHere() insilmaril@98: { insilmaril@98: if (currentMapEditor()) insilmaril@98: currentMapEditor()->removeBranchHere(); insilmaril@98: } insilmaril@98: insilmaril@98: void Main::editRemoveChilds() insilmaril@98: { insilmaril@98: if (currentMapEditor()) insilmaril@98: currentMapEditor()->removeChilds(); insilmaril@98: } insilmaril@98: insilmaril@0: void Main::editDeleteSelection() insilmaril@0: { insilmaril@151: if (currentMapEditor() && actionSettingsUseDelKey->isOn()) insilmaril@0: currentMapEditor()->deleteSelection(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editUpperBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectUpperBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editLowerBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectLowerBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editLeftBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectLeftBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editRightBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectRightBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editFirstBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectFirstBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editLastBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectLastBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editLoadImage() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->loadFloatImage(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editSaveImage(int item) insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->saveFloatImage(item); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::editToggleFloatExport() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->toggleFloatExport(); insilmaril@0: } insilmaril@0: insilmaril@95: void Main::editFollowXLink(int item) insilmaril@89: { insilmaril@89: if (currentMapEditor()) insilmaril@95: currentMapEditor()->followXLink(branchLinksContextMenu->indexOf(item)); insilmaril@89: } insilmaril@89: insilmaril@95: void Main::editEditXLink(int item) insilmaril@94: { insilmaril@94: if (currentMapEditor()) insilmaril@95: currentMapEditor()->editXLink(branchLinksContextMenuDup->indexOf(item)); insilmaril@94: } insilmaril@94: insilmaril@0: void Main::formatSelectColor() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: QColor col = QColorDialog::getColor( currentMapEditor()->color(), this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: currentMapEditor()->setColor( col ); insilmaril@0: colorChanged( col ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatPickColor() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: colorChanged( currentMapEditor()->pickColor() ); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::colorChanged(QColor c) insilmaril@0: { insilmaril@0: QPixmap pix( 16, 16 ); insilmaril@0: pix.fill( c ); insilmaril@0: actionFormatColor->setIconSet( pix ); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatColorItem() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->colorItem(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatColorBranch() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->colorBranch(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatLinkStyleLine() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->setLinkStyle(StyleLine); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatLinkStyleParabel() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->setLinkStyle(StyleParabel); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatLinkStylePolyLine() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->setLinkStyle(StylePolyLine); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatLinkStylePolyParabel() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->setLinkStyle(StylePolyParabel); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatSelectBackColor() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectBackgroundColor(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatSelectLinkColor() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->selectLinkColor(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatToggleLinkColorHint() insilmaril@0: { insilmaril@0: currentMapEditor()->toggleLinkColorHint(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatFrameNone() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->setFrame(NoFrame); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::formatFrameRectangle() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: currentMapEditor()->setFrame(Rectangle); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::viewZoomReset() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: QWMatrix m; insilmaril@0: m.reset(); insilmaril@0: currentMapEditor()->setWorldMatrix( m ); insilmaril@0: currentMapEditor()->setViewCenter(); insilmaril@0: currentMapEditor()->adjustCanvasSize(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::viewZoomIn() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: QWMatrix m = currentMapEditor()->worldMatrix(); insilmaril@0: m.scale( 1.25, 1.25 ); insilmaril@0: currentMapEditor()->setWorldMatrix( m ); insilmaril@0: currentMapEditor()->setViewCenter(); insilmaril@0: currentMapEditor()->adjustCanvasSize(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void Main::viewZoomOut() insilmaril@0: { insilmaril@0: if (currentMapEditor()) insilmaril@0: { insilmaril@0: QWMatrix m = currentMapEditor()->worldMatrix(); insilmaril@0: m.scale( 0.8, 0.8 ); insilmaril@0: currentMapEditor()->setWorldMatrix( m ); insilmaril@0: currentMapEditor()->setViewCenter(); insilmaril@0: currentMapEditor()->adjustCanvasSize(); insilmaril@0: } insilmaril@0: } insilmaril@89: insilmaril@89: void Main::modModeColor() insilmaril@89: { insilmaril@89: } insilmaril@89: insilmaril@89: void Main::modModeLink() insilmaril@89: { insilmaril@89: } insilmaril@89: insilmaril@0: bool Main::settingsPDF() insilmaril@0: { insilmaril@0: // Default browser is set in constructor insilmaril@0: bool ok; insilmaril@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal, insilmaril@0: settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this ); insilmaril@0: if (ok) insilmaril@0: settings.writeEntry ("/vym/mainwindow/readerPDF",text); insilmaril@0: return ok; insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: bool Main::settingsURL() insilmaril@0: { insilmaril@0: // Default browser is set in constructor insilmaril@0: bool ok; insilmaril@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal, insilmaril@0: settings.readEntry("/vym/mainwindow/readerURL") insilmaril@0: , &ok, this ); insilmaril@0: if (ok) insilmaril@0: settings.writeEntry ("/vym/mainwindow/readerURL",text); insilmaril@0: return ok; insilmaril@0: } insilmaril@0: insilmaril@0: void Main::windowToggleNoteEditor() insilmaril@0: { insilmaril@0: if (textEditor->showWithMain() ) insilmaril@0: windowHideNoteEditor(); insilmaril@0: else insilmaril@0: windowShowNoteEditor(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::windowShowNoteEditor() insilmaril@0: { insilmaril@0: textEditor->setShowWithMain(true); insilmaril@0: textEditor->show(); insilmaril@0: actionViewToggleNoteEditor->setOn (true); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::windowHideNoteEditor() insilmaril@0: { insilmaril@0: textEditor->setShowWithMain(false); insilmaril@0: textEditor->hide(); insilmaril@0: actionViewToggleNoteEditor->setOn (false); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::windowNextEditor() insilmaril@0: { insilmaril@0: if (tabWidget->currentPageIndex() < tabWidget->count()) insilmaril@0: tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::windowPreviousEditor() insilmaril@0: { insilmaril@0: if (tabWidget->currentPageIndex() >0) insilmaril@0: tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::standardFlagChanged() insilmaril@0: { insilmaril@0: currentMapEditor()->toggleStandardFlag(sender()->name()); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::testFunction() insilmaril@0: { insilmaril@0: //textEditor->stackUnder(this); insilmaril@0: currentMapEditor()->testFunction(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::testShowClipboard() insilmaril@0: { insilmaril@0: clipboardME->show(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::helpDoc() insilmaril@0: { insilmaril@0: QString docpath; insilmaril@103: #if defined(Q_OS_MACX) insilmaril@103: docpath="./vym.app/Contents/vym.pdf"; insilmaril@103: #else insilmaril@103: // default path in SUSE LINUX insilmaril@103: docpath="/usr/share/doc/packages/vym/doc/vym.pdf"; insilmaril@103: #endif insilmaril@0: insilmaril@0: if (!QFile (docpath).exists() ) insilmaril@0: { insilmaril@0: // relative path for easy testing in tarball insilmaril@0: docpath="doc/vym.pdf"; insilmaril@0: if (!QFile (docpath).exists() ) insilmaril@0: { insilmaril@0: // relative path for testing while still writing vym.tex insilmaril@0: docpath="doc/tex/vym.pdf"; insilmaril@0: if (!QFile (docpath).exists() ) insilmaril@0: { insilmaril@0: QMessageBox::critical(0, insilmaril@0: tr("Critcal error"), insilmaril@0: tr("Couldn't find the documentation\n" insilmaril@0: "vym.pdf in various places.")); insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: Process *pdfProc = new Process(); insilmaril@0: pdfProc->clearArguments(); insilmaril@0: pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF")); insilmaril@0: pdfProc->addArgument( docpath); insilmaril@0: insilmaril@0: if ( !pdfProc->start() ) insilmaril@0: { insilmaril@0: // error handling insilmaril@0: QMessageBox::critical(0, insilmaril@0: tr("Critcal error"), insilmaril@0: tr("Couldn't find a viewer to read vym.pdf.\n" insilmaril@0: "Please use Settings->")+tr("Set application to open pdf files")); insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void Main::helpAbout() insilmaril@0: { insilmaril@148: AboutDialog ad; insilmaril@150: ad.setName ("aboutwindow"); insilmaril@148: ad.setMinimumSize(500,500); insilmaril@148: ad.resize (QSize (500,500)); insilmaril@148: ad.exec(); insilmaril@0: } insilmaril@0: insilmaril@0: void Main::helpAboutQT() insilmaril@0: { insilmaril@0: QMessageBox::aboutQt( this, "Qt Application Example" ); insilmaril@0: } insilmaril@0: