BibleTime
btmessageinputdialog.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 "btmessageinputdialog.h"
14 
15 #include <QAction>
16 #include <QDialogButtonBox>
17 #include <QLabel>
18 #include <QLineEdit>
19 #include <QSizePolicy>
20 #include <QSpacerItem>
21 #include <QTextBrowser>
22 #include <QVBoxLayout>
23 #include "../util/btconnect.h"
24 #include "../util/cresmgr.h"
25 #include "messagedialog.h"
26 
27 
29  QString const & inputLabel,
30  InputType inputType,
31  QString const & inputText,
32  QString const & infoMessage,
33  QWidget * parent,
34  Qt::WindowFlags f)
35  : QDialog(parent, f)
36 {
37  resize(280, 90);
38  setWindowTitle(title);
39  QVBoxLayout * verticalLayout = new QVBoxLayout(this);
40 
41  if (!infoMessage.isEmpty()) {
42  auto * const infoTextView = new QTextBrowser(this);
43  infoTextView->setPlainText(infoMessage);
44  infoTextView->setReadOnly(true);
45  infoTextView->setOpenLinks(false);
46  verticalLayout->addWidget(infoTextView);
47  resize(480, 200);
48  }
49 
50  QSpacerItem * verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
51  verticalLayout->addItem(verticalSpacer);
52 
53  QLabel * unlockTextLabel = new QLabel(inputLabel, this);
54  verticalLayout->addWidget(unlockTextLabel);
55 
56  m_inputTextEdit = new QLineEdit(inputText, parent);
57  if (inputType == Password) {
58  m_inputTextEdit->setEchoMode(QLineEdit::Password);
59 
60  // Add action to show/hide password:
61  auto * const passwordVisibilityAction =
62  m_inputTextEdit->addAction(CResMgr::mainIndex::showHide::icon(),
63  QLineEdit::TrailingPosition);
64  passwordVisibilityAction->setText(tr("Show password"));
65  passwordVisibilityAction->setCheckable(true);
66  BT_CONNECT(passwordVisibilityAction, &QAction::toggled,
67  [this,passwordVisibilityAction](bool enable) {
68  if (enable) {
69  m_inputTextEdit->setEchoMode(QLineEdit::Normal);
70  passwordVisibilityAction->setText(
71  tr("Hide password"));
72  } else {
73  m_inputTextEdit->setEchoMode(QLineEdit::Password);
74  passwordVisibilityAction->setText(
75  tr("Show password"));
76  }
77  });
78  }
79  verticalLayout->addWidget(m_inputTextEdit);
80 
81  QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
82  buttonBox->setOrientation(Qt::Horizontal);
83  buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
84  message::prepareDialogBox(buttonBox);
85  verticalLayout->addWidget(buttonBox);
86 
87  BT_CONNECT(buttonBox, &QDialogButtonBox::accepted,
88  this, &BtMessageInputDialog::accept);
89  BT_CONNECT(buttonBox, &QDialogButtonBox::rejected,
90  this, &BtMessageInputDialog::reject);
91 }
92 
94  return m_inputTextEdit->text();
95 }
96 
#define BT_CONNECT(...)
Definition: btconnect.h:20
QString getUserInput() const
getUserInput
BtMessageInputDialog(QString const &title, QString const &inputLabel, InputType inputType, QString const &inputText, QString const &infoMessage=QString(), QWidget *parent=nullptr, Qt::WindowFlags f=Qt::Dialog)
The BtMessageInputDialog class provides a editable field for user input. Optionally it displays a lar...
void prepareDialogBox(QDialogButtonBox *box)