<file>res/images/led_red_g.png</file>
<file>res/images/led_red_h.png</file>
<file>res/images/led_red_s.png</file>
+ <file>res/images/friend_group.png</file>
</qresource>
</RCC>
m_facebookAuthenticator->hide();
m_ui->show();
m_situareService->fetchLocations(); // request user locations
+
+ m_situareService->debugData();
}
void SituareEngine::requestAddress()
*/
#include <QDebug>
+
#include "mapengine.h"
#include "baselocationitem.h"
: QObject(parent)
{
qDebug() << __PRETTY_FUNCTION__;
+
+ setFlag(QGraphicsItem::ItemIgnoresTransformations);
+}
+
+QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
+{
+ QRect rect = sceneBoundingRect().toRect();
+ int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
+
+ int heightDelta = (rect.height() * multiplier - rect.height()) / 2;
+ int widthDelta = (rect.width() * multiplier - rect.width()) / 2;
+
+ return rect.adjusted(-widthDelta, -heightDelta, widthDelta, heightDelta);
}
void BaseLocationItem::setPosition(const QPointF & newPosition)
*/
QPoint position() const;
+ QRect sceneTransformedBoundingRect(int zoomLevel) const;
+
/**
* @brief sets position of item as specified in parameter.
* Parameter can be given in georaphical coordinates
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+
+#include <QDebug>
+
+#include "frienditemshandler.h"
+
+FriendItemsHandler::FriendItemsHandler(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void FriendItemsHandler::checkFriendsForCollisions()
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+// foreach(FriendGroupItem *item, m_friendGroupItems) {
+// m_friendGroupItems.removeAll(item);
+// m_mapScene->removeItem(item);
+// }
+
+ int lastItem = m_friendsLocations.size() - 1;
+ for (int checking = 0; checking <= lastItem; checking++) {
+ QRect beginItemRect = m_friendsLocations.at(checking)->sceneTransformedBoundingRect(m_zoomLevel);
+
+ // don't check items which are already part of a group (and thus unvisible)
+ if (m_friendsLocations.at(checking)->isPartOfGroup())
+ continue;
+
+ // check all other items
+ for (int another = 0; another <= lastItem; another++)
+ {
+ // don't check against itself
+ if (checking == another)
+ continue;
+
+ // don't check against items which are already part of a group (and thus unvisible)
+ if (m_friendsLocations.at(another)->isPartOfGroup())
+ continue;
+
+ // does items collide
+ QRect iterItemRect = m_friendsLocations.at(another)->sceneTransformedBoundingRect(m_zoomLevel);
+ if (beginItemRect.intersects(iterItemRect)) {
+ qWarning() << __PRETTY_FUNCTION__ << "collision found" << checking << another;
+ FriendGroupItem *group = new FriendGroupItem();
+ m_friendGroupItems.append(group);
+ group->setPos(m_friendsLocations.at(checking)->pos());
+ group->joinFriend(m_friendsLocations.at(checking));
+ group->joinFriend(m_friendsLocations.at(another));
+ m_mapScene->addItem(group);
+ break;
+ }
+ }
+ }
+}
+
+void FriendItemsHandler::checkGroupsForCollisions()
+{
+
+}
+
+void FriendItemsHandler::dropOutOfGroupFriends()
+{
+
+}
+
+void FriendItemsHandler::refactorFriendItems()
+{
+ dropOutOfGroupFriends();
+ checkGroupsForCollisions();
+ checkFriendsForCollisions();
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+
+#ifndef FRIENDITEMSHANDLER_H
+#define FRIENDITEMSHANDLER_H
+
+#include <QList>
+#include <QObject>
+
+class FriendGroupItem;
+
+class FriendItemsHandler : public QObject
+{
+ Q_OBJECT
+
+public:
+ FriendItemsHandler(QObject *parent = 0);
+
+ void checkFriendsForCollisions();
+
+ void checkGroupsForCollisions();
+
+ void dropOutOfGroupFriends();
+
+ void refactorFriendItems();
+
+private:
+ QList<FriendGroupItem *> m_friendGroupItems;
+};
+
+#endif // FRIENDITEMSHANDLER_H
FriendLocationItem::FriendLocationItem(const QPixmap &icon,
const QPointF &friendsLocation,
QObject *parent)
- : BaseLocationItem(parent)
+ : BaseLocationItem(parent),
+ m_partOfGroup(false)
{
- //Q_UNUSED(parent);
qDebug() << __PRETTY_FUNCTION__;
setPixmap(icon);
setPosition(QPointF( friendsLocation.x(), friendsLocation.y() ));
setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
setOffset(-icon.width()/2, -icon.height()/2);
- setFlag(QGraphicsItem::ItemIgnoresTransformations);
}
+bool FriendLocationItem::isPartOfGroup() const
+{
+ return m_partOfGroup;
+}
void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit iconClicked(m_userId);
}
+void FriendLocationItem::setPartOfGroup(bool value)
+{
+ m_partOfGroup = value;
+}
+
QString FriendLocationItem::userId() const
{
return m_userId;
*/
FriendLocationItem(const QPixmap &icon, const QPointF &friendsLocation, QObject *parent = 0);
+ bool isPartOfGroup() const;
+
/**
* @brief getter for m_userId
*
*/
QString userId() const;
+ void setPartOfGroup(bool value);
+
/**
* @brief sets name for friend.
*
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
+ bool m_partOfGroup;
QString m_userId; ///< Friends user ID
};
#include <QHashIterator>
#include <QRect>
+#include "frienditemshandler.h"
#include "mapengine.h"
#include "maptile.h"
connect(m_mapZoomPanel, SIGNAL(zoomInPressed()), this, SLOT(zoomIn()));
connect(m_mapZoomPanel, SIGNAL(zoomOutPressed()), this, SLOT(zoomOut()));
- m_ownLocation = new OwnLocationItem(QPointF());
+ /// @todo VILLE: m_ownLocation ei poisteta mikäli ei koskaan saa tietoa sijainnista jolloin vasta
+ /// lisätään sceneen
+ m_ownLocation = new OwnLocationItem(QPointF());
+
+ m_friendItemsHandler = new FriendItemsHandler(this);
}
MapEngine::~MapEngine()
friendLocation->setUserId(friendsList.at(i)->userId());
m_friendsLocations.append(friendLocation);
m_mapScene->addItem(friendLocation);
+
+ m_friendItemsHandler->refactorFriendItems();
}
}
+
+
+
+
#include "friendlocationitem.h"
#include "user/user.h"
+class FriendItemsHandler;
+
/**
* @brief Map engine
*
******************************************************************************/
private:
QPoint m_centerTile; ///< Current center tile
+ FriendItemsHandler *m_friendItemsHandler;
MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
MapScene *m_mapScene; ///< Scene for map tiles
MapZoomPanel *m_mapZoomPanel; ///< Toolbar for zoom buttons
setPosition(ownPosition);
setZValue(OWN_LOCATION_ICON_Z_LEVEL);
setOffset(-ownLocationIcon.width()/2, -ownLocationIcon.height()/2);
- setFlag(QGraphicsItem::ItemIgnoresTransformations);
}
#include <QtAlgorithms>
#include <QDebug>
#include <QtGlobal>
+#include <QString>
#include <QStringList>
#include <QPixmap>
#include <QNetworkReply>
m_friendsList.clear();
}
+void SituareService::debugData()
+{
+ qWarning() << __PRETTY_FUNCTION__;
+ QFile file("/home/ramosam-local/situare_debug_data.txt");
+ qWarning() << __PRETTY_FUNCTION__ << "file size: " << file.size();
+ qWarning() << __PRETTY_FUNCTION__ << "file open success?" << file.open(QIODevice::ReadOnly);
+ QByteArray debugReplyArray = file.readAll();
+ qWarning() << __PRETTY_FUNCTION__ << "did read" << debugReplyArray.size();
+ parseUserData(debugReplyArray);
+}
+
void SituareService::fetchLocations()
{
qDebug() << __PRETTY_FUNCTION__;
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
+ void debugData();
+
/**
* @brief Retrieves location user and friends information from Situare server
*
* @param urlParameters optional parameters for url
* @return QUrl formed url
*/
- QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
+ QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = QString());
/**
* @brief Forms url parameters
* @param publish optional publish location on Facebook wall (true/false)
* @return QString
*/
- QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
+ QString formUrlParameters(const QPointF &coordinates, QString status = QString(), QString publish = QString());
/**
* @brief Parses user and friend data from JSON string
ui/situareuser.cpp \
engine/engine.cpp \
ui/settingsdialog.cpp \
- map/maptilerequest.cpp
+ map/maptilerequest.cpp \
+ map/friendgroupitem.cpp \
+ map/frienditemshandler.cpp
HEADERS += ui/mainwindow.h \
ui/mapviewscreen.h \
ui/listviewscreen.h \
ui/situareuser.h \
engine/engine.h \
ui/settingsdialog.h \
- map/maptilerequest.h
+ map/maptilerequest.h \
+ map/friendgroupitem.h \
+ map/frienditemshandler.h
QT += network \
webkit
DEFINES += QT_NO_DEBUG_OUTPUT
message(Make sure you have QJson development headers installed)
message(install headers with: sudo apt-get install libqjson-dev)
}
-maemo5 {
+maemo5 {
message(QJson built in)
message(Make sure you have QJson development headers installed)
message(add: deb http://repository.maemo.org/extras-devel fremantle free non-free)