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