summaryrefslogtreecommitdiff
path: root/src/frontend/keychooser/cscrollerwidgetset.cpp
blob: a599bf533fe9928f1b9587dd012c6b4e01e8d2b7 (plain)
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
/*********
*
* 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/keychooser/cscrollerwidgetset.h"

#include <QString>
#include <QToolButton>
#include <QVBoxLayout>
#include <QWheelEvent>
#include "frontend/keychooser/cscrollbutton.h"
#include "util/btconnect.h"


#define WIDTH (static_cast<unsigned int>(16))
#define ARROW_HEIGHT (static_cast<unsigned int>(12))
#define MOVER_HEIGHT (static_cast<unsigned int>(6))


CScrollerWidgetSet::CScrollerWidgetSet(QWidget * parent)
    : QWidget(parent)
{
    m_layout = new QVBoxLayout(this);
    m_layout->setSpacing(0);
    m_layout->setContentsMargins(0, 0, 0, 0);
    m_layout->setAlignment(this, Qt::AlignHCenter | Qt::AlignCenter);

    m_buttonUp = new QToolButton(this);
    m_buttonUp->setArrowType(Qt::UpArrow);

    m_buttonUp->setFixedSize(WIDTH, ARROW_HEIGHT);
    m_buttonUp->setFocusPolicy(Qt::NoFocus);
    m_buttonUp->setAutoRaise(true);

    m_scrollButton = new CScrollButton(this);
    m_scrollButton->setFixedSize(WIDTH, MOVER_HEIGHT);
    m_scrollButton->setFocusPolicy(Qt::NoFocus);

    m_buttonDown = new QToolButton(this);
    m_buttonDown->setArrowType(Qt::DownArrow);
    m_buttonDown->setFixedSize(WIDTH, ARROW_HEIGHT);
    m_buttonDown->setFocusPolicy(Qt::NoFocus);
    m_buttonDown->setAutoRaise(true);

    m_layout->addWidget(m_buttonUp, 0);
    m_layout->addWidget(m_scrollButton, 0);
    m_layout->addWidget(m_buttonDown, 0);
    setMinimumWidth(WIDTH); // Kludge to add some spacing but seems to work.

    BT_CONNECT(m_scrollButton, SIGNAL(lock()), SLOT(slotLock()));
    BT_CONNECT(m_scrollButton, SIGNAL(unlock()), SLOT(slotUnlock()));
    BT_CONNECT(m_scrollButton, SIGNAL(change_requested(int)),
               SLOT(slotScroller(int)));
    BT_CONNECT(m_buttonUp, SIGNAL(clicked()), SLOT(slotUpClick()));
    BT_CONNECT(m_buttonDown, SIGNAL(clicked()), SLOT(slotDownClick()));
}

/** Sets the tooltips for the given entries using the parameters as text. */
void CScrollerWidgetSet::setToolTips(const QString & nextEntryTip,
                                     const QString & scrollButtonTip,
                                     const QString & previousEntryTip)
{
    m_scrollButton->setToolTip(scrollButtonTip);
    m_buttonDown->setToolTip(nextEntryTip);
    m_buttonUp->setToolTip(previousEntryTip);
}


void CScrollerWidgetSet::wheelEvent(QWheelEvent * e) {
    int const delta = e->delta();
    if (delta == 0) {
        e->ignore();
    } else {
        emit change((delta > 0) ? -1 : 1);
        e->accept();
    }
}

void CScrollerWidgetSet::slotLock() {
    emit scroller_pressed();
}

void CScrollerWidgetSet::slotUnlock() {
    emit scroller_released();
}

void CScrollerWidgetSet::slotScroller(int n) {
    emit change(n);
}

void CScrollerWidgetSet::slotUpClick() {
    slotScroller(-1);
}

void CScrollerWidgetSet::slotDownClick() {
    slotScroller(1);
}