propertyeditor.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 635 行 · 第 1/2 页
CPP
635 行
/******************************************************************************** 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 "propertyeditor.h"#include "qpropertyeditor_model_p.h"#include "qpropertyeditor_items_p.h"#include "newdynamicpropertydialog.h"#include "dynamicpropertysheet.h"#include "paletteeditorbutton.h"#include "graphicspropertyeditor.h"// sdk#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerFormWindowManagerInterface>#include <QtDesigner/QExtensionManager>#include <QtDesigner/QDesignerPropertySheetExtension>// shared#include <qdesigner_utils_p.h>#include <qdesigner_propertycommand_p.h>#include <metadatabase_p.h>#include <QtGui/QAction>#include <QtGui/QLineEdit>#include <QtGui/QMenu>#include <QtGui/QApplication>#include <QtGui/QVBoxLayout>// ---------------------------------------------------------------------------------namespace qdesigner_internal {IProperty *PropertyEditor::createSpecialProperty(const QVariant &value, const QString &name){ Q_UNUSED(value); Q_UNUSED(name); return 0;}class PaletteProperty : public AbstractProperty<QPalette>{public: PaletteProperty(QDesignerFormEditorInterface *core, const QPalette &value, QWidget *selectedWidget, const QString &name); void setValue(const QVariant &value); QString toString() const; QWidget *createEditor(QWidget *parent, const QObject *target, const char *receiver) const; void updateEditorContents(QWidget *editor); void updateValue(QWidget *editor);private: QDesignerFormEditorInterface *m_core; QWidget *m_selectedWidget;};// -------------------------------------------------------------------------PaletteProperty::PaletteProperty(QDesignerFormEditorInterface *core, const QPalette &value, QWidget *selectedWidget, const QString &name) : AbstractProperty<QPalette>(value, name), m_core(core), m_selectedWidget(selectedWidget){}void PaletteProperty::setValue(const QVariant &value){ m_value = qvariant_cast<QPalette>(value); QPalette parentPalette = QPalette(); if (m_selectedWidget) { if (m_selectedWidget->isWindow()) parentPalette = QApplication::palette(m_selectedWidget); else { if (m_selectedWidget->parentWidget()) parentPalette = m_selectedWidget->parentWidget()->palette(); } } const uint mask = m_value.resolve(); m_value = m_value.resolve(parentPalette); m_value.resolve(mask);}QString PaletteProperty::toString() const{ return QString(); // ### implement me}QWidget *PaletteProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ PaletteEditorButton *btn = new PaletteEditorButton(m_core, m_value, m_selectedWidget, parent); QObject::connect(btn, SIGNAL(changed()), target, receiver); return btn;}void PaletteProperty::updateEditorContents(QWidget *editor){ if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) { btn->setPalette(m_value); }}void PaletteProperty::updateValue(QWidget *editor){ if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) { const QPalette newValue = btn->palette(); if (newValue.resolve() != m_value.resolve() || newValue != m_value) { m_value = newValue; setChanged(true); } }}// -------------------------------------------------------------------------------------struct Group{ QString name; QList<IProperty*> properties; inline Group() {} inline Group(const QString &n): name(n) {} inline bool operator == (const Group &other) const { return name == other.name; }};// A pair <ValidationMode, bool hasComment>.typedef QPair<TextPropertyValidationMode, bool> StringPropertyParameters;// Return a pair of validation mode and flag indicating whether property has a comment// for textual properties.StringPropertyParameters textPropertyValidationMode(const QObject *object,const QString &pname, QVariant::Type type, bool isMainContainer) { if (type == QVariant::ByteArray) { return StringPropertyParameters(ValidationMultiLine, false); } // object name - no comment if (pname == QLatin1String("objectName")) { const TextPropertyValidationMode vm = isMainContainer ? ValidationObjectNameScope : ValidationObjectName; return StringPropertyParameters(vm, false); } // Accessibility. Both are texts the narrator reads if (pname == QLatin1String("accessibleDescription") || pname == QLatin1String("accessibleName")) return StringPropertyParameters(ValidationMultiLine, true); // Any names if (pname == QLatin1String("buddy") || pname.endsWith(QLatin1String("Name"))) return StringPropertyParameters(ValidationObjectName, false); // Multi line? if (pname == QLatin1String("styleSheet")) return StringPropertyParameters(ValidationStyleSheet, false); if (pname == QLatin1String("styleSheet") || pname == QLatin1String("toolTip") || pname.endsWith(QLatin1String("ToolTip")) || pname == QLatin1String("whatsThis") || pname == QLatin1String("iconText") || pname == QLatin1String("windowIconText") || pname == QLatin1String("html")) return StringPropertyParameters(ValidationMultiLine, true); // text only if not Action, LineEdit if (pname == QLatin1String("text") && !(qobject_cast<const QAction *>(object) || qobject_cast<const QLineEdit *>(object))) return StringPropertyParameters(ValidationMultiLine, true); // default to single return StringPropertyParameters(ValidationSingleLine, true); }// Create a string prop with proper validation modeStringProperty* PropertyEditor::createStringProperty(QObject *object, const QString &pname, const QVariant &value, bool isMainContainer) const { const StringPropertyParameters params = textPropertyValidationMode(object, pname, value.type(), isMainContainer); // Does a meta DB entry exist - add comment const bool hasComment = params.second && metaDataBaseItem(); const QString comment = hasComment ? propertyComment(m_core, object, pname) : QString(); const QString stringValue = value.type() == QVariant::ByteArray ? QString::fromUtf8(value.toByteArray()) : value.toString(); return new StringProperty(stringValue, pname, params.first, hasComment, comment );}QDesignerMetaDataBaseItemInterface* PropertyEditor::metaDataBaseItem() const { QObject *o = object(); if (!o) return 0; QDesignerMetaDataBaseInterface *db = core()->metaDataBase(); if (!db) return 0; return db->item(o);}void PropertyEditor::createPropertySheet(PropertyCollection *root, QObject *object){ QList<Group> groups; QExtensionManager *m = m_core->extensionManager(); bool isMainContainer = false; if (QWidget *widget = qobject_cast<QWidget*>(object)) { if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(widget)) { isMainContainer = (fw->mainContainer() == widget); } } m_prop_sheet = qobject_cast<QDesignerPropertySheetExtension*>(m->extension(object, Q_TYPEID(QDesignerPropertySheetExtension))); const int count = m_prop_sheet->count(); for (int i=0; i < count; ++i) { if (!m_prop_sheet->isVisible(i)) continue; const QString pname = m_prop_sheet->propertyName(i); // Is this property redefined/hidden in a derived class? // Make it appear under that category only if (m_prop_sheet->indexOf(pname) != i) continue; const QVariant value = m_prop_sheet->property(i); IProperty *p = 0; if (qVariantCanConvert<FlagType>(value)) { FlagType f = qvariant_cast<FlagType>(value); if (pname == QLatin1String("alignment")) { p = new AlignmentProperty(f.items, Qt::Alignment(f.value.toInt()), pname); } else { p = new FlagsProperty(f.items, f.value.toInt(), pname); } } else if (qVariantCanConvert<EnumType>(value)) { EnumType e = qvariant_cast<EnumType>(value); p = new MapProperty(e.items, e.value, pname, e.names); } if (!p) { switch (value.type()) { case 0: p = createSpecialProperty(value, pname); break; case QVariant::Int: p = new IntProperty(value.toInt(), pname); break; case QVariant::UInt: p = new UIntProperty(value.toUInt(), pname); break; case QVariant::LongLong: p = new LongLongProperty(value.toLongLong(), pname); break; case QVariant::ULongLong: p = new ULongLongProperty(value.toULongLong(), pname); break; case QVariant::Double: p = new DoubleProperty(value.toDouble(), pname); break; case QVariant::Char: p = new CharProperty(value.toChar(), pname); break; case QVariant::Bool: p = new BoolProperty(value.toBool(), pname); break; case QVariant::ByteArray: case QVariant::String: p = createStringProperty(object, pname, value, isMainContainer); break; case QVariant::Size: p = new SizeProperty(value.toSize(), pname); break; case QVariant::SizeF: p = new SizeFProperty(value.toSizeF(), pname); break; case QVariant::Point: p = new PointProperty(value.toPoint(), pname); break; case QVariant::PointF: p = new PointFProperty(value.toPointF(), pname); break; case QVariant::Rect: p = new RectProperty(value.toRect(), pname); break; case QVariant::RectF: p = new RectFProperty(value.toRectF(), pname); break; case QVariant::Icon: p = new IconProperty(m_core, qvariant_cast<QIcon>(value), pname);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?