BibleTime
src
frontend
displaywindow
bttextwindowheader.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-2021 by the BibleTime developers.
8
* The BibleTime source code is licensed under the GNU General Public License
9
* version 2.0.
10
*
11
**********/
12
13
#include "
bttextwindowheader.h
"
14
15
#include <QHBoxLayout>
16
#include <QLayout>
17
#include <QSizePolicy>
18
#include <Qt>
19
#include <utility>
20
#include "../../util/btassert.h"
21
#include "../../util/btconnect.h"
22
#include "../../util/btmodules.h"
23
#include "
bttextwindowheaderwidget.h
"
24
25
26
BtTextWindowHeader::BtTextWindowHeader
(
CSwordModuleInfo::ModuleType
modtype,
27
BtModuleList
modules,
28
QWidget
*
const
parent)
29
:
QWidget
(parent)
30
, m_moduleType(modtype)
31
{
32
BT_ASSERT
(modtype !=
CSwordModuleInfo::GenericBook
);
33
34
auto
*
const
layout =
new
QHBoxLayout(
this
);
35
layout->setContentsMargins(0, 0, 0, 0);
36
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
37
setLayoutDirection(Qt::LeftToRight);
38
39
for
(
int
i = 0; i < modules.count(); i++)
40
addWidget
();
41
updateWidgets
(modules);
42
}
43
44
void
BtTextWindowHeader::setModules
(
BtModuleList
modules) {
45
adjustWidgetCount
(modules.size());
46
updateWidgets
(modules);
47
}
48
49
void
BtTextWindowHeader::adjustWidgetCount
(
int
const
numWidgets) {
50
if
(
m_widgetList
.size() > numWidgets) {
51
auto
toRemove =
m_widgetList
.size() - numWidgets;
52
do
{
53
// it should be safe to delete the button later
54
auto
*
const
w =
m_widgetList
.takeFirst();
55
w->setParent(
nullptr
);
56
w->deleteLater();
57
}
while
(--toRemove);
58
}
else
if
(numWidgets >
m_widgetList
.size()) {
59
auto
toAdd = numWidgets -
m_widgetList
.size();
60
do
{
61
addWidget
();
62
}
while
(--toAdd);
63
}
64
}
65
66
BtTextWindowHeaderWidget
*
BtTextWindowHeader::addWidget
() {
67
auto
*
const
w =
new
BtTextWindowHeaderWidget
(
m_moduleType
,
this
);
68
layout()->addWidget(w);
69
m_widgetList
.append(w);
70
BT_CONNECT
(w, &
BtTextWindowHeaderWidget::sigModuleAdd
,
71
this
, &
BtTextWindowHeader::moduleAdded
);
72
BT_CONNECT
(w, &
BtTextWindowHeaderWidget::sigModuleReplace
,
73
this
, &
BtTextWindowHeader::moduleReplaced
);
74
BT_CONNECT
(w, &
BtTextWindowHeaderWidget::sigModuleRemove
,
75
this
, &
BtTextWindowHeader::moduleRemoved
);
76
return
w;
77
}
78
79
void
BtTextWindowHeader::updateWidgets
(
BtModuleList
const
& modules) {
80
int
const
leftLikeModules =
leftLikeParallelModules
(modules);
81
for
(
int
i = 0; i <
m_widgetList
.count(); i++)
82
m_widgetList
.at(i)->updateWidget(modules,
83
modules.at(i),
84
i,
85
leftLikeModules);
86
}
BT_ASSERT
#define BT_ASSERT(...)
Definition:
btassert.h:17
BT_CONNECT
#define BT_CONNECT(...)
Definition:
btconnect.h:20
BtModuleList
QList< CSwordModuleInfo * > BtModuleList
Definition:
btmodulelist.h:20
leftLikeParallelModules
int leftLikeParallelModules(BtModuleList const &modules)
Definition:
btmodules.cpp:19
bttextwindowheader.h
bttextwindowheaderwidget.h
BtTextWindowHeaderWidget
Definition:
bttextwindowheaderwidget.h:36
BtTextWindowHeaderWidget::sigModuleReplace
void sigModuleReplace(int index, CSwordModuleInfo *newModule)
BtTextWindowHeaderWidget::sigModuleAdd
void sigModuleAdd(int index, CSwordModuleInfo *module)
BtTextWindowHeaderWidget::sigModuleRemove
void sigModuleRemove(int index)
BtTextWindowHeader::moduleAdded
void moduleAdded(int index, CSwordModuleInfo *module)
BtTextWindowHeader::moduleReplaced
void moduleReplaced(int index, CSwordModuleInfo *newModule)
BtTextWindowHeader::addWidget
BtTextWindowHeaderWidget * addWidget()
Definition:
bttextwindowheader.cpp:66
BtTextWindowHeader::adjustWidgetCount
void adjustWidgetCount(int const numWidgets)
Ensures exactly numModules widgets.
Definition:
bttextwindowheader.cpp:49
BtTextWindowHeader::setModules
void setModules(BtModuleList newModules)
Definition:
bttextwindowheader.cpp:44
BtTextWindowHeader::updateWidgets
void updateWidgets(BtModuleList const &modules)
Definition:
bttextwindowheader.cpp:79
BtTextWindowHeader::m_moduleType
CSwordModuleInfo::ModuleType const m_moduleType
Definition:
bttextwindowheader.h:64
BtTextWindowHeader::BtTextWindowHeader
BtTextWindowHeader(CSwordModuleInfo::ModuleType modtype, BtModuleList modules, QWidget *window=nullptr)
Definition:
bttextwindowheader.cpp:26
BtTextWindowHeader::moduleRemoved
void moduleRemoved(int index)
BtTextWindowHeader::m_widgetList
QList< BtTextWindowHeaderWidget * > m_widgetList
Definition:
bttextwindowheader.h:63
CSwordModuleInfo::ModuleType
ModuleType
Definition:
cswordmoduleinfo.h:87
CSwordModuleInfo::GenericBook
@ GenericBook
Definition:
cswordmoduleinfo.h:92
QWidget
Generated by
1.9.1