mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixes #185
This commit is contained in:
parent
62cf45a7bb
commit
6000b7626e
8 changed files with 153 additions and 101 deletions
|
@ -35,7 +35,7 @@ public:
|
||||||
explicit Channel(const QString &_name, Type type);
|
explicit Channel(const QString &_name, Type type);
|
||||||
virtual ~Channel();
|
virtual ~Channel();
|
||||||
|
|
||||||
pajlada::Signals::Signal<const QString &, const QString &> sendMessageSignal;
|
pajlada::Signals::Signal<const QString &, const QString &, bool &> sendMessageSignal;
|
||||||
|
|
||||||
pajlada::Signals::Signal<messages::MessagePtr &> messageRemovedFromStart;
|
pajlada::Signals::Signal<messages::MessagePtr &> messageRemovedFromStart;
|
||||||
pajlada::Signals::Signal<messages::MessagePtr &> messageAppended;
|
pajlada::Signals::Signal<messages::MessagePtr &> messageAppended;
|
||||||
|
|
|
@ -162,14 +162,16 @@ void TwitchChannel::sendMessage(const QString &message)
|
||||||
if (app->settings->allowDuplicateMessages) {
|
if (app->settings->allowDuplicateMessages) {
|
||||||
if (parsedMessage == this->lastSentMessage) {
|
if (parsedMessage == this->lastSentMessage) {
|
||||||
parsedMessage.append(this->messageSuffix);
|
parsedMessage.append(this->messageSuffix);
|
||||||
|
|
||||||
this->lastSentMessage = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->lastSentMessage = parsedMessage;
|
bool messageSent = false;
|
||||||
|
this->sendMessageSignal.invoke(this->name, parsedMessage, messageSent);
|
||||||
|
|
||||||
this->sendMessageSignal.invoke(this->name, parsedMessage);
|
if (messageSent) {
|
||||||
|
qDebug() << "sent";
|
||||||
|
this->lastSentMessage = parsedMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TwitchChannel::isMod() const
|
bool TwitchChannel::isMod() const
|
||||||
|
|
|
@ -71,8 +71,52 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
|
||||||
{
|
{
|
||||||
TwitchChannel *channel = new TwitchChannel(channelName, this->getReadConnection());
|
TwitchChannel *channel = new TwitchChannel(channelName, this->getReadConnection());
|
||||||
|
|
||||||
channel->sendMessageSignal.connect(
|
channel->sendMessageSignal.connect([this, channel](auto chan, auto msg, bool &sent) {
|
||||||
[this](auto chan, auto msg) { this->sendMessage(chan, msg); });
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(this->lastMessageMutex);
|
||||||
|
|
||||||
|
std::queue<QTime> &lastMessage =
|
||||||
|
channel->hasModRights() ? this->lastMessageMod : this->lastMessagePleb;
|
||||||
|
size_t maxMessageCount = channel->hasModRights() ? 99 : 19;
|
||||||
|
|
||||||
|
QTime now = QTime::currentTime();
|
||||||
|
|
||||||
|
if (lastMessage.size() > 0 &&
|
||||||
|
lastMessage.back().addMSecs(channel->hasModRights() ? 100 : 1100) > now) {
|
||||||
|
if (lastErrorTimeSpeed.addSecs(30) < now) {
|
||||||
|
auto errorMessage =
|
||||||
|
messages::Message::createSystemMessage("sending messages too fast");
|
||||||
|
|
||||||
|
channel->addMessage(errorMessage);
|
||||||
|
|
||||||
|
lastErrorTimeSpeed = now;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (lastMessage.size() > 0 && lastMessage.front().addSecs(32) < now) {
|
||||||
|
lastMessage.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastMessage.size() >= maxMessageCount) {
|
||||||
|
if (lastErrorTimeAmount.addSecs(30) < now) {
|
||||||
|
auto errorMessage =
|
||||||
|
messages::Message::createSystemMessage("sending too many messages");
|
||||||
|
|
||||||
|
channel->addMessage(errorMessage);
|
||||||
|
|
||||||
|
lastErrorTimeAmount = now;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastMessage.push(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->sendMessage(chan, msg);
|
||||||
|
sent = true;
|
||||||
|
});
|
||||||
|
|
||||||
return std::shared_ptr<Channel>(channel);
|
return std::shared_ptr<Channel>(channel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "util/mutexvalue.hpp"
|
#include "util/mutexvalue.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace providers {
|
namespace providers {
|
||||||
|
@ -46,8 +47,11 @@ protected:
|
||||||
QString cleanChannelName(const QString &dirtyChannelName) override;
|
QString cleanChannelName(const QString &dirtyChannelName) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// mutable std::mutex lastWhisperedPersonMutex;
|
std::mutex lastMessageMutex;
|
||||||
// QString lastWhisperedPerson;
|
std::queue<QTime> lastMessagePleb;
|
||||||
|
std::queue<QTime> lastMessageMod;
|
||||||
|
QTime lastErrorTimeSpeed;
|
||||||
|
QTime lastErrorTimeAmount;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace twitch
|
} // namespace twitch
|
||||||
|
|
|
@ -30,9 +30,9 @@ struct Deserialize<QString> {
|
||||||
|
|
||||||
return QString::fromUtf8(str, strLen);
|
return QString::fromUtf8(str, strLen);
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
int x = 5;
|
// int x = 5;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
int y = 5;
|
// int y = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
|
|
|
@ -21,16 +21,16 @@ namespace widgets {
|
||||||
|
|
||||||
SplitInput::SplitInput(Split *_chatWidget)
|
SplitInput::SplitInput(Split *_chatWidget)
|
||||||
: BaseWidget(_chatWidget)
|
: BaseWidget(_chatWidget)
|
||||||
, split(_chatWidget)
|
, split_(_chatWidget)
|
||||||
{
|
{
|
||||||
this->initLayout();
|
this->initLayout();
|
||||||
|
|
||||||
auto completer = new QCompleter(&this->split->getChannel().get()->completionModel);
|
auto completer = new QCompleter(&this->split_->getChannel().get()->completionModel);
|
||||||
this->ui.textEdit->setCompleter(completer);
|
this->ui_.textEdit->setCompleter(completer);
|
||||||
|
|
||||||
this->split->channelChanged.connect([this] {
|
this->split_->channelChanged.connect([this] {
|
||||||
auto completer = new QCompleter(&this->split->getChannel()->completionModel);
|
auto completer = new QCompleter(&this->split_->getChannel()->completionModel);
|
||||||
this->ui.textEdit->setCompleter(completer);
|
this->ui_.textEdit->setCompleter(completer);
|
||||||
});
|
});
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
|
@ -43,10 +43,11 @@ void SplitInput::initLayout()
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
util::LayoutCreator<SplitInput> layoutCreator(this);
|
util::LayoutCreator<SplitInput> layoutCreator(this);
|
||||||
|
|
||||||
auto layout = layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(&this->ui.hbox);
|
auto layout =
|
||||||
|
layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(&this->ui_.hbox);
|
||||||
|
|
||||||
// input
|
// input
|
||||||
auto textEdit = layout.emplace<ResizingTextEdit>().assign(&this->ui.textEdit);
|
auto textEdit = layout.emplace<ResizingTextEdit>().assign(&this->ui_.textEdit);
|
||||||
connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this,
|
connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this,
|
||||||
&SplitInput::editTextChanged);
|
&SplitInput::editTextChanged);
|
||||||
|
|
||||||
|
@ -54,54 +55,54 @@ void SplitInput::initLayout()
|
||||||
auto box = layout.emplace<QVBoxLayout>().withoutMargin();
|
auto box = layout.emplace<QVBoxLayout>().withoutMargin();
|
||||||
box->setSpacing(0);
|
box->setSpacing(0);
|
||||||
{
|
{
|
||||||
auto textEditLength = box.emplace<QLabel>().assign(&this->ui.textEditLength);
|
auto textEditLength = box.emplace<QLabel>().assign(&this->ui_.textEditLength);
|
||||||
textEditLength->setAlignment(Qt::AlignRight);
|
textEditLength->setAlignment(Qt::AlignRight);
|
||||||
|
|
||||||
box->addStretch(1);
|
box->addStretch(1);
|
||||||
box.emplace<RippleEffectLabel>().assign(&this->ui.emoteButton);
|
box.emplace<RippleEffectLabel>().assign(&this->ui_.emoteButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ui.emoteButton->getLabel().setTextFormat(Qt::RichText);
|
this->ui_.emoteButton->getLabel().setTextFormat(Qt::RichText);
|
||||||
|
|
||||||
// ---- misc
|
// ---- misc
|
||||||
|
|
||||||
// set edit font
|
// set edit font
|
||||||
this->ui.textEdit->setFont(
|
this->ui_.textEdit->setFont(
|
||||||
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
|
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
|
||||||
|
|
||||||
this->managedConnections.emplace_back(app->fonts->fontChanged.connect([=]() {
|
this->managedConnections_.emplace_back(app->fonts->fontChanged.connect([=]() {
|
||||||
this->ui.textEdit->setFont(
|
this->ui_.textEdit->setFont(
|
||||||
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
|
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// open emote popup
|
// open emote popup
|
||||||
QObject::connect(this->ui.emoteButton, &RippleEffectLabel::clicked, [this] {
|
QObject::connect(this->ui_.emoteButton, &RippleEffectLabel::clicked, [this] {
|
||||||
if (!this->emotePopup) {
|
if (!this->emotePopup_) {
|
||||||
this->emotePopup = std::make_unique<EmotePopup>();
|
this->emotePopup_ = std::make_unique<EmotePopup>();
|
||||||
this->emotePopup->linkClicked.connect([this](const messages::Link &link) {
|
this->emotePopup_->linkClicked.connect([this](const messages::Link &link) {
|
||||||
if (link.type == messages::Link::InsertText) {
|
if (link.type == messages::Link::InsertText) {
|
||||||
this->insertText(link.value + " ");
|
this->insertText(link.value + " ");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this->emotePopup->resize(int(300 * this->emotePopup->getScale()),
|
this->emotePopup_->resize(int(300 * this->emotePopup_->getScale()),
|
||||||
int(500 * this->emotePopup->getScale()));
|
int(500 * this->emotePopup_->getScale()));
|
||||||
this->emotePopup->loadChannel(this->split->getChannel());
|
this->emotePopup_->loadChannel(this->split_->getChannel());
|
||||||
this->emotePopup->show();
|
this->emotePopup_->show();
|
||||||
});
|
});
|
||||||
|
|
||||||
// clear channelview selection when selecting in the input
|
// clear channelview selection when selecting in the input
|
||||||
QObject::connect(this->ui.textEdit, &QTextEdit::copyAvailable, [this](bool available) {
|
QObject::connect(this->ui_.textEdit, &QTextEdit::copyAvailable, [this](bool available) {
|
||||||
if (available) {
|
if (available) {
|
||||||
this->split->view.clearSelection();
|
this->split_->view.clearSelection();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// textEditLength visibility
|
// textEditLength visibility
|
||||||
app->settings->showMessageLength.connect(
|
app->settings->showMessageLength.connect(
|
||||||
[this](const bool &value, auto) { this->ui.textEditLength->setHidden(!value); },
|
[this](const bool &value, auto) { this->ui_.textEditLength->setHidden(!value); },
|
||||||
this->managedConnections);
|
this->managedConnections_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitInput::scaleChangedEvent(float scale)
|
void SplitInput::scaleChangedEvent(float scale)
|
||||||
|
@ -110,8 +111,8 @@ void SplitInput::scaleChangedEvent(float scale)
|
||||||
QString text = "<img src=':/images/emote.svg' width='xD' height='xD' />";
|
QString text = "<img src=':/images/emote.svg' width='xD' height='xD' />";
|
||||||
text.replace("xD", QString::number(int(12 * scale)));
|
text.replace("xD", QString::number(int(12 * scale)));
|
||||||
|
|
||||||
this->ui.emoteButton->getLabel().setText(text);
|
this->ui_.emoteButton->getLabel().setText(text);
|
||||||
this->ui.emoteButton->setFixedHeight(int(18 * scale));
|
this->ui_.emoteButton->setFixedHeight(int(18 * scale));
|
||||||
|
|
||||||
// set maximum height
|
// set maximum height
|
||||||
this->setMaximumHeight(int(150 * this->getScale()));
|
this->setMaximumHeight(int(150 * this->getScale()));
|
||||||
|
@ -123,65 +124,66 @@ void SplitInput::themeRefreshEvent()
|
||||||
|
|
||||||
palette.setColor(QPalette::Foreground, this->themeManager->splits.input.text);
|
palette.setColor(QPalette::Foreground, this->themeManager->splits.input.text);
|
||||||
|
|
||||||
this->ui.textEditLength->setPalette(palette);
|
this->ui_.textEditLength->setPalette(palette);
|
||||||
|
|
||||||
this->ui.textEdit->setStyleSheet(this->themeManager->splits.input.styleSheet);
|
this->ui_.textEdit->setStyleSheet(this->themeManager->splits.input.styleSheet);
|
||||||
|
|
||||||
this->ui.hbox->setMargin(int((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale()));
|
this->ui_.hbox->setMargin(int((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitInput::installKeyPressedEvent()
|
void SplitInput::installKeyPressedEvent()
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
this->ui.textEdit->keyPressed.connect([this, app](QKeyEvent *event) {
|
this->ui_.textEdit->keyPressed.connect([this, app](QKeyEvent *event) {
|
||||||
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
||||||
auto c = this->split->getChannel();
|
auto c = this->split_->getChannel();
|
||||||
if (c == nullptr) {
|
if (c == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString message = ui.textEdit->toPlainText();
|
|
||||||
|
QString message = ui_.textEdit->toPlainText();
|
||||||
|
|
||||||
QString sendMessage = app->commands->execCommand(message, c, false);
|
QString sendMessage = app->commands->execCommand(message, c, false);
|
||||||
sendMessage = sendMessage.replace('\n', ' ');
|
sendMessage = sendMessage.replace('\n', ' ');
|
||||||
|
|
||||||
c->sendMessage(sendMessage);
|
c->sendMessage(sendMessage);
|
||||||
// don't add duplicate messages to message history
|
// don't add duplicate messages to message history
|
||||||
if (this->prevMsg.isEmpty() || !this->prevMsg.endsWith(message))
|
if (this->prevMsg_.isEmpty() || !this->prevMsg_.endsWith(message))
|
||||||
this->prevMsg.append(message);
|
this->prevMsg_.append(message);
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
if (!(event->modifiers() == Qt::ControlModifier)) {
|
if (!(event->modifiers() == Qt::ControlModifier)) {
|
||||||
this->currMsg = QString();
|
this->currMsg_ = QString();
|
||||||
this->ui.textEdit->setText(QString());
|
this->ui_.textEdit->setText(QString());
|
||||||
this->prevIndex = 0;
|
this->prevIndex_ = 0;
|
||||||
} else if (this->ui.textEdit->toPlainText() ==
|
} else if (this->ui_.textEdit->toPlainText() ==
|
||||||
this->prevMsg.at(this->prevMsg.size() - 1)) {
|
this->prevMsg_.at(this->prevMsg_.size() - 1)) {
|
||||||
this->prevMsg.removeLast();
|
this->prevMsg_.removeLast();
|
||||||
}
|
}
|
||||||
this->prevIndex = this->prevMsg.size();
|
this->prevIndex_ = this->prevMsg_.size();
|
||||||
} else if (event->key() == Qt::Key_Up) {
|
} else if (event->key() == Qt::Key_Up) {
|
||||||
if ((event->modifiers() & Qt::ShiftModifier) != 0) {
|
if ((event->modifiers() & Qt::ShiftModifier) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event->modifiers() == Qt::AltModifier) {
|
if (event->modifiers() == Qt::AltModifier) {
|
||||||
SplitContainer *page = this->split->getContainer();
|
SplitContainer *page = this->split_->getContainer();
|
||||||
|
|
||||||
if (page != nullptr) {
|
if (page != nullptr) {
|
||||||
page->selectNextSplit(SplitContainer::Above);
|
page->selectNextSplit(SplitContainer::Above);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this->prevMsg.size() && this->prevIndex) {
|
if (this->prevMsg_.size() && this->prevIndex_) {
|
||||||
if (this->prevIndex == (this->prevMsg.size())) {
|
if (this->prevIndex_ == (this->prevMsg_.size())) {
|
||||||
this->currMsg = ui.textEdit->toPlainText();
|
this->currMsg_ = ui_.textEdit->toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->prevIndex--;
|
this->prevIndex_--;
|
||||||
this->ui.textEdit->setText(this->prevMsg.at(this->prevIndex));
|
this->ui_.textEdit->setText(this->prevMsg_.at(this->prevIndex_));
|
||||||
|
|
||||||
QTextCursor cursor = this->ui.textEdit->textCursor();
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
this->ui.textEdit->setTextCursor(cursor);
|
this->ui_.textEdit->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event->key() == Qt::Key_Down) {
|
} else if (event->key() == Qt::Key_Down) {
|
||||||
|
@ -189,28 +191,28 @@ void SplitInput::installKeyPressedEvent()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event->modifiers() == Qt::AltModifier) {
|
if (event->modifiers() == Qt::AltModifier) {
|
||||||
SplitContainer *page = this->split->getContainer();
|
SplitContainer *page = this->split_->getContainer();
|
||||||
|
|
||||||
if (page != nullptr) {
|
if (page != nullptr) {
|
||||||
page->selectNextSplit(SplitContainer::Below);
|
page->selectNextSplit(SplitContainer::Below);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this->prevIndex != (this->prevMsg.size() - 1) &&
|
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
|
||||||
this->prevIndex != this->prevMsg.size()) {
|
this->prevIndex_ != this->prevMsg_.size()) {
|
||||||
this->prevIndex++;
|
this->prevIndex_++;
|
||||||
this->ui.textEdit->setText(this->prevMsg.at(this->prevIndex));
|
this->ui_.textEdit->setText(this->prevMsg_.at(this->prevIndex_));
|
||||||
} else {
|
} else {
|
||||||
this->prevIndex = this->prevMsg.size();
|
this->prevIndex_ = this->prevMsg_.size();
|
||||||
this->ui.textEdit->setText(this->currMsg);
|
this->ui_.textEdit->setText(this->currMsg_);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCursor cursor = this->ui.textEdit->textCursor();
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
this->ui.textEdit->setTextCursor(cursor);
|
this->ui_.textEdit->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
} else if (event->key() == Qt::Key_Left) {
|
} else if (event->key() == Qt::Key_Left) {
|
||||||
if (event->modifiers() == Qt::AltModifier) {
|
if (event->modifiers() == Qt::AltModifier) {
|
||||||
SplitContainer *page = this->split->getContainer();
|
SplitContainer *page = this->split_->getContainer();
|
||||||
|
|
||||||
if (page != nullptr) {
|
if (page != nullptr) {
|
||||||
page->selectNextSplit(SplitContainer::Left);
|
page->selectNextSplit(SplitContainer::Left);
|
||||||
|
@ -218,7 +220,7 @@ void SplitInput::installKeyPressedEvent()
|
||||||
}
|
}
|
||||||
} else if (event->key() == Qt::Key_Right) {
|
} else if (event->key() == Qt::Key_Right) {
|
||||||
if (event->modifiers() == Qt::AltModifier) {
|
if (event->modifiers() == Qt::AltModifier) {
|
||||||
SplitContainer *page = this->split->getContainer();
|
SplitContainer *page = this->split_->getContainer();
|
||||||
|
|
||||||
if (page != nullptr) {
|
if (page != nullptr) {
|
||||||
page->selectNextSplit(SplitContainer::Right);
|
page->selectNextSplit(SplitContainer::Right);
|
||||||
|
@ -226,7 +228,7 @@ void SplitInput::installKeyPressedEvent()
|
||||||
}
|
}
|
||||||
} else if (event->key() == Qt::Key_Tab) {
|
} else if (event->key() == Qt::Key_Tab) {
|
||||||
if (event->modifiers() == Qt::ControlModifier) {
|
if (event->modifiers() == Qt::ControlModifier) {
|
||||||
SplitContainer *page = static_cast<SplitContainer *>(this->split->parentWidget());
|
SplitContainer *page = static_cast<SplitContainer *>(this->split_->parentWidget());
|
||||||
|
|
||||||
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
|
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
|
||||||
|
|
||||||
|
@ -234,15 +236,15 @@ void SplitInput::installKeyPressedEvent()
|
||||||
}
|
}
|
||||||
} else if (event->key() == Qt::Key_Backtab) {
|
} else if (event->key() == Qt::Key_Backtab) {
|
||||||
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
|
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
|
||||||
SplitContainer *page = static_cast<SplitContainer *>(this->split->parentWidget());
|
SplitContainer *page = static_cast<SplitContainer *>(this->split_->parentWidget());
|
||||||
|
|
||||||
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
|
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
|
||||||
|
|
||||||
notebook->selectPreviousTab();
|
notebook->selectPreviousTab();
|
||||||
}
|
}
|
||||||
} else if (event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier) {
|
} else if (event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier) {
|
||||||
if (this->split->view.hasSelection()) {
|
if (this->split_->view.hasSelection()) {
|
||||||
this->split->doCopy();
|
this->split_->doCopy();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,22 +253,22 @@ void SplitInput::installKeyPressedEvent()
|
||||||
|
|
||||||
void SplitInput::clearSelection()
|
void SplitInput::clearSelection()
|
||||||
{
|
{
|
||||||
QTextCursor c = this->ui.textEdit->textCursor();
|
QTextCursor c = this->ui_.textEdit->textCursor();
|
||||||
|
|
||||||
c.setPosition(c.position());
|
c.setPosition(c.position());
|
||||||
c.setPosition(c.position(), QTextCursor::KeepAnchor);
|
c.setPosition(c.position(), QTextCursor::KeepAnchor);
|
||||||
|
|
||||||
this->ui.textEdit->setTextCursor(c);
|
this->ui_.textEdit->setTextCursor(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SplitInput::getInputText() const
|
QString SplitInput::getInputText() const
|
||||||
{
|
{
|
||||||
return this->ui.textEdit->toPlainText();
|
return this->ui_.textEdit->toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitInput::insertText(const QString &text)
|
void SplitInput::insertText(const QString &text)
|
||||||
{
|
{
|
||||||
this->ui.textEdit->insertPlainText(text);
|
this->ui_.textEdit->insertPlainText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitInput::editTextChanged()
|
void SplitInput::editTextChanged()
|
||||||
|
@ -274,15 +276,15 @@ void SplitInput::editTextChanged()
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
// set textLengthLabel value
|
// set textLengthLabel value
|
||||||
QString text = this->ui.textEdit->toPlainText();
|
QString text = this->ui_.textEdit->toPlainText();
|
||||||
|
|
||||||
if (text.startsWith("/r ", Qt::CaseInsensitive) &&
|
if (text.startsWith("/r ", Qt::CaseInsensitive) &&
|
||||||
this->split->getChannel()->isTwitchChannel()) //
|
this->split_->getChannel()->isTwitchChannel()) //
|
||||||
{
|
{
|
||||||
QString lastUser = app->twitch.server->lastUserThatWhisperedMe.get();
|
QString lastUser = app->twitch.server->lastUserThatWhisperedMe.get();
|
||||||
if (!lastUser.isEmpty()) {
|
if (!lastUser.isEmpty()) {
|
||||||
this->ui.textEdit->setPlainText("/w " + lastUser + text.mid(2));
|
this->ui_.textEdit->setPlainText("/w " + lastUser + text.mid(2));
|
||||||
this->ui.textEdit->moveCursor(QTextCursor::EndOfBlock);
|
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->textChanged.invoke(text);
|
this->textChanged.invoke(text);
|
||||||
|
@ -291,7 +293,7 @@ void SplitInput::editTextChanged()
|
||||||
static QRegularExpression spaceRegex("\\s\\s+");
|
static QRegularExpression spaceRegex("\\s\\s+");
|
||||||
text = text.replace(spaceRegex, " ");
|
text = text.replace(spaceRegex, " ");
|
||||||
|
|
||||||
text = app->commands->execCommand(text, this->split->getChannel(), true);
|
text = app->commands->execCommand(text, this->split_->getChannel(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString labelText;
|
QString labelText;
|
||||||
|
@ -302,7 +304,7 @@ void SplitInput::editTextChanged()
|
||||||
labelText = QString::number(text.length());
|
labelText = QString::number(text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ui.textEditLength->setText(labelText);
|
this->ui_.textEditLength->setText(labelText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitInput::paintEvent(QPaintEvent *)
|
void SplitInput::paintEvent(QPaintEvent *)
|
||||||
|
@ -335,15 +337,15 @@ void SplitInput::paintEvent(QPaintEvent *)
|
||||||
void SplitInput::resizeEvent(QResizeEvent *)
|
void SplitInput::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
if (this->height() == this->maximumHeight()) {
|
if (this->height() == this->maximumHeight()) {
|
||||||
this->ui.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
} else {
|
} else {
|
||||||
this->ui.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitInput::mousePressEvent(QMouseEvent *)
|
void SplitInput::mousePressEvent(QMouseEvent *)
|
||||||
{
|
{
|
||||||
this->split->giveFocus(Qt::MouseFocusReason);
|
this->split_->giveFocus(Qt::MouseFocusReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
|
|
|
@ -40,8 +40,8 @@ protected:
|
||||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Split *const split;
|
Split *const split_;
|
||||||
std::unique_ptr<EmotePopup> emotePopup;
|
std::unique_ptr<EmotePopup> emotePopup_;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
ResizingTextEdit *textEdit;
|
ResizingTextEdit *textEdit;
|
||||||
|
@ -49,12 +49,12 @@ private:
|
||||||
RippleEffectLabel *emoteButton;
|
RippleEffectLabel *emoteButton;
|
||||||
|
|
||||||
QHBoxLayout *hbox;
|
QHBoxLayout *hbox;
|
||||||
} ui;
|
} ui_;
|
||||||
|
|
||||||
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
|
||||||
QStringList prevMsg;
|
QStringList prevMsg_;
|
||||||
QString currMsg;
|
QString currMsg_;
|
||||||
int prevIndex = 0;
|
int prevIndex_ = 0;
|
||||||
|
|
||||||
void initLayout();
|
void initLayout();
|
||||||
void installKeyPressedEvent();
|
void installKeyPressedEvent();
|
||||||
|
|
|
@ -94,7 +94,7 @@ Split::Split(QWidget *parent)
|
||||||
// CreateShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
|
// CreateShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
|
||||||
// CreateShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
|
// CreateShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
|
||||||
|
|
||||||
this->input.ui.textEdit->installEventFilter(parent);
|
this->input.ui_.textEdit->installEventFilter(parent);
|
||||||
|
|
||||||
this->view.mouseDown.connect([this](QMouseEvent *) {
|
this->view.mouseDown.connect([this](QMouseEvent *) {
|
||||||
//
|
//
|
||||||
|
@ -142,7 +142,7 @@ Split::Split(QWidget *parent)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this->input.ui.textEdit->focused.connect([this] { this->focused.invoke(); });
|
this->input.ui_.textEdit->focused.connect([this] { this->focused.invoke(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
Split::~Split()
|
Split::~Split()
|
||||||
|
@ -266,12 +266,12 @@ void Split::updateLastReadMessage()
|
||||||
|
|
||||||
void Split::giveFocus(Qt::FocusReason reason)
|
void Split::giveFocus(Qt::FocusReason reason)
|
||||||
{
|
{
|
||||||
this->input.ui.textEdit->setFocus(reason);
|
this->input.ui_.textEdit->setFocus(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Split::hasFocus() const
|
bool Split::hasFocus() const
|
||||||
{
|
{
|
||||||
return this->input.ui.textEdit->hasFocus();
|
return this->input.ui_.textEdit->hasFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Split::paintEvent(QPaintEvent *)
|
void Split::paintEvent(QPaintEvent *)
|
||||||
|
|
Loading…
Reference in a new issue