3 #include <QNetworkRequest>
4 #include <QNetworkReply>
7 #include <QImageReader>
11 #define BTN_STYLE "background-color: #333333; color: white;"
13 #define FONT_SIZE_BOLD 22
15 #define STARS_IMG_OFFSET 1520
16 #define STARS_IMG_HEIGHT 69
17 #define STARS_IMG_WIDTH 324
19 #define LABEL_NAME_HEIGHT 37
20 #define LABEL_ADDR_HEIGHT 30
21 #define LABEL_PHONE_HEIGHT 30
22 #define LABEL_IMG_HEIGHT 220
23 #define LABEL_REVIEWS_HEIGHT 24
25 InfoPanel::InfoPanel(QWidget *parent, QRect rect):
27 nameLabel(this, rect),
28 imageLabel(this, rect),
29 addressLabel(this, rect),
30 phoneLabel(this, rect),
31 imgRatingLabel(this, rect),
32 nbReviewsLabel(this, rect),
33 btnsBackground(this, rect),
34 cancelButton("Cancel", this),
35 goButton("Go !", this),
36 networkManager(parent)
42 void InfoPanel::populateInfo(Business & business)
46 bool isImageDownloaded = false;
48 QRect rect = this->geometry();
50 font = nameLabel.font();
51 font.setPointSize(FONT_SIZE);
53 fontBold = nameLabel.font();
54 fontBold.setPointSize(FONT_SIZE_BOLD);
55 fontBold.setBold(true);
57 /* Preload image Url: */
58 TRACE_INFO("Image URL: %s", qPrintable(business.ImageUrl));
60 QObject::connect(&networkManager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
61 QNetworkRequest req(QUrl(business.ImageUrl));
62 QNetworkReply* reply = networkManager.get(req);
64 eventLoop.exec(); // wait for answer
65 if (reply->error() == QNetworkReply::NoError)
67 QByteArray jpegData = reply->readAll();
68 pixmap.loadFromData(jpegData);
69 isImageDownloaded = true;
71 networkManager.disconnect();
75 nameLabel.Init(y, LABEL_NAME_HEIGHT, business.Name, &fontBold);
76 y += LABEL_NAME_HEIGHT;
78 /* Display Address: */
79 addressLabel.Init(y, LABEL_ADDR_HEIGHT,
80 business.Address+", "+business.City+", "+business.State+" "+business.ZipCode+", "+business.Country,
82 y += LABEL_ADDR_HEIGHT;
84 /* Display phone number: */
85 phoneLabel.Init(y, LABEL_PHONE_HEIGHT, business.Phone, &font);
86 y += LABEL_PHONE_HEIGHT;
89 imageLabel.Init(y, LABEL_IMG_HEIGHT, QString(""));
90 y += LABEL_IMG_HEIGHT;
91 if (isImageDownloaded)
93 imageLabel.setPixmap(pixmap.scaled(QSize(rect.width(), LABEL_IMG_HEIGHT-6), Qt::KeepAspectRatio));
96 /* Display number of reviews: */
97 nbReviewsLabel.Init(y, LABEL_REVIEWS_HEIGHT, QString("Number of reviews : %1").arg(business.ReviewCount), &font);
98 y += LABEL_REVIEWS_HEIGHT;
101 QImageReader reader(QString(":/images/stars_map_www.png"));
102 int RatingImgIndex = (int)((double)business.Rating*2)-1;
103 if (RatingImgIndex < 0)
107 reader.setClipRect(QRect(0,
108 STARS_IMG_OFFSET + RatingImgIndex*STARS_IMG_HEIGHT, STARS_IMG_WIDTH, STARS_IMG_HEIGHT));
109 const QImage image = reader.read();
110 imgRatingLabel.Init(y, STARS_IMG_HEIGHT, QString(""));
111 y += STARS_IMG_HEIGHT;
112 imgRatingLabel.setPixmap(QPixmap::fromImage(image).scaled(QSize(rect.width() / 3, STARS_IMG_HEIGHT), Qt::KeepAspectRatio));
115 btnsBackground.Init(y, 70, QString(""));
118 cancelButton.setStyleSheet(BTN_STYLE);
119 cancelButton.setFont(font);
120 cancelButton.setMinimumSize(QSize(rect.width()/4, 50));
121 //cancelButton.setGeometry(QRect(rect.x()+rect.width()/8, rect.y()+y-60, rect.width()/4, 50));
122 cancelButton.setGeometry(QRect(rect.width()/8, y-60, rect.width()/4, 50));
124 goButton.setStyleSheet(BTN_STYLE);
125 goButton.setFont(font);
126 goButton.setMinimumSize(QSize(rect.width()/4, 50));
127 goButton.setGeometry(QRect(rect.width()*5/8, y-60, rect.width()/4, 50));