1 #include "texteditor.h"
4 #include <qstatusbar.h>
5 #include <qmessagebox.h>
7 #include <qapplication.h>
11 #include <q3filedialog.h>
12 #include <q3toolbar.h>
13 #include <q3popupmenu.h>
15 #include <q3textedit.h>
17 #include <qtextstream.h>
18 #include <q3paintdevicemetrics.h>
19 #include <qsettings.h>
20 #include <qfontdialog.h>
21 #include <qmessagebox.h>
22 #include <qcolordialog.h>
24 #include <qlineedit.h>
25 #include <q3simplerichtext.h>
27 #include <Q3ValueList>
29 #include <QActionGroup>
30 #include <QCloseEvent>
39 extern Q3Canvas* actCanvas;
40 extern int statusbarTime;
41 extern QSettings settings;
43 extern QAction *actionViewToggleNoteEditor;
45 extern QString iconPath;
50 ///////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////
54 TextEditor::TextEditor()
56 printer = new QPrinter( QPrinter::HighResolution );
57 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
59 // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
60 // int argument. see header file)
61 e = new MyTextEdit( this, "editor" );
63 e->setTextFormat(Qt::RichText); // default
64 e->setTabStopWidth (20); // unit is pixel
65 e->setColor (Qt::black);
66 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
67 setCentralWidget( e );
68 statusBar()->message( "Ready", statusbarTime);
69 setCaption(__VYM " - " +tr ("Note Editor"));
75 setupSettingsActions();
78 emptyPaper = QBrush(Qt::gray);
79 filledPaper = QBrush(Qt::white);
80 inactivePaper= QBrush(Qt::black);
84 resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
85 settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
86 move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
87 settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
89 if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
90 setShowWithMain(true);
92 setShowWithMain(false);
94 varFont.fromString( settings.readEntry
95 ("/vym/noteeditor/fonts/varFont",
96 "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
98 fixedFont.fromString (settings.readEntry (
99 "/vym/noteeditor/fonts/fixedFont",
100 "Courier,14,-1,5,48,0,0,0,1,0")
102 QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
105 actionSettingsFonthintDefault->setOn (true);
106 e->setCurrentFont (fixedFont);
109 actionSettingsFonthintDefault->setOn (false);
110 e->setCurrentFont (varFont);
114 // Save settings in vymrc
115 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
119 TextEditor::~TextEditor()
121 if (printer) delete printer;
123 settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
124 settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
125 settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
126 settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
129 settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
131 settings.writeEntry( "/vym/noteeditor/showWithMain","no");
134 if (actionSettingsFonthintDefault->isOn() )
138 settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
139 settings.writeEntry ("/vym/noteeditor/fonts/varFont",
140 varFont.toString() );
141 settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
142 fixedFont.toString() );
145 bool TextEditor::isEmpty()
147 if (e->text().length())
153 void TextEditor::setShowWithMain(bool v)
158 bool TextEditor::showWithMain()
163 void TextEditor::setFontHint (const QString &fh)
166 actionFormatUseFixedFont->setOn (true);
168 actionFormatUseFixedFont->setOn (false);
172 QString TextEditor::getFontHint()
174 if (actionFormatUseFixedFont->isOn())
180 QString TextEditor::getFontHintDefault()
182 if (actionSettingsFonthintDefault->isOn())
188 void TextEditor::setFilename(const QString &fn)
190 if (state==filledEditor)
194 statusBar()->message( "No filename available for this note.", statusbarTime );
199 statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
203 QString TextEditor::getFilename()
208 void TextEditor::setFilenameHint(const QString &fnh)
213 QString TextEditor::getFilenameHint()
218 bool TextEditor::findText(const QString &t, const bool &cs)
220 bool wo=false; // word matches
221 if (e->find (t, cs, wo, true, 0, 0 ))
227 void TextEditor::setupFileActions()
229 Q3ToolBar *tb = new Q3ToolBar( this );
230 tb->setLabel( "File Actions" );
231 Q3PopupMenu *menu = new Q3PopupMenu( this );
232 menuBar()->insertItem( tr( "&File" ), menu );
235 a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
236 a->setStatusTip (tr( "Import" ) );
237 a->setShortcut( Qt::CTRL + Qt::Key_O );
238 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
239 a->setEnabled(false);
244 menu->insertSeparator();
245 a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
246 a->setStatusTip (tr( "Export Note (HTML)" ) );
247 a->setShortcut( Qt::CTRL + Qt::Key_S );
248 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
253 a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
254 a->setStatusTip (tr( "Export Note As (HTML) " ));
255 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
259 a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
260 a->setStatusTip ( tr( "Export Note As (ASCII) " ) );
261 a->setShortcut(Qt::ALT + Qt::Key_X );
262 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
266 menu->insertSeparator();
267 a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
268 a->setStatusTip (tr( "Print Note" ) );
269 a->setShortcut( Qt::CTRL + Qt::Key_P );
270 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
276 void TextEditor::setupEditActions()
278 Q3ToolBar *tb = new Q3ToolBar( this );
279 tb->setLabel( "Edit Actions" );
280 Q3PopupMenu *menu = new Q3PopupMenu( this );
281 menuBar()->insertItem( tr( "&Edit" ), menu );
284 a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
285 a->setStatusTip ( tr( "Undo" ) );
286 a->setShortcut(Qt::CTRL + Qt::Key_Z );
287 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
292 a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
293 a->setStatusTip ( tr( "Redo" ) );
294 a->setShortcut( Qt::CTRL + Qt::Key_Y );
295 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
300 menu->insertSeparator();
301 a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
302 a->setStatusTip ( tr( "Select and copy all" ) );
303 a->setShortcut( Qt::CTRL + Qt::Key_A );
304 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
307 menu->insertSeparator();
308 a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
309 a->setStatusTip ( tr( "Copy" ) );
310 a->setShortcut( Qt::CTRL + Qt::Key_C );
311 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
316 a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
317 a->setStatusTip ( tr( "Cut" ) );
318 a->setShortcut( Qt::CTRL + Qt::Key_X );
319 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
324 a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
325 a->setStatusTip ( tr( "Paste" ) );
326 a->setShortcut( Qt::CTRL + Qt::Key_V );
327 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
332 a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
333 a->setStatusTip (tr( "Delete all" ) );
334 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
337 actionEditDeleteAll=a;
339 a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
340 a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
341 a->setShortcut( Qt::ALT + Qt::Key_P );
342 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
344 actionEditConvertPar=a;
346 a = new QAction( QPixmap(), tr( "&Join lines" ), this);
347 a->setStatusTip(tr( "Join all lines of a paragraph" ) );
348 a->setShortcut(Qt::ALT + Qt::Key_J );
349 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
351 actionEditJoinLines=a;
354 void TextEditor::setupFormatActions()
356 Q3ToolBar *tb = new Q3ToolBar( this );
357 tb->setLabel( "Format Actions" );
358 Q3PopupMenu *menu = new Q3PopupMenu( this );
359 menuBar()->insertItem( tr( "F&ormat" ), menu );
363 a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
364 a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
365 a->setToggleAction (true);
366 a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
367 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
370 actionFormatUseFixedFont=a;
372 menu->insertSeparator();
374 comboFont = new QComboBox( true, tb );
376 comboFont->insertStringList( db.families() );
377 connect( comboFont, SIGNAL( activated( const QString & ) ),
378 this, SLOT( textFamily( const QString & ) ) );
379 comboFont->lineEdit()->setText( QApplication::font().family() );
381 comboSize = new QComboBox( true, tb );
382 Q3ValueList<int> sizes = db.standardSizes();
383 Q3ValueList<int>::Iterator it = sizes.begin();
384 for ( ; it != sizes.end(); ++it )
385 comboSize->insertItem( QString::number( *it ) );
386 connect( comboSize, SIGNAL( activated( const QString & ) ),
387 this, SLOT( textSize( const QString & ) ) );
388 comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
390 menu->insertSeparator();
392 QPixmap pix( 16, 16 );
393 pix.fill( e->color());
394 actionTextColor = new QAction( pix, tr( "&Color..." ), this);
395 actionTextColor->addTo( tb );
396 actionTextColor->addTo( menu );
397 connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) );
399 actionTextBold = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
400 actionTextBold->setShortcut(Qt::CTRL + Qt::Key_B );
401 connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
402 actionTextBold->addTo( tb );
403 actionTextBold->addTo( menu );
404 actionTextBold->setToggleAction( true );
405 actionTextItalic = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
406 actionTextItalic->setShortcut(Qt::CTRL + Qt::Key_I);
407 connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) );
408 actionTextItalic->addTo( tb );
409 actionTextItalic->addTo( menu );
410 actionTextItalic->setToggleAction( true );
411 actionTextUnderline = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
412 actionTextUnderline->setShortcut(Qt::CTRL + Qt::Key_U );
413 connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
414 actionTextUnderline->addTo( tb );
415 actionTextUnderline->addTo( menu );
416 actionTextUnderline->setToggleAction( true );
417 menu->insertSeparator();
419 QActionGroup *grp = new QActionGroup( this );
420 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
422 actionAlignLeft = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
423 actionAlignLeft->setShortcut( Qt::CTRL+Qt::Key_L );
424 actionAlignLeft->setToggleAction( true );
425 actionAlignCenter = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
426 actionAlignCenter->setShortcut( Qt::CTRL + Qt::Key_E);
427 actionAlignCenter->setToggleAction( true );
428 actionAlignRight = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
429 actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R );
430 actionAlignRight->setToggleAction( true );
431 actionAlignJustify = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
432 actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J );
433 actionAlignJustify->setToggleAction( true );
438 QActionGroup *grp2 = new QActionGroup( this );
439 grp2->setExclusive(false);
440 actionAlignSubScript = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
441 actionAlignSubScript->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
442 actionAlignSubScript->setToggleAction( true );
443 connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
445 actionAlignSuperScript = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
446 actionAlignSuperScript->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
447 actionAlignSuperScript->setToggleAction( true );
448 connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
450 menu->insertSeparator();
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 & ) ) );
459 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
460 this, SLOT( alignmentChanged( int ) ) );
461 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
462 this, SLOT( verticalAlignmentChanged(int)));
466 void TextEditor::setupSettingsActions()
468 Q3PopupMenu *menu = new Q3PopupMenu( this );
469 menuBar()->insertItem( tr( "&Settings" ), menu );
472 a = new QAction(tr( "Set &fixed font" ), this);
473 a->setStatusTip ( tr( "Set fixed font" ));
474 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
476 actionSettingsFixedFont=a;
478 a = new QAction(tr( "Set &variable font" ), this);
479 a->setStatusTip ( tr( "Set variable font" ) );
480 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
482 actionSettingsVarFont=a;
484 a = new QAction(tr( "&fixed font is default" ), this);
485 a->setStatusTip (tr( "Used fixed font by default" ) );
486 a->setToggleAction (true);
487 // set state later in constructor...
489 actionSettingsFonthintDefault=a;
492 void TextEditor::textLoad()
494 if (state!=inactiveEditor)
498 QMessageBox mb( __VYM " - " +tr("Note Editor"),
499 "Loading will overwrite the existing note",
500 QMessageBox::Warning,
501 QMessageBox::Yes | QMessageBox::Default,
504 mb.setButtonText( QMessageBox::Yes, "Load note" );
505 switch( mb.exec() ) {
506 case QMessageBox::Cancel:
512 Q3FileDialog *fd=new Q3FileDialog( this);
513 fd->addFilter ("ASCII texts (*.txt)");
514 fd->addFilter ("VYM notes (*.html)");
517 if ( fd->exec() == QDialog::Accepted )
518 fn = fd->selectedFile();
523 if ( !f.open( QIODevice::ReadOnly ) )
526 QTextStream ts( &f );
527 setText( ts.read() );
533 void TextEditor::closeEvent( QCloseEvent* ce )
535 ce->accept(); // TextEditor can be reopened with show()
536 actionViewToggleNoteEditor->setOn (false);
541 QString TextEditor::getText()
546 void TextEditor::editorChanged()
553 if (state==emptyEditor)
554 e->setPaper (emptyPaper);
556 e->setPaper (filledPaper);
557 // SLOT is LinkableMapObj, which will update systemFlag
558 emit (textHasChanged() );
562 void TextEditor::setText(QString t)
564 if ( !Q3StyleSheet::mightBeRichText( t ) )
565 t = Q3StyleSheet::convertFromPlainText( t, Q3StyleSheetItem::WhiteSpaceNormal );
566 e->setReadOnly(false);
568 // editorChanged(); //not called automagically FIXME or is it?
573 void TextEditor::setInactive()
575 state=inactiveEditor;
577 e->setPaper (inactivePaper);
578 e->setReadOnly (true);
583 void TextEditor::editCopyAll()
589 void TextEditor::textSaveAs()
591 QString fn = Q3FileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
592 this,"export note dialog",tr("Export Note to single file") );
599 QMessageBox mb( __VYM,
600 tr("The file ") + fn +
601 tr(" exists already. "
602 "Do you want to overwrite it?"),
603 QMessageBox::Warning,
604 QMessageBox::Yes | QMessageBox::Default,
605 QMessageBox::Cancel | QMessageBox::Escape,
607 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
608 mb.setButtonText( QMessageBox::No, tr("Cancel"));
609 switch( mb.exec() ) {
610 case QMessageBox::Yes:
615 case QMessageBox::Cancel:
626 statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
630 void TextEditor::textSave()
632 if ( filename.isEmpty() )
638 QString text = e->text();
640 if ( !f.open( QIODevice::WriteOnly ) )
642 statusBar()->message( QString("Could not write to %1").arg(filename),
651 e->setModified( FALSE );
653 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
656 void TextEditor::textConvertPar()
658 // In X11 a copy&paste generates paragraphs,
659 // which is not always wanted
660 // This function replaces paragraphs by linebreaks.
661 int parFrom, parTo, indFrom, indTo;
662 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
672 t.replace ("</p>","<br />");
675 e->setCursorPosition (parFrom,indFrom);
677 // Tried to simply insert the changed text with
678 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
679 // but then the html would be quoted. So I use the ugly
680 // way: insert a marker, replace it in whole text of QTextEdit
681 QString marker="R3PlAcEMeL4teR!";
683 e->setText (e->text().replace(marker,t));
688 void TextEditor::textJoinLines()
690 int parFrom, parTo, indFrom, indTo;
691 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
697 // In addition to textConvertPar it is sometimes
698 // useful to join all lines of a paragraph
699 QRegExp re("</p>\n+<p>(?!</p>)");
703 // Above we may have introduced new " " at beginning of a
704 // paragraph - remove it.
705 re.setPattern("<p> ");
706 t.replace (re,"<p>");
709 e->setCursorPosition (parFrom,indFrom);
711 // Tried to simply insert the changed text with
712 // e->insert (t,(uint)(QTextEdit::RemoveSelected));
713 // but then the html would be quoted. So I use the ugly
714 // way: insert a marker, replace it in whole text of QTextEdit
715 QString marker="R3PlAcEMeL4teR!";
717 e->setText (e->text().replace(marker,t));
722 void TextEditor::textExportAsASCII()
724 QString text = NoteObj (e->text()).getNoteASCII();
726 if (!filenameHint.isEmpty())
728 if (!filenameHint.contains (".txt"))
729 s=filenameHint+".txt";
734 fn = Q3FileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
742 QMessageBox mb( "VYM",
743 tr("The file ") + fn +
744 tr(" exists already. "
745 "Do you want to overwrite it?"),
746 QMessageBox::Warning,
747 QMessageBox::Yes | QMessageBox::Default,
748 QMessageBox::Cancel | QMessageBox::Escape,
750 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
751 mb.setButtonText( QMessageBox::No, tr("Cancel"));
754 if (ret==QMessageBox::Cancel)
758 if ( !file.open( QIODevice::WriteOnly ) )
759 statusBar()->message( QString("Could not write to %1").arg(filename),
763 QTextStream t( &file );
767 statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
773 void TextEditor::textPrint()
775 printer->setFullPage(TRUE);
776 if ( printer->setup( this ) )
778 QPainter p( printer );
779 // Check that there is a valid device to print to.
780 if ( !p.device() ) return;
781 Q3PaintDeviceMetrics metrics( p.device() );
782 int dpiy = metrics.logicalDpiY();
783 int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
784 QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
785 QFont font( e->currentFont() );
786 font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
788 Q3SimpleRichText richText( e->text(), font,
791 e->mimeSourceFactory(),
793 richText.setWidth( &p, body.width() );
798 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
799 view.moveBy( 0, body.height() );
800 p.translate( 0 , -body.height() );
802 p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
803 view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
804 if ( view.top() >= richText.height() )
812 void TextEditor::textEditUndo()
816 void TextEditor::toggleFonthint()
818 setUpdatesEnabled (false);
820 if (!actionFormatUseFixedFont->isOn() )
821 e->setCurrentFont (varFont);
823 e->setCurrentFont (fixedFont);
824 e->selectAll (false);
825 setUpdatesEnabled (true);
829 void TextEditor::setFixedFont()
832 QFont font =QFontDialog::getFont(
833 &ok, fixedFont, this );
835 // font is set to the font the user selected
839 void TextEditor::setVarFont()
842 QFont font =QFontDialog::getFont(
843 &ok, varFont, this );
845 // font is set to the font the user selected
849 void TextEditor::textBold()
851 e->setBold( actionTextBold->isOn() );
854 void TextEditor::textUnderline()
856 e->setUnderline( actionTextUnderline->isOn() );
859 void TextEditor::textItalic()
861 e->setItalic( actionTextItalic->isOn() );
864 void TextEditor::textFamily( const QString &f )
869 void TextEditor::textSize( const QString &p )
871 e->setPointSize( p.toInt() );
875 void TextEditor::textColor()
877 QColor col = QColorDialog::getColor( e->color(), this );
878 if ( !col.isValid() )
881 QPixmap pix( 16, 16 );
882 pix.fill( Qt::black );
883 actionTextColor->setIconSet( pix );
886 void TextEditor::textAlign( QAction *a )
888 if ( a == actionAlignLeft )
889 e->setAlignment( Qt::AlignLeft );
890 else if ( a == actionAlignCenter )
891 e->setAlignment( Qt::AlignHCenter );
892 else if ( a == actionAlignRight )
893 e->setAlignment( Qt::AlignRight );
894 else if ( a == actionAlignJustify )
895 e->setAlignment( Qt::AlignJustify );
898 void TextEditor::textVAlign()
900 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
901 e->setVerticalAlignment( Q3TextEdit::AlignSuperScript);
902 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
903 e->setVerticalAlignment( Q3TextEdit::AlignSubScript);
905 e->setVerticalAlignment( Q3TextEdit::AlignNormal);
910 void TextEditor::fontChanged( const QFont &f )
912 comboFont->lineEdit()->setText( f.family() );
913 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
914 actionTextBold->setOn( f.bold() );
915 actionTextItalic->setOn( f.italic() );
916 actionTextUnderline->setOn( f.underline() );
919 void TextEditor::colorChanged( const QColor &c )
921 QPixmap pix( 16, 16 );
923 actionTextColor->setIconSet( pix );
926 void TextEditor::alignmentChanged( int a )
928 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
929 actionAlignLeft->setOn( true );
930 else if ( ( a & Qt::AlignHCenter ) )
931 actionAlignCenter->setOn( true );
932 else if ( ( a & Qt::AlignRight ) )
933 actionAlignRight->setOn( true );
934 else if ( ( a & Qt::AlignJustify ) )
935 actionAlignJustify->setOn( true );
938 void TextEditor::verticalAlignmentChanged(int a)
940 if (a == Q3TextEdit::AlignSuperScript ) {
941 actionAlignSuperScript->setOn(true);
942 actionAlignSubScript->setOn(false);
943 } else if (a == Q3TextEdit::AlignSubScript ) {
944 actionAlignSuperScript->setOn(false);
945 actionAlignSubScript->setOn(true);
947 actionAlignSuperScript->setOn(false);
948 actionAlignSubScript->setOn(false);
954 void TextEditor::enableActions()
956 actionFileLoad->setEnabled(true);
957 actionFileSave->setEnabled(true);
958 actionFileSaveAs->setEnabled(true);
959 actionFilePrint->setEnabled(true);
960 actionEditUndo->setEnabled(true);
961 actionEditRedo->setEnabled(true);
962 actionEditCopy->setEnabled(true);
963 actionEditCut->setEnabled(true);
964 actionEditPaste->setEnabled(true);
965 actionEditDeleteAll->setEnabled(true);
966 actionEditConvertPar->setEnabled(true);
967 actionEditJoinLines->setEnabled(true);
968 actionFormatUseFixedFont->setEnabled(true);
971 void TextEditor::disableActions()
973 actionFileLoad->setEnabled(false);
974 actionFileSave->setEnabled(false);
975 actionFileSaveAs->setEnabled(false);
976 actionFilePrint->setEnabled(false);
977 actionEditUndo->setEnabled(false);
978 actionEditRedo->setEnabled(false);
979 actionEditCopy->setEnabled(false);
980 actionEditCut->setEnabled(false);
981 actionEditPaste->setEnabled(false);
982 actionEditDeleteAll->setEnabled(false);
983 actionEditConvertPar->setEnabled(false);
984 actionEditJoinLines->setEnabled(false);
985 actionFormatUseFixedFont->setEnabled(false);