1 /*
2  * %kadu copyright begin%
3  * Copyright 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
4  * Copyright 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
5  * %kadu copyright end%
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <QtWidgets/QApplication>
22 #include <QtWidgets/QDialogButtonBox>
23 #include <QtWidgets/QFormLayout>
24 #include <QtWidgets/QLabel>
25 #include <QtWidgets/QLineEdit>
26 #include <QtWidgets/QPushButton>
27 #include <QtWidgets/QStyle>
28 
29 #include "token-window.h"
30 
TokenWindow(const QPixmap & tokenPixmap,QWidget * parent)31 TokenWindow::TokenWindow(const QPixmap &tokenPixmap, QWidget *parent) :
32 		QDialog(parent)
33 {
34 	setAttribute(Qt::WA_DeleteOnClose);
35 	setWindowTitle(tr("Enter Token Value"));
36 
37 	createGui(tokenPixmap);
38 }
39 
~TokenWindow()40 TokenWindow::~TokenWindow()
41 {
42 }
43 
createGui(const QPixmap & tokenPixmap)44 void TokenWindow::createGui(const QPixmap &tokenPixmap)
45 {
46 	QVBoxLayout *layout = new QVBoxLayout(this);
47 
48 	QLabel *imageLabel = new QLabel(this);
49 	imageLabel->setPixmap(tokenPixmap);
50 
51 	TokenValue = new QLineEdit(this);
52 
53 	QWidget *formWidget = new QWidget(this);
54 	layout->addWidget(formWidget);
55 
56 	QFormLayout *formLayout = new QFormLayout(formWidget);
57 	formLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
58 	formLayout->addRow(0, imageLabel);
59 	formLayout->addRow(tr("Enter text from the picture:"), TokenValue);
60 
61 	QDialogButtonBox *buttons = new QDialogButtonBox(this);
62 
63 	QPushButton *okButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogOkButton), tr("Ok"), buttons);
64 	QPushButton *cancelButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogCancelButton), tr("Cancel"), buttons);
65 
66 	buttons->addButton(okButton, QDialogButtonBox::AcceptRole);
67 	buttons->addButton(cancelButton, QDialogButtonBox::DestructiveRole);
68 
69 	layout->addSpacing(16);
70 	layout->addWidget(buttons);
71 
72 	connect(TokenValue, SIGNAL(returnPressed()), this, SLOT(accept()));
73 	connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
74 	connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
75 }
76 
accept()77 void TokenWindow::accept()
78 {
79 	emit tokenValueEntered(TokenValue->text());
80 	QDialog::accept();
81 }
82 
reject()83 void TokenWindow::reject()
84 {
85 	emit tokenValueEntered(QString());
86 	QDialog::reject();
87 }
88 
89 #include "moc_token-window.cpp"
90