82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
#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);
|
|
}
|
|
|
|
void Dialog::SetTitle(const QString& title) {
|
|
if (!delegate_) {
|
|
return;
|
|
}
|
|
|
|
delegate_->SetTitle(title);
|
|
}
|
|
|
|
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);
|
|
|
|
titleBar->SetSysButton(FrameTitleBar::FTB_ICON | FrameTitleBar::FTB_CLOSE | FrameTitleBar::FTB_TTILE);
|
|
|
|
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);
|
|
}
|