mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Add shortcuts for chat-only & Room List-only views
Ctrl-O -> Chat Ctrl-L -> Room list
This commit is contained in:
parent
ccc6cd8dab
commit
4073d61045
6 changed files with 113 additions and 4 deletions
|
@ -28,6 +28,14 @@ public:
|
||||||
|
|
||||||
void restoreSizes(int fallback);
|
void restoreSizes(int fallback);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void showSidebar();
|
||||||
|
void hideSidebar();
|
||||||
|
void showChatView();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hiddenSidebar();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onSplitterMoved(int pos, int index);
|
void onSplitterMoved(int pos, int index);
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,12 @@ public:
|
||||||
QColor borderColor() const { return borderColor_; }
|
QColor borderColor() const { return borderColor_; }
|
||||||
void setBorderColor(QColor &color) { borderColor_ = color; }
|
void setBorderColor(QColor &color) { borderColor_ = color; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void enableBackButton();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void inviteUsers(QStringList users);
|
void inviteUsers(QStringList users);
|
||||||
|
void showSidebar();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *) override
|
void mousePressEvent(QMouseEvent *) override
|
||||||
|
@ -89,6 +93,7 @@ private:
|
||||||
QAction *inviteUsers_ = nullptr;
|
QAction *inviteUsers_ = nullptr;
|
||||||
|
|
||||||
FlatButton *settingsBtn_;
|
FlatButton *settingsBtn_;
|
||||||
|
FlatButton *backBtn_;
|
||||||
|
|
||||||
Avatar *avatar_;
|
Avatar *avatar_;
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
emit showOverlayProgressBar();
|
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) {
|
connect(top_bar_, &TopRoomBar::inviteUsers, this, [this](QStringList users) {
|
||||||
const auto room_id = current_room_.toStdString();
|
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, text_input_, &TextInputWidget::stopTyping);
|
||||||
connect(room_list_, &RoomList::roomChanged, this, &ChatPage::changeTopRoomInfo);
|
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, text_input_, &TextInputWidget::focusLineEdit);
|
||||||
connect(
|
connect(
|
||||||
room_list_, &RoomList::roomChanged, view_manager_, &TimelineViewManager::setHistoryView);
|
room_list_, &RoomList::roomChanged, view_manager_, &TimelineViewManager::setHistoryView);
|
||||||
|
|
|
@ -15,8 +15,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QShortcut>
|
||||||
|
|
||||||
#include "Splitter.h"
|
#include "Splitter.h"
|
||||||
#include "Theme.h"
|
#include "Theme.h"
|
||||||
|
@ -27,6 +30,28 @@ Splitter::Splitter(QWidget *parent)
|
||||||
connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved);
|
connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved);
|
||||||
setChildrenCollapsible(false);
|
setChildrenCollapsible(false);
|
||||||
setStyleSheet("QSplitter::handle { image: none; }");
|
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
|
void
|
||||||
|
@ -53,6 +78,11 @@ Splitter::restoreSizes(int fallback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (savedWidth == 0) {
|
||||||
|
hideSidebar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setSizes({ui::sidebar::NormalSize, fallback - ui::sidebar::NormalSize});
|
setSizes({ui::sidebar::NormalSize, fallback - ui::sidebar::NormalSize});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +92,10 @@ Splitter::~Splitter()
|
||||||
|
|
||||||
if (left) {
|
if (left) {
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
if (!left->isVisible())
|
||||||
|
settings.setValue("sidebar/width", 0);
|
||||||
|
else
|
||||||
settings.setValue("sidebar/width", left->width());
|
settings.setValue("sidebar/width", left->width());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +148,44 @@ Splitter::onSplitterMoved(int pos, int index)
|
||||||
left->setMaximumWidth(2 * ui::sidebar::NormalSize);
|
left->setMaximumWidth(2 * ui::sidebar::NormalSize);
|
||||||
|
|
||||||
leftMoveCount_ = 0;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -73,7 +73,24 @@ TopRoomBar::TopRoomBar(QWidget *parent)
|
||||||
settingsBtn_->setIcon(settings_icon);
|
settingsBtn_->setIcon(settings_icon);
|
||||||
settingsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
|
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(avatar_);
|
||||||
|
topLayout_->addWidget(backBtn_);
|
||||||
topLayout_->addLayout(textLayout_, 1);
|
topLayout_->addLayout(textLayout_, 1);
|
||||||
topLayout_->addWidget(settingsBtn_, 0, Qt::AlignRight);
|
topLayout_->addWidget(settingsBtn_, 0, Qt::AlignRight);
|
||||||
|
|
||||||
|
@ -112,6 +129,13 @@ TopRoomBar::TopRoomBar(QWidget *parent)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TopRoomBar::enableBackButton()
|
||||||
|
{
|
||||||
|
avatar_->hide();
|
||||||
|
backBtn_->show();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TopRoomBar::updateRoomAvatarFromName(const QString &name)
|
TopRoomBar::updateRoomAvatarFromName(const QString &name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,10 +45,8 @@
|
||||||
void
|
void
|
||||||
stacktraceHandler(int signum)
|
stacktraceHandler(int signum)
|
||||||
{
|
{
|
||||||
auto dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
|
||||||
|
|
||||||
std::signal(signum, SIG_DFL);
|
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);
|
std::raise(SIGABRT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue