qpropertyeditor_items.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 2,138 行 · 第 1/5 页
CPP
2,138 行
/******************************************************************************** Copyright (C) 1992-2007 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://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** 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 "stringlisteditorbutton.h"#include "defs.h"#include "qlonglongvalidator.h"#include "qtcolorbutton.h"#include <qdesigner_utils_p.h>#include <textpropertyeditor_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/QApplication>#include <QtGui/QBitmap>#include <QtGui/QLabel>#include <QtGui/QMenu>#include <QtGui/QHBoxLayout>#include <QtCore/QUrl>#include <QContextMenuEvent>#include <private/qfont_p.h>#include <QtCore/qdebug.h>#include <limits.h>#include <math.h>using namespace qdesigner_internal;Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)static QString matchStringInKeys(const QString &str, const QMap<QString, QVariant> &items) { for (QMap<QString, QVariant>::const_iterator it = items.begin(); it != items.end(); ++it) { if (it.key().contains(str)) return it.key(); } return str;}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());}QString AbstractPropertyGroup::toString() const{ QString text = QString(QLatin1Char('[')); for (int i=0; i<propertyCount(); ++i) { if (i) text += QLatin1String(", "); text += propertyAt(i)->toString(); } text += QLatin1Char(']'); return text;}// -------------------------------------------------------------------------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 (const QComboBox *combo = qobject_cast<const QComboBox*>(editor)) { const 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(), QString(QLatin1Char('x'))); px->setFake(true); px->setParent(this); IProperty *py = new IntProperty(value.y(), QString(QLatin1Char('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){ const QPoint pt = value.toPoint(); propertyAt(0)->setValue(pt.x()); propertyAt(1)->setValue(pt.y());}// -------------------------------------------------------------------------PointFProperty::PointFProperty(const QPointF &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); m_properties << px << py;}QVariant PointFProperty::value() const{ return QPointF(propertyAt(0)->value().toDouble(), propertyAt(1)->value().toDouble());}void PointFProperty::setValue(const QVariant &value){ const QPointF pt = value.toPointF(); 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, TextPropertyValidationMode validationMode, bool hasComment, const QString &comment) : AbstractPropertyGroup(name), m_validationMode(validationMode), m_value(value){ if (hasComment) { StringProperty *pcomment = new StringProperty(comment, QLatin1String("comment")); pcomment->setParent(this); m_properties << pcomment; }}QVariant StringProperty::value() const{ return m_value;}void StringProperty::setValue(const QVariant &value){ m_value = value.toString();}QString StringProperty::toString() const{ return TextPropertyEditor::stringToEditorString(m_value, m_validationMode);}bool StringProperty::hasEditor() const{ return true;}QWidget *StringProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ TextPropertyEditor* textEditor = new TextPropertyEditor(TextPropertyEditor::EmbeddingTreeView, m_validationMode, parent); QObject::connect(textEditor, SIGNAL(textChanged(QString)), target, receiver); return textEditor;}void StringProperty::updateEditorContents(QWidget *editor){ if (TextPropertyEditor *textEditor = qobject_cast<TextPropertyEditor*>(editor)) { if (textEditor->text() != m_value) textEditor->setText(m_value); }}void StringProperty::updateValue(QWidget *editor){ if (const TextPropertyEditor *textEditor = qobject_cast<const TextPropertyEditor*>(editor)) { const QString newValue = textEditor->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)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?