summary refs log tree commit diff
path: root/src/Splitter.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-01 22:57:14 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-01 22:57:14 +0300
commit4073d6104537ce44c353f2222c32604177e3dbed (patch)
treef7e6fbdd000638ac9209752bb70b496173c760d2 /src/Splitter.cc
parentMark encrypted messages with a lock icon (diff)
downloadnheko-4073d6104537ce44c353f2222c32604177e3dbed.tar.xz
Add shortcuts for chat-only & Room List-only views
Ctrl-O -> Chat
Ctrl-L -> Room list
Diffstat (limited to 'src/Splitter.cc')
-rw-r--r--src/Splitter.cc73
1 files changed, 72 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>. */ +#include <QApplication> #include <QDebug> +#include <QDesktopWidget> #include <QSettings> +#include <QShortcut> #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(); + } +}