15 #include <QApplication>
18 #include <QFocusEvent>
19 #include <QHBoxLayout>
22 #include <QMouseEvent>
25 #include <QStringList>
27 #include <QToolButton>
28 #include "../../../backend/keys/cswordversekey.h"
29 #include "../../../util/btconnect.h"
30 #include "../../../util/cresmgr.h"
31 #include "../cscrollerwidgetset.h"
42 Qt::FocusReason reason =
event->reason();
43 if (reason == Qt::OtherFocusReason) {
47 QWidget::focusInEvent(event);
58 , m_dropDownHoverTimer(this)
77 auto const slotStepBook =
78 [slotStep](
int offset)
80 auto const slotStepChapter =
81 [slotStep](
int offset)
83 auto const slotStepVerse =
84 [slotStep](
int offset)
89 setFocusPolicy(Qt::WheelFocus);
92 clearRef->setIcon(CResMgr::icon_clearEdit());
93 clearRef->setAutoRaise(
true);
94 clearRef->setStyleSheet(QStringLiteral(
"QToolButton{margin:0px;}"));
105 m_textbox->setContentsMargins(0, 0, 0, 0);
110 QHBoxLayout* m_mainLayout =
new QHBoxLayout(
this );
111 m_mainLayout->setContentsMargins(0, 0, 0, 0);
112 m_mainLayout->setSpacing(0);
113 m_mainLayout->addWidget(clearRef);
114 m_mainLayout->addWidget(bookScroller);
116 m_mainLayout->addWidget(chapterScroller);
117 m_mainLayout->addWidget(verseScroller);
130 auto *
const bookChooser =
133 bookChooser->setToolTip(tr(
"Select book"));
134 BT_CONNECT(bookChooser->menu(), &QMenu::triggered,
135 [
this](
QAction *
const action) {
136 auto bookname = action->property(
"bookname").toString();
137 if (m_key->bookName() != bookname) {
138 m_key->setBookName(std::move(bookname));
145 dropDownButtonsLayout->addWidget(bookChooser, 2);
147 auto *
const chapterChooser =
150 chapterChooser->setToolTip(tr(
"Select chapter"));
151 BT_CONNECT(chapterChooser->menu(), &QMenu::triggered,
152 [
this](
QAction *
const action) {
153 int const n = action->property(
"chapter").toInt();
154 if (m_key->chapter() != n) {
155 m_key->setChapter(n);
159 Q_EMIT changed(m_key);
164 dropDownButtonsLayout->addWidget(chapterChooser, 1);
166 auto *
const verseChooser =
169 verseChooser->setToolTip(tr(
"Select verse"));
170 BT_CONNECT(verseChooser->menu(), &QMenu::triggered,
171 [
this](
QAction *
const action) {
172 int const n = action->property(
"verse").toInt();
173 if (m_key->verse() != n) {
178 Q_EMIT changed(m_key);
181 dropDownButtonsLayout->addWidget(verseChooser, 1);
183 dropDownButtonsLayout->setContentsMargins(0, 0, 0, 0);
184 dropDownButtonsLayout->setSpacing(0);
185 m_dropDownButtons->setLayout(dropDownButtonsLayout);
186 m_dropDownButtons->hide();
188 m_dropDownButtons->installEventFilter(
this);
190 m_dropDownHoverTimer.setInterval(500);
191 m_dropDownHoverTimer.setSingleShot(
true);
192 BT_CONNECT(&m_dropDownHoverTimer, &QTimer::timeout,
193 m_dropDownButtons, &QWidget::hide);
195 QString scrollButtonToolTip(tr(
"Scroll through the entries of the list. Press the button and move the mouse to increase or decrease the item."));
196 bookScroller->setToolTips(
201 chapterScroller->setToolTips(
204 tr(
"Previous chapter")
206 verseScroller->setToolTips(
213 auto const initScrollerConnections =
222 oldKey = m_key->key();
227 if (oldKey != m_key->key())
228 Q_EMIT changed(m_key);
231 initScrollerConnections(*bookScroller, slotStepBook);
232 initScrollerConnections(*chapterScroller, slotStepChapter);
233 initScrollerConnections(*verseScroller, slotStepVerse);
235 BT_CONNECT(m_textbox, &QLineEdit::returnPressed,
237 m_key->setKey(m_textbox->text());
238 Q_EMIT changed(m_key);
273 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
294 QWidget::resizeEvent(event);
300 QPoint topLeft(mapTo(window(),
310 int nw(
m_textbox->minimumSizeHint().width() + fm.horizontalAdvance(text));
318 if (!key)
return false;
326 menu.addAction(bookname)->setProperty(
"bookname", bookname);
331 for (
int i = 1; i <= count; i++)
332 menu.addAction(QString::number(i))->setProperty(
"chapter", i);
337 for (
int i = 1; i <= count; i++)
338 menu.addAction(QString::number(i))->setProperty(
"verse", i);
BtLineEdit(QWidget *parent)
void focusInEvent(QFocusEvent *event) override
Implementation for Sword Bibles.
unsigned int verseCount(const unsigned int book, const unsigned int chapter) const
unsigned int chapterCount(const unsigned int book) const
QStringList const & books() const
CSwordKey implementation for Sword's VerseKey.
bool next(const JumpType type=JumpType::UseVerse)
void setModule(const CSwordModuleInfo *newModule) final override
bool previous(const JumpType type=JumpType::UseVerse)
QString key() const final override
bool setKey(const QString &key) final override