From d33adff5c938605ae50ff6fce635bfa279a3fba4 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sat, 27 Jan 2018 21:13:22 +0100 Subject: [PATCH] fixed emotes popup emotes --- chatterino.pro | 6 ++- src/messages/messageelement.cpp | 3 +- src/singletons/ircmanager.cpp | 6 +-- src/singletons/thememanager.cpp | 25 +++++---- src/twitch/twitchmessagebuilder.cpp | 2 +- src/widgets/basewindow.cpp | 3 -- src/widgets/emotepopup.cpp | 9 +++- src/widgets/helper/channelview.cpp | 15 +++++- src/widgets/helper/channelview.hpp | 3 ++ src/widgets/helper/label.cpp | 78 +++++++++++++++++++++++++++++ src/widgets/helper/label.hpp | 33 ++++++++++++ src/widgets/helper/splitheader.cpp | 5 ++ src/widgets/helper/splitheader.hpp | 2 + src/widgets/split.cpp | 1 - 14 files changed, 163 insertions(+), 28 deletions(-) create mode 100644 src/widgets/helper/label.cpp create mode 100644 src/widgets/helper/label.hpp diff --git a/chatterino.pro b/chatterino.pro index bd0109acc..304086ea3 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -168,7 +168,8 @@ SOURCES += \ src/widgets/settingspages/ignoremessagespage.cpp \ src/widgets/settingspages/specialchannelspage.cpp \ src/widgets/settingspages/keyboardsettingspage.cpp \ - src/widgets/helper/titlebarbutton.cpp + src/widgets/helper/titlebarbutton.cpp \ + src/widgets/helper/label.cpp HEADERS += \ src/precompiled_header.hpp \ @@ -277,7 +278,8 @@ HEADERS += \ src/widgets/settingspages/specialchannelspage.hpp \ src/widgets/settingspages/keyboardsettings.hpp \ src/widgets/settingspages/keyboardsettingspage.hpp \ - src/widgets/helper/titlebarbutton.hpp + src/widgets/helper/titlebarbutton.hpp \ + src/widgets/helper/label.hpp RESOURCES += \ resources/resources.qrc diff --git a/src/messages/messageelement.cpp b/src/messages/messageelement.cpp index 42976eea1..7285d2721 100644 --- a/src/messages/messageelement.cpp +++ b/src/messages/messageelement.cpp @@ -78,7 +78,6 @@ EmoteElement::EmoteElement(const util::EmoteData &_data, MessageElement::Flags f { if (_data.isValid()) { this->setTooltip(data.image1x->getTooltip()); - qDebug() << "valid xDDDDDDDDD" << _data.image1x->getName(); this->textElement = new TextElement(_data.image1x->getName(), MessageElement::Misc); } } @@ -93,7 +92,7 @@ EmoteElement::~EmoteElement() void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) { if (_flags & this->getFlags()) { - if (_flags & this->getFlags() & MessageElement::EmoteImages) { + if (_flags & MessageElement::EmoteImages) { if (!this->data.isValid()) { return; } diff --git a/src/singletons/ircmanager.cpp b/src/singletons/ircmanager.cpp index aa5753cf0..0103d7840 100644 --- a/src/singletons/ircmanager.cpp +++ b/src/singletons/ircmanager.cpp @@ -246,10 +246,10 @@ void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message) return; } - auto xd = message->content(); - auto xd2 = message->toData(); + // auto xd = message->content(); + // auto xd2 = message->toData(); - debug::Log("HEHE: {}", xd2.toStdString()); + // debug::Log("HEHE: {}", xd2.toStdString()); messages::MessageParseArgs args; diff --git a/src/singletons/thememanager.cpp b/src/singletons/thememanager.cpp index c729d04b3..fb9ff0043 100644 --- a/src/singletons/thememanager.cpp +++ b/src/singletons/thememanager.cpp @@ -59,24 +59,23 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier) QColor themeColor = QColor::fromHslF(hue, 0.5, 0.5); QColor themeColorNoSat = QColor::fromHslF(hue, 0, 0.5); - //#ifdef USEWINSDK - // isLightTabs = isLight; - // QColor tabFg = isLight ? "#000" : "#fff"; - // this->windowBg = isLight ? "#fff" : "#444"; - - //#else - isLightTabs = true; - QColor tabFg = isLightTabs ? "#000" : "#fff"; - this->windowBg = "#fff"; - - //#endif - - qreal sat = 0.05; + qreal sat = 0.1; + // 0.05; auto getColor = [multiplier](double h, double s, double l, double a = 1.0) { return QColor::fromHslF(h, s, ((l - 0.5) * multiplier) + 0.5, a); }; + //#ifdef USEWINSDK + // isLightTabs = isLight; + // QColor tabFg = isLight ? "#000" : "#fff"; + // this->windowBg = isLight ? "#fff" : getColor(0, sat, 0.9); + //#else + isLightTabs = true; + QColor tabFg = isLightTabs ? "#000" : "#fff"; + this->windowBg = "#fff"; + //#endif + // Ubuntu style // TODO: add setting for this // TabText = QColor(210, 210, 210); diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index 1c841ac5d..7aea3714b 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -457,7 +457,7 @@ bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString) singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance(); util::EmoteData emoteData; - auto appendEmote = [=](MessageElement::Flags flags) { + auto appendEmote = [&](MessageElement::Flags flags) { this->emplace(emoteData, flags); return true; }; diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index c3853b41c..eb780184d 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -247,7 +247,6 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r switch (msg->message) { case WM_DPICHANGED: { - qDebug() << "dpi changed"; int dpi = HIWORD(msg->wParam); float oldScale = this->scale; @@ -349,8 +348,6 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r } } - qDebug() << *result; - return true; } else { return QWidget::nativeEvent(eventType, message, result); diff --git a/src/widgets/emotepopup.cpp b/src/widgets/emotepopup.cpp index e2aa58256..21c0e47e8 100644 --- a/src/widgets/emotepopup.cpp +++ b/src/widgets/emotepopup.cpp @@ -18,6 +18,11 @@ EmotePopup::EmotePopup(singletons::ThemeManager &themeManager) this->viewEmotes = new ChannelView(); this->viewEmojis = new ChannelView(); + this->viewEmotes->setOverrideFlags((MessageElement::Flags)( + MessageElement::Default | MessageElement::AlwaysShow | MessageElement::EmoteImages)); + this->viewEmojis->setOverrideFlags((MessageElement::Flags)( + MessageElement::Default | MessageElement::AlwaysShow | MessageElement::EmoteImages)); + this->viewEmotes->setEnableScrollingToBottom(false); this->viewEmojis->setEnableScrollingToBottom(false); @@ -62,7 +67,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel) builder2.getMessage()->addFlags(Message::DisableCompactEmotes); map.each([&](const QString &key, const util::EmoteData &value) { - builder2.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow)) // + builder2.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow)) ->setLink(Link(Link::InsertText, key))); }); @@ -101,7 +106,7 @@ void EmotePopup::loadEmojis() builder.getMessage()->addFlags(Message::DisableCompactEmotes); emojis.each([this, &builder](const QString &key, const util::EmoteData &value) { - builder.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow)) // + builder.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow)) ->setLink(Link(Link::Type::InsertText, key))); }); emojiChannel->addMessage(builder.getMessage()); diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 8d7525b2e..da94ac2df 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -291,6 +291,16 @@ bool ChannelView::getEnableScrollingToBottom() const return this->enableScrollingToBottom; } +void ChannelView::setOverrideFlags(boost::optional value) +{ + this->overrideFlags = value; +} + +const boost::optional &ChannelView::getOverrideFlags() const +{ + return this->overrideFlags; +} + messages::LimitedQueueSnapshot ChannelView::getMessagesSnapshot() { if (!this->paused) { @@ -338,7 +348,6 @@ void ChannelView::setChannel(ChannelPtr newChannel) newChannel->messagesAddedAtStart.connect([this](std::vector &messages) { std::vector messageRefs; messageRefs.resize(messages.size()); - qDebug() << messages.size(); for (size_t i = 0; i < messages.size(); i++) { messageRefs.at(i) = MessageLayoutPtr(new MessageLayout(messages.at(i))); } @@ -455,6 +464,10 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem & messages::MessageElement::Flags ChannelView::getFlags() const { + if (this->overrideFlags) { + return this->overrideFlags.get(); + } + MessageElement::Flags flags = singletons::SettingManager::getInstance().getWordFlags(); Split *split = dynamic_cast(this->parentWidget()); diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index 9212e3368..8c794263d 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -38,6 +38,8 @@ public: void clearSelection(); void setEnableScrollingToBottom(bool); bool getEnableScrollingToBottom() const; + void setOverrideFlags(boost::optional value); + const boost::optional &getOverrideFlags() const; void pause(int msecTimeout); void updateLastReadMessage(); @@ -80,6 +82,7 @@ private: bool messageWasAdded = false; bool paused = false; QTimer pauseTimeout; + boost::optional overrideFlags; messages::MessageLayoutPtr lastReadMessage; messages::LimitedQueueSnapshot snapshot; diff --git a/src/widgets/helper/label.cpp b/src/widgets/helper/label.cpp new file mode 100644 index 000000000..a8332d9e4 --- /dev/null +++ b/src/widgets/helper/label.cpp @@ -0,0 +1,78 @@ +#include "label.hpp" +#include "singletons/fontmanager.hpp" + +#include + +namespace chatterino { +namespace widgets { +Label::Label(BaseWidget *parent) + : BaseWidget(parent) +{ + singletons::FontManager::getInstance().fontChanged.connect( + [this]() { this->scaleChangedEvent(this->getScale()); }); +} + +const QString &Label::getText() const +{ + return this->text; +} + +void Label::setText(const QString &value) +{ + this->text = value; + this->scaleChangedEvent(this->getScale()); +} + +FontStyle Label::getFontStyle() const +{ + return this->fontStyle; +} + +void Label::setFontStyle(FontStyle style) +{ + this->fontStyle = style; + this->scaleChangedEvent(this->getScale()); +} + +void Label::scaleChangedEvent(float scale) +{ + QFontMetrics metrics = + singletons::FontManager::getInstance().getFontMetrics(this->fontStyle, scale); + + this->preferedSize = QSize(metrics.width(this->text), metrics.height()); + + this->updateGeometry(); +} + +QSize Label::sizeHint() const +{ + return this->preferedSize; +} + +QSize Label::minimumSizeHint() const +{ + return this->preferedSize; +} + +void Label::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setFont(singletons::FontManager::getInstance().getFont( + this->fontStyle, this->getScale() / painter.device()->devicePixelRatioF())); + + int width = singletons::FontManager::getInstance() + .getFontMetrics(this->fontStyle, this->getScale()) + .width(this->text); + + int flags = Qt::TextSingleLine; + + if (this->width() < width) { + flags |= Qt::AlignLeft | Qt::AlignVCenter; + } else { + flags |= Qt::AlignCenter; + } + + painter.drawText(this->rect(), flags, this->text); +} +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/helper/label.hpp b/src/widgets/helper/label.hpp new file mode 100644 index 000000000..ea3b3b604 --- /dev/null +++ b/src/widgets/helper/label.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "singletons/fontmanager.hpp" +#include "widgets/basewidget.hpp" + +namespace chatterino { +namespace widgets { + +class Label : public BaseWidget +{ +public: + Label(BaseWidget *parent); + + const QString &getText() const; + void setText(const QString &text); + + FontStyle getFontStyle() const; + void setFontStyle(FontStyle style); + +protected: + virtual void scaleChangedEvent(float scale) override; + virtual void paintEvent(QPaintEvent *event) override; + + virtual QSize sizeHint() const override; + virtual QSize minimumSizeHint() const override; + +private: + QSize preferedSize; + QString text; + FontStyle fontStyle = FontStyle::Medium; +}; +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index 1750331f0..b6f9b885f 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -4,6 +4,7 @@ #include "twitch/twitchchannel.hpp" #include "util/layoutcreator.hpp" #include "util/urlfetch.hpp" +#include "widgets/helper/label.hpp" #include "widgets/split.hpp" #include "widgets/splitcontainer.hpp" #include "widgets/tooltipwidget.hpp" @@ -47,7 +48,9 @@ SplitHeader::SplitHeader(Split *_split) layout->addStretch(1); // channel name label + // auto title = layout.emplace