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
116
117
118
|
/*********
*
* In the name of the Father, and of the Son, and of the Holy Spirit.
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
**********/
#include "frontend/btopenworkaction.h"
#include "backend/bookshelfmodel/btbookshelffiltermodel.h"
#include "backend/managers/cswordbackend.h"
#include "bibletimeapp.h"
#include "frontend/btbookshelfgroupingmenu.h"
#include "util/btconnect.h"
#include "util/cresmgr.h"
BtOpenWorkActionMenu::BtOpenWorkActionMenu(const QString &groupingConfigKey,
QWidget *parent)
: BtMenuView(parent)
, m_treeModel(nullptr)
, m_postFilterModel(nullptr)
, m_groupingMenu(nullptr)
, m_groupingConfigKey(groupingConfigKey)
{
// Setup models:
m_treeModel = new BtBookshelfTreeModel(groupingConfigKey, this);
m_postFilterModel = new BtBookshelfFilterModel(this);
m_postFilterModel->setSourceModel(m_treeModel);
setModel(m_postFilterModel);
BT_CONNECT(this, SIGNAL(triggered(QModelIndex)),
this, SLOT(slotIndexTriggered(QModelIndex)));
}
void BtOpenWorkActionMenu::setSourceModel(QAbstractItemModel *model) {
m_treeModel->setSourceModel(model);
}
void BtOpenWorkActionMenu::retranslateUi() {
if (!m_groupingMenu)
return;
m_groupingMenu->setTitle(tr("&Grouping order"));
m_groupingMenu->setStatusTip(tr("Sets the grouping order for the items in "
"this menu."));
}
void BtOpenWorkActionMenu::postBuildMenu() {
addSeparator();
m_groupingMenu = new BtBookshelfGroupingMenu(false, this);
BT_CONNECT(m_groupingMenu,
SIGNAL(signalGroupingOrderChanged(
BtBookshelfTreeModel::Grouping)),
this,
SLOT(slotGroupingActionTriggered(
BtBookshelfTreeModel::Grouping)));
retranslateUi();
addMenu(m_groupingMenu);
}
void BtOpenWorkActionMenu::slotIndexTriggered(const QModelIndex &index) {
static const int MPR = BtBookshelfModel::ModulePointerRole;
CSwordModuleInfo *i;
i = static_cast<CSwordModuleInfo *>(model()->data(index, MPR).value<void*>());
if (i != nullptr) {
emit triggered(i);
}
}
void BtOpenWorkActionMenu::slotGroupingActionTriggered(const BtBookshelfTreeModel::Grouping &grouping) {
m_treeModel->setGroupingOrder(grouping);
grouping.saveTo(m_groupingConfigKey);
}
BtOpenWorkAction::BtOpenWorkAction(const QString &groupingConfigKey,
QObject *parent)
: QAction(parent)
{
m_menu = new BtOpenWorkActionMenu(groupingConfigKey);
m_menu->setSourceModel(CSwordBackend::instance()->model());
setMenu(m_menu);
setIcon(CResMgr::mainWindow::icon_openAction());
retranslateUi();
slotModelChanged();
BtBookshelfFilterModel *filterModel = m_menu->postFilterModel();
BT_CONNECT(m_menu, SIGNAL(triggered(CSwordModuleInfo *)),
this, SIGNAL(triggered(CSwordModuleInfo *)));
BT_CONNECT(filterModel, SIGNAL(layoutChanged()),
this, SLOT(slotModelChanged()));
BT_CONNECT(filterModel, SIGNAL(modelReset()),
this, SLOT(slotModelChanged()));
BT_CONNECT(filterModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
this, SLOT(slotModelChanged()));
BT_CONNECT(filterModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
this, SLOT(slotModelChanged()));
}
BtOpenWorkAction::~BtOpenWorkAction() {
delete m_menu;
}
void BtOpenWorkAction::retranslateUi() {
setText(tr("&Open work"));
}
void BtOpenWorkAction::slotModelChanged() {
setEnabled(m_menu->postFilterModel()->rowCount() > 0);
}
|