mirror-chatterino2/widgets/chatwidget.cpp

88 lines
1.7 KiB
C++
Raw Normal View History

2017-01-18 21:30:23 +01:00
#include "widgets/chatwidget.h"
2017-01-17 00:15:44 +01:00
#include "channels.h"
2017-01-01 02:30:42 +01:00
#include "colorscheme.h"
2017-01-23 16:38:06 +01:00
#include "settings.h"
2017-01-18 21:30:23 +01:00
#include "widgets/textinputdialog.h"
2017-01-17 00:15:44 +01:00
#include <QFont>
#include <QFontDatabase>
#include <QPainter>
#include <QVBoxLayout>
2016-12-29 17:31:07 +01:00
2017-01-18 21:30:23 +01:00
namespace chatterino {
namespace widgets {
2016-12-29 17:31:07 +01:00
ChatWidget::ChatWidget(QWidget *parent)
2017-01-11 18:52:09 +01:00
: QWidget(parent)
2017-01-18 04:33:30 +01:00
, channel(NULL)
, channelName(QString())
, vbox(this)
, header(this)
, view(this)
, input()
2016-12-29 17:31:07 +01:00
{
2017-01-18 04:33:30 +01:00
this->vbox.setSpacing(0);
this->vbox.setMargin(1);
2017-01-01 02:30:42 +01:00
2017-01-18 04:33:30 +01:00
this->vbox.addWidget(&header);
2017-01-21 05:14:27 +01:00
this->vbox.addWidget(&view, 1);
2017-01-18 04:33:30 +01:00
this->vbox.addWidget(&input);
2017-01-01 02:30:42 +01:00
}
ChatWidget::~ChatWidget()
{
2016-12-29 17:31:07 +01:00
}
2017-01-17 00:15:44 +01:00
void
ChatWidget::setChannelName(const QString &name)
{
QString channel = name.trimmed();
2017-01-18 04:33:30 +01:00
if (QString::compare(channel, this->channelName, Qt::CaseInsensitive) ==
0) {
this->channelName = channel;
this->header.updateChannelText();
2017-01-17 00:15:44 +01:00
return;
}
2017-01-18 04:33:30 +01:00
this->channelName = channel;
this->header.updateChannelText();
2017-01-17 00:15:44 +01:00
2017-01-18 04:33:30 +01:00
this->view.layoutMessages();
2017-01-17 00:15:44 +01:00
2017-01-18 04:33:30 +01:00
if (!this->channelName.isEmpty()) {
Channels::removeChannel(this->channelName);
2017-01-17 00:15:44 +01:00
}
if (channel.isEmpty()) {
2017-01-18 04:33:30 +01:00
this->channel = NULL;
2017-01-17 00:15:44 +01:00
} else {
2017-01-18 04:33:30 +01:00
this->channel = Channels::addChannel(channel);
2017-01-17 00:15:44 +01:00
}
2017-01-26 04:26:40 +01:00
this->view.layoutMessages();
this->view.repaint();
2017-01-17 00:15:44 +01:00
}
void
ChatWidget::showChangeChannelPopup()
{
TextInputDialog dialog(this);
2017-01-18 04:33:30 +01:00
dialog.setText(this->channelName);
2017-01-17 00:15:44 +01:00
if (dialog.exec() == QDialog::Accepted) {
2017-01-18 04:33:30 +01:00
setChannelName(dialog.getText());
2017-01-17 00:15:44 +01:00
}
}
2017-01-11 18:52:09 +01:00
void
ChatWidget::paintEvent(QPaintEvent *)
2016-12-29 17:31:07 +01:00
{
2017-01-11 18:52:09 +01:00
QPainter painter(this);
2016-12-29 17:31:07 +01:00
2017-01-24 20:15:12 +01:00
painter.fillRect(this->rect(), ColorScheme::getInstance().ChatBackground);
2016-12-29 17:31:07 +01:00
}
2017-01-18 21:30:23 +01:00
}
}