summaryrefslogtreecommitdiffstats
path: root/lib/koproperty/editors/fontedit.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/koproperty/editors/fontedit.cpp
downloadkoffice-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 'lib/koproperty/editors/fontedit.cpp')
-rw-r--r--lib/koproperty/editors/fontedit.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/lib/koproperty/editors/fontedit.cpp b/lib/koproperty/editors/fontedit.cpp
new file mode 100644
index 00000000..9d0101fa
--- /dev/null
+++ b/lib/koproperty/editors/fontedit.cpp
@@ -0,0 +1,156 @@
+/* This file is part of the KDE project
+ Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
+ Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
+ Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
+
+ 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 "fontedit.h"
+#include "editoritem.h"
+
+#include <qpushbutton.h>
+#include <qpainter.h>
+#include <qlayout.h>
+#include <qvariant.h>
+#include <qfont.h>
+#include <qfontmetrics.h>
+#include <qlabel.h>
+#include <qtooltip.h>
+
+#include <kdeversion.h>
+#include <kfontrequester.h>
+#include <kaccelmanager.h>
+#include <klocale.h>
+
+//! @internal
+//! reimplemented to better button and label's positioning
+
+namespace KoProperty {
+
+class FontEditRequester : public KFontRequester
+{
+ public:
+ FontEditRequester(QWidget* parent)
+ : KFontRequester(parent)
+ {
+ label()->setPaletteBackgroundColor(palette().active().base());
+ label()->setMinimumWidth(0);
+ label()->setFrameShape(QFrame::Box);
+ label()->setIndent(-1);
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
+ label()->setFocusPolicy(ClickFocus);
+ KAcceleratorManager::setNoAccel(label());
+#endif
+ layout()->remove(label());
+ layout()->remove(button());//->reparent(this, 0, QPoint(0,0));
+ delete layout();
+ button()->setText(i18n("..."));
+ QToolTip::add(button(), i18n("Change font"));
+ button()->setFocusPolicy(NoFocus);
+ button()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ QFontMetrics fm(button()->font());
+ button()->setFixedWidth(fm.width(button()->text()+' '));
+ }
+ virtual void resizeEvent(QResizeEvent *e)
+ {
+ KFontRequester::resizeEvent(e);
+ label()->move(0,0);
+ label()->resize(e->size()-QSize(button()->width(),-1));
+ button()->move(label()->width(),0);
+ button()->setFixedSize(button()->width(), height());
+ }
+};
+
+}
+
+using namespace KoProperty;
+
+FontEdit::FontEdit(Property *property, QWidget *parent, const char *name)
+ : Widget(property, parent, name)
+{
+ m_edit = new FontEditRequester(this);
+ m_edit->setMinimumHeight(5);
+ setEditor(m_edit);
+ setFocusWidget(m_edit->label());
+ connect(m_edit, SIGNAL(fontSelected(const QFont& )), this, SLOT(slotValueChanged(const QFont&)));
+}
+
+FontEdit::~FontEdit()
+{}
+
+QVariant
+FontEdit::value() const
+{
+ return m_edit->font();
+}
+
+static QString sampleText(const QVariant &value)
+{
+ QFontInfo fi(value.toFont());
+ return fi.family() + (fi.bold() ? " " + i18n("Bold") : QString()) +
+ (fi.italic() ? " " + i18n("Italic") : QString::null) +
+ " " + QString::number(fi.pointSize());
+}
+
+void
+FontEdit::setValue(const QVariant &value, bool emitChange)
+{
+ m_edit->blockSignals(true);
+ m_edit->setFont(value.toFont());
+ m_edit->blockSignals(false);
+ m_edit->setSampleText(sampleText(value));
+ if (emitChange)
+ emit valueChanged(this);
+}
+
+void
+FontEdit::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value)
+{
+ p->eraseRect(r);
+ p->setFont(value.toFont());
+ QRect r2(r);
+ r2.setLeft(r2.left()+KPROPEDITOR_ITEM_MARGIN);
+ r2.setBottom(r2.bottom()+1);
+ p->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, sampleText(value));
+}
+
+void
+FontEdit::slotValueChanged(const QFont &)
+{
+ emit valueChanged(this);
+}
+
+bool
+FontEdit::eventFilter(QObject* watched, QEvent* e)
+{
+ if(e->type() == QEvent::KeyPress) {
+ QKeyEvent* ev = static_cast<QKeyEvent*>(e);
+ if(ev->key() == Key_Space) {
+ m_edit->button()->animateClick();
+ return true;
+ }
+ }
+ return Widget::eventFilter(watched, e);
+}
+
+void
+FontEdit::setReadOnlyInternal(bool readOnly)
+{
+ setVisibleFlag(!readOnly);
+}
+
+#include "fontedit.moc"