⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpropertyeditor_items.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qpropertyeditor_items_p.h"#include "flagbox_p.h"#include "paletteeditorbutton.h"#include "defs.h"#include <QtDesigner/propertysheet.h>#include <qdesigner_utils_p.h>#include <QtGui/QLineEdit>#include <QtGui/QListView>#include <QtGui/QComboBox>#include <QtGui/QSpinBox>#include <QtGui/QValidator>#include <QtGui/QFontDatabase>#include <QtGui/QPainter>#include <QtGui/QDateTimeEdit>#include <QtGui/QBitmap>#include <QtGui/QLabel>#include <QtCore/qdebug.h>#include <limits.h>using namespace qdesigner_internal;Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)void IProperty::setDirty(bool b){    if (isFake()) {        IProperty *p = parent();        while (p != 0 && p->isFake())            p = p->parent();        if (p != 0)            p->setDirty(true);    } else {        m_dirty = b;    }}void IProperty::setChanged(bool b){    if (isFake()) {        IProperty *p = parent();        while (p != 0 && p->isFake())            p = p->parent();        if (p != 0)            p->setChanged(true);    } else {        m_changed = b;    }    setDirty(true);}// -------------------------------------------------------------------------QWidget *AbstractPropertyGroup::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    Q_UNUSED(target);    Q_UNUSED(receiver);    QLabel *label = new QLabel(parent);    label->setIndent(2); // ### hardcode it should have the same value of textMargin in QItemDelegate    label->setBackgroundRole(QPalette::Base);    return label;}void AbstractPropertyGroup::updateEditorContents(QWidget *editor){    QLabel *label = qobject_cast<QLabel*>(editor);    if (label == 0)        return;    label->setText(toString());}// -------------------------------------------------------------------------BoolProperty::BoolProperty(bool value, const QString &name)    : AbstractProperty<bool>(value, name){}void BoolProperty::setValue(const QVariant &value){    m_value = value.toBool();}QString BoolProperty::toString() const{    return m_value ? QLatin1String("true") : QLatin1String("false");}QWidget *BoolProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QComboBox *combo = new QComboBox(parent);    combo->view()->setTextElideMode(Qt::ElideLeft);    combo->setFrame(0);    combo->addItems(QStringList() << QString::fromUtf8("false") << QString::fromUtf8("true"));    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);    return combo;}void BoolProperty::updateEditorContents(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        combo->setCurrentIndex(m_value ? 1 : 0);    }}void BoolProperty::updateValue(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        bool newValue = combo->currentIndex() ? true : false;        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------PointProperty::PointProperty(const QPoint &value, const QString &name)    : AbstractPropertyGroup(name){    IProperty *px = new IntProperty(value.x(), QLatin1String("x"));    px->setFake(true);    px->setParent(this);    IProperty *py = new IntProperty(value.y(), QLatin1String("y"));    py->setFake(true);    py->setParent(this);    m_properties << px << py;}QVariant PointProperty::value() const{    return QPoint(propertyAt(0)->value().toInt(),                  propertyAt(1)->value().toInt());}void PointProperty::setValue(const QVariant &value){    QPoint pt = value.toPoint();    propertyAt(0)->setValue(pt.x());    propertyAt(1)->setValue(pt.y());}// -------------------------------------------------------------------------PropertyCollection::PropertyCollection(const QString &name)    : m_name(name){}PropertyCollection::~PropertyCollection(){    qDeleteAll(m_properties);}void PropertyCollection::addProperty(IProperty *property){    property->setParent(this);    m_properties.append(property);}void PropertyCollection::removeProperty(IProperty *property){    Q_UNUSED(property);}int PropertyCollection::indexOf(IProperty *property) const{    return m_properties.indexOf(property);}int PropertyCollection::propertyCount() const{    return m_properties.size();}IProperty *PropertyCollection::propertyAt(int index) const{    return m_properties.at(index);}QString PropertyCollection::propertyName() const{    return m_name;}QVariant PropertyCollection::value() const{    return QVariant();}void PropertyCollection::setValue(const QVariant &value){    Q_UNUSED(value);}QString PropertyCollection::toString() const{    return QString();}bool PropertyCollection::hasEditor() const{    return false;}QWidget *PropertyCollection::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    Q_UNUSED(parent);    Q_UNUSED(target);    Q_UNUSED(receiver);    return 0;}bool PropertyCollection::hasExternalEditor() const{    return false;}QWidget *PropertyCollection::createExternalEditor(QWidget *parent){    Q_UNUSED(parent);    return 0;}// -------------------------------------------------------------------------StringProperty::StringProperty(const QString &value, const QString &name, bool hasComment, const QString &comment)    : AbstractPropertyGroup(name),      m_value(value),      m_checkValidObjectName(false),      m_allowScope(false){    if (hasComment) {        StringProperty *pcomment = new StringProperty(comment, QLatin1String("comment"));        pcomment->setParent(this);        m_properties << pcomment;    }}bool StringProperty::checkValidObjectName() const{    return m_checkValidObjectName;}void StringProperty::setCheckValidObjectName(bool b){    m_checkValidObjectName = b;}bool StringProperty::allowScope() const{    return m_allowScope;}void StringProperty::setAllowScope(bool b){    m_allowScope = b;}QVariant StringProperty::value() const{    return m_value;}void StringProperty::setValue(const QVariant &value){    m_value = value.toString();}QString StringProperty::toString() const{    return m_value;}bool StringProperty::hasEditor() const{    return true;}QWidget *StringProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    if (checkValidObjectName()) {        QString rx = allowScope() ? QString("[_a-zA-Z:][_a-zA-Z0-9:]*") : QString("[_a-zA-Z][_a-zA-Z0-9]*");        lineEdit->setValidator(new QRegExpValidator(QRegExp(rx), lineEdit));    }    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void StringProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        if (lineEdit->text() != m_value)            lineEdit->setText(m_value);    }}void StringProperty::updateValue(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        QString newValue = lineEdit->text();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------ListProperty::ListProperty(const QStringList &items, int value, const QString &name)    : AbstractProperty<int>(value, name), m_items(items){}QStringList ListProperty::items() const{    return m_items;}void ListProperty::setValue(const QVariant &value){    m_value = value.toInt();}QString ListProperty::toString() const{    if (m_items.isEmpty())        return QString();    else if (m_value < 0 || m_value >= m_items.count())        return m_items.first();    return m_items.at(m_value);}QWidget *ListProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QComboBox *combo = new QComboBox(parent);    combo->view()->setTextElideMode(Qt::ElideLeft);    combo->setFrame(0);    combo->addItems(items());    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);    return combo;}void ListProperty::updateEditorContents(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        combo->setCurrentIndex(m_value);    }}void ListProperty::updateValue(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        int newValue = combo->currentIndex();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------SizeProperty::SizeProperty(const QSize &value, const QString &name)    : AbstractPropertyGroup(name){    IntProperty *pw = new IntProperty(value.width(), QLatin1String("width"));    pw->setFake(true);    pw->setParent(this);    pw->setRange(0, INT_MAX);    IntProperty *ph = new IntProperty(value.height(), QLatin1String("height"));    ph->setFake(true);    ph->setParent(this);    ph->setRange(0, INT_MAX);    m_properties << pw << ph;}QVariant SizeProperty::value() const{    return QSize(propertyAt(0)->value().toInt(),                 propertyAt(1)->value().toInt());}void SizeProperty::setValue(const QVariant &value){    QSize pt = value.toSize();    propertyAt(0)->setValue(pt.width());    propertyAt(1)->setValue(pt.height());}// -------------------------------------------------------------------------// QIntPropertySpinBox also emits editingFinished when the spinbox is usedclass QIntPropertySpinBox: public QSpinBox{public:    QIntPropertySpinBox(QWidget *parent = 0)        : QSpinBox(parent) { }    void stepBy(int steps)    {        QSpinBox::stepBy(steps);        emit editingFinished();    }};IntProperty::IntProperty(int value, const QString &name)    : AbstractProperty<int>(value, name), m_low(INT_MIN), m_hi(INT_MAX){}void IntProperty::setRange(int low, int hi){    m_low = low;    m_hi = hi;}QString IntProperty::specialValue() const{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -