main.cpp
author insilmaril
Tue, 05 Sep 2006 09:30:16 +0000
branchqt4-port
changeset 21 b091563e28e6
parent 18 70c41284cb48
permissions -rw-r--r--
More undo/redo commands. Undo debug output still enabled
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@16
    49
QAction *actionEditOpenMultipleURLTabs;
insilmaril@0
    50
QAction *actionEditURL;
insilmaril@0
    51
QAction *actionEditHeading2URL;
insilmaril@0
    52
QAction *actionEditBugzilla2URL;
insilmaril@2
    53
QAction *actionEditFATE2URL;
insilmaril@0
    54
QAction *actionEditOpenVymLink;
insilmaril@17
    55
QAction *actionEditOpenMultipleVymLinks;
insilmaril@0
    56
QAction *actionEditVymLink;
insilmaril@2
    57
QAction *actionEditToggleHideExport;
insilmaril@0
    58
QAction *actionEditDeleteVymLink;
insilmaril@0
    59
QAction *actionEditMapInfo;
insilmaril@0
    60
QAction *actionEditHeading;
insilmaril@0
    61
QAction *actionEditDelete;
insilmaril@0
    62
QAction *actionEditAddBranch;
insilmaril@2
    63
QAction *actionEditAddBranchHere;
insilmaril@0
    64
QAction *actionEditAddBranchAbove;
insilmaril@0
    65
QAction *actionEditAddBranchBelow;
insilmaril@2
    66
QAction *actionEditRemoveBranchKeepChilds;
insilmaril@2
    67
QAction *actionEditRemoveChilds;
insilmaril@0
    68
QAction *actionEditImportAdd;
insilmaril@0
    69
QAction *actionEditImportReplace;
insilmaril@0
    70
QAction *actionEditSaveBranch;
insilmaril@0
    71
QAction *actionEditSelectFirst;
insilmaril@0
    72
QAction *actionEditSelectLast;
insilmaril@0
    73
QAction *actionEditLoadImage;
insilmaril@0
    74
insilmaril@0
    75
QAction *actionFormatColor;		
insilmaril@0
    76
QAction *actionFormatPickColor;		
insilmaril@0
    77
QAction *actionFormatColorBranch;
insilmaril@0
    78
QAction *actionFormatColorSubtree;
insilmaril@0
    79
QAction *actionFormatBackColor;
insilmaril@0
    80
QAction *actionFormatLinkColorHint;
insilmaril@0
    81
QAction *actionFormatLinkColor;		
insilmaril@0
    82
insilmaril@3
    83
QActionGroup *actionGroupModModes;
insilmaril@2
    84
QAction *actionModModeColor;
insilmaril@2
    85
QAction *actionModModeLink;
insilmaril@2
    86
QAction *actionModModeCopy;
insilmaril@2
    87
insilmaril@3
    88
QActionGroup *actionGroupFormatFrameTypes;
insilmaril@0
    89
QAction *actionFormatFrameNone;
insilmaril@0
    90
QAction *actionFormatFrameRectangle;
insilmaril@0
    91
insilmaril@3
    92
QActionGroup *actionGroupFormatLinkStyles;
insilmaril@2
    93
QAction *actionFormatIncludeImagesVer;
insilmaril@2
    94
QAction *actionFormatIncludeImagesHor;
insilmaril@2
    95
QAction *actionFormatHideLinkUnselected;
insilmaril@0
    96
QAction *actionFormatLinkStyleLine;
insilmaril@0
    97
QAction *actionFormatLinkStyleParabel;
insilmaril@0
    98
QAction *actionFormatLinkStylePolyLine;
insilmaril@0
    99
QAction *actionFormatLinkStylePolyParabel;
insilmaril@0
   100
insilmaril@0
   101
QAction *actionViewToggleNoteEditor;
insilmaril@2
   102
QAction *actionViewToggleHistoryWindow;
insilmaril@0
   103
insilmaril@0
   104
QAction *actionSettingsAutoselectHeading;
insilmaril@0
   105
QAction *actionSettingsAutoselectText;
insilmaril@0
   106
QAction *actionSettingsAutoedit;
insilmaril@0
   107
QAction *actionSettingsUseDelKey;
insilmaril@2
   108
QAction *actionSettingsUseFlagGroups;
insilmaril@2
   109
QAction *actionSettingsUseHideExport;
insilmaril@0
   110
insilmaril@4
   111
insilmaril@4
   112
QMenu* branchContextMenu;
insilmaril@4
   113
QMenu* branchAddContextMenu;
insilmaril@4
   114
QMenu* branchRemoveContextMenu;
insilmaril@17
   115
QMenu* branchLinksContextMenu;
insilmaril@17
   116
QMenu* branchXLinksContextMenuEdit;
insilmaril@17
   117
QMenu* branchXLinksContextMenuFollow;
insilmaril@4
   118
QMenu* floatimageContextMenu;
insilmaril@4
   119
QMenu* canvasContextMenu;
insilmaril@4
   120
QMenu* fileLastMapsMenu;
insilmaril@4
   121
QMenu* fileImportMenu;
insilmaril@4
   122
QMenu* fileExportMenu;
insilmaril@0
   123
insilmaril@0
   124
insilmaril@16
   125
Settings settings ("InSilmaril","vym"); // Organization, Application name
insilmaril@16
   126
insilmaril@0
   127
Options options;
insilmaril@4
   128
ImageIO imageIO;
insilmaril@0
   129
insilmaril@0
   130
int statusbarTime=3500;
insilmaril@0
   131
insilmaril@0
   132
int main(int argc, char** argv)
insilmaril@0
   133
{
insilmaril@13
   134
//FIXME	Q_INIT_RESOURCE (application);
insilmaril@13
   135
insilmaril@0
   136
    QApplication app(argc,argv);
insilmaril@0
   137
insilmaril@0
   138
insilmaril@0
   139
	// Reading and initializing options commandline options
insilmaril@0
   140
	options.add ("version", SwitchOption, "v","version");
insilmaril@2
   141
	options.add ("local", SwitchOption, "l", "local");
insilmaril@0
   142
	options.add ("help", SwitchOption, "h", "help");
insilmaril@0
   143
	options.add ("quit", SwitchOption, "q", "quit");
insilmaril@0
   144
	options.add ("test", StringOption, "t", "test");
insilmaril@0
   145
	options.setHelpText (
insilmaril@0
   146
		"VYM - View Your Mind\n"
insilmaril@0
   147
		"--------------------\n\n"
insilmaril@0
   148
		"Information about vym can be found in vym.pdf,\n"
insilmaril@0
   149
		"which should be part of the vym package.\n"
insilmaril@0
   150
		"It is also available at the project homepage:\n\n"
insilmaril@0
   151
		"http://www.InSilmaril.de/vym\n");
insilmaril@0
   152
	if (options.parse())
insilmaril@0
   153
	{
insilmaril@18
   154
		cout << endl << options.getHelpText().ascii()<<endl;
insilmaril@0
   155
		return 1;
insilmaril@0
   156
	}
insilmaril@0
   157
insilmaril@0
   158
	if (options.isOn ("version"))
insilmaril@0
   159
	{
insilmaril@2
   160
		cout << "vym version "<<__VYM_VERSION
insilmaril@13
   161
			<<"  (c) 2004-2006 Uwe Drechsel - "
insilmaril@2
   162
			<<__BUILD_DATE<<endl;
insilmaril@0
   163
			
insilmaril@0
   164
		return 0;	
insilmaril@0
   165
	}		
insilmaril@0
   166
	
insilmaril@2
   167
	// Use /usr/share/vym or /usr/local/share/vym or . ?
insilmaril@2
   168
	// First try options
insilmaril@2
   169
	if (options.isOn ("local"))
insilmaril@2
   170
	{
insilmaril@2
   171
		vymBaseDir.setPath (vymBaseDir.currentDirPath());
insilmaril@2
   172
	} else
insilmaril@2
   173
	// then look for environment variable
insilmaril@2
   174
	if (getenv("VYMHOME")!=0)
insilmaril@2
   175
	{
insilmaril@2
   176
		vymBaseDir.setPath (getenv("VYMHOME"));
insilmaril@2
   177
	} else
insilmaril@2
   178
	// ok, let's find my way on my own
insilmaril@2
   179
	{
insilmaril@2
   180
		vymBaseDir.setPath ("/usr/share/vym");
insilmaril@2
   181
		if (!vymBaseDir.exists())
insilmaril@2
   182
		{
insilmaril@2
   183
			vymBaseDir.setPath ("/usr/local/share/vym");
insilmaril@2
   184
			if (!vymBaseDir.exists())
insilmaril@2
   185
				vymBaseDir.setPath(vymBaseDir.currentDirPath() );
insilmaril@2
   186
		}		
insilmaril@2
   187
	}
insilmaril@2
   188
insilmaril@2
   189
	iconPath=vymBaseDir.path()+"/icons/";
insilmaril@2
   190
	flagsPath=vymBaseDir.path()+"/flags/";
insilmaril@2
   191
insilmaril@4
   192
	// Some directories
insilmaril@11
   193
	lastImageDir=QDir().current();
insilmaril@11
   194
	lastFileDir=QDir().current();
insilmaril@4
   195
insilmaril@0
   196
	if (options.isOn ("help"))
insilmaril@0
   197
	{
insilmaril@4
   198
		cout << options.getHelpText().ascii()<<endl;
insilmaril@0
   199
		return 0;	
insilmaril@0
   200
	}	
insilmaril@0
   201
insilmaril@2
   202
    q3InitNetworkProtocols();
insilmaril@2
   203
insilmaril@2
   204
insilmaril@2
   205
	// Initialize translations
insilmaril@2
   206
	QTranslator translator (0);
insilmaril@2
   207
	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
insilmaril@2
   208
    app.installTranslator( &translator );
insilmaril@2
   209
insilmaril@2
   210
	// Initializing the row of system flags
insilmaril@2
   211
	// is done in first call to MapEditor(),
insilmaril@2
   212
	// because we need at least one canvas first
insilmaril@2
   213
	systemFlagsDefault=NULL;
insilmaril@2
   214
	standardFlagsDefault=NULL;
insilmaril@2
   215
insilmaril@0
   216
	// Initialize window of TextEditor
insilmaril@0
   217
	textEditor = new TextEditor();
insilmaril@2
   218
	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
insilmaril@0
   219
	if (textEditor->showWithMain()) textEditor->show();
insilmaril@0
   220
insilmaril@2
   221
	// Initialize mainwindow 
insilmaril@0
   222
    Main m;
insilmaril@0
   223
	//m.resize(m.sizeHint());
insilmaril@2
   224
	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
insilmaril@0
   225
	m.show();
insilmaril@0
   226
	m.fileNew();
insilmaril@0
   227
	m.loadCmdLine();
insilmaril@0
   228
insilmaril@0
   229
	// For benchmarking we may want to quit immediatly after drawing
insilmaril@0
   230
	if (options.isOn ("quit"))
insilmaril@0
   231
	{
insilmaril@0
   232
		return 0;
insilmaril@0
   233
	}	
insilmaril@0
   234
insilmaril@0
   235
    QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
insilmaril@0
   236
insilmaril@0
   237
    return app.exec();
insilmaril@0
   238
}
insilmaril@0
   239