qpropertyeditor_items.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 2,138 行 · 第 1/5 页

CPP
2,138
字号
{    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        combo->setCurrentIndex(m_value);    }}void ListProperty::updateValue(QWidget *editor){    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {        const 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);    if (name == QLatin1String("maximumSize")) {        pw->setRange(0, 0xFFFFFF);        ph->setRange(0, 0xFFFFFF);    }    if (name == QLatin1String("minimumSize")) {        pw->setRange(0, 0xFFF);        ph->setRange(0, 0xFFF);    }    m_properties << pw << ph;}QVariant SizeProperty::value() const{    return QSize(propertyAt(0)->value().toInt(),                 propertyAt(1)->value().toInt());}void SizeProperty::setValue(const QVariant &value){    const QSize pt = value.toSize();    propertyAt(0)->setValue(pt.width());    propertyAt(1)->setValue(pt.height());}// -------------------------------------------------------------------------SizeFProperty::SizeFProperty(const QSizeF &value, const QString &name)    : AbstractPropertyGroup(name){    SpinBoxDoubleProperty *pw = new SpinBoxDoubleProperty(value.width(), QLatin1String("width"));    pw->setFake(true);    pw->setParent(this);    pw->setRange(0.0, HUGE_VAL);    SpinBoxDoubleProperty *ph = new SpinBoxDoubleProperty(value.height(), QLatin1String("height"));    ph->setFake(true);    ph->setParent(this);    ph->setRange(0.0, HUGE_VAL);    m_properties << pw << ph;}QVariant SizeFProperty::value() const{    return QSizeF(propertyAt(0)->value().toDouble(),                 propertyAt(1)->value().toDouble());}void SizeFProperty::setValue(const QVariant &value){    const QSizeF pt = value.toSizeF();    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{    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)) {        const 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(), QString(QLatin1Char('x')));    px->setFake(true);    px->setParent(this);    IntProperty *py = new IntProperty(value.y(), QString(QLatin1Char('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);    if (name == QLatin1String("geometry")) {        pw->setRange(0, 0xFFF);        ph->setRange(0, 0xFFF);    }    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());}// -------------------------------------------------------------------------RectFProperty::RectFProperty(const QRectF &value, const QString &name)    : AbstractPropertyGroup(name){    DoubleProperty *px = new DoubleProperty(value.x(), QString(QLatin1Char('x')));    px->setFake(true);    px->setParent(this);    DoubleProperty *py = new DoubleProperty(value.y(), QString(QLatin1Char('y')));    py->setFake(true);    py->setParent(this);    SpinBoxDoubleProperty *pw = new SpinBoxDoubleProperty(value.width(), QLatin1String("width"));    pw->setFake(true);    pw->setParent(this);    pw->setRange(0.0, HUGE_VAL);    SpinBoxDoubleProperty *ph = new SpinBoxDoubleProperty(value.height(), QLatin1String("height"));    ph->setFake(true);    ph->setParent(this);    ph->setRange(0.0, HUGE_VAL);    m_properties << px << py << pw << ph;}QVariant RectFProperty::value() const{    return QRectF(propertyAt(0)->value().toDouble(),                 propertyAt(1)->value().toDouble(),                 propertyAt(2)->value().toDouble(),                 propertyAt(3)->value().toDouble());}void RectFProperty::setValue(const QVariant &value){    QRectF pt = value.toRectF();    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);}QWidget *ColorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QtColorButton *button = new QtColorButton(parent);    QObject::connect(button, SIGNAL(colorChanged(const QColor &)), target, receiver);    return button;}void ColorProperty::updateEditorContents(QWidget *editor){    QtColorButton *button = qobject_cast<QtColorButton *>(editor);    if (!button)        return;    button->setColor(qvariant_cast<QColor>(value()));}void ColorProperty::updateValue(QWidget *editor){    QtColorButton *button = qobject_cast<QtColorButton *>(editor);    if (!button)        return;    const QVariant color = qVariantFromValue(button->color());    if (color != value()) {        setValue(color);        setChanged(true);    }}// -------------------------------------------------------------------------FontProperty::FontProperty(const QFont &value, const QString &name, QWidget *selectedWidget)    : AbstractPropertyGroup(name){    m_selectedWidget = selectedWidget;    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->setHasReset(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->setHasReset(true);    ii->setRange(1, INT_MAX); // ### check    ii->setParent(this);    m_properties << ii;    i = new BoolProperty(value.bold(), QLatin1String("Bold"));    i->setFake(true);    i->setHasReset(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.italic(), QLatin1String("Italic"));    i->setFake(true);    i->setHasReset(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.underline(), QLatin1String("Underline"));    i->setFake(true);    i->setHasReset(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.strikeOut(), QLatin1String("Strikeout"));    i->setFake(true);    i->setHasReset(true);    i->setParent(this);    m_properties << i;    i = new BoolProperty(value.kerning(), QLatin1String("Kerning"));    i->setFake(true);    i->setHasReset(true);    i->setParent(this);    m_properties << i;    QStringList keys;    keys << QString::fromUtf8("QFont::PreferDefault");    keys << QString::fromUtf8("QFont::NoAntialias");    keys << QString::fromUtf8("QFont::PreferAntialias");    QMap<QString, QVariant> map;    map[QString::fromUtf8("QFont::PreferDefault")] = QVariant(QFont::PreferDefault);    map[QString::fromUtf8("QFont::NoAntialias")] = QVariant(QFont::NoAntialias);    map[QString::fromUtf8("QFont::PreferAntialias")] = QVariant(QFont::PreferAntialias);    MapProperty *pa = new MapProperty(map, value.styleStrategy(), QLatin1String("Antialiasing"), keys);    pa->setFake(true);    pa->setHasReset(true);    pa->setParent(this);    m_properties << pa;    m_font = value;}QVariant FontProperty::value() const{    return m_font;}void FontProperty::setValue(const QVariant &value){    m_font = qvariant_cast<QFont>(value);    QFont parentFont = QFont();    if (m_selectedWidget) {        if (m_selectedWidget->isWindow())            parentFont = QApplication::font(m_selectedWidget);        else {            if (m_selectedWidget->parentWidget())                parentFont = m_selectedWidget->parentWidget()->font();        }    }    const uint mask = m_font.resolve();    m_font = m_font.resolve(parentFont);    m_font.resolve(mask);    m_changed = mask != 0;

⌨️ 快捷键说明

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