Added superscript and subscript in text editor
authorjhilmer
Sun, 31 Jul 2005 12:24:53 +0000
changeset 1423590c3490789
parent 141 c93caccfc116
child 143 56c57552f1d2
Added superscript and subscript in text editor
icons/formattextsub.xpm
icons/formattextsuper.xpm
texteditor.cpp
texteditor.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/icons/formattextsub.xpm	Sun Jul 31 12:24:53 2005 +0000
     1.3 @@ -0,0 +1,28 @@
     1.4 +/* XPM */
     1.5 +static const char * formattextsub_xpm[] = {
     1.6 +"22 22 3 1",
     1.7 +" 	c None",
     1.8 +".	c #000000",
     1.9 +"+	c #FF0000",
    1.10 +"                      ",
    1.11 +"                      ",
    1.12 +"                      ",
    1.13 +"                      ",
    1.14 +"   ..       ..        ",
    1.15 +"   ...     ...        ",
    1.16 +"    ..     ..         ",
    1.17 +"    ...   ...         ",
    1.18 +"     ..   ..          ",
    1.19 +"      .. ..           ",
    1.20 +"       ...            ",
    1.21 +"       ...            ",
    1.22 +"      .. ..           ",
    1.23 +"     ..   ..          ",
    1.24 +"    ...   ...   ++    ",
    1.25 +"    ..     ..  +  +   ",
    1.26 +"   ...     ...    +   ",
    1.27 +"   ..       ..   +    ",
    1.28 +"                +     ",
    1.29 +"               ++++   ",
    1.30 +"                      ",
    1.31 +"                      "};
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/icons/formattextsuper.xpm	Sun Jul 31 12:24:53 2005 +0000
     2.3 @@ -0,0 +1,28 @@
     2.4 +/* XPM */
     2.5 +static const char * formattextsuper_xpm[] = {
     2.6 +"22 22 3 1",
     2.7 +" 	c None",
     2.8 +".	c #000000",
     2.9 +"+	c #FF0000",
    2.10 +"                      ",
    2.11 +"                 ++   ",
    2.12 +"                +  +  ",
    2.13 +"                   +  ",
    2.14 +"   ..       ..    +   ",
    2.15 +"   ...     ...   +    ",
    2.16 +"    ..     ..   ++++  ",
    2.17 +"    ...   ...         ",
    2.18 +"     ..   ..          ",
    2.19 +"      .. ..           ",
    2.20 +"       ...            ",
    2.21 +"       ...            ",
    2.22 +"      .. ..           ",
    2.23 +"     ..   ..          ",
    2.24 +"    ...   ...         ",
    2.25 +"    ..     ..         ",
    2.26 +"   ...     ...        ",
    2.27 +"   ..       ..        ",
    2.28 +"                      ",
    2.29 +"                      ",
    2.30 +"                      ",
    2.31 +"                      "};
     3.1 --- a/texteditor.cpp	Thu Jul 28 10:23:25 2005 +0000
     3.2 +++ b/texteditor.cpp	Sun Jul 31 12:24:53 2005 +0000
     3.3 @@ -1,3 +1,4 @@
     3.4 +/* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
     3.5  #include "texteditor.h"
     3.6  
     3.7  #include <qcanvas.h>
     3.8 @@ -45,6 +46,8 @@
     3.9  #include "icons/formattextcenter.xpm"
    3.10  #include "icons/formattextright.xpm"
    3.11  #include "icons/formattextjustify.xpm"
    3.12 +#include "icons/formattextsub.xpm"
    3.13 +#include "icons/formattextsuper.xpm"
    3.14  
    3.15  extern QCanvas* actCanvas;
    3.16  extern int statusbarTime;
    3.17 @@ -58,13 +61,15 @@
    3.18  ///////////////////////////////////////////////////////////////////////
    3.19  ///////////////////////////////////////////////////////////////////////
    3.20  
    3.21 +
    3.22  TextEditor::TextEditor()
    3.23  {
    3.24      printer = new QPrinter( QPrinter::HighResolution );
    3.25  	printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
    3.26  
    3.27 -	// Editor
    3.28 -    e = new QTextEdit( this, "editor" );
    3.29 +	// Editor (use MyTextEdit to wrap verticalAlignmentChanged to 
    3.30 +	//         int argument. see header file)
    3.31 +    e = new MyTextEdit( this, "editor" );
    3.32      e->setFocus();
    3.33  	e->setTextFormat(RichText);		// default
    3.34  	e->setTabStopWidth (20);		// unit is pixel
    3.35 @@ -407,12 +412,31 @@
    3.36      grp->addTo( tb );
    3.37      grp->addTo( menu );
    3.38  
    3.39 +    QActionGroup *grp2 = new QActionGroup( this );
    3.40 +    grp2->setExclusive(false);
    3.41 +    actionAlignSubScript = new QAction( QPixmap (formattextsub_xpm ), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" );
    3.42 +
    3.43 +    actionAlignSubScript->setToggleAction( true );
    3.44 +    connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
    3.45 +
    3.46 +    actionAlignSuperScript = new QAction( QPixmap (formattextsuper_xpm ), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" );
    3.47 +
    3.48 +    actionAlignSuperScript->setToggleAction( true );
    3.49 +    connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
    3.50 +
    3.51 +    menu->insertSeparator();
    3.52 +    
    3.53 +    grp2->addTo(tb);
    3.54 +    grp2->addTo(menu);
    3.55 +
    3.56      connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
    3.57  	     this, SLOT( fontChanged( const QFont & ) ) );
    3.58      connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
    3.59  	     this, SLOT( colorChanged( const QColor & ) ) );
    3.60      connect( e, SIGNAL( currentAlignmentChanged( int ) ),
    3.61  	     this, SLOT( alignmentChanged( int ) ) );
    3.62 +    connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
    3.63 +	     this, SLOT( verticalAlignmentChanged(int)));
    3.64  
    3.65  }
    3.66  
    3.67 @@ -883,6 +907,18 @@
    3.68  	e->setAlignment( AlignJustify );
    3.69  }
    3.70  
    3.71 +void TextEditor::textVAlign()
    3.72 +{
    3.73 +    if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
    3.74 +	e->setVerticalAlignment( QTextEdit::AlignSuperScript);
    3.75 +    } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
    3.76 +	e->setVerticalAlignment( QTextEdit::AlignSubScript);
    3.77 +    } else {
    3.78 +	e->setVerticalAlignment( QTextEdit::AlignNormal);
    3.79 +    }
    3.80 +}
    3.81 +
    3.82 +
    3.83  void TextEditor::fontChanged( const QFont &f )
    3.84  {
    3.85      comboFont->lineEdit()->setText( f.family() );
    3.86 @@ -911,6 +947,20 @@
    3.87  	actionAlignJustify->setOn( true );
    3.88  }
    3.89  
    3.90 +void TextEditor::verticalAlignmentChanged(int a) 
    3.91 +{
    3.92 +    if (a == QTextEdit::AlignSuperScript ) {
    3.93 +	actionAlignSuperScript->setOn(true);
    3.94 +	actionAlignSubScript->setOn(false);
    3.95 +    } else if (a == QTextEdit::AlignSubScript ) {
    3.96 +	actionAlignSuperScript->setOn(false);
    3.97 +	actionAlignSubScript->setOn(true);
    3.98 +    } else {
    3.99 +	actionAlignSuperScript->setOn(false);
   3.100 +	actionAlignSubScript->setOn(false);
   3.101 +    }
   3.102 +}
   3.103 +
   3.104  
   3.105  
   3.106  void TextEditor::enableActions()
     4.1 --- a/texteditor.h	Thu Jul 28 10:23:25 2005 +0000
     4.2 +++ b/texteditor.h	Sun Jul 31 12:24:53 2005 +0000
     4.3 @@ -1,3 +1,4 @@
     4.4 +/* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
     4.5  #ifndef TEXTEDITOR_H 
     4.6  #define TEXTEDITOR_H
     4.7  
     4.8 @@ -12,6 +13,8 @@
     4.9  
    4.10  QString textConvertToASCII(const QString &);
    4.11  
    4.12 +class MyTextEdit;
    4.13 +
    4.14  class TextEditor : public QMainWindow {
    4.15      Q_OBJECT
    4.16  public:
    4.17 @@ -71,15 +74,17 @@
    4.18      void textSize( const QString &p );
    4.19  	void textColor();
    4.20  	void textAlign(QAction*);
    4.21 +	void textVAlign();
    4.22      void fontChanged( const QFont &f );
    4.23      void colorChanged( const QColor &c );
    4.24      void alignmentChanged( int a );
    4.25 +    void verticalAlignmentChanged(int a);
    4.26  	void enableActions();
    4.27  	void disableActions();
    4.28  
    4.29  private:
    4.30      QPrinter *printer;
    4.31 -    QTextEdit *e;
    4.32 +    MyTextEdit *e;
    4.33  	QPoint lastPos;			// save last position of window
    4.34      QString filename;
    4.35      QString filenameHint;
    4.36 @@ -119,7 +124,39 @@
    4.37  	*actionAlignLeft,
    4.38  	*actionAlignCenter,
    4.39  	*actionAlignRight,
    4.40 -	*actionAlignJustify;
    4.41 +	*actionAlignJustify,
    4.42 +	*actionAlignSubScript,
    4.43 +	*actionAlignSuperScript;
    4.44 +};
    4.45 +
    4.46 +/* Wraps currentVerticalAlignmentChanged(VerticalAlignment)
    4.47 + * to currentVerticalAlignmentChanged(int) 
    4.48 + * this way the signal can be used without use of the internal 
    4.49 + * VerticalAlignment enum of QTextEdit 
    4.50 + * If VerticalAlignment has been a global like the normal alignment there
    4.51 + * have been no problems!
    4.52 + */
    4.53 + 
    4.54 +class MyTextEdit : public QTextEdit 
    4.55 +{
    4.56 +    Q_OBJECT;
    4.57 + public:
    4.58 +    MyTextEdit(QWidget *parent, const char *name) : QTextEdit(parent, name) {
    4.59 +	connect(this, 
    4.60 +		SIGNAL(currentVerticalAlignmentChanged(VerticalAlignment)),
    4.61 +		this, 
    4.62 +		SLOT(verticalAlignmentChanged(VerticalAlignment)));
    4.63 +    }
    4.64 +    int verticalAlignment() const { return m_verticalAlignment; } 
    4.65 + signals:
    4.66 +    void currentVerticalAlignmentChanged(int a);
    4.67 + public slots:
    4.68 +    void verticalAlignmentChanged(VerticalAlignment a) {
    4.69 +     m_verticalAlignment = a;
    4.70 +	emit currentVerticalAlignmentChanged((int)a);
    4.71 +    }
    4.72 + private: 
    4.73 + int m_verticalAlignment;
    4.74  };
    4.75  
    4.76  #endif