More documentation, fixed small bug where links of unselected objects where visible again
1 #include "texteditor.h"
4 #include <qstatusbar.h>
5 #include <qmessagebox.h>
7 #include <qapplication.h>
11 #include <qfiledialog.h>
13 #include <qpopupmenu.h>
15 #include <qtextedit.h>
17 #include <qtextstream.h>
18 #include <qpaintdevicemetrics.h>
19 #include <qsettings.h>
20 #include <qfontdialog.h>
21 #include <qmessagebox.h>
22 #include <qcolordialog.h>
24 #include <qlineedit.h>
25 #include <qsimplerichtext.h>
34 #include "icons/fileopen.xpm"
35 #include "icons/filesave.xpm"
36 #include "icons/fileprint.xpm"
37 #include "icons/editundo.xpm"
38 #include "icons/editredo.xpm"
39 #include "icons/editcopy.xpm"
40 #include "icons/editcut.xpm"
41 #include "icons/editpaste.xpm"
42 #include "icons/edittrash.xpm"
43 #include "icons/formatfixedfont.xpm"
44 #include "icons/formattextbold.xpm"
45 #include "icons/formattextitalic.xpm"
46 #include "icons/formattextunder.xpm"
47 #include "icons/formattextleft.xpm"
48 #include "icons/formattextcenter.xpm"
49 #include "icons/formattextright.xpm"
50 #include "icons/formattextjustify.xpm"
51 #include "icons/formattextsub.xpm"
52 #include "icons/formattextsuper.xpm"
54 extern QCanvas* actCanvas;
55 extern int statusbarTime;
56 extern QSettings settings;
58 extern QAction *actionViewToggleNoteEditor;
63 ///////////////////////////////////////////////////////////////////////
64 ///////////////////////////////////////////////////////////////////////
67 TextEditor::TextEditor()
69 printer = new QPrinter( QPrinter::HighResolution );
70 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
72 // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
73 // int argument. see header file)
74 e = new MyTextEdit( this, "editor" );
76 e->setTextFormat(RichText); // default
77 e->setTabStopWidth (20); // unit is pixel
79 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
80 setCentralWidget( e );
81 statusBar()->message( "Ready", statusbarTime);
82 setCaption(__VYM " - " +tr ("Note Editor"));
88 setupSettingsActions();
91 emptyPaper = QBrush(gray);
92 filledPaper = QBrush(white);
93 inactivePaper= QBrush(black);
97 resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
98 settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
99 move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
100 settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
102 if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
103 setShowWithMain(true);
105 setShowWithMain(false);
107 varFont.fromString( settings.readEntry
108 ("/vym/noteeditor/fonts/varFont",
109 "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
111 fixedFont.fromString (settings.readEntry (
112 "/vym/noteeditor/fonts/fixedFont",
113 "Courier,14,-1,5,48,0,0,0,1,0")
115 QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
118 actionSettingsFonthintDefault->setOn (true);
119 e->setCurrentFont (fixedFont);
122 actionSettingsFonthintDefault->setOn (false);
123 e->setCurrentFont (varFont);
127 // Save settings in vymrc
128 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
132 TextEditor::~TextEditor()
134 if (printer) delete printer;
136 settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
137 settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
138 settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
139 settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
142 settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
144 settings.writeEntry( "/vym/noteeditor/showWithMain","no");
147 if (actionSettingsFonthintDefault->isOn() )
151 settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
152 settings.writeEntry ("/vym/noteeditor/fonts/varFont",
153 varFont.toString() );
154 settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
155 fixedFont.toString() );
158 bool TextEditor::isEmpty()
160 if (e->text().length())
166 void TextEditor::setShowWithMain(bool v)
171 bool TextEditor::showWithMain()
176 void TextEditor::setFontHint (const QString &fh)
179 actionFormatUseFixedFont->setOn (true);
181 actionFormatUseFixedFont->setOn (false);
185 QString TextEditor::getFontHint()
187 if (actionFormatUseFixedFont->isOn())
193 QString TextEditor::getFontHintDefault()
195 if (actionSettingsFonthintDefault->isOn())
201 void TextEditor::setFilename(const QString &fn)
203 if (state==filledEditor)
207 statusBar()->message( "No filename available for this note.", statusbarTime );
212 statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
216 QString TextEditor::getFilename()
221 void TextEditor::setFilenameHint(const QString &fnh)
226 QString TextEditor::getFilenameHint()
231 bool TextEditor::findText(const QString &t, const bool &cs)
233 bool wo=false; // word matches
234 if (e->find (t, cs, wo, true, 0, 0 ))
240 void TextEditor::setupFileActions()
242 QToolBar *tb = new QToolBar( this );
243 tb->setLabel( "File Actions" );
244 QPopupMenu *menu = new QPopupMenu( this );
245 menuBar()->insertItem( tr( "&File" ), menu );
248 a = new QAction( tr( "Import" ), QPixmap( fileopen_xpm), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" );
249 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
250 a->setEnabled(false);
255 menu->insertSeparator();
256 a = new QAction( tr( "Export Note (HTML)" ), QPixmap( filesave_xpm ), tr( "&Export..." ), CTRL + Key_S, this, "fileSave" );
257 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
262 a = new QAction( tr( "Export Note As (HTML) " ), QPixmap(), tr( "Export &As... (HTML)" ), 0, this, "exportHTML" );
263 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
267 a = new QAction( tr( "Export Note As (ASCII) " ), QPixmap(), tr( "Export &As...(ASCII)" ), ALT + Key_X, this, "exportASCII" );
268 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
272 menu->insertSeparator();
273 a = new QAction( tr( "Print Note" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
274 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
280 void TextEditor::setupEditActions()
282 QToolBar *tb = new QToolBar( this );
283 tb->setLabel( "Edit Actions" );
284 QPopupMenu *menu = new QPopupMenu( this );
285 menuBar()->insertItem( tr( "&Edit" ), menu );
288 a = new QAction( tr( "Undo" ), QPixmap(editundo_xpm), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" );
289 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
294 a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
295 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
300 menu->insertSeparator();
301 a = new QAction( tr( "Select and copy all" ), QPixmap(), tr( "Select and copy &all" ), CTRL + Key_A, this, "editcopyall" );
302 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
305 menu->insertSeparator();
306 a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
307 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
312 a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
313 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
318 a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
319 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
324 a = new QAction( tr( "Delete all" ), QPixmap( edittrash_xpm ), tr( "&Delete All" ), 0, this, "editDeleteAll" );
325 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
328 actionEditDeleteAll=a;
330 a = new QAction( tr( "Convert paragraphs to linebreaks" ), QPixmap(), tr( "&Convert Paragraphs" ), ALT + Key_P, this, "editConvertPar" );
331 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
333 actionEditConvertPar=a;
335 a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" );
336 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
338 actionEditJoinLines=a;
341 void TextEditor::setupFormatActions()
343 QToolBar *tb = new QToolBar( this );
344 tb->setLabel( "Format Actions" );
345 QPopupMenu *menu = new QPopupMenu( this );
346 menuBar()->insertItem( tr( "&Format" ), menu );
350 a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(formatfixedfont_xpm), tr( "&Font hint" ), ALT + Key_I, this, "fontHint" );
351 a->setToggleAction (true);
352 a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
353 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
356 actionFormatUseFixedFont=a;
358 menu->insertSeparator();
360 comboFont = new QComboBox( true, tb );
362 comboFont->insertStringList( db.families() );
363 connect( comboFont, SIGNAL( activated( const QString & ) ),
364 this, SLOT( textFamily( const QString & ) ) );
365 comboFont->lineEdit()->setText( QApplication::font().family() );
367 comboSize = new QComboBox( true, tb );
368 QValueList<int> sizes = db.standardSizes();
369 QValueList<int>::Iterator it = sizes.begin();
370 for ( ; it != sizes.end(); ++it )
371 comboSize->insertItem( QString::number( *it ) );
372 connect( comboSize, SIGNAL( activated( const QString & ) ),
373 this, SLOT( textSize( const QString & ) ) );
374 comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
376 menu->insertSeparator();
378 QPixmap pix( 16, 16 );
379 pix.fill( e->color());
380 actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" );
381 connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) );
382 actionTextColor->addTo( tb );
383 actionTextColor->addTo( menu );
385 actionTextBold = new QAction( QPixmap (formattextbold_xpm), tr( "&Bold" ), CTRL + Key_B, this, "textBold" );
386 connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
387 actionTextBold->addTo( tb );
388 actionTextBold->addTo( menu );
389 actionTextBold->setToggleAction( true );
390 actionTextItalic = new QAction( QPixmap(formattextitalic_xpm ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" );
391 connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) );
392 actionTextItalic->addTo( tb );
393 actionTextItalic->addTo( menu );
394 actionTextItalic->setToggleAction( true );
395 actionTextUnderline = new QAction( QPixmap (formattextunder_xpm ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" );
396 connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
397 actionTextUnderline->addTo( tb );
398 actionTextUnderline->addTo( menu );
399 actionTextUnderline->setToggleAction( true );
400 menu->insertSeparator();
402 QActionGroup *grp = new QActionGroup( this );
403 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
405 actionAlignLeft = new QAction( QPixmap (formattextleft_xpm ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" );
406 actionAlignLeft->setToggleAction( true );
407 actionAlignCenter = new QAction( QPixmap (formattextcenter_xpm ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" );
408 actionAlignCenter->setToggleAction( true );
409 actionAlignRight = new QAction( QPixmap (formattextright_xpm ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" );
410 actionAlignRight->setToggleAction( true );
411 actionAlignJustify = new QAction( QPixmap ( formattextjustify_xpm ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" );
412 actionAlignJustify->setToggleAction( true );
417 QActionGroup *grp2 = new QActionGroup( this );
418 grp2->setExclusive(false);
419 actionAlignSubScript = new QAction( QPixmap (formattextsub_xpm ), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" );
421 actionAlignSubScript->setToggleAction( true );
422 connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
424 actionAlignSuperScript = new QAction( QPixmap (formattextsuper_xpm ), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" );
426 actionAlignSuperScript->setToggleAction( true );
427 connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
429 menu->insertSeparator();
434 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
435 this, SLOT( fontChanged( const QFont & ) ) );
436 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
437 this, SLOT( colorChanged( const QColor & ) ) );
438 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
439 this, SLOT( alignmentChanged( int ) ) );
440 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
441 this, SLOT( verticalAlignmentChanged(int)));
445 void TextEditor::setupSettingsActions()
447 QPopupMenu *menu = new QPopupMenu( this );
448 menuBar()->insertItem( tr( "&Settings" ), menu );
451 a = new QAction( tr( "Set fixed font" ), QPixmap(), tr( "Set &fixed font" ), 0, this, "setFixedFont" );
452 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
454 actionSettingsFixedFont=a;
456 a = new QAction( tr( "Set variable font" ), QPixmap(), tr( "Set &variable font" ), 0, this, "setvariableFont" );
457 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
459 actionSettingsVarFont=a;
461 a = new QAction( tr( "Used fixed font by default" ), QPixmap(), tr( "&fixed font is default" ), 0, this, "fonthintDefault" );
462 a->setToggleAction (true);
463 // set state later in constructor...
465 actionSettingsFonthintDefault=a;
468 void TextEditor::textLoad()
470 if (state!=inactiveEditor)
474 QMessageBox mb( __VYM " - " +tr("Note Editor"),
475 "Loading will overwrite the existing note",
476 QMessageBox::Warning,
477 QMessageBox::Yes | QMessageBox::Default,
480 mb.setButtonText( QMessageBox::Yes, "Load note" );
481 switch( mb.exec() ) {
482 case QMessageBox::Cancel:
488 QFileDialog *fd=new QFileDialog( this);
489 fd->addFilter ("ASCII texts (*.txt)");
490 fd->addFilter ("VYM notes (*.html)");
493 if ( fd->exec() == QDialog::Accepted )
494 fn = fd->selectedFile();
499 if ( !f.open( IO_ReadOnly ) )
502 QTextStream ts( &f );
503 setText( ts.read() );
509 void TextEditor::closeEvent( QCloseEvent* ce )
511 ce->accept(); // TextEditor can be reopened with show()
512 actionViewToggleNoteEditor->setOn (false);
517 QString TextEditor::getText()
522 void TextEditor::editorChanged()
529 if (state==emptyEditor)
530 e->setPaper (emptyPaper);
532 e->setPaper (filledPaper);
533 // SLOT is LinkableMapObj, which will update systemFlag
534 emit (textHasChanged() );
538 void TextEditor::setText(QString t)
540 if ( !QStyleSheet::mightBeRichText( t ) )
541 t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal );
542 e->setReadOnly(false);
544 // editorChanged(); //not called automagically FIXME or is it?
549 void TextEditor::setInactive()
551 state=inactiveEditor;
553 e->setPaper (inactivePaper);
554 e->setReadOnly (true);
559 void TextEditor::editCopyAll()
565 void TextEditor::textSaveAs()
567 QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
568 this,"export note dialog",tr("Export Note to single file") );
575 QMessageBox mb( __VYM,
576 tr("The file ") + fn +
577 tr(" exists already. "
578 "Do you want to overwrite it?"),
579 QMessageBox::Warning,
580 QMessageBox::Yes | QMessageBox::Default,
581 QMessageBox::Cancel | QMessageBox::Escape,
582 QMessageBox::NoButton );
583 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
584 mb.setButtonText( QMessageBox::No, tr("Cancel"));
585 switch( mb.exec() ) {
586 case QMessageBox::Yes:
591 case QMessageBox::Cancel:
602 statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
606 void TextEditor::textSave()
608 if ( filename.isEmpty() )
614 QString text = e->text();
616 if ( !f.open( IO_WriteOnly ) )
618 statusBar()->message( QString("Could not write to %1").arg(filename),
627 e->setModified( FALSE );
629 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
632 void TextEditor::textConvertPar()
634 // In X11 a copy&paste generates paragraphs,
635 // which is not always wanted
636 // This function replaces paragraphs by linebreaks.
637 int parFrom, parTo, indFrom, indTo;
638 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
648 t.replace ("</p>","<br />");
651 e->setCursorPosition (parFrom,indFrom);
653 // Tried to simply insert the changed text with
654 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
655 // but then the html would be quoted. So I use the ugly
656 // way: insert a marker, replace it in whole text of QTextEdit
657 QString marker="R3PlAcEMeL4teR!";
659 e->setText (e->text().replace(marker,t));
664 void TextEditor::textJoinLines()
666 int parFrom, parTo, indFrom, indTo;
667 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
673 // In addition to textConvertPar it is sometimes
674 // useful to join all lines of a paragraph
675 QRegExp re("</p>\n+<p>(?!</p>)");
679 // Above we may have introduced new " " at beginning of a
680 // paragraph - remove it.
681 re.setPattern("<p> ");
682 t.replace (re,"<p>");
685 e->setCursorPosition (parFrom,indFrom);
687 // Tried to simply insert the changed text with
688 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
689 // but then the html would be quoted. So I use the ugly
690 // way: insert a marker, replace it in whole text of QTextEdit
691 QString marker="R3PlAcEMeL4teR!";
693 e->setText (e->text().replace(marker,t));
698 void TextEditor::textExportAsASCII()
700 QString text = NoteObj (e->text()).getNoteASCII();
702 if (!filenameHint.isEmpty())
704 if (!filenameHint.contains (".txt"))
705 s=filenameHint+".txt";
710 fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
718 QMessageBox mb( "VYM",
719 tr("The file ") + fn +
720 tr(" exists already. "
721 "Do you want to overwrite it?"),
722 QMessageBox::Warning,
723 QMessageBox::Yes | QMessageBox::Default,
724 QMessageBox::Cancel | QMessageBox::Escape,
725 QMessageBox::NoButton );
726 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
727 mb.setButtonText( QMessageBox::No, tr("Cancel"));
730 if (ret==QMessageBox::Cancel)
734 if ( !file.open( IO_WriteOnly ) )
735 statusBar()->message( QString("Could not write to %1").arg(filename),
739 QTextStream t( &file );
743 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
749 void TextEditor::textPrint()
751 printer->setFullPage(TRUE);
752 if ( printer->setup( this ) )
754 QPainter p( printer );
755 // Check that there is a valid device to print to.
756 if ( !p.device() ) return;
757 QPaintDeviceMetrics metrics( p.device() );
758 int dpiy = metrics.logicalDpiY();
759 int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
760 QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
761 QFont font( e->currentFont() );
762 font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
764 QSimpleRichText richText( e->text(), font,
767 e->mimeSourceFactory(),
769 richText.setWidth( &p, body.width() );
774 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
775 view.moveBy( 0, body.height() );
776 p.translate( 0 , -body.height() );
778 p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
779 view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
780 if ( view.top() >= richText.height() )
788 void TextEditor::textEditUndo()
792 void TextEditor::toggleFonthint()
794 setUpdatesEnabled (false);
796 if (!actionFormatUseFixedFont->isOn() )
797 e->setCurrentFont (varFont);
799 e->setCurrentFont (fixedFont);
800 e->selectAll (false);
801 setUpdatesEnabled (true);
805 void TextEditor::setFixedFont()
808 QFont font =QFontDialog::getFont(
809 &ok, fixedFont, this );
811 // font is set to the font the user selected
815 void TextEditor::setVarFont()
818 QFont font =QFontDialog::getFont(
819 &ok, varFont, this );
821 // font is set to the font the user selected
825 void TextEditor::textBold()
827 e->setBold( actionTextBold->isOn() );
830 void TextEditor::textUnderline()
832 e->setUnderline( actionTextUnderline->isOn() );
835 void TextEditor::textItalic()
837 e->setItalic( actionTextItalic->isOn() );
840 void TextEditor::textFamily( const QString &f )
845 void TextEditor::textSize( const QString &p )
847 e->setPointSize( p.toInt() );
851 void TextEditor::textColor()
853 QColor col = QColorDialog::getColor( e->color(), this );
854 if ( !col.isValid() )
857 QPixmap pix( 16, 16 );
859 actionTextColor->setIconSet( pix );
862 void TextEditor::textAlign( QAction *a )
864 if ( a == actionAlignLeft )
865 e->setAlignment( AlignLeft );
866 else if ( a == actionAlignCenter )
867 e->setAlignment( AlignHCenter );
868 else if ( a == actionAlignRight )
869 e->setAlignment( AlignRight );
870 else if ( a == actionAlignJustify )
871 e->setAlignment( AlignJustify );
874 void TextEditor::textVAlign()
876 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
877 e->setVerticalAlignment( QTextEdit::AlignSuperScript);
878 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
879 e->setVerticalAlignment( QTextEdit::AlignSubScript);
881 e->setVerticalAlignment( QTextEdit::AlignNormal);
886 void TextEditor::fontChanged( const QFont &f )
888 comboFont->lineEdit()->setText( f.family() );
889 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
890 actionTextBold->setOn( f.bold() );
891 actionTextItalic->setOn( f.italic() );
892 actionTextUnderline->setOn( f.underline() );
895 void TextEditor::colorChanged( const QColor &c )
897 QPixmap pix( 16, 16 );
899 actionTextColor->setIconSet( pix );
902 void TextEditor::alignmentChanged( int a )
904 if ( ( a == AlignAuto ) || ( a & AlignLeft ))
905 actionAlignLeft->setOn( true );
906 else if ( ( a & AlignHCenter ) )
907 actionAlignCenter->setOn( true );
908 else if ( ( a & AlignRight ) )
909 actionAlignRight->setOn( true );
910 else if ( ( a & AlignJustify ) )
911 actionAlignJustify->setOn( true );
914 void TextEditor::verticalAlignmentChanged(int a)
916 if (a == QTextEdit::AlignSuperScript ) {
917 actionAlignSuperScript->setOn(true);
918 actionAlignSubScript->setOn(false);
919 } else if (a == QTextEdit::AlignSubScript ) {
920 actionAlignSuperScript->setOn(false);
921 actionAlignSubScript->setOn(true);
923 actionAlignSuperScript->setOn(false);
924 actionAlignSubScript->setOn(false);
930 void TextEditor::enableActions()
932 actionFileLoad->setEnabled(true);
933 actionFileSave->setEnabled(true);
934 actionFileSaveAs->setEnabled(true);
935 actionFilePrint->setEnabled(true);
936 actionEditUndo->setEnabled(true);
937 actionEditRedo->setEnabled(true);
938 actionEditCopy->setEnabled(true);
939 actionEditCut->setEnabled(true);
940 actionEditPaste->setEnabled(true);
941 actionEditDeleteAll->setEnabled(true);
942 actionEditConvertPar->setEnabled(true);
943 actionEditJoinLines->setEnabled(true);
944 actionFormatUseFixedFont->setEnabled(true);
947 void TextEditor::disableActions()
949 actionFileLoad->setEnabled(false);
950 actionFileSave->setEnabled(false);
951 actionFileSaveAs->setEnabled(false);
952 actionFilePrint->setEnabled(false);
953 actionEditUndo->setEnabled(false);
954 actionEditRedo->setEnabled(false);
955 actionEditCopy->setEnabled(false);
956 actionEditCut->setEnabled(false);
957 actionEditPaste->setEnabled(false);
958 actionEditDeleteAll->setEnabled(false);
959 actionEditConvertPar->setEnabled(false);
960 actionEditJoinLines->setEnabled(false);
961 actionFormatUseFixedFont->setEnabled(false);