1 #include "texteditor.h"
7 #include <q3filedialog.h>
9 #include <q3popupmenu.h>
11 #include <q3textedit.h>
12 #include <qtextstream.h>
13 #include <q3paintdevicemetrics.h>
14 #include <qsettings.h>
15 #include <qfontdialog.h>
16 #include <qmessagebox.h>
17 #include <qcolordialog.h>
19 #include <q3simplerichtext.h>
21 #include <Q3ValueList>
23 #include <QCloseEvent>
32 extern Q3Canvas* actCanvas;
33 extern int statusbarTime;
34 extern QSettings settings;
36 extern QAction *actionViewToggleNoteEditor;
38 extern QString iconPath;
43 ///////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////
47 TextEditor::TextEditor()
49 printer = new QPrinter( QPrinter::HighResolution );
50 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
52 // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
53 // int argument. see header file)
54 e = new MyTextEdit( this, "editor" );
56 e->setTextFormat(Qt::RichText); // default
57 e->setTabStopWidth (20); // unit is pixel
58 e->setColor (Qt::black);
59 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
60 setCentralWidget( e );
61 statusBar()->message( "Ready", statusbarTime);
62 setCaption(__VYM " - " +tr ("Note Editor"));
68 setupSettingsActions();
71 emptyPaper = QBrush(Qt::gray);
72 filledPaper = QBrush(Qt::white);
73 inactivePaper= QBrush(Qt::black);
77 resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
78 settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
79 move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
80 settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
82 if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
83 setShowWithMain(true);
85 setShowWithMain(false);
87 varFont.fromString( settings.readEntry
88 ("/vym/noteeditor/fonts/varFont",
89 "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
91 fixedFont.fromString (settings.readEntry (
92 "/vym/noteeditor/fonts/fixedFont",
93 "Courier,14,-1,5,48,0,0,0,1,0")
95 QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
98 actionSettingsFonthintDefault->setOn (true);
99 e->setCurrentFont (fixedFont);
102 actionSettingsFonthintDefault->setOn (false);
103 e->setCurrentFont (varFont);
107 // Save settings in vymrc
108 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
112 TextEditor::~TextEditor()
114 if (printer) delete printer;
116 settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
117 settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
118 settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
119 settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
122 settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
124 settings.writeEntry( "/vym/noteeditor/showWithMain","no");
127 if (actionSettingsFonthintDefault->isOn() )
131 settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
132 settings.writeEntry ("/vym/noteeditor/fonts/varFont",
133 varFont.toString() );
134 settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
135 fixedFont.toString() );
138 bool TextEditor::isEmpty()
140 if (e->text().length())
146 void TextEditor::setShowWithMain(bool v)
151 bool TextEditor::showWithMain()
156 void TextEditor::setFontHint (const QString &fh)
159 actionFormatUseFixedFont->setOn (true);
161 actionFormatUseFixedFont->setOn (false);
165 QString TextEditor::getFontHint()
167 if (actionFormatUseFixedFont->isOn())
173 QString TextEditor::getFontHintDefault()
175 if (actionSettingsFonthintDefault->isOn())
181 void TextEditor::setFilename(const QString &fn)
183 if (state==filledEditor)
187 statusBar()->message( "No filename available for this note.", statusbarTime );
192 statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
196 QString TextEditor::getFilename()
201 void TextEditor::setFilenameHint(const QString &fnh)
206 QString TextEditor::getFilenameHint()
211 bool TextEditor::findText(const QString &t, const bool &cs)
213 bool wo=false; // word matches
214 if (e->find (t, cs, wo, true, 0, 0 ))
220 void TextEditor::setupFileActions()
222 QToolBar *tb = addToolBar ( tr("File Actions") );
223 QMenu *fileMenu = menuBar()->addMenu( tr( "&File" ));
226 a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
227 a->setStatusTip (tr( "Import" ) );
228 a->setShortcut( Qt::CTRL + Qt::Key_O );
229 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
231 fileMenu->addAction (a);
234 fileMenu->addSeparator();
235 a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
236 a->setStatusTip (tr( "Export Note (HTML)" ) );
237 a->setShortcut( Qt::CTRL + Qt::Key_S );
238 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
240 fileMenu->addAction (a);
243 a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
244 a->setStatusTip (tr( "Export Note As (HTML) " ));
245 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
246 fileMenu->addAction (a);
249 a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
250 a->setStatusTip ( tr( "Export Note As (ASCII) " ) );
251 a->setShortcut(Qt::ALT + Qt::Key_X );
252 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
253 fileMenu->addAction (a);
256 fileMenu->addSeparator();
257 a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
258 a->setStatusTip (tr( "Print Note" ) );
259 a->setShortcut( Qt::CTRL + Qt::Key_P );
260 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
262 fileMenu->addAction (a);
266 void TextEditor::setupEditActions()
268 QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
269 QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
272 a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
273 a->setStatusTip ( tr( "Undo" ) );
274 a->setShortcut(Qt::CTRL + Qt::Key_Z );
275 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
276 editMenu->addAction (a);
280 a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
281 a->setStatusTip ( tr( "Redo" ) );
282 a->setShortcut( Qt::CTRL + Qt::Key_Y );
283 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
284 editMenu->addAction (a);
288 editMenu->addSeparator();
289 a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
290 a->setStatusTip ( tr( "Select and copy all" ) );
291 a->setShortcut( Qt::CTRL + Qt::Key_A );
292 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
293 editMenu->addAction (a);
295 editMenu->addSeparator();
296 a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
297 a->setStatusTip ( tr( "Copy" ) );
298 a->setShortcut( Qt::CTRL + Qt::Key_C );
299 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
300 editMenu->addAction (a);
304 a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
305 a->setStatusTip ( tr( "Cut" ) );
306 a->setShortcut( Qt::CTRL + Qt::Key_X );
307 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
308 editMenu->addAction (a);
312 a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
313 a->setStatusTip ( tr( "Paste" ) );
314 a->setShortcut( Qt::CTRL + Qt::Key_V );
315 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
316 editMenu->addAction (a);
320 a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
321 a->setStatusTip (tr( "Delete all" ) );
322 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
323 editMenu->addAction (a);
325 actionEditDeleteAll=a;
327 a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
328 a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
329 a->setShortcut( Qt::ALT + Qt::Key_P );
330 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
331 editMenu->addAction (a);
332 actionEditConvertPar=a;
334 a = new QAction( QPixmap(), tr( "&Join lines" ), this);
335 a->setStatusTip(tr( "Join all lines of a paragraph" ) );
336 a->setShortcut(Qt::ALT + Qt::Key_J );
337 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
338 editMenu->addAction (a);
339 actionEditJoinLines=a;
342 void TextEditor::setupFormatActions()
344 QToolBar *tb = addToolBar ( tr("Format Actions" ));
345 QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
349 a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
350 a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
351 a->setToggleAction (true);
352 a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
353 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
354 formatMenu->addAction (a);
356 actionFormatUseFixedFont=a;
358 // comboFont = new QComboBox( true, tb );
359 comboFont = new QComboBox;
360 tb->addWidget (comboFont);
362 comboFont->insertStringList( db.families() );
363 connect( comboFont, SIGNAL( activated( const QString & ) ),
364 this, SLOT( textFamily( const QString & ) ) );
365 comboFont->addItem( QApplication::font().family() );
366 // comboSize = new QComboBox( true, tb );
367 comboSize = new QComboBox;
368 tb->addWidget (comboSize);
369 Q3ValueList<int> sizes = db.standardSizes();
370 Q3ValueList<int>::Iterator it = sizes.begin();
371 for ( ; it != sizes.end(); ++it )
372 comboSize->insertItem( QString::number( *it ) );
373 connect( comboSize, SIGNAL( activated( const QString & ) ),
374 this, SLOT( textSize( const QString & ) ) );
375 comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
377 formatMenu->addSeparator();
379 QPixmap pix( 16, 16 );
380 pix.fill( e->color());
381 a = new QAction( pix, tr( "&Color..." ), this);
382 formatMenu->addAction (a);
384 connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
387 a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
388 a->setShortcut(Qt::CTRL + Qt::Key_B );
389 connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
391 formatMenu->addAction (a);
392 a->setToggleAction( true );
395 a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
396 a->setShortcut(Qt::CTRL + Qt::Key_I);
397 connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
399 formatMenu->addAction (a);
400 a->setToggleAction( true );
403 a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
404 a->setShortcut(Qt::CTRL + Qt::Key_U );
405 connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
407 formatMenu->addAction (a);
408 a->setToggleAction( true );
409 actionTextUnderline=a;
410 formatMenu->addSeparator();
412 QActionGroup *grp = new QActionGroup( this );
413 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
415 a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
416 a->setShortcut( Qt::CTRL+Qt::Key_L );
417 a->setToggleAction( true );
419 formatMenu->addAction (a);
421 a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
422 a->setShortcut( Qt::CTRL + Qt::Key_E);
423 a->setToggleAction( true );
425 formatMenu->addAction (a);
427 a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
428 a->setShortcut(Qt::CTRL + Qt::Key_R );
429 a->setToggleAction( true );
431 formatMenu->addAction (a);
433 a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
434 a->setShortcut(Qt::CTRL + Qt::Key_J );
435 a->setToggleAction( true );
437 formatMenu->addAction (a);
438 actionAlignJustify=a;
440 QActionGroup *grp2 = new QActionGroup( this );
441 grp2->setExclusive(true);
442 a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
443 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
444 a->setToggleAction( true );
446 formatMenu->addAction (a);
447 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
448 actionAlignSubScript=a;
450 a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
451 a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
452 a->setToggleAction( true );
454 formatMenu->addAction (a);
455 connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
456 actionAlignSuperScript=a;
458 formatMenu->addSeparator();
460 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
461 this, SLOT( fontChanged( const QFont & ) ) );
462 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
463 this, SLOT( colorChanged( const QColor & ) ) );
464 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
465 this, SLOT( alignmentChanged( int ) ) );
466 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
467 this, SLOT( verticalAlignmentChanged(int)));
471 void TextEditor::setupSettingsActions()
473 QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
476 a = new QAction(tr( "Set &fixed font" ), this);
477 a->setStatusTip ( tr( "Set fixed font" ));
478 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
479 settingsMenu->addAction (a);
480 actionSettingsFixedFont=a;
482 a = new QAction(tr( "Set &variable font" ), this);
483 a->setStatusTip ( tr( "Set variable font" ) );
484 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
485 settingsMenu->addAction (a);
486 actionSettingsVarFont=a;
488 a = new QAction(tr( "&fixed font is default" ), this);
489 a->setStatusTip (tr( "Used fixed font by default" ) );
490 a->setToggleAction (true);
491 // set state later in constructor...
492 settingsMenu->addAction (a);
493 actionSettingsFonthintDefault=a;
496 void TextEditor::textLoad()
498 if (state!=inactiveEditor)
502 QMessageBox mb( __VYM " - " +tr("Note Editor"),
503 "Loading will overwrite the existing note",
504 QMessageBox::Warning,
505 QMessageBox::Yes | QMessageBox::Default,
508 mb.setButtonText( QMessageBox::Yes, "Load note" );
509 switch( mb.exec() ) {
510 case QMessageBox::Cancel:
516 Q3FileDialog *fd=new Q3FileDialog( this);
517 fd->addFilter ("ASCII texts (*.txt)");
518 fd->addFilter ("VYM notes (*.html)");
521 if ( fd->exec() == QDialog::Accepted )
522 fn = fd->selectedFile();
527 if ( !f.open( QIODevice::ReadOnly ) )
530 QTextStream ts( &f );
531 setText( ts.read() );
537 void TextEditor::closeEvent( QCloseEvent* ce )
539 ce->accept(); // TextEditor can be reopened with show()
540 actionViewToggleNoteEditor->setOn (false);
545 QString TextEditor::getText()
550 void TextEditor::editorChanged()
557 if (state==emptyEditor)
558 e->setPaper (emptyPaper);
560 e->setPaper (filledPaper);
561 // SLOT is LinkableMapObj, which will update systemFlag
562 emit (textHasChanged() );
566 void TextEditor::setText(QString t)
568 if ( !Q3StyleSheet::mightBeRichText( t ) )
569 t = Q3StyleSheet::convertFromPlainText( t, Q3StyleSheetItem::WhiteSpaceNormal );
570 e->setReadOnly(false);
572 // editorChanged(); //not called automagically FIXME or is it?
577 void TextEditor::setInactive()
579 state=inactiveEditor;
581 e->setPaper (inactivePaper);
582 e->setReadOnly (true);
587 void TextEditor::editCopyAll()
593 void TextEditor::textSaveAs()
595 QString fn = Q3FileDialog::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.
665 int parFrom, parTo, indFrom, indTo;
666 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));
692 void TextEditor::textJoinLines()
694 int parFrom, parTo, indFrom, indTo;
695 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
701 // In addition to textConvertPar it is sometimes
702 // useful to join all lines of a paragraph
703 QRegExp re("</p>\n+<p>(?!</p>)");
707 // Above we may have introduced new " " at beginning of a
708 // paragraph - remove it.
709 re.setPattern("<p> ");
710 t.replace (re,"<p>");
713 e->setCursorPosition (parFrom,indFrom);
715 // Tried to simply insert the changed text with
716 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
717 // but then the html would be quoted. So I use the ugly
718 // way: insert a marker, replace it in whole text of QTextEdit
719 QString marker="R3PlAcEMeL4teR!";
721 e->setText (e->text().replace(marker,t));
726 void TextEditor::textExportAsASCII()
728 QString text = NoteObj (e->text()).getNoteASCII();
730 if (!filenameHint.isEmpty())
732 if (!filenameHint.contains (".txt"))
733 s=filenameHint+".txt";
738 fn = Q3FileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
746 QMessageBox mb( "VYM",
747 tr("The file ") + fn +
748 tr(" exists already. "
749 "Do you want to overwrite it?"),
750 QMessageBox::Warning,
751 QMessageBox::Yes | QMessageBox::Default,
752 QMessageBox::Cancel | QMessageBox::Escape,
754 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
755 mb.setButtonText( QMessageBox::No, tr("Cancel"));
758 if (ret==QMessageBox::Cancel)
762 if ( !file.open( QIODevice::WriteOnly ) )
763 statusBar()->message( QString("Could not write to %1").arg(filename),
767 QTextStream t( &file );
771 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
777 void TextEditor::textPrint()
779 printer->setFullPage(TRUE);
780 if ( printer->setup( this ) )
782 QPainter p( printer );
783 // Check that there is a valid device to print to.
784 if ( !p.device() ) return;
785 Q3PaintDeviceMetrics metrics( p.device() );
786 int dpiy = metrics.logicalDpiY();
787 int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
788 QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
789 QFont font( e->currentFont() );
790 font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
792 Q3SimpleRichText richText( e->text(), font,
795 e->mimeSourceFactory(),
797 richText.setWidth( &p, body.width() );
802 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
803 view.moveBy( 0, body.height() );
804 p.translate( 0 , -body.height() );
806 p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
807 view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
808 if ( view.top() >= richText.height() )
816 void TextEditor::textEditUndo()
820 void TextEditor::toggleFonthint()
822 setUpdatesEnabled (false);
824 if (!actionFormatUseFixedFont->isOn() )
825 e->setCurrentFont (varFont);
827 e->setCurrentFont (fixedFont);
828 e->selectAll (false);
829 setUpdatesEnabled (true);
833 void TextEditor::setFixedFont()
836 QFont font =QFontDialog::getFont(
837 &ok, fixedFont, this );
839 // font is set to the font the user selected
843 void TextEditor::setVarFont()
846 QFont font =QFontDialog::getFont(
847 &ok, varFont, this );
849 // font is set to the font the user selected
853 void TextEditor::textBold()
855 e->setBold( actionTextBold->isOn() );
858 void TextEditor::textUnderline()
860 e->setUnderline( actionTextUnderline->isOn() );
863 void TextEditor::textItalic()
865 e->setItalic( actionTextItalic->isOn() );
868 void TextEditor::textFamily( const QString &f )
873 void TextEditor::textSize( const QString &p )
875 e->setPointSize( p.toInt() );
879 void TextEditor::textColor()
881 QColor col = QColorDialog::getColor( e->color(), this );
882 if ( !col.isValid() )
885 QPixmap pix( 16, 16 );
886 pix.fill( Qt::black );
887 actionTextColor->setIconSet( pix );
890 void TextEditor::textAlign( QAction *a )
892 if ( a == actionAlignLeft )
893 e->setAlignment( Qt::AlignLeft );
894 else if ( a == actionAlignCenter )
895 e->setAlignment( Qt::AlignHCenter );
896 else if ( a == actionAlignRight )
897 e->setAlignment( Qt::AlignRight );
898 else if ( a == actionAlignJustify )
899 e->setAlignment( Qt::AlignJustify );
902 void TextEditor::textVAlign()
904 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
905 e->setVerticalAlignment( Q3TextEdit::AlignSuperScript);
906 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
907 e->setVerticalAlignment( Q3TextEdit::AlignSubScript);
909 e->setVerticalAlignment( Q3TextEdit::AlignNormal);
914 void TextEditor::fontChanged( const QFont &f )
917 comboFont->lineEdit()->setText( f.family() );
918 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
920 actionTextBold->setOn( f.bold() );
921 actionTextItalic->setOn( f.italic() );
922 actionTextUnderline->setOn( f.underline() );
925 void TextEditor::colorChanged( const QColor &c )
927 QPixmap pix( 16, 16 );
929 actionTextColor->setIconSet( pix );
932 void TextEditor::alignmentChanged( int a )
934 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
935 actionAlignLeft->setOn( true );
936 else if ( ( a & Qt::AlignHCenter ) )
937 actionAlignCenter->setOn( true );
938 else if ( ( a & Qt::AlignRight ) )
939 actionAlignRight->setOn( true );
940 else if ( ( a & Qt::AlignJustify ) )
941 actionAlignJustify->setOn( true );
944 void TextEditor::verticalAlignmentChanged(int a)
946 if (a == Q3TextEdit::AlignSuperScript ) {
947 actionAlignSuperScript->setOn(true);
948 actionAlignSubScript->setOn(false);
949 } else if (a == Q3TextEdit::AlignSubScript ) {
950 actionAlignSuperScript->setOn(false);
951 actionAlignSubScript->setOn(true);
953 actionAlignSuperScript->setOn(false);
954 actionAlignSubScript->setOn(false);
960 void TextEditor::enableActions()
962 actionFileLoad->setEnabled(true);
963 actionFileSave->setEnabled(true);
964 actionFileSaveAs->setEnabled(true);
965 actionFilePrint->setEnabled(true);
966 actionEditUndo->setEnabled(true);
967 actionEditRedo->setEnabled(true);
968 actionEditCopy->setEnabled(true);
969 actionEditCut->setEnabled(true);
970 actionEditPaste->setEnabled(true);
971 actionEditDeleteAll->setEnabled(true);
972 actionEditConvertPar->setEnabled(true);
973 actionEditJoinLines->setEnabled(true);
974 actionFormatUseFixedFont->setEnabled(true);
977 void TextEditor::disableActions()
979 actionFileLoad->setEnabled(false);
980 actionFileSave->setEnabled(false);
981 actionFileSaveAs->setEnabled(false);
982 actionFilePrint->setEnabled(false);
983 actionEditUndo->setEnabled(false);
984 actionEditRedo->setEnabled(false);
985 actionEditCopy->setEnabled(false);
986 actionEditCut->setEnabled(false);
987 actionEditPaste->setEnabled(false);
988 actionEditDeleteAll->setEnabled(false);
989 actionEditConvertPar->setEnabled(false);
990 actionEditJoinLines->setEnabled(false);
991 actionFormatUseFixedFont->setEnabled(false);