diff --git a/chatterino.pro b/chatterino.pro index cc692b864..9444d6e1b 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -212,6 +212,7 @@ SOURCES += \ src/widgets/AccountSwitchPopup.cpp \ src/widgets/AccountSwitchWidget.cpp \ src/widgets/AttachedWindow.cpp \ + src/widgets/BasePopup.cpp \ src/widgets/BaseWidget.cpp \ src/widgets/BaseWindow.cpp \ src/widgets/dialogs/EmotePopup.cpp \ @@ -432,6 +433,7 @@ HEADERS += \ src/widgets/AccountSwitchPopup.hpp \ src/widgets/AccountSwitchWidget.hpp \ src/widgets/AttachedWindow.hpp \ + src/widgets/BasePopup.hpp \ src/widgets/BaseWidget.hpp \ src/widgets/BaseWindow.hpp \ src/widgets/dialogs/EmotePopup.hpp \ diff --git a/src/widgets/BasePopup.cpp b/src/widgets/BasePopup.cpp new file mode 100644 index 000000000..f8c5c5e62 --- /dev/null +++ b/src/widgets/BasePopup.cpp @@ -0,0 +1,21 @@ +#include "widgets/BasePopup.hpp" + +namespace chatterino { + +BasePopup::BasePopup(FlagsEnum _flags, QWidget *parent) + : BaseWindow(std::move(_flags), parent) +{ +} + +void BasePopup::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Escape) + { + this->close(); + return; + } + + BaseWindow::keyPressEvent(e); +} + +} // namespace chatterino diff --git a/src/widgets/BasePopup.hpp b/src/widgets/BasePopup.hpp new file mode 100644 index 000000000..6d7ab7d65 --- /dev/null +++ b/src/widgets/BasePopup.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "common/FlagsEnum.hpp" +#include "widgets/BaseWindow.hpp" + +namespace chatterino { + +class BasePopup : public BaseWindow +{ +public: + explicit BasePopup(FlagsEnum flags_ = None, + QWidget *parent = nullptr); + + virtual ~BasePopup() = default; + +protected: + void keyPressEvent(QKeyEvent *e) override; +}; + +} // namespace chatterino diff --git a/src/widgets/helper/SearchPopup.cpp b/src/widgets/helper/SearchPopup.cpp index e656bc5e9..82abf5f0a 100644 --- a/src/widgets/helper/SearchPopup.cpp +++ b/src/widgets/helper/SearchPopup.cpp @@ -73,17 +73,6 @@ void SearchPopup::search() this->channelName_, this->snapshot_)); } -void SearchPopup::keyPressEvent(QKeyEvent *e) -{ - if (e->key() == Qt::Key_Escape) - { - this->close(); - return; - } - - BaseWidget::keyPressEvent(e); -} - void SearchPopup::initLayout() { // VBOX diff --git a/src/widgets/helper/SearchPopup.hpp b/src/widgets/helper/SearchPopup.hpp index 261886c18..bebf715af 100644 --- a/src/widgets/helper/SearchPopup.hpp +++ b/src/widgets/helper/SearchPopup.hpp @@ -3,7 +3,7 @@ #include "ForwardDecl.hpp" #include "messages/LimitedQueueSnapshot.hpp" #include "messages/search/MessagePredicate.hpp" -#include "widgets/BaseWindow.hpp" +#include "widgets/BasePopup.hpp" #include @@ -11,7 +11,7 @@ class QLineEdit; namespace chatterino { -class SearchPopup : public BaseWindow +class SearchPopup : public BasePopup { public: SearchPopup(); @@ -19,8 +19,6 @@ public: virtual void setChannel(const ChannelPtr &channel); protected: - void keyPressEvent(QKeyEvent *e) override; - virtual void updateWindowTitle(); private: