diff -r a40af6315ac6 -r 3a58c9ef4a18 texteditor.cpp --- a/texteditor.cpp Thu Sep 14 11:38:17 2006 +0000 +++ b/texteditor.cpp Thu Sep 14 11:38:18 2006 +0000 @@ -41,9 +41,7 @@ printer = new QPrinter( QPrinter::HighResolution ); printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); - // Editor (use MyTextEdit to wrap verticalAlignmentChanged to - // int argument. see header file) - e = new MyTextEdit( this, "editor" ); + e = new QTextEdit( this); e->setFocus(); e->setTextFormat(Qt::RichText); // default e->setTabStopWidth (20); // unit is pixel @@ -51,9 +49,15 @@ e->setAutoFillBackground (true); connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); setCentralWidget( e ); - statusBar()->message( "Ready", statusbarTime); + statusBar()->message( tr("Ready","Statusbar message"), statusbarTime); setCaption(__VYM " - " +tr ("Note Editor")); + + connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), + this, SLOT(formatChanged(const QTextCharFormat &))); + + + // Toolbars setupFileActions(); setupEditActions(); @@ -92,6 +96,9 @@ } filenameHint=""; + // Restore position of toolbars + restoreState (settings.value("/noteeditor/state",0).toByteArray()); + // Save settings in vymrc settings.setValue("/mainwindow/printerName",printer->printerName()); } @@ -103,6 +110,7 @@ // Save Settings settings.setValue( "/noteeditor/geometry/size", size() ); settings.setValue( "/noteeditor/geometry/pos", pos() ); + settings.setValue ("/noteeditor/state",saveState(0)); settings.setValue( "/noteeditor/showWithMain",showWithMain()); @@ -114,6 +122,8 @@ settings.setValue( "/noteeditor/fonts/fonthintDefault",s ); settings.setValue("/noteeditor/fonts/varFont", varFont.toString() ); settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() ); + + } bool TextEditor::isEmpty() @@ -165,12 +175,12 @@ if (fn.isEmpty() ) { filename=""; - statusBar()->message( "No filename available for this note.", statusbarTime ); + statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime ); } else { filename=fn; - statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime ); + statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime ); } } @@ -304,23 +314,6 @@ tb->addAction (a); actionEditDeleteAll=a; - a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this); - /* TODO not needed any longer? remove also from docu... - a->setStatusTip(tr( "Convert paragraphs to linebreaks" )); - a->setShortcut( Qt::ALT + Qt::Key_P ); - connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) ); - editMenu->addAction (a); - */ - actionEditConvertPar=a; - - a = new QAction( QPixmap(), tr( "&Join lines" ), this); - /* TODO not needed any longer? remove also from docu... - a->setStatusTip(tr( "Join all lines of a paragraph" ) ); - a->setShortcut(Qt::ALT + Qt::Key_J ); - connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) ); - editMenu->addAction (a); - */ - actionEditJoinLines=a; } void TextEditor::setupFormatActions() @@ -339,7 +332,6 @@ tb->addAction (a); actionFormatUseFixedFont=a; -// comboFont = new QComboBox( true, tb ); comboFont = new QComboBox; tb->addWidget (comboFont); QFontDatabase fontDB; @@ -395,9 +387,28 @@ actionTextUnderline=a; formatMenu->addSeparator(); + QActionGroup *grp2 = new QActionGroup( this ); + grp2->setExclusive(true); + a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 ); + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B ); + a->setToggleAction( true ); + tb->addAction (a); + formatMenu->addAction (a); + connect(a, SIGNAL(activated()), this, SLOT(textVAlign())); + actionAlignSubScript=a; + + a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 ); + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P ); + a->setToggleAction( true ); + tb->addAction (a); + formatMenu->addAction (a); + connect(a, SIGNAL(activated()), this, SLOT(textVAlign())); + actionAlignSuperScript=a; QActionGroup *grp = new QActionGroup( this ); connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) ); + formatMenu->addSeparator(); + a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp ); a->setShortcut( Qt::CTRL+Qt::Key_L ); a->setToggleAction( true ); @@ -423,31 +434,13 @@ formatMenu->addAction (a); actionAlignJustify=a; - QActionGroup *grp2 = new QActionGroup( this ); - grp2->setExclusive(true); - a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 ); - a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B ); - a->setToggleAction( true ); - tb->addAction (a); - formatMenu->addAction (a); - connect(a, SIGNAL(activated()), this, SLOT(textVAlign())); - actionAlignSubScript=a; - a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 ); - a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P ); - a->setToggleAction( true ); - tb->addAction (a); - formatMenu->addAction (a); - connect(a, SIGNAL(activated()), this, SLOT(textVAlign())); - actionAlignSuperScript=a; - - formatMenu->addSeparator(); + /* FIXME connect( e, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( fontChanged( const QFont & ) ) ); connect( e, SIGNAL( currentColorChanged( const QColor & ) ), this, SLOT( colorChanged( const QColor & ) ) ); - /* connect( e, SIGNAL( currentAlignmentChanged( int ) ), this, SLOT( alignmentChanged( int ) ) ); connect( e, SIGNAL( currentVerticalAlignmentChanged(int)), @@ -648,84 +641,6 @@ statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime ); } -void TextEditor::textConvertPar() -{ - // In X11 a copy&paste generates paragraphs, - // which is not always wanted - // This function replaces paragraphs by linebreaks. - - QString t; - t=e->text(); - QRegExp re(""); - re.setMinimal(true); - t.replace (re,""); - t.replace ("

","
"); - e->setText(t); - - /* TODO QT3 use seletion () - int parFrom, parTo, indFrom, indTo; - e->getSelection (&parFrom,&indFrom,&parTo,&indTo); - if (parFrom>-1) - t=e->selectedText(); - else - t=e->text(); - - QRegExp re(""); - re.setMinimal(true); - t.replace (re,""); - t.replace ("

","
"); - if (parFrom>-1) - { - e->setCursorPosition (parFrom,indFrom); - e->cut(); - // Tried to simply insert the changed text with - // e->insert (t,(uint)(QTextEdit::RemoveSelected)); - // but then the html would be quoted. So I use the ugly - // way: insert a marker, replace it in whole text of QTextEdit - QString marker="R3PlAcEMeL4teR!"; - e->insert (marker); - e->setText (e->text().replace(marker,t)); - } else - e->setText(t); - */ -} - -void TextEditor::textJoinLines() -{ -/* TODO QT3 - int parFrom, parTo, indFrom, indTo; - e->getSelection (&parFrom,&indFrom,&parTo,&indTo); - QString t; - if (parFrom>-1) - t=e->selectedText(); - else - t=e->text(); - // In addition to textConvertPar it is sometimes - // useful to join all lines of a paragraph - QRegExp re("

\n+

(?!

)"); - re.setMinimal(true); - t.replace (re," "); - - // Above we may have introduced new " " at beginning of a - // paragraph - remove it. - re.setPattern("

"); - t.replace (re,"

"); - if (parFrom>-1) - { - e->setCursorPosition (parFrom,indFrom); - e->cut(); - // Tried to simply insert the changed text with - // e->insert (t,(uint)(QTextEdit::RemoveSelected)); - // but then the html would be quoted. So I use the ugly - // way: insert a marker, replace it in whole text of QTextEdit - QString marker="R3PlAcEMeL4teR!"; - e->insert (marker); - e->setText (e->text().replace(marker,t)); - } else - e->setText(t); -*/ -} - void TextEditor::textExportAsASCII() { QString text = NoteObj (e->text()).getNoteASCII(); @@ -857,8 +772,7 @@ void TextEditor::textColor() { QColor col = QColorDialog::getColor( e->color(), this ); - if ( !col.isValid() ) - return; + if ( !col.isValid() ) return; e->setColor( col ); QPixmap pix( 16, 16 ); pix.fill( Qt::black ); @@ -868,35 +782,36 @@ void TextEditor::textAlign( QAction *a ) { if ( a == actionAlignLeft ) - e->setAlignment( Qt::AlignLeft ); + e->setAlignment( Qt::AlignLeft ); else if ( a == actionAlignCenter ) - e->setAlignment( Qt::AlignHCenter ); + e->setAlignment( Qt::AlignHCenter ); else if ( a == actionAlignRight ) - e->setAlignment( Qt::AlignRight ); + e->setAlignment( Qt::AlignRight ); else if ( a == actionAlignJustify ) - e->setAlignment( Qt::AlignJustify ); + e->setAlignment( Qt::AlignJustify ); } void TextEditor::textVAlign() { -/* FIXME QT3 alignment + QTextCharFormat format; + if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) { - e->setVerticalAlignment( QTextEdit::AlignSuperScript); + format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) { - e->setVerticalAlignment( QTextEdit::AlignSubScript); + format.setVerticalAlignment(QTextCharFormat::AlignSubScript); } else { - e->setVerticalAlignment( QTextEdit::AlignNormal); + format.setVerticalAlignment(QTextCharFormat::AlignNormal); } -*/ + e->mergeCurrentCharFormat(format); } void TextEditor::fontChanged( const QFont &f ) { -/* - comboFont->lineEdit()->setText( f.family() ); - comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); -*/ + int i=comboFont->findText(f.family()); + if (i>=0) comboFont->setCurrentIndex (i); + i=comboSize->findText(QString::number(f.pointSize())); + if (i>=0) comboSize->setCurrentIndex(i); actionTextBold->setOn( f.bold() ); actionTextItalic->setOn( f.italic() ); actionTextUnderline->setOn( f.underline() ); @@ -909,32 +824,40 @@ actionTextColor->setIconSet( pix ); } +void TextEditor::formatChanged( const QTextCharFormat &f ) +{ + fontChanged(f.font()); + colorChanged(f.foreground().color()); + alignmentChanged(e->alignment()); + verticalAlignmentChanged (f.verticalAlignment()); +} + void TextEditor::alignmentChanged( int a ) { if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft )) - actionAlignLeft->setOn( true ); + actionAlignLeft->setOn( true ); else if ( ( a & Qt::AlignHCenter ) ) - actionAlignCenter->setOn( true ); + actionAlignCenter->setOn( true ); else if ( ( a & Qt::AlignRight ) ) - actionAlignRight->setOn( true ); + actionAlignRight->setOn( true ); else if ( ( a & Qt::AlignJustify ) ) - actionAlignJustify->setOn( true ); + actionAlignJustify->setOn( true ); } -void TextEditor::verticalAlignmentChanged(int a) +void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a) { - /* FIXME QT3 alignment - if (a == QTextEdit::AlignSuperScript ) { - actionAlignSuperScript->setOn(true); - actionAlignSubScript->setOn(false); - } else if (a == QTextEdit::AlignSubScript ) { - actionAlignSuperScript->setOn(false); - actionAlignSubScript->setOn(true); - } else { - actionAlignSuperScript->setOn(false); - actionAlignSubScript->setOn(false); - } - */ + actionAlignSubScript->setOn (false); + actionAlignSuperScript->setOn (false); + switch (a) + { + case QTextCharFormat::AlignSuperScript: + actionAlignSuperScript->setOn (true); + break; + case QTextCharFormat::AlignSubScript: + actionAlignSubScript->setOn (true); + break; + default: ; + } } @@ -951,8 +874,6 @@ actionEditCut->setEnabled(true); actionEditPaste->setEnabled(true); actionEditDeleteAll->setEnabled(true); - actionEditConvertPar->setEnabled(true); - actionEditJoinLines->setEnabled(true); actionFormatUseFixedFont->setEnabled(true); } @@ -968,8 +889,6 @@ actionEditCut->setEnabled(false); actionEditPaste->setEnabled(false); actionEditDeleteAll->setEnabled(false); - actionEditConvertPar->setEnabled(false); - actionEditJoinLines->setEnabled(false); actionFormatUseFixedFont->setEnabled(false); }