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
|
#include <QLabel>
#include <QMenu>
#include <QString>
#include <QDebug>
#include "addEntryForm.h"
#include "../../backend/db_sqlite.h"
#include "editGroupForm.h"
#include "groupLayout.h"
#include "lib.h"
GroupLayout::GroupLayout(const Group &g) :
group(g)
{
this->setContentsMargins(0, 10, 0, 10);
QLabel *name_label = new QLabel(this->group.name);
name_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
name_label->setToolTip("Right-Click for actions");
name_label->setContextMenuPolicy(Qt::CustomContextMenu);
//name_label->customContextMenuRequested(const QPoint &pos)
QObject::connect(name_label,
SIGNAL(customContextMenuRequested(const QPoint &)),
SLOT(showContextMenu()));
QFont name_font = QFont("Arial", 13);
name_font.setUnderline(true);
name_label->setFont(name_font);
this->addWidget(name_label);
}
void GroupLayout::showContextMenu() {
QMenu menu;
QAction *add_entry_act = new QAction("Add Entry");
QObject::connect(add_entry_act, &QAction::triggered, this, &GroupLayout::addEntry);
menu.addAction(add_entry_act);
QAction *edit_group_act = new QAction("Edit Group");
QObject::connect(edit_group_act, &QAction::triggered, this, &GroupLayout::editGroup);
menu.addAction(edit_group_act);
QAction *del_group_act = new QAction("Remove Group");
QObject::connect(del_group_act, &QAction::triggered, this, &GroupLayout::removeGroup);
menu.addAction(del_group_act);
menu.exec(QCursor::pos());
}
void GroupLayout::addEntry() {
AddEntryForm create_new_entry_dialog(this->group);
if(create_new_entry_dialog.exec() == QDialog::Accepted)
getMainWindow()->displayWidgets();
}
void GroupLayout::editGroup() {
EditGroupForm edit_group_dialog(this->group);
if(edit_group_dialog.exec() == QDialog::Accepted)
getMainWindow()->displayWidgets();
}
void GroupLayout::removeGroup() {
BackendDB database;
if(database.removeGroup(this->group) > 0)
getMainWindow()->displayWidgets();
}
|