1.1 --- a/texteditor.cpp Thu Sep 14 11:38:17 2006 +0000
1.2 +++ b/texteditor.cpp Thu Sep 14 11:38:18 2006 +0000
1.3 @@ -41,9 +41,7 @@
1.4 printer = new QPrinter( QPrinter::HighResolution );
1.5 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1.6
1.7 - // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
1.8 - // int argument. see header file)
1.9 - e = new MyTextEdit( this, "editor" );
1.10 + e = new QTextEdit( this);
1.11 e->setFocus();
1.12 e->setTextFormat(Qt::RichText); // default
1.13 e->setTabStopWidth (20); // unit is pixel
1.14 @@ -51,9 +49,15 @@
1.15 e->setAutoFillBackground (true);
1.16 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
1.17 setCentralWidget( e );
1.18 - statusBar()->message( "Ready", statusbarTime);
1.19 + statusBar()->message( tr("Ready","Statusbar message"), statusbarTime);
1.20 setCaption(__VYM " - " +tr ("Note Editor"));
1.21
1.22 +
1.23 + connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
1.24 + this, SLOT(formatChanged(const QTextCharFormat &)));
1.25 +
1.26 +
1.27 +
1.28 // Toolbars
1.29 setupFileActions();
1.30 setupEditActions();
1.31 @@ -92,6 +96,9 @@
1.32 }
1.33 filenameHint="";
1.34
1.35 + // Restore position of toolbars
1.36 + restoreState (settings.value("/noteeditor/state",0).toByteArray());
1.37 +
1.38 // Save settings in vymrc
1.39 settings.setValue("/mainwindow/printerName",printer->printerName());
1.40 }
1.41 @@ -103,6 +110,7 @@
1.42 // Save Settings
1.43 settings.setValue( "/noteeditor/geometry/size", size() );
1.44 settings.setValue( "/noteeditor/geometry/pos", pos() );
1.45 + settings.setValue ("/noteeditor/state",saveState(0));
1.46
1.47 settings.setValue( "/noteeditor/showWithMain",showWithMain());
1.48
1.49 @@ -114,6 +122,8 @@
1.50 settings.setValue( "/noteeditor/fonts/fonthintDefault",s );
1.51 settings.setValue("/noteeditor/fonts/varFont", varFont.toString() );
1.52 settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() );
1.53 +
1.54 +
1.55 }
1.56
1.57 bool TextEditor::isEmpty()
1.58 @@ -165,12 +175,12 @@
1.59 if (fn.isEmpty() )
1.60 {
1.61 filename="";
1.62 - statusBar()->message( "No filename available for this note.", statusbarTime );
1.63 + statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime );
1.64 }
1.65 else
1.66 {
1.67 filename=fn;
1.68 - statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
1.69 + statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime );
1.70 }
1.71 }
1.72
1.73 @@ -304,23 +314,6 @@
1.74 tb->addAction (a);
1.75 actionEditDeleteAll=a;
1.76
1.77 - a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
1.78 - /* TODO not needed any longer? remove also from docu...
1.79 - a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
1.80 - a->setShortcut( Qt::ALT + Qt::Key_P );
1.81 - connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
1.82 - editMenu->addAction (a);
1.83 - */
1.84 - actionEditConvertPar=a;
1.85 -
1.86 - a = new QAction( QPixmap(), tr( "&Join lines" ), this);
1.87 - /* TODO not needed any longer? remove also from docu...
1.88 - a->setStatusTip(tr( "Join all lines of a paragraph" ) );
1.89 - a->setShortcut(Qt::ALT + Qt::Key_J );
1.90 - connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
1.91 - editMenu->addAction (a);
1.92 - */
1.93 - actionEditJoinLines=a;
1.94 }
1.95
1.96 void TextEditor::setupFormatActions()
1.97 @@ -339,7 +332,6 @@
1.98 tb->addAction (a);
1.99 actionFormatUseFixedFont=a;
1.100
1.101 -// comboFont = new QComboBox( true, tb );
1.102 comboFont = new QComboBox;
1.103 tb->addWidget (comboFont);
1.104 QFontDatabase fontDB;
1.105 @@ -395,9 +387,28 @@
1.106 actionTextUnderline=a;
1.107 formatMenu->addSeparator();
1.108
1.109 + QActionGroup *grp2 = new QActionGroup( this );
1.110 + grp2->setExclusive(true);
1.111 + a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
1.112 + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
1.113 + a->setToggleAction( true );
1.114 + tb->addAction (a);
1.115 + formatMenu->addAction (a);
1.116 + connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.117 + actionAlignSubScript=a;
1.118 +
1.119 + a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
1.120 + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
1.121 + a->setToggleAction( true );
1.122 + tb->addAction (a);
1.123 + formatMenu->addAction (a);
1.124 + connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.125 + actionAlignSuperScript=a;
1.126 QActionGroup *grp = new QActionGroup( this );
1.127 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
1.128
1.129 + formatMenu->addSeparator();
1.130 +
1.131 a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
1.132 a->setShortcut( Qt::CTRL+Qt::Key_L );
1.133 a->setToggleAction( true );
1.134 @@ -423,31 +434,13 @@
1.135 formatMenu->addAction (a);
1.136 actionAlignJustify=a;
1.137
1.138 - QActionGroup *grp2 = new QActionGroup( this );
1.139 - grp2->setExclusive(true);
1.140 - a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
1.141 - a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
1.142 - a->setToggleAction( true );
1.143 - tb->addAction (a);
1.144 - formatMenu->addAction (a);
1.145 - connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.146 - actionAlignSubScript=a;
1.147
1.148 - a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
1.149 - a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
1.150 - a->setToggleAction( true );
1.151 - tb->addAction (a);
1.152 - formatMenu->addAction (a);
1.153 - connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.154 - actionAlignSuperScript=a;
1.155 -
1.156 - formatMenu->addSeparator();
1.157
1.158 + /* FIXME
1.159 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
1.160 this, SLOT( fontChanged( const QFont & ) ) );
1.161 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
1.162 this, SLOT( colorChanged( const QColor & ) ) );
1.163 - /*
1.164 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
1.165 this, SLOT( alignmentChanged( int ) ) );
1.166 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
1.167 @@ -648,84 +641,6 @@
1.168 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
1.169 }
1.170
1.171 -void TextEditor::textConvertPar()
1.172 -{
1.173 - // In X11 a copy&paste generates paragraphs,
1.174 - // which is not always wanted
1.175 - // This function replaces paragraphs by linebreaks.
1.176 -
1.177 - QString t;
1.178 - t=e->text();
1.179 - QRegExp re("<p.*>");
1.180 - re.setMinimal(true);
1.181 - t.replace (re,"");
1.182 - t.replace ("</p>","<br />");
1.183 - e->setText(t);
1.184 -
1.185 - /* TODO QT3 use seletion ()
1.186 - int parFrom, parTo, indFrom, indTo;
1.187 - e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
1.188 - if (parFrom>-1)
1.189 - t=e->selectedText();
1.190 - else
1.191 - t=e->text();
1.192 -
1.193 - QRegExp re("<p.*>");
1.194 - re.setMinimal(true);
1.195 - t.replace (re,"");
1.196 - t.replace ("</p>","<br />");
1.197 - if (parFrom>-1)
1.198 - {
1.199 - e->setCursorPosition (parFrom,indFrom);
1.200 - e->cut();
1.201 - // Tried to simply insert the changed text with
1.202 - // e->insert (t,(uint)(QTextEdit::RemoveSelected));
1.203 - // but then the html would be quoted. So I use the ugly
1.204 - // way: insert a marker, replace it in whole text of QTextEdit
1.205 - QString marker="R3PlAcEMeL4teR!";
1.206 - e->insert (marker);
1.207 - e->setText (e->text().replace(marker,t));
1.208 - } else
1.209 - e->setText(t);
1.210 - */
1.211 -}
1.212 -
1.213 -void TextEditor::textJoinLines()
1.214 -{
1.215 -/* TODO QT3
1.216 - int parFrom, parTo, indFrom, indTo;
1.217 - e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
1.218 - QString t;
1.219 - if (parFrom>-1)
1.220 - t=e->selectedText();
1.221 - else
1.222 - t=e->text();
1.223 - // In addition to textConvertPar it is sometimes
1.224 - // useful to join all lines of a paragraph
1.225 - QRegExp re("</p>\n+<p>(?!</p>)");
1.226 - re.setMinimal(true);
1.227 - t.replace (re," ");
1.228 -
1.229 - // Above we may have introduced new " " at beginning of a
1.230 - // paragraph - remove it.
1.231 - re.setPattern("<p> ");
1.232 - t.replace (re,"<p>");
1.233 - if (parFrom>-1)
1.234 - {
1.235 - e->setCursorPosition (parFrom,indFrom);
1.236 - e->cut();
1.237 - // Tried to simply insert the changed text with
1.238 - // e->insert (t,(uint)(QTextEdit::RemoveSelected));
1.239 - // but then the html would be quoted. So I use the ugly
1.240 - // way: insert a marker, replace it in whole text of QTextEdit
1.241 - QString marker="R3PlAcEMeL4teR!";
1.242 - e->insert (marker);
1.243 - e->setText (e->text().replace(marker,t));
1.244 - } else
1.245 - e->setText(t);
1.246 -*/
1.247 -}
1.248 -
1.249 void TextEditor::textExportAsASCII()
1.250 {
1.251 QString text = NoteObj (e->text()).getNoteASCII();
1.252 @@ -857,8 +772,7 @@
1.253 void TextEditor::textColor()
1.254 {
1.255 QColor col = QColorDialog::getColor( e->color(), this );
1.256 - if ( !col.isValid() )
1.257 - return;
1.258 + if ( !col.isValid() ) return;
1.259 e->setColor( col );
1.260 QPixmap pix( 16, 16 );
1.261 pix.fill( Qt::black );
1.262 @@ -868,35 +782,36 @@
1.263 void TextEditor::textAlign( QAction *a )
1.264 {
1.265 if ( a == actionAlignLeft )
1.266 - e->setAlignment( Qt::AlignLeft );
1.267 + e->setAlignment( Qt::AlignLeft );
1.268 else if ( a == actionAlignCenter )
1.269 - e->setAlignment( Qt::AlignHCenter );
1.270 + e->setAlignment( Qt::AlignHCenter );
1.271 else if ( a == actionAlignRight )
1.272 - e->setAlignment( Qt::AlignRight );
1.273 + e->setAlignment( Qt::AlignRight );
1.274 else if ( a == actionAlignJustify )
1.275 - e->setAlignment( Qt::AlignJustify );
1.276 + e->setAlignment( Qt::AlignJustify );
1.277 }
1.278
1.279 void TextEditor::textVAlign()
1.280 {
1.281 -/* FIXME QT3 alignment
1.282 + QTextCharFormat format;
1.283 +
1.284 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
1.285 - e->setVerticalAlignment( QTextEdit::AlignSuperScript);
1.286 + format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
1.287 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
1.288 - e->setVerticalAlignment( QTextEdit::AlignSubScript);
1.289 + format.setVerticalAlignment(QTextCharFormat::AlignSubScript);
1.290 } else {
1.291 - e->setVerticalAlignment( QTextEdit::AlignNormal);
1.292 + format.setVerticalAlignment(QTextCharFormat::AlignNormal);
1.293 }
1.294 -*/
1.295 + e->mergeCurrentCharFormat(format);
1.296 }
1.297
1.298
1.299 void TextEditor::fontChanged( const QFont &f )
1.300 {
1.301 -/*
1.302 - comboFont->lineEdit()->setText( f.family() );
1.303 - comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
1.304 -*/
1.305 + int i=comboFont->findText(f.family());
1.306 + if (i>=0) comboFont->setCurrentIndex (i);
1.307 + i=comboSize->findText(QString::number(f.pointSize()));
1.308 + if (i>=0) comboSize->setCurrentIndex(i);
1.309 actionTextBold->setOn( f.bold() );
1.310 actionTextItalic->setOn( f.italic() );
1.311 actionTextUnderline->setOn( f.underline() );
1.312 @@ -909,32 +824,40 @@
1.313 actionTextColor->setIconSet( pix );
1.314 }
1.315
1.316 +void TextEditor::formatChanged( const QTextCharFormat &f )
1.317 +{
1.318 + fontChanged(f.font());
1.319 + colorChanged(f.foreground().color());
1.320 + alignmentChanged(e->alignment());
1.321 + verticalAlignmentChanged (f.verticalAlignment());
1.322 +}
1.323 +
1.324 void TextEditor::alignmentChanged( int a )
1.325 {
1.326 if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
1.327 - actionAlignLeft->setOn( true );
1.328 + actionAlignLeft->setOn( true );
1.329 else if ( ( a & Qt::AlignHCenter ) )
1.330 - actionAlignCenter->setOn( true );
1.331 + actionAlignCenter->setOn( true );
1.332 else if ( ( a & Qt::AlignRight ) )
1.333 - actionAlignRight->setOn( true );
1.334 + actionAlignRight->setOn( true );
1.335 else if ( ( a & Qt::AlignJustify ) )
1.336 - actionAlignJustify->setOn( true );
1.337 + actionAlignJustify->setOn( true );
1.338 }
1.339
1.340 -void TextEditor::verticalAlignmentChanged(int a)
1.341 +void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a)
1.342 {
1.343 - /* FIXME QT3 alignment
1.344 - if (a == QTextEdit::AlignSuperScript ) {
1.345 - actionAlignSuperScript->setOn(true);
1.346 - actionAlignSubScript->setOn(false);
1.347 - } else if (a == QTextEdit::AlignSubScript ) {
1.348 - actionAlignSuperScript->setOn(false);
1.349 - actionAlignSubScript->setOn(true);
1.350 - } else {
1.351 - actionAlignSuperScript->setOn(false);
1.352 - actionAlignSubScript->setOn(false);
1.353 - }
1.354 - */
1.355 + actionAlignSubScript->setOn (false);
1.356 + actionAlignSuperScript->setOn (false);
1.357 + switch (a)
1.358 + {
1.359 + case QTextCharFormat::AlignSuperScript:
1.360 + actionAlignSuperScript->setOn (true);
1.361 + break;
1.362 + case QTextCharFormat::AlignSubScript:
1.363 + actionAlignSubScript->setOn (true);
1.364 + break;
1.365 + default: ;
1.366 + }
1.367 }
1.368
1.369
1.370 @@ -951,8 +874,6 @@
1.371 actionEditCut->setEnabled(true);
1.372 actionEditPaste->setEnabled(true);
1.373 actionEditDeleteAll->setEnabled(true);
1.374 - actionEditConvertPar->setEnabled(true);
1.375 - actionEditJoinLines->setEnabled(true);
1.376 actionFormatUseFixedFont->setEnabled(true);
1.377 }
1.378
1.379 @@ -968,8 +889,6 @@
1.380 actionEditCut->setEnabled(false);
1.381 actionEditPaste->setEnabled(false);
1.382 actionEditDeleteAll->setEnabled(false);
1.383 - actionEditConvertPar->setEnabled(false);
1.384 - actionEditJoinLines->setEnabled(false);
1.385 actionFormatUseFixedFont->setEnabled(false);
1.386 }
1.387