refactor: some mini feature changes in BaseWindow (#6074)
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
- Dev: Refactored some settings styles/APIs. (#6023)
|
||||
- Dev: Added snapshot tests for EventSub. (#5965)
|
||||
- Dev: Updated crashpad. (#6026)
|
||||
- Dev: Mini feature refactor of BaseWindow. (#6074)
|
||||
- Dev: Removed dead code and some MSVC warnings. (#6024)
|
||||
- Dev: Added check if WEBP is supported. (#6073)
|
||||
|
||||
|
||||
@@ -88,20 +88,14 @@ void WindowManager::showSettingsDialog(QWidget *parent,
|
||||
|
||||
void WindowManager::showAccountSelectPopup(QPoint point)
|
||||
{
|
||||
// static QWidget *lastFocusedWidget = nullptr;
|
||||
static AccountSwitchPopup *w = new AccountSwitchPopup();
|
||||
static auto *w = new AccountSwitchPopup;
|
||||
|
||||
if (w->hasFocus())
|
||||
{
|
||||
w->hide();
|
||||
// if (lastFocusedWidget) {
|
||||
// lastFocusedWidget->setFocus();
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// lastFocusedWidget = this->focusWidget();
|
||||
|
||||
w->refresh();
|
||||
|
||||
w->moveTo(point - QPoint(30, 0), widgets::BoundsChecking::CursorPosition);
|
||||
|
||||
@@ -14,7 +14,6 @@ void initUpdateButton(Button &button,
|
||||
// show update prompt when clicking the button
|
||||
QObject::connect(&button, &Button::leftClicked, [&button] {
|
||||
auto *dialog = new UpdateDialog();
|
||||
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
|
||||
auto globalPoint = button.mapToGlobal(
|
||||
QPoint(int(-100 * button.scale()), button.height()));
|
||||
|
||||
@@ -14,13 +14,16 @@ namespace chatterino {
|
||||
using namespace literals;
|
||||
|
||||
AccountSwitchPopup::AccountSwitchPopup(QWidget *parent)
|
||||
: BaseWindow({BaseWindow::TopMost, BaseWindow::Frameless,
|
||||
BaseWindow::DisableLayoutSave},
|
||||
parent)
|
||||
: BaseWindow(
|
||||
{
|
||||
BaseWindow::TopMost,
|
||||
BaseWindow::Frameless,
|
||||
BaseWindow::DisableLayoutSave,
|
||||
BaseWindow::LinuxPopup,
|
||||
},
|
||||
parent)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
this->setWindowFlag(Qt::Popup);
|
||||
#endif
|
||||
this->focusOutAction = FocusOutAction::Hide;
|
||||
|
||||
this->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
@@ -92,11 +95,6 @@ void AccountSwitchPopup::refresh()
|
||||
this->ui_.accountSwitchWidget->refresh();
|
||||
}
|
||||
|
||||
void AccountSwitchPopup::focusOutEvent(QFocusEvent *)
|
||||
{
|
||||
this->hide();
|
||||
}
|
||||
|
||||
void AccountSwitchPopup::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -18,7 +18,6 @@ public:
|
||||
void refresh();
|
||||
|
||||
protected:
|
||||
void focusOutEvent(QFocusEvent *event) final;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
void themeChangedEvent() override;
|
||||
|
||||
+42
-36
@@ -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)
|
||||
{
|
||||
|
||||
@@ -38,9 +38,10 @@ public:
|
||||
DisableLayoutSave = 1 << 7,
|
||||
BoundsCheckOnShow = 1 << 8,
|
||||
ClearBuffersOnDpiChange = 1 << 9,
|
||||
};
|
||||
|
||||
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
|
||||
/// special flag that enables the Qt::Popup flag on Linux
|
||||
LinuxPopup = 1 << 10,
|
||||
};
|
||||
|
||||
explicit BaseWindow(FlagsEnum<Flags> flags_ = None,
|
||||
QWidget *parent = nullptr);
|
||||
@@ -55,9 +56,6 @@ public:
|
||||
std::function<void()> onClicked);
|
||||
EffectLabel *addTitleBarLabel(std::function<void()> onClicked);
|
||||
|
||||
void setActionOnFocusLoss(ActionOnFocusLoss value);
|
||||
ActionOnFocusLoss getActionOnFocusLoss() const;
|
||||
|
||||
void moveTo(QPoint point, widgets::BoundsChecking mode);
|
||||
|
||||
/**
|
||||
@@ -93,6 +91,25 @@ Q_SIGNALS:
|
||||
void topMostChanged(bool topMost);
|
||||
|
||||
protected:
|
||||
enum class FocusOutAction : std::uint8_t {
|
||||
None,
|
||||
Hide,
|
||||
};
|
||||
|
||||
/// focusOutAction is used when the `FocusOut` event is fired
|
||||
FocusOutAction focusOutAction = FocusOutAction::None;
|
||||
|
||||
enum class WindowDeactivateAction : std::uint8_t {
|
||||
Nothing,
|
||||
Delete,
|
||||
Close,
|
||||
Hide,
|
||||
};
|
||||
|
||||
/// This action is used when the `WindowDeactivate` event is fired
|
||||
WindowDeactivateAction windowDeactivateAction =
|
||||
WindowDeactivateAction::Nothing;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool nativeEvent(const QByteArray &eventType, void *message,
|
||||
qintptr *result) override;
|
||||
@@ -118,6 +135,9 @@ protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
|
||||
QPointF movingRelativePos;
|
||||
bool moving{};
|
||||
|
||||
@@ -132,7 +152,6 @@ private:
|
||||
|
||||
void calcButtonsSizes();
|
||||
void drawCustomWindowFrame(QPainter &painter);
|
||||
void onFocusLost();
|
||||
|
||||
static void applyScaleRecursive(QObject *root, float scale);
|
||||
|
||||
@@ -148,7 +167,6 @@ private:
|
||||
#endif
|
||||
|
||||
bool enableCustomFrame_;
|
||||
ActionOnFocusLoss actionOnFocusLoss_ = Nothing;
|
||||
bool frameless_;
|
||||
bool shown_ = false;
|
||||
FlagsEnum<Flags> flags_;
|
||||
|
||||
@@ -47,7 +47,7 @@ DraggablePopup::DraggablePopup(bool closeAutomatically, QWidget *parent)
|
||||
{
|
||||
if (closeAutomatically)
|
||||
{
|
||||
this->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
this->windowDeactivateAction = WindowDeactivateAction::Delete;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -108,12 +108,12 @@ void DraggablePopup::togglePinned()
|
||||
this->isPinned_ = !isPinned_;
|
||||
if (isPinned_)
|
||||
{
|
||||
this->setActionOnFocusLoss(BaseWindow::Nothing);
|
||||
this->windowDeactivateAction = WindowDeactivateAction::Nothing;
|
||||
this->pinButton_->setPixmap(getResources().buttons.pinEnabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
this->windowDeactivateAction = WindowDeactivateAction::Delete;
|
||||
this->pinButton_->setPixmap(getTheme()->buttons.pin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ UpdateDialog::UpdateDialog()
|
||||
: BaseWindow({BaseWindow::Frameless, BaseWindow::TopMost,
|
||||
BaseWindow::EnableCustomFrame, BaseWindow::DisableLayoutSave})
|
||||
{
|
||||
this->windowDeactivateAction = WindowDeactivateAction::Delete;
|
||||
|
||||
auto layout =
|
||||
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();
|
||||
|
||||
|
||||
@@ -48,8 +48,9 @@ QuickSwitcherPopup::QuickSwitcherPopup(Window *parent)
|
||||
, switcherModel_(this)
|
||||
, window(parent)
|
||||
{
|
||||
this->setWindowFlag(Qt::Dialog);
|
||||
this->setActionOnFocusLoss(BaseWindow::ActionOnFocusLoss::Delete);
|
||||
assert(this->windowFlags().testFlag(Qt::Dialog));
|
||||
|
||||
this->windowDeactivateAction = WindowDeactivateAction::Delete;
|
||||
this->setMinimumSize(QuickSwitcherPopup::MINIMUM_SIZE);
|
||||
|
||||
this->initWidgets();
|
||||
|
||||
Reference in New Issue
Block a user