texteditor.cpp
author insilmaril
Thu, 16 Nov 2006 10:07:11 +0000
changeset 399 190b3a70fabc
parent 395 7ced3733ba60
child 404 53efc2562a7d
permissions -rw-r--r--
Version 1.8.59: More fixes in undo/redo area
insilmaril@0
     1
#include "texteditor.h"
insilmaril@0
     2
insilmaril@0
     3
#include <iostream>
insilmaril@95
     4
#include <cstdlib>
insilmaril@0
     5
#include <typeinfo>
insilmaril@0
     6
insilmaril@189
     7
#include "noteobj.h"
insilmaril@189
     8
#include "version.h"
insilmaril@189
     9
insilmaril@0
    10
extern int statusbarTime;
insilmaril@0
    11
extern QSettings settings;
insilmaril@0
    12
insilmaril@94
    13
extern QAction *actionViewToggleNoteEditor;
insilmaril@94
    14
insilmaril@269
    15
extern QString iconPath;
insilmaril@269
    16
insilmaril@0
    17
using namespace std;
insilmaril@0
    18
insilmaril@0
    19
insilmaril@0
    20
///////////////////////////////////////////////////////////////////////
insilmaril@0
    21
///////////////////////////////////////////////////////////////////////
insilmaril@0
    22
jhilmer@142
    23
insilmaril@0
    24
TextEditor::TextEditor()
insilmaril@0
    25
{
insilmaril@0
    26
    printer = new QPrinter( QPrinter::HighResolution );
insilmaril@366
    27
	printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@0
    28
insilmaril@388
    29
    e = new QTextEdit( this);
insilmaril@0
    30
    e->setFocus();
insilmaril@366
    31
	e->setTextFormat(Qt::RichText);		// default
insilmaril@0
    32
	e->setTabStopWidth (20);		// unit is pixel
insilmaril@366
    33
	e->setColor (Qt::black);
insilmaril@366
    34
	e->setAutoFillBackground (true);
insilmaril@0
    35
	connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
insilmaril@0
    36
    setCentralWidget( e );
insilmaril@388
    37
    statusBar()->message( tr("Ready","Statusbar message"), statusbarTime);
insilmaril@395
    38
	setCaption(__VYM " - " +tr ("Note Editor","Window caption"));
insilmaril@0
    39
insilmaril@388
    40
insilmaril@388
    41
	connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
insilmaril@388
    42
            this, SLOT(formatChanged(const QTextCharFormat &)));
insilmaril@388
    43
insilmaril@388
    44
insilmaril@388
    45
insilmaril@0
    46
	// Toolbars
insilmaril@0
    47
	setupFileActions();
insilmaril@0
    48
	setupEditActions();
insilmaril@0
    49
	setupFormatActions();
insilmaril@0
    50
	setupSettingsActions();
insilmaril@0
    51
	
insilmaril@0
    52
	// Various states
insilmaril@0
    53
	setInactive();
insilmaril@0
    54
insilmaril@0
    55
	// Load Settings
insilmaril@366
    56
	resize (settings.value ( "/noteeditor/geometry/size", QSize(450,600)).toSize());
insilmaril@366
    57
	move   (settings.value ( "/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
insilmaril@0
    58
	
insilmaril@366
    59
	if (settings.value ( "/noteeditor/showWithMain",true).toBool())
insilmaril@0
    60
		setShowWithMain(true);
insilmaril@0
    61
	else	
insilmaril@0
    62
		setShowWithMain(false);
insilmaril@0
    63
insilmaril@366
    64
	varFont.fromString( settings.value
insilmaril@366
    65
		("/noteeditor/fonts/varFont",
insilmaril@366
    66
		"Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString() 
insilmaril@0
    67
	);
insilmaril@366
    68
	fixedFont.fromString (settings.value(
insilmaril@366
    69
		"/noteeditor/fonts/fixedFont",
insilmaril@366
    70
		"Courier,14,-1,5,48,0,0,0,1,0").toString() 
insilmaril@0
    71
	);
insilmaril@366
    72
	QString s=settings.value ("/noteeditor/fonts/fonthintDefault","variable").toString();
insilmaril@0
    73
	if (s == "fixed")
insilmaril@0
    74
	{	
insilmaril@0
    75
		actionSettingsFonthintDefault->setOn (true);
insilmaril@0
    76
		e->setCurrentFont (fixedFont);
insilmaril@0
    77
	} else	
insilmaril@0
    78
	{
insilmaril@0
    79
		actionSettingsFonthintDefault->setOn (false);
insilmaril@0
    80
		e->setCurrentFont (varFont);
insilmaril@0
    81
	}	
insilmaril@106
    82
	filenameHint="";
insilmaril@123
    83
insilmaril@388
    84
	// Restore position of toolbars
insilmaril@388
    85
	restoreState (settings.value("/noteeditor/state",0).toByteArray());
insilmaril@388
    86
insilmaril@123
    87
	// Save settings in vymrc
insilmaril@366
    88
	settings.setValue("/mainwindow/printerName",printer->printerName());
insilmaril@0
    89
}
insilmaril@0
    90
insilmaril@0
    91
insilmaril@0
    92
TextEditor::~TextEditor()
insilmaril@0
    93
{
insilmaril@0
    94
    if (printer) delete printer;
insilmaril@0
    95
	// Save Settings
insilmaril@366
    96
	settings.setValue( "/noteeditor/geometry/size", size() );
insilmaril@366
    97
	settings.setValue( "/noteeditor/geometry/pos", pos() );
insilmaril@388
    98
	settings.setValue ("/noteeditor/state",saveState(0));
insilmaril@0
    99
	
insilmaril@366
   100
	settings.setValue( "/noteeditor/showWithMain",showWithMain());
insilmaril@0
   101
insilmaril@0
   102
	QString s;
insilmaril@0
   103
	if (actionSettingsFonthintDefault->isOn() )
insilmaril@0
   104
		s="fixed";
insilmaril@0
   105
	else	
insilmaril@0
   106
		s="variable";
insilmaril@366
   107
	settings.setValue( "/noteeditor/fonts/fonthintDefault",s );
insilmaril@366
   108
	settings.setValue("/noteeditor/fonts/varFont", varFont.toString() );
insilmaril@366
   109
	settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() );
insilmaril@388
   110
insilmaril@388
   111
insilmaril@0
   112
}
insilmaril@0
   113
insilmaril@0
   114
bool TextEditor::isEmpty()
insilmaril@0
   115
{
insilmaril@366
   116
	if (e->toPlainText().length()>0)
insilmaril@0
   117
		return false;
insilmaril@0
   118
	else
insilmaril@0
   119
		return true;
insilmaril@0
   120
}
insilmaril@0
   121
insilmaril@0
   122
void TextEditor::setShowWithMain(bool v)
insilmaril@0
   123
{
insilmaril@0
   124
	showwithmain=v;
insilmaril@0
   125
}
insilmaril@0
   126
insilmaril@0
   127
bool TextEditor::showWithMain()
insilmaril@0
   128
{
insilmaril@0
   129
	return showwithmain;
insilmaril@0
   130
}
insilmaril@0
   131
insilmaril@0
   132
void TextEditor::setFontHint (const QString &fh)
insilmaril@0
   133
{
insilmaril@0
   134
	if (fh=="fixed")
insilmaril@0
   135
		actionFormatUseFixedFont->setOn (true);
insilmaril@0
   136
	else
insilmaril@0
   137
		actionFormatUseFixedFont->setOn (false);
insilmaril@0
   138
}
insilmaril@0
   139
insilmaril@0
   140
insilmaril@0
   141
QString TextEditor::getFontHint()
insilmaril@0
   142
{
insilmaril@0
   143
	if (actionFormatUseFixedFont->isOn())
insilmaril@0
   144
		return "fixed";
insilmaril@0
   145
	else	
insilmaril@0
   146
		return "var";
insilmaril@0
   147
}
insilmaril@0
   148
insilmaril@0
   149
QString TextEditor::getFontHintDefault()
insilmaril@0
   150
{
insilmaril@0
   151
	if (actionSettingsFonthintDefault->isOn())
insilmaril@0
   152
		return "fixed";
insilmaril@0
   153
	else	
insilmaril@0
   154
		return "var";
insilmaril@0
   155
}
insilmaril@0
   156
insilmaril@0
   157
void TextEditor::setFilename(const QString &fn)
insilmaril@0
   158
{
insilmaril@0
   159
	if (state==filledEditor)
insilmaril@0
   160
		if (fn.isEmpty() )
insilmaril@0
   161
		{
insilmaril@0
   162
			filename="";
insilmaril@388
   163
			statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime );
insilmaril@0
   164
		}	
insilmaril@0
   165
		else
insilmaril@0
   166
		{
insilmaril@0
   167
			filename=fn;
insilmaril@388
   168
			statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime );
insilmaril@0
   169
		}	
insilmaril@0
   170
}
insilmaril@0
   171
insilmaril@0
   172
QString TextEditor::getFilename()
insilmaril@0
   173
{
insilmaril@0
   174
	return filename;
insilmaril@0
   175
}
insilmaril@0
   176
insilmaril@106
   177
void TextEditor::setFilenameHint(const QString &fnh)
insilmaril@106
   178
{
insilmaril@106
   179
	filenameHint=fnh;
insilmaril@106
   180
}
insilmaril@106
   181
insilmaril@106
   182
QString TextEditor::getFilenameHint()
insilmaril@106
   183
{
insilmaril@106
   184
	return filenameHint;
insilmaril@106
   185
}
insilmaril@106
   186
insilmaril@366
   187
bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
insilmaril@0
   188
{
insilmaril@366
   189
	if (e->find (t,flags))
insilmaril@0
   190
		return true;
insilmaril@0
   191
	else	
insilmaril@0
   192
		return false;
insilmaril@0
   193
}
insilmaril@0
   194
insilmaril@0
   195
void TextEditor::setupFileActions()
insilmaril@0
   196
{
insilmaril@366
   197
    QToolBar *tb = addToolBar ( tr("Note Actions") );
insilmaril@389
   198
	tb->setObjectName ("noteEditorFileActions");
insilmaril@395
   199
    QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" ));
insilmaril@0
   200
insilmaril@0
   201
    QAction *a;
insilmaril@366
   202
    a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
insilmaril@395
   203
	a->setStatusTip (tr( "Import","Status tip for Note menu" ) );
insilmaril@366
   204
	a->setShortcut( Qt::CTRL + Qt::Key_O );
insilmaril@0
   205
    connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
insilmaril@366
   206
	tb->addAction (a);
insilmaril@366
   207
	fileMenu->addAction (a);
insilmaril@0
   208
	actionFileLoad=a;
insilmaril@0
   209
insilmaril@366
   210
    fileMenu->addSeparator();
insilmaril@366
   211
    a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
insilmaril@395
   212
	a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) );
insilmaril@366
   213
	a->setShortcut( Qt::CTRL + Qt::Key_S );
insilmaril@0
   214
    connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
insilmaril@366
   215
	tb->addAction (a);
insilmaril@366
   216
	fileMenu->addAction (a);
insilmaril@0
   217
	actionFileSave=a;
insilmaril@0
   218
	
insilmaril@366
   219
    a = new QAction(  QPixmap(), tr( "Export &As... (HTML)" ), this);
insilmaril@395
   220
	a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu"  ));
insilmaril@0
   221
    connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
insilmaril@366
   222
	fileMenu->addAction (a);
insilmaril@0
   223
	actionFileSaveAs=a;
insilmaril@0
   224
insilmaril@366
   225
    a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
insilmaril@395
   226
	a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) );
insilmaril@366
   227
	a->setShortcut(Qt::ALT + Qt::Key_X );
insilmaril@0
   228
    connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
insilmaril@366
   229
	fileMenu->addAction (a);
insilmaril@0
   230
	actionFileSaveAs=a;
insilmaril@0
   231
insilmaril@366
   232
    fileMenu->addSeparator();
insilmaril@366
   233
    a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
insilmaril@395
   234
	a->setStatusTip (tr( "Print Note","Status tip for note menu" ) );
insilmaril@366
   235
	a->setShortcut( Qt::CTRL + Qt::Key_P );
insilmaril@0
   236
    connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
insilmaril@366
   237
	tb->addAction (a);
insilmaril@366
   238
	fileMenu->addAction (a);
insilmaril@0
   239
	actionFilePrint=a;
insilmaril@0
   240
}
insilmaril@0
   241
insilmaril@0
   242
void TextEditor::setupEditActions()
insilmaril@0
   243
{
insilmaril@366
   244
    QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
insilmaril@389
   245
	tb->setObjectName ("noteEditorEditActions");
insilmaril@366
   246
    QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
insilmaril@0
   247
insilmaril@0
   248
    QAction *a;
insilmaril@366
   249
    a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
insilmaril@395
   250
	a->setStatusTip ( tr( "Undo","Status tip for note menu" ) );
insilmaril@366
   251
	a->setShortcut(Qt::CTRL + Qt::Key_Z );
insilmaril@0
   252
    connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
insilmaril@366
   253
	editMenu->addAction (a);
insilmaril@366
   254
	tb->addAction (a);
insilmaril@0
   255
	actionEditUndo=a;
insilmaril@0
   256
	
insilmaril@366
   257
    a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this); 
insilmaril@395
   258
	a->setStatusTip ( tr( "Redo","Status tip for note menu" ) );
insilmaril@366
   259
	a->setShortcut( Qt::CTRL + Qt::Key_Y );
insilmaril@0
   260
    connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
insilmaril@366
   261
	editMenu->addAction (a);
insilmaril@366
   262
	tb->addAction (a);
insilmaril@0
   263
	actionEditRedo=a;
insilmaril@0
   264
insilmaril@366
   265
    editMenu->addSeparator();
insilmaril@366
   266
    a = new QAction(QPixmap(), tr( "Select and copy &all" ),this); 
insilmaril@395
   267
	a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) );
insilmaril@366
   268
	a->setShortcut( Qt::CTRL + Qt::Key_A );
insilmaril@0
   269
    connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
insilmaril@366
   270
	editMenu->addAction (a);
insilmaril@0
   271
insilmaril@366
   272
    editMenu->addSeparator();
insilmaril@366
   273
    a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
insilmaril@395
   274
	a->setStatusTip ( tr( "Copy","Status tip for note menu" ) );
insilmaril@366
   275
	a->setShortcut( Qt::CTRL + Qt::Key_C );
insilmaril@0
   276
    connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
insilmaril@366
   277
	editMenu->addAction (a);
insilmaril@366
   278
	tb->addAction (a);
insilmaril@0
   279
	actionEditCopy=a;
insilmaril@0
   280
	
insilmaril@366
   281
    a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
insilmaril@395
   282
	a->setStatusTip ( tr( "Cut","Status tip for note menu" ) );
insilmaril@366
   283
	a->setShortcut( Qt::CTRL + Qt::Key_X );
insilmaril@0
   284
    connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
insilmaril@366
   285
	editMenu->addAction (a);
insilmaril@366
   286
	tb->addAction (a);
insilmaril@0
   287
	actionEditCut=a;
insilmaril@0
   288
insilmaril@366
   289
    a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
insilmaril@395
   290
	a->setStatusTip ( tr( "Paste","Status tip for note menu" ) );
insilmaril@366
   291
	a->setShortcut( Qt::CTRL + Qt::Key_V );
insilmaril@0
   292
    connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
insilmaril@366
   293
	editMenu->addAction (a);
insilmaril@366
   294
	tb->addAction (a);
insilmaril@0
   295
	actionEditPaste=a;
insilmaril@0
   296
	
insilmaril@366
   297
    a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
insilmaril@395
   298
	a->setStatusTip (tr( "Delete all","Status tip for note menu" ) );
insilmaril@0
   299
    connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
insilmaril@366
   300
	editMenu->addAction (a);
insilmaril@366
   301
	tb->addAction (a);
insilmaril@0
   302
	actionEditDeleteAll=a;
insilmaril@0
   303
insilmaril@0
   304
}
insilmaril@0
   305
insilmaril@0
   306
void TextEditor::setupFormatActions()
insilmaril@0
   307
{
insilmaril@366
   308
    QToolBar *tb = addToolBar ( tr("Format Actions" ));
insilmaril@389
   309
	tb->setObjectName ("noteEditorFormatActions");
insilmaril@366
   310
    QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
insilmaril@0
   311
insilmaril@0
   312
    QAction *a;
insilmaril@0
   313
insilmaril@366
   314
    a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
insilmaril@395
   315
	a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) );
insilmaril@0
   316
	a->setToggleAction (true);
insilmaril@366
   317
	a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
insilmaril@0
   318
    connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
insilmaril@366
   319
	formatMenu->addAction (a);
insilmaril@366
   320
	tb->addAction (a);
insilmaril@0
   321
	actionFormatUseFixedFont=a;
insilmaril@0
   322
insilmaril@366
   323
    comboFont = new QComboBox;
insilmaril@366
   324
	tb->addWidget (comboFont);
insilmaril@366
   325
    QFontDatabase fontDB;
insilmaril@366
   326
    comboFont->insertStringList( fontDB.families() );
insilmaril@0
   327
    connect( comboFont, SIGNAL( activated( const QString & ) ),
insilmaril@0
   328
	     this, SLOT( textFamily( const QString & ) ) );
insilmaril@366
   329
    comboFont->addItem( QApplication::font().family() );
insilmaril@366
   330
    comboSize = new QComboBox;
insilmaril@366
   331
	tb->addWidget (comboSize);
insilmaril@366
   332
	QList<int> sizes=fontDB.standardSizes();
insilmaril@366
   333
	QList<int>::iterator i = sizes.begin();
insilmaril@366
   334
	while (i != sizes.end()) 
insilmaril@366
   335
	{
insilmaril@366
   336
		++i; // increment i before using it
insilmaril@366
   337
		comboSize->insertItem ( QString::number(*i));
insilmaril@366
   338
	}	
insilmaril@0
   339
    connect( comboSize, SIGNAL( activated( const QString & ) ),
insilmaril@0
   340
	     this, SLOT( textSize( const QString & ) ) );
insilmaril@366
   341
    comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
insilmaril@0
   342
insilmaril@366
   343
    formatMenu->addSeparator();
insilmaril@0
   344
insilmaril@0
   345
    QPixmap pix( 16, 16 );
insilmaril@0
   346
    pix.fill( e->color());
insilmaril@366
   347
    a = new QAction( pix, tr( "&Color..." ), this);
insilmaril@366
   348
	formatMenu->addAction (a);
insilmaril@366
   349
	tb->addAction (a);
insilmaril@366
   350
    connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
insilmaril@366
   351
    actionTextColor=a;
insilmaril@0
   352
insilmaril@366
   353
    a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
insilmaril@366
   354
	a->setShortcut(Qt::CTRL + Qt::Key_B );
insilmaril@366
   355
    connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
insilmaril@366
   356
	tb->addAction (a);
insilmaril@366
   357
	formatMenu->addAction (a);
insilmaril@366
   358
    a->setToggleAction( true );
insilmaril@366
   359
    actionTextBold=a;
insilmaril@366
   360
	
insilmaril@366
   361
    a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ),  this);
insilmaril@366
   362
	a->setShortcut(Qt::CTRL + Qt::Key_I);
insilmaril@366
   363
    connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
insilmaril@366
   364
	tb->addAction (a);
insilmaril@366
   365
	formatMenu->addAction (a);
insilmaril@366
   366
    a->setToggleAction( true );
insilmaril@366
   367
    actionTextItalic=a;
insilmaril@366
   368
	
insilmaril@366
   369
    a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
insilmaril@366
   370
	a->setShortcut(Qt::CTRL + Qt::Key_U );
insilmaril@366
   371
    connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
insilmaril@366
   372
	tb->addAction (a);
insilmaril@366
   373
	formatMenu->addAction (a);
insilmaril@366
   374
    a->setToggleAction( true );
insilmaril@366
   375
    actionTextUnderline=a;
insilmaril@366
   376
    formatMenu->addSeparator();
insilmaril@0
   377
insilmaril@388
   378
    QActionGroup *grp2 = new QActionGroup( this );
insilmaril@388
   379
    grp2->setExclusive(true);
insilmaril@388
   380
    a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
insilmaril@388
   381
	a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
insilmaril@388
   382
    a->setToggleAction( true );
insilmaril@388
   383
	tb->addAction (a);
insilmaril@388
   384
	formatMenu->addAction (a);
insilmaril@388
   385
    connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
insilmaril@388
   386
    actionAlignSubScript=a;
insilmaril@388
   387
insilmaril@388
   388
    a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2  );
insilmaril@388
   389
	a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
insilmaril@388
   390
    a->setToggleAction( true );
insilmaril@388
   391
	tb->addAction (a);
insilmaril@388
   392
	formatMenu->addAction (a);
insilmaril@388
   393
    connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
insilmaril@388
   394
    actionAlignSuperScript=a;
insilmaril@0
   395
    QActionGroup *grp = new QActionGroup( this );
insilmaril@0
   396
    connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
insilmaril@0
   397
insilmaril@388
   398
    formatMenu->addSeparator();
insilmaril@388
   399
insilmaril@366
   400
    a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
insilmaril@366
   401
	a->setShortcut( Qt::CTRL+Qt::Key_L );
insilmaril@366
   402
    a->setToggleAction( true );
insilmaril@366
   403
	tb->addAction (a);
insilmaril@366
   404
	formatMenu->addAction (a);
insilmaril@366
   405
    actionAlignLeft=a;
insilmaril@366
   406
    a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
insilmaril@366
   407
    a->setShortcut(  Qt::CTRL + Qt::Key_E);
insilmaril@366
   408
    a->setToggleAction( true );
insilmaril@366
   409
	tb->addAction (a);
insilmaril@366
   410
	formatMenu->addAction (a);
insilmaril@366
   411
    actionAlignCenter=a;
insilmaril@366
   412
    a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
insilmaril@366
   413
	a->setShortcut(Qt::CTRL + Qt::Key_R );
insilmaril@366
   414
    a->setToggleAction( true );
insilmaril@366
   415
	tb->addAction (a);
insilmaril@366
   416
	formatMenu->addAction (a);
insilmaril@366
   417
    actionAlignRight=a;
insilmaril@366
   418
    a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
insilmaril@366
   419
	a->setShortcut(Qt::CTRL + Qt::Key_J );
insilmaril@366
   420
    a->setToggleAction( true );
insilmaril@366
   421
	tb->addAction (a);
insilmaril@366
   422
	formatMenu->addAction (a);
insilmaril@366
   423
    actionAlignJustify=a;
insilmaril@0
   424
}
insilmaril@0
   425
insilmaril@0
   426
void TextEditor::setupSettingsActions()
insilmaril@0
   427
{
insilmaril@366
   428
    QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
insilmaril@0
   429
insilmaril@0
   430
    QAction *a;
insilmaril@366
   431
    a = new QAction(tr( "Set &fixed font" ), this);
insilmaril@395
   432
	a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" ));
insilmaril@0
   433
    connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
insilmaril@366
   434
	settingsMenu->addAction (a);
insilmaril@0
   435
	actionSettingsFixedFont=a;
insilmaril@0
   436
insilmaril@366
   437
    a = new QAction(tr( "Set &variable font" ), this);
insilmaril@395
   438
	a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) );
insilmaril@0
   439
    connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
insilmaril@366
   440
	settingsMenu->addAction (a);
insilmaril@0
   441
	actionSettingsVarFont=a;
insilmaril@0
   442
insilmaril@366
   443
    a = new QAction(tr( "&fixed font is default" ),  this);
insilmaril@395
   444
	a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) );
insilmaril@0
   445
	a->setToggleAction (true);
insilmaril@0
   446
	// set state later in constructor...
insilmaril@366
   447
	settingsMenu->addAction (a);
insilmaril@0
   448
	actionSettingsFonthintDefault=a;
insilmaril@0
   449
}
insilmaril@0
   450
insilmaril@0
   451
void TextEditor::textLoad()
insilmaril@0
   452
{
insilmaril@0
   453
	if (state!=inactiveEditor)
insilmaril@0
   454
	{
insilmaril@366
   455
		if (e->text().length()) 
insilmaril@0
   456
		{
insilmaril@189
   457
			QMessageBox mb( __VYM " - " +tr("Note Editor"),
insilmaril@0
   458
				"Loading will overwrite the existing note",
insilmaril@0
   459
				QMessageBox::Warning,
insilmaril@0
   460
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   461
				QMessageBox::Cancel,
insilmaril@0
   462
				0 );
insilmaril@0
   463
			mb.setButtonText( QMessageBox::Yes, "Load note" );
insilmaril@0
   464
			switch( mb.exec() ) {
insilmaril@0
   465
				case QMessageBox::Cancel:
insilmaril@0
   466
					return;
insilmaril@0
   467
					break;
insilmaril@0
   468
			}
insilmaril@0
   469
		} 
insilmaril@0
   470
		// Load note
insilmaril@0
   471
		QFileDialog *fd=new QFileDialog( this);
insilmaril@366
   472
		QStringList types;
insilmaril@366
   473
		types<< "VYM notes (*.html)" <<
insilmaril@366
   474
			"ASCII texts (*.txt)" <<
insilmaril@366
   475
			"All filed (*)";
insilmaril@366
   476
		fd->setFilters (types);
insilmaril@366
   477
		fd->setDirectory (QDir().current());
insilmaril@0
   478
		fd->show();
insilmaril@0
   479
		QString fn;
insilmaril@0
   480
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
   481
			fn = fd->selectedFile();
insilmaril@0
   482
insilmaril@0
   483
		if ( !fn.isEmpty() )
insilmaril@0
   484
		{
insilmaril@0
   485
			QFile f( fn );
insilmaril@366
   486
			if ( !f.open( QIODevice::ReadOnly ) )
insilmaril@0
   487
			return;
insilmaril@0
   488
insilmaril@0
   489
			QTextStream ts( &f );
insilmaril@0
   490
			setText( ts.read() );
insilmaril@0
   491
			editorChanged();
insilmaril@0
   492
		}
insilmaril@0
   493
	}
insilmaril@0
   494
}
insilmaril@0
   495
insilmaril@0
   496
void TextEditor::closeEvent( QCloseEvent* ce )
insilmaril@0
   497
{
jhilmer@144
   498
    ce->accept();	// TextEditor can be reopened with show()
insilmaril@393
   499
    showwithmain=false;
insilmaril@390
   500
	emit (textEditorClosed() );
jhilmer@144
   501
    return;
insilmaril@0
   502
}
insilmaril@0
   503
insilmaril@0
   504
QString TextEditor::getText()
insilmaril@0
   505
{
insilmaril@366
   506
	if (e->toPlainText().isEmpty())
insilmaril@366
   507
		return "";
insilmaril@366
   508
	else	
insilmaril@366
   509
		return e->text();
insilmaril@0
   510
}
insilmaril@0
   511
insilmaril@0
   512
void TextEditor::editorChanged()
insilmaril@0
   513
{
insilmaril@0
   514
	if (isEmpty())
insilmaril@0
   515
		state=emptyEditor;
insilmaril@0
   516
	else
insilmaril@0
   517
		state=filledEditor;
insilmaril@0
   518
insilmaril@0
   519
		if (state==emptyEditor)
insilmaril@366
   520
			setState (emptyEditor);
insilmaril@0
   521
		else
insilmaril@366
   522
			setState (filledEditor);
insilmaril@0
   523
	// SLOT is LinkableMapObj, which will update systemFlag
insilmaril@0
   524
	emit (textHasChanged() );
insilmaril@0
   525
}
insilmaril@0
   526
insilmaril@0
   527
insilmaril@0
   528
void TextEditor::setText(QString t)
insilmaril@0
   529
{
insilmaril@0
   530
	e->setReadOnly(false);
insilmaril@0
   531
	e->setText(t);
insilmaril@0
   532
	enableActions();
insilmaril@0
   533
}
insilmaril@0
   534
insilmaril@0
   535
void TextEditor::setInactive()
insilmaril@0
   536
{
jhilmer@135
   537
	state=inactiveEditor;
insilmaril@0
   538
	setText("");
insilmaril@366
   539
	setState (inactiveEditor);
insilmaril@0
   540
	e->setReadOnly (true);
insilmaril@0
   541
insilmaril@0
   542
	disableActions();
insilmaril@0
   543
}
insilmaril@0
   544
insilmaril@0
   545
void TextEditor::editCopyAll()
insilmaril@0
   546
{
insilmaril@0
   547
	e->selectAll();
insilmaril@0
   548
	e->copy();
insilmaril@0
   549
}
insilmaril@0
   550
insilmaril@0
   551
void TextEditor::textSaveAs()
insilmaril@0
   552
{
insilmaril@0
   553
    QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
insilmaril@0
   554
					       this,"export note dialog",tr("Export Note to single file") );
insilmaril@0
   555
insilmaril@0
   556
    if ( !fn.isEmpty() ) 
insilmaril@0
   557
	{
insilmaril@0
   558
		QFile file (fn);
insilmaril@0
   559
		if (file.exists())
insilmaril@0
   560
		{
insilmaril@189
   561
			QMessageBox mb( __VYM,
insilmaril@395
   562
				tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
insilmaril@0
   563
			QMessageBox::Warning,
insilmaril@0
   564
			QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   565
			QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
   566
			Qt::NoButton );
insilmaril@0
   567
			mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
   568
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
   569
			switch( mb.exec() ) {
insilmaril@0
   570
				case QMessageBox::Yes:
insilmaril@0
   571
					// save 
insilmaril@0
   572
					filename = fn;
insilmaril@0
   573
					textSave();
insilmaril@0
   574
					return;
insilmaril@0
   575
				case QMessageBox::Cancel:
insilmaril@0
   576
					// do nothing
insilmaril@0
   577
					break;
insilmaril@0
   578
			}
insilmaril@0
   579
		} else
insilmaril@0
   580
		{
insilmaril@0
   581
			filename = fn;
insilmaril@0
   582
			textSave();
insilmaril@0
   583
			return;
insilmaril@0
   584
		}			
insilmaril@0
   585
    }
insilmaril@395
   586
	statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime );
insilmaril@0
   587
}
insilmaril@0
   588
insilmaril@0
   589
insilmaril@0
   590
void TextEditor::textSave()
insilmaril@0
   591
{
insilmaril@0
   592
    if ( filename.isEmpty() ) 
insilmaril@0
   593
	{
insilmaril@0
   594
		textSaveAs();
insilmaril@0
   595
		return;
insilmaril@0
   596
    }
insilmaril@0
   597
insilmaril@0
   598
    QString text = e->text();
insilmaril@0
   599
    QFile f( filename );
insilmaril@366
   600
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@0
   601
	{
insilmaril@0
   602
		statusBar()->message( QString("Could not write to %1").arg(filename),
insilmaril@0
   603
					  statusbarTime );
insilmaril@0
   604
		return;
insilmaril@0
   605
    }
insilmaril@0
   606
insilmaril@0
   607
    QTextStream t( &f );
insilmaril@0
   608
    t << text;
insilmaril@0
   609
    f.close();
insilmaril@0
   610
insilmaril@0
   611
    e->setModified( FALSE );
insilmaril@0
   612
insilmaril@0
   613
    statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
insilmaril@0
   614
}
insilmaril@0
   615
insilmaril@0
   616
void TextEditor::textExportAsASCII()
insilmaril@0
   617
{
insilmaril@189
   618
	QString text = NoteObj (e->text()).getNoteASCII();
insilmaril@106
   619
	QString fn,s;
insilmaril@106
   620
	if (!filenameHint.isEmpty())
insilmaril@106
   621
	{
insilmaril@106
   622
		if (!filenameHint.contains (".txt"))
insilmaril@106
   623
			s=filenameHint+".txt";
insilmaril@106
   624
		else	
insilmaril@106
   625
			s=filenameHint;
insilmaril@106
   626
	} else	
insilmaril@106
   627
		s=QString::null;
insilmaril@106
   628
	fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
insilmaril@0
   629
	int ret=-1;
insilmaril@0
   630
insilmaril@0
   631
    if ( !fn.isEmpty() ) 
insilmaril@0
   632
	{
insilmaril@0
   633
		QFile file (fn);
insilmaril@0
   634
		if (file.exists())
insilmaril@0
   635
		{
insilmaril@395
   636
			QMessageBox mb( __VYM,
insilmaril@395
   637
				tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
insilmaril@0
   638
			QMessageBox::Warning,
insilmaril@0
   639
			QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   640
			QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
   641
			Qt::NoButton );
insilmaril@0
   642
			mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
   643
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
   644
			ret=mb.exec();
insilmaril@0
   645
		}	
insilmaril@0
   646
		if (ret==QMessageBox::Cancel)
insilmaril@0
   647
			return;
insilmaril@0
   648
			
insilmaril@0
   649
		// save 
insilmaril@366
   650
		if ( !file.open( QIODevice::WriteOnly ) ) 
insilmaril@0
   651
			statusBar()->message( QString("Could not write to %1").arg(filename),
insilmaril@0
   652
						  statusbarTime );
insilmaril@0
   653
		else
insilmaril@0
   654
		{
insilmaril@0
   655
			QTextStream t( &file );
insilmaril@0
   656
			t << text;
insilmaril@0
   657
			file.close();
insilmaril@0
   658
insilmaril@0
   659
			statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
insilmaril@0
   660
		}
insilmaril@0
   661
    }
insilmaril@0
   662
}
insilmaril@0
   663
insilmaril@0
   664
insilmaril@0
   665
void TextEditor::textPrint()
insilmaril@0
   666
{
insilmaril@0
   667
insilmaril@366
   668
    QTextDocument *document = e->document();
insilmaril@366
   669
    QPrinter printer;
insilmaril@366
   670
insilmaril@366
   671
    QPrintDialog *dialog = new QPrintDialog(&printer, this);
insilmaril@395
   672
    dialog->setWindowTitle(tr("Print Note"));
insilmaril@366
   673
    if (dialog->exec() != QDialog::Accepted)
insilmaril@366
   674
        return;
insilmaril@366
   675
insilmaril@366
   676
    document->print(&printer);
insilmaril@0
   677
}
insilmaril@0
   678
insilmaril@0
   679
void TextEditor::textEditUndo()
insilmaril@0
   680
{
insilmaril@0
   681
}
insilmaril@0
   682
insilmaril@0
   683
void TextEditor::toggleFonthint()
insilmaril@0
   684
{
insilmaril@0
   685
	setUpdatesEnabled (false);
insilmaril@366
   686
	e->selectAll ();
insilmaril@0
   687
	if (!actionFormatUseFixedFont->isOn() ) 
insilmaril@0
   688
		e->setCurrentFont (varFont);
insilmaril@0
   689
	else	
insilmaril@0
   690
		e->setCurrentFont (fixedFont);
insilmaril@366
   691
	e->selectAll ();
insilmaril@0
   692
	setUpdatesEnabled (true);
insilmaril@0
   693
	repaint();
insilmaril@0
   694
}
insilmaril@0
   695
insilmaril@0
   696
void TextEditor::setFixedFont()
insilmaril@0
   697
{
insilmaril@0
   698
	bool ok;
insilmaril@0
   699
	QFont font =QFontDialog::getFont(
insilmaril@0
   700
                    &ok, fixedFont, this );
insilmaril@0
   701
    if ( ok ) 
insilmaril@0
   702
        // font is set to the font the user selected
insilmaril@0
   703
		fixedFont=font;
insilmaril@0
   704
}
insilmaril@0
   705
insilmaril@0
   706
void TextEditor::setVarFont()
insilmaril@0
   707
{
insilmaril@0
   708
	bool ok;
insilmaril@0
   709
	QFont font =QFontDialog::getFont(
insilmaril@0
   710
                    &ok, varFont, this );
insilmaril@0
   711
    if ( ok ) 
insilmaril@0
   712
        // font is set to the font the user selected
insilmaril@0
   713
		varFont=font;
insilmaril@0
   714
}
insilmaril@0
   715
insilmaril@0
   716
void TextEditor::textBold()
insilmaril@0
   717
{
insilmaril@0
   718
    e->setBold( actionTextBold->isOn() );
insilmaril@0
   719
}
insilmaril@0
   720
insilmaril@0
   721
void TextEditor::textUnderline()
insilmaril@0
   722
{
insilmaril@0
   723
    e->setUnderline( actionTextUnderline->isOn() );
insilmaril@0
   724
}
insilmaril@0
   725
insilmaril@0
   726
void TextEditor::textItalic()
insilmaril@0
   727
{
insilmaril@0
   728
    e->setItalic( actionTextItalic->isOn() );
insilmaril@0
   729
}
insilmaril@0
   730
insilmaril@0
   731
void TextEditor::textFamily( const QString &f )
insilmaril@0
   732
{
insilmaril@0
   733
    e->setFamily( f );
insilmaril@0
   734
}
insilmaril@0
   735
insilmaril@0
   736
void TextEditor::textSize( const QString &p )
insilmaril@0
   737
{
insilmaril@0
   738
    e->setPointSize( p.toInt() );
insilmaril@0
   739
}
insilmaril@0
   740
insilmaril@0
   741
insilmaril@0
   742
void TextEditor::textColor()
insilmaril@0
   743
{
insilmaril@0
   744
    QColor col = QColorDialog::getColor( e->color(), this );
insilmaril@388
   745
    if ( !col.isValid() ) return;
insilmaril@0
   746
    e->setColor( col );
insilmaril@0
   747
    QPixmap pix( 16, 16 );
insilmaril@366
   748
    pix.fill( Qt::black );
insilmaril@0
   749
    actionTextColor->setIconSet( pix );
insilmaril@0
   750
}
insilmaril@0
   751
insilmaril@0
   752
void TextEditor::textAlign( QAction *a )
insilmaril@0
   753
{
insilmaril@0
   754
    if ( a == actionAlignLeft )
insilmaril@388
   755
		e->setAlignment( Qt::AlignLeft );
insilmaril@0
   756
    else if ( a == actionAlignCenter )
insilmaril@388
   757
		e->setAlignment( Qt::AlignHCenter );
insilmaril@0
   758
    else if ( a == actionAlignRight )
insilmaril@388
   759
		e->setAlignment( Qt::AlignRight );
insilmaril@0
   760
    else if ( a == actionAlignJustify )
insilmaril@388
   761
		e->setAlignment( Qt::AlignJustify );
insilmaril@0
   762
}
insilmaril@0
   763
jhilmer@142
   764
void TextEditor::textVAlign()
jhilmer@142
   765
{
insilmaril@388
   766
	QTextCharFormat format;
insilmaril@388
   767
jhilmer@142
   768
    if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
insilmaril@388
   769
		format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
jhilmer@142
   770
    } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
insilmaril@388
   771
		format.setVerticalAlignment(QTextCharFormat::AlignSubScript);
jhilmer@142
   772
    } else {
insilmaril@388
   773
		format.setVerticalAlignment(QTextCharFormat::AlignNormal);
jhilmer@142
   774
    }
insilmaril@388
   775
	e->mergeCurrentCharFormat(format);
jhilmer@142
   776
}
jhilmer@142
   777
jhilmer@142
   778
insilmaril@0
   779
void TextEditor::fontChanged( const QFont &f )
insilmaril@0
   780
{
insilmaril@388
   781
	int i=comboFont->findText(f.family());
insilmaril@388
   782
    if (i>=0) comboFont->setCurrentIndex (i);
insilmaril@388
   783
	i=comboSize->findText(QString::number(f.pointSize()));
insilmaril@388
   784
	if (i>=0) comboSize->setCurrentIndex(i);
insilmaril@0
   785
    actionTextBold->setOn( f.bold() );
insilmaril@0
   786
    actionTextItalic->setOn( f.italic() );
insilmaril@0
   787
    actionTextUnderline->setOn( f.underline() );
insilmaril@0
   788
}
insilmaril@0
   789
insilmaril@0
   790
void TextEditor::colorChanged( const QColor &c )
insilmaril@0
   791
{
insilmaril@0
   792
    QPixmap pix( 16, 16 );
insilmaril@0
   793
    pix.fill( c );
insilmaril@0
   794
    actionTextColor->setIconSet( pix );
insilmaril@0
   795
}
insilmaril@0
   796
insilmaril@388
   797
void TextEditor::formatChanged( const QTextCharFormat &f )
insilmaril@388
   798
{
insilmaril@388
   799
	fontChanged(f.font());
insilmaril@388
   800
    colorChanged(f.foreground().color());
insilmaril@388
   801
    alignmentChanged(e->alignment());
insilmaril@388
   802
	verticalAlignmentChanged (f.verticalAlignment());
insilmaril@388
   803
}
insilmaril@388
   804
insilmaril@0
   805
void TextEditor::alignmentChanged( int a )
insilmaril@0
   806
{
insilmaril@366
   807
    if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
insilmaril@388
   808
		actionAlignLeft->setOn( true );
insilmaril@366
   809
    else if ( ( a & Qt::AlignHCenter ) )
insilmaril@388
   810
		actionAlignCenter->setOn( true );
insilmaril@366
   811
    else if ( ( a & Qt::AlignRight ) )
insilmaril@388
   812
		actionAlignRight->setOn( true );
insilmaril@366
   813
    else if ( ( a & Qt::AlignJustify ) )
insilmaril@388
   814
		actionAlignJustify->setOn( true );
insilmaril@0
   815
}
insilmaril@0
   816
insilmaril@388
   817
void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a)
jhilmer@142
   818
{
insilmaril@388
   819
	actionAlignSubScript->setOn (false);
insilmaril@388
   820
	actionAlignSuperScript->setOn (false);
insilmaril@388
   821
	switch (a)
insilmaril@388
   822
	{
insilmaril@388
   823
		case QTextCharFormat::AlignSuperScript: 
insilmaril@388
   824
			actionAlignSuperScript->setOn (true);
insilmaril@388
   825
			break;
insilmaril@388
   826
		case QTextCharFormat::AlignSubScript:
insilmaril@388
   827
			actionAlignSubScript->setOn (true);
insilmaril@388
   828
			break;
insilmaril@388
   829
		default: ;	
insilmaril@388
   830
	}
jhilmer@142
   831
}
jhilmer@142
   832
insilmaril@0
   833
insilmaril@0
   834
insilmaril@0
   835
void TextEditor::enableActions()
insilmaril@0
   836
{
insilmaril@0
   837
	actionFileLoad->setEnabled(true);
insilmaril@0
   838
	actionFileSave->setEnabled(true);
insilmaril@0
   839
	actionFileSaveAs->setEnabled(true);
insilmaril@0
   840
	actionFilePrint->setEnabled(true);
insilmaril@0
   841
	actionEditUndo->setEnabled(true);
insilmaril@0
   842
	actionEditRedo->setEnabled(true);
insilmaril@0
   843
	actionEditCopy->setEnabled(true);
insilmaril@0
   844
	actionEditCut->setEnabled(true);
insilmaril@0
   845
	actionEditPaste->setEnabled(true);
insilmaril@0
   846
	actionEditDeleteAll->setEnabled(true);
insilmaril@0
   847
	actionFormatUseFixedFont->setEnabled(true);
insilmaril@0
   848
}
insilmaril@0
   849
insilmaril@0
   850
void TextEditor::disableActions()
insilmaril@0
   851
{
insilmaril@0
   852
	actionFileLoad->setEnabled(false);
insilmaril@0
   853
	actionFileSave->setEnabled(false);
insilmaril@0
   854
	actionFileSaveAs->setEnabled(false);
insilmaril@0
   855
	actionFilePrint->setEnabled(false);
insilmaril@0
   856
	actionEditUndo->setEnabled(false);
insilmaril@0
   857
	actionEditRedo->setEnabled(false);
insilmaril@0
   858
	actionEditCopy->setEnabled(false);
insilmaril@0
   859
	actionEditCut->setEnabled(false);
insilmaril@0
   860
	actionEditPaste->setEnabled(false);
insilmaril@0
   861
	actionEditDeleteAll->setEnabled(false);
insilmaril@0
   862
	actionFormatUseFixedFont->setEnabled(false);
insilmaril@0
   863
}
insilmaril@0
   864
insilmaril@366
   865
void TextEditor::setState (EditorState s)
insilmaril@366
   866
{
insilmaril@366
   867
	
insilmaril@366
   868
	QPalette p=palette();
insilmaril@366
   869
	QColor c;
insilmaril@366
   870
	switch (s)
insilmaril@366
   871
	{
insilmaril@366
   872
		case emptyEditor:    c=QColor (150,150,150); break;
insilmaril@366
   873
		case filledEditor:   c=QColor (255,255,255); break;
insilmaril@366
   874
		case inactiveEditor: c=QColor (0,0,0);
insilmaril@366
   875
	}
insilmaril@366
   876
    p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
insilmaril@366
   877
    p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
insilmaril@366
   878
    e->setPalette(p);
insilmaril@366
   879
}
insilmaril@0
   880
insilmaril@366
   881