From 4073d6104537ce44c353f2222c32604177e3dbed Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 1 Jul 2018 22:57:14 +0300 Subject: [PATCH] Add shortcuts for chat-only & Room List-only views Ctrl-O -> Chat Ctrl-L -> Room list --- include/Splitter.h | 8 +++++ include/TopRoomBar.h | 5 +++ src/ChatPage.cc | 3 ++ src/Splitter.cc | 73 +++++++++++++++++++++++++++++++++++++++++++- src/TopRoomBar.cc | 24 +++++++++++++++ src/main.cc | 4 +-- 6 files changed, 113 insertions(+), 4 deletions(-) diff --git a/include/Splitter.h b/include/Splitter.h index 38b38e84..d4c34430 100644 --- a/include/Splitter.h +++ b/include/Splitter.h @@ -28,6 +28,14 @@ public: void restoreSizes(int fallback); +public slots: + void showSidebar(); + void hideSidebar(); + void showChatView(); + +signals: + void hiddenSidebar(); + private: void onSplitterMoved(int pos, int index); diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index 73fad9ee..981e3e40 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -54,8 +54,12 @@ public: QColor borderColor() const { return borderColor_; } void setBorderColor(QColor &color) { borderColor_ = color; } +public slots: + void enableBackButton(); + signals: void inviteUsers(QStringList users); + void showSidebar(); protected: void mousePressEvent(QMouseEvent *) override @@ -89,6 +93,7 @@ private: QAction *inviteUsers_ = nullptr; FlatButton *settingsBtn_; + FlatButton *backBtn_; Avatar *avatar_; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index df1ab172..fdd4e910 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -183,6 +183,8 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) emit showOverlayProgressBar(); }); + connect(splitter, &Splitter::hiddenSidebar, top_bar_, &TopRoomBar::enableBackButton); + connect(top_bar_, &TopRoomBar::showSidebar, splitter, &Splitter::showSidebar); connect(top_bar_, &TopRoomBar::inviteUsers, this, [this](QStringList users) { const auto room_id = current_room_.toStdString(); @@ -223,6 +225,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) }); connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::stopTyping); connect(room_list_, &RoomList::roomChanged, this, &ChatPage::changeTopRoomInfo); + connect(room_list_, &RoomList::roomChanged, splitter, &Splitter::showChatView); connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::focusLineEdit); connect( room_list_, &RoomList::roomChanged, view_manager_, &TimelineViewManager::setHistoryView); diff --git a/src/Splitter.cc b/src/Splitter.cc index 0344df92..acf0fd19 100644 --- a/src/Splitter.cc +++ b/src/Splitter.cc @@ -15,8 +15,11 @@ * along with this program. If not, see . */ +#include #include +#include #include +#include #include "Splitter.h" #include "Theme.h" @@ -27,6 +30,28 @@ Splitter::Splitter(QWidget *parent) connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved); setChildrenCollapsible(false); setStyleSheet("QSplitter::handle { image: none; }"); + + auto showChatShortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "Show chat")), parent); + auto showSidebarShortcut = + new QShortcut(QKeySequence(tr("Ctrl+L", "Show sidebar")), parent); + + connect(showChatShortcut, &QShortcut::activated, this, [this]() { + if (count() != 2) + return; + + hideSidebar(); + widget(1)->show(); + }); + connect(showSidebarShortcut, &QShortcut::activated, this, [this]() { + if (count() != 2) + return; + + widget(0)->setMinimumWidth(ui::sidebar::NormalSize); + widget(0)->setMaximumWidth(QApplication::desktop()->screenGeometry().height()); + + widget(0)->show(); + widget(1)->hide(); + }); } void @@ -53,6 +78,11 @@ Splitter::restoreSizes(int fallback) } } + if (savedWidth == 0) { + hideSidebar(); + return; + } + setSizes({ui::sidebar::NormalSize, fallback - ui::sidebar::NormalSize}); } @@ -62,7 +92,11 @@ Splitter::~Splitter() if (left) { QSettings settings; - settings.setValue("sidebar/width", left->width()); + + if (!left->isVisible()) + settings.setValue("sidebar/width", 0); + else + settings.setValue("sidebar/width", left->width()); } } @@ -114,7 +148,44 @@ Splitter::onSplitterMoved(int pos, int index) left->setMaximumWidth(2 * ui::sidebar::NormalSize); leftMoveCount_ = 0; + } else if (left->rect().contains(left->mapFromGlobal(QCursor::pos()))) { + hideSidebar(); } } } } +void +Splitter::showChatView() +{ + if (count() != 2) + return; + + auto right = widget(1); + + // We are in Roomlist-only view so we'll switch into Chat-only view. + if (!right->isVisible()) { + right->show(); + hideSidebar(); + } +} + +void +Splitter::showSidebar() +{ + auto left = widget(0); + if (left) { + left->setMinimumWidth(ui::sidebar::SmallSize); + left->setMaximumWidth(ui::sidebar::SmallSize); + left->show(); + } +} + +void +Splitter::hideSidebar() +{ + auto left = widget(0); + if (left) { + left->hide(); + emit hiddenSidebar(); + } +} diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index ae4c0926..03241717 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -73,7 +73,24 @@ TopRoomBar::TopRoomBar(QWidget *parent) settingsBtn_->setIcon(settings_icon); settingsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2)); + backBtn_ = new FlatButton(this); + backBtn_->setFixedSize(buttonSize_, buttonSize_); + backBtn_->setCornerRadius(buttonSize_ / 2); + + QIcon backIcon; + backIcon.addFile(":/icons/icons/ui/angle-pointing-to-left.png"); + backBtn_->setIcon(backIcon); + backBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2)); + backBtn_->hide(); + + connect(backBtn_, &QPushButton::clicked, this, [this]() { + backBtn_->hide(); + avatar_->show(); + emit showSidebar(); + }); + topLayout_->addWidget(avatar_); + topLayout_->addWidget(backBtn_); topLayout_->addLayout(textLayout_, 1); topLayout_->addWidget(settingsBtn_, 0, Qt::AlignRight); @@ -112,6 +129,13 @@ TopRoomBar::TopRoomBar(QWidget *parent) }); } +void +TopRoomBar::enableBackButton() +{ + avatar_->hide(); + backBtn_->show(); +} + void TopRoomBar::updateRoomAvatarFromName(const QString &name) { diff --git a/src/main.cc b/src/main.cc index bc264931..3ba19b4a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -45,10 +45,8 @@ void stacktraceHandler(int signum) { - auto dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - std::signal(signum, SIG_DFL); - boost::stacktrace::safe_dump_to(dir.toStdString() + "/backtrace.dump"); + boost::stacktrace::safe_dump_to("./nheko-backtrace.dump"); std::raise(SIGABRT); }