-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwarningyesno.cpp
More file actions
48 lines (41 loc) · 1.23 KB
/
warningyesno.cpp
File metadata and controls
48 lines (41 loc) · 1.23 KB
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
#include "warningyesno.h"
#include "ui_warningyesno.h"
#include <QPushButton>
#include <QStyle>
WarningYesNo::WarningYesNo(QWidget *parent) :
QDialog(parent),
ui(new Ui::WarningYesNo)
{
ui->setupUi(this);
QStyle *s = QApplication::style();
int sz = s->pixelMetric(QStyle::PM_MessageBoxIconSize) ;
QIcon i = s->standardIcon(QStyle::SP_MessageBoxQuestion) ;
ui->icon->setPixmap(i.pixmap(sz,sz)) ;
ui->textEditWarning->viewport()->setAutoFillBackground( false );
ui->textEditWarning->setFocus() ;
yes = QChar('y') ;
no = QChar('n') ;
}
WarningYesNo::~WarningYesNo()
{
delete ui;
}
// Handle Y/N commands
void WarningYesNo::keyPressEvent(QKeyEvent *event)
{
int k = event->key() ;
if (k==Qt::Key_Enter || k==Qt::Key_Y) accept() ;
else if (k==Qt::Key_Escape || k==Qt::Key_N) reject() ;
else QDialog::keyPressEvent(event) ;
}
void WarningYesNo::setText(QString text)
{
ui->textEditWarning->setText(text) ;
}
void WarningYesNo::setButtons(QString yestext, QChar yeskey, QString notext, QChar nokey)
{
ui->buttonBox->button(QDialogButtonBox::Yes)->setText(yestext) ;
ui->buttonBox->button(QDialogButtonBox::No)->setText(notext) ;
yes = yeskey.toLower() ;
no = nokey.toLower() ;
}