modified buttons a bit

This commit is contained in:
fourtf 2017-09-15 17:23:49 +02:00
parent 4ac811f2a9
commit 84c23a5d00
15 changed files with 193 additions and 222 deletions

View file

@ -96,7 +96,8 @@ SOURCES += \
src/widgets/resizingtextedit.cpp \
src/completionmanager.cpp \
src/widgets/logindialog.cpp \
src/widgets/qualitypopup.cpp
src/widgets/qualitypopup.cpp \
src/widgets/emotepopup.cpp
HEADERS += \
src/asyncexec.hpp \
@ -157,7 +158,8 @@ HEADERS += \
src/util/distancebetweenpoints.hpp \
src/widgets/basewidget.hpp \
src/completionmanager.hpp \
src/widgets/qualitypopup.h
src/widgets/qualitypopup.h \
src/widgets/emotepopup.h
PRECOMPILED_HEADER =

View file

@ -111,7 +111,7 @@ void ColorScheme::setColors(double hue, double multiplier)
ScrollbarBG = ChatBackground;
ScrollbarThumb = getColor(0, 0.1, 0.85);
ScrollbarThumbSelected = getColor(0, 0.1, 0.7);
ScrollbarArrow = getColor(0, 0.1, 0.4);
ScrollbarArrow = getColor(0, 0.1, 0.9);
// stylesheet
InputStyleSheet = "background:" + ChatInputBackground.name() + ";" +

View file

@ -81,6 +81,18 @@ public:
this->data.insert(name, value);
}
void each(std::function<void(const TKey &name, const TValue &value)> &func) const
{
QMutexLocker lock(this->mutex.get());
QMapIterator<TKey, TValue> it(this->data);
while (it.hasNext()) {
it.next();
func(it.key(), it.value());
}
}
private:
mutable std::unique_ptr<QMutex> mutex;
QMap<TKey, TValue> data;

View file

@ -4,8 +4,8 @@
#include "notebookpage.hpp"
#include "settingsmanager.hpp"
#include "util/urlfetch.hpp"
#include "widgets/textinputdialog.hpp"
#include "widgets/qualitypopup.h"
#include "widgets/textinputdialog.hpp"
#include <QApplication>
#include <QClipboard>
@ -100,9 +100,7 @@ std::shared_ptr<Channel> &ChatWidget::getChannelRef()
void ChatWidget::setChannel(std::shared_ptr<Channel> _newChannel)
{
this->channel = _newChannel;
this->channel->roomIDchanged.connect([this](){
this->header.checkLive();
});
this->channel->roomIDchanged.connect([this]() { this->header.checkLive(); });
this->view.userPopupWidget.setChannel(_newChannel);
@ -131,7 +129,7 @@ void ChatWidget::setChannel(std::shared_ptr<Channel> _newChannel)
auto snapshot = this->channel->getMessageSnapshot();
for (int i = 0; i < snapshot.getLength(); i++) {
for (size_t i = 0; i < snapshot.getLength(); i++) {
SharedMessageRef deleted;
auto messageRef = new MessageRef(snapshot[i]);
@ -270,8 +268,7 @@ void ChatWidget::doChangeChannel()
{
this->showChangeChannelPopup("Change channel");
auto popup = this->findChildren<QDockWidget *>();
if(popup.at(0)->isVisible() && !popup.at(0)->isFloating())
{
if (popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
popup.at(0)->hide();
doOpenViewerList();
}
@ -310,7 +307,8 @@ void ChatWidget::doOpenPopupPlayer()
void ChatWidget::doOpenStreamlink()
{
SettingsManager &settings = SettingsManager::getInstance();
QString preferredQuality = QString::fromStdString(settings.preferredQuality.getValue()).toLower();
QString preferredQuality =
QString::fromStdString(settings.preferredQuality.getValue()).toLower();
// TODO(Confuseh): Default streamlink paths
QString path = QString::fromStdString(settings.streamlinkPath.getValue());
QString channel = QString::fromStdString(this->channelName.getValue());
@ -351,7 +349,8 @@ void ChatWidget::doOpenStreamlink()
lastLine = lastLine.trimmed().split('\n').last();
if (lastLine.startsWith("Available streams: ")) {
QStringList options;
QStringList split = lastLine.right(lastLine.length() - 19).split(", ");
QStringList split =
lastLine.right(lastLine.length() - 19).split(", ");
for (int i = split.length() - 1; i >= 0; i--) {
QString option = split.at(i);
@ -377,9 +376,9 @@ void ChatWidget::doOpenViewerList()
auto viewerDock = new QDockWidget("Viewer List", this);
viewerDock->setAllowedAreas(Qt::LeftDockWidgetArea);
viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar |
QDockWidget::DockWidgetClosable |
QDockWidget::DockWidgetFloatable);
viewerDock->resize(0.5*this->width(),this->height() - this->header.height() - this->input.height());
QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
viewerDock->resize(0.5 * this->width(),
this->height() - this->header.height() - this->input.height());
viewerDock->move(0, this->header.height());
auto accountPopup = new AccountPopupWidget(this->channel);
@ -393,20 +392,19 @@ void ChatWidget::doOpenViewerList()
static QStringList labels = {"Moderators", "Staff", "Admins", "Global Moderators", "Viewers"};
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
QList<QListWidgetItem *> labelList;
for(auto &x : labels)
{
for (auto &x : labels) {
auto label = new QListWidgetItem(x);
label->setBackgroundColor(this->colorScheme.ChatHeaderBackground);
labelList.append(label);
}
auto loadingLabel = new QLabel("Loading...");
util::twitch::get("https://tmi.twitch.tv/group/user/" + channel->name + "/chatters",[=](QJsonObject obj){
util::twitch::get(
"https://tmi.twitch.tv/group/user/" + channel->name + "/chatters", [=](QJsonObject obj) {
QJsonObject chattersObj = obj.value("chatters").toObject();
loadingLabel->hide();
for(int i = 0; i < jsonLabels.size(); i++)
{
for (int i = 0; i < jsonLabels.size(); i++) {
chattersList->addItem(labelList.at(i));
foreach (const QJsonValue &v, chattersObj.value(jsonLabels.at(i)).toArray())
chattersList->addItem(v.toString());
@ -416,39 +414,32 @@ void ChatWidget::doOpenViewerList()
searchBar->setPlaceholderText("Search User...");
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
auto query = searchBar->text();
if(!query.isEmpty())
{
if (!query.isEmpty()) {
auto results = chattersList->findItems(query, Qt::MatchStartsWith);
chattersList->hide();
resultList->clear();
for (auto & item : results)
{
for (auto &item : results) {
if (!labels.contains(item->text()))
resultList->addItem(item->text());
}
resultList->show();
}
else
{
} else {
resultList->hide();
chattersList->show();
}
});
QObject::connect(viewerDock,&QDockWidget::topLevelChanged,this,[=](){
viewerDock->setMinimumWidth(300);
});
QObject::connect(viewerDock, &QDockWidget::topLevelChanged, this,
[=]() { viewerDock->setMinimumWidth(300); });
QObject::connect(chattersList, &QListWidget::doubleClicked, this, [=]() {
if(!labels.contains(chattersList->currentItem()->text()))
{
if (!labels.contains(chattersList->currentItem()->text())) {
doOpenAccountPopupWidget(accountPopup, chattersList->currentItem()->text());
}
});
QObject::connect(resultList, &QListWidget::doubleClicked, this, [=]() {
if(!labels.contains(resultList->currentItem()->text()))
{
if (!labels.contains(resultList->currentItem()->text())) {
doOpenAccountPopupWidget(accountPopup, resultList->currentItem()->text());
}
});

View file

@ -1,8 +1,8 @@
#include "widgets/chatwidgetheader.hpp"
#include "colorscheme.hpp"
#include "util/urlfetch.hpp"
#include "widgets/chatwidget.hpp"
#include "widgets/notebookpage.hpp"
#include "util/urlfetch.hpp"
#include <QByteArray>
#include <QDrag>
@ -81,21 +81,17 @@ void ChatWidgetHeader::updateChannelText()
if (channelName.empty()) {
this->channelNameLabel.setText("<no channel>");
} else {
if(this->chatWidget->getChannelRef()->isLive)
{
if (this->chatWidget->getChannelRef()->isLive) {
auto channel = this->chatWidget->getChannelRef();
this->channelNameLabel.setText(QString::fromStdString(channelName) + " (live)");
this->setToolTip("<style>.center { text-align: center; }</style>" \
"<p class = \"center\">" + \
channel->streamStatus + "<br><br>" + \
channel->streamGame + "<br>" \
"Live for " + channel->streamUptime + \
" with " + channel->streamViewerCount + " viewers" \
"</p>"
);
}
else
{
this->setToolTip(
"<style>.center { text-align: center; }</style>"
"<p class = \"center\">" +
channel->streamStatus + "<br><br>" + channel->streamGame + "<br>"
"Live for " +
channel->streamUptime + " with " + channel->streamViewerCount + " viewers"
"</p>");
} else {
this->channelNameLabel.setText(QString::fromStdString(channelName));
this->setToolTip("");
}
@ -161,8 +157,10 @@ void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
void ChatWidgetHeader::leftButtonClicked()
{
QTimer::singleShot(100, [&] {
this->leftMenu.move(this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
this->leftMenu.show();
});
}
void ChatWidgetHeader::rightButtonClicked()
@ -200,21 +198,20 @@ void ChatWidgetHeader::checkLive()
auto channel = this->chatWidget->getChannelRef();
auto id = QString::fromStdString(channel->roomID);
util::twitch::get("https://api.twitch.tv/kraken/streams/" + id, [=](QJsonObject obj) {
if(obj.value("stream").isNull())
{
if (obj.value("stream").isNull()) {
channel->isLive = false;
this->updateChannelText();
}
else
{
} else {
channel->isLive = true;
auto stream = obj.value("stream").toObject();
channel->streamViewerCount = QString::number(stream.value("viewers").toDouble());
channel->streamGame = stream.value("game").toString();
channel->streamStatus = stream.value("channel").toObject().value("status").toString();
QDateTime since = QDateTime::fromString(stream.value("created_at").toString(),Qt::ISODate);
QDateTime since =
QDateTime::fromString(stream.value("created_at").toString(), Qt::ISODate);
auto diff = since.secsTo(QDateTime::currentDateTime());
channel->streamUptime = QString::number(diff/3600) + "h " + QString::number(diff % 3600 / 60) + "m";
channel->streamUptime =
QString::number(diff / 3600) + "h " + QString::number(diff % 3600 / 60) + "m";
this->updateChannelText();
}
});

View file

@ -9,9 +9,7 @@ namespace chatterino {
namespace widgets {
ChatWidgetHeaderButton::ChatWidgetHeaderButton(BaseWidget *parent, int spacing)
: BaseWidget(parent)
, mouseOver(false)
, mouseDown(false)
: FancyButton(parent)
{
setLayout(&this->ui.hbox);
@ -22,76 +20,14 @@ ChatWidgetHeaderButton::ChatWidgetHeaderButton(BaseWidget *parent, int spacing)
this->ui.hbox.addWidget(&this->ui.label);
this->ui.hbox.addSpacing(spacing);
QObject::connect(&this->ui.label, &SignalLabel::mouseUp, this,
&ChatWidgetHeaderButton::labelMouseUp);
QObject::connect(&this->ui.label, &SignalLabel::mouseDown, this,
&ChatWidgetHeaderButton::labelMouseDown);
this->setMouseEffectColor(QColor(255, 255, 255, 63));
}
void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QBrush brush(this->colorScheme.isLightTheme() ? QColor(0, 0, 0, 32)
: QColor(255, 255, 255, 32));
if (mouseDown) {
painter.fillRect(rect(), brush);
}
if (mouseOver) {
painter.fillRect(rect(), brush);
}
}
void ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
mouseDown = true;
update();
}
}
void ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
mouseDown = false;
update();
emit clicked();
}
}
void ChatWidgetHeaderButton::enterEvent(QEvent *)
{
mouseOver = true;
update();
}
void ChatWidgetHeaderButton::leaveEvent(QEvent *)
{
mouseOver = false;
update();
}
void ChatWidgetHeaderButton::labelMouseUp()
{
mouseDown = false;
update();
emit clicked();
}
void ChatWidgetHeaderButton::labelMouseDown()
{
mouseDown = true;
update();
this->fancyPaint(painter);
}
} // namespace widgets

View file

@ -1,6 +1,7 @@
#pragma once
#include "widgets/basewidget.hpp"
#include "widgets/fancybutton.hpp"
#include "widgets/signallabel.hpp"
#include <QHBoxLayout>
@ -16,10 +17,8 @@ namespace widgets {
class ChatWidgetHeader;
class ChatWidgetHeaderButton : public BaseWidget
class ChatWidgetHeaderButton : public FancyButton
{
Q_OBJECT
public:
explicit ChatWidgetHeaderButton(BaseWidget *parent, int spacing = 6);
@ -28,29 +27,14 @@ public:
return this->ui.label;
}
signals:
void clicked();
protected:
virtual void paintEvent(QPaintEvent *) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
private:
struct {
QHBoxLayout hbox;
SignalLabel label;
} ui;
bool mouseOver = false;
bool mouseDown = false;
void labelMouseUp();
void labelMouseDown();
};
} // namespace widgets

View file

@ -9,7 +9,6 @@
#include <QCompleter>
#include <QPainter>
#include <boost/signals2.hpp>
namespace chatterino {
namespace widgets {
@ -23,7 +22,7 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
this->setLayout(&this->hbox);
this->hbox.setMargin(4);
this->hbox.setMargin(0);
this->hbox.addLayout(&this->editContainer);
this->hbox.addLayout(&this->vbox);
@ -31,6 +30,8 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
this->editContainer.addWidget(&this->textInput);
this->editContainer.setMargin(4);
this->emotesLabel.setMinimumHeight(24);
this->vbox.addWidget(&this->textLengthLabel);
this->vbox.addStretch(1);
this->vbox.addWidget(&this->emotesLabel);
@ -43,10 +44,18 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
"<img src=':/images/Emoji_Color_1F60A_19.png' width='12' height='12' "
"/>");
connect(&this->emotesLabel, &ChatWidgetHeaderButton::clicked, [this] {
if (this->emotePopup == nullptr) {
this->emotePopup = new EmotePopup();
}
this->emotePopup->show(); //
});
connect(&textInput, &ResizingTextEdit::textChanged, this, &ChatWidgetInput::editTextChanged);
this->refreshTheme();
this->setMessageLengthVisible(SettingsManager::getInstance().showMessageLength.get());
textLengthLabel.setHidden(!SettingsManager::getInstance().showMessageLength.get());
auto completer = new QCompleter(
this->chatWidget->completionManager.createModel(this->chatWidget->channelName));
@ -148,21 +157,14 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
}
});
/* XXX(pajlada): FIX THIS
QObject::connect(&Settings::getInstance().showMessageLength,
&BoolSetting::valueChanged, this,
&ChatWidgetInput::setMessageLengthVisible);
*/
this->textLengthVisibleChangedConnection =
SettingsManager::getInstance().showMessageLength.valueChanged.connect(
[this](const bool &value) { this->textLengthLabel.setHidden(!value); });
}
ChatWidgetInput::~ChatWidgetInput()
{
/* XXX(pajlada): FIX THIS
QObject::disconnect(
&Settings::getInstance().getShowMessageLength(),
&BoolSetting::valueChanged, this,
&ChatWidgetInput::setMessageLengthVisible);
*/
this->textLengthVisibleChangedConnection.disconnect();
}
void ChatWidgetInput::refreshTheme()

View file

@ -3,6 +3,7 @@
#include "resizingtextedit.hpp"
#include "widgets/basewidget.hpp"
#include "widgets/chatwidgetheaderbutton.hpp"
#include "widgets/emotepopup.h"
#include <QHBoxLayout>
#include <QLabel>
@ -12,6 +13,8 @@
#include <QVBoxLayout>
#include <QWidget>
#include <boost/signals2.hpp>
namespace chatterino {
namespace widgets {
@ -33,7 +36,9 @@ protected:
private:
ChatWidget *const chatWidget;
EmotePopup *emotePopup = nullptr;
boost::signals2::connection textLengthVisibleChangedConnection;
QHBoxLayout hbox;
QVBoxLayout vbox;
QHBoxLayout editContainer;
@ -45,10 +50,6 @@ private:
virtual void refreshTheme() override;
private slots:
void setMessageLengthVisible(bool value)
{
textLengthLabel.setHidden(!value);
}
void editTextChanged();
// void editKeyPressed(QKeyEvent *event);

View file

@ -30,7 +30,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *_chatWidget)
, userPopupWidget(_chatWidget->getChannelRef())
{
#ifndef Q_OS_MAC
this->setAttribute(Qt::WA_OpaquePaintEvent);
// this->setAttribute(Qt::WA_OpaquePaintEvent);
#endif
this->setMouseTracking(true);
@ -70,7 +70,8 @@ bool ChatWidgetView::layoutMessages()
this->showingLatestMessages = this->scrollBar.isAtBottom() || !this->scrollBar.isVisible();
size_t start = this->scrollBar.getCurrentValue();
int layoutWidth = this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width();
int layoutWidth =
(this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4;
// layout the visible messages in the view
if (messages.getLength() > start) {
@ -258,17 +259,17 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
// only update gif emotes
#ifndef Q_OS_MAC
if (this->onlyUpdateEmotes) {
this->onlyUpdateEmotes = false;
// if (this->onlyUpdateEmotes) {
// this->onlyUpdateEmotes = false;
for (const GifEmoteData &item : this->gifEmotes) {
painter.fillRect(item.rect, this->colorScheme.ChatBackground);
// for (const GifEmoteData &item : this->gifEmotes) {
// painter.fillRect(item.rect, this->colorScheme.ChatBackground);
painter.drawPixmap(item.rect, *item.image->getPixmap());
}
// painter.drawPixmap(item.rect, *item.image->getPixmap());
// }
return;
}
// return;
// }
#endif
// update all messages

View file

@ -0,0 +1,18 @@
#include "emotepopup.h"
namespace chatterino {
namespace widgets {
EmotePopup::EmotePopup(QWidget *parent)
: QWidget(parent)
{
}
void EmotePopup::loadChannel(std::shared_ptr<Channel> channel)
{
// channel->bttvChannelEmotes.each([](const QString &key, const EmoteData &value) {
// //
// });
}
}
}

18
src/widgets/emotepopup.h Normal file
View file

@ -0,0 +1,18 @@
#pragma once
#include <QWidget>
#include "channel.hpp"
namespace chatterino {
namespace widgets {
class EmotePopup : public QWidget
{
public:
explicit EmotePopup(QWidget *parent = 0);
void loadChannel(std::shared_ptr<Channel> channel);
};
}
}

View file

@ -86,6 +86,10 @@ void FancyButton::mouseReleaseEvent(QMouseEvent *event)
}
this->mouseDown = false;
if (this->rect().contains(event->pos())) {
emit clicked();
}
}
void FancyButton::mouseMoveEvent(QMouseEvent *event)

View file

@ -13,6 +13,8 @@ namespace widgets {
class FancyButton : public BaseWidget
{
Q_OBJECT
struct ClickEffect {
double progress = 0.0;
QPoint position;
@ -28,6 +30,9 @@ public:
void setMouseEffectColor(QColor color);
signals:
void clicked();
protected:
bool selected = false;
bool mouseOver = false;

View file

@ -212,7 +212,7 @@ void Notebook::resizeEvent(QResizeEvent *)
void Notebook::settingsButtonClicked()
{
SettingsDialog::showDialog();
QTimer::singleShot(100, [this] { SettingsDialog::showDialog(); });
}
void Notebook::usersButtonClicked()
@ -221,7 +221,7 @@ void Notebook::usersButtonClicked()
void Notebook::addPageButtonClicked()
{
addPage(true);
QTimer::singleShot(100, [this] { this->addPage(true); });
}
void Notebook::load(const boost::property_tree::ptree &tree)