refactoring
This commit is contained in:
+117
-60
@@ -1,7 +1,7 @@
|
||||
#include "widgets/chatwidget.h"
|
||||
#include "channels.h"
|
||||
#include "channelmanager.h"
|
||||
#include "colorscheme.h"
|
||||
#include "settings.h"
|
||||
#include "settingsmanager.h"
|
||||
#include "widgets/textinputdialog.h"
|
||||
|
||||
#include <QDebug>
|
||||
@@ -11,110 +11,167 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <boost/signals2.hpp>
|
||||
|
||||
using namespace chatterino::messages;
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidget::ChatWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, messages()
|
||||
, channel(Channels::getEmpty())
|
||||
, channelName(QString())
|
||||
, vbox(this)
|
||||
, header(this)
|
||||
, view(this)
|
||||
, input(this)
|
||||
, _messages()
|
||||
, _channel(ChannelManager::getInstance().getEmpty())
|
||||
, _channelName(QString())
|
||||
, _vbox(this)
|
||||
, _header(this)
|
||||
, _view(this)
|
||||
, _input(this)
|
||||
{
|
||||
this->vbox.setSpacing(0);
|
||||
this->vbox.setMargin(1);
|
||||
this->_vbox.setSpacing(0);
|
||||
this->_vbox.setMargin(1);
|
||||
|
||||
this->vbox.addWidget(&header);
|
||||
this->vbox.addWidget(&view, 1);
|
||||
this->vbox.addWidget(&input);
|
||||
this->_vbox.addWidget(&_header);
|
||||
this->_vbox.addWidget(&_view, 1);
|
||||
this->_vbox.addWidget(&_input);
|
||||
}
|
||||
|
||||
ChatWidget::~ChatWidget()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel>
|
||||
ChatWidget::getChannel() const
|
||||
{
|
||||
return _channel;
|
||||
}
|
||||
|
||||
const QString &
|
||||
ChatWidget::getChannelName() const
|
||||
{
|
||||
return _channelName;
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::setChannelName(const QString &name)
|
||||
{
|
||||
QString channel = name.trimmed();
|
||||
|
||||
if (QString::compare(channel, this->channelName, Qt::CaseInsensitive) ==
|
||||
0) {
|
||||
this->channelName = channel;
|
||||
this->header.updateChannelText();
|
||||
// return if channel name is the same
|
||||
if (QString::compare(channel, _channelName, Qt::CaseInsensitive) == 0) {
|
||||
_channelName = channel;
|
||||
_header.updateChannelText();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->channelName.isEmpty()) {
|
||||
Channels::removeChannel(this->channelName);
|
||||
// remove current channel
|
||||
if (!_channelName.isEmpty()) {
|
||||
ChannelManager::getInstance().removeChannel(_channelName);
|
||||
|
||||
this->messageAppendedConnection.disconnect();
|
||||
this->messageRemovedConnection.disconnect();
|
||||
detachChannel(_channel);
|
||||
}
|
||||
|
||||
this->channelName = channel;
|
||||
this->header.updateChannelText();
|
||||
// update members
|
||||
_channelName = channel;
|
||||
|
||||
this->view.layoutMessages();
|
||||
|
||||
messages.clear();
|
||||
// update messages
|
||||
_messages.clear();
|
||||
|
||||
if (channel.isEmpty()) {
|
||||
this->channel = NULL;
|
||||
|
||||
_channel = NULL;
|
||||
} else {
|
||||
this->channel = Channels::addChannel(channel);
|
||||
_channel = ChannelManager::getInstance().addChannel(channel);
|
||||
|
||||
this->messageAppendedConnection =
|
||||
this->channel.get()->messageAppended.connect([this](
|
||||
std::shared_ptr<messages::Message> &message) {
|
||||
|
||||
std::shared_ptr<messages::MessageRef> deleted;
|
||||
|
||||
auto messageRef = new messages::MessageRef(message);
|
||||
|
||||
this->messages.appendItem(
|
||||
std::shared_ptr<messages::MessageRef>(messageRef), deleted);
|
||||
});
|
||||
|
||||
this->messageRemovedConnection =
|
||||
this->channel.get()->messageRemovedFromStart.connect(
|
||||
[this](std::shared_ptr<messages::Message> &) {});
|
||||
|
||||
auto snapshot = this->channel.get()->getMessageSnapshot();
|
||||
|
||||
for (int i = 0; i < snapshot.getLength(); i++) {
|
||||
std::shared_ptr<messages::MessageRef> deleted;
|
||||
|
||||
auto messageRef = new messages::MessageRef(snapshot[i]);
|
||||
|
||||
this->messages.appendItem(
|
||||
std::shared_ptr<messages::MessageRef>(messageRef), deleted);
|
||||
}
|
||||
attachChannel(_channel);
|
||||
}
|
||||
|
||||
this->view.layoutMessages();
|
||||
this->view.update();
|
||||
// update header
|
||||
_header.updateChannelText();
|
||||
|
||||
// update view
|
||||
_view.layoutMessages();
|
||||
_view.update();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::attachChannel(SharedChannel channel)
|
||||
{
|
||||
// on new message
|
||||
_messageAppendedConnection =
|
||||
channel->messageAppended.connect([this](SharedMessage &message) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(message);
|
||||
|
||||
if (_messages.appendItem(SharedMessageRef(messageRef), deleted)) {
|
||||
qreal value =
|
||||
std::max(0.0, _view.getScrollbar()->getDesiredValue() - 1);
|
||||
|
||||
_view.getScrollbar()->setDesiredValue(value, false);
|
||||
}
|
||||
});
|
||||
|
||||
// on message removed
|
||||
_messageRemovedConnection =
|
||||
_channel->messageRemovedFromStart.connect([this](SharedMessage &) {});
|
||||
|
||||
auto snapshot = _channel.get()->getMessageSnapshot();
|
||||
|
||||
for (int i = 0; i < snapshot.getLength(); i++) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(snapshot[i]);
|
||||
|
||||
_messages.appendItem(SharedMessageRef(messageRef), deleted);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::detachChannel(std::shared_ptr<Channel> channel)
|
||||
{
|
||||
// on message added
|
||||
_messageAppendedConnection.disconnect();
|
||||
|
||||
// on message removed
|
||||
_messageRemovedConnection.disconnect();
|
||||
}
|
||||
|
||||
LimitedQueueSnapshot<SharedMessageRef>
|
||||
ChatWidget::getMessagesSnapshot()
|
||||
{
|
||||
return _messages.getSnapshot();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::showChangeChannelPopup()
|
||||
{
|
||||
// create new input dialog and execute it
|
||||
TextInputDialog dialog(this);
|
||||
|
||||
dialog.setText(this->channelName);
|
||||
dialog.setText(_channelName);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
setChannelName(dialog.getText());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::layoutMessages()
|
||||
{
|
||||
if (_view.layoutMessages()) {
|
||||
_view.update();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::updateGifEmotes()
|
||||
{
|
||||
_view.updateGifEmotes();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
// color the background of the chat
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(this->rect(), ColorScheme::getInstance().ChatBackground);
|
||||
@@ -123,7 +180,7 @@ ChatWidget::paintEvent(QPaintEvent *)
|
||||
void
|
||||
ChatWidget::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
// Load tab text
|
||||
// load tab text
|
||||
try {
|
||||
this->setChannelName(
|
||||
QString::fromStdString(tree.get<std::string>("channelName")));
|
||||
|
||||
+18
-34
@@ -27,51 +27,35 @@ public:
|
||||
ChatWidget(QWidget *parent = 0);
|
||||
~ChatWidget();
|
||||
|
||||
ChatWidgetView &
|
||||
getView()
|
||||
{
|
||||
return view;
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel>
|
||||
getChannel() const
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
const QString &
|
||||
getChannelName() const
|
||||
{
|
||||
return channelName;
|
||||
}
|
||||
|
||||
SharedChannel getChannel() const;
|
||||
const QString &getChannelName() const;
|
||||
void setChannelName(const QString &name);
|
||||
|
||||
void showChangeChannelPopup();
|
||||
|
||||
messages::LimitedQueueSnapshot<std::shared_ptr<messages::MessageRef>>
|
||||
getMessagesSnapshot()
|
||||
{
|
||||
return messages.getSnapshot();
|
||||
}
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
|
||||
void layoutMessages();
|
||||
void updateGifEmotes();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
private:
|
||||
messages::LimitedQueue<std::shared_ptr<messages::MessageRef>> messages;
|
||||
void attachChannel(std::shared_ptr<Channel> _channel);
|
||||
void detachChannel(std::shared_ptr<Channel> _channel);
|
||||
|
||||
std::shared_ptr<Channel> channel;
|
||||
QString channelName;
|
||||
messages::LimitedQueue<messages::SharedMessageRef> _messages;
|
||||
|
||||
QFont font;
|
||||
QVBoxLayout vbox;
|
||||
ChatWidgetHeader header;
|
||||
ChatWidgetView view;
|
||||
ChatWidgetInput input;
|
||||
SharedChannel _channel;
|
||||
QString _channelName;
|
||||
|
||||
boost::signals2::connection messageAppendedConnection;
|
||||
boost::signals2::connection messageRemovedConnection;
|
||||
QFont _font;
|
||||
QVBoxLayout _vbox;
|
||||
ChatWidgetHeader _header;
|
||||
ChatWidgetView _view;
|
||||
ChatWidgetInput _input;
|
||||
|
||||
boost::signals2::connection _messageAppendedConnection;
|
||||
boost::signals2::connection _messageRemovedConnection;
|
||||
|
||||
public:
|
||||
void load(const boost::property_tree::ptree &tree);
|
||||
|
||||
@@ -13,90 +13,81 @@ namespace widgets {
|
||||
|
||||
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent)
|
||||
: QWidget()
|
||||
, chatWidget(parent)
|
||||
, dragStart()
|
||||
, dragging(false)
|
||||
, leftLabel()
|
||||
, middleLabel()
|
||||
, rightLabel()
|
||||
, leftMenu(this)
|
||||
, rightMenu(this)
|
||||
, _chatWidget(parent)
|
||||
, _dragStart()
|
||||
, _dragging(false)
|
||||
, _leftLabel()
|
||||
, _middleLabel()
|
||||
, _rightLabel()
|
||||
, _leftMenu(this)
|
||||
, _rightMenu(this)
|
||||
{
|
||||
setFixedHeight(32);
|
||||
|
||||
updateColors();
|
||||
updateChannelText();
|
||||
|
||||
setLayout(&this->hbox);
|
||||
this->hbox.setMargin(0);
|
||||
this->hbox.addWidget(&this->leftLabel);
|
||||
this->hbox.addWidget(&this->middleLabel, 1);
|
||||
this->hbox.addWidget(&this->rightLabel);
|
||||
setLayout(&_hbox);
|
||||
_hbox.setMargin(0);
|
||||
_hbox.addWidget(&_leftLabel);
|
||||
_hbox.addWidget(&_middleLabel, 1);
|
||||
_hbox.addWidget(&_rightLabel);
|
||||
|
||||
// left
|
||||
this->leftLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
this->leftLabel.getLabel().setText(
|
||||
"<img src=':/images/tool_moreCollapser_off16.png' />");
|
||||
_leftLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
_leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
|
||||
|
||||
QObject::connect(&this->leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
||||
QObject::connect(&_leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
||||
&ChatWidgetHeader::leftButtonClicked);
|
||||
|
||||
this->leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()),
|
||||
QKeySequence(tr("Ctrl+T")));
|
||||
this->leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()),
|
||||
QKeySequence(tr("Ctrl+W")));
|
||||
this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
||||
this->leftMenu.addAction("Popup", this, SLOT(menuPopup()));
|
||||
this->leftMenu.addSeparator();
|
||||
this->leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()),
|
||||
QKeySequence(tr("Ctrl+R")));
|
||||
this->leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
|
||||
this->leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
|
||||
this->leftMenu.addAction("Open pop-out player", this,
|
||||
SLOT(menuPopupPlayer()));
|
||||
this->leftMenu.addSeparator();
|
||||
this->leftMenu.addAction("Reload channel emotes", this,
|
||||
SLOT(menuReloadChannelEmotes()));
|
||||
this->leftMenu.addAction("Manual reconnect", this,
|
||||
SLOT(menuManualReconnect()));
|
||||
this->leftMenu.addSeparator();
|
||||
this->leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
||||
_leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()), QKeySequence(tr("Ctrl+T")));
|
||||
_leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()), QKeySequence(tr("Ctrl+W")));
|
||||
_leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
||||
_leftMenu.addAction("Popup", this, SLOT(menuPopup()));
|
||||
_leftMenu.addSeparator();
|
||||
_leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()),
|
||||
QKeySequence(tr("Ctrl+R")));
|
||||
_leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
|
||||
_leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
|
||||
_leftMenu.addAction("Open pop-out player", this, SLOT(menuPopupPlayer()));
|
||||
_leftMenu.addSeparator();
|
||||
_leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
|
||||
_leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
|
||||
_leftMenu.addSeparator();
|
||||
_leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
||||
|
||||
// middle
|
||||
this->middleLabel.setAlignment(Qt::AlignCenter);
|
||||
_middleLabel.setAlignment(Qt::AlignCenter);
|
||||
|
||||
connect(&this->middleLabel, &SignalLabel::mouseDoubleClick, this,
|
||||
connect(&_middleLabel, &SignalLabel::mouseDoubleClick, this,
|
||||
&ChatWidgetHeader::mouseDoubleClickEvent);
|
||||
// connect(&this->middleLabel, &SignalLabel::mouseDown, this,
|
||||
// &ChatWidgetHeader::mouseDoubleClickEvent);
|
||||
|
||||
// right
|
||||
this->rightLabel.setMinimumWidth(height());
|
||||
this->rightLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
this->rightLabel.getLabel().setText("ayy");
|
||||
_rightLabel.setMinimumWidth(height());
|
||||
_rightLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
_rightLabel.getLabel().setText("ayy");
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::updateColors()
|
||||
void ChatWidgetHeader::updateColors()
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text);
|
||||
|
||||
this->leftLabel.setPalette(palette);
|
||||
this->middleLabel.setPalette(palette);
|
||||
this->rightLabel.setPalette(palette);
|
||||
_leftLabel.setPalette(palette);
|
||||
_middleLabel.setPalette(palette);
|
||||
_rightLabel.setPalette(palette);
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::updateChannelText()
|
||||
void ChatWidgetHeader::updateChannelText()
|
||||
{
|
||||
const QString &c = this->chatWidget->getChannelName();
|
||||
const QString &c = _chatWidget->getChannelName();
|
||||
|
||||
this->middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
|
||||
_middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::paintEvent(QPaintEvent *)
|
||||
void ChatWidgetHeader::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -105,21 +96,19 @@ ChatWidgetHeader::paintEvent(QPaintEvent *)
|
||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::mousePressEvent(QMouseEvent *event)
|
||||
void ChatWidgetHeader::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
this->dragging = true;
|
||||
_dragging = true;
|
||||
|
||||
this->dragStart = event->pos();
|
||||
_dragStart = event->pos();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
||||
void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->dragging) {
|
||||
if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
|
||||
std::abs(this->dragStart.y() - event->pos().y()) > 12) {
|
||||
auto chatWidget = this->chatWidget;
|
||||
if (_dragging) {
|
||||
if (std::abs(_dragStart.x() - event->pos().x()) > 12 ||
|
||||
std::abs(_dragStart.y() - event->pos().y()) > 12) {
|
||||
auto chatWidget = _chatWidget;
|
||||
auto page = static_cast<NotebookPage *>(chatWidget->parentWidget());
|
||||
|
||||
if (page != NULL) {
|
||||
@@ -149,73 +138,58 @@ ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
this->chatWidget->showChangeChannelPopup();
|
||||
_chatWidget->showChangeChannelPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::leftButtonClicked()
|
||||
void ChatWidgetHeader::leftButtonClicked()
|
||||
{
|
||||
this->leftMenu.move(
|
||||
this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
|
||||
this->leftMenu.show();
|
||||
_leftMenu.move(_leftLabel.mapToGlobal(QPoint(0, _leftLabel.height())));
|
||||
_leftMenu.show();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::rightButtonClicked()
|
||||
void ChatWidgetHeader::rightButtonClicked()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeader::menuAddSplit()
|
||||
void ChatWidgetHeader::menuAddSplit()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuCloseSplit()
|
||||
void ChatWidgetHeader::menuCloseSplit()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuMoveSplit()
|
||||
void ChatWidgetHeader::menuMoveSplit()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuPopup()
|
||||
void ChatWidgetHeader::menuPopup()
|
||||
{
|
||||
auto widget = new ChatWidget();
|
||||
widget->setChannelName(this->chatWidget->getChannelName());
|
||||
widget->setChannelName(_chatWidget->getChannelName());
|
||||
widget->show();
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuChangeChannel()
|
||||
void ChatWidgetHeader::menuChangeChannel()
|
||||
{
|
||||
this->chatWidget->showChangeChannelPopup();
|
||||
_chatWidget->showChangeChannelPopup();
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuClearChat()
|
||||
void ChatWidgetHeader::menuClearChat()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuOpenChannel()
|
||||
void ChatWidgetHeader::menuOpenChannel()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuPopupPlayer()
|
||||
void ChatWidgetHeader::menuPopupPlayer()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuReloadChannelEmotes()
|
||||
void ChatWidgetHeader::menuReloadChannelEmotes()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuManualReconnect()
|
||||
void ChatWidgetHeader::menuManualReconnect()
|
||||
{
|
||||
}
|
||||
void
|
||||
ChatWidgetHeader::menuShowChangelog()
|
||||
void ChatWidgetHeader::menuShowChangelog()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -24,10 +24,9 @@ class ChatWidgetHeader : public QWidget
|
||||
public:
|
||||
explicit ChatWidgetHeader(ChatWidget *parent);
|
||||
|
||||
ChatWidget *
|
||||
getChatWidget()
|
||||
ChatWidget *getChatWidget()
|
||||
{
|
||||
return chatWidget;
|
||||
return _chatWidget;
|
||||
}
|
||||
|
||||
void updateColors();
|
||||
@@ -40,19 +39,19 @@ protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
ChatWidget *chatWidget;
|
||||
ChatWidget *_chatWidget;
|
||||
|
||||
QPoint dragStart;
|
||||
bool dragging;
|
||||
QPoint _dragStart;
|
||||
bool _dragging;
|
||||
|
||||
QHBoxLayout hbox;
|
||||
QHBoxLayout _hbox;
|
||||
|
||||
ChatWidgetHeaderButton leftLabel;
|
||||
SignalLabel middleLabel;
|
||||
ChatWidgetHeaderButton rightLabel;
|
||||
ChatWidgetHeaderButton _leftLabel;
|
||||
SignalLabel _middleLabel;
|
||||
ChatWidgetHeaderButton _rightLabel;
|
||||
|
||||
QMenu leftMenu;
|
||||
QMenu rightMenu;
|
||||
QMenu _leftMenu;
|
||||
QMenu _rightMenu;
|
||||
|
||||
void leftButtonClicked();
|
||||
void rightButtonClicked();
|
||||
|
||||
@@ -9,59 +9,55 @@ namespace widgets {
|
||||
|
||||
ChatWidgetHeaderButton::ChatWidgetHeaderButton(int spacing)
|
||||
: QWidget()
|
||||
, hbox()
|
||||
, label()
|
||||
, mouseOver(false)
|
||||
, mouseDown(false)
|
||||
, _hbox()
|
||||
, _label()
|
||||
, _mouseOver(false)
|
||||
, _mouseDown(false)
|
||||
{
|
||||
setLayout(&hbox);
|
||||
setLayout(&_hbox);
|
||||
|
||||
label.setAlignment(Qt::AlignCenter);
|
||||
_label.setAlignment(Qt::AlignCenter);
|
||||
|
||||
hbox.setMargin(0);
|
||||
hbox.addSpacing(spacing);
|
||||
hbox.addWidget(&this->label);
|
||||
hbox.addSpacing(spacing);
|
||||
_hbox.setMargin(0);
|
||||
_hbox.addSpacing(spacing);
|
||||
_hbox.addWidget(&_label);
|
||||
_hbox.addSpacing(spacing);
|
||||
|
||||
QObject::connect(&this->label, &SignalLabel::mouseUp, this,
|
||||
QObject::connect(&_label, &SignalLabel::mouseUp, this,
|
||||
&ChatWidgetHeaderButton::labelMouseUp);
|
||||
QObject::connect(&this->label, &SignalLabel::mouseDown, this,
|
||||
QObject::connect(&_label, &SignalLabel::mouseDown, this,
|
||||
&ChatWidgetHeaderButton::labelMouseDown);
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
||||
void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
QBrush brush(ColorScheme::getInstance().IsLightTheme
|
||||
? QColor(0, 0, 0, 32)
|
||||
: QColor(255, 255, 255, 32));
|
||||
QBrush brush(ColorScheme::getInstance().IsLightTheme ? QColor(0, 0, 0, 32)
|
||||
: QColor(255, 255, 255, 32));
|
||||
|
||||
if (this->mouseDown) {
|
||||
if (_mouseDown) {
|
||||
painter.fillRect(rect(), brush);
|
||||
}
|
||||
|
||||
if (this->mouseOver) {
|
||||
if (_mouseOver) {
|
||||
painter.fillRect(rect(), brush);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
||||
void ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
this->mouseDown = true;
|
||||
_mouseDown = true;
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
void ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
this->mouseDown = false;
|
||||
_mouseDown = false;
|
||||
|
||||
update();
|
||||
|
||||
@@ -69,36 +65,32 @@ ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::enterEvent(QEvent *)
|
||||
void ChatWidgetHeaderButton::enterEvent(QEvent *)
|
||||
{
|
||||
this->mouseOver = true;
|
||||
_mouseOver = true;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::leaveEvent(QEvent *)
|
||||
void ChatWidgetHeaderButton::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOver = false;
|
||||
_mouseOver = false;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::labelMouseUp()
|
||||
void ChatWidgetHeaderButton::labelMouseUp()
|
||||
{
|
||||
this->mouseDown = false;
|
||||
_mouseDown = false;
|
||||
|
||||
update();
|
||||
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetHeaderButton::labelMouseDown()
|
||||
void ChatWidgetHeaderButton::labelMouseDown()
|
||||
{
|
||||
this->mouseDown = true;
|
||||
_mouseDown = true;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@ class ChatWidgetHeaderButton : public QWidget
|
||||
public:
|
||||
explicit ChatWidgetHeaderButton(int spacing = 6);
|
||||
|
||||
SignalLabel &
|
||||
getLabel()
|
||||
SignalLabel &getLabel()
|
||||
{
|
||||
return label;
|
||||
return _label;
|
||||
}
|
||||
|
||||
signals:
|
||||
@@ -37,11 +36,11 @@ protected:
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QHBoxLayout hbox;
|
||||
SignalLabel label;
|
||||
QHBoxLayout _hbox;
|
||||
SignalLabel _label;
|
||||
|
||||
bool mouseOver;
|
||||
bool mouseDown;
|
||||
bool _mouseOver;
|
||||
bool _mouseDown;
|
||||
|
||||
void labelMouseUp();
|
||||
void labelMouseDown();
|
||||
|
||||
+41
-46
@@ -2,7 +2,7 @@
|
||||
#include "chatwidget.h"
|
||||
#include "colorscheme.h"
|
||||
#include "ircmanager.h"
|
||||
#include "settings.h"
|
||||
#include "settingsmanager.h"
|
||||
|
||||
#include <QCompleter>
|
||||
#include <QPainter>
|
||||
@@ -12,44 +12,43 @@ namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetInput::ChatWidgetInput(ChatWidget *widget)
|
||||
: chatWidget(widget)
|
||||
, hbox()
|
||||
, vbox()
|
||||
, editContainer()
|
||||
, edit()
|
||||
, textLengthLabel()
|
||||
, emotesLabel(0)
|
||||
: _chatWidget(widget)
|
||||
, _hbox()
|
||||
, _vbox()
|
||||
, _editContainer()
|
||||
, _edit()
|
||||
, _textLengthLabel()
|
||||
, _emotesLabel(0)
|
||||
{
|
||||
this->setLayout(&this->hbox);
|
||||
this->setMaximumHeight(150);
|
||||
this->hbox.setMargin(4);
|
||||
setLayout(&_hbox);
|
||||
setMaximumHeight(150);
|
||||
_hbox.setMargin(4);
|
||||
|
||||
this->hbox.addLayout(&this->editContainer);
|
||||
this->hbox.addLayout(&this->vbox);
|
||||
_hbox.addLayout(&_editContainer);
|
||||
_hbox.addLayout(&_vbox);
|
||||
|
||||
this->editContainer.addWidget(&this->edit);
|
||||
this->editContainer.setMargin(4);
|
||||
_editContainer.addWidget(&_edit);
|
||||
_editContainer.setMargin(4);
|
||||
|
||||
this->vbox.addWidget(&this->textLengthLabel);
|
||||
this->vbox.addStretch(1);
|
||||
this->vbox.addWidget(&this->emotesLabel);
|
||||
_vbox.addWidget(&_textLengthLabel);
|
||||
_vbox.addStretch(1);
|
||||
_vbox.addWidget(&_emotesLabel);
|
||||
|
||||
this->textLengthLabel.setText("100");
|
||||
this->textLengthLabel.setAlignment(Qt::AlignRight);
|
||||
this->emotesLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
this->emotesLabel.getLabel().setText(
|
||||
_textLengthLabel.setText("100");
|
||||
_textLengthLabel.setAlignment(Qt::AlignRight);
|
||||
_emotesLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
_emotesLabel.getLabel().setText(
|
||||
"<img src=':/images/Emoji_Color_1F60A_19.png' width='12' height='12' "
|
||||
"/>");
|
||||
|
||||
QObject::connect(&edit, &ResizingTextEdit::textChanged, this,
|
||||
QObject::connect(&_edit, &ResizingTextEdit::textChanged, this,
|
||||
&ChatWidgetInput::editTextChanged);
|
||||
|
||||
// QObject::connect(&edit, &ResizingTextEdit::keyPressEvent, this,
|
||||
// &ChatWidgetInput::editKeyPressed);
|
||||
|
||||
this->refreshTheme();
|
||||
this->setMessageLengthVisisble(
|
||||
Settings::getInstance().showMessageLength.get());
|
||||
refreshTheme();
|
||||
setMessageLengthVisisble(SettingsManager::getInstance().showMessageLength.get());
|
||||
|
||||
QStringList list;
|
||||
list.append("asd");
|
||||
@@ -57,20 +56,20 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *widget)
|
||||
list.append("asdg");
|
||||
list.append("asdh");
|
||||
|
||||
QCompleter *completer = new QCompleter(list, &edit);
|
||||
QCompleter *completer = new QCompleter(list, &_edit);
|
||||
|
||||
completer->setWidget(&edit);
|
||||
completer->setWidget(&_edit);
|
||||
|
||||
this->edit.keyPressed.connect([this, completer](QKeyEvent *event) {
|
||||
_edit.keyPressed.connect([this, completer](QKeyEvent *event) {
|
||||
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
||||
auto ptr = this->chatWidget->getChannel();
|
||||
auto ptr = _chatWidget->getChannel();
|
||||
Channel *c = ptr.get();
|
||||
|
||||
if (c != nullptr) {
|
||||
IrcManager::send("PRIVMSG #" + c->getName() + ": " +
|
||||
this->edit.toPlainText());
|
||||
IrcManager::getInstance().send("PRIVMSG #" + c->getName() + ": " +
|
||||
_edit.toPlainText());
|
||||
event->accept();
|
||||
this->edit.setText(QString());
|
||||
_edit.setText(QString());
|
||||
}
|
||||
}
|
||||
// else {
|
||||
@@ -97,20 +96,18 @@ ChatWidgetInput::~ChatWidgetInput()
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetInput::refreshTheme()
|
||||
void ChatWidgetInput::refreshTheme()
|
||||
{
|
||||
QPalette palette;
|
||||
|
||||
palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text);
|
||||
|
||||
this->textLengthLabel.setPalette(palette);
|
||||
_textLengthLabel.setPalette(palette);
|
||||
|
||||
edit.setStyleSheet(ColorScheme::getInstance().InputStyleSheet);
|
||||
_edit.setStyleSheet(ColorScheme::getInstance().InputStyleSheet);
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetInput::editTextChanged()
|
||||
void ChatWidgetInput::editTextChanged()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -124,8 +121,7 @@ ChatWidgetInput::editTextChanged()
|
||||
// }
|
||||
//}
|
||||
|
||||
void
|
||||
ChatWidgetInput::paintEvent(QPaintEvent *)
|
||||
void ChatWidgetInput::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -134,13 +130,12 @@ ChatWidgetInput::paintEvent(QPaintEvent *)
|
||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetInput::resizeEvent(QResizeEvent *)
|
||||
void ChatWidgetInput::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
if (height() == this->maximumHeight()) {
|
||||
edit.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
if (height() == maximumHeight()) {
|
||||
_edit.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
} else {
|
||||
edit.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
_edit.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,21 +31,20 @@ protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
private:
|
||||
ChatWidget *chatWidget;
|
||||
ChatWidget *_chatWidget;
|
||||
|
||||
QHBoxLayout hbox;
|
||||
QVBoxLayout vbox;
|
||||
QHBoxLayout editContainer;
|
||||
ResizingTextEdit edit;
|
||||
QLabel textLengthLabel;
|
||||
ChatWidgetHeaderButton emotesLabel;
|
||||
QHBoxLayout _hbox;
|
||||
QVBoxLayout _vbox;
|
||||
QHBoxLayout _editContainer;
|
||||
ResizingTextEdit _edit;
|
||||
QLabel _textLengthLabel;
|
||||
ChatWidgetHeaderButton _emotesLabel;
|
||||
|
||||
private slots:
|
||||
void refreshTheme();
|
||||
void
|
||||
setMessageLengthVisisble(bool value)
|
||||
void setMessageLengthVisisble(bool value)
|
||||
{
|
||||
this->textLengthLabel.setHidden(!value);
|
||||
_textLengthLabel.setHidden(!value);
|
||||
}
|
||||
void editTextChanged();
|
||||
// void editKeyPressed(QKeyEvent *event);
|
||||
|
||||
+132
-78
@@ -1,9 +1,10 @@
|
||||
#include "widgets/chatwidgetview.h"
|
||||
#include "channels.h"
|
||||
#include "channelmanager.h"
|
||||
#include "colorscheme.h"
|
||||
#include "messages/message.h"
|
||||
#include "messages/wordpart.h"
|
||||
#include "settings.h"
|
||||
#include "settingsmanager.h"
|
||||
#include "ui_userpopup.h"
|
||||
#include "widgets/chatwidget.h"
|
||||
|
||||
#include <math.h>
|
||||
@@ -18,46 +19,46 @@ namespace widgets {
|
||||
|
||||
ChatWidgetView::ChatWidgetView(ChatWidget *parent)
|
||||
: QWidget()
|
||||
, chatWidget(parent)
|
||||
, scrollbar(this)
|
||||
, onlyUpdateEmotes(false)
|
||||
, _chatWidget(parent)
|
||||
, _scrollbar(this)
|
||||
, _userPopupWidget(_chatWidget->getChannel())
|
||||
, _onlyUpdateEmotes(false)
|
||||
, _mouseDown(false)
|
||||
, _lastPressPosition()
|
||||
{
|
||||
this->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
this->scrollbar.setSmallChange(5);
|
||||
_scrollbar.setSmallChange(5);
|
||||
this->setMouseTracking(true);
|
||||
|
||||
QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged,
|
||||
this, &ChatWidgetView::wordTypeMaskChanged);
|
||||
QObject::connect(&SettingsManager::getInstance(), &SettingsManager::wordTypeMaskChanged, this,
|
||||
&ChatWidgetView::wordTypeMaskChanged);
|
||||
|
||||
this->scrollbar.getCurrentValueChanged().connect([this] { update(); });
|
||||
_scrollbar.getCurrentValueChanged().connect([this] { update(); });
|
||||
}
|
||||
|
||||
ChatWidgetView::~ChatWidgetView()
|
||||
{
|
||||
QObject::disconnect(&Settings::getInstance(),
|
||||
&Settings::wordTypeMaskChanged, this,
|
||||
&ChatWidgetView::wordTypeMaskChanged);
|
||||
QObject::disconnect(&SettingsManager::getInstance(), &SettingsManager::wordTypeMaskChanged,
|
||||
this, &ChatWidgetView::wordTypeMaskChanged);
|
||||
}
|
||||
|
||||
bool
|
||||
ChatWidgetView::layoutMessages()
|
||||
bool ChatWidgetView::layoutMessages()
|
||||
{
|
||||
auto messages = chatWidget->getMessagesSnapshot();
|
||||
auto messages = _chatWidget->getMessagesSnapshot();
|
||||
|
||||
if (messages.getLength() == 0) {
|
||||
this->scrollbar.setVisible(false);
|
||||
_scrollbar.setVisible(false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool showScrollbar = false, redraw = false;
|
||||
|
||||
int start = this->scrollbar.getCurrentValue();
|
||||
int start = _scrollbar.getCurrentValue();
|
||||
|
||||
// layout the visible messages in the view
|
||||
if (messages.getLength() > start) {
|
||||
int y = -(messages[start].get()->getHeight() *
|
||||
(fmod(this->scrollbar.getCurrentValue(), 1)));
|
||||
int y = -(messages[start].get()->getHeight() * (fmod(_scrollbar.getCurrentValue(), 1)));
|
||||
|
||||
for (int i = start; i < messages.getLength(); ++i) {
|
||||
auto messagePtr = messages[i];
|
||||
@@ -84,39 +85,47 @@ ChatWidgetView::layoutMessages()
|
||||
h -= message->getHeight();
|
||||
|
||||
if (h < 0) {
|
||||
this->scrollbar.setLargeChange((messages.getLength() - i) +
|
||||
(qreal)h / message->getHeight());
|
||||
this->scrollbar.setDesiredValue(this->scrollbar.getDesiredValue());
|
||||
_scrollbar.setLargeChange((messages.getLength() - i) + (qreal)h / message->getHeight());
|
||||
_scrollbar.setDesiredValue(_scrollbar.getDesiredValue());
|
||||
|
||||
showScrollbar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->scrollbar.setVisible(showScrollbar);
|
||||
_scrollbar.setVisible(showScrollbar);
|
||||
|
||||
if (!showScrollbar) {
|
||||
this->scrollbar.setDesiredValue(0);
|
||||
_scrollbar.setDesiredValue(0);
|
||||
}
|
||||
|
||||
this->scrollbar.setMaximum(messages.getLength());
|
||||
_scrollbar.setMaximum(messages.getLength());
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetView::resizeEvent(QResizeEvent *)
|
||||
void ChatWidgetView::updateGifEmotes()
|
||||
{
|
||||
this->scrollbar.resize(this->scrollbar.width(), height());
|
||||
this->scrollbar.move(width() - this->scrollbar.width(), 0);
|
||||
_onlyUpdateEmotes = true;
|
||||
this->update();
|
||||
}
|
||||
|
||||
ScrollBar *ChatWidgetView::getScrollbar()
|
||||
{
|
||||
return &_scrollbar;
|
||||
}
|
||||
|
||||
void ChatWidgetView::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
_scrollbar.resize(_scrollbar.width(), height());
|
||||
_scrollbar.move(width() - _scrollbar.width(), 0);
|
||||
|
||||
layoutMessages();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
void ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter _painter(this);
|
||||
|
||||
@@ -125,10 +134,10 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
ColorScheme &scheme = ColorScheme::getInstance();
|
||||
|
||||
// only update gif emotes
|
||||
if (onlyUpdateEmotes) {
|
||||
onlyUpdateEmotes = false;
|
||||
if (_onlyUpdateEmotes) {
|
||||
_onlyUpdateEmotes = false;
|
||||
|
||||
for (GifEmoteData &item : this->gifEmotes) {
|
||||
for (GifEmoteData &item : _gifEmotes) {
|
||||
_painter.fillRect(item.rect, scheme.ChatBackground);
|
||||
|
||||
_painter.drawPixmap(item.rect, *item.image->getPixmap());
|
||||
@@ -138,7 +147,7 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
|
||||
// update all messages
|
||||
gifEmotes.clear();
|
||||
_gifEmotes.clear();
|
||||
|
||||
_painter.fillRect(rect(), scheme.ChatBackground);
|
||||
|
||||
@@ -175,16 +184,15 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
|
||||
painter.fillRect(QRect(0, 9, 500, 2), QColor(0, 0, 0));*/
|
||||
|
||||
auto messages = chatWidget->getMessagesSnapshot();
|
||||
auto messages = _chatWidget->getMessagesSnapshot();
|
||||
|
||||
int start = this->scrollbar.getCurrentValue();
|
||||
int start = _scrollbar.getCurrentValue();
|
||||
|
||||
if (start >= messages.getLength()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int y = -(messages[start].get()->getHeight() *
|
||||
(fmod(this->scrollbar.getCurrentValue(), 1)));
|
||||
int y = -(messages[start].get()->getHeight() * (fmod(_scrollbar.getCurrentValue(), 1)));
|
||||
|
||||
for (int i = start; i < messages.getLength(); ++i) {
|
||||
messages::MessageRef *messageRef = messages[i].get();
|
||||
@@ -205,20 +213,17 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
QPainter painter(buffer);
|
||||
painter.fillRect(buffer->rect(), scheme.ChatBackground);
|
||||
|
||||
for (messages::WordPart const &wordPart :
|
||||
messageRef->getWordParts()) {
|
||||
for (messages::WordPart const &wordPart : messageRef->getWordParts()) {
|
||||
// image
|
||||
if (wordPart.getWord().isImage()) {
|
||||
messages::LazyLoadedImage &lli =
|
||||
wordPart.getWord().getImage();
|
||||
messages::LazyLoadedImage &lli = wordPart.getWord().getImage();
|
||||
|
||||
const QPixmap *image = lli.getPixmap();
|
||||
|
||||
if (image != NULL) {
|
||||
painter.drawPixmap(
|
||||
QRect(wordPart.getX(), wordPart.getY(),
|
||||
wordPart.getWidth(), wordPart.getHeight()),
|
||||
*image);
|
||||
painter.drawPixmap(QRect(wordPart.getX(), wordPart.getY(),
|
||||
wordPart.getWidth(), wordPart.getHeight()),
|
||||
*image);
|
||||
}
|
||||
}
|
||||
// text
|
||||
@@ -230,10 +235,8 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
painter.setPen(color);
|
||||
painter.setFont(wordPart.getWord().getFont());
|
||||
|
||||
painter.drawText(
|
||||
QRectF(wordPart.getX(), wordPart.getY(), 10000, 10000),
|
||||
wordPart.getText(),
|
||||
QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
painter.drawText(QRectF(wordPart.getX(), wordPart.getY(), 10000, 10000),
|
||||
wordPart.getText(), QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,12 +251,12 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
if (lli.getAnimated()) {
|
||||
GifEmoteData data;
|
||||
data.image = &lli;
|
||||
QRect rect(wordPart.getX(), wordPart.getY() + y,
|
||||
wordPart.getWidth(), wordPart.getHeight());
|
||||
QRect rect(wordPart.getX(), wordPart.getY() + y, wordPart.getWidth(),
|
||||
wordPart.getHeight());
|
||||
|
||||
data.rect = rect;
|
||||
|
||||
gifEmotes.push_back(data);
|
||||
_gifEmotes.push_back(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,27 +272,24 @@ ChatWidgetView::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
for (GifEmoteData &item : this->gifEmotes) {
|
||||
for (GifEmoteData &item : _gifEmotes) {
|
||||
_painter.fillRect(item.rect, scheme.ChatBackground);
|
||||
|
||||
_painter.drawPixmap(item.rect, *item.image->getPixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetView::wheelEvent(QWheelEvent *event)
|
||||
void ChatWidgetView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (this->scrollbar.isVisible()) {
|
||||
this->scrollbar.setDesiredValue(
|
||||
this->scrollbar.getDesiredValue() -
|
||||
event->delta() / 10.0 *
|
||||
Settings::getInstance().mouseScrollMultiplier.get(),
|
||||
if (_scrollbar.isVisible()) {
|
||||
_scrollbar.setDesiredValue(
|
||||
_scrollbar.getDesiredValue() -
|
||||
event->delta() / 10.0 * SettingsManager::getInstance().mouseScrollMultiplier.get(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatWidgetView::mouseMoveEvent(QMouseEvent *event)
|
||||
void ChatWidgetView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
std::shared_ptr<messages::MessageRef> message;
|
||||
QPoint relativePos;
|
||||
@@ -311,32 +311,86 @@ ChatWidgetView::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
int index = message->getSelectionIndex(relativePos);
|
||||
|
||||
qDebug() << index;
|
||||
|
||||
if (hoverWord.getLink().getIsValid()) {
|
||||
this->setCursor(Qt::PointingHandCursor);
|
||||
qDebug() << hoverWord.getLink().getValue();
|
||||
} else {
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ChatWidgetView::tryGetMessageAt(QPoint p,
|
||||
std::shared_ptr<messages::MessageRef> &_message,
|
||||
QPoint &relativePos)
|
||||
void ChatWidgetView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
auto messages = chatWidget->getMessagesSnapshot();
|
||||
_mouseDown = true;
|
||||
_lastPressPosition = event->screenPos();
|
||||
}
|
||||
|
||||
int start = this->scrollbar.getCurrentValue();
|
||||
static float distanceBetweenPoints(const QPointF &p1, const QPointF &p2)
|
||||
{
|
||||
QPointF tmp = p1 - p2;
|
||||
|
||||
float distance = 0.f;
|
||||
distance += tmp.x() * tmp.x();
|
||||
distance += tmp.y() * tmp.y();
|
||||
|
||||
return std::sqrt(distance);
|
||||
}
|
||||
|
||||
void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!_mouseDown) {
|
||||
// We didn't grab the mouse press, so we shouldn't be handling the mouse
|
||||
// release
|
||||
return;
|
||||
}
|
||||
|
||||
_mouseDown = false;
|
||||
|
||||
float distance = distanceBetweenPoints(_lastPressPosition, event->screenPos());
|
||||
|
||||
qDebug() << "Distance: " << distance;
|
||||
|
||||
if (fabsf(distance) > 15.f) {
|
||||
// It wasn't a proper click, so we don't care about that here
|
||||
return;
|
||||
}
|
||||
|
||||
// If you clicked and released less than X pixels away, it counts
|
||||
// as a click!
|
||||
|
||||
// show user thing pajaW
|
||||
|
||||
std::shared_ptr<messages::MessageRef> message;
|
||||
QPoint relativePos;
|
||||
|
||||
if (!tryGetMessageAt(event->pos(), message, relativePos)) {
|
||||
// No message at clicked position
|
||||
_userPopupWidget.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
auto _message = message->getMessage();
|
||||
auto user = _message->getUserName();
|
||||
|
||||
qDebug() << "Clicked " << user << "s message";
|
||||
|
||||
_userPopupWidget.setName(user);
|
||||
_userPopupWidget.move(event->screenPos().toPoint());
|
||||
_userPopupWidget.show();
|
||||
_userPopupWidget.setFocus();
|
||||
}
|
||||
|
||||
bool ChatWidgetView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &_message,
|
||||
QPoint &relativePos)
|
||||
{
|
||||
auto messages = _chatWidget->getMessagesSnapshot();
|
||||
|
||||
int start = _scrollbar.getCurrentValue();
|
||||
|
||||
if (start >= messages.getLength()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int y = -(messages[start].get()->getHeight() *
|
||||
(fmod(this->scrollbar.getCurrentValue(), 1))) +
|
||||
12;
|
||||
int y = -(messages[start].get()->getHeight() * (fmod(_scrollbar.getCurrentValue(), 1))) + 12;
|
||||
|
||||
for (int i = start; i < messages.getLength(); ++i) {
|
||||
auto message = messages[i];
|
||||
@@ -352,5 +406,5 @@ ChatWidgetView::tryGetMessageAt(QPoint p,
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
+19
-18
@@ -6,6 +6,7 @@
|
||||
#include "messages/messageref.h"
|
||||
#include "messages/word.h"
|
||||
#include "widgets/scrollbar.h"
|
||||
#include "widgets/userpopupwidget.h"
|
||||
|
||||
#include <QPaintEvent>
|
||||
#include <QScroller>
|
||||
@@ -18,20 +19,14 @@ class ChatWidget;
|
||||
|
||||
class ChatWidgetView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChatWidgetView(ChatWidget *parent);
|
||||
~ChatWidgetView();
|
||||
|
||||
bool layoutMessages();
|
||||
|
||||
void
|
||||
updateGifEmotes()
|
||||
{
|
||||
this->onlyUpdateEmotes = true;
|
||||
this->update();
|
||||
}
|
||||
void updateGifEmotes();
|
||||
ScrollBar *getScrollbar();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
@@ -40,9 +35,10 @@ protected:
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
bool tryGetMessageAt(QPoint p,
|
||||
std::shared_ptr<messages::MessageRef> &message,
|
||||
bool tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &message,
|
||||
QPoint &relativePos);
|
||||
|
||||
private:
|
||||
@@ -51,22 +47,27 @@ private:
|
||||
QRect rect;
|
||||
};
|
||||
|
||||
std::vector<GifEmoteData> gifEmotes;
|
||||
std::vector<GifEmoteData> _gifEmotes;
|
||||
|
||||
ChatWidget *chatWidget;
|
||||
ChatWidget *_chatWidget;
|
||||
|
||||
ScrollBar scrollbar;
|
||||
bool onlyUpdateEmotes;
|
||||
ScrollBar _scrollbar;
|
||||
|
||||
UserPopupWidget _userPopupWidget;
|
||||
bool _onlyUpdateEmotes;
|
||||
|
||||
// Mouse event variables
|
||||
bool _mouseDown;
|
||||
QPointF _lastPressPosition;
|
||||
|
||||
private slots:
|
||||
void
|
||||
wordTypeMaskChanged()
|
||||
void wordTypeMaskChanged()
|
||||
{
|
||||
layoutMessages();
|
||||
update();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
#endif // CHATVIEW_H
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
#include "fancybutton.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
FancyButton::FancyButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, _selected()
|
||||
, _mouseOver()
|
||||
, _mouseDown()
|
||||
, _mousePos()
|
||||
, _hoverMultiplier()
|
||||
, _effectTimer()
|
||||
, _mouseEffectColor(QColor(255, 255, 255))
|
||||
|
||||
{
|
||||
connect(&_effectTimer, &QTimer::timeout, this, &FancyButton::onMouseEffectTimeout);
|
||||
|
||||
_effectTimer.setInterval(20);
|
||||
_effectTimer.start();
|
||||
}
|
||||
|
||||
void FancyButton::setMouseEffectColor(QColor color)
|
||||
{
|
||||
_mouseEffectColor = color;
|
||||
}
|
||||
|
||||
void FancyButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter;
|
||||
|
||||
fancyPaint(painter);
|
||||
}
|
||||
|
||||
void FancyButton::fancyPaint(QPainter &painter)
|
||||
{
|
||||
QColor &c = _mouseEffectColor;
|
||||
|
||||
if (_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)));
|
||||
|
||||
painter.fillRect(this->rect(), gradient);
|
||||
}
|
||||
|
||||
for (auto effect : _clickEffects) {
|
||||
QRadialGradient gradient(effect.position.x(), effect.position.y(),
|
||||
effect.progress * (float)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 FancyButton::enterEvent(QEvent *)
|
||||
{
|
||||
_mouseOver = true;
|
||||
}
|
||||
|
||||
void FancyButton::leaveEvent(QEvent *)
|
||||
{
|
||||
_mouseOver = false;
|
||||
}
|
||||
|
||||
void FancyButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
_clickEffects.push_back(ClickEffect(event->pos()));
|
||||
|
||||
_mouseDown = true;
|
||||
}
|
||||
|
||||
void FancyButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
_mouseDown = false;
|
||||
}
|
||||
|
||||
void FancyButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
_mousePos = event->pos();
|
||||
}
|
||||
|
||||
void FancyButton::onMouseEffectTimeout()
|
||||
{
|
||||
bool performUpdate = false;
|
||||
|
||||
if (_selected) {
|
||||
if (_hoverMultiplier != 0) {
|
||||
_hoverMultiplier = std::max(0.0, _hoverMultiplier - 0.1);
|
||||
performUpdate = true;
|
||||
}
|
||||
} else if (_mouseOver) {
|
||||
if (_hoverMultiplier != 1) {
|
||||
_hoverMultiplier = std::min(1.0, _hoverMultiplier + 0.5);
|
||||
performUpdate = true;
|
||||
}
|
||||
} else {
|
||||
if (_hoverMultiplier != 0) {
|
||||
_hoverMultiplier = std::max(0.0, _hoverMultiplier - 0.3);
|
||||
performUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_clickEffects.size() != 0) {
|
||||
performUpdate = true;
|
||||
|
||||
for (auto it = _clickEffects.begin(); it != _clickEffects.end();) {
|
||||
(*it).progress += _mouseDown ? 0.02 : 0.07;
|
||||
|
||||
if ((*it).progress >= 1.0) {
|
||||
it = _clickEffects.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (performUpdate) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef FANCYBUTTON_H
|
||||
#define FANCYBUTTON_H
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPoint>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
class FancyButton : public QWidget
|
||||
{
|
||||
struct ClickEffect {
|
||||
float progress;
|
||||
QPoint position;
|
||||
|
||||
ClickEffect(QPoint position)
|
||||
: progress()
|
||||
, position(position)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
FancyButton(QWidget *parent = nullptr);
|
||||
|
||||
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;
|
||||
|
||||
void fancyPaint(QPainter &painter);
|
||||
|
||||
private:
|
||||
bool _selected;
|
||||
bool _mouseOver;
|
||||
bool _mouseDown;
|
||||
QPoint _mousePos;
|
||||
float _hoverMultiplier;
|
||||
QTimer _effectTimer;
|
||||
std::vector<ClickEffect> _clickEffects;
|
||||
QColor _mouseEffectColor;
|
||||
|
||||
void onMouseEffectTimeout();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // FANCYBUTTON_H
|
||||
+53
-31
@@ -1,24 +1,46 @@
|
||||
#include "widgets/mainwindow.h"
|
||||
#include "colorscheme.h"
|
||||
#include "settingsmanager.h"
|
||||
#include "widgets/chatwidget.h"
|
||||
#include "widgets/notebook.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPalette>
|
||||
#include <QVBoxLayout>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#ifdef USEWINSDK
|
||||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, notebook(this)
|
||||
: QWidget(parent)
|
||||
, _notebook(this)
|
||||
, _loaded(false)
|
||||
, _titleBar()
|
||||
{
|
||||
setCentralWidget(&this->notebook);
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
// add titlebar
|
||||
// if (SettingsManager::getInstance().useCustomWindowFrame.get()) {
|
||||
// layout->addWidget(&_titleBar);
|
||||
// }
|
||||
|
||||
layout->addWidget(&_notebook);
|
||||
setLayout(layout);
|
||||
|
||||
// set margin
|
||||
// if (SettingsManager::getInstance().useCustomWindowFrame.get()) {
|
||||
// layout->setMargin(1);
|
||||
// } else {
|
||||
layout->setMargin(0);
|
||||
// }
|
||||
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Background,
|
||||
ColorScheme::getInstance().TabPanelBackground);
|
||||
palette.setColor(QPalette::Background, ColorScheme::getInstance().TabPanelBackground);
|
||||
setPalette(palette);
|
||||
|
||||
resize(1280, 800);
|
||||
@@ -28,10 +50,9 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::layoutVisibleChatWidgets(Channel *channel)
|
||||
void MainWindow::layoutVisibleChatWidgets(Channel *channel)
|
||||
{
|
||||
auto *page = notebook.getSelectedPage();
|
||||
auto *page = _notebook.getSelectedPage();
|
||||
|
||||
if (page == NULL) {
|
||||
return;
|
||||
@@ -43,17 +64,14 @@ MainWindow::layoutVisibleChatWidgets(Channel *channel)
|
||||
ChatWidget *widget = *it;
|
||||
|
||||
if (channel == NULL || channel == widget->getChannel().get()) {
|
||||
if (widget->getView().layoutMessages()) {
|
||||
widget->getView().update();
|
||||
}
|
||||
widget->layoutMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
||||
void MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
||||
{
|
||||
auto *page = notebook.getSelectedPage();
|
||||
auto *page = _notebook.getSelectedPage();
|
||||
|
||||
if (page == NULL) {
|
||||
return;
|
||||
@@ -65,16 +83,14 @@ MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
||||
ChatWidget *widget = *it;
|
||||
|
||||
if (channel == NULL || channel == widget->getChannel().get()) {
|
||||
widget->getView().layoutMessages();
|
||||
widget->getView().update();
|
||||
widget->layoutMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::repaintGifEmotes()
|
||||
void MainWindow::repaintGifEmotes()
|
||||
{
|
||||
auto *page = notebook.getSelectedPage();
|
||||
auto *page = _notebook.getSelectedPage();
|
||||
|
||||
if (page == NULL) {
|
||||
return;
|
||||
@@ -85,37 +101,43 @@ MainWindow::repaintGifEmotes()
|
||||
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
|
||||
ChatWidget *widget = *it;
|
||||
|
||||
widget->getView().updateGifEmotes();
|
||||
widget->updateGifEmotes();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::load(const boost::property_tree::ptree &tree)
|
||||
void MainWindow::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
this->notebook.load(tree);
|
||||
this->_notebook.load(tree);
|
||||
|
||||
this->loaded = true;
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree
|
||||
MainWindow::save()
|
||||
boost::property_tree::ptree MainWindow::save()
|
||||
{
|
||||
boost::property_tree::ptree child;
|
||||
|
||||
child.put("type", "main");
|
||||
|
||||
this->notebook.save(child);
|
||||
_notebook.save(child);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::loadDefaults()
|
||||
void MainWindow::loadDefaults()
|
||||
{
|
||||
this->notebook.loadDefaults();
|
||||
_notebook.loadDefaults();
|
||||
|
||||
this->loaded = true;
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
bool MainWindow::isLoaded() const
|
||||
{
|
||||
return _loaded;
|
||||
}
|
||||
|
||||
Notebook &MainWindow::getNotebook()
|
||||
{
|
||||
return _notebook;
|
||||
}
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
+11
-10
@@ -2,38 +2,39 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include "widgets/notebook.h"
|
||||
#include "widgets/titlebar.h"
|
||||
|
||||
#include <platform/borderless/qwinwidget.h>
|
||||
#include <QMainWindow>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
Notebook notebook;
|
||||
|
||||
void layoutVisibleChatWidgets(Channel *channel = NULL);
|
||||
void repaintVisibleChatWidgets(Channel *channel = NULL);
|
||||
void layoutVisibleChatWidgets(Channel *channel = nullptr);
|
||||
void repaintVisibleChatWidgets(Channel *channel = nullptr);
|
||||
void repaintGifEmotes();
|
||||
|
||||
void load(const boost::property_tree::ptree &tree);
|
||||
boost::property_tree::ptree save();
|
||||
void loadDefaults();
|
||||
|
||||
bool
|
||||
isLoaded() const
|
||||
{
|
||||
return this->loaded;
|
||||
}
|
||||
bool isLoaded() const;
|
||||
|
||||
Notebook &getNotebook();
|
||||
|
||||
private:
|
||||
bool loaded = false;
|
||||
Notebook _notebook;
|
||||
bool _loaded;
|
||||
TitleBar _titleBar;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
+79
-98
@@ -19,106 +19,99 @@ namespace widgets {
|
||||
|
||||
Notebook::Notebook(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, addButton(this)
|
||||
, settingsButton(this)
|
||||
, userButton(this)
|
||||
, selectedPage(nullptr)
|
||||
, _addButton(this)
|
||||
, _settingsButton(this)
|
||||
, _userButton(this)
|
||||
, _selectedPage(nullptr)
|
||||
{
|
||||
connect(&this->settingsButton, SIGNAL(clicked()), this,
|
||||
SLOT(settingsButtonClicked()));
|
||||
connect(&this->userButton, SIGNAL(clicked()), this,
|
||||
SLOT(usersButtonClicked()));
|
||||
connect(&this->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()));
|
||||
|
||||
this->settingsButton.resize(24, 24);
|
||||
this->settingsButton.icon = NotebookButton::IconSettings;
|
||||
_settingsButton.resize(24, 24);
|
||||
_settingsButton.icon = NotebookButton::IconSettings;
|
||||
|
||||
this->userButton.resize(24, 24);
|
||||
this->userButton.move(24, 0);
|
||||
this->userButton.icon = NotebookButton::IconUser;
|
||||
_userButton.resize(24, 24);
|
||||
_userButton.move(24, 0);
|
||||
_userButton.icon = NotebookButton::IconUser;
|
||||
|
||||
this->addButton.resize(24, 24);
|
||||
_addButton.resize(24, 24);
|
||||
|
||||
Settings::getInstance().hidePreferencesButton.valueChanged.connect(
|
||||
[this](const bool &) { this->performLayout(); });
|
||||
Settings::getInstance().hideUserButton.valueChanged.connect(
|
||||
[this](const bool &) { this->performLayout(); });
|
||||
SettingsManager::getInstance().hidePreferencesButton.valueChanged.connect(
|
||||
[this](const bool &) { performLayout(); });
|
||||
SettingsManager::getInstance().hideUserButton.valueChanged.connect(
|
||||
[this](const bool &) { performLayout(); });
|
||||
}
|
||||
|
||||
NotebookPage *
|
||||
Notebook::addPage(bool select)
|
||||
NotebookPage *Notebook::addPage(bool select)
|
||||
{
|
||||
auto tab = new NotebookTab(this);
|
||||
auto page = new NotebookPage(this, tab);
|
||||
|
||||
tab->show();
|
||||
|
||||
if (select || this->pages.count() == 0) {
|
||||
if (select || _pages.count() == 0) {
|
||||
this->select(page);
|
||||
}
|
||||
|
||||
this->pages.append(page);
|
||||
_pages.append(page);
|
||||
|
||||
this->performLayout();
|
||||
performLayout();
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::removePage(NotebookPage *page)
|
||||
void Notebook::removePage(NotebookPage *page)
|
||||
{
|
||||
int index = this->pages.indexOf(page);
|
||||
int index = _pages.indexOf(page);
|
||||
|
||||
if (pages.size() == 1) {
|
||||
this->select(NULL);
|
||||
} else if (index == pages.count() - 1) {
|
||||
this->select(pages[index - 1]);
|
||||
if (_pages.size() == 1) {
|
||||
select(NULL);
|
||||
} else if (index == _pages.count() - 1) {
|
||||
select(_pages[index - 1]);
|
||||
} else {
|
||||
this->select(pages[index + 1]);
|
||||
select(_pages[index + 1]);
|
||||
}
|
||||
|
||||
delete page->tab;
|
||||
delete page->getTab();
|
||||
delete page;
|
||||
|
||||
this->pages.removeOne(page);
|
||||
_pages.removeOne(page);
|
||||
|
||||
if (this->pages.size() == 0) {
|
||||
if (_pages.size() == 0) {
|
||||
addPage();
|
||||
}
|
||||
|
||||
performLayout();
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::select(NotebookPage *page)
|
||||
void Notebook::select(NotebookPage *page)
|
||||
{
|
||||
if (page == this->selectedPage)
|
||||
if (page == _selectedPage)
|
||||
return;
|
||||
|
||||
if (page != nullptr) {
|
||||
page->setHidden(false);
|
||||
page->tab->setSelected(true);
|
||||
page->tab->raise();
|
||||
page->getTab()->setSelected(true);
|
||||
page->getTab()->raise();
|
||||
}
|
||||
|
||||
if (this->selectedPage != nullptr) {
|
||||
this->selectedPage->setHidden(true);
|
||||
this->selectedPage->tab->setSelected(false);
|
||||
if (_selectedPage != nullptr) {
|
||||
_selectedPage->setHidden(true);
|
||||
_selectedPage->getTab()->setSelected(false);
|
||||
}
|
||||
|
||||
this->selectedPage = page;
|
||||
_selectedPage = page;
|
||||
|
||||
performLayout();
|
||||
}
|
||||
|
||||
NotebookPage *
|
||||
Notebook::tabAt(QPoint point, int &index)
|
||||
NotebookPage *Notebook::tabAt(QPoint point, int &index)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (auto *page : pages) {
|
||||
if (page->tab->getDesiredRect().contains(point)) {
|
||||
for (auto *page : _pages) {
|
||||
if (page->getTab()->getDesiredRect().contains(point)) {
|
||||
index = i;
|
||||
return page;
|
||||
}
|
||||
@@ -130,97 +123,87 @@ Notebook::tabAt(QPoint point, int &index)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::rearrangePage(NotebookPage *page, int index)
|
||||
void Notebook::rearrangePage(NotebookPage *page, int index)
|
||||
{
|
||||
pages.move(pages.indexOf(page), index);
|
||||
_pages.move(_pages.indexOf(page), index);
|
||||
|
||||
performLayout();
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::performLayout(bool animated)
|
||||
void Notebook::performLayout(bool animated)
|
||||
{
|
||||
int x = 0, y = 0;
|
||||
|
||||
if (Settings::getInstance().hidePreferencesButton.get()) {
|
||||
settingsButton.hide();
|
||||
if (SettingsManager::getInstance().hidePreferencesButton.get()) {
|
||||
_settingsButton.hide();
|
||||
} else {
|
||||
settingsButton.show();
|
||||
_settingsButton.show();
|
||||
x += 24;
|
||||
}
|
||||
if (Settings::getInstance().hideUserButton.get()) {
|
||||
userButton.hide();
|
||||
if (SettingsManager::getInstance().hideUserButton.get()) {
|
||||
_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 : this->pages) {
|
||||
tabHeight = i->tab->height();
|
||||
for (auto &i : _pages) {
|
||||
tabHeight = i->getTab()->height();
|
||||
|
||||
if (!first &&
|
||||
(i == this->pages.last() ? tabHeight : 0) + x + i->tab->width() >
|
||||
width()) {
|
||||
y += i->tab->height();
|
||||
i->tab->moveAnimated(QPoint(0, y), animated);
|
||||
x = i->tab->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();
|
||||
} else {
|
||||
i->tab->moveAnimated(QPoint(x, y), animated);
|
||||
x += i->tab->width();
|
||||
i->getTab()->moveAnimated(QPoint(x, y), animated);
|
||||
x += i->getTab()->width();
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
this->addButton.move(x, y);
|
||||
_addButton.move(x, y);
|
||||
|
||||
if (this->selectedPage != nullptr) {
|
||||
this->selectedPage->move(0, y + tabHeight);
|
||||
this->selectedPage->resize(width(), height() - y - tabHeight);
|
||||
if (_selectedPage != nullptr) {
|
||||
_selectedPage->move(0, y + tabHeight);
|
||||
_selectedPage->resize(width(), height() - y - tabHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::resizeEvent(QResizeEvent *)
|
||||
void Notebook::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
performLayout(false);
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::settingsButtonClicked()
|
||||
void Notebook::settingsButtonClicked()
|
||||
{
|
||||
SettingsDialog *a = new SettingsDialog();
|
||||
|
||||
a->show();
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::usersButtonClicked()
|
||||
void Notebook::usersButtonClicked()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::addPageButtonClicked()
|
||||
void Notebook::addPageButtonClicked()
|
||||
{
|
||||
addPage(true);
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::load(const boost::property_tree::ptree &tree)
|
||||
void Notebook::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
// Read a list of tabs
|
||||
try {
|
||||
BOOST_FOREACH (const boost::property_tree::ptree::value_type &v,
|
||||
tree.get_child("tabs.")) {
|
||||
BOOST_FOREACH (const boost::property_tree::ptree::value_type &v, tree.get_child("tabs.")) {
|
||||
bool select = v.second.get<bool>("selected", false);
|
||||
|
||||
auto page = this->addPage(select);
|
||||
auto tab = page->tab;
|
||||
auto page = addPage(select);
|
||||
auto tab = page->getTab();
|
||||
tab->load(v.second);
|
||||
page->load(v.second);
|
||||
}
|
||||
@@ -228,20 +211,19 @@ Notebook::load(const boost::property_tree::ptree &tree)
|
||||
// can't read tabs
|
||||
}
|
||||
|
||||
if (this->pages.size() == 0) {
|
||||
if (_pages.size() == 0) {
|
||||
// No pages saved, show default stuff
|
||||
this->loadDefaults();
|
||||
loadDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::save(boost::property_tree::ptree &tree)
|
||||
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 : this->pages) {
|
||||
boost::property_tree::ptree pTab = page->tab->save();
|
||||
for (const auto &page : _pages) {
|
||||
boost::property_tree::ptree pTab = page->getTab()->save();
|
||||
|
||||
boost::property_tree::ptree pChats = page->save();
|
||||
|
||||
@@ -255,10 +237,9 @@ Notebook::save(boost::property_tree::ptree &tree)
|
||||
tree.add_child("tabs", tabs);
|
||||
}
|
||||
|
||||
void
|
||||
Notebook::loadDefaults()
|
||||
void Notebook::loadDefaults()
|
||||
{
|
||||
this->addPage();
|
||||
addPage();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
+7
-8
@@ -26,10 +26,9 @@ public:
|
||||
void removePage(NotebookPage *page);
|
||||
void select(NotebookPage *page);
|
||||
|
||||
NotebookPage *
|
||||
getSelectedPage()
|
||||
NotebookPage *getSelectedPage()
|
||||
{
|
||||
return selectedPage;
|
||||
return _selectedPage;
|
||||
}
|
||||
|
||||
void performLayout(bool animate = true);
|
||||
@@ -48,13 +47,13 @@ public slots:
|
||||
void addPageButtonClicked();
|
||||
|
||||
private:
|
||||
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);
|
||||
|
||||
+24
-46
@@ -1,20 +1,22 @@
|
||||
#include "widgets/notebookbutton.h"
|
||||
#include "colorscheme.h"
|
||||
#include "widgets/fancybutton.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QRadialGradient>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
NotebookButton::NotebookButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: FancyButton(parent)
|
||||
{
|
||||
setMouseEffectColor(QColor(0, 0, 0));
|
||||
}
|
||||
|
||||
void
|
||||
NotebookButton::paintEvent(QPaintEvent *)
|
||||
void NotebookButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -23,29 +25,30 @@ NotebookButton::paintEvent(QPaintEvent *)
|
||||
|
||||
auto &colorScheme = ColorScheme::getInstance();
|
||||
|
||||
if (mouseDown) {
|
||||
if (_mouseDown) {
|
||||
background = colorScheme.TabSelectedBackground;
|
||||
foreground = colorScheme.TabSelectedText;
|
||||
} else if (mouseOver) {
|
||||
} else if (_mouseOver) {
|
||||
background = colorScheme.TabHoverBackground;
|
||||
foreground = colorScheme.TabSelectedBackground;
|
||||
} else {
|
||||
background = colorScheme.TabPanelBackground;
|
||||
foreground = colorScheme.TabSelectedBackground;
|
||||
// foreground = colorScheme.TabSelectedBackground;
|
||||
foreground = QColor(230, 230, 230);
|
||||
}
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.fillRect(this->rect(), background);
|
||||
|
||||
float h = this->height(), w = this->width();
|
||||
float h = height(), w = width();
|
||||
|
||||
if (icon == IconPlus) {
|
||||
painter.fillRect(QRectF((h / 12) * 2 + 1, (h / 12) * 5 + 1,
|
||||
w - ((h / 12) * 5), (h / 12) * 1),
|
||||
foreground);
|
||||
painter.fillRect(QRectF((h / 12) * 5 + 1, (h / 12) * 2 + 1,
|
||||
(h / 12) * 1, w - ((h / 12) * 5)),
|
||||
foreground);
|
||||
painter.fillRect(
|
||||
QRectF((h / 12) * 2 + 1, (h / 12) * 5 + 1, w - ((h / 12) * 5), (h / 12) * 1),
|
||||
foreground);
|
||||
painter.fillRect(
|
||||
QRectF((h / 12) * 5 + 1, (h / 12) * 2 + 1, (h / 12) * 1, w - ((h / 12) * 5)),
|
||||
foreground);
|
||||
} else if (icon == IconUser) {
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
@@ -74,10 +77,8 @@ NotebookButton::paintEvent(QPaintEvent *)
|
||||
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));
|
||||
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.fillPath(path, foreground);
|
||||
@@ -85,44 +86,21 @@ NotebookButton::paintEvent(QPaintEvent *)
|
||||
painter.setBrush(background);
|
||||
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
|
||||
}
|
||||
|
||||
fancyPaint(painter);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookButton::mousePressEvent(QMouseEvent *event)
|
||||
void NotebookButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
mouseDown = true;
|
||||
_mouseDown = false;
|
||||
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
mouseDown = false;
|
||||
|
||||
this->update();
|
||||
update();
|
||||
|
||||
emit clicked();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookButton::enterEvent(QEvent *)
|
||||
{
|
||||
mouseOver = true;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookButton::leaveEvent(QEvent *)
|
||||
{
|
||||
mouseOver = false;
|
||||
|
||||
this->update();
|
||||
FancyButton::mouseReleaseEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#ifndef NOTEBOOKBUTTON_H
|
||||
#define NOTEBOOKBUTTON_H
|
||||
|
||||
#include "fancybutton.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class NotebookButton : public QWidget
|
||||
class NotebookButton : public FancyButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static const int IconPlus = 0;
|
||||
static const int IconUser = 1;
|
||||
@@ -18,18 +21,17 @@ public:
|
||||
|
||||
NotebookButton(QWidget *parent);
|
||||
|
||||
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void enterEvent(QEvent *) Q_DECL_OVERRIDE;
|
||||
void leaveEvent(QEvent *) Q_DECL_OVERRIDE;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
private:
|
||||
bool mouseOver = false;
|
||||
bool mouseDown = false;
|
||||
bool _mouseOver = false;
|
||||
bool _mouseDown = false;
|
||||
QPoint _mousePos;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+94
-106
@@ -21,49 +21,60 @@ std::pair<int, int> NotebookPage::dropPosition = std::pair<int, int>(-1, -1);
|
||||
|
||||
NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab)
|
||||
: QWidget(parent)
|
||||
, parentbox(this)
|
||||
, chatWidgets()
|
||||
, preview(this)
|
||||
, _tab(tab)
|
||||
, _parentbox(this)
|
||||
, _chatWidgets()
|
||||
, _preview(this)
|
||||
{
|
||||
this->tab = tab;
|
||||
tab->page = this;
|
||||
|
||||
setHidden(true);
|
||||
setAcceptDrops(true);
|
||||
|
||||
this->parentbox.addSpacing(2);
|
||||
this->parentbox.addLayout(&this->hbox);
|
||||
this->parentbox.setMargin(0);
|
||||
_parentbox.addSpacing(2);
|
||||
_parentbox.addLayout(&_hbox);
|
||||
_parentbox.setMargin(0);
|
||||
|
||||
this->hbox.setSpacing(1);
|
||||
this->hbox.setMargin(0);
|
||||
_hbox.setSpacing(1);
|
||||
_hbox.setMargin(0);
|
||||
}
|
||||
|
||||
std::pair<int, int>
|
||||
NotebookPage::removeFromLayout(ChatWidget *widget)
|
||||
const std::vector<ChatWidget *> &NotebookPage::getChatWidgets() const
|
||||
{
|
||||
for (auto it = this->chatWidgets.begin(); it != this->chatWidgets.end();
|
||||
++it) {
|
||||
return _chatWidgets;
|
||||
}
|
||||
|
||||
NotebookTab *NotebookPage::getTab() const
|
||||
{
|
||||
return _tab;
|
||||
}
|
||||
|
||||
std::pair<int, int> NotebookPage::removeFromLayout(ChatWidget *widget)
|
||||
{
|
||||
// remove from chatWidgets vector
|
||||
for (auto it = _chatWidgets.begin(); it != _chatWidgets.end(); ++it) {
|
||||
if (*it == widget) {
|
||||
this->chatWidgets.erase(it);
|
||||
_chatWidgets.erase(it);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(this->hbox.itemAt(i));
|
||||
// remove from box and return location
|
||||
for (int i = 0; i < _hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(_hbox.itemAt(i));
|
||||
|
||||
for (int j = 0; j < vbox->count(); ++j) {
|
||||
if (vbox->itemAt(j)->widget() != widget)
|
||||
if (vbox->itemAt(j)->widget() != widget) {
|
||||
continue;
|
||||
}
|
||||
|
||||
widget->setParent(NULL);
|
||||
|
||||
bool isLastItem = vbox->count() == 0;
|
||||
|
||||
if (isLastItem) {
|
||||
this->hbox.removeItem(vbox);
|
||||
_hbox.removeItem(vbox);
|
||||
|
||||
delete vbox;
|
||||
}
|
||||
@@ -75,19 +86,17 @@ NotebookPage::removeFromLayout(ChatWidget *widget)
|
||||
return std::pair<int, int>(-1, -1);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::addToLayout(
|
||||
ChatWidget *widget,
|
||||
std::pair<int, int> position = std::pair<int, int>(-1, -1))
|
||||
void NotebookPage::addToLayout(ChatWidget *widget,
|
||||
std::pair<int, int> position = std::pair<int, int>(-1, -1))
|
||||
{
|
||||
this->chatWidgets.push_back(widget);
|
||||
_chatWidgets.push_back(widget);
|
||||
|
||||
// add vbox at the end
|
||||
if (position.first < 0 || position.first >= this->hbox.count()) {
|
||||
if (position.first < 0 || position.first >= _hbox.count()) {
|
||||
auto vbox = new QVBoxLayout();
|
||||
vbox->addWidget(widget);
|
||||
|
||||
this->hbox.addLayout(vbox, 1);
|
||||
_hbox.addLayout(vbox, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,101 +105,91 @@ NotebookPage::addToLayout(
|
||||
auto vbox = new QVBoxLayout();
|
||||
vbox->addWidget(widget);
|
||||
|
||||
this->hbox.insertLayout(position.first, vbox, 1);
|
||||
_hbox.insertLayout(position.first, vbox, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// add to existing vbox
|
||||
auto vbox = static_cast<QVBoxLayout *>(this->hbox.itemAt(position.first));
|
||||
auto vbox = static_cast<QVBoxLayout *>(_hbox.itemAt(position.first));
|
||||
|
||||
vbox->insertWidget(std::max(0, std::min(vbox->count(), position.second)),
|
||||
widget);
|
||||
vbox->insertWidget(std::max(0, std::min(vbox->count(), position.second)), widget);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::enterEvent(QEvent *)
|
||||
void NotebookPage::enterEvent(QEvent *)
|
||||
{
|
||||
if (this->hbox.count() == 0) {
|
||||
if (_hbox.count() == 0) {
|
||||
setCursor(QCursor(Qt::PointingHandCursor));
|
||||
} else {
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::leaveEvent(QEvent *)
|
||||
void NotebookPage::leaveEvent(QEvent *)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
void NotebookPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->hbox.count() == 0 && event->button() == Qt::LeftButton) {
|
||||
if (_hbox.count() == 0 && event->button() == Qt::LeftButton) {
|
||||
// "Add Chat" was clicked
|
||||
this->addToLayout(new ChatWidget(), std::pair<int, int>(-1, -1));
|
||||
addToLayout(new ChatWidget(), std::pair<int, int>(-1, -1));
|
||||
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::dragEnterEvent(QDragEnterEvent *event)
|
||||
void NotebookPage::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (!event->mimeData()->hasFormat("chatterino/split"))
|
||||
return;
|
||||
|
||||
if (isDraggingSplit) {
|
||||
this->dropRegions.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->hbox.count() == 0) {
|
||||
this->dropRegions.push_back(
|
||||
DropRegion(rect(), std::pair<int, int>(-1, -1)));
|
||||
} else {
|
||||
for (int i = 0; i < this->hbox.count() + 1; ++i) {
|
||||
this->dropRegions.push_back(DropRegion(
|
||||
QRect(((i * 4 - 1) * width() / this->hbox.count()) / 4, 0,
|
||||
width() / this->hbox.count() / 2 + 1, height() + 1),
|
||||
_dropRegions.clear();
|
||||
|
||||
std::pair<int, int>(i, -1)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(this->hbox.itemAt(i));
|
||||
|
||||
for (int j = 0; j < vbox->count() + 1; ++j) {
|
||||
this->dropRegions.push_back(DropRegion(
|
||||
QRect(i * width() / this->hbox.count(),
|
||||
((j * 2 - 1) * height() / vbox->count()) / 2,
|
||||
width() / this->hbox.count() + 1,
|
||||
height() / vbox->count() + 1),
|
||||
|
||||
std::pair<int, int>(i, j)));
|
||||
}
|
||||
}
|
||||
if (_hbox.count() == 0) {
|
||||
_dropRegions.push_back(DropRegion(rect(), std::pair<int, int>(-1, -1)));
|
||||
} else {
|
||||
for (int i = 0; i < _hbox.count() + 1; ++i) {
|
||||
_dropRegions.push_back(DropRegion(QRect(((i * 4 - 1) * width() / _hbox.count()) / 4, 0,
|
||||
width() / _hbox.count() / 2 + 1, height() + 1),
|
||||
std::pair<int, int>(i, -1)));
|
||||
}
|
||||
|
||||
setPreviewRect(event->pos());
|
||||
for (int i = 0; i < _hbox.count(); ++i) {
|
||||
auto vbox = static_cast<QVBoxLayout *>(_hbox.itemAt(i));
|
||||
|
||||
event->acceptProposedAction();
|
||||
for (int j = 0; j < vbox->count() + 1; ++j) {
|
||||
_dropRegions.push_back(DropRegion(
|
||||
QRect(i * width() / _hbox.count(), ((j * 2 - 1) * height() / vbox->count()) / 2,
|
||||
width() / _hbox.count() + 1, height() / vbox->count() + 1),
|
||||
|
||||
std::pair<int, int>(i, j)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setPreviewRect(event->pos());
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::dragMoveEvent(QDragMoveEvent *event)
|
||||
void NotebookPage::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
setPreviewRect(event->pos());
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::setPreviewRect(QPoint mousePos)
|
||||
void NotebookPage::setPreviewRect(QPoint mousePos)
|
||||
{
|
||||
for (DropRegion region : this->dropRegions) {
|
||||
for (DropRegion region : _dropRegions) {
|
||||
if (region.rect.contains(mousePos)) {
|
||||
this->preview.setBounds(region.rect);
|
||||
_preview.setBounds(region.rect);
|
||||
|
||||
if (!this->preview.isVisible()) {
|
||||
this->preview.show();
|
||||
this->preview.raise();
|
||||
if (!_preview.isVisible()) {
|
||||
_preview.show();
|
||||
_preview.raise();
|
||||
}
|
||||
|
||||
dropPosition = region.position;
|
||||
@@ -199,17 +198,15 @@ NotebookPage::setPreviewRect(QPoint mousePos)
|
||||
}
|
||||
}
|
||||
|
||||
this->preview.hide();
|
||||
_preview.hide();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
void NotebookPage::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
this->preview.hide();
|
||||
_preview.hide();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::dropEvent(QDropEvent *event)
|
||||
void NotebookPage::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (isDraggingSplit) {
|
||||
event->acceptProposedAction();
|
||||
@@ -219,33 +216,28 @@ NotebookPage::dropEvent(QDropEvent *event)
|
||||
addToLayout(NotebookPage::draggingSplit, dropPosition);
|
||||
}
|
||||
|
||||
this->preview.hide();
|
||||
_preview.hide();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::paintEvent(QPaintEvent *)
|
||||
void NotebookPage::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
if (this->hbox.count() == 0) {
|
||||
if (_hbox.count() == 0) {
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().ChatBackground);
|
||||
|
||||
painter.fillRect(0, 0, width(), 2,
|
||||
ColorScheme::getInstance().TabSelectedBackground);
|
||||
painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground);
|
||||
|
||||
painter.setPen(ColorScheme::getInstance().Text);
|
||||
painter.drawText(rect(), "Add Chat", QTextOption(Qt::AlignCenter));
|
||||
} else {
|
||||
painter.fillRect(rect(),
|
||||
ColorScheme::getInstance().TabSelectedBackground);
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().TabSelectedBackground);
|
||||
|
||||
painter.fillRect(0, 0, width(), 2,
|
||||
ColorScheme::getInstance().TabSelectedBackground);
|
||||
painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground);
|
||||
}
|
||||
}
|
||||
|
||||
static std::pair<int, int>
|
||||
getWidgetPositionInLayout(QLayout *layout, const ChatWidget *chatWidget)
|
||||
static std::pair<int, int> getWidgetPositionInLayout(QLayout *layout, const ChatWidget *chatWidget)
|
||||
{
|
||||
for (int i = 0; i < layout->count(); ++i) {
|
||||
printf("xD\n");
|
||||
@@ -254,10 +246,9 @@ getWidgetPositionInLayout(QLayout *layout, const ChatWidget *chatWidget)
|
||||
return std::make_pair(-1, -1);
|
||||
}
|
||||
|
||||
std::pair<int, int>
|
||||
NotebookPage::getChatPosition(const ChatWidget *chatWidget)
|
||||
std::pair<int, int> NotebookPage::getChatPosition(const ChatWidget *chatWidget)
|
||||
{
|
||||
auto layout = this->hbox.layout();
|
||||
auto layout = _hbox.layout();
|
||||
|
||||
if (layout == nullptr) {
|
||||
return std::make_pair(-1, -1);
|
||||
@@ -266,8 +257,7 @@ NotebookPage::getChatPosition(const ChatWidget *chatWidget)
|
||||
return getWidgetPositionInLayout(layout, chatWidget);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||
void NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
try {
|
||||
int column = 0;
|
||||
@@ -276,7 +266,7 @@ NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||
for (const auto &innerV : v.second.get_child("")) {
|
||||
auto widget = new ChatWidget();
|
||||
widget->load(innerV.second);
|
||||
this->addToLayout(widget, std::pair<int, int>(column, row));
|
||||
addToLayout(widget, std::pair<int, int>(column, row));
|
||||
++row;
|
||||
}
|
||||
++column;
|
||||
@@ -286,8 +276,7 @@ NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
saveFromLayout(QLayout *layout, boost::property_tree::ptree &tree)
|
||||
static void saveFromLayout(QLayout *layout, boost::property_tree::ptree &tree)
|
||||
{
|
||||
for (int i = 0; i < layout->count(); ++i) {
|
||||
auto item = layout->itemAt(i);
|
||||
@@ -323,17 +312,16 @@ saveFromLayout(QLayout *layout, boost::property_tree::ptree &tree)
|
||||
}
|
||||
}
|
||||
|
||||
boost::property_tree::ptree
|
||||
NotebookPage::save()
|
||||
boost::property_tree::ptree NotebookPage::save()
|
||||
{
|
||||
boost::property_tree::ptree tree;
|
||||
|
||||
auto layout = this->hbox.layout();
|
||||
auto layout = _hbox.layout();
|
||||
|
||||
saveFromLayout(layout, tree);
|
||||
|
||||
/*
|
||||
for (const auto &chat : this->chatWidgets) {
|
||||
for (const auto &chat : chatWidgets) {
|
||||
boost::property_tree::ptree child = chat->save();
|
||||
|
||||
// Set child position
|
||||
|
||||
+16
-18
@@ -23,34 +23,31 @@ class NotebookPage : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NotebookPage(QWidget *parent, NotebookTab *tab);
|
||||
NotebookTab *tab;
|
||||
NotebookPage(QWidget *parent, NotebookTab *_tab);
|
||||
|
||||
std::pair<int, int> removeFromLayout(ChatWidget *widget);
|
||||
void addToLayout(ChatWidget *widget, std::pair<int, int> position);
|
||||
|
||||
const std::vector<ChatWidget *> &
|
||||
getChatWidgets() const
|
||||
{
|
||||
return chatWidgets;
|
||||
}
|
||||
const std::vector<ChatWidget *> &getChatWidgets() const;
|
||||
NotebookTab *getTab() const;
|
||||
|
||||
static bool isDraggingSplit;
|
||||
static ChatWidget *draggingSplit;
|
||||
static std::pair<int, int> dropPosition;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
void enterEvent(QEvent *) override;
|
||||
void leaveEvent(QEvent *) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
|
||||
void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
|
||||
void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private:
|
||||
struct DropRegion {
|
||||
QRect rect;
|
||||
std::pair<int, int> position;
|
||||
@@ -62,15 +59,16 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
QVBoxLayout parentbox;
|
||||
QHBoxLayout hbox;
|
||||
NotebookTab *_tab;
|
||||
|
||||
std::vector<ChatWidget *> chatWidgets;
|
||||
std::vector<DropRegion> dropRegions;
|
||||
QVBoxLayout _parentbox;
|
||||
QHBoxLayout _hbox;
|
||||
|
||||
NotebookPageDropPreview preview;
|
||||
std::vector<ChatWidget *> _chatWidgets;
|
||||
std::vector<DropRegion> _dropRegions;
|
||||
|
||||
NotebookPageDropPreview _preview;
|
||||
|
||||
private:
|
||||
void setPreviewRect(QPoint mousePos);
|
||||
|
||||
std::pair<int, int> getChatPosition(const ChatWidget *chatWidget);
|
||||
|
||||
@@ -17,8 +17,7 @@ NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent)
|
||||
this->setHidden(true);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPageDropPreview::paintEvent(QPaintEvent *)
|
||||
void NotebookPageDropPreview::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -26,14 +25,12 @@ NotebookPageDropPreview::paintEvent(QPaintEvent *)
|
||||
ColorScheme::getInstance().DropPreviewBackground);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPageDropPreview::hideEvent(QHideEvent *)
|
||||
void NotebookPageDropPreview::hideEvent(QHideEvent *)
|
||||
{
|
||||
animate = false;
|
||||
}
|
||||
|
||||
void
|
||||
NotebookPageDropPreview::setBounds(const QRect &rect)
|
||||
void NotebookPageDropPreview::setBounds(const QRect &rect)
|
||||
{
|
||||
if (rect == this->desiredGeometry) {
|
||||
return;
|
||||
|
||||
+122
-95
@@ -1,6 +1,6 @@
|
||||
#include "widgets/notebooktab.h"
|
||||
#include "colorscheme.h"
|
||||
#include "settings.h"
|
||||
#include "settingsmanager.h"
|
||||
#include "widgets/notebook.h"
|
||||
|
||||
#include <QPainter>
|
||||
@@ -10,75 +10,113 @@ namespace widgets {
|
||||
|
||||
NotebookTab::NotebookTab(Notebook *notebook)
|
||||
: QWidget(notebook)
|
||||
, posAnimation(this, "pos")
|
||||
, posAnimated(false)
|
||||
, posAnimationDesired()
|
||||
, notebook(notebook)
|
||||
, title("<no title>")
|
||||
, selected(false)
|
||||
, mouseOver(false)
|
||||
, mouseDown(false)
|
||||
, mouseOverX(false)
|
||||
, mouseDownX(false)
|
||||
, highlightStyle(HighlightNone)
|
||||
, _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);
|
||||
|
||||
posAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
|
||||
_posAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
|
||||
|
||||
this->hideXConnection =
|
||||
Settings::getInstance().hideTabX.valueChanged.connect(
|
||||
boost::bind(&NotebookTab::hideTabXChanged, this, _1));
|
||||
this->_hideXConnection = SettingsManager::getInstance().hideTabX.valueChanged.connect(
|
||||
boost::bind(&NotebookTab::hideTabXChanged, this, _1));
|
||||
|
||||
this->setMouseTracking(true);
|
||||
}
|
||||
|
||||
NotebookTab::~NotebookTab()
|
||||
{
|
||||
this->hideXConnection.disconnect();
|
||||
this->_hideXConnection.disconnect();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::calcSize()
|
||||
void NotebookTab::calcSize()
|
||||
{
|
||||
if (Settings::getInstance().hideTabX.get()) {
|
||||
this->resize(this->fontMetrics().width(this->title) + 8, 24);
|
||||
if (SettingsManager::getInstance().hideTabX.get()) {
|
||||
resize(fontMetrics().width(_title) + 8, 24);
|
||||
} else {
|
||||
this->resize(this->fontMetrics().width(this->title) + 8 + 24, 24);
|
||||
resize(fontMetrics().width(_title) + 8 + 24, 24);
|
||||
}
|
||||
|
||||
if (this->parent() != nullptr) {
|
||||
((Notebook *)this->parent())->performLayout(true);
|
||||
if (parent() != nullptr) {
|
||||
((Notebook *)parent())->performLayout(true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::moveAnimated(QPoint pos, bool animated)
|
||||
const QString &NotebookTab::getTitle() const
|
||||
{
|
||||
posAnimationDesired = pos;
|
||||
return _title;
|
||||
}
|
||||
|
||||
if ((this->window() != NULL && !this->window()->isVisible()) || !animated ||
|
||||
posAnimated == false) {
|
||||
void NotebookTab::setTitle(const QString &title)
|
||||
{
|
||||
_title = title;
|
||||
}
|
||||
|
||||
bool NotebookTab::getSelected()
|
||||
{
|
||||
return _selected;
|
||||
}
|
||||
|
||||
void NotebookTab::setSelected(bool value)
|
||||
{
|
||||
_selected = value;
|
||||
update();
|
||||
}
|
||||
|
||||
NotebookTab::HighlightStyle NotebookTab::getHighlightStyle() const
|
||||
{
|
||||
return _highlightStyle;
|
||||
}
|
||||
|
||||
void NotebookTab::setHighlightStyle(HighlightStyle style)
|
||||
{
|
||||
_highlightStyle = style;
|
||||
update();
|
||||
}
|
||||
|
||||
QRect NotebookTab::getDesiredRect() const
|
||||
{
|
||||
return QRect(_posAnimationDesired, size());
|
||||
}
|
||||
|
||||
void NotebookTab::hideTabXChanged(bool)
|
||||
{
|
||||
calcSize();
|
||||
update();
|
||||
}
|
||||
|
||||
void NotebookTab::moveAnimated(QPoint pos, bool animated)
|
||||
{
|
||||
_posAnimationDesired = pos;
|
||||
|
||||
if ((window() != NULL && !window()->isVisible()) || !animated || _posAnimated == false) {
|
||||
move(pos);
|
||||
|
||||
posAnimated = true;
|
||||
_posAnimated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->posAnimation.endValue() == pos) {
|
||||
if (_posAnimation.endValue() == pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->posAnimation.stop();
|
||||
this->posAnimation.setDuration(75);
|
||||
this->posAnimation.setStartValue(this->pos());
|
||||
this->posAnimation.setEndValue(pos);
|
||||
this->posAnimation.start();
|
||||
_posAnimation.stop();
|
||||
_posAnimation.setDuration(75);
|
||||
_posAnimation.setStartValue(this->pos());
|
||||
_posAnimation.setEndValue(pos);
|
||||
_posAnimation.start();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::paintEvent(QPaintEvent *)
|
||||
void NotebookTab::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -86,16 +124,16 @@ NotebookTab::paintEvent(QPaintEvent *)
|
||||
|
||||
auto &colorScheme = ColorScheme::getInstance();
|
||||
|
||||
if (this->selected) {
|
||||
if (_selected) {
|
||||
painter.fillRect(rect(), colorScheme.TabSelectedBackground);
|
||||
fg = colorScheme.TabSelectedText;
|
||||
} else if (this->mouseOver) {
|
||||
} else if (_mouseOver) {
|
||||
painter.fillRect(rect(), colorScheme.TabHoverBackground);
|
||||
fg = colorScheme.TabHoverText;
|
||||
} else if (this->highlightStyle == HighlightHighlighted) {
|
||||
} else if (_highlightStyle == HighlightHighlighted) {
|
||||
painter.fillRect(rect(), colorScheme.TabHighlightedBackground);
|
||||
fg = colorScheme.TabHighlightedText;
|
||||
} else if (this->highlightStyle == HighlightNewMessage) {
|
||||
} else if (_highlightStyle == HighlightNewMessage) {
|
||||
painter.fillRect(rect(), colorScheme.TabNewMessageBackground);
|
||||
fg = colorScheme.TabHighlightedText;
|
||||
} else {
|
||||
@@ -105,116 +143,105 @@ NotebookTab::paintEvent(QPaintEvent *)
|
||||
|
||||
painter.setPen(fg);
|
||||
|
||||
QRect rect(0, 0,
|
||||
width() - (Settings::getInstance().hideTabX.get() ? 0 : 16),
|
||||
height());
|
||||
QRect rect(0, 0, width() - (SettingsManager::getInstance().hideTabX.get() ? 0 : 16), height());
|
||||
|
||||
painter.drawText(rect, this->title, QTextOption(Qt::AlignCenter));
|
||||
painter.drawText(rect, _title, QTextOption(Qt::AlignCenter));
|
||||
|
||||
if (!Settings::getInstance().hideTabX.get() &&
|
||||
(this->mouseOver || this->selected)) {
|
||||
if (this->mouseOverX) {
|
||||
painter.fillRect(this->getXRect(), QColor(0, 0, 0, 64));
|
||||
if (!SettingsManager::getInstance().hideTabX.get() && (_mouseOver || _selected)) {
|
||||
if (_mouseOverX) {
|
||||
painter.fillRect(getXRect(), QColor(0, 0, 0, 64));
|
||||
|
||||
if (this->mouseDownX) {
|
||||
painter.fillRect(this->getXRect(), QColor(0, 0, 0, 64));
|
||||
if (_mouseDownX) {
|
||||
painter.fillRect(getXRect(), QColor(0, 0, 0, 64));
|
||||
}
|
||||
}
|
||||
|
||||
painter.drawLine(this->getXRect().topLeft() + QPoint(4, 4),
|
||||
this->getXRect().bottomRight() + QPoint(-4, -4));
|
||||
painter.drawLine(this->getXRect().topRight() + QPoint(-4, 4),
|
||||
this->getXRect().bottomLeft() + QPoint(4, -4));
|
||||
painter.drawLine(getXRect().topLeft() + QPoint(4, 4),
|
||||
getXRect().bottomRight() + QPoint(-4, -4));
|
||||
painter.drawLine(getXRect().topRight() + QPoint(-4, 4),
|
||||
getXRect().bottomLeft() + QPoint(4, -4));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::mousePressEvent(QMouseEvent *event)
|
||||
void NotebookTab::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
this->mouseDown = true;
|
||||
this->mouseDownX = this->getXRect().contains(event->pos());
|
||||
_mouseDown = true;
|
||||
_mouseDownX = getXRect().contains(event->pos());
|
||||
|
||||
this->update();
|
||||
update();
|
||||
|
||||
this->notebook->select(page);
|
||||
_notebook->select(page);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
||||
void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
this->mouseDown = false;
|
||||
_mouseDown = false;
|
||||
|
||||
if (!Settings::getInstance().hideTabX.get() && this->mouseDownX &&
|
||||
this->getXRect().contains(event->pos())) {
|
||||
this->mouseDownX = false;
|
||||
if (!SettingsManager::getInstance().hideTabX.get() && _mouseDownX &&
|
||||
getXRect().contains(event->pos())) {
|
||||
_mouseDownX = false;
|
||||
|
||||
this->notebook->removePage(this->page);
|
||||
_notebook->removePage(page);
|
||||
} else {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::enterEvent(QEvent *)
|
||||
void NotebookTab::enterEvent(QEvent *)
|
||||
{
|
||||
this->mouseOver = true;
|
||||
_mouseOver = true;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::leaveEvent(QEvent *)
|
||||
void NotebookTab::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOverX = this->mouseOver = false;
|
||||
_mouseOverX = _mouseOver = false;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::dragEnterEvent(QDragEnterEvent *)
|
||||
void NotebookTab::dragEnterEvent(QDragEnterEvent *)
|
||||
{
|
||||
this->notebook->select(page);
|
||||
_notebook->select(page);
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::mouseMoveEvent(QMouseEvent *event)
|
||||
void NotebookTab::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
bool overX = this->getXRect().contains(event->pos());
|
||||
bool overX = getXRect().contains(event->pos());
|
||||
|
||||
if (overX != this->mouseOverX) {
|
||||
this->mouseOverX = overX && !Settings::getInstance().hideTabX.get();
|
||||
if (overX != _mouseOverX) {
|
||||
_mouseOverX = overX && !SettingsManager::getInstance().hideTabX.get();
|
||||
|
||||
this->update();
|
||||
update();
|
||||
}
|
||||
|
||||
if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) {
|
||||
QPoint relPoint = this->mapToParent(event->pos());
|
||||
if (_mouseDown && !getDesiredRect().contains(event->pos())) {
|
||||
QPoint relPoint = mapToParent(event->pos());
|
||||
|
||||
int index;
|
||||
NotebookPage *page = notebook->tabAt(relPoint, index);
|
||||
NotebookPage *page = _notebook->tabAt(relPoint, index);
|
||||
|
||||
if (page != nullptr && page != this->page) {
|
||||
notebook->rearrangePage(this->page, index);
|
||||
if (page != nullptr && page != page) {
|
||||
_notebook->rearrangePage(page, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NotebookTab::load(const boost::property_tree::ptree &tree)
|
||||
void NotebookTab::load(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
// Load tab title
|
||||
try {
|
||||
this->setTitle(QString::fromStdString(tree.get<std::string>("title")));
|
||||
setTitle(QString::fromStdString(tree.get<std::string>("title")));
|
||||
} catch (boost::property_tree::ptree_error) {
|
||||
}
|
||||
}
|
||||
|
||||
boost::property_tree::ptree
|
||||
NotebookTab::save()
|
||||
boost::property_tree::ptree NotebookTab::save()
|
||||
{
|
||||
boost::property_tree::ptree tree;
|
||||
|
||||
tree.put("title", this->getTitle().toStdString());
|
||||
tree.put("title", getTitle().toStdString());
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
+23
-69
@@ -18,72 +18,27 @@ class NotebookTab : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum HighlightStyle {
|
||||
HighlightNone,
|
||||
HighlightHighlighted,
|
||||
HighlightNewMessage
|
||||
};
|
||||
enum HighlightStyle { HighlightNone, HighlightHighlighted, HighlightNewMessage };
|
||||
|
||||
explicit NotebookTab(Notebook *notebook);
|
||||
explicit NotebookTab(Notebook *_notebook);
|
||||
~NotebookTab();
|
||||
|
||||
void calcSize();
|
||||
|
||||
NotebookPage *page;
|
||||
|
||||
const QString &
|
||||
getTitle() const
|
||||
{
|
||||
return this->title;
|
||||
}
|
||||
const QString &getTitle() const;
|
||||
void setTitle(const QString &title);
|
||||
bool getSelected();
|
||||
void setSelected(bool value);
|
||||
|
||||
void
|
||||
setTitle(const QString &title)
|
||||
{
|
||||
this->title = title;
|
||||
}
|
||||
|
||||
bool
|
||||
getSelected()
|
||||
{
|
||||
return this->selected;
|
||||
}
|
||||
|
||||
void
|
||||
setSelected(bool value)
|
||||
{
|
||||
this->selected = value;
|
||||
update();
|
||||
}
|
||||
|
||||
HighlightStyle
|
||||
getHighlightStyle() const
|
||||
{
|
||||
return this->highlightStyle;
|
||||
}
|
||||
|
||||
void
|
||||
setHighlightStyle(HighlightStyle style)
|
||||
{
|
||||
this->highlightStyle = style;
|
||||
update();
|
||||
}
|
||||
HighlightStyle getHighlightStyle() const;
|
||||
void setHighlightStyle(HighlightStyle style);
|
||||
|
||||
void moveAnimated(QPoint pos, bool animated = true);
|
||||
|
||||
public:
|
||||
QRect
|
||||
getDesiredRect() const
|
||||
{
|
||||
return QRect(posAnimationDesired, this->size());
|
||||
}
|
||||
|
||||
void
|
||||
hideTabXChanged(bool)
|
||||
{
|
||||
calcSize();
|
||||
update();
|
||||
}
|
||||
QRect getDesiredRect() const;
|
||||
void hideTabXChanged(bool);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
@@ -98,26 +53,25 @@ protected:
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
boost::signals2::connection hideXConnection;
|
||||
boost::signals2::connection _hideXConnection;
|
||||
|
||||
QPropertyAnimation posAnimation;
|
||||
bool posAnimated;
|
||||
QPoint posAnimationDesired;
|
||||
QPropertyAnimation _posAnimation;
|
||||
bool _posAnimated;
|
||||
QPoint _posAnimationDesired;
|
||||
|
||||
Notebook *notebook;
|
||||
Notebook *_notebook;
|
||||
|
||||
QString title;
|
||||
QString _title;
|
||||
|
||||
bool selected;
|
||||
bool mouseOver;
|
||||
bool mouseDown;
|
||||
bool mouseOverX;
|
||||
bool mouseDownX;
|
||||
bool _selected;
|
||||
bool _mouseOver;
|
||||
bool _mouseDown;
|
||||
bool _mouseOverX;
|
||||
bool _mouseDownX;
|
||||
|
||||
HighlightStyle highlightStyle;
|
||||
HighlightStyle _highlightStyle;
|
||||
|
||||
QRect
|
||||
getXRect()
|
||||
QRect getXRect()
|
||||
{
|
||||
return QRect(this->width() - 20, 4, 16, 16);
|
||||
}
|
||||
|
||||
@@ -16,18 +16,15 @@ public:
|
||||
sizePolicy.setVerticalPolicy(QSizePolicy::Preferred);
|
||||
this->setSizePolicy(sizePolicy);
|
||||
|
||||
QObject::connect(this, &QTextEdit::textChanged, this,
|
||||
&QWidget::updateGeometry);
|
||||
QObject::connect(this, &QTextEdit::textChanged, this, &QWidget::updateGeometry);
|
||||
}
|
||||
|
||||
QSize
|
||||
sizeHint() const override
|
||||
QSize sizeHint() const override
|
||||
{
|
||||
return QSize(this->width(), this->heightForWidth(this->width()));
|
||||
}
|
||||
|
||||
bool
|
||||
hasHeightForWidth() const override
|
||||
bool hasHeightForWidth() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -35,17 +32,14 @@ public:
|
||||
boost::signals2::signal<void(QKeyEvent *)> keyPressed;
|
||||
|
||||
protected:
|
||||
int
|
||||
heightForWidth(int) const override
|
||||
int heightForWidth(int) const override
|
||||
{
|
||||
auto margins = this->contentsMargins();
|
||||
|
||||
return margins.top() + document()->size().height() + margins.bottom() +
|
||||
5;
|
||||
return margins.top() + document()->size().height() + margins.bottom() + 5;
|
||||
}
|
||||
|
||||
void
|
||||
keyPressEvent(QKeyEvent *event)
|
||||
void keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
|
||||
|
||||
+188
-107
@@ -11,35 +11,34 @@ namespace widgets {
|
||||
|
||||
ScrollBar::ScrollBar(QWidget *widget)
|
||||
: QWidget(widget)
|
||||
, mutex()
|
||||
, currentValueAnimation(this, "currentValue")
|
||||
, highlights(NULL)
|
||||
, mouseOverIndex(-1)
|
||||
, mouseDownIndex(-1)
|
||||
, lastMousePosition()
|
||||
, buttonHeight(16)
|
||||
, trackHeight(100)
|
||||
, thumbRect()
|
||||
, maximum()
|
||||
, minimum()
|
||||
, largeChange()
|
||||
, smallChange()
|
||||
, desiredValue()
|
||||
, currentValueChanged()
|
||||
, currentValue()
|
||||
, _mutex()
|
||||
, _currentValueAnimation(this, "currentValue")
|
||||
, _highlights(NULL)
|
||||
, _mouseOverIndex(-1)
|
||||
, _mouseDownIndex(-1)
|
||||
, _lastMousePosition()
|
||||
, _buttonHeight(16)
|
||||
, _trackHeight(100)
|
||||
, _thumbRect()
|
||||
, _maximum()
|
||||
, _minimum()
|
||||
, _largeChange()
|
||||
, _smallChange()
|
||||
, _desiredValue()
|
||||
, _currentValueChanged()
|
||||
, _currentValue()
|
||||
{
|
||||
this->resize(16, 100);
|
||||
resize(16, 100);
|
||||
|
||||
this->currentValueAnimation.setDuration(300);
|
||||
this->currentValueAnimation.setEasingCurve(
|
||||
QEasingCurve(QEasingCurve::OutCubic));
|
||||
_currentValueAnimation.setDuration(250);
|
||||
_currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic));
|
||||
|
||||
this->setMouseTracking(true);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
ScrollBar::~ScrollBar()
|
||||
{
|
||||
auto highlight = this->highlights;
|
||||
auto highlight = _highlights;
|
||||
|
||||
while (highlight != NULL) {
|
||||
auto tmp = highlight->next;
|
||||
@@ -48,18 +47,17 @@ ScrollBar::~ScrollBar()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func)
|
||||
void ScrollBar::removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func)
|
||||
{
|
||||
this->mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
ScrollBarHighlight *last = NULL;
|
||||
ScrollBarHighlight *current = this->highlights;
|
||||
ScrollBarHighlight *current = _highlights;
|
||||
|
||||
while (current != NULL) {
|
||||
if (func(*current)) {
|
||||
if (last == NULL) {
|
||||
this->highlights = current->next;
|
||||
_highlights = current->next;
|
||||
} else {
|
||||
last->next = current->next;
|
||||
}
|
||||
@@ -73,150 +71,233 @@ ScrollBar::removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func)
|
||||
}
|
||||
}
|
||||
|
||||
this->mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::addHighlight(ScrollBarHighlight *highlight)
|
||||
void ScrollBar::addHighlight(ScrollBarHighlight *highlight)
|
||||
{
|
||||
this->mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
if (this->highlights == NULL) {
|
||||
this->highlights = highlight;
|
||||
if (_highlights == NULL) {
|
||||
_highlights = highlight;
|
||||
} else {
|
||||
highlight->next = this->highlights->next;
|
||||
this->highlights->next = highlight;
|
||||
highlight->next = _highlights->next;
|
||||
_highlights->next = highlight;
|
||||
}
|
||||
|
||||
this->mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::paintEvent(QPaintEvent *)
|
||||
void ScrollBar::setMaximum(qreal value)
|
||||
{
|
||||
_maximum = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void ScrollBar::setMinimum(qreal value)
|
||||
{
|
||||
_minimum = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void ScrollBar::setLargeChange(qreal value)
|
||||
{
|
||||
_largeChange = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void ScrollBar::setSmallChange(qreal value)
|
||||
{
|
||||
_smallChange = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void ScrollBar::setDesiredValue(qreal value, bool animated)
|
||||
{
|
||||
value = std::max(_minimum, std::min(_maximum - _largeChange, value));
|
||||
|
||||
if (_desiredValue != value) {
|
||||
if (animated) {
|
||||
_currentValueAnimation.stop();
|
||||
_currentValueAnimation.setStartValue(_currentValue);
|
||||
|
||||
_currentValueAnimation.setEndValue(value);
|
||||
_currentValueAnimation.start();
|
||||
} else {
|
||||
if (_currentValueAnimation.state() != QPropertyAnimation::Running) {
|
||||
// currentValueAnimation.stop();
|
||||
|
||||
setCurrentValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_desiredValue = value;
|
||||
}
|
||||
|
||||
qreal ScrollBar::getMaximum() const
|
||||
{
|
||||
return _maximum;
|
||||
}
|
||||
|
||||
qreal ScrollBar::getMinimum() const
|
||||
{
|
||||
return _minimum;
|
||||
}
|
||||
|
||||
qreal ScrollBar::getLargeChange() const
|
||||
{
|
||||
return _largeChange;
|
||||
}
|
||||
|
||||
qreal ScrollBar::getSmallChange() const
|
||||
{
|
||||
return _smallChange;
|
||||
}
|
||||
|
||||
qreal ScrollBar::getDesiredValue() const
|
||||
{
|
||||
return _desiredValue;
|
||||
}
|
||||
|
||||
qreal ScrollBar::getCurrentValue() const
|
||||
{
|
||||
return _currentValue;
|
||||
}
|
||||
|
||||
boost::signals2::signal<void()> &ScrollBar::getCurrentValueChanged()
|
||||
{
|
||||
return _currentValueChanged;
|
||||
}
|
||||
|
||||
void ScrollBar::setCurrentValue(qreal value)
|
||||
{
|
||||
value = std::max(_minimum, std::min(_maximum - _largeChange, value));
|
||||
|
||||
if (_currentValue != value) {
|
||||
_currentValue = value;
|
||||
|
||||
updateScroll();
|
||||
_currentValueChanged();
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollBar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), ColorScheme::getInstance().ScrollbarBG);
|
||||
|
||||
painter.fillRect(QRect(0, 0, width(), this->buttonHeight),
|
||||
QColor(255, 0, 0));
|
||||
painter.fillRect(
|
||||
QRect(0, height() - this->buttonHeight, width(), this->buttonHeight),
|
||||
QColor(255, 0, 0));
|
||||
painter.fillRect(QRect(0, 0, width(), _buttonHeight), QColor(255, 0, 0));
|
||||
painter.fillRect(QRect(0, height() - _buttonHeight, width(), _buttonHeight), QColor(255, 0, 0));
|
||||
|
||||
painter.fillRect(this->thumbRect, QColor(0, 255, 255));
|
||||
painter.fillRect(_thumbRect, QColor(0, 255, 255));
|
||||
|
||||
ScrollBarHighlight *highlight = this->highlights;
|
||||
// ScrollBarHighlight *highlight = highlights;
|
||||
|
||||
this->mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
// do {
|
||||
// painter.fillRect();
|
||||
// } while ((highlight = highlight->next()) != NULL);
|
||||
|
||||
this->mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::mouseMoveEvent(QMouseEvent *event)
|
||||
void ScrollBar::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->mouseDownIndex == -1) {
|
||||
if (_mouseDownIndex == -1) {
|
||||
int y = event->pos().y();
|
||||
|
||||
auto oldIndex = this->mouseOverIndex;
|
||||
auto oldIndex = _mouseOverIndex;
|
||||
|
||||
if (y < this->buttonHeight) {
|
||||
this->mouseOverIndex = 0;
|
||||
} else if (y < this->thumbRect.y()) {
|
||||
this->mouseOverIndex = 1;
|
||||
} else if (this->thumbRect.contains(2, y)) {
|
||||
this->mouseOverIndex = 2;
|
||||
} else if (y < height() - this->buttonHeight) {
|
||||
this->mouseOverIndex = 3;
|
||||
if (y < _buttonHeight) {
|
||||
_mouseOverIndex = 0;
|
||||
} else if (y < _thumbRect.y()) {
|
||||
_mouseOverIndex = 1;
|
||||
} else if (_thumbRect.contains(2, y)) {
|
||||
_mouseOverIndex = 2;
|
||||
} else if (y < height() - _buttonHeight) {
|
||||
_mouseOverIndex = 3;
|
||||
} else {
|
||||
this->mouseOverIndex = 4;
|
||||
_mouseOverIndex = 4;
|
||||
}
|
||||
|
||||
if (oldIndex != this->mouseOverIndex) {
|
||||
this->update();
|
||||
if (oldIndex != _mouseOverIndex) {
|
||||
update();
|
||||
}
|
||||
} else if (this->mouseDownIndex == 2) {
|
||||
int delta = event->pos().y() - lastMousePosition.y();
|
||||
} else if (_mouseDownIndex == 2) {
|
||||
int delta = event->pos().y() - _lastMousePosition.y();
|
||||
|
||||
this->setDesiredValue(this->desiredValue +
|
||||
(qreal)delta / this->trackHeight * maximum);
|
||||
setDesiredValue(_desiredValue + (qreal)delta / _trackHeight * _maximum);
|
||||
}
|
||||
|
||||
this->lastMousePosition = event->pos();
|
||||
_lastMousePosition = event->pos();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::mousePressEvent(QMouseEvent *event)
|
||||
void ScrollBar::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
int y = event->pos().y();
|
||||
|
||||
if (y < this->buttonHeight) {
|
||||
this->mouseDownIndex = 0;
|
||||
} else if (y < this->thumbRect.y()) {
|
||||
this->mouseDownIndex = 1;
|
||||
} else if (this->thumbRect.contains(2, y)) {
|
||||
this->mouseDownIndex = 2;
|
||||
} else if (y < height() - this->buttonHeight) {
|
||||
this->mouseDownIndex = 3;
|
||||
if (y < _buttonHeight) {
|
||||
_mouseDownIndex = 0;
|
||||
} else if (y < _thumbRect.y()) {
|
||||
_mouseDownIndex = 1;
|
||||
} else if (_thumbRect.contains(2, y)) {
|
||||
_mouseDownIndex = 2;
|
||||
} else if (y < height() - _buttonHeight) {
|
||||
_mouseDownIndex = 3;
|
||||
} else {
|
||||
this->mouseDownIndex = 4;
|
||||
_mouseDownIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::mouseReleaseEvent(QMouseEvent *event)
|
||||
void ScrollBar::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
int y = event->pos().y();
|
||||
|
||||
if (y < this->buttonHeight) {
|
||||
if (this->mouseDownIndex == 0) {
|
||||
this->setDesiredValue(this->desiredValue - this->smallChange, true);
|
||||
if (y < _buttonHeight) {
|
||||
if (_mouseDownIndex == 0) {
|
||||
setDesiredValue(_desiredValue - _smallChange, true);
|
||||
}
|
||||
} else if (y < this->thumbRect.y()) {
|
||||
if (this->mouseDownIndex == 1) {
|
||||
this->setDesiredValue(this->desiredValue - this->smallChange, true);
|
||||
} else if (y < _thumbRect.y()) {
|
||||
if (_mouseDownIndex == 1) {
|
||||
setDesiredValue(_desiredValue - _smallChange, true);
|
||||
}
|
||||
} else if (this->thumbRect.contains(2, y)) {
|
||||
} else if (_thumbRect.contains(2, y)) {
|
||||
// do nothing
|
||||
} else if (y < height() - this->buttonHeight) {
|
||||
if (this->mouseDownIndex == 3) {
|
||||
this->setDesiredValue(this->desiredValue + this->smallChange, true);
|
||||
} else if (y < height() - _buttonHeight) {
|
||||
if (_mouseDownIndex == 3) {
|
||||
setDesiredValue(_desiredValue + _smallChange, true);
|
||||
}
|
||||
} else {
|
||||
if (this->mouseDownIndex == 4) {
|
||||
this->setDesiredValue(this->desiredValue + this->smallChange, true);
|
||||
if (_mouseDownIndex == 4) {
|
||||
setDesiredValue(_desiredValue + _smallChange, true);
|
||||
}
|
||||
}
|
||||
|
||||
this->mouseDownIndex = -1;
|
||||
_mouseDownIndex = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::leaveEvent(QEvent *)
|
||||
void ScrollBar::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOverIndex = -1;
|
||||
_mouseOverIndex = -1;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollBar::updateScroll()
|
||||
void ScrollBar::updateScroll()
|
||||
{
|
||||
this->trackHeight = height() - this->buttonHeight - this->buttonHeight -
|
||||
MIN_THUMB_HEIGHT - 1;
|
||||
_trackHeight = height() - _buttonHeight - _buttonHeight - MIN_THUMB_HEIGHT - 1;
|
||||
|
||||
this->thumbRect =
|
||||
QRect(0,
|
||||
(int)(this->currentValue / this->maximum * this->trackHeight) +
|
||||
1 + this->buttonHeight,
|
||||
width(),
|
||||
(int)(this->largeChange / this->maximum * this->trackHeight) +
|
||||
MIN_THUMB_HEIGHT);
|
||||
_thumbRect = QRect(0, (int)(_currentValue / _maximum * _trackHeight) + 1 + _buttonHeight,
|
||||
width(), (int)(_largeChange / _maximum * _trackHeight) + MIN_THUMB_HEIGHT);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
+31
-130
@@ -23,128 +23,29 @@ public:
|
||||
void removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func);
|
||||
void addHighlight(ScrollBarHighlight *highlight);
|
||||
|
||||
Q_PROPERTY(qreal desiredValue READ getDesiredValue WRITE setDesiredValue)
|
||||
Q_PROPERTY(qreal _desiredValue READ getDesiredValue WRITE setDesiredValue)
|
||||
|
||||
void
|
||||
setMaximum(qreal value)
|
||||
{
|
||||
this->maximum = value;
|
||||
|
||||
this->updateScroll();
|
||||
}
|
||||
|
||||
void
|
||||
setMinimum(qreal value)
|
||||
{
|
||||
this->minimum = value;
|
||||
|
||||
this->updateScroll();
|
||||
}
|
||||
|
||||
void
|
||||
setLargeChange(qreal value)
|
||||
{
|
||||
this->largeChange = value;
|
||||
|
||||
this->updateScroll();
|
||||
}
|
||||
|
||||
void
|
||||
setSmallChange(qreal value)
|
||||
{
|
||||
this->smallChange = value;
|
||||
|
||||
this->updateScroll();
|
||||
}
|
||||
|
||||
void
|
||||
setDesiredValue(qreal value, bool animated = false)
|
||||
{
|
||||
value = std::max(this->minimum,
|
||||
std::min(this->maximum - this->largeChange, value));
|
||||
|
||||
if (this->desiredValue != value) {
|
||||
if (animated) {
|
||||
this->currentValueAnimation.stop();
|
||||
this->currentValueAnimation.setStartValue(this->currentValue);
|
||||
|
||||
this->currentValueAnimation.setEndValue(value);
|
||||
this->currentValueAnimation.start();
|
||||
} else {
|
||||
this->currentValueAnimation.stop();
|
||||
|
||||
this->setCurrentValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
this->desiredValue = value;
|
||||
}
|
||||
|
||||
qreal
|
||||
getMaximum() const
|
||||
{
|
||||
return this->maximum;
|
||||
}
|
||||
|
||||
qreal
|
||||
getMinimum() const
|
||||
{
|
||||
return this->minimum;
|
||||
}
|
||||
|
||||
qreal
|
||||
getLargeChange() const
|
||||
{
|
||||
return this->largeChange;
|
||||
}
|
||||
|
||||
qreal
|
||||
getSmallChange() const
|
||||
{
|
||||
return this->smallChange;
|
||||
}
|
||||
|
||||
qreal
|
||||
getDesiredValue() const
|
||||
{
|
||||
return this->desiredValue;
|
||||
}
|
||||
|
||||
qreal
|
||||
getCurrentValue() const
|
||||
{
|
||||
return this->currentValue;
|
||||
}
|
||||
|
||||
boost::signals2::signal<void()> &
|
||||
getCurrentValueChanged()
|
||||
{
|
||||
return currentValueChanged;
|
||||
}
|
||||
|
||||
void
|
||||
setCurrentValue(qreal value)
|
||||
{
|
||||
value = std::max(this->minimum,
|
||||
std::min(this->maximum - this->largeChange, value));
|
||||
|
||||
if (this->currentValue != value) {
|
||||
this->currentValue = value;
|
||||
|
||||
this->updateScroll();
|
||||
this->currentValueChanged();
|
||||
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
void setMaximum(qreal value);
|
||||
void setMinimum(qreal value);
|
||||
void setLargeChange(qreal value);
|
||||
void setSmallChange(qreal value);
|
||||
void setDesiredValue(qreal value, bool animated = false);
|
||||
qreal getMaximum() const;
|
||||
qreal getMinimum() const;
|
||||
qreal getLargeChange() const;
|
||||
qreal getSmallChange() const;
|
||||
qreal getDesiredValue() const;
|
||||
qreal getCurrentValue() const;
|
||||
boost::signals2::signal<void()> &getCurrentValueChanged();
|
||||
void setCurrentValue(qreal value);
|
||||
|
||||
private:
|
||||
Q_PROPERTY(qreal currentValue READ getCurrentValue WRITE setCurrentValue)
|
||||
Q_PROPERTY(qreal _currentValue READ getCurrentValue WRITE setCurrentValue)
|
||||
|
||||
QMutex mutex;
|
||||
ScrollBarHighlight *highlights;
|
||||
QMutex _mutex;
|
||||
ScrollBarHighlight *_highlights;
|
||||
|
||||
QPropertyAnimation currentValueAnimation;
|
||||
QPropertyAnimation _currentValueAnimation;
|
||||
|
||||
void paintEvent(QPaintEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
@@ -152,23 +53,23 @@ private:
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void leaveEvent(QEvent *);
|
||||
|
||||
int mouseOverIndex;
|
||||
int mouseDownIndex;
|
||||
QPoint lastMousePosition;
|
||||
int _mouseOverIndex;
|
||||
int _mouseDownIndex;
|
||||
QPoint _lastMousePosition;
|
||||
|
||||
int buttonHeight;
|
||||
int trackHeight;
|
||||
int _buttonHeight;
|
||||
int _trackHeight;
|
||||
|
||||
QRect thumbRect;
|
||||
QRect _thumbRect;
|
||||
|
||||
qreal maximum;
|
||||
qreal minimum;
|
||||
qreal largeChange;
|
||||
qreal smallChange;
|
||||
qreal desiredValue;
|
||||
qreal currentValue;
|
||||
qreal _maximum;
|
||||
qreal _minimum;
|
||||
qreal _largeChange;
|
||||
qreal _smallChange;
|
||||
qreal _desiredValue;
|
||||
qreal _currentValue;
|
||||
|
||||
boost::signals2::signal<void()> currentValueChanged;
|
||||
boost::signals2::signal<void()> _currentValueChanged;
|
||||
|
||||
void updateScroll();
|
||||
};
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ScrollBarHighlight::ScrollBarHighlight(float position, int colorIndex,
|
||||
Style style, QString tag)
|
||||
: position(position)
|
||||
, colorIndex(std::max(
|
||||
0, std::min(ColorScheme::getInstance().HighlightColorCount, colorIndex)))
|
||||
, style(style)
|
||||
, tag(tag)
|
||||
ScrollBarHighlight::ScrollBarHighlight(float position, int colorIndex, Style style, QString tag)
|
||||
: _position(position)
|
||||
, _colorIndex(std::max(0, std::min(ColorScheme::getInstance().HighlightColorCount, colorIndex)))
|
||||
, _style(style)
|
||||
, _tag(tag)
|
||||
, next(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,40 +11,36 @@ class ScrollBarHighlight
|
||||
public:
|
||||
enum Style { Default, Left, Right, SingleLine };
|
||||
|
||||
ScrollBarHighlight(float getPosition, int getColorIndex,
|
||||
Style getStyle = Default, QString tag = "");
|
||||
ScrollBarHighlight(float getPosition, int getColorIndex, Style getStyle = Default,
|
||||
QString _tag = "");
|
||||
|
||||
Style
|
||||
getStyle()
|
||||
Style getStyle()
|
||||
{
|
||||
return style;
|
||||
return _style;
|
||||
}
|
||||
|
||||
float
|
||||
getPosition()
|
||||
float getPosition()
|
||||
{
|
||||
return position;
|
||||
return _position;
|
||||
}
|
||||
|
||||
int
|
||||
getColorIndex()
|
||||
int getColorIndex()
|
||||
{
|
||||
return colorIndex;
|
||||
return _colorIndex;
|
||||
}
|
||||
|
||||
QString
|
||||
getTag()
|
||||
QString getTag()
|
||||
{
|
||||
return tag;
|
||||
return _tag;
|
||||
}
|
||||
|
||||
ScrollBarHighlight *next;
|
||||
|
||||
private:
|
||||
Style style;
|
||||
float position;
|
||||
int colorIndex;
|
||||
QString tag;
|
||||
Style _style;
|
||||
float _position;
|
||||
int _colorIndex;
|
||||
QString _tag;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+55
-81
@@ -1,6 +1,6 @@
|
||||
#include "widgets/settingsdialog.h"
|
||||
#include "widgets/settingsdialogtab.h"
|
||||
#include "windows.h"
|
||||
#include "windowmanager.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QFile>
|
||||
@@ -14,7 +14,7 @@ namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
SettingsDialog::SettingsDialog()
|
||||
: snapshot(Settings::getInstance().createSnapshot())
|
||||
: _snapshot(SettingsManager::getInstance().createSnapshot())
|
||||
{
|
||||
QFile file(":/qss/settings.qss");
|
||||
file.open(QFile::ReadOnly);
|
||||
@@ -25,44 +25,41 @@ SettingsDialog::SettingsDialog()
|
||||
palette.setColor(QPalette::Background, QColor("#444"));
|
||||
setPalette(palette);
|
||||
|
||||
pageStack.setObjectName("pages");
|
||||
_pageStack.setObjectName("pages");
|
||||
|
||||
setLayout(&vbox);
|
||||
setLayout(&_vbox);
|
||||
|
||||
vbox.addLayout(&hbox);
|
||||
_vbox.addLayout(&_hbox);
|
||||
|
||||
vbox.addWidget(&buttonBox);
|
||||
_vbox.addWidget(&_buttonBox);
|
||||
|
||||
auto tabWidget = new QWidget();
|
||||
tabWidget->setObjectName("tabWidget");
|
||||
|
||||
tabWidget->setLayout(&tabs);
|
||||
tabWidget->setLayout(&_tabs);
|
||||
tabWidget->setFixedWidth(200);
|
||||
|
||||
hbox.addWidget(tabWidget);
|
||||
hbox.addLayout(&pageStack);
|
||||
_hbox.addWidget(tabWidget);
|
||||
_hbox.addLayout(&_pageStack);
|
||||
|
||||
buttonBox.addButton(&okButton, QDialogButtonBox::ButtonRole::AcceptRole);
|
||||
buttonBox.addButton(&cancelButton,
|
||||
QDialogButtonBox::ButtonRole::RejectRole);
|
||||
_buttonBox.addButton(&_okButton, QDialogButtonBox::ButtonRole::AcceptRole);
|
||||
_buttonBox.addButton(&_cancelButton, QDialogButtonBox::ButtonRole::RejectRole);
|
||||
|
||||
QObject::connect(&okButton, &QPushButton::clicked, this,
|
||||
&SettingsDialog::okButtonClicked);
|
||||
QObject::connect(&cancelButton, &QPushButton::clicked, this,
|
||||
QObject::connect(&_okButton, &QPushButton::clicked, this, &SettingsDialog::okButtonClicked);
|
||||
QObject::connect(&_cancelButton, &QPushButton::clicked, this,
|
||||
&SettingsDialog::cancelButtonClicked);
|
||||
|
||||
okButton.setText("OK");
|
||||
cancelButton.setText("Cancel");
|
||||
_okButton.setText("OK");
|
||||
_cancelButton.setText("Cancel");
|
||||
|
||||
resize(600, 500);
|
||||
|
||||
addTabs();
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialog::addTabs()
|
||||
void SettingsDialog::addTabs()
|
||||
{
|
||||
Settings &settings = Settings::getInstance();
|
||||
SettingsManager &settings = SettingsManager::getInstance();
|
||||
|
||||
QVBoxLayout *vbox;
|
||||
|
||||
@@ -77,11 +74,9 @@ SettingsDialog::addTabs()
|
||||
auto slider = new QSlider(Qt::Horizontal);
|
||||
auto font = new QPushButton("select");
|
||||
auto compactTabs = createCheckbox("Hide tab X", settings.hideTabX);
|
||||
auto hidePreferencesButton =
|
||||
createCheckbox("Hide preferences button (ctrl+p to show)",
|
||||
settings.hidePreferencesButton);
|
||||
auto hideUserButton =
|
||||
createCheckbox("Hide user button", settings.hideUserButton);
|
||||
auto hidePreferencesButton = createCheckbox("Hide preferences button (ctrl+p to show)",
|
||||
settings.hidePreferencesButton);
|
||||
auto hideUserButton = createCheckbox("Hide user button", settings.hideUserButton);
|
||||
|
||||
form->addRow("Theme:", combo);
|
||||
form->addRow("Theme color:", slider);
|
||||
@@ -110,9 +105,7 @@ SettingsDialog::addTabs()
|
||||
}
|
||||
|
||||
QObject::connect(combo, &QComboBox::currentTextChanged, this,
|
||||
[this, &settings](const QString &value) {
|
||||
settings.theme.set(value);
|
||||
});
|
||||
[this, &settings](const QString &value) { settings.theme.set(value); });
|
||||
|
||||
// theme hue
|
||||
slider->setMinimum(0);
|
||||
@@ -120,14 +113,12 @@ SettingsDialog::addTabs()
|
||||
|
||||
float hue = settings.themeHue.get();
|
||||
|
||||
slider->setValue(std::min(std::max(hue, (float)0.0), (float)1.0) *
|
||||
1000);
|
||||
slider->setValue(std::min(std::max(hue, (float)0.0), (float)1.0) * 1000);
|
||||
|
||||
QObject::connect(slider, &QSlider::valueChanged, this,
|
||||
[this, &settings](int value) {
|
||||
settings.themeHue.set(value / 1000.0);
|
||||
Windows::updateAll();
|
||||
});
|
||||
QObject::connect(slider, &QSlider::valueChanged, this, [this, &settings](int value) {
|
||||
settings.themeHue.set(value / 1000.0);
|
||||
WindowManager::updateAll();
|
||||
});
|
||||
|
||||
group->setLayout(form);
|
||||
|
||||
@@ -139,15 +130,11 @@ SettingsDialog::addTabs()
|
||||
|
||||
auto v = new QVBoxLayout();
|
||||
v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps));
|
||||
v->addWidget(createCheckbox("Show seconds in timestamp",
|
||||
settings.showTimestampSeconds));
|
||||
v->addWidget(createCheckbox(
|
||||
"Allow sending duplicate messages (add a space at the end)",
|
||||
settings.allowDouplicateMessages));
|
||||
v->addWidget(
|
||||
createCheckbox("Seperate messages", settings.seperateMessages));
|
||||
v->addWidget(
|
||||
createCheckbox("Show message length", settings.showMessageLength));
|
||||
v->addWidget(createCheckbox("Show seconds in timestamp", settings.showTimestampSeconds));
|
||||
v->addWidget(createCheckbox("Allow sending duplicate messages (add a space at the end)",
|
||||
settings.allowDouplicateMessages));
|
||||
v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages));
|
||||
v->addWidget(createCheckbox("Show message length", settings.showMessageLength));
|
||||
|
||||
group->setLayout(v);
|
||||
|
||||
@@ -161,15 +148,12 @@ SettingsDialog::addTabs()
|
||||
// Behaviour
|
||||
vbox = new QVBoxLayout();
|
||||
|
||||
vbox->addWidget(createCheckbox("Hide input box if empty", settings.hideEmptyInput));
|
||||
vbox->addWidget(
|
||||
createCheckbox("Hide input box if empty", settings.hideEmptyInput));
|
||||
createCheckbox("Mention users with a @ (except in commands)", settings.mentionUsersWithAt));
|
||||
vbox->addWidget(createCheckbox("Window always on top", settings.windowTopMost));
|
||||
vbox->addWidget(
|
||||
createCheckbox("Mention users with a @ (except in commands)",
|
||||
settings.mentionUsersWithAt));
|
||||
vbox->addWidget(
|
||||
createCheckbox("Window always on top", settings.windowTopMost));
|
||||
vbox->addWidget(createCheckbox("Show last read message indicator",
|
||||
settings.showLastMessageIndicator));
|
||||
createCheckbox("Show last read message indicator", settings.showLastMessageIndicator));
|
||||
|
||||
{
|
||||
auto v = new QVBoxLayout();
|
||||
@@ -197,17 +181,13 @@ SettingsDialog::addTabs()
|
||||
// Emotes
|
||||
vbox = new QVBoxLayout();
|
||||
|
||||
vbox->addWidget(
|
||||
createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
||||
vbox->addWidget(
|
||||
createCheckbox("Enable BetterTTV Emotes", settings.enableBttvEmotes));
|
||||
vbox->addWidget(
|
||||
createCheckbox("Enable FrankerFaceZ Emotes", settings.enableFfzEmotes));
|
||||
vbox->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
||||
vbox->addWidget(createCheckbox("Enable BetterTTV Emotes", settings.enableBttvEmotes));
|
||||
vbox->addWidget(createCheckbox("Enable FrankerFaceZ Emotes", settings.enableFfzEmotes));
|
||||
vbox->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifs));
|
||||
vbox->addWidget(createCheckbox("Enable Emojis", settings.enableEmojis));
|
||||
|
||||
vbox->addWidget(
|
||||
createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
||||
vbox->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
|
||||
|
||||
vbox->addStretch(1);
|
||||
addTab(vbox, "Emotes", ":/images/Emoji_Color_1F60A_19.png");
|
||||
@@ -215,8 +195,7 @@ SettingsDialog::addTabs()
|
||||
// Ignored Users
|
||||
vbox = new QVBoxLayout();
|
||||
vbox->addStretch(1);
|
||||
addTab(vbox, "Ignored Users",
|
||||
":/images/StatusAnnotations_Blocked_16xLG_color.png");
|
||||
addTab(vbox, "Ignored Users", ":/images/StatusAnnotations_Blocked_16xLG_color.png");
|
||||
|
||||
// Ignored Messages
|
||||
vbox = new QVBoxLayout();
|
||||
@@ -244,11 +223,10 @@ SettingsDialog::addTabs()
|
||||
addTab(vbox, "Whispers", ":/images/Message_16xLG.png");
|
||||
|
||||
// Add stretch
|
||||
tabs.addStretch(1);
|
||||
_tabs.addStretch(1);
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes)
|
||||
void SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes)
|
||||
{
|
||||
auto widget = new QWidget();
|
||||
|
||||
@@ -258,33 +236,31 @@ SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes)
|
||||
|
||||
tab->setWidget(widget);
|
||||
|
||||
tabs.addWidget(tab, 0, Qt::AlignTop);
|
||||
_tabs.addWidget(tab, 0, Qt::AlignTop);
|
||||
|
||||
pageStack.addWidget(widget);
|
||||
_pageStack.addWidget(widget);
|
||||
|
||||
if (tabs.count() == 1) {
|
||||
if (_tabs.count() == 1) {
|
||||
select(tab);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialog::select(SettingsDialogTab *tab)
|
||||
void SettingsDialog::select(SettingsDialogTab *tab)
|
||||
{
|
||||
pageStack.setCurrentWidget(tab->getWidget());
|
||||
_pageStack.setCurrentWidget(tab->getWidget());
|
||||
|
||||
if (selectedTab != NULL) {
|
||||
selectedTab->setSelected(false);
|
||||
selectedTab->setStyleSheet("color: #FFF");
|
||||
if (_selectedTab != NULL) {
|
||||
_selectedTab->setSelected(false);
|
||||
_selectedTab->setStyleSheet("color: #FFF");
|
||||
}
|
||||
|
||||
tab->setSelected(true);
|
||||
tab->setStyleSheet("background: #555; color: #FFF");
|
||||
selectedTab = tab;
|
||||
_selectedTab = tab;
|
||||
}
|
||||
|
||||
/// Widget creation helpers
|
||||
QCheckBox *
|
||||
SettingsDialog::createCheckbox(const QString &title, Setting<bool> &setting)
|
||||
QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting<bool> &setting)
|
||||
{
|
||||
auto checkbox = new QCheckBox(title);
|
||||
|
||||
@@ -297,16 +273,14 @@ SettingsDialog::createCheckbox(const QString &title, Setting<bool> &setting)
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialog::okButtonClicked()
|
||||
void SettingsDialog::okButtonClicked()
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialog::cancelButtonClicked()
|
||||
void SettingsDialog::cancelButtonClicked()
|
||||
{
|
||||
snapshot.apply();
|
||||
_snapshot.apply();
|
||||
|
||||
this->close();
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
#ifndef SETTINGSDIALOG_H
|
||||
#define SETTINGSDIALOG_H
|
||||
|
||||
#include "settings.h"
|
||||
#include "settingsmanager.h"
|
||||
#include "settingssnapshot.h"
|
||||
#include "widgets/settingsdialogtab.h"
|
||||
|
||||
@@ -27,21 +27,21 @@ public:
|
||||
void select(SettingsDialogTab *tab);
|
||||
|
||||
private:
|
||||
SettingsSnapshot snapshot;
|
||||
SettingsSnapshot _snapshot;
|
||||
|
||||
QVBoxLayout tabs;
|
||||
QVBoxLayout vbox;
|
||||
QHBoxLayout hbox;
|
||||
QStackedLayout pageStack;
|
||||
QDialogButtonBox buttonBox;
|
||||
QPushButton okButton;
|
||||
QPushButton cancelButton;
|
||||
QVBoxLayout _tabs;
|
||||
QVBoxLayout _vbox;
|
||||
QHBoxLayout _hbox;
|
||||
QStackedLayout _pageStack;
|
||||
QDialogButtonBox _buttonBox;
|
||||
QPushButton _okButton;
|
||||
QPushButton _cancelButton;
|
||||
|
||||
void addTab(QLayout *layout, QString title, QString imageRes);
|
||||
|
||||
void addTabs();
|
||||
|
||||
SettingsDialogTab *selectedTab = NULL;
|
||||
SettingsDialogTab *_selectedTab = NULL;
|
||||
|
||||
/// Widget creation helpers
|
||||
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label,
|
||||
QString imageRes)
|
||||
: image(QImage(imageRes))
|
||||
SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label, QString imageRes)
|
||||
: _label(label)
|
||||
, _image(QImage(imageRes))
|
||||
, _dialog(dialog)
|
||||
, _selected(false)
|
||||
{
|
||||
this->dialog = dialog;
|
||||
|
||||
this->label = label;
|
||||
setFixedHeight(32);
|
||||
|
||||
setCursor(QCursor(Qt::PointingHandCursor));
|
||||
@@ -21,8 +20,31 @@ SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label,
|
||||
setStyleSheet("color: #FFF");
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialogTab::paintEvent(QPaintEvent *)
|
||||
void SettingsDialogTab::setSelected(bool selected)
|
||||
{
|
||||
if (_selected == selected)
|
||||
return;
|
||||
|
||||
_selected = selected;
|
||||
emit selectedChanged(selected);
|
||||
}
|
||||
|
||||
bool SettingsDialogTab::getSelected() const
|
||||
{
|
||||
return _selected;
|
||||
}
|
||||
|
||||
QWidget *SettingsDialogTab::getWidget()
|
||||
{
|
||||
return _widget;
|
||||
}
|
||||
|
||||
void SettingsDialogTab::setWidget(QWidget *widget)
|
||||
{
|
||||
_widget = widget;
|
||||
}
|
||||
|
||||
void SettingsDialogTab::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -31,23 +53,22 @@ SettingsDialogTab::paintEvent(QPaintEvent *)
|
||||
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
|
||||
|
||||
int a = (height() - image.width()) / 2;
|
||||
int a = (height() - _image.width()) / 2;
|
||||
|
||||
painter.drawImage(a, a, image);
|
||||
painter.drawImage(a, a, _image);
|
||||
|
||||
a = a + a + image.width();
|
||||
a = a + a + _image.width();
|
||||
|
||||
painter.drawText(QRect(a, 0, width() - a, height()), label,
|
||||
painter.drawText(QRect(a, 0, width() - a, height()), _label,
|
||||
QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
|
||||
}
|
||||
|
||||
void
|
||||
SettingsDialogTab::mouseReleaseEvent(QMouseEvent *event)
|
||||
void SettingsDialogTab::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
dialog->select(this);
|
||||
_dialog->select(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-35
@@ -12,39 +12,15 @@ class SettingsDialog;
|
||||
class SettingsDialogTab : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool getSelected READ getSelected WRITE setSelected NOTIFY
|
||||
selectedChanged)
|
||||
Q_PROPERTY(bool getSelected READ getSelected WRITE setSelected NOTIFY selectedChanged)
|
||||
|
||||
public:
|
||||
SettingsDialogTab(SettingsDialog *dialog, QString label, QString imageRes);
|
||||
SettingsDialogTab(SettingsDialog *_dialog, QString _label, QString imageRes);
|
||||
|
||||
void
|
||||
setSelected(bool selected)
|
||||
{
|
||||
if (this->selected == selected)
|
||||
return;
|
||||
|
||||
this->selected = selected;
|
||||
emit selectedChanged(selected);
|
||||
}
|
||||
|
||||
bool
|
||||
getSelected() const
|
||||
{
|
||||
return this->selected;
|
||||
}
|
||||
|
||||
QWidget *
|
||||
getWidget()
|
||||
{
|
||||
return this->widget;
|
||||
}
|
||||
|
||||
void
|
||||
setWidget(QWidget *widget)
|
||||
{
|
||||
this->widget = widget;
|
||||
}
|
||||
void setSelected(bool selected);
|
||||
bool getSelected() const;
|
||||
QWidget *getWidget();
|
||||
void setWidget(QWidget *widget);
|
||||
|
||||
signals:
|
||||
void selectedChanged(bool);
|
||||
@@ -53,13 +29,13 @@ private:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
QWidget *widget;
|
||||
QString label;
|
||||
QImage image;
|
||||
QWidget *_widget;
|
||||
QString _label;
|
||||
QImage _image;
|
||||
|
||||
SettingsDialog *dialog = NULL;
|
||||
SettingsDialog *_dialog;
|
||||
|
||||
bool selected = false;
|
||||
bool _selected;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,12 @@ signals:
|
||||
void mouseUp();
|
||||
|
||||
protected:
|
||||
virtual void
|
||||
mouseDoubleClickEvent(QMouseEvent *ev) override
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *ev) override
|
||||
{
|
||||
emit this->mouseDoubleClick(ev);
|
||||
}
|
||||
|
||||
virtual void
|
||||
mousePressEvent(QMouseEvent *event) override
|
||||
virtual void mousePressEvent(QMouseEvent *event) override
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
emit mouseDown();
|
||||
@@ -40,8 +38,7 @@ protected:
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void
|
||||
mouseReleaseEvent(QMouseEvent *event) override
|
||||
void mouseReleaseEvent(QMouseEvent *event) override
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
emit mouseUp();
|
||||
@@ -50,8 +47,7 @@ protected:
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
virtual void
|
||||
mouseMoveEvent(QMouseEvent *event) override
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
+16
-20
@@ -6,38 +6,34 @@ namespace widgets {
|
||||
|
||||
TextInputDialog::TextInputDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, vbox(this)
|
||||
, lineEdit()
|
||||
, buttonBox()
|
||||
, okButton("OK")
|
||||
, cancelButton("Cancel")
|
||||
, _vbox(this)
|
||||
, _lineEdit()
|
||||
, _buttonBox()
|
||||
, _okButton("OK")
|
||||
, _cancelButton("Cancel")
|
||||
{
|
||||
this->vbox.addWidget(&this->lineEdit);
|
||||
this->vbox.addLayout(&this->buttonBox);
|
||||
this->buttonBox.addStretch(1);
|
||||
this->buttonBox.addWidget(&this->okButton);
|
||||
this->buttonBox.addWidget(&this->cancelButton);
|
||||
_vbox.addWidget(&_lineEdit);
|
||||
_vbox.addLayout(&_buttonBox);
|
||||
_buttonBox.addStretch(1);
|
||||
_buttonBox.addWidget(&_okButton);
|
||||
_buttonBox.addWidget(&_cancelButton);
|
||||
|
||||
QObject::connect(&this->okButton, SIGNAL(clicked()), this,
|
||||
SLOT(okButtonClicked()));
|
||||
QObject::connect(&this->cancelButton, SIGNAL(clicked()), this,
|
||||
SLOT(cancelButtonClicked()));
|
||||
QObject::connect(&_okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
|
||||
QObject::connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
|
||||
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
setWindowFlags((windowFlags() & ~(Qt::WindowContextHelpButtonHint)) |
|
||||
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
||||
setWindowFlags((windowFlags() & ~(Qt::WindowContextHelpButtonHint)) | Qt::Dialog |
|
||||
Qt::MSWindowsFixedSizeDialogHint);
|
||||
}
|
||||
|
||||
void
|
||||
TextInputDialog::okButtonClicked()
|
||||
void TextInputDialog::okButtonClicked()
|
||||
{
|
||||
accept();
|
||||
close();
|
||||
}
|
||||
|
||||
void
|
||||
TextInputDialog::cancelButtonClicked()
|
||||
void TextInputDialog::cancelButtonClicked()
|
||||
{
|
||||
reject();
|
||||
close();
|
||||
|
||||
@@ -18,24 +18,22 @@ class TextInputDialog : public QDialog
|
||||
public:
|
||||
TextInputDialog(QWidget *parent = NULL);
|
||||
|
||||
QString
|
||||
getText() const
|
||||
QString getText() const
|
||||
{
|
||||
return lineEdit.text();
|
||||
return _lineEdit.text();
|
||||
}
|
||||
|
||||
void
|
||||
setText(const QString &text)
|
||||
void setText(const QString &text)
|
||||
{
|
||||
lineEdit.setText(text);
|
||||
_lineEdit.setText(text);
|
||||
}
|
||||
|
||||
private:
|
||||
QVBoxLayout vbox;
|
||||
QLineEdit lineEdit;
|
||||
QHBoxLayout buttonBox;
|
||||
QPushButton okButton;
|
||||
QPushButton cancelButton;
|
||||
QVBoxLayout _vbox;
|
||||
QLineEdit _lineEdit;
|
||||
QHBoxLayout _buttonBox;
|
||||
QPushButton _okButton;
|
||||
QPushButton _cancelButton;
|
||||
|
||||
private slots:
|
||||
void okButtonClicked();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "titlebar.h"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
TitleBar::TitleBar(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setFixedHeight(32);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef TITLEBAR_H
|
||||
#define TITLEBAR_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
class TitleBar : public QWidget
|
||||
{
|
||||
public:
|
||||
TitleBar(QWidget *parent = nullptr);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TITLEBAR_H
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "widgets/userpopupwidget.h"
|
||||
#include "channel.h"
|
||||
#include "ui_userpopup.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
UserPopupWidget::UserPopupWidget(std::shared_ptr<Channel> &&channel)
|
||||
: QWidget(nullptr)
|
||||
, _ui(new Ui::UserPopup)
|
||||
, _channel(std::move(channel))
|
||||
{
|
||||
_ui->setupUi(this);
|
||||
|
||||
resize(0, 0);
|
||||
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
|
||||
// Close button
|
||||
connect(_ui->btnClose, &QPushButton::clicked, [=]() {
|
||||
hide(); //
|
||||
});
|
||||
|
||||
connect(_ui->btnPurge, &QPushButton::clicked, [=]() {
|
||||
qDebug() << "xD: " << _channel->getName();
|
||||
/*
|
||||
_channel->sendMessage(
|
||||
QString(".timeout %1 0").arg(_ui->lblUsername->text()));
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
void UserPopupWidget::setName(const QString &name)
|
||||
{
|
||||
_ui->lblUsername->setText(name);
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef USERPOPUPWIDGET_H
|
||||
#define USERPOPUPWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Ui {
|
||||
class UserPopup;
|
||||
}
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Channel;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class UserPopupWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UserPopupWidget(std::shared_ptr<Channel> &&_channel);
|
||||
|
||||
void setName(const QString &name);
|
||||
|
||||
private:
|
||||
Ui::UserPopup *_ui;
|
||||
|
||||
std::shared_ptr<Channel> _channel;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
#endif // USERPOPUPWIDGET_H
|
||||
Reference in New Issue
Block a user