From 85505a055daef331a354ab61dbace92273243f0a Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 31 May 2018 16:02:20 +0200 Subject: [PATCH] fixed scrollbar size and split focus --- src/application.cpp | 2 +- src/providers/twitch/twitchchannel.cpp | 12 ++++--- src/widgets/helper/channelview.cpp | 2 +- src/widgets/notebook.cpp | 50 +++++++++++++++++++++++--- src/widgets/notebook.hpp | 6 ++++ src/widgets/split.cpp | 17 +++++---- src/widgets/split.hpp | 3 +- src/widgets/splitcontainer.cpp | 12 +++++++ src/widgets/splitcontainer.hpp | 1 + 9 files changed, 87 insertions(+), 18 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 90b95741e..07178d52c 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -93,6 +93,7 @@ void Application::initialize() this->settings->load(); this->commands->load(); + this->logging->initialize(); this->windows->initialize(); this->resources->initialize(); @@ -105,7 +106,6 @@ void Application::initialize() this->accounts->load(); this->twitch.server->initialize(); - this->logging->initialize(); // XXX this->settings->updateWordTypeMask(); diff --git a/src/providers/twitch/twitchchannel.cpp b/src/providers/twitch/twitchchannel.cpp index 1fb4d1c2a..369945b44 100644 --- a/src/providers/twitch/twitchchannel.cpp +++ b/src/providers/twitch/twitchchannel.cpp @@ -228,8 +228,10 @@ void TwitchChannel::addJoinedUser(const QString &user) QTimer::singleShot(500, &this->object, [this] { std::lock_guard guard(this->joinedUserMutex); - this->addMessage(messages::Message::createSystemMessage("Users joined: " + - this->joinedUsers.join(", "))); + auto message = messages::Message::createSystemMessage("Users joined: " + + this->joinedUsers.join(", ")); + message->flags |= messages::Message::Collapsed; + this->addMessage(message); this->joinedUsers.clear(); this->joinedUsersMergeQueued = false; }); @@ -255,8 +257,10 @@ void TwitchChannel::addPartedUser(const QString &user) QTimer::singleShot(500, &this->object, [this] { std::lock_guard guard(this->partedUserMutex); - this->addMessage(messages::Message::createSystemMessage("Users parted: " + - this->partedUsers.join(", "))); + auto message = messages::Message::createSystemMessage("Users parted: " + + this->partedUsers.join(", ")); + message->flags |= messages::Message::Collapsed; + this->addMessage(message); this->partedUsers.clear(); this->partedUsersMergeQueued = false; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index cf1d68c9e..6b461e65a 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -123,7 +123,7 @@ ChannelView::ChannelView(BaseWidget *parent) } }); - QTimer::singleShot(1, this, [this] { + QTimer::singleShot(1000, this, [this] { this->scrollBar.setGeometry(this->width() - this->scrollBar.width(), 0, this->scrollBar.width(), this->height()); }); diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 818a885a1..a099c0c20 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -120,20 +120,35 @@ void Notebook::select(QWidget *page) if (page != nullptr) { page->setHidden(false); - NotebookTab *tab = this->getTabFromPage(page); - tab->setSelected(true); - tab->raise(); + assert(this->containsPage(page)); + Item &item = this->findItem(page); + + item.tab->setSelected(true); + item.tab->raise(); + + if (item.selectedWidget == nullptr) { + item.page->setFocus(); + } else { + if (containsChild(page, item.selectedWidget)) { + qDebug() << item.selectedWidget; + item.selectedWidget->setFocus(Qt::MouseFocusReason); + } else { + qDebug() << "Notebook: selected child of page doesn't exist anymore"; + } + } } if (this->selectedPage != nullptr) { this->selectedPage->setHidden(true); - NotebookTab *tab = this->getTabFromPage(selectedPage); - tab->setSelected(false); + Item &item = this->findItem(selectedPage); + item.tab->setSelected(false); // for (auto split : this->selectedPage->getSplits()) { // split->updateLastReadMessage(); // } + + item.selectedWidget = this->selectedPage->focusWidget(); } this->selectedPage = page; @@ -141,6 +156,31 @@ void Notebook::select(QWidget *page) this->performLayout(); } +bool Notebook::containsPage(QWidget *page) +{ + return std::any_of(this->items.begin(), this->items.end(), + [page](const auto &item) { return item.page == page; }); +} + +Notebook::Item &Notebook::findItem(QWidget *page) +{ + auto it = std::find_if(this->items.begin(), this->items.end(), + [page](const auto &item) { return page == item.page; }); + assert(it != this->items.end()); + return *it; +} + +bool Notebook::containsChild(const QObject *obj, const QObject *child) +{ + return std::any_of(obj->children().begin(), obj->children().end(), [child](const QObject *o) { + if (o == child) { + return true; + } + + return containsChild(o, child); + }); +} + void Notebook::selectIndex(int index) { if (index < 0 || this->items.count() <= index) { diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index e578e17a8..e419c3298 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -59,11 +59,17 @@ private: struct Item { NotebookTab *tab; QWidget *page; + QWidget *selectedWidget = nullptr; }; QList items; QWidget *selectedPage = nullptr; + bool containsPage(QWidget *page); + Item &findItem(QWidget *page); + + static bool containsChild(const QObject *obj, const QObject *child); + NotebookButton addButton; std::vector customButtons; diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index 0776d3256..096203a5c 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -279,19 +279,19 @@ void Split::paintEvent(QPaintEvent *) void Split::mouseMoveEvent(QMouseEvent *event) { - this->handleModifiers(event, QGuiApplication::queryKeyboardModifiers()); + this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); } void Split::keyPressEvent(QKeyEvent *event) { this->view.unsetCursor(); - this->handleModifiers(event, QGuiApplication::queryKeyboardModifiers()); + this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); } void Split::keyReleaseEvent(QKeyEvent *event) { this->view.unsetCursor(); - this->handleModifiers(event, QGuiApplication::queryKeyboardModifiers()); + this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); } void Split::resizeEvent(QResizeEvent *event) @@ -305,7 +305,7 @@ void Split::enterEvent(QEvent *event) { this->isMouseOver = true; - this->handleModifiers(event, QGuiApplication::queryKeyboardModifiers()); + this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); if (modifierStatus == Qt::AltModifier || modifierStatus == (Qt::AltModifier | Qt::ControlModifier)) { @@ -319,10 +319,15 @@ void Split::leaveEvent(QEvent *event) this->overlay->hide(); - this->handleModifiers(event, QGuiApplication::queryKeyboardModifiers()); + this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); } -void Split::handleModifiers(QEvent *event, Qt::KeyboardModifiers modifiers) +void Split::focusInEvent(QFocusEvent *event) +{ + this->giveFocus(event->reason()); +} + +void Split::handleModifiers(Qt::KeyboardModifiers modifiers) { if (modifierStatus != modifiers) { modifierStatus = modifiers; diff --git a/src/widgets/split.hpp b/src/widgets/split.hpp index 35b974850..4d7bf2bf6 100644 --- a/src/widgets/split.hpp +++ b/src/widgets/split.hpp @@ -83,6 +83,7 @@ protected: void resizeEvent(QResizeEvent *event) override; void enterEvent(QEvent *event) override; void leaveEvent(QEvent *event) override; + void focusInEvent(QFocusEvent *event) override; private: SplitContainer *container; @@ -109,7 +110,7 @@ private: void doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user); void channelNameUpdated(const QString &newChannelName); - void handleModifiers(QEvent *event, Qt::KeyboardModifiers modifiers); + void handleModifiers(Qt::KeyboardModifiers modifiers); public slots: // Add new split to the notebook page that this chat widget is in diff --git a/src/widgets/splitcontainer.cpp b/src/widgets/splitcontainer.cpp index 580ebae0b..df46b361a 100644 --- a/src/widgets/splitcontainer.cpp +++ b/src/widgets/splitcontainer.cpp @@ -459,6 +459,18 @@ void SplitContainer::leaveEvent(QEvent *) this->update(); } +void SplitContainer::focusInEvent(QFocusEvent *) +{ + if (this->baseNode.findNodeContainingSplit(this->selected) != nullptr) { + this->selected->setFocus(); + return; + } + + if (this->splits.size() != 0) { + this->splits.front()->setFocus(); + } +} + void SplitContainer::refreshTabTitle() { if (this->tab == nullptr) { diff --git a/src/widgets/splitcontainer.hpp b/src/widgets/splitcontainer.hpp index eb7e7a009..d86d83c7e 100644 --- a/src/widgets/splitcontainer.hpp +++ b/src/widgets/splitcontainer.hpp @@ -195,6 +195,7 @@ public: protected: void paintEvent(QPaintEvent *event) override; + void focusInEvent(QFocusEvent *event) override; void leaveEvent(QEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override;