main.cpp
author insilmaril
Fri Aug 19 07:42:31 2005 +0000 (2005-08-19)
changeset 155 7f06b2e3afb5
parent 117 835f2eb4d744
child 160 72cc3873306a
permissions -rw-r--r--
added license in new aboutwindow and debian subdir by Steffen Joeris
     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 *actionFormatLinkStyleLine;
    85 QAction *actionFormatLinkStyleParabel;
    86 QAction *actionFormatLinkStylePolyLine;
    87 QAction *actionFormatLinkStylePolyParabel;
    88 
    89 QAction *actionViewToggleNoteEditor;
    90 
    91 QAction *actionSettingsAutoselectHeading;
    92 QAction *actionSettingsAutoselectText;
    93 QAction *actionSettingsPasteNewHeading;
    94 QAction *actionSettingsAutoedit;
    95 QAction *actionSettingsUseDelKey;
    96 QAction *actionSettingsUseFlagGroups;
    97 
    98 QPopupMenu *branchContextMenu;
    99 QPopupMenu *branchAddContextMenu;
   100 QPopupMenu *branchRemoveContextMenu;
   101 QPopupMenu *branchLinksContextMenu;
   102 QPopupMenu *branchLinksContextMenuDup;
   103 QPopupMenu *floatimageContextMenu;
   104 QPopupMenu *saveImageFormatMenu;
   105 QPopupMenu *canvasContextMenu;
   106 QPopupMenu *lastMapsMenu;
   107 QPopupMenu *exportMenu;
   108 QPopupMenu *exportImageFormatMenu;
   109 
   110 
   111 Settings settings;
   112 Options options;
   113 
   114 int statusbarTime=3500;
   115 
   116 int main(int argc, char** argv)
   117 {
   118     QApplication app(argc,argv);
   119 
   120     QMimeSourceFactory *factory = QMimeSourceFactory::defaultFactory();
   121     factory->setPixmap("vym_logo", QPixmap(vym_logo_xpm));
   122     qInitNetworkProtocols();
   123 
   124 	// Use /usr/share/vym or /usr/local/share/vym or .
   125 	QDir shareDir;
   126 	shareDir.setPath ("/usr/share/vym");
   127 	if (!shareDir.exists())
   128         shareDir.setPath ("/usr/local/share/vym");
   129 	if (!shareDir.exists())
   130         shareDir.setPath(".");
   131 
   132 	// Initialize translations
   133 	QTranslator translator (0);
   134 	translator.load( QString("vym_")+QTextCodec::locale(), shareDir.path() + "/lang");
   135     app.installTranslator( &translator );
   136 
   137 	// Initializing the row of system flags
   138 	// is done in first call to MapEditor(),
   139 	// because we need at least one canvas first
   140 	systemFlagsDefault=NULL;
   141 	standardFlagsDefault=NULL;
   142 
   143 	// Reading and initializing options commandline options
   144 	options.add ("version", SwitchOption, "v","version");
   145 	options.add ("help", SwitchOption, "h", "help");
   146 	options.add ("quit", SwitchOption, "q", "quit");
   147 	options.add ("test", StringOption, "t", "test");
   148 	options.setHelpText (
   149 		"VYM - View Your Mind\n"
   150 		"--------------------\n\n"
   151 		"Information about vym can be found in vym.pdf,\n"
   152 		"which should be part of the vym package.\n"
   153 		"It is also available at the project homepage:\n\n"
   154 		"http://www.InSilmaril.de/vym\n");
   155 	if (options.parse())
   156 	{
   157 		cout << endl << options.getHelpText()<<endl;
   158 		return 1;
   159 	}
   160 
   161 	if (options.isOn ("version"))
   162 	{
   163 		cout << "vym version "<<__VYM_VERSION__
   164 			<<"  (c) 2004 Uwe Drechsel - "
   165 			<<__BUILD_DATE__<<endl;
   166 			
   167 		return 0;	
   168 	}		
   169 	
   170 	if (options.isOn ("help"))
   171 	{
   172 		cout << options.getHelpText()<<endl;
   173 		return 0;	
   174 	}	
   175 
   176 	if (options.isOn ("test"))
   177 	{
   178 		// FIXME testing string option only
   179 		cout << "Testing: "<<options.getArg("test")<< endl;
   180 	}	
   181 
   182 	// Initialize window of TextEditor
   183 	textEditor = new TextEditor();
   184 	textEditor->setIcon (QPixmap (vym_editor_xpm));
   185 	if (textEditor->showWithMain()) textEditor->show();
   186 
   187 	clipboardME = new MapEditor();
   188 	clipboardME->resize (800,600);
   189 	clipboardME->setCaption("VYM - clipboard");
   190 	clipboardME->hide();
   191 
   192 	// Initialize mainwindow after Mapeditors (because of Flags)
   193     Main m;
   194 	//m.resize(m.sizeHint());
   195 	m.setIcon (QPixmap (vym_logo_xpm));
   196 	m.show();
   197 	m.fileNew();
   198 	m.loadCmdLine();
   199 
   200 	// For benchmarking we may want to quit immediatly after drawing
   201 	if (options.isOn ("quit"))
   202 	{
   203 		return 0;
   204 	}	
   205 
   206     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   207 
   208     return app.exec();
   209 }
   210