mirror-chatterino2/chatwidget.cpp

78 lines
1.5 KiB
C++
Raw Normal View History

2016-12-29 17:31:07 +01:00
#include "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-17 00:15:44 +01:00
#include "textinputdialog.h"
#include <QFont>
#include <QFontDatabase>
#include <QPainter>
#include <QVBoxLayout>
2016-12-29 17:31:07 +01:00
ChatWidget::ChatWidget(QWidget *parent)
2017-01-11 18:52:09 +01:00
: QWidget(parent)
2017-01-17 00:15:44 +01:00
, m_channel(NULL)
, m_channelName(QString())
, m_vbox(this)
2017-01-17 00:15:44 +01:00
, m_header(this)
, m_view(this)
, m_input()
2016-12-29 17:31:07 +01:00
{
m_vbox.setSpacing(0);
m_vbox.setMargin(1);
2017-01-01 02:30:42 +01:00
m_vbox.addWidget(&m_header);
m_vbox.addWidget(&m_view);
m_vbox.addWidget(&m_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();
if (QString::compare(channel, m_channelName, Qt::CaseInsensitive) == 0) {
m_channelName = channel;
m_header.updateChannelText();
return;
}
m_channelName = channel;
m_header.updateChannelText();
m_view.layoutMessages();
if (!m_channelName.isEmpty()) {
Channels::removeChannel(m_channelName);
}
if (channel.isEmpty()) {
m_channel = NULL;
} else {
m_channel = Channels::addChannel(channel);
}
}
void
ChatWidget::showChangeChannelPopup()
{
TextInputDialog dialog(this);
dialog.setText(m_channelName);
if (dialog.exec() == QDialog::Accepted) {
setChannelName(dialog.text());
}
}
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-06 23:28:48 +01:00
painter.fillRect(rect(), ColorScheme::instance().ChatBackground);
2016-12-29 17:31:07 +01:00
}