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, Business & business, QRect rect):
26 nameLabel(parent, rect),
27 imageLabel(parent, rect),
28 addressLabel(parent, rect),
29 phoneLabel(parent, rect),
30 imgRatingLabel(parent, rect),
31 nbReviewsLabel(parent, rect),
32 btnsBackground(parent, rect),
33 cancelButton("Cancel", parent),
34 goButton("Go !", parent),
35 networkManager(parent)
39 bool isImageDownloaded = false;
42 font = nameLabel.font();
43 font.setPointSize(FONT_SIZE);
45 fontBold = nameLabel.font();
46 fontBold.setPointSize(FONT_SIZE_BOLD);
47 fontBold.setBold(true);
49 /* Preload image Url: */
50 TRACE_INFO("Image URL: %s", qPrintable(business.ImageUrl));
52 QObject::connect(&networkManager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
53 QNetworkRequest req(QUrl(business.ImageUrl));
54 QNetworkReply* reply = networkManager.get(req);
56 eventLoop.exec(); // wait for answer
57 if (reply->error() == QNetworkReply::NoError)
59 QByteArray jpegData = reply->readAll();
60 pixmap.loadFromData(jpegData);
61 isImageDownloaded = true;
63 networkManager.disconnect();
67 nameLabel.Init(y, LABEL_NAME_HEIGHT, business.Name, &fontBold);
68 y += LABEL_NAME_HEIGHT;
70 /* Display Address: */
71 addressLabel.Init(y, LABEL_ADDR_HEIGHT,
72 business.Address+", "+business.City+", "+business.State+" "+business.ZipCode+", "+business.Country,
74 y += LABEL_ADDR_HEIGHT;
76 /* Display phone number: */
77 phoneLabel.Init(y, LABEL_PHONE_HEIGHT, business.Phone, &font);
78 y += LABEL_PHONE_HEIGHT;
81 imageLabel.Init(y, LABEL_IMG_HEIGHT, QString(""));
82 y += LABEL_IMG_HEIGHT;
83 if (isImageDownloaded)
85 imageLabel.setPixmap(pixmap.scaled(QSize(rect.width(), LABEL_IMG_HEIGHT-6), Qt::KeepAspectRatio));
88 /* Display number of reviews: */
89 nbReviewsLabel.Init(y, LABEL_REVIEWS_HEIGHT, QString("Number of reviews : %1").arg(business.ReviewCount), &font);
90 y += LABEL_REVIEWS_HEIGHT;
93 QImageReader reader(QString(":/images/stars_map_www.png"));
94 int RatingImgIndex = (int)((double)business.Rating*2)-1;
95 if (RatingImgIndex < 0)
99 reader.setClipRect(QRect(0,
100 STARS_IMG_OFFSET + RatingImgIndex*STARS_IMG_HEIGHT, STARS_IMG_WIDTH, STARS_IMG_HEIGHT));
101 const QImage image = reader.read();
102 imgRatingLabel.Init(y, STARS_IMG_HEIGHT, QString(""));
103 y += STARS_IMG_HEIGHT;
104 imgRatingLabel.setPixmap(QPixmap::fromImage(image).scaled(QSize(rect.width() / 3, STARS_IMG_HEIGHT), Qt::KeepAspectRatio));
107 btnsBackground.Init(y, 70, QString(""));
110 cancelButton.setStyleSheet(BTN_STYLE);
111 cancelButton.setFont(font);
112 cancelButton.setMinimumSize(QSize(rect.width()/4, 50));
113 cancelButton.setGeometry(QRect(rect.x()+rect.width()/8, rect.y()+y-60, rect.width()/4, 50));
114 cancelButton.setVisible(true);
116 goButton.setStyleSheet(BTN_STYLE);
117 goButton.setFont(font);
118 goButton.setMinimumSize(QSize(rect.width()/4, 50));
119 goButton.setGeometry(QRect(rect.x()+rect.width()*5/8, rect.y()+y-60, rect.width()/4, 50));
120 goButton.setVisible(true);