src/declarative/graphicsitems/qdeclarativepathview_p.h
changeset 30 5dc02b23752f
child 33 3e2da88830cd
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: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 QDECLARATIVEPATHVIEW_H
       
    43 #define QDECLARATIVEPATHVIEW_H
       
    44 
       
    45 #include "qdeclarativeitem.h"
       
    46 #include "private/qdeclarativepath_p.h"
       
    47 
       
    48 QT_BEGIN_HEADER
       
    49 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 QT_MODULE(Declarative)
       
    53 
       
    54 class QDeclarativePathViewPrivate;
       
    55 class QDeclarativePathViewAttached;
       
    56 class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem
       
    57 {
       
    58     Q_OBJECT
       
    59 
       
    60     Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
       
    61     Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged)
       
    62     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
       
    63     Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged)
       
    64 
       
    65     Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
       
    66     Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
       
    67 
       
    68     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
       
    69     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
       
    70     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
       
    71     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
       
    72 
       
    73     Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged)
       
    74     Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
       
    75     Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
       
    76 
       
    77     Q_PROPERTY(int count READ count NOTIFY countChanged)
       
    78     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
       
    79     Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged)
       
    80 
       
    81     Q_ENUMS(HighlightRangeMode)
       
    82 
       
    83 public:
       
    84     QDeclarativePathView(QDeclarativeItem *parent=0);
       
    85     virtual ~QDeclarativePathView();
       
    86 
       
    87     QVariant model() const;
       
    88     void setModel(const QVariant &);
       
    89 
       
    90     QDeclarativePath *path() const;
       
    91     void setPath(QDeclarativePath *);
       
    92 
       
    93     int currentIndex() const;
       
    94     void setCurrentIndex(int idx);
       
    95 
       
    96     qreal offset() const;
       
    97     void setOffset(qreal offset);
       
    98 
       
    99     QDeclarativeComponent *highlight() const;
       
   100     void setHighlight(QDeclarativeComponent *highlight);
       
   101     QDeclarativeItem *highlightItem();
       
   102 
       
   103     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
       
   104     HighlightRangeMode highlightRangeMode() const;
       
   105     void setHighlightRangeMode(HighlightRangeMode mode);
       
   106 
       
   107     qreal preferredHighlightBegin() const;
       
   108     void setPreferredHighlightBegin(qreal);
       
   109 
       
   110     qreal preferredHighlightEnd() const;
       
   111     void setPreferredHighlightEnd(qreal);
       
   112 
       
   113     int highlightMoveDuration() const;
       
   114     void setHighlightMoveDuration(int);
       
   115 
       
   116     qreal dragMargin() const;
       
   117     void setDragMargin(qreal margin);
       
   118 
       
   119     qreal flickDeceleration() const;
       
   120     void setFlickDeceleration(qreal dec);
       
   121 
       
   122     bool isInteractive() const;
       
   123     void setInteractive(bool);
       
   124 
       
   125     int count() const;
       
   126 
       
   127     QDeclarativeComponent *delegate() const;
       
   128     void setDelegate(QDeclarativeComponent *);
       
   129 
       
   130     int pathItemCount() const;
       
   131     void setPathItemCount(int);
       
   132 
       
   133     static QDeclarativePathViewAttached *qmlAttachedProperties(QObject *);
       
   134 
       
   135 public Q_SLOTS:
       
   136     void incrementCurrentIndex();
       
   137     void decrementCurrentIndex();
       
   138 
       
   139 Q_SIGNALS:
       
   140     void currentIndexChanged();
       
   141     void offsetChanged();
       
   142     void modelChanged();
       
   143     void countChanged();
       
   144     void pathChanged();
       
   145     void preferredHighlightBeginChanged();
       
   146     void preferredHighlightEndChanged();
       
   147     void highlightRangeModeChanged();
       
   148     void dragMarginChanged();
       
   149     void snapPositionChanged();
       
   150     void delegateChanged();
       
   151     void pathItemCountChanged();
       
   152     void flickDecelerationChanged();
       
   153     void interactiveChanged();
       
   154     void highlightChanged();
       
   155     void highlightItemChanged();
       
   156     void highlightMoveDurationChanged();
       
   157 
       
   158 protected:
       
   159     void mousePressEvent(QGraphicsSceneMouseEvent *event);
       
   160     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
       
   161     void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
       
   162     bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
       
   163     bool sceneEventFilter(QGraphicsItem *, QEvent *);
       
   164     void componentComplete();
       
   165 
       
   166 private Q_SLOTS:
       
   167     void refill();
       
   168     void ticked();
       
   169     void itemsInserted(int index, int count);
       
   170     void itemsRemoved(int index, int count);
       
   171     void itemsMoved(int,int,int);
       
   172     void modelReset();
       
   173     void createdItem(int index, QDeclarativeItem *item);
       
   174     void destroyingItem(QDeclarativeItem *item);
       
   175 
       
   176 private:
       
   177     friend class QDeclarativePathViewAttached;
       
   178     Q_DISABLE_COPY(QDeclarativePathView)
       
   179     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativePathView)
       
   180 };
       
   181 
       
   182 class QDeclarativeOpenMetaObject;
       
   183 class QDeclarativePathViewAttached : public QObject
       
   184 {
       
   185     Q_OBJECT
       
   186 
       
   187     Q_PROPERTY(QDeclarativePathView *view READ view CONSTANT)
       
   188     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
       
   189     Q_PROPERTY(bool onPath READ isOnPath NOTIFY pathChanged)
       
   190 
       
   191 public:
       
   192     QDeclarativePathViewAttached(QObject *parent);
       
   193     ~QDeclarativePathViewAttached();
       
   194 
       
   195     QDeclarativePathView *view() { return m_view; }
       
   196 
       
   197     bool isCurrentItem() const { return m_isCurrent; }
       
   198     void setIsCurrentItem(bool c) {
       
   199         if (m_isCurrent != c) {
       
   200             m_isCurrent = c;
       
   201             emit currentItemChanged();
       
   202         }
       
   203     }
       
   204 
       
   205     QVariant value(const QByteArray &name) const;
       
   206     void setValue(const QByteArray &name, const QVariant &val);
       
   207 
       
   208     bool isOnPath() const { return m_onPath; }
       
   209     void setOnPath(bool on) {
       
   210         if (on != m_onPath) {
       
   211             m_onPath = on;
       
   212             emit pathChanged();
       
   213         }
       
   214     }
       
   215 
       
   216 Q_SIGNALS:
       
   217     void currentItemChanged();
       
   218     void pathChanged();
       
   219 
       
   220 private:
       
   221     friend class QDeclarativePathViewPrivate;
       
   222     friend class QDeclarativePathView;
       
   223     QDeclarativePathView *m_view;
       
   224     QDeclarativeOpenMetaObject *m_metaobject;
       
   225     bool m_onPath : 1;
       
   226     bool m_isCurrent : 1;
       
   227 };
       
   228 
       
   229 
       
   230 QT_END_NAMESPACE
       
   231 
       
   232 QML_DECLARE_TYPE(QDeclarativePathView)
       
   233 QML_DECLARE_TYPEINFO(QDeclarativePathView, QML_HAS_ATTACHED_PROPERTIES)
       
   234 QT_END_HEADER
       
   235 
       
   236 #endif // QDECLARATIVEPATHVIEW_H