2025-01-04 04:12:51 +00:00
|
|
|
#include "FramelessDelegate.h"
|
|
|
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
|
|
|
#include "FrameTitleBar.h"
|
|
|
|
|
|
|
|
|
|
|
|
FramelessDelegate::FramelessDelegate(QWidget* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, mainWidget_(parent) {
|
|
|
|
if (nullptr != mainWidget_) {
|
|
|
|
mainWidget_->installEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FramelessDelegate::~FramelessDelegate() {
|
|
|
|
if (nullptr != titleBar_) {
|
|
|
|
titleBar_->removeEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nullptr != mainWidget_) {
|
|
|
|
mainWidget_->removeEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
bool FramelessDelegate::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) {
|
|
|
|
#else
|
|
|
|
bool FramelessDelegate::nativeEvent(const QByteArray & eventType, void* message, long* result) {
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramelessDelegate::SetTitleBar(FrameTitleBar* titleBar) {
|
|
|
|
if (nullptr == titleBar || titleBar_ == titleBar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (nullptr != titleBar_) {
|
|
|
|
titleBar_->removeEventFilter(this);
|
|
|
|
titleBar_->deleteLater();
|
|
|
|
}
|
|
|
|
titleBar_ = titleBar;
|
|
|
|
|
|
|
|
if (nullptr != titleBar_) {
|
|
|
|
titleBar_->installEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-05 09:41:54 +00:00
|
|
|
void FramelessDelegate::SetTitle(const QString& title) {
|
|
|
|
if (nullptr != titleBar_) {
|
|
|
|
titleBar_->SetTitle(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
bool FramelessDelegate::eventFilter(QObject* watched, QEvent* event) {
|
|
|
|
if (nullptr != mainWidget_ && mainWidget_ == watched) {
|
|
|
|
if (QEvent::Show == event->type()) {
|
|
|
|
OnShow();
|
|
|
|
} else if (QEvent::Hide == event->type()) {
|
|
|
|
OnHide();
|
|
|
|
} else if (QEvent::Close == event->type()) {
|
|
|
|
OnClose();
|
|
|
|
} else if (QEvent::WinIdChange == event->type()) {
|
|
|
|
isFirstShow_ = true;
|
|
|
|
}
|
|
|
|
//#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
else if (QEvent::ScreenChangeInternal == event->type()) {
|
|
|
|
OnScreenChangeInternaal();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//#endif
|
|
|
|
} else if (nullptr != titleBar_ && titleBar_ == watched) {
|
|
|
|
if (QEvent::Close == event->type() || QEvent::Hide == event->type()) {
|
|
|
|
RemoveMoveBar(titleBar_);
|
|
|
|
} else if (QEvent::Show == event->type()) {
|
|
|
|
AddMoveBar(titleBar_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QObject::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramelessDelegate::RemoveMoveBar(QWidget* moveWidget) {
|
|
|
|
moveBars_.removeOne(moveWidget);
|
|
|
|
}
|
|
|
|
|