summary refs log tree commit diff
path: root/src/ChatPage.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-15 21:06:27 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-15 21:06:27 +0300
commit8d81489e053c28173ca864064774bd07e2758a1d (patch)
treeca166acddaea998f70b22d8dbe3fa27ebb8115ed /src/ChatPage.cc
parentFocus on the text input when switching rooms (diff)
downloadnheko-8d81489e053c28173ca864064774bd07e2758a1d.tar.xz
Ghetto room switcher
Diffstat (limited to 'src/ChatPage.cc')
-rw-r--r--src/ChatPage.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 43b1f0d3..55933d25 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -32,6 +32,7 @@
 #include "CreateEventContent.h"
 #include "HistoryVisibilityEventContent.h"
 #include "JoinRulesEventContent.h"
+#include "MainWindow.h"
 #include "MemberEventContent.h"
 #include "NameEventContent.h"
 #include "PowerLevelsEventContent.h"
@@ -563,6 +564,41 @@ void ChatPage::loadStateFromCache()
 	sync_timer_->start(sync_interval_);
 }
 
+void ChatPage::keyPressEvent(QKeyEvent *event)
+{
+	if (event->key() == Qt::Key_K) {
+		if (event->modifiers() == Qt::ControlModifier)
+			showQuickSwitcher();
+	}
+}
+
+void ChatPage::showQuickSwitcher()
+{
+	if (quickSwitcher_ == nullptr) {
+		quickSwitcher_ = new QuickSwitcher(this);
+
+		connect(quickSwitcher_, &QuickSwitcher::roomSelected, room_list_, &RoomList::highlightSelectedRoom);
+		connect(quickSwitcher_, &QuickSwitcher::closing, this, [=]() {
+			if (this->quickSwitcherModal_ != nullptr)
+				this->quickSwitcherModal_->fadeOut();
+		});
+	}
+
+	if (quickSwitcherModal_ == nullptr) {
+		quickSwitcherModal_ = new OverlayModal(MainWindow::instance(), quickSwitcher_);
+		quickSwitcherModal_->setDuration(0);
+		quickSwitcherModal_->setColor(QColor(30, 30, 30, 170));
+	}
+
+	QMap<QString, QString> rooms;
+
+	for (auto it = state_manager_.constBegin(); it != state_manager_.constEnd(); ++it)
+		rooms.insert(it.value().getName(), it.key());
+
+	quickSwitcher_->setRoomList(rooms);
+	quickSwitcherModal_->fadeIn();
+}
+
 ChatPage::~ChatPage()
 {
 	sync_timer_->stop();