main.cpp
author insilmaril
Wed, 06 Sep 2006 12:47:06 +0000
changeset 378 1ab7353f8f44
parent 366 e95081c21da2
child 390 0e1aeb21cb78
permissions -rw-r--r--
1.8.55 New history window and showtextwindow
insilmaril@366
     1
#include <QApplication>
insilmaril@366
     2
#include <QPixmap>
insilmaril@366
     3
#include <QTranslator>
insilmaril@366
     4
#include <QDir>
insilmaril@366
     5
#include <q3ptrlist.h>
insilmaril@366
     6
#include <QTextCodec>
insilmaril@366
     7
#include <q3network.h>
insilmaril@366
     8
#include <QMenu>
insilmaril@366
     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@164
    21
QString tmpVymDir;				// All temp files go there, created in mainwindow
insilmaril@166
    22
QString clipboardDir;			// Clipboard used in all mapEditors
insilmaril@215
    23
QDir vymBaseDir;				// Containing all styles, scripts, images, ...
insilmaril@366
    24
QDir lastImageDir;
insilmaril@366
    25
QDir lastFileDir;
insilmaril@269
    26
QString iconPath;				// Pointing to icons used for toolbars
insilmaril@269
    27
QString flagsPath;				// Pointing to flags
insilmaril@166
    28
bool clipboardEmpty;			
insilmaril@0
    29
FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
insilmaril@0
    30
FlagRowObj *standardFlagsDefault;
insilmaril@0
    31
insilmaril@98
    32
// Lists of actions
insilmaril@98
    33
// (QActionGroup could not be "enabled")
insilmaril@366
    34
Q3PtrList <QAction> actionListBranches;
insilmaril@98
    35
insilmaril@0
    36
// Actions which change sometimes
insilmaril@0
    37
QAction *actionFileSave;
insilmaril@0
    38
QAction *actionFilePrint;
insilmaril@0
    39
QAction *actionEditUndo;
insilmaril@163
    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@266
    48
QAction *actionEditOpenURLTab;
insilmaril@366
    49
QAction *actionEditOpenMultipleURLTabs;
insilmaril@0
    50
QAction *actionEditURL;
insilmaril@0
    51
QAction *actionEditHeading2URL;
insilmaril@0
    52
QAction *actionEditBugzilla2URL;
insilmaril@175
    53
QAction *actionEditFATE2URL;
insilmaril@0
    54
QAction *actionEditOpenVymLink;
insilmaril@366
    55
QAction *actionEditOpenMultipleVymLinks;
insilmaril@0
    56
QAction *actionEditVymLink;
insilmaril@243
    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@98
    63
QAction *actionEditAddBranchHere;
insilmaril@0
    64
QAction *actionEditAddBranchAbove;
insilmaril@0
    65
QAction *actionEditAddBranchBelow;
insilmaril@294
    66
QAction *actionEditRemoveBranchKeepChilds;
insilmaril@98
    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@89
    83
QActionGroup *actionGroupModModes;
insilmaril@89
    84
QAction *actionModModeColor;
insilmaril@89
    85
QAction *actionModModeLink;
insilmaril@93
    86
QAction *actionModModeCopy;
insilmaril@89
    87
insilmaril@0
    88
QActionGroup *actionGroupFormatFrameTypes;
insilmaril@0
    89
QAction *actionFormatFrameNone;
insilmaril@0
    90
QAction *actionFormatFrameRectangle;
insilmaril@0
    91
insilmaril@0
    92
QActionGroup *actionGroupFormatLinkStyles;
insilmaril@175
    93
QAction *actionFormatIncludeImagesVer;
insilmaril@175
    94
QAction *actionFormatIncludeImagesHor;
insilmaril@160
    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@294
   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@103
   108
QAction *actionSettingsUseFlagGroups;
insilmaril@260
   109
QAction *actionSettingsUseHideExport;
insilmaril@0
   110
insilmaril@0
   111
insilmaril@366
   112
QMenu* branchContextMenu;
insilmaril@366
   113
QMenu* branchAddContextMenu;
insilmaril@366
   114
QMenu* branchRemoveContextMenu;
insilmaril@366
   115
QMenu* branchLinksContextMenu;
insilmaril@366
   116
QMenu* branchXLinksContextMenuEdit;
insilmaril@366
   117
QMenu* branchXLinksContextMenuFollow;
insilmaril@366
   118
QMenu* floatimageContextMenu;
insilmaril@366
   119
QMenu* canvasContextMenu;
insilmaril@366
   120
QMenu* fileLastMapsMenu;
insilmaril@366
   121
QMenu* fileImportMenu;
insilmaril@366
   122
QMenu* fileExportMenu;
insilmaril@0
   123
insilmaril@366
   124
insilmaril@366
   125
Settings settings ("InSilmaril","vym"); // Organization, Application name
insilmaril@366
   126
insilmaril@0
   127
Options options;
insilmaril@366
   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@366
   134
//FIXME	Q_INIT_RESOURCE (application);
insilmaril@366
   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@243
   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@366
   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@185
   160
		cout << "vym version "<<__VYM_VERSION
insilmaril@366
   161
			<<"  (c) 2004-2006 Uwe Drechsel - "
insilmaril@185
   162
			<<__BUILD_DATE<<endl;
insilmaril@0
   163
			
insilmaril@0
   164
		return 0;	
insilmaril@0
   165
	}		
insilmaril@0
   166
	
insilmaril@243
   167
	// Use /usr/share/vym or /usr/local/share/vym or . ?
insilmaril@269
   168
	// First try options
insilmaril@243
   169
	if (options.isOn ("local"))
insilmaril@243
   170
	{
insilmaril@243
   171
		vymBaseDir.setPath (vymBaseDir.currentDirPath());
insilmaril@269
   172
	} else
insilmaril@269
   173
	// then look for environment variable
insilmaril@269
   174
	if (getenv("VYMHOME")!=0)
insilmaril@269
   175
	{
insilmaril@269
   176
		vymBaseDir.setPath (getenv("VYMHOME"));
insilmaril@269
   177
	} else
insilmaril@269
   178
	// ok, let's find my way on my own
insilmaril@243
   179
	{
insilmaril@243
   180
		vymBaseDir.setPath ("/usr/share/vym");
insilmaril@243
   181
		if (!vymBaseDir.exists())
insilmaril@308
   182
		{
insilmaril@243
   183
			vymBaseDir.setPath ("/usr/local/share/vym");
insilmaril@308
   184
			if (!vymBaseDir.exists())
insilmaril@308
   185
				vymBaseDir.setPath(vymBaseDir.currentDirPath() );
insilmaril@308
   186
		}		
insilmaril@243
   187
	}
insilmaril@243
   188
insilmaril@269
   189
	iconPath=vymBaseDir.path()+"/icons/";
insilmaril@269
   190
	flagsPath=vymBaseDir.path()+"/flags/";
insilmaril@269
   191
insilmaril@366
   192
	// Some directories
insilmaril@366
   193
	lastImageDir=QDir().current();
insilmaril@366
   194
	lastFileDir=QDir().current();
insilmaril@366
   195
insilmaril@0
   196
	if (options.isOn ("help"))
insilmaril@0
   197
	{
insilmaril@366
   198
		cout << options.getHelpText().ascii()<<endl;
insilmaril@0
   199
		return 0;	
insilmaril@0
   200
	}	
insilmaril@0
   201
insilmaril@366
   202
    q3InitNetworkProtocols();
insilmaril@243
   203
insilmaril@243
   204
insilmaril@243
   205
	// Initialize translations
insilmaril@243
   206
	QTranslator translator (0);
insilmaril@243
   207
	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
insilmaril@243
   208
    app.installTranslator( &translator );
insilmaril@243
   209
insilmaril@243
   210
	// Initializing the row of system flags
insilmaril@243
   211
	// is done in first call to MapEditor(),
insilmaril@243
   212
	// because we need at least one canvas first
insilmaril@243
   213
	systemFlagsDefault=NULL;
insilmaril@243
   214
	standardFlagsDefault=NULL;
insilmaril@243
   215
insilmaril@0
   216
	// Initialize window of TextEditor
insilmaril@0
   217
	textEditor = new TextEditor();
insilmaril@269
   218
	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
insilmaril@0
   219
	if (textEditor->showWithMain()) textEditor->show();
insilmaril@0
   220
insilmaril@166
   221
	// Initialize mainwindow 
insilmaril@0
   222
    Main m;
insilmaril@0
   223
	//m.resize(m.sizeHint());
insilmaril@269
   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