DYTSrouce/src/ui/Dialog.cpp

82 lines
2.0 KiB
C++
Raw Normal View History

2025-01-04 04:12:51 +00:00
#include "Dialog.h"
#include <QStyleOption>
#include <QPainter>
#include <QVBoxLayout>
#include "FrameTitleBar.h"
#include "FramelessDelegate.h"
Dialog::Dialog(QWidget* parent)
: QDialog(parent)
, delegate_(FramelessDelegate::Create(this)) {
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
InitFrame();
}
void Dialog::DeleteThisOnClose() {
setAttribute(Qt::WA_DeleteOnClose);
}
void Dialog::SetTitleBar(FrameTitleBar* titleBar) {
delegate_->SetTitleBar(titleBar);
QVBoxLayout* layout = reinterpret_cast<QVBoxLayout*>(this->layout());
layout->insertWidget(0, titleBar, 0);
}
2025-01-05 09:41:54 +00:00
void Dialog::SetTitle(const QString& title) {
if (!delegate_) {
return;
}
delegate_->SetTitle(title);
}
2025-01-04 04:12:51 +00:00
void Dialog::hideEvent(QHideEvent*) {
}
bool Dialog::eventFilter(QObject*, QEvent*) {
return false;
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool Dialog::nativeEvent(const QByteArray& eventType, void* message, long* result) {
#else
bool Dialog::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) {
#endif
if (!delegate_->nativeEvent(eventType, message, result)) {
return QDialog::nativeEvent(eventType, message, result);
}
return true;
}
void Dialog::paintEvent(QPaintEvent* event) {
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
void Dialog::InitFrame() {
FrameTitleBar* titleBar = new FrameTitleBar(this);
titleBar->SetMainWidget(this);
2025-01-05 09:41:54 +00:00
titleBar->SetSysButton(FrameTitleBar::FTB_ICON | FrameTitleBar::FTB_CLOSE | FrameTitleBar::FTB_TTILE);
2025-01-04 04:12:51 +00:00
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setStretch(0, 0);
layout->setStretch(1, 1);
layout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
SetTitleBar(titleBar);
mainDilag_ = new QWidget(this);
layout->addWidget(mainDilag_, 1);
}