~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to src/location/maps/tiled/qgeotiledmappixmapobjectinfo_p.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
**
9
9
** $QT_BEGIN_LICENSE:LGPL$
10
10
** Commercial Usage
11
 
** Licensees holding valid Qt Commercial licenses may use this file in
12
 
** accordance with the Qt Solutions Commercial License Agreement provided
13
 
** with the Software or, alternatively, in accordance with the terms
 
11
** Licensees holding valid Qt Commercial licenses may use this file in 
 
12
** accordance with the Qt Commercial License Agreement provided with
 
13
** the Software or, alternatively, in accordance with the terms
14
14
** contained in a written agreement between you and Nokia.
15
15
**
16
16
** GNU Lesser General Public License Usage
33
33
** ensure the GNU General Public License version 3.0 requirements will be
34
34
** met: http://www.gnu.org/copyleft/gpl.html.
35
35
**
36
 
** Please note Third Party Software included with Qt Solutions may impose
37
 
** additional restrictions and it is the user's responsibility to ensure
38
 
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
 
** Solutions Commercial license and the relevant license of the Third
40
 
** Party Software they are using.
41
 
**
42
36
** If you are unsure which license is appropriate for your use, please
43
37
** contact the sales department at qt-sales@nokia.com.
44
38
** $QT_END_LICENSE$
54
48
 
55
49
QTM_BEGIN_NAMESPACE
56
50
 
57
 
QGeoTiledMapPixmapObjectInfo::QGeoTiledMapPixmapObjectInfo(QGeoMapData *mapData, QGeoMapObject *mapObject)
58
 
        : QGeoTiledMapObjectInfo(mapData, mapObject),
59
 
        pixmapItem(0)
60
 
 
 
51
QGeoTiledMapPixmapObjectInfo::QGeoTiledMapPixmapObjectInfo(QGeoTiledMapData *mapData, QGeoMapObject *mapObject)
 
52
    : QGeoTiledMapObjectInfo(mapData, mapObject),
 
53
      pixmapItem2(0)
61
54
{
62
55
    pixmap = static_cast<QGeoMapPixmapObject*>(mapObject);
 
56
 
 
57
    connect(pixmap,
 
58
            SIGNAL(coordinateChanged(QGeoCoordinate)),
 
59
            this,
 
60
            SLOT(coordinateChanged(QGeoCoordinate)));
 
61
    connect(pixmap,
 
62
            SIGNAL(pixmapChanged(QPixmap)),
 
63
            this,
 
64
            SLOT(pixmapChanged(QPixmap)));
 
65
    connect(pixmap,
 
66
            SIGNAL(offsetChanged(QPoint)),
 
67
            this,
 
68
            SLOT(offsetChanged(QPoint)));
 
69
 
 
70
    pixmapItem1 = new QGraphicsPixmapItem();
 
71
    graphicsItem = pixmapItem1;
 
72
 
 
73
    pixmapChanged(this->pixmap->pixmap());
 
74
    coordinateChanged(this->pixmap->coordinate());
63
75
}
64
76
 
65
77
QGeoTiledMapPixmapObjectInfo::~QGeoTiledMapPixmapObjectInfo() {}
66
78
 
67
 
void QGeoTiledMapPixmapObjectInfo::objectUpdated()
68
 
{
69
 
    if (!pixmap->coordinate().isValid()
70
 
            || pixmap->pixmap().isNull()) {
71
 
        if (pixmapItem) {
72
 
            delete pixmapItem;
73
 
            pixmapItem = 0;
74
 
            graphicsItem = 0;
75
 
        }
76
 
        return;
77
 
    }
78
 
 
79
 
    if (!pixmapItem)
80
 
        pixmapItem = new QGraphicsPixmapItem();
81
 
 
82
 
    pixmapItem->setPixmap(pixmap->pixmap());
83
 
    pixmapItem->setPos(tiledMapData->coordinateToWorldPixel(pixmap->coordinate()));
84
 
    mapUpdated();
85
 
    graphicsItem = pixmapItem;
 
79
void QGeoTiledMapPixmapObjectInfo::updateValidity()
 
80
{
 
81
    setValid((pixmap->coordinate().isValid() && !pixmap->pixmap().isNull()));
 
82
}
 
83
 
 
84
void QGeoTiledMapPixmapObjectInfo::coordinateChanged(const QGeoCoordinate &coordinate)
 
85
{
 
86
    updateValidity();
 
87
    if (valid())
 
88
        update();
 
89
}
 
90
 
 
91
void QGeoTiledMapPixmapObjectInfo::pixmapChanged(const QPixmap &pixmap)
 
92
{
 
93
    updateValidity();
 
94
    if (!this->pixmap->pixmap().isNull()) {
 
95
        pixmapItem1->setPixmap(this->pixmap->pixmap());
 
96
        if (pixmapItem2)
 
97
            pixmapItem2->setPixmap(this->pixmap->pixmap());
 
98
    }
 
99
    if (valid())
 
100
        updateItem();
 
101
}
 
102
 
 
103
void QGeoTiledMapPixmapObjectInfo::offsetChanged(const QPoint &offset)
 
104
{
 
105
    if (valid())
 
106
        update();
 
107
}
 
108
 
 
109
void QGeoTiledMapPixmapObjectInfo::zoomLevelChanged(qreal zoomLevel)
 
110
{
 
111
    if (valid())
 
112
        update();
 
113
}
 
114
 
 
115
void QGeoTiledMapPixmapObjectInfo::update()
 
116
{
 
117
    int zoomFactor = tiledMapData->zoomFactor();
 
118
    
 
119
    QPointF pos = tiledMapData->coordinateToWorldReferencePosition(pixmap->coordinate());
 
120
 
 
121
    QPointF offset = pixmap->offset();
 
122
    offset *= zoomFactor;
 
123
    pos += offset;
 
124
 
 
125
    int width = tiledMapData->worldReferenceSize().width();
 
126
    int x = pos.x();
 
127
 
 
128
    if (x > width)
 
129
        x -= width;
 
130
    if (x < 0)
 
131
        x += width;
 
132
 
 
133
    pos.setX(x);
 
134
 
 
135
    int rightBound = pos.x() + pixmap->pixmap().width() * zoomFactor;
 
136
 
 
137
    QPointF pos2 = QPointF(-1.0 * static_cast<qreal>(width / zoomFactor), 0);
 
138
 
 
139
    if (rightBound > width ) {
 
140
        if (!pixmapItem2) {
 
141
            pixmapItem2 = new QGraphicsPixmapItem(pixmapItem1);
 
142
            pixmapItem2->setPixmap(pixmap->pixmap());
 
143
        }
 
144
    } else {
 
145
        if (pixmapItem2) {
 
146
            delete pixmapItem2;
 
147
            pixmapItem2 = 0;
 
148
        }
 
149
    }
 
150
 
 
151
    pixmapItem1->setScale(zoomFactor);
 
152
 
 
153
    pixmapItem1->setPos(pos);
 
154
    if (pixmapItem2)
 
155
        pixmapItem2->setPos(pos2);
 
156
 
86
157
    updateItem();
87
158
}
88
159
 
89
 
void QGeoTiledMapPixmapObjectInfo::mapUpdated()
90
 
{
91
 
    if (pixmapItem) {
92
 
        qreal zoomFactor = tiledMapData->zoomFactor();
93
 
        pixmapItem->setScale(zoomFactor);
94
 
        pixmapItem->setTransform(QTransform::fromTranslate(pixmap->offset().x() * zoomFactor, pixmap->offset().y() * zoomFactor));
95
 
    }
96
 
}
 
160
#include "moc_qgeotiledmappixmapobjectinfo_p.cpp"
97
161
 
98
162
QTM_END_NAMESPACE
99
163