examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h
changeset 30 5dc02b23752f
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:BSD$
       
    10 ** You may use this file under the terms of the BSD license as follows:
       
    11 **
       
    12 ** "Redistribution and use in source and binary forms, with or without
       
    13 ** modification, are permitted provided that the following conditions are
       
    14 ** met:
       
    15 **   * Redistributions of source code must retain the above copyright
       
    16 **     notice, this list of conditions and the following disclaimer.
       
    17 **   * Redistributions in binary form must reproduce the above copyright
       
    18 **     notice, this list of conditions and the following disclaimer in
       
    19 **     the documentation and/or other materials provided with the
       
    20 **     distribution.
       
    21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
       
    22 **     the names of its contributors may be used to endorse or promote
       
    23 **     products derived from this software without specific prior written
       
    24 **     permission.
       
    25 **
       
    26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
       
    37 ** $QT_END_LICENSE$
       
    38 **
       
    39 ****************************************************************************/
       
    40 
       
    41 #ifndef GRAPHICSLAYOUTS_H
       
    42 #define GRAPHICSLAYOUTS_H
       
    43 
       
    44 #include <QtGui/QGraphicsLinearLayout>
       
    45 #include <QtGui/QGraphicsGridLayout>
       
    46 #include <qdeclarative.h>
       
    47 
       
    48 QT_BEGIN_HEADER
       
    49 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 QT_MODULE(Declarative)
       
    53 
       
    54 class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem
       
    55 {
       
    56     Q_OBJECT
       
    57     Q_INTERFACES(QGraphicsLayoutItem)
       
    58 public:
       
    59     QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0);
       
    60 
       
    61     virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const;
       
    62 };
       
    63 
       
    64 class LinearLayoutAttached;
       
    65 class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout
       
    66 {
       
    67     Q_OBJECT
       
    68     Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem)
       
    69 
       
    70     Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children)
       
    71     Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
       
    72     Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing)
       
    73     Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin)
       
    74     Q_CLASSINFO("DefaultProperty", "children")
       
    75 public:
       
    76     QGraphicsLinearLayoutObject(QObject * = 0);
       
    77     ~QGraphicsLinearLayoutObject();
       
    78 
       
    79     QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); }
       
    80 
       
    81     static LinearLayoutAttached *qmlAttachedProperties(QObject *);
       
    82 
       
    83     qreal contentsMargin() const;
       
    84     void setContentsMargin(qreal);
       
    85 
       
    86 private Q_SLOTS:
       
    87     void updateStretch(QGraphicsLayoutItem*,int);
       
    88     void updateSpacing(QGraphicsLayoutItem*,int);
       
    89     void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
       
    90 
       
    91 private:
       
    92     friend class LinearLayoutAttached;
       
    93     void clearChildren();
       
    94     void insertLayoutItem(int, QGraphicsLayoutItem *);
       
    95     static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties;
       
    96 
       
    97     static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
       
    98         static_cast<QGraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item);
       
    99     }
       
   100 
       
   101     static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
       
   102         static_cast<QGraphicsLinearLayoutObject*>(prop->object)->clearChildren();
       
   103     }
       
   104 
       
   105     static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
       
   106         return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->count();
       
   107     }
       
   108 
       
   109     static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
       
   110         return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->itemAt(index);
       
   111     }
       
   112 };
       
   113 
       
   114 class GridLayoutAttached;
       
   115 class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout
       
   116 {
       
   117     Q_OBJECT
       
   118     Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem)
       
   119 
       
   120     Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children)
       
   121     Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing)
       
   122     Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin)
       
   123     Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
       
   124     Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
       
   125     Q_CLASSINFO("DefaultProperty", "children")
       
   126 public:
       
   127     QGraphicsGridLayoutObject(QObject * = 0);
       
   128     ~QGraphicsGridLayoutObject();
       
   129 
       
   130     QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); }
       
   131 
       
   132     qreal spacing() const;
       
   133     qreal contentsMargin() const;
       
   134     void setContentsMargin(qreal);
       
   135 
       
   136     static GridLayoutAttached *qmlAttachedProperties(QObject *);
       
   137 
       
   138 private Q_SLOTS:
       
   139     void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
       
   140 
       
   141 private:
       
   142     friend class GraphicsLayoutAttached;
       
   143     void addWidget(QGraphicsWidget *);
       
   144     void clearChildren();
       
   145     void addLayoutItem(QGraphicsLayoutItem *);
       
   146     static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties;
       
   147 
       
   148     static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
       
   149         static_cast<QGraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item);
       
   150     }
       
   151 
       
   152     static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
       
   153         static_cast<QGraphicsGridLayoutObject*>(prop->object)->clearChildren();
       
   154     }
       
   155 
       
   156     static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
       
   157         return static_cast<QGraphicsGridLayoutObject*>(prop->object)->count();
       
   158     }
       
   159 
       
   160     static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
       
   161         return static_cast<QGraphicsGridLayoutObject*>(prop->object)->itemAt(index);
       
   162     }
       
   163 };
       
   164 
       
   165 class LinearLayoutAttached : public QObject
       
   166 {
       
   167     Q_OBJECT
       
   168 
       
   169     Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged)
       
   170     Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
       
   171     Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
       
   172 public:
       
   173     LinearLayoutAttached(QObject *parent);
       
   174 
       
   175     int stretchFactor() const { return _stretch; }
       
   176     void setStretchFactor(int f);
       
   177     Qt::Alignment alignment() const { return _alignment; }
       
   178     void setAlignment(Qt::Alignment a);
       
   179     int spacing() const { return _spacing; }
       
   180     void setSpacing(int s);
       
   181 
       
   182 Q_SIGNALS:
       
   183     void stretchChanged(QGraphicsLayoutItem*,int);
       
   184     void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment);
       
   185     void spacingChanged(QGraphicsLayoutItem*,int);
       
   186 
       
   187 private:
       
   188     int _stretch;
       
   189     Qt::Alignment _alignment;
       
   190     int _spacing;
       
   191 };
       
   192 
       
   193 class GridLayoutAttached : public QObject
       
   194 {
       
   195     Q_OBJECT
       
   196 
       
   197     Q_PROPERTY(int row READ row WRITE setRow)
       
   198     Q_PROPERTY(int column READ column WRITE setColumn)
       
   199     Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan)
       
   200     Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan)
       
   201     Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
       
   202     Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor)
       
   203     Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor)
       
   204     Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
       
   205     Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
       
   206     Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight)
       
   207     Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight)
       
   208     Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight)
       
   209     Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight)
       
   210     Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth)
       
   211     Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth)
       
   212     Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth)
       
   213     Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth)
       
   214 
       
   215 public:
       
   216     GridLayoutAttached(QObject *parent);
       
   217 
       
   218     int row() const { return _row; }
       
   219     void setRow(int r);
       
   220 
       
   221     int column() const { return _column; }
       
   222     void setColumn(int c);
       
   223 
       
   224     int rowSpan() const { return _rowspan; }
       
   225     void setRowSpan(int rs);
       
   226 
       
   227     int columnSpan() const { return _colspan; }
       
   228     void setColumnSpan(int cs);
       
   229 
       
   230     Qt::Alignment alignment() const { return _alignment; }
       
   231     void setAlignment(Qt::Alignment a);
       
   232 
       
   233     int rowStretchFactor() const { return _rowstretch; }
       
   234     void setRowStretchFactor(int f);
       
   235     int columnStretchFactor() const { return _colstretch; }
       
   236     void setColumnStretchFactor(int f);
       
   237 
       
   238     int rowSpacing() const { return _rowspacing; }
       
   239     void setRowSpacing(int s);
       
   240     int columnSpacing() const { return _colspacing; }
       
   241     void setColumnSpacing(int s);
       
   242 
       
   243     int rowPreferredHeight() const { return _rowprefheight; }
       
   244     void setRowPreferredHeight(int s) { _rowprefheight = s; }
       
   245 
       
   246     int rowMaximumHeight() const { return _rowmaxheight; }
       
   247     void setRowMaximumHeight(int s) { _rowmaxheight = s; }
       
   248 
       
   249     int rowMinimumHeight() const { return _rowminheight; }
       
   250     void setRowMinimumHeight(int s) { _rowminheight = s; }
       
   251 
       
   252     int rowFixedHeight() const { return _rowfixheight; }
       
   253     void setRowFixedHeight(int s) { _rowfixheight = s; }
       
   254 
       
   255     int columnPreferredWidth() const { return _colprefwidth; }
       
   256     void setColumnPreferredWidth(int s) { _colprefwidth = s; }
       
   257 
       
   258     int columnMaximumWidth() const { return _colmaxwidth; }
       
   259     void setColumnMaximumWidth(int s) { _colmaxwidth = s; }
       
   260 
       
   261     int columnMinimumWidth() const { return _colminwidth; }
       
   262     void setColumnMinimumWidth(int s) { _colminwidth = s; }
       
   263 
       
   264     int columnFixedWidth() const { return _colfixwidth; }
       
   265     void setColumnFixedWidth(int s) { _colfixwidth = s; }
       
   266 
       
   267 Q_SIGNALS:
       
   268     void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment);
       
   269 
       
   270 private:
       
   271     int _row;
       
   272     int _column;
       
   273     int _rowspan;
       
   274     int _colspan;
       
   275     Qt::Alignment _alignment;
       
   276     int _rowstretch;
       
   277     int _colstretch;
       
   278     int _rowspacing;
       
   279     int _colspacing;
       
   280     int _rowprefheight;
       
   281     int _rowmaxheight;
       
   282     int _rowminheight;
       
   283     int _rowfixheight;
       
   284     int _colprefwidth;
       
   285     int _colmaxwidth;
       
   286     int _colminwidth;
       
   287     int _colfixwidth;
       
   288 };
       
   289 
       
   290 QT_END_NAMESPACE
       
   291 
       
   292 QML_DECLARE_INTERFACE(QGraphicsLayoutItem)
       
   293 QML_DECLARE_INTERFACE(QGraphicsLayout)
       
   294 QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject)
       
   295 QML_DECLARE_TYPE(QGraphicsLinearLayoutObject)
       
   296 QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES)
       
   297 QML_DECLARE_TYPE(QGraphicsGridLayoutObject)
       
   298 QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES)
       
   299 
       
   300 QT_END_HEADER
       
   301 
       
   302 #endif // GRAPHICSLAYOUTS_H