texteditor.cpp
author insilmaril
Fri Jul 08 07:24:42 2005 +0000 (2005-07-08)
changeset 110 fdb26d5b3715
parent 95 f688a9913724
child 123 09edde7ae30e
permissions -rw-r--r--
changes for 1.6.9
insilmaril@0
     1
#include "texteditor.h"
insilmaril@0
     2
insilmaril@0
     3
#include <qcanvas.h>
insilmaril@0
     4
#include <qstatusbar.h>
insilmaril@0
     5
#include <qmessagebox.h>
insilmaril@0
     6
#include <qaction.h>
insilmaril@0
     7
#include <qapplication.h>
insilmaril@0
     8
#include <qpainter.h>
insilmaril@0
     9
#include <qprinter.h>
insilmaril@0
    10
#include <qfile.h>
insilmaril@0
    11
#include <qfiledialog.h>
insilmaril@0
    12
#include <qtoolbar.h>
insilmaril@0
    13
#include <qpopupmenu.h>
insilmaril@0
    14
#include <qmenubar.h>
insilmaril@0
    15
#include <qtextedit.h>
insilmaril@0
    16
#include <qaccel.h>
insilmaril@0
    17
#include <qtextstream.h>
insilmaril@0
    18
#include <qpaintdevicemetrics.h>
insilmaril@0
    19
#include <qsettings.h>
insilmaril@0
    20
#include <qfontdialog.h>
insilmaril@0
    21
#include <qmessagebox.h>
insilmaril@0
    22
#include <qcolordialog.h>
insilmaril@0
    23
#include <qregexp.h>
insilmaril@0
    24
#include <qlineedit.h>
insilmaril@0
    25
#include <qsimplerichtext.h>
insilmaril@0
    26
insilmaril@0
    27
#include <iostream>
insilmaril@95
    28
#include <cstdlib>
insilmaril@0
    29
#include <typeinfo>
insilmaril@0
    30
insilmaril@0
    31
#include "icons/fileopen.xpm"
insilmaril@0
    32
#include "icons/filesave.xpm"
insilmaril@0
    33
#include "icons/fileprint.xpm"
insilmaril@0
    34
#include "icons/editundo.xpm"	
insilmaril@0
    35
#include "icons/editredo.xpm"	
insilmaril@0
    36
#include "icons/editcopy.xpm"
insilmaril@0
    37
#include "icons/editcut.xpm"
insilmaril@0
    38
#include "icons/editpaste.xpm"
insilmaril@0
    39
#include "icons/edittrash.xpm"
insilmaril@0
    40
#include "icons/formatfixedfont.xpm"
insilmaril@0
    41
#include "icons/formattextbold.xpm"
insilmaril@0
    42
#include "icons/formattextitalic.xpm"
insilmaril@0
    43
#include "icons/formattextunder.xpm"
insilmaril@0
    44
#include "icons/formattextleft.xpm"
insilmaril@0
    45
#include "icons/formattextcenter.xpm"
insilmaril@0
    46
#include "icons/formattextright.xpm"
insilmaril@0
    47
#include "icons/formattextjustify.xpm"
insilmaril@0
    48
insilmaril@0
    49
extern QCanvas* actCanvas;
insilmaril@0
    50
extern int statusbarTime;
insilmaril@0
    51
extern QSettings settings;
insilmaril@0
    52
insilmaril@94
    53
extern QAction *actionViewToggleNoteEditor;
insilmaril@94
    54
insilmaril@0
    55
using namespace std;
insilmaril@0
    56
insilmaril@0
    57
insilmaril@0
    58
///////////////////////////////////////////////////////////////////////
insilmaril@0
    59
///////////////////////////////////////////////////////////////////////
insilmaril@0
    60
insilmaril@0
    61
TextEditor::TextEditor()
insilmaril@0
    62
{
insilmaril@0
    63
    printer = new QPrinter( QPrinter::HighResolution );
insilmaril@0
    64
insilmaril@0
    65
	// Editor
insilmaril@0
    66
    e = new QTextEdit( this, "editor" );
insilmaril@0
    67
    e->setFocus();
insilmaril@0
    68
	e->setTextFormat(RichText);		// default
insilmaril@0
    69
	e->setTabStopWidth (20);		// unit is pixel
insilmaril@0
    70
	e->setColor (black);
insilmaril@0
    71
	connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
insilmaril@0
    72
    setCentralWidget( e );
insilmaril@0
    73
    statusBar()->message( "Ready", statusbarTime);
insilmaril@0
    74
	setCaption("VYM - Note Editor");
insilmaril@0
    75
insilmaril@0
    76
	// Toolbars
insilmaril@0
    77
	setupFileActions();
insilmaril@0
    78
	setupEditActions();
insilmaril@0
    79
	setupFormatActions();
insilmaril@0
    80
	setupSettingsActions();
insilmaril@0
    81
	
insilmaril@0
    82
	// Various states
insilmaril@0
    83
	emptyPaper   = QBrush(gray);
insilmaril@0
    84
	filledPaper  = QBrush(white);
insilmaril@0
    85
	inactivePaper= QBrush(black);
insilmaril@0
    86
	setInactive();
insilmaril@0
    87
insilmaril@0
    88
	// Load Settings
insilmaril@0
    89
	resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
insilmaril@0
    90
	        settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
insilmaril@0
    91
	move   (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
insilmaril@0
    92
	        settings.readNumEntry( "/vym/noteeditor/geometry/posY",  50));
insilmaril@0
    93
	
insilmaril@0
    94
	if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
insilmaril@0
    95
		setShowWithMain(true);
insilmaril@0
    96
	else	
insilmaril@0
    97
		setShowWithMain(false);
insilmaril@0
    98
insilmaril@0
    99
	varFont.fromString( settings.readEntry 
insilmaril@0
   100
		("/vym/noteeditor/fonts/varFont",
insilmaril@0
   101
		"Nimbus Sans l,14,-1,5,48,0,0,0,0,0") 
insilmaril@0
   102
	);
insilmaril@0
   103
	fixedFont.fromString (settings.readEntry (
insilmaril@0
   104
		"/vym/noteeditor/fonts/fixedFont",
insilmaril@0
   105
		"Courier,14,-1,5,48,0,0,0,1,0") 
insilmaril@0
   106
	);
insilmaril@0
   107
	QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
insilmaril@0
   108
	if (s == "fixed")
insilmaril@0
   109
	{	
insilmaril@0
   110
		actionSettingsFonthintDefault->setOn (true);
insilmaril@0
   111
		e->setCurrentFont (fixedFont);
insilmaril@0
   112
	} else	
insilmaril@0
   113
	{
insilmaril@0
   114
		actionSettingsFonthintDefault->setOn (false);
insilmaril@0
   115
		e->setCurrentFont (varFont);
insilmaril@0
   116
	}	
insilmaril@106
   117
	filenameHint="";
insilmaril@0
   118
}
insilmaril@0
   119
insilmaril@0
   120
insilmaril@0
   121
TextEditor::~TextEditor()
insilmaril@0
   122
{
insilmaril@0
   123
    if (printer) delete printer;
insilmaril@0
   124
	// Save Settings
insilmaril@0
   125
	settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
insilmaril@0
   126
	settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
insilmaril@0
   127
	settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
insilmaril@0
   128
	settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
insilmaril@0
   129
	
insilmaril@0
   130
	if (showWithMain())
insilmaril@0
   131
		settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
insilmaril@0
   132
	else	
insilmaril@0
   133
		settings.writeEntry( "/vym/noteeditor/showWithMain","no");
insilmaril@0
   134
insilmaril@0
   135
	QString s;
insilmaril@0
   136
	if (actionSettingsFonthintDefault->isOn() )
insilmaril@0
   137
		s="fixed";
insilmaril@0
   138
	else	
insilmaril@0
   139
		s="variable";
insilmaril@0
   140
	settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
insilmaril@0
   141
	settings.writeEntry ("/vym/noteeditor/fonts/varFont",
insilmaril@0
   142
		varFont.toString() );
insilmaril@0
   143
	settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
insilmaril@0
   144
		fixedFont.toString() );
insilmaril@0
   145
}
insilmaril@0
   146
insilmaril@0
   147
bool TextEditor::isEmpty()
insilmaril@0
   148
{
insilmaril@0
   149
	if (e->text().length())
insilmaril@0
   150
		return false;
insilmaril@0
   151
	else
insilmaril@0
   152
		return true;
insilmaril@0
   153
}
insilmaril@0
   154
insilmaril@0
   155
void TextEditor::setShowWithMain(bool v)
insilmaril@0
   156
{
insilmaril@0
   157
	showwithmain=v;
insilmaril@0
   158
}
insilmaril@0
   159
insilmaril@0
   160
bool TextEditor::showWithMain()
insilmaril@0
   161
{
insilmaril@0
   162
	return showwithmain;
insilmaril@0
   163
}
insilmaril@0
   164
insilmaril@0
   165
void TextEditor::setFontHint (const QString &fh)
insilmaril@0
   166
{
insilmaril@0
   167
	if (fh=="fixed")
insilmaril@0
   168
		actionFormatUseFixedFont->setOn (true);
insilmaril@0
   169
	else
insilmaril@0
   170
		actionFormatUseFixedFont->setOn (false);
insilmaril@0
   171
}
insilmaril@0
   172
insilmaril@0
   173
insilmaril@0
   174
QString TextEditor::getFontHint()
insilmaril@0
   175
{
insilmaril@0
   176
	if (actionFormatUseFixedFont->isOn())
insilmaril@0
   177
		return "fixed";
insilmaril@0
   178
	else	
insilmaril@0
   179
		return "var";
insilmaril@0
   180
}
insilmaril@0
   181
insilmaril@0
   182
QString TextEditor::getFontHintDefault()
insilmaril@0
   183
{
insilmaril@0
   184
	if (actionSettingsFonthintDefault->isOn())
insilmaril@0
   185
		return "fixed";
insilmaril@0
   186
	else	
insilmaril@0
   187
		return "var";
insilmaril@0
   188
}
insilmaril@0
   189
insilmaril@0
   190
void TextEditor::setFilename(const QString &fn)
insilmaril@0
   191
{
insilmaril@0
   192
	if (state==filledEditor)
insilmaril@0
   193
		if (fn.isEmpty() )
insilmaril@0
   194
		{
insilmaril@0
   195
			filename="";
insilmaril@0
   196
			statusBar()->message( "No filename available for this note.", statusbarTime );
insilmaril@0
   197
		}	
insilmaril@0
   198
		else
insilmaril@0
   199
		{
insilmaril@0
   200
			filename=fn;
insilmaril@0
   201
			statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
insilmaril@0
   202
		}	
insilmaril@0
   203
}
insilmaril@0
   204
insilmaril@0
   205
QString TextEditor::getFilename()
insilmaril@0
   206
{
insilmaril@0
   207
	return filename;
insilmaril@0
   208
}
insilmaril@0
   209
insilmaril@106
   210
void TextEditor::setFilenameHint(const QString &fnh)
insilmaril@106
   211
{
insilmaril@106
   212
	filenameHint=fnh;
insilmaril@106
   213
}
insilmaril@106
   214
insilmaril@106
   215
QString TextEditor::getFilenameHint()
insilmaril@106
   216
{
insilmaril@106
   217
	return filenameHint;
insilmaril@106
   218
}
insilmaril@106
   219
insilmaril@0
   220
bool TextEditor::findText(const QString &t, const bool &cs)
insilmaril@0
   221
{
insilmaril@0
   222
	bool wo=false;	// word matches
insilmaril@0
   223
	if (e->find (t, cs, wo, true, 0, 0 ))
insilmaril@0
   224
		return true;
insilmaril@0
   225
	else	
insilmaril@0
   226
		return false;
insilmaril@0
   227
}
insilmaril@0
   228
insilmaril@0
   229
void TextEditor::setupFileActions()
insilmaril@0
   230
{
insilmaril@0
   231
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   232
    tb->setLabel( "File Actions" );
insilmaril@0
   233
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   234
    menuBar()->insertItem( tr( "&File" ), menu );
insilmaril@0
   235
insilmaril@0
   236
    QAction *a;
insilmaril@0
   237
    a = new QAction( tr( "Import" ), QPixmap( fileopen_xpm), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" );
insilmaril@0
   238
    connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
insilmaril@0
   239
	a->setEnabled(false);
insilmaril@0
   240
    a->addTo( tb );
insilmaril@0
   241
    a->addTo( menu );
insilmaril@0
   242
	actionFileLoad=a;
insilmaril@0
   243
insilmaril@0
   244
    menu->insertSeparator();
insilmaril@0
   245
    a = new QAction( tr( "Export Note (HTML)" ), QPixmap( filesave_xpm ), tr( "&Export..." ), CTRL + Key_S, this, "fileSave" );
insilmaril@0
   246
    connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
insilmaril@0
   247
    a->addTo( tb );
insilmaril@0
   248
    a->addTo( menu );
insilmaril@0
   249
	actionFileSave=a;
insilmaril@0
   250
	
insilmaril@0
   251
    a = new QAction( tr( "Export Note As (HTML) " ), QPixmap(), tr( "Export &As... (HTML)" ), 0, this, "exportHTML" );
insilmaril@0
   252
    connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
insilmaril@0
   253
    a->addTo( menu );
insilmaril@0
   254
	actionFileSaveAs=a;
insilmaril@0
   255
insilmaril@0
   256
    a = new QAction( tr( "Export Note As (ASCII) " ), QPixmap(), tr( "Export &As...(ASCII)" ), ALT + Key_X, this, "exportASCII" );
insilmaril@0
   257
    connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
insilmaril@0
   258
    a->addTo( menu );
insilmaril@0
   259
	actionFileSaveAs=a;
insilmaril@0
   260
insilmaril@0
   261
    menu->insertSeparator();
insilmaril@0
   262
    a = new QAction( tr( "Print Note" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
insilmaril@0
   263
    connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
insilmaril@0
   264
    a->addTo( tb );
insilmaril@0
   265
    a->addTo( menu );
insilmaril@0
   266
	actionFilePrint=a;
insilmaril@0
   267
}
insilmaril@0
   268
insilmaril@0
   269
void TextEditor::setupEditActions()
insilmaril@0
   270
{
insilmaril@0
   271
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   272
    tb->setLabel( "Edit Actions" );
insilmaril@0
   273
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   274
    menuBar()->insertItem( tr( "&Edit" ), menu );
insilmaril@0
   275
insilmaril@0
   276
    QAction *a;
insilmaril@0
   277
    a = new QAction( tr( "Undo" ), QPixmap(editundo_xpm), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" );
insilmaril@0
   278
    connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
insilmaril@0
   279
    a->addTo( menu );
insilmaril@0
   280
    a->addTo( tb);
insilmaril@0
   281
	actionEditUndo=a;
insilmaril@0
   282
	
insilmaril@0
   283
    a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); 
insilmaril@0
   284
    connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
insilmaril@0
   285
    a->addTo( tb );
insilmaril@0
   286
    a->addTo( menu );
insilmaril@0
   287
	actionEditRedo=a;
insilmaril@0
   288
insilmaril@0
   289
    menu->insertSeparator();
insilmaril@0
   290
    a = new QAction( tr( "Select and copy all" ), QPixmap(), tr( "Select and copy &all" ), CTRL + Key_A, this, "editcopyall" ); 
insilmaril@0
   291
    connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
insilmaril@0
   292
    a->addTo( menu );
insilmaril@0
   293
insilmaril@0
   294
    menu->insertSeparator();
insilmaril@0
   295
    a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
insilmaril@0
   296
    connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
insilmaril@0
   297
    a->addTo( tb );
insilmaril@0
   298
    a->addTo( menu );
insilmaril@0
   299
	actionEditCopy=a;
insilmaril@0
   300
	
insilmaril@0
   301
    a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
insilmaril@0
   302
    connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
insilmaril@0
   303
    a->addTo( tb );
insilmaril@0
   304
    a->addTo( menu );
insilmaril@0
   305
	actionEditCut=a;
insilmaril@0
   306
insilmaril@0
   307
    a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
insilmaril@0
   308
    connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
insilmaril@0
   309
    a->addTo( tb );
insilmaril@0
   310
    a->addTo( menu );
insilmaril@0
   311
	actionEditPaste=a;
insilmaril@0
   312
	
insilmaril@0
   313
    a = new QAction( tr( "Delete all" ), QPixmap( edittrash_xpm ), tr( "&Delete All" ), 0, this, "editDeleteAll" );
insilmaril@0
   314
    connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
insilmaril@0
   315
    a->addTo( tb );
insilmaril@0
   316
    a->addTo( menu );
insilmaril@0
   317
	actionEditDeleteAll=a;
insilmaril@0
   318
insilmaril@0
   319
	a = new QAction( tr( "Convert paragraphs to linebreaks" ), QPixmap(), tr( "&Convert Paragraphs" ), ALT + Key_P, this, "editConvertPar" );
insilmaril@0
   320
    connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
insilmaril@0
   321
    a->addTo( menu );
insilmaril@0
   322
	actionEditConvertPar=a;
insilmaril@0
   323
insilmaril@0
   324
	a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" );
insilmaril@0
   325
    connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
insilmaril@0
   326
    a->addTo( menu );
insilmaril@0
   327
	actionEditJoinLines=a;
insilmaril@0
   328
}
insilmaril@0
   329
insilmaril@0
   330
void TextEditor::setupFormatActions()
insilmaril@0
   331
{
insilmaril@0
   332
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   333
    tb->setLabel( "Format Actions" );
insilmaril@0
   334
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   335
    menuBar()->insertItem( tr( "&Format" ), menu );
insilmaril@0
   336
insilmaril@0
   337
    QAction *a;
insilmaril@0
   338
insilmaril@0
   339
    a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(formatfixedfont_xpm), tr( "&Font hint" ), ALT + Key_I, this, "fontHint" );
insilmaril@0
   340
	a->setToggleAction (true);
insilmaril@0
   341
	a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
insilmaril@0
   342
    connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
insilmaril@0
   343
    a->addTo( menu );
insilmaril@0
   344
    a->addTo( tb );
insilmaril@0
   345
	actionFormatUseFixedFont=a;
insilmaril@0
   346
insilmaril@0
   347
	menu->insertSeparator();
insilmaril@0
   348
insilmaril@0
   349
    comboFont = new QComboBox( true, tb );
insilmaril@0
   350
    QFontDatabase db;
insilmaril@0
   351
    comboFont->insertStringList( db.families() );
insilmaril@0
   352
    connect( comboFont, SIGNAL( activated( const QString & ) ),
insilmaril@0
   353
	     this, SLOT( textFamily( const QString & ) ) );
insilmaril@0
   354
    comboFont->lineEdit()->setText( QApplication::font().family() );
insilmaril@0
   355
insilmaril@0
   356
    comboSize = new QComboBox( true, tb );
insilmaril@0
   357
    QValueList<int> sizes = db.standardSizes();
insilmaril@0
   358
    QValueList<int>::Iterator it = sizes.begin();
insilmaril@0
   359
    for ( ; it != sizes.end(); ++it )
insilmaril@0
   360
	comboSize->insertItem( QString::number( *it ) );
insilmaril@0
   361
    connect( comboSize, SIGNAL( activated( const QString & ) ),
insilmaril@0
   362
	     this, SLOT( textSize( const QString & ) ) );
insilmaril@0
   363
    comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
insilmaril@0
   364
insilmaril@0
   365
    menu->insertSeparator();
insilmaril@0
   366
insilmaril@0
   367
    QPixmap pix( 16, 16 );
insilmaril@0
   368
    pix.fill( e->color());
insilmaril@0
   369
    actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" );
insilmaril@0
   370
    connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) );
insilmaril@0
   371
    actionTextColor->addTo( tb );
insilmaril@0
   372
    actionTextColor->addTo( menu );
insilmaril@0
   373
insilmaril@0
   374
    actionTextBold = new QAction( QPixmap (formattextbold_xpm), tr( "&Bold" ), CTRL + Key_B, this, "textBold" );
insilmaril@0
   375
    connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
insilmaril@0
   376
    actionTextBold->addTo( tb );
insilmaril@0
   377
    actionTextBold->addTo( menu );
insilmaril@0
   378
    actionTextBold->setToggleAction( true );
insilmaril@0
   379
    actionTextItalic = new QAction( QPixmap(formattextitalic_xpm ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" );
insilmaril@0
   380
    connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) );
insilmaril@0
   381
    actionTextItalic->addTo( tb );
insilmaril@0
   382
    actionTextItalic->addTo( menu );
insilmaril@0
   383
    actionTextItalic->setToggleAction( true );
insilmaril@0
   384
    actionTextUnderline = new QAction( QPixmap (formattextunder_xpm ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" );
insilmaril@0
   385
    connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
insilmaril@0
   386
    actionTextUnderline->addTo( tb );
insilmaril@0
   387
    actionTextUnderline->addTo( menu );
insilmaril@0
   388
    actionTextUnderline->setToggleAction( true );
insilmaril@0
   389
    menu->insertSeparator();
insilmaril@0
   390
insilmaril@0
   391
    QActionGroup *grp = new QActionGroup( this );
insilmaril@0
   392
    connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
insilmaril@0
   393
insilmaril@0
   394
    actionAlignLeft = new QAction( QPixmap (formattextleft_xpm ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" );
insilmaril@0
   395
    actionAlignLeft->setToggleAction( true );
insilmaril@0
   396
    actionAlignCenter = new QAction( QPixmap (formattextcenter_xpm ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" );
insilmaril@0
   397
    actionAlignCenter->setToggleAction( true );
insilmaril@0
   398
    actionAlignRight = new QAction( QPixmap (formattextright_xpm ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" );
insilmaril@0
   399
    actionAlignRight->setToggleAction( true );
insilmaril@0
   400
    actionAlignJustify = new QAction( QPixmap ( formattextjustify_xpm ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" );
insilmaril@0
   401
    actionAlignJustify->setToggleAction( true );
insilmaril@0
   402
insilmaril@0
   403
    grp->addTo( tb );
insilmaril@0
   404
    grp->addTo( menu );
insilmaril@0
   405
insilmaril@0
   406
    connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
insilmaril@0
   407
	     this, SLOT( fontChanged( const QFont & ) ) );
insilmaril@0
   408
    connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
insilmaril@0
   409
	     this, SLOT( colorChanged( const QColor & ) ) );
insilmaril@0
   410
    connect( e, SIGNAL( currentAlignmentChanged( int ) ),
insilmaril@0
   411
	     this, SLOT( alignmentChanged( int ) ) );
insilmaril@0
   412
insilmaril@0
   413
}
insilmaril@0
   414
insilmaril@0
   415
void TextEditor::setupSettingsActions()
insilmaril@0
   416
{
insilmaril@0
   417
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   418
    menuBar()->insertItem( tr( "&Settings" ), menu );
insilmaril@0
   419
insilmaril@0
   420
    QAction *a;
insilmaril@0
   421
    a = new QAction( tr( "Set fixed font" ), QPixmap(), tr( "Set &fixed font" ), 0, this, "setFixedFont" );
insilmaril@0
   422
    connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
insilmaril@0
   423
    a->addTo( menu );
insilmaril@0
   424
	actionSettingsFixedFont=a;
insilmaril@0
   425
insilmaril@0
   426
    a = new QAction( tr( "Set variable font" ), QPixmap(), tr( "Set &variable font" ), 0, this, "setvariableFont" );
insilmaril@0
   427
    connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
insilmaril@0
   428
    a->addTo( menu );
insilmaril@0
   429
	actionSettingsVarFont=a;
insilmaril@0
   430
insilmaril@0
   431
    a = new QAction( tr( "Used fixed font by default" ), QPixmap(), tr( "&fixed font is default" ), 0, this, "fonthintDefault" );
insilmaril@0
   432
	a->setToggleAction (true);
insilmaril@0
   433
	// set state later in constructor...
insilmaril@0
   434
    a->addTo( menu );
insilmaril@0
   435
	actionSettingsFonthintDefault=a;
insilmaril@0
   436
}
insilmaril@0
   437
insilmaril@0
   438
void TextEditor::textLoad()
insilmaril@0
   439
{
insilmaril@0
   440
	if (state!=inactiveEditor)
insilmaril@0
   441
	{
insilmaril@0
   442
		if (e->length()) 
insilmaril@0
   443
		{
insilmaril@0
   444
			QMessageBox mb( "VYM - Note Editor",
insilmaril@0
   445
				"Loading will overwrite the existing note",
insilmaril@0
   446
				QMessageBox::Warning,
insilmaril@0
   447
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   448
				QMessageBox::Cancel,
insilmaril@0
   449
				0 );
insilmaril@0
   450
			mb.setButtonText( QMessageBox::Yes, "Load note" );
insilmaril@0
   451
			switch( mb.exec() ) {
insilmaril@0
   452
				case QMessageBox::Cancel:
insilmaril@0
   453
					return;
insilmaril@0
   454
					break;
insilmaril@0
   455
			}
insilmaril@0
   456
		} 
insilmaril@0
   457
		// Load note
insilmaril@0
   458
		QFileDialog *fd=new QFileDialog( this);
insilmaril@0
   459
		fd->addFilter ("ASCII texts (*.txt)");
insilmaril@0
   460
		fd->addFilter ("VYM notes (*.html)");
insilmaril@0
   461
		fd->show();
insilmaril@0
   462
		QString fn;
insilmaril@0
   463
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
   464
			fn = fd->selectedFile();
insilmaril@0
   465
insilmaril@0
   466
		if ( !fn.isEmpty() )
insilmaril@0
   467
		{
insilmaril@0
   468
			QFile f( fn );
insilmaril@0
   469
			if ( !f.open( IO_ReadOnly ) )
insilmaril@0
   470
			return;
insilmaril@0
   471
insilmaril@0
   472
			QTextStream ts( &f );
insilmaril@0
   473
			setText( ts.read() );
insilmaril@0
   474
			editorChanged();
insilmaril@0
   475
		}
insilmaril@0
   476
	}
insilmaril@0
   477
}
insilmaril@0
   478
insilmaril@0
   479
void TextEditor::closeEvent( QCloseEvent* ce )
insilmaril@0
   480
{
insilmaril@0
   481
    if ( !e->isModified() ) 
insilmaril@0
   482
	{
insilmaril@0
   483
		ce->accept();	// TextEditor can be reopened with show()
insilmaril@94
   484
		actionViewToggleNoteEditor->setOn (false);
insilmaril@94
   485
		showwithmain=false;
insilmaril@0
   486
		return;
insilmaril@0
   487
    }
insilmaril@0
   488
}
insilmaril@0
   489
insilmaril@0
   490
QString TextEditor::getText()
insilmaril@0
   491
{
insilmaril@0
   492
	return e->text();
insilmaril@0
   493
}
insilmaril@0
   494
insilmaril@0
   495
void TextEditor::editorChanged()
insilmaril@0
   496
{
insilmaril@0
   497
	// received, when QTextEdit::text() has changed
insilmaril@0
   498
	EditorState	oldstate=state;
insilmaril@0
   499
insilmaril@0
   500
	if (isEmpty())
insilmaril@0
   501
		state=emptyEditor;
insilmaril@0
   502
	else
insilmaril@0
   503
		state=filledEditor;
insilmaril@0
   504
insilmaril@0
   505
	if (state != oldstate)
insilmaril@0
   506
	{
insilmaril@0
   507
		if (state==emptyEditor)
insilmaril@0
   508
			e->setPaper (emptyPaper);
insilmaril@0
   509
		else
insilmaril@0
   510
			e->setPaper (filledPaper);
insilmaril@0
   511
	}
insilmaril@0
   512
	// SLOT is LinkableMapObj, which will update systemFlag
insilmaril@0
   513
	emit (textHasChanged() );
insilmaril@0
   514
}
insilmaril@0
   515
insilmaril@0
   516
insilmaril@0
   517
void TextEditor::setText(QString t)
insilmaril@0
   518
{
insilmaril@0
   519
	if ( !QStyleSheet::mightBeRichText( t ) )
insilmaril@0
   520
		t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal );
insilmaril@0
   521
	e->setReadOnly(false);
insilmaril@0
   522
	e->setText(t);
insilmaril@0
   523
	editorChanged();	//not called automagically
insilmaril@0
   524
insilmaril@0
   525
	enableActions();
insilmaril@0
   526
}
insilmaril@0
   527
insilmaril@0
   528
void TextEditor::setInactive()
insilmaril@0
   529
{
insilmaril@0
   530
	setText("");
insilmaril@0
   531
	state=inactiveEditor;
insilmaril@0
   532
	e->setPaper (inactivePaper);
insilmaril@0
   533
	e->setReadOnly (true);
insilmaril@0
   534
insilmaril@0
   535
	disableActions();
insilmaril@0
   536
}
insilmaril@0
   537
insilmaril@0
   538
void TextEditor::editCopyAll()
insilmaril@0
   539
{
insilmaril@0
   540
	e->selectAll();
insilmaril@0
   541
	e->copy();
insilmaril@0
   542
}
insilmaril@0
   543
insilmaril@0
   544
void TextEditor::textSaveAs()
insilmaril@0
   545
{
insilmaril@0
   546
    QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
insilmaril@0
   547
					       this,"export note dialog",tr("Export Note to single file") );
insilmaril@0
   548
insilmaril@0
   549
    if ( !fn.isEmpty() ) 
insilmaril@0
   550
	{
insilmaril@0
   551
		QFile file (fn);
insilmaril@0
   552
		if (file.exists())
insilmaril@0
   553
		{
insilmaril@0
   554
			QMessageBox mb( "VYM",
insilmaril@0
   555
				tr("The file ") + fn + 
insilmaril@0
   556
				tr(" exists already. "
insilmaril@0
   557
				"Do you want to overwrite it?"),
insilmaril@0
   558
			QMessageBox::Warning,
insilmaril@0
   559
			QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   560
			QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
   561
			QMessageBox::NoButton );
insilmaril@0
   562
			mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
   563
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
   564
			switch( mb.exec() ) {
insilmaril@0
   565
				case QMessageBox::Yes:
insilmaril@0
   566
					// save 
insilmaril@0
   567
					filename = fn;
insilmaril@0
   568
					textSave();
insilmaril@0
   569
					return;
insilmaril@0
   570
				case QMessageBox::Cancel:
insilmaril@0
   571
					// do nothing
insilmaril@0
   572
					break;
insilmaril@0
   573
			}
insilmaril@0
   574
		} else
insilmaril@0
   575
		{
insilmaril@0
   576
			filename = fn;
insilmaril@0
   577
			textSave();
insilmaril@0
   578
			return;
insilmaril@0
   579
		}			
insilmaril@0
   580
    }
insilmaril@0
   581
	statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
insilmaril@0
   582
}
insilmaril@0
   583
insilmaril@0
   584
insilmaril@0
   585
void TextEditor::textSave()
insilmaril@0
   586
{
insilmaril@0
   587
    if ( filename.isEmpty() ) 
insilmaril@0
   588
	{
insilmaril@0
   589
		textSaveAs();
insilmaril@0
   590
		return;
insilmaril@0
   591
    }
insilmaril@0
   592
insilmaril@0
   593
    QString text = e->text();
insilmaril@0
   594
    QFile f( filename );
insilmaril@0
   595
    if ( !f.open( IO_WriteOnly ) ) 
insilmaril@0
   596
	{
insilmaril@0
   597
		statusBar()->message( QString("Could not write to %1").arg(filename),
insilmaril@0
   598
					  statusbarTime );
insilmaril@0
   599
		return;
insilmaril@0
   600
    }
insilmaril@0
   601
insilmaril@0
   602
    QTextStream t( &f );
insilmaril@0
   603
    t << text;
insilmaril@0
   604
    f.close();
insilmaril@0
   605
insilmaril@0
   606
    e->setModified( FALSE );
insilmaril@0
   607
insilmaril@0
   608
    statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
insilmaril@0
   609
}
insilmaril@0
   610
insilmaril@0
   611
void TextEditor::textConvertPar()
insilmaril@0
   612
{
insilmaril@0
   613
	// In X11 a copy&paste generates paragraphs, 
insilmaril@0
   614
	// which is not always wanted
insilmaril@0
   615
	// This function replaces paragraphs by linebreaks.
insilmaril@0
   616
	int parFrom, parTo, indFrom, indTo;
insilmaril@0
   617
	e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
insilmaril@0
   618
	QString t;
insilmaril@0
   619
	if (parFrom>-1)
insilmaril@0
   620
		t=e->selectedText();
insilmaril@0
   621
	else
insilmaril@0
   622
		t=e->text();
insilmaril@0
   623
insilmaril@0
   624
	QRegExp re("<p.*>");
insilmaril@0
   625
	re.setMinimal(true);
insilmaril@0
   626
	t.replace (re,"");
insilmaril@0
   627
	t.replace ("</p>","<br />");
insilmaril@0
   628
	if (parFrom>-1)
insilmaril@0
   629
	{
insilmaril@0
   630
		e->setCursorPosition (parFrom,indFrom);
insilmaril@0
   631
		e->cut();
insilmaril@0
   632
		// Tried to simply insert the changed text with
insilmaril@0
   633
		// e->insert (t,(uint)(QTextEdit::RemoveSelected));
insilmaril@0
   634
		// but then the html would be quoted. So I use the ugly
insilmaril@0
   635
		// way: insert a marker, replace it in whole text of QTextEdit
insilmaril@0
   636
		QString marker="R3PlAcEMeL4teR!";
insilmaril@0
   637
		e->insert (marker);
insilmaril@0
   638
		e->setText (e->text().replace(marker,t));
insilmaril@0
   639
	} else
insilmaril@0
   640
		e->setText(t);
insilmaril@0
   641
}
insilmaril@0
   642
insilmaril@0
   643
void TextEditor::textJoinLines()
insilmaril@0
   644
{
insilmaril@0
   645
	int parFrom, parTo, indFrom, indTo;
insilmaril@0
   646
	e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
insilmaril@0
   647
	QString t;
insilmaril@0
   648
	if (parFrom>-1)
insilmaril@0
   649
		t=e->selectedText();
insilmaril@0
   650
	else
insilmaril@0
   651
		t=e->text();
insilmaril@0
   652
	// In addition to textConvertPar it is sometimes
insilmaril@0
   653
	// useful to join all lines of a paragraph
insilmaril@0
   654
	QRegExp re("</p>\n+<p>(?!</p>)");
insilmaril@0
   655
	re.setMinimal(true);
insilmaril@0
   656
	t.replace (re," ");
insilmaril@0
   657
insilmaril@0
   658
	// Above we may have introduced new " " at beginning of a
insilmaril@0
   659
	// paragraph - remove it.
insilmaril@0
   660
	re.setPattern("<p> ");
insilmaril@0
   661
	t.replace (re,"<p>");
insilmaril@0
   662
	if (parFrom>-1)
insilmaril@0
   663
	{
insilmaril@0
   664
		e->setCursorPosition (parFrom,indFrom);
insilmaril@0
   665
		e->cut();
insilmaril@0
   666
		// Tried to simply insert the changed text with
insilmaril@0
   667
		// e->insert (t,(uint)(QTextEdit::RemoveSelected));
insilmaril@0
   668
		// but then the html would be quoted. So I use the ugly
insilmaril@0
   669
		// way: insert a marker, replace it in whole text of QTextEdit
insilmaril@0
   670
		QString marker="R3PlAcEMeL4teR!";
insilmaril@0
   671
		e->insert (marker);
insilmaril@0
   672
		e->setText (e->text().replace(marker,t));
insilmaril@0
   673
	} else
insilmaril@0
   674
		e->setText(t);
insilmaril@0
   675
}
insilmaril@0
   676
insilmaril@0
   677
QString TextEditor::textConvertToASCII(const QString &t)
insilmaril@0
   678
{
insilmaril@0
   679
	QString r=t;
insilmaril@0
   680
insilmaril@0
   681
	// convert all "<br*>" to "\n"
insilmaril@0
   682
	QRegExp re("<br.*>");
insilmaril@0
   683
	re.setMinimal(true);
insilmaril@0
   684
	r.replace (re,"\n");
insilmaril@0
   685
insilmaril@0
   686
	// convert all "</p>" to "\n"
insilmaril@0
   687
	re.setPattern ("/p");
insilmaril@0
   688
	r.replace (re,"\n");
insilmaril@0
   689
	
insilmaril@0
   690
	// remove all remaining tags 
insilmaril@0
   691
	re.setPattern ("<.*>");
insilmaril@0
   692
	r.replace (re,"");
insilmaril@0
   693
insilmaril@0
   694
	// convert "&", "<" and ">"
insilmaril@0
   695
	re.setPattern ("&gt;");
insilmaril@0
   696
	r.replace (re,">");
insilmaril@0
   697
	re.setPattern ("&lt;");
insilmaril@0
   698
	r.replace (re,"<");
insilmaril@0
   699
	re.setPattern ("&amp;");
insilmaril@0
   700
	r.replace (re,"&");
insilmaril@0
   701
	return r;
insilmaril@0
   702
}
insilmaril@0
   703
insilmaril@0
   704
void TextEditor::textExportAsASCII()
insilmaril@0
   705
{
insilmaril@0
   706
	QString text = textConvertToASCII( e->text());
insilmaril@106
   707
	QString fn,s;
insilmaril@106
   708
	if (!filenameHint.isEmpty())
insilmaril@106
   709
	{
insilmaril@106
   710
		if (!filenameHint.contains (".txt"))
insilmaril@106
   711
			s=filenameHint+".txt";
insilmaril@106
   712
		else	
insilmaril@106
   713
			s=filenameHint;
insilmaril@106
   714
	} else	
insilmaril@106
   715
		s=QString::null;
insilmaril@106
   716
	fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
insilmaril@0
   717
	int ret=-1;
insilmaril@0
   718
insilmaril@0
   719
    if ( !fn.isEmpty() ) 
insilmaril@0
   720
	{
insilmaril@0
   721
		QFile file (fn);
insilmaril@0
   722
		if (file.exists())
insilmaril@0
   723
		{
insilmaril@0
   724
			QMessageBox mb( "VYM",
insilmaril@0
   725
				tr("The file ") + fn + 
insilmaril@0
   726
				tr(" exists already. "
insilmaril@0
   727
				"Do you want to overwrite it?"),
insilmaril@0
   728
			QMessageBox::Warning,
insilmaril@0
   729
			QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
   730
			QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
   731
			QMessageBox::NoButton );
insilmaril@0
   732
			mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
   733
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
   734
			ret=mb.exec();
insilmaril@0
   735
		}	
insilmaril@0
   736
		if (ret==QMessageBox::Cancel)
insilmaril@0
   737
			return;
insilmaril@0
   738
			
insilmaril@0
   739
		// save 
insilmaril@0
   740
		if ( !file.open( IO_WriteOnly ) ) 
insilmaril@0
   741
			statusBar()->message( QString("Could not write to %1").arg(filename),
insilmaril@0
   742
						  statusbarTime );
insilmaril@0
   743
		else
insilmaril@0
   744
		{
insilmaril@0
   745
			QTextStream t( &file );
insilmaril@0
   746
			t << text;
insilmaril@0
   747
			file.close();
insilmaril@0
   748
insilmaril@0
   749
			statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
insilmaril@0
   750
		}
insilmaril@0
   751
    }
insilmaril@0
   752
}
insilmaril@0
   753
insilmaril@0
   754
insilmaril@0
   755
void TextEditor::textPrint()
insilmaril@0
   756
{
insilmaril@0
   757
    printer->setFullPage(TRUE);
insilmaril@0
   758
    if ( printer->setup( this ) ) 
insilmaril@0
   759
	{
insilmaril@0
   760
		QPainter p( printer );
insilmaril@0
   761
		// Check that there is a valid device to print to.
insilmaril@0
   762
		if ( !p.device() ) return;
insilmaril@0
   763
		QPaintDeviceMetrics metrics( p.device() );
insilmaril@0
   764
		int dpiy = metrics.logicalDpiY();
insilmaril@0
   765
		int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
insilmaril@0
   766
		QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
insilmaril@0
   767
		QFont font( e->currentFont() );
insilmaril@0
   768
		font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
insilmaril@0
   769
insilmaril@0
   770
		QSimpleRichText richText( e->text(), font,
insilmaril@0
   771
					  e->context(),
insilmaril@0
   772
					  e->styleSheet(),
insilmaril@0
   773
					  e->mimeSourceFactory(),
insilmaril@0
   774
					  body.height() );
insilmaril@0
   775
		richText.setWidth( &p, body.width() );
insilmaril@0
   776
		QRect view( body );
insilmaril@0
   777
		int page = 1;
insilmaril@0
   778
		do 
insilmaril@0
   779
		{
insilmaril@0
   780
			richText.draw( &p, body.left(), body.top(), view, colorGroup() );
insilmaril@0
   781
			view.moveBy( 0, body.height() );
insilmaril@0
   782
			p.translate( 0 , -body.height() );
insilmaril@0
   783
			p.setFont( font );
insilmaril@0
   784
			p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
insilmaril@0
   785
				view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
insilmaril@0
   786
			if ( view.top()  >= richText.height() )
insilmaril@0
   787
			break;
insilmaril@0
   788
			printer->newPage();
insilmaril@0
   789
			page++;
insilmaril@0
   790
		} while (TRUE);
insilmaril@0
   791
    }
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@0
   801
	e->selectAll (true);
insilmaril@0
   802
	if (!actionFormatUseFixedFont->isOn() ) 
insilmaril@0
   803
		e->setCurrentFont (varFont);
insilmaril@0
   804
	else	
insilmaril@0
   805
		e->setCurrentFont (fixedFont);
insilmaril@0
   806
	e->selectAll (false);
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@0
   864
    pix.fill( 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@0
   871
	e->setAlignment( AlignLeft );
insilmaril@0
   872
    else if ( a == actionAlignCenter )
insilmaril@0
   873
	e->setAlignment( AlignHCenter );
insilmaril@0
   874
    else if ( a == actionAlignRight )
insilmaril@0
   875
	e->setAlignment( AlignRight );
insilmaril@0
   876
    else if ( a == actionAlignJustify )
insilmaril@0
   877
	e->setAlignment( AlignJustify );
insilmaril@0
   878
}
insilmaril@0
   879
insilmaril@0
   880
void TextEditor::fontChanged( const QFont &f )
insilmaril@0
   881
{
insilmaril@0
   882
    comboFont->lineEdit()->setText( f.family() );
insilmaril@0
   883
    comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
insilmaril@0
   884
    actionTextBold->setOn( f.bold() );
insilmaril@0
   885
    actionTextItalic->setOn( f.italic() );
insilmaril@0
   886
    actionTextUnderline->setOn( f.underline() );
insilmaril@0
   887
}
insilmaril@0
   888
insilmaril@0
   889
void TextEditor::colorChanged( const QColor &c )
insilmaril@0
   890
{
insilmaril@0
   891
    QPixmap pix( 16, 16 );
insilmaril@0
   892
    pix.fill( c );
insilmaril@0
   893
    actionTextColor->setIconSet( pix );
insilmaril@0
   894
}
insilmaril@0
   895
insilmaril@0
   896
void TextEditor::alignmentChanged( int a )
insilmaril@0
   897
{
insilmaril@0
   898
    if ( ( a == AlignAuto ) || ( a & AlignLeft ))
insilmaril@0
   899
	actionAlignLeft->setOn( true );
insilmaril@0
   900
    else if ( ( a & AlignHCenter ) )
insilmaril@0
   901
	actionAlignCenter->setOn( true );
insilmaril@0
   902
    else if ( ( a & AlignRight ) )
insilmaril@0
   903
	actionAlignRight->setOn( true );
insilmaril@0
   904
    else if ( ( a & AlignJustify ) )
insilmaril@0
   905
	actionAlignJustify->setOn( true );
insilmaril@0
   906
}
insilmaril@0
   907
insilmaril@0
   908
insilmaril@0
   909
insilmaril@0
   910
void TextEditor::enableActions()
insilmaril@0
   911
{
insilmaril@0
   912
	actionFileLoad->setEnabled(true);
insilmaril@0
   913
	actionFileSave->setEnabled(true);
insilmaril@0
   914
	actionFileSaveAs->setEnabled(true);
insilmaril@0
   915
	actionFilePrint->setEnabled(true);
insilmaril@0
   916
	actionEditUndo->setEnabled(true);
insilmaril@0
   917
	actionEditRedo->setEnabled(true);
insilmaril@0
   918
	actionEditCopy->setEnabled(true);
insilmaril@0
   919
	actionEditCut->setEnabled(true);
insilmaril@0
   920
	actionEditPaste->setEnabled(true);
insilmaril@0
   921
	actionEditDeleteAll->setEnabled(true);
insilmaril@0
   922
	actionEditConvertPar->setEnabled(true);
insilmaril@0
   923
	actionEditJoinLines->setEnabled(true);
insilmaril@0
   924
	actionFormatUseFixedFont->setEnabled(true);
insilmaril@0
   925
}
insilmaril@0
   926
insilmaril@0
   927
void TextEditor::disableActions()
insilmaril@0
   928
{
insilmaril@0
   929
	actionFileLoad->setEnabled(false);
insilmaril@0
   930
	actionFileSave->setEnabled(false);
insilmaril@0
   931
	actionFileSaveAs->setEnabled(false);
insilmaril@0
   932
	actionFilePrint->setEnabled(false);
insilmaril@0
   933
	actionEditUndo->setEnabled(false);
insilmaril@0
   934
	actionEditRedo->setEnabled(false);
insilmaril@0
   935
	actionEditCopy->setEnabled(false);
insilmaril@0
   936
	actionEditCut->setEnabled(false);
insilmaril@0
   937
	actionEditPaste->setEnabled(false);
insilmaril@0
   938
	actionEditDeleteAll->setEnabled(false);
insilmaril@0
   939
	actionEditConvertPar->setEnabled(false);
insilmaril@0
   940
	actionEditJoinLines->setEnabled(false);
insilmaril@0
   941
	actionFormatUseFixedFont->setEnabled(false);
insilmaril@0
   942
}
insilmaril@0
   943
insilmaril@0
   944