1 #include "texteditor.h"
8 #include <qtextstream.h>
10 #include <QFontDialog>
11 #include <QMessageBox>
12 #include <QColorDialog>
16 #include <QCloseEvent>
25 extern int statusbarTime;
26 extern QSettings settings;
28 extern QAction *actionViewToggleNoteEditor;
30 extern QString iconPath;
35 ///////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////
39 TextEditor::TextEditor()
41 printer = new QPrinter( QPrinter::HighResolution );
42 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
44 // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
45 // int argument. see header file)
46 e = new MyTextEdit( this, "editor" );
48 e->setTextFormat(Qt::RichText); // default
49 e->setTabStopWidth (20); // unit is pixel
50 e->setColor (Qt::black);
51 e->setAutoFillBackground (true);
52 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
53 setCentralWidget( e );
54 statusBar()->message( "Ready", statusbarTime);
55 setCaption(__VYM " - " +tr ("Note Editor"));
61 setupSettingsActions();
67 resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
68 settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
69 move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
70 settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
72 if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
73 setShowWithMain(true);
75 setShowWithMain(false);
77 varFont.fromString( settings.readEntry
78 ("/vym/noteeditor/fonts/varFont",
79 "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
81 fixedFont.fromString (settings.readEntry (
82 "/vym/noteeditor/fonts/fixedFont",
83 "Courier,14,-1,5,48,0,0,0,1,0")
85 QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
88 actionSettingsFonthintDefault->setOn (true);
89 e->setCurrentFont (fixedFont);
92 actionSettingsFonthintDefault->setOn (false);
93 e->setCurrentFont (varFont);
97 // Save settings in vymrc
98 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
102 TextEditor::~TextEditor()
104 if (printer) delete printer;
106 settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
107 settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
108 settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
109 settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
112 settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
114 settings.writeEntry( "/vym/noteeditor/showWithMain","no");
117 if (actionSettingsFonthintDefault->isOn() )
121 settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
122 settings.writeEntry ("/vym/noteeditor/fonts/varFont",
123 varFont.toString() );
124 settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
125 fixedFont.toString() );
128 bool TextEditor::isEmpty()
130 if (e->toPlainText().length()>0)
136 void TextEditor::setShowWithMain(bool v)
141 bool TextEditor::showWithMain()
146 void TextEditor::setFontHint (const QString &fh)
149 actionFormatUseFixedFont->setOn (true);
151 actionFormatUseFixedFont->setOn (false);
155 QString TextEditor::getFontHint()
157 if (actionFormatUseFixedFont->isOn())
163 QString TextEditor::getFontHintDefault()
165 if (actionSettingsFonthintDefault->isOn())
171 void TextEditor::setFilename(const QString &fn)
173 if (state==filledEditor)
177 statusBar()->message( "No filename available for this note.", statusbarTime );
182 statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
186 QString TextEditor::getFilename()
191 void TextEditor::setFilenameHint(const QString &fnh)
196 QString TextEditor::getFilenameHint()
201 bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
203 if (e->find (t,flags))
209 void TextEditor::setupFileActions()
211 QToolBar *tb = addToolBar ( tr("File Actions") );
212 QMenu *fileMenu = menuBar()->addMenu( tr( "&File" ));
215 a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
216 a->setStatusTip (tr( "Import" ) );
217 a->setShortcut( Qt::CTRL + Qt::Key_O );
218 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
220 fileMenu->addAction (a);
223 fileMenu->addSeparator();
224 a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
225 a->setStatusTip (tr( "Export Note (HTML)" ) );
226 a->setShortcut( Qt::CTRL + Qt::Key_S );
227 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
229 fileMenu->addAction (a);
232 a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
233 a->setStatusTip (tr( "Export Note As (HTML) " ));
234 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
235 fileMenu->addAction (a);
238 a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
239 a->setStatusTip ( tr( "Export Note As (ASCII) " ) );
240 a->setShortcut(Qt::ALT + Qt::Key_X );
241 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
242 fileMenu->addAction (a);
245 fileMenu->addSeparator();
246 a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
247 a->setStatusTip (tr( "Print Note" ) );
248 a->setShortcut( Qt::CTRL + Qt::Key_P );
249 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
251 fileMenu->addAction (a);
255 void TextEditor::setupEditActions()
257 QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
258 QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
261 a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
262 a->setStatusTip ( tr( "Undo" ) );
263 a->setShortcut(Qt::CTRL + Qt::Key_Z );
264 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
265 editMenu->addAction (a);
269 a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
270 a->setStatusTip ( tr( "Redo" ) );
271 a->setShortcut( Qt::CTRL + Qt::Key_Y );
272 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
273 editMenu->addAction (a);
277 editMenu->addSeparator();
278 a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
279 a->setStatusTip ( tr( "Select and copy all" ) );
280 a->setShortcut( Qt::CTRL + Qt::Key_A );
281 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
282 editMenu->addAction (a);
284 editMenu->addSeparator();
285 a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
286 a->setStatusTip ( tr( "Copy" ) );
287 a->setShortcut( Qt::CTRL + Qt::Key_C );
288 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
289 editMenu->addAction (a);
293 a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
294 a->setStatusTip ( tr( "Cut" ) );
295 a->setShortcut( Qt::CTRL + Qt::Key_X );
296 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
297 editMenu->addAction (a);
301 a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
302 a->setStatusTip ( tr( "Paste" ) );
303 a->setShortcut( Qt::CTRL + Qt::Key_V );
304 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
305 editMenu->addAction (a);
309 a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
310 a->setStatusTip (tr( "Delete all" ) );
311 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
312 editMenu->addAction (a);
314 actionEditDeleteAll=a;
316 a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
317 a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
318 a->setShortcut( Qt::ALT + Qt::Key_P );
319 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
320 editMenu->addAction (a);
321 actionEditConvertPar=a;
323 a = new QAction( QPixmap(), tr( "&Join lines" ), this);
324 a->setStatusTip(tr( "Join all lines of a paragraph" ) );
325 a->setShortcut(Qt::ALT + Qt::Key_J );
326 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
327 editMenu->addAction (a);
328 actionEditJoinLines=a;
331 void TextEditor::setupFormatActions()
333 QToolBar *tb = addToolBar ( tr("Format Actions" ));
334 QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
338 a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
339 a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
340 a->setToggleAction (true);
341 a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
342 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
343 formatMenu->addAction (a);
345 actionFormatUseFixedFont=a;
347 // comboFont = new QComboBox( true, tb );
348 comboFont = new QComboBox;
349 tb->addWidget (comboFont);
350 QFontDatabase fontDB;
351 comboFont->insertStringList( fontDB.families() );
352 connect( comboFont, SIGNAL( activated( const QString & ) ),
353 this, SLOT( textFamily( const QString & ) ) );
354 comboFont->addItem( QApplication::font().family() );
355 comboSize = new QComboBox;
356 tb->addWidget (comboSize);
357 QList<int> sizes=fontDB.standardSizes();
358 QList<int>::iterator i = sizes.begin();
359 while (i != sizes.end())
361 ++i; // increment i before using it
362 comboSize->insertItem ( QString::number(*i));
364 connect( comboSize, SIGNAL( activated( const QString & ) ),
365 this, SLOT( textSize( const QString & ) ) );
366 comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
368 formatMenu->addSeparator();
370 QPixmap pix( 16, 16 );
371 pix.fill( e->color());
372 a = new QAction( pix, tr( "&Color..." ), this);
373 formatMenu->addAction (a);
375 connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
378 a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
379 a->setShortcut(Qt::CTRL + Qt::Key_B );
380 connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
382 formatMenu->addAction (a);
383 a->setToggleAction( true );
386 a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
387 a->setShortcut(Qt::CTRL + Qt::Key_I);
388 connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
390 formatMenu->addAction (a);
391 a->setToggleAction( true );
394 a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
395 a->setShortcut(Qt::CTRL + Qt::Key_U );
396 connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
398 formatMenu->addAction (a);
399 a->setToggleAction( true );
400 actionTextUnderline=a;
401 formatMenu->addSeparator();
403 QActionGroup *grp = new QActionGroup( this );
404 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
406 a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
407 a->setShortcut( Qt::CTRL+Qt::Key_L );
408 a->setToggleAction( true );
410 formatMenu->addAction (a);
412 a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
413 a->setShortcut( Qt::CTRL + Qt::Key_E);
414 a->setToggleAction( true );
416 formatMenu->addAction (a);
418 a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
419 a->setShortcut(Qt::CTRL + Qt::Key_R );
420 a->setToggleAction( true );
422 formatMenu->addAction (a);
424 a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
425 a->setShortcut(Qt::CTRL + Qt::Key_J );
426 a->setToggleAction( true );
428 formatMenu->addAction (a);
429 actionAlignJustify=a;
431 QActionGroup *grp2 = new QActionGroup( this );
432 grp2->setExclusive(true);
433 a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
434 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
435 a->setToggleAction( true );
437 formatMenu->addAction (a);
438 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
439 actionAlignSubScript=a;
441 a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
442 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
443 a->setToggleAction( true );
445 formatMenu->addAction (a);
446 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
447 actionAlignSuperScript=a;
449 formatMenu->addSeparator();
451 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
452 this, SLOT( fontChanged( const QFont & ) ) );
453 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
454 this, SLOT( colorChanged( const QColor & ) ) );
456 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
457 this, SLOT( alignmentChanged( int ) ) );
458 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
459 this, SLOT( verticalAlignmentChanged(int)));
464 void TextEditor::setupSettingsActions()
466 QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
469 a = new QAction(tr( "Set &fixed font" ), this);
470 a->setStatusTip ( tr( "Set fixed font" ));
471 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
472 settingsMenu->addAction (a);
473 actionSettingsFixedFont=a;
475 a = new QAction(tr( "Set &variable font" ), this);
476 a->setStatusTip ( tr( "Set variable font" ) );
477 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
478 settingsMenu->addAction (a);
479 actionSettingsVarFont=a;
481 a = new QAction(tr( "&fixed font is default" ), this);
482 a->setStatusTip (tr( "Used fixed font by default" ) );
483 a->setToggleAction (true);
484 // set state later in constructor...
485 settingsMenu->addAction (a);
486 actionSettingsFonthintDefault=a;
489 void TextEditor::textLoad()
491 if (state!=inactiveEditor)
493 if (e->text().length())
495 QMessageBox mb( __VYM " - " +tr("Note Editor"),
496 "Loading will overwrite the existing note",
497 QMessageBox::Warning,
498 QMessageBox::Yes | QMessageBox::Default,
501 mb.setButtonText( QMessageBox::Yes, "Load note" );
502 switch( mb.exec() ) {
503 case QMessageBox::Cancel:
509 QFileDialog *fd=new QFileDialog( this);
511 types<< "VYM notes (*.html)" <<
512 "ASCII texts (*.txt)" <<
514 fd->setFilters (types);
515 fd->setDirectory (QDir().current());
518 if ( fd->exec() == QDialog::Accepted )
519 fn = fd->selectedFile();
524 if ( !f.open( QIODevice::ReadOnly ) )
527 QTextStream ts( &f );
528 setText( ts.read() );
534 void TextEditor::closeEvent( QCloseEvent* ce )
536 ce->accept(); // TextEditor can be reopened with show()
537 actionViewToggleNoteEditor->setOn (false);
542 QString TextEditor::getText()
544 if (e->toPlainText().isEmpty())
550 void TextEditor::editorChanged()
557 if (state==emptyEditor)
558 setState (emptyEditor);
560 setState (filledEditor);
561 // SLOT is LinkableMapObj, which will update systemFlag
562 emit (textHasChanged() );
566 void TextEditor::setText(QString t)
568 e->setReadOnly(false);
573 void TextEditor::setInactive()
575 state=inactiveEditor;
577 setState (inactiveEditor);
578 e->setReadOnly (true);
583 void TextEditor::editCopyAll()
589 void TextEditor::textSaveAs()
591 QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
592 this,"export note dialog",tr("Export Note to single file") );
599 QMessageBox mb( __VYM,
600 tr("The file ") + fn +
601 tr(" exists already. "
602 "Do you want to overwrite it?"),
603 QMessageBox::Warning,
604 QMessageBox::Yes | QMessageBox::Default,
605 QMessageBox::Cancel | QMessageBox::Escape,
607 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
608 mb.setButtonText( QMessageBox::No, tr("Cancel"));
609 switch( mb.exec() ) {
610 case QMessageBox::Yes:
615 case QMessageBox::Cancel:
626 statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
630 void TextEditor::textSave()
632 if ( filename.isEmpty() )
638 QString text = e->text();
640 if ( !f.open( QIODevice::WriteOnly ) )
642 statusBar()->message( QString("Could not write to %1").arg(filename),
651 e->setModified( FALSE );
653 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
656 void TextEditor::textConvertPar()
658 // In X11 a copy&paste generates paragraphs,
659 // which is not always wanted
660 // This function replaces paragraphs by linebreaks.
662 e->setBackgroundRole (QPalette::Text);
670 t.replace ("</p>","<br />");
673 /* FIXME QT3 use seletion ()
674 int parFrom, parTo, indFrom, indTo;
675 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
684 t.replace ("</p>","<br />");
687 e->setCursorPosition (parFrom,indFrom);
689 // Tried to simply insert the changed text with
690 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
691 // but then the html would be quoted. So I use the ugly
692 // way: insert a marker, replace it in whole text of QTextEdit
693 QString marker="R3PlAcEMeL4teR!";
695 e->setText (e->text().replace(marker,t));
701 void TextEditor::textJoinLines()
703 e->setBackgroundRole (QPalette::Light);
707 int parFrom, parTo, indFrom, indTo;
708 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
714 // In addition to textConvertPar it is sometimes
715 // useful to join all lines of a paragraph
716 QRegExp re("</p>\n+<p>(?!</p>)");
720 // Above we may have introduced new " " at beginning of a
721 // paragraph - remove it.
722 re.setPattern("<p> ");
723 t.replace (re,"<p>");
726 e->setCursorPosition (parFrom,indFrom);
728 // Tried to simply insert the changed text with
729 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
730 // but then the html would be quoted. So I use the ugly
731 // way: insert a marker, replace it in whole text of QTextEdit
732 QString marker="R3PlAcEMeL4teR!";
734 e->setText (e->text().replace(marker,t));
740 void TextEditor::textExportAsASCII()
742 QString text = NoteObj (e->text()).getNoteASCII();
744 if (!filenameHint.isEmpty())
746 if (!filenameHint.contains (".txt"))
747 s=filenameHint+".txt";
752 fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
760 QMessageBox mb( "VYM",
761 tr("The file ") + fn +
762 tr(" exists already. "
763 "Do you want to overwrite it?"),
764 QMessageBox::Warning,
765 QMessageBox::Yes | QMessageBox::Default,
766 QMessageBox::Cancel | QMessageBox::Escape,
768 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
769 mb.setButtonText( QMessageBox::No, tr("Cancel"));
772 if (ret==QMessageBox::Cancel)
776 if ( !file.open( QIODevice::WriteOnly ) )
777 statusBar()->message( QString("Could not write to %1").arg(filename),
781 QTextStream t( &file );
785 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
791 void TextEditor::textPrint()
794 QTextDocument *document = e->document();
797 QPrintDialog *dialog = new QPrintDialog(&printer, this);
798 dialog->setWindowTitle(tr("Print Document"));
799 if (dialog->exec() != QDialog::Accepted)
802 document->print(&printer);
805 void TextEditor::textEditUndo()
809 void TextEditor::toggleFonthint()
811 setUpdatesEnabled (false);
813 if (!actionFormatUseFixedFont->isOn() )
814 e->setCurrentFont (varFont);
816 e->setCurrentFont (fixedFont);
818 setUpdatesEnabled (true);
822 void TextEditor::setFixedFont()
825 QFont font =QFontDialog::getFont(
826 &ok, fixedFont, this );
828 // font is set to the font the user selected
832 void TextEditor::setVarFont()
835 QFont font =QFontDialog::getFont(
836 &ok, varFont, this );
838 // font is set to the font the user selected
842 void TextEditor::textBold()
844 e->setBold( actionTextBold->isOn() );
847 void TextEditor::textUnderline()
849 e->setUnderline( actionTextUnderline->isOn() );
852 void TextEditor::textItalic()
854 e->setItalic( actionTextItalic->isOn() );
857 void TextEditor::textFamily( const QString &f )
862 void TextEditor::textSize( const QString &p )
864 e->setPointSize( p.toInt() );
868 void TextEditor::textColor()
870 QColor col = QColorDialog::getColor( e->color(), this );
871 if ( !col.isValid() )
874 QPixmap pix( 16, 16 );
875 pix.fill( Qt::black );
876 actionTextColor->setIconSet( pix );
879 void TextEditor::textAlign( QAction *a )
881 if ( a == actionAlignLeft )
882 e->setAlignment( Qt::AlignLeft );
883 else if ( a == actionAlignCenter )
884 e->setAlignment( Qt::AlignHCenter );
885 else if ( a == actionAlignRight )
886 e->setAlignment( Qt::AlignRight );
887 else if ( a == actionAlignJustify )
888 e->setAlignment( Qt::AlignJustify );
891 void TextEditor::textVAlign()
894 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
895 e->setVerticalAlignment( QTextEdit::AlignSuperScript);
896 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
897 e->setVerticalAlignment( QTextEdit::AlignSubScript);
899 e->setVerticalAlignment( QTextEdit::AlignNormal);
905 void TextEditor::fontChanged( const QFont &f )
908 comboFont->lineEdit()->setText( f.family() );
909 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
911 actionTextBold->setOn( f.bold() );
912 actionTextItalic->setOn( f.italic() );
913 actionTextUnderline->setOn( f.underline() );
916 void TextEditor::colorChanged( const QColor &c )
918 QPixmap pix( 16, 16 );
920 actionTextColor->setIconSet( pix );
923 void TextEditor::alignmentChanged( int a )
925 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
926 actionAlignLeft->setOn( true );
927 else if ( ( a & Qt::AlignHCenter ) )
928 actionAlignCenter->setOn( true );
929 else if ( ( a & Qt::AlignRight ) )
930 actionAlignRight->setOn( true );
931 else if ( ( a & Qt::AlignJustify ) )
932 actionAlignJustify->setOn( true );
935 void TextEditor::verticalAlignmentChanged(int a)
938 if (a == QTextEdit::AlignSuperScript ) {
939 actionAlignSuperScript->setOn(true);
940 actionAlignSubScript->setOn(false);
941 } else if (a == QTextEdit::AlignSubScript ) {
942 actionAlignSuperScript->setOn(false);
943 actionAlignSubScript->setOn(true);
945 actionAlignSuperScript->setOn(false);
946 actionAlignSubScript->setOn(false);
953 void TextEditor::enableActions()
955 actionFileLoad->setEnabled(true);
956 actionFileSave->setEnabled(true);
957 actionFileSaveAs->setEnabled(true);
958 actionFilePrint->setEnabled(true);
959 actionEditUndo->setEnabled(true);
960 actionEditRedo->setEnabled(true);
961 actionEditCopy->setEnabled(true);
962 actionEditCut->setEnabled(true);
963 actionEditPaste->setEnabled(true);
964 actionEditDeleteAll->setEnabled(true);
965 actionEditConvertPar->setEnabled(true);
966 actionEditJoinLines->setEnabled(true);
967 actionFormatUseFixedFont->setEnabled(true);
970 void TextEditor::disableActions()
972 actionFileLoad->setEnabled(false);
973 actionFileSave->setEnabled(false);
974 actionFileSaveAs->setEnabled(false);
975 actionFilePrint->setEnabled(false);
976 actionEditUndo->setEnabled(false);
977 actionEditRedo->setEnabled(false);
978 actionEditCopy->setEnabled(false);
979 actionEditCut->setEnabled(false);
980 actionEditPaste->setEnabled(false);
981 actionEditDeleteAll->setEnabled(false);
982 actionEditConvertPar->setEnabled(false);
983 actionEditJoinLines->setEnabled(false);
984 actionFormatUseFixedFont->setEnabled(false);
987 void TextEditor::setState (EditorState s)
990 QPalette p=palette();
994 case emptyEditor: c=QColor (150,150,150); break;
995 case filledEditor: c=QColor (255,255,255); break;
996 case inactiveEditor: c=QColor (0,0,0);
998 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
999 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);