-
Notifications
You must be signed in to change notification settings - Fork 1
/
searchlistview.cpp
116 lines (96 loc) · 2.99 KB
/
searchlistview.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "searchlistview.h"
#include "ui_searchlistview.h"
#include "bookmarkmodel.h"
#include <QDebug>
#include <QMenu>
SearchListView::SearchListView(QWidget *parent) :
QFrame(parent),
ui(new Ui::SearchListView)
{
ui->setupUi(this);
BookmarkModel *model = new BookmarkModel();
ui->bookmarks->setModel(model);
ui->bookmarks->header()->hide();
connect(ui->bookmarks, SIGNAL(clicked(QModelIndex)),
this, SLOT(onListItemSelected(QModelIndex)));
connect(ui->filter, SIGNAL(textChanged(QString)),
this, SLOT(onFilterChanged(QString)));
connect(ui->bookmarks,
SIGNAL(customContextMenuRequested(QPoint)),
this,
SLOT(onCustomContextMenu(QPoint)));
}
SearchListView::~SearchListView()
{
delete ui;
}
BookmarkModel* SearchListView::model()
{
return static_cast<BookmarkModel*>(ui->bookmarks->model());
}
void SearchListView::onListItemSelected(const QModelIndex & index)
{
if(index.isValid())
{
TreeItem *itm = static_cast<TreeItem*>(index.internalPointer());
if(itm != NULL && itm->getType() == ModelUtil::Link)
emit urlSelected(itm->getLink());
}
}
void SearchListView::onFilterChanged(const QString &fliter)
{
;
}
void SearchListView::onCustomContextMenu(const QPoint &pos)
{
QModelIndex index = ui->bookmarks->indexAt(pos);
TreeItem *item = model()->getItem(index);
if (index.isValid())
{
QAction *action = NULL;
switch(item->getType())
{
case ModelUtil::Folder:
{
// Context menu for folders
QMenu *contextMenu = new QMenu(this);
contextMenu->addAction(ui->actionAddBookmark);
contextMenu->addAction(ui->actionRemoveBookmark);
contextMenu->addSeparator();
contextMenu->addAction(ui->actionAddFolder);
contextMenu->addAction(ui->actionRemoveFolder);
action = contextMenu->exec(ui->bookmarks->mapToGlobal(pos));
break;
}
case ModelUtil::Link:
{
// Context menu for links
QMenu *contextMenu = new QMenu(this);
contextMenu->addAction(ui->actionAddBookmark);
contextMenu->addAction(ui->actionRemoveBookmark);
action = contextMenu->exec(ui->bookmarks->mapToGlobal(pos));
// New bookmark will be created in same folder!
index = index.parent();
break;
}
default:
break;
}
if(action == ui->actionAddBookmark)
{
emit addBookmark(index);
}
else if(action == ui->actionRemoveBookmark)
{
emit removeBookmark(index);
}
else if(action == ui->actionAddFolder)
{
emit addFolder(index);
}
else if(action == ui->actionRemoveFolder)
{
emit removeFolder(index);
}
}
}