git-svn-id: svn://db.shs.com.ru/libs@626 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
77
qglengine/widgets/propertyeditor.h
Normal file
77
qglengine/widgets/propertyeditor.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef PROPERTYEDITOR_H
|
||||
#define PROPERTYEDITOR_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QMetaProperty>
|
||||
#include <QEvent>
|
||||
#include <QDebug>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <qpiconfigwidget.h>
|
||||
|
||||
|
||||
class Delegate: public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Delegate(QObject * parent = 0): QStyledItemDelegate() {ab = QBrush(QImage(":/icons/alpha.png"));}
|
||||
|
||||
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {cmi = const_cast<QModelIndex & >(index); return widgetForProperty(parent, index);}
|
||||
void setEditorData(QWidget * editor, const QModelIndex & index) const {setWidgetProperty(editor, index.data(Qt::UserRole));}
|
||||
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
|
||||
void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {editor->setGeometry(option.rect);}
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
|
||||
private:
|
||||
QWidget * widgetForProperty(QWidget * parent, const QModelIndex & index) const;
|
||||
void setWidgetProperty(QWidget * w, const QVariant & value) const;
|
||||
const QVariant widgetProperty(QWidget * w) const;
|
||||
QString pointString(const QPoint & p) const {return QString::number(p.x()) + " x " + QString::number(p.y());}
|
||||
QString pointString(const QPointF & p) const {return QString::number(p.x()) + " x " + QString::number(p.y());}
|
||||
QString rectString(const QRect & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " +
|
||||
QString::number(r.width()) + " x " + QString::number(r.height());}
|
||||
QString rectString(const QRectF & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " +
|
||||
QString::number(r.width()) + " x " + QString::number(r.height());}
|
||||
|
||||
QBrush ab;
|
||||
mutable QModelIndex cmi;
|
||||
|
||||
private slots:
|
||||
void changed() {setModelData((QWidget * )sender(), const_cast<QAbstractItemModel * >(cmi.model()), cmi);}
|
||||
void changedFlag();
|
||||
|
||||
};
|
||||
|
||||
typedef QPair<QMetaProperty, QVariant> PropertyValuePair;
|
||||
Q_DECLARE_METATYPE (PropertyValuePair)
|
||||
Q_DECLARE_METATYPE (QMetaProperty)
|
||||
|
||||
class PropertyEditor: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PropertyEditor(QWidget * parent = 0);
|
||||
virtual ~PropertyEditor();
|
||||
|
||||
void assignObject(QObject * o) {object = o; rebuild();}
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e);
|
||||
|
||||
private:
|
||||
void configTree();
|
||||
void setItemBackColor(QTreeWidgetItem * i, const QColor & c) {i->setBackgroundColor(0, c); i->setBackgroundColor(1, c);}
|
||||
void setItemForeColor(QTreeWidgetItem * i, const QColor & c) {i->setForeground(0, c); i->setForeground(1, c);}
|
||||
void rebuild();
|
||||
void refresh();
|
||||
|
||||
QObject * object;
|
||||
QFont font_b;
|
||||
QList<QMetaProperty> props;
|
||||
bool active_;
|
||||
|
||||
private slots:
|
||||
void itemClicked(QTreeWidgetItem * item, int column);
|
||||
void itemChanged(QTreeWidgetItem * item, int column);
|
||||
|
||||
};
|
||||
|
||||
#endif // PROPERTYEDITOR_H
|
||||
Reference in New Issue
Block a user