BibleTime
btdropdownchooserbutton.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 
14 
15 #include <QWheelEvent>
16 #include "btversekeymenu.h"
17 #include "btbiblekeywidget.h"
18 
19 
20 const unsigned int ARROW_HEIGHT = 15;
21 
23  void (BtBibleKeyWidget::*populateMenu)(QMenu &),
24  BtBibleKeyWidget & parent)
25  : QToolButton(&parent)
26  , m_populateMenu(populateMenu)
27  , m_parent(parent)
28 {
29  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
30 
31  setAutoRaise(false);
32  setArrowType(Qt::NoArrow);
33  setFixedHeight(ARROW_HEIGHT);
34  setFocusPolicy(Qt::NoFocus);
35  setPopupMode(QToolButton::InstantPopup);
36  setStyleSheet(
37  QStringLiteral(
38  "QToolButton{margin:0px;}"
39  "QToolButton::menu-indicator{"
40  "subcontrol-position:center center"
41  "}"));
42 
43  setMenu(new BtVerseKeyMenu(this));
44 }
45 
46 
48  //recreate the menu
49  menu()->clear();
50  (m_parent.*m_populateMenu)(*menu());
51 
52  QToolButton::mousePressEvent(e);
53 }
54 
55 void BtDropdownChooserButton::wheelEvent(QWheelEvent * e) {
56  int const delta = e->angleDelta().y();
57  if (delta == 0) {
58  e->ignore();
59  } else {
60  Q_EMIT stepItem((delta > 0) ? -1 : 1);
61  e->accept();
62  }
63 }
const unsigned int ARROW_HEIGHT
void stepItem(int step)
void mousePressEvent(QMouseEvent *event) override
void(BtBibleKeyWidget::* m_populateMenu)(QMenu &)
void wheelEvent(QWheelEvent *event) override
BtDropdownChooserButton(void(BtBibleKeyWidget::*populateMenu)(QMenu &), BtBibleKeyWidget &parent)