-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbookmarkwidget.cpp
More file actions
101 lines (84 loc) · 2.94 KB
/
bookmarkwidget.cpp
File metadata and controls
101 lines (84 loc) · 2.94 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
100
101
#include "bookmarkwidget.h"
BookmarkWidget::BookmarkWidget(QWidget *parent) :
QListView(parent)
{
delegate = new Delegate(this);
delegate->setContentsMargins(4, 2, 4, 2);
delegate->setIconSize(24, 24);
delegate->setHorizontalSpacing(8);
delegate->setVerticalSpacing(2);
setModel(new QStandardItemModel(this));
setItemDelegate(delegate);
removeAction = new QAction("Remove", this);
removeAllAction = new QAction("Remove All", this);
editAction = new QAction("Edit", this);
setWordWrap(true);
}
quint64 BookmarkWidget::getLineNumber(int index)
{
QStringList topTextList = (static_cast<QStandardItemModel *>(model())->item(index)->text()).split(" : ");
return topTextList[0].toULongLong();
}
QString BookmarkWidget::getFilepath(int index)
{
QStringList topTextList = (static_cast<QStandardItemModel *>(model())->item(index)->text()).split(" : ");
return topTextList[1];
}
QString BookmarkWidget::getItemText(int index)
{
return static_cast<QStandardItemModel *>(model())->item(index)->data(Qt::UserRole).toString();
}
QIcon BookmarkWidget::getIcon(int index)
{
return static_cast<QStandardItemModel *>(model())->item(index)->icon();
}
void BookmarkWidget::setTopText(int index, QString topText)
{
static_cast<QStandardItemModel *>(model())->item(index)->setText(topText);
}
void BookmarkWidget::addItem(const QPixmap &pixmap, const QString &text, const QString &topText)
{
auto *item = new QStandardItem(QIcon(pixmap), topText);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setData(text, Qt::UserRole);
static_cast<QStandardItemModel *>(model())->appendRow(item);
scrollToBottom();
}
void BookmarkWidget::removeAll()
{
static_cast<QStandardItemModel *>(model())->clear();
}
void BookmarkWidget::removeItem(int index)
{
static_cast<QStandardItemModel *>(model())->removeRow(index);
}
void BookmarkWidget::setItemText(int index, QString text)
{
static_cast<QStandardItemModel *>(model())->item(index)->setData(text, Qt::UserRole);
}
void BookmarkWidget::contextMenuEvent(QContextMenuEvent *e)
{
QMouseEvent leftClick(QEvent::MouseButtonPress, e->pos(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
mousePressEvent(&leftClick);
contextMenu = new QMenu;
contextMenu->addAction(editAction);
contextMenu->addSeparator();
contextMenu->addAction(removeAction);
contextMenu->addSeparator();
contextMenu->addAction(removeAllAction);
if(model()->rowCount()>0)
{
editAction->setEnabled(true);
removeAction->setEnabled(true);
removeAllAction->setEnabled(true);
}
else
{
editAction->setEnabled(false);
removeAction->setEnabled(false);
removeAllAction->setEnabled(false);
}
contextMenu->exec(e->globalPos());
if (!contextMenu.isNull())
delete contextMenu;
}