1.1 --- a/texteditor.cpp Sun Jan 30 12:58:47 2005 +0000
1.2 +++ b/texteditor.cpp Thu Jul 30 07:40:05 2009 +0000
1.3 @@ -1,54 +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 <qmenubar.h>
1.18 -#include <qtextedit.h>
1.19 -#include <qaccel.h>
1.20 -#include <qtextstream.h>
1.21 -#include <qpaintdevicemetrics.h>
1.22 -#include <qsettings.h>
1.23 -#include <qfontdialog.h>
1.24 -#include <qmessagebox.h>
1.25 -#include <qcolordialog.h>
1.26 -#include <qregexp.h>
1.27 -#include <qlineedit.h>
1.28 -#include <qsimplerichtext.h>
1.29 -
1.30 #include <iostream>
1.31 -#include <stdlib.h>
1.32 +#include <cstdlib>
1.33 #include <typeinfo>
1.34
1.35 -#include "icons/fileopen.xpm"
1.36 -#include "icons/filesave.xpm"
1.37 -#include "icons/fileprint.xpm"
1.38 -#include "icons/editundo.xpm"
1.39 -#include "icons/editredo.xpm"
1.40 -#include "icons/editcopy.xpm"
1.41 -#include "icons/editcut.xpm"
1.42 -#include "icons/editpaste.xpm"
1.43 -#include "icons/edittrash.xpm"
1.44 -#include "icons/formatfixedfont.xpm"
1.45 -#include "icons/formattextbold.xpm"
1.46 -#include "icons/formattextitalic.xpm"
1.47 -#include "icons/formattextunder.xpm"
1.48 -#include "icons/formattextleft.xpm"
1.49 -#include "icons/formattextcenter.xpm"
1.50 -#include "icons/formattextright.xpm"
1.51 -#include "icons/formattextjustify.xpm"
1.52 +#include "noteobj.h"
1.53 +#include "settings.h"
1.54
1.55 -extern QCanvas* actCanvas;
1.56 extern int statusbarTime;
1.57 -extern QSettings settings;
1.58 +extern Settings settings;
1.59 +
1.60 +extern QAction *actionViewToggleNoteEditor;
1.61 +
1.62 +extern QString iconPath;
1.63 +extern QString vymName;
1.64
1.65 using namespace std;
1.66
1.67 @@ -56,20 +21,28 @@
1.68 ///////////////////////////////////////////////////////////////////////
1.69 ///////////////////////////////////////////////////////////////////////
1.70
1.71 +
1.72 TextEditor::TextEditor()
1.73 {
1.74 printer = new QPrinter( QPrinter::HighResolution );
1.75 + printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1.76
1.77 - // Editor
1.78 - e = new QTextEdit( this, "editor" );
1.79 + e = new QTextEdit( this);
1.80 e->setFocus();
1.81 - e->setTextFormat(RichText); // default
1.82 + e->setTextFormat(Qt::RichText); // default
1.83 e->setTabStopWidth (20); // unit is pixel
1.84 - e->setColor (black);
1.85 + e->setColor (Qt::black);
1.86 + e->setAutoFillBackground (true);
1.87 connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
1.88 setCentralWidget( e );
1.89 - statusBar()->message( "Ready", statusbarTime);
1.90 - setCaption("VYM - Note Editor");
1.91 + statusBar()->message( tr("Ready","Statusbar message"), statusbarTime);
1.92 + setCaption(vymName +" - " +tr ("Note Editor","Window caption"));
1.93 +
1.94 +
1.95 + connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
1.96 + this, SLOT(formatChanged(const QTextCharFormat &)));
1.97 +
1.98 +
1.99
1.100 // Toolbars
1.101 setupFileActions();
1.102 @@ -78,31 +51,24 @@
1.103 setupSettingsActions();
1.104
1.105 // Various states
1.106 - emptyPaper = QBrush(gray);
1.107 - filledPaper = QBrush(white);
1.108 - inactivePaper= QBrush(black);
1.109 + blockChangedSignal=false;
1.110 setInactive();
1.111
1.112 // Load Settings
1.113 - resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450),
1.114 - settings.readNumEntry( "/vym/noteeditor/geometry/height",600));
1.115 - move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150),
1.116 - settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50));
1.117 + resize (settings.value ( "/satellite/noteeditor/geometry/size", QSize(450,600)).toSize());
1.118 + move (settings.value ( "/satellite/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
1.119
1.120 - if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes")
1.121 - setShowWithMain(true);
1.122 - else
1.123 - setShowWithMain(false);
1.124 + setShowWithMain (settings.value ( "/satellite/noteeditor/showWithMain",true).toBool());
1.125
1.126 - varFont.fromString( settings.readEntry
1.127 - ("/vym/noteeditor/fonts/varFont",
1.128 - "Nimbus Sans l,14,-1,5,48,0,0,0,0,0")
1.129 + varFont.fromString( settings.value
1.130 + ("/satellite/noteeditor/fonts/varFont",
1.131 + "Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString()
1.132 );
1.133 - fixedFont.fromString (settings.readEntry (
1.134 - "/vym/noteeditor/fonts/fixedFont",
1.135 - "Courier,14,-1,5,48,0,0,0,1,0")
1.136 + fixedFont.fromString (settings.value(
1.137 + "/satellite/noteeditor/fonts/fixedFont",
1.138 + "Courier,14,-1,5,48,0,0,0,1,0").toString()
1.139 );
1.140 - QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable");
1.141 + QString s=settings.value ("/satellite/noteeditor/fonts/fonthintDefault","variable").toString();
1.142 if (s == "fixed")
1.143 {
1.144 actionSettingsFonthintDefault->setOn (true);
1.145 @@ -112,6 +78,13 @@
1.146 actionSettingsFonthintDefault->setOn (false);
1.147 e->setCurrentFont (varFont);
1.148 }
1.149 + filenameHint="";
1.150 +
1.151 + // Restore position of toolbars
1.152 + restoreState (settings.value("/satellite/noteeditor/state",0).toByteArray());
1.153 +
1.154 + // Save settings in vymrc
1.155 + settings.setValue("/mainwindow/printerName",printer->printerName());
1.156 }
1.157
1.158
1.159 @@ -119,31 +92,27 @@
1.160 {
1.161 if (printer) delete printer;
1.162 // Save Settings
1.163 - settings.writeEntry( "/vym/noteeditor/geometry/width", width() );
1.164 - settings.writeEntry( "/vym/noteeditor/geometry/height", height() );
1.165 - settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() );
1.166 - settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() );
1.167 + settings.setValue( "/satellite/noteeditor/geometry/size", size() );
1.168 + settings.setValue( "/satellite/noteeditor/geometry/pos", pos() );
1.169 + settings.setValue ("/satellite/noteeditor/state",saveState(0));
1.170
1.171 - if (showWithMain())
1.172 - settings.writeEntry( "/vym/noteeditor/showWithMain","yes");
1.173 - else
1.174 - settings.writeEntry( "/vym/noteeditor/showWithMain","no");
1.175 + settings.setValue( "/satellite/noteeditor/showWithMain",showwithmain);
1.176
1.177 QString s;
1.178 if (actionSettingsFonthintDefault->isOn() )
1.179 s="fixed";
1.180 else
1.181 s="variable";
1.182 - settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s );
1.183 - settings.writeEntry ("/vym/noteeditor/fonts/varFont",
1.184 - varFont.toString() );
1.185 - settings.writeEntry ("/vym/noteeditor/fonts/fixedFont",
1.186 - fixedFont.toString() );
1.187 + settings.setValue( "/satellite/noteeditor/fonts/fonthintDefault",s );
1.188 + settings.setValue("/satellite/noteeditor/fonts/varFont", varFont.toString() );
1.189 + settings.setValue("/satellite/noteeditor/fonts/fixedFont", fixedFont.toString() );
1.190 +
1.191 +
1.192 }
1.193
1.194 bool TextEditor::isEmpty()
1.195 {
1.196 - if (e->text().length())
1.197 + if (e->toPlainText().length()>0)
1.198 return false;
1.199 else
1.200 return true;
1.201 @@ -159,6 +128,7 @@
1.202 return showwithmain;
1.203 }
1.204
1.205 +
1.206 void TextEditor::setFontHint (const QString &fh)
1.207 {
1.208 if (fh=="fixed")
1.209 @@ -187,16 +157,18 @@
1.210 void TextEditor::setFilename(const QString &fn)
1.211 {
1.212 if (state==filledEditor)
1.213 + {
1.214 if (fn.isEmpty() )
1.215 {
1.216 filename="";
1.217 - statusBar()->message( "No filename available for this note.", statusbarTime );
1.218 + statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime );
1.219 }
1.220 else
1.221 {
1.222 filename=fn;
1.223 - statusBar()->message( QString( "Current filename is %1" ).arg( filename ), statusbarTime );
1.224 + statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime );
1.225 }
1.226 + }
1.227 }
1.228
1.229 QString TextEditor::getFilename()
1.230 @@ -204,10 +176,19 @@
1.231 return filename;
1.232 }
1.233
1.234 -bool TextEditor::findText(const QString &t, const bool &cs)
1.235 +void TextEditor::setFilenameHint(const QString &fnh)
1.236 {
1.237 - bool wo=false; // word matches
1.238 - if (e->find (t, cs, wo, true, 0, 0 ))
1.239 + filenameHint=fnh;
1.240 +}
1.241 +
1.242 +QString TextEditor::getFilenameHint()
1.243 +{
1.244 + return filenameHint;
1.245 +}
1.246 +
1.247 +bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
1.248 +{
1.249 + if (e->find (t,flags))
1.250 return true;
1.251 else
1.252 return false;
1.253 @@ -215,210 +196,257 @@
1.254
1.255 void TextEditor::setupFileActions()
1.256 {
1.257 - QToolBar *tb = new QToolBar( this );
1.258 - tb->setLabel( "File Actions" );
1.259 - QPopupMenu *menu = new QPopupMenu( this );
1.260 - menuBar()->insertItem( tr( "&File" ), menu );
1.261 + QToolBar *tb = addToolBar ( tr("Note Actions") );
1.262 + tb->setObjectName ("noteEditorFileActions");
1.263 + QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" ));
1.264
1.265 QAction *a;
1.266 - a = new QAction( tr( "Import" ), QPixmap( fileopen_xpm), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" );
1.267 + a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
1.268 + a->setStatusTip (tr( "Import","Status tip for Note menu" ) );
1.269 + a->setShortcut( Qt::CTRL + Qt::Key_O );
1.270 connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
1.271 - a->setEnabled(false);
1.272 - a->addTo( tb );
1.273 - a->addTo( menu );
1.274 + tb->addAction (a);
1.275 + fileMenu->addAction (a);
1.276 actionFileLoad=a;
1.277
1.278 - menu->insertSeparator();
1.279 - a = new QAction( tr( "Export Note (HTML)" ), QPixmap( filesave_xpm ), tr( "&Export..." ), CTRL + Key_S, this, "fileSave" );
1.280 + fileMenu->addSeparator();
1.281 + a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
1.282 + a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) );
1.283 + a->setShortcut( Qt::CTRL + Qt::Key_S );
1.284 connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
1.285 - a->addTo( tb );
1.286 - a->addTo( menu );
1.287 + tb->addAction (a);
1.288 + fileMenu->addAction (a);
1.289 actionFileSave=a;
1.290
1.291 - a = new QAction( tr( "Export Note As (HTML) " ), QPixmap(), tr( "Export &As... (HTML)" ), 0, this, "exportHTML" );
1.292 + a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
1.293 + a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu" ));
1.294 connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
1.295 - a->addTo( menu );
1.296 + fileMenu->addAction (a);
1.297 actionFileSaveAs=a;
1.298
1.299 - a = new QAction( tr( "Export Note As (ASCII) " ), QPixmap(), tr( "Export &As...(ASCII)" ), ALT + Key_X, this, "exportASCII" );
1.300 + a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
1.301 + a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) );
1.302 + a->setShortcut(Qt::ALT + Qt::Key_X );
1.303 connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
1.304 - a->addTo( menu );
1.305 + fileMenu->addAction (a);
1.306 actionFileSaveAs=a;
1.307
1.308 - menu->insertSeparator();
1.309 - a = new QAction( tr( "Print Note" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
1.310 + fileMenu->addSeparator();
1.311 + a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
1.312 + a->setStatusTip (tr( "Print Note","Status tip for note menu" ) );
1.313 + a->setShortcut( Qt::CTRL + Qt::Key_P );
1.314 connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
1.315 - a->addTo( tb );
1.316 - a->addTo( menu );
1.317 + tb->addAction (a);
1.318 + fileMenu->addAction (a);
1.319 actionFilePrint=a;
1.320 }
1.321
1.322 void TextEditor::setupEditActions()
1.323 {
1.324 - QToolBar *tb = new QToolBar( this );
1.325 - tb->setLabel( "Edit Actions" );
1.326 - QPopupMenu *menu = new QPopupMenu( this );
1.327 - menuBar()->insertItem( tr( "&Edit" ), menu );
1.328 + QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
1.329 + tb->setObjectName ("noteEditorEditActions");
1.330 + QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
1.331
1.332 QAction *a;
1.333 - a = new QAction( tr( "Undo" ), QPixmap(editundo_xpm), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" );
1.334 + a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
1.335 + a->setStatusTip ( tr( "Undo","Status tip for note menu" ) );
1.336 + a->setShortcut(Qt::CTRL + Qt::Key_Z );
1.337 connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
1.338 - a->addTo( menu );
1.339 - a->addTo( tb);
1.340 + editMenu->addAction (a);
1.341 + tb->addAction (a);
1.342 actionEditUndo=a;
1.343
1.344 - a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" );
1.345 + a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
1.346 + a->setStatusTip ( tr( "Redo","Status tip for note menu" ) );
1.347 + a->setShortcut( Qt::CTRL + Qt::Key_Y );
1.348 connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
1.349 - a->addTo( tb );
1.350 - a->addTo( menu );
1.351 + editMenu->addAction (a);
1.352 + tb->addAction (a);
1.353 actionEditRedo=a;
1.354
1.355 - menu->insertSeparator();
1.356 - a = new QAction( tr( "Select and copy all" ), QPixmap(), tr( "Select and copy &all" ), CTRL + Key_A, this, "editcopyall" );
1.357 + editMenu->addSeparator();
1.358 + a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
1.359 + a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) );
1.360 + a->setShortcut( Qt::CTRL + Qt::Key_A );
1.361 connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
1.362 - a->addTo( menu );
1.363 + editMenu->addAction (a);
1.364
1.365 - menu->insertSeparator();
1.366 - a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
1.367 + editMenu->addSeparator();
1.368 + a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
1.369 + a->setStatusTip ( tr( "Copy","Status tip for note menu" ) );
1.370 + a->setShortcut( Qt::CTRL + Qt::Key_C );
1.371 connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
1.372 - a->addTo( tb );
1.373 - a->addTo( menu );
1.374 + editMenu->addAction (a);
1.375 + tb->addAction (a);
1.376 actionEditCopy=a;
1.377
1.378 - a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
1.379 + a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
1.380 + a->setStatusTip ( tr( "Cut","Status tip for note menu" ) );
1.381 + a->setShortcut( Qt::CTRL + Qt::Key_X );
1.382 connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
1.383 - a->addTo( tb );
1.384 - a->addTo( menu );
1.385 + editMenu->addAction (a);
1.386 + tb->addAction (a);
1.387 actionEditCut=a;
1.388
1.389 - a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
1.390 + a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
1.391 + a->setStatusTip ( tr( "Paste","Status tip for note menu" ) );
1.392 + a->setShortcut( Qt::CTRL + Qt::Key_V );
1.393 connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
1.394 - a->addTo( tb );
1.395 - a->addTo( menu );
1.396 + editMenu->addAction (a);
1.397 + tb->addAction (a);
1.398 actionEditPaste=a;
1.399
1.400 - a = new QAction( tr( "Delete all" ), QPixmap( edittrash_xpm ), tr( "&Delete All" ), 0, this, "editDeleteAll" );
1.401 + a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
1.402 + a->setStatusTip (tr( "Delete all","Status tip for note menu" ) );
1.403 connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
1.404 - a->addTo( tb );
1.405 - a->addTo( menu );
1.406 + editMenu->addAction (a);
1.407 + tb->addAction (a);
1.408 actionEditDeleteAll=a;
1.409
1.410 - a = new QAction( tr( "Convert paragraphs to linebreaks" ), QPixmap(), tr( "&Convert Paragraphs" ), ALT + Key_P, this, "editConvertPar" );
1.411 - connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) );
1.412 - a->addTo( menu );
1.413 - actionEditConvertPar=a;
1.414 -
1.415 - a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" );
1.416 - connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) );
1.417 - a->addTo( menu );
1.418 - actionEditJoinLines=a;
1.419 }
1.420
1.421 void TextEditor::setupFormatActions()
1.422 {
1.423 - QToolBar *tb = new QToolBar( this );
1.424 - tb->setLabel( "Format Actions" );
1.425 - QPopupMenu *menu = new QPopupMenu( this );
1.426 - menuBar()->insertItem( tr( "&Format" ), menu );
1.427 + QToolBar *tb = addToolBar ( tr("Format Actions" ));
1.428 + tb->setObjectName ("noteEditorFormatActions");
1.429 + QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
1.430
1.431 QAction *a;
1.432
1.433 - a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(formatfixedfont_xpm), tr( "&Font hint" ), ALT + Key_I, this, "fontHint" );
1.434 + a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
1.435 + a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) );
1.436 a->setToggleAction (true);
1.437 - a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) );
1.438 + a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
1.439 connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
1.440 - a->addTo( menu );
1.441 - a->addTo( tb );
1.442 + formatMenu->addAction (a);
1.443 + tb->addAction (a);
1.444 actionFormatUseFixedFont=a;
1.445
1.446 - menu->insertSeparator();
1.447 -
1.448 - comboFont = new QComboBox( true, tb );
1.449 - QFontDatabase db;
1.450 - comboFont->insertStringList( db.families() );
1.451 + comboFont = new QComboBox;
1.452 + tb->addWidget (comboFont);
1.453 + QFontDatabase fontDB;
1.454 + comboFont->insertStringList( fontDB.families() );
1.455 connect( comboFont, SIGNAL( activated( const QString & ) ),
1.456 this, SLOT( textFamily( const QString & ) ) );
1.457 - comboFont->lineEdit()->setText( QApplication::font().family() );
1.458 -
1.459 - comboSize = new QComboBox( true, tb );
1.460 - QValueList<int> sizes = db.standardSizes();
1.461 - QValueList<int>::Iterator it = sizes.begin();
1.462 - for ( ; it != sizes.end(); ++it )
1.463 - comboSize->insertItem( QString::number( *it ) );
1.464 + comboFont->addItem( QApplication::font().family() );
1.465 + comboSize = new QComboBox;
1.466 + tb->addWidget (comboSize);
1.467 + QList<int> sizes=fontDB.standardSizes();
1.468 + QList<int>::iterator i = sizes.begin();
1.469 + while (i != sizes.end())
1.470 + {
1.471 + ++i; // increment i before using it
1.472 + comboSize->insertItem ( QString::number(*i));
1.473 + }
1.474 connect( comboSize, SIGNAL( activated( const QString & ) ),
1.475 this, SLOT( textSize( const QString & ) ) );
1.476 - comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
1.477 + comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
1.478
1.479 - menu->insertSeparator();
1.480 + formatMenu->addSeparator();
1.481
1.482 QPixmap pix( 16, 16 );
1.483 pix.fill( e->color());
1.484 - actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" );
1.485 - connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) );
1.486 - actionTextColor->addTo( tb );
1.487 - actionTextColor->addTo( menu );
1.488 + a = new QAction( pix, tr( "&Color..." ), this);
1.489 + formatMenu->addAction (a);
1.490 + tb->addAction (a);
1.491 + connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
1.492 + actionTextColor=a;
1.493
1.494 - actionTextBold = new QAction( QPixmap (formattextbold_xpm), tr( "&Bold" ), CTRL + Key_B, this, "textBold" );
1.495 - connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
1.496 - actionTextBold->addTo( tb );
1.497 - actionTextBold->addTo( menu );
1.498 - actionTextBold->setToggleAction( true );
1.499 - actionTextItalic = new QAction( QPixmap(formattextitalic_xpm ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" );
1.500 - connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) );
1.501 - actionTextItalic->addTo( tb );
1.502 - actionTextItalic->addTo( menu );
1.503 - actionTextItalic->setToggleAction( true );
1.504 - actionTextUnderline = new QAction( QPixmap (formattextunder_xpm ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" );
1.505 - connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
1.506 - actionTextUnderline->addTo( tb );
1.507 - actionTextUnderline->addTo( menu );
1.508 - actionTextUnderline->setToggleAction( true );
1.509 - menu->insertSeparator();
1.510 + a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
1.511 + a->setShortcut(Qt::CTRL + Qt::Key_B );
1.512 + connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
1.513 + tb->addAction (a);
1.514 + formatMenu->addAction (a);
1.515 + a->setToggleAction( true );
1.516 + actionTextBold=a;
1.517 +
1.518 + a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
1.519 + a->setShortcut(Qt::CTRL + Qt::Key_I);
1.520 + connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
1.521 + tb->addAction (a);
1.522 + formatMenu->addAction (a);
1.523 + a->setToggleAction( true );
1.524 + actionTextItalic=a;
1.525 +
1.526 + a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
1.527 + a->setShortcut(Qt::CTRL + Qt::Key_U );
1.528 + connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
1.529 + tb->addAction (a);
1.530 + formatMenu->addAction (a);
1.531 + a->setToggleAction( true );
1.532 + actionTextUnderline=a;
1.533 + formatMenu->addSeparator();
1.534
1.535 + QActionGroup *grp2 = new QActionGroup( this );
1.536 + grp2->setExclusive(true);
1.537 + a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
1.538 + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
1.539 + a->setToggleAction( true );
1.540 + tb->addAction (a);
1.541 + formatMenu->addAction (a);
1.542 + connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.543 + actionAlignSubScript=a;
1.544 +
1.545 + a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
1.546 + a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
1.547 + a->setToggleAction( true );
1.548 + tb->addAction (a);
1.549 + formatMenu->addAction (a);
1.550 + connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
1.551 + actionAlignSuperScript=a;
1.552 QActionGroup *grp = new QActionGroup( this );
1.553 connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
1.554
1.555 - actionAlignLeft = new QAction( QPixmap (formattextleft_xpm ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" );
1.556 - actionAlignLeft->setToggleAction( true );
1.557 - actionAlignCenter = new QAction( QPixmap (formattextcenter_xpm ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" );
1.558 - actionAlignCenter->setToggleAction( true );
1.559 - actionAlignRight = new QAction( QPixmap (formattextright_xpm ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" );
1.560 - actionAlignRight->setToggleAction( true );
1.561 - actionAlignJustify = new QAction( QPixmap ( formattextjustify_xpm ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" );
1.562 - actionAlignJustify->setToggleAction( true );
1.563 + formatMenu->addSeparator();
1.564
1.565 - grp->addTo( tb );
1.566 - grp->addTo( menu );
1.567 -
1.568 - connect( e, SIGNAL( currentFontChanged( const QFont & ) ),
1.569 - this, SLOT( fontChanged( const QFont & ) ) );
1.570 - connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
1.571 - this, SLOT( colorChanged( const QColor & ) ) );
1.572 - connect( e, SIGNAL( currentAlignmentChanged( int ) ),
1.573 - this, SLOT( alignmentChanged( int ) ) );
1.574 -
1.575 + a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
1.576 + a->setShortcut( Qt::CTRL+Qt::Key_L );
1.577 + a->setToggleAction( true );
1.578 + tb->addAction (a);
1.579 + formatMenu->addAction (a);
1.580 + actionAlignLeft=a;
1.581 + a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
1.582 + a->setShortcut( Qt::CTRL + Qt::Key_E);
1.583 + a->setToggleAction( true );
1.584 + tb->addAction (a);
1.585 + formatMenu->addAction (a);
1.586 + actionAlignCenter=a;
1.587 + a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
1.588 + a->setShortcut(Qt::CTRL + Qt::Key_R );
1.589 + a->setToggleAction( true );
1.590 + tb->addAction (a);
1.591 + formatMenu->addAction (a);
1.592 + actionAlignRight=a;
1.593 + a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
1.594 + a->setShortcut(Qt::CTRL + Qt::Key_J );
1.595 + a->setToggleAction( true );
1.596 + tb->addAction (a);
1.597 + formatMenu->addAction (a);
1.598 + actionAlignJustify=a;
1.599 }
1.600
1.601 void TextEditor::setupSettingsActions()
1.602 {
1.603 - QPopupMenu *menu = new QPopupMenu( this );
1.604 - menuBar()->insertItem( tr( "&Settings" ), menu );
1.605 + QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
1.606
1.607 QAction *a;
1.608 - a = new QAction( tr( "Set fixed font" ), QPixmap(), tr( "Set &fixed font" ), 0, this, "setFixedFont" );
1.609 + a = new QAction(tr( "Set &fixed font" ), this);
1.610 + a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" ));
1.611 connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
1.612 - a->addTo( menu );
1.613 + settingsMenu->addAction (a);
1.614 actionSettingsFixedFont=a;
1.615
1.616 - a = new QAction( tr( "Set variable font" ), QPixmap(), tr( "Set &variable font" ), 0, this, "setvariableFont" );
1.617 + a = new QAction(tr( "Set &variable font" ), this);
1.618 + a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) );
1.619 connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
1.620 - a->addTo( menu );
1.621 + settingsMenu->addAction (a);
1.622 actionSettingsVarFont=a;
1.623
1.624 - a = new QAction( tr( "Used fixed font by default" ), QPixmap(), tr( "&fixed font is default" ), 0, this, "fonthintDefault" );
1.625 + a = new QAction(tr( "&fixed font is default" ), this);
1.626 + a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) );
1.627 a->setToggleAction (true);
1.628 // set state later in constructor...
1.629 - a->addTo( menu );
1.630 + settingsMenu->addAction (a);
1.631 actionSettingsFonthintDefault=a;
1.632 }
1.633
1.634 @@ -426,9 +454,9 @@
1.635 {
1.636 if (state!=inactiveEditor)
1.637 {
1.638 - if (e->length())
1.639 + if (!isEmpty())
1.640 {
1.641 - QMessageBox mb( "VYM - Note Editor",
1.642 + QMessageBox mb( vymName + " - " +tr("Note Editor"),
1.643 "Loading will overwrite the existing note",
1.644 QMessageBox::Warning,
1.645 QMessageBox::Yes | QMessageBox::Default,
1.646 @@ -443,8 +471,12 @@
1.647 }
1.648 // Load note
1.649 QFileDialog *fd=new QFileDialog( this);
1.650 - fd->addFilter ("ASCII texts (*.txt)");
1.651 - fd->addFilter ("VYM notes (*.html)");
1.652 + QStringList types;
1.653 + types<< "VYM notes (*.html)" <<
1.654 + "ASCII texts (*.txt)" <<
1.655 + "All filed (*)";
1.656 + fd->setFilters (types);
1.657 + fd->setDirectory (QDir().current());
1.658 fd->show();
1.659 QString fn;
1.660 if ( fd->exec() == QDialog::Accepted )
1.661 @@ -453,7 +485,7 @@
1.662 if ( !fn.isEmpty() )
1.663 {
1.664 QFile f( fn );
1.665 - if ( !f.open( IO_ReadOnly ) )
1.666 + if ( !f.open( QIODevice::ReadOnly ) )
1.667 return;
1.668
1.669 QTextStream ts( &f );
1.670 @@ -465,56 +497,51 @@
1.671
1.672 void TextEditor::closeEvent( QCloseEvent* ce )
1.673 {
1.674 - if ( !e->isModified() )
1.675 - {
1.676 - ce->accept(); // TextEditor can be reopened with show()
1.677 - return;
1.678 - }
1.679 + ce->accept(); // TextEditor can be reopened with show()
1.680 + showwithmain=false;
1.681 + hide();
1.682 + emit (windowClosed() );
1.683 + return;
1.684 }
1.685
1.686 QString TextEditor::getText()
1.687 {
1.688 - return e->text();
1.689 + if (e->toPlainText().isEmpty())
1.690 + return "";
1.691 + else
1.692 + return e->text();
1.693 }
1.694
1.695 void TextEditor::editorChanged()
1.696 {
1.697 - // received, when QTextEdit::text() has changed
1.698 - EditorState oldstate=state;
1.699 -
1.700 if (isEmpty())
1.701 state=emptyEditor;
1.702 else
1.703 state=filledEditor;
1.704
1.705 - if (state != oldstate)
1.706 - {
1.707 if (state==emptyEditor)
1.708 - e->setPaper (emptyPaper);
1.709 + setState (emptyEditor);
1.710 else
1.711 - e->setPaper (filledPaper);
1.712 - }
1.713 + setState (filledEditor);
1.714 // SLOT is LinkableMapObj, which will update systemFlag
1.715 - emit (textHasChanged() );
1.716 + if (!blockChangedSignal) emit (textHasChanged() );
1.717 }
1.718
1.719
1.720 void TextEditor::setText(QString t)
1.721 {
1.722 - if ( !QStyleSheet::mightBeRichText( t ) )
1.723 - t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal );
1.724 + blockChangedSignal=true;
1.725 e->setReadOnly(false);
1.726 e->setText(t);
1.727 - editorChanged(); //not called automagically
1.728 -
1.729 enableActions();
1.730 + blockChangedSignal=false;
1.731 }
1.732
1.733 void TextEditor::setInactive()
1.734 {
1.735 + state=inactiveEditor;
1.736 setText("");
1.737 - state=inactiveEditor;
1.738 - e->setPaper (inactivePaper);
1.739 + setState (inactiveEditor);
1.740 e->setReadOnly (true);
1.741
1.742 disableActions();
1.743 @@ -536,14 +563,12 @@
1.744 QFile file (fn);
1.745 if (file.exists())
1.746 {
1.747 - QMessageBox mb( "VYM",
1.748 - tr("The file ") + fn +
1.749 - tr(" exists already. "
1.750 - "Do you want to overwrite it?"),
1.751 + QMessageBox mb( vymName,
1.752 + tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
1.753 QMessageBox::Warning,
1.754 QMessageBox::Yes | QMessageBox::Default,
1.755 QMessageBox::Cancel | QMessageBox::Escape,
1.756 - QMessageBox::NoButton );
1.757 + Qt::NoButton );
1.758 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1.759 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1.760 switch( mb.exec() ) {
1.761 @@ -563,7 +588,7 @@
1.762 return;
1.763 }
1.764 }
1.765 - statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime );
1.766 + statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime );
1.767 }
1.768
1.769
1.770 @@ -577,7 +602,7 @@
1.771
1.772 QString text = e->text();
1.773 QFile f( filename );
1.774 - if ( !f.open( IO_WriteOnly ) )
1.775 + if ( !f.open( QIODevice::WriteOnly ) )
1.776 {
1.777 statusBar()->message( QString("Could not write to %1").arg(filename),
1.778 statusbarTime );
1.779 @@ -593,104 +618,19 @@
1.780 statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
1.781 }
1.782
1.783 -void TextEditor::textConvertPar()
1.784 -{
1.785 - // In X11 a copy&paste generates paragraphs,
1.786 - // which is not always wanted
1.787 - // This function replaces paragraphs by linebreaks.
1.788 - int parFrom, parTo, indFrom, indTo;
1.789 - e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
1.790 - QString t;
1.791 - if (parFrom>-1)
1.792 - t=e->selectedText();
1.793 - else
1.794 - t=e->text();
1.795 -
1.796 - QRegExp re("<p.*>");
1.797 - re.setMinimal(true);
1.798 - t.replace (re,"");
1.799 - t.replace ("</p>","<br />");
1.800 - if (parFrom>-1)
1.801 - {
1.802 - e->setCursorPosition (parFrom,indFrom);
1.803 - e->cut();
1.804 - // Tried to simply insert the changed text with
1.805 - // e->insert (t,(uint)(QTextEdit::RemoveSelected));
1.806 - // but then the html would be quoted. So I use the ugly
1.807 - // way: insert a marker, replace it in whole text of QTextEdit
1.808 - QString marker="R3PlAcEMeL4teR!";
1.809 - e->insert (marker);
1.810 - e->setText (e->text().replace(marker,t));
1.811 - } else
1.812 - e->setText(t);
1.813 -}
1.814 -
1.815 -void TextEditor::textJoinLines()
1.816 -{
1.817 - int parFrom, parTo, indFrom, indTo;
1.818 - e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
1.819 - QString t;
1.820 - if (parFrom>-1)
1.821 - t=e->selectedText();
1.822 - else
1.823 - t=e->text();
1.824 - // In addition to textConvertPar it is sometimes
1.825 - // useful to join all lines of a paragraph
1.826 - QRegExp re("</p>\n+<p>(?!</p>)");
1.827 - re.setMinimal(true);
1.828 - t.replace (re," ");
1.829 -
1.830 - // Above we may have introduced new " " at beginning of a
1.831 - // paragraph - remove it.
1.832 - re.setPattern("<p> ");
1.833 - t.replace (re,"<p>");
1.834 - if (parFrom>-1)
1.835 - {
1.836 - e->setCursorPosition (parFrom,indFrom);
1.837 - e->cut();
1.838 - // Tried to simply insert the changed text with
1.839 - // e->insert (t,(uint)(QTextEdit::RemoveSelected));
1.840 - // but then the html would be quoted. So I use the ugly
1.841 - // way: insert a marker, replace it in whole text of QTextEdit
1.842 - QString marker="R3PlAcEMeL4teR!";
1.843 - e->insert (marker);
1.844 - e->setText (e->text().replace(marker,t));
1.845 - } else
1.846 - e->setText(t);
1.847 -}
1.848 -
1.849 -QString TextEditor::textConvertToASCII(const QString &t)
1.850 -{
1.851 - QString r=t;
1.852 -
1.853 - // convert all "<br*>" to "\n"
1.854 - QRegExp re("<br.*>");
1.855 - re.setMinimal(true);
1.856 - r.replace (re,"\n");
1.857 -
1.858 - // convert all "</p>" to "\n"
1.859 - re.setPattern ("/p");
1.860 - r.replace (re,"\n");
1.861 -
1.862 - // remove all remaining tags
1.863 - re.setPattern ("<.*>");
1.864 - r.replace (re,"");
1.865 -
1.866 - // convert "&", "<" and ">"
1.867 - re.setPattern (">");
1.868 - r.replace (re,">");
1.869 - re.setPattern ("<");
1.870 - r.replace (re,"<");
1.871 - re.setPattern ("&");
1.872 - r.replace (re,"&");
1.873 - return r;
1.874 -}
1.875 -
1.876 void TextEditor::textExportAsASCII()
1.877 {
1.878 - QString text = textConvertToASCII( e->text());
1.879 - QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (ASCII) (*.txt);;All files (*)",
1.880 - this,"export note dialog",tr("Export Note to single file (ASCII)") );
1.881 + QString text = NoteObj (e->text()).getNoteASCII();
1.882 + QString fn,s;
1.883 + if (!filenameHint.isEmpty())
1.884 + {
1.885 + if (!filenameHint.contains (".txt"))
1.886 + s=filenameHint+".txt";
1.887 + else
1.888 + s=filenameHint;
1.889 + } else
1.890 + s=QString::null;
1.891 + fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
1.892 int ret=-1;
1.893
1.894 if ( !fn.isEmpty() )
1.895 @@ -698,14 +638,12 @@
1.896 QFile file (fn);
1.897 if (file.exists())
1.898 {
1.899 - QMessageBox mb( "VYM",
1.900 - tr("The file ") + fn +
1.901 - tr(" exists already. "
1.902 - "Do you want to overwrite it?"),
1.903 + QMessageBox mb( vymName,
1.904 + tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
1.905 QMessageBox::Warning,
1.906 QMessageBox::Yes | QMessageBox::Default,
1.907 QMessageBox::Cancel | QMessageBox::Escape,
1.908 - QMessageBox::NoButton );
1.909 + Qt::NoButton );
1.910 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1.911 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1.912 ret=mb.exec();
1.913 @@ -714,7 +652,7 @@
1.914 return;
1.915
1.916 // save
1.917 - if ( !file.open( IO_WriteOnly ) )
1.918 + if ( !file.open( QIODevice::WriteOnly ) )
1.919 statusBar()->message( QString("Could not write to %1").arg(filename),
1.920 statusbarTime );
1.921 else
1.922 @@ -731,41 +669,16 @@
1.923
1.924 void TextEditor::textPrint()
1.925 {
1.926 - printer->setFullPage(TRUE);
1.927 - if ( printer->setup( this ) )
1.928 - {
1.929 - QPainter p( printer );
1.930 - // Check that there is a valid device to print to.
1.931 - if ( !p.device() ) return;
1.932 - QPaintDeviceMetrics metrics( p.device() );
1.933 - int dpiy = metrics.logicalDpiY();
1.934 - int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
1.935 - QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
1.936 - QFont font( e->currentFont() );
1.937 - font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
1.938
1.939 - QSimpleRichText richText( e->text(), font,
1.940 - e->context(),
1.941 - e->styleSheet(),
1.942 - e->mimeSourceFactory(),
1.943 - body.height() );
1.944 - richText.setWidth( &p, body.width() );
1.945 - QRect view( body );
1.946 - int page = 1;
1.947 - do
1.948 - {
1.949 - richText.draw( &p, body.left(), body.top(), view, colorGroup() );
1.950 - view.moveBy( 0, body.height() );
1.951 - p.translate( 0 , -body.height() );
1.952 - p.setFont( font );
1.953 - p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
1.954 - view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
1.955 - if ( view.top() >= richText.height() )
1.956 - break;
1.957 - printer->newPage();
1.958 - page++;
1.959 - } while (TRUE);
1.960 - }
1.961 + QTextDocument *document = e->document();
1.962 + QPrinter printer;
1.963 +
1.964 + QPrintDialog *dialog = new QPrintDialog(&printer, this);
1.965 + dialog->setWindowTitle(tr("Print Note"));
1.966 + if (dialog->exec() != QDialog::Accepted)
1.967 + return;
1.968 +
1.969 + document->print(&printer);
1.970 }
1.971
1.972 void TextEditor::textEditUndo()
1.973 @@ -775,12 +688,12 @@
1.974 void TextEditor::toggleFonthint()
1.975 {
1.976 setUpdatesEnabled (false);
1.977 - e->selectAll (true);
1.978 + e->selectAll ();
1.979 if (!actionFormatUseFixedFont->isOn() )
1.980 e->setCurrentFont (varFont);
1.981 else
1.982 e->setCurrentFont (fixedFont);
1.983 - e->selectAll (false);
1.984 + e->selectAll ();
1.985 setUpdatesEnabled (true);
1.986 repaint();
1.987 }
1.988 @@ -834,30 +747,46 @@
1.989 void TextEditor::textColor()
1.990 {
1.991 QColor col = QColorDialog::getColor( e->color(), this );
1.992 - if ( !col.isValid() )
1.993 - return;
1.994 + if ( !col.isValid() ) return;
1.995 e->setColor( col );
1.996 QPixmap pix( 16, 16 );
1.997 - pix.fill( black );
1.998 + pix.fill( Qt::black );
1.999 actionTextColor->setIconSet( pix );
1.1000 }
1.1001
1.1002 void TextEditor::textAlign( QAction *a )
1.1003 {
1.1004 if ( a == actionAlignLeft )
1.1005 - e->setAlignment( AlignLeft );
1.1006 + e->setAlignment( Qt::AlignLeft );
1.1007 else if ( a == actionAlignCenter )
1.1008 - e->setAlignment( AlignHCenter );
1.1009 + e->setAlignment( Qt::AlignHCenter );
1.1010 else if ( a == actionAlignRight )
1.1011 - e->setAlignment( AlignRight );
1.1012 + e->setAlignment( Qt::AlignRight );
1.1013 else if ( a == actionAlignJustify )
1.1014 - e->setAlignment( AlignJustify );
1.1015 + e->setAlignment( Qt::AlignJustify );
1.1016 }
1.1017
1.1018 +void TextEditor::textVAlign()
1.1019 +{
1.1020 + QTextCharFormat format;
1.1021 +
1.1022 + if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
1.1023 + format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
1.1024 + } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
1.1025 + format.setVerticalAlignment(QTextCharFormat::AlignSubScript);
1.1026 + } else {
1.1027 + format.setVerticalAlignment(QTextCharFormat::AlignNormal);
1.1028 + }
1.1029 + e->mergeCurrentCharFormat(format);
1.1030 +}
1.1031 +
1.1032 +
1.1033 void TextEditor::fontChanged( const QFont &f )
1.1034 {
1.1035 - comboFont->lineEdit()->setText( f.family() );
1.1036 - comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
1.1037 + int i=comboFont->findText(f.family());
1.1038 + if (i>=0) comboFont->setCurrentIndex (i);
1.1039 + i=comboSize->findText(QString::number(f.pointSize()));
1.1040 + if (i>=0) comboSize->setCurrentIndex(i);
1.1041 actionTextBold->setOn( f.bold() );
1.1042 actionTextItalic->setOn( f.italic() );
1.1043 actionTextUnderline->setOn( f.underline() );
1.1044 @@ -870,16 +799,40 @@
1.1045 actionTextColor->setIconSet( pix );
1.1046 }
1.1047
1.1048 +void TextEditor::formatChanged( const QTextCharFormat &f )
1.1049 +{
1.1050 + fontChanged(f.font());
1.1051 + colorChanged(f.foreground().color());
1.1052 + alignmentChanged(e->alignment());
1.1053 + verticalAlignmentChanged (f.verticalAlignment());
1.1054 +}
1.1055 +
1.1056 void TextEditor::alignmentChanged( int a )
1.1057 {
1.1058 - if ( ( a == AlignAuto ) || ( a & AlignLeft ))
1.1059 - actionAlignLeft->setOn( true );
1.1060 - else if ( ( a & AlignHCenter ) )
1.1061 - actionAlignCenter->setOn( true );
1.1062 - else if ( ( a & AlignRight ) )
1.1063 - actionAlignRight->setOn( true );
1.1064 - else if ( ( a & AlignJustify ) )
1.1065 - actionAlignJustify->setOn( true );
1.1066 + if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
1.1067 + actionAlignLeft->setOn( true );
1.1068 + else if ( ( a & Qt::AlignHCenter ) )
1.1069 + actionAlignCenter->setOn( true );
1.1070 + else if ( ( a & Qt::AlignRight ) )
1.1071 + actionAlignRight->setOn( true );
1.1072 + else if ( ( a & Qt::AlignJustify ) )
1.1073 + actionAlignJustify->setOn( true );
1.1074 +}
1.1075 +
1.1076 +void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a)
1.1077 +{
1.1078 + actionAlignSubScript->setOn (false);
1.1079 + actionAlignSuperScript->setOn (false);
1.1080 + switch (a)
1.1081 + {
1.1082 + case QTextCharFormat::AlignSuperScript:
1.1083 + actionAlignSuperScript->setOn (true);
1.1084 + break;
1.1085 + case QTextCharFormat::AlignSubScript:
1.1086 + actionAlignSubScript->setOn (true);
1.1087 + break;
1.1088 + default: ;
1.1089 + }
1.1090 }
1.1091
1.1092
1.1093 @@ -896,8 +849,6 @@
1.1094 actionEditCut->setEnabled(true);
1.1095 actionEditPaste->setEnabled(true);
1.1096 actionEditDeleteAll->setEnabled(true);
1.1097 - actionEditConvertPar->setEnabled(true);
1.1098 - actionEditJoinLines->setEnabled(true);
1.1099 actionFormatUseFixedFont->setEnabled(true);
1.1100 }
1.1101
1.1102 @@ -913,9 +864,23 @@
1.1103 actionEditCut->setEnabled(false);
1.1104 actionEditPaste->setEnabled(false);
1.1105 actionEditDeleteAll->setEnabled(false);
1.1106 - actionEditConvertPar->setEnabled(false);
1.1107 - actionEditJoinLines->setEnabled(false);
1.1108 actionFormatUseFixedFont->setEnabled(false);
1.1109 }
1.1110
1.1111 +void TextEditor::setState (EditorState s)
1.1112 +{
1.1113 +
1.1114 + QPalette p=palette();
1.1115 + QColor c;
1.1116 + switch (s)
1.1117 + {
1.1118 + case emptyEditor: c=QColor (150,150,150); break;
1.1119 + case filledEditor: c=QColor (255,255,255); break;
1.1120 + case inactiveEditor: c=QColor (0,0,0);
1.1121 + }
1.1122 + p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
1.1123 + p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
1.1124 + e->setPalette(p);
1.1125 +}
1.1126
1.1127 +