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.value("/mainwindow/printerName",printer->printerName()).toString());
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.value ( "/noteeditor/geometry/size", QSize(450,600)).toSize());
68 move (settings.value ( "/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
70 if (settings.value ( "/noteeditor/showWithMain",true).toBool())
71 setShowWithMain(true);
73 setShowWithMain(false);
75 varFont.fromString( settings.value
76 ("/noteeditor/fonts/varFont",
77 "Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString()
79 fixedFont.fromString (settings.value(
80 "/noteeditor/fonts/fixedFont",
81 "Courier,14,-1,5,48,0,0,0,1,0").toString()
83 QString s=settings.value ("/noteeditor/fonts/fonthintDefault","variable").toString();
86 actionSettingsFonthintDefault->setOn (true);
87 e->setCurrentFont (fixedFont);
90 actionSettingsFonthintDefault->setOn (false);
91 e->setCurrentFont (varFont);
95 // Save settings in vymrc
96 settings.setValue("/mainwindow/printerName",printer->printerName());
100 TextEditor::~TextEditor()
102 if (printer) delete printer;
104 settings.setValue( "/noteeditor/geometry/size", size() );
105 settings.setValue( "/noteeditor/geometry/pos", pos() );
107 settings.setValue( "/noteeditor/showWithMain",showWithMain());
110 if (actionSettingsFonthintDefault->isOn() )
114 settings.setValue( "/noteeditor/fonts/fonthintDefault",s );
115 settings.setValue("/noteeditor/fonts/varFont", varFont.toString() );
116 settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() );
119 bool TextEditor::isEmpty()
121 if (e->toPlainText().length()>0)
127 void TextEditor::setShowWithMain(bool v)
132 bool TextEditor::showWithMain()
137 void TextEditor::setFontHint (const QString &fh)
140 actionFormatUseFixedFont->setOn (true);
142 actionFormatUseFixedFont->setOn (false);
146 QString TextEditor::getFontHint()
148 if (actionFormatUseFixedFont->isOn())
154 QString TextEditor::getFontHintDefault()
156 if (actionSettingsFonthintDefault->isOn())
162 void TextEditor::setFilename(const QString &fn)
164 if (state==filledEditor)
168 statusBar()->message( "No filename available for this note.", statusbarTime );
173 statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
177 QString TextEditor::getFilename()
182 void TextEditor::setFilenameHint(const QString &fnh)
187 QString TextEditor::getFilenameHint()
192 bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
194 if (e->find (t,flags))
200 void TextEditor::setupFileActions()
202 QToolBar *tb = addToolBar ( tr("Note Actions") );
203 QMenu *fileMenu = menuBar()->addMenu( tr( "&Note" ));
206 a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
207 a->setStatusTip (tr( "Import" ) );
208 a->setShortcut( Qt::CTRL + Qt::Key_O );
209 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
211 fileMenu->addAction (a);
214 fileMenu->addSeparator();
215 a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
216 a->setStatusTip (tr( "Export Note (HTML)" ) );
217 a->setShortcut( Qt::CTRL + Qt::Key_S );
218 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
220 fileMenu->addAction (a);
223 a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
224 a->setStatusTip (tr( "Export Note As (HTML) " ));
225 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
226 fileMenu->addAction (a);
229 a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
230 a->setStatusTip ( tr( "Export Note As (ASCII) " ) );
231 a->setShortcut(Qt::ALT + Qt::Key_X );
232 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
233 fileMenu->addAction (a);
236 fileMenu->addSeparator();
237 a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
238 a->setStatusTip (tr( "Print Note" ) );
239 a->setShortcut( Qt::CTRL + Qt::Key_P );
240 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
242 fileMenu->addAction (a);
246 void TextEditor::setupEditActions()
248 QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
249 QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
252 a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
253 a->setStatusTip ( tr( "Undo" ) );
254 a->setShortcut(Qt::CTRL + Qt::Key_Z );
255 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
256 editMenu->addAction (a);
260 a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
261 a->setStatusTip ( tr( "Redo" ) );
262 a->setShortcut( Qt::CTRL + Qt::Key_Y );
263 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
264 editMenu->addAction (a);
268 editMenu->addSeparator();
269 a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
270 a->setStatusTip ( tr( "Select and copy all" ) );
271 a->setShortcut( Qt::CTRL + Qt::Key_A );
272 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
273 editMenu->addAction (a);
275 editMenu->addSeparator();
276 a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
277 a->setStatusTip ( tr( "Copy" ) );
278 a->setShortcut( Qt::CTRL + Qt::Key_C );
279 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
280 editMenu->addAction (a);
284 a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
285 a->setStatusTip ( tr( "Cut" ) );
286 a->setShortcut( Qt::CTRL + Qt::Key_X );
287 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
288 editMenu->addAction (a);
292 a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
293 a->setStatusTip ( tr( "Paste" ) );
294 a->setShortcut( Qt::CTRL + Qt::Key_V );
295 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
296 editMenu->addAction (a);
300 a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
301 a->setStatusTip (tr( "Delete all" ) );
302 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
303 editMenu->addAction (a);
305 actionEditDeleteAll=a;
307 a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
308 /* TODO not needed any longer? remove also from docu...
309 a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
310 a->setShortcut( Qt::ALT + Qt::Key_P );
311 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
312 editMenu->addAction (a);
314 actionEditConvertPar=a;
316 a = new QAction( QPixmap(), tr( "&Join lines" ), this);
317 /* TODO not needed any longer? remove also from docu...
318 a->setStatusTip(tr( "Join all lines of a paragraph" ) );
319 a->setShortcut(Qt::ALT + Qt::Key_J );
320 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
321 editMenu->addAction (a);
323 actionEditJoinLines=a;
326 void TextEditor::setupFormatActions()
328 QToolBar *tb = addToolBar ( tr("Format Actions" ));
329 QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
333 a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
334 a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
335 a->setToggleAction (true);
336 a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
337 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
338 formatMenu->addAction (a);
340 actionFormatUseFixedFont=a;
342 // comboFont = new QComboBox( true, tb );
343 comboFont = new QComboBox;
344 tb->addWidget (comboFont);
345 QFontDatabase fontDB;
346 comboFont->insertStringList( fontDB.families() );
347 connect( comboFont, SIGNAL( activated( const QString & ) ),
348 this, SLOT( textFamily( const QString & ) ) );
349 comboFont->addItem( QApplication::font().family() );
350 comboSize = new QComboBox;
351 tb->addWidget (comboSize);
352 QList<int> sizes=fontDB.standardSizes();
353 QList<int>::iterator i = sizes.begin();
354 while (i != sizes.end())
356 ++i; // increment i before using it
357 comboSize->insertItem ( QString::number(*i));
359 connect( comboSize, SIGNAL( activated( const QString & ) ),
360 this, SLOT( textSize( const QString & ) ) );
361 comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
363 formatMenu->addSeparator();
365 QPixmap pix( 16, 16 );
366 pix.fill( e->color());
367 a = new QAction( pix, tr( "&Color..." ), this);
368 formatMenu->addAction (a);
370 connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
373 a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
374 a->setShortcut(Qt::CTRL + Qt::Key_B );
375 connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
377 formatMenu->addAction (a);
378 a->setToggleAction( true );
381 a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
382 a->setShortcut(Qt::CTRL + Qt::Key_I);
383 connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
385 formatMenu->addAction (a);
386 a->setToggleAction( true );
389 a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
390 a->setShortcut(Qt::CTRL + Qt::Key_U );
391 connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
393 formatMenu->addAction (a);
394 a->setToggleAction( true );
395 actionTextUnderline=a;
396 formatMenu->addSeparator();
398 QActionGroup *grp = new QActionGroup( this );
399 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
401 a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
402 a->setShortcut( Qt::CTRL+Qt::Key_L );
403 a->setToggleAction( true );
405 formatMenu->addAction (a);
407 a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
408 a->setShortcut( Qt::CTRL + Qt::Key_E);
409 a->setToggleAction( true );
411 formatMenu->addAction (a);
413 a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
414 a->setShortcut(Qt::CTRL + Qt::Key_R );
415 a->setToggleAction( true );
417 formatMenu->addAction (a);
419 a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
420 a->setShortcut(Qt::CTRL + Qt::Key_J );
421 a->setToggleAction( true );
423 formatMenu->addAction (a);
424 actionAlignJustify=a;
426 QActionGroup *grp2 = new QActionGroup( this );
427 grp2->setExclusive(true);
428 a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
429 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
430 a->setToggleAction( true );
432 formatMenu->addAction (a);
433 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
434 actionAlignSubScript=a;
436 a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
437 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
438 a->setToggleAction( true );
440 formatMenu->addAction (a);
441 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
442 actionAlignSuperScript=a;
444 formatMenu->addSeparator();
446 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
447 this, SLOT( fontChanged( const QFont & ) ) );
448 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
449 this, SLOT( colorChanged( const QColor & ) ) );
451 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
452 this, SLOT( alignmentChanged( int ) ) );
453 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
454 this, SLOT( verticalAlignmentChanged(int)));
459 void TextEditor::setupSettingsActions()
461 QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
464 a = new QAction(tr( "Set &fixed font" ), this);
465 a->setStatusTip ( tr( "Set fixed font" ));
466 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
467 settingsMenu->addAction (a);
468 actionSettingsFixedFont=a;
470 a = new QAction(tr( "Set &variable font" ), this);
471 a->setStatusTip ( tr( "Set variable font" ) );
472 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
473 settingsMenu->addAction (a);
474 actionSettingsVarFont=a;
476 a = new QAction(tr( "&fixed font is default" ), this);
477 a->setStatusTip (tr( "Used fixed font by default" ) );
478 a->setToggleAction (true);
479 // set state later in constructor...
480 settingsMenu->addAction (a);
481 actionSettingsFonthintDefault=a;
484 void TextEditor::textLoad()
486 if (state!=inactiveEditor)
488 if (e->text().length())
490 QMessageBox mb( __VYM " - " +tr("Note Editor"),
491 "Loading will overwrite the existing note",
492 QMessageBox::Warning,
493 QMessageBox::Yes | QMessageBox::Default,
496 mb.setButtonText( QMessageBox::Yes, "Load note" );
497 switch( mb.exec() ) {
498 case QMessageBox::Cancel:
504 QFileDialog *fd=new QFileDialog( this);
506 types<< "VYM notes (*.html)" <<
507 "ASCII texts (*.txt)" <<
509 fd->setFilters (types);
510 fd->setDirectory (QDir().current());
513 if ( fd->exec() == QDialog::Accepted )
514 fn = fd->selectedFile();
519 if ( !f.open( QIODevice::ReadOnly ) )
522 QTextStream ts( &f );
523 setText( ts.read() );
529 void TextEditor::closeEvent( QCloseEvent* ce )
531 ce->accept(); // TextEditor can be reopened with show()
532 actionViewToggleNoteEditor->setOn (false);
537 QString TextEditor::getText()
539 if (e->toPlainText().isEmpty())
545 void TextEditor::editorChanged()
552 if (state==emptyEditor)
553 setState (emptyEditor);
555 setState (filledEditor);
556 // SLOT is LinkableMapObj, which will update systemFlag
557 emit (textHasChanged() );
561 void TextEditor::setText(QString t)
563 e->setReadOnly(false);
568 void TextEditor::setInactive()
570 state=inactiveEditor;
572 setState (inactiveEditor);
573 e->setReadOnly (true);
578 void TextEditor::editCopyAll()
584 void TextEditor::textSaveAs()
586 QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
587 this,"export note dialog",tr("Export Note to single file") );
594 QMessageBox mb( __VYM,
595 tr("The file ") + fn +
596 tr(" exists already. "
597 "Do you want to overwrite it?"),
598 QMessageBox::Warning,
599 QMessageBox::Yes | QMessageBox::Default,
600 QMessageBox::Cancel | QMessageBox::Escape,
602 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
603 mb.setButtonText( QMessageBox::No, tr("Cancel"));
604 switch( mb.exec() ) {
605 case QMessageBox::Yes:
610 case QMessageBox::Cancel:
621 statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
625 void TextEditor::textSave()
627 if ( filename.isEmpty() )
633 QString text = e->text();
635 if ( !f.open( QIODevice::WriteOnly ) )
637 statusBar()->message( QString("Could not write to %1").arg(filename),
646 e->setModified( FALSE );
648 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
651 void TextEditor::textConvertPar()
653 // In X11 a copy&paste generates paragraphs,
654 // which is not always wanted
655 // This function replaces paragraphs by linebreaks.
662 t.replace ("</p>","<br />");
665 /* TODO QT3 use seletion ()
666 int parFrom, parTo, indFrom, indTo;
667 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
676 t.replace ("</p>","<br />");
679 e->setCursorPosition (parFrom,indFrom);
681 // Tried to simply insert the changed text with
682 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
683 // but then the html would be quoted. So I use the ugly
684 // way: insert a marker, replace it in whole text of QTextEdit
685 QString marker="R3PlAcEMeL4teR!";
687 e->setText (e->text().replace(marker,t));
693 void TextEditor::textJoinLines()
696 int parFrom, parTo, indFrom, indTo;
697 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
703 // In addition to textConvertPar it is sometimes
704 // useful to join all lines of a paragraph
705 QRegExp re("</p>\n+<p>(?!</p>)");
709 // Above we may have introduced new " " at beginning of a
710 // paragraph - remove it.
711 re.setPattern("<p> ");
712 t.replace (re,"<p>");
715 e->setCursorPosition (parFrom,indFrom);
717 // Tried to simply insert the changed text with
718 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
719 // but then the html would be quoted. So I use the ugly
720 // way: insert a marker, replace it in whole text of QTextEdit
721 QString marker="R3PlAcEMeL4teR!";
723 e->setText (e->text().replace(marker,t));
729 void TextEditor::textExportAsASCII()
731 QString text = NoteObj (e->text()).getNoteASCII();
733 if (!filenameHint.isEmpty())
735 if (!filenameHint.contains (".txt"))
736 s=filenameHint+".txt";
741 fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
749 QMessageBox mb( "VYM",
750 tr("The file ") + fn +
751 tr(" exists already. "
752 "Do you want to overwrite it?"),
753 QMessageBox::Warning,
754 QMessageBox::Yes | QMessageBox::Default,
755 QMessageBox::Cancel | QMessageBox::Escape,
757 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
758 mb.setButtonText( QMessageBox::No, tr("Cancel"));
761 if (ret==QMessageBox::Cancel)
765 if ( !file.open( QIODevice::WriteOnly ) )
766 statusBar()->message( QString("Could not write to %1").arg(filename),
770 QTextStream t( &file );
774 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
780 void TextEditor::textPrint()
783 QTextDocument *document = e->document();
786 QPrintDialog *dialog = new QPrintDialog(&printer, this);
787 dialog->setWindowTitle(tr("Print Document"));
788 if (dialog->exec() != QDialog::Accepted)
791 document->print(&printer);
794 void TextEditor::textEditUndo()
798 void TextEditor::toggleFonthint()
800 setUpdatesEnabled (false);
802 if (!actionFormatUseFixedFont->isOn() )
803 e->setCurrentFont (varFont);
805 e->setCurrentFont (fixedFont);
807 setUpdatesEnabled (true);
811 void TextEditor::setFixedFont()
814 QFont font =QFontDialog::getFont(
815 &ok, fixedFont, this );
817 // font is set to the font the user selected
821 void TextEditor::setVarFont()
824 QFont font =QFontDialog::getFont(
825 &ok, varFont, this );
827 // font is set to the font the user selected
831 void TextEditor::textBold()
833 e->setBold( actionTextBold->isOn() );
836 void TextEditor::textUnderline()
838 e->setUnderline( actionTextUnderline->isOn() );
841 void TextEditor::textItalic()
843 e->setItalic( actionTextItalic->isOn() );
846 void TextEditor::textFamily( const QString &f )
851 void TextEditor::textSize( const QString &p )
853 e->setPointSize( p.toInt() );
857 void TextEditor::textColor()
859 QColor col = QColorDialog::getColor( e->color(), this );
860 if ( !col.isValid() )
863 QPixmap pix( 16, 16 );
864 pix.fill( Qt::black );
865 actionTextColor->setIconSet( pix );
868 void TextEditor::textAlign( QAction *a )
870 if ( a == actionAlignLeft )
871 e->setAlignment( Qt::AlignLeft );
872 else if ( a == actionAlignCenter )
873 e->setAlignment( Qt::AlignHCenter );
874 else if ( a == actionAlignRight )
875 e->setAlignment( Qt::AlignRight );
876 else if ( a == actionAlignJustify )
877 e->setAlignment( Qt::AlignJustify );
880 void TextEditor::textVAlign()
882 /* FIXME QT3 alignment
883 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
884 e->setVerticalAlignment( QTextEdit::AlignSuperScript);
885 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
886 e->setVerticalAlignment( QTextEdit::AlignSubScript);
888 e->setVerticalAlignment( QTextEdit::AlignNormal);
894 void TextEditor::fontChanged( const QFont &f )
897 comboFont->lineEdit()->setText( f.family() );
898 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
900 actionTextBold->setOn( f.bold() );
901 actionTextItalic->setOn( f.italic() );
902 actionTextUnderline->setOn( f.underline() );
905 void TextEditor::colorChanged( const QColor &c )
907 QPixmap pix( 16, 16 );
909 actionTextColor->setIconSet( pix );
912 void TextEditor::alignmentChanged( int a )
914 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
915 actionAlignLeft->setOn( true );
916 else if ( ( a & Qt::AlignHCenter ) )
917 actionAlignCenter->setOn( true );
918 else if ( ( a & Qt::AlignRight ) )
919 actionAlignRight->setOn( true );
920 else if ( ( a & Qt::AlignJustify ) )
921 actionAlignJustify->setOn( true );
924 void TextEditor::verticalAlignmentChanged(int a)
926 /* FIXME QT3 alignment
927 if (a == QTextEdit::AlignSuperScript ) {
928 actionAlignSuperScript->setOn(true);
929 actionAlignSubScript->setOn(false);
930 } else if (a == QTextEdit::AlignSubScript ) {
931 actionAlignSuperScript->setOn(false);
932 actionAlignSubScript->setOn(true);
934 actionAlignSuperScript->setOn(false);
935 actionAlignSubScript->setOn(false);
942 void TextEditor::enableActions()
944 actionFileLoad->setEnabled(true);
945 actionFileSave->setEnabled(true);
946 actionFileSaveAs->setEnabled(true);
947 actionFilePrint->setEnabled(true);
948 actionEditUndo->setEnabled(true);
949 actionEditRedo->setEnabled(true);
950 actionEditCopy->setEnabled(true);
951 actionEditCut->setEnabled(true);
952 actionEditPaste->setEnabled(true);
953 actionEditDeleteAll->setEnabled(true);
954 actionEditConvertPar->setEnabled(true);
955 actionEditJoinLines->setEnabled(true);
956 actionFormatUseFixedFont->setEnabled(true);
959 void TextEditor::disableActions()
961 actionFileLoad->setEnabled(false);
962 actionFileSave->setEnabled(false);
963 actionFileSaveAs->setEnabled(false);
964 actionFilePrint->setEnabled(false);
965 actionEditUndo->setEnabled(false);
966 actionEditRedo->setEnabled(false);
967 actionEditCopy->setEnabled(false);
968 actionEditCut->setEnabled(false);
969 actionEditPaste->setEnabled(false);
970 actionEditDeleteAll->setEnabled(false);
971 actionEditConvertPar->setEnabled(false);
972 actionEditJoinLines->setEnabled(false);
973 actionFormatUseFixedFont->setEnabled(false);
976 void TextEditor::setState (EditorState s)
979 QPalette p=palette();
983 case emptyEditor: c=QColor (150,150,150); break;
984 case filledEditor: c=QColor (255,255,255); break;
985 case inactiveEditor: c=QColor (0,0,0);
987 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
988 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);