qdesigner_propertycommand.cpp

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

CPP
1,210
字号
/******************************************************************************** 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 "qdesigner_propertycommand_p.h"#include "qdesigner_utils_p.h"#include "dynamicpropertysheet.h"#include "qdesigner_propertyeditor_p.h"#include "qdesigner_integration_p.h"#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerFormWindowInterface>#include <QtDesigner/QDesignerFormWindowCursorInterface>#include <QtDesigner/QDesignerDynamicPropertySheetExtension>#include <QtDesigner/QDesignerPropertySheetExtension>#include <QtDesigner/QDesignerPropertyEditorInterface>#include <QtDesigner/QDesignerObjectInspectorInterface>#include <QtDesigner/QDesignerIntegrationInterface>#include <QtDesigner/QDesignerWidgetDataBaseInterface>#include <QtDesigner/QExtensionManager>#include <QtCore/QSize>#include <QtCore/QTextStream>#include <QtGui/QWidget>#include <QtGui/QApplication>#include <QtGui/QAction>#include <QtGui/QDialog>#include <QtGui/QPushButton>#include <qdebug.h>namespace  {enum { debugPropertyCommands = 0 };QSize checkSize(const QSize &size){    return size.boundedTo(QSize(0xFFFFFF, 0xFFFFFF));}QSize diffSize(QDesignerFormWindowInterface *fw){    const QWidget *container = fw->core()->integration()->containerWindow(fw);    if (!container)        return QSize();    const QSize diff = container->size() - fw->size(); // decoration offset of container window    return diff;}void checkSizes(QDesignerFormWindowInterface *fw, const QSize &size, QSize *formSize, QSize *containerSize){    const QWidget *container = fw->core()->integration()->containerWindow(fw);    if (!container)        return;    const  QSize diff = diffSize(fw); // decoration offset of container window    QSize newFormSize = checkSize(size).expandedTo(fw->mainContainer()->minimumSizeHint()); // don't try to resize to smaller size than minimumSizeHint    QSize newContainerSize = newFormSize + diff;    newContainerSize = newContainerSize.expandedTo(container->minimumSizeHint());    newContainerSize = newContainerSize.expandedTo(container->minimumSize());    newFormSize = newContainerSize - diff;    newContainerSize = checkSize(newContainerSize);    if (formSize)        *formSize = newFormSize;    if (containerSize)        *containerSize = newContainerSize;}/* SubProperties: When applying a changed property to a multiselection, it sometimes makes * sense to apply only parts (subproperties) of the property. * For example, if someone changes the x-value of a geometry in the property editor * and applies it to a multi-selection, y should not be applied as this would cause all * the widgets to overlap. * The following routines can be used to find out the changed subproperties of a property, * which are represented as a mask, and to apply them while leaving the others intact. */enum RectSubPropertyMask {  SubPropertyX=1, SubPropertyY = 2, SubPropertyWidth = 4, SubPropertyHeight = 8 };enum SizePolicySubPropertyMask { SubPropertyHSizePolicy = 1, SubPropertyHStretch = 2, SubPropertyVSizePolicy =4, SubPropertyVStretch = 8 };enum FontSubPropertyMask { SubPropertyFamily=1, SubPropertyPointSize=2, SubPropertyBold=4,  SubPropertyItalic=8,                           SubPropertyUnderline=16, SubPropertyStrikeOut=32, SubPropertyKerning=64, SubPropertyStyleStrategy=128};enum AlignmentSubPropertyMask { SubPropertyHorizontalAlignment=1, SubPropertyVerticalAlignment=2 };enum CommonSubPropertyMask { SubPropertyAll = 0xFFFFFFFF };// Set the mask flag in mask if the properties do not match.#define COMPARE_SUBPROPERTY(object1, object2, getter, mask, maskFlag) if (object1.getter() != object2.getter()) mask |= maskFlag;// find changed subproperties of a rectangleunsigned compareSubProperties(const QRect & r1, const QRect & r2){    unsigned rc = 0;    COMPARE_SUBPROPERTY(r1, r2, x, rc, SubPropertyX)    COMPARE_SUBPROPERTY(r1, r2, y, rc, SubPropertyY)    COMPARE_SUBPROPERTY(r1, r2, width, rc, SubPropertyWidth)    COMPARE_SUBPROPERTY(r1, r2, height, rc, SubPropertyHeight)    return rc;}// find changed subproperties of a QSizeunsigned compareSubProperties(const QSize & r1, const QSize & r2){    unsigned rc = 0;    COMPARE_SUBPROPERTY(r1, r2, width,  rc, SubPropertyWidth)    COMPARE_SUBPROPERTY(r1, r2, height, rc, SubPropertyHeight)    return rc;}// find changed subproperties of a QSizePolicyunsigned compareSubProperties(const QSizePolicy & sp1, const QSizePolicy & sp2){    unsigned rc = 0;    COMPARE_SUBPROPERTY(sp1, sp2, horizontalPolicy,  rc, SubPropertyHSizePolicy)    COMPARE_SUBPROPERTY(sp1, sp2, horizontalStretch, rc, SubPropertyHStretch)    COMPARE_SUBPROPERTY(sp1, sp2, verticalPolicy,    rc, SubPropertyVSizePolicy)    COMPARE_SUBPROPERTY(sp1, sp2, verticalStretch,   rc, SubPropertyVStretch)    return rc;}// find changed subproperties of a QFontunsigned compareSubProperties(const QFont & f1, const QFont & f2){    unsigned rc = 0;    COMPARE_SUBPROPERTY(f1, f2, family,        rc, SubPropertyFamily)    COMPARE_SUBPROPERTY(f1, f2, pointSize,     rc, SubPropertyPointSize)    COMPARE_SUBPROPERTY(f1, f2, bold,          rc, SubPropertyBold)    COMPARE_SUBPROPERTY(f1, f2, italic,        rc, SubPropertyItalic)    COMPARE_SUBPROPERTY(f1, f2, underline,     rc, SubPropertyUnderline)    COMPARE_SUBPROPERTY(f1, f2, strikeOut,     rc, SubPropertyStrikeOut)    COMPARE_SUBPROPERTY(f1, f2, kerning,       rc, SubPropertyKerning)    COMPARE_SUBPROPERTY(f1, f2, styleStrategy, rc, SubPropertyStyleStrategy)    return rc;}// Compare colors of a rolebool roleColorChanged(const QPalette & p1, const QPalette & p2, QPalette::ColorRole role){    for (int group = QPalette::Active; group < QPalette::NColorGroups;  group++) {        const QPalette::ColorGroup pgroup = static_cast<QPalette::ColorGroup>(group);        if (p1.color(pgroup, role) != p2.color(pgroup, role))            return true;    }    return false;}// find changed subproperties of a QPaletteunsigned compareSubProperties(const QPalette & p1, const QPalette & p2){    unsigned rc = 0;    unsigned maskBit = 1u;    // generate a mask for each role    const unsigned p1Changed = p1.resolve();    const unsigned p2Changed = p2.resolve();    for (int role = QPalette::WindowText;  role < QPalette::NColorRoles; role++, maskBit <<= 1u) {        const bool p1RoleChanged = p1Changed & maskBit;        const bool p2RoleChanged = p2Changed & maskBit;        // Role has been set/reset in editor        if (p1RoleChanged != p2RoleChanged) {            rc |= maskBit;        } else {            // Was modified in both palettes: Compare values.            if (p1RoleChanged && p2RoleChanged && roleColorChanged(p1, p2, static_cast<QPalette::ColorRole>(role)))                rc |= maskBit;        }    }    return rc;}// find changed subproperties of a QAlignment which is a flag combination of vertical and horizontalunsigned compareSubProperties(Qt::Alignment a1, Qt::Alignment a2){    unsigned rc = 0;    if ((a1 & Qt::AlignHorizontal_Mask) != (a2 & Qt::AlignHorizontal_Mask))        rc |= SubPropertyHorizontalAlignment;    if ((a1 & Qt::AlignVertical_Mask) != (a2 & Qt::AlignVertical_Mask))        rc |= SubPropertyVerticalAlignment;    return rc;}Qt::Alignment variantToAlignment(const QVariant & q){    return Qt::Alignment(qdesigner_internal::Utils::valueOf(q));}// find changed subproperties of a variantunsigned compareSubProperties(const QVariant & q1, const QVariant & q2, qdesigner_internal::SpecialProperty specialProperty){    switch (q1.type()) {    case QVariant::Rect:        return compareSubProperties(q1.toRect(), q2.toRect());    case QVariant::Size:        return compareSubProperties(q1.toSize(), q2.toSize());    case QVariant::SizePolicy:        return compareSubProperties(qvariant_cast<QSizePolicy>(q1), qvariant_cast<QSizePolicy>(q2));    case QVariant::Font:        return compareSubProperties(qvariant_cast<QFont>(q1), qvariant_cast<QFont>(q2));    case QVariant::Palette:        return compareSubProperties(qvariant_cast<QPalette>(q1), qvariant_cast<QPalette>(q2));    default:        // Enumerations, flags        switch (specialProperty) {        case qdesigner_internal::SP_Alignment:            return compareSubProperties(variantToAlignment(q1), variantToAlignment(q2));        default:        break;        }        break;    }    return SubPropertyAll;}// Apply  the sub property if mask flag is set in mask#define SET_SUBPROPERTY(rc, newValue, getter, setter, mask, maskFlag) if (mask & maskFlag) rc.setter(newValue.getter());// apply changed subproperties to a rectangleQRect applyRectSubProperty(const QRect &oldValue, const QRect &newValue, unsigned mask){    QRect rc = oldValue;    SET_SUBPROPERTY(rc, newValue, x,      moveLeft,  mask, SubPropertyX)    SET_SUBPROPERTY(rc, newValue, y,      moveTop,   mask, SubPropertyY)    SET_SUBPROPERTY(rc, newValue, width,  setWidth,  mask, SubPropertyWidth)    SET_SUBPROPERTY(rc, newValue, height, setHeight, mask, SubPropertyHeight)    return rc;}// apply changed subproperties to a rectangle QSizeQSize applySizeSubProperty(const QSize &oldValue, const QSize &newValue, unsigned mask){    QSize rc = oldValue;    SET_SUBPROPERTY(rc, newValue, width,  setWidth,  mask, SubPropertyWidth)    SET_SUBPROPERTY(rc, newValue, height, setHeight, mask, SubPropertyHeight)    return rc;}// apply changed subproperties to a SizePolicyQSizePolicy applySizePolicySubProperty(const QSizePolicy &oldValue, const QSizePolicy &newValue, unsigned mask){    QSizePolicy rc = oldValue;    SET_SUBPROPERTY(rc, newValue, horizontalPolicy,  setHorizontalPolicy,  mask, SubPropertyHSizePolicy)    SET_SUBPROPERTY(rc, newValue, horizontalStretch, setHorizontalStretch, mask, SubPropertyHStretch)    SET_SUBPROPERTY(rc, newValue, verticalPolicy,    setVerticalPolicy,    mask, SubPropertyVSizePolicy)    SET_SUBPROPERTY(rc, newValue, verticalStretch,   setVerticalStretch,   mask, SubPropertyVStretch)    return rc;}// apply changed subproperties to a QFontQFont applyFontSubProperty(const QFont &oldValue, const QFont &newValue, unsigned mask){    QFont  rc = oldValue;    SET_SUBPROPERTY(rc, newValue, family,        setFamily,        mask, SubPropertyFamily)    SET_SUBPROPERTY(rc, newValue, pointSize,     setPointSize,     mask, SubPropertyPointSize)    SET_SUBPROPERTY(rc, newValue, bold,          setBold,          mask, SubPropertyBold)    SET_SUBPROPERTY(rc, newValue, italic,        setItalic,        mask, SubPropertyItalic)    SET_SUBPROPERTY(rc, newValue, underline,     setUnderline,     mask, SubPropertyUnderline)    SET_SUBPROPERTY(rc, newValue, strikeOut,     setStrikeOut,     mask, SubPropertyStrikeOut)    SET_SUBPROPERTY(rc, newValue, kerning,       setKerning,       mask, SubPropertyKerning)    SET_SUBPROPERTY(rc, newValue, styleStrategy, setStyleStrategy, mask, SubPropertyStyleStrategy)    return rc;}// apply changed subproperties to a QPaletteQPalette applyPaletteSubProperty(const QPalette &oldValue, const QPalette &newValue, unsigned mask){    QPalette rc = oldValue;    // apply a mask for each role    unsigned maskBit = 1u;    for (int role = QPalette::WindowText;  role < QPalette::NColorRoles; role++, maskBit <<= 1u) {

⌨️ 快捷键说明

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