1 #include "texteditor.h"
9 extern int statusbarTime;
10 extern Settings settings;
12 extern QAction *actionViewToggleNoteEditor;
14 extern QString iconPath;
15 extern QString vymName;
20 ///////////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////////////////////////////////////
24 TextEditor::TextEditor()
26 printer = new QPrinter( QPrinter::HighResolution );
27 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
29 e = new QTextEdit( this);
31 e->setTextFormat(Qt::RichText); // default
32 e->setTabStopWidth (20); // unit is pixel
33 e->setColor (Qt::black);
34 e->setAutoFillBackground (true);
35 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
36 setCentralWidget( e );
37 statusBar()->message( tr("Ready","Statusbar message"), statusbarTime);
38 setCaption(vymName +" - " +tr ("Note Editor","Window caption"));
41 connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
42 this, SLOT(formatChanged(const QTextCharFormat &)));
50 setupSettingsActions();
53 blockChangedSignal=false;
57 resize (settings.value ( "/satellite/noteeditor/geometry/size", QSize(450,600)).toSize());
58 move (settings.value ( "/satellite/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
60 setShowWithMain (settings.value ( "/satellite/noteeditor/showWithMain",true).toBool());
62 varFont.fromString( settings.value
63 ("/satellite/noteeditor/fonts/varFont",
64 "Nimbus Sans l,10,-1,5,48,0,0,0,0,0").toString()
66 fixedFont.fromString (settings.value(
67 "/satellite/noteeditor/fonts/fixedFont",
68 "Courier,10-1,5,48,0,0,0,1,0").toString()
70 QString s=settings.value ("/satellite/noteeditor/fonts/fonthintDefault","variable").toString();
73 actionSettingsFonthintDefault->setOn (true);
74 e->setCurrentFont (fixedFont);
77 actionSettingsFonthintDefault->setOn (false);
78 e->setCurrentFont (varFont);
82 // Restore position of toolbars
83 restoreState (settings.value("/satellite/noteeditor/state",0).toByteArray());
85 // Save settings in vymrc
86 settings.setValue("/mainwindow/printerName",printer->printerName());
90 TextEditor::~TextEditor()
92 if (printer) delete printer;
94 settings.setValue( "/satellite/noteeditor/geometry/size", size() );
95 settings.setValue( "/satellite/noteeditor/geometry/pos", pos() );
96 settings.setValue ("/satellite/noteeditor/state",saveState(0));
98 settings.setValue( "/satellite/noteeditor/showWithMain",showwithmain);
101 if (actionSettingsFonthintDefault->isOn() )
105 settings.setValue( "/satellite/noteeditor/fonts/fonthintDefault",s );
106 settings.setValue("/satellite/noteeditor/fonts/varFont", varFont.toString() );
107 settings.setValue("/satellite/noteeditor/fonts/fixedFont", fixedFont.toString() );
112 void TextEditor::reset()
115 actionFormatUseFixedFont->setOn (false);
116 actionTextBold->setOn (false);
119 actionTextUnderline->setOn (false);
120 e->setUnderline (false);
122 actionTextItalic->setOn (false);
123 e->setItalic (false);
125 QPixmap pix( 16, 16 );
126 pix.fill( Qt::black );
127 actionTextColor->setIconSet( pix );
128 e->setColor (Qt::black);
130 actionAlignSubScript->setOn (false);
131 actionAlignSuperScript->setOn (false);
132 actionAlignLeft->setOn (true);
133 e->setAlignment( Qt::AlignLeft );
136 bool TextEditor::isEmpty()
138 if (e->toPlainText().length()>0)
144 void TextEditor::setShowWithMain(bool v)
149 bool TextEditor::showWithMain()
155 void TextEditor::setFontHint (const QString &fh)
158 actionFormatUseFixedFont->setOn (true);
160 actionFormatUseFixedFont->setOn (false);
164 QString TextEditor::getFontHint()
166 if (actionFormatUseFixedFont->isOn())
172 QString TextEditor::getFontHintDefault()
174 if (actionSettingsFonthintDefault->isOn())
180 void TextEditor::setFilename(const QString &fn)
182 if (state==filledEditor)
187 statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime );
192 statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime );
197 QString TextEditor::getFilename()
202 void TextEditor::setFilenameHint(const QString &fnh)
207 QString TextEditor::getFilenameHint()
212 QString TextEditor::getText()
214 if (e->toPlainText().isEmpty())
220 NoteObj TextEditor::getNoteObj()
222 NoteObj note (getText() );
223 note.setFontHint (getFontHint() );
224 note.setFilenameHint (getFilenameHint () );
228 void TextEditor::setNote (const NoteObj ¬e)
230 setText (note.getNote() );
231 setFilenameHint (note.getFilenameHint() );
232 setFontHint (note.getFontHint() );
235 bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
237 if (e->find (t,flags))
243 bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags, int i)
245 // Position at beginning
246 QTextCursor c=e->textCursor();
247 c.setPosition (0,QTextCursor::MoveAnchor);
248 e->setTextCursor (c);
254 if (!e->find (t,flags)) return false;
261 void TextEditor::setTextCursor (const QTextCursor &cursor)
263 e->setTextCursor (cursor);
266 QTextCursor TextEditor::getTextCursor()
268 return e->textCursor();
271 void TextEditor::setupFileActions()
273 QToolBar *tb = addToolBar ( tr("Note Actions") );
274 tb->setObjectName ("noteEditorFileActions");
275 QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" ));
278 a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
279 a->setStatusTip (tr( "Import","Status tip for Note menu" ) );
280 a->setShortcut( Qt::CTRL + Qt::Key_O );
281 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
283 fileMenu->addAction (a);
286 fileMenu->addSeparator();
287 a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
288 a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) );
289 a->setShortcut( Qt::CTRL + Qt::Key_S );
290 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
292 fileMenu->addAction (a);
295 a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
296 a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu" ));
297 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
298 fileMenu->addAction (a);
301 a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
302 a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) );
303 a->setShortcut(Qt::ALT + Qt::Key_X );
304 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
305 fileMenu->addAction (a);
308 fileMenu->addSeparator();
309 a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
310 a->setStatusTip (tr( "Print Note","Status tip for note menu" ) );
311 a->setShortcut( Qt::CTRL + Qt::Key_P );
312 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
314 fileMenu->addAction (a);
318 void TextEditor::setupEditActions()
320 QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
321 tb->setObjectName ("noteEditorEditActions");
322 QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
325 a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
326 a->setStatusTip ( tr( "Undo","Status tip for note menu" ) );
327 a->setShortcut(Qt::CTRL + Qt::Key_Z );
328 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
329 editMenu->addAction (a);
333 a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
334 a->setStatusTip ( tr( "Redo","Status tip for note menu" ) );
335 a->setShortcut( Qt::CTRL + Qt::Key_Y );
336 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
337 editMenu->addAction (a);
341 editMenu->addSeparator();
342 a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
343 a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) );
344 a->setShortcut( Qt::CTRL + Qt::Key_A );
345 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
346 editMenu->addAction (a);
348 editMenu->addSeparator();
349 a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
350 a->setStatusTip ( tr( "Copy","Status tip for note menu" ) );
351 a->setShortcut( Qt::CTRL + Qt::Key_C );
352 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
353 editMenu->addAction (a);
357 a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
358 a->setStatusTip ( tr( "Cut","Status tip for note menu" ) );
359 a->setShortcut( Qt::CTRL + Qt::Key_X );
360 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
361 editMenu->addAction (a);
365 a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
366 a->setStatusTip ( tr( "Paste","Status tip for note menu" ) );
367 a->setShortcut( Qt::CTRL + Qt::Key_V );
368 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
369 editMenu->addAction (a);
373 a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
374 a->setStatusTip (tr( "Delete all","Status tip for note menu" ) );
375 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
376 editMenu->addAction (a);
378 actionEditDeleteAll=a;
382 void TextEditor::setupFormatActions()
384 QToolBar *tb = addToolBar ( tr("Format Actions" ));
385 tb->setObjectName ("noteEditorFormatActions");
386 QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
390 a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
391 a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) );
392 a->setToggleAction (true);
393 a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
394 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
395 formatMenu->addAction (a);
397 actionFormatUseFixedFont=a;
399 comboFont = new QComboBox;
400 tb->addWidget (comboFont);
401 QFontDatabase fontDB;
402 comboFont->insertStringList( fontDB.families() );
403 connect( comboFont, SIGNAL( activated( const QString & ) ),
404 this, SLOT( textFamily( const QString & ) ) );
405 comboFont->addItem( QApplication::font().family() );
406 comboSize = new QComboBox;
407 tb->addWidget (comboSize);
408 QList<int> sizes=fontDB.standardSizes();
409 QList<int>::iterator i = sizes.begin();
410 while (i != sizes.end())
412 ++i; // increment i before using it
413 comboSize->insertItem ( QString::number(*i));
415 connect( comboSize, SIGNAL( activated( const QString & ) ),
416 this, SLOT( textSize( const QString & ) ) );
417 comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
419 formatMenu->addSeparator();
421 QPixmap pix( 16, 16 );
422 pix.fill( e->color());
423 a = new QAction( pix, tr( "&Color..." ), this);
424 formatMenu->addAction (a);
426 connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
429 a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
430 a->setShortcut(Qt::CTRL + Qt::Key_B );
431 connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
433 formatMenu->addAction (a);
434 a->setToggleAction( true );
437 a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
438 a->setShortcut(Qt::CTRL + Qt::Key_I);
439 connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
441 formatMenu->addAction (a);
442 a->setToggleAction( true );
445 a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
446 a->setShortcut(Qt::CTRL + Qt::Key_U );
447 connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
449 formatMenu->addAction (a);
450 a->setToggleAction( true );
451 actionTextUnderline=a;
452 formatMenu->addSeparator();
454 QActionGroup *grp2 = new QActionGroup( this );
455 grp2->setExclusive(true);
456 a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
457 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
458 a->setToggleAction( true );
460 formatMenu->addAction (a);
461 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
462 actionAlignSubScript=a;
464 a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
465 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
466 a->setToggleAction( true );
468 formatMenu->addAction (a);
469 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
470 actionAlignSuperScript=a;
471 QActionGroup *grp = new QActionGroup( this );
472 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
474 formatMenu->addSeparator();
476 a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
477 a->setShortcut( Qt::CTRL+Qt::Key_L );
478 a->setToggleAction( true );
480 formatMenu->addAction (a);
482 a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
483 a->setShortcut( Qt::CTRL + Qt::Key_E);
484 a->setToggleAction( true );
486 formatMenu->addAction (a);
488 a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
489 a->setShortcut(Qt::CTRL + Qt::Key_R );
490 a->setToggleAction( true );
492 formatMenu->addAction (a);
494 a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
495 a->setShortcut(Qt::CTRL + Qt::Key_J );
496 a->setToggleAction( true );
498 formatMenu->addAction (a);
499 actionAlignJustify=a;
502 void TextEditor::setupSettingsActions()
504 QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
507 a = new QAction(tr( "Set &fixed font" ), this);
508 a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" ));
509 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
510 settingsMenu->addAction (a);
511 actionSettingsFixedFont=a;
513 a = new QAction(tr( "Set &variable font" ), this);
514 a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) );
515 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
516 settingsMenu->addAction (a);
517 actionSettingsVarFont=a;
519 a = new QAction(tr( "&fixed font is default" ), this);
520 a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) );
521 a->setToggleAction (true);
522 // set state later in constructor...
523 settingsMenu->addAction (a);
524 actionSettingsFonthintDefault=a;
527 void TextEditor::textLoad()
529 if (state!=inactiveEditor)
533 QMessageBox mb( vymName + " - " +tr("Note Editor"),
534 "Loading will overwrite the existing note",
535 QMessageBox::Warning,
536 QMessageBox::Yes | QMessageBox::Default,
539 mb.setButtonText( QMessageBox::Yes, "Load note" );
540 switch( mb.exec() ) {
541 case QMessageBox::Cancel:
547 QFileDialog *fd=new QFileDialog( this);
549 types<< "Text (*.txt *.html)"<<
550 "VYM notes and HTML (*.html)" <<
551 "ASCII texts (*.txt)" <<
553 fd->setFilters (types);
554 fd->setDirectory (QDir().current());
557 if ( fd->exec() == QDialog::Accepted )
558 fn = fd->selectedFile();
563 if ( !f.open( QIODevice::ReadOnly ) )
566 QTextStream ts( &f );
567 setText( ts.read() );
573 void TextEditor::closeEvent( QCloseEvent* ce )
575 ce->accept(); // TextEditor can be reopened with show()
578 emit (windowClosed() );
582 void TextEditor::editorChanged()
589 if (state==emptyEditor)
590 setState (emptyEditor);
592 setState (filledEditor);
593 // SLOT is LinkableMapObj, which will update systemFlag
594 if (!blockChangedSignal) emit (textHasChanged() );
598 void TextEditor::setText(const QString &t)
600 blockChangedSignal=true;
601 e->setReadOnly(false);
603 if (Qt::mightBeRichText (t))
607 actionFormatUseFixedFont->setChecked (true);
611 blockChangedSignal=false;
614 void TextEditor::setInactive()
616 state=inactiveEditor;
618 setState (inactiveEditor);
619 e->setReadOnly (true);
624 void TextEditor::editCopyAll()
630 void TextEditor::textSaveAs()
632 QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
633 this,"export note dialog",tr("Export Note to single file") );
640 QMessageBox mb( vymName,
641 tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
642 QMessageBox::Warning,
643 QMessageBox::Yes | QMessageBox::Default,
644 QMessageBox::Cancel | QMessageBox::Escape,
646 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
647 mb.setButtonText( QMessageBox::No, tr("Cancel"));
648 switch( mb.exec() ) {
649 case QMessageBox::Yes:
654 case QMessageBox::Cancel:
665 statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime );
669 void TextEditor::textSave()
671 if ( filename.isEmpty() )
677 QString text = e->text();
679 if ( !f.open( QIODevice::WriteOnly ) )
681 statusBar()->message( QString("Could not write to %1").arg(filename),
690 e->setModified( FALSE );
692 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
695 void TextEditor::textExportAsASCII()
697 QString text = NoteObj (e->text()).getNoteASCII();
699 if (!filenameHint.isEmpty())
701 if (!filenameHint.contains (".txt"))
702 s=filenameHint+".txt";
707 fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
715 QMessageBox mb( vymName,
716 tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
717 QMessageBox::Warning,
718 QMessageBox::Yes | QMessageBox::Default,
719 QMessageBox::Cancel | QMessageBox::Escape,
721 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
722 mb.setButtonText( QMessageBox::No, tr("Cancel"));
725 if (ret==QMessageBox::Cancel)
729 if ( !file.open( QIODevice::WriteOnly ) )
730 statusBar()->message( QString("Could not write to %1").arg(filename),
734 QTextStream t( &file );
738 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
744 void TextEditor::textPrint()
747 QTextDocument *document = e->document();
750 QPrintDialog *dialog = new QPrintDialog(&printer, this);
751 dialog->setWindowTitle(tr("Print Note"));
752 if (dialog->exec() != QDialog::Accepted)
755 document->print(&printer);
758 void TextEditor::textEditUndo()
762 void TextEditor::toggleFonthint()
764 setUpdatesEnabled (false);
766 if (!actionFormatUseFixedFont->isOn() )
767 e->setCurrentFont (varFont);
769 e->setCurrentFont (fixedFont);
771 setUpdatesEnabled (true);
775 void TextEditor::setFixedFont()
778 QFont font =QFontDialog::getFont(
779 &ok, fixedFont, this );
781 // font is set to the font the user selected
785 void TextEditor::setVarFont()
788 QFont font =QFontDialog::getFont(
789 &ok, varFont, this );
791 // font is set to the font the user selected
795 void TextEditor::textBold()
797 e->setBold( actionTextBold->isOn() );
800 void TextEditor::textUnderline()
802 e->setUnderline( actionTextUnderline->isOn() );
805 void TextEditor::textItalic()
807 e->setItalic( actionTextItalic->isOn() );
810 void TextEditor::textFamily( const QString &f )
815 void TextEditor::textSize( const QString &p )
817 e->setPointSize( p.toInt() );
821 void TextEditor::textColor()
823 QColor col = QColorDialog::getColor( e->color(), this );
824 if ( !col.isValid() ) return;
826 QPixmap pix( 16, 16 );
827 pix.fill( Qt::black );
828 actionTextColor->setIconSet( pix );
831 void TextEditor::textAlign( QAction *a )
833 qDebug()<<"TE::textAlign";
834 QTextCursor c=e->textCursor();
835 c.setPosition (3,QTextCursor::MoveAnchor);
836 e->setTextCursor (c);
838 if ( a == actionAlignLeft )
839 e->setAlignment( Qt::AlignLeft );
840 else if ( a == actionAlignCenter )
841 e->setAlignment( Qt::AlignHCenter );
842 else if ( a == actionAlignRight )
843 e->setAlignment( Qt::AlignRight );
844 else if ( a == actionAlignJustify )
845 e->setAlignment( Qt::AlignJustify );
848 void TextEditor::textVAlign()
850 QTextCharFormat format;
852 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
853 format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
854 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
855 format.setVerticalAlignment(QTextCharFormat::AlignSubScript);
857 format.setVerticalAlignment(QTextCharFormat::AlignNormal);
859 e->mergeCurrentCharFormat(format);
863 void TextEditor::fontChanged( const QFont &f )
865 int i=comboFont->findText(f.family());
866 if (i>=0) comboFont->setCurrentIndex (i);
867 i=comboSize->findText(QString::number(f.pointSize()));
868 if (i>=0) comboSize->setCurrentIndex(i);
869 actionTextBold->setOn( f.bold() );
870 actionTextItalic->setOn( f.italic() );
871 actionTextUnderline->setOn( f.underline() );
874 void TextEditor::colorChanged( const QColor &c )
876 QPixmap pix( 16, 16 );
878 actionTextColor->setIconSet( pix );
881 void TextEditor::formatChanged( const QTextCharFormat &f )
883 fontChanged(f.font());
884 colorChanged(f.foreground().color());
885 alignmentChanged(e->alignment());
886 verticalAlignmentChanged (f.verticalAlignment());
889 void TextEditor::alignmentChanged( int a )
891 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
892 actionAlignLeft->setOn( true );
893 else if ( ( a & Qt::AlignHCenter ) )
894 actionAlignCenter->setOn( true );
895 else if ( ( a & Qt::AlignRight ) )
896 actionAlignRight->setOn( true );
897 else if ( ( a & Qt::AlignJustify ) )
898 actionAlignJustify->setOn( true );
901 void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a)
903 actionAlignSubScript->setOn (false);
904 actionAlignSuperScript->setOn (false);
907 case QTextCharFormat::AlignSuperScript:
908 actionAlignSuperScript->setOn (true);
910 case QTextCharFormat::AlignSubScript:
911 actionAlignSubScript->setOn (true);
919 void TextEditor::enableActions()
921 actionFileLoad->setEnabled(true);
922 actionFileSave->setEnabled(true);
923 actionFileSaveAs->setEnabled(true);
924 actionFilePrint->setEnabled(true);
925 actionEditUndo->setEnabled(true);
926 actionEditRedo->setEnabled(true);
927 actionEditCopy->setEnabled(true);
928 actionEditCut->setEnabled(true);
929 actionEditPaste->setEnabled(true);
930 actionEditDeleteAll->setEnabled(true);
931 actionFormatUseFixedFont->setEnabled(true);
934 void TextEditor::disableActions()
936 actionFileLoad->setEnabled(false);
937 actionFileSave->setEnabled(false);
938 actionFileSaveAs->setEnabled(false);
939 actionFilePrint->setEnabled(false);
940 actionEditUndo->setEnabled(false);
941 actionEditRedo->setEnabled(false);
942 actionEditCopy->setEnabled(false);
943 actionEditCut->setEnabled(false);
944 actionEditPaste->setEnabled(false);
945 actionEditDeleteAll->setEnabled(false);
946 actionFormatUseFixedFont->setEnabled(false);
949 void TextEditor::setState (EditorState s)
952 QPalette p=palette();
956 case emptyEditor: c=QColor (150,150,150); break;
957 case filledEditor: c=QColor (255,255,255); break;
958 case inactiveEditor: c=QColor (0,0,0);
960 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
961 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);