diff --git a/src/KPropertyFactory.cpp b/src/KPropertyFactory.cpp index 2f53c23..7377b9d 100644 --- a/src/KPropertyFactory.cpp +++ b/src/KPropertyFactory.cpp @@ -1,174 +1,190 @@ /* This file is part of the KDE project Copyright (C) 2008-2015 Jarosław Staniek 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 "KPropertyFactory.h" //--------------- //! @internal class KPropertyFactoryManager::Private { public: Private() { } ~Private() { qDeleteAll(factories); } QSet factories; QHash composedPropertyCreators; }; - Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) +Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) //! @internal class KPropertyFactory::Private { public: Private() { } ~Private() { } QHash composedPropertyCreators; QSet composedPropertyCreatorsSet; }; +typedef QList InitFunctions; +//! @internal Used by KPropertyFactoryManager::addInitFunction() +Q_GLOBAL_STATIC(InitFunctions, _initFunctions) + KPropertyFactory::KPropertyFactory() : d( new Private ) { } KPropertyFactory::~KPropertyFactory() { delete d; } QHash KPropertyFactory::composedPropertyCreators() const { return d->composedPropertyCreators; } void KPropertyFactory::addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ) { addComposedPropertyCreatorInternal( type, creator, true ); } void KPropertyFactory::addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own) { if (own) d->composedPropertyCreatorsSet.insert(creator); d->composedPropertyCreators.insert(type, creator); } //------------ KPropertyFactoryManager::KPropertyFactoryManager() : QObject(0) , d(new Private) { setObjectName(QLatin1String("KPropertyFactoryManager")); - //TODO ??? registerFactory(new KDefaultPropertyFactory); - } KPropertyFactoryManager::~KPropertyFactoryManager() { delete d; } KPropertyFactoryManager* KPropertyFactoryManager::self() { + if (_self.exists()) { // avoid recursion: initFunctions below may call self() + return _self; + } + _self(); // KPropertyFactoryManager should exist as initFunctions may need it + foreach(void (*initFunction)(), *_initFunctions) { + initFunction(); + } + _initFunctions->clear(); return _self; } void KPropertyFactoryManager::registerFactory(KPropertyFactory *factory) { d->factories.insert(factory); QHash::ConstIterator composedPropertyCreatorsItEnd = factory->composedPropertyCreators().constEnd(); for (QHash::ConstIterator it( factory->composedPropertyCreators().constBegin() ); it != composedPropertyCreatorsItEnd; ++it) { d->composedPropertyCreators.insert(it.key(), it.value()); } } KComposedPropertyInterface* KPropertyFactoryManager::createComposedProperty(KProperty *parent) { const KComposedPropertyCreatorInterface *creator = d->composedPropertyCreators.value( parent->type() ); return creator ? creator->createComposedProperty(parent) : 0; } +//static +void KPropertyFactoryManager::addInitFunction(void (*initFunction)()) +{ + _initFunctions->append(initFunction); +} + //! @todo #if 0 const int type = parent->type(); /* CustomPropertyFactory *factory = d->registeredWidgets[type]; if (factory) return factory->createCustomProperty(parent); */ switch (type) { case Size: case Size_Width: case Size_Height: return new SizeCustomProperty(parent); case Point: case Point_X: case Point_Y: return new PointCustomProperty(parent); case Rect: case Rect_X: case Rect_Y: case Rect_Width: case Rect_Height: return new RectCustomProperty(parent); case SizePolicy: /* case SizePolicy_HorizontalStretch: case SizePolicy_VerticalStretch: case SizePolicy_HorizontalPolicy: case SizePolicy_VerticalPolicy:*/ return new SizePolicyCustomProperty(parent); default:; } return 0; #endif KComposedPropertyInterface::KComposedPropertyInterface(KProperty *parent) : m_childValueChangedEnabled(true) { Q_UNUSED(parent) } KComposedPropertyInterface::~KComposedPropertyInterface() { } KComposedPropertyCreatorInterface::KComposedPropertyCreatorInterface() { } KComposedPropertyCreatorInterface::~KComposedPropertyCreatorInterface() { } diff --git a/src/KPropertyFactory.h b/src/KPropertyFactory.h index 1ac1b1b..6d37fbb 100644 --- a/src/KPropertyFactory.h +++ b/src/KPropertyFactory.h @@ -1,134 +1,139 @@ /* This file is part of the KDE project Copyright (C) 2008-2015 Jarosław Staniek 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_FACTORY_H #define KPROPERTY_FACTORY_H #include "KProperty.h" #include #include #include //! An interface for for composed property handlers /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n In the constructor, you should create the child properties (if needed). Then, you need to implement the functions concerning values.\n Example implementation of composed properties can be found in editors/ directory. */ class KPROPERTYCORE_EXPORT KComposedPropertyInterface { public: explicit KComposedPropertyInterface(KProperty *parent); virtual ~KComposedPropertyInterface(); /*! This function modifies the child properties for parent value @a value. It is called by @ref Property::setValue() when the property is composed. You don't have to modify the property value, it is done by Property class. Note that when calling Property::setValue, you need to set useComposedProperty (the third parameter) to false, or there will be infinite recursion. */ virtual void setValue(KProperty *property, const QVariant &value, bool rememberOldValue) = 0; void childValueChangedInternal(KProperty *child, const QVariant &value, bool rememberOldValue) { if (m_childValueChangedEnabled) childValueChanged(child, value, rememberOldValue); } void setChildValueChangedEnabled(bool set) { m_childValueChangedEnabled = set; } /*! @return true if values @a first and @a second are equal. Used in KProperty::setValue() to check if value has been changed before setting value. Default implementation uses operator==. */ inline virtual bool valuesEqual(const QVariant &first, const QVariant &second) { return first == second; } protected: virtual void childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) = 0; /*! This method emits the \a Set::propertyChanged() signal for all sets our parent-property is registered in. */ void emitPropertyChanged(); bool m_childValueChangedEnabled : 1; }; class KPROPERTYCORE_EXPORT KComposedPropertyCreatorInterface { public: KComposedPropertyCreatorInterface(); virtual ~KComposedPropertyCreatorInterface(); virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; }; //! Creator returning composed property object template class KComposedPropertyCreator : public KComposedPropertyCreatorInterface { public: KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} virtual ~KComposedPropertyCreator() {} virtual ComposedProperty* createComposedProperty(KProperty *parent) const { return new ComposedProperty(parent); } }; class KPROPERTYCORE_EXPORT KPropertyFactory { public: KPropertyFactory(); virtual ~KPropertyFactory(); QHash composedPropertyCreators() const; void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); protected: void addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own = true); class Private; Private * const d; }; class KProperty; class KCustomProperty; class KPROPERTYCORE_EXPORT KPropertyFactoryManager : public QObject { Q_OBJECT public: KComposedPropertyInterface* createComposedProperty(KProperty *parent); //! Registers factory @a factory. It becomes owned by the manager. void registerFactory(KPropertyFactory *factory); /*! \return a pointer to a factory manager instance.*/ static KPropertyFactoryManager* self(); KPropertyFactoryManager(); ~KPropertyFactoryManager(); + + //! Adds function @a initFunction that will be called after the manager is created. + //! Useful for creation custom factories. + static void addInitFunction(void (*initFunction)()); + private: class Private; Private * const d; }; #endif diff --git a/src/KPropertyWidgetsFactory.cpp b/src/KPropertyWidgetsFactory.cpp index 6299234..db3c25f 100644 --- a/src/KPropertyWidgetsFactory.cpp +++ b/src/KPropertyWidgetsFactory.cpp @@ -1,392 +1,398 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek 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 "KPropertyFactory.h" #include "KDefaultPropertyFactory.h" #include "KPropertyEditorView.h" #include "KPropertyEditorDataModel.h" KPropertyLabel::KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface) : QLabel(parent) , m_iface(iface) { setAutoFillBackground(true); setContentsMargins(0,1,0,0); setIndent(1); } QVariant KPropertyLabel::value() const { return m_value; } void KPropertyLabel::setValue(const QVariant& value) { setText( m_iface->displayText(value) ); m_value = value; } void KPropertyLabel::paintEvent( QPaintEvent * event ) { QLabel::paintEvent(event); KPropertyWidgetsFactory::paintTopGridLine(this); } //--------------- //! @internal class KPropertyWidgetsFactoryManager::Private { public: Private() { } ~Private() { - qDeleteAll(factories); } - QSet factories; QHash editorCreators; QHash valuePainters; QHash valueDisplays; - }; - Q_GLOBAL_STATIC(KPropertyWidgetsFactoryManager, _self) +Q_GLOBAL_STATIC(KPropertyWidgetsFactoryManager, _self) + +//! @internal Make sure sure the KPropertyWidgetsFactoryManager is created after +//! KPropertyFactoryManager (delayed). Unless KPropertyFactoryManager is created, +//! KPropertyWidgetsFactoryManager isn't created. +//! @todo is this worth putting in a reusable macro? +struct KPropertyWidgetsFactoryManagerInitializer { + KPropertyWidgetsFactoryManagerInitializer() { + KPropertyFactoryManager::addInitFunction(&initMe); + } + static void initMe() { KPropertyWidgetsFactoryManager::self(); } +}; +KPropertyWidgetsFactoryManagerInitializer init; //! @internal class KPropertyWidgetsFactory::Private { public: Private() { } ~Private() { qDeleteAll(editorCreatorsSet); qDeleteAll(valuePaintersSet); qDeleteAll(valueDisplaysSet); } QHash editorCreators; QHash valuePainters; QHash valueDisplays; QSet editorCreatorsSet; QSet valuePaintersSet; QSet valueDisplaysSet; - }; KPropertyWidgetsFactory::KPropertyWidgetsFactory() : d( new Private ) { } KPropertyWidgetsFactory::~KPropertyWidgetsFactory() { delete d; } QHash KPropertyWidgetsFactory::editorCreators() const { return d->editorCreators; } QHash KPropertyWidgetsFactory::valuePainters() const { return d->valuePainters; } QHash KPropertyWidgetsFactory::valueDisplays() const { return d->valueDisplays; } void KPropertyWidgetsFactory::addEditor(int type, KPropertyEditorCreatorInterface *creator) { addEditorInternal( type, creator, true ); if (dynamic_cast(creator)) { addComposedPropertyCreatorInternal( type, dynamic_cast(creator), false/* !own*/ ); } if (dynamic_cast(creator)) { addPainterInternal( type, dynamic_cast(creator), false/* !own*/ ); } if (dynamic_cast(creator)) { addDisplayInternal( type, dynamic_cast(creator), false/* !own*/ ); } } void KPropertyWidgetsFactory::addPainter(int type, KPropertyValuePainterInterface *painter) { addPainterInternal(type, painter, true); if (dynamic_cast(painter)) { addComposedPropertyCreatorInternal( type, dynamic_cast(painter), false/* !own*/ ); } if (dynamic_cast(painter)) { addEditorInternal( type, dynamic_cast(painter), false/* !own*/ ); } if (dynamic_cast(painter)) { addDisplayInternal( type, dynamic_cast(painter), false/* !own*/ ); } } void KPropertyWidgetsFactory::addDisplay(int type, KPropertyValueDisplayInterface *display) { addDisplayInternal(type, display, true); if (dynamic_cast(display)) { addComposedPropertyCreatorInternal( type, dynamic_cast(display), false/* !own*/ ); } if (dynamic_cast(display)) { addEditorInternal( type, dynamic_cast(display), false/* !own*/ ); } if (dynamic_cast(display)) { addDisplayInternal( type, dynamic_cast(display), false/* !own*/ ); } } void KPropertyWidgetsFactory::addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own) { if (own) d->editorCreatorsSet.insert(editor); d->editorCreators.insert(type, editor); } void KPropertyWidgetsFactory::addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own) { if (own) d->valuePaintersSet.insert(painter); d->valuePainters.insert(type, painter); } void KPropertyWidgetsFactory::addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own) { if (own) d->valueDisplaysSet.insert(display); d->valueDisplays.insert(type, display); } //static void KPropertyWidgetsFactory::paintTopGridLine(QWidget *widget) { // paint top grid line QPainter p(widget); QColor gridLineColor( dynamic_cast(widget->parentWidget()) ? dynamic_cast(widget->parentWidget())->gridLineColor() : KPropertyEditorView::defaultGridLineColor() ); p.setPen(QPen( QBrush(gridLineColor), 1)); p.drawLine(0, 0, widget->width()-1, 0); } //static void KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, const QString& extraStyleSheet) { QColor gridLineColor( dynamic_cast(parent) ? dynamic_cast(parent)->gridLineColor() : KPropertyEditorView::defaultGridLineColor() ); widget->setStyleSheet( QString::fromLatin1("%1 { border-top: 1px solid %2;border-bottom: 1px solid %2; } %3") .arg(QLatin1String(widget->metaObject()->className())) .arg(gridLineColor.name()).arg(extraStyleSheet)); } //------------ KPropertyWidgetsFactoryManager::KPropertyWidgetsFactoryManager() - : KPropertyFactoryManager() - , d(new Private) + : d(new Private) { - setObjectName(QLatin1String("KPropertyWidgetsFactoryManager")); registerFactory(new KDefaultPropertyFactory); } KPropertyWidgetsFactoryManager::~KPropertyWidgetsFactoryManager() { delete d; } KPropertyWidgetsFactoryManager* KPropertyWidgetsFactoryManager::self() { return _self; } void KPropertyWidgetsFactoryManager::registerFactory(KPropertyWidgetsFactory *factory) { - d->factories.insert(factory); + KPropertyFactoryManager::self()->registerFactory(factory); QHash::ConstIterator editorCreatorsItEnd = factory->editorCreators().constEnd(); for (QHash::ConstIterator it( factory->editorCreators().constBegin() ); it != editorCreatorsItEnd; ++it) { d->editorCreators.insert(it.key(), it.value()); } QHash::ConstIterator valuePaintersItEnd = factory->valuePainters().constEnd(); for (QHash::ConstIterator it( factory->valuePainters().constBegin() ); it != valuePaintersItEnd; ++it) { d->valuePainters.insert(it.key(), it.value()); } QHash::ConstIterator valueDisplaysItEnd = factory->valueDisplays().constEnd(); for (QHash::ConstIterator it( factory->valueDisplays().constBegin() ); it != valueDisplaysItEnd; ++it) { d->valueDisplays.insert(it.key(), it.value()); } } bool KPropertyWidgetsFactoryManager::isEditorForTypeAvailable( int type ) const { return d->editorCreators.value(type); } QWidget * KPropertyWidgetsFactoryManager::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { const KPropertyEditorCreatorInterface *creator = d->editorCreators.value(type); if (!creator) return 0; QWidget *w = creator->createEditor(type, parent, option, index); if (w) { const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *property = editorModel->propertyForItem(index); w->setObjectName(QLatin1String(property->name())); if (creator->options.removeBorders) { //! @todo get real border color from the palette QColor gridLineColor( dynamic_cast(parent) ? dynamic_cast(parent)->gridLineColor() : KPropertyEditorView::defaultGridLineColor() ); QString cssClassName = QLatin1String(w->metaObject()->className()); cssClassName.replace(QLatin1String("KProperty"), QString()); //!< @todo QString css = QString::fromLatin1("%1 { border-top: 1px solid %2; } ") .arg(cssClassName).arg(gridLineColor.name()); // kprDebug() << css; w->setStyleSheet(css); } } return w; } bool KPropertyWidgetsFactoryManager::paint( int type, QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { const KPropertyValuePainterInterface *_painter = d->valuePainters.value(type); if (!_painter) return false; QStyleOptionViewItem realOption(option); if (option.state & QStyle::State_Selected) { // paint background because there may be editor widget with no autoFillBackground set realOption.palette.setBrush(QPalette::Text, realOption.palette.highlightedText()); painter->fillRect(realOption.rect, realOption.palette.highlight()); } painter->setPen(realOption.palette.text().color()); _painter->paint(painter, realOption, index); return true; } bool KPropertyWidgetsFactoryManager::canConvertValueToText( int type ) const { return d->valueDisplays.value(type) != 0; } bool KPropertyWidgetsFactoryManager::canConvertValueToText( const KProperty* property ) const { return d->valueDisplays.value( property->type() ) != 0; } QString KPropertyWidgetsFactoryManager::convertValueToText( const KProperty* property ) const { const KPropertyValueDisplayInterface *display = d->valueDisplays.value( property->type() ); return display ? display->displayTextForProperty( property ) : property->value().toString(); } //! @todo #if 0 const int type = parent->type(); /* CustomPropertyFactory *factory = d->registeredWidgets[type]; if (factory) return factory->createCustomProperty(parent); */ switch (type) { case Size: case Size_Width: case Size_Height: return new SizeCustomProperty(parent); case Point: case Point_X: case Point_Y: return new PointCustomProperty(parent); case Rect: case Rect_X: case Rect_Y: case Rect_Width: case Rect_Height: return new RectCustomProperty(parent); case SizePolicy: /* case SizePolicy_HorizontalStretch: case SizePolicy_VerticalStretch: case SizePolicy_HorizontalPolicy: case SizePolicy_VerticalPolicy:*/ return new SizePolicyCustomProperty(parent); default:; } return 0; #endif KPropertyEditorCreatorInterface::KPropertyEditorCreatorInterface() { } KPropertyEditorCreatorInterface::~KPropertyEditorCreatorInterface() { } KPropertyEditorCreatorInterface::Options::Options() : removeBorders(true) { } KPropertyValuePainterInterface::KPropertyValuePainterInterface() { } KPropertyValuePainterInterface::~KPropertyValuePainterInterface() { } KPropertyValueDisplayInterface::KPropertyValueDisplayInterface() { } KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() { } diff --git a/src/KPropertyWidgetsFactory.h b/src/KPropertyWidgetsFactory.h index c6614bb..ef0d7b5 100644 --- a/src/KPropertyWidgetsFactory.h +++ b/src/KPropertyWidgetsFactory.h @@ -1,223 +1,217 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek 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 KPROPERTYWIDGETS_FACTORY_H #define KPROPERTYWIDGETS_FACTORY_H #include "kpropertywidgets_export.h" #include "KProperty.h" #include "KPropertyFactory.h" #include #include #include - #include #include #include //! An interface for editor widget creators. /*! Options can be set in the options attribute in order to customize widget creation process. Do this in the EditorCreatorInterface constructor. */ class KPROPERTYWIDGETS_EXPORT KPropertyEditorCreatorInterface { public: KPropertyEditorCreatorInterface(); virtual ~KPropertyEditorCreatorInterface(); virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; /*! Options for altering the editor widget creation process, used by KPropertyFactoryManager::createEditor(). */ class Options { public: Options(); /*! In order to have better look of the widget within the property editor view, we usually remove borders from the widget (see FactoryManager::createEditor()). and adding 1 pixel 'gray border' on the top. Default value is true. */ bool removeBorders; }; //! Options for altering the editor widget creation process Options options; }; class KPROPERTYWIDGETS_EXPORT KPropertyValuePainterInterface { public: KPropertyValuePainterInterface(); virtual ~KPropertyValuePainterInterface(); virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; }; class KPROPERTYWIDGETS_EXPORT KPropertyValueDisplayInterface { public: KPropertyValueDisplayInterface(); virtual ~KPropertyValueDisplayInterface(); virtual QString displayTextForProperty( const KProperty* property ) const { return displayText(property->value()); } virtual QString displayText( const QVariant& value ) const { return value.toString(); } }; //! Label widget that can be used for displaying text-based read-only items //! Used in LabelCreator. class KPROPERTYWIDGETS_EXPORT KPropertyLabel : public QLabel { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface); QVariant value() const; Q_SIGNALS: void commitData( QWidget * editor ); public Q_SLOTS: void setValue(const QVariant& value); protected: virtual void paintEvent( QPaintEvent * event ); private: const KPropertyValueDisplayInterface *m_iface; QVariant m_value; }; //! Creator returning editor template class KPROPERTYWIDGETS_EXPORT KPropertyEditorCreator : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface, public KPropertyValuePainterInterface { public: KPropertyEditorCreator() : KPropertyEditorCreatorInterface() {} virtual ~KPropertyEditorCreator() {} virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); Q_UNUSED(index); return new Widget(parent, this); } virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->save(); QRect r(option.rect); r.setLeft(r.left()+1); painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, displayText( index.data(Qt::EditRole) ) ); painter->restore(); } }; typedef KPropertyEditorCreator KPropertyLabelCreator; class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactory : public KPropertyFactory { public: KPropertyWidgetsFactory(); virtual ~KPropertyWidgetsFactory(); QHash editorCreators() const; QHash valuePainters() const; QHash valueDisplays() const; //! Adds editor creator @a creator for type @a type. //! The creator becomes owned by the factory. void addEditor(int type, KPropertyEditorCreatorInterface *creator); void addPainter(int type, KPropertyValuePainterInterface *painter); void addDisplay(int type, KPropertyValueDisplayInterface *display); static void paintTopGridLine(QWidget *widget); static void setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, const QString& extraStyleSheet = QString()); protected: void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); //! Adds value painter @a painter for type @a type. //! The painter becomes owned by the factory. void addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own = true); //! Adds value-to-text converted @a painter for type @a type. //! The converter becomes owned by the factory. void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); class Private; Private * const d; }; class KProperty; class KCustomProperty; -class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactoryManager : public KPropertyFactoryManager +class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactoryManager { - Q_OBJECT public: bool isEditorForTypeAvailable( int type ) const; QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; bool paint( int type, QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; - KComposedPropertyInterface* createComposedProperty(KProperty *parent); - bool canConvertValueToText( int type ) const; bool canConvertValueToText( const KProperty* property ) const; QString convertValueToText( const KProperty* property ) const; //! Registers factory @a factory. It becomes owned by the manager. void registerFactory(KPropertyWidgetsFactory *factory); - KCustomProperty* createCustomProperty( KProperty *parent ); - /*! \return a pointer to a factory manager instance.*/ static KPropertyWidgetsFactoryManager* self(); KPropertyWidgetsFactoryManager(); ~KPropertyWidgetsFactoryManager(); private: class Private; Private * const d; }; #endif