From e577d02cc9cba2033cd21c23a4420a1f0d5469a4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 8 May 2011 20:51:18 +0200 Subject: move files in src/gui into their final locations Rename the guikernel subdir to kernel and guiutil to util. --- src/gui/kernel/qguivariant.cpp | 789 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 789 insertions(+) create mode 100644 src/gui/kernel/qguivariant.cpp (limited to 'src/gui/kernel/qguivariant.cpp') diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp new file mode 100644 index 0000000000..c1e07e55a5 --- /dev/null +++ b/src/gui/kernel/qguivariant.cpp @@ -0,0 +1,789 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qvariant.h" + +#include "qbitmap.h" +#include "qbrush.h" +#include "qcolor.h" +#include "qcursor.h" +#include "qdatastream.h" +#include "qdebug.h" +#include "qfont.h" +#include "qimage.h" +#include "qkeysequence.h" +#include "qtransform.h" +#include "qmatrix.h" +#include "qpalette.h" +#include "qpen.h" +#include "qpixmap.h" +#include "qpolygon.h" +#include "qregion.h" +#include "qtextformat.h" +#include "qmatrix4x4.h" +#include "qvector2d.h" +#include "qvector3d.h" +#include "qvector4d.h" +#include "qquaternion.h" + +#include "private/qvariant_p.h" + +QT_BEGIN_NAMESPACE + +Q_GUI_EXPORT const QVariant::Handler *qt_widgets_variant_handler = 0; + +Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler(); + +static void construct(QVariant::Private *x, const void *copy) +{ + switch (x->type) { + case QVariant::Bitmap: + v_construct(x, copy); + break; + case QVariant::Region: + v_construct(x, copy); + break; + case QVariant::Polygon: + v_construct(x, copy); + break; + case QVariant::Font: + v_construct(x, copy); + break; + case QVariant::Pixmap: + v_construct(x, copy); + break; + case QVariant::Image: + v_construct(x, copy); + break; + case QVariant::Brush: + v_construct(x, copy); + break; + case QVariant::Color: + v_construct(x, copy); + break; + case QVariant::Palette: + v_construct(x, copy); + break; + case QVariant::Matrix: + v_construct(x, copy); + break; + case QVariant::Transform: + v_construct(x, copy); + break; + case QVariant::TextFormat: + v_construct(x, copy); + break; + case QVariant::TextLength: + v_construct(x, copy); + break; +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: + v_construct(x, copy); + break; +#endif + case QVariant::Pen: + v_construct(x, copy); + break; +#ifndef QT_NO_CURSOR + case QVariant::Cursor: + v_construct(x, copy); + break; +#endif + case 62: { + // small 'trick' to let a QVariant(Qt::blue) create a variant + // of type QColor + x->type = QVariant::Color; + QColor color(*reinterpret_cast(copy)); + v_construct(x, &color); + break; + } +#ifndef QT_NO_MATRIX4X4 + case QVariant::Matrix4x4: + v_construct(x, copy); + break; +#endif +#ifndef QT_NO_VECTOR2D + case QVariant::Vector2D: + v_construct(x, copy); + break; +#endif +#ifndef QT_NO_VECTOR3D + case QVariant::Vector3D: + v_construct(x, copy); + break; +#endif +#ifndef QT_NO_VECTOR4D + case QVariant::Vector4D: + v_construct(x, copy); + break; +#endif +#ifndef QT_NO_QUATERNION + case QVariant::Quaternion: + v_construct(x, copy); + break; +#endif + case QVariant::SizePolicy: + case QVariant::Icon: + if (qt_widgets_variant_handler) { + qt_widgets_variant_handler->construct(x, copy); + return; + } + break; + default: + qcoreVariantHandler()->construct(x, copy); + return; + } + x->is_null = !copy; +} + +static void clear(QVariant::Private *d) +{ + switch (d->type) { + case QVariant::Bitmap: + v_clear(d); + break; + case QVariant::Cursor: + v_clear(d); + break; + case QVariant::Region: + v_clear(d); + break; + case QVariant::Polygon: + v_clear(d); + break; + case QVariant::Font: + v_clear(d); + break; + case QVariant::Pixmap: + v_clear(d); + break; + case QVariant::Image: + v_clear(d); + break; + case QVariant::Brush: + v_clear(d); + break; + case QVariant::Color: + v_clear(d); + break; + case QVariant::Palette: + v_clear(d); + break; + case QVariant::Matrix: + v_clear(d); + break; + case QVariant::Transform: + v_clear(d); + break; + case QVariant::TextFormat: + v_clear(d); + break; + case QVariant::TextLength: + v_clear(d); + break; +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: + v_clear(d); + break; +#endif + case QVariant::Pen: + v_clear(d); + break; +#ifndef QT_NO_MATRIX4X4 + case QVariant::Matrix4x4: + v_clear(d); + break; +#endif +#ifndef QT_NO_VECTOR2D + case QVariant::Vector2D: + v_clear(d); + break; +#endif +#ifndef QT_NO_VECTOR3D + case QVariant::Vector3D: + v_clear(d); + break; +#endif +#ifndef QT_NO_VECTOR4D + case QVariant::Vector4D: + v_clear(d); + break; +#endif +#ifndef QT_NO_QUATERNION + case QVariant::Quaternion: + v_clear(d); + break; +#endif + case QVariant::SizePolicy: + case QVariant::Icon: + if (qt_widgets_variant_handler) { + qt_widgets_variant_handler->clear(d); + return; + } + break; + default: + qcoreVariantHandler()->clear(d); + return; + } + + d->type = QVariant::Invalid; + d->is_null = true; + d->is_shared = false; +} + + +static bool isNull(const QVariant::Private *d) +{ + switch(d->type) { + case QVariant::Bitmap: + return v_cast(d)->isNull(); + case QVariant::Region: + return v_cast(d)->isEmpty(); + case QVariant::Polygon: + return v_cast(d)->isEmpty(); + case QVariant::Pixmap: + return v_cast(d)->isNull(); + case QVariant::Image: + return v_cast(d)->isNull(); + case QVariant::Matrix: + case QVariant::TextFormat: + case QVariant::TextLength: + case QVariant::Cursor: + case QVariant::StringList: + case QVariant::Font: + case QVariant::Brush: + case QVariant::Color: + case QVariant::Palette: + case QVariant::SizePolicy: +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: +#endif + case QVariant::Pen: +#ifndef QT_NO_MATRIX4X4 + case QVariant::Matrix4x4: +#endif + break; +#ifndef QT_NO_VECTOR2D + case QVariant::Vector2D: + return v_cast(d)->isNull(); +#endif +#ifndef QT_NO_VECTOR3D + case QVariant::Vector3D: + return v_cast(d)->isNull(); +#endif +#ifndef QT_NO_VECTOR4D + case QVariant::Vector4D: + return v_cast(d)->isNull(); +#endif +#ifndef QT_NO_QUATERNION + case QVariant::Quaternion: + return v_cast(d)->isNull(); +#endif + case QVariant::Icon: + if (qt_widgets_variant_handler) + return qt_widgets_variant_handler->isNull(d); + break; + default: + return qcoreVariantHandler()->isNull(d); + } + return d->is_null; +} + +static bool compare(const QVariant::Private *a, const QVariant::Private *b) +{ + Q_ASSERT(a->type == b->type); + switch(a->type) { + case QVariant::Cursor: +#ifndef QT_NO_CURSOR + return v_cast(a)->shape() == v_cast(b)->shape(); +#endif + case QVariant::Bitmap: + return v_cast(a)->cacheKey() + == v_cast(b)->cacheKey(); + case QVariant::Polygon: + return *v_cast(a) == *v_cast(b); + case QVariant::Region: + return *v_cast(a) == *v_cast(b); + case QVariant::Font: + return *v_cast(a) == *v_cast(b); + case QVariant::Pixmap: + return v_cast(a)->cacheKey() == v_cast(b)->cacheKey(); + case QVariant::Image: + return *v_cast(a) == *v_cast(b); + case QVariant::Brush: + return *v_cast(a) == *v_cast(b); + case QVariant::Color: + return *v_cast(a) == *v_cast(b); + case QVariant::Palette: + return *v_cast(a) == *v_cast(b); +#ifndef QT_NO_ICON + case QVariant::Icon: + /* QIcon::operator==() cannot be reasonably implemented for QIcon, + * so we always return false. */ + return false; +#endif + case QVariant::Matrix: + return *v_cast(a) == *v_cast(b); + case QVariant::Transform: + return *v_cast(a) == *v_cast(b); + case QVariant::TextFormat: + return *v_cast(a) == *v_cast(b); + case QVariant::TextLength: + return *v_cast(a) == *v_cast(b); +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: + return *v_cast(a) == *v_cast(b); +#endif + case QVariant::Pen: + return *v_cast(a) == *v_cast(b); +#ifndef QT_NO_MATRIX4X4 + case QVariant::Matrix4x4: + return *v_cast(a) == *v_cast(b); +#endif +#ifndef QT_NO_VECTOR2D + case QVariant::Vector2D: + return *v_cast(a) == *v_cast(b); +#endif +#ifndef QT_NO_VECTOR3D + case QVariant::Vector3D: + return *v_cast(a) == *v_cast(b); +#endif +#ifndef QT_NO_VECTOR4D + case QVariant::Vector4D: + return *v_cast(a) == *v_cast(b); +#endif +#ifndef QT_NO_QUATERNION + case QVariant::Quaternion: + return *v_cast(a) == *v_cast(b); +#endif + case QVariant::SizePolicy: + if (qt_widgets_variant_handler) + return qt_widgets_variant_handler->compare(a, b); + break; + default: + break; + } + return qcoreVariantHandler()->compare(a, b); +} + + + +static bool convert(const QVariant::Private *d, QVariant::Type t, + void *result, bool *ok) +{ + switch (t) { + case QVariant::ByteArray: + if (d->type == QVariant::Color) { + *static_cast(result) = v_cast(d)->name().toLatin1(); + return true; + } + break; + case QVariant::String: { + QString *str = static_cast(result); + switch (d->type) { +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: + *str = QString(*v_cast(d)); + return true; +#endif + case QVariant::Font: + *str = v_cast(d)->toString(); + return true; + case QVariant::Color: + *str = v_cast(d)->name(); + return true; + default: + break; + } + break; + } + case QVariant::Pixmap: + if (d->type == QVariant::Image) { + *static_cast(result) = QPixmap::fromImage(*v_cast(d)); + return true; + } else if (d->type == QVariant::Bitmap) { + *static_cast(result) = *v_cast(d); + return true; + } else if (d->type == QVariant::Brush) { + if (v_cast(d)->style() == Qt::TexturePattern) { + *static_cast(result) = v_cast(d)->texture(); + return true; + } + } + break; + case QVariant::Image: + if (d->type == QVariant::Pixmap) { + *static_cast(result) = v_cast(d)->toImage(); + return true; + } else if (d->type == QVariant::Bitmap) { + *static_cast(result) = v_cast(d)->toImage(); + return true; + } + break; + case QVariant::Bitmap: + if (d->type == QVariant::Pixmap) { + *static_cast(result) = *v_cast(d); + return true; + } else if (d->type == QVariant::Image) { + *static_cast(result) = QBitmap::fromImage(*v_cast(d)); + return true; + } + break; +#ifndef QT_NO_SHORTCUT + case QVariant::Int: + if (d->type == QVariant::KeySequence) { + *static_cast(result) = (int)(*(v_cast(d))); + return true; + } + break; +#endif + case QVariant::Font: + if (d->type == QVariant::String) { + QFont *f = static_cast(result); + f->fromString(*v_cast(d)); + return true; + } + break; + case QVariant::Color: + if (d->type == QVariant::String) { + static_cast(result)->setNamedColor(*v_cast(d)); + return static_cast(result)->isValid(); + } else if (d->type == QVariant::ByteArray) { + static_cast(result)->setNamedColor(QString::fromLatin1( + *v_cast(d))); + return true; + } else if (d->type == QVariant::Brush) { + if (v_cast(d)->style() == Qt::SolidPattern) { + *static_cast(result) = v_cast(d)->color(); + return true; + } + } + break; + case QVariant::Brush: + if (d->type == QVariant::Color) { + *static_cast(result) = QBrush(*v_cast(d)); + return true; + } else if (d->type == QVariant::Pixmap) { + *static_cast(result) = QBrush(*v_cast(d)); + return true; + } + break; +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: { + QKeySequence *seq = static_cast(result); + switch (d->type) { + case QVariant::String: + *seq = QKeySequence(*v_cast(d)); + return true; + case QVariant::Int: + *seq = QKeySequence(d->data.i); + return true; + default: + break; + } + } +#endif + default: + break; + } + return qcoreVariantHandler()->convert(d, t, result, ok); +} + +#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +static void streamDebug(QDebug dbg, const QVariant &v) +{ + switch(v.type()) { + case QVariant::Cursor: +#ifndef QT_NO_CURSOR +// dbg.nospace() << qvariant_cast(v); //FIXME +#endif + break; + case QVariant::Bitmap: +// dbg.nospace() << qvariant_cast(v); //FIXME + break; + case QVariant::Polygon: + dbg.nospace() << qvariant_cast(v); + break; + case QVariant::Region: + dbg.nospace() << qvariant_cast(v); + break; + case QVariant::Font: +// dbg.nospace() << qvariant_cast(v); //FIXME + break; + case QVariant::Matrix: + dbg.nospace() << qvariant_cast(v); + break; + case QVariant::Transform: + dbg.nospace() << qvariant_cast(v); + break; + case QVariant::Pixmap: +// dbg.nospace() << qvariant_cast(v); //FIXME + break; + case QVariant::Image: +// dbg.nospace() << qvariant_cast(v); //FIXME + break; + case QVariant::Brush: + dbg.nospace() << qvariant_cast(v); + break; + case QVariant::Color: + dbg.nospace() << qvariant_cast(v); + break; + case QVariant::Palette: +// dbg.nospace() << qvariant_cast(v); //FIXME + break; +#ifndef QT_NO_ICON + case QVariant::Icon: +// dbg.nospace() << qvariant_cast(v); // FIXME + break; +#endif + case QVariant::SizePolicy: +// dbg.nospace() << qvariant_cast(v); //FIXME + break; +#ifndef QT_NO_SHORTCUT + case QVariant::KeySequence: + dbg.nospace() << qvariant_cast(v); + break; +#endif + case QVariant::Pen: + dbg.nospace() << qvariant_cast(v); + break; +#ifndef QT_NO_MATRIX4X4 + case QVariant::Matrix4x4: + dbg.nospace() << qvariant_cast(v); + break; +#endif +#ifndef QT_NO_VECTOR2D + case QVariant::Vector2D: + dbg.nospace() << qvariant_cast(v); + break; +#endif +#ifndef QT_NO_VECTOR3D + case QVariant::Vector3D: + dbg.nospace() << qvariant_cast(v); + break; +#endif +#ifndef QT_NO_VECTOR4D + case QVariant::Vector4D: + dbg.nospace() << qvariant_cast(v); + break; +#endif +#ifndef QT_NO_QUATERNION + case QVariant::Quaternion: + dbg.nospace() << qvariant_cast(v); + break; +#endif + default: + qcoreVariantHandler()->debugStream(dbg, v); + break; + } +} +#endif + +const QVariant::Handler qt_gui_variant_handler = { + construct, + clear, + isNull, +#ifndef QT_NO_DATASTREAM + 0, + 0, +#endif + compare, + convert, + 0, +#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) + streamDebug +#else + 0 +#endif +}; + +struct QMetaTypeGuiHelper +{ + QMetaType::Constructor constr; + QMetaType::Destructor destr; +#ifndef QT_NO_DATASTREAM + QMetaType::SaveOperator saveOp; + QMetaType::LoadOperator loadOp; +#endif +}; + +extern Q_CORE_EXPORT const QMetaTypeGuiHelper *qMetaTypeGuiHelper; + + +#ifdef QT_NO_DATASTREAM +# define Q_DECL_METATYPE_HELPER(TYPE) \ + typedef void *(*QConstruct##TYPE)(const TYPE *); \ + static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper; \ + typedef void (*QDestruct##TYPE)(TYPE *); \ + static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper; +#else +# define Q_DECL_METATYPE_HELPER(TYPE) \ + typedef void *(*QConstruct##TYPE)(const TYPE *); \ + static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper; \ + typedef void (*QDestruct##TYPE)(TYPE *); \ + static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper; \ + typedef void (*QSave##TYPE)(QDataStream &, const TYPE *); \ + static const QSave##TYPE qSave##TYPE = qMetaTypeSaveHelper; \ + typedef void (*QLoad##TYPE)(QDataStream &, TYPE *); \ + static const QLoad##TYPE qLoad##TYPE = qMetaTypeLoadHelper; +#endif + +Q_DECL_METATYPE_HELPER(QFont) +Q_DECL_METATYPE_HELPER(QPixmap) +Q_DECL_METATYPE_HELPER(QBrush) +Q_DECL_METATYPE_HELPER(QColor) +Q_DECL_METATYPE_HELPER(QPalette) +Q_DECL_METATYPE_HELPER(QImage) +Q_DECL_METATYPE_HELPER(QPolygon) +Q_DECL_METATYPE_HELPER(QRegion) +Q_DECL_METATYPE_HELPER(QBitmap) +#ifndef QT_NO_CURSOR +Q_DECL_METATYPE_HELPER(QCursor) +#endif +#ifndef QT_NO_SHORTCUT +Q_DECL_METATYPE_HELPER(QKeySequence) +#endif +Q_DECL_METATYPE_HELPER(QPen) +Q_DECL_METATYPE_HELPER(QTextLength) +Q_DECL_METATYPE_HELPER(QTextFormat) +Q_DECL_METATYPE_HELPER(QMatrix) +Q_DECL_METATYPE_HELPER(QTransform) +#ifndef QT_NO_MATRIX4X4 +Q_DECL_METATYPE_HELPER(QMatrix4x4) +#endif +#ifndef QT_NO_VECTOR2D +Q_DECL_METATYPE_HELPER(QVector2D) +#endif +#ifndef QT_NO_VECTOR3D +Q_DECL_METATYPE_HELPER(QVector3D) +#endif +#ifndef QT_NO_VECTOR4D +Q_DECL_METATYPE_HELPER(QVector4D) +#endif +#ifndef QT_NO_QUATERNION +Q_DECL_METATYPE_HELPER(QQuaternion) +#endif + +#ifdef QT_NO_DATASTREAM +# define Q_IMPL_METATYPE_HELPER(TYPE) \ + { reinterpret_cast(qConstruct##TYPE), \ + reinterpret_cast(qDestruct##TYPE) } +#else +# define Q_IMPL_METATYPE_HELPER(TYPE) \ + { reinterpret_cast(qConstruct##TYPE), \ + reinterpret_cast(qDestruct##TYPE), \ + reinterpret_cast(qSave##TYPE), \ + reinterpret_cast(qLoad##TYPE) \ + } +#endif + +static const QMetaTypeGuiHelper qVariantGuiHelper[] = { + Q_IMPL_METATYPE_HELPER(QFont), + Q_IMPL_METATYPE_HELPER(QPixmap), + Q_IMPL_METATYPE_HELPER(QBrush), + Q_IMPL_METATYPE_HELPER(QColor), + Q_IMPL_METATYPE_HELPER(QPalette), + Q_IMPL_METATYPE_HELPER(QImage), + Q_IMPL_METATYPE_HELPER(QPolygon), + Q_IMPL_METATYPE_HELPER(QRegion), + Q_IMPL_METATYPE_HELPER(QBitmap), +#ifdef QT_NO_CURSOR + {0, 0, 0, 0}, +#else + Q_IMPL_METATYPE_HELPER(QCursor), +#endif +#ifdef QT_NO_SHORTCUT + {0, 0, 0, 0}, +#else + Q_IMPL_METATYPE_HELPER(QKeySequence), +#endif + Q_IMPL_METATYPE_HELPER(QPen), + Q_IMPL_METATYPE_HELPER(QTextLength), + Q_IMPL_METATYPE_HELPER(QTextFormat), + Q_IMPL_METATYPE_HELPER(QMatrix), + Q_IMPL_METATYPE_HELPER(QTransform), +#ifndef QT_NO_MATRIX4X4 + Q_IMPL_METATYPE_HELPER(QMatrix4x4), +#else + {0, 0, 0, 0}, +#endif +#ifndef QT_NO_VECTOR2D + Q_IMPL_METATYPE_HELPER(QVector2D), +#else + {0, 0, 0, 0}, +#endif +#ifndef QT_NO_VECTOR3D + Q_IMPL_METATYPE_HELPER(QVector3D), +#else + {0, 0, 0, 0}, +#endif +#ifndef QT_NO_VECTOR4D + Q_IMPL_METATYPE_HELPER(QVector4D), +#else + {0, 0, 0, 0}, +#endif +#ifndef QT_NO_QUATERNION + Q_IMPL_METATYPE_HELPER(QQuaternion) +#else + {0, 0, 0, 0} +#endif +}; + +static const QVariant::Handler *qt_guivariant_last_handler = 0; +int qRegisterGuiVariant() +{ + qt_guivariant_last_handler = QVariant::handler; + QVariant::handler = &qt_gui_variant_handler; + qMetaTypeGuiHelper = qVariantGuiHelper; + return 1; +} +Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant) + +int qUnregisterGuiVariant() +{ + QVariant::handler = qt_guivariant_last_handler; + qMetaTypeGuiHelper = 0; + return 1; +} +Q_DESTRUCTOR_FUNCTION(qUnregisterGuiVariant) + + +QT_END_NAMESPACE -- cgit v1.2.3