Skip to content

Commit

Permalink
Time created pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Oct 20, 2015
1 parent 9a4e239 commit eb3aded
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 58 deletions.
28 changes: 18 additions & 10 deletions MobileClient/QtProject/src/SpotViewDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import QtQuick 2.1
import QtQuick.Controls 1.0

// Project imports -------------------------
// Project qml imports ---------------------
import "qrc:/widgets"

Item {
id: root
width: parent.width
height: rectangle_Top.height
+ image_Picture.height
+ text_SpotDescription.height

signal userClicked
signal spotClicked
Expand All @@ -22,53 +21,62 @@ Item {
width: parent.width
height: 40
color: "#aaaaaa"

// Username
Text{
id: text_Username
width: parent.width / 2
height: parent.height / 2
text: role_UserUsername

text: role_UserUsername
color: hc_Application.color_TextLink()
font.bold: true

MouseArea {
anchors.fill: parent
onClicked: {
userClicked();
}
}
}

// Time
Text {
anchors.top: parent.top
anchors.left: text_Username.right
width: text_Username.width
height: text_Username.height
horizontalAlignment: Text.AlignRight

text: role_PictureCreated
}

// Title
Text {
id: text_SpotName
anchors.top: text_Username.bottom
width: parent.width
height: text_Username.height
horizontalAlignment: Text.AlignHCenter

text: role_SpotName
}
}

// Picture
CachedPicture {
id: image_Picture
anchors.top: rectangle_Top.bottom
width: parent.width
height: width

sourceUrl: role_PictureUrl

MouseArea {
anchors.fill: parent
onClicked: {
spotClicked();
}
}
}
Text {
id: text_SpotDescription
anchors.top: image_Picture.bottom
width: parent.width
height: 40
text: role_SpotDescription
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public slots:
bool developmentMode() const;
void setDevelopmentMode(bool developmentMode);

// Colors
QString color_TextLink() const { return "#265f8b"; }

private slots:

void slot_CommandGetCurrentClientVersion_Finished(const WebApiError &error);
Expand Down
37 changes: 22 additions & 15 deletions MobileClient/QtProject/src/cpp/WebApi/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ Picture::Picture(QObject *parent) :
{
}

Picture::Picture(const Picture &other) :
QObject(other.parent()),
m_Id (other.m_Id),
m_IdUser (other.m_IdUser),
m_IdSpot (other.m_IdSpot),
m_Url (other.m_Url),
m_Username (other.m_Username),
m_SpotName (other.m_SpotName),
m_SpotDescription(other.m_SpotDescription),
m_Created (other.m_Created),
m_WebApiCommand (NULL)
{

}

Picture::Picture(int id,
int idUser,
Expand Down Expand Up @@ -118,7 +104,7 @@ QVariant Picture::pictureRole(PictureRoles role) const
return m_SpotDescription;
break;
case Role_PictureCreated:
return m_Created;
return createdText();
break;
case Role_PictureUrl:
return m_Url;
Expand All @@ -144,4 +130,25 @@ QHash<int, QByteArray> Picture::roleNames()
return roles;
}

//-----------------------------------------------------------------------------------------------------------------------------

QString Picture::createdText() const
{
int elapseTime = m_Created.msecsTo(QDateTime::currentDateTime()) / 1000;

if(elapseTime < 60)
return tr("%1s").arg(elapseTime);

if(elapseTime < 60 * 60)
return tr("%1m").arg(elapseTime / 60);

if(elapseTime < 60 * 60 * 24)
return tr("%1h").arg(elapseTime / (60 * 60));

if(elapseTime < 60 * 60 * 24 * 7)
return tr("%1d").arg(elapseTime / (60 * 60 * 24));

return tr("%1w").arg(elapseTime / (60 * 60 * 24 * 7));
}


5 changes: 3 additions & 2 deletions MobileClient/QtProject/src/cpp/WebApi/Picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class Picture : public QObject
};

explicit Picture(QObject *parent = 0);
explicit Picture(const Picture &other);
explicit Picture(int id,
int idUser,
int idSpot, QString url, QString username,
QString name,
QString description, QDateTime created,
QString description,
QDateTime created,
QObject *parent = 0);
~Picture();
Picture &operator=(const Picture &other);
Expand All @@ -59,6 +59,7 @@ class Picture : public QObject
QString spotName() const { return m_SpotName; }
QString spotDescription() const { return m_SpotDescription; }
QDateTime created() const { return m_Created; }
QString createdText() const;

void setIdSpot (int idSpot) {m_IdSpot = idSpot;}
void setUrl (const QString &url) {m_Url = url;}
Expand Down
16 changes: 16 additions & 0 deletions MobileClient/QtProject/src/cpp/WebApi/Spot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ Spot::Spot(int id,

//-----------------------------------------------------------------------------------------------------------------------------

Spot::Spot(QObject *parent)
: QObject(parent),
m_Id (-1),
m_Name (""),
m_Description (""),
m_Latitude (0.0),
m_Longitude (0.0),
m_Distance_km (0.0),
m_PictureUrl1 (""),
m_PictureUrl2 ("")
{

}

//-----------------------------------------------------------------------------------------------------------------------------

Spot::~Spot()
{

Expand Down
1 change: 1 addition & 0 deletions MobileClient/QtProject/src/cpp/WebApi/Spot.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Spot : public QObject
QString pictureUrl1,
QString pictureUrl2,
QObject *parent = 0);
explicit Spot(QObject *parent = 0);
~Spot();

QVariant spotRole(SpotRoles role) const;
Expand Down
4 changes: 4 additions & 0 deletions MobileClient/QtProject/src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include "HelperClasses/PictureCacher.h"
#include "WebApi/SpotRepository.h"
#include "WebApi/SpotsModel.h"
#include "WebApi/Spot.h"
#include "WebApi/PictureRepository.h"
#include "WebApi/PicturesModel.h"
#include "WebApi/Picture.h"
#include "WebApi/User.h"
#include "WebApi/NewsModel.h"
#include "WebApi/NearbySpotsModel.h"
Expand Down Expand Up @@ -58,7 +60,9 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("wa_PictureUploader", &pictureUploader);

qmlRegisterType<PicturesModel> ("PicturesModel", 1, 0, "PicturesModel");
qmlRegisterType<Picture> ("Picture", 1, 0, "Picture");
qmlRegisterType<SpotsModel> ("SpotsModel", 1, 0, "SpotsModel");
qmlRegisterType<Spot> ("Spot", 1, 0, "Spot");
qmlRegisterType<NewsModel> ("NewsModel", 1, 0, "NewsModel");
qmlRegisterType<NearbySpotsModel>("NearbySpotsModel", 1, 0, "NearbySpotsModel");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ public function indexAction()
->getManager()
->getRepository('InstaspotsSpotsBundle:Picture');

$pictures = $repository->getNews();
$pictures = $repository->getPicturesByNewest();

return $this->render('InstaspotsSpotsBundle:Advert:index.html.twig',
return $this->render('InstaspotsSpotsBundle:Advert:index.html.twig',
array('listPictures' => $pictures));
}

public function downloadAction()
{
$listPlatforms = array(
array('title' => 'Android', 'link' => 'link'),
array('title' => 'Source', 'link' => 'https://github.com/domi4484/instaspots')
);
return $this->render('InstaspotsSpotsBundle:Advert:download.html.twig',

return $this->render('InstaspotsSpotsBundle:Advert:download.html.twig',
array('listPlatforms' => $listPlatforms));
}

public function viewAction($id)
{
$repository = $this->getDoctrine()
->getManager()
->getRepository('InstaspotsSpotsBundle:Spot');

$spot = $repository->find($id);

if (null === $spot) {
throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
}

return new Response("Affichage de l'annonce d'id : ".$spot->getName());
}

public function menuAction($limit)
{
// On fixe en dur une liste ici, bien entendu par la suite
Expand All @@ -64,4 +64,3 @@ public function menuAction($limit)
));
}
}

Loading

0 comments on commit eb3aded

Please sign in to comment.