changed to 80 max column

This commit is contained in:
fourtf
2018-08-06 21:17:03 +02:00
parent defa7e41fa
commit f71ff08e68
203 changed files with 3792 additions and 2405 deletions
+46 -31
View File
@@ -128,19 +128,23 @@ Split::Split(QWidget *parent)
this->header_.updateModerationModeIcon();
this->overlay_->hide();
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
this->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
this->managedConnect(modifierStatusChanged, [this](Qt::KeyboardModifiers status) {
if ((status == showSplitOverlayModifiers /*|| status == showAddSplitRegions*/) &&
this->managedConnect(modifierStatusChanged,
[this](Qt::KeyboardModifiers status) {
if ((status == showSplitOverlayModifiers /*|| status == showAddSplitRegions*/) &&
this->isMouseOver_) {
this->overlay_->show();
} else {
this->overlay_->hide();
}
});
this->overlay_->show();
} else {
this->overlay_->hide();
}
});
this->input_.ui_.textEdit->focused.connect([this] { this->focused.invoke(); });
this->input_.ui_.textEdit->focusLost.connect([this] { this->focusLost.invoke(); });
this->input_.ui_.textEdit->focused.connect(
[this] { this->focused.invoke(); });
this->input_.ui_.textEdit->focusLost.connect(
[this] { this->focusLost.invoke(); });
}
Split::~Split()
@@ -199,13 +203,14 @@ void Split::setChannel(IndirectChannel newChannel)
this->header_.updateRoomModes();
});
this->roomModeChangedConnection_ =
tc->roomModesChanged.connect([this] { this->header_.updateRoomModes(); });
this->roomModeChangedConnection_ = tc->roomModesChanged.connect(
[this] { this->header_.updateRoomModes(); });
}
this->indirectChannelChangedConnection_ = newChannel.getChannelChanged().connect([this] { //
QTimer::singleShot(0, [this] { this->setChannel(this->channel_); });
});
this->indirectChannelChangedConnection_ =
newChannel.getChannelChanged().connect([this] { //
QTimer::singleShot(0, [this] { this->setChannel(this->channel_); });
});
this->header_.updateModerationModeIcon();
this->header_.updateChannelText();
@@ -376,7 +381,8 @@ void Split::doChangeChannel()
this->showChangeChannelPopup("Change channel", false, [](bool) {});
auto popup = this->findChildren<QDockWidget *>();
if (popup.size() && popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
if (popup.size() && popup.at(0)->isVisible() &&
!popup.at(0)->isFloating()) {
popup.at(0)->hide();
showViewerList();
}
@@ -387,8 +393,8 @@ void Split::doPopup()
auto app = getApp();
Window &window = app->windows->createWindow(Window::Type::Popup);
Split *split =
new Split(static_cast<SplitContainer *>(window.getNotebook().getOrAddSelectedPage()));
Split *split = new Split(static_cast<SplitContainer *>(
window.getNotebook().getOrAddSelectedPage()));
split->setChannel(this->getIndirectChannel());
window.getNotebook().getOrAddSelectedPage()->appendSplit(split);
@@ -406,7 +412,8 @@ void Split::openInBrowser()
auto channel = this->getChannel();
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
QDesktopServices::openUrl("https://twitch.tv/" + twitchChannel->getName());
QDesktopServices::openUrl("https://twitch.tv/" +
twitchChannel->getName());
}
}
@@ -414,7 +421,8 @@ void Split::openInPopupPlayer()
{
ChannelPtr channel = this->getChannel();
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
QDesktopServices::openUrl("https://player.twitch.tv/?channel=" + twitchChannel->getName());
QDesktopServices::openUrl("https://player.twitch.tv/?channel=" +
twitchChannel->getName());
}
}
@@ -432,9 +440,11 @@ void Split::showViewerList()
auto viewerDock = new QDockWidget("Viewer List", this);
viewerDock->setAllowedAreas(Qt::LeftDockWidgetArea);
viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar |
QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
viewerDock->resize(0.5 * this->width(),
this->height() - this->header_.height() - this->input_.height());
QDockWidget::DockWidgetClosable |
QDockWidget::DockWidgetFloatable);
viewerDock->resize(
0.5 * this->width(),
this->height() - this->header_.height() - this->input_.height());
viewerDock->move(0, this->header_.height());
auto multiWidget = new QWidget(viewerDock);
@@ -444,8 +454,10 @@ void Split::showViewerList()
auto chattersList = new QListWidget();
auto resultList = new QListWidget();
static QStringList labels = {"Moderators", "Staff", "Admins", "Global Moderators", "Viewers"};
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
static QStringList labels = {"Moderators", "Staff", "Admins",
"Global Moderators", "Viewers"};
static QStringList jsonLabels = {"moderators", "staff", "admins",
"global_mods", "viewers"};
QList<QListWidgetItem *> labelList;
for (auto &x : labels) {
auto label = new QListWidgetItem(x);
@@ -454,8 +466,9 @@ void Split::showViewerList()
}
auto loadingLabel = new QLabel("Loading...");
auto request = NetworkRequest::twitchRequest("https://tmi.twitch.tv/group/user/" +
this->getChannel()->getName() + "/chatters");
auto request = NetworkRequest::twitchRequest(
"https://tmi.twitch.tv/group/user/" + this->getChannel()->getName() +
"/chatters");
request.setCaller(this);
request.onSuccess([=](auto result) -> Outcome {
@@ -465,7 +478,8 @@ void Split::showViewerList()
loadingLabel->hide();
for (int i = 0; i < jsonLabels.size(); i++) {
chattersList->addItem(labelList.at(i));
foreach (const QJsonValue &v, chattersObj.value(jsonLabels.at(i)).toArray())
foreach (const QJsonValue &v,
chattersObj.value(jsonLabels.at(i)).toArray())
chattersList->addItem(v.toString());
}
@@ -482,7 +496,8 @@ void Split::showViewerList()
chattersList->hide();
resultList->clear();
for (auto &item : results) {
if (!labels.contains(item->text())) resultList->addItem(item->text());
if (!labels.contains(item->text()))
resultList->addItem(item->text());
}
resultList->show();
} else {
@@ -523,8 +538,8 @@ void Split::showUserInfoPopup(const UserName &user)
auto *userPopup = new UserInfoPopup;
userPopup->setData(user.string, this->getChannel());
userPopup->setAttribute(Qt::WA_DeleteOnClose);
userPopup->move(QCursor::pos() -
QPoint(int(150 * this->getScale()), int(70 * this->getScale())));
userPopup->move(QCursor::pos() - QPoint(int(150 * this->getScale()),
int(70 * this->getScale())));
userPopup->show();
}
+6 -4
View File
@@ -24,9 +24,10 @@ class SplitContainer;
class SplitOverlay;
class SelectChannelDialog;
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
// ChatWidgetHeader
// - Responsible for rendering which channel the ChatWidget is in, and the menu in the top-left of
// Each ChatWidget consists of three sub-elements that handle their own part of
// the chat widget: ChatWidgetHeader
// - Responsible for rendering which channel the ChatWidget is in, and the
// menu in the top-left of
// the chat widget
// ChatWidgetView
// - Responsible for rendering all chat messages, and the scrollbar
@@ -76,7 +77,8 @@ public:
void setContainer(SplitContainer *container);
static pajlada::Signals::Signal<Qt::KeyboardModifiers> modifierStatusChanged;
static pajlada::Signals::Signal<Qt::KeyboardModifiers>
modifierStatusChanged;
static Qt::KeyboardModifiers modifierStatus;
protected:
+164 -101
View File
@@ -124,10 +124,12 @@ void SplitContainer::appendSplit(Split *split)
void SplitContainer::insertSplit(Split *split, const Position &position)
{
this->insertSplit(split, position.direction_, reinterpret_cast<Node *>(position.relativeNode_));
this->insertSplit(split, position.direction_,
reinterpret_cast<Node *>(position.relativeNode_));
}
void SplitContainer::insertSplit(Split *split, Direction direction, Split *relativeTo)
void SplitContainer::insertSplit(Split *split, Direction direction,
Split *relativeTo)
{
Node *node = this->baseNode_.findNodeContainingSplit(relativeTo);
assert(node != nullptr);
@@ -135,7 +137,8 @@ void SplitContainer::insertSplit(Split *split, Direction direction, Split *relat
this->insertSplit(split, direction, node);
}
void SplitContainer::insertSplit(Split *split, Direction direction, Node *relativeTo)
void SplitContainer::insertSplit(Split *split, Direction direction,
Node *relativeTo)
{
assertInGuiThread();
@@ -170,11 +173,12 @@ void SplitContainer::addSplit(Split *split)
this->refreshTabTitle();
split->getChannelView().tabHighlightRequested.connect([this](HighlightState state) {
if (this->tab_ != nullptr) {
this->tab_->setHighlightState(state);
}
});
split->getChannelView().tabHighlightRequested.connect(
[this](HighlightState state) {
if (this->tab_ != nullptr) {
this->tab_->setHighlightState(state);
}
});
split->focused.connect([this, split] { this->setSelected(split); });
@@ -206,7 +210,8 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split)
Node *node = this->baseNode_.findNodeContainingSplit(split);
assert(node != nullptr);
this->splits_.erase(std::find(this->splits_.begin(), this->splits_.end(), split));
this->splits_.erase(
std::find(this->splits_.begin(), this->splits_.end(), split));
split->setParent(nullptr);
Position position = node->releaseSplit();
this->layout();
@@ -251,21 +256,24 @@ void SplitContainer::selectSplitRecursive(Node *node, Direction direction)
if (node->parent_->type_ == Node::toContainerType(direction)) {
auto &siblings = node->parent_->children_;
auto it = std::find_if(siblings.begin(), siblings.end(),
[node](const auto &other) { return other.get() == node; });
auto it = std::find_if(
siblings.begin(), siblings.end(),
[node](const auto &other) { return other.get() == node; });
assert(it != siblings.end());
if (direction == Direction::Left || direction == Direction::Above) {
if (it == siblings.begin()) {
this->selectSplitRecursive(node->parent_, direction);
} else {
this->focusSplitRecursive(siblings[it - siblings.begin() - 1].get(), direction);
this->focusSplitRecursive(
siblings[it - siblings.begin() - 1].get(), direction);
}
} else {
if (it->get() == siblings.back().get()) {
this->selectSplitRecursive(node->parent_, direction);
} else {
this->focusSplitRecursive(siblings[it - siblings.begin() + 1].get(), direction);
this->focusSplitRecursive(
siblings[it - siblings.begin() + 1].get(), direction);
}
}
} else {
@@ -285,14 +293,16 @@ void SplitContainer::focusSplitRecursive(Node *node, Direction direction)
case Node::VerticalContainer: {
auto &children = node->children_;
auto it = std::find_if(children.begin(), children.end(), [node](const auto &other) {
return node->preferedFocusTarget_ == other.get();
});
auto it = std::find_if(
children.begin(), children.end(), [node](const auto &other) {
return node->preferedFocusTarget_ == other.get();
});
if (it != children.end()) {
this->focusSplitRecursive(it->get(), direction);
} else {
this->focusSplitRecursive(node->children_.front().get(), direction);
this->focusSplitRecursive(node->children_.front().get(),
direction);
}
} break;
@@ -306,8 +316,9 @@ void SplitContainer::layout()
std::vector<DropRect> _dropRects;
std::vector<ResizeRect> _resizeRects;
this->baseNode_.layout(Split::modifierStatus == showAddSplitRegions || this->isDragging_,
this->getScale(), _dropRects, _resizeRects);
this->baseNode_.layout(
Split::modifierStatus == showAddSplitRegions || this->isDragging_,
this->getScale(), _dropRects, _resizeRects);
this->dropRects_ = _dropRects;
@@ -316,23 +327,26 @@ void SplitContainer::layout()
Node *node = this->baseNode_.findNodeContainingSplit(split);
_dropRects.push_back(DropRect(QRect(g.left(), g.top(), g.width() / 4, g.height()),
Position(node, Direction::Left)));
_dropRects.push_back(
DropRect(QRect(g.left() + g.width() / 4 * 3, g.top(), g.width() / 4, g.height()),
Position(node, Direction::Right)));
DropRect(QRect(g.left(), g.top(), g.width() / 4, g.height()),
Position(node, Direction::Left)));
_dropRects.push_back(DropRect(QRect(g.left() + g.width() / 4 * 3,
g.top(), g.width() / 4, g.height()),
Position(node, Direction::Right)));
_dropRects.push_back(DropRect(QRect(g.left(), g.top(), g.width(), g.height() / 2),
Position(node, Direction::Above)));
_dropRects.push_back(
DropRect(QRect(g.left(), g.top() + g.height() / 2, g.width(), g.height() / 2),
Position(node, Direction::Below)));
DropRect(QRect(g.left(), g.top(), g.width(), g.height() / 2),
Position(node, Direction::Above)));
_dropRects.push_back(DropRect(QRect(g.left(), g.top() + g.height() / 2,
g.width(), g.height() / 2),
Position(node, Direction::Below)));
}
if (this->splits_.empty()) {
QRect g = this->rect();
_dropRects.push_back(DropRect(QRect(g.left(), g.top(), g.width(), g.height()),
Position(nullptr, Direction::Below)));
_dropRects.push_back(
DropRect(QRect(g.left(), g.top(), g.width(), g.height()),
Position(nullptr, Direction::Below)));
}
this->overlay_.setRects(std::move(_dropRects));
@@ -340,7 +354,8 @@ void SplitContainer::layout()
// handle resizeHandles
if (this->resizeHandles_.size() < _resizeRects.size()) {
while (this->resizeHandles_.size() < _resizeRects.size()) {
this->resizeHandles_.push_back(std::make_unique<ResizeHandle>(this));
this->resizeHandles_.push_back(
std::make_unique<ResizeHandle>(this));
}
} else if (this->resizeHandles_.size() > _resizeRects.size()) {
this->resizeHandles_.resize(_resizeRects.size());
@@ -386,7 +401,9 @@ void SplitContainer::mouseReleaseEvent(QMouseEvent *event)
} else {
auto it =
std::find_if(this->dropRects_.begin(), this->dropRects_.end(),
[event](DropRect &rect) { return rect.rect.contains(event->pos()); });
[event](DropRect &rect) {
return rect.rect.contains(event->pos());
});
if (it != this->dropRects_.end()) {
this->insertSplit(new Split(this), it->position);
}
@@ -409,7 +426,8 @@ void SplitContainer::paintEvent(QPaintEvent *)
if (notebook != nullptr) {
if (notebook->getPageCount() > 1) {
text += "\n\nTip: After adding a split you can hold <Alt> to move it or split it "
text += "\n\nTip: After adding a split you can hold <Alt> to "
"move it or split it "
"further.";
}
}
@@ -442,22 +460,28 @@ void SplitContainer::paintEvent(QPaintEvent *)
painter.drawRect(rect);
int s = std::min<int>(dropRect.rect.width(), dropRect.rect.height()) - 12;
int s =
std::min<int>(dropRect.rect.width(), dropRect.rect.height()) - 12;
if (this->theme->isLightTheme()) {
painter.setPen(QColor(0, 0, 0));
} else {
painter.setPen(QColor(255, 255, 255));
}
painter.drawLine(rect.left() + rect.width() / 2 - (s / 2), rect.top() + rect.height() / 2,
rect.left() + rect.width() / 2 + (s / 2), rect.top() + rect.height() / 2);
painter.drawLine(rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 - (s / 2),
rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 + (s / 2));
painter.drawLine(rect.left() + rect.width() / 2 - (s / 2),
rect.top() + rect.height() / 2,
rect.left() + rect.width() / 2 + (s / 2),
rect.top() + rect.height() / 2);
painter.drawLine(rect.left() + rect.width() / 2,
rect.top() + rect.height() / 2 - (s / 2),
rect.left() + rect.width() / 2,
rect.top() + rect.height() / 2 + (s / 2));
}
QBrush accentColor = (QApplication::activeWindow() == this->window()
? this->theme->tabs.selected.backgrounds.regular
: this->theme->tabs.selected.backgrounds.unfocused);
QBrush accentColor =
(QApplication::activeWindow() == this->window()
? this->theme->tabs.selected.backgrounds.regular
: this->theme->tabs.selected.backgrounds.unfocused);
painter.fillRect(0, 0, width(), 1, accentColor);
}
@@ -562,7 +586,8 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node)
if (type == "split") {
auto *split = new Split(this);
split->setChannel(WindowManager::decodeChannel(obj.value("data").toObject()));
split->setChannel(
WindowManager::decodeChannel(obj.value("data").toObject()));
this->appendSplit(split);
} else if (type == "horizontal" || type == "vertical") {
@@ -570,7 +595,8 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node)
Direction direction = vertical ? Direction::Below : Direction::Right;
node->type_ = vertical ? Node::VerticalContainer : Node::HorizontalContainer;
node->type_ =
vertical ? Node::VerticalContainer : Node::HorizontalContainer;
for (QJsonValue _val : obj.value("items").toArray()) {
auto _obj = _val.toObject();
@@ -578,7 +604,8 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node)
auto _type = _obj.value("type");
if (_type == "split") {
auto *split = new Split(this);
split->setChannel(WindowManager::decodeChannel(_obj.value("data").toObject()));
split->setChannel(WindowManager::decodeChannel(
_obj.value("data").toObject()));
Node *_node = new Node();
_node->parent_ = node;
@@ -601,7 +628,8 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node)
for (int i = 0; i < 2; i++) {
if (node->getChildren().size() < 2) {
auto *split = new Split(this);
split->setChannel(WindowManager::decodeChannel(obj.value("data").toObject()));
split->setChannel(
WindowManager::decodeChannel(obj.value("data").toObject()));
this->insertSplit(split, direction, node);
}
@@ -637,7 +665,8 @@ qreal SplitContainer::Node::getVerticalFlex()
return this->flexV_;
}
const std::vector<std::unique_ptr<SplitContainer::Node>> &SplitContainer::Node::getChildren()
const std::vector<std::unique_ptr<SplitContainer::Node>>
&SplitContainer::Node::getChildren()
{
return this->children_;
}
@@ -663,10 +692,13 @@ bool SplitContainer::Node::isOrContainsNode(SplitContainer::Node *_node)
}
return std::any_of(this->children_.begin(), this->children_.end(),
[_node](std::unique_ptr<Node> &n) { return n->isOrContainsNode(_node); });
[_node](std::unique_ptr<Node> &n) {
return n->isOrContainsNode(_node);
});
}
SplitContainer::Node *SplitContainer::Node::findNodeContainingSplit(Split *_split)
SplitContainer::Node *SplitContainer::Node::findNodeContainingSplit(
Split *_split)
{
if (this->type_ == Type::_Split && this->split_ == _split) {
return this;
@@ -682,7 +714,8 @@ SplitContainer::Node *SplitContainer::Node::findNodeContainingSplit(Split *_spli
return nullptr;
}
void SplitContainer::Node::insertSplitRelative(Split *_split, Direction _direction)
void SplitContainer::Node::insertSplitRelative(Split *_split,
Direction _direction)
{
if (this->parent_ == nullptr) {
switch (this->type_) {
@@ -711,7 +744,8 @@ void SplitContainer::Node::insertSplitRelative(Split *_split, Direction _directi
}
}
void SplitContainer::Node::nestSplitIntoCollection(Split *_split, Direction _direction)
void SplitContainer::Node::nestSplitIntoCollection(Split *_split,
Direction _direction)
{
if (toContainerType(_direction) == this->type_) {
this->children_.emplace_back(new Node(_split, this));
@@ -784,8 +818,9 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
} else {
auto &siblings = this->parent_->children_;
auto it = std::find_if(begin(siblings), end(siblings),
[this](auto &node) { return this == node.get(); });
auto it =
std::find_if(begin(siblings), end(siblings),
[this](auto &node) { return this == node.get(); });
assert(it != siblings.end());
Position position;
@@ -793,9 +828,11 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
// delete this and move split to parent
position.relativeNode_ = this->parent_;
if (this->parent_->type_ == Type::VerticalContainer) {
position.direction_ = siblings.begin() == it ? Direction::Above : Direction::Below;
position.direction_ = siblings.begin() == it ? Direction::Above
: Direction::Below;
} else {
position.direction_ = siblings.begin() == it ? Direction::Left : Direction::Right;
position.direction_ =
siblings.begin() == it ? Direction::Left : Direction::Right;
}
Node *_parent = this->parent_;
@@ -803,23 +840,26 @@ SplitContainer::Position SplitContainer::Node::releaseSplit()
std::unique_ptr<Node> &sibling = siblings.front();
_parent->type_ = sibling->type_;
_parent->split_ = sibling->split_;
std::vector<std::unique_ptr<Node>> nodes = std::move(sibling->children_);
std::vector<std::unique_ptr<Node>> nodes =
std::move(sibling->children_);
for (auto &node : nodes) {
node->parent_ = _parent;
}
_parent->children_ = std::move(nodes);
} else {
if (this == siblings.back().get()) {
position.direction_ = this->parent_->type_ == Type::VerticalContainer
? Direction::Below
: Direction::Right;
position.direction_ =
this->parent_->type_ == Type::VerticalContainer
? Direction::Below
: Direction::Right;
siblings.erase(it);
position.relativeNode_ = siblings.back().get();
} else {
position.relativeNode_ = (it + 1)->get();
position.direction_ = this->parent_->type_ == Type::VerticalContainer
? Direction::Above
: Direction::Left;
position.direction_ =
this->parent_->type_ == Type::VerticalContainer
? Direction::Above
: Direction::Left;
siblings.erase(it);
}
}
@@ -840,12 +880,15 @@ qreal SplitContainer::Node::getSize(bool isVertical)
qreal SplitContainer::Node::getChildrensTotalFlex(bool isVertical)
{
return std::accumulate(
this->children_.begin(), this->children_.end(), qreal(0),
[=](qreal val, std::unique_ptr<Node> &node) { return val + node->getFlex(isVertical); });
return std::accumulate(this->children_.begin(), this->children_.end(),
qreal(0),
[=](qreal val, std::unique_ptr<Node> &node) {
return val + node->getFlex(isVertical);
});
}
void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<DropRect> &dropRects,
void SplitContainer::Node::layout(bool addSpacing, float _scale,
std::vector<DropRect> &dropRects,
std::vector<ResizeRect> &resizeRects)
{
for (std::unique_ptr<Node> &node : this->children_) {
@@ -856,7 +899,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
switch (this->type_) {
case Node::_Split: {
QRect rect = this->geometry_.toRect();
this->split_->setGeometry(rect.marginsRemoved(QMargins(1, 1, 1, 1)));
this->split_->setGeometry(
rect.marginsRemoved(QMargins(1, 1, 1, 1)));
} break;
case Node::VerticalContainer:
case Node::HorizontalContainer: {
@@ -869,7 +913,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
qreal totalSize = std::accumulate(
this->children_.begin(), this->children_.end(), qreal(0),
[=](int val, std::unique_ptr<Node> &node) {
return val + std::max<qreal>(this->getSize(isVertical) / totalFlex *
return val + std::max<qreal>(this->getSize(isVertical) /
totalFlex *
node->getFlex(isVertical),
minSize);
});
@@ -879,8 +924,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
// add spacing if reqested
if (addSpacing) {
qreal offset =
std::min<qreal>(this->getSize(!isVertical) * 0.1, qreal(_scale * 24));
qreal offset = std::min<qreal>(this->getSize(!isVertical) * 0.1,
qreal(_scale * 24));
// droprect left / above
dropRects.emplace_back(
@@ -888,18 +933,21 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
isVertical ? offset : this->geometry_.width(),
isVertical ? this->geometry_.height() : offset)
.toRect(),
Position(this, isVertical ? Direction::Left : Direction::Above));
Position(this,
isVertical ? Direction::Left : Direction::Above));
// droprect right / below
if (isVertical) {
dropRects.emplace_back(
QRectF(this->geometry_.right() - offset, this->geometry_.top(), offset,
QRectF(this->geometry_.right() - offset,
this->geometry_.top(), offset,
this->geometry_.height())
.toRect(),
Position(this, Direction::Right));
} else {
dropRects.emplace_back(
QRectF(this->geometry_.left(), this->geometry_.bottom() - offset,
QRectF(this->geometry_.left(),
this->geometry_.bottom() - offset,
this->geometry_.width(), offset)
.toRect(),
Position(this, Direction::Below));
@@ -923,15 +971,16 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
if (isVertical) {
rect.setTop(pos);
rect.setHeight(
std::max<qreal>(this->geometry_.height() / totalFlex * child->flexV_,
std::max<qreal>(this->geometry_.height() / totalFlex *
child->flexV_,
minSize) *
sizeMultiplier);
} else {
rect.setLeft(pos);
rect.setWidth(
std::max<qreal>(this->geometry_.width() / totalFlex * child->flexH_,
minSize) *
sizeMultiplier);
rect.setWidth(std::max<qreal>(this->geometry_.width() /
totalFlex * child->flexH_,
minSize) *
sizeMultiplier);
}
child->geometry_ = rect;
@@ -941,20 +990,24 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
// add resize rect
if (child != this->children_.front()) {
QRectF r = isVertical
? QRectF(this->geometry_.left(), child->geometry_.top() - 4,
this->geometry_.width(), 8)
: QRectF(child->geometry_.left() - 4, this->geometry_.top(), 8,
this->geometry_.height());
resizeRects.push_back(ResizeRect(r.toRect(), child.get(), isVertical));
QRectF r = isVertical ? QRectF(this->geometry_.left(),
child->geometry_.top() - 4,
this->geometry_.width(), 8)
: QRectF(child->geometry_.left() - 4,
this->geometry_.top(), 8,
this->geometry_.height());
resizeRects.push_back(
ResizeRect(r.toRect(), child.get(), isVertical));
}
// normalize flex
if (isVertical) {
child->flexV_ = child->flexV_ / totalFlex * this->children_.size();
child->flexV_ =
child->flexV_ / totalFlex * this->children_.size();
child->flexH_ = 1;
} else {
child->flexH_ = child->flexH_ / totalFlex * this->children_.size();
child->flexH_ =
child->flexH_ / totalFlex * this->children_.size();
child->flexV_ = 1;
}
}
@@ -964,8 +1017,9 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector<Dro
SplitContainer::Node::Type SplitContainer::Node::toContainerType(Direction _dir)
{
return _dir == Direction::Left || _dir == Direction::Right ? Type::HorizontalContainer
: Type::VerticalContainer;
return _dir == Direction::Left || _dir == Direction::Right
? Type::HorizontalContainer
: Type::VerticalContainer;
}
//
@@ -981,7 +1035,8 @@ SplitContainer::DropOverlay::DropOverlay(SplitContainer *_parent)
this->setAcceptDrops(true);
}
void SplitContainer::DropOverlay::setRects(std::vector<SplitContainer::DropRect> _rects)
void SplitContainer::DropOverlay::setRects(
std::vector<SplitContainer::DropRect> _rects)
{
this->rects_ = std::move(_rects);
}
@@ -1074,12 +1129,15 @@ void SplitContainer::ResizeHandle::paintEvent(QPaintEvent *)
QPainter painter(this);
painter.setPen(QPen(getApp()->themes->splits.resizeHandle, 2));
painter.fillRect(this->rect(), getApp()->themes->splits.resizeHandleBackground);
painter.fillRect(this->rect(),
getApp()->themes->splits.resizeHandleBackground);
if (this->vertical_) {
painter.drawLine(0, this->height() / 2, this->width(), this->height() / 2);
painter.drawLine(0, this->height() / 2, this->width(),
this->height() / 2);
} else {
painter.drawLine(this->width() / 2, 0, this->width() / 2, this->height());
painter.drawLine(this->width() / 2, 0, this->width() / 2,
this->height());
}
}
@@ -1103,29 +1161,34 @@ void SplitContainer::ResizeHandle::mouseMoveEvent(QMouseEvent *event)
assert(node->parent_ != nullptr);
auto &siblings = node->parent_->getChildren();
auto it =
std::find_if(siblings.begin(), siblings.end(),
[this](const std::unique_ptr<Node> &n) { return n.get() == this->node; });
auto it = std::find_if(siblings.begin(), siblings.end(),
[this](const std::unique_ptr<Node> &n) {
return n.get() == this->node;
});
assert(it != siblings.end());
Node *before = siblings[it - siblings.begin() - 1].get();
QPoint topLeft = this->parent->mapToGlobal(before->geometry_.topLeft().toPoint());
QPoint bottomRight = this->parent->mapToGlobal(this->node->geometry_.bottomRight().toPoint());
QPoint topLeft =
this->parent->mapToGlobal(before->geometry_.topLeft().toPoint());
QPoint bottomRight = this->parent->mapToGlobal(
this->node->geometry_.bottomRight().toPoint());
int globalX = topLeft.x() > event->globalX()
? topLeft.x()
: (bottomRight.x() < event->globalX() ? bottomRight.x() : event->globalX());
: (bottomRight.x() < event->globalX() ? bottomRight.x()
: event->globalX());
int globalY = topLeft.y() > event->globalY()
? topLeft.y()
: (bottomRight.y() < event->globalY() ? bottomRight.y() : event->globalY());
: (bottomRight.y() < event->globalY() ? bottomRight.y()
: event->globalY());
QPoint mousePoint(globalX, globalY);
if (this->vertical_) {
qreal totalFlexV = this->node->flexV_ + before->flexV_;
before->flexV_ =
totalFlexV * (mousePoint.y() - topLeft.y()) / (bottomRight.y() - topLeft.y());
before->flexV_ = totalFlexV * (mousePoint.y() - topLeft.y()) /
(bottomRight.y() - topLeft.y());
this->node->flexV_ = totalFlexV - before->flexV_;
this->parent->layout();
@@ -1134,8 +1197,8 @@ void SplitContainer::ResizeHandle::mouseMoveEvent(QMouseEvent *event)
this->move(this->x(), int(before->geometry_.bottom() - 4));
} else {
qreal totalFlexH = this->node->flexH_ + before->flexH_;
before->flexH_ =
totalFlexH * (mousePoint.x() - topLeft.x()) / (bottomRight.x() - topLeft.x());
before->flexH_ = totalFlexH * (mousePoint.x() - topLeft.x()) /
(bottomRight.x() - topLeft.x());
this->node->flexH_ = totalFlexH - before->flexH_;
this->parent->layout();
+6 -4
View File
@@ -23,8 +23,8 @@ class QJsonObject;
namespace chatterino {
//
// Note: This class is a spaghetti container. There is a lot of spaghetti code inside but it doesn't
// expose any of it publicly.
// Note: This class is a spaghetti container. There is a lot of spaghetti code
// inside but it doesn't expose any of it publicly.
//
class SplitContainer : public BaseWidget, pajlada::Signals::SignalHolder
@@ -103,7 +103,8 @@ public:
qreal getFlex(bool isVertical);
qreal getSize(bool isVertical);
qreal getChildrensTotalFlex(bool isVertical);
void layout(bool addSpacing, float _scale, std::vector<DropRect> &dropRects_,
void layout(bool addSpacing, float _scale,
std::vector<DropRect> &dropRects_,
std::vector<ResizeRect> &resizeRects);
static Type toContainerType(Direction _dir);
@@ -171,7 +172,8 @@ public:
void appendSplit(Split *split);
void insertSplit(Split *split, const Position &position);
void insertSplit(Split *split, Direction direction, Split *relativeTo);
void insertSplit(Split *split, Direction direction, Node *relativeTo = nullptr);
void insertSplit(Split *split, Direction direction,
Node *relativeTo = nullptr);
Position releaseSplit(Split *split);
Position deleteSplit(Split *split);
+117 -88
View File
@@ -39,48 +39,58 @@ SplitHeader::SplitHeader(Split *_split)
{
// channel name label
auto title = layout.emplace<Label>().assign(&this->titleLabel);
title->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
title->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::Preferred);
title->setCentered(true);
title->setHasOffset(false);
// mode button
auto mode = layout.emplace<RippleEffectLabel>(nullptr).assign(&this->modeButton_);
auto mode = layout.emplace<RippleEffectLabel>(nullptr).assign(
&this->modeButton_);
mode->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
mode->hide();
this->setupModeLabel(*mode);
QObject::connect(mode.getElement(), &RippleEffectLabel::clicked, this, [this] {
QTimer::singleShot(80, this, [&, this] {
ChannelPtr _channel = this->split_->getChannel();
if (_channel->hasModRights()) {
this->modeMenu_.popup(QCursor::pos());
}
QObject::connect(
mode.getElement(), &RippleEffectLabel::clicked, this, [this] {
QTimer::singleShot(80, this, [&, this] {
ChannelPtr _channel = this->split_->getChannel();
if (_channel->hasModRights()) {
this->modeMenu_.popup(QCursor::pos());
}
});
});
});
// moderation mode
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton_);
auto moderator = layout.emplace<RippleEffectButton>(this).assign(
&this->moderationButton_);
QObject::connect(moderator.getElement(), &RippleEffectButton::clicked, this,
[this, moderator]() mutable {
this->split_->setModerationMode(!this->split_->getModerationMode());
QObject::connect(
moderator.getElement(), &RippleEffectButton::clicked, this,
[this, moderator]() mutable {
this->split_->setModerationMode(
!this->split_->getModerationMode());
moderator->setDim(!this->split_->getModerationMode());
});
moderator->setDim(!this->split_->getModerationMode());
});
this->updateModerationModeIcon();
// dropdown label
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton_);
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(
&this->dropdownButton_);
dropdown->setMouseTracking(true);
// dropdown->setPixmap(*app->resources->splitHeaderContext->getPixmap());
// dropdown->setScaleIndependantSize(23, 23);
this->addDropdownItems(dropdown.getElement());
QObject::connect(dropdown.getElement(), &RippleEffectButton::leftMousePress, this, [this] {
QTimer::singleShot(80, [&, this] { this->dropdownMenu_.popup(QCursor::pos()); });
});
QObject::connect(dropdown.getElement(),
&RippleEffectButton::leftMousePress, this, [this] {
QTimer::singleShot(80, [&, this] {
this->dropdownMenu_.popup(QCursor::pos());
});
});
}
// ---- misc
@@ -166,53 +176,57 @@ void SplitHeader::updateRoomModes()
void SplitHeader::setupModeLabel(RippleEffectLabel &label)
{
this->managedConnections_.push_back(this->modeUpdateRequested_.connect([this, &label] {
auto twitchChannel = dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
this->managedConnections_.push_back(
this->modeUpdateRequested_.connect([this, &label] {
auto twitchChannel =
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
// return if the channel is not a twitch channel
if (twitchChannel == nullptr) {
label.hide();
return;
}
// set lable enabled
label.setEnable(twitchChannel->hasModRights());
// set the label text
QString text;
{
auto roomModes = twitchChannel->accessRoomModes();
if (roomModes->r9k) text += "r9k, ";
if (roomModes->slowMode)
text += QString("slow(%1), ").arg(QString::number(roomModes->slowMode));
if (roomModes->emoteOnly) text += "emote, ";
if (roomModes->submode) text += "sub, ";
}
if (text.length() > 2) {
text = text.mid(0, text.size() - 2);
}
if (text.isEmpty()) {
if (twitchChannel->hasModRights()) {
label.getLabel().setText("none");
label.show();
} else {
// return if the channel is not a twitch channel
if (twitchChannel == nullptr) {
label.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));
return;
}
label.getLabel().setText(text);
label.show();
}
}));
// set lable enabled
label.setEnable(twitchChannel->hasModRights());
// set the label text
QString text;
{
auto roomModes = twitchChannel->accessRoomModes();
if (roomModes->r9k) text += "r9k, ";
if (roomModes->slowMode)
text += QString("slow(%1), ")
.arg(QString::number(roomModes->slowMode));
if (roomModes->emoteOnly) text += "emote, ";
if (roomModes->submode) text += "sub, ";
}
if (text.length() > 2) {
text = text.mid(0, text.size() - 2);
}
if (text.isEmpty()) {
if (twitchChannel->hasModRights()) {
label.getLabel().setText("none");
label.show();
} else {
label.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));
}
label.getLabel().setText(text);
label.show();
}
}));
}
void SplitHeader::addModeActions(QMenu &menu)
@@ -234,7 +248,8 @@ void SplitHeader::addModeActions(QMenu &menu)
this->managedConnections_.push_back(this->modeUpdateRequested_.connect( //
[this, setSub, setEmote, setSlow, setR9k]() {
auto twitchChannel = dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
auto twitchChannel =
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
if (twitchChannel == nullptr) {
this->modeButton_->hide();
return;
@@ -260,11 +275,13 @@ void SplitHeader::addModeActions(QMenu &menu)
this->split_->getChannel().get()->sendMessage(command);
};
QObject::connect(setSub, &QAction::triggered, this,
[setSub, toggle]() mutable { toggle("/subscribers", setSub); });
QObject::connect(
setSub, &QAction::triggered, this,
[setSub, toggle]() mutable { toggle("/subscribers", setSub); });
QObject::connect(setEmote, &QAction::triggered, this,
[setEmote, toggle]() mutable { toggle("/emoteonly", setEmote); });
QObject::connect(
setEmote, &QAction::triggered, this,
[setEmote, toggle]() mutable { toggle("/emoteonly", setEmote); });
QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() {
if (!setSlow->isChecked()) {
@@ -273,17 +290,19 @@ void SplitHeader::addModeActions(QMenu &menu)
return;
};
bool ok;
int slowSec =
QInputDialog::getInt(this, "", "Seconds:", 10, 0, 500, 1, &ok, Qt::FramelessWindowHint);
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));
this->split_->getChannel().get()->sendMessage(
QString("/slow %1").arg(slowSec));
} else {
setSlow->setChecked(false);
}
});
QObject::connect(setR9k, &QAction::triggered, this,
[setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });
QObject::connect(
setR9k, &QAction::triggered, this,
[setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });
}
void SplitHeader::initializeChannelSignals()
@@ -295,9 +314,10 @@ void SplitHeader::initializeChannelSignals()
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel) {
this->managedConnections_.emplace_back(twitchChannel->liveStatusChanged.connect([this]() {
this->updateChannelText(); //
}));
this->managedConnections_.emplace_back(
twitchChannel->liveStatusChanged.connect([this]() {
this->updateChannelText(); //
}));
}
}
@@ -332,9 +352,10 @@ void SplitHeader::updateChannelText()
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 " +
streamStatus->title + "<br><br>" +
streamStatus->game + "<br>" +
(streamStatus->rerun ? "Vod-casting" : "Live") +
" for " + streamStatus->uptime + " with " +
QString::number(streamStatus->viewerCount) +
" viewers"
"</p>";
@@ -346,7 +367,8 @@ void SplitHeader::updateChannelText()
title += " (live)";
}
if (getSettings()->showViewerCount) {
title += " - " + QString::number(streamStatus->viewerCount) + " viewers";
title += " - " + QString::number(streamStatus->viewerCount) +
" viewers";
}
if (getSettings()->showTitle) {
title += " - " + streamStatus->title;
@@ -374,9 +396,10 @@ void SplitHeader::updateModerationModeIcon()
{
auto app = getApp();
this->moderationButton_->setPixmap(this->split_->getModerationMode()
? app->resources->buttons.modModeEnabled
: app->resources->buttons.modModeDisabled);
this->moderationButton_->setPixmap(
this->split_->getModerationMode()
? app->resources->buttons.modModeEnabled
: app->resources->buttons.modModeDisabled);
bool modButtonVisible = false;
ChannelPtr channel = this->split_->getChannel();
@@ -427,7 +450,8 @@ void SplitHeader::mouseReleaseEvent(QMouseEvent *event)
TooltipWidget *widget = new TooltipWidget();
widget->setText("Double click or press <Ctrl+R> to change the channel.\nClick and "
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);
@@ -448,8 +472,10 @@ void SplitHeader::mouseReleaseEvent(QMouseEvent *event)
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())) {
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;
}
@@ -468,7 +494,8 @@ void SplitHeader::enterEvent(QEvent *event)
{
if (!this->tooltip_.isEmpty()) {
auto tooltipWidget = TooltipWidget::getInstance();
tooltipWidget->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()), false);
tooltipWidget->moveTo(
this, this->mapToGlobal(this->rect().bottomLeft()), false);
tooltipWidget->setText(this->tooltip_);
tooltipWidget->show();
tooltipWidget->raise();
@@ -493,7 +520,8 @@ void SplitHeader::themeChangedEvent()
QPalette palette;
if (this->split_->hasFocus()) {
palette.setColor(QPalette::Foreground, this->theme->splits.header.focusedText);
palette.setColor(QPalette::Foreground,
this->theme->splits.header.focusedText);
} else {
palette.setColor(QPalette::Foreground, this->theme->splits.header.text);
}
@@ -501,7 +529,8 @@ void SplitHeader::themeChangedEvent()
if (this->theme->isLightTheme()) {
this->dropdownButton_->setPixmap(getApp()->resources->buttons.menuDark);
} else {
this->dropdownButton_->setPixmap(getApp()->resources->buttons.menuLight);
this->dropdownButton_->setPixmap(
getApp()->resources->buttons.menuLight);
}
this->titleLabel->setPalette(palette);
+63 -39
View File
@@ -22,11 +22,13 @@ SplitInput::SplitInput(Split *_chatWidget)
{
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->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);
});
@@ -41,10 +43,12 @@ void SplitInput::initLayout()
LayoutCreator<SplitInput> layoutCreator(this);
auto layout =
layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(&this->ui_.hbox);
layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(
&this->ui_.hbox);
// 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,
&SplitInput::editTextChanged);
@@ -52,7 +56,8 @@ void SplitInput::initLayout()
auto box = layout.emplace<QVBoxLayout>().withoutMargin();
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);
box->addStretch(1);
@@ -64,39 +69,46 @@ void SplitInput::initLayout()
// ---- misc
// set edit font
this->ui_.textEdit->setFont(app->fonts->getFont(Fonts::Type::ChatMedium, this->getScale()));
this->ui_.textEdit->setFont(
app->fonts->getFont(Fonts::Type::ChatMedium, this->getScale()));
this->managedConnections_.push_back(app->fonts->fontChanged.connect([=]() {
this->ui_.textEdit->setFont(app->fonts->getFont(Fonts::Type::ChatMedium, this->getScale()));
this->ui_.textEdit->setFont(
app->fonts->getFont(Fonts::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 Link &link) {
if (link.type == Link::InsertText) {
this->insertText(link.value + " ");
}
});
}
QObject::connect(
this->ui_.emoteButton, &RippleEffectLabel::clicked, [this] {
if (!this->emotePopup_) {
this->emotePopup_ = std::make_unique<EmotePopup>();
this->emotePopup_->linkClicked.connect(
[this](const Link &link) {
if (link.type == 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();
});
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();
}
});
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](const bool &value, auto) {
this->ui_.textEditLength->setHidden(!value);
},
this->managedConnections_);
}
@@ -107,7 +119,8 @@ void SplitInput::scaleChangedEvent(float scale)
// set maximum height
this->setMaximumHeight(int(150 * this->getScale()));
this->ui_.textEdit->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale()));
this->ui_.textEdit->setFont(
getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale()));
}
void SplitInput::themeChangedEvent()
@@ -121,7 +134,8 @@ void SplitInput::themeChangedEvent()
this->ui_.textEdit->setStyleSheet(this->theme->splits.input.styleSheet);
this->ui_.hbox->setMargin(int((this->theme->isLightTheme() ? 4 : 2) * this->getScale()));
this->ui_.hbox->setMargin(
int((this->theme->isLightTheme() ? 4 : 2) * this->getScale()));
this->ui_.emoteButton->getLabel().setStyleSheet("color: #000");
}
@@ -189,7 +203,8 @@ void SplitInput::installKeyPressedEvent()
}
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();
cursor.movePosition(QTextCursor::End);
@@ -210,7 +225,8 @@ void SplitInput::installKeyPressedEvent()
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
this->prevIndex_ != this->prevMsg_.size()) {
this->prevIndex_++;
this->ui_.textEdit->setText(this->prevMsg_.at(this->prevIndex_));
this->ui_.textEdit->setText(
this->prevMsg_.at(this->prevIndex_));
} else {
this->prevIndex_ = this->prevMsg_.size();
this->ui_.textEdit->setText(this->currMsg_);
@@ -238,21 +254,27 @@ void SplitInput::installKeyPressedEvent()
}
} else if (event->key() == Qt::Key_Tab) {
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());
notebook->selectNextTab();
}
} else if (event->key() == Qt::Key_Backtab) {
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
SplitContainer *page = static_cast<SplitContainer *>(this->split_->parentWidget());
if (event->modifiers() ==
(Qt::ControlModifier | Qt::ShiftModifier)) {
SplitContainer *page =
static_cast<SplitContainer *>(this->split_->parentWidget());
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
Notebook *notebook =
static_cast<Notebook *>(page->parentWidget());
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()) {
this->split_->copyToClipboard();
event->accept();
@@ -303,7 +325,8 @@ void SplitInput::editTextChanged()
static QRegularExpression spaceRegex("\\s\\s+");
text = text.replace(spaceRegex, " ");
text = app->commands->execCommand(text, this->split_->getChannel(), true);
text =
app->commands->execCommand(text, this->split_->getChannel(), true);
}
QString labelText;
@@ -340,7 +363,8 @@ void SplitInput::paintEvent(QPaintEvent *)
}
// int offset = 2;
// painter.fillRect(offset, this->height() - offset, this->width() - 2 * offset, 1,
// painter.fillRect(offset, this->height() - offset, this->width() - 2 *
// offset, 1,
// getApp()->themes->splits.input.focusedLine);
}
+26 -13
View File
@@ -30,10 +30,14 @@ SplitOverlay::SplitOverlay(Split *parent)
layout->setColumnStretch(3, 1);
auto *move = new QPushButton(getApp()->resources->split.move, QString());
auto *left = this->left_ = new QPushButton(getApp()->resources->split.left, QString());
auto *right = this->right_ = new QPushButton(getApp()->resources->split.right, QString());
auto *up = this->up_ = new QPushButton(getApp()->resources->split.up, QString());
auto *down = this->down_ = new QPushButton(getApp()->resources->split.down, QString());
auto *left = this->left_ =
new QPushButton(getApp()->resources->split.left, QString());
auto *right = this->right_ =
new QPushButton(getApp()->resources->split.right, QString());
auto *up = this->up_ =
new QPushButton(getApp()->resources->split.up, QString());
auto *down = this->down_ =
new QPushButton(getApp()->resources->split.down, QString());
move->setGraphicsEffect(new QGraphicsOpacityEffect(this));
left->setGraphicsEffect(new QGraphicsOpacityEffect(this));
@@ -103,7 +107,8 @@ void SplitOverlay::paintEvent(QPaintEvent *)
} break;
case SplitRight: {
rect = QRect(this->width() / 2, 0, this->width() / 2, this->height());
rect =
QRect(this->width() / 2, 0, this->width() / 2, this->height());
} break;
case SplitUp: {
@@ -111,7 +116,8 @@ void SplitOverlay::paintEvent(QPaintEvent *)
} break;
case SplitDown: {
rect = QRect(0, this->height() / 2, this->width(), this->height() / 2);
rect =
QRect(0, this->height() / 2, this->width(), this->height() / 2);
} break;
default:;
@@ -145,24 +151,28 @@ void SplitOverlay::mouseMoveEvent(QMouseEvent *event)
// qDebug() << QGuiApplication::queryKeyboardModifiers();
// if ((QGuiApplication::queryKeyboardModifiers() & Qt::AltModifier) == Qt::AltModifier) {
// if ((QGuiApplication::queryKeyboardModifiers() & Qt::AltModifier) ==
// Qt::AltModifier) {
// this->hide();
// }
}
SplitOverlay::ButtonEventFilter::ButtonEventFilter(SplitOverlay *_parent, HoveredElement _element)
SplitOverlay::ButtonEventFilter::ButtonEventFilter(SplitOverlay *_parent,
HoveredElement _element)
: QObject(_parent)
, parent(_parent)
, hoveredElement(_element)
{
}
bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched, QEvent *event)
bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched,
QEvent *event)
{
switch (event->type()) {
case QEvent::Enter: {
QGraphicsOpacityEffect *effect =
dynamic_cast<QGraphicsOpacityEffect *>(((QWidget *)watched)->graphicsEffect());
dynamic_cast<QGraphicsOpacityEffect *>(
((QWidget *)watched)->graphicsEffect());
if (effect != nullptr) {
effect->setOpacity(0.99);
@@ -173,7 +183,8 @@ bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched, QEvent *even
} break;
case QEvent::Leave: {
QGraphicsOpacityEffect *effect =
dynamic_cast<QGraphicsOpacityEffect *>(((QWidget *)watched)->graphicsEffect());
dynamic_cast<QGraphicsOpacityEffect *>(
((QWidget *)watched)->graphicsEffect());
if (effect != nullptr) {
effect->setOpacity(0.7);
@@ -193,12 +204,14 @@ bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched, QEvent *even
} break;
case QEvent::MouseButtonRelease: {
if (this->hoveredElement != HoveredElement::SplitMove) {
SplitContainer *container = this->parent->split_->getContainer();
SplitContainer *container =
this->parent->split_->getContainer();
if (container != nullptr) {
auto *_split = new Split(container);
auto dir = SplitContainer::Direction(this->hoveredElement +
SplitContainer::Left - SplitLeft);
SplitContainer::Left -
SplitLeft);
container->insertSplit(_split, dir, this->parent->split_);
this->parent->hide();
}
+8 -1
View File
@@ -23,7 +23,14 @@ protected:
private:
// fourtf: !!! preserve the order of left, up, right and down
enum HoveredElement { None, SplitMove, SplitLeft, SplitUp, SplitRight, SplitDown };
enum HoveredElement {
None,
SplitMove,
SplitLeft,
SplitUp,
SplitRight,
SplitDown
};
class ButtonEventFilter : public QObject
{