summaryrefslogtreecommitdiff
path: root/src/frontend/searchdialog/crangechooserdialog.h
blob: a9cbaf4b4fbddf8f33d8e56932f55aef33ca7aab (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*********
*
* In the name of the Father, and of the Son, and of the Holy Spirit.
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#ifndef CRANGECHOOSERDIALOG_H
#define CRANGECHOOSERDIALOG_H

#include <QDialog>

#include <QListWidgetItem>


class QDialogButtonBox;
class QLabel;
class QLineEdit;
class QListWidget;
class QPushButton;
class QTextEdit;

namespace Search {

/** \todo Redesign this dialog and rename to have a Bt prefix. */
class CRangeChooserDialog: public QDialog {

        Q_OBJECT

private: /* Types: */

    class RangeItem: public QListWidgetItem {

    public:

        inline RangeItem(const QString &caption,
                         const QString &range = QString::null,
                         QListWidget * parent = 0)
            : QListWidgetItem(caption, parent)
            , m_range(range) {}

        inline const QString caption() const { return text(); }
        inline void setCaption(const QString &caption) { setText(caption); }
        inline const QString &range() const { return m_range; }
        inline void setRange(const QString &range) { m_range = range; }

    private: /* Fields: */

        QString m_range;

    }; /* class RangeItem */

public: /* Methods: */

    CRangeChooserDialog(QWidget *parentDialog = 0);

    virtual void accept();

private: /* Methods: */

    /**
      Initializes widgets.
    */
    void initView();

    /**
      Initializes connections.
    */
    void initConnections();

    void retranslateUi();

    /**
      Stores the values from the current edit view to the given RangeItem.
      \param[out] i The RangeItem object to store the values to.
    */
    void saveCurrentToRange(RangeItem * i);

    /**
      Resets the editing controls based on whether a range is selected in the
      range list.
    */
    void resetEditControls();

private slots:

    /**
      Adds a new range to the list.
    */
    void addNewRange();

    /**
      Handles changes in m_rangeList.
    */
    void selectedRangeChanged(QListWidgetItem * current,
                              QListWidgetItem * previous);

    /**
      Parses the entered text and prints out the result in the list box below
      the edit area.
    */
    void updateResultList();

    /**
      Deletes the selected range.
    */
    void deleteCurrentRange();

    /**
      Restores the default ranges.
    */
    void restoreDefaults();

    /**
      Called when m_nameEdit changes.
    */
    void nameEditTextChanged(const QString &newText);

private:

    QLabel      *m_rangeListLabel;
    QListWidget *m_rangeList;

    QLabel    *m_nameEditLabel;
    QLineEdit *m_nameEdit;

    QLabel    *m_rangeEditLabel;
    QTextEdit *m_rangeEdit;

    QLabel      *m_resultListLabel;
    QListWidget *m_resultList;

    QPushButton *m_newRangeButton;
    QPushButton *m_deleteRangeButton;

    QDialogButtonBox *m_buttonBox;

}; /* class CRangeChooserDialog */

} /* namespace Search */

#endif