1 /* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
2 #include "texteditor.h"
5 #include <qstatusbar.h>
6 #include <qmessagebox.h>
8 #include <qapplication.h>
12 #include <qfiledialog.h>
14 #include <qpopupmenu.h>
16 #include <qtextedit.h>
18 #include <qtextstream.h>
19 #include <qpaintdevicemetrics.h>
20 #include <qsettings.h>
21 #include <qfontdialog.h>
22 #include <qmessagebox.h>
23 #include <qcolordialog.h>
25 #include <qlineedit.h>
26 #include <qsimplerichtext.h>
32 #include "icons/fileopen.xpm"
33 #include "icons/filesave.xpm"
34 #include "icons/fileprint.xpm"
35 #include "icons/editundo.xpm"
36 #include "icons/editredo.xpm"
37 #include "icons/editcopy.xpm"
38 #include "icons/editcut.xpm"
39 #include "icons/editpaste.xpm"
40 #include "icons/edittrash.xpm"
41 #include "icons/formatfixedfont.xpm"
42 #include "icons/formattextbold.xpm"
43 #include "icons/formattextitalic.xpm"
44 #include "icons/formattextunder.xpm"
45 #include "icons/formattextleft.xpm"
46 #include "icons/formattextcenter.xpm"
47 #include "icons/formattextright.xpm"
48 #include "icons/formattextjustify.xpm"
49 #include "icons/formattextsub.xpm"
50 #include "icons/formattextsuper.xpm"
52 extern QCanvas* actCanvas;
53 extern int statusbarTime;
54 extern QSettings settings;
56 extern QAction *actionViewToggleNoteEditor;
61 ///////////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////////
65 TextEditor::TextEditor()
67 printer = new QPrinter( QPrinter::HighResolution );
68 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
70 // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
71 // int argument. see header file)
72 e = new MyTextEdit( this, "editor" );
74 e->setTextFormat(RichText); // default
75 e->setTabStopWidth (20); // unit is pixel
77 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
78 setCentralWidget( e );
79 statusBar()->message( "Ready", statusbarTime);
80 setCaption("VYM - Note Editor");
86 setupSettingsActions();
89 emptyPaper = QBrush(gray);
90 filledPaper = QBrush(white);
91 inactivePaper= QBrush(black);
95 resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
96 settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
97 move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
98 settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
100 if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
101 setShowWithMain(true);
103 setShowWithMain(false);
105 varFont.fromString( settings.readEntry
106 ("/vym/noteeditor/fonts/varFont",
107 "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
109 fixedFont.fromString (settings.readEntry (
110 "/vym/noteeditor/fonts/fixedFont",
111 "Courier,14,-1,5,48,0,0,0,1,0")
113 QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
116 actionSettingsFonthintDefault->setOn (true);
117 e->setCurrentFont (fixedFont);
120 actionSettingsFonthintDefault->setOn (false);
121 e->setCurrentFont (varFont);
125 // Save settings in vymrc
126 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
130 TextEditor::~TextEditor()
132 if (printer) delete printer;
134 settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
135 settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
136 settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
137 settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
140 settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
142 settings.writeEntry( "/vym/noteeditor/showWithMain","no");
145 if (actionSettingsFonthintDefault->isOn() )
149 settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
150 settings.writeEntry ("/vym/noteeditor/fonts/varFont",
151 varFont.toString() );
152 settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
153 fixedFont.toString() );
156 bool TextEditor::isEmpty()
158 if (e->text().length())
164 void TextEditor::setShowWithMain(bool v)
169 bool TextEditor::showWithMain()
174 void TextEditor::setFontHint (const QString &fh)
177 actionFormatUseFixedFont->setOn (true);
179 actionFormatUseFixedFont->setOn (false);
183 QString TextEditor::getFontHint()
185 if (actionFormatUseFixedFont->isOn())
191 QString TextEditor::getFontHintDefault()
193 if (actionSettingsFonthintDefault->isOn())
199 void TextEditor::setFilename(const QString &fn)
201 if (state==filledEditor)
205 statusBar()->message( "No filename available for this note.", statusbarTime );
210 statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
214 QString TextEditor::getFilename()
219 void TextEditor::setFilenameHint(const QString &fnh)
224 QString TextEditor::getFilenameHint()
229 bool TextEditor::findText(const QString &t, const bool &cs)
231 bool wo=false; // word matches
232 if (e->find (t, cs, wo, true, 0, 0 ))
238 void TextEditor::setupFileActions()
240 QToolBar *tb = new QToolBar( this );
241 tb->setLabel( "File Actions" );
242 QPopupMenu *menu = new QPopupMenu( this );
243 menuBar()->insertItem( tr( "&File" ), menu );
246 a = new QAction( tr( "Import" ), QPixmap( fileopen_xpm), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" );
247 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
248 a->setEnabled(false);
253 menu->insertSeparator();
254 a = new QAction( tr( "Export Note (HTML)" ), QPixmap( filesave_xpm ), tr( "&Export..." ), CTRL + Key_S, this, "fileSave" );
255 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
260 a = new QAction( tr( "Export Note As (HTML) " ), QPixmap(), tr( "Export &As... (HTML)" ), 0, this, "exportHTML" );
261 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
265 a = new QAction( tr( "Export Note As (ASCII) " ), QPixmap(), tr( "Export &As...(ASCII)" ), ALT + Key_X, this, "exportASCII" );
266 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
270 menu->insertSeparator();
271 a = new QAction( tr( "Print Note" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
272 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
278 void TextEditor::setupEditActions()
280 QToolBar *tb = new QToolBar( this );
281 tb->setLabel( "Edit Actions" );
282 QPopupMenu *menu = new QPopupMenu( this );
283 menuBar()->insertItem( tr( "&Edit" ), menu );
286 a = new QAction( tr( "Undo" ), QPixmap(editundo_xpm), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" );
287 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
292 a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
293 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
298 menu->insertSeparator();
299 a = new QAction( tr( "Select and copy all" ), QPixmap(), tr( "Select and copy &all" ), CTRL + Key_A, this, "editcopyall" );
300 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
303 menu->insertSeparator();
304 a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
305 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
310 a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
311 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
316 a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
317 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
322 a = new QAction( tr( "Delete all" ), QPixmap( edittrash_xpm ), tr( "&Delete All" ), 0, this, "editDeleteAll" );
323 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
326 actionEditDeleteAll=a;
328 a = new QAction( tr( "Convert paragraphs to linebreaks" ), QPixmap(), tr( "&Convert Paragraphs" ), ALT + Key_P, this, "editConvertPar" );
329 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
331 actionEditConvertPar=a;
333 a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" );
334 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
336 actionEditJoinLines=a;
339 void TextEditor::setupFormatActions()
341 QToolBar *tb = new QToolBar( this );
342 tb->setLabel( "Format Actions" );
343 QPopupMenu *menu = new QPopupMenu( this );
344 menuBar()->insertItem( tr( "&Format" ), menu );
348 a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(formatfixedfont_xpm), tr( "&Font hint" ), ALT + Key_I, this, "fontHint" );
349 a->setToggleAction (true);
350 a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
351 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
354 actionFormatUseFixedFont=a;
356 menu->insertSeparator();
358 comboFont = new QComboBox( true, tb );
360 comboFont->insertStringList( db.families() );
361 connect( comboFont, SIGNAL( activated( const QString & ) ),
362 this, SLOT( textFamily( const QString & ) ) );
363 comboFont->lineEdit()->setText( QApplication::font().family() );
365 comboSize = new QComboBox( true, tb );
366 QValueList<int> sizes = db.standardSizes();
367 QValueList<int>::Iterator it = sizes.begin();
368 for ( ; it != sizes.end(); ++it )
369 comboSize->insertItem( QString::number( *it ) );
370 connect( comboSize, SIGNAL( activated( const QString & ) ),
371 this, SLOT( textSize( const QString & ) ) );
372 comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
374 menu->insertSeparator();
376 QPixmap pix( 16, 16 );
377 pix.fill( e->color());
378 actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" );
379 connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) );
380 actionTextColor->addTo( tb );
381 actionTextColor->addTo( menu );
383 actionTextBold = new QAction( QPixmap (formattextbold_xpm), tr( "&Bold" ), CTRL + Key_B, this, "textBold" );
384 connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
385 actionTextBold->addTo( tb );
386 actionTextBold->addTo( menu );
387 actionTextBold->setToggleAction( true );
388 actionTextItalic = new QAction( QPixmap(formattextitalic_xpm ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" );
389 connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) );
390 actionTextItalic->addTo( tb );
391 actionTextItalic->addTo( menu );
392 actionTextItalic->setToggleAction( true );
393 actionTextUnderline = new QAction( QPixmap (formattextunder_xpm ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" );
394 connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
395 actionTextUnderline->addTo( tb );
396 actionTextUnderline->addTo( menu );
397 actionTextUnderline->setToggleAction( true );
398 menu->insertSeparator();
400 QActionGroup *grp = new QActionGroup( this );
401 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
403 actionAlignLeft = new QAction( QPixmap (formattextleft_xpm ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" );
404 actionAlignLeft->setToggleAction( true );
405 actionAlignCenter = new QAction( QPixmap (formattextcenter_xpm ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" );
406 actionAlignCenter->setToggleAction( true );
407 actionAlignRight = new QAction( QPixmap (formattextright_xpm ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" );
408 actionAlignRight->setToggleAction( true );
409 actionAlignJustify = new QAction( QPixmap ( formattextjustify_xpm ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" );
410 actionAlignJustify->setToggleAction( true );
415 QActionGroup *grp2 = new QActionGroup( this );
416 grp2->setExclusive(false);
417 actionAlignSubScript = new QAction( QPixmap (formattextsub_xpm ), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" );
419 actionAlignSubScript->setToggleAction( true );
420 connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
422 actionAlignSuperScript = new QAction( QPixmap (formattextsuper_xpm ), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" );
424 actionAlignSuperScript->setToggleAction( true );
425 connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
427 menu->insertSeparator();
432 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
433 this, SLOT( fontChanged( const QFont & ) ) );
434 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
435 this, SLOT( colorChanged( const QColor & ) ) );
436 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
437 this, SLOT( alignmentChanged( int ) ) );
438 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
439 this, SLOT( verticalAlignmentChanged(int)));
443 void TextEditor::setupSettingsActions()
445 QPopupMenu *menu = new QPopupMenu( this );
446 menuBar()->insertItem( tr( "&Settings" ), menu );
449 a = new QAction( tr( "Set fixed font" ), QPixmap(), tr( "Set &fixed font" ), 0, this, "setFixedFont" );
450 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
452 actionSettingsFixedFont=a;
454 a = new QAction( tr( "Set variable font" ), QPixmap(), tr( "Set &variable font" ), 0, this, "setvariableFont" );
455 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
457 actionSettingsVarFont=a;
459 a = new QAction( tr( "Used fixed font by default" ), QPixmap(), tr( "&fixed font is default" ), 0, this, "fonthintDefault" );
460 a->setToggleAction (true);
461 // set state later in constructor...
463 actionSettingsFonthintDefault=a;
466 void TextEditor::textLoad()
468 if (state!=inactiveEditor)
472 QMessageBox mb( "VYM - Note Editor",
473 "Loading will overwrite the existing note",
474 QMessageBox::Warning,
475 QMessageBox::Yes | QMessageBox::Default,
478 mb.setButtonText( QMessageBox::Yes, "Load note" );
479 switch( mb.exec() ) {
480 case QMessageBox::Cancel:
486 QFileDialog *fd=new QFileDialog( this);
487 fd->addFilter ("ASCII texts (*.txt)");
488 fd->addFilter ("VYM notes (*.html)");
491 if ( fd->exec() == QDialog::Accepted )
492 fn = fd->selectedFile();
497 if ( !f.open( IO_ReadOnly ) )
500 QTextStream ts( &f );
501 setText( ts.read() );
507 void TextEditor::closeEvent( QCloseEvent* ce )
509 ce->accept(); // TextEditor can be reopened with show()
510 actionViewToggleNoteEditor->setOn (false);
515 QString TextEditor::getText()
520 void TextEditor::editorChanged()
522 // received, when QTextEdit::text() has changed
523 EditorState oldstate=state;
530 if (state != oldstate)
532 if (state==emptyEditor)
533 e->setPaper (emptyPaper);
535 e->setPaper (filledPaper);
537 // SLOT is LinkableMapObj, which will update systemFlag
538 emit (textHasChanged() );
542 void TextEditor::setText(QString t)
544 if ( !QStyleSheet::mightBeRichText( t ) )
545 t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal );
546 e->setReadOnly(false);
548 editorChanged(); //not called automagically
553 void TextEditor::setInactive()
555 state=inactiveEditor;
557 e->setPaper (inactivePaper);
558 e->setReadOnly (true);
563 void TextEditor::editCopyAll()
569 void TextEditor::textSaveAs()
571 QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
572 this,"export note dialog",tr("Export Note to single file") );
579 QMessageBox mb( "VYM",
580 tr("The file ") + fn +
581 tr(" exists already. "
582 "Do you want to overwrite it?"),
583 QMessageBox::Warning,
584 QMessageBox::Yes | QMessageBox::Default,
585 QMessageBox::Cancel | QMessageBox::Escape,
586 QMessageBox::NoButton );
587 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
588 mb.setButtonText( QMessageBox::No, tr("Cancel"));
589 switch( mb.exec() ) {
590 case QMessageBox::Yes:
595 case QMessageBox::Cancel:
606 statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
610 void TextEditor::textSave()
612 if ( filename.isEmpty() )
618 QString text = e->text();
620 if ( !f.open( IO_WriteOnly ) )
622 statusBar()->message( QString("Could not write to %1").arg(filename),
631 e->setModified( FALSE );
633 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
636 void TextEditor::textConvertPar()
638 // In X11 a copy&paste generates paragraphs,
639 // which is not always wanted
640 // This function replaces paragraphs by linebreaks.
641 int parFrom, parTo, indFrom, indTo;
642 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
652 t.replace ("</p>","<br />");
655 e->setCursorPosition (parFrom,indFrom);
657 // Tried to simply insert the changed text with
658 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
659 // but then the html would be quoted. So I use the ugly
660 // way: insert a marker, replace it in whole text of QTextEdit
661 QString marker="R3PlAcEMeL4teR!";
663 e->setText (e->text().replace(marker,t));
668 void TextEditor::textJoinLines()
670 int parFrom, parTo, indFrom, indTo;
671 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
677 // In addition to textConvertPar it is sometimes
678 // useful to join all lines of a paragraph
679 QRegExp re("</p>\n+<p>(?!</p>)");
683 // Above we may have introduced new " " at beginning of a
684 // paragraph - remove it.
685 re.setPattern("<p> ");
686 t.replace (re,"<p>");
689 e->setCursorPosition (parFrom,indFrom);
691 // Tried to simply insert the changed text with
692 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
693 // but then the html would be quoted. So I use the ugly
694 // way: insert a marker, replace it in whole text of QTextEdit
695 QString marker="R3PlAcEMeL4teR!";
697 e->setText (e->text().replace(marker,t));
702 QString textConvertToASCII(const QString &t)
706 // convert all "<br*>" to "\n"
707 QRegExp re("<br.*>");
711 // convert all "<p>" to "\n"
712 re.setPattern ("<p>");
715 // remove all remaining tags
716 re.setPattern ("<.*>");
719 // convert "&", "<" and ">"
720 re.setPattern (">");
722 re.setPattern ("<");
724 re.setPattern ("&");
726 re.setPattern (""");
731 void TextEditor::textExportAsASCII()
733 QString text = textConvertToASCII( e->text());
735 if (!filenameHint.isEmpty())
737 if (!filenameHint.contains (".txt"))
738 s=filenameHint+".txt";
743 fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
751 QMessageBox mb( "VYM",
752 tr("The file ") + fn +
753 tr(" exists already. "
754 "Do you want to overwrite it?"),
755 QMessageBox::Warning,
756 QMessageBox::Yes | QMessageBox::Default,
757 QMessageBox::Cancel | QMessageBox::Escape,
758 QMessageBox::NoButton );
759 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
760 mb.setButtonText( QMessageBox::No, tr("Cancel"));
763 if (ret==QMessageBox::Cancel)
767 if ( !file.open( IO_WriteOnly ) )
768 statusBar()->message( QString("Could not write to %1").arg(filename),
772 QTextStream t( &file );
776 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
782 void TextEditor::textPrint()
784 printer->setFullPage(TRUE);
785 if ( printer->setup( this ) )
787 QPainter p( printer );
788 // Check that there is a valid device to print to.
789 if ( !p.device() ) return;
790 QPaintDeviceMetrics metrics( p.device() );
791 int dpiy = metrics.logicalDpiY();
792 int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
793 QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
794 QFont font( e->currentFont() );
795 font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
797 QSimpleRichText richText( e->text(), font,
800 e->mimeSourceFactory(),
802 richText.setWidth( &p, body.width() );
807 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
808 view.moveBy( 0, body.height() );
809 p.translate( 0 , -body.height() );
811 p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
812 view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
813 if ( view.top() >= richText.height() )
821 void TextEditor::textEditUndo()
825 void TextEditor::toggleFonthint()
827 setUpdatesEnabled (false);
829 if (!actionFormatUseFixedFont->isOn() )
830 e->setCurrentFont (varFont);
832 e->setCurrentFont (fixedFont);
833 e->selectAll (false);
834 setUpdatesEnabled (true);
838 void TextEditor::setFixedFont()
841 QFont font =QFontDialog::getFont(
842 &ok, fixedFont, this );
844 // font is set to the font the user selected
848 void TextEditor::setVarFont()
851 QFont font =QFontDialog::getFont(
852 &ok, varFont, this );
854 // font is set to the font the user selected
858 void TextEditor::textBold()
860 e->setBold( actionTextBold->isOn() );
863 void TextEditor::textUnderline()
865 e->setUnderline( actionTextUnderline->isOn() );
868 void TextEditor::textItalic()
870 e->setItalic( actionTextItalic->isOn() );
873 void TextEditor::textFamily( const QString &f )
878 void TextEditor::textSize( const QString &p )
880 e->setPointSize( p.toInt() );
884 void TextEditor::textColor()
886 QColor col = QColorDialog::getColor( e->color(), this );
887 if ( !col.isValid() )
890 QPixmap pix( 16, 16 );
892 actionTextColor->setIconSet( pix );
895 void TextEditor::textAlign( QAction *a )
897 if ( a == actionAlignLeft )
898 e->setAlignment( AlignLeft );
899 else if ( a == actionAlignCenter )
900 e->setAlignment( AlignHCenter );
901 else if ( a == actionAlignRight )
902 e->setAlignment( AlignRight );
903 else if ( a == actionAlignJustify )
904 e->setAlignment( AlignJustify );
907 void TextEditor::textVAlign()
909 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
910 e->setVerticalAlignment( QTextEdit::AlignSuperScript);
911 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
912 e->setVerticalAlignment( QTextEdit::AlignSubScript);
914 e->setVerticalAlignment( QTextEdit::AlignNormal);
919 void TextEditor::fontChanged( const QFont &f )
921 comboFont->lineEdit()->setText( f.family() );
922 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
923 actionTextBold->setOn( f.bold() );
924 actionTextItalic->setOn( f.italic() );
925 actionTextUnderline->setOn( f.underline() );
928 void TextEditor::colorChanged( const QColor &c )
930 QPixmap pix( 16, 16 );
932 actionTextColor->setIconSet( pix );
935 void TextEditor::alignmentChanged( int a )
937 if ( ( a == AlignAuto ) || ( a & AlignLeft ))
938 actionAlignLeft->setOn( true );
939 else if ( ( a & AlignHCenter ) )
940 actionAlignCenter->setOn( true );
941 else if ( ( a & AlignRight ) )
942 actionAlignRight->setOn( true );
943 else if ( ( a & AlignJustify ) )
944 actionAlignJustify->setOn( true );
947 void TextEditor::verticalAlignmentChanged(int a)
949 if (a == QTextEdit::AlignSuperScript ) {
950 actionAlignSuperScript->setOn(true);
951 actionAlignSubScript->setOn(false);
952 } else if (a == QTextEdit::AlignSubScript ) {
953 actionAlignSuperScript->setOn(false);
954 actionAlignSubScript->setOn(true);
956 actionAlignSuperScript->setOn(false);
957 actionAlignSubScript->setOn(false);
963 void TextEditor::enableActions()
965 actionFileLoad->setEnabled(true);
966 actionFileSave->setEnabled(true);
967 actionFileSaveAs->setEnabled(true);
968 actionFilePrint->setEnabled(true);
969 actionEditUndo->setEnabled(true);
970 actionEditRedo->setEnabled(true);
971 actionEditCopy->setEnabled(true);
972 actionEditCut->setEnabled(true);
973 actionEditPaste->setEnabled(true);
974 actionEditDeleteAll->setEnabled(true);
975 actionEditConvertPar->setEnabled(true);
976 actionEditJoinLines->setEnabled(true);
977 actionFormatUseFixedFont->setEnabled(true);
980 void TextEditor::disableActions()
982 actionFileLoad->setEnabled(false);
983 actionFileSave->setEnabled(false);
984 actionFileSaveAs->setEnabled(false);
985 actionFilePrint->setEnabled(false);
986 actionEditUndo->setEnabled(false);
987 actionEditRedo->setEnabled(false);
988 actionEditCopy->setEnabled(false);
989 actionEditCut->setEnabled(false);
990 actionEditPaste->setEnabled(false);
991 actionEditDeleteAll->setEnabled(false);
992 actionEditConvertPar->setEnabled(false);
993 actionEditJoinLines->setEnabled(false);
994 actionFormatUseFixedFont->setEnabled(false);