-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdialogbase.cpp
43 lines (35 loc) · 1.19 KB
/
dialogbase.cpp
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
/*
SPDX-FileCopyrightText: 2015 Tomasz Bojczuk <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "dialogbase.h"
#include <QBoxLayout>
#include <QKeyEvent>
DialogBase::DialogBase(QDialogButtonBox::StandardButtons buttons, QWidget *parent)
: QDialog(parent)
, m_okButton(nullptr)
, m_cancelButton(nullptr)
{
m_buttonBox = new QDialogButtonBox(this);
if (buttons & QDialogButtonBox::Ok) {
m_okButton = m_buttonBox->addButton(QDialogButtonBox::Ok);
m_okButton->setDefault(true);
}
if (buttons & QDialogButtonBox::Cancel) {
m_cancelButton = m_buttonBox->addButton(QDialogButtonBox::Cancel);
}
m_layout = new QBoxLayout(QBoxLayout::TopToBottom);
m_layout->addWidget(m_buttonBox);
setLayout(m_layout);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
void DialogBase::keyReleaseEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return && event->modifiers() == Qt::ControlModifier) {
done(Accepted);
} else {
QWidget::keyReleaseEvent(event);
}
}
#include "moc_dialogbase.cpp"