mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
improved split header menu button
This commit is contained in:
parent
f34063213c
commit
5df231f072
|
@ -249,7 +249,8 @@ SOURCES += \
|
||||||
src/util/JsonQuery.cpp \
|
src/util/JsonQuery.cpp \
|
||||||
src/RunGui.cpp \
|
src/RunGui.cpp \
|
||||||
src/BrowserExtension.cpp \
|
src/BrowserExtension.cpp \
|
||||||
src/util/FormatTime.cpp
|
src/util/FormatTime.cpp \
|
||||||
|
src/util/FunctionEventFilter.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/Application.hpp \
|
src/Application.hpp \
|
||||||
|
@ -446,7 +447,8 @@ HEADERS += \
|
||||||
src/util/JsonQuery.hpp \
|
src/util/JsonQuery.hpp \
|
||||||
src/RunGui.hpp \
|
src/RunGui.hpp \
|
||||||
src/BrowserExtension.hpp \
|
src/BrowserExtension.hpp \
|
||||||
src/util/FormatTime.hpp
|
src/util/FormatTime.hpp \
|
||||||
|
src/util/FunctionEventFilter.hpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources/resources.qrc \
|
resources/resources.qrc \
|
||||||
|
|
17
src/util/FunctionEventFilter.cpp
Normal file
17
src/util/FunctionEventFilter.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include "FunctionEventFilter.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
FunctionEventFilter::FunctionEventFilter(
|
||||||
|
QObject *parent, std::function<bool(QObject *, QEvent *)> function)
|
||||||
|
: QObject(parent)
|
||||||
|
, function_(std::move(function))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FunctionEventFilter::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
return this->function_(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
24
src/util/FunctionEventFilter.hpp
Normal file
24
src/util/FunctionEventFilter.hpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QObject>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
class FunctionEventFilter : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FunctionEventFilter(QObject *parent,
|
||||||
|
std::function<bool(QObject *, QEvent *)> function);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<bool(QObject *, QEvent *)> function_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -6,6 +6,7 @@
|
||||||
#include "providers/twitch/TwitchServer.hpp"
|
#include "providers/twitch/TwitchServer.hpp"
|
||||||
#include "singletons/Resources.hpp"
|
#include "singletons/Resources.hpp"
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
|
#include "util/FunctionEventFilter.hpp"
|
||||||
#include "util/LayoutCreator.hpp"
|
#include "util/LayoutCreator.hpp"
|
||||||
#include "widgets/Label.hpp"
|
#include "widgets/Label.hpp"
|
||||||
#include "widgets/TooltipWidget.hpp"
|
#include "widgets/TooltipWidget.hpp"
|
||||||
|
@ -86,33 +87,13 @@ SplitHeader::SplitHeader(Split *_split)
|
||||||
// dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
|
// dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
|
||||||
// dropdown->setScaleIndependantSize(23, 23);
|
// dropdown->setScaleIndependantSize(23, 23);
|
||||||
this->addDropdownItems(dropdown.getElement());
|
this->addDropdownItems(dropdown.getElement());
|
||||||
QObject::connect(
|
QObject::connect(dropdown.getElement(),
|
||||||
dropdown.getElement(), &RippleEffectButton::leftMousePress, this,
|
&RippleEffectButton::leftMousePress, this, [this] {
|
||||||
[this] {
|
if (!this->menuVisible_) {
|
||||||
QTimer::singleShot(80, this, [this] {
|
QTimer::singleShot(
|
||||||
auto point = [this] {
|
80, this, [this] { this->showMenu(); });
|
||||||
auto bounds =
|
}
|
||||||
QApplication::desktop()->availableGeometry(this);
|
});
|
||||||
|
|
||||||
auto point = this->dropdownButton_->mapToGlobal(
|
|
||||||
QPoint(this->dropdownButton_->width() -
|
|
||||||
this->dropdownMenu_.width(),
|
|
||||||
this->dropdownButton_->height()));
|
|
||||||
|
|
||||||
if (point.y() + this->dropdownMenu_.height() >
|
|
||||||
bounds.bottom()) {
|
|
||||||
point.setY(point.y() -
|
|
||||||
this->dropdownMenu_.height() -
|
|
||||||
this->dropdownButton_->height());
|
|
||||||
}
|
|
||||||
|
|
||||||
return point;
|
|
||||||
};
|
|
||||||
|
|
||||||
this->dropdownMenu_.popup(point());
|
|
||||||
this->dropdownMenu_.move(point());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- misc
|
// ---- misc
|
||||||
|
@ -147,6 +128,15 @@ SplitHeader::SplitHeader(Split *_split)
|
||||||
getSettings()->showUptime.connect(
|
getSettings()->showUptime.connect(
|
||||||
[this](const auto &, const auto &) { this->updateChannelText(); },
|
[this](const auto &, const auto &) { this->updateChannelText(); },
|
||||||
this->managedConnections_);
|
this->managedConnections_);
|
||||||
|
|
||||||
|
this->dropdownMenu_.installEventFilter(
|
||||||
|
new FunctionEventFilter(this, [this](QObject *, QEvent *event) {
|
||||||
|
if (event->type() == QEvent::Hide) {
|
||||||
|
QTimer::singleShot(20, this,
|
||||||
|
[this] { this->menuVisible_ = false; });
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
SplitHeader::~SplitHeader()
|
SplitHeader::~SplitHeader()
|
||||||
|
@ -191,6 +181,28 @@ void SplitHeader::addDropdownItems(RippleEffectButton *)
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SplitHeader::showMenu()
|
||||||
|
{
|
||||||
|
auto point = [this] {
|
||||||
|
auto bounds = QApplication::desktop()->availableGeometry(this);
|
||||||
|
|
||||||
|
auto point = this->dropdownButton_->mapToGlobal(
|
||||||
|
QPoint(this->dropdownButton_->width() - this->dropdownMenu_.width(),
|
||||||
|
this->dropdownButton_->height()));
|
||||||
|
|
||||||
|
if (point.y() + this->dropdownMenu_.height() > bounds.bottom()) {
|
||||||
|
point.setY(point.y() - this->dropdownMenu_.height() -
|
||||||
|
this->dropdownButton_->height());
|
||||||
|
}
|
||||||
|
|
||||||
|
return point;
|
||||||
|
};
|
||||||
|
|
||||||
|
this->dropdownMenu_.popup(point());
|
||||||
|
this->dropdownMenu_.move(point());
|
||||||
|
this->menuVisible_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
void SplitHeader::updateRoomModes()
|
void SplitHeader::updateRoomModes()
|
||||||
{
|
{
|
||||||
this->modeUpdateRequested_.invoke();
|
this->modeUpdateRequested_.invoke();
|
||||||
|
|
|
@ -54,6 +54,7 @@ private:
|
||||||
void addModeActions(QMenu &menu);
|
void addModeActions(QMenu &menu);
|
||||||
void setupModeLabel(RippleEffectLabel &label);
|
void setupModeLabel(RippleEffectLabel &label);
|
||||||
void addDropdownItems(RippleEffectButton *label);
|
void addDropdownItems(RippleEffectButton *label);
|
||||||
|
void showMenu();
|
||||||
|
|
||||||
Split *const split_;
|
Split *const split_;
|
||||||
|
|
||||||
|
@ -64,15 +65,17 @@ private:
|
||||||
|
|
||||||
pajlada::Signals::Connection onlineStatusChangedConnection_;
|
pajlada::Signals::Connection onlineStatusChangedConnection_;
|
||||||
|
|
||||||
RippleEffectButton *dropdownButton_ = nullptr;
|
RippleEffectButton *dropdownButton_{};
|
||||||
// Label *titleLabel;
|
// Label *titleLabel{};
|
||||||
Label *titleLabel = nullptr;
|
Label *titleLabel{};
|
||||||
RippleEffectLabel *modeButton_ = nullptr;
|
RippleEffectLabel *modeButton_{};
|
||||||
RippleEffectButton *moderationButton_ = nullptr;
|
RippleEffectButton *moderationButton_{};
|
||||||
|
|
||||||
QMenu dropdownMenu_;
|
QMenu dropdownMenu_;
|
||||||
QMenu modeMenu_;
|
QMenu modeMenu_;
|
||||||
|
|
||||||
|
bool menuVisible_{};
|
||||||
|
|
||||||
pajlada::Signals::NoArgSignal modeUpdateRequested_;
|
pajlada::Signals::NoArgSignal modeUpdateRequested_;
|
||||||
|
|
||||||
QString tooltip_;
|
QString tooltip_;
|
||||||
|
|
Loading…
Reference in a new issue