52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
#include "abstractdialog.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QGuiApplication>
|
|
#include <QLabel>
|
|
#include <QScreen>
|
|
#include <QVBoxLayout>
|
|
|
|
AbstractDialog::AbstractDialog(QWidget* parent)
|
|
: QDialog(parent) {
|
|
setWindowTitle(tr("Dialog does what?..."));
|
|
setModal(true);
|
|
|
|
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &AbstractDialog::accept);
|
|
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &AbstractDialog::reject);
|
|
|
|
m_contentContainer = new QLabel("content", this);
|
|
|
|
m_outerLayout = new QVBoxLayout;
|
|
m_outerLayout->addWidget(m_contentContainer);
|
|
m_outerLayout->addWidget(m_buttonBox);
|
|
|
|
setLayout(m_outerLayout);
|
|
}
|
|
|
|
void AbstractDialog::show() {
|
|
centerInParent();
|
|
QWidget::show();
|
|
}
|
|
|
|
void AbstractDialog::accept() { QDialog::accept(); }
|
|
|
|
void AbstractDialog::reject() { QDialog::reject(); }
|
|
|
|
void AbstractDialog::centerInParent() {
|
|
// BUG the centering in the parent doesn't work the first time (and the later ones seem off too)
|
|
QWidget* parent = parentWidget();
|
|
|
|
if (parent) {
|
|
auto parentRect = parent->geometry();
|
|
move(parentRect.center() - rect().center());
|
|
} else {
|
|
QRect screenGeometry = QGuiApplication::screens().at(0)->geometry();
|
|
int x = (screenGeometry.width() - width()) / 2;
|
|
int y = (screenGeometry.height() - height()) / 2;
|
|
move(x, y);
|
|
}
|
|
}
|
|
|
|
void AbstractDialog::closeEvent(QCloseEvent* event) { QWidget::closeEvent(event); }
|