summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJani Mustonen <janijohannes@kapsi.fi>2017-11-03 08:54:17 +0200
committermujx <mujx@users.noreply.github.com>2017-11-03 08:54:17 +0200
commit13cb0521fa4fd692f66a89c83ef17b7e3ea339bb (patch)
tree632e0721e88b301e2ed7b45a10e9f48bf18004f6 /src
parentUpdate issue template (diff)
downloadnheko-13cb0521fa4fd692f66a89c83ef17b7e3ea339bb.tar.xz
Improvements to the quick switcher (#109)
- Ghetto disambiguation for the quick switcher
- Fix the Ctrl+K shortcut
- Fix keyboard focus when the quick switcher is closed

fixes #114
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cc9
-rw-r--r--src/MainWindow.cc14
-rw-r--r--src/QuickSwitcher.cc11
-rw-r--r--src/TextInputWidget.cc6
4 files changed, 28 insertions, 12 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index e32b288a..884e219a 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -562,6 +562,7 @@ ChatPage::showQuickSwitcher()
                 connect(quickSwitcher_.data(), &QuickSwitcher::closing, this, [=]() {
                         if (!this->quickSwitcherModal_.isNull())
                                 this->quickSwitcherModal_->fadeOut();
+                        this->text_input_->setFocus(Qt::FocusReason::PopupFocusReason);
                 });
         }
 
@@ -575,8 +576,12 @@ ChatPage::showQuickSwitcher()
 
         QMap<QString, QString> rooms;
 
-        for (auto it = state_manager_.constBegin(); it != state_manager_.constEnd(); ++it)
-                rooms.insert(it.value().getName(), it.key());
+        for (auto it = state_manager_.constBegin(); it != state_manager_.constEnd(); ++it) {
+                QString deambiguator = it.value().canonical_alias.content().alias();
+                if (deambiguator == "")
+                        deambiguator = it.key();
+                rooms.insert(it.value().getName() + " (" + deambiguator + ")", it.key());
+        }
 
         quickSwitcher_->setRoomList(rooms);
         quickSwitcherModal_->fadeIn();
diff --git a/src/MainWindow.cc b/src/MainWindow.cc
index 04576d44..9c81ef85 100644
--- a/src/MainWindow.cc
+++ b/src/MainWindow.cc
@@ -114,6 +114,11 @@ MainWindow::MainWindow(QWidget *parent)
         QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this);
         connect(quitShortcut, &QShortcut::activated, this, QApplication::quit);
 
+        QShortcut *quickSwitchShortcut = new QShortcut(QKeySequence("Ctrl+K"), this);
+        connect(quickSwitchShortcut, &QShortcut::activated, this, [=]() {
+                chat_page_->showQuickSwitcher();
+        });
+
         QSettings settings;
 
         trayIcon_->setVisible(userSettings_->isTrayEnabled());
@@ -128,15 +133,6 @@ MainWindow::MainWindow(QWidget *parent)
 }
 
 void
-MainWindow::keyPressEvent(QKeyEvent *e)
-{
-        if ((e->key() == Qt::Key_K) && (e->modifiers().testFlag(Qt::ControlModifier)))
-                chat_page_->showQuickSwitcher();
-        else
-                QMainWindow::keyPressEvent(e);
-}
-
-void
 MainWindow::restoreWindowSize()
 {
         QSettings settings;
diff --git a/src/QuickSwitcher.cc b/src/QuickSwitcher.cc
index 542eebd9..2be636a4 100644
--- a/src/QuickSwitcher.cc
+++ b/src/QuickSwitcher.cc
@@ -122,7 +122,16 @@ QuickSwitcher::QuickSwitcher(QWidget *parent)
           roomSearch_, &RoomSearchInput::hiding, this, [=]() { completer_->popup()->hide(); });
         connect(roomSearch_, &QLineEdit::returnPressed, this, [=]() {
                 emit closing();
-                emit roomSelected(rooms_[this->roomSearch_->text().trimmed()]);
+
+                QString text("");
+
+                if (selection_ == -1) {
+                        completer_->setCurrentRow(0);
+                        text = completer_->currentCompletion();
+                } else {
+                        text = this->roomSearch_->text().trimmed();
+                }
+                emit roomSelected(rooms_[text]);
 
                 roomSearch_->clear();
         });
diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc
index 7ebef6b1..e68b1c28 100644
--- a/src/TextInputWidget.cc
+++ b/src/TextInputWidget.cc
@@ -259,3 +259,9 @@ TextInputWidget::stopTyping()
 {
         input_->stopTyping();
 }
+
+void
+TextInputWidget::focusInEvent(QFocusEvent *event)
+{
+        input_->setFocus(event->reason());
+}