/* properties.h This file is part of the Project::OSiRiON world editor and is distributed under the terms and conditions of the GNU General Public License version 2 */ #ifndef __INCLUDED_EDITOR_PROPERTIES__ #define __INCLUDED_EDITOR_PROPERTIES__ #include "vector3f.h" #include #include #include #include namespace editor { /** * @brief abstract base class to hold properties for game objects * */ class Properties { public: Properties(); /** * @brief copy constructor * */ Properties(const Properties & other); virtual ~Properties(); /* ---- inspectors ---- */ /** * @brief returns the label of this object * */ inline const QString &label() const { return properties_label; } /** * @brief returns the name of this object * */ inline const QString &name() const { return properties_name; } /** * @brief returns the location of this object * */ inline const Vector3f &location() const { return properties_location; } /** * @brief returns the color of this object * */ inline const QColor &color() const { return properties_color; } /** * @brief returns the comment string of this object * */ inline const QString &comment() const { return properties_comment; } /** * @brief returns the comment string for a specified attribute * */ inline const QString comment(const QString &attribute) const { return properties_comments[attribute]; } /** * @brief returns the info string of this object * */ inline const QString &info() const { return properties_info; } /** * @brief returns the values string of this object * */ inline const QString &values() const { return properties_values; } /* ---- mutators ---- */ /** * @brief assign all values of another Properties instance to this instance * */ void assign(const Properties & other); /** * @brief assignment operator * */ inline Properties & operator=(const Properties & other) { assign(other); return *this; } /** * @brief set the comments string of this object * */ inline void set_comment(const QString &text) { properties_comment = text; } /** * @brief set the comments string for a specified attribute * */ inline void set_comment(const QString attribute, const QString &text) { properties_comments[attribute] = text; } /** * @brief set the info string of this object * */ inline void set_info(const QString &text) { properties_info = text; } /** * @brief add a line of text to the info string of this object * */ void add_info(const QString &text); /** * @brief set the subsection string of this object * */ inline void set_values(const QString &text) { properties_values = text; } /** * @brief add a value key pair to the values string * */ void add_value(const QString &key, const QString &value, const QString &comment); /** * @brief set the object label * */ inline void set_label(const QString &label) { properties_label = label; } /** * @brief set the object name * */ inline void set_name(const QString &name) { properties_name = name; } /** * @brief set the object location * */ inline void set_location(const Vector3f &location) { properties_location = location; } /** * @brief set the object location * */ inline void set_location(const float x, const float y, const float z) { properties_location.assign(x, y, z); } /** * @brief set the object color * */ inline void set_color(const QColor &color) { properties_color = color; } /** * @brief set the object color * */ inline void set_color(const float r, const float g, const float b) { float cr = r; float cg = g; float cb = b; // Qt RGB colors are in the 0-255 range if ((r <= 1) && (g <= 1) && (b <= 1)) { cr *= 255; cg *= 255; cg *= 255; } properties_color.setRgb(r, g, b); } protected: /** * @brief save attribute comments to a textstream * */ void save_comment(QTextStream &textstream, const QString &attribute); private: typedef QMap Comments; /// comments for this objects QString properties_comment; /// comments for the individual attributes; Comments properties_comments; QString properties_label; QString properties_name; Vector3f properties_location; QColor properties_color; QString properties_info; QString properties_values; }; } // namespace editor #endif // __INCLUDED_EDITOR_PROPERTIES__