src/tools/uic3/domtool.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the tools applications of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef DOMTOOL_H
       
    43 #define DOMTOOL_H
       
    44 
       
    45 #include <QVariant>
       
    46 
       
    47 QT_BEGIN_NAMESPACE
       
    48 
       
    49 class QDomElement;
       
    50 class QDomDocument;
       
    51 class QDomNode;
       
    52 class QDomNodeList;
       
    53 
       
    54 struct Common
       
    55 {
       
    56     int kind;
       
    57 
       
    58     enum {
       
    59         Kind_Unknown = 0,
       
    60         Kind_Color,
       
    61         Kind_Point,
       
    62         Kind_Size,
       
    63         Kind_Rect,
       
    64         Kind_Font,
       
    65         Kind_SizePolicy,
       
    66         Kind_Cursor
       
    67     };
       
    68 
       
    69     inline void init()
       
    70     { kind = Kind_Unknown; }
       
    71 };
       
    72 
       
    73 struct Color
       
    74 {
       
    75     Common common;
       
    76     int red, green, blue;
       
    77 
       
    78     inline void init(int r, int g, int b)
       
    79     {
       
    80         common.kind = Common::Kind_Color;
       
    81         red = r;
       
    82         green = g;
       
    83         blue = b;
       
    84     }
       
    85 
       
    86     inline bool operator == (const Color &other) const
       
    87     { return red == other.red && green == other.green && blue == other.blue; }
       
    88 };
       
    89 
       
    90 struct Point
       
    91 {
       
    92     Common common;
       
    93     int x, y;
       
    94 
       
    95     inline void init(int x, int y)
       
    96     {
       
    97         common.kind = Common::Kind_Point;
       
    98         this->x = x;
       
    99         this->y = y;
       
   100     }
       
   101 };
       
   102 
       
   103 struct Size
       
   104 {
       
   105     Common common;
       
   106     int width, height;
       
   107 
       
   108     inline bool isNull() const
       
   109     { return this->width == 0 && this->height == 0; }
       
   110 
       
   111     inline void init(int width, int height)
       
   112     {
       
   113         common.kind = Common::Kind_Size;
       
   114         this->width = width;
       
   115         this->height = height;
       
   116     }
       
   117 };
       
   118 
       
   119 struct Rect
       
   120 {
       
   121     Common common;
       
   122     int x, y;
       
   123     int width, height;
       
   124 
       
   125     inline void init(int x, int y, int width, int height)
       
   126     {
       
   127         common.kind = Common::Kind_Rect;
       
   128         this->x = x;
       
   129         this->y = y;
       
   130         this->width = width;
       
   131         this->height = height;
       
   132     }
       
   133 };
       
   134 
       
   135 struct Font
       
   136 {
       
   137     Common common;
       
   138     char *family;
       
   139     int pointsize;
       
   140     bool bold;
       
   141     bool italic;
       
   142     bool underline;
       
   143     bool strikeout;
       
   144 
       
   145     inline void init()
       
   146     {
       
   147         common.kind = Common::Kind_Font;
       
   148         family = 0;
       
   149         pointsize = 0;
       
   150         bold = false;
       
   151         italic = false;
       
   152         underline = false;
       
   153         strikeout = false;
       
   154     }
       
   155 };
       
   156 
       
   157 struct SizePolicy
       
   158 {
       
   159     Common common;
       
   160     int hsizetype;
       
   161     int vsizetype;
       
   162     int horstretch;
       
   163     int verstretch;
       
   164 
       
   165     inline void init()
       
   166     {
       
   167         common.kind = Common::Kind_SizePolicy;
       
   168         hsizetype = 0;
       
   169         vsizetype = 0;
       
   170         horstretch = 0;
       
   171         verstretch = 0;
       
   172     }
       
   173 };
       
   174 
       
   175 struct Cursor
       
   176 {
       
   177     Common common;
       
   178     int shape;
       
   179 
       
   180     inline void init(int shape)
       
   181     {
       
   182         common.kind = Common::Kind_Cursor;
       
   183         this->shape = shape;
       
   184     }
       
   185 };
       
   186 
       
   187 union Variant
       
   188 {
       
   189     Common common;
       
   190     Color color;
       
   191     Size size;
       
   192     Point point;
       
   193     Rect rect;
       
   194     Font font;
       
   195     SizePolicy sizePolicy;
       
   196     Cursor cursor;
       
   197 
       
   198     inline Variant()
       
   199     { common.kind = Common::Kind_Unknown; }
       
   200 
       
   201     inline ~Variant()
       
   202     {
       
   203         if (common.kind == Common::Kind_Font) {
       
   204             delete[] font.family;
       
   205             font.family = 0;
       
   206         }
       
   207     }
       
   208 
       
   209     inline int kind() const
       
   210     { return common.kind; }
       
   211 
       
   212     inline Variant &createColor(int r, int g, int b)
       
   213     { color.init(r, g, b); return *this; }
       
   214 
       
   215     inline Variant &createPoint(int x, int y)
       
   216     { point.init(x, y); return *this; }
       
   217 
       
   218     inline Variant &createSize(int width, int height)
       
   219     { size.init(width, height); return *this; }
       
   220 
       
   221     inline Variant &createRect(int x, int y, int w, int h)
       
   222     { rect.init(x, y, w, h); return *this; }
       
   223 
       
   224     inline Variant &createFont()
       
   225     { font.init(); return *this; }
       
   226 
       
   227     inline Variant &createSizePolicy()
       
   228     { sizePolicy.init(); return *this; }
       
   229 
       
   230     inline Variant &createCursor(int shape)
       
   231     { cursor.init(shape); return *this; }
       
   232 };
       
   233 
       
   234 class DomTool
       
   235 {
       
   236 public:
       
   237     static QVariant readProperty(const QDomElement& e, const QString& name, const QVariant& defValue);
       
   238     static QVariant readProperty(const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment);
       
   239     static bool hasProperty(const QDomElement& e, const QString& name);
       
   240     static QStringList propertiesOfType(const QDomElement& e, const QString& type);
       
   241     static QVariant elementToVariant(const QDomElement& e, const QVariant& defValue);
       
   242     static QVariant elementToVariant(const QDomElement& e, const QVariant& defValue, QString &comment);
       
   243     static QVariant readAttribute(const QDomElement& e, const QString& name, const QVariant& defValue);
       
   244     static QVariant readAttribute(const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment);
       
   245     static bool hasAttribute(const QDomElement& e, const QString& name);
       
   246     static Color readColor(const QDomElement &e);
       
   247     static void fixDocument(QDomDocument&);
       
   248     static void fixAttributes(QDomNodeList&, double);
       
   249     static void fixAttribute(QDomNode&, double);
       
   250 };
       
   251 
       
   252 QT_END_NAMESPACE
       
   253 
       
   254 Q_DECLARE_METATYPE(Size)
       
   255 Q_DECLARE_METATYPE(Rect)
       
   256 Q_DECLARE_METATYPE(Font)
       
   257 Q_DECLARE_METATYPE(SizePolicy)
       
   258 Q_DECLARE_METATYPE(Cursor)
       
   259 Q_DECLARE_METATYPE(Color)
       
   260 Q_DECLARE_METATYPE(Point)
       
   261 Q_DECLARE_METATYPE(Common)
       
   262 Q_DECLARE_METATYPE(Variant)
       
   263 
       
   264 QT_BEGIN_NAMESPACE
       
   265 
       
   266 inline Variant asVariant(const QVariant &v)
       
   267 {
       
   268     Variant var;
       
   269     var = qVariantValue<Variant>(v);
       
   270     return var;
       
   271 }
       
   272 
       
   273 QT_END_NAMESPACE
       
   274 
       
   275 #endif // DOMTOOL_H