From d7ceadeae173e26d63db0b58b6ea5a3ed839999c Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 17 Apr 2020 08:19:22 -0400 Subject: hook ctrl+f and escape directly on widgets instead of on the main window to allow other widgets to use the same shortcuts, like the FilterWidget --- src/mainwindow.cpp | 77 +++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 85d0fe39..cac9a0b9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -204,6 +204,42 @@ QString UnmanagedModName() bool runLoot(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList); + +void setFilterShortcuts(QWidget* widget, QLineEdit* edit) +{ + auto activate = [=] { + edit->setFocus(); + edit->selectAll(); + }; + + auto reset = [=] { + edit->clear(); + widget->setFocus(); + }; + + auto hookActivate = [activate](auto* w) { + auto* s = new QShortcut(QKeySequence::Find, w); + s->setAutoRepeat(false); + s->setContext(Qt::WidgetWithChildrenShortcut); + QObject::connect(s, &QShortcut::activated, activate); + }; + + auto hookReset = [reset](auto* w) { + auto* s = new QShortcut(QKeySequence(Qt::Key_Escape), w); + s->setAutoRepeat(false); + s->setContext(Qt::WidgetWithChildrenShortcut); + QObject::connect(s, &QShortcut::activated, reset); + }; + + + hookActivate(widget); + hookReset(widget); + + hookActivate(edit); + hookReset(edit); +} + + MainWindow::MainWindow(Settings &settings , OrganizerCore &organizerCore , PluginContainer &pluginContainer @@ -432,8 +468,9 @@ MainWindow::MainWindow(Settings &settings new QShortcut(QKeySequence::Refresh, this, SLOT(refreshProfile_activated())); - new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this, SLOT(search_activated())); - new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(searchClear_activated())); + setFilterShortcuts(ui->modList, ui->modFilterEdit); + setFilterShortcuts(ui->espList, ui->espFilterEdit); + setFilterShortcuts(ui->downloadView, ui->downloadFilterEdit); m_UpdateProblemsTimer.setSingleShot(true); connect(&m_UpdateProblemsTimer, SIGNAL(timeout()), this, SLOT(updateProblemsButton())); @@ -3353,42 +3390,6 @@ void MainWindow::refreshProfile_activated() m_OrganizerCore.profileRefresh(); } -void MainWindow::search_activated() -{ - if (ui->modList->hasFocus() || ui->modFilterEdit->hasFocus()) { - ui->modFilterEdit->setFocus(); - ui->modFilterEdit->setSelection(0, INT_MAX); - } - - else if (ui->espList->hasFocus() || ui->espFilterEdit->hasFocus()) { - ui->espFilterEdit->setFocus(); - ui->espFilterEdit->setSelection(0, INT_MAX); - } - - else if (ui->downloadView->hasFocus() || ui->downloadFilterEdit->hasFocus()) { - ui->downloadFilterEdit->setFocus(); - ui->downloadFilterEdit->setSelection(0, INT_MAX); - } -} - -void MainWindow::searchClear_activated() -{ - if (ui->modList->hasFocus() || ui->modFilterEdit->hasFocus()) { - ui->modFilterEdit->clear(); - ui->modList->setFocus(); - } - - else if (ui->espList->hasFocus() || ui->espFilterEdit->hasFocus()) { - ui->espFilterEdit->clear(); - ui->espList->setFocus(); - } - - else if (ui->downloadView->hasFocus() || ui->downloadFilterEdit->hasFocus()) { - ui->downloadFilterEdit->clear(); - ui->downloadView->setFocus(); - } -} - void MainWindow::updateModCount() { int activeCount = 0; -- cgit v1.3.1 From f43c11497df6550ac224e0965b7a07d4c548055b Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:01:33 -0400 Subject: added game, instance and profile to status bar --- src/mainwindow.cpp | 2 ++ src/statusbar.cpp | 36 +++++++++++++++++++++++++++++++++--- src/statusbar.h | 4 ++++ 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cac9a0b9..df1063ba 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -523,6 +523,7 @@ MainWindow::MainWindow(Settings &settings updatePluginCount(); updateModCount(); processUpdates(); + ui->statusBar->updateNormalMessage(m_OrganizerCore); } void MainWindow::setupModList() @@ -1699,6 +1700,7 @@ void MainWindow::activateSelectedProfile() m_OrganizerCore.refreshModList(); updateModCount(); updatePluginCount(); + ui->statusBar->updateNormalMessage(m_OrganizerCore); } void MainWindow::on_profileBox_currentIndexChanged(int index) diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 58189619..5897b6bb 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -1,12 +1,15 @@ #include "statusbar.h" #include "nexusinterface.h" #include "settings.h" +#include "organizercore.h" +#include "instancemanager.h" #include "ui_mainwindow.h" StatusBar::StatusBar(QWidget* parent) : - QStatusBar(parent), ui(nullptr), m_progress(new QProgressBar), - m_progressSpacer1(new QWidget), m_progressSpacer2(new QWidget), - m_notifications(nullptr), m_update(nullptr), m_api(new QLabel) + QStatusBar(parent), ui(nullptr), m_normal(new QLabel), + m_progress(new QProgressBar), m_progressSpacer1(new QWidget), + m_progressSpacer2(new QWidget), m_notifications(nullptr), m_update(nullptr), + m_api(new QLabel) { } @@ -16,6 +19,8 @@ void StatusBar::setup(Ui::MainWindow* mainWindowUI, const Settings& settings) m_notifications = new StatusBarAction(ui->actionNotifications); m_update = new StatusBarAction(ui->actionUpdate); + addWidget(m_normal); + m_progressSpacer1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); addPermanentWidget(m_progressSpacer1, 0); addPermanentWidget(m_progress); @@ -138,6 +143,31 @@ void StatusBar::checkSettings(const Settings& settings) m_api->setVisible(!settings.interface().hideAPICounter()); } +void StatusBar::updateNormalMessage(OrganizerCore& core) +{ + QString game; + + if (core.managedGame()) { + game = core.managedGame()->gameName(); + } else { + game = tr("Unknown game"); + } + + QString instance = InstanceManager::instance().currentInstance(); + if (instance.isEmpty()) { + instance = tr("Portable"); + } + + QString profile = core.profileName(); + + const auto s = QString("%1 - %2 - %3") + .arg(game) + .arg(instance) + .arg(profile); + + m_normal->setText(s); +} + void StatusBar::showEvent(QShowEvent*) { visibilityChanged(true); diff --git a/src/statusbar.h b/src/statusbar.h index 708615a1..7ff8fcbb 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -7,6 +7,8 @@ struct APIStats; class APIUserAccount; class Settings; +class OrganizerCore; + namespace Ui { class MainWindow; } @@ -41,6 +43,7 @@ public: void setAPI(const APIStats& stats, const APIUserAccount& user); void setUpdateAvailable(bool b); void checkSettings(const Settings& settings); + void updateNormalMessage(OrganizerCore& core); protected: void showEvent(QShowEvent* e); @@ -48,6 +51,7 @@ protected: private: Ui::MainWindow* ui; + QLabel* m_normal; QProgressBar* m_progress; QWidget* m_progressSpacer1; QWidget* m_progressSpacer2; -- cgit v1.3.1