/*************************************************************************** multilineeditdlg.cpp - description ------------------- begin : Sam Jan 11 2003 copyright : (C) 2003 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "multilineeditdlg.h" #include "tokendialog.h" // KDE includes #include #include #include #include #include #include #include #include #include // TQt includes #include #include MultiLineEditor::MultiLineEditor( TokenProvider* token, TQWidget *parent, const char *name ) : TQWidget( parent, name ), m_token( token ) { TQVBoxLayout* tqlayout = new TQVBoxLayout( this, 6, 6 ); // ksc = new KSpellConfig( this ); editor = new DSTextEdit( this ); editor->setTextFormat( TQt::RichText ); //editor->setText( text, "" ); editor->setFocus(); TQDockArea* area = new TQDockArea( Qt::Horizontal, TQDockArea::Normal, this ); toolBar = new KToolBar( area ); tool2Bar = new KToolBar( area ); tool3Bar = new KToolBar( area ); setupActions(); tqlayout->addWidget( area ); tqlayout->addWidget( editor ); } MultiLineEditor::~MultiLineEditor() { } void MultiLineEditor::setupActions() { ac = new KActionCollection( this ); KAction* action_export = new KAction( i18n("Export"), "fileexport", 0, TQT_TQOBJECT(this), TQT_SLOT( save() ), ac ); // // Edit Actions // KAction *action_undo = KStdAction::undo( TQT_TQOBJECT(editor), TQT_SLOT( undo() ), ac ); action_undo->setEnabled( false ); connect( editor, TQT_SIGNAL( undoAvailable(bool) ), action_undo, TQT_SLOT( setEnabled(bool) ) ); KAction *action_redo = KStdAction::redo( TQT_TQOBJECT(editor), TQT_SLOT( redo() ), ac ); action_redo->setEnabled( false ); connect( editor, TQT_SIGNAL( redoAvailable(bool) ), action_redo, TQT_SLOT( setEnabled(bool) ) ); KAction *action_cut = KStdAction::cut( TQT_TQOBJECT(editor), TQT_SLOT( cut() ), ac ); action_cut->setEnabled( false ); connect( editor, TQT_SIGNAL( copyAvailable(bool) ), action_cut, TQT_SLOT( setEnabled(bool) ) ); KAction *action_copy = KStdAction::copy( TQT_TQOBJECT(editor), TQT_SLOT( copy() ), ac ); action_copy->setEnabled( false ); connect( editor, TQT_SIGNAL( copyAvailable(bool) ), action_copy, TQT_SLOT( setEnabled(bool) ) ); KAction* action_paste = KStdAction::paste( TQT_TQOBJECT(editor), TQT_SLOT( paste() ), ac ); // // Character Formatting // action_bold = new KToggleAction( i18n("&Bold"), "text_bold", CTRL+Key_B, ac, "format_bold" ); connect( action_bold, TQT_SIGNAL( toggled(bool) ), editor, TQT_SLOT( setBold(bool) ) ); action_italic = new KToggleAction( i18n("&Italic"), "text_italic", CTRL+Key_I, ac, "format_italic" ); connect( action_italic, TQT_SIGNAL( toggled(bool) ), editor, TQT_SLOT( setItalic(bool) ) ); action_underline = new KToggleAction( i18n("&Underline"), "text_under", CTRL+Key_U, ac, "format_underline" ); connect( action_underline, TQT_SIGNAL( toggled(bool) ), editor, TQT_SLOT( setUnderline(bool) ) ); KAction* action_color = new KAction( i18n("Text &Color..."), "colorpicker", 0, TQT_TQOBJECT(this), TQT_SLOT( formatColor() ), ac, "format_color" ); // // Font // action_font = new KFontAction( i18n("&Font"), 0, ac, "format_font" ); connect( action_font, TQT_SIGNAL( activated( const TQString & ) ), editor, TQT_SLOT( setFamily( const TQString & ) ) ); action_font_size = new KFontSizeAction( i18n("Font &Size"), 0, ac, "format_font_size" ); connect( action_font_size, TQT_SIGNAL( fontSizeChanged(int) ), editor, TQT_SLOT( setPointSize(int) ) ); // // Alignment // action_align_left = new KToggleAction( i18n("Align &Left"), "text_left", 0, ac, "format_align_left" ); connect( action_align_left, TQT_SIGNAL( toggled(bool) ), TQT_TQOBJECT(this), TQT_SLOT( setAlignLeft(bool) ) ); action_align_center = new KToggleAction( i18n("Align &Center"), "text_center", 0, ac, "format_align_center" ); connect( action_align_center, TQT_SIGNAL( toggled(bool) ), TQT_TQOBJECT(this), TQT_SLOT( setAlignCenter(bool) ) ); action_align_right = new KToggleAction( i18n("Align &Right"), "text_right", 0, ac, "format_align_right" ); connect( action_align_right, TQT_SIGNAL( toggled(bool) ), TQT_TQOBJECT(this), TQT_SLOT( setAlignRight(bool) ) ); action_align_justify = new KToggleAction( i18n("&Justify"), "text_block", 0, ac, "format_align_justify" ); connect( action_align_justify, TQT_SIGNAL( toggled(bool) ), TQT_TQOBJECT(this), TQT_SLOT( setAlignJustify(bool) ) ); action_align_left->setExclusiveGroup( "tqalignment" ); action_align_center->setExclusiveGroup( "tqalignment" ); action_align_right->setExclusiveGroup( "tqalignment" ); action_align_justify->setExclusiveGroup( "tqalignment" ); //KAction* action_spell = KStdAction::spelling( this, TQT_SLOT( checkSpelling() ), ac ); KAction* textDataAct = new KAction( i18n("Insert &Data Field"), "contents", 0, TQT_TQOBJECT(this), TQT_SLOT( insertNewField() ), ac, "text_data_act"); action_export->plug( toolBar ); toolBar->insertSeparator(); action_undo->plug( toolBar ); action_redo->plug( toolBar ); toolBar->insertSeparator(); action_cut->plug( toolBar ); action_copy->plug( toolBar ); action_paste->plug( toolBar ); toolBar->insertSeparator(); action_bold->plug( toolBar ); action_italic->plug( toolBar ); action_underline->plug( toolBar ); toolBar->insertSeparator(); //#if KDE_IS_VERSION( 3, 1, 90 ) // action_spell->plug( toolBar ); //#endif action_font->plug( tool2Bar ); action_font_size->plug( tool2Bar ); action_color->plug( tool2Bar ); tool2Bar->insertSeparator(); action_align_left->plug( tool2Bar ); action_align_center->plug( tool2Bar ); action_align_right->plug( tool2Bar ); action_align_justify->plug( tool2Bar ); textDataAct->plug( tool3Bar ); // // Setup enable/disable // updateActions(); connect( editor, TQT_SIGNAL( currentFontChanged( const TQFont & ) ), TQT_TQOBJECT(this), TQT_SLOT( updateFont() ) ); connect( editor, TQT_SIGNAL( currentFontChanged( const TQFont & ) ), TQT_TQOBJECT(this), TQT_SLOT( updateCharFmt() ) ); connect( editor, TQT_SIGNAL( cursorPositionChanged( int,int ) ), TQT_TQOBJECT(this), TQT_SLOT( updateAligment() ) ); } TQString MultiLineEditor::text() { return editor->text(); } void MultiLineEditor::setText( const TQString & t ) { editor->setText( t ); } void MultiLineEditor::updateCharFmt() { action_bold->setChecked( editor->bold() ); action_italic->setChecked( editor->italic() ); action_underline->setChecked( editor->underline() ); } void MultiLineEditor::updateAligment() { int align = editor->tqalignment(); switch ( align ) { case AlignRight: action_align_right->setChecked( true ); break; case AlignCenter: action_align_center->setChecked( true ); break; case AlignLeft: action_align_left->setChecked( true ); break; case AlignJustify: action_align_justify->setChecked( true ); break; default: break; } } void MultiLineEditor::updateFont() { if ( editor->pointSize() > 0 ) action_font_size->setFontSize( editor->pointSize() ); action_font->setFont( editor->family() ); } void MultiLineEditor::updateActions() { updateCharFmt(); updateAligment(); updateFont(); } void MultiLineEditor::formatColor() { TQColor col; int s = KColorDialog::getColor( col, editor->color(), editor ); if ( s != TQDialog::Accepted ) return; editor->setColor( col ); } void MultiLineEditor::setAlignLeft( bool yes ) { if ( yes ) editor->tqsetAlignment( AlignLeft ); } void MultiLineEditor::setAlignRight( bool yes ) { if ( yes ) editor->tqsetAlignment( AlignRight ); } void MultiLineEditor::setAlignCenter( bool yes ) { if ( yes ) editor->tqsetAlignment( AlignCenter ); } void MultiLineEditor::setAlignJustify( bool yes ) { if ( yes ) editor->tqsetAlignment( AlignJustify ); } void MultiLineEditor::insertNewField() { TokenDialog dlg( m_token, this, "dlg" ); if( dlg.exec() == TQDialog::Accepted ) editor->insert( dlg.token() ); } void MultiLineEditor::checkSpelling() { /* #if KDE_IS_VERSION( 3, 1, 90 ) TQString s; if ( editor->hasSelectedText() ) s = editor->selectedText(); else s = editor->text(); spell = new KSpell( this, i18n("Spell Checking"), 0, 0, 0, true, true, KSpell::HTML ); spell->setAutoDelete( true ); spell->check( s, true ); connect( spell, TQT_SIGNAL( done(const TQString &) ), TQT_TQOBJECT(this), TQT_SLOT( spellCheckDone(const TQString &) ) ); spell->cleanUp(); #endif */ } void MultiLineEditor::spellCheckDone(const TQString & buffer) { editor->setText( buffer ); spell->cleanUp(); } void MultiLineEditor::save() { TQString name = KFileDialog::getSaveFileName ( NULL, "*", this ); if( name.isEmpty() ) return; TQFile file( name ); if ( file.open( IO_WriteOnly ) ) { TQTextStream ts( &file ); ts << editor->text(); } } #include "multilineeditdlg.moc"