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