diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kexi/formeditor/richtextdialog.cpp | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kexi/formeditor/richtextdialog.cpp')
-rw-r--r-- | kexi/formeditor/richtextdialog.cpp | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/kexi/formeditor/richtextdialog.cpp b/kexi/formeditor/richtextdialog.cpp new file mode 100644 index 00000000..f4596ed5 --- /dev/null +++ b/kexi/formeditor/richtextdialog.cpp @@ -0,0 +1,210 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Cedric Pasteur <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ +#include <qlayout.h> + +#include <ktoolbar.h> +#include <kfontcombo.h> +#include <kcolorcombo.h> +#include <ktoolbarradiogroup.h> +#include <kdebug.h> +#include <klocale.h> + +#include "richtextdialog.h" + +namespace KFormDesigner { + +////////////////////////////////////////////////////////////////////////////////// +//////////////// A simple dialog to edit rich text //////////////////////////// +////////////////////////////////////////////////////////////////////////////////// + +RichTextDialog::RichTextDialog(QWidget *parent, const QString &text) +: KDialogBase(parent, "richtext_dialog", true, i18n("Edit Rich Text"), Ok|Cancel, Ok, false) +{ + QFrame *frame = makeMainWidget(); + QVBoxLayout *l = new QVBoxLayout(frame); + l->setAutoAdd(true); + + m_toolbar = new KToolBar(frame); + m_toolbar->setFlat(true); + m_toolbar->show(); + + m_fcombo = new KFontCombo(m_toolbar); + m_toolbar->insertWidget(TBFont, 40, m_fcombo); + connect(m_fcombo, SIGNAL(textChanged(const QString&)), this, SLOT(changeFont(const QString &))); + + m_toolbar->insertSeparator(); + + m_colCombo = new KColorCombo(m_toolbar); + m_toolbar->insertWidget(TBColor, 30, m_colCombo); + connect(m_colCombo, SIGNAL(activated(const QColor&)), this, SLOT(changeColor(const QColor&))); + + m_toolbar->insertButton("text_bold", TBBold, true, i18n("Bold")); + m_toolbar->insertButton("text_italic", TBItalic, true, i18n("Italic")); + m_toolbar->insertButton("text_under", TBUnder, true, i18n("Underline")); + m_toolbar->setToggle(TBBold, true); + m_toolbar->setToggle(TBItalic, true); + m_toolbar->setToggle(TBUnder, true); + m_toolbar->insertSeparator(); + + m_toolbar->insertButton("text_super", TBSuper, true, i18n("Superscript")); + m_toolbar->insertButton("text_sub", TBSub, true, i18n("Subscript")); + m_toolbar->setToggle(TBSuper, true); + m_toolbar->setToggle(TBSub, true); + m_toolbar->insertSeparator(); + + KToolBarRadioGroup *group = new KToolBarRadioGroup(m_toolbar); + m_toolbar->insertButton("text_left", TBLeft, true, i18n("Left Align")); + m_toolbar->setToggle(TBLeft, true); + group->addButton(TBLeft); + m_toolbar->insertButton("text_center", TBCenter, true, i18n("Centered")); + m_toolbar->setToggle(TBCenter, true); + group->addButton(TBCenter); + m_toolbar->insertButton("text_right", TBRight, true, i18n("Right Align")); + m_toolbar->setToggle(TBRight, true); + group->addButton(TBRight); + m_toolbar->insertButton("text_block", TBJustify, true, i18n("Justified")); + m_toolbar->setToggle(TBJustify, true); + group->addButton(TBJustify); + + connect(m_toolbar, SIGNAL(toggled(int)), this, SLOT(buttonToggled(int))); + + m_edit = new KTextEdit(text, QString::null, frame, "richtext_edit"); + m_edit->setTextFormat(RichText); + m_edit->setFocus(); + + connect(m_edit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(cursorPositionChanged(int, int))); + connect(m_edit, SIGNAL(clicked(int, int)), this, SLOT(cursorPositionChanged(int, int))); + connect(m_edit, SIGNAL(currentVerticalAlignmentChanged(VerticalAlignment)), this, SLOT(slotVerticalAlignmentChanged(VerticalAlignment))); + + m_edit->moveCursor(QTextEdit::MoveEnd, false); + cursorPositionChanged(0, 0); + m_edit->show(); + frame->show(); +} + +QString +RichTextDialog::text() +{ + return m_edit->text(); +} + +void +RichTextDialog::changeFont(const QString &font) +{ + m_edit->setFamily(font); +} + +void +RichTextDialog::changeColor(const QColor &color) +{ + m_edit->setColor(color); +} + +void +RichTextDialog::buttonToggled(int id) +{ + bool isOn = m_toolbar->isButtonOn(id); + + switch(id) + { + case TBBold: m_edit->setBold(isOn); break; + case TBItalic: m_edit->setItalic(isOn); break; + case TBUnder: m_edit->setUnderline(isOn); break; + case TBSuper: + { + if(isOn && m_toolbar->isButtonOn(TBSub)) + m_toolbar->setButton(TBSub, false); + m_edit->setVerticalAlignment(isOn ? QTextEdit::AlignSuperScript : QTextEdit::AlignNormal); + break; + } + case TBSub: + { + if(isOn && m_toolbar->isButtonOn(TBSuper)) + m_toolbar->setButton(TBSuper, false); + m_edit->setVerticalAlignment(isOn ? QTextEdit::AlignSubScript : QTextEdit::AlignNormal); + break; + } + case TBLeft: case TBCenter: + case TBRight: case TBJustify: + { + if(!isOn) break; + switch(id) + { + case TBLeft: m_edit->setAlignment(Qt::AlignLeft); break; + case TBCenter: m_edit->setAlignment(Qt::AlignCenter); break; + case TBRight: m_edit->setAlignment(Qt::AlignRight); break; + case TBJustify: m_edit->setAlignment(Qt::AlignJustify); break; + default: break; + } + } + default: break; + } + +} + +void +RichTextDialog::cursorPositionChanged(int, int) +{ + m_fcombo->setCurrentFont(m_edit->currentFont().family()); + m_colCombo->setColor(m_edit->color()); + m_toolbar->setButton(TBBold, m_edit->bold()); + m_toolbar->setButton(TBItalic, m_edit->italic()); + m_toolbar->setButton(TBUnder, m_edit->underline()); + + int id = 0; + switch(m_edit->alignment()) + { + case Qt::AlignLeft: id = TBLeft; break; + case Qt::AlignCenter: id = TBCenter; break; + case Qt::AlignRight: id = TBRight; break; + case Qt::AlignJustify: id = TBJustify; break; + default: id = TBLeft; break; + } + m_toolbar->setButton(id, true); +} + +void +RichTextDialog::slotVerticalAlignmentChanged(VerticalAlignment align) +{ + switch(align) + { + case QTextEdit::AlignSuperScript: + { + m_toolbar->setButton(TBSuper, true); + m_toolbar->setButton(TBSub, false); + break; + } + case QTextEdit::AlignSubScript: + { + m_toolbar->setButton(TBSub, true); + m_toolbar->setButton(TBSuper, false); + break; + } + default: + { + m_toolbar->setButton(TBSuper, false); + m_toolbar->setButton(TBSub, false); + } + } +} + + +} + +#include "richtextdialog.moc" |