BibleTime
ckeychooserwidget.h
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 #pragma once
14 
15 #include <QComboBox>
16 
17 #include <QObject>
18 #include <QString>
19 #include <QStringList>
20 #include <QWidget>
21 #include "../../util/btassert.h"
22 
23 
24 class CScrollerWidgetSet;
25 class QEvent;
26 class QHBoxLayout;
27 
28 /**
29 * We use this class to control the focus move in the combobox
30 * This class is used in the key chooser widgets
31 */
32 class CKCComboBox: public QComboBox {
33 
34  Q_OBJECT
35 
36 public: // methods:
37 
38  CKCComboBox(QWidget * parent = nullptr);
39 
40 protected: // methods:
41 
42  bool eventFilter(QObject * o, QEvent * e) override;
43 
44 Q_SIGNALS:
45 
46  /**
47  * Emitted when the user moves the focus away from the combo by pressing tab
48  */
49  void focusOut(int itemIndex);
50 
51 };
52 
53 /**
54  * This class implements the KeyCooser Widget, which
55  * consists of a @ref QComboBox, two normal ref @QToolButton
56  * and a enhanced @ref CScrollButton
57  *
58  * @author The BibleTime team
59  */
60 class CKeyChooserWidget: public QWidget {
61 
62  Q_OBJECT
63 
64 public: // methods:
65 
66  CKeyChooserWidget(QStringList * list = nullptr,
67  QWidget * parent = nullptr);
68 
69  CKeyChooserWidget(int count = 0,
70  QWidget * parent = nullptr);
71 
72  /**
73  * This function does clear the combobox, then fill in
74  * the StringList, set the ComboBox' current item to index
75  * and if do_emit is true, it will emit @ref #changed
76  *
77  * @param list the stringlist to be inserted
78  * @param index the index that the combobox is to jump to
79  * @param do_emit should we emit @ref #changed(int)
80  */
81  void reset(const int count, int index, bool do_emit);
82 
83  void reset(const QStringList & list, int index, bool do_emit);
84 
85  void reset(const QStringList * list, int index, bool do_emit);
86 
87  /**
88  * Initializes this widget. We need this function because
89  * we have more than one constructor.
90  */
91  void init();
92 
93  /**
94  * Sets the tooltips for the given entries using the parameters as text.
95  */
96  void setToolTips(const QString & comboTip,
97  const QString & nextEntry,
98  const QString & scrollButton,
99  const QString & previousEntry);
100 
101  /**
102  * Sets the current item to the one with the given text
103  */
104  bool setItem(const QString & item);
105 
106  /**
107  * Return the combobox of this key chooser widget.
108  */
109  QComboBox & comboBox() const {
111  return *m_comboBox;
112  }
113 
114 Q_SIGNALS:
115 
116  /**
117  * Is emitted if the widget changed, but
118  * only if it is not locked or being reset
119  *
120  * @param the current ComboBox index
121  */
122  void changed(int index);
123 
124  /**
125  * Is emitted if the widget was left with a focus out event.
126  * @param index The new index of the ComboBox
127  */
128  void focusOut(int index);
129 
130 private: // fields:
131 
132  QStringList m_list;
134 
135  /**
136  * Members should never be public!!
137  */
139  QHBoxLayout * m_mainLayout;
141 
142  /**
143  * indicates wheter we are resetting at the moment
144  */
146 
147  QString m_oldKey;
148 
149 };
#define BT_ASSERT(...)
Definition: btassert.h:17
CKCComboBox(QWidget *parent=nullptr)
void focusOut(int itemIndex)
bool eventFilter(QObject *o, QEvent *e) override
QHBoxLayout * m_mainLayout
void focusOut(int index)
bool setItem(const QString &item)
CKeyChooserWidget(QStringList *list=nullptr, QWidget *parent=nullptr)
void setToolTips(const QString &comboTip, const QString &nextEntry, const QString &scrollButton, const QString &previousEntry)
QComboBox & comboBox() const
void changed(int index)
void reset(const int count, int index, bool do_emit)
CScrollerWidgetSet * m_scroller
CKCComboBox * m_comboBox