main.cpp
author insilmaril
Mon, 10 Apr 2006 11:21:35 +0000
changeset 291 45f029ea85ee
parent 269 4c3e9fa0093b
child 294 3492af261af2
permissions -rw-r--r--
switching to KDE icons
     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 *actionEditRemoveBranchHere;
    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 
    99 QAction *actionSettingsAutoselectHeading;
   100 QAction *actionSettingsAutoselectText;
   101 QAction *actionSettingsPasteNewHeading;
   102 QAction *actionSettingsAutoedit;
   103 QAction *actionSettingsUseDelKey;
   104 QAction *actionSettingsUseFlagGroups;
   105 QAction *actionSettingsUseHideExport;
   106 
   107 QPopupMenu *branchContextMenu;
   108 QPopupMenu *branchAddContextMenu;
   109 QPopupMenu *branchRemoveContextMenu;
   110 QPopupMenu *branchLinksContextMenu;
   111 QPopupMenu *branchLinksContextMenuDup;
   112 QPopupMenu *floatimageContextMenu;
   113 QPopupMenu *saveImageFormatMenu;
   114 QPopupMenu *canvasContextMenu;
   115 QPopupMenu *lastMapsMenu;
   116 QPopupMenu *importMenu;
   117 QPopupMenu *exportMenu;
   118 QPopupMenu *exportImageFormatMenu;
   119 
   120 
   121 Settings settings;
   122 Options options;
   123 
   124 int statusbarTime=3500;
   125 
   126 int main(int argc, char** argv)
   127 {
   128     QApplication app(argc,argv);
   129 
   130 
   131 	// Reading and initializing options commandline options
   132 	options.add ("version", SwitchOption, "v","version");
   133 	options.add ("local", SwitchOption, "l", "local");
   134 	options.add ("help", SwitchOption, "h", "help");
   135 	options.add ("quit", SwitchOption, "q", "quit");
   136 	options.add ("test", StringOption, "t", "test");
   137 	options.setHelpText (
   138 		"VYM - View Your Mind\n"
   139 		"--------------------\n\n"
   140 		"Information about vym can be found in vym.pdf,\n"
   141 		"which should be part of the vym package.\n"
   142 		"It is also available at the project homepage:\n\n"
   143 		"http://www.InSilmaril.de/vym\n");
   144 	if (options.parse())
   145 	{
   146 		cout << endl << options.getHelpText()<<endl;
   147 		return 1;
   148 	}
   149 
   150 	if (options.isOn ("version"))
   151 	{
   152 		cout << "vym version "<<__VYM_VERSION
   153 			<<"  (c) 2004 Uwe Drechsel - "
   154 			<<__BUILD_DATE<<endl;
   155 			
   156 		return 0;	
   157 	}		
   158 	
   159 	// Use /usr/share/vym or /usr/local/share/vym or . ?
   160 	QDir vymBaseDir;
   161 
   162 	// First try options
   163 	if (options.isOn ("local"))
   164 	{
   165 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
   166 	} else
   167 	// then look for environment variable
   168 	if (getenv("VYMHOME")!=0)
   169 	{
   170 		vymBaseDir.setPath (getenv("VYMHOME"));
   171 	} else
   172 	// ok, let's find my way on my own
   173 	{
   174 		vymBaseDir.setPath ("/usr/share/vym");
   175 		if (!vymBaseDir.exists())
   176 			vymBaseDir.setPath ("/usr/local/share/vym");
   177 		if (!vymBaseDir.exists())
   178 			vymBaseDir.setPath(vymBaseDir.currentDirPath() );
   179 	}
   180 
   181 	iconPath=vymBaseDir.path()+"/icons/";
   182 	flagsPath=vymBaseDir.path()+"/flags/";
   183 
   184 	if (options.isOn ("help"))
   185 	{
   186 		cout << options.getHelpText()<<endl;
   187 		return 0;	
   188 	}	
   189 
   190 	if (options.isOn ("test"))
   191 	{
   192 		// FIXME testing string option only
   193 		cout << "Testing: "<<options.getArg("test")<< endl;
   194 	}	
   195 
   196 
   197     QMimeSourceFactory *factory = QMimeSourceFactory::defaultFactory();
   198     factory->setPixmap("vym-128x128", QPixmap(iconPath+"vym-128x128.png"));
   199     qInitNetworkProtocols();
   200 
   201 
   202 	// Initialize translations
   203 	QTranslator translator (0);
   204 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   205     app.installTranslator( &translator );
   206 
   207 	// Initializing the row of system flags
   208 	// is done in first call to MapEditor(),
   209 	// because we need at least one canvas first
   210 	systemFlagsDefault=NULL;
   211 	standardFlagsDefault=NULL;
   212 
   213 	// Initialize window of TextEditor
   214 	textEditor = new TextEditor();
   215 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   216 	if (textEditor->showWithMain()) textEditor->show();
   217 
   218 	// Initialize mainwindow 
   219     Main m;
   220 	//m.resize(m.sizeHint());
   221 	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
   222 	m.show();
   223 	m.fileNew();
   224 	m.loadCmdLine();
   225 
   226 	// For benchmarking we may want to quit immediatly after drawing
   227 	if (options.isOn ("quit"))
   228 	{
   229 		return 0;
   230 	}	
   231 
   232     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   233 
   234     return app.exec();
   235 }
   236