BibleTime
bttextwindowheaderwidget.cpp
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
14
15#include <QAction>
16#include <QFontMetrics>
17#include <QFrame>
18#include <QHBoxLayout>
19#include <QIcon>
20#include <QLabel>
21#include <QMenu>
22#include <Qt>
23#include <QToolButton>
24#include "../../backend/drivers/cswordmoduleinfo.h"
25#include "../../util/btassert.h"
26#include "../../util/btconnect.h"
27#include "../../util/cresmgr.h"
28#include "btmodulechoosermenu.h"
29
30
33 QWidget * parent)
34 : QWidget(parent)
35{
36 QHBoxLayout* layout = new QHBoxLayout(this);
37 layout->setContentsMargins(0, 0, 0, 0);
38 layout->addStretch(1);
39
40 m_iconLabel = new QLabel(this);
41 m_iconLabel->setAlignment(Qt::AlignCenter);
42 layout->addWidget(m_iconLabel);
43
44 m_label = new QLabel(QString(), this);
45 m_label->setStyleSheet(QStringLiteral("QLabel{font-weight:bold}"));
46 layout->addWidget(m_label);
47
48 m_button = new QToolButton( this );
49 m_button->setPopupMode( QToolButton::InstantPopup );
50 m_button->setArrowType(Qt::NoArrow);
51 m_button->setStyleSheet(
52 QStringLiteral(
53 "QToolButton{margin:0px;}"
54 "QToolButton::menu-indicator{"
55 "subcontrol-position:center center"
56 "}"));
57 m_button->setToolTip(tr("Add/remove/replace"));
58
59 auto * const popup = new QMenu(m_button);
60 m_removeAction = new QAction(tr("Remove"), popup);
61 m_removeAction->setIcon(
62 CResMgr::displaywindows::general::icon_removeModule());
63 BT_CONNECT(m_removeAction, &QAction::triggered,
64 [this] { Q_EMIT sigModuleRemove(m_id); });
65 popup->addAction(m_removeAction);
66
67 // Add Replace and Add menus, both have all modules in them
70 tr("Replace"),
71 mtype,
73 popup);
74 m_replaceMenu->setIcon(
75 CResMgr::displaywindows::general::icon_replaceModule());
77 [this](CSwordModuleInfo * const module) {
78 BT_ASSERT(module);
79 Q_EMIT sigModuleReplace(m_id, module);
80 });
81 popup->addMenu(m_replaceMenu);
82
83 m_addMenu =
85 tr("Add"),
86 mtype,
88 popup);
89 m_addMenu->setIcon(CResMgr::displaywindows::general::icon_addModule());
91 [this](CSwordModuleInfo * const module) {
92 BT_ASSERT(module);
93 Q_EMIT sigModuleAdd(m_id + 1, module);
94 });
95 popup->addMenu(m_addMenu);
96 m_button->setMenu(popup);
97
98 layout->addWidget(m_button);
99 layout->addStretch(1);
100
101 auto * const separator = new QFrame(this);
102 separator->setFrameShape(QFrame::VLine);
103 layout->addWidget(separator);
104}
105
107 CSwordModuleInfo * module,
108 int newIndex,
109 int leftLikeModules)
110{
111 m_label->setText(module->name());
112 m_iconLabel->setPixmap(
113 module->moduleIcon().pixmap(m_label->fontMetrics().height()));
114 m_id = newIndex;
115
116 bool disableRemove = false;
117 if (newModulesToUse.count() == 1 ||
118 (newIndex == 0 && leftLikeModules == 1))
119 disableRemove = true;
120 m_removeAction->setDisabled(disableRemove);
121
122 m_replaceMenu->update(newModulesToUse,
123 module,
124 newIndex,
125 leftLikeModules);
126 m_addMenu->update(newModulesToUse, module, newIndex, leftLikeModules);
127}
#define BT_ASSERT(...)
Definition btassert.h:17
#define BT_CONNECT(...)
Definition btconnect.h:20
QList< CSwordModuleInfo * > BtModuleList
void update(BtModuleList newModulesToUse, CSwordModuleInfo *newSelectedModule, int newButtonIndexIndex, int newLeftLikeModules)
void sigModuleChosen(CSwordModuleInfo *module)
void updateWidget(BtModuleList newModulesToUse, CSwordModuleInfo *module, int newIndex, int leftLikeModules)
BtTextWindowHeaderWidget(CSwordModuleInfo::ModuleType mtype, QWidget *parent=nullptr)
void sigModuleReplace(int index, CSwordModuleInfo *newModule)
void sigModuleAdd(int index, CSwordModuleInfo *module)
BtModuleChooserMenu * m_replaceMenu
void sigModuleRemove(int index)
QIcon moduleIcon() const
QString const & name() const