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
+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();