diff options
Diffstat (limited to 'lib/koproperty/editors')
41 files changed, 3957 insertions, 0 deletions
diff --git a/lib/koproperty/editors/Makefile.am b/lib/koproperty/editors/Makefile.am new file mode 100644 index 00000000..461fbc00 --- /dev/null +++ b/lib/koproperty/editors/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(top_srcdir)/lib/koproperty -I$(top_srcdir)/lib/kofficecore $(all_includes) + +noinst_LTLIBRARIES = libkopropertyeditors.la +libkopropertyeditors_la_LIBADD = $(LIB_KDEUI) $(LIB_KIO) +libkopropertyeditors_la_LDFLAGS = -Wno-unresolved $(all_libraries) +libkopropertyeditors_la_SOURCES = booledit.cpp coloredit.cpp combobox.cpp cursoredit.cpp dateedit.cpp \ + datetimeedit.cpp dummywidget.cpp fontedit.cpp linestyledit.cpp pixmapedit.cpp pointedit.cpp \ + rectedit.cpp sizeedit.cpp sizepolicyedit.cpp spinbox.cpp stringedit.cpp stringlistedit.cpp \ + symbolcombo.cpp timeedit.cpp urledit.cpp + +METASOURCES = AUTO + +SUBDIRS = . diff --git a/lib/koproperty/editors/booledit.cpp b/lib/koproperty/editors/booledit.cpp new file mode 100644 index 00000000..67fb82ec --- /dev/null +++ b/lib/koproperty/editors/booledit.cpp @@ -0,0 +1,213 @@ +/* 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) 2006 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 "booledit.h" +#include "../property.h" + +#include <kiconloader.h> +#include <klocale.h> +#include <kcombobox.h> +#include <kdebug.h> + +#include <qtoolbutton.h> +#include <qpainter.h> +#include <qvariant.h> +#include <qlayout.h> +#include <qbitmap.h> + +using namespace KoProperty; + +BoolEdit::BoolEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) + , m_yesIcon( SmallIcon("button_ok") ) + , m_noIcon( SmallIcon("button_no") ) +{ + m_toggle = new QToolButton(this); + m_toggle->setToggleButton( true ); + m_toggle->setFocusPolicy(QWidget::WheelFocus); + m_toggle->setUsesTextLabel(true); + m_toggle->setTextPosition(QToolButton::Right); + m_toggle->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + //we're not using layout to because of problems with button size + m_toggle->move(0, 0); + m_toggle->resize(width(), height()); + setFocusWidget(m_toggle); + connect(m_toggle, SIGNAL(stateChanged(int)), this, SLOT(slotValueChanged(int))); +} + +BoolEdit::~BoolEdit() +{ +} + +QVariant +BoolEdit::value() const +{ + return QVariant(m_toggle->isOn(), 4); +} + +void +BoolEdit::setValue(const QVariant &value, bool emitChange) +{ + m_toggle->blockSignals(true); + m_toggle->setOn(value.toBool()); + setState( value.toBool() ? QButton::On : QButton::Off ); + m_toggle->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +BoolEdit::slotValueChanged(int state) +{ + setState(state); + emit valueChanged(this); +} + +static void drawViewerInternal(QPainter *p, const QRect &r, const QVariant &value, + const QPixmap& yesIcon, const QPixmap& noIcon, const QString& nullText) +{ + p->eraseRect(r); + QRect r2(r); + r2.moveLeft(KIcon::SizeSmall + 6); + + if(value.isNull() && !nullText.isEmpty()) { + p->drawText(r2, Qt::AlignVCenter | Qt::AlignLeft, nullText); + } + else if(value.toBool()) { + p->drawPixmap(3, (r.height()-1-KIcon::SizeSmall)/2, yesIcon); + p->drawText(r2, Qt::AlignVCenter | Qt::AlignLeft, i18n("Yes")); + } + else { + p->drawPixmap(3, (r.height()-1-KIcon::SizeSmall)/2, noIcon); + p->drawText(r2, Qt::AlignVCenter | Qt::AlignLeft, i18n("No")); + } +} + +void +BoolEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + Q_UNUSED(cg); + drawViewerInternal(p, r, value, m_yesIcon, m_noIcon, ""); +} + +void +BoolEdit::setState(int state) +{ + if(QButton::On == state) { + m_toggle->setIconSet(QIconSet(m_yesIcon)); + m_toggle->setTextLabel(i18n("Yes")); + } + else if (QButton::Off == state) { + m_toggle->setIconSet(QIconSet(m_noIcon)); + m_toggle->setTextLabel(i18n("No")); + } +} + +void +BoolEdit::resizeEvent(QResizeEvent *ev) +{ + m_toggle->resize(ev->size()); +} + +bool +BoolEdit::eventFilter(QObject* watched, QEvent* e) +{ + if(e->type() == QEvent::KeyPress) { + QKeyEvent* ev = static_cast<QKeyEvent*>(e); + const int k = ev->key(); + if(k == Qt::Key_Space || k == Qt::Key_Enter || k == Qt::Key_Return) { + if (m_toggle) + m_toggle->toggle(); + return true; + } + } + return Widget::eventFilter(watched, e); +} + +void +BoolEdit::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + +//-------------------------------------------------- + +ThreeStateBoolEdit::ThreeStateBoolEdit(Property *property, QWidget *parent, const char *name) + : ComboBox(property, parent, name) + , m_yesIcon( SmallIcon("button_ok") ) + , m_noIcon( SmallIcon("button_no") ) +{ + m_edit->insertItem( m_yesIcon, i18n("Yes") ); + m_edit->insertItem( m_noIcon, i18n("No") ); + QVariant thirdState = property ? property->option("3rdState") : QVariant(); + QPixmap nullIcon( m_yesIcon.size() ); //transparent pixmap of appropriate size + nullIcon.setMask(QBitmap(m_yesIcon.size(), true)); + m_edit->insertItem( nullIcon, thirdState.toString().isEmpty() ? i18n("None") : thirdState.toString() ); +} + +ThreeStateBoolEdit::~ThreeStateBoolEdit() +{ +} + +QVariant +ThreeStateBoolEdit::value() const +{ + // list items: true, false, NULL + const int idx = m_edit->currentItem(); + if (idx==0) + return QVariant(true, 1); + else + return idx==1 ? QVariant(false) : QVariant(); +} + +void +ThreeStateBoolEdit::setProperty(Property *prop) +{ + m_setValueEnabled = false; //setValue() couldn't be called before fillBox() + Widget::setProperty(prop); + m_setValueEnabled = true; + if(prop) + setValue(prop->value(), false); //now the value can be set +} + +void +ThreeStateBoolEdit::setValue(const QVariant &value, bool emitChange) +{ + if (!m_setValueEnabled) + return; + + if (value.isNull()) + m_edit->setCurrentItem(2); + else + m_edit->setCurrentItem(value.toBool() ? 0 : 1); + + if (emitChange) + emit valueChanged(this); +} + +void +ThreeStateBoolEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + Q_UNUSED(cg); + drawViewerInternal(p, r, value, m_yesIcon, m_noIcon, m_edit->text(2)); +} + +#include "booledit.moc" diff --git a/lib/koproperty/editors/booledit.h b/lib/koproperty/editors/booledit.h new file mode 100644 index 00000000..f9ab371f --- /dev/null +++ b/lib/koproperty/editors/booledit.h @@ -0,0 +1,77 @@ +/* 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) 2006 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. +*/ + +#ifndef KPROPERTY_BOOLEDIT_H +#define KPROPERTY_BOOLEDIT_H + +#include "../widget.h" +#include "combobox.h" +#include <qpixmap.h> + +class QToolButton; + +namespace KoProperty { + +class KOPROPERTY_EXPORT BoolEdit : public Widget +{ + Q_OBJECT + + public: + BoolEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~BoolEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected slots: + void slotValueChanged(int state); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + void setState(int state); + virtual void resizeEvent(QResizeEvent *ev); + virtual bool eventFilter(QObject* watched, QEvent* e); + + private: + QToolButton *m_toggle; + QPixmap m_yesIcon, m_noIcon; //!< icons for m_toggle +}; + +class KOPROPERTY_EXPORT ThreeStateBoolEdit : public ComboBox +{ + Q_OBJECT + + public: + ThreeStateBoolEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~ThreeStateBoolEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void setProperty(Property *property); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + QPixmap m_yesIcon, m_noIcon; //!< icons for m_toggle +}; + +} + +#endif diff --git a/lib/koproperty/editors/coloredit.cpp b/lib/koproperty/editors/coloredit.cpp new file mode 100644 index 00000000..81897e1d --- /dev/null +++ b/lib/koproperty/editors/coloredit.cpp @@ -0,0 +1,96 @@ +/* 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> + + 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 "coloredit.h" + +#include <qvariant.h> +#include <qlayout.h> +#include <qcolor.h> +#include <qpainter.h> + +#include <kcolorcombo.h> + +using namespace KoProperty; + +ColorButton::ColorButton(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new KColorCombo(this); + m_edit->setFocusPolicy(QWidget::NoFocus); + connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int))); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + setFocusWidget(m_edit); +} + +ColorButton::~ColorButton() +{} + +QVariant +ColorButton::value() const +{ + return m_edit->color(); +} + +void +ColorButton::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setColor(value.toColor()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +ColorButton::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value) +{ + p->eraseRect(r); + + p->setBrush(value.toColor()); + p->setPen(Qt::SolidLine); + QRect r2(r); + r2.setTopLeft(r.topLeft() + QPoint(5,5)); + r2.setBottomRight(r.bottomRight() - QPoint(5,5)); + p->drawRect(r2); +} + +void +ColorButton::slotValueChanged(int) +{ + emit valueChanged(this); +} + + +bool +ColorButton::eventFilter(QObject* watched, QEvent* e) +{ + return Widget::eventFilter(watched, e); +} + +void +ColorButton::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + +#include "coloredit.moc" diff --git a/lib/koproperty/editors/coloredit.h b/lib/koproperty/editors/coloredit.h new file mode 100644 index 00000000..339d6239 --- /dev/null +++ b/lib/koproperty/editors/coloredit.h @@ -0,0 +1,56 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_COLOREDIT_H +#define KPROPERTY_COLOREDIT_H + +#include "../widget.h" + +class KColorCombo; + +namespace KoProperty { + +class KOPROPERTY_EXPORT ColorButton : public Widget +{ + Q_OBJECT + + public: + ColorButton(Property *property, QWidget *parent=0, const char *name=0); + virtual ~ColorButton(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + virtual bool eventFilter(QObject* watched, QEvent* e); + + protected slots: + void slotValueChanged(int index); + + private: + KColorCombo *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/combobox.cpp b/lib/koproperty/editors/combobox.cpp new file mode 100644 index 00000000..64563dcb --- /dev/null +++ b/lib/koproperty/editors/combobox.cpp @@ -0,0 +1,199 @@ +/* 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> + + 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 "combobox.h" + +#include <qlayout.h> +#include <qmap.h> +#include <qvariant.h> +#include <qpainter.h> + +#include <kcombobox.h> +#include <kdebug.h> + +#include "property.h" + +using namespace KoProperty; + +ComboBox::ComboBox(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) + , m_setValueEnabled(true) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new KComboBox(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + m_edit->setEditable(false); + m_edit->setInsertionPolicy(QComboBox::NoInsertion); + m_edit->setMinimumSize(10, 0); // to allow the combo to be resized to a small size + m_edit->setAutoCompletion(true); + m_edit->setContextMenuEnabled(false); + + if (this->property()->listData()) { + fillBox(); + } +//not needed for combo setLeavesTheSpaceForRevertButton(true); + + setFocusWidget(m_edit); + connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int))); +} + +ComboBox::~ComboBox() +{ +} + +QVariant +ComboBox::value() const +{ + if (!property()->listData()) { + kopropertywarn << "ComboBox::value(): propery listData not available!" << endl; + return QVariant(); + } + const int idx = m_edit->currentItem(); + if (idx<0 || idx>=(int)property()->listData()->keys.count()) + return QVariant(); + return QVariant( property()->listData()->keys[idx] ); +// if(property()->listData() && property()->listData()->contains(m_edit->currentText())) +// return (*(property()->valueList()))[m_edit->currentText()]; +// return QVariant(); +} + +void +ComboBox::setValue(const QVariant &value, bool emitChange) +{ + if (!property() || !property()->listData()) { + kopropertywarn << "ComboBox::value(): propery listData not available!" << endl; + return; + } + if (!m_setValueEnabled) + return; + int idx = property()->listData()->keys.findIndex( value ); + if (idx>=0 && idx<m_edit->count()) { + m_edit->setCurrentItem(idx); + } + else { + if (idx<0) { + kopropertywarn << "ComboBox::setValue(): NO SUCH KEY '" << value.toString() + << "' (property '" << property()->name() << "')" << endl; + } else { + QStringList list; + for (int i=0; i<m_edit->count(); i++) + list += m_edit->text(i); + kopropertywarn << "ComboBox::setValue(): NO SUCH INDEX WITHIN COMBOBOX: " << idx + << " count=" << m_edit->count() << " value='" << value.toString() + << "' (property '" << property()->name() << "')\nActual combobox contents: " + << list << endl; + } + m_edit->setCurrentText(QString::null); + } + + if(value.isNull()) + return; + +// m_edit->blockSignals(true); +// m_edit->setCurrentText(keyForValue(value)); +// m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +ComboBox::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + QString txt; + if (property()->listData()) { + const int idx = property()->listData()->keys.findIndex( value ); + if (idx>=0) + txt = property()->listData()->names[ idx ]; + } + + Widget::drawViewer(p, cg, r, txt); //keyForValue(value)); +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, keyForValue(value)); +} + +void +ComboBox::fillBox() +{ + m_edit->clear(); + //m_edit->clearContents(); + + if(!property()) + return; + if (!property()->listData()) { + kopropertywarn << "ComboBox::fillBox(): propery listData not available!" << endl; + return; + } + + m_edit->insertStringList(property()->listData()->names); + KCompletion *comp = m_edit->completionObject(); + comp->insertItems(property()->listData()->names); + comp->setCompletionMode(KGlobalSettings::CompletionShell); +} + +void +ComboBox::setProperty(Property *prop) +{ + const bool b = (property() == prop); + m_setValueEnabled = false; //setValue() couldn't be called before fillBox() + Widget::setProperty(prop); + m_setValueEnabled = true; + if(!b) + fillBox(); + if(prop) + setValue(prop->value(), false); //now the value can be set +} + +void +ComboBox::slotValueChanged(int) +{ + emit valueChanged(this); +} + +void +ComboBox::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + + +/*QString +ComboBox::keyForValue(const QVariant &value) +{ + const QMap<QString, QVariant> *list = property()->valueList(); + Property::ListData *list = property()->listData(); + + if (!list) + return QString::null; + int idx = listData->keys.findIndex( value ); + + + QMap<QString, QVariant>::ConstIterator endIt = list->constEnd(); + for(QMap<QString, QVariant>::ConstIterator it = list->constBegin(); it != endIt; ++it) { + if(it.data() == value) + return it.key(); + } + return QString::null; +}*/ + + +#include "combobox.moc" + diff --git a/lib/koproperty/editors/combobox.h b/lib/koproperty/editors/combobox.h new file mode 100644 index 00000000..5d1f56f9 --- /dev/null +++ b/lib/koproperty/editors/combobox.h @@ -0,0 +1,59 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_COMBOBOX_H +#define KPROPERTY_COMBOBOX_H + +#include "../widget.h" + +class KComboBox; + +namespace KoProperty { + +class KOPROPERTY_EXPORT ComboBox : public Widget +{ + Q_OBJECT + + public: + ComboBox(Property *property, QWidget *parent=0, const char *name=0); + virtual ~ComboBox(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void setProperty(Property *property); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected slots: + void slotValueChanged(int value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + QString keyForValue(const QVariant &value); + void fillBox(); + + KComboBox *m_edit; + bool m_setValueEnabled : 1; +}; + +} + +#endif + diff --git a/lib/koproperty/editors/cursoredit.cpp b/lib/koproperty/editors/cursoredit.cpp new file mode 100644 index 00000000..a0b3227c --- /dev/null +++ b/lib/koproperty/editors/cursoredit.cpp @@ -0,0 +1,138 @@ +/* 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> + + 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 "cursoredit.h" + +#include <qmap.h> +#include <qvariant.h> +#include <qcursor.h> + +#include <klocale.h> +#include <kdebug.h> + +#include "property.h" + +using namespace KoProperty; + +//QMap<QString, QVariant> *CursorEdit::m_spValues = 0; +Property::ListData *m_cursorListData = 0; + + +CursorEdit::CursorEdit(Property *property, QWidget *parent, const char *name) +: ComboBox(property, parent, name) +{ + /* + if(!m_spValues) { + m_spValues = new QMap<QString, QVariant>(); + (*m_spValues)[i18n("Arrow")] = Qt::ArrowCursor; + (*m_spValues)[i18n("Up Arrow")] = Qt::UpArrowCursor; + (*m_spValues)[i18n("Cross")] = Qt::CrossCursor; + (*m_spValues)[i18n("Waiting")] = Qt::WaitCursor; + (*m_spValues)[i18n("iBeam")] = Qt::IbeamCursor; + (*m_spValues)[i18n("Size Vertical")] = Qt::SizeVerCursor; + (*m_spValues)[i18n("Size Horizontal")] = Qt::SizeHorCursor; + (*m_spValues)[i18n("Size Slash")] = Qt::SizeBDiagCursor; + (*m_spValues)[i18n("Size Backslash")] = Qt::SizeFDiagCursor; + (*m_spValues)[i18n("Size All")] = Qt::SizeAllCursor; + (*m_spValues)[i18n("Blank")] = Qt::BlankCursor; + (*m_spValues)[i18n("Split Vertical")] = Qt::SplitVCursor; + (*m_spValues)[i18n("Split Horizontal")] = Qt::SplitHCursor; + (*m_spValues)[i18n("Pointing Hand")] = Qt::PointingHandCursor; + (*m_spValues)[i18n("Forbidden")] = Qt::ForbiddenCursor; + (*m_spValues)[i18n("What's this")] = Qt::WhatsThisCursor; + }*/ + +//! @todo NOT THREAD-SAFE + if (!m_cursorListData) { + QValueList<QVariant> keys; + keys + << Qt::BlankCursor + << Qt::ArrowCursor + << Qt::UpArrowCursor + << Qt::CrossCursor + << Qt::WaitCursor + << Qt::IbeamCursor + << Qt::SizeVerCursor + << Qt::SizeHorCursor + << Qt::SizeBDiagCursor + << Qt::SizeFDiagCursor + << Qt::SizeAllCursor + << Qt::SplitVCursor + << Qt::SplitHCursor + << Qt::PointingHandCursor + << Qt::ForbiddenCursor + << Qt::WhatsThisCursor; + QStringList strings; + strings << i18n("Mouse Cursor Shape", "No Cursor") + << i18n("Mouse Cursor Shape", "Arrow") + << i18n("Mouse Cursor Shape", "Up Arrow") + << i18n("Mouse Cursor Shape", "Cross") + << i18n("Mouse Cursor Shape", "Waiting") + << i18n("Mouse Cursor Shape", "I") + << i18n("Mouse Cursor Shape", "Size Vertical") + << i18n("Mouse Cursor Shape", "Size Horizontal") + << i18n("Mouse Cursor Shape", "Size Slash") + << i18n("Mouse Cursor Shape", "Size Backslash") + << i18n("Mouse Cursor Shape", "Size All") + << i18n("Mouse Cursor Shape", "Split Vertical") + << i18n("Mouse Cursor Shape", "Split Horizontal") + << i18n("Mouse Cursor Shape", "Pointing Hand") + << i18n("Mouse Cursor Shape", "Forbidden") + << i18n("Mouse Cursor Shape", "What's This?"); + m_cursorListData = new Property::ListData(keys, strings); + } + + if(property) + property->setListData(new Property::ListData(*m_cursorListData)); +} + +CursorEdit::~CursorEdit() +{ + delete m_cursorListData; + m_cursorListData = 0; +} + +QVariant +CursorEdit::value() const +{ + return QCursor(ComboBox::value().toInt()); +} + +void +CursorEdit::setValue(const QVariant &value, bool emitChange) +{ + ComboBox::setValue(value.toCursor().shape(), emitChange); +} + +void +CursorEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + ComboBox::drawViewer(p, cg, r, value.toCursor().shape()); +} + +void +CursorEdit::setProperty(Property *prop) +{ + if(prop && prop != property()) + prop->setListData(new Property::ListData(*m_cursorListData)); + ComboBox::setProperty(prop); +} + +#include "cursoredit.moc" diff --git a/lib/koproperty/editors/cursoredit.h b/lib/koproperty/editors/cursoredit.h new file mode 100644 index 00000000..81587cc4 --- /dev/null +++ b/lib/koproperty/editors/cursoredit.h @@ -0,0 +1,50 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_CURSOREDIT_H +#define KPROPERTY_CURSOREDIT_H + +#include "combobox.h" + +template<class U, class T> class QMap; + +namespace KoProperty { + +class KOPROPERTY_EXPORT CursorEdit : public ComboBox +{ + Q_OBJECT + + public: + CursorEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~CursorEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void setProperty(Property *property); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + private: + static QMap<QString, QVariant> *m_spValues; +}; + +} + +#endif diff --git a/lib/koproperty/editors/dateedit.cpp b/lib/koproperty/editors/dateedit.cpp new file mode 100644 index 00000000..797c0e5c --- /dev/null +++ b/lib/koproperty/editors/dateedit.cpp @@ -0,0 +1,89 @@ +/* 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> + + 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 "dateedit.h" + +#include <qdatetimeedit.h> +#include <qrangecontrol.h> +#include <qobjectlist.h> +#include <qlayout.h> +#include <qvariant.h> +#include <qpainter.h> + +#include <klocale.h> +#include <kglobal.h> + +using namespace KoProperty; + +DateEdit::DateEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new QDateEdit(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + setLeavesTheSpaceForRevertButton(true); + + setFocusWidget(m_edit); + connect(m_edit, SIGNAL(valueChanged(const QDate&)), this, SLOT(slotValueChanged(const QDate&))); +} + +DateEdit::~DateEdit() +{} + +QVariant +DateEdit::value() const +{ + return m_edit->date(); +} + +void +DateEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setDate(value.toDate()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +DateEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + p->eraseRect(r); + Widget::drawViewer(p, cg, r, KGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ )); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, KGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ )); +} + +void +DateEdit::slotValueChanged(const QDate&) +{ + emit valueChanged(this); +} + +void +DateEdit::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + +#include "dateedit.moc" diff --git a/lib/koproperty/editors/dateedit.h b/lib/koproperty/editors/dateedit.h new file mode 100644 index 00000000..509ae572 --- /dev/null +++ b/lib/koproperty/editors/dateedit.h @@ -0,0 +1,56 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_DATEEDIT_H +#define KPROPERTY_DATEEDIT_H + +#include "../widget.h" + +class QDateEdit; +class QDate; + +namespace KoProperty { + +class KOPROPERTY_EXPORT DateEdit : public Widget +{ + Q_OBJECT + + public: + DateEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~DateEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void slotValueChanged(const QDate &date); + + private: + QDateEdit *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/datetimeedit.cpp b/lib/koproperty/editors/datetimeedit.cpp new file mode 100644 index 00000000..33bb8de3 --- /dev/null +++ b/lib/koproperty/editors/datetimeedit.cpp @@ -0,0 +1,89 @@ +/* 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> + + 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 "datetimeedit.h" + +#include <qdatetimeedit.h> +#include <qrangecontrol.h> +#include <qobjectlist.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qvariant.h> + +#include <klocale.h> +#include <kglobal.h> + +using namespace KoProperty; + +DateTimeEdit::DateTimeEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new QDateTimeEdit(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + setLeavesTheSpaceForRevertButton(true); + setFocusWidget(m_edit); + connect(m_edit, SIGNAL(valueChanged(const QDateTime&)), this, SLOT(slotValueChanged(const QDateTime&))); +} + +DateTimeEdit::~DateTimeEdit() +{} + +QVariant +DateTimeEdit::value() const +{ + return m_edit->dateTime(); +} + +void +DateTimeEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setDateTime(value.toDateTime()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +DateTimeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + p->eraseRect(r); + Widget::drawViewer(p, cg, r, KGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ )); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, +// KGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ )); +} + +void +DateTimeEdit::slotValueChanged(const QDateTime&) +{ + emit valueChanged(this); +} + +void +DateTimeEdit::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + +#include "datetimeedit.moc" diff --git a/lib/koproperty/editors/datetimeedit.h b/lib/koproperty/editors/datetimeedit.h new file mode 100644 index 00000000..f7b81795 --- /dev/null +++ b/lib/koproperty/editors/datetimeedit.h @@ -0,0 +1,56 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_DATETIMEEDIT_H +#define KPROPERTY_DATETIMEEDIT_H + +#include "../widget.h" + +class QDateTimeEdit; +class QDateTime; + +namespace KoProperty { + +class KOPROPERTY_EXPORT DateTimeEdit : public Widget +{ + Q_OBJECT + + public: + DateTimeEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~DateTimeEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void slotValueChanged(const QDateTime &dateTime); + + private: + QDateTimeEdit *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/dummywidget.cpp b/lib/koproperty/editors/dummywidget.cpp new file mode 100644 index 00000000..9c72c8cd --- /dev/null +++ b/lib/koproperty/editors/dummywidget.cpp @@ -0,0 +1,63 @@ +/* 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> + + 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 "dummywidget.h" + +#include <qpainter.h> + +using namespace KoProperty; + +DummyWidget::DummyWidget(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{} + +DummyWidget::~DummyWidget() +{} + +QVariant +DummyWidget::value() const +{ + return m_value; +} + +void +DummyWidget::setValue(const QVariant &value, bool emitChange) +{ + m_value = value; + if(emitChange) + emit valueChanged(this); +} + +void +DummyWidget::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &) +{ + p->setBrush(cg.background()); + p->setPen(Qt::NoPen); + p->drawRect(r); +} + +void +DummyWidget::setReadOnlyInternal(bool readOnly) +{ + Q_UNUSED(readOnly); +} + +#include "dummywidget.moc" + diff --git a/lib/koproperty/editors/dummywidget.h b/lib/koproperty/editors/dummywidget.h new file mode 100644 index 00000000..b85ccb95 --- /dev/null +++ b/lib/koproperty/editors/dummywidget.h @@ -0,0 +1,53 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_DUMMYWIDGET_H +#define KPROPERTY_DUMMYWIDGET_H + +#include "../widget.h" + +#include <qvariant.h> + +namespace KoProperty { + +class KOPROPERTY_EXPORT DummyWidget: public Widget +{ + Q_OBJECT + + public: + DummyWidget(Property *property, QWidget *parent=0, const char *name=0); + virtual ~DummyWidget(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + private: + QVariant m_value; +}; + +} + +#endif + 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" diff --git a/lib/koproperty/editors/fontedit.h b/lib/koproperty/editors/fontedit.h new file mode 100644 index 00000000..0112171a --- /dev/null +++ b/lib/koproperty/editors/fontedit.h @@ -0,0 +1,57 @@ +/* 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. +*/ + +#ifndef KPROPERTY_FONTEDIT_H +#define KPROPERTY_FONTEDIT_H + +#include "widget.h" + +namespace KoProperty { + +class FontEditRequester; + +class KOPROPERTY_EXPORT FontEdit : public Widget +{ + Q_OBJECT + + public: + FontEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~FontEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + virtual bool eventFilter(QObject* watched, QEvent* e); + + protected slots: + void slotValueChanged(const QFont &font); + + private: + FontEditRequester *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/linestyledit.cpp b/lib/koproperty/editors/linestyledit.cpp new file mode 100644 index 00000000..0d2353ff --- /dev/null +++ b/lib/koproperty/editors/linestyledit.cpp @@ -0,0 +1,225 @@ +/* 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> + + 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 "linestyleedit.h" +#include "editoritem.h" + +#include <qpainter.h> +#include <qpixmap.h> +#include <qcombobox.h> +#include <qlayout.h> +#include <qvariant.h> + +using namespace KoProperty; + + //! @internal + static const char *nopen[]={ + "48 16 1 1", + ". c None", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................"}; + //! @internal + static const char *solid[]={ + "48 16 2 1", + ". c None", + "# c #000000", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + ".###########################################....", + ".###########################################....", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................"}; + //! @internal + static const char *dash[]={ + "48 16 2 1", + ". c None", + "# c #000000", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + ".#########..#########..#########..##########....", + ".#########..#########..#########..##########....", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................"}; + //! @internal + static const char *dashdot[]={ + "48 16 2 1", + ". c None", + "# c #000000", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + ".#########..##..#########..##..#########..##....", + ".#########..##..#########..##..#########..##....", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................"}; + //! @internal + static const char *dashdotdot[]={ + "48 16 2 1", + ". c None", + "# c #000000", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + ".#########..##..##..#########..##..##..#####....", + ".#########..##..##..#########..##..##..#####....", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................", + "................................................"}; + + +LineStyleEdit::LineStyleEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new QComboBox(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + m_edit->insertItem(QPixmap(nopen)); + m_edit->insertItem(QPixmap(solid)); + m_edit->insertItem(QPixmap(dash)); + m_edit->insertItem(QPixmap(dashdot)); + m_edit->insertItem(QPixmap(dashdotdot)); + + setLeavesTheSpaceForRevertButton(true); + setFocusWidget(m_edit); + connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int))); +} + +LineStyleEdit::~LineStyleEdit() +{} + +QVariant +LineStyleEdit::value() const +{ + return m_edit->currentItem(); +} + +void +LineStyleEdit::setValue(const QVariant &value, bool emitChange) +{ + if (!value.canCast(QVariant::Int)) + return; + if ((value.toInt() > 5) || (value.toInt() < 0)) + return; + + m_edit->blockSignals(true); + m_edit->setCurrentItem(value.toInt()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +LineStyleEdit::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value) +{ + p->eraseRect(r); + + if (!value.canCast(QVariant::Int)) + return; + + QPixmap px; + switch (value.toInt()) { + case 0: + px = QPixmap(nopen); + break; + case 1: + px = QPixmap(solid); + break; + case 2: + px = QPixmap(dash); + break; + case 3: + px = QPixmap(dashdot); + break; + case 4: + px = QPixmap(dashdotdot); + break; + default: + return; + } + p->drawPixmap(r.left()+KPROPEDITOR_ITEM_MARGIN, r.top()+(r.height()-px.height())/2, px); +} + +void +LineStyleEdit::slotValueChanged(int) +{ + emit valueChanged(this); +} + +void +LineStyleEdit::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + +#include "linestyleedit.moc" diff --git a/lib/koproperty/editors/linestyleedit.h b/lib/koproperty/editors/linestyleedit.h new file mode 100644 index 00000000..6392e2f7 --- /dev/null +++ b/lib/koproperty/editors/linestyleedit.h @@ -0,0 +1,55 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_LINESTYLEEDIT_H +#define KPROPERTY_LINESTYLEEDIT_H + +#include "../widget.h" + +class QComboBox; + +namespace KoProperty { + +class KOPROPERTY_EXPORT LineStyleEdit : public Widget +{ + Q_OBJECT + + public: + LineStyleEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~LineStyleEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void slotValueChanged(int value); + + private: + QComboBox *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/pixmapedit.cpp b/lib/koproperty/editors/pixmapedit.cpp new file mode 100644 index 00000000..d141eed3 --- /dev/null +++ b/lib/koproperty/editors/pixmapedit.cpp @@ -0,0 +1,247 @@ +/* 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 "pixmapedit.h" +#include "editoritem.h" +#include "property.h" + +#include <qlayout.h> +#include <qpainter.h> +#include <qlabel.h> +#include <qcursor.h> +#include <qpushbutton.h> +#include <qfont.h> +#include <qfontmetrics.h> +#include <qimage.h> +#include <qfiledialog.h> +#include <qtooltip.h> +#include <qapplication.h> + +#include <kdebug.h> +#include <kimageio.h> + +#ifdef Q_WS_WIN +#include <win32_utils.h> +#include <krecentdirs.h> +#endif + +#ifndef PURE_QT +#include <kfiledialog.h> +#include <klocale.h> +#include <kfiledialog.h> +#endif + +using namespace KoProperty; + +PixmapEdit::PixmapEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); + + m_edit = new QLabel(this, "m_edit"); + QToolTip::add(m_edit, i18n("Click to show image preview")); + m_edit->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); + m_edit->setMinimumHeight(5); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_edit->setBackgroundMode(Qt::PaletteBase); + m_edit->setMouseTracking(true); + setBackgroundMode(Qt::PaletteBase); + + m_button = new QPushButton(i18n("..."), this, "m_button"); + QToolTip::add(m_button, i18n("Insert image from file")); + m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + QFontMetrics fm(m_button->font()); + m_button->setFixedWidth(fm.width(m_button->text()+' ')); + m_button->setFocusPolicy(NoFocus); + + m_popup = new QLabel(0, "m_popup", Qt::WStyle_Customize|Qt::WStyle_NoBorder|Qt::WX11BypassWM|WStyle_StaysOnTop); + m_popup->setPaletteBackgroundColor(m_popup->palette().active().base()); + m_popup->setFrameStyle(QFrame::Plain|QFrame::Box); + m_popup->setMargin(2); + m_popup->setLineWidth(1); + m_popup->hide(); + + setFocusWidget(m_edit); + connect(m_button, SIGNAL(clicked()), this, SLOT(selectPixmap())); +} + +PixmapEdit::~PixmapEdit() +{ + delete m_popup; +} + +QVariant +PixmapEdit::value() const +{ + return m_pixmap; +} + +void +PixmapEdit::setValue(const QVariant &value, bool emitChange) +{ + m_pixmap = value.toPixmap(); + if (m_pixmap.isNull() || (m_pixmap.height()<=height())) { + m_edit->setPixmap(m_pixmap); + m_previewPixmap = m_pixmap; + } + else { + QImage img(m_pixmap.convertToImage()); + if (!QRect(QPoint(0,0), m_edit->size()*3).contains(m_pixmap.rect())) { + img = img.smoothScale(m_edit->size()*3, QImage::ScaleMin); + m_previewPixmap.convertFromImage(img);//preview pixmap is a bit larger + } + else { + m_previewPixmap = m_pixmap; + } + img = img.smoothScale(m_edit->size(), QImage::ScaleMin); + QPixmap pm; + pm.convertFromImage(img); + m_edit->setPixmap(pm); + } + if (emitChange) + emit valueChanged(this); +} + +void +PixmapEdit::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value) +{ + QRect r2(r); + r2.setHeight(r2.height()+1); + p->setClipRect(r2, QPainter::CoordPainter); + p->setClipping(true); + p->eraseRect(r2); + if (value.toPixmap().isNull()) + return; + if (m_recentlyPainted!=value) { + m_recentlyPainted = value; + m_scaledPixmap = value.toPixmap(); + if (m_scaledPixmap.height() > r2.height() || m_scaledPixmap.width() > r2.width()) { //scale down + QImage img(m_scaledPixmap.convertToImage()); + img = img.smoothScale(r2.size()/*+QSize(0,2)*/, QImage::ScaleMin); + m_scaledPixmap.convertFromImage(img); + } + } + p->drawPixmap(r2.topLeft().x(), //+KPROPEDITOR_ITEM_MARGIN, + r2.topLeft().y()+(r2.height()-m_scaledPixmap.height())/2, m_scaledPixmap); +} + +QString +PixmapEdit::selectPixmapFileName() +{ +/*#ifdef PURE_QT + QString url = QFileDialog::getOpenFileName(); + if (!url.isEmpty()) { + m_edit->setPixmap(QPixmap(url)); + emit valueChanged(this); + } +#endif*/ + QString caption( i18n("Insert Image From File (for \"%1\" property)").arg(property()->caption()) ); +#ifdef Q_WS_WIN + QString recentDir; + QString fileName = QFileDialog::getOpenFileName( + KFileDialog::getStartURL(":lastVisitedImagePath", recentDir).path(), + convertKFileDialogFilterToQFileDialogFilter(KImageIO::pattern(KImageIO::Reading)), + this, 0, caption); +#else + KURL url( KFileDialog::getImageOpenURL( + ":lastVisitedImagePath", this, caption) ); + QString fileName = url.isLocalFile() ? url.path() : url.prettyURL(); + + //! @todo download the file if remote, then set fileName properly +#endif + return fileName; +} + +void +PixmapEdit::selectPixmap() +{ + QString fileName( selectPixmapFileName() ); + if (fileName.isEmpty()) + return; + + QPixmap pm; + if (!pm.load(fileName)) { + //! @todo err msg + return; + } + setValue(pm); + +#ifdef Q_WS_WIN + //save last visited path + KURL url(fileName); + if (url.isLocalFile()) + KRecentDirs::add(":lastVisitedImagePath", url.directory()); +#endif +} + +void +PixmapEdit::resizeEvent(QResizeEvent *e) +{ + Widget::resizeEvent(e); + m_edit->move(0,0); + m_edit->resize(e->size()-QSize(m_button->width(),-1)); + m_button->move(m_edit->width(),0); + m_button->setFixedSize(m_button->width(), height()); +} + +bool +PixmapEdit::eventFilter(QObject *o, QEvent *ev) +{ + if(o == m_edit) { + if(ev->type() == QEvent::MouseButtonPress && static_cast<QMouseEvent*>(ev)->button()==LeftButton) { + if(m_previewPixmap.height() <= m_edit->height() + && m_previewPixmap.width() <= m_edit->width()) + return false; + + m_popup->setPixmap(m_previewPixmap.isNull() ? m_pixmap : m_previewPixmap); + m_popup->resize(m_previewPixmap.size()+QSize(2*3,2*3)); + QPoint pos = QCursor::pos()+QPoint(3,15); + QRect screenRect = QApplication::desktop()->availableGeometry( this ); + if ((pos.x()+m_popup->width()) > screenRect.width()) + pos.setX(screenRect.width()-m_popup->width()); + if ((pos.y()+m_popup->height()) > screenRect.height()) + pos.setY(mapToGlobal(QPoint(0,0)).y()-m_popup->height()); + m_popup->move(pos); + m_popup->show(); + } + else if(ev->type() == QEvent::MouseButtonRelease || ev->type() == QEvent::Hide) { + if(m_popup->isVisible()) + m_popup->hide(); + } + else if(ev->type() == QEvent::KeyPress) { + QKeyEvent* e = static_cast<QKeyEvent*>(ev); + if((e->key() == Key_Enter) || (e->key()== Key_Space) || (e->key() == Key_Return)) { + m_button->animateClick(); + return true; + } + } + } + + return Widget::eventFilter(o, ev); +} + +void +PixmapEdit::setReadOnlyInternal(bool readOnly) +{ + m_button->setEnabled(!readOnly); +} + +#include "pixmapedit.moc" diff --git a/lib/koproperty/editors/pixmapedit.h b/lib/koproperty/editors/pixmapedit.h new file mode 100644 index 00000000..7b0268bf --- /dev/null +++ b/lib/koproperty/editors/pixmapedit.h @@ -0,0 +1,72 @@ +/* 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. +*/ + +#ifndef KPROPERTY_PIXMAPEDIT_H +#define KPROPERTY_PIXMAPEDIT_H + +#include "../widget.h" +#include <qpixmap.h> +#include <qvariant.h> + +class QLabel; +class QPushButton; + +namespace KoProperty { + +class KOPROPERTY_EXPORT PixmapEdit : public Widget +{ + Q_OBJECT + + public: + PixmapEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~PixmapEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + void resizeEvent(QResizeEvent *ev); + bool eventFilter(QObject *o, QEvent *ev); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + /*! Helper used by selectPixmap(). Can be also used by subclassess. + Selected path will be stored in "lastVisitedImagePath" config entry within "Recent Dirs" + config group of application's settings. This entry can be later reused when file dialogs + are opened for selecting image files. */ + QString selectPixmapFileName(); + + /*! Selects a new pixmap using "open" file dialog. Can be reimplemented. */ + virtual void selectPixmap(); + + protected: + QLabel *m_edit; + QLabel *m_popup; + QPushButton *m_button; + QVariant m_recentlyPainted; + QPixmap m_pixmap, m_scaledPixmap, m_previewPixmap; +}; + +} + +#endif diff --git a/lib/koproperty/editors/pointedit.cpp b/lib/koproperty/editors/pointedit.cpp new file mode 100644 index 00000000..60d74a89 --- /dev/null +++ b/lib/koproperty/editors/pointedit.cpp @@ -0,0 +1,91 @@ +/* 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> + + 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 "pointedit.h" +#include "editoritem.h" + +#include <qlabel.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qtooltip.h> + +#include <kactivelabel.h> +#include <klocale.h> + +//"[ %1, %2 ]" +#define POINTEDIT_MASK "%1,%2" + +using namespace KoProperty; + +PointEdit::PointEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); + m_edit = new KActiveLabel(this); + m_edit->setFocusPolicy(NoFocus); +// m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN); + m_edit->setPaletteBackgroundColor(palette().active().base()); + m_edit->setWordWrap( QTextEdit::NoWrap ); +// m_edit->setBackgroundMode(Qt::PaletteBase); +// m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + setEditor(m_edit); +// setFocusWidget(m_edit); +} + +PointEdit::~PointEdit() +{} + +QVariant +PointEdit::value() const +{ + return m_value; +} + +void +PointEdit::setValue(const QVariant &value, bool emitChange) +{ + m_value = value; + m_edit->selectAll(false); + m_edit->setText(QString(POINTEDIT_MASK).arg(value.toPoint().x()).arg(value.toPoint().y())); + QToolTip::add(this, QString("%1, %2").arg(value.toPoint().x()).arg(value.toPoint().y())); + + if (emitChange) + emit valueChanged(this); +} + +void +PointEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + QRect rect(r); + rect.setBottom(r.bottom()+1); + Widget::drawViewer(p, cg, rect, QString(POINTEDIT_MASK).arg(value.toPoint().x()).arg(value.toPoint().y())); +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, +// QString("[ %1, %2 ]").arg(value.toPoint().x()).arg(value.toPoint().y())); +} + +void +PointEdit::setReadOnlyInternal(bool readOnly) +{ + Q_UNUSED(readOnly); +} + +#include "pointedit.moc" diff --git a/lib/koproperty/editors/pointedit.h b/lib/koproperty/editors/pointedit.h new file mode 100644 index 00000000..bba2fda1 --- /dev/null +++ b/lib/koproperty/editors/pointedit.h @@ -0,0 +1,56 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_POINTEDIT_H +#define KPROPERTY_POINTEDIT_H + +#include "../widget.h" + +#include <qvariant.h> + +class KActiveLabel; + +namespace KoProperty { + +class KOPROPERTY_EXPORT PointEdit : public Widget +{ + Q_OBJECT + + public: + PointEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~PointEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + private: + KActiveLabel *m_edit; + QVariant m_value; +}; + +} + +#endif + diff --git a/lib/koproperty/editors/rectedit.cpp b/lib/koproperty/editors/rectedit.cpp new file mode 100644 index 00000000..4f495b60 --- /dev/null +++ b/lib/koproperty/editors/rectedit.cpp @@ -0,0 +1,92 @@ +/* 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> + + 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 "rectedit.h" +#include "editoritem.h" + +#include <qvariant.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qtooltip.h> + +#include <kactivelabel.h> +#include <klocale.h> + +// "[ %1, %2, %3, %4 ]" +#define RECTEDIT_MASK "%1,%2 %3x%4" + +using namespace KoProperty; + +RectEdit::RectEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); + m_edit = new KActiveLabel(this); + m_edit->setFocusPolicy(NoFocus); + m_edit->setPaletteBackgroundColor(palette().active().base()); + m_edit->setWordWrap( QTextEdit::NoWrap ); + m_edit->setMinimumHeight(5); + setEditor(m_edit); +// setFocusWidget(m_edit); +} + +RectEdit::~RectEdit() +{} + +QVariant +RectEdit::value() const +{ + return m_value; +} + +void +RectEdit::setValue(const QVariant &value, bool emitChange) +{ + m_value = value; + m_edit->selectAll(false); + m_edit->setText(QString(RECTEDIT_MASK).arg(value.toRect().x()). + arg(value.toRect().y()).arg(value.toRect().width()).arg(value.toRect().height())); + QToolTip::add(this, i18n("Position: %1, %2\nSize: %3 x %4").arg(value.toRect().x()). + arg(value.toRect().y()).arg(value.toRect().width()).arg(value.toRect().height())); + + if (emitChange) + emit valueChanged(this); +} + +void +RectEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + QRect rect(r); + rect.setBottom(r.bottom()+1); + Widget::drawViewer(p, cg, rect, + QString(RECTEDIT_MASK).arg(value.toRect().x()).arg(value.toRect().y()) + .arg(value.toRect().width()).arg(value.toRect().height())); +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, +// QString("[ %1, %2, %3, %4 ]").arg(value.toRect().x()).arg(value.toRect().y()) +// .arg(value.toRect().width()).arg(value.toRect().height())); +} + +void +RectEdit::setReadOnlyInternal(bool readOnly) +{ + Q_UNUSED(readOnly); +} + +#include "rectedit.moc" diff --git a/lib/koproperty/editors/rectedit.h b/lib/koproperty/editors/rectedit.h new file mode 100644 index 00000000..fe1f7e74 --- /dev/null +++ b/lib/koproperty/editors/rectedit.h @@ -0,0 +1,55 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_RECTEDIT_H +#define KPROPERTY_RECTEDIT_H + +#include "../widget.h" + +#include <qvariant.h> + +class KActiveLabel; + +namespace KoProperty { + +class KOPROPERTY_EXPORT RectEdit : public Widget +{ + Q_OBJECT + + public: + RectEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~RectEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + private: + KActiveLabel *m_edit; + QVariant m_value; +}; + +} + +#endif diff --git a/lib/koproperty/editors/sizeedit.cpp b/lib/koproperty/editors/sizeedit.cpp new file mode 100644 index 00000000..e8a0c339 --- /dev/null +++ b/lib/koproperty/editors/sizeedit.cpp @@ -0,0 +1,91 @@ +/* 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> + + 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 "sizeedit.h" +#include "editoritem.h" + +#include <qlabel.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qtooltip.h> + +#include <kactivelabel.h> +#include <klocale.h> + +//"[ %1, %2 ]" +#define SIZEEDIT_MASK "%1x%2" + +using namespace KoProperty; + +SizeEdit::SizeEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); + m_edit = new KActiveLabel(this); + m_edit->setFocusPolicy(NoFocus); +// m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN); + m_edit->setPaletteBackgroundColor(palette().active().base()); +// m_edit->setBackgroundMode(Qt::PaletteBase); +// m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + setEditor(m_edit); +// setFocusWidget(m_edit); +} + +SizeEdit::~SizeEdit() +{} + +QVariant +SizeEdit::value() const +{ + return m_value; +} + +void +SizeEdit::setValue(const QVariant &value, bool emitChange) +{ + m_value = value; + m_edit->selectAll(false); + m_edit->setText(QString(SIZEEDIT_MASK).arg(value.toSize().width()).arg(value.toSize().height())); + QToolTip::add(this, QString("%1 x %2").arg(value.toSize().width()).arg(value.toSize().height())); + + if (emitChange) + emit valueChanged(this); +} + +void +SizeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + QRect rect(r); + rect.setBottom(r.bottom()+1); + Widget::drawViewer(p, cg, rect, + QString(SIZEEDIT_MASK).arg(value.toSize().width()).arg(value.toSize().height())); +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, +// QString("[ %1, %2 ]").arg(value.toSize().width()).arg(value.toSize().height())); +} + +void +SizeEdit::setReadOnlyInternal(bool readOnly) +{ + Q_UNUSED(readOnly); +} + +#include "sizeedit.moc" diff --git a/lib/koproperty/editors/sizeedit.h b/lib/koproperty/editors/sizeedit.h new file mode 100644 index 00000000..0fe96c64 --- /dev/null +++ b/lib/koproperty/editors/sizeedit.h @@ -0,0 +1,55 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_SIZEEDIT_H +#define KPROPERTY_SIZEEDIT_H + +#include "../widget.h" + +#include <qvariant.h> + +class KActiveLabel; + +namespace KoProperty { + +class KOPROPERTY_EXPORT SizeEdit : public Widget +{ + Q_OBJECT + + public: + SizeEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~SizeEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + private: + KActiveLabel *m_edit; + QVariant m_value; +}; + +} + +#endif diff --git a/lib/koproperty/editors/sizepolicyedit.cpp b/lib/koproperty/editors/sizepolicyedit.cpp new file mode 100644 index 00000000..c04c9579 --- /dev/null +++ b/lib/koproperty/editors/sizepolicyedit.cpp @@ -0,0 +1,122 @@ +/* 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> + + 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 "sizepolicyedit.h" +#include "editoritem.h" + +#include <qlabel.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qsizepolicy.h> +#include <qmap.h> +#include <qtooltip.h> + +#include <klocale.h> + +using namespace KoProperty; + +QMap<QString, QVariant> *SizePolicyEdit::m_spValues = 0; + +SizePolicyEdit::SizePolicyEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); +// QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new QLabel(this); + m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN); + m_edit->setBackgroundMode(Qt::PaletteBase); +// m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + setEditor(m_edit); +// l->addWidget(m_edit); + setFocusWidget(m_edit); + + + if(!m_spValues) { + m_spValues = new QMap<QString, QVariant>(); + (*m_spValues)[i18n("Size Policy", "Fixed")] = QSizePolicy::Fixed; + (*m_spValues)[i18n("Size Policy", "Minimum")] = QSizePolicy::Minimum; + (*m_spValues)[i18n("Size Policy", "Maximum")] = QSizePolicy::Maximum; + (*m_spValues)[i18n("Size Policy", "Preferred")] = QSizePolicy::Preferred; + (*m_spValues)[i18n("Size Policy", "Expanding")] = QSizePolicy::Expanding; + (*m_spValues)[i18n("Size Policy", "Minimum Expanding")] = QSizePolicy::MinimumExpanding; + (*m_spValues)[i18n("Size Policy", "Ignored")] = QSizePolicy::Ignored; + } +} + +SizePolicyEdit::~SizePolicyEdit() +{ + delete m_spValues; + m_spValues = 0; +} + +QVariant +SizePolicyEdit::value() const +{ + return m_value; +} + +void +SizePolicyEdit::setValue(const QVariant &value, bool emitChange) +{ + m_value = value; + m_edit->setText(QString("%1/%2/%3/%4").arg(findDescription(value.toSizePolicy().horData())). + arg(findDescription(value.toSizePolicy().verData())). + arg(value.toSizePolicy().horStretch()).arg(value.toSizePolicy().verStretch())); + QToolTip::add(this, m_edit->text()); + + if (emitChange) + emit valueChanged(this); +} + +void +SizePolicyEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, + QRect rect(r); + rect.setBottom(r.bottom()+1); + Widget::drawViewer(p, cg, rect, + QString("%1/%2/%3/%4").arg(findDescription(value.toSizePolicy().horData())). + arg(findDescription(value.toSizePolicy().verData())). + arg(value.toSizePolicy().horStretch()).arg(value.toSizePolicy().verStretch())); +} + +QString +SizePolicyEdit::findDescription(const QVariant &value) const +{ + if(!m_spValues) + return QString::null; + + QMap<QString, QVariant>::ConstIterator endIt = m_spValues->constEnd(); + for (QMap<QString, QVariant>::ConstIterator it = m_spValues->constBegin(); it != endIt; ++ it) { + if (it.data() == value) + return it.key(); + } + return QString::null;; +} + +void +SizePolicyEdit::setReadOnlyInternal(bool readOnly) +{ + Q_UNUSED(readOnly); +} + +#include "sizepolicyedit.moc" diff --git a/lib/koproperty/editors/sizepolicyedit.h b/lib/koproperty/editors/sizepolicyedit.h new file mode 100644 index 00000000..0edd3b38 --- /dev/null +++ b/lib/koproperty/editors/sizepolicyedit.h @@ -0,0 +1,59 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_SIZEPOLICYEDIT_H +#define KPROPERTY_SIZEPOLICYEDIT_H + +#include "../widget.h" + +#include <qvariant.h> + +template<class U, class T> class QMap; + +class QLabel; + +namespace KoProperty { + +class KOPROPERTY_EXPORT SizePolicyEdit : public Widget +{ + Q_OBJECT + + public: + SizePolicyEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~SizePolicyEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + QString findDescription(const QVariant &value) const; + + private: + QVariant m_value; + QLabel *m_edit; + static QMap<QString, QVariant> *m_spValues; +}; + +} + +#endif diff --git a/lib/koproperty/editors/spinbox.cpp b/lib/koproperty/editors/spinbox.cpp new file mode 100644 index 00000000..2e4bcc7c --- /dev/null +++ b/lib/koproperty/editors/spinbox.cpp @@ -0,0 +1,329 @@ +/* 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> + + 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 "spinbox.h" + +#include "property.h" + +#include <qlayout.h> +#include <qobjectlist.h> +#include <qvariant.h> +#include <qpainter.h> +#include <qlineedit.h> + +#include <kglobal.h> +#include <klocale.h> + +using namespace KoProperty; + +IntSpinBox::IntSpinBox(int lower, int upper, int step, int value, int base, IntEdit *parent, const char *name) +: KIntSpinBox(lower, upper, step, value, base, parent, name) +{ + editor()->setAlignment(Qt::AlignLeft); + installEventFilter(editor()); + installEventFilter(this); + QObjectList *spinwidgets = queryList( "QSpinWidget", 0, false, true ); + QSpinWidget* spin = static_cast<QSpinWidget*>(spinwidgets->first()); + if (spin) + spin->installEventFilter(this); + delete spinwidgets; +} + +void IntSpinBox::setValue(const QVariant &value) +{ + if (dynamic_cast<IntEdit*>(parentWidget()) && dynamic_cast<IntEdit*>(parentWidget())->isReadOnly()) + return; + if (value.isNull()) + editor()->clear(); + else + KIntSpinBox::setValue(value.toInt()); +} + +bool +IntSpinBox::eventFilter(QObject *o, QEvent *e) +{ + if(o == editor()) + { + if(e->type() == QEvent::KeyPress) + { + QKeyEvent* ev = static_cast<QKeyEvent*>(e); + if((ev->key()==Key_Up || ev->key()==Key_Down) && ev->state() !=ControlButton) + { + parentWidget()->eventFilter(o, e); + return true; + } + } + } + if ((o == editor() || o == this || o->parent() == this) + && e->type() == QEvent::Wheel && static_cast<IntEdit*>(parentWidget())->isReadOnly()) + { + return true; //avoid value changes for read-only widget + } + + return KIntSpinBox::eventFilter(o, e); +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +IntEdit::IntEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QVariant minVal( property ? property->option("min") : 0 ); + QVariant maxVal( property ? property->option("max") : QVariant() ); + QVariant minValueText( property ? property->option("minValueText") : QVariant() ); + if (minVal.isNull()) + minVal = 0; + if (maxVal.isNull()) + maxVal = INT_MAX; + + m_edit = new IntSpinBox(minVal.toInt(), maxVal.toInt(), 1, 0, 10, this); + if (!minValueText.isNull()) + m_edit->setSpecialValueText(minValueText.toString()); + m_edit->setMinimumHeight(5); + setEditor(m_edit); + + setLeavesTheSpaceForRevertButton(true); + setFocusWidget(m_edit); + connect(m_edit, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int))); +} + +IntEdit::~IntEdit() +{} + +QVariant +IntEdit::value() const +{ + if (m_edit->cleanText().isEmpty()) + return QVariant(); + return m_edit->value(); +} + +void +IntEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setValue(value); + updateSpinWidgets(); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +IntEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + QString valueText = value.toString(); + if (property() && property()->hasOptions()) { + //replace min value with minValueText if defined + QVariant minValue( property()->option("min") ); + QVariant minValueText( property()->option("minValueText") ); + if (!minValue.isNull() && !minValueText.isNull() && minValue.toInt() == value.toInt()) { + valueText = minValueText.toString(); + } + } + + Widget::drawViewer(p, cg, r, valueText); +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, valueText); +} + +void +IntEdit::slotValueChanged(int) +{ + emit valueChanged(this); +} + +void +IntEdit::updateSpinWidgets() +{ + QObjectList *spinwidgets = queryList( "QSpinWidget", 0, false, true ); + QSpinWidget* spin = static_cast<QSpinWidget*>(spinwidgets->first()); + if (spin) { + spin->setUpEnabled(!isReadOnly()); + spin->setDownEnabled(!isReadOnly()); + } + delete spinwidgets; +} + +void +IntEdit::setReadOnlyInternal(bool readOnly) +{ + //disable editor and spin widget + m_edit->editor()->setReadOnly(readOnly); + updateSpinWidgets(); + if (readOnly) + setLeavesTheSpaceForRevertButton(false); +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +DoubleSpinBox::DoubleSpinBox (double lower, double upper, double step, double value, int precision, DoubleEdit *parent) +: KDoubleSpinBox(lower, upper, step, value, precision, parent) +{ + editor()->setAlignment(Qt::AlignLeft); + installEventFilter(editor()); + installEventFilter(this); + QObjectList *spinwidgets = queryList( "QSpinWidget", 0, false, true ); + QSpinWidget* spin = static_cast<QSpinWidget*>(spinwidgets->first()); + if (spin) + spin->installEventFilter(this); + delete spinwidgets; +} + +bool +DoubleSpinBox::eventFilter(QObject *o, QEvent *e) +{ + if(o == editor()) + { + if(e->type() == QEvent::KeyPress) + { + QKeyEvent* ev = static_cast<QKeyEvent*>(e); + if((ev->key()==Key_Up || ev->key()==Key_Down) && ev->state()!=ControlButton) + { + parentWidget()->eventFilter(o, e); + return true; + } + } + } + if ((o == editor() || o == this || o->parent() == this) + && e->type() == QEvent::Wheel && static_cast<IntEdit*>(parentWidget())->isReadOnly()) + { + return true; //avoid value changes for read-only widget + } + + return KDoubleSpinBox::eventFilter(o, e); +} + + +void DoubleSpinBox::setValue( const QVariant& value ) +{ + if (dynamic_cast<DoubleEdit*>(parentWidget()) && dynamic_cast<DoubleEdit*>(parentWidget())->isReadOnly()) + return; + if (value.isNull()) + editor()->clear(); + else + KDoubleSpinBox::setValue(value.toDouble()); +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +DoubleEdit::DoubleEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QVariant minVal( property ? property->option("min") : 0 ); + QVariant maxVal( property ? property->option("max") : QVariant() ); + QVariant step( property ? property->option("step") : QVariant()); + QVariant precision( property ? property->option("precision") : QVariant()); + QVariant minValueText( property ? property->option("minValueText") : QVariant() ); + if (minVal.isNull()) + minVal = 0; + if (maxVal.isNull()) + maxVal = (double)(INT_MAX/100); + if(step.isNull()) + step = 0.1; + if(precision.isNull()) + precision = 2; + + m_edit = new DoubleSpinBox(minVal.toDouble(), maxVal.toDouble(), step.toDouble(), + 0, precision.toInt(), this); + if (!minValueText.isNull()) + m_edit->setSpecialValueText(minValueText.toString()); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + setEditor(m_edit); + + setLeavesTheSpaceForRevertButton(true); + setFocusWidget(m_edit); + connect(m_edit, SIGNAL(valueChanged(double)), this, SLOT(slotValueChanged(double))); +} + +DoubleEdit::~DoubleEdit() +{} + +QVariant +DoubleEdit::value() const +{ + if (m_edit->cleanText().isEmpty()) + return QVariant(); + return m_edit->value(); +} + +void +DoubleEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setValue(value); + updateSpinWidgets(); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +DoubleEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + QString valueText; + if (property() && property()->hasOptions()) { + //replace min value with minValueText if defined + QVariant minValue( property()->option("min") ); + QVariant minValueText( property()->option("minValueText") ); + if (!minValue.isNull() && !minValueText.isNull() && minValue.toString().toDouble() == value.toString().toDouble()) { + valueText = minValueText.toString(); + } + } + if (valueText.isEmpty()) + valueText = QString(value.toString()).replace('.', KGlobal::locale()->decimalSymbol()); + + Widget::drawViewer(p, cg, r, valueText); +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, valueText); +} + +void +DoubleEdit::slotValueChanged(double) +{ + emit valueChanged(this); +} + +void +DoubleEdit::updateSpinWidgets() +{ + QObjectList *spinwidgets = queryList( "QSpinWidget", 0, false, true ); + QSpinWidget* spin = static_cast<QSpinWidget*>(spinwidgets->first()); + if (spin) { + spin->setUpEnabled(!isReadOnly()); + spin->setDownEnabled(!isReadOnly()); + } + delete spinwidgets; +} + +void +DoubleEdit::setReadOnlyInternal(bool readOnly) +{ + //disable editor and spin widget + m_edit->editor()->setReadOnly(readOnly); + updateSpinWidgets(); + if (readOnly) + setLeavesTheSpaceForRevertButton(false); +} + +#include "spinbox.moc" diff --git a/lib/koproperty/editors/spinbox.h b/lib/koproperty/editors/spinbox.h new file mode 100644 index 00000000..527aae4f --- /dev/null +++ b/lib/koproperty/editors/spinbox.h @@ -0,0 +1,117 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_SPINBOX_H +#define KPROPERTY_SPINBOX_H + +#include <knuminput.h> + +#include "../widget.h" + +namespace KoProperty { + +class IntEdit; +class DoubleEdit; + +// Int Editor + +class IntSpinBox : public KIntSpinBox +{ + Q_OBJECT + + public: + IntSpinBox(int lower, int upper, int step, int value, int base=10, + IntEdit *parent=0, const char *name=0); + virtual ~IntSpinBox() {;} + + virtual void setValue(const QVariant &value); + + virtual bool eventFilter(QObject *o, QEvent *e); + QLineEdit * editor () const { return KIntSpinBox::editor(); } +}; + +class KOPROPERTY_EXPORT IntEdit : public Widget +{ + Q_OBJECT + + public: + IntEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~IntEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + void updateSpinWidgets(); + + protected slots: + void slotValueChanged(int value); + + private: + IntSpinBox *m_edit; +}; + +// Double editor + +class DoubleSpinBox : public KDoubleSpinBox +{ + Q_OBJECT + + public: + //! \todo Support setting precision limits, step, etc. + DoubleSpinBox(double lower, double upper, double step, double value=0, + int precision=2, DoubleEdit *parent=0); + virtual ~DoubleSpinBox() {;} + + virtual bool eventFilter(QObject *o, QEvent *e); + QLineEdit * editor () const { return KDoubleSpinBox::editor(); } + + public slots: + virtual void setValue( const QVariant& value ); +}; + +class KOPROPERTY_EXPORT DoubleEdit : public Widget +{ + Q_OBJECT + + public: + DoubleEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~DoubleEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + void updateSpinWidgets(); + + protected slots: + void slotValueChanged(double value); + + private: + DoubleSpinBox *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/stringedit.cpp b/lib/koproperty/editors/stringedit.cpp new file mode 100644 index 00000000..8c58b511 --- /dev/null +++ b/lib/koproperty/editors/stringedit.cpp @@ -0,0 +1,74 @@ +/* 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> + + 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 "stringedit.h" + +#include <qlayout.h> +#include <qlineedit.h> +#include <qvariant.h> + +using namespace KoProperty; + +StringEdit::StringEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new QLineEdit(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMargin(1); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + setFocusWidget(m_edit); + + connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&))); +} + +StringEdit::~StringEdit() +{} + +QVariant +StringEdit::value() const +{ + return m_edit->text(); +} + +void +StringEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setText(value.toString()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +StringEdit::slotValueChanged(const QString &) +{ + emit valueChanged(this); +} + +void +StringEdit::setReadOnlyInternal(bool readOnly) +{ + m_edit->setReadOnly(readOnly); +} + +#include "stringedit.moc" diff --git a/lib/koproperty/editors/stringedit.h b/lib/koproperty/editors/stringedit.h new file mode 100644 index 00000000..69dd45a2 --- /dev/null +++ b/lib/koproperty/editors/stringedit.h @@ -0,0 +1,53 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_STRINGEDIT_H +#define KPROPERTY_STRINGEDIT_H + +#include "../widget.h" + +class QLineEdit; + +namespace KoProperty { + +class KOPROPERTY_EXPORT StringEdit : public Widget +{ + Q_OBJECT + + public: + StringEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~StringEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void slotValueChanged(const QString&); + + protected: + QLineEdit *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/stringlistedit.cpp b/lib/koproperty/editors/stringlistedit.cpp new file mode 100644 index 00000000..44238ff9 --- /dev/null +++ b/lib/koproperty/editors/stringlistedit.cpp @@ -0,0 +1,111 @@ +/* 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> + + 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 "stringlistedit.h" + +#include <qlineedit.h> +#include <qlayout.h> +#include <qdialog.h> +#include <qpainter.h> +#include <qvariant.h> +#include <qpushbutton.h> + +#include <keditlistbox.h> +#include <kdialogbase.h> +#include <kstdguiitem.h> +#include <klocale.h> +#include <kdebug.h> + +#include "property.h" + +using namespace KoProperty; + +StringListEdit::StringListEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + + m_edit = new QLineEdit(this); + m_edit->setLineWidth(0); + m_edit->setReadOnly(true); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + m_selectButton = new QPushButton("...", this); + m_selectButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); + l->addWidget(m_selectButton); + setFocusWidget(m_selectButton); + + connect(m_selectButton, SIGNAL(clicked()), this, SLOT(showEditor())); +} + +StringListEdit::~StringListEdit() +{} + +QVariant +StringListEdit::value() const +{ + return m_list; +} + +void +StringListEdit::setValue(const QVariant &value, bool emitChange) +{ + m_list = value.toStringList(); + m_edit->setText(value.toStringList().join(", ")); + if(emitChange) + emit valueChanged(this); +} + +void +StringListEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toStringList().join(", ")); + Widget::drawViewer(p, cg, r, value.toStringList().join(", ")); +} + +void +StringListEdit::showEditor() +{ + KDialogBase dialog(this->topLevelWidget(), "stringlist_dialog", true, i18n("Edit List of Items"), + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, false); + + KEditListBox *edit = new KEditListBox(i18n("Contents of %1").arg(property()->caption()), &dialog, "editlist"); + dialog.setMainWidget(edit); + edit->insertStringList(m_list); + + if(dialog.exec() == QDialog::Accepted) + { + m_list = edit->items(); + m_edit->setText(m_list.join(", ")); + emit valueChanged(this); + } +} + +void +StringListEdit::setReadOnlyInternal(bool readOnly) +{ + m_selectButton->setEnabled(!readOnly); +} + +#include "stringlistedit.moc" diff --git a/lib/koproperty/editors/stringlistedit.h b/lib/koproperty/editors/stringlistedit.h new file mode 100644 index 00000000..0370e98a --- /dev/null +++ b/lib/koproperty/editors/stringlistedit.h @@ -0,0 +1,60 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_STRINGLISTEDIT_H +#define KPROPERTY_STRINGLISTEDIT_H + +#include "../widget.h" + +#include <qstringlist.h> + +class QLineEdit; +class QPushButton; + +namespace KoProperty { + +class KOPROPERTY_EXPORT StringListEdit : public Widget +{ + Q_OBJECT + + public: + StringListEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~StringListEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void showEditor(); + + private: + QLineEdit *m_edit; + QStringList m_list; + QPushButton *m_selectButton; +}; + +} + +#endif diff --git a/lib/koproperty/editors/symbolcombo.cpp b/lib/koproperty/editors/symbolcombo.cpp new file mode 100644 index 00000000..ee0056bd --- /dev/null +++ b/lib/koproperty/editors/symbolcombo.cpp @@ -0,0 +1,122 @@ +/* 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> + + 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 <qlineedit.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qvariant.h> + +#include <kcharselect.h> +#include <klocale.h> +#include <kdialogbase.h> + +#include "symbolcombo.h" + +using namespace KoProperty; + +SymbolCombo::SymbolCombo(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + setHasBorders(false); + QHBoxLayout *l = new QHBoxLayout(this); + + m_edit = new QLineEdit(this); + m_edit->setLineWidth(0); + m_edit->setReadOnly(true); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + m_edit->setMaxLength(1); + l->addWidget(m_edit); + m_select = new QPushButton("...", this); + m_select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); + m_select->setMinimumHeight(5); + l->addWidget(m_select); + + connect(m_select, SIGNAL(clicked()), this, SLOT(selectChar())); + connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&))); +} + +SymbolCombo::~SymbolCombo() +{} + +QVariant +SymbolCombo::value() const +{ + if (!(m_edit->text().isNull())) + return m_edit->text().at(0).unicode(); + else + return 0; +} + +void +SymbolCombo::setValue(const QVariant &value, bool emitChange) +{ +#if QT_VERSION >= 0x030100 + if (!(value.isNull())) +#else + if (value.canCast(QVariant::Int)) +#endif + { + m_edit->blockSignals(true); + m_edit->setText(QChar(value.toInt())); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); + } +} + +void +SymbolCombo::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ +// p->eraseRect(r); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, QChar(value.toInt())); + Widget::drawViewer(p, cg, r, QString( QChar(value.toInt()) )); +} + +void +SymbolCombo::selectChar() +{ + KDialogBase dialog(this->topLevelWidget(), "charselect_dialog", true, i18n("Select Char"), + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, false); + + KCharSelect *select = new KCharSelect(&dialog, "select_char"); + dialog.setMainWidget(select); + + if (!(m_edit->text().isNull())) + select->setChar(m_edit->text().at(0)); + + if (dialog.exec() == QDialog::Accepted) + m_edit->setText(select->chr()); +} + +void +SymbolCombo::slotValueChanged(const QString&) +{ + emit valueChanged(this); +} + +void +SymbolCombo::setReadOnlyInternal(bool readOnly) +{ + m_select->setEnabled(!readOnly); +} + +#include "symbolcombo.moc" diff --git a/lib/koproperty/editors/symbolcombo.h b/lib/koproperty/editors/symbolcombo.h new file mode 100644 index 00000000..5812d4a8 --- /dev/null +++ b/lib/koproperty/editors/symbolcombo.h @@ -0,0 +1,58 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_SYMBOLCOMBO_H +#define KPROPERTY_SYMBOLCOMBO_H + +#include "../widget.h" + +class QLineEdit; +class QPushButton; + +namespace KoProperty { + +class KOPROPERTY_EXPORT SymbolCombo : public Widget +{ + Q_OBJECT + + public: + SymbolCombo(Property *property, QWidget *parent=0, const char *name=0); + virtual ~SymbolCombo(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void selectChar(); + void slotValueChanged(const QString &text); + + private: + QLineEdit *m_edit; + QPushButton *m_select; +}; + +} + +#endif diff --git a/lib/koproperty/editors/timeedit.cpp b/lib/koproperty/editors/timeedit.cpp new file mode 100644 index 00000000..3d38d39b --- /dev/null +++ b/lib/koproperty/editors/timeedit.cpp @@ -0,0 +1,87 @@ +/* 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> + + 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 "timeedit.h" + +#include <qdatetimeedit.h> +#include <qrangecontrol.h> +#include <qobjectlist.h> +#include <qpainter.h> +#include <qlayout.h> +#include <qvariant.h> +#include <qdatetime.h> + +#include <klocale.h> +#include <kglobal.h> + +using namespace KoProperty; + +TimeEdit::TimeEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new QTimeEdit(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + setLeavesTheSpaceForRevertButton(true); + connect(m_edit, SIGNAL(valueChanged(const QTime&)), this, SLOT(slotValueChanged(const QTime&))); +} + +TimeEdit::~TimeEdit() +{} + +QVariant +TimeEdit::value() const +{ + return m_edit->time(); +} + +void +TimeEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setTime(value.toTime()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +TimeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) +{ + Widget::drawViewer(p, cg, r, KGlobal::locale()->formatTime(value.toTime(), true /* include sec*/)); +// p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, KGlobal::locale()->formatTime(value.toTime(), true /* include sec*/)); +} + +void +TimeEdit::slotValueChanged(const QTime&) +{ + emit valueChanged(this); +} + +void +TimeEdit::setReadOnlyInternal(bool readOnly) +{ + setVisibleFlag(!readOnly); +} + +#include "timeedit.moc" diff --git a/lib/koproperty/editors/timeedit.h b/lib/koproperty/editors/timeedit.h new file mode 100644 index 00000000..d41f4633 --- /dev/null +++ b/lib/koproperty/editors/timeedit.h @@ -0,0 +1,55 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_TIMEEDIT_H +#define KPROPERTY_TIMEEDIT_H + +#include "../widget.h" + +class QTimeEdit; + +namespace KoProperty { + +class KOPROPERTY_EXPORT TimeEdit : public Widget +{ + Q_OBJECT + + public: + TimeEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~TimeEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void slotValueChanged(const QTime &time); + + private: + QTimeEdit *m_edit; +}; + +} + +#endif diff --git a/lib/koproperty/editors/urledit.cpp b/lib/koproperty/editors/urledit.cpp new file mode 100644 index 00000000..41cd5efe --- /dev/null +++ b/lib/koproperty/editors/urledit.cpp @@ -0,0 +1,96 @@ +/* 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> + + 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 "urledit.h" + +#include <qlayout.h> +#include <qvariant.h> + +#include <kurlrequester.h> +#include <klineedit.h> + +#include "property.h" + + +using namespace KoProperty; + +URLEdit::URLEdit(Property *property, QWidget *parent, const char *name) + : Widget(property, parent, name) +{ + QHBoxLayout *l = new QHBoxLayout(this, 0, 0); + m_edit = new KURLRequester(this); + m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_edit->setMinimumHeight(5); + l->addWidget(m_edit); + + setProperty(property); + + connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&))); + m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); +} + +URLEdit::~URLEdit() +{} + +QVariant +URLEdit::value() const +{ + return m_edit->url(); +} + +void +URLEdit::setValue(const QVariant &value, bool emitChange) +{ + m_edit->blockSignals(true); + m_edit->setURL(value.toString()); + m_edit->blockSignals(false); + if (emitChange) + emit valueChanged(this); +} + +void +URLEdit::slotValueChanged(const QString&) +{ + emit valueChanged(this); +} + +void +URLEdit::setProperty(Property *property) +{ + int mode; + if(property) { + switch(property->type()) { + case DirectoryURL: mode = KFile::Directory|KFile::ExistingOnly; break; + case FileURL: case PictureFileURL: default: mode = KFile::File|KFile::ExistingOnly; + } + m_edit->setMode(mode); + } + + Widget::setProperty(property); +} + +void +URLEdit::setReadOnlyInternal(bool readOnly) +{ + m_edit->lineEdit()->setReadOnly(readOnly); + m_edit->button()->setEnabled(!readOnly); +} + +#include "urledit.moc" diff --git a/lib/koproperty/editors/urledit.h b/lib/koproperty/editors/urledit.h new file mode 100644 index 00000000..7bebf7b1 --- /dev/null +++ b/lib/koproperty/editors/urledit.h @@ -0,0 +1,55 @@ +/* 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> + + 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. +*/ + +#ifndef KPROPERTY_URLEDIT_H +#define KPROPERTY_URLEDIT_H + +#include "../widget.h" + +class KURLRequester; + +namespace KoProperty { + +class KOPROPERTY_EXPORT URLEdit : public Widget +{ + Q_OBJECT + + public: + URLEdit(Property *property, QWidget *parent=0, const char *name=0); + virtual ~URLEdit(); + + virtual QVariant value() const; + virtual void setValue(const QVariant &value, bool emitChange=true); + + virtual void setProperty(Property *property); + + protected: + virtual void setReadOnlyInternal(bool readOnly); + + protected slots: + void slotValueChanged(const QString &url); + + private: + KURLRequester *m_edit; +}; + +} + +#endif |