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