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