Add a "BasePopup" class, which helps add default functionality to any popups (like the search popup)

This commit is contained in:
Rasmus Karlsson 2019-12-14 12:57:16 +01:00
parent dd77a0088a
commit 55080bd354
5 changed files with 45 additions and 15 deletions

View file

@ -212,6 +212,7 @@ SOURCES += \
src/widgets/AccountSwitchPopup.cpp \ src/widgets/AccountSwitchPopup.cpp \
src/widgets/AccountSwitchWidget.cpp \ src/widgets/AccountSwitchWidget.cpp \
src/widgets/AttachedWindow.cpp \ src/widgets/AttachedWindow.cpp \
src/widgets/BasePopup.cpp \
src/widgets/BaseWidget.cpp \ src/widgets/BaseWidget.cpp \
src/widgets/BaseWindow.cpp \ src/widgets/BaseWindow.cpp \
src/widgets/dialogs/EmotePopup.cpp \ src/widgets/dialogs/EmotePopup.cpp \
@ -432,6 +433,7 @@ HEADERS += \
src/widgets/AccountSwitchPopup.hpp \ src/widgets/AccountSwitchPopup.hpp \
src/widgets/AccountSwitchWidget.hpp \ src/widgets/AccountSwitchWidget.hpp \
src/widgets/AttachedWindow.hpp \ src/widgets/AttachedWindow.hpp \
src/widgets/BasePopup.hpp \
src/widgets/BaseWidget.hpp \ src/widgets/BaseWidget.hpp \
src/widgets/BaseWindow.hpp \ src/widgets/BaseWindow.hpp \
src/widgets/dialogs/EmotePopup.hpp \ src/widgets/dialogs/EmotePopup.hpp \

21
src/widgets/BasePopup.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "widgets/BasePopup.hpp"
namespace chatterino {
BasePopup::BasePopup(FlagsEnum<Flags> _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

20
src/widgets/BasePopup.hpp Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include "common/FlagsEnum.hpp"
#include "widgets/BaseWindow.hpp"
namespace chatterino {
class BasePopup : public BaseWindow
{
public:
explicit BasePopup(FlagsEnum<BaseWindow::Flags> flags_ = None,
QWidget *parent = nullptr);
virtual ~BasePopup() = default;
protected:
void keyPressEvent(QKeyEvent *e) override;
};
} // namespace chatterino

View file

@ -73,17 +73,6 @@ void SearchPopup::search()
this->channelName_, this->snapshot_)); this->channelName_, this->snapshot_));
} }
void SearchPopup::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Escape)
{
this->close();
return;
}
BaseWidget::keyPressEvent(e);
}
void SearchPopup::initLayout() void SearchPopup::initLayout()
{ {
// VBOX // VBOX

View file

@ -3,7 +3,7 @@
#include "ForwardDecl.hpp" #include "ForwardDecl.hpp"
#include "messages/LimitedQueueSnapshot.hpp" #include "messages/LimitedQueueSnapshot.hpp"
#include "messages/search/MessagePredicate.hpp" #include "messages/search/MessagePredicate.hpp"
#include "widgets/BaseWindow.hpp" #include "widgets/BasePopup.hpp"
#include <memory> #include <memory>
@ -11,7 +11,7 @@ class QLineEdit;
namespace chatterino { namespace chatterino {
class SearchPopup : public BaseWindow class SearchPopup : public BasePopup
{ {
public: public:
SearchPopup(); SearchPopup();
@ -19,8 +19,6 @@ public:
virtual void setChannel(const ChannelPtr &channel); virtual void setChannel(const ChannelPtr &channel);
protected: protected:
void keyPressEvent(QKeyEvent *e) override;
virtual void updateWindowTitle(); virtual void updateWindowTitle();
private: private: