main.cpp
author insilmaril
Wed, 30 Aug 2006 12:16:25 +0000
branchqt4-port
changeset 17 557239819c45
parent 16 41c3d7f9f532
child 18 70c41284cb48
permissions -rw-r--r--
Fixed editing of headings. 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 *actionSettingsPasteNewHeading;
insilmaril@0
   107
QAction *actionSettingsAutoedit;
insilmaril@0
   108
QAction *actionSettingsUseDelKey;
insilmaril@2
   109
QAction *actionSettingsUseFlagGroups;
insilmaril@2
   110
QAction *actionSettingsUseHideExport;
insilmaril@0
   111
insilmaril@4
   112
insilmaril@4
   113
QMenu* branchContextMenu;
insilmaril@4
   114
QMenu* branchAddContextMenu;
insilmaril@4
   115
QMenu* branchRemoveContextMenu;
insilmaril@17
   116
QMenu* branchLinksContextMenu;
insilmaril@17
   117
QMenu* branchXLinksContextMenuEdit;
insilmaril@17
   118
QMenu* branchXLinksContextMenuFollow;
insilmaril@4
   119
QMenu* floatimageContextMenu;
insilmaril@4
   120
QMenu* canvasContextMenu;
insilmaril@4
   121
QMenu* fileLastMapsMenu;
insilmaril@4
   122
QMenu* fileImportMenu;
insilmaril@4
   123
QMenu* fileExportMenu;
insilmaril@0
   124
insilmaril@0
   125
insilmaril@16
   126
Settings settings ("InSilmaril","vym"); // Organization, Application name
insilmaril@16
   127
insilmaril@0
   128
Options options;
insilmaril@4
   129
ImageIO imageIO;
insilmaril@0
   130
insilmaril@0
   131
int statusbarTime=3500;
insilmaril@0
   132
insilmaril@0
   133
int main(int argc, char** argv)
insilmaril@0
   134
{
insilmaril@13
   135
//FIXME	Q_INIT_RESOURCE (application);
insilmaril@13
   136
insilmaril@0
   137
    QApplication app(argc,argv);
insilmaril@0
   138
insilmaril@0
   139
insilmaril@0
   140
	// Reading and initializing options commandline options
insilmaril@0
   141
	options.add ("version", SwitchOption, "v","version");
insilmaril@2
   142
	options.add ("local", SwitchOption, "l", "local");
insilmaril@0
   143
	options.add ("help", SwitchOption, "h", "help");
insilmaril@0
   144
	options.add ("quit", SwitchOption, "q", "quit");
insilmaril@0
   145
	options.add ("test", StringOption, "t", "test");
insilmaril@0
   146
	options.setHelpText (
insilmaril@0
   147
		"VYM - View Your Mind\n"
insilmaril@0
   148
		"--------------------\n\n"
insilmaril@0
   149
		"Information about vym can be found in vym.pdf,\n"
insilmaril@0
   150
		"which should be part of the vym package.\n"
insilmaril@0
   151
		"It is also available at the project homepage:\n\n"
insilmaril@0
   152
		"http://www.InSilmaril.de/vym\n");
insilmaril@0
   153
	if (options.parse())
insilmaril@0
   154
	{
insilmaril@2
   155
//FIXME QT3		cout << endl << options.getHelpText()<<endl;
insilmaril@0
   156
		return 1;
insilmaril@0
   157
	}
insilmaril@0
   158
insilmaril@0
   159
	if (options.isOn ("version"))
insilmaril@0
   160
	{
insilmaril@2
   161
		cout << "vym version "<<__VYM_VERSION
insilmaril@13
   162
			<<"  (c) 2004-2006 Uwe Drechsel - "
insilmaril@2
   163
			<<__BUILD_DATE<<endl;
insilmaril@0
   164
			
insilmaril@0
   165
		return 0;	
insilmaril@0
   166
	}		
insilmaril@0
   167
	
insilmaril@2
   168
	// Use /usr/share/vym or /usr/local/share/vym or . ?
insilmaril@2
   169
	// First try options
insilmaril@2
   170
	if (options.isOn ("local"))
insilmaril@2
   171
	{
insilmaril@2
   172
		vymBaseDir.setPath (vymBaseDir.currentDirPath());
insilmaril@2
   173
	} else
insilmaril@2
   174
	// then look for environment variable
insilmaril@2
   175
	if (getenv("VYMHOME")!=0)
insilmaril@2
   176
	{
insilmaril@2
   177
		vymBaseDir.setPath (getenv("VYMHOME"));
insilmaril@2
   178
	} else
insilmaril@2
   179
	// ok, let's find my way on my own
insilmaril@2
   180
	{
insilmaril@2
   181
		vymBaseDir.setPath ("/usr/share/vym");
insilmaril@2
   182
		if (!vymBaseDir.exists())
insilmaril@2
   183
		{
insilmaril@2
   184
			vymBaseDir.setPath ("/usr/local/share/vym");
insilmaril@2
   185
			if (!vymBaseDir.exists())
insilmaril@2
   186
				vymBaseDir.setPath(vymBaseDir.currentDirPath() );
insilmaril@2
   187
		}		
insilmaril@2
   188
	}
insilmaril@2
   189
insilmaril@2
   190
	iconPath=vymBaseDir.path()+"/icons/";
insilmaril@2
   191
	flagsPath=vymBaseDir.path()+"/flags/";
insilmaril@2
   192
insilmaril@4
   193
	// Some directories
insilmaril@11
   194
	lastImageDir=QDir().current();
insilmaril@11
   195
	lastFileDir=QDir().current();
insilmaril@4
   196
insilmaril@0
   197
	if (options.isOn ("help"))
insilmaril@0
   198
	{
insilmaril@4
   199
		cout << options.getHelpText().ascii()<<endl;
insilmaril@0
   200
		return 0;	
insilmaril@0
   201
	}	
insilmaril@0
   202
insilmaril@0
   203
	if (options.isOn ("test"))
insilmaril@0
   204
	{
insilmaril@0
   205
		// FIXME testing string option only
insilmaril@4
   206
		cout << "Testing: "<<options.getArg("test").ascii()<< endl;
insilmaril@0
   207
	}	
insilmaril@0
   208
insilmaril@2
   209
    q3InitNetworkProtocols();
insilmaril@2
   210
insilmaril@2
   211
insilmaril@2
   212
	// Initialize translations
insilmaril@2
   213
	QTranslator translator (0);
insilmaril@2
   214
	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
insilmaril@2
   215
    app.installTranslator( &translator );
insilmaril@2
   216
insilmaril@2
   217
	// Initializing the row of system flags
insilmaril@2
   218
	// is done in first call to MapEditor(),
insilmaril@2
   219
	// because we need at least one canvas first
insilmaril@2
   220
	systemFlagsDefault=NULL;
insilmaril@2
   221
	standardFlagsDefault=NULL;
insilmaril@2
   222
insilmaril@0
   223
	// Initialize window of TextEditor
insilmaril@0
   224
	textEditor = new TextEditor();
insilmaril@2
   225
	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
insilmaril@0
   226
	if (textEditor->showWithMain()) textEditor->show();
insilmaril@0
   227
insilmaril@2
   228
	// Initialize mainwindow 
insilmaril@0
   229
    Main m;
insilmaril@0
   230
	//m.resize(m.sizeHint());
insilmaril@2
   231
	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
insilmaril@0
   232
	m.show();
insilmaril@0
   233
	m.fileNew();
insilmaril@0
   234
	m.loadCmdLine();
insilmaril@0
   235
insilmaril@0
   236
	// For benchmarking we may want to quit immediatly after drawing
insilmaril@0
   237
	if (options.isOn ("quit"))
insilmaril@0
   238
	{
insilmaril@0
   239
		return 0;
insilmaril@0
   240
	}	
insilmaril@0
   241
insilmaril@0
   242
    QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
insilmaril@0
   243
insilmaril@0
   244
    return app.exec();
insilmaril@0
   245
}
insilmaril@0
   246