main.cpp
author insilmaril
Mon, 10 Apr 2006 11:00:19 +0000
changeset 268 2a6157d381fe
parent 266 7d91b35c1b6f
child 269 4c3e9fa0093b
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 "icons/vym-48x48.xpm"
insilmaril@205
    15
#include "icons/vym-128x128.xpm"
insilmaril@0
    16
#include "icons/vym-editor.xpm"
insilmaril@0
    17
insilmaril@0
    18
#include "flagrowobj.h"
insilmaril@0
    19
insilmaril@0
    20
// Global variables
insilmaril@0
    21
TextEditor *textEditor;			// used in Constr. of LinkableMapObj
insilmaril@0
    22
								// initialized in mainwindow
insilmaril@0
    23
insilmaril@0
    24
Main *mainWindow;				// used in BranchObj::select()								
insilmaril@164
    25
QString tmpVymDir;				// All temp files go there, created in mainwindow
insilmaril@166
    26
QString clipboardDir;			// Clipboard used in all mapEditors
insilmaril@215
    27
QDir vymBaseDir;				// Containing all styles, scripts, images, ...
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@98
    34
QPtrList <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@0
    49
QAction *actionEditURL;
insilmaril@0
    50
QAction *actionEditHeading2URL;
insilmaril@0
    51
QAction *actionEditBugzilla2URL;
insilmaril@175
    52
QAction *actionEditFATE2URL;
insilmaril@0
    53
QAction *actionEditOpenVymLink;
insilmaril@0
    54
QAction *actionEditVymLink;
insilmaril@243
    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@98
    61
QAction *actionEditAddBranchHere;
insilmaril@0
    62
QAction *actionEditAddBranchAbove;
insilmaril@0
    63
QAction *actionEditAddBranchBelow;
insilmaril@98
    64
QAction *actionEditRemoveBranchHere;
insilmaril@98
    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@89
    81
QActionGroup *actionGroupModModes;
insilmaril@89
    82
QAction *actionModModeColor;
insilmaril@89
    83
QAction *actionModModeLink;
insilmaril@93
    84
QAction *actionModModeCopy;
insilmaril@89
    85
insilmaril@0
    86
QActionGroup *actionGroupFormatFrameTypes;
insilmaril@0
    87
QAction *actionFormatFrameNone;
insilmaril@0
    88
QAction *actionFormatFrameRectangle;
insilmaril@0
    89
insilmaril@0
    90
QActionGroup *actionGroupFormatLinkStyles;
insilmaril@175
    91
QAction *actionFormatIncludeImagesVer;
insilmaril@175
    92
QAction *actionFormatIncludeImagesHor;
insilmaril@160
    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@0
   100
insilmaril@0
   101
QAction *actionSettingsAutoselectHeading;
insilmaril@0
   102
QAction *actionSettingsAutoselectText;
insilmaril@0
   103
QAction *actionSettingsPasteNewHeading;
insilmaril@0
   104
QAction *actionSettingsAutoedit;
insilmaril@0
   105
QAction *actionSettingsUseDelKey;
insilmaril@103
   106
QAction *actionSettingsUseFlagGroups;
insilmaril@260
   107
QAction *actionSettingsUseHideExport;
insilmaril@0
   108
insilmaril@0
   109
QPopupMenu *branchContextMenu;
insilmaril@98
   110
QPopupMenu *branchAddContextMenu;
insilmaril@98
   111
QPopupMenu *branchRemoveContextMenu;
insilmaril@89
   112
QPopupMenu *branchLinksContextMenu;
insilmaril@94
   113
QPopupMenu *branchLinksContextMenuDup;
insilmaril@0
   114
QPopupMenu *floatimageContextMenu;
insilmaril@0
   115
QPopupMenu *saveImageFormatMenu;
insilmaril@0
   116
QPopupMenu *canvasContextMenu;
insilmaril@0
   117
QPopupMenu *lastMapsMenu;
insilmaril@205
   118
QPopupMenu *importMenu;
insilmaril@0
   119
QPopupMenu *exportMenu;
insilmaril@0
   120
QPopupMenu *exportImageFormatMenu;
insilmaril@0
   121
insilmaril@0
   122
insilmaril@0
   123
Settings settings;
insilmaril@0
   124
Options options;
insilmaril@0
   125
insilmaril@0
   126
int statusbarTime=3500;
insilmaril@0
   127
insilmaril@0
   128
int main(int argc, char** argv)
insilmaril@0
   129
{
insilmaril@0
   130
    QApplication app(argc,argv);
insilmaril@0
   131
insilmaril@0
   132
insilmaril@0
   133
	// Reading and initializing options commandline options
insilmaril@0
   134
	options.add ("version", SwitchOption, "v","version");
insilmaril@243
   135
	options.add ("local", SwitchOption, "l", "local");
insilmaril@0
   136
	options.add ("help", SwitchOption, "h", "help");
insilmaril@0
   137
	options.add ("quit", SwitchOption, "q", "quit");
insilmaril@0
   138
	options.add ("test", StringOption, "t", "test");
insilmaril@0
   139
	options.setHelpText (
insilmaril@0
   140
		"VYM - View Your Mind\n"
insilmaril@0
   141
		"--------------------\n\n"
insilmaril@0
   142
		"Information about vym can be found in vym.pdf,\n"
insilmaril@0
   143
		"which should be part of the vym package.\n"
insilmaril@0
   144
		"It is also available at the project homepage:\n\n"
insilmaril@0
   145
		"http://www.InSilmaril.de/vym\n");
insilmaril@0
   146
	if (options.parse())
insilmaril@0
   147
	{
insilmaril@0
   148
		cout << endl << options.getHelpText()<<endl;
insilmaril@0
   149
		return 1;
insilmaril@0
   150
	}
insilmaril@0
   151
insilmaril@0
   152
	if (options.isOn ("version"))
insilmaril@0
   153
	{
insilmaril@185
   154
		cout << "vym version "<<__VYM_VERSION
insilmaril@0
   155
			<<"  (c) 2004 Uwe Drechsel - "
insilmaril@185
   156
			<<__BUILD_DATE<<endl;
insilmaril@0
   157
			
insilmaril@0
   158
		return 0;	
insilmaril@0
   159
	}		
insilmaril@0
   160
	
insilmaril@243
   161
	// Use /usr/share/vym or /usr/local/share/vym or . ?
insilmaril@243
   162
	QDir vymBaseDir;
insilmaril@243
   163
	if (options.isOn ("local"))
insilmaril@243
   164
	{
insilmaril@243
   165
		vymBaseDir.setPath (vymBaseDir.currentDirPath());
insilmaril@243
   166
	}else
insilmaril@243
   167
	{
insilmaril@243
   168
		vymBaseDir.setPath ("/usr/share/vym");
insilmaril@243
   169
		if (!vymBaseDir.exists())
insilmaril@243
   170
			vymBaseDir.setPath ("/usr/local/share/vym");
insilmaril@243
   171
		if (!vymBaseDir.exists())
insilmaril@243
   172
			vymBaseDir.setPath(vymBaseDir.currentDirPath() );
insilmaril@243
   173
	}
insilmaril@243
   174
insilmaril@0
   175
	if (options.isOn ("help"))
insilmaril@0
   176
	{
insilmaril@0
   177
		cout << options.getHelpText()<<endl;
insilmaril@0
   178
		return 0;	
insilmaril@0
   179
	}	
insilmaril@0
   180
insilmaril@0
   181
	if (options.isOn ("test"))
insilmaril@0
   182
	{
insilmaril@0
   183
		// FIXME testing string option only
insilmaril@0
   184
		cout << "Testing: "<<options.getArg("test")<< endl;
insilmaril@0
   185
	}	
insilmaril@0
   186
insilmaril@243
   187
insilmaril@243
   188
    QMimeSourceFactory *factory = QMimeSourceFactory::defaultFactory();
insilmaril@243
   189
    factory->setPixmap("vym_128x128", QPixmap(vym_128x128_xpm));
insilmaril@243
   190
    qInitNetworkProtocols();
insilmaril@243
   191
insilmaril@243
   192
insilmaril@243
   193
	// Initialize translations
insilmaril@243
   194
	QTranslator translator (0);
insilmaril@243
   195
	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
insilmaril@243
   196
    app.installTranslator( &translator );
insilmaril@243
   197
insilmaril@243
   198
	// Initializing the row of system flags
insilmaril@243
   199
	// is done in first call to MapEditor(),
insilmaril@243
   200
	// because we need at least one canvas first
insilmaril@243
   201
	systemFlagsDefault=NULL;
insilmaril@243
   202
	standardFlagsDefault=NULL;
insilmaril@243
   203
insilmaril@0
   204
	// Initialize window of TextEditor
insilmaril@0
   205
	textEditor = new TextEditor();
insilmaril@0
   206
	textEditor->setIcon (QPixmap (vym_editor_xpm));
insilmaril@0
   207
	if (textEditor->showWithMain()) textEditor->show();
insilmaril@0
   208
insilmaril@166
   209
	// Initialize mainwindow 
insilmaril@0
   210
    Main m;
insilmaril@0
   211
	//m.resize(m.sizeHint());
insilmaril@205
   212
	m.setIcon (QPixmap (vym_48x48_xpm));
insilmaril@0
   213
	m.show();
insilmaril@0
   214
	m.fileNew();
insilmaril@0
   215
	m.loadCmdLine();
insilmaril@0
   216
insilmaril@0
   217
	// For benchmarking we may want to quit immediatly after drawing
insilmaril@0
   218
	if (options.isOn ("quit"))
insilmaril@0
   219
	{
insilmaril@0
   220
		return 0;
insilmaril@0
   221
	}	
insilmaril@0
   222
insilmaril@0
   223
    QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
insilmaril@0
   224
insilmaril@0
   225
    return app.exec();
insilmaril@0
   226
}
insilmaril@0
   227