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