insilmaril@0: #include "texteditor.h" insilmaril@0: insilmaril@0: #include insilmaril@95: #include insilmaril@0: #include insilmaril@0: insilmaril@189: #include "noteobj.h" insilmaril@404: #include "settings.h" insilmaril@189: #include "version.h" insilmaril@189: insilmaril@0: extern int statusbarTime; insilmaril@404: extern Settings settings; insilmaril@0: insilmaril@94: extern QAction *actionViewToggleNoteEditor; insilmaril@94: insilmaril@269: extern QString iconPath; insilmaril@404: extern QString vymName; insilmaril@269: insilmaril@0: using namespace std; insilmaril@0: insilmaril@0: insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: jhilmer@142: insilmaril@0: TextEditor::TextEditor() insilmaril@0: { insilmaril@0: printer = new QPrinter( QPrinter::HighResolution ); insilmaril@366: printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); insilmaril@0: insilmaril@388: e = new QTextEdit( this); insilmaril@0: e->setFocus(); insilmaril@366: e->setTextFormat(Qt::RichText); // default insilmaril@0: e->setTabStopWidth (20); // unit is pixel insilmaril@366: e->setColor (Qt::black); insilmaril@366: e->setAutoFillBackground (true); insilmaril@0: connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); insilmaril@0: setCentralWidget( e ); insilmaril@388: statusBar()->message( tr("Ready","Statusbar message"), statusbarTime); insilmaril@404: setCaption(vymName +" - " +tr ("Note Editor","Window caption")); insilmaril@0: insilmaril@388: insilmaril@388: connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), insilmaril@388: this, SLOT(formatChanged(const QTextCharFormat &))); insilmaril@388: insilmaril@388: insilmaril@388: insilmaril@0: // Toolbars insilmaril@0: setupFileActions(); insilmaril@0: setupEditActions(); insilmaril@0: setupFormatActions(); insilmaril@0: setupSettingsActions(); insilmaril@0: insilmaril@0: // Various states insilmaril@427: blockChangedSignal=false; insilmaril@0: setInactive(); insilmaril@0: insilmaril@0: // Load Settings insilmaril@366: resize (settings.value ( "/noteeditor/geometry/size", QSize(450,600)).toSize()); insilmaril@366: move (settings.value ( "/noteeditor/geometry/pos", QPoint (250,50)).toPoint()); insilmaril@0: insilmaril@366: if (settings.value ( "/noteeditor/showWithMain",true).toBool()) insilmaril@0: setShowWithMain(true); insilmaril@0: else insilmaril@0: setShowWithMain(false); insilmaril@0: insilmaril@366: varFont.fromString( settings.value insilmaril@366: ("/noteeditor/fonts/varFont", insilmaril@366: "Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString() insilmaril@0: ); insilmaril@366: fixedFont.fromString (settings.value( insilmaril@366: "/noteeditor/fonts/fixedFont", insilmaril@366: "Courier,14,-1,5,48,0,0,0,1,0").toString() insilmaril@0: ); insilmaril@366: QString s=settings.value ("/noteeditor/fonts/fonthintDefault","variable").toString(); insilmaril@0: if (s == "fixed") insilmaril@0: { insilmaril@0: actionSettingsFonthintDefault->setOn (true); insilmaril@0: e->setCurrentFont (fixedFont); insilmaril@0: } else insilmaril@0: { insilmaril@0: actionSettingsFonthintDefault->setOn (false); insilmaril@0: e->setCurrentFont (varFont); insilmaril@0: } insilmaril@106: filenameHint=""; insilmaril@123: insilmaril@388: // Restore position of toolbars insilmaril@388: restoreState (settings.value("/noteeditor/state",0).toByteArray()); insilmaril@388: insilmaril@123: // Save settings in vymrc insilmaril@366: settings.setValue("/mainwindow/printerName",printer->printerName()); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: TextEditor::~TextEditor() insilmaril@0: { insilmaril@0: if (printer) delete printer; insilmaril@0: // Save Settings insilmaril@366: settings.setValue( "/noteeditor/geometry/size", size() ); insilmaril@366: settings.setValue( "/noteeditor/geometry/pos", pos() ); insilmaril@388: settings.setValue ("/noteeditor/state",saveState(0)); insilmaril@0: insilmaril@366: settings.setValue( "/noteeditor/showWithMain",showWithMain()); insilmaril@0: insilmaril@0: QString s; insilmaril@0: if (actionSettingsFonthintDefault->isOn() ) insilmaril@0: s="fixed"; insilmaril@0: else insilmaril@0: s="variable"; insilmaril@366: settings.setValue( "/noteeditor/fonts/fonthintDefault",s ); insilmaril@366: settings.setValue("/noteeditor/fonts/varFont", varFont.toString() ); insilmaril@366: settings.setValue("/noteeditor/fonts/fixedFont", fixedFont.toString() ); insilmaril@388: insilmaril@388: insilmaril@0: } insilmaril@0: insilmaril@0: bool TextEditor::isEmpty() insilmaril@0: { insilmaril@366: if (e->toPlainText().length()>0) insilmaril@0: return false; insilmaril@0: else insilmaril@0: return true; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setShowWithMain(bool v) insilmaril@0: { insilmaril@0: showwithmain=v; insilmaril@0: } insilmaril@0: insilmaril@0: bool TextEditor::showWithMain() insilmaril@0: { insilmaril@0: return showwithmain; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setFontHint (const QString &fh) insilmaril@0: { insilmaril@0: if (fh=="fixed") insilmaril@0: actionFormatUseFixedFont->setOn (true); insilmaril@0: else insilmaril@0: actionFormatUseFixedFont->setOn (false); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: QString TextEditor::getFontHint() insilmaril@0: { insilmaril@0: if (actionFormatUseFixedFont->isOn()) insilmaril@0: return "fixed"; insilmaril@0: else insilmaril@0: return "var"; insilmaril@0: } insilmaril@0: insilmaril@0: QString TextEditor::getFontHintDefault() insilmaril@0: { insilmaril@0: if (actionSettingsFonthintDefault->isOn()) insilmaril@0: return "fixed"; insilmaril@0: else insilmaril@0: return "var"; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setFilename(const QString &fn) insilmaril@0: { insilmaril@0: if (state==filledEditor) insilmaril@0: if (fn.isEmpty() ) insilmaril@0: { insilmaril@0: filename=""; insilmaril@388: statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime ); insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@0: filename=fn; insilmaril@388: statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: QString TextEditor::getFilename() insilmaril@0: { insilmaril@0: return filename; insilmaril@0: } insilmaril@0: insilmaril@106: void TextEditor::setFilenameHint(const QString &fnh) insilmaril@106: { insilmaril@106: filenameHint=fnh; insilmaril@106: } insilmaril@106: insilmaril@106: QString TextEditor::getFilenameHint() insilmaril@106: { insilmaril@106: return filenameHint; insilmaril@106: } insilmaril@106: insilmaril@366: bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags) insilmaril@0: { insilmaril@366: if (e->find (t,flags)) insilmaril@0: return true; insilmaril@0: else insilmaril@0: return false; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setupFileActions() insilmaril@0: { insilmaril@366: QToolBar *tb = addToolBar ( tr("Note Actions") ); insilmaril@389: tb->setObjectName ("noteEditorFileActions"); insilmaril@395: QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" )); insilmaril@0: insilmaril@0: QAction *a; insilmaril@366: a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this); insilmaril@395: a->setStatusTip (tr( "Import","Status tip for Note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_O ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) ); insilmaril@366: tb->addAction (a); insilmaril@366: fileMenu->addAction (a); insilmaril@0: actionFileLoad=a; insilmaril@0: insilmaril@366: fileMenu->addSeparator(); insilmaril@366: a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this); insilmaril@395: a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_S ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) ); insilmaril@366: tb->addAction (a); insilmaril@366: fileMenu->addAction (a); insilmaril@0: actionFileSave=a; insilmaril@0: insilmaril@366: a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this); insilmaril@395: a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu" )); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) ); insilmaril@366: fileMenu->addAction (a); insilmaril@0: actionFileSaveAs=a; insilmaril@0: insilmaril@366: a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this); insilmaril@395: a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) ); insilmaril@366: a->setShortcut(Qt::ALT + Qt::Key_X ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) ); insilmaril@366: fileMenu->addAction (a); insilmaril@0: actionFileSaveAs=a; insilmaril@0: insilmaril@366: fileMenu->addSeparator(); insilmaril@366: a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this); insilmaril@395: a->setStatusTip (tr( "Print Note","Status tip for note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_P ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) ); insilmaril@366: tb->addAction (a); insilmaril@366: fileMenu->addAction (a); insilmaril@0: actionFilePrint=a; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setupEditActions() insilmaril@0: { insilmaril@366: QToolBar *tb = addToolBar ( tr( "Edit Actions" )); insilmaril@389: tb->setObjectName ("noteEditorEditActions"); insilmaril@366: QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" )); insilmaril@0: insilmaril@0: QAction *a; insilmaril@366: a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this ); insilmaril@395: a->setStatusTip ( tr( "Undo","Status tip for note menu" ) ); insilmaril@366: a->setShortcut(Qt::CTRL + Qt::Key_Z ); insilmaril@0: connect( a, SIGNAL( activated() ), e, SLOT( undo() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionEditUndo=a; insilmaril@0: insilmaril@366: a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this); insilmaril@395: a->setStatusTip ( tr( "Redo","Status tip for note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_Y ); insilmaril@0: connect( a, SIGNAL( activated() ), e, SLOT( redo() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionEditRedo=a; insilmaril@0: insilmaril@366: editMenu->addSeparator(); insilmaril@366: a = new QAction(QPixmap(), tr( "Select and copy &all" ),this); insilmaril@395: a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_A ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@0: insilmaril@366: editMenu->addSeparator(); insilmaril@366: a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this); insilmaril@395: a->setStatusTip ( tr( "Copy","Status tip for note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_C ); insilmaril@0: connect( a, SIGNAL( activated() ), e, SLOT( copy() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionEditCopy=a; insilmaril@0: insilmaril@366: a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this); insilmaril@395: a->setStatusTip ( tr( "Cut","Status tip for note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_X ); insilmaril@0: connect( a, SIGNAL( activated() ), e, SLOT( cut() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionEditCut=a; insilmaril@0: insilmaril@366: a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this); insilmaril@395: a->setStatusTip ( tr( "Paste","Status tip for note menu" ) ); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_V ); insilmaril@0: connect( a, SIGNAL( activated() ), e, SLOT( paste() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionEditPaste=a; insilmaril@0: insilmaril@366: a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this); insilmaril@395: a->setStatusTip (tr( "Delete all","Status tip for note menu" ) ); insilmaril@0: connect( a, SIGNAL( activated() ), e, SLOT( clear() ) ); insilmaril@366: editMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionEditDeleteAll=a; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setupFormatActions() insilmaril@0: { insilmaril@366: QToolBar *tb = addToolBar ( tr("Format Actions" )); insilmaril@389: tb->setObjectName ("noteEditorFormatActions"); insilmaril@366: QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" )); insilmaril@0: insilmaril@0: QAction *a; insilmaril@0: insilmaril@366: a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" ); insilmaril@395: a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) ); insilmaril@0: a->setToggleAction (true); insilmaril@366: a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) ); insilmaril@366: formatMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@0: actionFormatUseFixedFont=a; insilmaril@0: insilmaril@366: comboFont = new QComboBox; insilmaril@366: tb->addWidget (comboFont); insilmaril@366: QFontDatabase fontDB; insilmaril@366: comboFont->insertStringList( fontDB.families() ); insilmaril@0: connect( comboFont, SIGNAL( activated( const QString & ) ), insilmaril@0: this, SLOT( textFamily( const QString & ) ) ); insilmaril@366: comboFont->addItem( QApplication::font().family() ); insilmaril@366: comboSize = new QComboBox; insilmaril@366: tb->addWidget (comboSize); insilmaril@366: QList sizes=fontDB.standardSizes(); insilmaril@366: QList::iterator i = sizes.begin(); insilmaril@366: while (i != sizes.end()) insilmaril@366: { insilmaril@366: ++i; // increment i before using it insilmaril@366: comboSize->insertItem ( QString::number(*i)); insilmaril@366: } insilmaril@0: connect( comboSize, SIGNAL( activated( const QString & ) ), insilmaril@0: this, SLOT( textSize( const QString & ) ) ); insilmaril@366: comboSize->addItem ( QString::number( QApplication::font().pointSize() ) ); insilmaril@0: insilmaril@366: formatMenu->addSeparator(); insilmaril@0: insilmaril@0: QPixmap pix( 16, 16 ); insilmaril@0: pix.fill( e->color()); insilmaril@366: a = new QAction( pix, tr( "&Color..." ), this); insilmaril@366: formatMenu->addAction (a); insilmaril@366: tb->addAction (a); insilmaril@366: connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) ); insilmaril@366: actionTextColor=a; insilmaril@0: insilmaril@366: a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this); insilmaril@366: a->setShortcut(Qt::CTRL + Qt::Key_B ); insilmaril@366: connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: a->setToggleAction( true ); insilmaril@366: actionTextBold=a; insilmaril@366: insilmaril@366: a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this); insilmaril@366: a->setShortcut(Qt::CTRL + Qt::Key_I); insilmaril@366: connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: a->setToggleAction( true ); insilmaril@366: actionTextItalic=a; insilmaril@366: insilmaril@366: a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this); insilmaril@366: a->setShortcut(Qt::CTRL + Qt::Key_U ); insilmaril@366: connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: a->setToggleAction( true ); insilmaril@366: actionTextUnderline=a; insilmaril@366: formatMenu->addSeparator(); insilmaril@0: insilmaril@388: QActionGroup *grp2 = new QActionGroup( this ); insilmaril@388: grp2->setExclusive(true); insilmaril@388: a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 ); insilmaril@388: a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B ); insilmaril@388: a->setToggleAction( true ); insilmaril@388: tb->addAction (a); insilmaril@388: formatMenu->addAction (a); insilmaril@388: connect(a, SIGNAL(activated()), this, SLOT(textVAlign())); insilmaril@388: actionAlignSubScript=a; insilmaril@388: insilmaril@388: a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 ); insilmaril@388: a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P ); insilmaril@388: a->setToggleAction( true ); insilmaril@388: tb->addAction (a); insilmaril@388: formatMenu->addAction (a); insilmaril@388: connect(a, SIGNAL(activated()), this, SLOT(textVAlign())); insilmaril@388: actionAlignSuperScript=a; insilmaril@0: QActionGroup *grp = new QActionGroup( this ); insilmaril@0: connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) ); insilmaril@0: insilmaril@388: formatMenu->addSeparator(); insilmaril@388: insilmaril@366: a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp ); insilmaril@366: a->setShortcut( Qt::CTRL+Qt::Key_L ); insilmaril@366: a->setToggleAction( true ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: actionAlignLeft=a; insilmaril@366: a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp); insilmaril@366: a->setShortcut( Qt::CTRL + Qt::Key_E); insilmaril@366: a->setToggleAction( true ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: actionAlignCenter=a; insilmaril@366: a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp); insilmaril@366: a->setShortcut(Qt::CTRL + Qt::Key_R ); insilmaril@366: a->setToggleAction( true ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: actionAlignRight=a; insilmaril@366: a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp ); insilmaril@366: a->setShortcut(Qt::CTRL + Qt::Key_J ); insilmaril@366: a->setToggleAction( true ); insilmaril@366: tb->addAction (a); insilmaril@366: formatMenu->addAction (a); insilmaril@366: actionAlignJustify=a; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setupSettingsActions() insilmaril@0: { insilmaril@366: QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" )); insilmaril@0: insilmaril@0: QAction *a; insilmaril@366: a = new QAction(tr( "Set &fixed font" ), this); insilmaril@395: a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" )); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) ); insilmaril@366: settingsMenu->addAction (a); insilmaril@0: actionSettingsFixedFont=a; insilmaril@0: insilmaril@366: a = new QAction(tr( "Set &variable font" ), this); insilmaril@395: a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) ); insilmaril@0: connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) ); insilmaril@366: settingsMenu->addAction (a); insilmaril@0: actionSettingsVarFont=a; insilmaril@0: insilmaril@366: a = new QAction(tr( "&fixed font is default" ), this); insilmaril@395: a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) ); insilmaril@0: a->setToggleAction (true); insilmaril@0: // set state later in constructor... insilmaril@366: settingsMenu->addAction (a); insilmaril@0: actionSettingsFonthintDefault=a; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textLoad() insilmaril@0: { insilmaril@0: if (state!=inactiveEditor) insilmaril@0: { insilmaril@366: if (e->text().length()) insilmaril@0: { insilmaril@404: QMessageBox mb( vymName + " - " +tr("Note Editor"), insilmaril@0: "Loading will overwrite the existing note", insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel, insilmaril@0: 0 ); insilmaril@0: mb.setButtonText( QMessageBox::Yes, "Load note" ); insilmaril@0: switch( mb.exec() ) { insilmaril@0: case QMessageBox::Cancel: insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: // Load note insilmaril@0: QFileDialog *fd=new QFileDialog( this); insilmaril@366: QStringList types; insilmaril@366: types<< "VYM notes (*.html)" << insilmaril@366: "ASCII texts (*.txt)" << insilmaril@366: "All filed (*)"; insilmaril@366: fd->setFilters (types); insilmaril@366: fd->setDirectory (QDir().current()); insilmaril@0: fd->show(); insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: fn = fd->selectedFile(); insilmaril@0: insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: QFile f( fn ); insilmaril@366: if ( !f.open( QIODevice::ReadOnly ) ) insilmaril@0: return; insilmaril@0: insilmaril@0: QTextStream ts( &f ); insilmaril@0: setText( ts.read() ); insilmaril@0: editorChanged(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::closeEvent( QCloseEvent* ce ) insilmaril@0: { jhilmer@144: ce->accept(); // TextEditor can be reopened with show() insilmaril@393: showwithmain=false; insilmaril@390: emit (textEditorClosed() ); jhilmer@144: return; insilmaril@0: } insilmaril@0: insilmaril@0: QString TextEditor::getText() insilmaril@0: { insilmaril@366: if (e->toPlainText().isEmpty()) insilmaril@366: return ""; insilmaril@366: else insilmaril@366: return e->text(); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::editorChanged() insilmaril@0: { insilmaril@0: if (isEmpty()) insilmaril@0: state=emptyEditor; insilmaril@0: else insilmaril@0: state=filledEditor; insilmaril@0: insilmaril@0: if (state==emptyEditor) insilmaril@366: setState (emptyEditor); insilmaril@0: else insilmaril@366: setState (filledEditor); insilmaril@0: // SLOT is LinkableMapObj, which will update systemFlag insilmaril@427: if (!blockChangedSignal) emit (textHasChanged() ); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void TextEditor::setText(QString t) insilmaril@0: { insilmaril@427: blockChangedSignal=true; insilmaril@0: e->setReadOnly(false); insilmaril@0: e->setText(t); insilmaril@0: enableActions(); insilmaril@427: blockChangedSignal=false; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setInactive() insilmaril@0: { jhilmer@135: state=inactiveEditor; insilmaril@0: setText(""); insilmaril@366: setState (inactiveEditor); insilmaril@0: e->setReadOnly (true); insilmaril@0: insilmaril@0: disableActions(); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::editCopyAll() insilmaril@0: { insilmaril@0: e->selectAll(); insilmaril@0: e->copy(); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textSaveAs() insilmaril@0: { insilmaril@0: QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)", insilmaril@0: this,"export note dialog",tr("Export Note to single file") ); insilmaril@0: insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: QFile file (fn); insilmaril@0: if (file.exists()) insilmaril@0: { insilmaril@404: QMessageBox mb( vymName, insilmaril@395: tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@366: Qt::NoButton ); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: switch( mb.exec() ) { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save insilmaril@0: filename = fn; insilmaril@0: textSave(); insilmaril@0: return; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: break; insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: filename = fn; insilmaril@0: textSave(); insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@395: statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime ); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void TextEditor::textSave() insilmaril@0: { insilmaril@0: if ( filename.isEmpty() ) insilmaril@0: { insilmaril@0: textSaveAs(); insilmaril@0: return; insilmaril@0: } insilmaril@0: insilmaril@0: QString text = e->text(); insilmaril@0: QFile f( filename ); insilmaril@366: if ( !f.open( QIODevice::WriteOnly ) ) insilmaril@0: { insilmaril@0: statusBar()->message( QString("Could not write to %1").arg(filename), insilmaril@0: statusbarTime ); insilmaril@0: return; insilmaril@0: } insilmaril@0: insilmaril@0: QTextStream t( &f ); insilmaril@0: t << text; insilmaril@0: f.close(); insilmaril@0: insilmaril@0: e->setModified( FALSE ); insilmaril@0: insilmaril@0: statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textExportAsASCII() insilmaril@0: { insilmaril@189: QString text = NoteObj (e->text()).getNoteASCII(); insilmaril@106: QString fn,s; insilmaril@106: if (!filenameHint.isEmpty()) insilmaril@106: { insilmaril@106: if (!filenameHint.contains (".txt")) insilmaril@106: s=filenameHint+".txt"; insilmaril@106: else insilmaril@106: s=filenameHint; insilmaril@106: } else insilmaril@106: s=QString::null; insilmaril@106: fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") ); insilmaril@0: int ret=-1; insilmaril@0: insilmaril@0: if ( !fn.isEmpty() ) insilmaril@0: { insilmaril@0: QFile file (fn); insilmaril@0: if (file.exists()) insilmaril@0: { insilmaril@404: QMessageBox mb( vymName, insilmaril@395: tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@366: Qt::NoButton ); insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: ret=mb.exec(); insilmaril@0: } insilmaril@0: if (ret==QMessageBox::Cancel) insilmaril@0: return; insilmaril@0: insilmaril@0: // save insilmaril@366: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@0: statusBar()->message( QString("Could not write to %1").arg(filename), insilmaril@0: statusbarTime ); insilmaril@0: else insilmaril@0: { insilmaril@0: QTextStream t( &file ); insilmaril@0: t << text; insilmaril@0: file.close(); insilmaril@0: insilmaril@0: statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime ); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void TextEditor::textPrint() insilmaril@0: { insilmaril@0: insilmaril@366: QTextDocument *document = e->document(); insilmaril@366: QPrinter printer; insilmaril@366: insilmaril@366: QPrintDialog *dialog = new QPrintDialog(&printer, this); insilmaril@395: dialog->setWindowTitle(tr("Print Note")); insilmaril@366: if (dialog->exec() != QDialog::Accepted) insilmaril@366: return; insilmaril@366: insilmaril@366: document->print(&printer); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textEditUndo() insilmaril@0: { insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::toggleFonthint() insilmaril@0: { insilmaril@0: setUpdatesEnabled (false); insilmaril@366: e->selectAll (); insilmaril@0: if (!actionFormatUseFixedFont->isOn() ) insilmaril@0: e->setCurrentFont (varFont); insilmaril@0: else insilmaril@0: e->setCurrentFont (fixedFont); insilmaril@366: e->selectAll (); insilmaril@0: setUpdatesEnabled (true); insilmaril@0: repaint(); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setFixedFont() insilmaril@0: { insilmaril@0: bool ok; insilmaril@0: QFont font =QFontDialog::getFont( insilmaril@0: &ok, fixedFont, this ); insilmaril@0: if ( ok ) insilmaril@0: // font is set to the font the user selected insilmaril@0: fixedFont=font; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::setVarFont() insilmaril@0: { insilmaril@0: bool ok; insilmaril@0: QFont font =QFontDialog::getFont( insilmaril@0: &ok, varFont, this ); insilmaril@0: if ( ok ) insilmaril@0: // font is set to the font the user selected insilmaril@0: varFont=font; insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textBold() insilmaril@0: { insilmaril@0: e->setBold( actionTextBold->isOn() ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textUnderline() insilmaril@0: { insilmaril@0: e->setUnderline( actionTextUnderline->isOn() ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textItalic() insilmaril@0: { insilmaril@0: e->setItalic( actionTextItalic->isOn() ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textFamily( const QString &f ) insilmaril@0: { insilmaril@0: e->setFamily( f ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textSize( const QString &p ) insilmaril@0: { insilmaril@0: e->setPointSize( p.toInt() ); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void TextEditor::textColor() insilmaril@0: { insilmaril@0: QColor col = QColorDialog::getColor( e->color(), this ); insilmaril@388: if ( !col.isValid() ) return; insilmaril@0: e->setColor( col ); insilmaril@0: QPixmap pix( 16, 16 ); insilmaril@366: pix.fill( Qt::black ); insilmaril@0: actionTextColor->setIconSet( pix ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::textAlign( QAction *a ) insilmaril@0: { insilmaril@0: if ( a == actionAlignLeft ) insilmaril@388: e->setAlignment( Qt::AlignLeft ); insilmaril@0: else if ( a == actionAlignCenter ) insilmaril@388: e->setAlignment( Qt::AlignHCenter ); insilmaril@0: else if ( a == actionAlignRight ) insilmaril@388: e->setAlignment( Qt::AlignRight ); insilmaril@0: else if ( a == actionAlignJustify ) insilmaril@388: e->setAlignment( Qt::AlignJustify ); insilmaril@0: } insilmaril@0: jhilmer@142: void TextEditor::textVAlign() jhilmer@142: { insilmaril@388: QTextCharFormat format; insilmaril@388: jhilmer@142: if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) { insilmaril@388: format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); jhilmer@142: } else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) { insilmaril@388: format.setVerticalAlignment(QTextCharFormat::AlignSubScript); jhilmer@142: } else { insilmaril@388: format.setVerticalAlignment(QTextCharFormat::AlignNormal); jhilmer@142: } insilmaril@388: e->mergeCurrentCharFormat(format); jhilmer@142: } jhilmer@142: jhilmer@142: insilmaril@0: void TextEditor::fontChanged( const QFont &f ) insilmaril@0: { insilmaril@388: int i=comboFont->findText(f.family()); insilmaril@388: if (i>=0) comboFont->setCurrentIndex (i); insilmaril@388: i=comboSize->findText(QString::number(f.pointSize())); insilmaril@388: if (i>=0) comboSize->setCurrentIndex(i); insilmaril@0: actionTextBold->setOn( f.bold() ); insilmaril@0: actionTextItalic->setOn( f.italic() ); insilmaril@0: actionTextUnderline->setOn( f.underline() ); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::colorChanged( const QColor &c ) insilmaril@0: { insilmaril@0: QPixmap pix( 16, 16 ); insilmaril@0: pix.fill( c ); insilmaril@0: actionTextColor->setIconSet( pix ); insilmaril@0: } insilmaril@0: insilmaril@388: void TextEditor::formatChanged( const QTextCharFormat &f ) insilmaril@388: { insilmaril@388: fontChanged(f.font()); insilmaril@388: colorChanged(f.foreground().color()); insilmaril@388: alignmentChanged(e->alignment()); insilmaril@388: verticalAlignmentChanged (f.verticalAlignment()); insilmaril@388: } insilmaril@388: insilmaril@0: void TextEditor::alignmentChanged( int a ) insilmaril@0: { insilmaril@366: if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft )) insilmaril@388: actionAlignLeft->setOn( true ); insilmaril@366: else if ( ( a & Qt::AlignHCenter ) ) insilmaril@388: actionAlignCenter->setOn( true ); insilmaril@366: else if ( ( a & Qt::AlignRight ) ) insilmaril@388: actionAlignRight->setOn( true ); insilmaril@366: else if ( ( a & Qt::AlignJustify ) ) insilmaril@388: actionAlignJustify->setOn( true ); insilmaril@0: } insilmaril@0: insilmaril@388: void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a) jhilmer@142: { insilmaril@388: actionAlignSubScript->setOn (false); insilmaril@388: actionAlignSuperScript->setOn (false); insilmaril@388: switch (a) insilmaril@388: { insilmaril@388: case QTextCharFormat::AlignSuperScript: insilmaril@388: actionAlignSuperScript->setOn (true); insilmaril@388: break; insilmaril@388: case QTextCharFormat::AlignSubScript: insilmaril@388: actionAlignSubScript->setOn (true); insilmaril@388: break; insilmaril@388: default: ; insilmaril@388: } jhilmer@142: } jhilmer@142: insilmaril@0: insilmaril@0: insilmaril@0: void TextEditor::enableActions() insilmaril@0: { insilmaril@0: actionFileLoad->setEnabled(true); insilmaril@0: actionFileSave->setEnabled(true); insilmaril@0: actionFileSaveAs->setEnabled(true); insilmaril@0: actionFilePrint->setEnabled(true); insilmaril@0: actionEditUndo->setEnabled(true); insilmaril@0: actionEditRedo->setEnabled(true); insilmaril@0: actionEditCopy->setEnabled(true); insilmaril@0: actionEditCut->setEnabled(true); insilmaril@0: actionEditPaste->setEnabled(true); insilmaril@0: actionEditDeleteAll->setEnabled(true); insilmaril@0: actionFormatUseFixedFont->setEnabled(true); insilmaril@0: } insilmaril@0: insilmaril@0: void TextEditor::disableActions() insilmaril@0: { insilmaril@0: actionFileLoad->setEnabled(false); insilmaril@0: actionFileSave->setEnabled(false); insilmaril@0: actionFileSaveAs->setEnabled(false); insilmaril@0: actionFilePrint->setEnabled(false); insilmaril@0: actionEditUndo->setEnabled(false); insilmaril@0: actionEditRedo->setEnabled(false); insilmaril@0: actionEditCopy->setEnabled(false); insilmaril@0: actionEditCut->setEnabled(false); insilmaril@0: actionEditPaste->setEnabled(false); insilmaril@0: actionEditDeleteAll->setEnabled(false); insilmaril@0: actionFormatUseFixedFont->setEnabled(false); insilmaril@0: } insilmaril@0: insilmaril@366: void TextEditor::setState (EditorState s) insilmaril@366: { insilmaril@366: insilmaril@366: QPalette p=palette(); insilmaril@366: QColor c; insilmaril@366: switch (s) insilmaril@366: { insilmaril@366: case emptyEditor: c=QColor (150,150,150); break; insilmaril@366: case filledEditor: c=QColor (255,255,255); break; insilmaril@366: case inactiveEditor: c=QColor (0,0,0); insilmaril@366: } insilmaril@366: p.setColor(QPalette::Active, static_cast(9), c); insilmaril@366: p.setColor(QPalette::Inactive, static_cast(9), c); insilmaril@366: e->setPalette(p); insilmaril@366: } insilmaril@0: insilmaril@366: