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