summaryrefslogtreecommitdiffstats
path: root/InfoPanel.cpp
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2019-08-30 11:43:58 -0400
committerScott Murray <scott.murray@konsulko.com>2019-08-30 11:45:55 -0400
commitededa7e3ef24a8cea9e513fa008ef481c1675457 (patch)
tree86a4c79d066b9638b11c0f127ad8f3c66c38c4f7 /InfoPanel.cpp
parent706ad73eb02caf8532deaf5d38995bd258725cb8 (diff)
Initial check in
Initial check in of the original repository: git://github.com/AGLExport/genivi-navi-yelp-client.git as of commit c2691cb265d9198542482a860f1df378e8c2708b. Bug-AGL: SPEC-2787 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: I7405367387622fb788a5712ed24005ee6d7ce495
Diffstat (limited to 'InfoPanel.cpp')
-rw-r--r--InfoPanel.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/InfoPanel.cpp b/InfoPanel.cpp
new file mode 100644
index 0000000..bc57e34
--- /dev/null
+++ b/InfoPanel.cpp
@@ -0,0 +1,121 @@
+#include <QWidget>
+#include <QFont>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QEventLoop>
+#include <QPixmap>
+#include <QImageReader>
+#include "InfoPanel.h"
+#include "traces.h"
+
+#define BTN_STYLE "background-color: #333333; color: white;"
+
+#define FONT_SIZE_BOLD 22
+#define FONT_SIZE 16
+#define STARS_IMG_OFFSET 1520
+#define STARS_IMG_HEIGHT 69
+#define STARS_IMG_WIDTH 324
+
+#define LABEL_NAME_HEIGHT 37
+#define LABEL_ADDR_HEIGHT 30
+#define LABEL_PHONE_HEIGHT 30
+#define LABEL_IMG_HEIGHT 220
+#define LABEL_REVIEWS_HEIGHT 24
+
+InfoPanel::InfoPanel(QWidget *parent, Business & business, QRect rect):
+ nameLabel(parent, rect),
+ imageLabel(parent, rect),
+ addressLabel(parent, rect),
+ phoneLabel(parent, rect),
+ imgRatingLabel(parent, rect),
+ nbReviewsLabel(parent, rect),
+ btnsBackground(parent, rect),
+ cancelButton("Cancel", parent),
+ goButton("Go !", parent),
+ networkManager(parent)
+{
+ int y = 0;
+ QPixmap pixmap;
+ bool isImageDownloaded = false;
+ QFont font, fontBold;
+
+ font = nameLabel.font();
+ font.setPointSize(FONT_SIZE);
+
+ fontBold = nameLabel.font();
+ fontBold.setPointSize(FONT_SIZE_BOLD);
+ fontBold.setBold(true);
+
+ /* Preload image Url: */
+ TRACE_INFO("Image URL: %s", qPrintable(business.ImageUrl));
+ QEventLoop eventLoop;
+ QObject::connect(&networkManager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
+ QNetworkRequest req(QUrl(business.ImageUrl));
+ QNetworkReply* reply = networkManager.get(req);
+
+ eventLoop.exec(); // wait for answer
+ if (reply->error() == QNetworkReply::NoError)
+ {
+ QByteArray jpegData = reply->readAll();
+ pixmap.loadFromData(jpegData);
+ isImageDownloaded = true;
+ }
+ networkManager.disconnect();
+ delete reply;
+
+ /* Display Name: */
+ nameLabel.Init(y, LABEL_NAME_HEIGHT, business.Name, &fontBold);
+ y += LABEL_NAME_HEIGHT;
+
+ /* Display Address: */
+ addressLabel.Init(y, LABEL_ADDR_HEIGHT,
+ business.Address+", "+business.City+", "+business.State+" "+business.ZipCode+", "+business.Country,
+ &font);
+ y += LABEL_ADDR_HEIGHT;
+
+ /* Display phone number: */
+ phoneLabel.Init(y, LABEL_PHONE_HEIGHT, business.Phone, &font);
+ y += LABEL_PHONE_HEIGHT;
+
+ /* Image Url: */
+ imageLabel.Init(y, LABEL_IMG_HEIGHT, QString(""));
+ y += LABEL_IMG_HEIGHT;
+ if (isImageDownloaded)
+ {
+ imageLabel.setPixmap(pixmap.scaled(QSize(rect.width(), LABEL_IMG_HEIGHT-6), Qt::KeepAspectRatio));
+ }
+
+ /* Display number of reviews: */
+ nbReviewsLabel.Init(y, LABEL_REVIEWS_HEIGHT, QString("Number of reviews : %1").arg(business.ReviewCount), &font);
+ y += LABEL_REVIEWS_HEIGHT;
+
+ /* Rating image: */
+ QImageReader reader(QString(":/images/stars_map_www.png"));
+ int RatingImgIndex = (int)((double)business.Rating*2)-1;
+ if (RatingImgIndex < 0)
+ {
+ RatingImgIndex = 0;
+ }
+ reader.setClipRect(QRect(0,
+ STARS_IMG_OFFSET + RatingImgIndex*STARS_IMG_HEIGHT, STARS_IMG_WIDTH, STARS_IMG_HEIGHT));
+ const QImage image = reader.read();
+ imgRatingLabel.Init(y, STARS_IMG_HEIGHT, QString(""));
+ y += STARS_IMG_HEIGHT;
+ imgRatingLabel.setPixmap(QPixmap::fromImage(image).scaled(QSize(rect.width() / 3, STARS_IMG_HEIGHT), Qt::KeepAspectRatio));
+
+ /* Buttons: */
+ btnsBackground.Init(y, 70, QString(""));
+ y += 70;
+
+ cancelButton.setStyleSheet(BTN_STYLE);
+ cancelButton.setFont(font);
+ cancelButton.setMinimumSize(QSize(rect.width()/4, 50));
+ cancelButton.setGeometry(QRect(rect.x()+rect.width()/8, rect.y()+y-60, rect.width()/4, 50));
+ cancelButton.setVisible(true);
+
+ goButton.setStyleSheet(BTN_STYLE);
+ goButton.setFont(font);
+ goButton.setMinimumSize(QSize(rect.width()/4, 50));
+ goButton.setGeometry(QRect(rect.x()+rect.width()*5/8, rect.y()+y-60, rect.width()/4, 50));
+ goButton.setVisible(true);
+}