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 /* FIXME not needed any longer? remove also from docu...
318 a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
319 a->setShortcut( Qt::ALT + Qt::Key_P );
320 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
321 editMenu->addAction (a);
323 actionEditConvertPar=a;
325 a = new QAction( QPixmap(), tr( "&Join lines" ), this);
326 /* FIXME not needed any longer? remove also from docu...
327 a->setStatusTip(tr( "Join all lines of a paragraph" ) );
328 a->setShortcut(Qt::ALT + Qt::Key_J );
329 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
330 editMenu->addAction (a);
332 actionEditJoinLines=a;
335 void TextEditor::setupFormatActions()
337 QToolBar *tb = addToolBar ( tr("Format Actions" ));
338 QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
342 a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
343 a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
344 a->setToggleAction (true);
345 a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
346 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
347 formatMenu->addAction (a);
349 actionFormatUseFixedFont=a;
351 // comboFont = new QComboBox( true, tb );
352 comboFont = new QComboBox;
353 tb->addWidget (comboFont);
354 QFontDatabase fontDB;
355 comboFont->insertStringList( fontDB.families() );
356 connect( comboFont, SIGNAL( activated( const QString & ) ),
357 this, SLOT( textFamily( const QString & ) ) );
358 comboFont->addItem( QApplication::font().family() );
359 comboSize = new QComboBox;
360 tb->addWidget (comboSize);
361 QList<int> sizes=fontDB.standardSizes();
362 QList<int>::iterator i = sizes.begin();
363 while (i != sizes.end())
365 ++i; // increment i before using it
366 comboSize->insertItem ( QString::number(*i));
368 connect( comboSize, SIGNAL( activated( const QString & ) ),
369 this, SLOT( textSize( const QString & ) ) );
370 comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
372 formatMenu->addSeparator();
374 QPixmap pix( 16, 16 );
375 pix.fill( e->color());
376 a = new QAction( pix, tr( "&Color..." ), this);
377 formatMenu->addAction (a);
379 connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
382 a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
383 a->setShortcut(Qt::CTRL + Qt::Key_B );
384 connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
386 formatMenu->addAction (a);
387 a->setToggleAction( true );
390 a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
391 a->setShortcut(Qt::CTRL + Qt::Key_I);
392 connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
394 formatMenu->addAction (a);
395 a->setToggleAction( true );
398 a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
399 a->setShortcut(Qt::CTRL + Qt::Key_U );
400 connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
402 formatMenu->addAction (a);
403 a->setToggleAction( true );
404 actionTextUnderline=a;
405 formatMenu->addSeparator();
407 QActionGroup *grp = new QActionGroup( this );
408 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
410 a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
411 a->setShortcut( Qt::CTRL+Qt::Key_L );
412 a->setToggleAction( true );
414 formatMenu->addAction (a);
416 a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
417 a->setShortcut( Qt::CTRL + Qt::Key_E);
418 a->setToggleAction( true );
420 formatMenu->addAction (a);
422 a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
423 a->setShortcut(Qt::CTRL + Qt::Key_R );
424 a->setToggleAction( true );
426 formatMenu->addAction (a);
428 a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
429 a->setShortcut(Qt::CTRL + Qt::Key_J );
430 a->setToggleAction( true );
432 formatMenu->addAction (a);
433 actionAlignJustify=a;
435 QActionGroup *grp2 = new QActionGroup( this );
436 grp2->setExclusive(true);
437 a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
438 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
439 a->setToggleAction( true );
441 formatMenu->addAction (a);
442 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
443 actionAlignSubScript=a;
445 a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
446 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
447 a->setToggleAction( true );
449 formatMenu->addAction (a);
450 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
451 actionAlignSuperScript=a;
453 formatMenu->addSeparator();
455 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
456 this, SLOT( fontChanged( const QFont & ) ) );
457 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
458 this, SLOT( colorChanged( const QColor & ) ) );
460 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
461 this, SLOT( alignmentChanged( int ) ) );
462 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
463 this, SLOT( verticalAlignmentChanged(int)));
468 void TextEditor::setupSettingsActions()
470 QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
473 a = new QAction(tr( "Set &fixed font" ), this);
474 a->setStatusTip ( tr( "Set fixed font" ));
475 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
476 settingsMenu->addAction (a);
477 actionSettingsFixedFont=a;
479 a = new QAction(tr( "Set &variable font" ), this);
480 a->setStatusTip ( tr( "Set variable font" ) );
481 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
482 settingsMenu->addAction (a);
483 actionSettingsVarFont=a;
485 a = new QAction(tr( "&fixed font is default" ), this);
486 a->setStatusTip (tr( "Used fixed font by default" ) );
487 a->setToggleAction (true);
488 // set state later in constructor...
489 settingsMenu->addAction (a);
490 actionSettingsFonthintDefault=a;
493 void TextEditor::textLoad()
495 if (state!=inactiveEditor)
497 if (e->text().length())
499 QMessageBox mb( __VYM " - " +tr("Note Editor"),
500 "Loading will overwrite the existing note",
501 QMessageBox::Warning,
502 QMessageBox::Yes | QMessageBox::Default,
505 mb.setButtonText( QMessageBox::Yes, "Load note" );
506 switch( mb.exec() ) {
507 case QMessageBox::Cancel:
513 QFileDialog *fd=new QFileDialog( this);
515 types<< "VYM notes (*.html)" <<
516 "ASCII texts (*.txt)" <<
518 fd->setFilters (types);
519 fd->setDirectory (QDir().current());
522 if ( fd->exec() == QDialog::Accepted )
523 fn = fd->selectedFile();
528 if ( !f.open( QIODevice::ReadOnly ) )
531 QTextStream ts( &f );
532 setText( ts.read() );
538 void TextEditor::closeEvent( QCloseEvent* ce )
540 ce->accept(); // TextEditor can be reopened with show()
541 actionViewToggleNoteEditor->setOn (false);
546 QString TextEditor::getText()
548 if (e->toPlainText().isEmpty())
554 void TextEditor::editorChanged()
561 if (state==emptyEditor)
562 setState (emptyEditor);
564 setState (filledEditor);
565 // SLOT is LinkableMapObj, which will update systemFlag
566 emit (textHasChanged() );
570 void TextEditor::setText(QString t)
572 e->setReadOnly(false);
577 void TextEditor::setInactive()
579 state=inactiveEditor;
581 setState (inactiveEditor);
582 e->setReadOnly (true);
587 void TextEditor::editCopyAll()
593 void TextEditor::textSaveAs()
595 QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
596 this,"export note dialog",tr("Export Note to single file") );
603 QMessageBox mb( __VYM,
604 tr("The file ") + fn +
605 tr(" exists already. "
606 "Do you want to overwrite it?"),
607 QMessageBox::Warning,
608 QMessageBox::Yes | QMessageBox::Default,
609 QMessageBox::Cancel | QMessageBox::Escape,
611 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
612 mb.setButtonText( QMessageBox::No, tr("Cancel"));
613 switch( mb.exec() ) {
614 case QMessageBox::Yes:
619 case QMessageBox::Cancel:
630 statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
634 void TextEditor::textSave()
636 if ( filename.isEmpty() )
642 QString text = e->text();
644 if ( !f.open( QIODevice::WriteOnly ) )
646 statusBar()->message( QString("Could not write to %1").arg(filename),
655 e->setModified( FALSE );
657 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
660 void TextEditor::textConvertPar()
662 // In X11 a copy&paste generates paragraphs,
663 // which is not always wanted
664 // This function replaces paragraphs by linebreaks.
671 t.replace ("</p>","<br />");
674 /* FIXME QT3 use seletion ()
675 int parFrom, parTo, indFrom, indTo;
676 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
685 t.replace ("</p>","<br />");
688 e->setCursorPosition (parFrom,indFrom);
690 // Tried to simply insert the changed text with
691 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
692 // but then the html would be quoted. So I use the ugly
693 // way: insert a marker, replace it in whole text of QTextEdit
694 QString marker="R3PlAcEMeL4teR!";
696 e->setText (e->text().replace(marker,t));
702 void TextEditor::textJoinLines()
705 int parFrom, parTo, indFrom, indTo;
706 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
712 // In addition to textConvertPar it is sometimes
713 // useful to join all lines of a paragraph
714 QRegExp re("</p>\n+<p>(?!</p>)");
718 // Above we may have introduced new " " at beginning of a
719 // paragraph - remove it.
720 re.setPattern("<p> ");
721 t.replace (re,"<p>");
724 e->setCursorPosition (parFrom,indFrom);
726 // Tried to simply insert the changed text with
727 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
728 // but then the html would be quoted. So I use the ugly
729 // way: insert a marker, replace it in whole text of QTextEdit
730 QString marker="R3PlAcEMeL4teR!";
732 e->setText (e->text().replace(marker,t));
738 void TextEditor::textExportAsASCII()
740 QString text = NoteObj (e->text()).getNoteASCII();
742 if (!filenameHint.isEmpty())
744 if (!filenameHint.contains (".txt"))
745 s=filenameHint+".txt";
750 fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
758 QMessageBox mb( "VYM",
759 tr("The file ") + fn +
760 tr(" exists already. "
761 "Do you want to overwrite it?"),
762 QMessageBox::Warning,
763 QMessageBox::Yes | QMessageBox::Default,
764 QMessageBox::Cancel | QMessageBox::Escape,
766 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
767 mb.setButtonText( QMessageBox::No, tr("Cancel"));
770 if (ret==QMessageBox::Cancel)
774 if ( !file.open( QIODevice::WriteOnly ) )
775 statusBar()->message( QString("Could not write to %1").arg(filename),
779 QTextStream t( &file );
783 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
789 void TextEditor::textPrint()
792 QTextDocument *document = e->document();
795 QPrintDialog *dialog = new QPrintDialog(&printer, this);
796 dialog->setWindowTitle(tr("Print Document"));
797 if (dialog->exec() != QDialog::Accepted)
800 document->print(&printer);
803 void TextEditor::textEditUndo()
807 void TextEditor::toggleFonthint()
809 setUpdatesEnabled (false);
811 if (!actionFormatUseFixedFont->isOn() )
812 e->setCurrentFont (varFont);
814 e->setCurrentFont (fixedFont);
816 setUpdatesEnabled (true);
820 void TextEditor::setFixedFont()
823 QFont font =QFontDialog::getFont(
824 &ok, fixedFont, this );
826 // font is set to the font the user selected
830 void TextEditor::setVarFont()
833 QFont font =QFontDialog::getFont(
834 &ok, varFont, this );
836 // font is set to the font the user selected
840 void TextEditor::textBold()
842 e->setBold( actionTextBold->isOn() );
845 void TextEditor::textUnderline()
847 e->setUnderline( actionTextUnderline->isOn() );
850 void TextEditor::textItalic()
852 e->setItalic( actionTextItalic->isOn() );
855 void TextEditor::textFamily( const QString &f )
860 void TextEditor::textSize( const QString &p )
862 e->setPointSize( p.toInt() );
866 void TextEditor::textColor()
868 QColor col = QColorDialog::getColor( e->color(), this );
869 if ( !col.isValid() )
872 QPixmap pix( 16, 16 );
873 pix.fill( Qt::black );
874 actionTextColor->setIconSet( pix );
877 void TextEditor::textAlign( QAction *a )
879 if ( a == actionAlignLeft )
880 e->setAlignment( Qt::AlignLeft );
881 else if ( a == actionAlignCenter )
882 e->setAlignment( Qt::AlignHCenter );
883 else if ( a == actionAlignRight )
884 e->setAlignment( Qt::AlignRight );
885 else if ( a == actionAlignJustify )
886 e->setAlignment( Qt::AlignJustify );
889 void TextEditor::textVAlign()
892 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
893 e->setVerticalAlignment( QTextEdit::AlignSuperScript);
894 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
895 e->setVerticalAlignment( QTextEdit::AlignSubScript);
897 e->setVerticalAlignment( QTextEdit::AlignNormal);
903 void TextEditor::fontChanged( const QFont &f )
906 comboFont->lineEdit()->setText( f.family() );
907 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
909 actionTextBold->setOn( f.bold() );
910 actionTextItalic->setOn( f.italic() );
911 actionTextUnderline->setOn( f.underline() );
914 void TextEditor::colorChanged( const QColor &c )
916 QPixmap pix( 16, 16 );
918 actionTextColor->setIconSet( pix );
921 void TextEditor::alignmentChanged( int a )
923 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
924 actionAlignLeft->setOn( true );
925 else if ( ( a & Qt::AlignHCenter ) )
926 actionAlignCenter->setOn( true );
927 else if ( ( a & Qt::AlignRight ) )
928 actionAlignRight->setOn( true );
929 else if ( ( a & Qt::AlignJustify ) )
930 actionAlignJustify->setOn( true );
933 void TextEditor::verticalAlignmentChanged(int a)
936 if (a == QTextEdit::AlignSuperScript ) {
937 actionAlignSuperScript->setOn(true);
938 actionAlignSubScript->setOn(false);
939 } else if (a == QTextEdit::AlignSubScript ) {
940 actionAlignSuperScript->setOn(false);
941 actionAlignSubScript->setOn(true);
943 actionAlignSuperScript->setOn(false);
944 actionAlignSubScript->setOn(false);
951 void TextEditor::enableActions()
953 actionFileLoad->setEnabled(true);
954 actionFileSave->setEnabled(true);
955 actionFileSaveAs->setEnabled(true);
956 actionFilePrint->setEnabled(true);
957 actionEditUndo->setEnabled(true);
958 actionEditRedo->setEnabled(true);
959 actionEditCopy->setEnabled(true);
960 actionEditCut->setEnabled(true);
961 actionEditPaste->setEnabled(true);
962 actionEditDeleteAll->setEnabled(true);
963 actionEditConvertPar->setEnabled(true);
964 actionEditJoinLines->setEnabled(true);
965 actionFormatUseFixedFont->setEnabled(true);
968 void TextEditor::disableActions()
970 actionFileLoad->setEnabled(false);
971 actionFileSave->setEnabled(false);
972 actionFileSaveAs->setEnabled(false);
973 actionFilePrint->setEnabled(false);
974 actionEditUndo->setEnabled(false);
975 actionEditRedo->setEnabled(false);
976 actionEditCopy->setEnabled(false);
977 actionEditCut->setEnabled(false);
978 actionEditPaste->setEnabled(false);
979 actionEditDeleteAll->setEnabled(false);
980 actionEditConvertPar->setEnabled(false);
981 actionEditJoinLines->setEnabled(false);
982 actionFormatUseFixedFont->setEnabled(false);
985 void TextEditor::setState (EditorState s)
988 QPalette p=palette();
992 case emptyEditor: c=QColor (150,150,150); break;
993 case filledEditor: c=QColor (255,255,255); break;
994 case inactiveEditor: c=QColor (0,0,0);
996 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
997 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);