Merge branch 'master' into git_is_pepega

This commit is contained in:
Mm2PL
2020-01-01 21:06:29 +01:00
committed by GitHub
174 changed files with 2445 additions and 1112 deletions
+343
View File
@@ -0,0 +1,343 @@
#include "Button.hpp"
#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QPainter>
#include "BaseTheme.hpp"
#include "util/FunctionEventFilter.hpp"
namespace chatterino {
Button::Button(BaseWidget *parent)
: BaseWidget(parent)
{
connect(&effectTimer_, &QTimer::timeout, this,
&Button::onMouseEffectTimeout);
this->effectTimer_.setInterval(20);
this->effectTimer_.start();
this->setMouseTracking(true);
}
void Button::setMouseEffectColor(boost::optional<QColor> color)
{
this->mouseEffectColor_ = color;
}
void Button::setPixmap(const QPixmap &_pixmap)
{
this->pixmap_ = _pixmap;
this->update();
}
const QPixmap &Button::getPixmap() const
{
return this->pixmap_;
}
void Button::setDim(Dim value)
{
this->dimPixmap_ = value;
this->update();
}
Button::Dim Button::getDim() const
{
return this->dimPixmap_;
}
void Button::setEnable(bool value)
{
this->enabled_ = value;
this->update();
}
bool Button::getEnable() const
{
return this->enabled_;
}
void Button::setEnableMargin(bool value)
{
this->enableMargin_ = value;
this->update();
}
bool Button::getEnableMargin() const
{
return this->enableMargin_;
}
qreal Button::getCurrentDimAmount() const
{
if (this->dimPixmap_ == Dim::None || this->mouseOver_)
return 1;
else if (this->dimPixmap_ == Dim::Some)
return 0.7;
else
return 0.15;
}
void Button::setBorderColor(const QColor &color)
{
this->borderColor_ = color;
this->update();
}
const QColor &Button::getBorderColor() const
{
return this->borderColor_;
}
void Button::setMenu(std::unique_ptr<QMenu> menu)
{
this->menu_ = std::move(menu);
this->menu_->installEventFilter(
new FunctionEventFilter(this, [this](QObject *, QEvent *event) {
if (event->type() == QEvent::Hide)
{
QTimer::singleShot(20, this,
[this] { this->menuVisible_ = false; });
}
return false;
}));
}
void Button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
if (!this->pixmap_.isNull())
{
painter.setOpacity(this->getCurrentDimAmount());
QRect rect = this->rect();
int margin = this->height() < 22 * this->scale() ? 3 : 6;
int s = this->enableMargin_ ? int(margin * this->scale()) : 0;
rect.moveLeft(s);
rect.setRight(rect.right() - s - s);
rect.moveTop(s);
rect.setBottom(rect.bottom() - s - s);
painter.drawPixmap(rect, this->pixmap_);
painter.setOpacity(1);
}
this->fancyPaint(painter);
if (this->borderColor_.isValid())
{
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setPen(this->borderColor_);
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
}
}
void Button::fancyPaint(QPainter &painter)
{
if (!this->enabled_)
{
return;
}
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.setRenderHint(QPainter::Antialiasing);
QColor c;
if (this->mouseEffectColor_)
{
c = this->mouseEffectColor_.get();
}
else
{
c = this->theme->isLightTheme() ? QColor(0, 0, 0)
: QColor(255, 255, 255);
}
if (this->hoverMultiplier_ > 0)
{
QRadialGradient gradient(QPointF(mousePos_), this->width() / 2);
gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(),
int(50 * this->hoverMultiplier_)));
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(),
int(40 * this->hoverMultiplier_)));
painter.fillRect(this->rect(), gradient);
}
for (auto effect : this->clickEffects_)
{
QRadialGradient gradient(effect.position.x(), effect.position.y(),
effect.progress * qreal(width()) * 2,
effect.position.x(), effect.position.y());
gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(),
int((1 - effect.progress) * 95)));
gradient.setColorAt(0.9999, QColor(c.red(), c.green(), c.blue(),
int((1 - effect.progress) * 95)));
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), int(0)));
painter.fillRect(this->rect(), gradient);
}
}
void Button::enterEvent(QEvent *)
{
this->mouseOver_ = true;
}
void Button::leaveEvent(QEvent *)
{
this->mouseOver_ = false;
}
void Button::mousePressEvent(QMouseEvent *event)
{
if (!this->enabled_)
{
return;
}
if (event->button() != Qt::LeftButton)
{
return;
}
this->clickEffects_.push_back(ClickEffect(event->pos()));
this->mouseDown_ = true;
emit this->leftMousePress();
if (this->menu_ && !this->menuVisible_)
{
QTimer::singleShot(80, this, [this] { this->showMenu(); });
this->mouseDown_ = false;
this->mouseOver_ = false;
}
}
void Button::mouseReleaseEvent(QMouseEvent *event)
{
if (!this->enabled_)
return;
if (event->button() == Qt::LeftButton)
{
this->mouseDown_ = false;
if (this->rect().contains(event->pos()))
emit leftClicked();
}
emit clicked(event->button());
}
void Button::mouseMoveEvent(QMouseEvent *event)
{
if (this->enabled_)
{
this->mousePos_ = event->pos();
this->update();
}
}
void Button::onMouseEffectTimeout()
{
bool performUpdate = false;
if (selected_)
{
if (this->hoverMultiplier_ != 0)
{
this->hoverMultiplier_ =
std::max(0.0, this->hoverMultiplier_ - 0.1);
performUpdate = true;
}
}
else if (mouseOver_)
{
if (this->hoverMultiplier_ != 1)
{
this->hoverMultiplier_ =
std::min(1.0, this->hoverMultiplier_ + 0.5);
performUpdate = true;
}
}
else
{
if (this->hoverMultiplier_ != 0)
{
this->hoverMultiplier_ =
std::max(0.0, this->hoverMultiplier_ - 0.3);
performUpdate = true;
}
}
if (this->clickEffects_.size() != 0)
{
performUpdate = true;
for (auto it = this->clickEffects_.begin();
it != this->clickEffects_.end();)
{
it->progress += mouseDown_ ? 0.02 : 0.07;
if (it->progress >= 1.0)
{
it = this->clickEffects_.erase(it);
}
else
{
it++;
}
}
}
if (performUpdate)
{
update();
}
}
void Button::showMenu()
{
if (!this->menu_)
return;
auto point = [this] {
auto bounds = QApplication::desktop()->availableGeometry(this);
auto point = this->mapToGlobal(
QPoint(this->width() - this->menu_->width(), this->height()));
if (point.y() + this->menu_->height() > bounds.bottom())
{
point.setY(point.y() - this->menu_->height() - this->height());
}
return point;
};
this->menu_->popup(point());
this->menu_->move(point());
this->menuVisible_ = true;
}
} // namespace chatterino
+91
View File
@@ -0,0 +1,91 @@
#pragma once
#include <boost/optional.hpp>
#include "widgets/BaseWidget.hpp"
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QPoint>
#include <QTimer>
#include <QWidget>
namespace chatterino {
class Button : public BaseWidget
{
Q_OBJECT
struct ClickEffect {
double progress = 0.0;
QPoint position;
ClickEffect(QPoint _position)
: position(_position)
{
}
};
public:
enum class Dim { None, Some, Lots };
Button(BaseWidget *parent = nullptr);
void setMouseEffectColor(boost::optional<QColor> color);
void setPixmap(const QPixmap &pixmap_);
const QPixmap &getPixmap() const;
void setDim(Dim value);
Dim getDim() const;
qreal getCurrentDimAmount() const;
void setEnable(bool value);
bool getEnable() const;
void setEnableMargin(bool value);
bool getEnableMargin() const;
void setBorderColor(const QColor &color);
const QColor &getBorderColor() const;
void setMenu(std::unique_ptr<QMenu> menu);
signals:
void leftClicked();
void clicked(Qt::MouseButton button);
void leftMousePress();
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;
virtual void mouseMoveEvent(QMouseEvent *event) override;
void fancyPaint(QPainter &painter);
bool enabled_{true};
bool selected_{false};
bool mouseOver_{false};
bool mouseDown_{false};
bool menuVisible_{false};
private:
void onMouseEffectTimeout();
void showMenu();
QColor borderColor_{};
QPixmap pixmap_{};
Dim dimPixmap_{Dim::Some};
bool enableMargin_{true};
QPoint mousePos_{};
double hoverMultiplier_{0.0};
QTimer effectTimer_{};
std::vector<ClickEffect> clickEffects_{};
boost::optional<QColor> mouseEffectColor_{};
std::unique_ptr<QMenu> menu_{};
};
} // namespace chatterino
+47 -54
View File
@@ -1,5 +1,17 @@
#include "ChannelView.hpp"
#include <QClipboard>
#include <QDebug>
#include <QDesktopServices>
#include <QGraphicsBlurEffect>
#include <QMessageBox>
#include <QPainter>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <memory>
#include "Application.hpp"
#include "common/Common.hpp"
#include "controllers/accounts/AccountController.hpp"
@@ -25,19 +37,6 @@
#include "widgets/helper/EffectLabel.hpp"
#include "widgets/splits/Split.hpp"
#include <QClipboard>
#include <QDebug>
#include <QDesktopServices>
#include <QGraphicsBlurEffect>
#include <QMessageBox>
#include <QPainter>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <memory>
#define DRAW_WIDTH (this->width())
#define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3
#define CHAT_HOVER_PAUSE_DURATION 1000
@@ -122,7 +121,7 @@ ChannelView::ChannelView(BaseWidget *parent)
for (auto it = this->pauses_.begin(); it != this->pauses_.end();)
it = it->second ? this->pauses_.erase(it) : ++it;
this->updatePauseTimer();
this->updatePauses();
});
auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
@@ -232,7 +231,7 @@ void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs)
this->pauses_[reason] = boost::none;
}
this->updatePauseTimer();
this->updatePauses();
}
void ChannelView::unpause(PauseReason reason)
@@ -240,23 +239,17 @@ void ChannelView::unpause(PauseReason reason)
/// Remove the value from the map
this->pauses_.erase(reason);
this->updatePauseTimer();
/// Move selection
this->selection_.selectionMin.messageIndex -= this->pauseSelectionOffset_;
this->selection_.selectionMax.messageIndex -= this->pauseSelectionOffset_;
this->selection_.start.messageIndex -= this->pauseSelectionOffset_;
this->selection_.end.messageIndex -= this->pauseSelectionOffset_;
this->pauseSelectionOffset_ = 0;
this->updatePauses();
}
void ChannelView::updatePauseTimer()
void ChannelView::updatePauses()
{
using namespace std::chrono;
if (this->pauses_.empty())
{
this->unpaused();
/// No pauses so we can stop the timer
this->pauseEnd_ = boost::none;
this->pauseTimer_.stop();
@@ -292,6 +285,17 @@ void ChannelView::updatePauseTimer()
}
}
void ChannelView::unpaused()
{
/// Move selection
this->selection_.selectionMin.messageIndex -= this->pauseSelectionOffset_;
this->selection_.selectionMax.messageIndex -= this->pauseSelectionOffset_;
this->selection_.start.messageIndex -= this->pauseSelectionOffset_;
this->selection_.end.messageIndex -= this->pauseSelectionOffset_;
this->pauseSelectionOffset_ = 0;
}
void ChannelView::themeChangedEvent()
{
BaseWidget::themeChangedEvent();
@@ -582,6 +586,11 @@ void ChannelView::setChannel(ChannelPtr channel)
this->lastMessageHasAlternateBackground_ =
!this->lastMessageHasAlternateBackground_;
if (channel->shouldIgnoreHighlights())
{
messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights);
}
this->messages_.pushBack(MessageLayoutPtr(messageLayout), deleted);
this->scrollBar_->addHighlight(snapshot[i]->getScrollBarHighlight());
}
@@ -1029,14 +1038,6 @@ void ChannelView::leaveEvent(QEvent *)
void ChannelView::mouseMoveEvent(QMouseEvent *event)
{
if (event->modifiers() & (Qt::AltModifier | Qt::ControlModifier))
{
this->unsetCursor();
event->ignore();
return;
}
/// Pause on hover
if (float pauseTime = getSettings()->pauseOnHoverDuration;
pauseTime > 0.001f)
@@ -1048,7 +1049,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
this->pause(PauseReason::Mouse);
}
auto tooltipWidget = TooltipWidget::getInstance();
auto tooltipWidget = TooltipWidget::instance();
std::shared_ptr<MessageLayout> layout;
QPoint relativePos;
int messageIndex;
@@ -1241,7 +1242,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
}
else
{
auto &tooltipPreviewImage = TooltipPreviewImage::getInstance();
auto &tooltipPreviewImage = TooltipPreviewImage::instance();
auto emoteElement = dynamic_cast<const EmoteElement *>(
&hoverLayoutElement->getCreator());
auto badgeElement = dynamic_cast<const BadgeElement *>(
@@ -1326,8 +1327,7 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
// check if message is collapsed
switch (event->button())
{
case Qt::LeftButton:
{
case Qt::LeftButton: {
this->lastPressPosition_ = event->screenPos();
this->isMouseDown_ = true;
@@ -1345,8 +1345,7 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
}
break;
case Qt::RightButton:
{
case Qt::RightButton: {
this->lastRightPressPosition_ = event->screenPos();
this->isRightMouseDown_ = true;
}
@@ -1464,8 +1463,7 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
{
switch (event->button())
{
case Qt::LeftButton:
{
case Qt::LeftButton: {
if (this->selecting_)
{
// this->pausedBySelection = false;
@@ -1489,8 +1487,7 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
}
}
break;
case Qt::RightButton:
{
case Qt::RightButton: {
auto insertText = [=](QString text) {
if (auto split = dynamic_cast<Split *>(this->parentWidget()))
{
@@ -1501,7 +1498,8 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
auto &link = hoveredElement->getLink();
if (link.type == Link::UserInfo)
{
insertText("@" + link.value + ", ");
const bool commaMention = getSettings()->mentionUsersWithComma;
insertText("@" + link.value + (commaMention ? ", " : " "));
}
else if (link.type == Link::UserWhisper)
{
@@ -1705,16 +1703,14 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
switch (link.type)
{
case Link::UserWhisper:
case Link::UserInfo:
{
case Link::UserInfo: {
auto user = link.value;
this->showUserInfoPopup(user);
qDebug() << "Clicked " << user << "s message";
}
break;
case Link::Url:
{
case Link::Url: {
if (getSettings()->openLinksIncognito && supportsIncognitoLinks())
openLinkIncognito(link.value);
else
@@ -1722,8 +1718,7 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
}
break;
case Link::UserAction:
{
case Link::UserAction: {
QString value = link.value;
value.replace("{user}", layout->getMessage()->loginName)
@@ -1735,14 +1730,12 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
}
break;
case Link::AutoModAllow:
{
case Link::AutoModAllow: {
getApp()->accounts->twitch.getCurrent()->autoModAllow(link.value);
}
break;
case Link::AutoModDeny:
{
case Link::AutoModDeny: {
getApp()->accounts->twitch.getCurrent()->autoModDeny(link.value);
}
+9 -9
View File
@@ -1,22 +1,21 @@
#pragma once
#include "common/FlagsEnum.hpp"
#include "messages/Image.hpp"
#include "messages/LimitedQueue.hpp"
#include "messages/LimitedQueueSnapshot.hpp"
#include "messages/Selection.hpp"
#include "widgets/BaseWidget.hpp"
#include <QPaintEvent>
#include <QScroller>
#include <QTimer>
#include <QWheelEvent>
#include <QWidget>
#include <pajlada/signals/signal.hpp>
#include <unordered_map>
#include <unordered_set>
#include "common/FlagsEnum.hpp"
#include "messages/Image.hpp"
#include "messages/LimitedQueue.hpp"
#include "messages/LimitedQueueSnapshot.hpp"
#include "messages/Selection.hpp"
#include "widgets/BaseWidget.hpp"
namespace chatterino {
enum class HighlightState;
@@ -146,7 +145,8 @@ private:
void addContextMenuItems(const MessageLayoutElement *hoveredElement,
MessageLayout *layout);
int getLayoutWidth() const;
void updatePauseTimer();
void updatePauses();
void unpaused();
QTimer *layoutCooldown_;
bool layoutQueued_;
+43
View File
@@ -0,0 +1,43 @@
#include "widgets/helper/EffectLabel.hpp"
#include <QBrush>
#include <QPainter>
namespace chatterino {
EffectLabel::EffectLabel(BaseWidget *parent, int spacing)
: Button(parent)
, label_(this)
{
setLayout(&this->hbox_);
this->label_.setAlignment(Qt::AlignCenter);
this->hbox_.setMargin(0);
this->hbox_.addSpacing(spacing);
this->hbox_.addWidget(&this->label_);
this->hbox_.addSpacing(spacing);
}
EffectLabel2::EffectLabel2(BaseWidget *parent, int padding)
: Button(parent)
, label_(this)
{
auto *hbox = new QHBoxLayout(this);
this->setLayout(hbox);
// this->label_.setAlignment(Qt::AlignCenter);
this->label_.setCentered(true);
hbox->setMargin(0);
// hbox.addSpacing(spacing);
hbox->addWidget(&this->label_);
// hbox.addSpacing(spacing);
}
Label &EffectLabel2::getLabel()
{
return this->label_;
}
} // namespace chatterino
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include "widgets/BaseWidget.hpp"
#include "widgets/Label.hpp"
#include "widgets/helper/Button.hpp"
#include "widgets/helper/SignalLabel.hpp"
#include <QHBoxLayout>
#include <QLabel>
#include <QPaintEvent>
#include <QWidget>
namespace chatterino {
class EffectLabel : public Button
{
public:
explicit EffectLabel(BaseWidget *parent = nullptr, int spacing = 6);
SignalLabel &getLabel()
{
return this->label_;
}
private:
QHBoxLayout hbox_;
SignalLabel label_;
};
class EffectLabel2 : public Button
{
public:
explicit EffectLabel2(BaseWidget *parent = nullptr, int padding = 6);
Label &getLabel();
private:
Label label_;
};
} // namespace chatterino
+3 -6
View File
@@ -62,8 +62,7 @@ void NotebookButton::paintEvent(QPaintEvent *event)
switch (icon_)
{
case Plus:
{
case Plus: {
painter.setPen([&] {
QColor tmp = foreground;
if (SplitContainer::isDraggingSplit)
@@ -90,8 +89,7 @@ void NotebookButton::paintEvent(QPaintEvent *event)
}
break;
case User:
{
case User: {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
@@ -111,8 +109,7 @@ void NotebookButton::paintEvent(QPaintEvent *event)
}
break;
case Settings:
{
case Settings: {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
+19 -10
View File
@@ -22,6 +22,16 @@
#include <boost/bind.hpp>
namespace chatterino {
namespace {
qreal deviceDpi(QWidget *widget)
{
#ifdef Q_OS_WIN
return widget->devicePixelRatioF();
#else
return 1.0;
#endif
}
} // namespace
NotebookTab::NotebookTab(Notebook *notebook)
: Button(notebook)
@@ -83,11 +93,10 @@ void NotebookTab::themeChangedEvent()
void NotebookTab::updateSize()
{
float scale = this->scale();
int width;
QFontMetrics metrics = getApp()->fonts->getFontMetrics(
FontStyle::UiTabs,
float(qreal(this->scale()) * this->devicePixelRatioF()));
FontStyle::UiTabs, float(qreal(this->scale()) * deviceDpi(this)));
if (this->hasXButton())
{
@@ -276,10 +285,10 @@ void NotebookTab::paintEvent(QPaintEvent *)
painter.setFont(getApp()->fonts->getFont(
FontStyle::UiTabs,
scale * 96.f / this->logicalDpiX() * this->devicePixelRatioF()));
scale * 96.f / this->logicalDpiX() * deviceDpi(this)));
QFontMetrics metrics = app->fonts->getFontMetrics(
FontStyle::UiTabs,
scale * 96.f / this->logicalDpiX() * this->devicePixelRatioF());
scale * 96.f / this->logicalDpiX() * deviceDpi(this));
int height = int(scale * NOTEBOOK_TAB_HEIGHT);
@@ -299,12 +308,12 @@ void NotebookTab::paintEvent(QPaintEvent *)
bool windowFocused = this->window() == QApplication::activeWindow();
QBrush tabBackground = /*this->mouseOver_ ? colors.backgrounds.hover
:*/
:*/
(windowFocused ? colors.backgrounds.regular
: colors.backgrounds.unfocused);
// fill the tab background
auto bgRect = rect();
auto bgRect = this->rect();
bgRect.setTop(ceil((this->selected_ ? 0.f : 1.f) * scale));
painter.fillRect(bgRect, tabBackground);
@@ -432,8 +441,7 @@ void NotebookTab::mousePressEvent(QMouseEvent *event)
{
switch (event->button())
{
case Qt::RightButton:
{
case Qt::RightButton: {
this->menu_.popup(event->globalPos());
}
break;
@@ -458,7 +466,8 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
}
};
if (event->button() == Qt::MiddleButton)
if (event->button() == Qt::MiddleButton &&
this->notebook_->getAllowUserTabManagement())
{
if (this->rect().contains(event->pos()))
{
-11
View File
@@ -73,17 +73,6 @@ void SearchPopup::search()
this->channelName_, this->snapshot_));
}
void SearchPopup::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Escape)
{
this->close();
return;
}
BaseWidget::keyPressEvent(e);
}
void SearchPopup::initLayout()
{
// VBOX
+2 -4
View File
@@ -3,7 +3,7 @@
#include "ForwardDecl.hpp"
#include "messages/LimitedQueueSnapshot.hpp"
#include "messages/search/MessagePredicate.hpp"
#include "widgets/BaseWindow.hpp"
#include "widgets/BasePopup.hpp"
#include <memory>
@@ -11,7 +11,7 @@ class QLineEdit;
namespace chatterino {
class SearchPopup : public BaseWindow
class SearchPopup : public BasePopup
{
public:
SearchPopup();
@@ -19,8 +19,6 @@ public:
virtual void setChannel(const ChannelPtr &channel);
protected:
void keyPressEvent(QKeyEvent *e) override;
virtual void updateWindowTitle();
private:
+41
View File
@@ -0,0 +1,41 @@
#include "widgets/helper/SignalLabel.hpp"
namespace chatterino {
SignalLabel::SignalLabel(QWidget *parent, Qt::WindowFlags f)
: QLabel(parent, f)
{
}
void SignalLabel::mouseDoubleClickEvent(QMouseEvent *ev)
{
emit this->mouseDoubleClick(ev);
}
void SignalLabel::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit mouseDown();
}
event->ignore();
}
void SignalLabel::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit mouseUp();
}
event->ignore();
}
void SignalLabel::mouseMoveEvent(QMouseEvent *event)
{
emit this->mouseMove(event);
event->ignore();
}
} // namespace chatterino
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include <QFlags>
#include <QLabel>
#include <QMouseEvent>
#include <QWidget>
namespace chatterino {
class SignalLabel : public QLabel
{
Q_OBJECT
public:
explicit SignalLabel(QWidget *parent = nullptr, Qt::WindowFlags f = 0);
virtual ~SignalLabel() override = default;
signals:
void mouseDoubleClick(QMouseEvent *ev);
void mouseDown();
void mouseUp();
void mouseMove(QMouseEvent *event);
protected:
void mouseDoubleClickEvent(QMouseEvent *ev) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
};
} // namespace chatterino
+128
View File
@@ -0,0 +1,128 @@
#include "TitlebarButton.hpp"
#include "BaseTheme.hpp"
namespace chatterino {
TitleBarButton::TitleBarButton()
: Button(nullptr)
{
}
TitleBarButtonStyle TitleBarButton::getButtonStyle() const
{
return this->style_;
}
void TitleBarButton::setButtonStyle(TitleBarButtonStyle _style)
{
this->style_ = _style;
this->update();
}
void TitleBarButton::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setOpacity(this->getCurrentDimAmount());
QColor color = this->theme->window.text;
QColor background = this->theme->window.background;
int xD = this->height() / 3;
int centerX = this->width() / 2;
painter.setRenderHint(QPainter::Antialiasing, false);
switch (this->style_)
{
case TitleBarButtonStyle::Minimize: {
painter.fillRect(centerX - xD / 2, xD * 3 / 2, xD, 1, color);
break;
}
case TitleBarButtonStyle::Maximize: {
painter.setPen(color);
painter.drawRect(centerX - xD / 2, xD, xD - 1, xD - 1);
break;
}
case TitleBarButtonStyle::Unmaximize: {
int xD2 = xD * 1 / 5;
int xD3 = xD * 4 / 5;
painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3);
painter.fillRect(centerX - xD / 2, xD + xD2, xD3, xD3,
this->theme->window.background);
painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3);
break;
}
case TitleBarButtonStyle::Close: {
QRect rect(centerX - xD / 2, xD, xD - 1, xD - 1);
painter.setPen(QPen(color, 1));
painter.drawLine(rect.topLeft(), rect.bottomRight());
painter.drawLine(rect.topRight(), rect.bottomLeft());
break;
}
case TitleBarButtonStyle::User: {
color = "#999";
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = xD / 3;
QPainterPath path;
painter.save();
painter.translate(3, 3);
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
painter.fillPath(path, color);
painter.setBrush(background);
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
painter.setBrush(color);
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
painter.restore();
break;
}
case TitleBarButtonStyle::Settings: {
color = "#999";
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.save();
painter.translate(3, 3);
auto a = xD / 3;
QPainterPath path;
path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
for (int i = 0; i < 8; i++)
{
path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0),
(360 / 32.0));
path.arcTo(2 * a, 2 * a, 4 * a, 4 * a,
i * (360 / 8.0) + (360 / 32.0), (360 / 32.0));
}
painter.strokePath(path, color);
painter.fillPath(path, color);
painter.setBrush(background);
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
painter.restore();
break;
}
default:;
}
Button::paintEvent(event);
// this->fancyPaint(painter);
}
} // namespace chatterino
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "widgets/helper/Button.hpp"
namespace chatterino {
enum class TitleBarButtonStyle {
None = 0,
Minimize = 1,
Maximize = 2,
Unmaximize = 4,
Close = 8,
User = 16,
Settings = 32
};
class TitleBarButton : public Button
{
public:
TitleBarButton();
TitleBarButtonStyle getButtonStyle() const;
void setButtonStyle(TitleBarButtonStyle style_);
protected:
void paintEvent(QPaintEvent *) override;
private:
TitleBarButtonStyle style_;
};
} // namespace chatterino