diff -r 1cc73bd7ee1f -r e95081c21da2 texteditor.cpp --- a/texteditor.cpp Tue Sep 05 09:47:13 2006 +0000 +++ b/texteditor.cpp Tue Sep 05 09:47:14 2006 +0000 @@ -1,28 +1,19 @@ #include "texteditor.h" -#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 +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -31,7 +22,6 @@ #include "noteobj.h" #include "version.h" -extern QCanvas* actCanvas; extern int statusbarTime; extern QSettings settings; @@ -49,15 +39,16 @@ TextEditor::TextEditor() { printer = new QPrinter( QPrinter::HighResolution ); - printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName())); + printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); // Editor (use MyTextEdit to wrap verticalAlignmentChanged to // int argument. see header file) e = new MyTextEdit( this, "editor" ); e->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); @@ -70,31 +61,26 @@ setupSettingsActions(); // Various states - emptyPaper = QBrush(gray); - filledPaper = QBrush(white); - inactivePaper= QBrush(black); 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 ( "/noteeditor/geometry/size", QSize(450,600)).toSize()); + move (settings.value ( "/noteeditor/geometry/pos", QPoint (250,50)).toPoint()); - if (settings.readEntry( "/vym/noteeditor/showWithMain","yes") =="yes") + if (settings.value ( "/noteeditor/showWithMain",true).toBool()) setShowWithMain(true); else setShowWithMain(false); - varFont.fromString( settings.readEntry - ("/vym/noteeditor/fonts/varFont", - "Nimbus Sans l,14,-1,5,48,0,0,0,0,0") + varFont.fromString( settings.value + ("/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( + "/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 ("/noteeditor/fonts/fonthintDefault","variable").toString(); if (s == "fixed") { actionSettingsFonthintDefault->setOn (true); @@ -107,7 +93,7 @@ filenameHint=""; // Save settings in vymrc - settings.writeEntry("/vym/mainwindow/printerName",printer->printerName()); + settings.setValue("/mainwindow/printerName",printer->printerName()); } @@ -115,31 +101,24 @@ { 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( "/noteeditor/geometry/size", size() ); + settings.setValue( "/noteeditor/geometry/pos", pos() ); - if (showWithMain()) - settings.writeEntry( "/vym/noteeditor/showWithMain","yes"); - else - settings.writeEntry( "/vym/noteeditor/showWithMain","no"); + settings.setValue( "/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( "/noteeditor/fonts/fonthintDefault",s ); + settings.setValue("/noteeditor/fonts/varFont", varFont.toString() ); + settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() ); } bool TextEditor::isEmpty() { - if (e->text().length()) + if (e->toPlainText().length()>0) return false; else return true; @@ -210,10 +189,9 @@ return filenameHint; } -bool TextEditor::findText(const QString &t, const bool &cs) +bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags) { - bool wo=false; // word matches - if (e->find (t, cs, wo, true, 0, 0 )) + if (e->find (t,flags)) return true; else return false; @@ -221,229 +199,285 @@ 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") ); + QMenu *fileMenu = menuBar()->addMenu( tr( "&Note" )); QAction *a; - a = new QAction( tr( "Import" ), QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ), CTRL + Key_O, this, "fileImport" ); + a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this); + a->setStatusTip (tr( "Import" ) ); + 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(iconPath+"filesave.png" ), 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)" ) ); + 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) " )); 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) " ) ); + 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(iconPath+"fileprint.png" ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" ); + fileMenu->addSeparator(); + a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this); + a->setStatusTip (tr( "Print Note" ) ); + 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" )); + QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" )); QAction *a; - a = new QAction( tr( "Undo" ), QPixmap(iconPath+"undo.png"), tr( "&Undo" ), CTRL + Key_Z, this, "undoEvent" ); + a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this ); + a->setStatusTip ( tr( "Undo" ) ); + 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(iconPath+"redo.png" ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); + a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this); + a->setStatusTip ( tr( "Redo" ) ); + 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" ) ); + 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(iconPath+"editcopy.png" ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" ); + editMenu->addSeparator(); + a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this); + a->setStatusTip ( tr( "Copy" ) ); + 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(iconPath+"editcut.png" ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" ); + a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this); + a->setStatusTip ( tr( "Cut" ) ); + 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(iconPath+"editpaste.png" ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" ); + a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this); + a->setStatusTip ( tr( "Paste" ) ); + 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( iconPath+"edittrash.png"), tr( "&Delete All" ), 0, this, "editDeleteAll" ); + a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this); + a->setStatusTip (tr( "Delete all" ) ); 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" ); + a = new QAction(QPixmap(), tr( "&Convert Paragraphs" ),this); + /* TODO not needed any longer? remove also from docu... + a->setStatusTip(tr( "Convert paragraphs to linebreaks" )); + a->setShortcut( Qt::ALT + Qt::Key_P ); connect( a, SIGNAL( activated() ), this, SLOT( textConvertPar() ) ); - a->addTo( menu ); + editMenu->addAction (a); + */ actionEditConvertPar=a; - a = new QAction( tr( "Join all lines of a paragraph" ), QPixmap(), tr( "&Join lines" ), ALT + Key_J, this, "editJoinLines" ); + a = new QAction( QPixmap(), tr( "&Join lines" ), this); + /* TODO not needed any longer? remove also from docu... + a->setStatusTip(tr( "Join all lines of a paragraph" ) ); + a->setShortcut(Qt::ALT + Qt::Key_J ); connect( a, SIGNAL( activated() ), this, SLOT( textJoinLines() ) ); - a->addTo( menu ); + editMenu->addAction (a); + */ actionEditJoinLines=a; } void TextEditor::setupFormatActions() { - QToolBar *tb = new QToolBar( this ); - tb->setLabel( "Format Actions" ); - QPopupMenu *menu = new QPopupMenu( this ); - menuBar()->insertItem( tr( "F&ormat" ), menu ); + QToolBar *tb = addToolBar ( tr("Format Actions" )); + QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" )); QAction *a; - a = new QAction( tr( "Toggle font hint for the whole text" ), QPixmap(iconPath+"formatfixedfont.png"), 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" ) ); 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( true, tb ); + 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 (iconPath+"text_bold.png"), 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(iconPath+"text_italic.png"), 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 (iconPath+"text_under.png"), 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 *grp = new QActionGroup( this ); connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) ); - actionAlignLeft = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" ); - actionAlignLeft->setToggleAction( true ); - actionAlignCenter = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" ); - actionAlignCenter->setToggleAction( true ); - actionAlignRight = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" ); - actionAlignRight->setToggleAction( true ); - actionAlignJustify = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" ); - actionAlignJustify->setToggleAction( true ); - - grp->addTo( tb ); - grp->addTo( menu ); + 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; QActionGroup *grp2 = new QActionGroup( this ); - grp2->setExclusive(false); - actionAlignSubScript = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ), CTRL + SHIFT + Key_B, grp2, "textSubscript" ); + 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; - actionAlignSubScript->setToggleAction( true ); - connect(actionAlignSubScript, SIGNAL(activated()), this, SLOT(textVAlign())); + 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; - actionAlignSuperScript = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ), CTRL + SHIFT + Key_P, grp2, "textSuperscript" ); - - actionAlignSuperScript->setToggleAction( true ); - connect(actionAlignSuperScript, SIGNAL(activated()), this, SLOT(textVAlign())); - - menu->insertSeparator(); + formatMenu->addSeparator(); - grp2->addTo(tb); - grp2->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 ) ) ); connect( e, SIGNAL( currentVerticalAlignmentChanged(int)), this, SLOT( verticalAlignmentChanged(int))); + */ } 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" )); 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" ) ); 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" ) ); a->setToggleAction (true); // set state later in constructor... - a->addTo( menu ); + settingsMenu->addAction (a); actionSettingsFonthintDefault=a; } @@ -451,7 +485,7 @@ { if (state!=inactiveEditor) { - if (e->length()) + if (e->text().length()) { QMessageBox mb( __VYM " - " +tr("Note Editor"), "Loading will overwrite the existing note", @@ -468,8 +502,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 ) @@ -478,7 +516,7 @@ if ( !fn.isEmpty() ) { QFile f( fn ); - if ( !f.open( IO_ReadOnly ) ) + if ( !f.open( QIODevice::ReadOnly ) ) return; QTextStream ts( &f ); @@ -498,7 +536,10 @@ QString TextEditor::getText() { - return e->text(); + if (e->toPlainText().isEmpty()) + return ""; + else + return e->text(); } void TextEditor::editorChanged() @@ -509,9 +550,9 @@ state=filledEditor; if (state==emptyEditor) - e->setPaper (emptyPaper); + setState (emptyEditor); else - e->setPaper (filledPaper); + setState (filledEditor); // SLOT is LinkableMapObj, which will update systemFlag emit (textHasChanged() ); } @@ -519,12 +560,8 @@ void TextEditor::setText(QString t) { - if ( !QStyleSheet::mightBeRichText( t ) ) - t = QStyleSheet::convertFromPlainText( t, QStyleSheetItem::WhiteSpaceNormal ); e->setReadOnly(false); e->setText(t); -// editorChanged(); //not called automagically FIXME or is it? - enableActions(); } @@ -532,7 +569,7 @@ { state=inactiveEditor; setText(""); - e->setPaper (inactivePaper); + setState (inactiveEditor); e->setReadOnly (true); disableActions(); @@ -561,7 +598,7 @@ 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() ) { @@ -595,7 +632,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 ); @@ -616,9 +653,18 @@ // In X11 a copy&paste generates paragraphs, // which is not always wanted // This function replaces paragraphs by linebreaks. + + QString t; + t=e->text(); + QRegExp re(""); + re.setMinimal(true); + t.replace (re,""); + t.replace ("

","
"); + e->setText(t); + + /* TODO QT3 use seletion () int parFrom, parTo, indFrom, indTo; e->getSelection (&parFrom,&indFrom,&parTo,&indTo); - QString t; if (parFrom>-1) t=e->selectedText(); else @@ -641,10 +687,12 @@ e->setText (e->text().replace(marker,t)); } else e->setText(t); + */ } void TextEditor::textJoinLines() { +/* TODO QT3 int parFrom, parTo, indFrom, indTo; e->getSelection (&parFrom,&indFrom,&parTo,&indTo); QString t; @@ -675,6 +723,7 @@ e->setText (e->text().replace(marker,t)); } else e->setText(t); +*/ } void TextEditor::textExportAsASCII() @@ -704,7 +753,7 @@ 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(); @@ -713,7 +762,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 @@ -730,41 +779,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 Document")); + if (dialog->exec() != QDialog::Accepted) + return; + + document->print(&printer); } void TextEditor::textEditUndo() @@ -774,12 +798,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(); } @@ -837,24 +861,25 @@ 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() { +/* FIXME QT3 alignment if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) { e->setVerticalAlignment( QTextEdit::AlignSuperScript); } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) { @@ -862,13 +887,16 @@ } else { e->setVerticalAlignment( QTextEdit::AlignNormal); } +*/ } void TextEditor::fontChanged( const QFont &f ) { +/* comboFont->lineEdit()->setText( f.family() ); comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); +*/ actionTextBold->setOn( f.bold() ); actionTextItalic->setOn( f.italic() ); actionTextUnderline->setOn( f.underline() ); @@ -883,18 +911,19 @@ void TextEditor::alignmentChanged( int a ) { - if ( ( a == AlignAuto ) || ( a & AlignLeft )) + if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft )) actionAlignLeft->setOn( true ); - else if ( ( a & AlignHCenter ) ) + else if ( ( a & Qt::AlignHCenter ) ) actionAlignCenter->setOn( true ); - else if ( ( a & AlignRight ) ) + else if ( ( a & Qt::AlignRight ) ) actionAlignRight->setOn( true ); - else if ( ( a & AlignJustify ) ) + else if ( ( a & Qt::AlignJustify ) ) actionAlignJustify->setOn( true ); } void TextEditor::verticalAlignmentChanged(int a) { + /* FIXME QT3 alignment if (a == QTextEdit::AlignSuperScript ) { actionAlignSuperScript->setOn(true); actionAlignSubScript->setOn(false); @@ -905,6 +934,7 @@ actionAlignSuperScript->setOn(false); actionAlignSubScript->setOn(false); } + */ } @@ -943,4 +973,20 @@ 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); +} +