main.cpp
author insilmaril
Wed, 14 Jun 2006 10:28:01 +0000
branchqt4-port
changeset 5 5cfbba1dc2f8
parent 4 ec3d2962893d
child 7 84f76a3876d7
permissions -rw-r--r--
Ported TextEditor Actions to QT4
     1 #include <QApplication>
     2 #include <qpixmap.h>
     3 #include <qtranslator.h>
     4 #include <qdir.h>
     5 #include <q3ptrlist.h>
     6 #include <qtextcodec.h>
     7 #include <q3network.h>
     8 #include <qmime.h>
     9 //Added by qt3to4:
    10 #include <Q3PopupMenu>
    11 #include <QActionGroup>
    12 
    13 #include "settings.h"
    14 #include "options.h"
    15 #include "mainwindow.h"
    16 
    17 #include "flagrowobj.h"
    18 
    19 // Global variables
    20 TextEditor *textEditor;			// used in Constr. of LinkableMapObj
    21 								// initialized in mainwindow
    22 
    23 Main *mainWindow;				// used in BranchObj::select()								
    24 QString tmpVymDir;				// All temp files go there, created in mainwindow
    25 QString clipboardDir;			// Clipboard used in all mapEditors
    26 QDir vymBaseDir;				// Containing all styles, scripts, images, ...
    27 QDir lastImageDir;
    28 QString iconPath;				// Pointing to icons used for toolbars
    29 QString flagsPath;				// Pointing to flags
    30 bool clipboardEmpty;			
    31 FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
    32 FlagRowObj *standardFlagsDefault;
    33 
    34 // Lists of actions
    35 // (QActionGroup could not be "enabled")
    36 Q3PtrList <QAction> actionListBranches;
    37 
    38 // Actions which change sometimes
    39 QAction *actionFileSave;
    40 QAction *actionFilePrint;
    41 QAction *actionEditUndo;
    42 QAction *actionEditRedo;
    43 QAction *actionEditCopy;
    44 QAction *actionEditCut;
    45 QAction *actionEditPaste;
    46 QAction *actionEditMoveUp;
    47 QAction *actionEditMoveDown;
    48 QAction *actionEditToggleScroll;
    49 QAction *actionEditOpenURL;
    50 QAction *actionEditOpenURLTab;
    51 QAction *actionEditURL;
    52 QAction *actionEditHeading2URL;
    53 QAction *actionEditBugzilla2URL;
    54 QAction *actionEditFATE2URL;
    55 QAction *actionEditOpenVymLink;
    56 QAction *actionEditVymLink;
    57 QAction *actionEditToggleHideExport;
    58 QAction *actionEditDeleteVymLink;
    59 QAction *actionEditMapInfo;
    60 QAction *actionEditHeading;
    61 QAction *actionEditDelete;
    62 QAction *actionEditAddBranch;
    63 QAction *actionEditAddBranchHere;
    64 QAction *actionEditAddBranchAbove;
    65 QAction *actionEditAddBranchBelow;
    66 QAction *actionEditRemoveBranchKeepChilds;
    67 QAction *actionEditRemoveChilds;
    68 QAction *actionEditImportAdd;
    69 QAction *actionEditImportReplace;
    70 QAction *actionEditSaveBranch;
    71 QAction *actionEditSelectFirst;
    72 QAction *actionEditSelectLast;
    73 QAction *actionEditLoadImage;
    74 
    75 QAction *actionFormatColor;		
    76 QAction *actionFormatPickColor;		
    77 QAction *actionFormatColorBranch;
    78 QAction *actionFormatColorSubtree;
    79 QAction *actionFormatBackColor;
    80 QAction *actionFormatLinkColorHint;
    81 QAction *actionFormatLinkColor;		
    82 
    83 QActionGroup *actionGroupModModes;
    84 QAction *actionModModeColor;
    85 QAction *actionModModeLink;
    86 QAction *actionModModeCopy;
    87 
    88 QActionGroup *actionGroupFormatFrameTypes;
    89 QAction *actionFormatFrameNone;
    90 QAction *actionFormatFrameRectangle;
    91 
    92 QActionGroup *actionGroupFormatLinkStyles;
    93 QAction *actionFormatIncludeImagesVer;
    94 QAction *actionFormatIncludeImagesHor;
    95 QAction *actionFormatHideLinkUnselected;
    96 QAction *actionFormatLinkStyleLine;
    97 QAction *actionFormatLinkStyleParabel;
    98 QAction *actionFormatLinkStylePolyLine;
    99 QAction *actionFormatLinkStylePolyParabel;
   100 
   101 QAction *actionViewToggleNoteEditor;
   102 QAction *actionViewToggleHistoryWindow;
   103 
   104 QAction *actionSettingsAutoselectHeading;
   105 QAction *actionSettingsAutoselectText;
   106 QAction *actionSettingsPasteNewHeading;
   107 QAction *actionSettingsAutoedit;
   108 QAction *actionSettingsUseDelKey;
   109 QAction *actionSettingsUseFlagGroups;
   110 QAction *actionSettingsUseHideExport;
   111 
   112 
   113 QMenu* branchContextMenu;
   114 QMenu* branchAddContextMenu;
   115 QMenu* branchRemoveContextMenu;
   116 QMenu* branchLinksContextMenu;
   117 QMenu* branchLinksContextMenuDup;
   118 QMenu* floatimageContextMenu;
   119 QMenu* saveImageFormatMenu;
   120 QMenu* canvasContextMenu;
   121 QMenu* fileLastMapsMenu;
   122 QMenu* fileImportMenu;
   123 QMenu* fileExportMenu;
   124 
   125 
   126 Settings settings ("vym","vym"); // Organization, Application name
   127 Options options;
   128 ImageIO imageIO;
   129 
   130 int statusbarTime=3500;
   131 
   132 int main(int argc, char** argv)
   133 {
   134     QApplication app(argc,argv);
   135 
   136 
   137 	// Reading and initializing options commandline options
   138 	options.add ("version", SwitchOption, "v","version");
   139 	options.add ("local", SwitchOption, "l", "local");
   140 	options.add ("help", SwitchOption, "h", "help");
   141 	options.add ("quit", SwitchOption, "q", "quit");
   142 	options.add ("test", StringOption, "t", "test");
   143 	options.setHelpText (
   144 		"VYM - View Your Mind\n"
   145 		"--------------------\n\n"
   146 		"Information about vym can be found in vym.pdf,\n"
   147 		"which should be part of the vym package.\n"
   148 		"It is also available at the project homepage:\n\n"
   149 		"http://www.InSilmaril.de/vym\n");
   150 	if (options.parse())
   151 	{
   152 //FIXME QT3		cout << endl << options.getHelpText()<<endl;
   153 		return 1;
   154 	}
   155 
   156 	if (options.isOn ("version"))
   157 	{
   158 		cout << "vym version "<<__VYM_VERSION
   159 			<<"  (c) 2004 Uwe Drechsel - "
   160 			<<__BUILD_DATE<<endl;
   161 			
   162 		return 0;	
   163 	}		
   164 	
   165 	// Use /usr/share/vym or /usr/local/share/vym or . ?
   166 	// First try options
   167 	if (options.isOn ("local"))
   168 	{
   169 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
   170 	} else
   171 	// then look for environment variable
   172 	if (getenv("VYMHOME")!=0)
   173 	{
   174 		vymBaseDir.setPath (getenv("VYMHOME"));
   175 	} else
   176 	// ok, let's find my way on my own
   177 	{
   178 		vymBaseDir.setPath ("/usr/share/vym");
   179 		if (!vymBaseDir.exists())
   180 		{
   181 			vymBaseDir.setPath ("/usr/local/share/vym");
   182 			if (!vymBaseDir.exists())
   183 				vymBaseDir.setPath(vymBaseDir.currentDirPath() );
   184 		}		
   185 	}
   186 
   187 	iconPath=vymBaseDir.path()+"/icons/";
   188 	flagsPath=vymBaseDir.path()+"/flags/";
   189 
   190 	// Some directories
   191 	lastImageDir=QDir().home();
   192 
   193 	if (options.isOn ("help"))
   194 	{
   195 		cout << options.getHelpText().ascii()<<endl;
   196 		return 0;	
   197 	}	
   198 
   199 	if (options.isOn ("test"))
   200 	{
   201 		// FIXME testing string option only
   202 		cout << "Testing: "<<options.getArg("test").ascii()<< endl;
   203 	}	
   204 
   205 
   206     Q3MimeSourceFactory *factory = Q3MimeSourceFactory::defaultFactory();
   207     factory->setPixmap("vym-128x128", QPixmap(iconPath+"vym-128x128.png"));
   208     q3InitNetworkProtocols();
   209 
   210 
   211 	// Initialize translations
   212 	QTranslator translator (0);
   213 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   214     app.installTranslator( &translator );
   215 
   216 	// Initializing the row of system flags
   217 	// is done in first call to MapEditor(),
   218 	// because we need at least one canvas first
   219 	systemFlagsDefault=NULL;
   220 	standardFlagsDefault=NULL;
   221 
   222 	// Initialize window of TextEditor
   223 	textEditor = new TextEditor();
   224 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   225 	if (textEditor->showWithMain()) textEditor->show();
   226 
   227 	// Initialize mainwindow 
   228     Main m;
   229 	//m.resize(m.sizeHint());
   230 	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
   231 	m.show();
   232 	m.fileNew();
   233 	m.loadCmdLine();
   234 
   235 	// For benchmarking we may want to quit immediatly after drawing
   236 	if (options.isOn ("quit"))
   237 	{
   238 		return 0;
   239 	}	
   240 
   241     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   242 
   243     return app.exec();
   244 }
   245