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> 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> 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 <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();
+ }
+}
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);
@@ -113,6 +130,13 @@ TopRoomBar::TopRoomBar(QWidget *parent)
}
void
+TopRoomBar::enableBackButton()
+{
+ avatar_->hide();
+ backBtn_->show();
+}
+
+void
TopRoomBar::updateRoomAvatarFromName(const QString &name)
{
avatar_->setLetter(utils::firstChar(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);
}
|