texteditor.cpp
author insilmaril
Wed, 09 Jun 2010 13:14:08 +0000
changeset 847 43268373032d
parent 842 bec082472471
permissions -rw-r--r--
1.13.4 Various fixes
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@842
   235
bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
insilmaril@0
   236
{
insilmaril@366
   237
	if (e->find (t,flags))
insilmaril@842
   238
		return true;
insilmaril@842
   239
	else	
insilmaril@842
   240
		return false;
insilmaril@842
   241
}
insilmaril@842
   242
insilmaril@842
   243
bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags, int i)
insilmaril@842
   244
{
insilmaril@842
   245
	// Position at beginning
insilmaril@842
   246
	QTextCursor c=e->textCursor();
insilmaril@842
   247
	c.setPosition (0,QTextCursor::MoveAnchor);
insilmaril@842
   248
	e->setTextCursor (c);
insilmaril@842
   249
insilmaril@842
   250
	// Search for t
insilmaril@842
   251
	int j=0;
insilmaril@842
   252
	while (j<=i)
insilmaril@829
   253
	{
insilmaril@842
   254
		if (!e->find (t,flags)) return false;
insilmaril@842
   255
		j++;
insilmaril@829
   256
	}
insilmaril@842
   257
	return true;
insilmaril@842
   258
insilmaril@842
   259
}
insilmaril@842
   260
insilmaril@842
   261
void TextEditor::setTextCursor (const QTextCursor &cursor)
insilmaril@842
   262
{
insilmaril@842
   263
	e->setTextCursor (cursor);
insilmaril@842
   264
}
insilmaril@842
   265
insilmaril@842
   266
QTextCursor TextEditor::getTextCursor()
insilmaril@842
   267
{
insilmaril@842
   268
	return e->textCursor();
insilmaril@0
   269
}
insilmaril@0
   270
insilmaril@0
   271
void TextEditor::setupFileActions()
insilmaril@0
   272
{
insilmaril@366
   273
    QToolBar *tb = addToolBar ( tr("Note Actions") );
insilmaril@389
   274
	tb->setObjectName ("noteEditorFileActions");
insilmaril@395
   275
    QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" ));
insilmaril@0
   276
insilmaril@0
   277
    QAction *a;
insilmaril@366
   278
    a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
insilmaril@395
   279
	a->setStatusTip (tr( "Import","Status tip for Note menu" ) );
insilmaril@366
   280
	a->setShortcut( Qt::CTRL + Qt::Key_O );
insilmaril@0
   281
    connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
insilmaril@366
   282
	tb->addAction (a);
insilmaril@366
   283
	fileMenu->addAction (a);
insilmaril@0
   284
	actionFileLoad=a;
insilmaril@0
   285
insilmaril@366
   286
    fileMenu->addSeparator();
insilmaril@366
   287
    a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
insilmaril@395
   288
	a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) );
insilmaril@366
   289
	a->setShortcut( Qt::CTRL + Qt::Key_S );
insilmaril@0
   290
    connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
insilmaril@366
   291
	tb->addAction (a);
insilmaril@366
   292
	fileMenu->addAction (a);
insilmaril@0
   293
	actionFileSave=a;
insilmaril@0
   294
	
insilmaril@366
   295
    a = new QAction(  QPixmap(), tr( "Export &As... (HTML)" ), this);
insilmaril@395
   296
	a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu"  ));
insilmaril@0
   297
    connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
insilmaril@366
   298
	fileMenu->addAction (a);
insilmaril@0
   299
	actionFileSaveAs=a;
insilmaril@0
   300
insilmaril@366
   301
    a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
insilmaril@395
   302
	a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) );
insilmaril@366
   303
	a->setShortcut(Qt::ALT + Qt::Key_X );
insilmaril@0
   304
    connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
insilmaril@366
   305
	fileMenu->addAction (a);
insilmaril@0
   306
	actionFileSaveAs=a;
insilmaril@0
   307
insilmaril@366
   308
    fileMenu->addSeparator();
insilmaril@366
   309
    a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
insilmaril@395
   310
	a->setStatusTip (tr( "Print Note","Status tip for note menu" ) );
insilmaril@366
   311
	a->setShortcut( Qt::CTRL + Qt::Key_P );
insilmaril@0
   312
    connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
insilmaril@366
   313
	tb->addAction (a);
insilmaril@366
   314
	fileMenu->addAction (a);
insilmaril@0
   315
	actionFilePrint=a;
insilmaril@0
   316
}
insilmaril@0
   317
insilmaril@0
   318
void TextEditor::setupEditActions()
insilmaril@0
   319
{
insilmaril@366
   320
    QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
insilmaril@389
   321
	tb->setObjectName ("noteEditorEditActions");
insilmaril@366
   322
    QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
insilmaril@0
   323
insilmaril@0
   324
    QAction *a;
insilmaril@366
   325
    a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
insilmaril@395
   326
	a->setStatusTip ( tr( "Undo","Status tip for note menu" ) );
insilmaril@366
   327
	a->setShortcut(Qt::CTRL + Qt::Key_Z );
insilmaril@0
   328
    connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
insilmaril@366
   329
	editMenu->addAction (a);
insilmaril@366
   330
	tb->addAction (a);
insilmaril@0
   331
	actionEditUndo=a;
insilmaril@0
   332
	
insilmaril@366
   333
    a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this); 
insilmaril@395
   334
	a->setStatusTip ( tr( "Redo","Status tip for note menu" ) );
insilmaril@366
   335
	a->setShortcut( Qt::CTRL + Qt::Key_Y );
insilmaril@0
   336
    connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
insilmaril@366
   337
	editMenu->addAction (a);
insilmaril@366
   338
	tb->addAction (a);
insilmaril@0
   339
	actionEditRedo=a;
insilmaril@0
   340
insilmaril@366
   341
    editMenu->addSeparator();
insilmaril@366
   342
    a = new QAction(QPixmap(), tr( "Select and copy &all" ),this); 
insilmaril@395
   343
	a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) );
insilmaril@366
   344
	a->setShortcut( Qt::CTRL + Qt::Key_A );
insilmaril@0
   345
    connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
insilmaril@366
   346
	editMenu->addAction (a);
insilmaril@0
   347
insilmaril@366
   348
    editMenu->addSeparator();
insilmaril@366
   349
    a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
insilmaril@395
   350
	a->setStatusTip ( tr( "Copy","Status tip for note menu" ) );
insilmaril@366
   351
	a->setShortcut( Qt::CTRL + Qt::Key_C );
insilmaril@0
   352
    connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
insilmaril@366
   353
	editMenu->addAction (a);
insilmaril@366
   354
	tb->addAction (a);
insilmaril@0
   355
	actionEditCopy=a;
insilmaril@0
   356
	
insilmaril@366
   357
    a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
insilmaril@395
   358
	a->setStatusTip ( tr( "Cut","Status tip for note menu" ) );
insilmaril@366
   359
	a->setShortcut( Qt::CTRL + Qt::Key_X );
insilmaril@0
   360
    connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
insilmaril@366
   361
	editMenu->addAction (a);
insilmaril@366
   362
	tb->addAction (a);
insilmaril@0
   363
	actionEditCut=a;
insilmaril@0
   364
insilmaril@366
   365
    a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
insilmaril@395
   366
	a->setStatusTip ( tr( "Paste","Status tip for note menu" ) );
insilmaril@366
   367
	a->setShortcut( Qt::CTRL + Qt::Key_V );
insilmaril@0
   368
    connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
insilmaril@366
   369
	editMenu->addAction (a);
insilmaril@366
   370
	tb->addAction (a);
insilmaril@0
   371
	actionEditPaste=a;
insilmaril@0
   372
	
insilmaril@366
   373
    a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
insilmaril@395
   374
	a->setStatusTip (tr( "Delete all","Status tip for note menu" ) );
insilmaril@0
   375
    connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
insilmaril@366
   376
	editMenu->addAction (a);
insilmaril@366
   377
	tb->addAction (a);
insilmaril@0
   378
	actionEditDeleteAll=a;
insilmaril@0
   379
insilmaril@0
   380
}
insilmaril@0
   381
insilmaril@0
   382
void TextEditor::setupFormatActions()
insilmaril@0
   383
{
insilmaril@366
   384
    QToolBar *tb = addToolBar ( tr("Format Actions" ));
insilmaril@389
   385
	tb->setObjectName ("noteEditorFormatActions");
insilmaril@366
   386
    QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
insilmaril@0
   387
insilmaril@0
   388
    QAction *a;
insilmaril@0
   389
insilmaril@366
   390
    a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
insilmaril@395
   391
	a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) );
insilmaril@0
   392
	a->setToggleAction (true);
insilmaril@366
   393
	a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
insilmaril@0
   394
    connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
insilmaril@366
   395
	formatMenu->addAction (a);
insilmaril@366
   396
	tb->addAction (a);
insilmaril@0
   397
	actionFormatUseFixedFont=a;
insilmaril@0
   398
insilmaril@366
   399
    comboFont = new QComboBox;
insilmaril@366
   400
	tb->addWidget (comboFont);
insilmaril@366
   401
    QFontDatabase fontDB;
insilmaril@366
   402
    comboFont->insertStringList( fontDB.families() );
insilmaril@0
   403
    connect( comboFont, SIGNAL( activated( const QString & ) ),
insilmaril@0
   404
	     this, SLOT( textFamily( const QString & ) ) );
insilmaril@366
   405
    comboFont->addItem( QApplication::font().family() );
insilmaril@366
   406
    comboSize = new QComboBox;
insilmaril@366
   407
	tb->addWidget (comboSize);
insilmaril@366
   408
	QList<int> sizes=fontDB.standardSizes();
insilmaril@366
   409
	QList<int>::iterator i = sizes.begin();
insilmaril@366
   410
	while (i != sizes.end()) 
insilmaril@366
   411
	{
insilmaril@366
   412
		++i; // increment i before using it
insilmaril@366
   413
		comboSize->insertItem ( QString::number(*i));
insilmaril@366
   414
	}	
insilmaril@0
   415
    connect( comboSize, SIGNAL( activated( const QString & ) ),
insilmaril@0
   416
	     this, SLOT( textSize( const QString & ) ) );
insilmaril@366
   417
    comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
insilmaril@0
   418
insilmaril@366
   419
    formatMenu->addSeparator();
insilmaril@0
   420
insilmaril@0
   421
    QPixmap pix( 16, 16 );
insilmaril@0
   422
    pix.fill( e->color());
insilmaril@366
   423
    a = new QAction( pix, tr( "&Color..." ), this);
insilmaril@366
   424
	formatMenu->addAction (a);
insilmaril@366
   425
	tb->addAction (a);
insilmaril@366
   426
    connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
insilmaril@366
   427
    actionTextColor=a;
insilmaril@0
   428
insilmaril@366
   429
    a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
insilmaril@366
   430
	a->setShortcut(Qt::CTRL + Qt::Key_B );
insilmaril@366
   431
    connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
insilmaril@366
   432
	tb->addAction (a);
insilmaril@366
   433
	formatMenu->addAction (a);
insilmaril@366
   434
    a->setToggleAction( true );
insilmaril@366
   435
    actionTextBold=a;
insilmaril@366
   436
	
insilmaril@366
   437
    a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ),  this);
insilmaril@366
   438
	a->setShortcut(Qt::CTRL + Qt::Key_I);
insilmaril@366
   439
    connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
insilmaril@366
   440
	tb->addAction (a);
insilmaril@366
   441
	formatMenu->addAction (a);
insilmaril@366
   442
    a->setToggleAction( true );
insilmaril@366
   443
    actionTextItalic=a;
insilmaril@366
   444
	
insilmaril@366
   445
    a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
insilmaril@366
   446
	a->setShortcut(Qt::CTRL + Qt::Key_U );
insilmaril@366
   447
    connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
insilmaril@366
   448
	tb->addAction (a);
insilmaril@366
   449
	formatMenu->addAction (a);
insilmaril@366
   450
    a->setToggleAction( true );
insilmaril@366
   451
    actionTextUnderline=a;
insilmaril@366
   452
    formatMenu->addSeparator();
insilmaril@0
   453
insilmaril@388
   454
    QActionGroup *grp2 = new QActionGroup( this );
insilmaril@388
   455
    grp2->setExclusive(true);
insilmaril@388
   456
    a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
insilmaril@388
   457
	a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
insilmaril@388
   458
    a->setToggleAction( true );
insilmaril@388
   459
	tb->addAction (a);
insilmaril@388
   460
	formatMenu->addAction (a);
insilmaril@388
   461
    connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
insilmaril@388
   462
    actionAlignSubScript=a;
insilmaril@388
   463
insilmaril@388
   464
    a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2  );
insilmaril@388
   465
	a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
insilmaril@388
   466
    a->setToggleAction( true );
insilmaril@388
   467
	tb->addAction (a);
insilmaril@388
   468
	formatMenu->addAction (a);
insilmaril@388
   469
    connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
insilmaril@388
   470
    actionAlignSuperScript=a;
insilmaril@0
   471
    QActionGroup *grp = new QActionGroup( this );
insilmaril@0
   472
    connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
insilmaril@0
   473
insilmaril@388
   474
    formatMenu->addSeparator();
insilmaril@388
   475
insilmaril@366
   476
    a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
insilmaril@366
   477
	a->setShortcut( Qt::CTRL+Qt::Key_L );
insilmaril@366
   478
    a->setToggleAction( true );
insilmaril@366
   479
	tb->addAction (a);
insilmaril@366
   480
	formatMenu->addAction (a);
insilmaril@366
   481
    actionAlignLeft=a;
insilmaril@366
   482
    a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
insilmaril@366
   483
    a->setShortcut(  Qt::CTRL + Qt::Key_E);
insilmaril@366
   484
    a->setToggleAction( true );
insilmaril@366
   485
	tb->addAction (a);
insilmaril@366
   486
	formatMenu->addAction (a);
insilmaril@366
   487
    actionAlignCenter=a;
insilmaril@366
   488
    a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
insilmaril@366
   489
	a->setShortcut(Qt::CTRL + Qt::Key_R );
insilmaril@366
   490
    a->setToggleAction( true );
insilmaril@366
   491
	tb->addAction (a);
insilmaril@366
   492
	formatMenu->addAction (a);
insilmaril@366
   493
    actionAlignRight=a;
insilmaril@366
   494
    a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
insilmaril@366
   495
	a->setShortcut(Qt::CTRL + Qt::Key_J );
insilmaril@366
   496
    a->setToggleAction( true );
insilmaril@366
   497
	tb->addAction (a);
insilmaril@366
   498
	formatMenu->addAction (a);
insilmaril@366
   499
    actionAlignJustify=a;
insilmaril@0
   500
}
insilmaril@0
   501
insilmaril@0
   502
void TextEditor::setupSettingsActions()
insilmaril@0
   503
{
insilmaril@366
   504
    QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
insilmaril@0
   505
insilmaril@0
   506
    QAction *a;
insilmaril@366
   507
    a = new QAction(tr( "Set &fixed font" ), this);
insilmaril@395
   508
	a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" ));
insilmaril@0
   509
    connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
insilmaril@366
   510
	settingsMenu->addAction (a);
insilmaril@0
   511
	actionSettingsFixedFont=a;
insilmaril@0
   512
insilmaril@366
   513
    a = new QAction(tr( "Set &variable font" ), this);
insilmaril@395
   514
	a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) );
insilmaril@0
   515
    connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
insilmaril@366
   516
	settingsMenu->addAction (a);
insilmaril@0
   517
	actionSettingsVarFont=a;
insilmaril@0
   518
insilmaril@366
   519
    a = new QAction(tr( "&fixed font is default" ),  this);
insilmaril@395
   520
	a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) );
insilmaril@0
   521
	a->setToggleAction (true);
insilmaril@0
   522
	// set state later in constructor...
insilmaril@366
   523
	settingsMenu->addAction (a);
insilmaril@0
   524
	actionSettingsFonthintDefault=a;
insilmaril@0
   525
}
insilmaril@0
   526
insilmaril@0
   527
void TextEditor::textLoad()
insilmaril@0
   528
{
insilmaril@0
   529
	if (state!=inactiveEditor)
insilmaril@0
   530
	{
insilmaril@664
   531
		if (!isEmpty()) 
insilmaril@0
   532
		{
insilmaril@404
   533
			QMessageBox mb( vymName + " - " +tr("Note Editor"),
insilmaril@0
   534
				"Loading will overwrite the existing note",
insilmaril@0
   535
				QMessageBox::Warning,
insilmaril@0
   536
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   537
				QMessageBox::Cancel,
insilmaril@0
   538
				0 );
insilmaril@0
   539
			mb.setButtonText( QMessageBox::Yes, "Load note" );
insilmaril@0
   540
			switch( mb.exec() ) {
insilmaril@0
   541
				case QMessageBox::Cancel:
insilmaril@0
   542
					return;
insilmaril@0
   543
					break;
insilmaril@0
   544
			}
insilmaril@0
   545
		} 
insilmaril@0
   546
		// Load note
insilmaril@0
   547
		QFileDialog *fd=new QFileDialog( this);
insilmaril@366
   548
		QStringList types;
insilmaril@823
   549
		types<< "Text (*.txt *.html)"<<
insilmaril@823
   550
			"VYM notes and HTML (*.html)" <<
insilmaril@366
   551
			"ASCII texts (*.txt)" <<
insilmaril@366
   552
			"All filed (*)";
insilmaril@366
   553
		fd->setFilters (types);
insilmaril@366
   554
		fd->setDirectory (QDir().current());
insilmaril@0
   555
		fd->show();
insilmaril@0
   556
		QString fn;
insilmaril@0
   557
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
   558
			fn = fd->selectedFile();
insilmaril@0
   559
insilmaril@0
   560
		if ( !fn.isEmpty() )
insilmaril@0
   561
		{
insilmaril@0
   562
			QFile f( fn );
insilmaril@366
   563
			if ( !f.open( QIODevice::ReadOnly ) )
insilmaril@0
   564
			return;
insilmaril@0
   565
insilmaril@0
   566
			QTextStream ts( &f );
insilmaril@0
   567
			setText( ts.read() );
insilmaril@0
   568
			editorChanged();
insilmaril@0
   569
		}
insilmaril@0
   570
	}
insilmaril@0
   571
}
insilmaril@0
   572
insilmaril@0
   573
void TextEditor::closeEvent( QCloseEvent* ce )
insilmaril@0
   574
{
jhilmer@144
   575
    ce->accept();	// TextEditor can be reopened with show()
insilmaril@497
   576
	showwithmain=false;
insilmaril@486
   577
	hide();
insilmaril@442
   578
	emit (windowClosed() );
jhilmer@144
   579
    return;
insilmaril@0
   580
}
insilmaril@0
   581
insilmaril@0
   582
void TextEditor::editorChanged()
insilmaril@0
   583
{
insilmaril@0
   584
	if (isEmpty())
insilmaril@0
   585
		state=emptyEditor;
insilmaril@0
   586
	else
insilmaril@0
   587
		state=filledEditor;
insilmaril@0
   588
insilmaril@0
   589
		if (state==emptyEditor)
insilmaril@366
   590
			setState (emptyEditor);
insilmaril@0
   591
		else
insilmaril@366
   592
			setState (filledEditor);
insilmaril@0
   593
	// SLOT is LinkableMapObj, which will update systemFlag
insilmaril@427
   594
	if (!blockChangedSignal) emit (textHasChanged() );
insilmaril@0
   595
}
insilmaril@0
   596
insilmaril@0
   597
insilmaril@746
   598
void TextEditor::setText(const QString &t)
insilmaril@0
   599
{
insilmaril@427
   600
	blockChangedSignal=true;
insilmaril@0
   601
	e->setReadOnly(false);
insilmaril@804
   602
	reset();
insilmaril@804
   603
	if (Qt::mightBeRichText (t))
insilmaril@804
   604
		e->setHtml(t);
insilmaril@804
   605
	else
insilmaril@804
   606
	{
insilmaril@804
   607
		actionFormatUseFixedFont->setChecked (true);
insilmaril@804
   608
		e->setPlainText(t);
insilmaril@804
   609
	}	
insilmaril@0
   610
	enableActions();
insilmaril@427
   611
	blockChangedSignal=false;
insilmaril@0
   612
}
insilmaril@0
   613
insilmaril@0
   614
void TextEditor::setInactive()
insilmaril@0
   615
{
jhilmer@135
   616
	state=inactiveEditor;
insilmaril@0
   617
	setText("");
insilmaril@366
   618
	setState (inactiveEditor);
insilmaril@0
   619
	e->setReadOnly (true);
insilmaril@0
   620
insilmaril@0
   621
	disableActions();
insilmaril@0
   622
}
insilmaril@0
   623
insilmaril@0
   624
void TextEditor::editCopyAll()
insilmaril@0
   625
{
insilmaril@0
   626
	e->selectAll();
insilmaril@0
   627
	e->copy();
insilmaril@0
   628
}
insilmaril@0
   629
insilmaril@0
   630
void TextEditor::textSaveAs()
insilmaril@0
   631
{
insilmaril@0
   632
    QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
insilmaril@0
   633
					       this,"export note dialog",tr("Export Note to single file") );
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
			switch( mb.exec() ) {
insilmaril@0
   649
				case QMessageBox::Yes:
insilmaril@0
   650
					// save 
insilmaril@0
   651
					filename = fn;
insilmaril@0
   652
					textSave();
insilmaril@0
   653
					return;
insilmaril@0
   654
				case QMessageBox::Cancel:
insilmaril@0
   655
					// do nothing
insilmaril@0
   656
					break;
insilmaril@0
   657
			}
insilmaril@0
   658
		} else
insilmaril@0
   659
		{
insilmaril@0
   660
			filename = fn;
insilmaril@0
   661
			textSave();
insilmaril@0
   662
			return;
insilmaril@0
   663
		}			
insilmaril@0
   664
    }
insilmaril@395
   665
	statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime );
insilmaril@0
   666
}
insilmaril@0
   667
insilmaril@0
   668
insilmaril@0
   669
void TextEditor::textSave()
insilmaril@0
   670
{
insilmaril@0
   671
    if ( filename.isEmpty() ) 
insilmaril@0
   672
	{
insilmaril@0
   673
		textSaveAs();
insilmaril@0
   674
		return;
insilmaril@0
   675
    }
insilmaril@0
   676
insilmaril@0
   677
    QString text = e->text();
insilmaril@0
   678
    QFile f( filename );
insilmaril@366
   679
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@0
   680
	{
insilmaril@0
   681
		statusBar()->message( QString("Could not write to %1").arg(filename),
insilmaril@0
   682
					  statusbarTime );
insilmaril@0
   683
		return;
insilmaril@0
   684
    }
insilmaril@0
   685
insilmaril@0
   686
    QTextStream t( &f );
insilmaril@0
   687
    t << text;
insilmaril@0
   688
    f.close();
insilmaril@0
   689
insilmaril@0
   690
    e->setModified( FALSE );
insilmaril@0
   691
insilmaril@0
   692
    statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
insilmaril@0
   693
}
insilmaril@0
   694
insilmaril@0
   695
void TextEditor::textExportAsASCII()
insilmaril@0
   696
{
insilmaril@189
   697
	QString text = NoteObj (e->text()).getNoteASCII();
insilmaril@106
   698
	QString fn,s;
insilmaril@106
   699
	if (!filenameHint.isEmpty())
insilmaril@106
   700
	{
insilmaril@106
   701
		if (!filenameHint.contains (".txt"))
insilmaril@106
   702
			s=filenameHint+".txt";
insilmaril@106
   703
		else	
insilmaril@106
   704
			s=filenameHint;
insilmaril@106
   705
	} else	
insilmaril@106
   706
		s=QString::null;
insilmaril@106
   707
	fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
insilmaril@0
   708
	int ret=-1;
insilmaril@0
   709
insilmaril@0
   710
    if ( !fn.isEmpty() ) 
insilmaril@0
   711
	{
insilmaril@0
   712
		QFile file (fn);
insilmaril@0
   713
		if (file.exists())
insilmaril@0
   714
		{
insilmaril@404
   715
			QMessageBox mb( vymName,
insilmaril@395
   716
				tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
insilmaril@0
   717
			QMessageBox::Warning,
insilmaril@0
   718
			QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   719
			QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
   720
			Qt::NoButton );
insilmaril@0
   721
			mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
   722
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
   723
			ret=mb.exec();
insilmaril@0
   724
		}	
insilmaril@0
   725
		if (ret==QMessageBox::Cancel)
insilmaril@0
   726
			return;
insilmaril@0
   727
			
insilmaril@0
   728
		// save 
insilmaril@366
   729
		if ( !file.open( QIODevice::WriteOnly ) ) 
insilmaril@0
   730
			statusBar()->message( QString("Could not write to %1").arg(filename),
insilmaril@0
   731
						  statusbarTime );
insilmaril@0
   732
		else
insilmaril@0
   733
		{
insilmaril@0
   734
			QTextStream t( &file );
insilmaril@0
   735
			t << text;
insilmaril@0
   736
			file.close();
insilmaril@0
   737
insilmaril@0
   738
			statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
insilmaril@0
   739
		}
insilmaril@0
   740
    }
insilmaril@0
   741
}
insilmaril@0
   742
insilmaril@0
   743
insilmaril@0
   744
void TextEditor::textPrint()
insilmaril@0
   745
{
insilmaril@0
   746
insilmaril@366
   747
    QTextDocument *document = e->document();
insilmaril@366
   748
    QPrinter printer;
insilmaril@366
   749
insilmaril@366
   750
    QPrintDialog *dialog = new QPrintDialog(&printer, this);
insilmaril@395
   751
    dialog->setWindowTitle(tr("Print Note"));
insilmaril@366
   752
    if (dialog->exec() != QDialog::Accepted)
insilmaril@366
   753
        return;
insilmaril@366
   754
insilmaril@366
   755
    document->print(&printer);
insilmaril@0
   756
}
insilmaril@0
   757
insilmaril@0
   758
void TextEditor::textEditUndo()
insilmaril@0
   759
{
insilmaril@0
   760
}
insilmaril@0
   761
insilmaril@0
   762
void TextEditor::toggleFonthint()
insilmaril@0
   763
{
insilmaril@0
   764
	setUpdatesEnabled (false);
insilmaril@366
   765
	e->selectAll ();
insilmaril@0
   766
	if (!actionFormatUseFixedFont->isOn() ) 
insilmaril@0
   767
		e->setCurrentFont (varFont);
insilmaril@0
   768
	else	
insilmaril@0
   769
		e->setCurrentFont (fixedFont);
insilmaril@366
   770
	e->selectAll ();
insilmaril@0
   771
	setUpdatesEnabled (true);
insilmaril@0
   772
	repaint();
insilmaril@0
   773
}
insilmaril@0
   774
insilmaril@0
   775
void TextEditor::setFixedFont()
insilmaril@0
   776
{
insilmaril@0
   777
	bool ok;
insilmaril@0
   778
	QFont font =QFontDialog::getFont(
insilmaril@0
   779
                    &ok, fixedFont, this );
insilmaril@0
   780
    if ( ok ) 
insilmaril@0
   781
        // font is set to the font the user selected
insilmaril@0
   782
		fixedFont=font;
insilmaril@0
   783
}
insilmaril@0
   784
insilmaril@0
   785
void TextEditor::setVarFont()
insilmaril@0
   786
{
insilmaril@0
   787
	bool ok;
insilmaril@0
   788
	QFont font =QFontDialog::getFont(
insilmaril@0
   789
                    &ok, varFont, this );
insilmaril@0
   790
    if ( ok ) 
insilmaril@0
   791
        // font is set to the font the user selected
insilmaril@0
   792
		varFont=font;
insilmaril@0
   793
}
insilmaril@0
   794
insilmaril@0
   795
void TextEditor::textBold()
insilmaril@0
   796
{
insilmaril@0
   797
    e->setBold( actionTextBold->isOn() );
insilmaril@0
   798
}
insilmaril@0
   799
insilmaril@0
   800
void TextEditor::textUnderline()
insilmaril@0
   801
{
insilmaril@0
   802
    e->setUnderline( actionTextUnderline->isOn() );
insilmaril@0
   803
}
insilmaril@0
   804
insilmaril@0
   805
void TextEditor::textItalic()
insilmaril@0
   806
{
insilmaril@0
   807
    e->setItalic( actionTextItalic->isOn() );
insilmaril@0
   808
}
insilmaril@0
   809
insilmaril@0
   810
void TextEditor::textFamily( const QString &f )
insilmaril@0
   811
{
insilmaril@0
   812
    e->setFamily( f );
insilmaril@0
   813
}
insilmaril@0
   814
insilmaril@0
   815
void TextEditor::textSize( const QString &p )
insilmaril@0
   816
{
insilmaril@0
   817
    e->setPointSize( p.toInt() );
insilmaril@0
   818
}
insilmaril@0
   819
insilmaril@0
   820
insilmaril@0
   821
void TextEditor::textColor()
insilmaril@0
   822
{
insilmaril@0
   823
    QColor col = QColorDialog::getColor( e->color(), this );
insilmaril@388
   824
    if ( !col.isValid() ) return;
insilmaril@0
   825
    e->setColor( col );
insilmaril@0
   826
    QPixmap pix( 16, 16 );
insilmaril@366
   827
    pix.fill( Qt::black );
insilmaril@0
   828
    actionTextColor->setIconSet( pix );
insilmaril@0
   829
}
insilmaril@0
   830
insilmaril@0
   831
void TextEditor::textAlign( QAction *a )
insilmaril@0
   832
{
insilmaril@842
   833
	qDebug()<<"TE::textAlign";
insilmaril@842
   834
	QTextCursor c=e->textCursor();
insilmaril@842
   835
	c.setPosition (3,QTextCursor::MoveAnchor);
insilmaril@842
   836
	e->setTextCursor (c);
insilmaril@842
   837
insilmaril@0
   838
    if ( a == actionAlignLeft )
insilmaril@388
   839
		e->setAlignment( Qt::AlignLeft );
insilmaril@0
   840
    else if ( a == actionAlignCenter )
insilmaril@388
   841
		e->setAlignment( Qt::AlignHCenter );
insilmaril@0
   842
    else if ( a == actionAlignRight )
insilmaril@388
   843
		e->setAlignment( Qt::AlignRight );
insilmaril@0
   844
    else if ( a == actionAlignJustify )
insilmaril@388
   845
		e->setAlignment( Qt::AlignJustify );
insilmaril@0
   846
}
insilmaril@0
   847
jhilmer@142
   848
void TextEditor::textVAlign()
jhilmer@142
   849
{
insilmaril@388
   850
	QTextCharFormat format;
insilmaril@388
   851
jhilmer@142
   852
    if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
insilmaril@388
   853
		format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
jhilmer@142
   854
    } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
insilmaril@388
   855
		format.setVerticalAlignment(QTextCharFormat::AlignSubScript);
jhilmer@142
   856
    } else {
insilmaril@388
   857
		format.setVerticalAlignment(QTextCharFormat::AlignNormal);
jhilmer@142
   858
    }
insilmaril@388
   859
	e->mergeCurrentCharFormat(format);
jhilmer@142
   860
}
jhilmer@142
   861
jhilmer@142
   862
insilmaril@0
   863
void TextEditor::fontChanged( const QFont &f )
insilmaril@0
   864
{
insilmaril@388
   865
	int i=comboFont->findText(f.family());
insilmaril@388
   866
    if (i>=0) comboFont->setCurrentIndex (i);
insilmaril@388
   867
	i=comboSize->findText(QString::number(f.pointSize()));
insilmaril@388
   868
	if (i>=0) comboSize->setCurrentIndex(i);
insilmaril@0
   869
    actionTextBold->setOn( f.bold() );
insilmaril@0
   870
    actionTextItalic->setOn( f.italic() );
insilmaril@0
   871
    actionTextUnderline->setOn( f.underline() );
insilmaril@0
   872
}
insilmaril@0
   873
insilmaril@0
   874
void TextEditor::colorChanged( const QColor &c )
insilmaril@0
   875
{
insilmaril@0
   876
    QPixmap pix( 16, 16 );
insilmaril@0
   877
    pix.fill( c );
insilmaril@0
   878
    actionTextColor->setIconSet( pix );
insilmaril@0
   879
}
insilmaril@0
   880
insilmaril@388
   881
void TextEditor::formatChanged( const QTextCharFormat &f )
insilmaril@388
   882
{
insilmaril@388
   883
	fontChanged(f.font());
insilmaril@388
   884
    colorChanged(f.foreground().color());
insilmaril@388
   885
    alignmentChanged(e->alignment());
insilmaril@388
   886
	verticalAlignmentChanged (f.verticalAlignment());
insilmaril@388
   887
}
insilmaril@388
   888
insilmaril@0
   889
void TextEditor::alignmentChanged( int a )
insilmaril@0
   890
{
insilmaril@366
   891
    if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
insilmaril@388
   892
		actionAlignLeft->setOn( true );
insilmaril@366
   893
    else if ( ( a & Qt::AlignHCenter ) )
insilmaril@388
   894
		actionAlignCenter->setOn( true );
insilmaril@366
   895
    else if ( ( a & Qt::AlignRight ) )
insilmaril@388
   896
		actionAlignRight->setOn( true );
insilmaril@366
   897
    else if ( ( a & Qt::AlignJustify ) )
insilmaril@388
   898
		actionAlignJustify->setOn( true );
insilmaril@0
   899
}
insilmaril@0
   900
insilmaril@388
   901
void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a)
jhilmer@142
   902
{
insilmaril@388
   903
	actionAlignSubScript->setOn (false);
insilmaril@388
   904
	actionAlignSuperScript->setOn (false);
insilmaril@388
   905
	switch (a)
insilmaril@388
   906
	{
insilmaril@388
   907
		case QTextCharFormat::AlignSuperScript: 
insilmaril@388
   908
			actionAlignSuperScript->setOn (true);
insilmaril@388
   909
			break;
insilmaril@388
   910
		case QTextCharFormat::AlignSubScript:
insilmaril@388
   911
			actionAlignSubScript->setOn (true);
insilmaril@388
   912
			break;
insilmaril@388
   913
		default: ;	
insilmaril@388
   914
	}
jhilmer@142
   915
}
jhilmer@142
   916
insilmaril@0
   917
insilmaril@0
   918
insilmaril@0
   919
void TextEditor::enableActions()
insilmaril@0
   920
{
insilmaril@0
   921
	actionFileLoad->setEnabled(true);
insilmaril@0
   922
	actionFileSave->setEnabled(true);
insilmaril@0
   923
	actionFileSaveAs->setEnabled(true);
insilmaril@0
   924
	actionFilePrint->setEnabled(true);
insilmaril@0
   925
	actionEditUndo->setEnabled(true);
insilmaril@0
   926
	actionEditRedo->setEnabled(true);
insilmaril@0
   927
	actionEditCopy->setEnabled(true);
insilmaril@0
   928
	actionEditCut->setEnabled(true);
insilmaril@0
   929
	actionEditPaste->setEnabled(true);
insilmaril@0
   930
	actionEditDeleteAll->setEnabled(true);
insilmaril@0
   931
	actionFormatUseFixedFont->setEnabled(true);
insilmaril@0
   932
}
insilmaril@0
   933
insilmaril@0
   934
void TextEditor::disableActions()
insilmaril@0
   935
{
insilmaril@0
   936
	actionFileLoad->setEnabled(false);
insilmaril@0
   937
	actionFileSave->setEnabled(false);
insilmaril@0
   938
	actionFileSaveAs->setEnabled(false);
insilmaril@0
   939
	actionFilePrint->setEnabled(false);
insilmaril@0
   940
	actionEditUndo->setEnabled(false);
insilmaril@0
   941
	actionEditRedo->setEnabled(false);
insilmaril@0
   942
	actionEditCopy->setEnabled(false);
insilmaril@0
   943
	actionEditCut->setEnabled(false);
insilmaril@0
   944
	actionEditPaste->setEnabled(false);
insilmaril@0
   945
	actionEditDeleteAll->setEnabled(false);
insilmaril@0
   946
	actionFormatUseFixedFont->setEnabled(false);
insilmaril@0
   947
}
insilmaril@0
   948
insilmaril@366
   949
void TextEditor::setState (EditorState s)
insilmaril@366
   950
{
insilmaril@366
   951
	
insilmaril@366
   952
	QPalette p=palette();
insilmaril@366
   953
	QColor c;
insilmaril@366
   954
	switch (s)
insilmaril@366
   955
	{
insilmaril@366
   956
		case emptyEditor:    c=QColor (150,150,150); break;
insilmaril@366
   957
		case filledEditor:   c=QColor (255,255,255); break;
insilmaril@366
   958
		case inactiveEditor: c=QColor (0,0,0);
insilmaril@366
   959
	}
insilmaril@366
   960
    p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
insilmaril@366
   961
    p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
insilmaril@366
   962
    e->setPalette(p);
insilmaril@366
   963
}
insilmaril@0
   964
insilmaril@366
   965