fixed /r and tab text alignment

This commit is contained in:
fourtf
2018-05-25 13:53:55 +02:00
parent b68b7ecb10
commit 9aa9b90267
13 changed files with 140 additions and 41 deletions
+36 -27
View File
@@ -2,6 +2,8 @@
#include "application.hpp"
#include "controllers/commands/commandcontroller.hpp"
#include "providers/twitch/twitchchannel.hpp"
#include "providers/twitch/twitchserver.hpp"
#include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp"
@@ -19,15 +21,15 @@ namespace widgets {
SplitInput::SplitInput(Split *_chatWidget)
: BaseWidget(_chatWidget)
, chatWidget(_chatWidget)
, split(_chatWidget)
{
this->initLayout();
auto completer = new QCompleter(&this->chatWidget->getChannel().get()->completionModel);
auto completer = new QCompleter(&this->split->getChannel().get()->completionModel);
this->ui.textEdit->setCompleter(completer);
this->chatWidget->channelChanged.connect([this] {
auto completer = new QCompleter(&this->chatWidget->getChannel()->completionModel);
this->split->channelChanged.connect([this] {
auto completer = new QCompleter(&this->split->getChannel()->completionModel);
this->ui.textEdit->setCompleter(completer);
});
@@ -83,16 +85,16 @@ void SplitInput::initLayout()
});
}
this->emotePopup->resize((int)(300 * this->emotePopup->getScale()),
(int)(500 * this->emotePopup->getScale()));
this->emotePopup->loadChannel(this->chatWidget->getChannel());
this->emotePopup->resize(int(300 * this->emotePopup->getScale()),
int(500 * this->emotePopup->getScale()));
this->emotePopup->loadChannel(this->split->getChannel());
this->emotePopup->show();
});
// clear channelview selection when selecting in the input
QObject::connect(this->ui.textEdit, &QTextEdit::copyAvailable, [this](bool available) {
if (available) {
this->chatWidget->view.clearSelection();
this->split->view.clearSelection();
}
});
@@ -106,13 +108,13 @@ void SplitInput::scaleChangedEvent(float scale)
{
// update the icon size of the emote button
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->setFixedHeight((int)18 * scale);
this->ui.emoteButton->setFixedHeight(int(18 * scale));
// set maximum height
this->setMaximumHeight((int)(150 * this->getScale()));
this->setMaximumHeight(int(150 * this->getScale()));
}
void SplitInput::themeRefreshEvent()
@@ -125,7 +127,7 @@ void SplitInput::themeRefreshEvent()
this->ui.textEdit->setStyleSheet(this->themeManager->splits.input.styleSheet);
this->ui.hbox->setMargin((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale());
this->ui.hbox->setMargin(int((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale()));
}
void SplitInput::installKeyPressedEvent()
@@ -134,7 +136,7 @@ void SplitInput::installKeyPressedEvent()
this->ui.textEdit->keyPressed.connect([this, app](QKeyEvent *event) {
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
auto c = this->chatWidget->getChannel();
auto c = this->split->getChannel();
if (c == nullptr) {
return;
}
@@ -241,8 +243,7 @@ void SplitInput::installKeyPressedEvent()
}
} else if (event->key() == Qt::Key_Tab) {
if (event->modifiers() == Qt::ControlModifier) {
SplitContainer *page =
static_cast<SplitContainer *>(this->chatWidget->parentWidget());
SplitContainer *page = static_cast<SplitContainer *>(this->split->parentWidget());
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
@@ -250,16 +251,15 @@ void SplitInput::installKeyPressedEvent()
}
} else if (event->key() == Qt::Key_Backtab) {
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
SplitContainer *page =
static_cast<SplitContainer *>(this->chatWidget->parentWidget());
SplitContainer *page = static_cast<SplitContainer *>(this->split->parentWidget());
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
notebook->selectPreviousTab();
}
} else if (event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier) {
if (this->chatWidget->view.hasSelection()) {
this->chatWidget->doCopy();
if (this->split->view.hasSelection()) {
this->split->doCopy();
event->accept();
}
}
@@ -293,13 +293,22 @@ void SplitInput::editTextChanged()
// set textLengthLabel value
QString text = this->ui.textEdit->toPlainText();
this->textChanged.invoke(text);
if (text.startsWith("/r ") && this->split->getChannel()->isTwitchChannel()) //
{
QString lastUser = app->twitch.server->lastUserThatWhisperedMe.get();
if (!lastUser.isEmpty()) {
this->ui.textEdit->setPlainText("/w " + lastUser + text.mid(2));
this->ui.textEdit->moveCursor(QTextCursor::EndOfBlock);
}
} else {
this->textChanged.invoke(text);
text = text.trimmed();
static QRegularExpression spaceRegex("\\s\\s+");
text = text.replace(spaceRegex, " ");
text = text.trimmed();
static QRegularExpression spaceRegex("\\s\\s+");
text = text.replace(spaceRegex, " ");
text = app->commands->execCommand(text, this->chatWidget->getChannel(), true);
text = app->commands->execCommand(text, this->split->getChannel(), true);
}
QString labelText;
@@ -317,7 +326,7 @@ void SplitInput::paintEvent(QPaintEvent *)
QPainter painter(this);
if (this->themeManager->isLightTheme()) {
int s = (int)(3 * this->getScale());
int s = int(3 * this->getScale());
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s));
painter.fillRect(rect, this->themeManager->splits.input.background);
@@ -325,7 +334,7 @@ void SplitInput::paintEvent(QPaintEvent *)
painter.setPen(QColor("#ccc"));
painter.drawRect(rect);
} else {
int s = (int)(1 * this->getScale());
int s = int(1 * this->getScale());
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s));
painter.fillRect(rect, this->themeManager->splits.input.background);
@@ -346,7 +355,7 @@ void SplitInput::resizeEvent(QResizeEvent *)
void SplitInput::mousePressEvent(QMouseEvent *)
{
this->chatWidget->giveFocus(Qt::MouseFocusReason);
this->split->giveFocus(Qt::MouseFocusReason);
}
} // namespace widgets