refactor: some mini feature changes in BaseWindow (#6074)

This commit is contained in:
pajlada
2025-03-13 22:20:03 +01:00
committed by GitHub
parent 55031c5108
commit fb375e149b
10 changed files with 86 additions and 68 deletions
+42 -36
View File
@@ -210,6 +210,13 @@ Qt::WindowFlags windowFlagsFor(FlagsEnum<BaseWindow::Flags> flags)
out.setFlag(Qt::WindowStaysOnTopHint, flags.has(BaseWindow::TopMost));
out.setFlag(Qt::FramelessWindowHint, flags.has(BaseWindow::Frameless));
#ifdef Q_OS_LINUX
if (flags.has(BaseWindow::LinuxPopup))
{
out.setFlag(Qt::Popup);
}
#endif
return out;
}
@@ -449,16 +456,6 @@ bool BaseWindow::isTopMost() const
return this->isTopMost_ || this->flags_.has(TopMost);
}
void BaseWindow::setActionOnFocusLoss(ActionOnFocusLoss value)
{
this->actionOnFocusLoss_ = value;
}
BaseWindow::ActionOnFocusLoss BaseWindow::getActionOnFocusLoss() const
{
return this->actionOnFocusLoss_;
}
QWidget *BaseWindow::getLayoutContainer()
{
if (this->hasCustomWindowFrame())
@@ -521,10 +518,26 @@ void BaseWindow::themeChangedEvent()
bool BaseWindow::event(QEvent *event)
{
if (event->type() ==
QEvent::WindowDeactivate /*|| event->type() == QEvent::FocusOut*/)
if (event->type() == QEvent::WindowDeactivate)
{
this->onFocusLost();
switch (this->windowDeactivateAction)
{
case WindowDeactivateAction::Delete:
this->deleteLater();
break;
case WindowDeactivateAction::Close:
this->close();
break;
case WindowDeactivateAction::Hide:
this->hide();
break;
case WindowDeactivateAction::Nothing:
default:
break;
}
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
@@ -571,29 +584,6 @@ void BaseWindow::wheelEvent(QWheelEvent *event)
}
}
void BaseWindow::onFocusLost()
{
switch (this->getActionOnFocusLoss())
{
case Delete: {
this->deleteLater();
}
break;
case Close: {
this->close();
}
break;
case Hide: {
this->hide();
}
break;
default:;
}
}
void BaseWindow::mousePressEvent(QMouseEvent *event)
{
#ifndef Q_OS_WIN
@@ -660,6 +650,22 @@ void BaseWindow::mouseMoveEvent(QMouseEvent *event)
BaseWidget::mouseMoveEvent(event);
}
void BaseWindow::focusOutEvent(QFocusEvent *event)
{
switch (this->focusOutAction)
{
case FocusOutAction::Hide:
this->hide();
break;
case FocusOutAction::None:
default:
break;
}
BaseWidget::focusOutEvent(event);
}
TitleBarButton *BaseWindow::addTitleBarButton(const TitleBarButtonStyle &style,
std::function<void()> onClicked)
{