texteditor.cpp
author insilmaril
Thu, 31 Aug 2006 11:55:33 +0000
branchqt4-port
changeset 18 70c41284cb48
parent 13 9aadd0f58300
permissions -rw-r--r--
More undo/redo commands. Undo debug output still enabled
insilmaril@0
     1
#include "texteditor.h"
insilmaril@0
     2
insilmaril@9
     3
#include <QPainter>
insilmaril@9
     4
#include <QPrinter>
insilmaril@9
     5
#include <QFile>
insilmaril@9
     6
#include <QFileDialog>
insilmaril@0
     7
#include <qmenubar.h>
insilmaril@0
     8
#include <qtextstream.h>
insilmaril@9
     9
#include <QSettings>
insilmaril@9
    10
#include <QFontDialog>
insilmaril@9
    11
#include <QMessageBox>
insilmaril@9
    12
#include <QColorDialog>
insilmaril@9
    13
#include <QRegExp>
insilmaril@9
    14
#include <QList>
insilmaril@2
    15
#include <QPixmap>
insilmaril@2
    16
#include <QCloseEvent>
insilmaril@0
    17
insilmaril@0
    18
#include <iostream>
insilmaril@2
    19
#include <cstdlib>
insilmaril@0
    20
#include <typeinfo>
insilmaril@0
    21
insilmaril@2
    22
#include "noteobj.h"
insilmaril@2
    23
#include "version.h"
insilmaril@0
    24
insilmaril@0
    25
extern int statusbarTime;
insilmaril@0
    26
extern QSettings settings;
insilmaril@0
    27
insilmaril@2
    28
extern QAction *actionViewToggleNoteEditor;
insilmaril@2
    29
insilmaril@2
    30
extern QString iconPath;
insilmaril@2
    31
insilmaril@0
    32
using namespace std;
insilmaril@0
    33
insilmaril@0
    34
insilmaril@0
    35
///////////////////////////////////////////////////////////////////////
insilmaril@0
    36
///////////////////////////////////////////////////////////////////////
insilmaril@0
    37
insilmaril@2
    38
insilmaril@0
    39
TextEditor::TextEditor()
insilmaril@0
    40
{
insilmaril@0
    41
    printer = new QPrinter( QPrinter::HighResolution );
insilmaril@13
    42
	printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@0
    43
insilmaril@2
    44
	// Editor (use MyTextEdit to wrap verticalAlignmentChanged to 
insilmaril@2
    45
	//         int argument. see header file)
insilmaril@2
    46
    e = new MyTextEdit( this, "editor" );
insilmaril@0
    47
    e->setFocus();
insilmaril@2
    48
	e->setTextFormat(Qt::RichText);		// default
insilmaril@0
    49
	e->setTabStopWidth (20);		// unit is pixel
insilmaril@2
    50
	e->setColor (Qt::black);
insilmaril@9
    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@2
    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@13
    67
	resize (settings.value ( "/noteeditor/geometry/size", QSize(450,600)).toSize());
insilmaril@13
    68
	move   (settings.value ( "/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
insilmaril@0
    69
	
insilmaril@13
    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@13
    75
	varFont.fromString( settings.value
insilmaril@13
    76
		("/noteeditor/fonts/varFont",
insilmaril@13
    77
		"Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString() 
insilmaril@0
    78
	);
insilmaril@13
    79
	fixedFont.fromString (settings.value(
insilmaril@13
    80
		"/noteeditor/fonts/fixedFont",
insilmaril@13
    81
		"Courier,14,-1,5,48,0,0,0,1,0").toString() 
insilmaril@0
    82
	);
insilmaril@13
    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@2
    93
	filenameHint="";
insilmaril@2
    94
insilmaril@2
    95
	// Save settings in vymrc
insilmaril@13
    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@13
   104
	settings.setValue( "/noteeditor/geometry/size", size() );
insilmaril@13
   105
	settings.setValue( "/noteeditor/geometry/pos", pos() );
insilmaril@0
   106
	
insilmaril@13
   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@13
   114
	settings.setValue( "/noteeditor/fonts/fonthintDefault",s );
insilmaril@13
   115
	settings.setValue("/noteeditor/fonts/varFont", varFont.toString() );
insilmaril@13
   116
	settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() );
insilmaril@0
   117
}
insilmaril@0
   118
insilmaril@0
   119
bool TextEditor::isEmpty()
insilmaril@0
   120
{
insilmaril@9
   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@2
   182
void TextEditor::setFilenameHint(const QString &fnh)
insilmaril@2
   183
{
insilmaril@2
   184
	filenameHint=fnh;
insilmaril@2
   185
}
insilmaril@2
   186
insilmaril@2
   187
QString TextEditor::getFilenameHint()
insilmaril@2
   188
{
insilmaril@2
   189
	return filenameHint;
insilmaril@2
   190
}
insilmaril@2
   191
insilmaril@9
   192
bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
insilmaril@0
   193
{
insilmaril@9
   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@13
   202
    QToolBar *tb = addToolBar ( tr("Note Actions") );
insilmaril@13
   203
    QMenu *fileMenu = menuBar()->addMenu( tr( "&Note" ));
insilmaril@0
   204
insilmaril@0
   205
    QAction *a;
insilmaril@2
   206
    a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
insilmaril@2
   207
	a->setStatusTip (tr( "Import" ) );
insilmaril@2
   208
	a->setShortcut( Qt::CTRL + Qt::Key_O );
insilmaril@0
   209
    connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
insilmaril@5
   210
	tb->addAction (a);
insilmaril@5
   211
	fileMenu->addAction (a);
insilmaril@0
   212
	actionFileLoad=a;
insilmaril@0
   213
insilmaril@5
   214
    fileMenu->addSeparator();
insilmaril@2
   215
    a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
insilmaril@2
   216
	a->setStatusTip (tr( "Export Note (HTML)" ) );
insilmaril@2
   217
	a->setShortcut( Qt::CTRL + Qt::Key_S );
insilmaril@0
   218
    connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
insilmaril@5
   219
	tb->addAction (a);
insilmaril@5
   220
	fileMenu->addAction (a);
insilmaril@0
   221
	actionFileSave=a;
insilmaril@0
   222
	
insilmaril@2
   223
    a = new QAction(  QPixmap(), tr( "Export &As... (HTML)" ), this);
insilmaril@2
   224
	a->setStatusTip (tr( "Export Note As (HTML) " ));
insilmaril@0
   225
    connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
insilmaril@5
   226
	fileMenu->addAction (a);
insilmaril@0
   227
	actionFileSaveAs=a;
insilmaril@0
   228
insilmaril@2
   229
    a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
insilmaril@2
   230
	a->setStatusTip ( tr( "Export Note As (ASCII) " ) );
insilmaril@2
   231
	a->setShortcut(Qt::ALT + Qt::Key_X );
insilmaril@0
   232
    connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
insilmaril@5
   233
	fileMenu->addAction (a);
insilmaril@0
   234
	actionFileSaveAs=a;
insilmaril@0
   235
insilmaril@5
   236
    fileMenu->addSeparator();
insilmaril@2
   237
    a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
insilmaril@2
   238
	a->setStatusTip (tr( "Print Note" ) );
insilmaril@2
   239
	a->setShortcut( Qt::CTRL + Qt::Key_P );
insilmaril@0
   240
    connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
insilmaril@5
   241
	tb->addAction (a);
insilmaril@5
   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@5
   248
    QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
insilmaril@5
   249
    QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
insilmaril@0
   250
insilmaril@0
   251
    QAction *a;
insilmaril@2
   252
    a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
insilmaril@2
   253
	a->setStatusTip ( tr( "Undo" ) );
insilmaril@2
   254
	a->setShortcut(Qt::CTRL + Qt::Key_Z );
insilmaril@0
   255
    connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
insilmaril@5
   256
	editMenu->addAction (a);
insilmaril@5
   257
	tb->addAction (a);
insilmaril@0
   258
	actionEditUndo=a;
insilmaril@0
   259
	
insilmaril@2
   260
    a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this); 
insilmaril@2
   261
	a->setStatusTip ( tr( "Redo" ) );
insilmaril@2
   262
	a->setShortcut( Qt::CTRL + Qt::Key_Y );
insilmaril@0
   263
    connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
insilmaril@5
   264
	editMenu->addAction (a);
insilmaril@5
   265
	tb->addAction (a);
insilmaril@0
   266
	actionEditRedo=a;
insilmaril@0
   267
insilmaril@5
   268
    editMenu->addSeparator();
insilmaril@2
   269
    a = new QAction(QPixmap(), tr( "Select and copy &all" ),this); 
insilmaril@2
   270
	a->setStatusTip ( tr( "Select and copy all" ) );
insilmaril@2
   271
	a->setShortcut( Qt::CTRL + Qt::Key_A );
insilmaril@0
   272
    connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
insilmaril@5
   273
	editMenu->addAction (a);
insilmaril@0
   274
insilmaril@5
   275
    editMenu->addSeparator();
insilmaril@2
   276
    a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
insilmaril@2
   277
	a->setStatusTip ( tr( "Copy" ) );
insilmaril@2
   278
	a->setShortcut( Qt::CTRL + Qt::Key_C );
insilmaril@0
   279
    connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
insilmaril@5
   280
	editMenu->addAction (a);
insilmaril@5
   281
	tb->addAction (a);
insilmaril@0
   282
	actionEditCopy=a;
insilmaril@0
   283
	
insilmaril@2
   284
    a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
insilmaril@2
   285
	a->setStatusTip ( tr( "Cut" ) );
insilmaril@2
   286
	a->setShortcut( Qt::CTRL + Qt::Key_X );
insilmaril@0
   287
    connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
insilmaril@5
   288
	editMenu->addAction (a);
insilmaril@5
   289
	tb->addAction (a);
insilmaril@0
   290
	actionEditCut=a;
insilmaril@0
   291
insilmaril@2
   292
    a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
insilmaril@2
   293
	a->setStatusTip ( tr( "Paste" ) );
insilmaril@2
   294
	a->setShortcut( Qt::CTRL + Qt::Key_V );
insilmaril@0
   295
    connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
insilmaril@5
   296
	editMenu->addAction (a);
insilmaril@5
   297
	tb->addAction (a);
insilmaril@0
   298
	actionEditPaste=a;
insilmaril@0
   299
	
insilmaril@2
   300
    a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
insilmaril@2
   301
	a->setStatusTip (tr( "Delete all" ) );
insilmaril@0
   302
    connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
insilmaril@5
   303
	editMenu->addAction (a);
insilmaril@5
   304
	tb->addAction (a);
insilmaril@0
   305
	actionEditDeleteAll=a;
insilmaril@0
   306
insilmaril@2
   307
	a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
insilmaril@18
   308
	/* TODO not needed any longer? remove also from docu...
insilmaril@2
   309
	a->setStatusTip(tr( "Convert paragraphs to linebreaks" )); 
insilmaril@2
   310
	a->setShortcut( Qt::ALT + Qt::Key_P );
insilmaril@0
   311
    connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
insilmaril@5
   312
	editMenu->addAction (a);
insilmaril@10
   313
	*/
insilmaril@0
   314
	actionEditConvertPar=a;
insilmaril@0
   315
insilmaril@2
   316
	a = new QAction( QPixmap(), tr( "&Join lines" ), this);
insilmaril@18
   317
	/* TODO not needed any longer? remove also from docu...
insilmaril@2
   318
	a->setStatusTip(tr( "Join all lines of a paragraph" ) ); 
insilmaril@2
   319
	a->setShortcut(Qt::ALT + Qt::Key_J );
insilmaril@0
   320
    connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
insilmaril@5
   321
	editMenu->addAction (a);
insilmaril@10
   322
	*/
insilmaril@0
   323
	actionEditJoinLines=a;
insilmaril@0
   324
}
insilmaril@0
   325
insilmaril@0
   326
void TextEditor::setupFormatActions()
insilmaril@0
   327
{
insilmaril@5
   328
    QToolBar *tb = addToolBar ( tr("Format Actions" ));
insilmaril@5
   329
    QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
insilmaril@0
   330
insilmaril@0
   331
    QAction *a;
insilmaril@0
   332
insilmaril@2
   333
    a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
insilmaril@2
   334
	a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
insilmaril@0
   335
	a->setToggleAction (true);
insilmaril@13
   336
	a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
insilmaril@0
   337
    connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
insilmaril@5
   338
	formatMenu->addAction (a);
insilmaril@5
   339
	tb->addAction (a);
insilmaril@0
   340
	actionFormatUseFixedFont=a;
insilmaril@0
   341
insilmaril@5
   342
//    comboFont = new QComboBox( true, tb );
insilmaril@5
   343
    comboFont = new QComboBox;
insilmaril@5
   344
	tb->addWidget (comboFont);
insilmaril@9
   345
    QFontDatabase fontDB;
insilmaril@9
   346
    comboFont->insertStringList( fontDB.families() );
insilmaril@0
   347
    connect( comboFont, SIGNAL( activated( const QString & ) ),
insilmaril@0
   348
	     this, SLOT( textFamily( const QString & ) ) );
insilmaril@5
   349
    comboFont->addItem( QApplication::font().family() );
insilmaril@5
   350
    comboSize = new QComboBox;
insilmaril@5
   351
	tb->addWidget (comboSize);
insilmaril@9
   352
	QList<int> sizes=fontDB.standardSizes();
insilmaril@9
   353
	QList<int>::iterator i = sizes.begin();
insilmaril@9
   354
	while (i != sizes.end()) 
insilmaril@9
   355
	{
insilmaril@9
   356
		++i; // increment i before using it
insilmaril@9
   357
		comboSize->insertItem ( QString::number(*i));
insilmaril@9
   358
	}	
insilmaril@0
   359
    connect( comboSize, SIGNAL( activated( const QString & ) ),
insilmaril@0
   360
	     this, SLOT( textSize( const QString & ) ) );
insilmaril@5
   361
    comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
insilmaril@0
   362
insilmaril@5
   363
    formatMenu->addSeparator();
insilmaril@0
   364
insilmaril@0
   365
    QPixmap pix( 16, 16 );
insilmaril@0
   366
    pix.fill( e->color());
insilmaril@5
   367
    a = new QAction( pix, tr( "&Color..." ), this);
insilmaril@5
   368
	formatMenu->addAction (a);
insilmaril@5
   369
	tb->addAction (a);
insilmaril@5
   370
    connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
insilmaril@5
   371
    actionTextColor=a;
insilmaril@0
   372
insilmaril@5
   373
    a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
insilmaril@5
   374
	a->setShortcut(Qt::CTRL + Qt::Key_B );
insilmaril@5
   375
    connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
insilmaril@5
   376
	tb->addAction (a);
insilmaril@5
   377
	formatMenu->addAction (a);
insilmaril@5
   378
    a->setToggleAction( true );
insilmaril@5
   379
    actionTextBold=a;
insilmaril@5
   380
	
insilmaril@5
   381
    a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ),  this);
insilmaril@5
   382
	a->setShortcut(Qt::CTRL + Qt::Key_I);
insilmaril@5
   383
    connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
insilmaril@5
   384
	tb->addAction (a);
insilmaril@5
   385
	formatMenu->addAction (a);
insilmaril@5
   386
    a->setToggleAction( true );
insilmaril@5
   387
    actionTextItalic=a;
insilmaril@5
   388
	
insilmaril@5
   389
    a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
insilmaril@5
   390
	a->setShortcut(Qt::CTRL + Qt::Key_U );
insilmaril@5
   391
    connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
insilmaril@5
   392
	tb->addAction (a);
insilmaril@5
   393
	formatMenu->addAction (a);
insilmaril@5
   394
    a->setToggleAction( true );
insilmaril@5
   395
    actionTextUnderline=a;
insilmaril@5
   396
    formatMenu->addSeparator();
insilmaril@0
   397
insilmaril@3
   398
    QActionGroup *grp = new QActionGroup( this );
insilmaril@0
   399
    connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
insilmaril@0
   400
insilmaril@5
   401
    a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
insilmaril@5
   402
	a->setShortcut( Qt::CTRL+Qt::Key_L );
insilmaril@5
   403
    a->setToggleAction( true );
insilmaril@5
   404
	tb->addAction (a);
insilmaril@5
   405
	formatMenu->addAction (a);
insilmaril@5
   406
    actionAlignLeft=a;
insilmaril@5
   407
    a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
insilmaril@5
   408
    a->setShortcut(  Qt::CTRL + Qt::Key_E);
insilmaril@5
   409
    a->setToggleAction( true );
insilmaril@5
   410
	tb->addAction (a);
insilmaril@5
   411
	formatMenu->addAction (a);
insilmaril@5
   412
    actionAlignCenter=a;
insilmaril@5
   413
    a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
insilmaril@5
   414
	a->setShortcut(Qt::CTRL + Qt::Key_R );
insilmaril@5
   415
    a->setToggleAction( true );
insilmaril@5
   416
	tb->addAction (a);
insilmaril@5
   417
	formatMenu->addAction (a);
insilmaril@5
   418
    actionAlignRight=a;
insilmaril@5
   419
    a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
insilmaril@5
   420
	a->setShortcut(Qt::CTRL + Qt::Key_J );
insilmaril@5
   421
    a->setToggleAction( true );
insilmaril@5
   422
	tb->addAction (a);
insilmaril@5
   423
	formatMenu->addAction (a);
insilmaril@5
   424
    actionAlignJustify=a;
insilmaril@0
   425
insilmaril@3
   426
    QActionGroup *grp2 = new QActionGroup( this );
insilmaril@5
   427
    grp2->setExclusive(true);
insilmaril@5
   428
    a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
insilmaril@5
   429
	a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
insilmaril@5
   430
    a->setToggleAction( true );
insilmaril@5
   431
	tb->addAction (a);
insilmaril@5
   432
	formatMenu->addAction (a);
insilmaril@5
   433
    connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
insilmaril@5
   434
    actionAlignSubScript=a;
insilmaril@2
   435
insilmaril@5
   436
    a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2  );
insilmaril@5
   437
	a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
insilmaril@5
   438
    a->setToggleAction( true );
insilmaril@5
   439
	tb->addAction (a);
insilmaril@5
   440
	formatMenu->addAction (a);
insilmaril@5
   441
    connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
insilmaril@5
   442
    actionAlignSuperScript=a;
insilmaril@2
   443
insilmaril@5
   444
    formatMenu->addSeparator();
insilmaril@2
   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@9
   450
		 /*
insilmaril@0
   451
    connect( e, SIGNAL( currentAlignmentChanged( int ) ),
insilmaril@0
   452
	     this, SLOT( alignmentChanged( int ) ) );
insilmaril@2
   453
    connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
insilmaril@2
   454
	     this, SLOT( verticalAlignmentChanged(int)));
insilmaril@9
   455
		 */
insilmaril@0
   456
insilmaril@0
   457
}
insilmaril@0
   458
insilmaril@0
   459
void TextEditor::setupSettingsActions()
insilmaril@0
   460
{
insilmaril@5
   461
    QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
insilmaril@0
   462
insilmaril@0
   463
    QAction *a;
insilmaril@2
   464
    a = new QAction(tr( "Set &fixed font" ), this);
insilmaril@2
   465
	a->setStatusTip ( tr( "Set fixed font" ));
insilmaril@0
   466
    connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
insilmaril@5
   467
	settingsMenu->addAction (a);
insilmaril@0
   468
	actionSettingsFixedFont=a;
insilmaril@0
   469
insilmaril@2
   470
    a = new QAction(tr( "Set &variable font" ), this);
insilmaril@2
   471
	a->setStatusTip ( tr( "Set variable font" ) );
insilmaril@0
   472
    connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
insilmaril@5
   473
	settingsMenu->addAction (a);
insilmaril@0
   474
	actionSettingsVarFont=a;
insilmaril@0
   475
insilmaril@2
   476
    a = new QAction(tr( "&fixed font is default" ),  this);
insilmaril@2
   477
	a->setStatusTip (tr( "Used fixed font by default" ) );
insilmaril@0
   478
	a->setToggleAction (true);
insilmaril@0
   479
	// set state later in constructor...
insilmaril@5
   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@9
   488
		if (e->text().length()) 
insilmaril@0
   489
		{
insilmaril@2
   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@9
   504
		QFileDialog *fd=new QFileDialog( this);
insilmaril@9
   505
		QStringList types;
insilmaril@9
   506
		types<< "VYM notes (*.html)" <<
insilmaril@9
   507
			"ASCII texts (*.txt)" <<
insilmaril@9
   508
			"All filed (*)";
insilmaril@9
   509
		fd->setFilters (types);
insilmaril@9
   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@2
   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
{
insilmaril@2
   531
    ce->accept();	// TextEditor can be reopened with show()
insilmaril@2
   532
    actionViewToggleNoteEditor->setOn (false);
insilmaril@2
   533
    showwithmain=false;
insilmaril@2
   534
    return;
insilmaril@0
   535
}
insilmaril@0
   536
insilmaril@0
   537
QString TextEditor::getText()
insilmaril@0
   538
{
insilmaril@9
   539
	if (e->toPlainText().isEmpty())
insilmaril@9
   540
		return "";
insilmaril@9
   541
	else	
insilmaril@9
   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@9
   553
			setState (emptyEditor);
insilmaril@0
   554
		else
insilmaril@9
   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
{
insilmaril@2
   570
	state=inactiveEditor;
insilmaril@0
   571
	setText("");
insilmaril@9
   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@9
   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@2
   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@2
   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@2
   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@9
   656
insilmaril@9
   657
	QString t;
insilmaril@9
   658
	t=e->text();
insilmaril@9
   659
	QRegExp re("<p.*>");
insilmaril@9
   660
	re.setMinimal(true);
insilmaril@9
   661
	t.replace (re,"");
insilmaril@9
   662
	t.replace ("</p>","<br />");
insilmaril@9
   663
	e->setText(t);
insilmaril@9
   664
insilmaril@18
   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@9
   690
	*/	
insilmaril@0
   691
}
insilmaril@0
   692
insilmaril@0
   693
void TextEditor::textJoinLines()
insilmaril@0
   694
{
insilmaril@18
   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@9
   726
*/		
insilmaril@0
   727
}
insilmaril@0
   728
insilmaril@0
   729
void TextEditor::textExportAsASCII()
insilmaril@0
   730
{
insilmaril@2
   731
	QString text = NoteObj (e->text()).getNoteASCII();
insilmaril@2
   732
	QString fn,s;
insilmaril@2
   733
	if (!filenameHint.isEmpty())
insilmaril@2
   734
	{
insilmaril@2
   735
		if (!filenameHint.contains (".txt"))
insilmaril@2
   736
			s=filenameHint+".txt";
insilmaril@2
   737
		else	
insilmaril@2
   738
			s=filenameHint;
insilmaril@2
   739
	} else	
insilmaril@2
   740
		s=QString::null;
insilmaril@9
   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@2
   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@2
   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@9
   783
    QTextDocument *document = e->document();
insilmaril@9
   784
    QPrinter printer;
insilmaril@9
   785
insilmaril@9
   786
    QPrintDialog *dialog = new QPrintDialog(&printer, this);
insilmaril@9
   787
    dialog->setWindowTitle(tr("Print Document"));
insilmaril@9
   788
    if (dialog->exec() != QDialog::Accepted)
insilmaril@9
   789
        return;
insilmaril@9
   790
insilmaril@9
   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@9
   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@9
   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@2
   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@2
   871
	e->setAlignment( Qt::AlignLeft );
insilmaril@0
   872
    else if ( a == actionAlignCenter )
insilmaril@2
   873
	e->setAlignment( Qt::AlignHCenter );
insilmaril@0
   874
    else if ( a == actionAlignRight )
insilmaril@2
   875
	e->setAlignment( Qt::AlignRight );
insilmaril@0
   876
    else if ( a == actionAlignJustify )
insilmaril@2
   877
	e->setAlignment( Qt::AlignJustify );
insilmaril@0
   878
}
insilmaril@0
   879
insilmaril@2
   880
void TextEditor::textVAlign()
insilmaril@2
   881
{
insilmaril@18
   882
/* FIXME QT3 alignment
insilmaril@2
   883
    if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
insilmaril@9
   884
	e->setVerticalAlignment( QTextEdit::AlignSuperScript);
insilmaril@2
   885
    } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
insilmaril@9
   886
	e->setVerticalAlignment( QTextEdit::AlignSubScript);
insilmaril@2
   887
    } else {
insilmaril@9
   888
	e->setVerticalAlignment( QTextEdit::AlignNormal);
insilmaril@2
   889
    }
insilmaril@9
   890
*/	
insilmaril@2
   891
}
insilmaril@2
   892
insilmaril@2
   893
insilmaril@0
   894
void TextEditor::fontChanged( const QFont &f )
insilmaril@0
   895
{
insilmaril@5
   896
/*
insilmaril@0
   897
    comboFont->lineEdit()->setText( f.family() );
insilmaril@0
   898
    comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
insilmaril@5
   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@2
   914
    if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
insilmaril@0
   915
	actionAlignLeft->setOn( true );
insilmaril@2
   916
    else if ( ( a & Qt::AlignHCenter ) )
insilmaril@0
   917
	actionAlignCenter->setOn( true );
insilmaril@2
   918
    else if ( ( a & Qt::AlignRight ) )
insilmaril@0
   919
	actionAlignRight->setOn( true );
insilmaril@2
   920
    else if ( ( a & Qt::AlignJustify ) )
insilmaril@0
   921
	actionAlignJustify->setOn( true );
insilmaril@0
   922
}
insilmaril@0
   923
insilmaril@2
   924
void TextEditor::verticalAlignmentChanged(int a) 
insilmaril@2
   925
{
insilmaril@18
   926
	/* FIXME QT3 alignment
insilmaril@9
   927
    if (a == QTextEdit::AlignSuperScript ) {
insilmaril@2
   928
	actionAlignSuperScript->setOn(true);
insilmaril@2
   929
	actionAlignSubScript->setOn(false);
insilmaril@9
   930
    } else if (a == QTextEdit::AlignSubScript ) {
insilmaril@2
   931
	actionAlignSuperScript->setOn(false);
insilmaril@2
   932
	actionAlignSubScript->setOn(true);
insilmaril@2
   933
    } else {
insilmaril@2
   934
	actionAlignSuperScript->setOn(false);
insilmaril@2
   935
	actionAlignSubScript->setOn(false);
insilmaril@2
   936
    }
insilmaril@9
   937
	*/
insilmaril@2
   938
}
insilmaril@2
   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@9
   976
void TextEditor::setState (EditorState s)
insilmaril@9
   977
{
insilmaril@9
   978
	
insilmaril@9
   979
	QPalette p=palette();
insilmaril@9
   980
	QColor c;
insilmaril@9
   981
	switch (s)
insilmaril@9
   982
	{
insilmaril@9
   983
		case emptyEditor:    c=QColor (150,150,150); break;
insilmaril@9
   984
		case filledEditor:   c=QColor (255,255,255); break;
insilmaril@9
   985
		case inactiveEditor: c=QColor (0,0,0);
insilmaril@9
   986
	}
insilmaril@9
   987
    p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
insilmaril@9
   988
    p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
insilmaril@9
   989
    e->setPalette(p);
insilmaril@9
   990
}
insilmaril@0
   991
insilmaril@9
   992