1.1 --- a/texteditor.cpp Thu Jul 28 10:23:25 2005 +0000
1.2 +++ b/texteditor.cpp Sun Jul 31 12:24:53 2005 +0000
1.3 @@ -1,3 +1,4 @@
1.4 +/* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
1.5 #include "texteditor.h"
1.6
1.7 #include <qcanvas.h>
1.8 @@ -45,6 +46,8 @@
1.9 #include "icons/formattextcenter.xpm"
1.10 #include "icons/formattextright.xpm"
1.11 #include "icons/formattextjustify.xpm"
1.12 +#include "icons/formattextsub.xpm"
1.13 +#include "icons/formattextsuper.xpm"
1.14
1.15 extern QCanvas* actCanvas;
1.16 extern int statusbarTime;
1.17 @@ -58,13 +61,15 @@
1.18 ///////////////////////////////////////////////////////////////////////
1.19 ///////////////////////////////////////////////////////////////////////
1.20
1.21 +
1.22 TextEditor::TextEditor()
1.23 {
1.24 printer = new QPrinter( QPrinter::HighResolution );
1.25 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1.26
1.27 - // Editor
1.28 - e = new QTextEdit( this, "editor" );
1.29 + // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
1.30 + // int argument. see header file)
1.31 + e = new MyTextEdit( this, "editor" );
1.32 e->setFocus();
1.33 e->setTextFormat(RichText); // default
1.34 e->setTabStopWidth (20); // unit is pixel
1.35 @@ -407,12 +412,31 @@
1.36 grp->addTo( tb );
1.37 grp->addTo( menu );
1.38
1.39 + QActionGroup *grp2 = new QActionGroup( this );
1.40 + grp2->setExclusive(false);
1.41 + actionAlignSubScript = new QAction( QPixmap (formattextsub_xpm ), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" );
1.42 +
1.43 + actionAlignSubScript->setToggleAction( true );
1.44 + connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
1.45 +
1.46 + actionAlignSuperScript = new QAction( QPixmap (formattextsuper_xpm ), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" );
1.47 +
1.48 + actionAlignSuperScript->setToggleAction( true );
1.49 + connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
1.50 +
1.51 + menu->insertSeparator();
1.52 +
1.53 + grp2->addTo(tb);
1.54 + grp2->addTo(menu);
1.55 +
1.56 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
1.57 this, SLOT( fontChanged( const QFont & ) ) );
1.58 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
1.59 this, SLOT( colorChanged( const QColor & ) ) );
1.60 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
1.61 this, SLOT( alignmentChanged( int ) ) );
1.62 + connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
1.63 + this, SLOT( verticalAlignmentChanged(int)));
1.64
1.65 }
1.66
1.67 @@ -883,6 +907,18 @@
1.68 e->setAlignment( AlignJustify );
1.69 }
1.70
1.71 +void TextEditor::textVAlign()
1.72 +{
1.73 + if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
1.74 + e->setVerticalAlignment( QTextEdit::AlignSuperScript);
1.75 + } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
1.76 + e->setVerticalAlignment( QTextEdit::AlignSubScript);
1.77 + } else {
1.78 + e->setVerticalAlignment( QTextEdit::AlignNormal);
1.79 + }
1.80 +}
1.81 +
1.82 +
1.83 void TextEditor::fontChanged( const QFont &f )
1.84 {
1.85 comboFont->lineEdit()->setText( f.family() );
1.86 @@ -911,6 +947,20 @@
1.87 actionAlignJustify->setOn( true );
1.88 }
1.89
1.90 +void TextEditor::verticalAlignmentChanged(int a)
1.91 +{
1.92 + if (a == QTextEdit::AlignSuperScript ) {
1.93 + actionAlignSuperScript->setOn(true);
1.94 + actionAlignSubScript->setOn(false);
1.95 + } else if (a == QTextEdit::AlignSubScript ) {
1.96 + actionAlignSuperScript->setOn(false);
1.97 + actionAlignSubScript->setOn(true);
1.98 + } else {
1.99 + actionAlignSuperScript->setOn(false);
1.100 + actionAlignSubScript->setOn(false);
1.101 + }
1.102 +}
1.103 +
1.104
1.105
1.106 void TextEditor::enableActions()