21 #include "defaulteditor.h"
24 #include <kgenericfactory.h>
25 #include <tdeapplication.h>
26 #include <tdeaction.h>
27 #include <kiconloader.h>
30 #include <tdeaction.h>
31 #include <kcolordialog.h>
32 #include <tdefiledialog.h>
33 #include <kinstance.h>
34 #include <tdelocale.h>
35 #include <kstdaction.h>
37 #include <kfinddialog.h>
39 #include <kreplacedialog.h>
42 #include <tqtextedit.h>
45 typedef KGenericFactory<DefaultEditor> DefaultEditorFactory;
46 K_EXPORT_COMPONENT_FACTORY( libkomposer_defaulteditor,
47 DefaultEditorFactory(
"komposer_defaulteditor" ) )
49 DefaultEditor::DefaultEditor( TQObject *parent, const
char *name, const TQStringList &args )
50 : Editor( parent, name, args ), m_textEdit( 0 )
52 setInstance( DefaultEditorFactory::instance() );
54 m_textEdit =
new TQTextEdit( 0 );
56 createActions( actionCollection() );
58 setXMLFile(
"defaulteditorui.rc" );
61 DefaultEditor::~DefaultEditor()
67 DefaultEditor::widget()
73 DefaultEditor::text()
const
75 return m_textEdit->text();
79 DefaultEditor::setText(
const TQString &text )
81 m_textEdit->setText( text );
85 DefaultEditor::changeSignature(
const TQString &sig )
87 TQString text = m_textEdit->text();
89 int sigStart = text.findRev(
"-- " );
90 TQString sigText = TQString(
"-- \n%1" ).arg( sig );
92 text.replace( sigStart, text.length(), sigText );
96 DefaultEditor::createActions( TDEActionCollection *ac )
101 (void) KStdAction::open(
this, TQ_SLOT(open()), ac );
102 (void) KStdAction::openRecent(
this, TQ_SLOT(openURL(
const KURL &)), ac );
103 (void) KStdAction::save(
this, TQ_SLOT(save()), ac );
104 (void) KStdAction::saveAs(
this, TQ_SLOT(saveAs()), ac );
109 TDEAction *actionUndo = KStdAction::undo( m_textEdit, TQ_SLOT(undo()), ac );
110 actionUndo->setEnabled(
false );
111 connect( m_textEdit, TQ_SIGNAL(undoAvailable(
bool)),
112 actionUndo, TQ_SLOT(setEnabled(
bool)) );
114 TDEAction *actionRedo = KStdAction::redo( m_textEdit, TQ_SLOT(redo()), ac );
115 actionRedo->setEnabled(
false );
116 connect( m_textEdit, TQ_SIGNAL(redoAvailable(
bool)),
117 actionRedo, TQ_SLOT(setEnabled(
bool)) );
119 TDEAction *action_cut = KStdAction::cut( m_textEdit, TQ_SLOT(cut()), ac );
120 action_cut->setEnabled(
false );
121 connect( m_textEdit, TQ_SIGNAL(copyAvailable(
bool)),
122 action_cut, TQ_SLOT(setEnabled(
bool)) );
124 TDEAction *action_copy = KStdAction::copy( m_textEdit, TQ_SLOT(copy()), ac );
125 action_copy->setEnabled(
false );
126 connect( m_textEdit, TQ_SIGNAL(copyAvailable(
bool)),
127 action_copy, TQ_SLOT(setEnabled(
bool)) );
129 (void) KStdAction::print(
this, TQ_SLOT(print()), ac );
131 (void) KStdAction::paste( m_textEdit, TQ_SLOT(paste()), ac );
132 (void)
new TDEAction( i18n(
"C&lear" ), 0,
133 m_textEdit, TQ_SLOT(removeSelectedText()),
136 (void) KStdAction::selectAll( m_textEdit, TQ_SLOT(selectAll()), ac );
141 (void) KStdAction::zoomIn( m_textEdit, TQ_SLOT(zoomIn()), ac );
142 (void) KStdAction::zoomOut( m_textEdit, TQ_SLOT(zoomOut()), ac );
147 m_actionBold =
new TDEToggleAction( i18n(
"&Bold"),
"format-text-bold", CTRL+Key_B,
149 connect( m_actionBold, TQ_SIGNAL(toggled(
bool)),
150 m_textEdit, TQ_SLOT(setBold(
bool)) );
152 m_actionItalic =
new TDEToggleAction( i18n(
"&Italic"),
"format-text-italic", CTRL+Key_I,
153 ac,
"format_italic" );
155 connect( m_actionItalic, TQ_SIGNAL(toggled(
bool)),
156 m_textEdit, TQ_SLOT(setItalic(
bool) ));
158 m_actionUnderline =
new TDEToggleAction( i18n(
"&Underline"),
"format-text-underline", CTRL+Key_U,
159 ac,
"format_underline" );
161 connect( m_actionUnderline, TQ_SIGNAL(toggled(
bool)),
162 m_textEdit, TQ_SLOT(setUnderline(
bool)) );
164 (void)
new TDEAction( i18n(
"Text &Color..."),
"colorpicker", 0,
165 this, TQ_SLOT(formatColor()),
166 ac,
"format_color" );
171 m_actionFont =
new TDEFontAction( i18n(
"&Font"), 0,
173 connect( m_actionFont, TQ_SIGNAL(activated(
const TQString &)),
174 m_textEdit, TQ_SLOT(setFamily(
const TQString &)) );
177 m_actionFontSize =
new TDEFontSizeAction( i18n(
"Font &Size"), 0,
178 ac,
"format_font_size" );
179 connect( m_actionFontSize, TQ_SIGNAL(fontSizeChanged(
int)),
180 m_textEdit, TQ_SLOT(setPointSize(
int)) );
185 m_actionAlignLeft =
new TDEToggleAction( i18n(
"Align &Left"),
"format-text-direction-ltr", 0,
186 ac,
"format_align_left" );
187 connect( m_actionAlignLeft, TQ_SIGNAL(toggled(
bool)),
188 this, TQ_SLOT(setAlignLeft(
bool)) );
190 m_actionAlignCenter =
new TDEToggleAction( i18n(
"Align &Center"),
"text_center", 0,
191 ac,
"format_align_center" );
192 connect( m_actionAlignCenter, TQ_SIGNAL(toggled(
bool)),
193 this, TQ_SLOT(setAlignCenter(
bool)) );
195 m_actionAlignRight =
new TDEToggleAction( i18n(
"Align &Right"),
"format-text-direction-rtl", 0,
196 ac,
"format_align_right" );
197 connect( m_actionAlignRight, TQ_SIGNAL(toggled(
bool)),
198 this, TQ_SLOT(setAlignRight(
bool)) );
200 m_actionAlignJustify =
new TDEToggleAction( i18n(
"&Justify"),
"text_block", 0,
201 ac,
"format_align_justify" );
202 connect( m_actionAlignJustify, TQ_SIGNAL(toggled(
bool)),
203 this, TQ_SLOT(setAlignJustify(
bool)) );
205 m_actionAlignLeft->setExclusiveGroup(
"alignment" );
206 m_actionAlignCenter->setExclusiveGroup(
"alignment" );
207 m_actionAlignRight->setExclusiveGroup(
"alignment" );
208 m_actionAlignJustify->setExclusiveGroup(
"alignment" );
213 (void) KStdAction::spelling(
this, TQ_SLOT(checkSpelling()), ac );
220 connect( m_textEdit, TQ_SIGNAL(currentFontChanged(
const TQFont &)),
221 this, TQ_SLOT( updateFont() ) );
222 connect( m_textEdit, TQ_SIGNAL(currentFontChanged(
const TQFont &)),
223 this, TQ_SLOT(updateCharFmt()) );
224 connect( m_textEdit, TQ_SIGNAL(cursorPositionChanged(
int,
int)),
225 this, TQ_SLOT(updateAligment()) );
229 DefaultEditor::updateActions()
237 DefaultEditor::updateCharFmt()
239 m_actionBold->setChecked( m_textEdit->bold() );
240 m_actionItalic->setChecked( m_textEdit->italic() );
241 m_actionUnderline->setChecked( m_textEdit->underline() );
245 DefaultEditor::updateAligment()
247 int align = m_textEdit->alignment();
251 m_actionAlignRight->setChecked(
true );
254 m_actionAlignCenter->setChecked(
true );
257 m_actionAlignLeft->setChecked(
true );
260 m_actionAlignJustify->setChecked(
true );
268 DefaultEditor::updateFont()
270 if ( m_textEdit->pointSize() > 0 )
271 m_actionFontSize->setFontSize( m_textEdit->pointSize() );
272 m_actionFont->setFont( m_textEdit->family() );
276 DefaultEditor::formatColor()
280 int s = KColorDialog::getColor( col, m_textEdit->color(), m_textEdit );
281 if ( s != TQDialog::Accepted )
284 m_textEdit->setColor( col );
288 DefaultEditor::setAlignLeft(
bool yes )
291 m_textEdit->setAlignment( AlignLeft );
295 DefaultEditor::setAlignRight(
bool yes )
298 m_textEdit->setAlignment( AlignRight );
302 DefaultEditor::setAlignCenter(
bool yes )
305 m_textEdit->setAlignment( AlignCenter );
309 DefaultEditor::setAlignJustify(
bool yes )
312 m_textEdit->setAlignment( AlignJustify );
320 DefaultEditor::open()
322 KURL url = KFileDialog::getOpenURL();
332 DefaultEditor::saveAs()
334 KURL url = KFileDialog::getSaveURL();
344 DefaultEditor::checkSpelling()
347 if ( m_textEdit->hasSelectedText() )
348 s = m_textEdit->selectedText();
350 s = m_textEdit->text();
356 DefaultEditor::print()
361 #include "defaulteditor.moc"