# HG changeset patch # User insilmaril # Date 1150206893 0 # Node ID ec3d2962893dd2447fae82ca76c8c9facb2d7009 # Parent 6a0342b3c519a0c7bacc7cc3f4b27fec2a5bd2c4 ported File Menu to QT4 diff -r 6a0342b3c519 -r ec3d2962893d file.cpp --- a/file.cpp Tue Jun 13 08:49:12 2006 +0000 +++ b/file.cpp Tue Jun 13 13:54:53 2006 +0000 @@ -303,3 +303,38 @@ } } +ImageIO::ImageIO () +{ + // Create list with supported image types + // foreach (QByteArray format, QImageWriter::supportedImageFormats()) + // imageTypes.append( tr("%1...").arg(QString(format).toUpper())); + imageFilters.append ("Images (*.png *.jpg *.jpeg *.bmp *.bmp *.ppm *.xpm *.xbm)"); + imageTypes.append ("PNG"); + imageFilters.append ("Portable Network Graphics (*.png)"); + imageTypes.append ("PNG"); + imageFilters.append ("Joint Photographic Experts Group (*.jpg)"); + imageTypes.append ("JPG"); + imageFilters.append ("Joint Photographic Experts Group (*.jpeg)"); + imageTypes.append ("JPG"); + imageFilters.append ("Windows Bitmap (*.bmp)"); + imageTypes.append ("BMP"); + imageFilters.append ("Portable Pixmap (*.ppm)"); + imageTypes.append ("PPM"); + imageFilters.append ("X11 Bitmap (*.xpm)"); + imageTypes.append ("XPM"); + imageFilters.append ("X11 Bitmap (*.xbm)"); + imageTypes.append ("XBM"); +} + +QStringList ImageIO::getFilters() +{ + return imageFilters; +} + +QString ImageIO::getType(QString filter) +{ + for (int i=0;i //#include // for random seed - #include #include #include @@ -131,23 +130,25 @@ extern QAction* actionSettingsUseFlagGroups; extern QAction* actionSettingsUseHideExport; -extern Q3PopupMenu* branchContextMenu; -extern Q3PopupMenu* branchAddContextMenu; -extern Q3PopupMenu* branchRemoveContextMenu; -extern Q3PopupMenu* branchLinksContextMenu; -extern Q3PopupMenu* branchLinksContextMenuDup; -extern Q3PopupMenu* floatimageContextMenu; -extern Q3PopupMenu* saveImageFormatMenu; -extern Q3PopupMenu* canvasContextMenu; -extern Q3PopupMenu* lastMapsMenu; -extern Q3PopupMenu* importMenu; -extern Q3PopupMenu* exportMenu; -extern Q3PopupMenu* exportImageFormatMenu; +extern QMenu* branchContextMenu; +extern QMenu* branchAddContextMenu; +extern QMenu* branchRemoveContextMenu; +extern QMenu* branchLinksContextMenu; +extern QMenu* branchLinksContextMenuDup; +extern QMenu* floatimageContextMenu; +extern QMenu* saveImageFormatMenu; +extern QMenu* canvasContextMenu; +extern QMenu* fileLastMapsMenu; +extern QMenu* fileImportMenu; +extern QMenu* fileExportMenu; extern Settings settings; extern Options options; +extern ImageIO imageIO; + extern QDir vymBaseDir; +extern QDir lastImageDir; extern QString iconPath; extern QString flagsPath; @@ -234,7 +235,7 @@ setupHelpActions(); // After menu is created, we can enable some actions - actionFilePrint->setEnabled (true); +//FIXME testing actionFilePrint->setEnabled (true); statusBar(); @@ -321,97 +322,130 @@ // File Actions void Main::setupFileActions() { + QMenu *fileMenu = menuBar()->addMenu ( tr ("&File") ); QToolBar *tb = addToolBar( tr ("&File") ); - Q3PopupMenu *menu = new Q3PopupMenu( this ); - menuBar()->insertItem( tr( "&File" ), menu ); - - // Keycodes: /usr/lib64/qt3/include/qnamespace.h QAction *a; a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&New..." ),this); a->setStatusTip ( tr( "New map","File menu" ) ); a->setShortcut ( Qt::CTRL + Qt::Key_N ); a->addTo( tb ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Open..." ),this); a->setStatusTip (tr( "Open","File menu" ) ); a->setShortcut ( Qt::CTRL + Qt::Key_O ); a->addTo( tb ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) ); - lastMapsMenu = new Q3PopupMenu (this); - - menu->insertItem (tr("Open Recent"),lastMapsMenu ); - menu->insertSeparator(); + fileLastMapsMenu = fileMenu->addMenu (tr("Open Recent")); + fileMenu->addSeparator(); a = new QAction( QPixmap( iconPath+"filesave.png"), tr( "&Save..." ), this); a->setStatusTip ( tr( "Save" )); a->setShortcut (Qt::CTRL + Qt::Key_S ); a->addTo( tb ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) ); actionFileSave=a; a = new QAction( QPixmap(iconPath+"filesaveas.png"), tr( "Save &As..." ), this); a->setStatusTip (tr( "Save &As" ) ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) ); - menu->insertSeparator(); - - importMenu = new Q3PopupMenu (this); - menu->insertItem (tr("Import"),importMenu ); + fileMenu->addSeparator(); + + fileImportMenu = fileMenu->addMenu (tr("Import")); a = new QAction(tr("KDE Bookmarks"), this); a->setStatusTip ( tr( "Import")+" "+tr("KDE Bookmarks" )); - a->addTo (importMenu); + a->addTo (fileImportMenu); connect( a, SIGNAL( activated() ), this, SLOT( fileImportKDEBookmarks() ) ); if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) { a = new QAction( QPixmap(), tr("Firefox Bookmarks"),this); a->setStatusTip (tr( "Import")+" "+tr("Firefox Bookmarks" ) ); - a->addTo (importMenu); + a->addTo (fileImportMenu); connect( a, SIGNAL( activated() ), this, SLOT( fileImportFirefoxBookmarks() ) ); } a = new QAction("Mind Manager...",this); a->setStatusTip ( tr( "Import")+" Mind Manager" ); - a->addTo (importMenu); + fileImportMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileImportMM() ) ); a = new QAction( tr( "Import Dir"+QString("...") ), this); a->setStatusTip (tr( "Import directory structure (experimental)" ) ); - a->addTo( importMenu); + fileImportMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) ); - exportMenu = new Q3PopupMenu (this); - menu->insertItem (tr("Export"),exportMenu ); - - menu->insertSeparator(); - + fileExportMenu = fileMenu->addMenu (tr("Export")); + + a = new QAction( tr("Image")+QString("..."), this); + a->setStatusTip( tr( "Export map as image" )); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportImage() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "Open Office"+QString("..."), this); + a->setStatusTip( tr( "Export in Open Document Format used e.g. in Open Office " )); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "Webpage (XHTML)...",this ); + a->setShortcut (Qt::ALT + Qt::Key_X); + a->setStatusTip ( tr( "Export as")+" webpage (XHTML)"); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "Text (ASCII)...", this); + a->setStatusTip ( tr( "Export as")+" ASCII"+" "+tr("(still experimental)" )); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) ); + fileExportMenu->addAction (a); + + a = new QAction( tr("KDE Bookmarks"), this); + a->setStatusTip( tr( "Export as")+" "+tr("KDE Bookmarks" )); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportKDEBookmarks() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "Taskjuggler...", this ); + a->setStatusTip( tr( "Export as")+" Taskjuggler"+" "+tr("(still experimental)" )); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportTaskjuggler() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "LaTeX...", this); + a->setStatusTip( tr( "Export as")+" LaTeX"+" "+tr("(still experimental)" )); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportLaTeX() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "XML..." , this ); + a->setStatusTip (tr( "Export as")+" XML"); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) ); + fileExportMenu->addAction (a); + + fileMenu->addSeparator(); a = new QAction(QPixmap( iconPath+"fileprint.png"), tr( "&Print")+QString("..."), this); a->setStatusTip ( tr( "Print" ) ); a->setShortcut (Qt::CTRL + Qt::Key_P ); a->addTo( tb ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) ); actionFilePrint=a; a = new QAction( QPixmap(iconPath+"fileclose.png"), tr( "&Close Map" ), this); a->setStatusTip (tr( "Close Map" ) ); a->setShortcut (Qt::ALT + Qt::Key_C ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) ); a = new QAction(QPixmap(iconPath+"exit.png"), tr( "E&xit")+" "+__VYM, this); a->setStatusTip ( tr( "Exit")+" "+__VYM ); a->setShortcut (Qt::CTRL + Qt::Key_Q ); - a->addTo( menu ); + fileMenu->addAction (a); connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) ); } @@ -1435,34 +1469,34 @@ QAction*a; // Context Menu for branch or mapcenter - branchContextMenu =new Q3PopupMenu (this); + branchContextMenu =new QMenu (this); // Submenu "Add" - branchAddContextMenu =new Q3PopupMenu (this); - actionEditPaste->addTo ( branchAddContextMenu ); - actionEditAddBranch->addTo ( branchAddContextMenu ); - actionEditAddBranchHere->addTo ( branchAddContextMenu ); - actionEditAddBranchAbove->addTo ( branchAddContextMenu ); - actionEditAddBranchBelow->addTo ( branchAddContextMenu ); - branchAddContextMenu->insertSeparator(); - actionEditLoadImage->addTo( branchAddContextMenu ); - branchAddContextMenu->insertSeparator(); - actionEditImportAdd->addTo ( branchAddContextMenu ); - actionEditImportReplace->addTo ( branchAddContextMenu ); + branchAddContextMenu =branchContextMenu->addMenu (tr("Add")); + branchAddContextMenu->addAction (actionEditPaste ); + branchAddContextMenu->addAction ( actionEditAddBranch ); + branchAddContextMenu->addAction ( actionEditAddBranchHere ); + branchAddContextMenu->addAction ( actionEditAddBranchAbove); + branchAddContextMenu->addAction ( actionEditAddBranchBelow ); + branchAddContextMenu->addSeparator(); + branchAddContextMenu->addAction ( actionEditLoadImage); + branchAddContextMenu->addSeparator(); + branchAddContextMenu->addAction ( actionEditLoadImage); + branchAddContextMenu->addAction ( actionEditImportAdd ); + branchAddContextMenu->addAction ( actionEditImportReplace ); // Submenu "Remove" - branchRemoveContextMenu =new Q3PopupMenu (this); - actionEditCut->addTo ( branchRemoveContextMenu ); - actionEditDelete->addTo ( branchRemoveContextMenu ); - actionEditRemoveBranchKeepChilds->addTo( branchRemoveContextMenu ); - actionEditRemoveChilds->addTo( branchRemoveContextMenu ); + branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove")); + branchRemoveContextMenu->addAction (actionEditCut); + branchRemoveContextMenu->addAction ( actionEditDelete ); + branchRemoveContextMenu->addAction ( actionEditRemoveBranchKeepChilds ); + branchRemoveContextMenu->addAction ( actionEditRemoveChilds ); - branchContextMenu->insertItem (tr("Add"),branchAddContextMenu); - branchContextMenu->insertItem (tr("Remove"),branchRemoveContextMenu); actionEditSaveBranch->addTo( branchContextMenu ); - branchContextMenu->insertSeparator(); +/* + branchContextMenu->addSeparator(); actionEditOpenURL->addTo ( branchContextMenu ); actionEditOpenURLTab->addTo ( branchContextMenu ); actionEditURL->addTo ( branchContextMenu ); @@ -1496,19 +1530,17 @@ branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu); connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) ); +*/ // Context menu for floatimage - floatimageContextMenu =new Q3PopupMenu (this); - saveImageFormatMenu=new Q3PopupMenu (this); - exportImageFormatMenu=new Q3PopupMenu (this); - -/* FIXME strange error + floatimageContextMenu =new QMenu (this); + saveImageFormatMenu=floatimageContextMenu->addMenu (tr("Save image")); + foreach (QByteArray format, QImageWriter::supportedImageFormats()) { QString text = tr("%1...").arg(QString(format).toUpper()); - saveImageFormatMenu->insertItem( text ); - exportImageFormatMenu->insertItem( text ); + a= new QAction (text,this); + saveImageFormatMenu->addAction ( a ); } -*/ /* FIXME not needed any longer Q3StrList fmt = QImageWriter::supportedImageFormats(); @@ -1518,57 +1550,19 @@ exportImageFormatMenu->insertItem( f ); } */ - connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) ); - connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) ); - floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu ); +// connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) ); +// connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) ); - floatimageContextMenu->insertSeparator(); + floatimageContextMenu->addSeparator(); actionEditCopy->addTo( floatimageContextMenu ); actionEditCut->addTo( floatimageContextMenu ); - floatimageContextMenu->insertSeparator(); - actionFormatHideLinkUnselected->addTo( floatimageContextMenu ); - - exportMenu->insertItem ( tr("Export as")+" Image",exportImageFormatMenu); - - a = new QAction( "Open Office"+QString("..."), this); - a->setStatusTip( tr( "Export in Open Document Format used e.g. in Open Office " )); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) ); - a->addTo (exportMenu); - - a = new QAction( "Webpage (XHTML)...",this ); - a->setShortcut (Qt::ALT + Qt::Key_X); - a->setStatusTip ( tr( "Export as")+" webpage (XHTML)"); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) ); - a->addTo( exportMenu ); - - a = new QAction( "Text (ASCII)...", this); - a->setStatusTip ( tr( "Export as")+" ASCII"+" "+tr("(still experimental)" )); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) ); - a->addTo( exportMenu ); - - a = new QAction( tr("KDE Bookmarks"), this); - a->setStatusTip( tr( "Export as")+" "+tr("KDE Bookmarks" )); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportKDEBookmarks() ) ); - a->addTo (exportMenu); - - a = new QAction( "Taskjuggler...", this ); - a->setStatusTip( tr( "Export as")+" Taskjuggler"+" "+tr("(still experimental)" )); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportTaskjuggler() ) ); - a->addTo( exportMenu ); - - a = new QAction( "LaTeX...", this); - a->setStatusTip( tr( "Export as")+" LaTeX"+" "+tr("(still experimental)" )); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportLaTeX() ) ); - a->addTo( exportMenu ); - - a = new QAction( "XML..." , this ); - a->setStatusTip (tr( "Export as")+" XML"); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) ); - a->addTo( exportMenu ); + floatimageContextMenu->addSeparator(); + floatimageContextMenu->addAction ( actionFormatHideLinkUnselected ); + // Context menu for canvas - canvasContextMenu =new Q3PopupMenu (this); + canvasContextMenu =new QMenu (this); actionEditMapInfo->addTo( canvasContextMenu ); canvasContextMenu->insertSeparator(); actionGroupFormatLinkStyles->addTo( canvasContextMenu ); @@ -1588,7 +1582,7 @@ lastMaps.append(s); } setupLastMapsMenu(); - connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) ); +// connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) ); } void Main::setupLastMapsMenu() @@ -1614,9 +1608,11 @@ while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back(); // build Menu from lastMaps string list - lastMapsMenu->clear(); + fileLastMapsMenu->clear(); + /* FIXME add actions instead of strings in QT4 for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) - lastMapsMenu->insertItem (*it ); + fileLastMapsMenu->addAction (*it ); + */ } @@ -1960,7 +1956,7 @@ void Main::fileLoadLast(int i) { - fileLoad(QString(*lastMaps.at(lastMapsMenu->indexOf (i)) ),NewMap); + fileLoad(QString(*lastMaps.at(fileLastMapsMenu->indexOf (i)) ),NewMap); } void Main::fileSave(const SaveMode &savemode) @@ -2263,18 +2259,23 @@ } } -void Main::fileExportImage(int item) +void Main::fileExportImage() { MapEditor *me=currentMapEditor(); if (me) { - QString fn = Q3FileDialog::getSaveFileName( QString::null, "Image (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)", - this ); - if ( !fn.isEmpty() ) - me->exportImage(fn,item); - else - statusBar()->message( tr("Couldn't save %1").arg(fn), statusbarTime ); - + QStringList fl; + QFileDialog *fd=new QFileDialog (this); + fd->setCaption (tr("Export map as image")); + fd->setFileMode(QFileDialog::AnyFile); + fd->setFilters (imageIO.getFilters() ); + fd->setDirectory (lastImageDir); + if (fd->exec()) + { + fl=fd->selectedFiles(); + qWarning ("Selected "+fl.first()+" filter: "+fd->selectedFilter()); + me->exportImage (fl.first(), imageIO.getType (fd->selectedFilter() ) ); + } } } diff -r 6a0342b3c519 -r ec3d2962893d mainwindow.h --- a/mainwindow.h Tue Jun 13 08:49:12 2006 +0000 +++ b/mainwindow.h Tue Jun 13 13:54:53 2006 +0000 @@ -75,7 +75,7 @@ void fileImportDir(); void fileExportXML(); void fileExportXHTML(); - void fileExportImage(int); + void fileExportImage(); void fileExportASCII(); void fileExportLaTeX(); void fileExportKDEBookmarks(); @@ -190,6 +190,8 @@ int maxLastMaps; QString lastFileDir; Q3Process *procBrowser; + + QStringList imageTypes; }; diff -r 6a0342b3c519 -r ec3d2962893d mapeditor.cpp --- a/mapeditor.cpp Tue Jun 13 08:49:12 2006 +0000 +++ b/mapeditor.cpp Tue Jun 13 13:54:53 2006 +0000 @@ -127,18 +127,25 @@ extern QAction *actionSettingsPasteNewHeading; extern QAction *actionSettingsUseFlagGroups; -extern Q3PopupMenu *branchContextMenu; -extern Q3PopupMenu *branchLinksContextMenu; -extern Q3PopupMenu *branchLinksContextMenuDup; -extern Q3PopupMenu *floatimageContextMenu; -extern Q3PopupMenu *saveImageFormatMenu; -extern Q3PopupMenu *exportImageFormatMenu; -extern Q3PopupMenu *canvasContextMenu; +extern QMenu* branchContextMenu; +extern QMenu* branchAddContextMenu; +extern QMenu* branchRemoveContextMenu; +extern QMenu* branchLinksContextMenu; +extern QMenu* branchLinksContextMenuDup; +extern QMenu* floatimageContextMenu; +extern QMenu* saveImageFormatMenu; +extern QMenu* canvasContextMenu; +extern QMenu* lastMapsMenu; +extern QMenu* importMenu; +extern QMenu* exportMenu; + extern Settings settings; +extern ImageIO imageIO; extern QString iconPath; extern QDir vymBaseDir; +extern QDir lastImageDir; int MapEditor::mapNum=0; // make instance @@ -1124,14 +1131,14 @@ setHideTmpMode (HideNone); } -void MapEditor::exportImage(QString fn, int item) +void MapEditor::exportImage(QString fn, QString format) { // Finish open lineEdits if (lineedit) finishedLineEdit(); setExportMode (true); QPixmap pix (getPixmap()); - pix.save(fn, exportImageFormatMenu->text(item) ); + pix.save(fn, format); setExportMode (false); } @@ -2506,6 +2513,7 @@ void MapEditor::updateActions() { +return; //FIXME testing QAction *a; if (getLinkColorHint()==HeadingColor) actionFormatLinkColorHint->setOn(true); @@ -2850,7 +2858,8 @@ if ( fd->exec() == QDialog::Accepted ) { saveState(selection, QString("Add floatimage to %1").arg(getName(selection))); - lastImageDir=fn.left(fn.findRev ("/")); + // FIXME in QT4 use: lastImageDir=fd->directory(); + lastImageDir=QDir (fd->dirPath()); QStringList flist = fd->selectedFiles(); QStringList::Iterator it = flist.begin(); while( it != flist.end() ) diff -r 6a0342b3c519 -r ec3d2962893d mapeditor.h --- a/mapeditor.h Tue Jun 13 08:49:12 2006 +0000 +++ b/mapeditor.h Tue Jun 13 13:54:53 2006 +0000 @@ -81,8 +81,8 @@ HideTmpMode getHideTmpMode(); // temporary hide stuff public: void setExportMode (bool); // temporary hide stuff during export - void exportImage (QString fn); // export as PNG - void exportImage (QString fn, int); // export in given format + void exportImage (QString fn); // export as PNG + void exportImage (QString fn, QString); // export in given format void exportOOPresentation(const QString &,const QString &); void exportXML(const QString&); // export to directory void clear(); // clear map @@ -235,7 +235,6 @@ QString fileDir; // dir where file is saved QString destPath; // path to .vym file (needed for vymlinks) QString mapName; // fileName without ".vym" - QString lastImageDir; // save dir for adding images bool isInteractive; // non interactive don't need tmpdirs QString tmpMapDir; // tmp directory with data for undo/redo