main.cpp
author insilmaril
Mon, 27 Mar 2006 20:21:58 +0000
changeset 265 96b8406d4a2f
parent 260 69d648a0a15b
child 266 7d91b35c1b6f
permissions -rw-r--r--
More documentation, fixed small bug where links of unselected objects where visible again
     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 *actionEditURL;
    49 QAction *actionEditHeading2URL;
    50 QAction *actionEditBugzilla2URL;
    51 QAction *actionEditFATE2URL;
    52 QAction *actionEditOpenVymLink;
    53 QAction *actionEditVymLink;
    54 QAction *actionEditToggleHideExport;
    55 QAction *actionEditDeleteVymLink;
    56 QAction *actionEditMapInfo;
    57 QAction *actionEditHeading;
    58 QAction *actionEditDelete;
    59 QAction *actionEditAddBranch;
    60 QAction *actionEditAddBranchHere;
    61 QAction *actionEditAddBranchAbove;
    62 QAction *actionEditAddBranchBelow;
    63 QAction *actionEditRemoveBranchHere;
    64 QAction *actionEditRemoveChilds;
    65 QAction *actionEditImportAdd;
    66 QAction *actionEditImportReplace;
    67 QAction *actionEditSaveBranch;
    68 QAction *actionEditSelectFirst;
    69 QAction *actionEditSelectLast;
    70 QAction *actionEditLoadImage;
    71 
    72 QAction *actionFormatColor;		
    73 QAction *actionFormatPickColor;		
    74 QAction *actionFormatColorBranch;
    75 QAction *actionFormatColorSubtree;
    76 QAction *actionFormatBackColor;
    77 QAction *actionFormatLinkColorHint;
    78 QAction *actionFormatLinkColor;		
    79 
    80 QActionGroup *actionGroupModModes;
    81 QAction *actionModModeColor;
    82 QAction *actionModModeLink;
    83 QAction *actionModModeCopy;
    84 
    85 QActionGroup *actionGroupFormatFrameTypes;
    86 QAction *actionFormatFrameNone;
    87 QAction *actionFormatFrameRectangle;
    88 
    89 QActionGroup *actionGroupFormatLinkStyles;
    90 QAction *actionFormatIncludeImagesVer;
    91 QAction *actionFormatIncludeImagesHor;
    92 QAction *actionFormatHideLinkUnselected;
    93 QAction *actionFormatLinkStyleLine;
    94 QAction *actionFormatLinkStyleParabel;
    95 QAction *actionFormatLinkStylePolyLine;
    96 QAction *actionFormatLinkStylePolyParabel;
    97 
    98 QAction *actionViewToggleNoteEditor;
    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 	QDir vymBaseDir;
   162 	if (options.isOn ("local"))
   163 	{
   164 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
   165 	}else
   166 	{
   167 		vymBaseDir.setPath ("/usr/share/vym");
   168 		if (!vymBaseDir.exists())
   169 			vymBaseDir.setPath ("/usr/local/share/vym");
   170 		if (!vymBaseDir.exists())
   171 			vymBaseDir.setPath(vymBaseDir.currentDirPath() );
   172 	}
   173 
   174 	if (options.isOn ("help"))
   175 	{
   176 		cout << options.getHelpText()<<endl;
   177 		return 0;	
   178 	}	
   179 
   180 	if (options.isOn ("test"))
   181 	{
   182 		// FIXME testing string option only
   183 		cout << "Testing: "<<options.getArg("test")<< endl;
   184 	}	
   185 
   186 
   187     QMimeSourceFactory *factory = QMimeSourceFactory::defaultFactory();
   188     factory->setPixmap("vym_128x128", QPixmap(vym_128x128_xpm));
   189     qInitNetworkProtocols();
   190 
   191 
   192 	// Initialize translations
   193 	QTranslator translator (0);
   194 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   195     app.installTranslator( &translator );
   196 
   197 	// Initializing the row of system flags
   198 	// is done in first call to MapEditor(),
   199 	// because we need at least one canvas first
   200 	systemFlagsDefault=NULL;
   201 	standardFlagsDefault=NULL;
   202 
   203 	// Initialize window of TextEditor
   204 	textEditor = new TextEditor();
   205 	textEditor->setIcon (QPixmap (vym_editor_xpm));
   206 	if (textEditor->showWithMain()) textEditor->show();
   207 
   208 	// Initialize mainwindow 
   209     Main m;
   210 	//m.resize(m.sizeHint());
   211 	m.setIcon (QPixmap (vym_48x48_xpm));
   212 	m.show();
   213 	m.fileNew();
   214 	m.loadCmdLine();
   215 
   216 	// For benchmarking we may want to quit immediatly after drawing
   217 	if (options.isOn ("quit"))
   218 	{
   219 		return 0;
   220 	}	
   221 
   222     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   223 
   224     return app.exec();
   225 }
   226