void FramelessDialog::installWindowAgent()
{
windowAgent = new QWK::WidgetWindowAgent(this);
windowAgent->setup(this);
auto menuBar = new QMenuBar();
menuBar->setObjectName(QStringLiteral("win-menu-bar"));
auto titleLabel = new QLabel();
titleLabel->setAlignment(Qt::AlignCenter);
titleLabel->setObjectName(QStringLiteral("win-title-label"));
ifndef Q_OS_MAC
auto iconButton = new QWK::WindowButton();
iconButton->setObjectName(QStringLiteral("icon-button"));
iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto minButton = new QWK::WindowButton();
minButton->setObjectName(QStringLiteral("min-button"));
minButton->setProperty("system-button", true);
minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto maxButton = new QWK::WindowButton();
maxButton->setCheckable(true);
maxButton->setObjectName(QStringLiteral("max-button"));
maxButton->setProperty("system-button", true);
maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto closeButton = new QWK::WindowButton();
closeButton->setObjectName(QStringLiteral("close-button"));
closeButton->setProperty("system-button", true);
closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
if (max) {
showMaximized();
} else {
showNormal();
}
// It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
// the button remains to be hovered until the mouse move. As a result, we need to
// manually send leave events to the button.
emulateLeaveEvent(maxButton);
});
connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
FramelessDialog::FramelessDialog(QWidget *parent) : QDialog(parent) { installWindowAgent(); setWindowTitle(tr("Dialog")); // resize(800, 600); }
static inline void emulateLeaveEvent(QWidget *widget) { Q_ASSERT(widget); if (!widget) { return; } QTimer::singleShot(0, widget, [widget]() {
if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
else
endif
if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
elif (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
else
endif
}
void FramelessDialog::closeEvent(QCloseEvent *event) { event->accept(); }
void FramelessDialog::installWindowAgent() { windowAgent = new QWK::WidgetWindowAgent(this); windowAgent->setup(this);
ifndef Q_OS_MAC
endif
ifndef Q_OS_MAC
endif
ifndef Q_OS_MAC
endif
ifdef Q_OS_MAC
endif
ifndef Q_OS_MAC
endif
}