main.cpp
author insilmaril
Tue, 15 Aug 2006 11:43:21 +0000
branchqt4-port
changeset 14 f4c37956d28d
parent 13 9aadd0f58300
child 16 41c3d7f9f532
permissions -rw-r--r--
removed unneeded toolbars.*
insilmaril@3
     1
#include <QApplication>
insilmaril@8
     2
#include <QPixmap>
insilmaril@8
     3
#include <QTranslator>
insilmaril@8
     4
#include <QDir>
insilmaril@2
     5
#include <q3ptrlist.h>
insilmaril@8
     6
#include <QTextCodec>
insilmaril@2
     7
#include <q3network.h>
insilmaril@8
     8
#include <QMenu>
insilmaril@3
     9
#include <QActionGroup>
insilmaril@0
    10
insilmaril@0
    11
#include "settings.h"
insilmaril@0
    12
#include "options.h"
insilmaril@0
    13
#include "mainwindow.h"
insilmaril@0
    14
#include "flagrowobj.h"
insilmaril@0
    15
insilmaril@0
    16
// Global variables
insilmaril@0
    17
TextEditor *textEditor;			// used in Constr. of LinkableMapObj
insilmaril@0
    18
								// initialized in mainwindow
insilmaril@0
    19
insilmaril@0
    20
Main *mainWindow;				// used in BranchObj::select()								
insilmaril@2
    21
QString tmpVymDir;				// All temp files go there, created in mainwindow
insilmaril@2
    22
QString clipboardDir;			// Clipboard used in all mapEditors
insilmaril@2
    23
QDir vymBaseDir;				// Containing all styles, scripts, images, ...
insilmaril@4
    24
QDir lastImageDir;
insilmaril@11
    25
QDir lastFileDir;
insilmaril@2
    26
QString iconPath;				// Pointing to icons used for toolbars
insilmaril@2
    27
QString flagsPath;				// Pointing to flags
insilmaril@2
    28
bool clipboardEmpty;			
insilmaril@0
    29
FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
insilmaril@0
    30
FlagRowObj *standardFlagsDefault;
insilmaril@0
    31
insilmaril@2
    32
// Lists of actions
insilmaril@2
    33
// (QActionGroup could not be "enabled")
insilmaril@2
    34
Q3PtrList <QAction> actionListBranches;
insilmaril@2
    35
insilmaril@0
    36
// Actions which change sometimes
insilmaril@0
    37
QAction *actionFileSave;
insilmaril@0
    38
QAction *actionFilePrint;
insilmaril@0
    39
QAction *actionEditUndo;
insilmaril@2
    40
QAction *actionEditRedo;
insilmaril@0
    41
QAction *actionEditCopy;
insilmaril@0
    42
QAction *actionEditCut;
insilmaril@0
    43
QAction *actionEditPaste;
insilmaril@0
    44
QAction *actionEditMoveUp;
insilmaril@0
    45
QAction *actionEditMoveDown;
insilmaril@0
    46
QAction *actionEditToggleScroll;
insilmaril@0
    47
QAction *actionEditOpenURL;
insilmaril@2
    48
QAction *actionEditOpenURLTab;
insilmaril@0
    49
QAction *actionEditURL;
insilmaril@0
    50
QAction *actionEditHeading2URL;
insilmaril@0
    51
QAction *actionEditBugzilla2URL;
insilmaril@2
    52
QAction *actionEditFATE2URL;
insilmaril@0
    53
QAction *actionEditOpenVymLink;
insilmaril@0
    54
QAction *actionEditVymLink;
insilmaril@2
    55
QAction *actionEditToggleHideExport;
insilmaril@0
    56
QAction *actionEditDeleteVymLink;
insilmaril@0
    57
QAction *actionEditMapInfo;
insilmaril@0
    58
QAction *actionEditHeading;
insilmaril@0
    59
QAction *actionEditDelete;
insilmaril@0
    60
QAction *actionEditAddBranch;
insilmaril@2
    61
QAction *actionEditAddBranchHere;
insilmaril@0
    62
QAction *actionEditAddBranchAbove;
insilmaril@0
    63
QAction *actionEditAddBranchBelow;
insilmaril@2
    64
QAction *actionEditRemoveBranchKeepChilds;
insilmaril@2
    65
QAction *actionEditRemoveChilds;
insilmaril@0
    66
QAction *actionEditImportAdd;
insilmaril@0
    67
QAction *actionEditImportReplace;
insilmaril@0
    68
QAction *actionEditSaveBranch;
insilmaril@0
    69
QAction *actionEditSelectFirst;
insilmaril@0
    70
QAction *actionEditSelectLast;
insilmaril@0
    71
QAction *actionEditLoadImage;
insilmaril@0
    72
insilmaril@0
    73
QAction *actionFormatColor;		
insilmaril@0
    74
QAction *actionFormatPickColor;		
insilmaril@0
    75
QAction *actionFormatColorBranch;
insilmaril@0
    76
QAction *actionFormatColorSubtree;
insilmaril@0
    77
QAction *actionFormatBackColor;
insilmaril@0
    78
QAction *actionFormatLinkColorHint;
insilmaril@0
    79
QAction *actionFormatLinkColor;		
insilmaril@0
    80
insilmaril@3
    81
QActionGroup *actionGroupModModes;
insilmaril@2
    82
QAction *actionModModeColor;
insilmaril@2
    83
QAction *actionModModeLink;
insilmaril@2
    84
QAction *actionModModeCopy;
insilmaril@2
    85
insilmaril@3
    86
QActionGroup *actionGroupFormatFrameTypes;
insilmaril@0
    87
QAction *actionFormatFrameNone;
insilmaril@0
    88
QAction *actionFormatFrameRectangle;
insilmaril@0
    89
insilmaril@3
    90
QActionGroup *actionGroupFormatLinkStyles;
insilmaril@2
    91
QAction *actionFormatIncludeImagesVer;
insilmaril@2
    92
QAction *actionFormatIncludeImagesHor;
insilmaril@2
    93
QAction *actionFormatHideLinkUnselected;
insilmaril@0
    94
QAction *actionFormatLinkStyleLine;
insilmaril@0
    95
QAction *actionFormatLinkStyleParabel;
insilmaril@0
    96
QAction *actionFormatLinkStylePolyLine;
insilmaril@0
    97
QAction *actionFormatLinkStylePolyParabel;
insilmaril@0
    98
insilmaril@0
    99
QAction *actionViewToggleNoteEditor;
insilmaril@2
   100
QAction *actionViewToggleHistoryWindow;
insilmaril@0
   101
insilmaril@0
   102
QAction *actionSettingsAutoselectHeading;
insilmaril@0
   103
QAction *actionSettingsAutoselectText;
insilmaril@0
   104
QAction *actionSettingsPasteNewHeading;
insilmaril@0
   105
QAction *actionSettingsAutoedit;
insilmaril@0
   106
QAction *actionSettingsUseDelKey;
insilmaril@2
   107
QAction *actionSettingsUseFlagGroups;
insilmaril@2
   108
QAction *actionSettingsUseHideExport;
insilmaril@0
   109
insilmaril@4
   110
insilmaril@4
   111
QMenu* branchContextMenu;
insilmaril@4
   112
QMenu* branchAddContextMenu;
insilmaril@4
   113
QMenu* branchRemoveContextMenu;
insilmaril@7
   114
QMenu* branchLinksContextMenuEdit;
insilmaril@7
   115
QMenu* branchLinksContextMenuFollow;
insilmaril@4
   116
QMenu* floatimageContextMenu;
insilmaril@4
   117
QMenu* canvasContextMenu;
insilmaril@4
   118
QMenu* fileLastMapsMenu;
insilmaril@4
   119
QMenu* fileImportMenu;
insilmaril@4
   120
QMenu* fileExportMenu;
insilmaril@0
   121
insilmaril@0
   122
insilmaril@3
   123
Settings settings ("vym","vym"); // Organization, Application name
insilmaril@0
   124
Options options;
insilmaril@4
   125
ImageIO imageIO;
insilmaril@0
   126
insilmaril@0
   127
int statusbarTime=3500;
insilmaril@0
   128
insilmaril@0
   129
int main(int argc, char** argv)
insilmaril@0
   130
{
insilmaril@13
   131
//FIXME	Q_INIT_RESOURCE (application);
insilmaril@13
   132
insilmaril@0
   133
    QApplication app(argc,argv);
insilmaril@0
   134
insilmaril@0
   135
insilmaril@0
   136
	// Reading and initializing options commandline options
insilmaril@0
   137
	options.add ("version", SwitchOption, "v","version");
insilmaril@2
   138
	options.add ("local", SwitchOption, "l", "local");
insilmaril@0
   139
	options.add ("help", SwitchOption, "h", "help");
insilmaril@0
   140
	options.add ("quit", SwitchOption, "q", "quit");
insilmaril@0
   141
	options.add ("test", StringOption, "t", "test");
insilmaril@0
   142
	options.setHelpText (
insilmaril@0
   143
		"VYM - View Your Mind\n"
insilmaril@0
   144
		"--------------------\n\n"
insilmaril@0
   145
		"Information about vym can be found in vym.pdf,\n"
insilmaril@0
   146
		"which should be part of the vym package.\n"
insilmaril@0
   147
		"It is also available at the project homepage:\n\n"
insilmaril@0
   148
		"http://www.InSilmaril.de/vym\n");
insilmaril@0
   149
	if (options.parse())
insilmaril@0
   150
	{
insilmaril@2
   151
//FIXME QT3		cout << endl << options.getHelpText()<<endl;
insilmaril@0
   152
		return 1;
insilmaril@0
   153
	}
insilmaril@0
   154
insilmaril@0
   155
	if (options.isOn ("version"))
insilmaril@0
   156
	{
insilmaril@2
   157
		cout << "vym version "<<__VYM_VERSION
insilmaril@13
   158
			<<"  (c) 2004-2006 Uwe Drechsel - "
insilmaril@2
   159
			<<__BUILD_DATE<<endl;
insilmaril@0
   160
			
insilmaril@0
   161
		return 0;	
insilmaril@0
   162
	}		
insilmaril@0
   163
	
insilmaril@2
   164
	// Use /usr/share/vym or /usr/local/share/vym or . ?
insilmaril@2
   165
	// First try options
insilmaril@2
   166
	if (options.isOn ("local"))
insilmaril@2
   167
	{
insilmaril@2
   168
		vymBaseDir.setPath (vymBaseDir.currentDirPath());
insilmaril@2
   169
	} else
insilmaril@2
   170
	// then look for environment variable
insilmaril@2
   171
	if (getenv("VYMHOME")!=0)
insilmaril@2
   172
	{
insilmaril@2
   173
		vymBaseDir.setPath (getenv("VYMHOME"));
insilmaril@2
   174
	} else
insilmaril@2
   175
	// ok, let's find my way on my own
insilmaril@2
   176
	{
insilmaril@2
   177
		vymBaseDir.setPath ("/usr/share/vym");
insilmaril@2
   178
		if (!vymBaseDir.exists())
insilmaril@2
   179
		{
insilmaril@2
   180
			vymBaseDir.setPath ("/usr/local/share/vym");
insilmaril@2
   181
			if (!vymBaseDir.exists())
insilmaril@2
   182
				vymBaseDir.setPath(vymBaseDir.currentDirPath() );
insilmaril@2
   183
		}		
insilmaril@2
   184
	}
insilmaril@2
   185
insilmaril@2
   186
	iconPath=vymBaseDir.path()+"/icons/";
insilmaril@2
   187
	flagsPath=vymBaseDir.path()+"/flags/";
insilmaril@2
   188
insilmaril@4
   189
	// Some directories
insilmaril@11
   190
	lastImageDir=QDir().current();
insilmaril@11
   191
	lastFileDir=QDir().current();
insilmaril@4
   192
insilmaril@0
   193
	if (options.isOn ("help"))
insilmaril@0
   194
	{
insilmaril@4
   195
		cout << options.getHelpText().ascii()<<endl;
insilmaril@0
   196
		return 0;	
insilmaril@0
   197
	}	
insilmaril@0
   198
insilmaril@0
   199
	if (options.isOn ("test"))
insilmaril@0
   200
	{
insilmaril@0
   201
		// FIXME testing string option only
insilmaril@4
   202
		cout << "Testing: "<<options.getArg("test").ascii()<< endl;
insilmaril@0
   203
	}	
insilmaril@0
   204
insilmaril@2
   205
    q3InitNetworkProtocols();
insilmaril@2
   206
insilmaril@2
   207
insilmaril@2
   208
	// Initialize translations
insilmaril@2
   209
	QTranslator translator (0);
insilmaril@2
   210
	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
insilmaril@2
   211
    app.installTranslator( &translator );
insilmaril@2
   212
insilmaril@2
   213
	// Initializing the row of system flags
insilmaril@2
   214
	// is done in first call to MapEditor(),
insilmaril@2
   215
	// because we need at least one canvas first
insilmaril@2
   216
	systemFlagsDefault=NULL;
insilmaril@2
   217
	standardFlagsDefault=NULL;
insilmaril@2
   218
insilmaril@0
   219
	// Initialize window of TextEditor
insilmaril@0
   220
	textEditor = new TextEditor();
insilmaril@2
   221
	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
insilmaril@0
   222
	if (textEditor->showWithMain()) textEditor->show();
insilmaril@0
   223
insilmaril@2
   224
	// Initialize mainwindow 
insilmaril@0
   225
    Main m;
insilmaril@0
   226
	//m.resize(m.sizeHint());
insilmaril@2
   227
	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
insilmaril@0
   228
	m.show();
insilmaril@0
   229
	m.fileNew();
insilmaril@0
   230
	m.loadCmdLine();
insilmaril@0
   231
insilmaril@0
   232
	// For benchmarking we may want to quit immediatly after drawing
insilmaril@0
   233
	if (options.isOn ("quit"))
insilmaril@0
   234
	{
insilmaril@0
   235
		return 0;
insilmaril@0
   236
	}	
insilmaril@0
   237
insilmaril@0
   238
    QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
insilmaril@0
   239
insilmaril@0
   240
    return app.exec();
insilmaril@0
   241
}
insilmaril@0
   242