diff options
Diffstat (limited to 'libkdepim/komposer/plugins')
-rw-r--r-- | libkdepim/komposer/plugins/Makefile.am | 1 | ||||
-rw-r--r-- | libkdepim/komposer/plugins/default/Makefile.am | 15 | ||||
-rw-r--r-- | libkdepim/komposer/plugins/default/defaulteditor.cpp | 361 | ||||
-rw-r--r-- | libkdepim/komposer/plugins/default/defaulteditor.desktop | 111 | ||||
-rw-r--r-- | libkdepim/komposer/plugins/default/defaulteditor.h | 117 | ||||
-rw-r--r-- | libkdepim/komposer/plugins/default/defaulteditorui.rc | 90 |
6 files changed, 695 insertions, 0 deletions
diff --git a/libkdepim/komposer/plugins/Makefile.am b/libkdepim/komposer/plugins/Makefile.am new file mode 100644 index 000000000..dcc4764a7 --- /dev/null +++ b/libkdepim/komposer/plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = default diff --git a/libkdepim/komposer/plugins/default/Makefile.am b/libkdepim/komposer/plugins/default/Makefile.am new file mode 100644 index 000000000..2c93eb098 --- /dev/null +++ b/libkdepim/komposer/plugins/default/Makefile.am @@ -0,0 +1,15 @@ +AM_CPPFLAGS = -I$(top_builddir)/libkdepim/komposer/core $(all_includes) + +kde_module_LTLIBRARIES = libkomposer_defaulteditor.la +libkomposer_defaulteditor_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) +libkomposer_defaulteditor_la_LIBADD = ../../core/libkomposer.la $(LIB_KPARTS) + +libkomposer_defaulteditor_la_SOURCES = defaulteditor.cpp + +METASOURCES = AUTO + +servicedir = $(kde_servicesdir)/komposer +service_DATA = defaulteditor.desktop + +rcdir = $(kde_datadir)/komposer_defaulteditor +rc_DATA = defaulteditorui.rc diff --git a/libkdepim/komposer/plugins/default/defaulteditor.cpp b/libkdepim/komposer/plugins/default/defaulteditor.cpp new file mode 100644 index 000000000..d08fbee5e --- /dev/null +++ b/libkdepim/komposer/plugins/default/defaulteditor.cpp @@ -0,0 +1,361 @@ +/** + * defaulteditor.cpp + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "defaulteditor.h" +#include "core.h" + +#include <kgenericfactory.h> +#include <kapplication.h> +#include <kaction.h> +#include <kiconloader.h> +#include <kdebug.h> + +#include <kaction.h> +#include <kcolordialog.h> +#include <kfiledialog.h> +#include <kinstance.h> +#include <klocale.h> +#include <kstdaction.h> +#include <kprinter.h> +#include <kfinddialog.h> +#include <kfind.h> +#include <kreplacedialog.h> +#include <kreplace.h> + +#include <qtextedit.h> +#include <qwidget.h> + +typedef KGenericFactory<DefaultEditor> DefaultEditorFactory; +K_EXPORT_COMPONENT_FACTORY( libkomposer_defaulteditor, + DefaultEditorFactory( "komposer_defaulteditor" ) ) + +DefaultEditor::DefaultEditor( QObject *parent, const char *name, const QStringList &args ) + : Editor( parent, name, args ), m_textEdit( 0 ) +{ + setInstance( DefaultEditorFactory::instance() ); + + m_textEdit = new QTextEdit( 0 ); + + createActions( actionCollection() ); + + setXMLFile( "defaulteditorui.rc" ); +} + +DefaultEditor::~DefaultEditor() +{ +} + + +QWidget* +DefaultEditor::widget() +{ + return m_textEdit; +} + +QString +DefaultEditor::text() const +{ + return m_textEdit->text(); +} + +void +DefaultEditor::setText( const QString &text ) +{ + m_textEdit->setText( text ); +} + +void +DefaultEditor::changeSignature( const QString &sig ) +{ + QString text = m_textEdit->text(); + + int sigStart = text.findRev( "-- " ); + QString sigText = QString( "-- \n%1" ).arg( sig ); + + text.replace( sigStart, text.length(), sigText ); +} + +void +DefaultEditor::createActions( KActionCollection *ac ) +{ + // + // File Actions + // + (void) KStdAction::open( this, SLOT(open()), ac ); + (void) KStdAction::openRecent( this, SLOT(openURL(const KURL &)), ac ); + (void) KStdAction::save( this, SLOT(save()), ac ); + (void) KStdAction::saveAs( this, SLOT(saveAs()), ac ); + + // + // Edit Actions + // + KAction *actionUndo = KStdAction::undo( m_textEdit, SLOT(undo()), ac ); + actionUndo->setEnabled( false ); + connect( m_textEdit, SIGNAL(undoAvailable(bool)), + actionUndo, SLOT(setEnabled(bool)) ); + + KAction *actionRedo = KStdAction::redo( m_textEdit, SLOT(redo()), ac ); + actionRedo->setEnabled( false ); + connect( m_textEdit, SIGNAL(redoAvailable(bool)), + actionRedo, SLOT(setEnabled(bool)) ); + + KAction *action_cut = KStdAction::cut( m_textEdit, SLOT(cut()), ac ); + action_cut->setEnabled( false ); + connect( m_textEdit, SIGNAL(copyAvailable(bool)), + action_cut, SLOT(setEnabled(bool)) ); + + KAction *action_copy = KStdAction::copy( m_textEdit, SLOT(copy()), ac ); + action_copy->setEnabled( false ); + connect( m_textEdit, SIGNAL(copyAvailable(bool)), + action_copy, SLOT(setEnabled(bool)) ); + + (void) KStdAction::print( this, SLOT(print()), ac ); + + (void) KStdAction::paste( m_textEdit, SLOT(paste()), ac ); + (void) new KAction( i18n( "C&lear" ), 0, + m_textEdit, SLOT(removeSelectedText()), + ac, "edit_clear" ); + + (void) KStdAction::selectAll( m_textEdit, SLOT(selectAll()), ac ); + + // + // View Actions + // + (void) KStdAction::zoomIn( m_textEdit, SLOT(zoomIn()), ac ); + (void) KStdAction::zoomOut( m_textEdit, SLOT(zoomOut()), ac ); + + // + // Character Formatting + // + m_actionBold = new KToggleAction( i18n("&Bold"), "text_bold", CTRL+Key_B, + ac, "format_bold" ); + connect( m_actionBold, SIGNAL(toggled(bool)), + m_textEdit, SLOT(setBold(bool)) ); + + m_actionItalic = new KToggleAction( i18n("&Italic"), "text_italic", CTRL+Key_I, + ac, "format_italic" ); + + connect( m_actionItalic, SIGNAL(toggled(bool)), + m_textEdit, SLOT(setItalic(bool) )); + + m_actionUnderline = new KToggleAction( i18n("&Underline"), "text_under", CTRL+Key_U, + ac, "format_underline" ); + + connect( m_actionUnderline, SIGNAL(toggled(bool)), + m_textEdit, SLOT(setUnderline(bool)) ); + + (void) new KAction( i18n("Text &Color..."), "colorpicker", 0, + this, SLOT(formatColor()), + ac, "format_color" ); + + // + // Font + // + m_actionFont = new KFontAction( i18n("&Font"), 0, + ac, "format_font" ); + connect( m_actionFont, SIGNAL(activated(const QString &)), + m_textEdit, SLOT(setFamily(const QString &)) ); + + + m_actionFontSize = new KFontSizeAction( i18n("Font &Size"), 0, + ac, "format_font_size" ); + connect( m_actionFontSize, SIGNAL(fontSizeChanged(int)), + m_textEdit, SLOT(setPointSize(int)) ); + + // + // Alignment + // + m_actionAlignLeft = new KToggleAction( i18n("Align &Left"), "text_left", 0, + ac, "format_align_left" ); + connect( m_actionAlignLeft, SIGNAL(toggled(bool)), + this, SLOT(setAlignLeft(bool)) ); + + m_actionAlignCenter = new KToggleAction( i18n("Align &Center"), "text_center", 0, + ac, "format_align_center" ); + connect( m_actionAlignCenter, SIGNAL(toggled(bool)), + this, SLOT(setAlignCenter(bool)) ); + + m_actionAlignRight = new KToggleAction( i18n("Align &Right"), "text_right", 0, + ac, "format_align_right" ); + connect( m_actionAlignRight, SIGNAL(toggled(bool)), + this, SLOT(setAlignRight(bool)) ); + + m_actionAlignJustify = new KToggleAction( i18n("&Justify"), "text_block", 0, + ac, "format_align_justify" ); + connect( m_actionAlignJustify, SIGNAL(toggled(bool)), + this, SLOT(setAlignJustify(bool)) ); + + m_actionAlignLeft->setExclusiveGroup( "alignment" ); + m_actionAlignCenter->setExclusiveGroup( "alignment" ); + m_actionAlignRight->setExclusiveGroup( "alignment" ); + m_actionAlignJustify->setExclusiveGroup( "alignment" ); + + // + // Tools + // + (void) KStdAction::spelling( this, SLOT(checkSpelling()), ac ); + + // + // Setup enable/disable + // + updateActions(); + + connect( m_textEdit, SIGNAL(currentFontChanged(const QFont &)), + this, SLOT( updateFont() ) ); + connect( m_textEdit, SIGNAL(currentFontChanged(const QFont &)), + this, SLOT(updateCharFmt()) ); + connect( m_textEdit, SIGNAL(cursorPositionChanged(int, int)), + this, SLOT(updateAligment()) ); +} + +void +DefaultEditor::updateActions() +{ + updateCharFmt(); + updateAligment(); + updateFont(); +} + +void +DefaultEditor::updateCharFmt() +{ + m_actionBold->setChecked( m_textEdit->bold() ); + m_actionItalic->setChecked( m_textEdit->italic() ); + m_actionUnderline->setChecked( m_textEdit->underline() ); +} + +void +DefaultEditor::updateAligment() +{ + int align = m_textEdit->alignment(); + + switch ( align ) { + case AlignRight: + m_actionAlignRight->setChecked( true ); + break; + case AlignCenter: + m_actionAlignCenter->setChecked( true ); + break; + case AlignLeft: + m_actionAlignLeft->setChecked( true ); + break; + case AlignJustify: + m_actionAlignJustify->setChecked( true ); + break; + default: + break; + } +} + +void +DefaultEditor::updateFont() +{ + if ( m_textEdit->pointSize() > 0 ) + m_actionFontSize->setFontSize( m_textEdit->pointSize() ); + m_actionFont->setFont( m_textEdit->family() ); +} + +void +DefaultEditor::formatColor() +{ + QColor col; + + int s = KColorDialog::getColor( col, m_textEdit->color(), m_textEdit ); + if ( s != QDialog::Accepted ) + return; + + m_textEdit->setColor( col ); +} + +void +DefaultEditor::setAlignLeft( bool yes ) +{ + if ( yes ) + m_textEdit->setAlignment( AlignLeft ); +} + +void +DefaultEditor::setAlignRight( bool yes ) +{ + if ( yes ) + m_textEdit->setAlignment( AlignRight ); +} + +void +DefaultEditor::setAlignCenter( bool yes ) +{ + if ( yes ) + m_textEdit->setAlignment( AlignCenter ); +} + +void +DefaultEditor::setAlignJustify( bool yes ) +{ + if ( yes ) + m_textEdit->setAlignment( AlignJustify ); +} + +// +// Content Actions +// + +bool +DefaultEditor::open() +{ + KURL url = KFileDialog::getOpenURL(); + if ( url.isEmpty() ) + return false; + + //fixme + //return openURL( url ); + return true; +} + +bool +DefaultEditor::saveAs() +{ + KURL url = KFileDialog::getSaveURL(); + if ( url.isEmpty() ) + return false; + + //FIXME + //return KParts::ReadWritePart::saveAs( url ); + return true; +} + +void +DefaultEditor::checkSpelling() +{ + QString s; + if ( m_textEdit->hasSelectedText() ) + s = m_textEdit->selectedText(); + else + s = m_textEdit->text(); + + //KSpell::modalCheck( s ); +} + +bool +DefaultEditor::print() +{ + return true; +} + +#include "defaulteditor.moc" diff --git a/libkdepim/komposer/plugins/default/defaulteditor.desktop b/libkdepim/komposer/plugins/default/defaulteditor.desktop new file mode 100644 index 000000000..b0fd5a651 --- /dev/null +++ b/libkdepim/komposer/plugins/default/defaulteditor.desktop @@ -0,0 +1,111 @@ +[Desktop Entry] +Type=Service +Icon=editor +ServiceTypes=Komposer/Editor + +X-KDE-Library=libkomposer_defaulteditor +X-Komposer-Version=1 +X-Komposer-Weight=10 + +X-KDE-PluginInfo-Author=Zack Rusin +X-KDE-PluginInfo-Email=zack@kde.org +X-KDE-PluginInfo-Name=komposer_defaulteditor +X-KDE-PluginInfo-Version=0.0.1 +X-KDE-PluginInfo-Website=http://www.kde.org +X-KDE-PluginInfo-Category=Editors +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=LGPL +X-KDE-PluginInfo-EnabledByDefault=true +Name=Komposer Editor +Name[af]=Komposer Redigeerder +Name[bg]=Редактор за Komposer +Name[br]=Aozer Komposer +Name[ca]=Editor Komposer +Name[cs]=Komposer editor +Name[da]=Komposer-editor +Name[el]=Επεξεργαστής Komposer +Name[eo]=Komposer-redaktilo +Name[es]=Editor Komposer +Name[et]=Komposeri redaktor +Name[eu]=Komposer editorea +Name[fa]=ویرایشگر Komposer +Name[fi]=Komposer-muokkain +Name[fr]=Éditeur Komposer +Name[fy]=Komposer-bewurker +Name[ga]=Eagarthóir Komposer +Name[gl]=Editor Komposer +Name[hu]=Komposer szerkesztő +Name[is]=Komposer ritill +Name[it]=Editor Komposer +Name[ja]=Komposer エディタ +Name[ka]=Komposer რედაქტორი +Name[kk]=Komposer өңдегіші +Name[km]=កម្មវិធីនិពន្ធ Komposer +Name[lt]=Komposer redaktorius +Name[ms]=Editor Komposer +Name[nb]=Komposer-redigering +Name[ne]=कम्पोजर सम्पादक +Name[nl]=Komposer-editor +Name[nn]=Komposer-redigering +Name[pl]=Edytor Komposer +Name[pt]=Editor Kompositor +Name[pt_BR]=Editor do Komposer +Name[ru]=Редактор Komposer +Name[sk]=Editor Komposer +Name[sl]=Urejevalnik Komposer +Name[sr]=Уређивач Komposer-а +Name[sr@Latn]=Uređivač Komposer-a +Name[sv]=Komposer editor +Name[ta]=கம்போசர் தொகுப்பான் +Name[tr]=Komposer Düzenleyicisi +Name[uk]=Редактор Komposer +Name[zh_CN]=Komposer 编辑器 +Name[zh_TW]=Komposer 編輯器 +Comment=Komposer default editor +Comment[af]=Komposer standaard redigeerder +Comment[bg]=Подразбиращ се редактор за Komposer +Comment[ca]=Editor predeterminat de Komposer +Comment[cs]=Výchozí Komposer editor +Comment[da]=Komposer standardeditor +Comment[de]=Komposer Standardeditor +Comment[el]=Προεπιλεγμένος επεξεργαστής του Komposer +Comment[eo]=Komposer-redaktilo apriora +Comment[es]=Editor predefinido Komposer +Comment[et]=Komposeri vaikeredaktor +Comment[eu]=Komposer editore lehenetsia +Comment[fa]=ویرایشگر پیشفرض Komposer +Comment[fi]=Komposer oletusmuokkain +Comment[fr]=Éditeur Komposer par défaut +Comment[fy]=Komposer standertbewurker +Comment[ga]=Eagarthóir réamhshocraithe Komposer +Comment[gl]=Editor por defecto Komposer +Comment[he]=עורך ברירת מחדל של Kompoer +Comment[hu]=A Komposer alapértelmezett szerkesztője +Comment[is]=Sjálfgefinn ritill Komposer +Comment[it]=Editor di default per Komposer +Comment[ja]=Komposer 標準エディタ +Comment[ka]=Komposer ნაგულისხმევი რედაქტორი +Comment[kk]=Komposer әдетті өңдегіші +Comment[km]=កម្មវិធីនិពន្ធលំនាំដើមរបស់ Komposer +Comment[ko]=Komposer 기본 편집기 +Comment[lt]=Komposer numatytasis redaktorius +Comment[ms]=Pengedit piawai Komposer +Comment[nb]=Komposer standard-redigerer +Comment[nds]=Komposer-Standardeditor +Comment[ne]=कम्पोजरको पूर्वनिर्धारित सम्पादक +Comment[nl]=Komposer standaardeditor +Comment[nn]=Komposer standard-redigeringsprogram +Comment[pl]=Domyślny edytor Komposera +Comment[pt]=Editor predefinido Kompositor +Comment[pt_BR]=Editor padrão do Komposer +Comment[ru]=Редактор Komposer по умолчанию +Comment[sk]=Štandardný editor Komposer +Comment[sl]=Privzeti urejevalnik Komposer +Comment[sr]=Подразумевани Komposer-ов уређивач +Comment[sr@Latn]=Podrazumevani Komposer-ov uređivač +Comment[sv]=Komposer standardeditor +Comment[ta]=கம்போசர் முன்னிருப்பு தொகுப்பான் +Comment[tr]=Öntanımlı Komposer düzenleyicisi +Comment[uk]=Типовий редактор Komposer +Comment[zh_CN]=Komposer 默认编辑器 +Comment[zh_TW]=Komposer 預設編輯器 diff --git a/libkdepim/komposer/plugins/default/defaulteditor.h b/libkdepim/komposer/plugins/default/defaulteditor.h new file mode 100644 index 000000000..18f47d147 --- /dev/null +++ b/libkdepim/komposer/plugins/default/defaulteditor.h @@ -0,0 +1,117 @@ +/* + * defaulteditor.h + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef DEFAULTEDITOR_H +#define DEFAULTEDITOR_H + +#include "editor.h" + +class QTextEdit; +class KFontAction; +class KFontSizeAction; +class KToggleAction; +class KActionCollection; + + +class DefaultEditor : public Komposer::Editor +{ + Q_OBJECT +public: + DefaultEditor( QObject *parent, const char *name, const QStringList &args ); + ~DefaultEditor(); + + virtual QWidget *widget(); + virtual QString text() const; +public slots: + virtual void setText( const QString &txt ); + virtual void changeSignature( const QString &txt ); + + /** + * Displays a file dialog and loads the selected file. + */ + bool open(); + + /** + * Displays a file dialog and saves to the selected file. + */ + bool saveAs(); + + /** + * Prints the current document + */ + bool print(); + + /** + * Displays a color dialog and sets the text color to the selected value. + */ + void formatColor(); + + void checkSpelling(); + + /** + * @internal + */ + void setAlignLeft( bool yes ); + + /** + * @internal + */ + void setAlignRight( bool yes ); + + /** + * @internal + */ + void setAlignCenter( bool yes ); + + /** + * @internal + */ + void setAlignJustify( bool yes ); + +protected slots: + /** + * Creates the part's actions in the part's action collection. + */ + void createActions( KActionCollection *ac ); + + void updateActions(); + + void updateFont(); + void updateCharFmt(); + void updateAligment(); + +private: + QTextEdit *m_textEdit; + + KToggleAction *m_actionBold; + KToggleAction *m_actionItalic; + KToggleAction *m_actionUnderline; + + KFontAction *m_actionFont; + KFontSizeAction *m_actionFontSize; + + KToggleAction *m_actionAlignLeft; + KToggleAction *m_actionAlignRight; + KToggleAction *m_actionAlignCenter; + KToggleAction *m_actionAlignJustify; +}; + +#endif diff --git a/libkdepim/komposer/plugins/default/defaulteditorui.rc b/libkdepim/komposer/plugins/default/defaulteditorui.rc new file mode 100644 index 000000000..479fa8b06 --- /dev/null +++ b/libkdepim/komposer/plugins/default/defaulteditorui.rc @@ -0,0 +1,90 @@ +<!DOCTYPE kpartgui> +<kpartgui name="defaulteditor" version="3"> +<MenuBar> + <Menu name="edit"><text>&Edit</text> + <Action name="edit_undo"/> + <Action name="edit_redo"/> + <Separator/> + <Action name="edit_cut" append="edit_paste_merge"/> + <Action name="edit_copy" append="edit_paste_merge"/> + <Action name="edit_paste" append="edit_paste_merge"/> + <Action name="edit_clear" append="edit_paste_merge"/> + <Separator/> + <Action name="edit_select_all" append="edit_select_merge"/> + </Menu> + <Menu name="view"><text>&View</text> + <Action name="view_zoom_in" /> + <Action name="view_zoom_out" /> + <DefineGroup name="view_zoom_group" /> + </Menu> + <Menu name="format"><text>F&ormat</text> + <Action name="format_bold"/> + <Action name="format_italic"/> + <Action name="format_underline"/> + <Action name="format_color"/> + <DefineGroup name="format_chars_group" /> + <Separator/> + <Menu name="alignment"><text>&Alignment</text> + <Action name="format_align_left"/> + <Action name="format_align_center"/> + <Action name="format_align_right"/> + <Action name="format_align_justify"/> + <DefineGroup name="format_align_group" /> + </Menu> + <Separator/> + <Action name="format_font"/> + <Action name="format_font_size"/> + <DefineGroup name="format_font_group" /> + </Menu> + <Menu name="tools"><text>&Tools</text> + <Action name="tools_spelling"/> + </Menu> + <Merge /> + <Menu name="help"><text>&Help</text> + </Menu> +</MenuBar> +<ToolBar name="mainToolBar"><text>Editor Toolbar</text> + <Separator lineSeparator="true"/> + <Action name="edit_undo"/> + <Action name="edit_redo"/> + <Separator lineSeparator="true"/> + <Action name="edit_cut"/> + <Action name="edit_copy"/> + <Action name="edit_paste"/> + <Separator lineSeparator="true"/> + <Action name="view_zoom_in" /> + <Action name="view_zoom_out" /> +</ToolBar> +<ToolBar name="formatToolBar"><text>Format Toolbar</text> + <Action name="format_bold"/> + <Action name="format_italic"/> + <Action name="format_underline"/> + <Action name="format_color"/> + <DefineGroup name="format_chars_group" /> + <Separator lineSeparator="true"/> + <Action name="format_font"/> + <Action name="format_font_size"/> + <DefineGroup name="format_font_group" /> + <Separator lineSeparator="true"/> + <Action name="format_align_left"/> + <Action name="format_align_center"/> + <Action name="format_align_right"/> + <Action name="format_align_justify"/> + <DefineGroup name="format_align_group" /> +</ToolBar> + +<Menu name="editor_popup"> + <Action name="edit_undo"/> + <Action name="edit_redo"/> + <Separator/> + <Action name="edit_cut"/> + <Action name="edit_copy"/> + <Action name="edit_paste"/> + <Action name="edit_clear"/> + <Separator/> + <Action name="edit_select_all"/> +</Menu> + +</kpartgui> + + |