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