# HG changeset patch # User insilmaril # Date 1227535921 0 # Node ID 1532402be6c267c7bc5e08bfb9c3f2b6bca03251 # Parent 6cd53d63956fd4b08937759d1e441c79920537c7 Added bracket to comfort gcc diff -r 6cd53d63956f -r 1532402be6c2 mapeditor.cpp --- a/mapeditor.cpp Wed Nov 12 11:15:37 2008 +0000 +++ b/mapeditor.cpp Mon Nov 24 14:12:01 2008 +0000 @@ -1814,6 +1814,13 @@ mapChanged=false; mapUnsaved=false; autosaveTimer->stop(); + /* + cout <<"ME::save filePath="< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include -#include +#include #include -#include "icons/fileopen.xpm" -#include "icons/filesave.xpm" -#include "icons/fileprint.xpm" -#include "icons/editundo.xpm" -#include "icons/editredo.xpm" -#include "icons/editcopy.xpm" -#include "icons/editcut.xpm" -#include "icons/editpaste.xpm" -#include "icons/edittrash.xpm" -#include "icons/formatfixedfont.xpm" -#include "icons/formattextbold.xpm" -#include "icons/formattextitalic.xpm" -#include "icons/formattextunder.xpm" -#include "icons/formattextleft.xpm" -#include "icons/formattextcenter.xpm" -#include "icons/formattextright.xpm" -#include "icons/formattextjustify.xpm" +#include "noteobj.h" +#include "settings.h" -extern QCanvas* actCanvas; extern int statusbarTime; -extern QSettings settings; +extern Settings settings; + +extern QAction *actionViewToggleNoteEditor; + +extern QString iconPath; +extern QString vymName; using namespace std; @@ -56,20 +21,28 @@ /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// + TextEditor::TextEditor() { printer = new QPrinter( QPrinter::HighResolution ); + printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); - // Editor - e = new QTextEdit( this, "editor" ); + e = new QTextEdit( this); e->setFocus(); - e->setTextFormat(RichText); // default + e->setTextFormat(Qt::RichText); // default e->setTabStopWidth (20); // unit is pixel - e->setColor (black); + e->setColor (Qt::black); + e->setAutoFillBackground (true); connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); setCentralWidget( e ); - statusBar()->message( "Ready", statusbarTime); - setCaption("VYM - Note Editor"); + statusBar()->message( tr("Ready","Statusbar message"), statusbarTime); + setCaption(vymName +" - " +tr ("Note Editor","Window caption")); + + + connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), + this, SLOT(formatChanged(const QTextCharFormat &))); + + // Toolbars setupFileActions(); @@ -78,31 +51,24 @@ setupSettingsActions(); // Various states - emptyPaper = QBrush(gray); - filledPaper = QBrush(white); - inactivePaper= QBrush(black); + blockChangedSignal=false; setInactive(); // Load Settings - resize (settings.readNumEntry( "/vym/noteeditor/geometry/width", 450), - settings.readNumEntry( "/vym/noteeditor/geometry/height",600)); - move (settings.readNumEntry( "/vym/noteeditor/geometry/posX", 150), - settings.readNumEntry( "/vym/noteeditor/geometry/posY", 50)); + resize (settings.value ( "/satellite/noteeditor/geometry/size", QSize(450,600)).toSize()); + move (settings.value ( "/satellite/noteeditor/geometry/pos", QPoint (250,50)).toPoint()); - if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes") - setShowWithMain(true); - else - setShowWithMain(false); + setShowWithMain (settings.value ( "/satellite/noteeditor/showWithMain",true).toBool()); - varFont.fromString( settings.readEntry - ("/vym/noteeditor/fonts/varFont", - "Nimbus Sans l,14,-1,5,48,0,0,0,0,0") + varFont.fromString( settings.value + ("/satellite/noteeditor/fonts/varFont", + "Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString() ); - fixedFont.fromString (settings.readEntry ( - "/vym/noteeditor/fonts/fixedFont", - "Courier,14,-1,5,48,0,0,0,1,0") + fixedFont.fromString (settings.value( + "/satellite/noteeditor/fonts/fixedFont", + "Courier,14,-1,5,48,0,0,0,1,0").toString() ); - QString s=settings.readEntry ("/vym/noteeditor/fonts/fonthintDefault","variable"); + QString s=settings.value ("/satellite/noteeditor/fonts/fonthintDefault","variable").toString(); if (s == "fixed") { actionSettingsFonthintDefault->setOn (true); @@ -112,6 +78,13 @@ actionSettingsFonthintDefault->setOn (false); e->setCurrentFont (varFont); } + filenameHint=""; + + // Restore position of toolbars + restoreState (settings.value("/satellite/noteeditor/state",0).toByteArray()); + + // Save settings in vymrc + settings.setValue("/mainwindow/printerName",printer->printerName()); } @@ -119,31 +92,27 @@ { if (printer) delete printer; // Save Settings - settings.writeEntry( "/vym/noteeditor/geometry/width", width() ); - settings.writeEntry( "/vym/noteeditor/geometry/height", height() ); - settings.writeEntry( "/vym/noteeditor/geometry/posX", pos().x() ); - settings.writeEntry( "/vym/noteeditor/geometry/posY", pos().y() ); + settings.setValue( "/satellite/noteeditor/geometry/size", size() ); + settings.setValue( "/satellite/noteeditor/geometry/pos", pos() ); + settings.setValue ("/satellite/noteeditor/state",saveState(0)); - if (showWithMain()) - settings.writeEntry( "/vym/noteeditor/showWithMain","yes"); - else - settings.writeEntry( "/vym/noteeditor/showWithMain","no"); + settings.setValue( "/satellite/noteeditor/showWithMain",showwithmain); QString s; if (actionSettingsFonthintDefault->isOn() ) s="fixed"; else s="variable"; - settings.writeEntry( "/vym/noteeditor/fonts/fonthintDefault",s ); - settings.writeEntry ("/vym/noteeditor/fonts/varFont", - varFont.toString() ); - settings.writeEntry ("/vym/noteeditor/fonts/fixedFont", - fixedFont.toString() ); + settings.setValue( "/satellite/noteeditor/fonts/fonthintDefault",s ); + settings.setValue("/satellite/noteeditor/fonts/varFont", varFont.toString() ); + settings.setValue("/satellite/noteeditor/fonts/fixedFont", fixedFont.toString() ); + + } bool TextEditor::isEmpty() { - if (e->text().length()) + if (e->toPlainText().length()>0) return false; else return true; @@ -159,6 +128,7 @@ return showwithmain; } + void TextEditor::setFontHint (const QString &fh) { if (fh=="fixed") @@ -187,16 +157,18 @@ void TextEditor::setFilename(const QString &fn) { if (state==filledEditor) + { 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 ); } + } } QString TextEditor::getFilename() @@ -204,10 +176,19 @@ return filename; } -bool TextEditor::findText(const QString &t, const bool &cs) +void TextEditor::setFilenameHint(const QString &fnh) { - bool wo=false; // word matches - if (e->find (t, cs, wo, true, 0, 0 )) + filenameHint=fnh; +} + +QString TextEditor::getFilenameHint() +{ + return filenameHint; +} + +bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags) +{ + if (e->find (t,flags)) return true; else return false; @@ -215,210 +196,257 @@ void TextEditor::setupFileActions() { - QToolBar *tb = new QToolBar( this ); - tb->setLabel( "File Actions" ); - QPopupMenu *menu = new QPopupMenu( this ); - menuBar()->insertItem( tr( "&File" ), menu ); + QToolBar *tb = addToolBar ( tr("Note Actions") ); + tb->setObjectName ("noteEditorFileActions"); + QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" )); QAction *a; - a = new QAction( tr( "Import" ), QPixmap( fileopen_xpm), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" ); + a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this); + a->setStatusTip (tr( "Import","Status tip for Note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_O ); connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) ); - a->setEnabled(false); - a->addTo( tb ); - a->addTo( menu ); + tb->addAction (a); + fileMenu->addAction (a); actionFileLoad=a; - menu->insertSeparator(); - a = new QAction( tr( "Export Note (HTML)" ), QPixmap( filesave_xpm ), tr( "&Export..." ), CTRL + Key_S, this, "fileSave" ); + fileMenu->addSeparator(); + a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this); + a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_S ); connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) ); - a->addTo( tb ); - a->addTo( menu ); + tb->addAction (a); + fileMenu->addAction (a); actionFileSave=a; - a = new QAction( tr( "Export Note As (HTML) " ), QPixmap(), tr( "Export &As... (HTML)" ), 0, this, "exportHTML" ); + a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this); + a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu" )); connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) ); - a->addTo( menu ); + fileMenu->addAction (a); actionFileSaveAs=a; - a = new QAction( tr( "Export Note As (ASCII) " ), QPixmap(), tr( "Export &As...(ASCII)" ), ALT + Key_X, this, "exportASCII" ); + a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this); + a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) ); + a->setShortcut(Qt::ALT + Qt::Key_X ); connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) ); - a->addTo( menu ); + fileMenu->addAction (a); actionFileSaveAs=a; - menu->insertSeparator(); - a = new QAction( tr( "Print Note" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" ); + fileMenu->addSeparator(); + a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this); + a->setStatusTip (tr( "Print Note","Status tip for note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_P ); connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) ); - a->addTo( tb ); - a->addTo( menu ); + tb->addAction (a); + fileMenu->addAction (a); actionFilePrint=a; } void TextEditor::setupEditActions() { - QToolBar *tb = new QToolBar( this ); - tb->setLabel( "Edit Actions" ); - QPopupMenu *menu = new QPopupMenu( this ); - menuBar()->insertItem( tr( "&Edit" ), menu ); + QToolBar *tb = addToolBar ( tr( "Edit Actions" )); + tb->setObjectName ("noteEditorEditActions"); + QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" )); QAction *a; - a = new QAction( tr( "Undo" ), QPixmap(editundo_xpm), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" ); + a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this ); + a->setStatusTip ( tr( "Undo","Status tip for note menu" ) ); + a->setShortcut(Qt::CTRL + Qt::Key_Z ); connect( a, SIGNAL( activated() ), e, SLOT( undo() ) ); - a->addTo( menu ); - a->addTo( tb); + editMenu->addAction (a); + tb->addAction (a); actionEditUndo=a; - a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); + a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this); + a->setStatusTip ( tr( "Redo","Status tip for note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_Y ); connect( a, SIGNAL( activated() ), e, SLOT( redo() ) ); - a->addTo( tb ); - a->addTo( menu ); + editMenu->addAction (a); + tb->addAction (a); actionEditRedo=a; - menu->insertSeparator(); - a = new QAction( tr( "Select and copy all" ), QPixmap(), tr( "Select and copy &all" ), CTRL + Key_A, this, "editcopyall" ); + editMenu->addSeparator(); + a = new QAction(QPixmap(), tr( "Select and copy &all" ),this); + a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_A ); connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) ); - a->addTo( menu ); + editMenu->addAction (a); - menu->insertSeparator(); - a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" ); + editMenu->addSeparator(); + a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this); + a->setStatusTip ( tr( "Copy","Status tip for note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_C ); connect( a, SIGNAL( activated() ), e, SLOT( copy() ) ); - a->addTo( tb ); - a->addTo( menu ); + editMenu->addAction (a); + tb->addAction (a); actionEditCopy=a; - a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" ); + a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this); + a->setStatusTip ( tr( "Cut","Status tip for note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_X ); connect( a, SIGNAL( activated() ), e, SLOT( cut() ) ); - a->addTo( tb ); - a->addTo( menu ); + editMenu->addAction (a); + tb->addAction (a); actionEditCut=a; - a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" ); + a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this); + a->setStatusTip ( tr( "Paste","Status tip for note menu" ) ); + a->setShortcut( Qt::CTRL + Qt::Key_V ); connect( a, SIGNAL( activated() ), e, SLOT( paste() ) ); - a->addTo( tb ); - a->addTo( menu ); + editMenu->addAction (a); + tb->addAction (a); actionEditPaste=a; - a = new QAction( tr( "Delete all" ), QPixmap( edittrash_xpm ), tr( "&Delete All" ), 0, this, "editDeleteAll" ); + a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this); + a->setStatusTip (tr( "Delete all","Status tip for note menu" ) ); connect( a, SIGNAL( activated() ), e, SLOT( clear() ) ); - a->addTo( tb ); - a->addTo( menu ); + editMenu->addAction (a); + tb->addAction (a); actionEditDeleteAll=a; - a = new QAction( tr( "Convert paragraphs to linebreaks" ), QPixmap(), tr( "&Convert Paragraphs" ), ALT + Key_P, this, "editConvertPar" ); - connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) ); - a->addTo( menu ); - actionEditConvertPar=a; - - a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" ); - connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) ); - a->addTo( menu ); - actionEditJoinLines=a; } void TextEditor::setupFormatActions() { - QToolBar *tb = new QToolBar( this ); - tb->setLabel( "Format Actions" ); - QPopupMenu *menu = new QPopupMenu( this ); - menuBar()->insertItem( tr( "&Format" ), menu ); + QToolBar *tb = addToolBar ( tr("Format Actions" )); + tb->setObjectName ("noteEditorFormatActions"); + QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" )); QAction *a; - a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(formatfixedfont_xpm), tr( "&Font hint" ), ALT + Key_I, this, "fontHint" ); + a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" ); + a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) ); a->setToggleAction (true); - a->setOn (settings.readBoolEntry ("/vym/noteeditor/fonts/useFixedByDefault",false) ); + a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() ); connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) ); - a->addTo( menu ); - a->addTo( tb ); + formatMenu->addAction (a); + tb->addAction (a); actionFormatUseFixedFont=a; - menu->insertSeparator(); - - comboFont = new QComboBox( true, tb ); - QFontDatabase db; - comboFont->insertStringList( db.families() ); + comboFont = new QComboBox; + tb->addWidget (comboFont); + QFontDatabase fontDB; + comboFont->insertStringList( fontDB.families() ); connect( comboFont, SIGNAL( activated( const QString & ) ), this, SLOT( textFamily( const QString & ) ) ); - comboFont->lineEdit()->setText( QApplication::font().family() ); - - comboSize = new QComboBox( true, tb ); - QValueList sizes = db.standardSizes(); - QValueList::Iterator it = sizes.begin(); - for ( ; it != sizes.end(); ++it ) - comboSize->insertItem( QString::number( *it ) ); + comboFont->addItem( QApplication::font().family() ); + comboSize = new QComboBox; + tb->addWidget (comboSize); + QList sizes=fontDB.standardSizes(); + QList::iterator i = sizes.begin(); + while (i != sizes.end()) + { + ++i; // increment i before using it + comboSize->insertItem ( QString::number(*i)); + } connect( comboSize, SIGNAL( activated( const QString & ) ), this, SLOT( textSize( const QString & ) ) ); - comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); + comboSize->addItem ( QString::number( QApplication::font().pointSize() ) ); - menu->insertSeparator(); + formatMenu->addSeparator(); QPixmap pix( 16, 16 ); pix.fill( e->color()); - actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" ); - connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) ); - actionTextColor->addTo( tb ); - actionTextColor->addTo( menu ); + a = new QAction( pix, tr( "&Color..." ), this); + formatMenu->addAction (a); + tb->addAction (a); + connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) ); + actionTextColor=a; - actionTextBold = new QAction( QPixmap (formattextbold_xpm), tr( "&Bold" ), CTRL + Key_B, this, "textBold" ); - connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); - actionTextBold->addTo( tb ); - actionTextBold->addTo( menu ); - actionTextBold->setToggleAction( true ); - actionTextItalic = new QAction( QPixmap(formattextitalic_xpm ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" ); - connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) ); - actionTextItalic->addTo( tb ); - actionTextItalic->addTo( menu ); - actionTextItalic->setToggleAction( true ); - actionTextUnderline = new QAction( QPixmap (formattextunder_xpm ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" ); - connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) ); - actionTextUnderline->addTo( tb ); - actionTextUnderline->addTo( menu ); - actionTextUnderline->setToggleAction( true ); - menu->insertSeparator(); + a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this); + a->setShortcut(Qt::CTRL + Qt::Key_B ); + connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) ); + tb->addAction (a); + formatMenu->addAction (a); + a->setToggleAction( true ); + actionTextBold=a; + + a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this); + a->setShortcut(Qt::CTRL + Qt::Key_I); + connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) ); + tb->addAction (a); + formatMenu->addAction (a); + a->setToggleAction( true ); + actionTextItalic=a; + + a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this); + a->setShortcut(Qt::CTRL + Qt::Key_U ); + connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) ); + tb->addAction (a); + formatMenu->addAction (a); + a->setToggleAction( true ); + 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* ) ) ); - actionAlignLeft = new QAction( QPixmap (formattextleft_xpm ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" ); - actionAlignLeft->setToggleAction( true ); - actionAlignCenter = new QAction( QPixmap (formattextcenter_xpm ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" ); - actionAlignCenter->setToggleAction( true ); - actionAlignRight = new QAction( QPixmap (formattextright_xpm ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" ); - actionAlignRight->setToggleAction( true ); - actionAlignJustify = new QAction( QPixmap ( formattextjustify_xpm ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" ); - actionAlignJustify->setToggleAction( true ); + formatMenu->addSeparator(); - grp->addTo( tb ); - grp->addTo( menu ); - - 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 ) ) ); - + a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp ); + a->setShortcut( Qt::CTRL+Qt::Key_L ); + a->setToggleAction( true ); + tb->addAction (a); + formatMenu->addAction (a); + actionAlignLeft=a; + a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp); + a->setShortcut( Qt::CTRL + Qt::Key_E); + a->setToggleAction( true ); + tb->addAction (a); + formatMenu->addAction (a); + actionAlignCenter=a; + a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp); + a->setShortcut(Qt::CTRL + Qt::Key_R ); + a->setToggleAction( true ); + tb->addAction (a); + formatMenu->addAction (a); + actionAlignRight=a; + a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp ); + a->setShortcut(Qt::CTRL + Qt::Key_J ); + a->setToggleAction( true ); + tb->addAction (a); + formatMenu->addAction (a); + actionAlignJustify=a; } void TextEditor::setupSettingsActions() { - QPopupMenu *menu = new QPopupMenu( this ); - menuBar()->insertItem( tr( "&Settings" ), menu ); + QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" )); QAction *a; - a = new QAction( tr( "Set fixed font" ), QPixmap(), tr( "Set &fixed font" ), 0, this, "setFixedFont" ); + a = new QAction(tr( "Set &fixed font" ), this); + a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" )); connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) ); - a->addTo( menu ); + settingsMenu->addAction (a); actionSettingsFixedFont=a; - a = new QAction( tr( "Set variable font" ), QPixmap(), tr( "Set &variable font" ), 0, this, "setvariableFont" ); + a = new QAction(tr( "Set &variable font" ), this); + a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) ); connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) ); - a->addTo( menu ); + settingsMenu->addAction (a); actionSettingsVarFont=a; - a = new QAction( tr( "Used fixed font by default" ), QPixmap(), tr( "&fixed font is default" ), 0, this, "fonthintDefault" ); + a = new QAction(tr( "&fixed font is default" ), this); + a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) ); a->setToggleAction (true); // set state later in constructor... - a->addTo( menu ); + settingsMenu->addAction (a); actionSettingsFonthintDefault=a; } @@ -426,9 +454,9 @@ { if (state!=inactiveEditor) { - if (e->length()) + if (!isEmpty()) { - QMessageBox mb( "VYM - Note Editor", + QMessageBox mb( vymName + " - " +tr("Note Editor"), "Loading will overwrite the existing note", QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, @@ -443,8 +471,12 @@ } // Load note QFileDialog *fd=new QFileDialog( this); - fd->addFilter ("ASCII texts (*.txt)"); - fd->addFilter ("VYM notes (*.html)"); + QStringList types; + types<< "VYM notes (*.html)" << + "ASCII texts (*.txt)" << + "All filed (*)"; + fd->setFilters (types); + fd->setDirectory (QDir().current()); fd->show(); QString fn; if ( fd->exec() == QDialog::Accepted ) @@ -453,7 +485,7 @@ if ( !fn.isEmpty() ) { QFile f( fn ); - if ( !f.open( IO_ReadOnly ) ) + if ( !f.open( QIODevice::ReadOnly ) ) return; QTextStream ts( &f ); @@ -465,56 +497,51 @@ void TextEditor::closeEvent( QCloseEvent* ce ) { - if ( !e->isModified() ) - { - ce->accept(); // TextEditor can be reopened with show() - return; - } + ce->accept(); // TextEditor can be reopened with show() + showwithmain=false; + hide(); + emit (windowClosed() ); + return; } QString TextEditor::getText() { - return e->text(); + if (e->toPlainText().isEmpty()) + return ""; + else + return e->text(); } void TextEditor::editorChanged() { - // received, when QTextEdit::text() has changed - EditorState oldstate=state; - if (isEmpty()) state=emptyEditor; else state=filledEditor; - if (state != oldstate) - { if (state==emptyEditor) - e->setPaper (emptyPaper); + setState (emptyEditor); else - e->setPaper (filledPaper); - } + setState (filledEditor); // SLOT is LinkableMapObj, which will update systemFlag - emit (textHasChanged() ); + if (!blockChangedSignal) emit (textHasChanged() ); } void TextEditor::setText(QString t) { - if ( !QStyleSheet::mightBeRichText( t ) ) - t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal ); + blockChangedSignal=true; e->setReadOnly(false); e->setText(t); - editorChanged(); //not called automagically - enableActions(); + blockChangedSignal=false; } void TextEditor::setInactive() { + state=inactiveEditor; setText(""); - state=inactiveEditor; - e->setPaper (inactivePaper); + setState (inactiveEditor); e->setReadOnly (true); disableActions(); @@ -536,14 +563,12 @@ QFile file (fn); if (file.exists()) { - QMessageBox mb( "VYM", - tr("The file ") + fn + - tr(" exists already. " - "Do you want to overwrite it?"), + QMessageBox mb( vymName, + tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, - QMessageBox::NoButton ); + Qt::NoButton ); mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); mb.setButtonText( QMessageBox::No, tr("Cancel")); switch( mb.exec() ) { @@ -563,7 +588,7 @@ return; } } - statusBar()->message(tr( "Couldn't export note ") + fn, statusbarTime ); + statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime ); } @@ -577,7 +602,7 @@ QString text = e->text(); QFile f( filename ); - if ( !f.open( IO_WriteOnly ) ) + if ( !f.open( QIODevice::WriteOnly ) ) { statusBar()->message( QString("Could not write to %1").arg(filename), statusbarTime ); @@ -593,104 +618,19 @@ 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. - int parFrom, parTo, indFrom, indTo; - e->getSelection (&parFrom,&indFrom,&parTo,&indTo); - QString t; - 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() -{ - 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); -} - -QString TextEditor::textConvertToASCII(const QString &t) -{ - QString r=t; - - // convert all "" to "\n" - QRegExp re(""); - re.setMinimal(true); - r.replace (re,"\n"); - - // convert all "

" to "\n" - re.setPattern ("/p"); - r.replace (re,"\n"); - - // remove all remaining tags - re.setPattern ("<.*>"); - r.replace (re,""); - - // convert "&", "<" and ">" - re.setPattern (">"); - r.replace (re,">"); - re.setPattern ("<"); - r.replace (re,"<"); - re.setPattern ("&"); - r.replace (re,"&"); - return r; -} - void TextEditor::textExportAsASCII() { - QString text = textConvertToASCII( e->text()); - QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (ASCII) (*.txt);;All files (*)", - this,"export note dialog",tr("Export Note to single file (ASCII)") ); + QString text = NoteObj (e->text()).getNoteASCII(); + QString fn,s; + if (!filenameHint.isEmpty()) + { + if (!filenameHint.contains (".txt")) + s=filenameHint+".txt"; + else + s=filenameHint; + } else + s=QString::null; + fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") ); int ret=-1; if ( !fn.isEmpty() ) @@ -698,14 +638,12 @@ QFile file (fn); if (file.exists()) { - QMessageBox mb( "VYM", - tr("The file ") + fn + - tr(" exists already. " - "Do you want to overwrite it?"), + QMessageBox mb( vymName, + tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, - QMessageBox::NoButton ); + Qt::NoButton ); mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); mb.setButtonText( QMessageBox::No, tr("Cancel")); ret=mb.exec(); @@ -714,7 +652,7 @@ return; // save - if ( !file.open( IO_WriteOnly ) ) + if ( !file.open( QIODevice::WriteOnly ) ) statusBar()->message( QString("Could not write to %1").arg(filename), statusbarTime ); else @@ -731,41 +669,16 @@ void TextEditor::textPrint() { - printer->setFullPage(TRUE); - if ( printer->setup( this ) ) - { - QPainter p( printer ); - // Check that there is a valid device to print to. - if ( !p.device() ) return; - QPaintDeviceMetrics metrics( p.device() ); - int dpiy = metrics.logicalDpiY(); - int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins - QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); - QFont font( e->currentFont() ); - font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing - QSimpleRichText richText( e->text(), font, - e->context(), - e->styleSheet(), - e->mimeSourceFactory(), - body.height() ); - richText.setWidth( &p, body.width() ); - QRect view( body ); - int page = 1; - do - { - richText.draw( &p, body.left(), body.top(), view, colorGroup() ); - view.moveBy( 0, body.height() ); - p.translate( 0 , -body.height() ); - p.setFont( font ); - p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), - view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); - if ( view.top() >= richText.height() ) - break; - printer->newPage(); - page++; - } while (TRUE); - } + QTextDocument *document = e->document(); + QPrinter printer; + + QPrintDialog *dialog = new QPrintDialog(&printer, this); + dialog->setWindowTitle(tr("Print Note")); + if (dialog->exec() != QDialog::Accepted) + return; + + document->print(&printer); } void TextEditor::textEditUndo() @@ -775,12 +688,12 @@ void TextEditor::toggleFonthint() { setUpdatesEnabled (false); - e->selectAll (true); + e->selectAll (); if (!actionFormatUseFixedFont->isOn() ) e->setCurrentFont (varFont); else e->setCurrentFont (fixedFont); - e->selectAll (false); + e->selectAll (); setUpdatesEnabled (true); repaint(); } @@ -834,30 +747,46 @@ 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( black ); + pix.fill( Qt::black ); actionTextColor->setIconSet( pix ); } void TextEditor::textAlign( QAction *a ) { if ( a == actionAlignLeft ) - e->setAlignment( AlignLeft ); + e->setAlignment( Qt::AlignLeft ); else if ( a == actionAlignCenter ) - e->setAlignment( AlignHCenter ); + e->setAlignment( Qt::AlignHCenter ); else if ( a == actionAlignRight ) - e->setAlignment( AlignRight ); + e->setAlignment( Qt::AlignRight ); else if ( a == actionAlignJustify ) - e->setAlignment( AlignJustify ); + e->setAlignment( Qt::AlignJustify ); } +void TextEditor::textVAlign() +{ + QTextCharFormat format; + + if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) { + format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); + } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) { + format.setVerticalAlignment(QTextCharFormat::AlignSubScript); + } else { + 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() ); @@ -870,16 +799,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 == AlignAuto ) || ( a & AlignLeft )) - actionAlignLeft->setOn( true ); - else if ( ( a & AlignHCenter ) ) - actionAlignCenter->setOn( true ); - else if ( ( a & AlignRight ) ) - actionAlignRight->setOn( true ); - else if ( ( a & AlignJustify ) ) - actionAlignJustify->setOn( true ); + if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft )) + actionAlignLeft->setOn( true ); + else if ( ( a & Qt::AlignHCenter ) ) + actionAlignCenter->setOn( true ); + else if ( ( a & Qt::AlignRight ) ) + actionAlignRight->setOn( true ); + else if ( ( a & Qt::AlignJustify ) ) + actionAlignJustify->setOn( true ); +} + +void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a) +{ + actionAlignSubScript->setOn (false); + actionAlignSuperScript->setOn (false); + switch (a) + { + case QTextCharFormat::AlignSuperScript: + actionAlignSuperScript->setOn (true); + break; + case QTextCharFormat::AlignSubScript: + actionAlignSubScript->setOn (true); + break; + default: ; + } } @@ -896,8 +849,6 @@ actionEditCut->setEnabled(true); actionEditPaste->setEnabled(true); actionEditDeleteAll->setEnabled(true); - actionEditConvertPar->setEnabled(true); - actionEditJoinLines->setEnabled(true); actionFormatUseFixedFont->setEnabled(true); } @@ -913,9 +864,23 @@ actionEditCut->setEnabled(false); actionEditPaste->setEnabled(false); actionEditDeleteAll->setEnabled(false); - actionEditConvertPar->setEnabled(false); - actionEditJoinLines->setEnabled(false); actionFormatUseFixedFont->setEnabled(false); } +void TextEditor::setState (EditorState s) +{ + + QPalette p=palette(); + QColor c; + switch (s) + { + case emptyEditor: c=QColor (150,150,150); break; + case filledEditor: c=QColor (255,255,255); break; + case inactiveEditor: c=QColor (0,0,0); + } + p.setColor(QPalette::Active, static_cast(9), c); + p.setColor(QPalette::Inactive, static_cast(9), c); + e->setPalette(p); +} +