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