1.1 --- a/texteditor.cpp Mon May 08 13:25:46 2006 +0000
1.2 +++ b/texteditor.cpp Thu Sep 14 11:38:17 2006 +0000
1.3 @@ -1,28 +1,19 @@
1.4 #include "texteditor.h"
1.5
1.6 -#include <qcanvas.h>
1.7 -#include <qstatusbar.h>
1.8 -#include <qmessagebox.h>
1.9 -#include <qaction.h>
1.10 -#include <qapplication.h>
1.11 -#include <qpainter.h>
1.12 -#include <qprinter.h>
1.13 -#include <qfile.h>
1.14 -#include <qfiledialog.h>
1.15 -#include <qtoolbar.h>
1.16 -#include <qpopupmenu.h>
1.17 +#include <QPainter>
1.18 +#include <QPrinter>
1.19 +#include <QFile>
1.20 +#include <QFileDialog>
1.21 #include <qmenubar.h>
1.22 -#include <qtextedit.h>
1.23 -#include <qaccel.h>
1.24 #include <qtextstream.h>
1.25 -#include <qpaintdevicemetrics.h>
1.26 -#include <qsettings.h>
1.27 -#include <qfontdialog.h>
1.28 -#include <qmessagebox.h>
1.29 -#include <qcolordialog.h>
1.30 -#include <qregexp.h>
1.31 -#include <qlineedit.h>
1.32 -#include <qsimplerichtext.h>
1.33 +#include <QSettings>
1.34 +#include <QFontDialog>
1.35 +#include <QMessageBox>
1.36 +#include <QColorDialog>
1.37 +#include <QRegExp>
1.38 +#include <QList>
1.39 +#include <QPixmap>
1.40 +#include <QCloseEvent>
1.41
1.42 #include <iostream>
1.43 #include <cstdlib>
1.44 @@ -31,7 +22,6 @@
1.45 #include "noteobj.h"
1.46 #include "version.h"
1.47
1.48 -extern QCanvas* actCanvas;
1.49 extern int statusbarTime;
1.50 extern QSettings settings;
1.51
1.52 @@ -49,15 +39,16 @@
1.53 TextEditor::TextEditor()
1.54 {
1.55 printer = new QPrinter( QPrinter::HighResolution );
1.56 - printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1.57 + printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1.58
1.59 // Editor (use MyTextEdit to wrap verticalAlignmentChanged to
1.60 // int argument. see header file)
1.61 e = new MyTextEdit( this, "editor" );
1.62 e->setFocus();
1.63 - e->setTextFormat(RichText); // default
1.64 + e->setTextFormat(Qt::RichText); // default
1.65 e->setTabStopWidth (20); // unit is pixel
1.66 - e->setColor (black);
1.67 + e->setColor (Qt::black);
1.68 + e->setAutoFillBackground (true);
1.69 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
1.70 setCentralWidget( e );
1.71 statusBar()->message( "Ready", statusbarTime);
1.72 @@ -70,31 +61,26 @@
1.73 setupSettingsActions();
1.74
1.75 // Various states
1.76 - emptyPaper = QBrush(gray);
1.77 - filledPaper = QBrush(white);
1.78 - inactivePaper= QBrush(black);
1.79 setInactive();
1.80
1.81 // Load Settings
1.82 - resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
1.83 - settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
1.84 - move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
1.85 - settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
1.86 + resize (settings.value ( "/noteeditor/geometry/size", QSize(450,600)).toSize());
1.87 + move (settings.value ( "/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
1.88
1.89 - if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
1.90 + if (settings.value ( "/noteeditor/showWithMain",true).toBool())
1.91 setShowWithMain(true);
1.92 else
1.93 setShowWithMain(false);
1.94
1.95 - varFont.fromString( settings.readEntry
1.96 - ("/vym/noteeditor/fonts/varFont",
1.97 - "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
1.98 + varFont.fromString( settings.value
1.99 + ("/noteeditor/fonts/varFont",
1.100 + "Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString()
1.101 );
1.102 - fixedFont.fromString (settings.readEntry (
1.103 - "/vym/noteeditor/fonts/fixedFont",
1.104 - "Courier,14,-1,5,48,0,0,0,1,0")
1.105 + fixedFont.fromString (settings.value(
1.106 + "/noteeditor/fonts/fixedFont",
1.107 + "Courier,14,-1,5,48,0,0,0,1,0").toString()
1.108 );
1.109 - QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
1.110 + QString s=settings.value ("/noteeditor/fonts/fonthintDefault","variable").toString();
1.111 if (s == "fixed")
1.112 {
1.113 actionSettingsFonthintDefault->setOn (true);
1.114 @@ -107,7 +93,7 @@
1.115 filenameHint="";
1.116
1.117 // Save settings in vymrc
1.118 - settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1.119 + settings.setValue("/mainwindow/printerName",printer->printerName());
1.120 }
1.121
1.122
1.123 @@ -115,31 +101,24 @@
1.124 {
1.125 if (printer) delete printer;
1.126 // Save Settings
1.127 - settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
1.128 - settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
1.129 - settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
1.130 - settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
1.131 + settings.setValue( "/noteeditor/geometry/size", size() );
1.132 + settings.setValue( "/noteeditor/geometry/pos", pos() );
1.133
1.134 - if (showWithMain())
1.135 - settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
1.136 - else
1.137 - settings.writeEntry( "/vym/noteeditor/showWithMain","no");
1.138 + settings.setValue( "/noteeditor/showWithMain",showWithMain());
1.139
1.140 QString s;
1.141 if (actionSettingsFonthintDefault->isOn() )
1.142 s="fixed";
1.143 else
1.144 s="variable";
1.145 - settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
1.146 - settings.writeEntry ("/vym/noteeditor/fonts/varFont",
1.147 - varFont.toString() );
1.148 - settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
1.149 - fixedFont.toString() );
1.150 + settings.setValue( "/noteeditor/fonts/fonthintDefault",s );
1.151 + settings.setValue("/noteeditor/fonts/varFont", varFont.toString() );
1.152 + settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() );
1.153 }
1.154
1.155 bool TextEditor::isEmpty()
1.156 {
1.157 - if (e->text().length())
1.158 + if (e->toPlainText().length()>0)
1.159 return false;
1.160 else
1.161 return true;
1.162 @@ -210,10 +189,9 @@
1.163 return filenameHint;
1.164 }
1.165
1.166 -bool TextEditor::findText(const QString &t, const bool &cs)
1.167 +bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
1.168 {
1.169 - bool wo=false; // word matches
1.170 - if (e->find (t, cs, wo, true, 0, 0 ))
1.171 + if (e->find (t,flags))
1.172 return true;
1.173 else
1.174 return false;
1.175 @@ -221,229 +199,285 @@
1.176
1.177 void TextEditor::setupFileActions()
1.178 {
1.179 - QToolBar *tb = new QToolBar( this );
1.180 - tb->setLabel( "File Actions" );
1.181 - QPopupMenu *menu = new QPopupMenu( this );
1.182 - menuBar()->insertItem( tr( "&File" ), menu );
1.183 + QToolBar *tb = addToolBar ( tr("Note Actions") );
1.184 + QMenu *fileMenu = menuBar()->addMenu( tr( "&Note" ));
1.185
1.186 QAction *a;
1.187 - a = new QAction( tr( "Import" ), QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" );
1.188 + a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
1.189 + a->setStatusTip (tr( "Import" ) );
1.190 + a->setShortcut( Qt::CTRL + Qt::Key_O );
1.191 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
1.192 - a->setEnabled(false);
1.193 - a->addTo( tb );
1.194 - a->addTo( menu );
1.195 + tb->addAction (a);
1.196 + fileMenu->addAction (a);
1.197 actionFileLoad=a;
1.198
1.199 - menu->insertSeparator();
1.200 - a = new QAction( tr( "Export Note (HTML)" ), QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ), CTRL + Key_S, this, "fileSave" );
1.201 + fileMenu->addSeparator();
1.202 + a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
1.203 + a->setStatusTip (tr( "Export Note (HTML)" ) );
1.204 + a->setShortcut( Qt::CTRL + Qt::Key_S );
1.205 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
1.206 - a->addTo( tb );
1.207 - a->addTo( menu );
1.208 + tb->addAction (a);
1.209 + fileMenu->addAction (a);
1.210 actionFileSave=a;
1.211
1.212 - a = new QAction( tr( "Export Note As (HTML) " ), QPixmap(), tr( "Export &As... (HTML)" ), 0, this, "exportHTML" );
1.213 + a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
1.214 + a->setStatusTip (tr( "Export Note As (HTML) " ));
1.215 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
1.216 - a->addTo( menu );
1.217 + fileMenu->addAction (a);
1.218 actionFileSaveAs=a;
1.219
1.220 - a = new QAction( tr( "Export Note As (ASCII) " ), QPixmap(), tr( "Export &As...(ASCII)" ), ALT + Key_X, this, "exportASCII" );
1.221 + a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
1.222 + a->setStatusTip ( tr( "Export Note As (ASCII) " ) );
1.223 + a->setShortcut(Qt::ALT + Qt::Key_X );
1.224 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
1.225 - a->addTo( menu );
1.226 + fileMenu->addAction (a);
1.227 actionFileSaveAs=a;
1.228
1.229 - menu->insertSeparator();
1.230 - a = new QAction( tr( "Print Note" ), QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
1.231 + fileMenu->addSeparator();
1.232 + a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
1.233 + a->setStatusTip (tr( "Print Note" ) );
1.234 + a->setShortcut( Qt::CTRL + Qt::Key_P );
1.235 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
1.236 - a->addTo( tb );
1.237 - a->addTo( menu );
1.238 + tb->addAction (a);
1.239 + fileMenu->addAction (a);
1.240 actionFilePrint=a;
1.241 }
1.242
1.243 void TextEditor::setupEditActions()
1.244 {
1.245 - QToolBar *tb = new QToolBar( this );
1.246 - tb->setLabel( "Edit Actions" );
1.247 - QPopupMenu *menu = new QPopupMenu( this );
1.248 - menuBar()->insertItem( tr( "&Edit" ), menu );
1.249 + QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
1.250 + QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
1.251
1.252 QAction *a;
1.253 - a = new QAction( tr( "Undo" ), QPixmap(iconPath+"undo.png"), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" );
1.254 + a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
1.255 + a->setStatusTip ( tr( "Undo" ) );
1.256 + a->setShortcut(Qt::CTRL + Qt::Key_Z );
1.257 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
1.258 - a->addTo( menu );
1.259 - a->addTo( tb);
1.260 + editMenu->addAction (a);
1.261 + tb->addAction (a);
1.262 actionEditUndo=a;
1.263
1.264 - a = new QAction( tr( "Redo" ), QPixmap(iconPath+"redo.png" ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
1.265 + a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
1.266 + a->setStatusTip ( tr( "Redo" ) );
1.267 + a->setShortcut( Qt::CTRL + Qt::Key_Y );
1.268 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
1.269 - a->addTo( tb );
1.270 - a->addTo( menu );
1.271 + editMenu->addAction (a);
1.272 + tb->addAction (a);
1.273 actionEditRedo=a;
1.274
1.275 - menu->insertSeparator();
1.276 - a = new QAction( tr( "Select and copy all" ), QPixmap(), tr( "Select and copy &all" ), CTRL + Key_A, this, "editcopyall" );
1.277 + editMenu->addSeparator();
1.278 + a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
1.279 + a->setStatusTip ( tr( "Select and copy all" ) );
1.280 + a->setShortcut( Qt::CTRL + Qt::Key_A );
1.281 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
1.282 - a->addTo( menu );
1.283 + editMenu->addAction (a);
1.284
1.285 - menu->insertSeparator();
1.286 - a = new QAction( tr( "Copy" ), QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
1.287 + editMenu->addSeparator();
1.288 + a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
1.289 + a->setStatusTip ( tr( "Copy" ) );
1.290 + a->setShortcut( Qt::CTRL + Qt::Key_C );
1.291 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
1.292 - a->addTo( tb );
1.293 - a->addTo( menu );
1.294 + editMenu->addAction (a);
1.295 + tb->addAction (a);
1.296 actionEditCopy=a;
1.297
1.298 - a = new QAction( tr( "Cut" ), QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
1.299 + a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
1.300 + a->setStatusTip ( tr( "Cut" ) );
1.301 + a->setShortcut( Qt::CTRL + Qt::Key_X );
1.302 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
1.303 - a->addTo( tb );
1.304 - a->addTo( menu );
1.305 + editMenu->addAction (a);
1.306 + tb->addAction (a);
1.307 actionEditCut=a;
1.308
1.309 - a = new QAction( tr( "Paste" ), QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
1.310 + a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
1.311 + a->setStatusTip ( tr( "Paste" ) );
1.312 + a->setShortcut( Qt::CTRL + Qt::Key_V );
1.313 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
1.314 - a->addTo( tb );
1.315 - a->addTo( menu );
1.316 + editMenu->addAction (a);
1.317 + tb->addAction (a);
1.318 actionEditPaste=a;
1.319
1.320 - a = new QAction( tr( "Delete all" ), QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), 0, this, "editDeleteAll" );
1.321 + a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
1.322 + a->setStatusTip (tr( "Delete all" ) );
1.323 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
1.324 - a->addTo( tb );
1.325 - a->addTo( menu );
1.326 + editMenu->addAction (a);
1.327 + tb->addAction (a);
1.328 actionEditDeleteAll=a;
1.329
1.330 - a = new QAction( tr( "Convert paragraphs to linebreaks" ), QPixmap(), tr( "&Convert Paragraphs" ), ALT + Key_P, this, "editConvertPar" );
1.331 + a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this);
1.332 + /* TODO not needed any longer? remove also from docu...
1.333 + a->setStatusTip(tr( "Convert paragraphs to linebreaks" ));
1.334 + a->setShortcut( Qt::ALT + Qt::Key_P );
1.335 connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
1.336 - a->addTo( menu );
1.337 + editMenu->addAction (a);
1.338 + */
1.339 actionEditConvertPar=a;
1.340
1.341 - a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" );
1.342 + a = new QAction( QPixmap(), tr( "&Join lines" ), this);
1.343 + /* TODO not needed any longer? remove also from docu...
1.344 + a->setStatusTip(tr( "Join all lines of a paragraph" ) );
1.345 + a->setShortcut(Qt::ALT + Qt::Key_J );
1.346 connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
1.347 - a->addTo( menu );
1.348 + editMenu->addAction (a);
1.349 + */
1.350 actionEditJoinLines=a;
1.351 }
1.352
1.353 void TextEditor::setupFormatActions()
1.354 {
1.355 - QToolBar *tb = new QToolBar( this );
1.356 - tb->setLabel( "Format Actions" );
1.357 - QPopupMenu *menu = new QPopupMenu( this );
1.358 - menuBar()->insertItem( tr( "F&ormat" ), menu );
1.359 + QToolBar *tb = addToolBar ( tr("Format Actions" ));
1.360 + QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
1.361
1.362 QAction *a;
1.363
1.364 - a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), ALT + Key_I, this, "fontHint" );
1.365 + a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
1.366 + a->setStatusTip (tr( "Toggle font hint for the whole text" ) );
1.367 a->setToggleAction (true);
1.368 - a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
1.369 + a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
1.370 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
1.371 - a->addTo( menu );
1.372 - a->addTo( tb );
1.373 + formatMenu->addAction (a);
1.374 + tb->addAction (a);
1.375 actionFormatUseFixedFont=a;
1.376
1.377 - menu->insertSeparator();
1.378 -
1.379 - comboFont = new QComboBox( true, tb );
1.380 - QFontDatabase db;
1.381 - comboFont->insertStringList( db.families() );
1.382 +// comboFont = new QComboBox( true, tb );
1.383 + comboFont = new QComboBox;
1.384 + tb->addWidget (comboFont);
1.385 + QFontDatabase fontDB;
1.386 + comboFont->insertStringList( fontDB.families() );
1.387 connect( comboFont, SIGNAL( activated( const QString & ) ),
1.388 this, SLOT( textFamily( const QString & ) ) );
1.389 - comboFont->lineEdit()->setText( QApplication::font().family() );
1.390 -
1.391 - comboSize = new QComboBox( true, tb );
1.392 - QValueList<int> sizes = db.standardSizes();
1.393 - QValueList<int>::Iterator it = sizes.begin();
1.394 - for ( ; it != sizes.end(); ++it )
1.395 - comboSize->insertItem( QString::number( *it ) );
1.396 + comboFont->addItem( QApplication::font().family() );
1.397 + comboSize = new QComboBox;
1.398 + tb->addWidget (comboSize);
1.399 + QList<int> sizes=fontDB.standardSizes();
1.400 + QList<int>::iterator i = sizes.begin();
1.401 + while (i != sizes.end())
1.402 + {
1.403 + ++i; // increment i before using it
1.404 + comboSize->insertItem ( QString::number(*i));
1.405 + }
1.406 connect( comboSize, SIGNAL( activated( const QString & ) ),
1.407 this, SLOT( textSize( const QString & ) ) );
1.408 - comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
1.409 + comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
1.410
1.411 - menu->insertSeparator();
1.412 + formatMenu->addSeparator();
1.413
1.414 QPixmap pix( 16, 16 );
1.415 pix.fill( e->color());
1.416 - actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" );
1.417 - connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) );
1.418 - actionTextColor->addTo( tb );
1.419 - actionTextColor->addTo( menu );
1.420 + a = new QAction( pix, tr( "&Color..." ), this);
1.421 + formatMenu->addAction (a);
1.422 + tb->addAction (a);
1.423 + connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
1.424 + actionTextColor=a;
1.425
1.426 - actionTextBold = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), CTRL + Key_B, this, "textBold" );
1.427 - connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
1.428 - actionTextBold->addTo( tb );
1.429 - actionTextBold->addTo( menu );
1.430 - actionTextBold->setToggleAction( true );
1.431 - actionTextItalic = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" );
1.432 - connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) );
1.433 - actionTextItalic->addTo( tb );
1.434 - actionTextItalic->addTo( menu );
1.435 - actionTextItalic->setToggleAction( true );
1.436 - actionTextUnderline = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" );
1.437 - connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
1.438 - actionTextUnderline->addTo( tb );
1.439 - actionTextUnderline->addTo( menu );
1.440 - actionTextUnderline->setToggleAction( true );
1.441 - menu->insertSeparator();
1.442 + a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
1.443 + a->setShortcut(Qt::CTRL + Qt::Key_B );
1.444 + connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
1.445 + tb->addAction (a);
1.446 + formatMenu->addAction (a);
1.447 + a->setToggleAction( true );
1.448 + actionTextBold=a;
1.449 +
1.450 + a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
1.451 + a->setShortcut(Qt::CTRL + Qt::Key_I);
1.452 + connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
1.453 + tb->addAction (a);
1.454 + formatMenu->addAction (a);
1.455 + a->setToggleAction( true );
1.456 + actionTextItalic=a;
1.457 +
1.458 + a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
1.459 + a->setShortcut(Qt::CTRL + Qt::Key_U );
1.460 + connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
1.461 + tb->addAction (a);
1.462 + formatMenu->addAction (a);
1.463 + a->setToggleAction( true );
1.464 + actionTextUnderline=a;
1.465 + formatMenu->addSeparator();
1.466
1.467 QActionGroup *grp = new QActionGroup( this );
1.468 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
1.469
1.470 - actionAlignLeft = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" );
1.471 - actionAlignLeft->setToggleAction( true );
1.472 - actionAlignCenter = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" );
1.473 - actionAlignCenter->setToggleAction( true );
1.474 - actionAlignRight = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" );
1.475 - actionAlignRight->setToggleAction( true );
1.476 - actionAlignJustify = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" );
1.477 - actionAlignJustify->setToggleAction( true );
1.478 -
1.479 - grp->addTo( tb );
1.480 - grp->addTo( menu );
1.481 + a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
1.482 + a->setShortcut( Qt::CTRL+Qt::Key_L );
1.483 + a->setToggleAction( true );
1.484 + tb->addAction (a);
1.485 + formatMenu->addAction (a);
1.486 + actionAlignLeft=a;
1.487 + a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
1.488 + a->setShortcut( Qt::CTRL + Qt::Key_E);
1.489 + a->setToggleAction( true );
1.490 + tb->addAction (a);
1.491 + formatMenu->addAction (a);
1.492 + actionAlignCenter=a;
1.493 + a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
1.494 + a->setShortcut(Qt::CTRL + Qt::Key_R );
1.495 + a->setToggleAction( true );
1.496 + tb->addAction (a);
1.497 + formatMenu->addAction (a);
1.498 + actionAlignRight=a;
1.499 + a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
1.500 + a->setShortcut(Qt::CTRL + Qt::Key_J );
1.501 + a->setToggleAction( true );
1.502 + tb->addAction (a);
1.503 + formatMenu->addAction (a);
1.504 + actionAlignJustify=a;
1.505
1.506 QActionGroup *grp2 = new QActionGroup( this );
1.507 - grp2->setExclusive(false);
1.508 - actionAlignSubScript = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" );
1.509 + grp2->setExclusive(true);
1.510 + a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
1.511 + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
1.512 + a->setToggleAction( true );
1.513 + tb->addAction (a);
1.514 + formatMenu->addAction (a);
1.515 + connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.516 + actionAlignSubScript=a;
1.517
1.518 - actionAlignSubScript->setToggleAction( true );
1.519 - connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign()));
1.520 + a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
1.521 + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
1.522 + a->setToggleAction( true );
1.523 + tb->addAction (a);
1.524 + formatMenu->addAction (a);
1.525 + connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.526 + actionAlignSuperScript=a;
1.527
1.528 - actionAlignSuperScript = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" );
1.529 -
1.530 - actionAlignSuperScript->setToggleAction( true );
1.531 - connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign()));
1.532 -
1.533 - menu->insertSeparator();
1.534 + formatMenu->addSeparator();
1.535
1.536 - grp2->addTo(tb);
1.537 - grp2->addTo(menu);
1.538 -
1.539 connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
1.540 this, SLOT( fontChanged( const QFont & ) ) );
1.541 connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
1.542 this, SLOT( colorChanged( const QColor & ) ) );
1.543 + /*
1.544 connect( e, SIGNAL( currentAlignmentChanged( int ) ),
1.545 this, SLOT( alignmentChanged( int ) ) );
1.546 connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
1.547 this, SLOT( verticalAlignmentChanged(int)));
1.548 + */
1.549
1.550 }
1.551
1.552 void TextEditor::setupSettingsActions()
1.553 {
1.554 - QPopupMenu *menu = new QPopupMenu( this );
1.555 - menuBar()->insertItem( tr( "&Settings" ), menu );
1.556 + QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
1.557
1.558 QAction *a;
1.559 - a = new QAction( tr( "Set fixed font" ), QPixmap(), tr( "Set &fixed font" ), 0, this, "setFixedFont" );
1.560 + a = new QAction(tr( "Set &fixed font" ), this);
1.561 + a->setStatusTip ( tr( "Set fixed font" ));
1.562 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
1.563 - a->addTo( menu );
1.564 + settingsMenu->addAction (a);
1.565 actionSettingsFixedFont=a;
1.566
1.567 - a = new QAction( tr( "Set variable font" ), QPixmap(), tr( "Set &variable font" ), 0, this, "setvariableFont" );
1.568 + a = new QAction(tr( "Set &variable font" ), this);
1.569 + a->setStatusTip ( tr( "Set variable font" ) );
1.570 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
1.571 - a->addTo( menu );
1.572 + settingsMenu->addAction (a);
1.573 actionSettingsVarFont=a;
1.574
1.575 - a = new QAction( tr( "Used fixed font by default" ), QPixmap(), tr( "&fixed font is default" ), 0, this, "fonthintDefault" );
1.576 + a = new QAction(tr( "&fixed font is default" ), this);
1.577 + a->setStatusTip (tr( "Used fixed font by default" ) );
1.578 a->setToggleAction (true);
1.579 // set state later in constructor...
1.580 - a->addTo( menu );
1.581 + settingsMenu->addAction (a);
1.582 actionSettingsFonthintDefault=a;
1.583 }
1.584
1.585 @@ -451,7 +485,7 @@
1.586 {
1.587 if (state!=inactiveEditor)
1.588 {
1.589 - if (e->length())
1.590 + if (e->text().length())
1.591 {
1.592 QMessageBox mb( __VYM " - " +tr("Note Editor"),
1.593 "Loading will overwrite the existing note",
1.594 @@ -468,8 +502,12 @@
1.595 }
1.596 // Load note
1.597 QFileDialog *fd=new QFileDialog( this);
1.598 - fd->addFilter ("ASCII texts (*.txt)");
1.599 - fd->addFilter ("VYM notes (*.html)");
1.600 + QStringList types;
1.601 + types<< "VYM notes (*.html)" <<
1.602 + "ASCII texts (*.txt)" <<
1.603 + "All filed (*)";
1.604 + fd->setFilters (types);
1.605 + fd->setDirectory (QDir().current());
1.606 fd->show();
1.607 QString fn;
1.608 if ( fd->exec() == QDialog::Accepted )
1.609 @@ -478,7 +516,7 @@
1.610 if ( !fn.isEmpty() )
1.611 {
1.612 QFile f( fn );
1.613 - if ( !f.open( IO_ReadOnly ) )
1.614 + if ( !f.open( QIODevice::ReadOnly ) )
1.615 return;
1.616
1.617 QTextStream ts( &f );
1.618 @@ -498,7 +536,10 @@
1.619
1.620 QString TextEditor::getText()
1.621 {
1.622 - return e->text();
1.623 + if (e->toPlainText().isEmpty())
1.624 + return "";
1.625 + else
1.626 + return e->text();
1.627 }
1.628
1.629 void TextEditor::editorChanged()
1.630 @@ -509,9 +550,9 @@
1.631 state=filledEditor;
1.632
1.633 if (state==emptyEditor)
1.634 - e->setPaper (emptyPaper);
1.635 + setState (emptyEditor);
1.636 else
1.637 - e->setPaper (filledPaper);
1.638 + setState (filledEditor);
1.639 // SLOT is LinkableMapObj, which will update systemFlag
1.640 emit (textHasChanged() );
1.641 }
1.642 @@ -519,12 +560,8 @@
1.643
1.644 void TextEditor::setText(QString t)
1.645 {
1.646 - if ( !QStyleSheet::mightBeRichText( t ) )
1.647 - t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal );
1.648 e->setReadOnly(false);
1.649 e->setText(t);
1.650 -// editorChanged(); //not called automagically FIXME or is it?
1.651 -
1.652 enableActions();
1.653 }
1.654
1.655 @@ -532,7 +569,7 @@
1.656 {
1.657 state=inactiveEditor;
1.658 setText("");
1.659 - e->setPaper (inactivePaper);
1.660 + setState (inactiveEditor);
1.661 e->setReadOnly (true);
1.662
1.663 disableActions();
1.664 @@ -561,7 +598,7 @@
1.665 QMessageBox::Warning,
1.666 QMessageBox::Yes | QMessageBox::Default,
1.667 QMessageBox::Cancel | QMessageBox::Escape,
1.668 - QMessageBox::NoButton );
1.669 + Qt::NoButton );
1.670 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1.671 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1.672 switch( mb.exec() ) {
1.673 @@ -595,7 +632,7 @@
1.674
1.675 QString text = e->text();
1.676 QFile f( filename );
1.677 - if ( !f.open( IO_WriteOnly ) )
1.678 + if ( !f.open( QIODevice::WriteOnly ) )
1.679 {
1.680 statusBar()->message( QString("Could not write to %1").arg(filename),
1.681 statusbarTime );
1.682 @@ -616,9 +653,18 @@
1.683 // In X11 a copy&paste generates paragraphs,
1.684 // which is not always wanted
1.685 // This function replaces paragraphs by linebreaks.
1.686 +
1.687 + QString t;
1.688 + t=e->text();
1.689 + QRegExp re("<p.*>");
1.690 + re.setMinimal(true);
1.691 + t.replace (re,"");
1.692 + t.replace ("</p>","<br />");
1.693 + e->setText(t);
1.694 +
1.695 + /* TODO QT3 use seletion ()
1.696 int parFrom, parTo, indFrom, indTo;
1.697 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
1.698 - QString t;
1.699 if (parFrom>-1)
1.700 t=e->selectedText();
1.701 else
1.702 @@ -641,10 +687,12 @@
1.703 e->setText (e->text().replace(marker,t));
1.704 } else
1.705 e->setText(t);
1.706 + */
1.707 }
1.708
1.709 void TextEditor::textJoinLines()
1.710 {
1.711 +/* TODO QT3
1.712 int parFrom, parTo, indFrom, indTo;
1.713 e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
1.714 QString t;
1.715 @@ -675,6 +723,7 @@
1.716 e->setText (e->text().replace(marker,t));
1.717 } else
1.718 e->setText(t);
1.719 +*/
1.720 }
1.721
1.722 void TextEditor::textExportAsASCII()
1.723 @@ -704,7 +753,7 @@
1.724 QMessageBox::Warning,
1.725 QMessageBox::Yes | QMessageBox::Default,
1.726 QMessageBox::Cancel | QMessageBox::Escape,
1.727 - QMessageBox::NoButton );
1.728 + Qt::NoButton );
1.729 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1.730 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1.731 ret=mb.exec();
1.732 @@ -713,7 +762,7 @@
1.733 return;
1.734
1.735 // save
1.736 - if ( !file.open( IO_WriteOnly ) )
1.737 + if ( !file.open( QIODevice::WriteOnly ) )
1.738 statusBar()->message( QString("Could not write to %1").arg(filename),
1.739 statusbarTime );
1.740 else
1.741 @@ -730,41 +779,16 @@
1.742
1.743 void TextEditor::textPrint()
1.744 {
1.745 - printer->setFullPage(TRUE);
1.746 - if ( printer->setup( this ) )
1.747 - {
1.748 - QPainter p( printer );
1.749 - // Check that there is a valid device to print to.
1.750 - if ( !p.device() ) return;
1.751 - QPaintDeviceMetrics metrics( p.device() );
1.752 - int dpiy = metrics.logicalDpiY();
1.753 - int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
1.754 - QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
1.755 - QFont font( e->currentFont() );
1.756 - font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
1.757
1.758 - QSimpleRichText richText( e->text(), font,
1.759 - e->context(),
1.760 - e->styleSheet(),
1.761 - e->mimeSourceFactory(),
1.762 - body.height() );
1.763 - richText.setWidth( &p, body.width() );
1.764 - QRect view( body );
1.765 - int page = 1;
1.766 - do
1.767 - {
1.768 - richText.draw( &p, body.left(), body.top(), view, colorGroup() );
1.769 - view.moveBy( 0, body.height() );
1.770 - p.translate( 0 , -body.height() );
1.771 - p.setFont( font );
1.772 - p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
1.773 - view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
1.774 - if ( view.top() >= richText.height() )
1.775 - break;
1.776 - printer->newPage();
1.777 - page++;
1.778 - } while (TRUE);
1.779 - }
1.780 + QTextDocument *document = e->document();
1.781 + QPrinter printer;
1.782 +
1.783 + QPrintDialog *dialog = new QPrintDialog(&printer, this);
1.784 + dialog->setWindowTitle(tr("Print Document"));
1.785 + if (dialog->exec() != QDialog::Accepted)
1.786 + return;
1.787 +
1.788 + document->print(&printer);
1.789 }
1.790
1.791 void TextEditor::textEditUndo()
1.792 @@ -774,12 +798,12 @@
1.793 void TextEditor::toggleFonthint()
1.794 {
1.795 setUpdatesEnabled (false);
1.796 - e->selectAll (true);
1.797 + e->selectAll ();
1.798 if (!actionFormatUseFixedFont->isOn() )
1.799 e->setCurrentFont (varFont);
1.800 else
1.801 e->setCurrentFont (fixedFont);
1.802 - e->selectAll (false);
1.803 + e->selectAll ();
1.804 setUpdatesEnabled (true);
1.805 repaint();
1.806 }
1.807 @@ -837,24 +861,25 @@
1.808 return;
1.809 e->setColor( col );
1.810 QPixmap pix( 16, 16 );
1.811 - pix.fill( black );
1.812 + pix.fill( Qt::black );
1.813 actionTextColor->setIconSet( pix );
1.814 }
1.815
1.816 void TextEditor::textAlign( QAction *a )
1.817 {
1.818 if ( a == actionAlignLeft )
1.819 - e->setAlignment( AlignLeft );
1.820 + e->setAlignment( Qt::AlignLeft );
1.821 else if ( a == actionAlignCenter )
1.822 - e->setAlignment( AlignHCenter );
1.823 + e->setAlignment( Qt::AlignHCenter );
1.824 else if ( a == actionAlignRight )
1.825 - e->setAlignment( AlignRight );
1.826 + e->setAlignment( Qt::AlignRight );
1.827 else if ( a == actionAlignJustify )
1.828 - e->setAlignment( AlignJustify );
1.829 + e->setAlignment( Qt::AlignJustify );
1.830 }
1.831
1.832 void TextEditor::textVAlign()
1.833 {
1.834 +/* FIXME QT3 alignment
1.835 if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
1.836 e->setVerticalAlignment( QTextEdit::AlignSuperScript);
1.837 } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
1.838 @@ -862,13 +887,16 @@
1.839 } else {
1.840 e->setVerticalAlignment( QTextEdit::AlignNormal);
1.841 }
1.842 +*/
1.843 }
1.844
1.845
1.846 void TextEditor::fontChanged( const QFont &f )
1.847 {
1.848 +/*
1.849 comboFont->lineEdit()->setText( f.family() );
1.850 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
1.851 +*/
1.852 actionTextBold->setOn( f.bold() );
1.853 actionTextItalic->setOn( f.italic() );
1.854 actionTextUnderline->setOn( f.underline() );
1.855 @@ -883,18 +911,19 @@
1.856
1.857 void TextEditor::alignmentChanged( int a )
1.858 {
1.859 - if ( ( a == AlignAuto ) || ( a & AlignLeft ))
1.860 + if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
1.861 actionAlignLeft->setOn( true );
1.862 - else if ( ( a & AlignHCenter ) )
1.863 + else if ( ( a & Qt::AlignHCenter ) )
1.864 actionAlignCenter->setOn( true );
1.865 - else if ( ( a & AlignRight ) )
1.866 + else if ( ( a & Qt::AlignRight ) )
1.867 actionAlignRight->setOn( true );
1.868 - else if ( ( a & AlignJustify ) )
1.869 + else if ( ( a & Qt::AlignJustify ) )
1.870 actionAlignJustify->setOn( true );
1.871 }
1.872
1.873 void TextEditor::verticalAlignmentChanged(int a)
1.874 {
1.875 + /* FIXME QT3 alignment
1.876 if (a == QTextEdit::AlignSuperScript ) {
1.877 actionAlignSuperScript->setOn(true);
1.878 actionAlignSubScript->setOn(false);
1.879 @@ -905,6 +934,7 @@
1.880 actionAlignSuperScript->setOn(false);
1.881 actionAlignSubScript->setOn(false);
1.882 }
1.883 + */
1.884 }
1.885
1.886
1.887 @@ -943,4 +973,20 @@
1.888 actionFormatUseFixedFont->setEnabled(false);
1.889 }
1.890
1.891 +void TextEditor::setState (EditorState s)
1.892 +{
1.893 +
1.894 + QPalette p=palette();
1.895 + QColor c;
1.896 + switch (s)
1.897 + {
1.898 + case emptyEditor: c=QColor (150,150,150); break;
1.899 + case filledEditor: c=QColor (255,255,255); break;
1.900 + case inactiveEditor: c=QColor (0,0,0);
1.901 + }
1.902 + p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
1.903 + p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
1.904 + e->setPalette(p);
1.905 +}
1.906
1.907 +