Renamed source code folder "Dialogs" into "dialogs".
This commit is contained in:
51
dialogs/abstractdialog.cpp
Normal file
51
dialogs/abstractdialog.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#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); }
|
||||
Reference in New Issue
Block a user