added alt+arrowkeys back

This commit is contained in:
fourtf 2018-05-25 14:57:17 +02:00
parent abd46d0bb8
commit 50a2454cc6
8 changed files with 154 additions and 56 deletions

View file

@ -137,10 +137,19 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
} }
} }
void ResizingTextEdit::focusInEvent(QFocusEvent *event)
{
QTextEdit::focusInEvent(event);
if (event->gotFocus()) {
this->focused.invoke();
}
}
void ResizingTextEdit::setCompleter(QCompleter *c) void ResizingTextEdit::setCompleter(QCompleter *c)
{ {
if (this->completer) { if (this->completer) {
QObject::disconnect(this->completer, 0, this, 0); QObject::disconnect(this->completer, nullptr, this, nullptr);
} }
this->completer = c; this->completer = c;

View file

@ -15,6 +15,7 @@ public:
bool hasHeightForWidth() const override; bool hasHeightForWidth() const override;
pajlada::Signals::Signal<QKeyEvent *> keyPressed; pajlada::Signals::Signal<QKeyEvent *> keyPressed;
pajlada::Signals::NoArgSignal focused;
void setCompleter(QCompleter *c); void setCompleter(QCompleter *c);
QCompleter *getCompleter() const; QCompleter *getCompleter() const;
@ -23,6 +24,8 @@ protected:
int heightForWidth(int) const override; int heightForWidth(int) const override;
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
private: private:
QCompleter *completer = nullptr; QCompleter *completer = nullptr;
bool completionInProgress = false; bool completionInProgress = false;

View file

@ -165,16 +165,11 @@ void SplitInput::installKeyPressedEvent()
return; return;
} }
if (event->modifiers() == Qt::AltModifier) { if (event->modifiers() == Qt::AltModifier) {
// SplitContainer *page = SplitContainer *page = this->split->getContainer();
// static_cast<SplitContainer *>(this->chatWidget->parentWidget());
// page->requestFocus(); if (page != nullptr) {
// int reqX = page->currentX; page->selectNextSplit(SplitContainer::Above);
// int reqY = page->lastRequestedY[reqX] - 1; }
// qDebug() << "Alt+Down to" << reqX << "/" << reqY;
// page->requestFocus(reqX, reqY);
} else { } else {
if (this->prevMsg.size() && this->prevIndex) { if (this->prevMsg.size() && this->prevIndex) {
if (this->prevIndex == (this->prevMsg.size())) { if (this->prevIndex == (this->prevMsg.size())) {
@ -194,15 +189,11 @@ void SplitInput::installKeyPressedEvent()
return; return;
} }
if (event->modifiers() == Qt::AltModifier) { if (event->modifiers() == Qt::AltModifier) {
// SplitContainer *page = SplitContainer *page = this->split->getContainer();
// static_cast<SplitContainer *>(this->chatWidget->parentWidget());
// int reqX = page->currentX; if (page != nullptr) {
// int reqY = page->lastRequestedY[reqX] + 1; page->selectNextSplit(SplitContainer::Below);
}
// qDebug() << "Alt+Down to" << reqX << "/" << reqY;
// page->requestFocus(reqX, reqY);
} else { } else {
if (this->prevIndex != (this->prevMsg.size() - 1) && if (this->prevIndex != (this->prevMsg.size() - 1) &&
this->prevIndex != this->prevMsg.size()) { this->prevIndex != this->prevMsg.size()) {
@ -219,27 +210,19 @@ void SplitInput::installKeyPressedEvent()
} }
} else if (event->key() == Qt::Key_Left) { } else if (event->key() == Qt::Key_Left) {
if (event->modifiers() == Qt::AltModifier) { if (event->modifiers() == Qt::AltModifier) {
// SplitContainer *page = SplitContainer *page = this->split->getContainer();
// static_cast<SplitContainer *>(this->chatWidget->parentWidget());
// int reqX = page->currentX - 1; if (page != nullptr) {
// int reqY = page->lastRequestedY[reqX]; page->selectNextSplit(SplitContainer::Left);
}
// qDebug() << "Alt+Left to" << reqX << "/" << reqY;
// page->requestFocus(reqX, reqY);
} }
} else if (event->key() == Qt::Key_Right) { } else if (event->key() == Qt::Key_Right) {
if (event->modifiers() == Qt::AltModifier) { if (event->modifiers() == Qt::AltModifier) {
// SplitContainer *page = SplitContainer *page = this->split->getContainer();
// static_cast<SplitContainer *>(this->chatWidget->parentWidget());
// int reqX = page->currentX + 1; if (page != nullptr) {
// int reqY = page->lastRequestedY[reqX]; page->selectNextSplit(SplitContainer::Right);
}
// qDebug() << "Alt+Right to" << reqX << "/" << reqY;
// page->requestFocus(reqX, reqY);
} }
} else if (event->key() == Qt::Key_Tab) { } else if (event->key() == Qt::Key_Tab) {
if (event->modifiers() == Qt::ControlModifier) { if (event->modifiers() == Qt::ControlModifier) {

View file

@ -52,12 +52,6 @@ private:
} ui; } ui;
std::vector<pajlada::Signals::ScopedConnection> managedConnections; std::vector<pajlada::Signals::ScopedConnection> managedConnections;
// QHBoxLayout hbox;
// QVBoxLayout vbox;
// QHBoxLayout editContainer;
// ResizingTextEdit textInput;
// QLabel textLengthLabel;
// RippleEffectLabel emotesLabel;
QStringList prevMsg; QStringList prevMsg;
QString currMsg; QString currMsg;
int prevIndex = 0; int prevIndex = 0;

View file

@ -136,6 +136,8 @@ Split::Split(QWidget *parent)
this->overlay->hide(); this->overlay->hide();
} }
}); });
this->input.ui.textEdit->focused.connect([this] { this->focused.invoke(); });
} }
Split::~Split() Split::~Split()

View file

@ -46,6 +46,7 @@ public:
~Split() override; ~Split() override;
pajlada::Signals::NoArgSignal channelChanged; pajlada::Signals::NoArgSignal channelChanged;
pajlada::Signals::NoArgSignal focused;
ChannelView &getChannelView(); ChannelView &getChannelView();
SplitContainer *getContainer(); SplitContainer *getContainer();

View file

@ -3,6 +3,7 @@
#include "common.hpp" #include "common.hpp"
#include "singletons/thememanager.hpp" #include "singletons/thememanager.hpp"
#include "singletons/windowmanager.hpp" #include "singletons/windowmanager.hpp"
#include "util/assertinguithread.hpp"
#include "util/helpers.hpp" #include "util/helpers.hpp"
#include "util/layoutcreator.hpp" #include "util/layoutcreator.hpp"
#include "widgets/helper/notebooktab.hpp" #include "widgets/helper/notebooktab.hpp"
@ -83,6 +84,8 @@ void SplitContainer::setTab(NotebookTab *_tab)
void SplitContainer::appendNewSplit(bool openChannelNameDialog) void SplitContainer::appendNewSplit(bool openChannelNameDialog)
{ {
util::assertInGuiThread();
Split *split = new Split(this); Split *split = new Split(this);
this->appendSplit(split); this->appendSplit(split);
@ -115,6 +118,8 @@ void SplitContainer::insertSplit(Split *split, Direction direction, Split *relat
void SplitContainer::insertSplit(Split *split, Direction direction, Node *relativeTo) void SplitContainer::insertSplit(Split *split, Direction direction, Node *relativeTo)
{ {
util::assertInGuiThread();
split->setContainer(this); split->setContainer(this);
if (relativeTo == nullptr) { if (relativeTo == nullptr) {
@ -136,6 +141,8 @@ void SplitContainer::insertSplit(Split *split, Direction direction, Node *relati
void SplitContainer::addSplit(Split *split) void SplitContainer::addSplit(Split *split)
{ {
util::assertInGuiThread();
split->setParent(this); split->setParent(this);
split->show(); split->show();
split->giveFocus(Qt::MouseFocusReason); split->giveFocus(Qt::MouseFocusReason);
@ -148,12 +155,33 @@ void SplitContainer::addSplit(Split *split)
this->tab->setHighlightState(state); this->tab->setHighlightState(state);
} }
}); });
split->focused.connect([this, split] { this->setSelected(split); });
this->layout(); this->layout();
} }
void SplitContainer::setSelected(Split *split)
{
this->selected = split;
if (Node *node = this->baseNode.findNodeContainingSplit(split)) {
this->setPreferedTargetRecursive(node);
}
}
void SplitContainer::setPreferedTargetRecursive(Node *node)
{
if (node->parent != nullptr) {
node->parent->preferedFocusTarget = node;
this->setPreferedTargetRecursive(node->parent);
}
}
SplitContainer::Position SplitContainer::releaseSplit(Split *split) SplitContainer::Position SplitContainer::releaseSplit(Split *split)
{ {
util::assertInGuiThread();
Node *node = this->baseNode.findNodeContainingSplit(split); Node *node = this->baseNode.findNodeContainingSplit(split);
assert(node != nullptr); assert(node != nullptr);
@ -161,7 +189,9 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split)
split->setParent(nullptr); split->setParent(nullptr);
Position position = node->releaseSplit(); Position position = node->releaseSplit();
this->layout(); this->layout();
if (splits.size() != 0) { if (splits.size() == 0) {
this->setSelected(nullptr);
} else {
this->splits.front()->giveFocus(Qt::MouseFocusReason); this->splits.front()->giveFocus(Qt::MouseFocusReason);
} }
@ -174,12 +204,77 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split)
SplitContainer::Position SplitContainer::deleteSplit(Split *split) SplitContainer::Position SplitContainer::deleteSplit(Split *split)
{ {
util::assertInGuiThread();
assert(split != nullptr); assert(split != nullptr);
split->deleteLater(); split->deleteLater();
return releaseSplit(split); return releaseSplit(split);
} }
void SplitContainer::selectNextSplit(Direction direction)
{
util::assertInGuiThread();
if (Node *node = this->baseNode.findNodeContainingSplit(this->selected)) {
this->selectSplitRecursive(node, direction);
}
}
void SplitContainer::selectSplitRecursive(Node *node, Direction direction)
{
if (node->parent != nullptr) {
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; });
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);
}
} else {
if (it->get() == siblings.back().get()) {
this->selectSplitRecursive(node->parent, direction);
} else {
this->focusSplitRecursive(siblings[it - siblings.begin() + 1].get(), direction);
}
}
} else {
this->selectSplitRecursive(node->parent, direction);
}
}
}
void SplitContainer::focusSplitRecursive(Node *node, Direction direction)
{
switch (node->type) {
case Node::_Split: {
node->split->giveFocus(Qt::OtherFocusReason);
} break;
case Node::HorizontalContainer:
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();
});
if (it != children.end()) {
this->focusSplitRecursive(it->get(), direction);
} else {
this->focusSplitRecursive(node->children.front().get(), direction);
}
} break;
default:;
}
}
void SplitContainer::layout() void SplitContainer::layout()
{ {
this->baseNode.geometry = this->rect(); this->baseNode.geometry = this->rect();
@ -383,6 +478,21 @@ void SplitContainer::refreshTabTitle()
this->tab->setTitle(newTitle); this->tab->setTitle(newTitle);
} }
int SplitContainer::getSplitCount()
{
return 0;
}
const std::vector<Split *> SplitContainer::getSplits() const
{
return this->splits;
}
SplitContainer::Node *SplitContainer::getBaseNode()
{
return &this->baseNode;
}
void SplitContainer::decodeFromJson(QJsonObject &obj) void SplitContainer::decodeFromJson(QJsonObject &obj)
{ {
assert(this->baseNode.type == Node::EmptyRoot); assert(this->baseNode.type == Node::EmptyRoot);

View file

@ -94,6 +94,7 @@ public:
private: private:
Type type; Type type;
Split *split; Split *split;
Node *preferedFocusTarget;
Node *parent; Node *parent;
QRectF geometry; QRectF geometry;
qreal flexH = 1; qreal flexH = 1;
@ -175,25 +176,15 @@ public:
Position releaseSplit(Split *split); Position releaseSplit(Split *split);
Position deleteSplit(Split *split); Position deleteSplit(Split *split);
void selectNextSplit(Direction direction);
void decodeFromJson(QJsonObject &obj); void decodeFromJson(QJsonObject &obj);
int getSplitCount() int getSplitCount();
{ const std::vector<Split *> getSplits() const;
return 0;
}
const std::vector<Split *> getSplits() const
{
return this->splits;
}
void refreshTabTitle(); void refreshTabTitle();
NotebookTab *getTab() const; NotebookTab *getTab() const;
Node *getBaseNode() Node *getBaseNode();
{
return &this->baseNode;
}
void setTab(NotebookTab *tab); void setTab(NotebookTab *tab);
@ -235,6 +226,11 @@ private:
void layout(); void layout();
Node baseNode; Node baseNode;
Split *selected;
void setSelected(Split *selected);
void selectSplitRecursive(Node *node, Direction direction);
void focusSplitRecursive(Node *node, Direction direction);
void setPreferedTargetRecursive(Node *node);
NotebookTab *tab; NotebookTab *tab;
std::vector<Split *> splits; std::vector<Split *> splits;