Repository navigation
Expand file tree
/
Copy pathdialog.cpp
More file actions
100 lines (79 loc) · 2.07 KB
/
Copy pathdialog.cpp
File metadata and controls
100 lines (79 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
init();
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::itemDoubleClicked(QListWidgetItem *item)
{
QString url = item->data(Qt::ItemDataRole::UserRole).toString();
QDesktopServices::openUrl(QUrl(url));
}
void Dialog::init()
{
//clear it out
while(ui->toolBox->count() > 0)
{
ui->toolBox->removeItem(0);
}
//Add pages
addCategory("News");
addCategory("Social Media");
addCategory("Search Engines");
addNews();
addSocial();
addSearch();
}
void Dialog::addCategory(QString name)
{
QListWidget * list = new QListWidget(this);
ui->toolBox->addItem(list,QIcon(":/files/images/world.png"),name);
connect(list,&QListWidget::itemDoubleClicked,this, &Dialog::itemDoubleClicked);
}
void Dialog::addLink(QListWidget *list, QString name, QString url)
{
QListWidgetItem *itm = new QListWidgetItem(QIcon(":/files/images/page_world.png"), name);
itm->setData(Qt::ItemDataRole::UserRole,url);
list->addItem(itm);
}
void Dialog::addNews()
{
QListWidget *list = qobject_cast<QListWidget*>(ui->toolBox->widget(0));
if(!list)
{
qWarning() << "Could not find News List!";
return;
}
addLink(list,"CNN", "http://www.cnn.com");
addLink(list,"Fox", "http://www.foxnews.com");
addLink(list,"Google", "http://www.google.com");
}
void Dialog::addSocial()
{
QListWidget *list = qobject_cast<QListWidget*>(ui->toolBox->widget(1));
if(!list)
{
qWarning() << "Could not find Social List!";
return;
}
addLink(list,"Facebook", "http://www.facebook.com");
addLink(list,"YouTube", "http://www.youtube.com");
}
void Dialog::addSearch()
{
QListWidget *list = qobject_cast<QListWidget*>(ui->toolBox->widget(2));
if(!list)
{
qWarning() << "Could not find Search List!";
return;
}
addLink(list,"Google", "http://www.google.com");
addLink(list,"Yahoo", "http://www.yahoo.com");
}