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