BibleTime
cscrollerwidgetset.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 "cscrollerwidgetset.h"
14 
15 #include <QPoint>
16 #include <QString>
17 #include <Qt>
18 #include <QToolButton>
19 #include <QVBoxLayout>
20 #include <QWheelEvent>
21 #include "../../util/btconnect.h"
22 #include "cscrollbutton.h"
23 
24 
25 #define WIDTH (static_cast<unsigned int>(16))
26 #define ARROW_HEIGHT (static_cast<unsigned int>(12))
27 #define MOVER_HEIGHT (static_cast<unsigned int>(6))
28 
29 
31  : QWidget(parent)
32 {
33  m_layout = new QVBoxLayout(this);
34  m_layout->setSpacing(0);
35  m_layout->setContentsMargins(0, 0, 0, 0);
36  m_layout->setAlignment(this, Qt::AlignHCenter | Qt::AlignCenter);
37 
38  m_buttonUp = new QToolButton(this);
39  m_buttonUp->setArrowType(Qt::UpArrow);
40 
41  m_buttonUp->setFixedSize(WIDTH, ARROW_HEIGHT);
42  m_buttonUp->setFocusPolicy(Qt::NoFocus);
43  m_buttonUp->setAutoRaise(true);
44 
45  m_scrollButton = new CScrollButton(this);
46  m_scrollButton->setFixedSize(WIDTH, MOVER_HEIGHT);
47  m_scrollButton->setFocusPolicy(Qt::NoFocus);
48 
49  m_buttonDown = new QToolButton(this);
50  m_buttonDown->setArrowType(Qt::DownArrow);
51  m_buttonDown->setFixedSize(WIDTH, ARROW_HEIGHT);
52  m_buttonDown->setFocusPolicy(Qt::NoFocus);
53  m_buttonDown->setAutoRaise(true);
54 
55  m_layout->addWidget(m_buttonUp, 0);
56  m_layout->addWidget(m_scrollButton, 0);
57  m_layout->addWidget(m_buttonDown, 0);
58  setMinimumWidth(WIDTH); // Kludge to add some spacing but seems to work.
59 
66  BT_CONNECT(m_buttonUp, &QToolButton::clicked, [this]{ Q_EMIT change(-1); });
67  BT_CONNECT(m_buttonDown, &QToolButton::clicked,
68  [this]{ Q_EMIT change(1); });
69 }
70 
71 /** Sets the tooltips for the given entries using the parameters as text. */
72 void CScrollerWidgetSet::setToolTips(const QString & nextEntryTip,
73  const QString & scrollButtonTip,
74  const QString & previousEntryTip)
75 {
76  m_scrollButton->setToolTip(scrollButtonTip);
77  m_buttonDown->setToolTip(nextEntryTip);
78  m_buttonUp->setToolTip(previousEntryTip);
79 }
80 
81 
82 void CScrollerWidgetSet::wheelEvent(QWheelEvent * e) {
83  int const delta = e->angleDelta().y();
84  if (delta == 0) {
85  e->ignore();
86  } else {
87  Q_EMIT change((delta > 0) ? -1 : 1);
88  e->accept();
89  }
90 }
#define BT_CONNECT(...)
Definition: btconnect.h:20
void unlock()
The unlock() signal is emitted when the button releases the leaves the locked state.
void lock()
The lock() signal is emitted when the button grabs the mouse and enters the locked state.
void change_requested(int count)
Indicates a change the user made by moving the mouse.
CScrollButton * m_scrollButton
QToolButton * m_buttonDown
CScrollerWidgetSet(QWidget *parent=nullptr)
void setToolTips(const QString &nextEntry, const QString &scrollButton, const QString &previousEntry)
void change(int count)
QVBoxLayout * m_layout
void wheelEvent(QWheelEvent *e) override
QToolButton * m_buttonUp
#define WIDTH
#define MOVER_HEIGHT
#define ARROW_HEIGHT