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