Merge remote-tracking branch 'main_repo/master' into git_is_pepega

This commit is contained in:
Mm2PL
2020-04-18 13:39:01 +02:00
155 changed files with 3182 additions and 2037 deletions
-1
View File
@@ -154,7 +154,6 @@ void Button::fancyPaint(QPainter &painter)
return;
}
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.setRenderHint(QPainter::Antialiasing);
QColor c;
+101 -8
View File
@@ -6,6 +6,7 @@
#include <QGraphicsBlurEffect>
#include <QMessageBox>
#include <QPainter>
#include <QScreen>
#include <algorithm>
#include <chrono>
#include <cmath>
@@ -15,6 +16,7 @@
#include "Application.hpp"
#include "common/Common.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandController.hpp"
#include "debug/Benchmark.hpp"
#include "messages/Emote.hpp"
#include "messages/LimitedQueueSnapshot.hpp"
@@ -24,6 +26,7 @@
#include "messages/layouts/MessageLayoutElement.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Resources.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "singletons/TooltipPreviewImage.hpp"
@@ -113,6 +116,10 @@ ChannelView::ChannelView(BaseWidget *parent)
this->initializeScrollbar();
this->initializeSignals();
this->cursors_.neutral = QCursor(getResources().scrolling.neutralScroll);
this->cursors_.up = QCursor(getResources().scrolling.upScroll);
this->cursors_.down = QCursor(getResources().scrolling.downScroll);
this->pauseTimer_.setSingleShot(true);
QObject::connect(&this->pauseTimer_, &QTimer::timeout, this, [this] {
/// remove elements that are finite
@@ -130,6 +137,10 @@ ChannelView::ChannelView(BaseWidget *parent)
this->clickTimer_->setSingleShot(true);
this->clickTimer_->setInterval(500);
this->scrollTimer_.setInterval(20);
QObject::connect(&this->scrollTimer_, &QTimer::timeout, this,
&ChannelView::scrollUpdateRequested);
this->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
}
@@ -1059,8 +1070,13 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
return;
}
if (this->isScrolling_)
{
this->currentMousePosition_ = event->screenPos();
}
// is selecting
if (this->isMouseDown_)
if (this->isLeftMouseDown_)
{
// this->pause(PauseReason::Selecting, 300);
int index = layout->getSelectionIndex(relativePos);
@@ -1325,8 +1341,11 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
switch (event->button())
{
case Qt::LeftButton: {
this->lastPressPosition_ = event->screenPos();
this->isMouseDown_ = true;
if (this->isScrolling_)
this->disableScrolling();
this->lastLeftPressPosition_ = event->screenPos();
this->isLeftMouseDown_ = true;
if (layout->flags.has(MessageLayoutFlag::Collapsed))
return;
@@ -1343,11 +1362,22 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
break;
case Qt::RightButton: {
if (this->isScrolling_)
this->disableScrolling();
this->lastRightPressPosition_ = event->screenPos();
this->isRightMouseDown_ = true;
}
break;
case Qt::MiddleButton: {
if (this->isScrolling_)
this->disableScrolling();
else
this->enableScrolling(event->screenPos());
}
break;
default:;
}
@@ -1372,11 +1402,11 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
return;
}
}
else if (this->isMouseDown_)
else if (this->isLeftMouseDown_)
{
this->isMouseDown_ = false;
this->isLeftMouseDown_ = false;
if (fabsf(distanceBetweenPoints(this->lastPressPosition_,
if (fabsf(distanceBetweenPoints(this->lastLeftPressPosition_,
event->screenPos())) > 15.f)
{
return;
@@ -1404,6 +1434,13 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
return;
}
}
else if (event->button() == Qt::MiddleButton)
{
if (event->screenPos() == this->lastMiddlePressPosition_)
this->enableScrolling(event->screenPos());
else
this->disableScrolling();
}
else
{
// not left or right button
@@ -1637,7 +1674,7 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
return;
}
if (!this->isMouseDown_)
if (!this->isLeftMouseDown_)
{
this->isDoubleClick_ = true;
@@ -1701,7 +1738,6 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
case Link::UserInfo: {
auto user = link.value;
this->showUserInfoPopup(user);
qDebug() << "Clicked " << user << "s message";
}
break;
@@ -1721,6 +1757,8 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
.replace("{msg-id}", layout->getMessage()->id)
.replace("{message}", layout->getMessage()->messageText);
value =
getApp()->commands->execCommand(value, this->channel_, false);
this->channel_->sendMessage(value);
}
break;
@@ -1801,4 +1839,59 @@ void ChannelView::getWordBounds(MessageLayout *layout,
wordEnd = wordStart + length;
}
void ChannelView::enableScrolling(const QPointF &scrollStart)
{
this->isScrolling_ = true;
this->lastMiddlePressPosition_ = scrollStart;
// The line below prevents a sudden jerk at the beginning
this->currentMousePosition_ = scrollStart;
this->scrollTimer_.start();
if (!QGuiApplication::overrideCursor())
QGuiApplication::setOverrideCursor(this->cursors_.neutral);
}
void ChannelView::disableScrolling()
{
this->isScrolling_ = false;
this->scrollTimer_.stop();
QGuiApplication::restoreOverrideCursor();
}
void ChannelView::scrollUpdateRequested()
{
const qreal dpi =
QGuiApplication::screenAt(this->pos())->devicePixelRatio();
const qreal delta = dpi * (this->currentMousePosition_.y() -
this->lastMiddlePressPosition_.y());
const int cursorHeight = this->cursors_.neutral.pixmap().height();
if (fabs(delta) <= cursorHeight * dpi)
{
/*
* If within an area close to the initial position, don't do any
* scrolling at all.
*/
QGuiApplication::changeOverrideCursor(this->cursors_.neutral);
return;
}
qreal offset;
if (delta > 0)
{
QGuiApplication::changeOverrideCursor(this->cursors_.down);
offset = delta - cursorHeight;
}
else
{
QGuiApplication::changeOverrideCursor(this->cursors_.up);
offset = delta + cursorHeight;
}
// "Good" feeling multiplier found by trial-and-error
const qreal multiplier = qreal(0.02);
this->scrollBar_->offset(multiplier * offset);
}
} // namespace chatterino
+18 -9
View File
@@ -148,6 +148,9 @@ private:
void updatePauses();
void unpaused();
void enableScrolling(const QPointF &scrollStart);
void disableScrolling();
QTimer *layoutCooldown_;
bool layoutQueued_;
@@ -183,27 +186,31 @@ private:
bool onlyUpdateEmotes_ = false;
// Mouse event variables
bool isMouseDown_ = false;
bool isLeftMouseDown_ = false;
bool isRightMouseDown_ = false;
bool isDoubleClick_ = false;
DoubleClickSelection doubleClickSelection_;
QPointF lastPressPosition_;
QPointF lastLeftPressPosition_;
QPointF lastRightPressPosition_;
QPointF lastDClickPosition_;
QTimer *clickTimer_;
bool isScrolling_ = false;
QPointF lastMiddlePressPosition_;
QPointF currentMousePosition_;
QTimer scrollTimer_;
struct {
QCursor neutral;
QCursor up;
QCursor down;
} cursors_;
Selection selection_;
bool selecting_ = false;
LimitedQueue<MessageLayoutPtr> messages_;
pajlada::Signals::Connection messageAppendedConnection_;
pajlada::Signals::Connection messageAddedAtStartConnection_;
pajlada::Signals::Connection messageRemovedConnection_;
pajlada::Signals::Connection messageReplacedConnection_;
pajlada::Signals::Connection repaintGifsConnection_;
pajlada::Signals::Connection layoutConnection_;
std::vector<pajlada::Signals::ScopedConnection> connections_;
std::vector<pajlada::Signals::ScopedConnection> channelConnections_;
@@ -218,6 +225,8 @@ private slots:
queueLayout();
update();
}
void scrollUpdateRequested();
};
} // namespace chatterino
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#define OPEN_IN_BROWSER "Open in browser"
#define OPEN_PLAYER_IN_BROWSER "Open in player in browser"
#define OPEN_PLAYER_IN_BROWSER "Open player in browser"
#define OPEN_IN_STREAMLINK "Open in streamlink"
#define DONT_OPEN "Don't open"
+16 -8
View File
@@ -15,9 +15,12 @@ EditableModelView::EditableModelView(QAbstractTableModel *model)
{
this->model_->setParent(this);
this->tableView_->setModel(model);
this->tableView_->setSelectionMode(QAbstractItemView::ExtendedSelection);
this->tableView_->setSelectionMode(QAbstractItemView::SingleSelection);
this->tableView_->setSelectionBehavior(QAbstractItemView::SelectRows);
this->tableView_->verticalHeader()->hide();
this->tableView_->setDragDropMode(QTableView::DragDropMode::InternalMove);
this->tableView_->setDragDropOverwriteMode(false);
this->tableView_->setDefaultDropAction(Qt::DropAction::MoveAction);
this->tableView_->verticalHeader()->setVisible(false);
// create layout
QVBoxLayout *vbox = new QVBoxLayout(this);
@@ -38,12 +41,17 @@ EditableModelView::EditableModelView(QAbstractTableModel *model)
QPushButton *remove = new QPushButton("Remove");
buttons->addWidget(remove);
QObject::connect(remove, &QPushButton::clicked, [this] {
QModelIndexList list;
while ((list = this->getTableView()->selectionModel()->selectedRows(0))
.length() > 0)
{
model_->removeRow(list[0].row());
}
auto selected = this->getTableView()->selectionModel()->selectedRows(0);
// Remove rows backwards so indices don't shift.
std::vector<int> rows;
for (auto &&index : selected)
rows.push_back(index.row());
std::sort(rows.begin(), rows.end(), std::greater{});
for (auto &&row : rows)
model_->removeRow(row);
});
buttons->addStretch();
+9 -11
View File
@@ -91,7 +91,6 @@ void NotebookButton::paintEvent(QPaintEvent *event)
case User: {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = w / 8;
QPainterPath path;
@@ -99,19 +98,18 @@ void NotebookButton::paintEvent(QPaintEvent *event)
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
QPainterPath remove;
remove.addEllipse(2 * a, 1 * a, 4 * a, 4 * a);
path = path.subtracted(remove);
path.addEllipse(2.5 * a, 1.5 * a, 3 * a, 3 * a);
painter.fillPath(path, foreground);
painter.setBrush(background);
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
painter.setBrush(foreground);
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
}
break;
case Settings: {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = w / 8;
QPainterPath path;
@@ -126,10 +124,10 @@ void NotebookButton::paintEvent(QPaintEvent *event)
i * (360 / 8.0) + (360 / 32.0), (360 / 32.0));
}
painter.fillPath(path, foreground);
QPainterPath remove;
remove.addEllipse(3 * a, 3 * a, 2 * a, 2 * a);
painter.setBrush(background);
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
painter.fillPath(path.subtracted(remove), foreground);
}
break;
+7 -1
View File
@@ -13,9 +13,10 @@ ScrollbarHighlight::ScrollbarHighlight()
}
ScrollbarHighlight::ScrollbarHighlight(const std::shared_ptr<QColor> color,
Style style)
Style style, bool isRedeemedHighlight)
: color_(color)
, style_(style)
, isRedeemedHighlight_(isRedeemedHighlight)
{
}
@@ -29,6 +30,11 @@ ScrollbarHighlight::Style ScrollbarHighlight::getStyle() const
return this->style_;
}
bool ScrollbarHighlight::isRedeemedHighlight() const
{
return this->isRedeemedHighlight_;
}
bool ScrollbarHighlight::isNull() const
{
return this->style_ == None;
+3 -1
View File
@@ -17,15 +17,17 @@ public:
ScrollbarHighlight();
ScrollbarHighlight(const std::shared_ptr<QColor> color,
Style style = Default);
Style style = Default, bool isRedeemedHighlight = false);
QColor getColor() const;
Style getStyle() const;
bool isRedeemedHighlight() const;
bool isNull() const;
private:
std::shared_ptr<QColor> color_;
Style style_;
bool isRedeemedHighlight_;
};
} // namespace chatterino
+23 -4
View File
@@ -8,12 +8,16 @@
namespace chatterino {
SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog,
SettingsPage *_page, QString imageFileName)
std::function<SettingsPage *()> _lazyPage,
const QString &name, QString imageFileName,
SettingsTabId id)
: BaseWidget(_dialog)
, dialog_(_dialog)
, page_(_page)
, lazyPage_(std::move(_lazyPage))
, id_(id)
, name_(name)
{
this->ui_.labelText = page_->getName();
this->ui_.labelText = name;
this->ui_.icon.addFile(imageFileName);
this->setCursor(QCursor(Qt::PointingHandCursor));
@@ -34,8 +38,13 @@ void SettingsDialogTab::setSelected(bool _selected)
emit selectedChanged(selected_);
}
SettingsPage *SettingsDialogTab::getSettingsPage()
SettingsPage *SettingsDialogTab::page()
{
if (this->page_)
return this->page_;
this->page_ = this->lazyPage_();
this->page_->setTab(this);
return this->page_;
}
@@ -72,4 +81,14 @@ void SettingsDialogTab::mousePressEvent(QMouseEvent *event)
this->setFocus();
}
const QString &SettingsDialogTab::name() const
{
return name_;
}
SettingsTabId SettingsDialogTab::id() const
{
return id_;
}
} // namespace chatterino
+20 -5
View File
@@ -5,22 +5,34 @@
#include <QIcon>
#include <QPaintEvent>
#include <QWidget>
#include <functional>
namespace chatterino {
class SettingsPage;
class SettingsDialog;
enum SettingsTabId {
None,
Accounts,
Moderation,
};
class SettingsDialogTab : public BaseWidget
{
Q_OBJECT
public:
SettingsDialogTab(SettingsDialog *dialog_, SettingsPage *page_,
QString imageFileName);
SettingsDialogTab(SettingsDialog *dialog_,
std::function<SettingsPage *()> page_,
const QString &name, QString imageFileName,
SettingsTabId id);
void setSelected(bool selected_);
SettingsPage *getSettingsPage();
SettingsPage *page();
SettingsTabId id() const;
const QString &name() const;
signals:
void selectedChanged(bool);
@@ -35,8 +47,11 @@ private:
} ui_;
// Parent settings dialog
SettingsDialog *dialog_;
SettingsPage *page_;
SettingsDialog *dialog_{};
SettingsPage *page_{};
std::function<SettingsPage *()> lazyPage_;
SettingsTabId id_;
QString name_;
bool selected_ = false;
};
-2
View File
@@ -67,7 +67,6 @@ void TitleBarButton::paintEvent(QPaintEvent *event)
color = "#999";
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = xD / 3;
QPainterPath path;
@@ -92,7 +91,6 @@ void TitleBarButton::paintEvent(QPaintEvent *event)
case TitleBarButtonStyle::Settings: {
color = "#999";
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.save();
painter.translate(3, 3);