File indexing completed on 2024-04-14 05:34:14
0001 /* 0002 SPDX-FileCopyrightText: 2015 Tomasz Bojczuk <seelook@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "dialogbase.h" 0008 #include <QBoxLayout> 0009 #include <QKeyEvent> 0010 0011 DialogBase::DialogBase(QDialogButtonBox::StandardButtons buttons, QWidget* parent): 0012 QDialog(parent), 0013 m_okButton(nullptr), 0014 m_cancelButton(nullptr) 0015 { 0016 m_buttonBox = new QDialogButtonBox(this); 0017 if (buttons & QDialogButtonBox::Ok) { 0018 m_okButton = m_buttonBox->addButton(QDialogButtonBox::Ok); 0019 m_okButton->setDefault(true); 0020 } 0021 if (buttons & QDialogButtonBox::Cancel) { 0022 m_cancelButton = m_buttonBox->addButton(QDialogButtonBox::Cancel); 0023 } 0024 0025 m_layout = new QBoxLayout(QBoxLayout::TopToBottom); 0026 m_layout->addWidget(m_buttonBox); 0027 0028 setLayout(m_layout); 0029 0030 connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0031 connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0032 } 0033 0034 void DialogBase::keyReleaseEvent(QKeyEvent* event) 0035 { 0036 if (event->key() == Qt::Key_Return && event->modifiers() == Qt::ControlModifier) { 0037 done(Accepted); 0038 } 0039 else { 0040 QWidget::keyReleaseEvent(event); 0041 } 0042 } 0043 0044 0045 0046 0047 #include "moc_dialogbase.cpp"