1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtDeclarative module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef QDECLARATIVEVALUETYPE_P_H 43 #define QDECLARATIVEVALUETYPE_P_H 44 45 // 46 // W A R N I N G 47 // ------------- 48 // 49 // This file is not part of the Qt API. It exists purely as an 50 // implementation detail. This header file may change from version to 51 // version without notice, or even be removed. 52 // 53 // We mean it. 54 // 55 56 #include "qdeclarativeproperty.h" 57 #include "private/qdeclarativeproperty_p.h" 58 #include "private/qdeclarativenullablevalue_p_p.h" 59 60 #include <QtCore/qobject.h> 61 #include <QtCore/qrect.h> 62 #include <QtCore/qeasingcurve.h> 63 #include <QtCore/qvariant.h> 64 #include <QtGui/qvector2d.h> 65 #include <QtGui/qvector3d.h> 66 #include <QtGui/qvector4d.h> 67 #include <QtGui/qmatrix4x4.h> 68 #include <QtGui/qquaternion.h> 69 #include <QtGui/qfont.h> 70 71 QT_BEGIN_NAMESPACE 72 73 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueType : public QObject 74 { 75 Q_OBJECT 76 public: 77 QDeclarativeValueType(QObject *parent = 0); 78 virtual void read(QObject *, int) = 0; 79 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags flags) = 0; 80 virtual QVariant value() = 0; 81 virtual void setValue(QVariant) = 0; 82 }; 83 84 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueTypeFactory 85 { 86 public: 87 QDeclarativeValueTypeFactory(); 88 ~QDeclarativeValueTypeFactory(); 89 static bool isValueType(int); 90 static QDeclarativeValueType *valueType(int); 91 92 static void registerValueTypes(); 93 static void registerValueTypesCompat(); 94 95 QDeclarativeValueType *operator[](int idx) const { 96 if (idx < 0 || idx >= (int)QVariant::UserType) return 0; 97 else return valueTypes[idx]; 98 } 99 100 private: 101 QDeclarativeValueType *valueTypes[QVariant::UserType - 1]; 102 }; 103 104 class Q_AUTOTEST_EXPORT QDeclarativePointFValueType : public QDeclarativeValueType 105 { 106 Q_PROPERTY(qreal x READ x WRITE setX) 107 Q_PROPERTY(qreal y READ y WRITE setY) 108 Q_OBJECT 109 public: 110 QDeclarativePointFValueType(QObject *parent = 0); 111 112 virtual void read(QObject *, int); 113 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 114 virtual QVariant value(); 115 virtual void setValue(QVariant value); 116 117 qreal x() const; 118 qreal y() const; 119 void setX(qreal); 120 void setY(qreal); 121 122 private: 123 QPointF point; 124 }; 125 126 class Q_AUTOTEST_EXPORT QDeclarativePointValueType : public QDeclarativeValueType 127 { 128 Q_PROPERTY(int x READ x WRITE setX) 129 Q_PROPERTY(int y READ y WRITE setY) 130 Q_OBJECT 131 public: 132 QDeclarativePointValueType(QObject *parent = 0); 133 134 virtual void read(QObject *, int); 135 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 136 virtual QVariant value(); 137 virtual void setValue(QVariant value); 138 139 int x() const; 140 int y() const; 141 void setX(int); 142 void setY(int); 143 144 private: 145 QPoint point; 146 }; 147 148 class Q_AUTOTEST_EXPORT QDeclarativeSizeFValueType : public QDeclarativeValueType 149 { 150 Q_PROPERTY(qreal width READ width WRITE setWidth) 151 Q_PROPERTY(qreal height READ height WRITE setHeight) 152 Q_OBJECT 153 public: 154 QDeclarativeSizeFValueType(QObject *parent = 0); 155 156 virtual void read(QObject *, int); 157 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 158 virtual QVariant value(); 159 virtual void setValue(QVariant value); 160 161 qreal width() const; 162 qreal height() const; 163 void setWidth(qreal); 164 void setHeight(qreal); 165 166 private: 167 QSizeF size; 168 }; 169 170 class Q_AUTOTEST_EXPORT QDeclarativeSizeValueType : public QDeclarativeValueType 171 { 172 Q_PROPERTY(int width READ width WRITE setWidth) 173 Q_PROPERTY(int height READ height WRITE setHeight) 174 Q_OBJECT 175 public: 176 QDeclarativeSizeValueType(QObject *parent = 0); 177 178 virtual void read(QObject *, int); 179 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 180 virtual QVariant value(); 181 virtual void setValue(QVariant value); 182 183 int width() const; 184 int height() const; 185 void setWidth(int); 186 void setHeight(int); 187 188 private: 189 QSize size; 190 }; 191 192 class Q_AUTOTEST_EXPORT QDeclarativeRectFValueType : public QDeclarativeValueType 193 { 194 Q_PROPERTY(qreal x READ x WRITE setX) 195 Q_PROPERTY(qreal y READ y WRITE setY) 196 Q_PROPERTY(qreal width READ width WRITE setWidth) 197 Q_PROPERTY(qreal height READ height WRITE setHeight) 198 Q_OBJECT 199 public: 200 QDeclarativeRectFValueType(QObject *parent = 0); 201 202 virtual void read(QObject *, int); 203 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 204 virtual QVariant value(); 205 virtual void setValue(QVariant value); 206 207 qreal x() const; 208 qreal y() const; 209 void setX(qreal); 210 void setY(qreal); 211 212 qreal width() const; 213 qreal height() const; 214 void setWidth(qreal); 215 void setHeight(qreal); 216 217 private: 218 QRectF rect; 219 }; 220 221 class Q_AUTOTEST_EXPORT QDeclarativeRectValueType : public QDeclarativeValueType 222 { 223 Q_PROPERTY(int x READ x WRITE setX) 224 Q_PROPERTY(int y READ y WRITE setY) 225 Q_PROPERTY(int width READ width WRITE setWidth) 226 Q_PROPERTY(int height READ height WRITE setHeight) 227 Q_OBJECT 228 public: 229 QDeclarativeRectValueType(QObject *parent = 0); 230 231 virtual void read(QObject *, int); 232 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 233 virtual QVariant value(); 234 virtual void setValue(QVariant value); 235 236 int x() const; 237 int y() const; 238 void setX(int); 239 void setY(int); 240 241 int width() const; 242 int height() const; 243 void setWidth(int); 244 void setHeight(int); 245 246 private: 247 QRect rect; 248 }; 249 250 class Q_AUTOTEST_EXPORT QDeclarativeVector2DValueType : public QDeclarativeValueType 251 { 252 Q_PROPERTY(qreal x READ x WRITE setX) 253 Q_PROPERTY(qreal y READ y WRITE setY) 254 Q_OBJECT 255 public: 256 QDeclarativeVector2DValueType(QObject *parent = 0); 257 258 virtual void read(QObject *, int); 259 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 260 virtual QVariant value(); 261 virtual void setValue(QVariant value); 262 263 qreal x() const; 264 qreal y() const; 265 void setX(qreal); 266 void setY(qreal); 267 268 private: 269 QVector2D vector; 270 }; 271 272 class Q_AUTOTEST_EXPORT QDeclarativeVector3DValueType : public QDeclarativeValueType 273 { 274 Q_PROPERTY(qreal x READ x WRITE setX) 275 Q_PROPERTY(qreal y READ y WRITE setY) 276 Q_PROPERTY(qreal z READ z WRITE setZ) 277 Q_OBJECT 278 public: 279 QDeclarativeVector3DValueType(QObject *parent = 0); 280 281 virtual void read(QObject *, int); 282 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 283 virtual QVariant value(); 284 virtual void setValue(QVariant value); 285 286 qreal x() const; 287 qreal y() const; 288 qreal z() const; 289 void setX(qreal); 290 void setY(qreal); 291 void setZ(qreal); 292 293 private: 294 QVector3D vector; 295 }; 296 297 class Q_AUTOTEST_EXPORT QDeclarativeVector4DValueType : public QDeclarativeValueType 298 { 299 Q_PROPERTY(qreal x READ x WRITE setX) 300 Q_PROPERTY(qreal y READ y WRITE setY) 301 Q_PROPERTY(qreal z READ z WRITE setZ) 302 Q_PROPERTY(qreal w READ w WRITE setW) 303 Q_OBJECT 304 public: 305 QDeclarativeVector4DValueType(QObject *parent = 0); 306 307 virtual void read(QObject *, int); 308 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 309 virtual QVariant value(); 310 virtual void setValue(QVariant value); 311 312 qreal x() const; 313 qreal y() const; 314 qreal z() const; 315 qreal w() const; 316 void setX(qreal); 317 void setY(qreal); 318 void setZ(qreal); 319 void setW(qreal); 320 321 private: 322 QVector4D vector; 323 }; 324 325 class Q_AUTOTEST_EXPORT QDeclarativeQuaternionValueType : public QDeclarativeValueType 326 { 327 Q_PROPERTY(qreal scalar READ scalar WRITE setScalar) 328 Q_PROPERTY(qreal x READ x WRITE setX) 329 Q_PROPERTY(qreal y READ y WRITE setY) 330 Q_PROPERTY(qreal z READ z WRITE setZ) 331 Q_OBJECT 332 public: 333 QDeclarativeQuaternionValueType(QObject *parent = 0); 334 335 virtual void read(QObject *, int); 336 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 337 virtual QVariant value(); 338 virtual void setValue(QVariant value); 339 340 qreal scalar() const; 341 qreal x() const; 342 qreal y() const; 343 qreal z() const; 344 void setScalar(qreal); 345 void setX(qreal); 346 void setY(qreal); 347 void setZ(qreal); 348 349 private: 350 QQuaternion quaternion; 351 }; 352 353 class Q_AUTOTEST_EXPORT QDeclarativeMatrix4x4ValueType : public QDeclarativeValueType 354 { 355 Q_PROPERTY(qreal m11 READ m11 WRITE setM11) 356 Q_PROPERTY(qreal m12 READ m12 WRITE setM12) 357 Q_PROPERTY(qreal m13 READ m13 WRITE setM13) 358 Q_PROPERTY(qreal m14 READ m14 WRITE setM14) 359 Q_PROPERTY(qreal m21 READ m21 WRITE setM21) 360 Q_PROPERTY(qreal m22 READ m22 WRITE setM22) 361 Q_PROPERTY(qreal m23 READ m23 WRITE setM23) 362 Q_PROPERTY(qreal m24 READ m24 WRITE setM24) 363 Q_PROPERTY(qreal m31 READ m31 WRITE setM31) 364 Q_PROPERTY(qreal m32 READ m32 WRITE setM32) 365 Q_PROPERTY(qreal m33 READ m33 WRITE setM33) 366 Q_PROPERTY(qreal m34 READ m34 WRITE setM34) 367 Q_PROPERTY(qreal m41 READ m41 WRITE setM41) 368 Q_PROPERTY(qreal m42 READ m42 WRITE setM42) 369 Q_PROPERTY(qreal m43 READ m43 WRITE setM43) 370 Q_PROPERTY(qreal m44 READ m44 WRITE setM44) 371 Q_OBJECT 372 public: 373 QDeclarativeMatrix4x4ValueType(QObject *parent = 0); 374 375 virtual void read(QObject *, int); 376 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 377 virtual QVariant value(); 378 virtual void setValue(QVariant value); 379 m11()380 qreal m11() const { return matrix(0, 0); } m12()381 qreal m12() const { return matrix(0, 1); } m13()382 qreal m13() const { return matrix(0, 2); } m14()383 qreal m14() const { return matrix(0, 3); } m21()384 qreal m21() const { return matrix(1, 0); } m22()385 qreal m22() const { return matrix(1, 1); } m23()386 qreal m23() const { return matrix(1, 2); } m24()387 qreal m24() const { return matrix(1, 3); } m31()388 qreal m31() const { return matrix(2, 0); } m32()389 qreal m32() const { return matrix(2, 1); } m33()390 qreal m33() const { return matrix(2, 2); } m34()391 qreal m34() const { return matrix(2, 3); } m41()392 qreal m41() const { return matrix(3, 0); } m42()393 qreal m42() const { return matrix(3, 1); } m43()394 qreal m43() const { return matrix(3, 2); } m44()395 qreal m44() const { return matrix(3, 3); } 396 setM11(qreal value)397 void setM11(qreal value) { matrix(0, 0) = value; } setM12(qreal value)398 void setM12(qreal value) { matrix(0, 1) = value; } setM13(qreal value)399 void setM13(qreal value) { matrix(0, 2) = value; } setM14(qreal value)400 void setM14(qreal value) { matrix(0, 3) = value; } setM21(qreal value)401 void setM21(qreal value) { matrix(1, 0) = value; } setM22(qreal value)402 void setM22(qreal value) { matrix(1, 1) = value; } setM23(qreal value)403 void setM23(qreal value) { matrix(1, 2) = value; } setM24(qreal value)404 void setM24(qreal value) { matrix(1, 3) = value; } setM31(qreal value)405 void setM31(qreal value) { matrix(2, 0) = value; } setM32(qreal value)406 void setM32(qreal value) { matrix(2, 1) = value; } setM33(qreal value)407 void setM33(qreal value) { matrix(2, 2) = value; } setM34(qreal value)408 void setM34(qreal value) { matrix(2, 3) = value; } setM41(qreal value)409 void setM41(qreal value) { matrix(3, 0) = value; } setM42(qreal value)410 void setM42(qreal value) { matrix(3, 1) = value; } setM43(qreal value)411 void setM43(qreal value) { matrix(3, 2) = value; } setM44(qreal value)412 void setM44(qreal value) { matrix(3, 3) = value; } 413 414 private: 415 QMatrix4x4 matrix; 416 }; 417 418 class Q_AUTOTEST_EXPORT QDeclarativeEasingValueType : public QDeclarativeValueType 419 { 420 Q_OBJECT 421 Q_ENUMS(Type) 422 423 Q_PROPERTY(QDeclarativeEasingValueType::Type type READ type WRITE setType) 424 Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude) 425 Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot) 426 Q_PROPERTY(qreal period READ period WRITE setPeriod) 427 public: 428 enum Type { 429 Linear = QEasingCurve::Linear, 430 InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad, 431 InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad, 432 InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic, 433 InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic, 434 InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart, 435 InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart, 436 InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint, 437 InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint, 438 InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine, 439 InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine, 440 InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo, 441 InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo, 442 InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc, 443 InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc, 444 InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic, 445 InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic, 446 InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack, 447 InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack, 448 InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce, 449 InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce, 450 InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve, 451 SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve 452 }; 453 454 QDeclarativeEasingValueType(QObject *parent = 0); 455 456 virtual void read(QObject *, int); 457 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 458 virtual QVariant value(); 459 virtual void setValue(QVariant value); 460 461 Type type() const; 462 qreal amplitude() const; 463 qreal overshoot() const; 464 qreal period() const; 465 void setType(Type); 466 void setAmplitude(qreal); 467 void setOvershoot(qreal); 468 void setPeriod(qreal); 469 470 private: 471 QEasingCurve easing; 472 }; 473 474 class Q_AUTOTEST_EXPORT QDeclarativeFontValueType : public QDeclarativeValueType 475 { 476 Q_OBJECT 477 Q_ENUMS(FontWeight) 478 Q_ENUMS(Capitalization) 479 480 Q_PROPERTY(QString family READ family WRITE setFamily) 481 Q_PROPERTY(bool bold READ bold WRITE setBold) 482 Q_PROPERTY(FontWeight weight READ weight WRITE setWeight) 483 Q_PROPERTY(bool italic READ italic WRITE setItalic) 484 Q_PROPERTY(bool underline READ underline WRITE setUnderline) 485 Q_PROPERTY(bool overline READ overline WRITE setOverline) 486 Q_PROPERTY(bool strikeout READ strikeout WRITE setStrikeout) 487 Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize) 488 Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize) 489 Q_PROPERTY(Capitalization capitalization READ capitalization WRITE setCapitalization) 490 Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing) 491 Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing) 492 493 public: 494 enum FontWeight { Light = QFont::Light, 495 Normal = QFont::Normal, 496 DemiBold = QFont::DemiBold, 497 Bold = QFont::Bold, 498 Black = QFont::Black }; 499 enum Capitalization { MixedCase = QFont::MixedCase, 500 AllUppercase = QFont::AllUppercase, 501 AllLowercase = QFont::AllLowercase, 502 SmallCaps = QFont::SmallCaps, 503 Capitalize = QFont::Capitalize }; 504 505 QDeclarativeFontValueType(QObject *parent = 0); 506 507 virtual void read(QObject *, int); 508 virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); 509 virtual QVariant value(); 510 virtual void setValue(QVariant value); 511 512 QString family() const; 513 void setFamily(const QString &); 514 515 bool bold() const; 516 void setBold(bool b); 517 518 FontWeight weight() const; 519 void setWeight(FontWeight); 520 521 bool italic() const; 522 void setItalic(bool b); 523 524 bool underline() const; 525 void setUnderline(bool b); 526 527 bool overline() const; 528 void setOverline(bool b); 529 530 bool strikeout() const; 531 void setStrikeout(bool b); 532 533 qreal pointSize() const; 534 void setPointSize(qreal size); 535 536 int pixelSize() const; 537 void setPixelSize(int size); 538 539 Capitalization capitalization() const; 540 void setCapitalization(Capitalization); 541 542 qreal letterSpacing() const; 543 void setLetterSpacing(qreal spacing); 544 545 qreal wordSpacing() const; 546 void setWordSpacing(qreal spacing); 547 548 private: 549 QFont font; 550 bool pixelSizeSet; 551 bool pointSizeSet; 552 mutable QDeclarativeNullableValue<int> dpi; 553 }; 554 555 QT_END_NAMESPACE 556 557 #endif // QDECLARATIVEVALUETYPE_P_H 558