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