# HG changeset patch
# User jhilmer
# Date 1122812693 0
# Node ID 3590c3490789d6f44dd8ce6f3026b98b8f4152dd
# Parent  c93caccfc1163bb25c8e72a228fba6cbfb19e3db
Added superscript and subscript in text editor

diff -r c93caccfc116 -r 3590c3490789 icons/formattextsub.xpm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/icons/formattextsub.xpm	Sun Jul 31 12:24:53 2005 +0000
@@ -0,0 +1,28 @@
+/* XPM */
+static const char * formattextsub_xpm[] = {
+"22 22 3 1",
+" 	c None",
+".	c #000000",
+"+	c #FF0000",
+"                      ",
+"                      ",
+"                      ",
+"                      ",
+"   ..       ..        ",
+"   ...     ...        ",
+"    ..     ..         ",
+"    ...   ...         ",
+"     ..   ..          ",
+"      .. ..           ",
+"       ...            ",
+"       ...            ",
+"      .. ..           ",
+"     ..   ..          ",
+"    ...   ...   ++    ",
+"    ..     ..  +  +   ",
+"   ...     ...    +   ",
+"   ..       ..   +    ",
+"                +     ",
+"               ++++   ",
+"                      ",
+"                      "};
diff -r c93caccfc116 -r 3590c3490789 icons/formattextsuper.xpm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/icons/formattextsuper.xpm	Sun Jul 31 12:24:53 2005 +0000
@@ -0,0 +1,28 @@
+/* XPM */
+static const char * formattextsuper_xpm[] = {
+"22 22 3 1",
+" 	c None",
+".	c #000000",
+"+	c #FF0000",
+"                      ",
+"                 ++   ",
+"                +  +  ",
+"                   +  ",
+"   ..       ..    +   ",
+"   ...     ...   +    ",
+"    ..     ..   ++++  ",
+"    ...   ...         ",
+"     ..   ..          ",
+"      .. ..           ",
+"       ...            ",
+"       ...            ",
+"      .. ..           ",
+"     ..   ..          ",
+"    ...   ...         ",
+"    ..     ..         ",
+"   ...     ...        ",
+"   ..       ..        ",
+"                      ",
+"                      ",
+"                      ",
+"                      "};
diff -r c93caccfc116 -r 3590c3490789 texteditor.cpp
--- a/texteditor.cpp	Thu Jul 28 10:23:25 2005 +0000
+++ b/texteditor.cpp	Sun Jul 31 12:24:53 2005 +0000
@@ -1,3 +1,4 @@
+/* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
 #include "texteditor.h"
 
 #include <qcanvas.h>
@@ -45,6 +46,8 @@
 #include "icons/formattextcenter.xpm"
 #include "icons/formattextright.xpm"
 #include "icons/formattextjustify.xpm"
+#include "icons/formattextsub.xpm"
+#include "icons/formattextsuper.xpm"
 
 extern QCanvas* actCanvas;
 extern int statusbarTime;
@@ -58,13 +61,15 @@
 ///////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 
+
 TextEditor::TextEditor()
 {
     printer = new QPrinter( QPrinter::HighResolution );
 	printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
 
-	// Editor
-    e = new QTextEdit( this, "editor" );
+	// Editor (use MyTextEdit to wrap verticalAlignmentChanged to 
+	//         int argument. see header file)
+    e = new MyTextEdit( this, "editor" );
     e->setFocus();
 	e->setTextFormat(RichText);		// default
 	e->setTabStopWidth (20);		// unit is pixel
@@ -407,12 +412,31 @@
     grp->addTo( tb );
     grp->addTo( menu );
 
+    QActionGroup *grp2 = new QActionGroup( this );
+    grp2->setExclusive(false);
+    actionAlignSubScript = new QAction( QPixmap (formattextsub_xpm ), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" );
+
+    actionAlignSubScript->setToggleAction( true );
+    connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
+
+    actionAlignSuperScript = new QAction( QPixmap (formattextsuper_xpm ), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" );
+
+    actionAlignSuperScript->setToggleAction( true );
+    connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
+
+    menu->insertSeparator();
+    
+    grp2->addTo(tb);
+    grp2->addTo(menu);
+
     connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
 	     this, SLOT( fontChanged( const QFont & ) ) );
     connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
 	     this, SLOT( colorChanged( const QColor & ) ) );
     connect( e, SIGNAL( currentAlignmentChanged( int ) ),
 	     this, SLOT( alignmentChanged( int ) ) );
+    connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
+	     this, SLOT( verticalAlignmentChanged(int)));
 
 }
 
@@ -883,6 +907,18 @@
 	e->setAlignment( AlignJustify );
 }
 
+void TextEditor::textVAlign()
+{
+    if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
+	e->setVerticalAlignment( QTextEdit::AlignSuperScript);
+    } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
+	e->setVerticalAlignment( QTextEdit::AlignSubScript);
+    } else {
+	e->setVerticalAlignment( QTextEdit::AlignNormal);
+    }
+}
+
+
 void TextEditor::fontChanged( const QFont &f )
 {
     comboFont->lineEdit()->setText( f.family() );
@@ -911,6 +947,20 @@
 	actionAlignJustify->setOn( true );
 }
 
+void TextEditor::verticalAlignmentChanged(int a) 
+{
+    if (a == QTextEdit::AlignSuperScript ) {
+	actionAlignSuperScript->setOn(true);
+	actionAlignSubScript->setOn(false);
+    } else if (a == QTextEdit::AlignSubScript ) {
+	actionAlignSuperScript->setOn(false);
+	actionAlignSubScript->setOn(true);
+    } else {
+	actionAlignSuperScript->setOn(false);
+	actionAlignSubScript->setOn(false);
+    }
+}
+
 
 
 void TextEditor::enableActions()
diff -r c93caccfc116 -r 3590c3490789 texteditor.h
--- a/texteditor.h	Thu Jul 28 10:23:25 2005 +0000
+++ b/texteditor.h	Sun Jul 31 12:24:53 2005 +0000
@@ -1,3 +1,4 @@
+/* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
 #ifndef TEXTEDITOR_H 
 #define TEXTEDITOR_H
 
@@ -12,6 +13,8 @@
 
 QString textConvertToASCII(const QString &);
 
+class MyTextEdit;
+
 class TextEditor : public QMainWindow {
     Q_OBJECT
 public:
@@ -71,15 +74,17 @@
     void textSize( const QString &p );
 	void textColor();
 	void textAlign(QAction*);
+	void textVAlign();
     void fontChanged( const QFont &f );
     void colorChanged( const QColor &c );
     void alignmentChanged( int a );
+    void verticalAlignmentChanged(int a);
 	void enableActions();
 	void disableActions();
 
 private:
     QPrinter *printer;
-    QTextEdit *e;
+    MyTextEdit *e;
 	QPoint lastPos;			// save last position of window
     QString filename;
     QString filenameHint;
@@ -119,7 +124,39 @@
 	*actionAlignLeft,
 	*actionAlignCenter,
 	*actionAlignRight,
-	*actionAlignJustify;
+	*actionAlignJustify,
+	*actionAlignSubScript,
+	*actionAlignSuperScript;
+};
+
+/* Wraps currentVerticalAlignmentChanged(VerticalAlignment)
+ * to currentVerticalAlignmentChanged(int) 
+ * this way the signal can be used without use of the internal 
+ * VerticalAlignment enum of QTextEdit 
+ * If VerticalAlignment has been a global like the normal alignment there
+ * have been no problems!
+ */
+ 
+class MyTextEdit : public QTextEdit 
+{
+    Q_OBJECT;
+ public:
+    MyTextEdit(QWidget *parent, const char *name) : QTextEdit(parent, name) {
+	connect(this, 
+		SIGNAL(currentVerticalAlignmentChanged(VerticalAlignment)),
+		this, 
+		SLOT(verticalAlignmentChanged(VerticalAlignment)));
+    }
+    int verticalAlignment() const { return m_verticalAlignment; } 
+ signals:
+    void currentVerticalAlignmentChanged(int a);
+ public slots:
+    void verticalAlignmentChanged(VerticalAlignment a) {
+     m_verticalAlignment = a;
+	emit currentVerticalAlignmentChanged((int)a);
+    }
+ private: 
+ int m_verticalAlignment;
 };
 
 #endif