put all split widgets inside the same directory

This commit is contained in:
fourtf
2018-06-26 14:39:22 +02:00
parent beaa2e849a
commit 22f528cd21
26 changed files with 41 additions and 60 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
#include "singletons/WindowManager.hpp"
#include "util/Benchmark.hpp"
#include "util/DistanceBetweenPoints.hpp"
#include "widgets/Split.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/TooltipWidget.hpp"
#include "widgets/UserInfoPopup.hpp"
+1 -1
View File
@@ -2,7 +2,7 @@
#include "singletons/ThemeManager.hpp"
#include "widgets/helper/RippleEffectButton.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/SplitContainer.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <QMouseEvent>
#include <QPainter>
+1 -1
View File
@@ -1,6 +1,6 @@
#include "widgets/helper/RippleEffectLabel.hpp"
#include "singletons/ThemeManager.hpp"
#include "widgets/helper/SplitHeader.hpp"
#include "widgets/splits/SplitHeader.hpp"
#include <QBrush>
#include <QPainter>
-7
View File
@@ -1,7 +0,0 @@
#include "SplitColumn.hpp"
namespace chatterino {
namespace helper {
} // namespace helper
} // namespace chatterino
-25
View File
@@ -1,25 +0,0 @@
#pragma once
#include "widgets/Split.hpp"
#include <vector>
namespace chatterino {
namespace helper {
class SplitColumn
{
public:
SplitColumn() = default;
void insert(widgets::Split *split, int index = -1);
void remove(int index);
double getFlex();
void setFlex(double flex);
private:
std::vector<widgets::Split> items;
};
} // namespace helper
} // namespace chatterino
-505
View File
@@ -1,505 +0,0 @@
#include "widgets/helper/SplitHeader.hpp"
#include "Application.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/ResourceManager.hpp"
#include "singletons/ThemeManager.hpp"
#include "util/LayoutCreator.hpp"
#include "util/UrlFetch.hpp"
#include "widgets/Label.hpp"
#include "widgets/Split.hpp"
#include "widgets/SplitContainer.hpp"
#include "widgets/TooltipWidget.hpp"
#include <QByteArray>
#include <QDrag>
#include <QInputDialog>
#include <QMimeData>
#include <QPainter>
#ifdef USEWEBENGINE
#include "widgets/StreamView.hpp"
#endif
using namespace chatterino::providers::twitch;
namespace chatterino {
namespace widgets {
SplitHeader::SplitHeader(Split *_split)
: BaseWidget(_split)
, split(_split)
{
this->split->focused.connect([this]() { this->themeRefreshEvent(); });
this->split->focusLost.connect([this]() { this->themeRefreshEvent(); });
auto app = getApp();
util::LayoutCreator<SplitHeader> layoutCreator(this);
auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin();
{
// dropdown label
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton);
dropdown->setMouseTracking(true);
dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
this->addDropdownItems(dropdown.getElement());
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
QTimer::singleShot(80, [&, this] {
this->dropdownMenu.move(
this->dropdownButton->mapToGlobal(QPoint(0, this->dropdownButton->height())));
this->dropdownMenu.show();
});
});
// channel name label
auto title = layout.emplace<Label>().assign(&this->titleLabel);
title->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
title->setCentered(true);
title->setHasOffset(false);
// mode button
auto mode = layout.emplace<RippleEffectLabel>(this).assign(&this->modeButton);
this->addModeItems(mode.getElement());
QObject::connect(mode.getElement(), &RippleEffectLabel::clicked, this, [this] {
QTimer::singleShot(80, [&, this] {
ChannelPtr _channel = this->split->getChannel();
if (_channel.get()->isMod() || _channel.get()->isBroadcaster()) {
this->modeMenu.move(
this->modeButton->mapToGlobal(QPoint(0, this->modeButton->height())));
this->modeMenu.show();
}
});
});
mode->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
mode->hide();
// QObject::connect(mode.getElement(), &RippleEffectButton::clicked, this, [this]
// {
// //
// });
// moderation mode
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
QObject::connect(moderator.getElement(), &RippleEffectButton::clicked, this, [this] {
this->split->setModerationMode(!this->split->getModerationMode());
});
this->updateModerationModeIcon();
}
// ---- misc
this->layout()->setMargin(0);
this->scaleChangedEvent(this->getScale());
this->updateChannelText();
this->initializeChannelSignals();
this->split->channelChanged.connect([this]() {
this->initializeChannelSignals(); //
});
this->managedConnect(app->accounts->twitch.currentUserChanged,
[this] { this->updateModerationModeIcon(); });
this->setMouseTracking(true);
}
SplitHeader::~SplitHeader()
{
this->onlineStatusChangedConnection.disconnect();
}
void SplitHeader::addDropdownItems(RippleEffectButton *)
{
// clang-format off
this->dropdownMenu.addAction("Add new split", this->split, &Split::doAddSplit, QKeySequence(tr("Ctrl+T")));
this->dropdownMenu.addAction("Close split", this->split, &Split::doCloseSplit, QKeySequence(tr("Ctrl+W")));
// this->dropdownMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
this->dropdownMenu.addAction("Popup", this->split, &Split::doPopup);
this->dropdownMenu.addAction("Open viewer list", this->split, &Split::doOpenViewerList);
this->dropdownMenu.addAction("Search in messages", this->split, &Split::doSearch, QKeySequence(tr("Ctrl+F")));
this->dropdownMenu.addSeparator();
#ifdef USEWEBENGINE
this->dropdownMenu.addAction("Start watching", this, [this]{
ChannelPtr _channel = this->split->getChannel();
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(_channel.get());
if (tc != nullptr) {
StreamView *view = new StreamView(_channel, "https://player.twitch.tv/?channel=" + tc->name);
view->setAttribute(Qt::WA_DeleteOnClose, true);
view->show();
}
});
#endif
this->dropdownMenu.addAction("Change channel", this->split, &Split::doChangeChannel, QKeySequence(tr("Ctrl+R")));
this->dropdownMenu.addAction("Clear chat", this->split, &Split::doClearChat);
this->dropdownMenu.addAction("Open in web browser", this->split, &Split::doOpenChannel);
#ifndef USEWEBENGINE
this->dropdownMenu.addAction("Open web player", this->split, &Split::doOpenPopupPlayer);
#endif
this->dropdownMenu.addAction("Open in Streamlink", this->split, &Split::doOpenStreamlink);
this->dropdownMenu.addSeparator();
this->dropdownMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
this->dropdownMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
// this->dropdownMenu.addSeparator();
// this->dropdownMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
// clang-format on
}
void SplitHeader::addModeItems(RippleEffectLabel *)
{
QAction *setSub = new QAction("Submode", this);
this->setSub = setSub;
setSub->setCheckable(true);
QObject::connect(setSub, &QAction::triggered, this, [setSub, this]() {
QString sendCommand = "/subscribers";
if (!setSub->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
QAction *setEmote = new QAction("Emote only", this);
this->setEmote = setEmote;
setEmote->setCheckable(true);
QObject::connect(setEmote, &QAction::triggered, this, [setEmote, this]() {
QString sendCommand = "/emoteonly";
if (!setEmote->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
QAction *setSlow = new QAction("Slow mode", this);
this->setSlow = setSlow;
setSlow->setCheckable(true);
QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
if (!setSlow->isChecked()) {
this->split->getChannel().get()->sendMessage("/slowoff");
setSlow->setChecked(false);
return;
};
bool ok;
int slowSec =
QInputDialog::getInt(this, "", "Seconds:", 10, 0, 500, 1, &ok, Qt::FramelessWindowHint);
if (ok) {
this->split->getChannel().get()->sendMessage(QString("/slow %1").arg(slowSec));
} else {
setSlow->setChecked(true);
}
});
QAction *setR9k = new QAction("R9K mode", this);
this->setR9k = setR9k;
setR9k->setCheckable(true);
QObject::connect(setR9k, &QAction::triggered, this, [setR9k, this]() {
QString sendCommand = "/r9kbeta";
if (!setR9k->isChecked()) {
sendCommand.append("off");
};
this->split->getChannel().get()->sendMessage(sendCommand);
});
this->modeMenu.addAction(setEmote);
this->modeMenu.addAction(setSub);
this->modeMenu.addAction(setSlow);
this->modeMenu.addAction(setR9k);
}
void SplitHeader::initializeChannelSignals()
{
// Disconnect any previous signal first
this->onlineStatusChangedConnection.disconnect();
auto channel = this->split->getChannel();
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel) {
this->managedConnections.emplace_back(twitchChannel->updateLiveInfo.connect([this]() {
this->updateChannelText(); //
}));
}
}
void SplitHeader::scaleChangedEvent(float scale)
{
int w = 28 * scale;
this->setFixedHeight(w);
this->dropdownButton->setFixedWidth(w);
this->moderationButton->setFixedWidth(w);
// this->titleLabel->setFont(
// singletons::FontManager::getInstance().getFont(FontStyle::Medium, scale));
}
void SplitHeader::updateChannelText()
{
auto indirectChannel = this->split->getIndirectChannel();
auto channel = this->split->getChannel();
QString title = channel->name;
if (indirectChannel.getType() == Channel::TwitchWatching) {
title = "watching: " + (title.isEmpty() ? "none" : title);
}
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel != nullptr) {
const auto streamStatus = twitchChannel->getStreamStatus();
if (streamStatus.live) {
this->isLive = true;
this->tooltip = "<style>.center { text-align: center; }</style>"
"<p class = \"center\">" +
streamStatus.title + "<br><br>" + streamStatus.game + "<br>" +
(streamStatus.rerun ? "Vod-casting" : "Live") + " for " +
streamStatus.uptime + " with " +
QString::number(streamStatus.viewerCount) +
" viewers"
"</p>";
if (streamStatus.rerun) {
title += " (rerun)";
} else if (streamStatus.streamType.isEmpty()) {
title += " (" + streamStatus.streamType + ")";
} else {
title += " (live)";
}
} else {
this->tooltip = QString();
}
}
if (title.isEmpty()) {
title = "<empty>";
}
this->isLive = false;
this->titleLabel->setText(title);
}
void SplitHeader::updateModerationModeIcon()
{
auto app = getApp();
this->moderationButton->setPixmap(this->split->getModerationMode()
? *app->resources->moderationmode_enabled->getPixmap()
: *app->resources->moderationmode_disabled->getPixmap());
bool modButtonVisible = false;
ChannelPtr channel = this->split->getChannel();
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(channel.get());
if (tc != nullptr && tc->hasModRights()) {
modButtonVisible = true;
}
this->moderationButton->setVisible(modButtonVisible);
}
void SplitHeader::updateModes()
{
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(this->split->getChannel().get());
if (tc == nullptr) {
this->modeButton->hide();
return;
}
TwitchChannel::RoomModes roomModes = tc->getRoomModes();
QString text;
this->setSlow->setChecked(false);
this->setEmote->setChecked(false);
this->setSub->setChecked(false);
this->setR9k->setChecked(false);
if (roomModes.r9k) {
text += "r9k, ";
this->setR9k->setChecked(true);
}
if (roomModes.slowMode) {
text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode));
this->setSlow->setChecked(true);
}
if (roomModes.emoteOnly) {
text += "emote, ";
this->setEmote->setChecked(true);
}
if (roomModes.submode) {
text += "sub, ";
this->setSub->setChecked(true);
}
if (text.length() > 2) {
text = text.mid(0, text.size() - 2);
} else {
if (tc->hasModRights()) {
text = "-";
}
}
if (text.isEmpty()) {
this->modeButton->hide();
} else {
static QRegularExpression commaReplacement("^.+?, .+?,( ).+$");
QRegularExpressionMatch match = commaReplacement.match(text);
if (match.hasMatch()) {
text = text.mid(0, match.capturedStart(1)) + '\n' + text.mid(match.capturedEnd(1));
}
this->modeButton->getLabel().setText(text);
this->modeButton->show();
}
}
void SplitHeader::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.fillRect(rect(), this->themeManager->splits.header.background);
painter.setPen(this->themeManager->splits.header.border);
painter.drawRect(0, 0, width() - 1, height() - 1);
}
void SplitHeader::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
this->dragging = true;
this->dragStart = event->pos();
}
this->doubleClicked = false;
}
void SplitHeader::mouseReleaseEvent(QMouseEvent *event)
{
if (this->dragging && event->button() == Qt::LeftButton) {
QPoint pos = event->globalPos();
if (!showingHelpTooltip) {
this->showingHelpTooltip = true;
QTimer::singleShot(400, this, [this, pos] {
if (this->doubleClicked) {
this->doubleClicked = false;
this->showingHelpTooltip = false;
return;
}
TooltipWidget *widget = new TooltipWidget();
widget->setText("Double click or press <Ctrl+R> to change the channel.\nClick and "
"drag to move the split.");
widget->setAttribute(Qt::WA_DeleteOnClose);
widget->move(pos);
widget->show();
widget->raise();
QTimer::singleShot(3000, widget, [this, widget] {
widget->close();
this->showingHelpTooltip = false;
});
});
}
}
this->dragging = false;
}
void SplitHeader::mouseMoveEvent(QMouseEvent *event)
{
if (this->dragging) {
if (std::abs(this->dragStart.x() - event->pos().x()) > int(12 * this->getScale()) ||
std::abs(this->dragStart.y() - event->pos().y()) > int(12 * this->getScale())) {
this->split->drag();
this->dragging = false;
}
}
}
void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
this->split->doChangeChannel();
}
this->doubleClicked = true;
}
void SplitHeader::enterEvent(QEvent *event)
{
if (!this->tooltip.isEmpty()) {
auto tooltipWidget = TooltipWidget::getInstance();
tooltipWidget->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()), false);
tooltipWidget->setText(this->tooltip);
tooltipWidget->show();
tooltipWidget->raise();
}
BaseWidget::enterEvent(event);
}
void SplitHeader::leaveEvent(QEvent *event)
{
TooltipWidget::getInstance()->hide();
BaseWidget::leaveEvent(event);
}
void SplitHeader::rightButtonClicked()
{
}
void SplitHeader::themeRefreshEvent()
{
QPalette palette;
if (this->split->hasFocus()) {
palette.setColor(QPalette::Foreground, this->themeManager->splits.header.focusedText);
} else {
palette.setColor(QPalette::Foreground, this->themeManager->splits.header.text);
}
// this->dropdownButton->setPalette(palette);
this->titleLabel->setPalette(palette);
// this->moderationLabel->setPalette(palette);
}
void SplitHeader::menuMoveSplit()
{
}
void SplitHeader::menuReloadChannelEmotes()
{
auto channel = this->split->getChannel();
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel) {
twitchChannel->reloadChannelEmotes();
}
}
void SplitHeader::menuManualReconnect()
{
auto app = getApp();
// fourtf: connection
app->twitch.server->connect();
}
void SplitHeader::menuShowChangelog()
{
}
} // namespace widgets
} // namespace chatterino
-96
View File
@@ -1,96 +0,0 @@
#pragma once
#include "widgets/BaseWidget.hpp"
#include "widgets/helper/RippleEffectLabel.hpp"
#include "widgets/helper/SignalLabel.hpp"
#include <QAction>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPoint>
#include <QWidget>
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/connection.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <vector>
namespace chatterino {
namespace widgets {
class Split;
class Label;
class SplitHeader : public BaseWidget, pajlada::Signals::SignalHolder
{
Q_OBJECT
public:
explicit SplitHeader(Split *_chatWidget);
virtual ~SplitHeader() override;
// Update channel text from chat widget
void updateChannelText();
void updateModerationModeIcon();
void updateModes();
protected:
virtual void scaleChangedEvent(float) override;
virtual void themeRefreshEvent() override;
virtual void paintEvent(QPaintEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *event) override;
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
private:
Split *const split;
QPoint dragStart;
bool dragging = false;
bool doubleClicked = false;
bool showingHelpTooltip = false;
pajlada::Signals::Connection onlineStatusChangedConnection;
RippleEffectButton *dropdownButton;
// Label *titleLabel;
Label *titleLabel;
RippleEffectLabel *modeButton;
RippleEffectButton *moderationButton;
QMenu dropdownMenu;
QMenu modeMenu;
QAction *setSub = nullptr;
QAction *setEmote = nullptr;
QAction *setSlow = nullptr;
QAction *setR9k = nullptr;
void rightButtonClicked();
void initializeChannelSignals();
QString tooltip;
bool isLive;
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
public slots:
void addDropdownItems(RippleEffectButton *label);
void addModeItems(RippleEffectLabel *label);
void menuMoveSplit();
void menuReloadChannelEmotes();
void menuManualReconnect();
void menuShowChangelog();
};
} // namespace widgets
} // namespace chatterino
-367
View File
@@ -1,367 +0,0 @@
#include "widgets/helper/SplitInput.hpp"
#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"
#include "util/LayoutCreator.hpp"
#include "util/UrlFetch.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/Split.hpp"
#include "widgets/SplitContainer.hpp"
#include <QCompleter>
#include <QPainter>
namespace chatterino {
namespace widgets {
SplitInput::SplitInput(Split *_chatWidget)
: BaseWidget(_chatWidget)
, split_(_chatWidget)
{
this->initLayout();
auto completer = new QCompleter(&this->split_->getChannel().get()->completionModel);
this->ui_.textEdit->setCompleter(completer);
this->split_->channelChanged.connect([this] {
auto completer = new QCompleter(&this->split_->getChannel()->completionModel);
this->ui_.textEdit->setCompleter(completer);
});
// misc
this->installKeyPressedEvent();
this->scaleChangedEvent(this->getScale());
}
void SplitInput::initLayout()
{
auto app = getApp();
util::LayoutCreator<SplitInput> layoutCreator(this);
auto layout =
layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(&this->ui_.hbox);
// input
auto textEdit = layout.emplace<ResizingTextEdit>().assign(&this->ui_.textEdit);
connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this,
&SplitInput::editTextChanged);
// right box
auto box = layout.emplace<QVBoxLayout>().withoutMargin();
box->setSpacing(0);
{
auto textEditLength = box.emplace<QLabel>().assign(&this->ui_.textEditLength);
textEditLength->setAlignment(Qt::AlignRight);
box->addStretch(1);
box.emplace<RippleEffectLabel>().assign(&this->ui_.emoteButton);
}
this->ui_.emoteButton->getLabel().setTextFormat(Qt::RichText);
// ---- misc
// set edit font
this->ui_.textEdit->setFont(
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
this->managedConnections_.push_back(app->fonts->fontChanged.connect([=]() {
this->ui_.textEdit->setFont(
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
}));
// open emote popup
QObject::connect(this->ui_.emoteButton, &RippleEffectLabel::clicked, [this] {
if (!this->emotePopup_) {
this->emotePopup_ = std::make_unique<EmotePopup>();
this->emotePopup_->linkClicked.connect([this](const messages::Link &link) {
if (link.type == messages::Link::InsertText) {
this->insertText(link.value + " ");
}
});
}
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->split_->view.clearSelection();
}
});
// textEditLength visibility
app->settings->showMessageLength.connect(
[this](const bool &value, auto) { this->ui_.textEditLength->setHidden(!value); },
this->managedConnections_);
}
void SplitInput::scaleChangedEvent(float scale)
{
// update the icon size of the emote button
this->updateEmoteButton();
// set maximum height
this->setMaximumHeight(int(150 * this->getScale()));
this->ui_.textEdit->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale()));
}
void SplitInput::themeRefreshEvent()
{
QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager->splits.input.text);
this->updateEmoteButton();
this->ui_.textEditLength->setPalette(palette);
this->ui_.textEdit->setStyleSheet(this->themeManager->splits.input.styleSheet);
this->ui_.hbox->setMargin(int((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale()));
this->ui_.emoteButton->getLabel().setStyleSheet("color: #000");
}
void SplitInput::updateEmoteButton()
{
float scale = this->getScale();
QString text = "<img src=':/images/emote.svg' width='xD' height='xD' />";
text.replace("xD", QString::number(int(12 * scale)));
if (this->themeManager->isLightTheme()) {
text.replace("emote", "emote_dark");
}
this->ui_.emoteButton->getLabel().setText(text);
this->ui_.emoteButton->setFixedHeight(int(18 * scale));
}
void SplitInput::installKeyPressedEvent()
{
auto app = getApp();
this->ui_.textEdit->keyPressed.connect([this, app](QKeyEvent *event) {
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
auto c = this->split_->getChannel();
if (c == nullptr) {
return;
}
QString message = ui_.textEdit->toPlainText();
QString sendMessage = app->commands->execCommand(message, c, false);
sendMessage = sendMessage.replace('\n', ' ');
c->sendMessage(sendMessage);
// don't add duplicate messages to message history
if (this->prevMsg_.isEmpty() || !this->prevMsg_.endsWith(message))
this->prevMsg_.append(message);
event->accept();
if (!(event->modifiers() == Qt::ControlModifier)) {
this->currMsg_ = QString();
this->ui_.textEdit->setText(QString());
this->prevIndex_ = 0;
} else if (this->ui_.textEdit->toPlainText() ==
this->prevMsg_.at(this->prevMsg_.size() - 1)) {
this->prevMsg_.removeLast();
}
this->prevIndex_ = this->prevMsg_.size();
} else if (event->key() == Qt::Key_Up) {
if ((event->modifiers() & Qt::ShiftModifier) != 0) {
return;
}
if (event->modifiers() == Qt::AltModifier) {
SplitContainer *page = this->split_->getContainer();
if (page != nullptr) {
page->selectNextSplit(SplitContainer::Above);
}
} else {
if (this->prevMsg_.size() && this->prevIndex_) {
if (this->prevIndex_ == (this->prevMsg_.size())) {
this->currMsg_ = ui_.textEdit->toPlainText();
}
this->prevIndex_--;
this->ui_.textEdit->setText(this->prevMsg_.at(this->prevIndex_));
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
}
}
} else if (event->key() == Qt::Key_Down) {
if ((event->modifiers() & Qt::ShiftModifier) != 0) {
return;
}
if (event->modifiers() == Qt::AltModifier) {
SplitContainer *page = this->split_->getContainer();
if (page != nullptr) {
page->selectNextSplit(SplitContainer::Below);
}
} else {
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
this->prevIndex_ != this->prevMsg_.size()) {
this->prevIndex_++;
this->ui_.textEdit->setText(this->prevMsg_.at(this->prevIndex_));
} else {
this->prevIndex_ = this->prevMsg_.size();
this->ui_.textEdit->setText(this->currMsg_);
}
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
}
} else if (event->key() == Qt::Key_Left) {
if (event->modifiers() == Qt::AltModifier) {
SplitContainer *page = this->split_->getContainer();
if (page != nullptr) {
page->selectNextSplit(SplitContainer::Left);
}
}
} else if (event->key() == Qt::Key_Right) {
if (event->modifiers() == Qt::AltModifier) {
SplitContainer *page = this->split_->getContainer();
if (page != nullptr) {
page->selectNextSplit(SplitContainer::Right);
}
}
} else if (event->key() == Qt::Key_Tab) {
if (event->modifiers() == Qt::ControlModifier) {
SplitContainer *page = static_cast<SplitContainer *>(this->split_->parentWidget());
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
notebook->selectNextTab();
}
} else if (event->key() == Qt::Key_Backtab) {
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
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->split_->view.hasSelection()) {
this->split_->doCopy();
event->accept();
}
}
});
}
void SplitInput::clearSelection()
{
QTextCursor c = this->ui_.textEdit->textCursor();
c.setPosition(c.position());
c.setPosition(c.position(), QTextCursor::KeepAnchor);
this->ui_.textEdit->setTextCursor(c);
}
QString SplitInput::getInputText() const
{
return this->ui_.textEdit->toPlainText();
}
void SplitInput::insertText(const QString &text)
{
this->ui_.textEdit->insertPlainText(text);
}
void SplitInput::editTextChanged()
{
auto app = getApp();
// set textLengthLabel value
QString text = this->ui_.textEdit->toPlainText();
if (text.startsWith("/r ", Qt::CaseInsensitive) &&
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 = app->commands->execCommand(text, this->split_->getChannel(), true);
}
QString labelText;
if (text.length() == 0) {
labelText = "";
} else {
labelText = QString::number(text.length());
}
this->ui_.textEditLength->setText(labelText);
}
void SplitInput::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if (this->themeManager->isLightTheme()) {
int s = int(3 * this->getScale());
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s));
painter.fillRect(rect, this->themeManager->splits.input.background);
painter.setPen(QColor("#ccc"));
painter.drawRect(rect);
} else {
int s = int(1 * this->getScale());
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s));
painter.fillRect(rect, this->themeManager->splits.input.background);
painter.setPen(QColor("#333"));
painter.drawRect(rect);
}
// int offset = 2;
// painter.fillRect(offset, this->height() - offset, this->width() - 2 * offset, 1,
// getApp()->themes->splits.input.focusedLine);
}
void SplitInput::resizeEvent(QResizeEvent *)
{
if (this->height() == this->maximumHeight()) {
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
} else {
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
}
void SplitInput::mousePressEvent(QMouseEvent *)
{
this->split_->giveFocus(Qt::MouseFocusReason);
}
} // namespace widgets
} // namespace chatterino
-72
View File
@@ -1,72 +0,0 @@
#pragma once
#include "ResizingTextEdit.hpp"
#include "widgets/BaseWidget.hpp"
#include "widgets/EmotePopup.hpp"
#include "widgets/helper/RippleEffectLabel.hpp"
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPaintEvent>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QWidget>
namespace chatterino {
namespace widgets {
class Split;
class SplitInput : public BaseWidget
{
Q_OBJECT
public:
SplitInput(Split *_chatWidget);
void clearSelection();
QString getInputText() const;
void insertText(const QString &text);
pajlada::Signals::Signal<const QString &> textChanged;
protected:
virtual void scaleChangedEvent(float scale) override;
virtual void themeRefreshEvent() override;
virtual void paintEvent(QPaintEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override;
private:
Split *const split_;
std::unique_ptr<EmotePopup> emotePopup_;
struct {
ResizingTextEdit *textEdit;
QLabel *textEditLength;
RippleEffectLabel *emoteButton;
QHBoxLayout *hbox;
} ui_;
std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
QStringList prevMsg_;
QString currMsg_;
int prevIndex_ = 0;
void initLayout();
void installKeyPressedEvent();
void updateEmoteButton();
private slots:
void editTextChanged();
friend class Split;
};
} // namespace widgets
} // namespace chatterino
-6
View File
@@ -1,6 +0,0 @@
#include "SplitNode.hpp"
SplitNode::SplitNode()
{
}
-11
View File
@@ -1,11 +0,0 @@
#ifndef SPLITNODE_HPP
#define SPLITNODE_HPP
class SplitNode
{
public:
SplitNode();
};
#endif // SPLITNODE_HPP
-215
View File
@@ -1,215 +0,0 @@
#include "SplitOverlay.hpp"
#include <QEvent>
#include <QGraphicsBlurEffect>
#include <QGraphicsEffect>
#include <QGraphicsOpacityEffect>
#include <QGridLayout>
#include <QPainter>
#include <QPushButton>
#include "Application.hpp"
#include "singletons/ResourceManager.hpp"
#include "widgets/Split.hpp"
#include "widgets/SplitContainer.hpp"
namespace chatterino {
namespace widgets {
SplitOverlay::SplitOverlay(Split *parent)
: BaseWidget(parent)
, split(parent)
{
QGridLayout *layout = new QGridLayout(this);
this->_layout = layout;
layout->setMargin(1);
layout->setSpacing(1);
layout->setRowStretch(1, 1);
layout->setRowStretch(3, 1);
layout->setColumnStretch(1, 1);
layout->setColumnStretch(3, 1);
QPushButton *move = new QPushButton(getApp()->resources->split.move, QString());
QPushButton *left = this->_left = new QPushButton(getApp()->resources->split.left, QString());
QPushButton *right = this->_right =
new QPushButton(getApp()->resources->split.right, QString());
QPushButton *up = this->_up = new QPushButton(getApp()->resources->split.up, QString());
QPushButton *down = this->_down = new QPushButton(getApp()->resources->split.down, QString());
move->setGraphicsEffect(new QGraphicsOpacityEffect(this));
left->setGraphicsEffect(new QGraphicsOpacityEffect(this));
right->setGraphicsEffect(new QGraphicsOpacityEffect(this));
up->setGraphicsEffect(new QGraphicsOpacityEffect(this));
down->setGraphicsEffect(new QGraphicsOpacityEffect(this));
move->setFlat(true);
left->setFlat(true);
right->setFlat(true);
up->setFlat(true);
down->setFlat(true);
layout->addWidget(move, 2, 2);
layout->addWidget(left, 2, 0);
layout->addWidget(right, 2, 4);
layout->addWidget(up, 0, 2);
layout->addWidget(down, 4, 2);
move->installEventFilter(new ButtonEventFilter(this, SplitMove));
left->installEventFilter(new ButtonEventFilter(this, SplitLeft));
right->installEventFilter(new ButtonEventFilter(this, SplitRight));
up->installEventFilter(new ButtonEventFilter(this, SplitUp));
down->installEventFilter(new ButtonEventFilter(this, SplitDown));
move->setFocusPolicy(Qt::NoFocus);
left->setFocusPolicy(Qt::NoFocus);
right->setFocusPolicy(Qt::NoFocus);
up->setFocusPolicy(Qt::NoFocus);
down->setFocusPolicy(Qt::NoFocus);
move->setCursor(Qt::SizeAllCursor);
left->setCursor(Qt::PointingHandCursor);
right->setCursor(Qt::PointingHandCursor);
up->setCursor(Qt::PointingHandCursor);
down->setCursor(Qt::PointingHandCursor);
this->managedConnect(this->scaleChanged, [=](float _scale) {
int a = int(_scale * 30);
QSize size(a, a);
move->setIconSize(size);
left->setIconSize(size);
right->setIconSize(size);
up->setIconSize(size);
down->setIconSize(size);
});
this->setMouseTracking(true);
this->setCursor(Qt::ArrowCursor);
}
void SplitOverlay::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if (this->themeManager->isLightTheme()) {
painter.fillRect(this->rect(), QColor(255, 255, 255, 200));
} else {
painter.fillRect(this->rect(), QColor(0, 0, 0, 150));
}
QRect rect;
switch (this->hoveredElement) {
case SplitLeft: {
rect = QRect(0, 0, this->width() / 2, this->height());
} break;
case SplitRight: {
rect = QRect(this->width() / 2, 0, this->width() / 2, this->height());
} break;
case SplitUp: {
rect = QRect(0, 0, this->width(), this->height() / 2);
} break;
case SplitDown: {
rect = QRect(0, this->height() / 2, this->width(), this->height() / 2);
} break;
default:;
}
rect.setRight(rect.right() - 1);
rect.setBottom(rect.bottom() - 1);
if (!rect.isNull()) {
painter.setPen(getApp()->themes->splits.dropPreviewBorder);
painter.setBrush(getApp()->themes->splits.dropPreview);
painter.drawRect(rect);
}
}
void SplitOverlay::resizeEvent(QResizeEvent *event)
{
float _scale = this->getScale();
bool wideEnough = event->size().width() > 150 * _scale;
bool highEnough = event->size().height() > 150 * _scale;
this->_left->setVisible(wideEnough);
this->_right->setVisible(wideEnough);
this->_up->setVisible(highEnough);
this->_down->setVisible(highEnough);
}
void SplitOverlay::mouseMoveEvent(QMouseEvent *event)
{
BaseWidget::mouseMoveEvent(event);
// qDebug() << QGuiApplication::queryKeyboardModifiers();
// if ((QGuiApplication::queryKeyboardModifiers() & Qt::AltModifier) == Qt::AltModifier) {
// this->hide();
// }
}
SplitOverlay::ButtonEventFilter::ButtonEventFilter(SplitOverlay *_parent, HoveredElement _element)
: QObject(_parent)
, parent(_parent)
, hoveredElement(_element)
{
}
bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched, QEvent *event)
{
switch (event->type()) {
case QEvent::Enter: {
QGraphicsOpacityEffect *effect =
dynamic_cast<QGraphicsOpacityEffect *>(((QWidget *)watched)->graphicsEffect());
if (effect != nullptr) {
effect->setOpacity(0.99);
}
this->parent->hoveredElement = this->hoveredElement;
this->parent->update();
} break;
case QEvent::Leave: {
QGraphicsOpacityEffect *effect =
dynamic_cast<QGraphicsOpacityEffect *>(((QWidget *)watched)->graphicsEffect());
if (effect != nullptr) {
effect->setOpacity(0.7);
}
this->parent->hoveredElement = HoveredElement::None;
this->parent->update();
} break;
case QEvent::MouseButtonPress: {
if (this->hoveredElement == HoveredElement::SplitMove) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::LeftButton) {
this->parent->split->drag();
}
return true;
}
} break;
case QEvent::MouseButtonRelease: {
if (this->hoveredElement != HoveredElement::SplitMove) {
SplitContainer *container = this->parent->split->getContainer();
if (container != nullptr) {
auto *_split = new Split(container);
auto dir = SplitContainer::Direction(this->hoveredElement +
SplitContainer::Left - SplitLeft);
container->insertSplit(_split, dir, this->parent->split);
this->parent->hide();
}
}
} break;
default:;
}
return QObject::eventFilter(watched, event);
}
} // namespace widgets
} // namespace chatterino
-52
View File
@@ -1,52 +0,0 @@
#pragma once
#include <QGridLayout>
#include <QPushButton>
#include "pajlada/signals/signalholder.hpp"
#include "widgets/BaseWidget.hpp"
namespace chatterino {
namespace widgets {
class Split;
class SplitOverlay : public BaseWidget, pajlada::Signals::SignalHolder
{
public:
explicit SplitOverlay(Split *parent = nullptr);
protected:
// bool event(QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private:
// fourtf: !!! preserve the order of left, up, right and down
enum HoveredElement { None, SplitMove, SplitLeft, SplitUp, SplitRight, SplitDown };
HoveredElement hoveredElement = None;
Split *split;
QGridLayout *_layout;
QPushButton *_left;
QPushButton *_up;
QPushButton *_right;
QPushButton *_down;
class ButtonEventFilter : public QObject
{
SplitOverlay *parent;
HoveredElement hoveredElement;
public:
ButtonEventFilter(SplitOverlay *parent, HoveredElement hoveredElement);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
};
friend class ButtonEventFilter;
};
} // namespace widgets
} // namespace chatterino