1 /* This file is part of the KDE project 2 * 3 * Copyright (C) 2012 Inge Wallin <inge@lysator.liu.se> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KO3DSCENE_H 22 #define KO3DSCENE_H 23 24 // Qt 25 #include <QColor> 26 #include <QVector3D> 27 28 class KoXmlWriter; 29 class KoXmlElement; 30 31 32 /** A scene in which to show 3d objects. 33 * 34 * The scene parameters include camera parameters (origin, direction 35 * and up direction), the projection to be used and a shadow 36 * slant. All these are attributes of the element. 37 * 38 * The scene can also have a number of light sources as child 39 * elements. These are picked up from the XML element but others are 40 * ignored and have to be loaded by code that handles the actual 41 * element. 42 * 43 * In ODF 1.2, a scene description can be part of a dr3d:scene or 44 * chart:plot-area if the chart also has 3D mode set. 45 */ 46 47 48 #include "koodf_export.h" 49 50 51 class KOODF_EXPORT Ko3dScene 52 { 53 public: 54 enum Projection { 55 Parallel, 56 Perspective 57 }; 58 59 enum Shademode { 60 Flat, 61 Gouraud, 62 Phong, 63 Draft // Wireframe 64 }; 65 66 class Lightsource 67 { 68 public: 69 Lightsource(); 70 ~Lightsource(); 71 72 bool loadOdf(const KoXmlElement &lightElement); 73 void saveOdf(KoXmlWriter &writer) const; 74 75 // getters 76 QColor diffuseColor() const; 77 QVector3D direction() const; 78 bool enabled() const; 79 bool specular() const; 80 81 // setters 82 void setDiffuseColor(const QColor &color); 83 void setDirection(const QVector3D &direction); 84 void setEnabled(const bool enabled); 85 void setSpecular(const bool specular); 86 87 private: 88 QColor m_diffuseColor; 89 QVector3D m_direction; 90 bool m_enabled; 91 bool m_specular; 92 }; 93 94 Ko3dScene(); 95 ~Ko3dScene(); 96 97 bool loadOdf(const KoXmlElement &sceneElement); 98 void saveOdfAttributes(KoXmlWriter &writer) const; 99 void saveOdfChildren(KoXmlWriter &writer) const; 100 101 // getters 102 QVector3D vrp() const; 103 QVector3D vpn() const; 104 QVector3D vup() const; 105 Projection projection() const; 106 QString distance() const; 107 QString focalLength() const; 108 QString shadowSlant() const; 109 Shademode shadeMode() const; 110 QColor ambientColor() const; 111 bool lightingMode() const; 112 QString transform() const; 113 114 // setters 115 void setVrp(const QVector3D &vrp); 116 void setVpn(const QVector3D &vpn); 117 void setVup(const QVector3D &vup); 118 void setProjection(Projection projection); 119 void setDistance(const QString &distance); 120 void setFocalLength(const QString &focalLength); 121 void setShadowSlant(const QString &shadowSlant); 122 void setShadeMode(Shademode shadeMode); 123 void setAmbientColor(const QColor &ambientColor); 124 void setLightingMode(bool lightingMode); 125 void setTransform(const QString &transform); 126 127 private: 128 class Private; 129 Private * const d; 130 }; 131 132 Q_DECLARE_TYPEINFO(Ko3dScene::Lightsource, Q_MOVABLE_TYPE); 133 134 135 /** Try to load a 3d scene from an element and return a pointer to a 136 * Ko3dScene if it succeeded. 137 */ 138 KOODF_EXPORT Ko3dScene *load3dScene(const KoXmlElement &element); 139 140 141 #endif 142