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