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