From efe1292ee3dffb7fe2f8cee2c4c2767cd53efb34 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Thu, 21 Jun 2018 20:46:54 -0500 Subject: [PATCH] client: Set Channel List input focus, sort A-Z Set Channel List input focus to reasonable defaults. When advanced channel search is visible, focus it. Otherwise, focus the channel list filter box. Sort channel list by name in ascending order by default. Sort order can be changed afterwards as before. --- src/qtui/channellistdlg.cpp | 19 +++++++++++++++++++ src/qtui/channellistdlg.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/src/qtui/channellistdlg.cpp b/src/qtui/channellistdlg.cpp index f8b70284..d6dde67d 100644 --- a/src/qtui/channellistdlg.cpp +++ b/src/qtui/channellistdlg.cpp @@ -49,6 +49,8 @@ ChannelListDlg::ChannelListDlg(QWidget *parent) ui.channelListView->setTabKeyNavigation(false); ui.channelListView->setModel(&_sortFilter); ui.channelListView->setSortingEnabled(true); + // Sort A-Z by default + ui.channelListView->sortByColumn(0, Qt::AscendingOrder); ui.channelListView->verticalHeader()->hide(); ui.channelListView->horizontalHeader()->setStretchLastSection(true); @@ -70,6 +72,9 @@ ChannelListDlg::ChannelListDlg(QWidget *parent) enableQuery(true); showFilterLine(false); showErrors(false); + + // Set initial input focus + updateInputFocus(); } @@ -113,6 +118,8 @@ void ChannelListDlg::receiveChannelList(const NetworkId &netId, const QStringLis showFilterLine(!channelList.isEmpty()); _ircListModel.setChannelList(channelList); enableQuery(_listFinished); + // Reset input focus since UI changed + updateInputFocus(); } @@ -157,6 +164,18 @@ void ChannelListDlg::setAdvancedMode(bool advanced) } +void ChannelListDlg::updateInputFocus() +{ + // Update keyboard focus to match what options are available. Prioritize the channel name + // editor as one likely won't need to filter when already limiting the list. + if (ui.channelNameLineEdit->isVisible()) { + ui.channelNameLineEdit->setFocus(); + } else if (ui.filterLineEdit->isVisible()) { + ui.filterLineEdit->setFocus(); + } +} + + void ChannelListDlg::showErrors(bool show) { if (!show) { diff --git a/src/qtui/channellistdlg.h b/src/qtui/channellistdlg.h index b8187782..fbdb38fe 100644 --- a/src/qtui/channellistdlg.h +++ b/src/qtui/channellistdlg.h @@ -66,6 +66,11 @@ private: void enableQuery(bool enable); void setAdvancedMode(bool advanced); + /** + * Update the focus of input widgets according to dialog state + */ + void updateInputFocus(); + Ui::ChannelListDlg ui; bool _listFinished; -- 2.20.1