main.cpp
author insilmaril
Thu, 31 Aug 2006 12:51:20 +0000
branchqt4-port
changeset 19 caba269c3757
parent 18 70c41284cb48
permissions -rw-r--r--
More undo/redo commands. Undo debug output still enabled
     1 #include <QApplication>
     2 #include <QPixmap>
     3 #include <QTranslator>
     4 #include <QDir>
     5 #include <q3ptrlist.h>
     6 #include <QTextCodec>
     7 #include <q3network.h>
     8 #include <QMenu>
     9 #include <QActionGroup>
    10 
    11 #include "settings.h"
    12 #include "options.h"
    13 #include "mainwindow.h"
    14 #include "flagrowobj.h"
    15 
    16 // Global variables
    17 TextEditor *textEditor;			// used in Constr. of LinkableMapObj
    18 								// initialized in mainwindow
    19 
    20 Main *mainWindow;				// used in BranchObj::select()								
    21 QString tmpVymDir;				// All temp files go there, created in mainwindow
    22 QString clipboardDir;			// Clipboard used in all mapEditors
    23 QDir vymBaseDir;				// Containing all styles, scripts, images, ...
    24 QDir lastImageDir;
    25 QDir lastFileDir;
    26 QString iconPath;				// Pointing to icons used for toolbars
    27 QString flagsPath;				// Pointing to flags
    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 Q3PtrList <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 *actionEditOpenMultipleURLTabs;
    50 QAction *actionEditURL;
    51 QAction *actionEditHeading2URL;
    52 QAction *actionEditBugzilla2URL;
    53 QAction *actionEditFATE2URL;
    54 QAction *actionEditOpenVymLink;
    55 QAction *actionEditOpenMultipleVymLinks;
    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 *actionSettingsAutoedit;
   107 QAction *actionSettingsUseDelKey;
   108 QAction *actionSettingsUseFlagGroups;
   109 QAction *actionSettingsUseHideExport;
   110 
   111 
   112 QMenu* branchContextMenu;
   113 QMenu* branchAddContextMenu;
   114 QMenu* branchRemoveContextMenu;
   115 QMenu* branchLinksContextMenu;
   116 QMenu* branchXLinksContextMenuEdit;
   117 QMenu* branchXLinksContextMenuFollow;
   118 QMenu* floatimageContextMenu;
   119 QMenu* canvasContextMenu;
   120 QMenu* fileLastMapsMenu;
   121 QMenu* fileImportMenu;
   122 QMenu* fileExportMenu;
   123 
   124 
   125 Settings settings ("InSilmaril","vym"); // Organization, Application name
   126 
   127 Options options;
   128 ImageIO imageIO;
   129 
   130 int statusbarTime=3500;
   131 
   132 int main(int argc, char** argv)
   133 {
   134 //FIXME	Q_INIT_RESOURCE (application);
   135 
   136     QApplication app(argc,argv);
   137 
   138 
   139 	// Reading and initializing options commandline options
   140 	options.add ("version", SwitchOption, "v","version");
   141 	options.add ("local", SwitchOption, "l", "local");
   142 	options.add ("help", SwitchOption, "h", "help");
   143 	options.add ("quit", SwitchOption, "q", "quit");
   144 	options.add ("test", StringOption, "t", "test");
   145 	options.setHelpText (
   146 		"VYM - View Your Mind\n"
   147 		"--------------------\n\n"
   148 		"Information about vym can be found in vym.pdf,\n"
   149 		"which should be part of the vym package.\n"
   150 		"It is also available at the project homepage:\n\n"
   151 		"http://www.InSilmaril.de/vym\n");
   152 	if (options.parse())
   153 	{
   154 		cout << endl << options.getHelpText().ascii()<<endl;
   155 		return 1;
   156 	}
   157 
   158 	if (options.isOn ("version"))
   159 	{
   160 		cout << "vym version "<<__VYM_VERSION
   161 			<<"  (c) 2004-2006 Uwe Drechsel - "
   162 			<<__BUILD_DATE<<endl;
   163 			
   164 		return 0;	
   165 	}		
   166 	
   167 	// Use /usr/share/vym or /usr/local/share/vym or . ?
   168 	// First try options
   169 	if (options.isOn ("local"))
   170 	{
   171 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
   172 	} else
   173 	// then look for environment variable
   174 	if (getenv("VYMHOME")!=0)
   175 	{
   176 		vymBaseDir.setPath (getenv("VYMHOME"));
   177 	} else
   178 	// ok, let's find my way on my own
   179 	{
   180 		vymBaseDir.setPath ("/usr/share/vym");
   181 		if (!vymBaseDir.exists())
   182 		{
   183 			vymBaseDir.setPath ("/usr/local/share/vym");
   184 			if (!vymBaseDir.exists())
   185 				vymBaseDir.setPath(vymBaseDir.currentDirPath() );
   186 		}		
   187 	}
   188 
   189 	iconPath=vymBaseDir.path()+"/icons/";
   190 	flagsPath=vymBaseDir.path()+"/flags/";
   191 
   192 	// Some directories
   193 	lastImageDir=QDir().current();
   194 	lastFileDir=QDir().current();
   195 
   196 	if (options.isOn ("help"))
   197 	{
   198 		cout << options.getHelpText().ascii()<<endl;
   199 		return 0;	
   200 	}	
   201 
   202     q3InitNetworkProtocols();
   203 
   204 
   205 	// Initialize translations
   206 	QTranslator translator (0);
   207 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   208     app.installTranslator( &translator );
   209 
   210 	// Initializing the row of system flags
   211 	// is done in first call to MapEditor(),
   212 	// because we need at least one canvas first
   213 	systemFlagsDefault=NULL;
   214 	standardFlagsDefault=NULL;
   215 
   216 	// Initialize window of TextEditor
   217 	textEditor = new TextEditor();
   218 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   219 	if (textEditor->showWithMain()) textEditor->show();
   220 
   221 	// Initialize mainwindow 
   222     Main m;
   223 	//m.resize(m.sizeHint());
   224 	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
   225 	m.show();
   226 	m.fileNew();
   227 	m.loadCmdLine();
   228 
   229 	// For benchmarking we may want to quit immediatly after drawing
   230 	if (options.isOn ("quit"))
   231 	{
   232 		return 0;
   233 	}	
   234 
   235     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   236 
   237     return app.exec();
   238 }
   239