main.cpp
author insilmaril
Wed, 25 Jan 2006 09:33:50 +0000
changeset 196 a9493dcaa306
parent 185 6691000c3262
child 205 30c4a6c7ff10
permissions -rw-r--r--
changed default location of exports to ~/.vym/exports
     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-editor.xpm"
    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 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 *actionEditURL;
    47 QAction *actionEditHeading2URL;
    48 QAction *actionEditBugzilla2URL;
    49 QAction *actionEditFATE2URL;
    50 QAction *actionEditOpenVymLink;
    51 QAction *actionEditVymLink;
    52 QAction *actionEditDeleteVymLink;
    53 QAction *actionEditMapInfo;
    54 QAction *actionEditHeading;
    55 QAction *actionEditDelete;
    56 QAction *actionEditAddBranch;
    57 QAction *actionEditAddBranchHere;
    58 QAction *actionEditAddBranchAbove;
    59 QAction *actionEditAddBranchBelow;
    60 QAction *actionEditRemoveBranchHere;
    61 QAction *actionEditRemoveChilds;
    62 QAction *actionEditImportAdd;
    63 QAction *actionEditImportReplace;
    64 QAction *actionEditSaveBranch;
    65 QAction *actionEditSelectFirst;
    66 QAction *actionEditSelectLast;
    67 QAction *actionEditLoadImage;
    68 QAction *actionEditToggleFloatExport;
    69 
    70 QAction *actionFormatColor;		
    71 QAction *actionFormatPickColor;		
    72 QAction *actionFormatColorBranch;
    73 QAction *actionFormatColorSubtree;
    74 QAction *actionFormatBackColor;
    75 QAction *actionFormatLinkColorHint;
    76 QAction *actionFormatLinkColor;		
    77 
    78 QActionGroup *actionGroupModModes;
    79 QAction *actionModModeColor;
    80 QAction *actionModModeLink;
    81 QAction *actionModModeCopy;
    82 
    83 QActionGroup *actionGroupFormatFrameTypes;
    84 QAction *actionFormatFrameNone;
    85 QAction *actionFormatFrameRectangle;
    86 
    87 QActionGroup *actionGroupFormatLinkStyles;
    88 QAction *actionFormatIncludeImagesVer;
    89 QAction *actionFormatIncludeImagesHor;
    90 QAction *actionFormatHideLinkUnselected;
    91 QAction *actionFormatLinkStyleLine;
    92 QAction *actionFormatLinkStyleParabel;
    93 QAction *actionFormatLinkStylePolyLine;
    94 QAction *actionFormatLinkStylePolyParabel;
    95 
    96 QAction *actionViewToggleNoteEditor;
    97 
    98 QAction *actionSettingsAutoselectHeading;
    99 QAction *actionSettingsAutoselectText;
   100 QAction *actionSettingsPasteNewHeading;
   101 QAction *actionSettingsAutoedit;
   102 QAction *actionSettingsUseDelKey;
   103 QAction *actionSettingsUseFlagGroups;
   104 
   105 QPopupMenu *branchContextMenu;
   106 QPopupMenu *branchAddContextMenu;
   107 QPopupMenu *branchRemoveContextMenu;
   108 QPopupMenu *branchLinksContextMenu;
   109 QPopupMenu *branchLinksContextMenuDup;
   110 QPopupMenu *floatimageContextMenu;
   111 QPopupMenu *saveImageFormatMenu;
   112 QPopupMenu *canvasContextMenu;
   113 QPopupMenu *lastMapsMenu;
   114 QPopupMenu *exportMenu;
   115 QPopupMenu *exportImageFormatMenu;
   116 
   117 
   118 Settings settings;
   119 Options options;
   120 
   121 int statusbarTime=3500;
   122 
   123 int main(int argc, char** argv)
   124 {
   125     QApplication app(argc,argv);
   126 
   127     QMimeSourceFactory *factory = QMimeSourceFactory::defaultFactory();
   128     factory->setPixmap("vym_logo", QPixmap(vym_logo_xpm));
   129     qInitNetworkProtocols();
   130 
   131 	// Use /usr/share/vym or /usr/local/share/vym or .
   132 	QDir shareDir;
   133 	shareDir.setPath ("/usr/share/vym");
   134 	if (!shareDir.exists())
   135         shareDir.setPath ("/usr/local/share/vym");
   136 	if (!shareDir.exists())
   137         shareDir.setPath(".");
   138 
   139 	// Initialize translations
   140 	QTranslator translator (0);
   141 	translator.load( QString("vym_")+QTextCodec::locale(), shareDir.path() + "/lang");
   142     app.installTranslator( &translator );
   143 
   144 	// Initializing the row of system flags
   145 	// is done in first call to MapEditor(),
   146 	// because we need at least one canvas first
   147 	systemFlagsDefault=NULL;
   148 	standardFlagsDefault=NULL;
   149 
   150 	// Reading and initializing options commandline options
   151 	options.add ("version", SwitchOption, "v","version");
   152 	options.add ("help", SwitchOption, "h", "help");
   153 	options.add ("quit", SwitchOption, "q", "quit");
   154 	options.add ("test", StringOption, "t", "test");
   155 	options.setHelpText (
   156 		"VYM - View Your Mind\n"
   157 		"--------------------\n\n"
   158 		"Information about vym can be found in vym.pdf,\n"
   159 		"which should be part of the vym package.\n"
   160 		"It is also available at the project homepage:\n\n"
   161 		"http://www.InSilmaril.de/vym\n");
   162 	if (options.parse())
   163 	{
   164 		cout << endl << options.getHelpText()<<endl;
   165 		return 1;
   166 	}
   167 
   168 	if (options.isOn ("version"))
   169 	{
   170 		cout << "vym version "<<__VYM_VERSION
   171 			<<"  (c) 2004 Uwe Drechsel - "
   172 			<<__BUILD_DATE<<endl;
   173 			
   174 		return 0;	
   175 	}		
   176 	
   177 	if (options.isOn ("help"))
   178 	{
   179 		cout << options.getHelpText()<<endl;
   180 		return 0;	
   181 	}	
   182 
   183 	if (options.isOn ("test"))
   184 	{
   185 		// FIXME testing string option only
   186 		cout << "Testing: "<<options.getArg("test")<< endl;
   187 	}	
   188 
   189 	// Initialize window of TextEditor
   190 	textEditor = new TextEditor();
   191 	textEditor->setIcon (QPixmap (vym_editor_xpm));
   192 	if (textEditor->showWithMain()) textEditor->show();
   193 
   194 	// Initialize mainwindow 
   195     Main m;
   196 	//m.resize(m.sizeHint());
   197 	m.setIcon (QPixmap (vym_logo_xpm));
   198 	m.show();
   199 	m.fileNew();
   200 	m.loadCmdLine();
   201 
   202 	// For benchmarking we may want to quit immediatly after drawing
   203 	if (options.isOn ("quit"))
   204 	{
   205 		return 0;
   206 	}	
   207 
   208     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   209 
   210     return app.exec();
   211 }
   212