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