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