mirror-chatterino2/src/widgets/chatwidgetinput.cpp

129 lines
3.5 KiB
C++
Raw Normal View History

2017-06-11 09:31:45 +02:00
#include "widgets/chatwidgetinput.hpp"
#include "chatwidget.hpp"
#include "colorscheme.hpp"
#include "completionmanager.hpp"
2017-06-11 09:31:45 +02:00
#include "ircmanager.hpp"
#include "settingsmanager.hpp"
2017-01-01 02:30:42 +01:00
#include <QCompleter>
2017-01-18 04:52:47 +01:00
#include <QPainter>
2017-01-29 13:23:22 +01:00
#include <boost/signals2.hpp>
2017-01-18 04:52:47 +01:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace widgets {
2017-01-18 21:30:23 +01:00
ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
: BaseWidget(_chatWidget)
, chatWidget(_chatWidget)
, emotesLabel(this)
2017-01-01 02:30:42 +01:00
{
this->setMaximumHeight(150);
this->setLayout(&this->hbox);
this->hbox.setMargin(4);
this->hbox.addLayout(&this->editContainer);
this->hbox.addLayout(&this->vbox);
this->editContainer.addWidget(&this->textInput);
this->editContainer.setMargin(4);
this->vbox.addWidget(&this->textLengthLabel);
this->vbox.addStretch(1);
this->vbox.addWidget(&this->emotesLabel);
this->textLengthLabel.setText("100");
this->textLengthLabel.setAlignment(Qt::AlignRight);
this->emotesLabel.getLabel().setTextFormat(Qt::RichText);
this->emotesLabel.getLabel().setText(
"<img src=':/images/Emoji_Color_1F60A_19.png' width='12' height='12' "
"/>");
connect(&textInput, &ResizingTextEdit::textChanged, this, &ChatWidgetInput::editTextChanged);
2017-01-22 12:46:35 +01:00
this->refreshTheme();
2017-07-09 00:09:02 +02:00
this->setMessageLengthVisible(SettingsManager::getInstance().showMessageLength.get());
2017-01-22 12:46:35 +01:00
auto completer = new QCompleter(
this->chatWidget->completionManager.createModel(this->chatWidget->channelName));
2017-07-09 00:09:02 +02:00
this->textInput.setCompleter(completer);
this->textInput.keyPressed.connect([this](QKeyEvent *event) {
2017-01-29 13:23:22 +01:00
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
auto c = this->chatWidget->getChannel();
2017-05-28 00:47:16 +02:00
if (c == nullptr) {
return;
2017-01-29 13:23:22 +01:00
}
2017-05-28 00:47:16 +02:00
c->sendMessage(textInput.toPlainText());
2017-05-28 00:47:16 +02:00
event->accept();
textInput.setText(QString());
2017-01-29 13:23:22 +01:00
}
});
/* XXX(pajlada): FIX THIS
2017-01-23 16:38:06 +01:00
QObject::connect(&Settings::getInstance().showMessageLength,
&BoolSetting::valueChanged, this,
2017-07-09 00:09:02 +02:00
&ChatWidgetInput::setMessageLengthVisible);
*/
2017-01-22 12:46:35 +01:00
}
ChatWidgetInput::~ChatWidgetInput()
{
/* XXX(pajlada): FIX THIS
2017-01-22 12:46:35 +01:00
QObject::disconnect(
2017-01-23 16:38:06 +01:00
&Settings::getInstance().getShowMessageLength(),
&BoolSetting::valueChanged, this,
2017-07-09 00:09:02 +02:00
&ChatWidgetInput::setMessageLengthVisible);
*/
}
2017-01-21 05:14:27 +01:00
2017-04-12 17:46:44 +02:00
void ChatWidgetInput::refreshTheme()
{
QPalette palette;
palette.setColor(QPalette::Foreground, this->colorScheme.Text);
this->textLengthLabel.setPalette(palette);
2017-01-21 05:14:27 +01:00
this->textInput.setStyleSheet(this->colorScheme.InputStyleSheet);
2017-01-01 02:30:42 +01:00
}
2017-04-12 17:46:44 +02:00
void ChatWidgetInput::editTextChanged()
2017-01-29 13:23:22 +01:00
{
}
// void
// ChatWidgetInput::editKeyPressed(QKeyEvent *event)
//{
// if (event->key() == Qt::Key_Enter) {
// event->accept();
// IrcManager::send("PRIVMSG #" + edit.toPlainText();
// edit.setText(QString());
// }
//}
2017-04-12 17:46:44 +02:00
void ChatWidgetInput::paintEvent(QPaintEvent *)
2017-01-01 02:30:42 +01:00
{
QPainter painter(this);
painter.fillRect(this->rect(), this->colorScheme.ChatInputBackground);
painter.setPen(this->colorScheme.ChatInputBorder);
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
2017-01-01 02:30:42 +01:00
}
2017-04-12 17:46:44 +02:00
void ChatWidgetInput::resizeEvent(QResizeEvent *)
{
if (this->height() == this->maximumHeight()) {
this->textInput.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
} else {
this->textInput.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
}
} // namespace widgets
} // namespace chatterino