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

📄 qpropertyeditor_items.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    return m_specialValue;}void IntProperty::setSpecialValue(const QString &specialValue){    m_specialValue = specialValue;}void IntProperty::setValue(const QVariant &value){    m_value = value.toInt();}QString IntProperty::toString() const{    return QString::number(m_value);}QWidget *IntProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QSpinBox *spinBox = new QIntPropertySpinBox(parent);    spinBox->setFrame(0);    spinBox->setSpecialValueText(m_specialValue);    spinBox->setRange(m_low, m_hi);    spinBox->setValue(m_value);    spinBox->selectAll();    QObject::connect(spinBox, SIGNAL(editingFinished()), target, receiver);    return spinBox;}void IntProperty::updateEditorContents(QWidget *editor){    if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(editor)) {        spinBox->setValue(m_value);    }}void IntProperty::updateValue(QWidget *editor){    if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(editor)) {        int newValue = spinBox->value();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------RectProperty::RectProperty(const QRect &value, const QString &name)    : AbstractPropertyGroup(name){    IntProperty *px = new IntProperty(value.x(), QLatin1String("x"));    px->setFake(true);    px->setParent(this);    IntProperty *py = new IntProperty(value.y(), QLatin1String("y"));    py->setFake(true);    py->setParent(this);    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 << px << py << pw << ph;}QVariant RectProperty::value() const{    return QRect(propertyAt(0)->value().toInt(),                 propertyAt(1)->value().toInt(),                 propertyAt(2)->value().toInt(),                 propertyAt(3)->value().toInt());}void RectProperty::setValue(const QVariant &value){    QRect pt = value.toRect();    propertyAt(0)->setValue(pt.x());    propertyAt(1)->setValue(pt.y());    propertyAt(2)->setValue(pt.width());    propertyAt(3)->setValue(pt.height());}// -------------------------------------------------------------------------ColorProperty::ColorProperty(const QColor &value, const QString &name)    : AbstractPropertyGroup(name){    IntProperty *r = new IntProperty(value.red(), QLatin1String("red"));    r->setFake(true);    r->setRange(0, 255);    r->setParent(this);    IntProperty *g = new IntProperty(value.green(), QLatin1String("green"));    g->setFake(true);    g->setRange(0, 255);    g->setParent(this);    IntProperty *b = new IntProperty(value.blue(), QLatin1String("blue"));    b->setFake(true);    b->setRange(0, 255);    b->setParent(this);    m_properties << r << g << b;}QVariant ColorProperty::value() const{    return qVariantFromValue(QColor(propertyAt(0)->value().toInt(),                  propertyAt(1)->value().toInt(),                  propertyAt(2)->value().toInt()));}void ColorProperty::setValue(const QVariant &value){    QColor c = qvariant_cast<QColor>(value);    propertyAt(0)->setValue(c.red());    propertyAt(1)->setValue(c.green());    propertyAt(2)->setValue(c.blue());}QVariant ColorProperty::decoration() const{    QPixmap pix(16, 16);    pix.fill(qvariant_cast<QColor>(value()));    return qVariantFromValue(pix);}// -------------------------------------------------------------------------FontProperty::FontProperty(const QFont &value, const QString &name)    : AbstractPropertyGroup(name){    QStringList fonts = fontDatabase()->families();    int index = fonts.indexOf(value.family());    if (index == -1)        index = 0;    IProperty *i = 0;    i = new ListProperty(fonts, index, QLatin1String("Family"));    i->setFake(true);    i->setParent(this);    m_properties << i;    int pointSize = value.pointSize();    if (pointSize < 1) {        // try to convert from pixel size and resolved font        // see also code in FontProperty::setValue        pointSize = QFontInfo(value).pointSize();    }    IntProperty *ii = new IntProperty(pointSize, QLatin1String("Point Size"));    ii->setFake(true);    ii->setRange(1, INT_MAX); // ### check    ii->setParent(this);    m_properties << ii;    i = new BoolProperty(value.bold(), QLatin1String("Bold"));    i->setFake(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.italic(), QLatin1String("Italic"));    i->setFake(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.underline(), QLatin1String("Underline"));    i->setFake(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.strikeOut(), QLatin1String("Strikeout"));    i->setFake(true);    i->setParent(this);    m_properties << i;}QVariant FontProperty::value() const{    QFont fnt;    fnt.setFamily(propertyAt(0)->toString());    fnt.setPointSize(propertyAt(1)->value().toInt());    fnt.setBold(propertyAt(2)->value().toBool());    fnt.setItalic(propertyAt(3)->value().toBool());    fnt.setUnderline(propertyAt(4)->value().toBool());    fnt.setStrikeOut(propertyAt(5)->value().toBool());    return qVariantFromValue(fnt);}void FontProperty::setValue(const QVariant &value){    QFont fnt = qvariant_cast<QFont>(value);    int family = fontDatabase()->families().indexOf(fnt.family());    propertyAt(0)->setValue(family);    int pointSize = fnt.pointSize();    if (pointSize < 1) {        // try to convert from pixel size and resolved font        // see also code in FontProperty constructor        pointSize = QFontInfo(fnt).pointSize();    }    propertyAt(1)->setValue(pointSize);    propertyAt(2)->setValue(fnt.bold());    propertyAt(3)->setValue(fnt.italic());    propertyAt(4)->setValue(fnt.underline());    propertyAt(5)->setValue(fnt.strikeOut());}QVariant FontProperty::decoration() const{    QPixmap pix(16, 16);    pix.fill(Qt::white);    QPainter p(&pix);    QFont fnt = qvariant_cast<QFont>(value());    fnt.setPointSize(10); // ### always 10pt!!    p.drawRect(0, 0, 16, 16);    p.setFont(fnt);    p.drawText(0, 16 - 2, QLatin1String("Aa")); // ### 2px for the border!!    return qVariantFromValue(pix);}QString FontProperty::toString() const{    QString family = propertyAt(0)->toString();    QString pointSize = propertyAt(1)->value().toString();    return QLatin1String("  ")  // ### temp hack        + QLatin1String("[") + family + QLatin1String(", ") + pointSize + QLatin1String("]");}// -------------------------------------------------------------------------MapProperty::MapProperty(const QMap<QString, QVariant> &items,                         const QVariant &value,                         const QString &name)    : AbstractProperty<QVariant>(value, name),      m_items(items),      m_keys(m_items.keys()){}QStringList MapProperty::keys() const{    return m_keys;}QMap<QString, QVariant> MapProperty::items() const{    return m_items;}QVariant MapProperty::value() const{    return m_value;}void MapProperty::setValue(const QVariant &value){   if (qVariantCanConvert<EnumType>(value)) {        EnumType e = qvariant_cast<EnumType>(value);        m_value = e.value;    } else if (qVariantCanConvert<FlagType>(value)) {        FlagType e = qvariant_cast<FlagType>(value);        m_value = e.value;    } else {        m_value = value;    }}QString MapProperty::toString() const{    return m_items.key(m_value);}int MapProperty::indexOf(const QVariant &value) const{    QString key = m_items.key(value);    return m_keys.indexOf(key);}QWidget *MapProperty::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(m_keys);    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);    return combo;}void MapProperty::updateEditorContents(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        combo->setCurrentIndex(indexOf(m_value));    }}void MapProperty::updateValue(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        QString key = combo->currentText();        QVariant newValue = m_items.value(key);        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------FlagsProperty::FlagsProperty(const QMap<QString, QVariant> &items, unsigned int value,                             const QString &name)    : MapProperty(items, QVariant(value), name){}QWidget *FlagsProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QList<FlagBoxModelItem> l;    QMapIterator<QString, QVariant> it(items());    unsigned int v = m_value.toUInt();    int initialIndex = -1;    int i = 0;    while (it.hasNext()) {        it.next();        unsigned int value = it.value().toUInt();        bool checked = (value == 0) ? (v == 0) : ((value & v) == value);        l.append(FlagBoxModelItem(it.key(), value, checked));        if ((value & v) == value) {            if (initialIndex == -1)                initialIndex = i;            else if (FlagBoxModel::bitcount(value) > FlagBoxModel::bitcount(l.at(initialIndex).value()))                initialIndex = i;        }        ++i;    }    FlagBox *editor = new FlagBox(parent);    editor->setItems(l);    editor->setCurrentIndex(initialIndex);    QObject::connect(editor, SIGNAL(activated(int)), target, receiver);    return editor;}void FlagsProperty::updateEditorContents(QWidget *editor){    FlagBox *box = qobject_cast<FlagBox*>(editor);    if (box == 0)        return;    box->view()->reset();}void FlagsProperty::updateValue(QWidget *editor){    FlagBox *box = qobject_cast<FlagBox*>(editor);    if ((box == 0) || (box->currentIndex() < 0))        return;    unsigned int newValue = 0;    FlagBoxModelItem &thisItem = box->item(box->currentIndex());    if (thisItem.value() == 0) {        // Uncheck all items except 0-mask        for (int i=0; i<box->count(); ++i)            box->item(i).setChecked(i == box->currentIndex());    } else {        // Compute new value, without including (additional) supermasks        if (thisItem.isChecked())            newValue = thisItem.value();        for (int i=0; i<box->count(); ++i) {            FlagBoxModelItem &item = box->item(i);            if (item.isChecked() && (FlagBoxModel::bitcount(item.value()) == 1))                newValue |= item.value();        }        if (newValue == 0) {            // Uncheck all items except 0-mask            for (int i=0; i<box->count(); ++i) {                FlagBoxModelItem &item = box->item(i);                item.setChecked(item.value() == 0);            }        } else if (newValue == m_value) {            if (!thisItem.isChecked() && (FlagBoxModel::bitcount(thisItem.value()) > 1)) {                // We unchecked something, but the original value still holds                thisItem.setChecked(true);            }        } else {            // Make sure 0-mask is not selected            for (int i=0; i<box->count(); ++i) {                FlagBoxModelItem &item = box->item(i);                if (item.value() == 0)                        item.setChecked(false);            }            // Check/uncheck proper masks            if (thisItem.isChecked()) {                // Make sure submasks and supermasks are selected                for (int i=0; i<box->count(); ++i) {                    FlagBoxModelItem &item = box->item(i);                    if ((item.value() != 0) && ((item.value() & newValue) == item.value()) && !item.isChecked())                        item.setChecked(true);                }            } else {                // Make sure supermasks are not selected if they're no longer valid                for (int i=0; i<box->count(); ++i) {                    FlagBoxModelItem &item = box->item(i);                    if (item.isChecked() && ((item.value() == thisItem.value()) || ((item.value() & newValue) != item.value())))                        item.setChecked(false);                }            }        }    }    if (newValue != m_value) {        m_value = newValue;        setChanged(true);    }}// -------------------------------------------------------------------------SizePolicyProperty::SizePolicyProperty(const QSizePolicy &value, const QString &name)    : AbstractPropertyGroup(name){    QStringList lst;    lst << QString::fromUtf8("Fixed")        << QString::fromUtf8("Minimum")        << QString::fromUtf8("Maximum")        << QString::fromUtf8("Preferred")        << QString::fromUtf8("MinimumExpanding")        << QString::fromUtf8("Expanding")        << QString::fromUtf8("Ignored");    IProperty *i = 0;    i = new ListProperty(lst, size_type_to_int(value.horizontalPolicy()), QLatin1String("hSizeType"));    i->setFake(true);    i->setParent(this);    m_properties << i;    i = new ListProperty(lst, size_type_to_int(value.verticalPolicy()), QLatin1String("vSizeType"));    i->setFake(true);    i->setParent(this);    m_properties << i;    i = new IntProperty(value.horizontalStretch(), QLatin1String("horizontalStretch"));

⌨️ 快捷键说明

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