refactor: buttons and friends (#6102)

This commit is contained in:
nerix
2025-05-25 11:17:06 +02:00
committed by GitHub
parent deed1061b5
commit 84c0b39fde
49 changed files with 1083 additions and 691 deletions
+13 -10
View File
@@ -20,9 +20,10 @@
#include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp"
#include "util/LayoutHelper.hpp"
#include "widgets/buttons/LabelButton.hpp"
#include "widgets/buttons/PixmapButton.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/helper/CommonTexts.hpp"
#include "widgets/helper/EffectLabel.hpp"
#include "widgets/Label.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp"
@@ -296,13 +297,13 @@ void SplitHeader::initializeLayout()
w->setScaleIndependentSize(8, 4);
}),
// mode
this->modeButton_ = makeWidget<EffectLabel>([&](auto w) {
this->modeButton_ = makeWidget<LabelButton>([&](auto w) {
w->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
w->hide();
w->setMenu(this->createChatModeMenu());
}),
// moderator
this->moderationButton_ = makeWidget<Button>([&](auto w) {
this->moderationButton_ = makeWidget<PixmapButton>([&](auto w) {
QObject::connect(
w, &Button::clicked, this,
[this, w](Qt::MouseButton button) mutable {
@@ -323,7 +324,9 @@ void SplitHeader::initializeLayout()
this->split_->setModerationMode(
!moderationMode);
w->setDim(Button::Dim(moderationMode));
w->setDim(moderationMode
? DimButton::Dim::Some
: DimButton::Dim::None);
}
break;
@@ -337,22 +340,22 @@ void SplitHeader::initializeLayout()
});
}),
// chatter list
this->chattersButton_ = makeWidget<Button>([&](auto w) {
this->chattersButton_ = makeWidget<PixmapButton>([&](auto w) {
QObject::connect(w, &Button::leftClicked, this, [this]() {
this->split_->showChatterList();
});
}),
// dropdown
this->dropdownButton_ = makeWidget<Button>([&](auto w) {
this->dropdownButton_ = makeWidget<PixmapButton>([&](auto w) {
/// XXX: this never gets disconnected
QObject::connect(w, &Button::leftMousePress, this, [this] {
this->dropdownButton_->setMenu(this->createMainMenu());
});
}),
// add split
this->addButton_ = makeWidget<Button>([&](auto w) {
this->addButton_ = makeWidget<PixmapButton>([&](auto w) {
w->setPixmap(getResources().buttons.addSplitDark);
w->setEnableMargin(false);
w->setMarginEnabled(false);
QObject::connect(w, &Button::leftClicked, this, [this]() {
this->split_->addSibling();
@@ -725,7 +728,7 @@ void SplitHeader::updateRoomModes()
if (auto *twitchChannel =
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get()))
{
this->modeButton_->setEnable(twitchChannel->hasModRights());
this->modeButton_->setEnabled(twitchChannel->hasModRights());
QString text;
{
@@ -746,7 +749,7 @@ void SplitHeader::updateRoomModes()
if (!text.isEmpty())
{
this->modeButton_->getLabel().setText(text);
this->modeButton_->setText(text);
this->modeButton_->show();
}
else
+7 -8
View File
@@ -16,8 +16,8 @@
namespace chatterino {
class Button;
class EffectLabel;
class PixmapButton;
class LabelButton;
class Label;
class Split;
@@ -54,7 +54,6 @@ protected:
private:
void initializeLayout();
void initializeModeSignals(EffectLabel &label);
std::unique_ptr<QMenu> createMainMenu();
std::unique_ptr<QMenu> createChatModeMenu();
@@ -76,19 +75,19 @@ private:
std::chrono::steady_clock::time_point lastReloadedSubEmotes_;
// ui
Button *dropdownButton_{};
PixmapButton *dropdownButton_{};
Label *titleLabel_{};
EffectLabel *modeButton_{};
LabelButton *modeButton_{};
QAction *modeActionSetEmote{};
QAction *modeActionSetSub{};
QAction *modeActionSetSlow{};
QAction *modeActionSetR9k{};
QAction *modeActionSetFollowers{};
Button *moderationButton_{};
Button *chattersButton_{};
Button *addButton_{};
PixmapButton *moderationButton_{};
PixmapButton *chattersButton_{};
PixmapButton *addButton_{};
// states
QPoint dragStart_{};
+25 -33
View File
@@ -10,13 +10,15 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "util/Helpers.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/buttons/LabelButton.hpp"
#include "widgets/buttons/SvgButton.hpp"
#include "widgets/dialogs/EmotePopup.hpp"
#include "widgets/helper/ChannelView.hpp"
#include "widgets/helper/EffectLabel.hpp"
#include "widgets/helper/MessageView.hpp"
#include "widgets/helper/ResizingTextEdit.hpp"
#include "widgets/Notebook.hpp"
@@ -112,8 +114,14 @@ void SplitInput::initLayout()
replyHbox->addStretch(1);
auto replyCancelButton =
replyHbox.emplace<Button>().assign(&this->ui_.cancelReplyButton);
auto replyCancelButton = replyHbox
.emplace<SvgButton>(
SvgButton::Src{
.dark = ":/buttons/cancel.svg",
.light = ":/buttons/cancelDark.svg",
},
nullptr, QSize{4, 0})
.assign(&this->ui_.cancelReplyButton);
replyCancelButton->hide();
replyLabel->hide();
@@ -133,11 +141,10 @@ void SplitInput::initLayout()
connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this,
&SplitInput::editTextChanged);
hboxLayout.emplace<EffectLabel>().assign(&this->ui_.sendButton);
this->ui_.sendButton->getLabel().setText("SEND");
hboxLayout.emplace<LabelButton>("SEND").assign(&this->ui_.sendButton);
this->ui_.sendButton->hide();
QObject::connect(this->ui_.sendButton, &EffectLabel::leftClicked, [this] {
QObject::connect(this->ui_.sendButton, &Button::leftClicked, [this] {
std::vector<QString> arguments;
this->handleSendMessage(arguments);
});
@@ -164,7 +171,13 @@ void SplitInput::initLayout()
textEditLength->setAlignment(Qt::AlignRight);
box->addStretch(1);
box.emplace<Button>().assign(&this->ui_.emoteButton);
box.emplace<SvgButton>(
SvgButton::Src{
.dark = ":/buttons/emote.svg",
.light = ":/buttons/emoteDark.svg",
},
nullptr, QSize{6, 3})
.assign(&this->ui_.emoteButton);
}
// ---- misc
@@ -186,15 +199,14 @@ void SplitInput::initLayout()
});
// open emote popup
QObject::connect(this->ui_.emoteButton, &EffectLabel::leftClicked, [this] {
QObject::connect(this->ui_.emoteButton, &Button::leftClicked, [this] {
this->openEmotePopup();
});
// remove reply target
QObject::connect(this->ui_.cancelReplyButton, &EffectLabel::leftClicked,
[this] {
this->setReply(nullptr);
});
// clear input and remove reply thread
QObject::connect(this->ui_.cancelReplyButton, &Button::leftClicked, [this] {
this->setReply(nullptr);
});
// Forward selection change signal
QObject::connect(this->ui_.textEdit, &QTextEdit::copyAvailable,
@@ -256,8 +268,6 @@ void SplitInput::themeChangedEvent()
QPalette::PlaceholderText,
this->theme->messages.textColors.chatPlaceholder);
this->updateEmoteButton();
this->updateCancelReplyButton();
this->ui_.textEditLength->setPalette(palette);
this->ui_.textEdit->setStyleSheet(this->theme->splits.input.styleSheet);
@@ -284,15 +294,6 @@ void SplitInput::updateEmoteButton()
{
auto scale = this->scale();
if (this->theme->isLightTheme())
{
this->ui_.emoteButton->setSvgResource(":/buttons/emoteDark.svg");
}
else
{
this->ui_.emoteButton->setSvgResource(":/buttons/emote.svg");
}
this->ui_.emoteButton->setFixedHeight(int(18 * scale));
// Make button slightly wider so it's easier to click
this->ui_.emoteButton->setFixedWidth(int(24 * scale));
@@ -302,15 +303,6 @@ void SplitInput::updateCancelReplyButton()
{
float scale = this->scale();
if (this->theme->isLightTheme())
{
this->ui_.cancelReplyButton->setSvgResource(":/buttons/cancelDark.svg");
}
else
{
this->ui_.cancelReplyButton->setSvgResource(":/buttons/cancel.svg");
}
this->ui_.cancelReplyButton->setEnableMargin(false);
this->ui_.cancelReplyButton->setFixedHeight(int(12 * scale));
this->ui_.cancelReplyButton->setFixedWidth(int(20 * scale));
}
+5 -5
View File
@@ -2,7 +2,6 @@
#include "messages/Message.hpp"
#include "widgets/BaseWidget.hpp"
#include "widgets/helper/Button.hpp"
#include <QHBoxLayout>
#include <QLabel>
@@ -20,10 +19,11 @@ namespace chatterino {
class Split;
class EmotePopup;
class InputCompletionPopup;
class EffectLabel;
class MessageView;
class LabelButton;
class ResizingTextEdit;
class ChannelView;
class SvgButton;
enum class CompletionKind;
class SplitInput : public BaseWidget
@@ -144,15 +144,15 @@ protected:
QHBoxLayout *replyHbox;
MessageView *replyMessage;
QLabel *replyLabel;
Button *cancelReplyButton;
SvgButton *cancelReplyButton;
// input widgets
QWidget *inputWrapper;
QHBoxLayout *inputHbox;
ResizingTextEdit *textEdit;
QLabel *textEditLength;
EffectLabel *sendButton;
Button *emoteButton;
LabelButton *sendButton;
SvgButton *emoteButton;
} ui_;
MessagePtr replyTarget_ = nullptr;