A lot of changes
Remove unused constructor of messages::Message Fixed LimitedQueueSnapshot _-prefixes Changed LimitedQueueSnapshot's usage of int to std::size_t ColorScheme is no longer a singleton Created a "BaseWidget" class which is pretty much a QWidget except it has a reference of ColorScheme since most widgets will need a reference to the style they should use. BaseWidget can be implemented either with a BaseWidget parent (which will copy the ColorScheme reference from the parent) or with a normal QWidget parent and an explicit ColorScheme reference. Save main window geometry on close Fix font changing in the Settings Dialog Update settings library version
This commit is contained in:
@@ -1,4 +1,34 @@
|
||||
#ifndef BASEWIDGET_HPP
|
||||
#define BASEWIDGET_HPP
|
||||
#pragma once
|
||||
|
||||
#endif // BASEWIDGET_HPP
|
||||
#include "colorscheme.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class BaseWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, colorScheme(_colorScheme)
|
||||
{
|
||||
}
|
||||
|
||||
explicit BaseWidget(BaseWidget *parent)
|
||||
: QWidget(parent)
|
||||
, colorScheme(parent->colorScheme)
|
||||
{
|
||||
}
|
||||
|
||||
ColorScheme &colorScheme;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -30,8 +30,8 @@ inline void ezShortcut(ChatWidget *w, const char *key, T t)
|
||||
|
||||
} // namespace
|
||||
|
||||
ChatWidget::ChatWidget(ChannelManager &_channelManager, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent)
|
||||
: BaseWidget(parent)
|
||||
, channelManager(_channelManager)
|
||||
, channel(_channelManager.getEmpty())
|
||||
, vbox(this)
|
||||
@@ -142,7 +142,7 @@ void ChatWidget::setChannel(std::shared_ptr<Channel> _newChannel)
|
||||
|
||||
auto snapshot = this->channel->getMessageSnapshot();
|
||||
|
||||
for (int i = 0; i < snapshot.getSize(); i++) {
|
||||
for (int i = 0; i < snapshot.getLength(); i++) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(snapshot[i]);
|
||||
@@ -199,7 +199,7 @@ void ChatWidget::paintEvent(QPaintEvent *)
|
||||
// color the background of the chat
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(this->rect(), ColorScheme::getInstance().ChatBackground);
|
||||
painter.fillRect(this->rect(), this->colorScheme.ChatBackground);
|
||||
}
|
||||
|
||||
void ChatWidget::load(const boost::property_tree::ptree &tree)
|
||||
@@ -241,7 +241,8 @@ void ChatWidget::doChangeChannel()
|
||||
void ChatWidget::doPopup()
|
||||
{
|
||||
// TODO: Copy signals and stuff too
|
||||
auto widget = new ChatWidget(this->channelManager);
|
||||
auto widget =
|
||||
new ChatWidget(this->channelManager, static_cast<NotebookPage *>(this->parentWidget()));
|
||||
widget->setChannelName(this->getChannelName());
|
||||
widget->show();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "messages/messageref.hpp"
|
||||
#include "messages/word.hpp"
|
||||
#include "messages/wordpart.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/chatwidgetheader.hpp"
|
||||
#include "widgets/chatwidgetinput.hpp"
|
||||
#include "widgets/chatwidgetview.hpp"
|
||||
@@ -19,9 +20,12 @@
|
||||
namespace chatterino {
|
||||
|
||||
class ChannelManager;
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class NotebookPage;
|
||||
|
||||
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
|
||||
// ChatWidgetHeader
|
||||
// - Responsible for rendering which channel the ChatWidget is in, and the menu in the top-left of
|
||||
@@ -32,12 +36,12 @@ namespace widgets {
|
||||
// - Responsible for rendering and handling user text input
|
||||
//
|
||||
// Each sub-element has a reference to the parent Chat Widget
|
||||
class ChatWidget : public QWidget
|
||||
class ChatWidget : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatWidget(ChannelManager &_channelManager, QWidget *parent = nullptr);
|
||||
ChatWidget(ChannelManager &_channelManager, NotebookPage *parent);
|
||||
~ChatWidget();
|
||||
|
||||
std::shared_ptr<Channel> getChannel() const;
|
||||
|
||||
@@ -12,9 +12,11 @@ namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
||||
: QWidget(_chatWidget)
|
||||
: BaseWidget(_chatWidget)
|
||||
, chatWidget(_chatWidget)
|
||||
, leftLabel(this)
|
||||
, leftMenu(this)
|
||||
, rightLabel(this)
|
||||
, rightMenu(this)
|
||||
{
|
||||
this->setFixedHeight(32);
|
||||
@@ -68,7 +70,7 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
||||
void ChatWidgetHeader::updateColors()
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text);
|
||||
palette.setColor(QPalette::Foreground, this->colorScheme.Text);
|
||||
|
||||
this->leftLabel.setPalette(palette);
|
||||
this->channelNameLabel.setPalette(palette);
|
||||
@@ -86,8 +88,8 @@ void ChatWidgetHeader::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().ChatHeaderBackground);
|
||||
painter.setPen(ColorScheme::getInstance().ChatHeaderBorder);
|
||||
painter.fillRect(rect(), this->colorScheme.ChatHeaderBackground);
|
||||
painter.setPen(this->colorScheme.ChatHeaderBorder);
|
||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "signallabel.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/chatwidgetheaderbutton.hpp"
|
||||
|
||||
#include <QAction>
|
||||
@@ -13,10 +14,14 @@
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class ChatWidget;
|
||||
|
||||
class ChatWidgetHeader : public QWidget
|
||||
class ChatWidgetHeader : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "widgets/chatwidgetheaderbutton.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "widgets/chatwidgetheader.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPainter>
|
||||
@@ -7,24 +8,23 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetHeaderButton::ChatWidgetHeaderButton(int spacing)
|
||||
: QWidget()
|
||||
, _hbox()
|
||||
, _label()
|
||||
, _mouseOver(false)
|
||||
, _mouseDown(false)
|
||||
ChatWidgetHeaderButton::ChatWidgetHeaderButton(BaseWidget *parent, int spacing)
|
||||
: BaseWidget(parent)
|
||||
, mouseOver(false)
|
||||
, mouseDown(false)
|
||||
{
|
||||
setLayout(&_hbox);
|
||||
setLayout(&this->ui.hbox);
|
||||
|
||||
_label.setAlignment(Qt::AlignCenter);
|
||||
this->ui.label.setAlignment(Qt::AlignCenter);
|
||||
|
||||
_hbox.setMargin(0);
|
||||
_hbox.addSpacing(spacing);
|
||||
_hbox.addWidget(&_label);
|
||||
_hbox.addSpacing(spacing);
|
||||
this->ui.hbox.setMargin(0);
|
||||
this->ui.hbox.addSpacing(spacing);
|
||||
this->ui.hbox.addWidget(&this->ui.label);
|
||||
this->ui.hbox.addSpacing(spacing);
|
||||
|
||||
QObject::connect(&_label, &SignalLabel::mouseUp, this, &ChatWidgetHeaderButton::labelMouseUp);
|
||||
QObject::connect(&_label, &SignalLabel::mouseDown, this,
|
||||
QObject::connect(&this->ui.label, &SignalLabel::mouseUp, this,
|
||||
&ChatWidgetHeaderButton::labelMouseUp);
|
||||
QObject::connect(&this->ui.label, &SignalLabel::mouseDown, this,
|
||||
&ChatWidgetHeaderButton::labelMouseDown);
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
QBrush brush(ColorScheme::getInstance().IsLightTheme ? QColor(0, 0, 0, 32)
|
||||
: QColor(255, 255, 255, 32));
|
||||
QBrush brush(this->colorScheme.isLightTheme() ? QColor(0, 0, 0, 32)
|
||||
: QColor(255, 255, 255, 32));
|
||||
|
||||
if (_mouseDown) {
|
||||
if (mouseDown) {
|
||||
painter.fillRect(rect(), brush);
|
||||
}
|
||||
|
||||
if (_mouseOver) {
|
||||
if (mouseOver) {
|
||||
painter.fillRect(rect(), brush);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
||||
void ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseDown = true;
|
||||
mouseDown = true;
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -56,7 +56,7 @@ void ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
||||
void ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseDown = false;
|
||||
mouseDown = false;
|
||||
|
||||
update();
|
||||
|
||||
@@ -66,21 +66,21 @@ void ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
|
||||
void ChatWidgetHeaderButton::enterEvent(QEvent *)
|
||||
{
|
||||
_mouseOver = true;
|
||||
mouseOver = true;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ChatWidgetHeaderButton::leaveEvent(QEvent *)
|
||||
{
|
||||
_mouseOver = false;
|
||||
mouseOver = false;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ChatWidgetHeaderButton::labelMouseUp()
|
||||
{
|
||||
_mouseDown = false;
|
||||
mouseDown = false;
|
||||
|
||||
update();
|
||||
|
||||
@@ -89,7 +89,7 @@ void ChatWidgetHeaderButton::labelMouseUp()
|
||||
|
||||
void ChatWidgetHeaderButton::labelMouseDown()
|
||||
{
|
||||
_mouseDown = true;
|
||||
mouseDown = true;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/signallabel.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
@@ -8,38 +9,45 @@
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class ChatWidgetHeaderButton : public QWidget
|
||||
class ChatWidgetHeader;
|
||||
|
||||
class ChatWidgetHeaderButton : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChatWidgetHeaderButton(int spacing = 6);
|
||||
explicit ChatWidgetHeaderButton(BaseWidget *parent, int spacing = 6);
|
||||
|
||||
SignalLabel &getLabel()
|
||||
{
|
||||
return _label;
|
||||
return this->ui.label;
|
||||
}
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
void enterEvent(QEvent *) Q_DECL_OVERRIDE;
|
||||
void leaveEvent(QEvent *) Q_DECL_OVERRIDE;
|
||||
virtual void enterEvent(QEvent *) override;
|
||||
virtual void leaveEvent(QEvent *) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
QHBoxLayout _hbox;
|
||||
SignalLabel _label;
|
||||
struct {
|
||||
QHBoxLayout hbox;
|
||||
SignalLabel label;
|
||||
} ui;
|
||||
|
||||
bool _mouseOver;
|
||||
bool _mouseDown;
|
||||
bool mouseOver = false;
|
||||
bool mouseDown = false;
|
||||
|
||||
void labelMouseUp();
|
||||
void labelMouseDown();
|
||||
|
||||
@@ -12,8 +12,9 @@ namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
|
||||
: QWidget(_chatWidget)
|
||||
: BaseWidget(_chatWidget)
|
||||
, chatWidget(_chatWidget)
|
||||
, emotesLabel(this)
|
||||
{
|
||||
this->setMaximumHeight(150);
|
||||
|
||||
@@ -93,11 +94,11 @@ void ChatWidgetInput::refreshTheme()
|
||||
{
|
||||
QPalette palette;
|
||||
|
||||
palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text);
|
||||
palette.setColor(QPalette::Foreground, this->colorScheme.Text);
|
||||
|
||||
this->textLengthLabel.setPalette(palette);
|
||||
|
||||
this->textInput.setStyleSheet(ColorScheme::getInstance().InputStyleSheet);
|
||||
this->textInput.setStyleSheet(this->colorScheme.InputStyleSheet);
|
||||
}
|
||||
|
||||
void ChatWidgetInput::editTextChanged()
|
||||
@@ -118,8 +119,8 @@ void ChatWidgetInput::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(this->rect(), ColorScheme::getInstance().ChatInputBackground);
|
||||
painter.setPen(ColorScheme::getInstance().ChatInputBorder);
|
||||
painter.fillRect(this->rect(), this->colorScheme.ChatInputBackground);
|
||||
painter.setPen(this->colorScheme.ChatInputBorder);
|
||||
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "resizingtextedit.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/chatwidgetheaderbutton.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
@@ -16,7 +17,7 @@ namespace widgets {
|
||||
|
||||
class ChatWidget;
|
||||
|
||||
class ChatWidgetInput : public QWidget
|
||||
class ChatWidgetInput : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetView::ChatWidgetView(ChatWidget *_chatWidget)
|
||||
: QWidget(_chatWidget)
|
||||
: BaseWidget(_chatWidget)
|
||||
, chatWidget(_chatWidget)
|
||||
, scrollBar(this)
|
||||
, userPopupWidget(_chatWidget->getChannelRef())
|
||||
@@ -47,7 +47,7 @@ bool ChatWidgetView::layoutMessages()
|
||||
{
|
||||
auto messages = this->chatWidget->getMessagesSnapshot();
|
||||
|
||||
if (messages.getSize() == 0) {
|
||||
if (messages.getLength() == 0) {
|
||||
this->scrollBar.setVisible(false);
|
||||
return false;
|
||||
}
|
||||
@@ -65,10 +65,10 @@ bool ChatWidgetView::layoutMessages()
|
||||
int layoutWidth = this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width();
|
||||
|
||||
// layout the visible messages in the view
|
||||
if (messages.getSize() > start) {
|
||||
if (messages.getLength() > start) {
|
||||
int y = -(messages[start]->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1)));
|
||||
|
||||
for (int i = start; i < messages.getSize(); ++i) {
|
||||
for (int i = start; i < messages.getLength(); ++i) {
|
||||
auto message = messages[i];
|
||||
|
||||
redraw |= message->layout(layoutWidth, true);
|
||||
@@ -84,7 +84,7 @@ bool ChatWidgetView::layoutMessages()
|
||||
// layout the messages at the bottom to determine the scrollbar thumb size
|
||||
int h = height() - 8;
|
||||
|
||||
for (int i = messages.getSize() - 1; i >= 0; i--) {
|
||||
for (std::size_t i = messages.getLength() - 1; i > 0; i--) {
|
||||
auto *message = messages[i].get();
|
||||
|
||||
message->layout(layoutWidth, true);
|
||||
@@ -92,7 +92,7 @@ bool ChatWidgetView::layoutMessages()
|
||||
h -= message->getHeight();
|
||||
|
||||
if (h < 0) {
|
||||
this->scrollBar.setLargeChange((messages.getSize() - i) +
|
||||
this->scrollBar.setLargeChange((messages.getLength() - i) +
|
||||
(qreal)h / message->getHeight());
|
||||
this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue());
|
||||
|
||||
@@ -107,7 +107,7 @@ bool ChatWidgetView::layoutMessages()
|
||||
this->scrollBar.setDesiredValue(0);
|
||||
}
|
||||
|
||||
this->scrollBar.setMaximum(messages.getSize());
|
||||
this->scrollBar.setMaximum(messages.getLength());
|
||||
|
||||
if (this->showingLatestMessages && showScrollbar) {
|
||||
// If we were showing the latest messages and the scrollbar now wants to be rendered, scroll
|
||||
@@ -148,14 +148,12 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
|
||||
_painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
ColorScheme &scheme = ColorScheme::getInstance();
|
||||
|
||||
// only update gif emotes
|
||||
if (this->onlyUpdateEmotes) {
|
||||
this->onlyUpdateEmotes = false;
|
||||
|
||||
for (const GifEmoteData &item : this->gifEmotes) {
|
||||
_painter.fillRect(item.rect, scheme.ChatBackground);
|
||||
_painter.fillRect(item.rect, this->colorScheme.ChatBackground);
|
||||
|
||||
_painter.drawPixmap(item.rect, *item.image->getPixmap());
|
||||
}
|
||||
@@ -166,7 +164,7 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
// update all messages
|
||||
this->gifEmotes.clear();
|
||||
|
||||
_painter.fillRect(rect(), scheme.ChatBackground);
|
||||
_painter.fillRect(rect(), this->colorScheme.ChatBackground);
|
||||
|
||||
// code for tesing colors
|
||||
/*
|
||||
@@ -205,13 +203,13 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
|
||||
int start = this->scrollBar.getCurrentValue();
|
||||
|
||||
if (start >= messages.getSize()) {
|
||||
if (start >= messages.getLength()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int y = -(messages[start].get()->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1)));
|
||||
|
||||
for (int i = start; i < messages.getSize(); ++i) {
|
||||
for (int i = start; i < messages.getLength(); ++i) {
|
||||
messages::MessageRef *messageRef = messages[i].get();
|
||||
|
||||
std::shared_ptr<QPixmap> bufferPtr = messageRef->buffer;
|
||||
@@ -228,7 +226,7 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
// update messages that have been changed
|
||||
if (updateBuffer) {
|
||||
QPainter painter(buffer);
|
||||
painter.fillRect(buffer->rect(), scheme.ChatBackground);
|
||||
painter.fillRect(buffer->rect(), this->colorScheme.ChatBackground);
|
||||
|
||||
for (messages::WordPart const &wordPart : messageRef->getWordParts()) {
|
||||
// image
|
||||
@@ -247,7 +245,7 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
else {
|
||||
QColor color = wordPart.getWord().getColor();
|
||||
|
||||
ColorScheme::getInstance().normalizeColor(color);
|
||||
this->colorScheme.normalizeColor(color);
|
||||
|
||||
painter.setPen(color);
|
||||
painter.setFont(wordPart.getWord().getFont());
|
||||
@@ -266,14 +264,14 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
messages::LazyLoadedImage &lli = wordPart.getWord().getImage();
|
||||
|
||||
if (lli.getAnimated()) {
|
||||
GifEmoteData data;
|
||||
data.image = &lli;
|
||||
GifEmoteData gifEmoteData;
|
||||
gifEmoteData.image = &lli;
|
||||
QRect rect(wordPart.getX(), wordPart.getY() + y, wordPart.getWidth(),
|
||||
wordPart.getHeight());
|
||||
|
||||
data.rect = rect;
|
||||
gifEmoteData.rect = rect;
|
||||
|
||||
this->gifEmotes.push_back(data);
|
||||
this->gifEmotes.push_back(gifEmoteData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +288,7 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
}
|
||||
|
||||
for (GifEmoteData &item : this->gifEmotes) {
|
||||
_painter.fillRect(item.rect, scheme.ChatBackground);
|
||||
_painter.fillRect(item.rect, this->colorScheme.ChatBackground);
|
||||
|
||||
_painter.drawPixmap(item.rect, *item.image->getPixmap());
|
||||
}
|
||||
@@ -401,13 +399,13 @@ bool ChatWidgetView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::Message
|
||||
|
||||
int start = this->scrollBar.getCurrentValue();
|
||||
|
||||
if (start >= messages.getSize()) {
|
||||
if (start >= messages.getLength()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int y = -(messages[start]->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1)));
|
||||
|
||||
for (int i = start; i < messages.getSize(); ++i) {
|
||||
for (int i = start; i < messages.getLength(); ++i) {
|
||||
auto message = messages[i];
|
||||
|
||||
if (p.y() < y + message->getHeight()) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "messages/messageref.hpp"
|
||||
#include "messages/word.hpp"
|
||||
#include "widgets/accountpopup.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/scrollbar.hpp"
|
||||
|
||||
#include <QPaintEvent>
|
||||
@@ -17,7 +18,7 @@ namespace widgets {
|
||||
|
||||
class ChatWidget;
|
||||
|
||||
class ChatWidgetView : public QWidget
|
||||
class ChatWidgetView : public BaseWidget
|
||||
{
|
||||
public:
|
||||
explicit ChatWidgetView(ChatWidget *_chatWidget);
|
||||
|
||||
+31
-38
@@ -6,49 +6,42 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
FancyButton::FancyButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, _selected()
|
||||
, _mouseOver()
|
||||
, _mouseDown()
|
||||
, _mousePos()
|
||||
, _hoverMultiplier()
|
||||
, _effectTimer()
|
||||
, _mouseEffectColor(QColor(255, 255, 255))
|
||||
FancyButton::FancyButton(BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
|
||||
{
|
||||
connect(&_effectTimer, &QTimer::timeout, this, &FancyButton::onMouseEffectTimeout);
|
||||
connect(&effectTimer, &QTimer::timeout, this, &FancyButton::onMouseEffectTimeout);
|
||||
|
||||
_effectTimer.setInterval(20);
|
||||
_effectTimer.start();
|
||||
this->effectTimer.setInterval(20);
|
||||
this->effectTimer.start();
|
||||
}
|
||||
|
||||
void FancyButton::setMouseEffectColor(QColor color)
|
||||
{
|
||||
_mouseEffectColor = color;
|
||||
this->mouseEffectColor = color;
|
||||
}
|
||||
|
||||
void FancyButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter;
|
||||
|
||||
fancyPaint(painter);
|
||||
this->fancyPaint(painter);
|
||||
}
|
||||
|
||||
void FancyButton::fancyPaint(QPainter &painter)
|
||||
{
|
||||
QColor &c = _mouseEffectColor;
|
||||
QColor &c = this->mouseEffectColor;
|
||||
|
||||
if (_hoverMultiplier > 0) {
|
||||
QRadialGradient gradient(_mousePos.x(), _mousePos.y(), 50, _mousePos.x(), _mousePos.y());
|
||||
if (this->hoverMultiplier > 0) {
|
||||
QRadialGradient gradient(mousePos.x(), mousePos.y(), 50, mousePos.x(), mousePos.y());
|
||||
|
||||
gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), (int)(24 * _hoverMultiplier)));
|
||||
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), (int)(12 * _hoverMultiplier)));
|
||||
gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), (int)(24 * this->hoverMultiplier)));
|
||||
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), (int)(12 * this->hoverMultiplier)));
|
||||
|
||||
painter.fillRect(this->rect(), gradient);
|
||||
}
|
||||
|
||||
for (auto effect : _clickEffects) {
|
||||
for (auto effect : this->clickEffects) {
|
||||
QRadialGradient gradient(effect.position.x(), effect.position.y(),
|
||||
effect.progress * (float)width() * 2, effect.position.x(),
|
||||
effect.position.y());
|
||||
@@ -65,12 +58,12 @@ void FancyButton::fancyPaint(QPainter &painter)
|
||||
|
||||
void FancyButton::enterEvent(QEvent *)
|
||||
{
|
||||
_mouseOver = true;
|
||||
this->mouseOver = true;
|
||||
}
|
||||
|
||||
void FancyButton::leaveEvent(QEvent *)
|
||||
{
|
||||
_mouseOver = false;
|
||||
this->mouseOver = false;
|
||||
}
|
||||
|
||||
void FancyButton::mousePressEvent(QMouseEvent *event)
|
||||
@@ -79,9 +72,9 @@ void FancyButton::mousePressEvent(QMouseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
_clickEffects.push_back(ClickEffect(event->pos()));
|
||||
this->clickEffects.push_back(ClickEffect(event->pos()));
|
||||
|
||||
_mouseDown = true;
|
||||
this->mouseDown = true;
|
||||
}
|
||||
|
||||
void FancyButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
@@ -90,43 +83,43 @@ void FancyButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
_mouseDown = false;
|
||||
this->mouseDown = false;
|
||||
}
|
||||
|
||||
void FancyButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
_mousePos = event->pos();
|
||||
this->mousePos = event->pos();
|
||||
}
|
||||
|
||||
void FancyButton::onMouseEffectTimeout()
|
||||
{
|
||||
bool performUpdate = false;
|
||||
|
||||
if (_selected) {
|
||||
if (_hoverMultiplier != 0) {
|
||||
_hoverMultiplier = std::max(0.0, _hoverMultiplier - 0.1);
|
||||
if (selected) {
|
||||
if (this->hoverMultiplier != 0) {
|
||||
this->hoverMultiplier = std::max(0.0, this->hoverMultiplier - 0.1);
|
||||
performUpdate = true;
|
||||
}
|
||||
} else if (_mouseOver) {
|
||||
if (_hoverMultiplier != 1) {
|
||||
_hoverMultiplier = std::min(1.0, _hoverMultiplier + 0.5);
|
||||
} else if (mouseOver) {
|
||||
if (this->hoverMultiplier != 1) {
|
||||
this->hoverMultiplier = std::min(1.0, this->hoverMultiplier + 0.5);
|
||||
performUpdate = true;
|
||||
}
|
||||
} else {
|
||||
if (_hoverMultiplier != 0) {
|
||||
_hoverMultiplier = std::max(0.0, _hoverMultiplier - 0.3);
|
||||
if (this->hoverMultiplier != 0) {
|
||||
this->hoverMultiplier = std::max(0.0, this->hoverMultiplier - 0.3);
|
||||
performUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_clickEffects.size() != 0) {
|
||||
if (this->clickEffects.size() != 0) {
|
||||
performUpdate = true;
|
||||
|
||||
for (auto it = _clickEffects.begin(); it != _clickEffects.end();) {
|
||||
(*it).progress += _mouseDown ? 0.02 : 0.07;
|
||||
for (auto it = this->clickEffects.begin(); it != this->clickEffects.end();) {
|
||||
(*it).progress += mouseDown ? 0.02 : 0.07;
|
||||
|
||||
if ((*it).progress >= 1.0) {
|
||||
it = _clickEffects.erase(it);
|
||||
it = this->clickEffects.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
|
||||
+21
-20
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPoint>
|
||||
@@ -9,43 +11,42 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class FancyButton : public QWidget
|
||||
class FancyButton : public BaseWidget
|
||||
{
|
||||
struct ClickEffect {
|
||||
float progress;
|
||||
double progress = 0.0;
|
||||
QPoint position;
|
||||
|
||||
ClickEffect(QPoint position)
|
||||
: progress()
|
||||
, position(position)
|
||||
ClickEffect(QPoint _position)
|
||||
: position(_position)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
FancyButton(QWidget *parent = nullptr);
|
||||
FancyButton(BaseWidget *parent);
|
||||
|
||||
void setMouseEffectColor(QColor color);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void enterEvent(QEvent *) override;
|
||||
void leaveEvent(QEvent *) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
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);
|
||||
|
||||
private:
|
||||
bool _selected;
|
||||
bool _mouseOver;
|
||||
bool _mouseDown;
|
||||
QPoint _mousePos;
|
||||
float _hoverMultiplier;
|
||||
QTimer _effectTimer;
|
||||
std::vector<ClickEffect> _clickEffects;
|
||||
QColor _mouseEffectColor;
|
||||
bool selected = false;
|
||||
bool mouseOver = false;
|
||||
bool mouseDown = false;
|
||||
QPoint mousePos;
|
||||
double hoverMultiplier = 0.0;
|
||||
QTimer effectTimer;
|
||||
std::vector<ClickEffect> clickEffects;
|
||||
QColor mouseEffectColor = {255, 255, 255};
|
||||
|
||||
void onMouseEffectTimeout();
|
||||
};
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
MainWindow::MainWindow(ChannelManager &_channelManager, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
MainWindow::MainWindow(ChannelManager &_channelManager, ColorScheme &_colorScheme)
|
||||
: BaseWidget(_colorScheme, nullptr)
|
||||
, channelManager(_channelManager)
|
||||
, colorScheme(_colorScheme)
|
||||
, notebook(this->channelManager, this)
|
||||
, _loaded(false)
|
||||
, _titleBar()
|
||||
, windowGeometry("/windows/0/geometry")
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
@@ -44,10 +44,17 @@ MainWindow::MainWindow(ChannelManager &_channelManager, QWidget *parent)
|
||||
// }
|
||||
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Background, ColorScheme::getInstance().TabPanelBackground);
|
||||
palette.setColor(QPalette::Background, this->colorScheme.TabPanelBackground);
|
||||
setPalette(palette);
|
||||
|
||||
resize(1280, 800);
|
||||
if (this->windowGeometry->isFilled()) {
|
||||
// Load geometry from settings file
|
||||
this->setGeometry(this->windowGeometry.getValueRef());
|
||||
} else {
|
||||
// Set default geometry
|
||||
// Default position is in the middle of the current monitor or the primary monitor
|
||||
this->resize(1280, 800);
|
||||
}
|
||||
|
||||
// Initialize program-wide hotkeys
|
||||
{
|
||||
@@ -122,7 +129,7 @@ void MainWindow::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
this->notebook.load(tree);
|
||||
|
||||
_loaded = true;
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree MainWindow::save()
|
||||
@@ -140,12 +147,12 @@ void MainWindow::loadDefaults()
|
||||
{
|
||||
this->notebook.loadDefaults();
|
||||
|
||||
_loaded = true;
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
bool MainWindow::isLoaded() const
|
||||
{
|
||||
return _loaded;
|
||||
return loaded;
|
||||
}
|
||||
|
||||
Notebook &MainWindow::getNotebook()
|
||||
@@ -153,5 +160,11 @@ Notebook &MainWindow::getNotebook()
|
||||
return this->notebook;
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
// Save closing window position
|
||||
this->windowGeometry = this->geometry();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
+104
-4
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/notebook.hpp"
|
||||
#include "widgets/titlebar.hpp"
|
||||
|
||||
@@ -9,19 +10,22 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <pajlada/settings/serialize.hpp>
|
||||
#include <pajlada/settings/settingdata.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ChannelManager;
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class MainWindow : public QWidget
|
||||
class MainWindow : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(ChannelManager &_channelManager, QWidget *parent = nullptr);
|
||||
explicit MainWindow(ChannelManager &_channelManager, ColorScheme &_colorScheme);
|
||||
~MainWindow();
|
||||
|
||||
void layoutVisibleChatWidgets(Channel *channel = nullptr);
|
||||
@@ -36,12 +40,108 @@ public:
|
||||
|
||||
Notebook &getNotebook();
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
ChannelManager &channelManager;
|
||||
ColorScheme &colorScheme;
|
||||
|
||||
Notebook notebook;
|
||||
bool _loaded;
|
||||
TitleBar _titleBar;
|
||||
bool loaded = false;
|
||||
TitleBar titleBar;
|
||||
|
||||
class QRectWrapper : public pajlada::Settings::ISettingData, public QRect
|
||||
{
|
||||
public:
|
||||
QRectWrapper()
|
||||
: QRect(-1, -1, -1, -1)
|
||||
{
|
||||
}
|
||||
|
||||
pajlada::Signals::Signal<const QRectWrapper &> valueChanged;
|
||||
|
||||
/*
|
||||
operator const QRect &() const
|
||||
{
|
||||
return static_cast<const QRect &>(*this);
|
||||
// return this->getValue();
|
||||
}
|
||||
*/
|
||||
|
||||
const QRectWrapper &getValueRef() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual rapidjson::Value marshalInto(rapidjson::Document &d) override
|
||||
{
|
||||
using namespace pajlada::Settings;
|
||||
|
||||
rapidjson::Value obj(rapidjson::kObjectType);
|
||||
|
||||
auto _x = serializeToJSON<int>::serialize(this->x(), d.GetAllocator());
|
||||
auto _y = serializeToJSON<int>::serialize(this->y(), d.GetAllocator());
|
||||
auto _width = serializeToJSON<int>::serialize(this->width(), d.GetAllocator());
|
||||
auto _height = serializeToJSON<int>::serialize(this->height(), d.GetAllocator());
|
||||
|
||||
obj.AddMember("x", _x, d.GetAllocator());
|
||||
obj.AddMember("y", _y, d.GetAllocator());
|
||||
obj.AddMember("width", _width, d.GetAllocator());
|
||||
obj.AddMember("height", _height, d.GetAllocator());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
virtual bool unmarshalFrom(rapidjson::Document &document) override
|
||||
{
|
||||
using namespace pajlada::Settings;
|
||||
|
||||
auto vXp = this->getValueWithSuffix("/x", document);
|
||||
auto vYp = this->getValueWithSuffix("/y", document);
|
||||
auto vWidthp = this->getValueWithSuffix("/width", document);
|
||||
auto vHeightp = this->getValueWithSuffix("/height", document);
|
||||
if (vXp != nullptr) {
|
||||
this->setX(deserializeJSON<int>::deserialize(*vXp));
|
||||
this->filled = true;
|
||||
}
|
||||
if (vYp != nullptr) {
|
||||
this->setY(deserializeJSON<int>::deserialize(*vYp));
|
||||
this->filled = true;
|
||||
}
|
||||
if (vWidthp != nullptr) {
|
||||
this->setWidth(deserializeJSON<int>::deserialize(*vWidthp));
|
||||
this->filled = true;
|
||||
}
|
||||
if (vHeightp != nullptr) {
|
||||
this->setHeight(deserializeJSON<int>::deserialize(*vHeightp));
|
||||
this->filled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void registerDocument(rapidjson::Document &d) override
|
||||
{
|
||||
this->valueChanged.connect([this, &d](const auto &) {
|
||||
this->marshalInto(d); //
|
||||
});
|
||||
}
|
||||
|
||||
QRectWrapper &operator=(const QRect &rhs)
|
||||
{
|
||||
static_cast<QRect &>(*this) = rhs;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void setValue(const QRect &rhs)
|
||||
{
|
||||
static_cast<QRect &>(*this) = rhs;
|
||||
}
|
||||
};
|
||||
|
||||
pajlada::Settings::Setting<QRectWrapper, QRectWrapper> windowGeometry;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
+45
-45
@@ -18,26 +18,26 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
Notebook::Notebook(ChannelManager &_channelManager, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, channelManager(_channelManager)
|
||||
, _addButton(this)
|
||||
, _settingsButton(this)
|
||||
, _userButton(this)
|
||||
, _selectedPage(nullptr)
|
||||
Notebook::Notebook(ChannelManager &_channelManager, BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
, channelManager(_channelManager)
|
||||
, addButton(this)
|
||||
, settingsButton(this)
|
||||
, userButton(this)
|
||||
, selectedPage(nullptr)
|
||||
{
|
||||
connect(&_settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
|
||||
connect(&_userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
|
||||
connect(&_addButton, SIGNAL(clicked()), this, SLOT(addPageButtonClicked()));
|
||||
connect(&settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
|
||||
connect(&userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
|
||||
connect(&addButton, SIGNAL(clicked()), this, SLOT(addPageButtonClicked()));
|
||||
|
||||
_settingsButton.resize(24, 24);
|
||||
_settingsButton.icon = NotebookButton::IconSettings;
|
||||
settingsButton.resize(24, 24);
|
||||
settingsButton.icon = NotebookButton::IconSettings;
|
||||
|
||||
_userButton.resize(24, 24);
|
||||
_userButton.move(24, 0);
|
||||
_userButton.icon = NotebookButton::IconUser;
|
||||
userButton.resize(24, 24);
|
||||
userButton.move(24, 0);
|
||||
userButton.icon = NotebookButton::IconUser;
|
||||
|
||||
_addButton.resize(24, 24);
|
||||
addButton.resize(24, 24);
|
||||
|
||||
SettingsManager::getInstance().hidePreferencesButton.valueChanged.connect(
|
||||
[this](const bool &) { performLayout(); });
|
||||
@@ -52,11 +52,11 @@ NotebookPage *Notebook::addPage(bool select)
|
||||
|
||||
tab->show();
|
||||
|
||||
if (select || _pages.count() == 0) {
|
||||
if (select || pages.count() == 0) {
|
||||
this->select(page);
|
||||
}
|
||||
|
||||
_pages.append(page);
|
||||
pages.append(page);
|
||||
|
||||
performLayout();
|
||||
|
||||
@@ -65,22 +65,22 @@ NotebookPage *Notebook::addPage(bool select)
|
||||
|
||||
void Notebook::removePage(NotebookPage *page)
|
||||
{
|
||||
int index = _pages.indexOf(page);
|
||||
int index = pages.indexOf(page);
|
||||
|
||||
if (_pages.size() == 1) {
|
||||
if (pages.size() == 1) {
|
||||
select(nullptr);
|
||||
} else if (index == _pages.count() - 1) {
|
||||
select(_pages[index - 1]);
|
||||
} else if (index == pages.count() - 1) {
|
||||
select(pages[index - 1]);
|
||||
} else {
|
||||
select(_pages[index + 1]);
|
||||
select(pages[index + 1]);
|
||||
}
|
||||
|
||||
delete page->getTab();
|
||||
delete page;
|
||||
|
||||
_pages.removeOne(page);
|
||||
pages.removeOne(page);
|
||||
|
||||
if (_pages.size() == 0) {
|
||||
if (pages.size() == 0) {
|
||||
addPage();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ void Notebook::removePage(NotebookPage *page)
|
||||
|
||||
void Notebook::select(NotebookPage *page)
|
||||
{
|
||||
if (page == _selectedPage)
|
||||
if (page == selectedPage)
|
||||
return;
|
||||
|
||||
if (page != nullptr) {
|
||||
@@ -98,12 +98,12 @@ void Notebook::select(NotebookPage *page)
|
||||
page->getTab()->raise();
|
||||
}
|
||||
|
||||
if (_selectedPage != nullptr) {
|
||||
_selectedPage->setHidden(true);
|
||||
_selectedPage->getTab()->setSelected(false);
|
||||
if (selectedPage != nullptr) {
|
||||
selectedPage->setHidden(true);
|
||||
selectedPage->getTab()->setSelected(false);
|
||||
}
|
||||
|
||||
_selectedPage = page;
|
||||
selectedPage = page;
|
||||
|
||||
performLayout();
|
||||
}
|
||||
@@ -112,7 +112,7 @@ NotebookPage *Notebook::tabAt(QPoint point, int &index)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (auto *page : _pages) {
|
||||
for (auto *page : pages) {
|
||||
if (page->getTab()->getDesiredRect().contains(point)) {
|
||||
index = i;
|
||||
return page;
|
||||
@@ -127,7 +127,7 @@ NotebookPage *Notebook::tabAt(QPoint point, int &index)
|
||||
|
||||
void Notebook::rearrangePage(NotebookPage *page, int index)
|
||||
{
|
||||
_pages.move(_pages.indexOf(page), index);
|
||||
pages.move(pages.indexOf(page), index);
|
||||
|
||||
performLayout();
|
||||
}
|
||||
@@ -137,26 +137,26 @@ void Notebook::performLayout(bool animated)
|
||||
int x = 0, y = 0;
|
||||
|
||||
if (SettingsManager::getInstance().hidePreferencesButton.get()) {
|
||||
_settingsButton.hide();
|
||||
settingsButton.hide();
|
||||
} else {
|
||||
_settingsButton.show();
|
||||
settingsButton.show();
|
||||
x += 24;
|
||||
}
|
||||
if (SettingsManager::getInstance().hideUserButton.get()) {
|
||||
_userButton.hide();
|
||||
userButton.hide();
|
||||
} else {
|
||||
_userButton.move(x, 0);
|
||||
_userButton.show();
|
||||
userButton.move(x, 0);
|
||||
userButton.show();
|
||||
x += 24;
|
||||
}
|
||||
|
||||
int tabHeight = 16;
|
||||
bool first = true;
|
||||
|
||||
for (auto &i : _pages) {
|
||||
for (auto &i : pages) {
|
||||
tabHeight = i->getTab()->height();
|
||||
|
||||
if (!first && (i == _pages.last() ? tabHeight : 0) + x + i->getTab()->width() > width()) {
|
||||
if (!first && (i == pages.last() ? tabHeight : 0) + x + i->getTab()->width() > width()) {
|
||||
y += i->getTab()->height();
|
||||
i->getTab()->moveAnimated(QPoint(0, y), animated);
|
||||
x = i->getTab()->width();
|
||||
@@ -168,11 +168,11 @@ void Notebook::performLayout(bool animated)
|
||||
first = false;
|
||||
}
|
||||
|
||||
_addButton.move(x, y);
|
||||
addButton.move(x, y);
|
||||
|
||||
if (_selectedPage != nullptr) {
|
||||
_selectedPage->move(0, y + tabHeight);
|
||||
_selectedPage->resize(width(), height() - y - tabHeight);
|
||||
if (selectedPage != nullptr) {
|
||||
selectedPage->move(0, y + tabHeight);
|
||||
selectedPage->resize(width(), height() - y - tabHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ void Notebook::load(const boost::property_tree::ptree &tree)
|
||||
// can't read tabs
|
||||
}
|
||||
|
||||
if (_pages.size() == 0) {
|
||||
if (pages.size() == 0) {
|
||||
// No pages saved, show default stuff
|
||||
loadDefaults();
|
||||
}
|
||||
@@ -222,7 +222,7 @@ void Notebook::save(boost::property_tree::ptree &tree)
|
||||
boost::property_tree::ptree tabs;
|
||||
|
||||
// Iterate through all tabs and add them to our tabs property thing
|
||||
for (const auto &page : _pages) {
|
||||
for (const auto &page : pages) {
|
||||
boost::property_tree::ptree pTab = page->getTab()->save();
|
||||
|
||||
boost::property_tree::ptree pChats = page->save();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/notebookbutton.hpp"
|
||||
#include "widgets/notebookpage.hpp"
|
||||
#include "widgets/notebooktab.hpp"
|
||||
@@ -11,17 +12,18 @@
|
||||
namespace chatterino {
|
||||
|
||||
class ChannelManager;
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class Notebook : public QWidget
|
||||
class Notebook : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum HighlightType { none, highlighted, newMessage };
|
||||
|
||||
Notebook(ChannelManager &_channelManager, QWidget *parent);
|
||||
explicit Notebook(ChannelManager &_channelManager, BaseWidget *parent);
|
||||
|
||||
NotebookPage *addPage(bool select = false);
|
||||
|
||||
@@ -30,7 +32,7 @@ public:
|
||||
|
||||
NotebookPage *getSelectedPage()
|
||||
{
|
||||
return _selectedPage;
|
||||
return selectedPage;
|
||||
}
|
||||
|
||||
void performLayout(bool animate = true);
|
||||
@@ -51,13 +53,13 @@ public slots:
|
||||
private:
|
||||
ChannelManager &channelManager;
|
||||
|
||||
QList<NotebookPage *> _pages;
|
||||
QList<NotebookPage *> pages;
|
||||
|
||||
NotebookButton _addButton;
|
||||
NotebookButton _settingsButton;
|
||||
NotebookButton _userButton;
|
||||
NotebookButton addButton;
|
||||
NotebookButton settingsButton;
|
||||
NotebookButton userButton;
|
||||
|
||||
NotebookPage *_selectedPage;
|
||||
NotebookPage *selectedPage;
|
||||
|
||||
public:
|
||||
void load(const boost::property_tree::ptree &tree);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
NotebookButton::NotebookButton(QWidget *parent)
|
||||
NotebookButton::NotebookButton(BaseWidget *parent)
|
||||
: FancyButton(parent)
|
||||
{
|
||||
setMouseEffectColor(QColor(0, 0, 0));
|
||||
@@ -23,17 +23,15 @@ void NotebookButton::paintEvent(QPaintEvent *)
|
||||
QColor background;
|
||||
QColor foreground;
|
||||
|
||||
auto &colorScheme = ColorScheme::getInstance();
|
||||
|
||||
if (_mouseDown) {
|
||||
background = colorScheme.TabSelectedBackground;
|
||||
foreground = colorScheme.TabSelectedText;
|
||||
} else if (_mouseOver) {
|
||||
background = colorScheme.TabHoverBackground;
|
||||
foreground = colorScheme.TabSelectedBackground;
|
||||
if (mouseDown) {
|
||||
background = this->colorScheme.TabSelectedBackground;
|
||||
foreground = this->colorScheme.TabSelectedText;
|
||||
} else if (mouseOver) {
|
||||
background = this->colorScheme.TabHoverBackground;
|
||||
foreground = this->colorScheme.TabSelectedBackground;
|
||||
} else {
|
||||
background = colorScheme.TabPanelBackground;
|
||||
// foreground = colorScheme.TabSelectedBackground;
|
||||
background = this->colorScheme.TabPanelBackground;
|
||||
// foreground = this->colorScheme.TabSelectedBackground;
|
||||
foreground = QColor(230, 230, 230);
|
||||
}
|
||||
|
||||
@@ -93,7 +91,7 @@ void NotebookButton::paintEvent(QPaintEvent *)
|
||||
void NotebookButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseDown = false;
|
||||
mouseDown = false;
|
||||
|
||||
update();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
int icon = 0;
|
||||
|
||||
NotebookButton(QWidget *parent);
|
||||
NotebookButton(BaseWidget *parent);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
@@ -28,9 +28,9 @@ signals:
|
||||
void clicked();
|
||||
|
||||
private:
|
||||
bool _mouseOver = false;
|
||||
bool _mouseDown = false;
|
||||
QPoint _mousePos;
|
||||
bool mouseOver = false;
|
||||
bool mouseDown = false;
|
||||
QPoint mousePos;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "widgets/notebookpage.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "widgets/chatwidget.hpp"
|
||||
#include "widgets/notebook.hpp"
|
||||
#include "widgets/notebooktab.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
@@ -19,8 +20,8 @@ bool NotebookPage::isDraggingSplit = false;
|
||||
ChatWidget *NotebookPage::draggingSplit = nullptr;
|
||||
std::pair<int, int> NotebookPage::dropPosition = std::pair<int, int>(-1, -1);
|
||||
|
||||
NotebookPage::NotebookPage(ChannelManager &_channelManager, QWidget *parent, NotebookTab *_tab)
|
||||
: QWidget(parent)
|
||||
NotebookPage::NotebookPage(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab)
|
||||
: BaseWidget(parent->colorScheme, parent)
|
||||
, channelManager(_channelManager)
|
||||
, tab(_tab)
|
||||
, _parentbox(this)
|
||||
@@ -52,7 +53,7 @@ NotebookTab *NotebookPage::getTab() const
|
||||
|
||||
void NotebookPage::addChat(bool openChannelNameDialog)
|
||||
{
|
||||
ChatWidget *w = new ChatWidget(this->channelManager);
|
||||
ChatWidget *w = this->createChatWidget();
|
||||
|
||||
if (openChannelNameDialog) {
|
||||
w->showChangeChannelPopup();
|
||||
@@ -130,9 +131,9 @@ void NotebookPage::addToLayout(ChatWidget *widget,
|
||||
void NotebookPage::enterEvent(QEvent *)
|
||||
{
|
||||
if (_hbox.count() == 0) {
|
||||
setCursor(QCursor(Qt::PointingHandCursor));
|
||||
this->setCursor(QCursor(Qt::PointingHandCursor));
|
||||
} else {
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
this->setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,9 +145,9 @@ void NotebookPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (_hbox.count() == 0 && event->button() == Qt::LeftButton) {
|
||||
// "Add Chat" was clicked
|
||||
addToLayout(new ChatWidget(this->channelManager), std::pair<int, int>(-1, -1));
|
||||
this->addToLayout(this->createChatWidget(), std::pair<int, int>(-1, -1));
|
||||
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
this->setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,16 +237,16 @@ void NotebookPage::paintEvent(QPaintEvent *)
|
||||
QPainter painter(this);
|
||||
|
||||
if (_hbox.count() == 0) {
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().ChatBackground);
|
||||
painter.fillRect(rect(), this->colorScheme.ChatBackground);
|
||||
|
||||
painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground);
|
||||
painter.fillRect(0, 0, width(), 2, this->colorScheme.TabSelectedBackground);
|
||||
|
||||
painter.setPen(ColorScheme::getInstance().Text);
|
||||
painter.setPen(this->colorScheme.Text);
|
||||
painter.drawText(rect(), "Add Chat", QTextOption(Qt::AlignCenter));
|
||||
} else {
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().TabSelectedBackground);
|
||||
painter.fillRect(rect(), this->colorScheme.TabSelectedBackground);
|
||||
|
||||
painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground);
|
||||
painter.fillRect(0, 0, width(), 2, this->colorScheme.TabSelectedBackground);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +270,11 @@ std::pair<int, int> NotebookPage::getChatPosition(const ChatWidget *chatWidget)
|
||||
return getWidgetPositionInLayout(layout, chatWidget);
|
||||
}
|
||||
|
||||
ChatWidget *NotebookPage::createChatWidget()
|
||||
{
|
||||
return new ChatWidget(this->channelManager, this);
|
||||
}
|
||||
|
||||
void NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
try {
|
||||
@@ -276,7 +282,7 @@ void NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||
for (const auto &v : tree.get_child("columns.")) {
|
||||
int row = 0;
|
||||
for (const auto &innerV : v.second.get_child("")) {
|
||||
auto widget = new ChatWidget(this->channelManager);
|
||||
auto widget = this->createChatWidget();
|
||||
widget->load(innerV.second);
|
||||
addToLayout(widget, std::pair<int, int>(column, row));
|
||||
++row;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/chatwidget.hpp"
|
||||
#include "widgets/notebookpage.hpp"
|
||||
#include "widgets/notebookpagedroppreview.hpp"
|
||||
@@ -20,12 +21,14 @@ class ChannelManager;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class NotebookPage : public QWidget
|
||||
class NotebookPage : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NotebookPage(ChannelManager &_channelManager, QWidget *parent, NotebookTab *_tab);
|
||||
NotebookPage(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab);
|
||||
|
||||
ChannelManager &channelManager;
|
||||
|
||||
std::pair<int, int> removeFromLayout(ChatWidget *widget);
|
||||
void addToLayout(ChatWidget *widget, std::pair<int, int> position);
|
||||
@@ -52,8 +55,6 @@ protected:
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private:
|
||||
ChannelManager &channelManager;
|
||||
|
||||
struct DropRegion {
|
||||
QRect rect;
|
||||
std::pair<int, int> position;
|
||||
@@ -79,6 +80,8 @@ private:
|
||||
|
||||
std::pair<int, int> getChatPosition(const ChatWidget *chatWidget);
|
||||
|
||||
ChatWidget *createChatWidget();
|
||||
|
||||
public:
|
||||
void load(const boost::property_tree::ptree &tree);
|
||||
boost::property_tree::ptree save();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "widgets/notebookpagedroppreview.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
@@ -7,11 +6,9 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
NotebookPageDropPreview::NotebookPageDropPreview(BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
, positionAnimation(this, "geometry")
|
||||
, desiredGeometry()
|
||||
, animate(false)
|
||||
{
|
||||
this->positionAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
|
||||
this->setHidden(true);
|
||||
@@ -21,13 +18,12 @@ void NotebookPageDropPreview::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(8, 8, width() - 17, height() - 17,
|
||||
ColorScheme::getInstance().DropPreviewBackground);
|
||||
painter.fillRect(8, 8, width() - 17, height() - 17, this->colorScheme.DropPreviewBackground);
|
||||
}
|
||||
|
||||
void NotebookPageDropPreview::hideEvent(QHideEvent *)
|
||||
{
|
||||
animate = false;
|
||||
this->animate = false;
|
||||
}
|
||||
|
||||
void NotebookPageDropPreview::setBounds(const QRect &rect)
|
||||
@@ -36,7 +32,7 @@ void NotebookPageDropPreview::setBounds(const QRect &rect)
|
||||
return;
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
if (this->animate) {
|
||||
this->positionAnimation.stop();
|
||||
this->positionAnimation.setDuration(50);
|
||||
this->positionAnimation.setStartValue(this->geometry());
|
||||
@@ -48,7 +44,7 @@ void NotebookPageDropPreview::setBounds(const QRect &rect)
|
||||
|
||||
this->desiredGeometry = rect;
|
||||
|
||||
animate = true;
|
||||
this->animate = true;
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
|
||||
#include <QPropertyAnimation>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class NotebookPageDropPreview : public QWidget
|
||||
class NotebookPageDropPreview : public BaseWidget
|
||||
{
|
||||
public:
|
||||
NotebookPageDropPreview(QWidget *parent);
|
||||
NotebookPageDropPreview(BaseWidget *parent);
|
||||
|
||||
void setBounds(const QRect &rect);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
void hideEvent(QHideEvent *);
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
virtual void hideEvent(QHideEvent *) override;
|
||||
|
||||
QPropertyAnimation positionAnimation;
|
||||
QRect desiredGeometry;
|
||||
bool animate;
|
||||
bool animate = false;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
+11
-21
@@ -10,17 +10,9 @@ namespace widgets {
|
||||
|
||||
NotebookTab::NotebookTab(Notebook *notebook)
|
||||
: QWidget(notebook)
|
||||
, colorScheme(notebook->colorScheme)
|
||||
, _posAnimation(this, "pos")
|
||||
, _posAnimated(false)
|
||||
, _posAnimationDesired()
|
||||
, _notebook(notebook)
|
||||
, _title("<no title>")
|
||||
, _selected(false)
|
||||
, _mouseOver(false)
|
||||
, _mouseDown(false)
|
||||
, _mouseOverX(false)
|
||||
, _mouseDownX(false)
|
||||
, _highlightStyle(HighlightNone)
|
||||
{
|
||||
this->calcSize();
|
||||
this->setAcceptDrops(true);
|
||||
@@ -122,23 +114,21 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||
|
||||
QColor fg = QColor(0, 0, 0);
|
||||
|
||||
auto &colorScheme = ColorScheme::getInstance();
|
||||
|
||||
if (_selected) {
|
||||
painter.fillRect(rect(), colorScheme.TabSelectedBackground);
|
||||
fg = colorScheme.TabSelectedText;
|
||||
painter.fillRect(rect(), this->colorScheme.TabSelectedBackground);
|
||||
fg = this->colorScheme.TabSelectedText;
|
||||
} else if (_mouseOver) {
|
||||
painter.fillRect(rect(), colorScheme.TabHoverBackground);
|
||||
fg = colorScheme.TabHoverText;
|
||||
painter.fillRect(rect(), this->colorScheme.TabHoverBackground);
|
||||
fg = this->colorScheme.TabHoverText;
|
||||
} else if (_highlightStyle == HighlightHighlighted) {
|
||||
painter.fillRect(rect(), colorScheme.TabHighlightedBackground);
|
||||
fg = colorScheme.TabHighlightedText;
|
||||
painter.fillRect(rect(), this->colorScheme.TabHighlightedBackground);
|
||||
fg = this->colorScheme.TabHighlightedText;
|
||||
} else if (_highlightStyle == HighlightNewMessage) {
|
||||
painter.fillRect(rect(), colorScheme.TabNewMessageBackground);
|
||||
fg = colorScheme.TabHighlightedText;
|
||||
painter.fillRect(rect(), this->colorScheme.TabNewMessageBackground);
|
||||
fg = this->colorScheme.TabHighlightedText;
|
||||
} else {
|
||||
painter.fillRect(rect(), colorScheme.TabBackground);
|
||||
fg = colorScheme.TabText;
|
||||
painter.fillRect(rect(), this->colorScheme.TabBackground);
|
||||
fg = this->colorScheme.TabText;
|
||||
}
|
||||
|
||||
painter.setPen(fg);
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <boost/signals2/connection.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class Notebook;
|
||||
@@ -22,6 +25,8 @@ public:
|
||||
explicit NotebookTab(Notebook *_notebook);
|
||||
~NotebookTab();
|
||||
|
||||
ColorScheme &colorScheme;
|
||||
|
||||
void calcSize();
|
||||
|
||||
NotebookPage *page;
|
||||
@@ -55,20 +60,20 @@ private:
|
||||
boost::signals2::connection _hideXConnection;
|
||||
|
||||
QPropertyAnimation _posAnimation;
|
||||
bool _posAnimated;
|
||||
bool _posAnimated = false;
|
||||
QPoint _posAnimationDesired;
|
||||
|
||||
Notebook *_notebook;
|
||||
|
||||
QString _title;
|
||||
QString _title = "<no title>";
|
||||
|
||||
bool _selected;
|
||||
bool _mouseOver;
|
||||
bool _mouseDown;
|
||||
bool _mouseOverX;
|
||||
bool _mouseDownX;
|
||||
bool _selected = false;
|
||||
bool _mouseOver = false;
|
||||
bool _mouseDown = false;
|
||||
bool _mouseOverX = false;
|
||||
bool _mouseDownX = false;
|
||||
|
||||
HighlightStyle _highlightStyle;
|
||||
HighlightStyle _highlightStyle = HighlightStyle::HighlightNone;
|
||||
|
||||
QRect getXRect()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "widgets/scrollbar.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "widgets/chatwidgetview.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
@@ -10,8 +11,8 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ScrollBar::ScrollBar(QWidget *widget)
|
||||
: QWidget(widget)
|
||||
ScrollBar::ScrollBar(ChatWidgetView *parent)
|
||||
: BaseWidget(parent)
|
||||
, _currentValueAnimation(this, "currentValue")
|
||||
, _highlights(nullptr)
|
||||
{
|
||||
@@ -197,7 +198,7 @@ void ScrollBar::printCurrentState(const QString &prefix) const
|
||||
void ScrollBar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().ScrollbarBG);
|
||||
painter.fillRect(rect(), this->colorScheme.ScrollbarBG);
|
||||
|
||||
painter.fillRect(QRect(0, 0, width(), _buttonHeight), QColor(255, 0, 0));
|
||||
painter.fillRect(QRect(0, height() - _buttonHeight, width(), _buttonHeight), QColor(255, 0, 0));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/scrollbarhighlight.hpp"
|
||||
|
||||
#include <QMutex>
|
||||
@@ -8,14 +9,19 @@
|
||||
#include <boost/signals2.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class ScrollBar : public QWidget
|
||||
class ChatWidgetView;
|
||||
|
||||
class ScrollBar : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScrollBar(QWidget *parent = 0);
|
||||
ScrollBar(ChatWidgetView *parent = 0);
|
||||
~ScrollBar();
|
||||
|
||||
void removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#include "widgets/scrollbarhighlight.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "widgets/scrollbar.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ScrollBarHighlight::ScrollBarHighlight(float position, int colorIndex, Style style, QString tag)
|
||||
: _style(style)
|
||||
, _position(position)
|
||||
, _colorIndex(std::max(0, std::min(ColorScheme::getInstance().HighlightColorCount, colorIndex)))
|
||||
, _tag(tag)
|
||||
ScrollBarHighlight::ScrollBarHighlight(double _position, int _colorIndex, ScrollBar *parent,
|
||||
Style _style, QString _tag)
|
||||
: colorScheme(parent->colorScheme)
|
||||
, position(_position)
|
||||
, colorIndex(std::max(0, std::min(this->colorScheme.HighlightColorCount, _colorIndex)))
|
||||
, style(_style)
|
||||
, tag(_tag)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -3,43 +3,50 @@
|
||||
#include "QString"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class ScrollBar;
|
||||
|
||||
class ScrollBarHighlight
|
||||
{
|
||||
public:
|
||||
enum Style { Default, Left, Right, SingleLine };
|
||||
|
||||
ScrollBarHighlight(float getPosition, int getColorIndex, Style getStyle = Default,
|
||||
ScrollBarHighlight(double _position, int _colorIndex, ScrollBar *parent, Style _style = Default,
|
||||
QString _tag = "");
|
||||
|
||||
Style getStyle()
|
||||
{
|
||||
return _style;
|
||||
}
|
||||
ColorScheme &colorScheme;
|
||||
|
||||
float getPosition()
|
||||
double getPosition()
|
||||
{
|
||||
return _position;
|
||||
return this->position;
|
||||
}
|
||||
|
||||
int getColorIndex()
|
||||
{
|
||||
return _colorIndex;
|
||||
return this->colorIndex;
|
||||
}
|
||||
|
||||
Style getStyle()
|
||||
{
|
||||
return this->style;
|
||||
}
|
||||
|
||||
QString getTag()
|
||||
{
|
||||
return _tag;
|
||||
return this->tag;
|
||||
}
|
||||
|
||||
ScrollBarHighlight *next = nullptr;
|
||||
|
||||
private:
|
||||
Style _style;
|
||||
float _position;
|
||||
int _colorIndex;
|
||||
QString _tag;
|
||||
double position;
|
||||
int colorIndex;
|
||||
Style style;
|
||||
QString tag;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -108,10 +108,31 @@ void SettingsDialog::addTabs()
|
||||
|
||||
auto form = new QFormLayout();
|
||||
auto combo = new QComboBox();
|
||||
auto slider = new QSlider(Qt::Horizontal);
|
||||
|
||||
auto font = new QPushButton("select");
|
||||
font->connect(font, &QPushButton::clicked, []() {
|
||||
auto fontLayout = new QHBoxLayout();
|
||||
auto fontFamilyLabel = new QLabel("Current font family");
|
||||
auto fontSizeLabel = new QLabel("Current font size");
|
||||
auto fontButton = new QPushButton("Select");
|
||||
|
||||
fontLayout->addWidget(fontButton);
|
||||
fontLayout->addWidget(fontFamilyLabel);
|
||||
fontLayout->addWidget(fontSizeLabel);
|
||||
|
||||
{
|
||||
auto fontManager = FontManager::getInstance();
|
||||
|
||||
fontManager.currentFontFamily.getValueChangedSignal().connect(
|
||||
[fontFamilyLabel](const std::string &newValue) {
|
||||
fontFamilyLabel->setText(QString::fromStdString(newValue)); //
|
||||
});
|
||||
|
||||
fontManager.currentFontSize.getValueChangedSignal().connect(
|
||||
[fontSizeLabel](const int &newValue) {
|
||||
fontSizeLabel->setText(QString(QString::number(newValue))); //
|
||||
});
|
||||
}
|
||||
|
||||
fontButton->connect(fontButton, &QPushButton::clicked, []() {
|
||||
auto fontManager = FontManager::getInstance();
|
||||
QFontDialog dialog(fontManager.getFont(FontManager::Medium));
|
||||
|
||||
@@ -131,48 +152,61 @@ void SettingsDialog::addTabs()
|
||||
auto hideUserButton = createCheckbox("Hide user button", settings.hideUserButton);
|
||||
|
||||
form->addRow("Theme:", combo);
|
||||
form->addRow("Theme color:", slider);
|
||||
form->addRow("Font:", font);
|
||||
form->addRow("Tabbar:", compactTabs);
|
||||
|
||||
{
|
||||
auto hbox = new QHBoxLayout();
|
||||
|
||||
auto slider = new QSlider(Qt::Horizontal);
|
||||
// Theme hue
|
||||
slider->setMinimum(0);
|
||||
slider->setMaximum(1000);
|
||||
|
||||
slider->setValue(std::min(std::max(settings.themeHue.getValue(), 0.0), 1.0) * 1000);
|
||||
|
||||
hbox->addWidget(slider);
|
||||
|
||||
auto button = new QPushButton();
|
||||
button->setFlat(true);
|
||||
|
||||
hbox->addWidget(button);
|
||||
|
||||
form->addRow("Theme color:", hbox);
|
||||
|
||||
QObject::connect(slider, &QSlider::valueChanged, this, [&settings, button](int value) {
|
||||
settings.themeHue.setValue(value / 1000.0);
|
||||
|
||||
QPalette pal = button->palette();
|
||||
QColor color;
|
||||
color.setHsvF(settings.themeHue.getValue(), 1.0, 1.0, 1.0);
|
||||
pal.setColor(QPalette::Button, color);
|
||||
button->setAutoFillBackground(true);
|
||||
button->setPalette(pal);
|
||||
button->update();
|
||||
|
||||
// TODO(pajlada): re-implement
|
||||
// this->windowManager.updateAll();
|
||||
});
|
||||
}
|
||||
|
||||
form->addRow("Font:", fontLayout);
|
||||
form->addRow("Tab bar:", compactTabs);
|
||||
form->addRow("", hidePreferencesButton);
|
||||
form->addRow("", hideUserButton);
|
||||
|
||||
// theme
|
||||
// Theme name
|
||||
combo->addItem("White");
|
||||
combo->addItem("Light");
|
||||
combo->addItem("Dark");
|
||||
combo->addItem("Black");
|
||||
|
||||
QString theme = settings.theme.get();
|
||||
theme = theme.toLower();
|
||||
auto xD = QString::fromStdString(settings.themeName);
|
||||
|
||||
if (theme == "light") {
|
||||
combo->setCurrentIndex(0);
|
||||
} else if (theme == "white") {
|
||||
combo->setCurrentIndex(1);
|
||||
} else if (theme == "black") {
|
||||
combo->setCurrentIndex(3);
|
||||
} else {
|
||||
combo->setCurrentIndex(2);
|
||||
}
|
||||
combo->setCurrentText(xD);
|
||||
|
||||
QObject::connect(combo, &QComboBox::currentTextChanged, this,
|
||||
[&settings](const QString &value) { settings.theme.set(value); });
|
||||
|
||||
// theme hue
|
||||
slider->setMinimum(0);
|
||||
slider->setMaximum(1000);
|
||||
|
||||
float hue = settings.themeHue.get();
|
||||
|
||||
slider->setValue(std::min(std::max(hue, (float)0.0), (float)1.0) * 1000);
|
||||
|
||||
QObject::connect(slider, &QSlider::valueChanged, this, [&settings](int value) {
|
||||
settings.themeHue.set(value / 1000.0);
|
||||
|
||||
// TODO(pajlada): re-implement
|
||||
// this->windowManager.updateAll();
|
||||
});
|
||||
[&settings](const QString &value) {
|
||||
settings.themeName.setValue(value.toStdString()); //
|
||||
});
|
||||
|
||||
group->setLayout(form);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user