|
1 #include "CustomListWidget.h" |
|
2 #include <qlistwidget.h> |
|
3 #include <qboxlayout.h> |
|
4 #include <qlabel.h> |
|
5 #include <qdebug.h> |
|
6 #include "ScreenSize.h" |
|
7 #include <qpushbutton.h> |
|
8 #include "WidgetConstants.h" |
|
9 |
|
10 CustomListWidget::CustomListWidget() |
|
11 { |
|
12 setStyleSheet("selection-color: yellow;" |
|
13 "selection-background-color: grey;"); |
|
14 } |
|
15 CustomListWidget::~CustomListWidget() |
|
16 { |
|
17 |
|
18 } |
|
19 |
|
20 void CustomListWidget::AddListItem(QString aIconPath,QString aFirstLine,QString aSecondLine) |
|
21 { |
|
22 QWidget* customwidget = new QWidget; |
|
23 QHBoxLayout* HMainlayout = new QHBoxLayout(customwidget); |
|
24 QLabel *lab =new QLabel(); |
|
25 lab->setPixmap(QPixmap(aIconPath)); |
|
26 lab->setFixedSize(60,60); |
|
27 HMainlayout->addWidget(lab); |
|
28 |
|
29 //To add First & second row horizontal layouts |
|
30 QVBoxLayout* VTextlayout = new QVBoxLayout; |
|
31 |
|
32 QHBoxLayout* HFirstrowLayout = new QHBoxLayout; |
|
33 //Add FirstLine label |
|
34 QLabel *lab1 =new QLabel(aFirstLine); |
|
35 lab1->setStyleSheet("font: bold 20px;"); |
|
36 HFirstrowLayout->addWidget(lab1); |
|
37 //Add Images to |
|
38 QLabel *Img1lab =new QLabel(); |
|
39 Img1lab->setPixmap(QPixmap(aIconPath)); |
|
40 Img1lab->setFixedSize(10,10); |
|
41 QLabel *Img2lab =new QLabel(); |
|
42 Img2lab->setPixmap(QPixmap(aIconPath)); |
|
43 Img2lab->setFixedSize(10,10); |
|
44 QLabel *Img3lab =new QLabel(); |
|
45 Img3lab->setPixmap(QPixmap(aIconPath)); |
|
46 Img3lab->setFixedSize(10,10); |
|
47 |
|
48 HFirstrowLayout->addWidget(Img1lab); |
|
49 HFirstrowLayout->addWidget(Img2lab); |
|
50 HFirstrowLayout->addWidget(Img3lab); |
|
51 |
|
52 // HFirstrowLayout->setAlignment(Img3lab,Qt::AlignRight); |
|
53 // HFirstrowLayout->setAlignment(Img2lab,Qt::AlignRight); |
|
54 // HFirstrowLayout->setAlignment(Img1lab,Qt::AlignRight); |
|
55 |
|
56 VTextlayout->addLayout(HFirstrowLayout); |
|
57 |
|
58 |
|
59 QHBoxLayout* HSecondrowLayout = new QHBoxLayout; |
|
60 QLabel *lab2 =new QLabel(aSecondLine); |
|
61 lab2->setStyleSheet("font: 16px;"); |
|
62 HSecondrowLayout->addWidget(lab2); |
|
63 |
|
64 QLabel *Timestamplabel =new QLabel("00:00 JUL 12"); |
|
65 Timestamplabel->setStyleSheet("font: 12px;"); |
|
66 HSecondrowLayout->addWidget(Timestamplabel); |
|
67 |
|
68 HSecondrowLayout->setAlignment(Timestamplabel,Qt::AlignRight); |
|
69 |
|
70 VTextlayout->addLayout(HSecondrowLayout); |
|
71 |
|
72 |
|
73 HMainlayout->addLayout(VTextlayout); |
|
74 customwidget->setLayout(HMainlayout); |
|
75 QListWidgetItem *item=new QListWidgetItem; |
|
76 |
|
77 //customlist->adjustSize(); |
|
78 //customlist->adjustSize(); |
|
79 item->setSizeHint(QSize(60,60)); |
|
80 |
|
81 addItem(item); |
|
82 setItemWidget(item,customwidget); |
|
83 } |
|
84 |
|
85 void CustomListWidget::AddListItem(QMainWindow *mainWindow,QStringList aIconPath,QStringList aNames) |
|
86 { |
|
87 qDebug()<<"Inside GridView::CreateGridView()"; |
|
88 qDebug()<<"aIconPath count = "<<aIconPath.count(); |
|
89 qDebug()<<"names count = "<<aNames.count(); |
|
90 |
|
91 int row; |
|
92 int col; |
|
93 //QWidget* widget = new QWidget(); |
|
94 QGridLayout* GridLayout = new QGridLayout(this); |
|
95 if((6 == aIconPath.count()) || (5 == aIconPath.count())) |
|
96 { |
|
97 row = 3; |
|
98 col = 2; |
|
99 } |
|
100 else if((4 == aIconPath.count()) || (3 == aIconPath.count())) |
|
101 { |
|
102 row = col = 2; |
|
103 } |
|
104 else if((2 == aIconPath.count()) || (1 == aIconPath.count())) |
|
105 { |
|
106 row = 1; |
|
107 col = 2; |
|
108 } |
|
109 else if(0 == aIconPath.count()) |
|
110 { |
|
111 row = col = 0; |
|
112 } |
|
113 |
|
114 int rowSpace = (ScreenSize::GetScreenRect().height() - (KHeadNameHeight+ToolbarIconHeight+2*KWidgetGapFactor))/row; |
|
115 int colSpace = (ScreenSize::GetScreenRect().width() - 2*KWidgetGapFactor )/col; |
|
116 |
|
117 int index = 0; |
|
118 for(int i=0;i<row;i++) |
|
119 { |
|
120 for(int j=0;j<col;j++) |
|
121 { |
|
122 QPushButton *pushBtn = new QPushButton(); |
|
123 qDebug()<<"name = "<<aNames[index]; |
|
124 int gapFac = KHeadNameHeight+ToolbarIconHeight; |
|
125 pushBtn->setGeometry(i*colSpace,(j*rowSpace + KWidgetGapFactor),colSpace,rowSpace); |
|
126 pushBtn->setIconSize(QSize(colSpace-(3*KWidgetGapFactor),colSpace+(3*KWidgetGapFactor))); |
|
127 qDebug()<<"icon = "<<aIconPath[index]; |
|
128 pushBtn->setIcon(QIcon(aIconPath[index])); |
|
129 qDebug()<<"After image display"; |
|
130 GridLayout->addWidget(pushBtn,i,j); |
|
131 |
|
132 index++; |
|
133 if(index == aNames.count()) |
|
134 { |
|
135 qDebug()<<"Count became same so exiting"; |
|
136 break; |
|
137 } |
|
138 } |
|
139 if(index == aNames.count()) |
|
140 { |
|
141 qDebug()<<"Count became same so exiting"; |
|
142 break; |
|
143 } |
|
144 } |
|
145 //Its required please don't remove |
|
146 show(); |
|
147 } |
|
148 |
|
149 |
|
150 QWidget* CustomListWidget::CreateListwidget(SmfContactList* friendsList) |
|
151 { |
|
152 qDebug()<<"Inside CustomListWidget::CreateListwidget() for friends"; |
|
153 qDebug()<<"Friends count = "<<friendsList->count(); |
|
154 |
|
155 QListWidget* customlist = new QListWidget(); |
|
156 |
|
157 // Todo:- Display something when no friends are available |
|
158 foreach(SmfContact contact, *friendsList) |
|
159 { |
|
160 QString name(contact.value("Name").value<QContactName>().firstName()); |
|
161 QString status(contact.value("Presence").value<QContactPresence>().customMessage()); |
|
162 if(!status.size()) |
|
163 status.append("Not available"); |
|
164 //QUrl url(contact.value("Avatar").value<QContactAvatar>().imageUrl()); |
|
165 QString url("C:\\data\\sample.bmp"); // ToDo:- should be the profile image path |
|
166 |
|
167 QWidget* widgetItem = new QWidget(); |
|
168 QHBoxLayout* HMainlayout = new QHBoxLayout(widgetItem); |
|
169 QLabel *lab =new QLabel(); |
|
170 lab->setPixmap(QPixmap(url)); |
|
171 lab->setFixedSize(60,60); |
|
172 HMainlayout->addWidget(lab); |
|
173 |
|
174 //To add First & second row horizontal layouts |
|
175 QVBoxLayout* VTextlayout = new QVBoxLayout; |
|
176 |
|
177 QHBoxLayout* HFirstrowLayout = new QHBoxLayout; |
|
178 |
|
179 //Add FirstLine label |
|
180 QLabel *lab1 = new QLabel(name); |
|
181 lab1->setStyleSheet("font: bold 16px;"); |
|
182 HFirstrowLayout->addWidget(lab1); |
|
183 |
|
184 //Add Images to |
|
185 QLabel *Img1lab =new QLabel(); |
|
186 Img1lab->setPixmap(QPixmap(url)); |
|
187 Img1lab->setFixedSize(10,10); |
|
188 QLabel *Img2lab =new QLabel(); |
|
189 Img2lab->setPixmap(QPixmap(url)); |
|
190 Img2lab->setFixedSize(10,10); |
|
191 QLabel *Img3lab =new QLabel(); |
|
192 Img3lab->setPixmap(QPixmap(url)); |
|
193 Img3lab->setFixedSize(10,10); |
|
194 |
|
195 HFirstrowLayout->addWidget(Img1lab); |
|
196 HFirstrowLayout->addWidget(Img2lab); |
|
197 HFirstrowLayout->addWidget(Img3lab); |
|
198 |
|
199 // HFirstrowLayout->setAlignment(Img3lab,Qt::AlignRight); |
|
200 // HFirstrowLayout->setAlignment(Img2lab,Qt::AlignRight); |
|
201 // HFirstrowLayout->setAlignment(Img1lab,Qt::AlignRight); |
|
202 |
|
203 VTextlayout->addLayout(HFirstrowLayout); |
|
204 |
|
205 |
|
206 QHBoxLayout* HSecondrowLayout = new QHBoxLayout; |
|
207 QLabel *lab2 =new QLabel(status); |
|
208 lab2->setStyleSheet("font: 8px;"); |
|
209 HSecondrowLayout->addWidget(lab2); |
|
210 |
|
211 QLabel *Timestamplabel =new QLabel(""); |
|
212 Timestamplabel->setStyleSheet("font: 7px;"); |
|
213 HSecondrowLayout->addWidget(Timestamplabel); |
|
214 |
|
215 HSecondrowLayout->setAlignment(Timestamplabel,Qt::AlignRight); |
|
216 |
|
217 VTextlayout->addLayout(HSecondrowLayout); |
|
218 |
|
219 |
|
220 HMainlayout->addLayout(VTextlayout); |
|
221 widgetItem->setLayout(HMainlayout); |
|
222 QListWidgetItem *item=new QListWidgetItem; |
|
223 |
|
224 //customlist->adjustSize(); |
|
225 //customlist->adjustSize(); |
|
226 item->setSizeHint(QSize(60,60)); |
|
227 |
|
228 customlist->addItem(item); |
|
229 customlist->setItemWidget(item,widgetItem); |
|
230 } |
|
231 customlist->setStyleSheet("selection-color: yellow;" |
|
232 "selection-background-color: grey;"); |
|
233 return customlist; |
|
234 } |
|
235 |
|
236 |
|
237 QWidget* CustomListWidget::CreateListwidget(SmfPostList *postsList) |
|
238 { |
|
239 qDebug()<<"Inside CustomListWidget::CreateListwidget() for posts"; |
|
240 qDebug()<<"Posts count = "<<postsList->count(); |
|
241 |
|
242 QListWidget* customlist = new QListWidget(); |
|
243 |
|
244 // Todo:- Display something when no posts are available |
|
245 foreach(SmfPost post, *postsList) |
|
246 { |
|
247 QString text(post.description()); |
|
248 QString ownerName(post.owner().value("Name").value<QContactName>().firstName()); |
|
249 |
|
250 //QUrl url(contact.value("Avatar").value<QContactAvatar>().imageUrl()); |
|
251 QString url("C:\\data\\sample.bmp"); // ToDo:- should be the profile image path |
|
252 |
|
253 QWidget* widgetItem = new QWidget(); |
|
254 QHBoxLayout* HMainlayout = new QHBoxLayout(widgetItem); |
|
255 QLabel *lab =new QLabel(); |
|
256 lab->setPixmap(QPixmap(url)); |
|
257 lab->setFixedSize(60,60); |
|
258 HMainlayout->addWidget(lab); |
|
259 |
|
260 //To add First & second row horizontal layouts |
|
261 QVBoxLayout* VTextlayout = new QVBoxLayout; |
|
262 |
|
263 QHBoxLayout* HFirstrowLayout = new QHBoxLayout; |
|
264 |
|
265 //Add FirstLine label |
|
266 QLabel *lab1 = new QLabel(ownerName); |
|
267 lab1->setStyleSheet("font: bold 16px;"); |
|
268 HFirstrowLayout->addWidget(lab1); |
|
269 |
|
270 //Add Images to |
|
271 QLabel *Img1lab =new QLabel(); |
|
272 Img1lab->setPixmap(QPixmap(url)); |
|
273 Img1lab->setFixedSize(10,10); |
|
274 QLabel *Img2lab =new QLabel(); |
|
275 Img2lab->setPixmap(QPixmap(url)); |
|
276 Img2lab->setFixedSize(10,10); |
|
277 QLabel *Img3lab =new QLabel(); |
|
278 Img3lab->setPixmap(QPixmap(url)); |
|
279 Img3lab->setFixedSize(10,10); |
|
280 |
|
281 HFirstrowLayout->addWidget(Img1lab); |
|
282 HFirstrowLayout->addWidget(Img2lab); |
|
283 HFirstrowLayout->addWidget(Img3lab); |
|
284 |
|
285 // HFirstrowLayout->setAlignment(Img3lab,Qt::AlignRight); |
|
286 // HFirstrowLayout->setAlignment(Img2lab,Qt::AlignRight); |
|
287 // HFirstrowLayout->setAlignment(Img1lab,Qt::AlignRight); |
|
288 |
|
289 VTextlayout->addLayout(HFirstrowLayout); |
|
290 |
|
291 |
|
292 QHBoxLayout* HSecondrowLayout = new QHBoxLayout; |
|
293 QLabel *lab2 =new QLabel(text); |
|
294 lab2->setStyleSheet("font: 8px;"); |
|
295 HSecondrowLayout->addWidget(lab2); |
|
296 |
|
297 QLabel *Timestamplabel =new QLabel(""); |
|
298 Timestamplabel->setStyleSheet("font: 7px;"); |
|
299 HSecondrowLayout->addWidget(Timestamplabel); |
|
300 |
|
301 HSecondrowLayout->setAlignment(Timestamplabel,Qt::AlignRight); |
|
302 |
|
303 VTextlayout->addLayout(HSecondrowLayout); |
|
304 |
|
305 |
|
306 HMainlayout->addLayout(VTextlayout); |
|
307 widgetItem->setLayout(HMainlayout); |
|
308 QListWidgetItem *item=new QListWidgetItem; |
|
309 |
|
310 //customlist->adjustSize(); |
|
311 //customlist->adjustSize(); |
|
312 item->setSizeHint(QSize(60,60)); |
|
313 |
|
314 customlist->addItem(item); |
|
315 customlist->setItemWidget(item,widgetItem); |
|
316 } |
|
317 customlist->setStyleSheet("selection-color: yellow;" |
|
318 "selection-background-color: grey;"); |
|
319 return customlist; |
|
320 |
|
321 } |
|
322 QWidget* CreateListwidget(SmfActivityEntryList *activityList) |
|
323 { |
|
324 |
|
325 } |
|
326 |
|
327 /*QWidget* CustomListWidget::CreateListwidget(QString aIconPath,QString aFirstLine,QString aSecondLine) |
|
328 { |
|
329 qDebug()<<"Inside CustomListWidget::CreateListwidget()"; |
|
330 qDebug()<<"Icon path = "<<aIconPath; |
|
331 qDebug()<<"firstline = "<<aFirstLine; |
|
332 qDebug()<<"second line = "<<aSecondLine; |
|
333 QListWidget* customlist = new QListWidget(); |
|
334 //for(int i =0;i<2;i++) |
|
335 //{ |
|
336 QWidget* widgetItem = new QWidget(); |
|
337 QHBoxLayout* HMainlayout = new QHBoxLayout(widgetItem); |
|
338 QLabel *lab =new QLabel(); |
|
339 lab->setPixmap(QPixmap(aIconPath)); |
|
340 lab->setFixedSize(60,60); |
|
341 HMainlayout->addWidget(lab); |
|
342 |
|
343 //To add First & second row horizontal layouts |
|
344 QVBoxLayout* VTextlayout = new QVBoxLayout; |
|
345 |
|
346 QHBoxLayout* HFirstrowLayout = new QHBoxLayout; |
|
347 //Add FirstLine label |
|
348 QLabel *lab1 =new QLabel(aFirstLine); |
|
349 lab1->setStyleSheet("font: bold 16px;"); |
|
350 HFirstrowLayout->addWidget(lab1); |
|
351 //Add Images to |
|
352 QLabel *Img1lab =new QLabel(); |
|
353 Img1lab->setPixmap(QPixmap(aIconPath)); |
|
354 Img1lab->setFixedSize(10,10); |
|
355 QLabel *Img2lab =new QLabel(); |
|
356 Img2lab->setPixmap(QPixmap(aIconPath)); |
|
357 Img2lab->setFixedSize(10,10); |
|
358 QLabel *Img3lab =new QLabel(); |
|
359 Img3lab->setPixmap(QPixmap(aIconPath)); |
|
360 Img3lab->setFixedSize(10,10); |
|
361 |
|
362 HFirstrowLayout->addWidget(Img1lab); |
|
363 HFirstrowLayout->addWidget(Img2lab); |
|
364 HFirstrowLayout->addWidget(Img3lab); |
|
365 |
|
366 // HFirstrowLayout->setAlignment(Img3lab,Qt::AlignRight); |
|
367 // HFirstrowLayout->setAlignment(Img2lab,Qt::AlignRight); |
|
368 // HFirstrowLayout->setAlignment(Img1lab,Qt::AlignRight); |
|
369 |
|
370 VTextlayout->addLayout(HFirstrowLayout); |
|
371 |
|
372 |
|
373 QHBoxLayout* HSecondrowLayout = new QHBoxLayout; |
|
374 QLabel *lab2 =new QLabel(aSecondLine); |
|
375 lab2->setStyleSheet("font: 8px;"); |
|
376 HSecondrowLayout->addWidget(lab2); |
|
377 |
|
378 QLabel *Timestamplabel =new QLabel("00:00 JUN 29"); |
|
379 Timestamplabel->setStyleSheet("font: 7px;"); |
|
380 HSecondrowLayout->addWidget(Timestamplabel); |
|
381 |
|
382 HSecondrowLayout->setAlignment(Timestamplabel,Qt::AlignRight); |
|
383 |
|
384 VTextlayout->addLayout(HSecondrowLayout); |
|
385 |
|
386 |
|
387 HMainlayout->addLayout(VTextlayout); |
|
388 widgetItem->setLayout(HMainlayout); |
|
389 QListWidgetItem *item=new QListWidgetItem; |
|
390 |
|
391 //customlist->adjustSize(); |
|
392 //customlist->adjustSize(); |
|
393 item->setSizeHint(QSize(60,60)); |
|
394 |
|
395 customlist->addItem(item); |
|
396 customlist->setItemWidget(item,widgetItem); |
|
397 //} |
|
398 customlist->setStyleSheet("selection-color: yellow;" |
|
399 "selection-background-color: grey;"); |
|
400 return customlist; |
|
401 }*/ |