mirror of
https://github.com/Rosalie241/RMG.git
synced 2026-07-11 01:24:01 +02:00
RMG: introduce RomBrowserSearchWidget
This commit is contained in:
@@ -49,6 +49,7 @@ set(RMG_SOURCES
|
||||
UserInterface/Widget/RomBrowser/RomBrowserLoadingWidget.cpp
|
||||
UserInterface/Widget/RomBrowser/RomBrowserEmptyWidget.cpp
|
||||
UserInterface/Widget/RomBrowser/RomBrowserEmptyWidget.ui
|
||||
UserInterface/Widget/RomBrowser/RomBrowserSearchWidget.cpp
|
||||
UserInterface/Widget/Render/DummyWidget.cpp
|
||||
UserInterface/Widget/Render/OGLWidget.cpp
|
||||
UserInterface/Widget/Render/VKWidget.cpp
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
||||
* Copyright (C) 2020-2025 Rosalie Wanders <rosalie@mailbox.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "RomBrowserSearchWidget.hpp"
|
||||
|
||||
using namespace UserInterface::Widget;
|
||||
|
||||
RomBrowserSearchWidget::RomBrowserSearchWidget(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
// configure search line edit
|
||||
this->lineEdit = new QLineEdit(this);
|
||||
this->lineEdit->setPlaceholderText("Search games...");
|
||||
connect(this->lineEdit, &QLineEdit::textChanged, this, &RomBrowserSearchWidget::on_lineEdit_textChanged);
|
||||
|
||||
// configure close button
|
||||
this->closeButton = new QPushButton(this);
|
||||
this->closeButton->setText("Close");
|
||||
connect(this->closeButton, &QPushButton::clicked, this, &RomBrowserSearchWidget::on_closeButton_clicked);
|
||||
|
||||
// configure layout
|
||||
this->widgetLayout = new QHBoxLayout(this);
|
||||
this->widgetLayout->addWidget(this->lineEdit);
|
||||
this->widgetLayout->addWidget(this->closeButton);
|
||||
this->setLayout(this->widgetLayout);
|
||||
}
|
||||
|
||||
RomBrowserSearchWidget::~RomBrowserSearchWidget(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RomBrowserSearchWidget::FocusSearchText(void)
|
||||
{
|
||||
this->lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void RomBrowserSearchWidget::ClearSearchTerm(void)
|
||||
{
|
||||
this->lineEdit->setText("");
|
||||
}
|
||||
|
||||
void RomBrowserSearchWidget::on_lineEdit_textChanged(const QString& text)
|
||||
{
|
||||
emit this->SearchTextChanged(text);
|
||||
}
|
||||
|
||||
void RomBrowserSearchWidget::on_closeButton_clicked(void)
|
||||
{
|
||||
this->hide();
|
||||
this->ClearSearchTerm();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
||||
* Copyright (C) 2020-2025 Rosalie Wanders <rosalie@mailbox.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef ROMBROWSERSEARCHWIDGET_HPP
|
||||
#define ROMBROWSERSEARCHWIDGET_HPP
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QWidget>
|
||||
|
||||
namespace UserInterface
|
||||
{
|
||||
namespace Widget
|
||||
{
|
||||
class RomBrowserSearchWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RomBrowserSearchWidget(QWidget* parent);
|
||||
~RomBrowserSearchWidget(void);
|
||||
|
||||
void FocusSearchText(void);
|
||||
void ClearSearchTerm(void);
|
||||
|
||||
signals:
|
||||
void SearchTextChanged(const QString& text);
|
||||
|
||||
private:
|
||||
QHBoxLayout* widgetLayout = nullptr;
|
||||
QLineEdit* lineEdit = nullptr;
|
||||
QPushButton* closeButton = nullptr;
|
||||
|
||||
private slots:
|
||||
void on_lineEdit_textChanged(const QString& text);
|
||||
void on_closeButton_clicked(void);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ROMBROWSERSEARCHWIDGET_HPP
|
||||
@@ -64,16 +64,13 @@ RomBrowserWidget::RomBrowserWidget(QWidget *parent) : QWidget(parent)
|
||||
// configure stacked widget
|
||||
this->stackedWidget = new QStackedWidget(this);
|
||||
|
||||
// configure search line edit
|
||||
this->searchLineEdit = new QLineEdit(this);
|
||||
this->searchLineEdit->setPlaceholderText("Search games...");
|
||||
this->searchLineEdit->setVisible(false);
|
||||
connect(this->searchLineEdit, &QLineEdit::textChanged, this, &RomBrowserWidget::on_searchLineEdit_textChanged);
|
||||
|
||||
// configure search widget
|
||||
this->searchWidget = new Widget::RomBrowserSearchWidget(this);
|
||||
connect(this->searchWidget, &RomBrowserSearchWidget::SearchTextChanged, this, &RomBrowserWidget::on_searchWidget_SearchTextChanged);
|
||||
// configure layout
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(this->stackedWidget);
|
||||
layout->addWidget(this->searchLineEdit);
|
||||
layout->addWidget(this->searchWidget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->setLayout(layout);
|
||||
|
||||
@@ -305,8 +302,8 @@ void RomBrowserWidget::RefreshRomList(void)
|
||||
|
||||
this->stackedWidget->setCurrentWidget(this->loadingWidget);
|
||||
|
||||
this->showSearchLineEdit = this->searchLineEdit->isVisible();
|
||||
this->searchLineEdit->hide();
|
||||
this->showSearchLineEdit = this->searchWidget->isVisible();
|
||||
this->searchWidget->hide();
|
||||
|
||||
this->romSearcherTimer.start();
|
||||
|
||||
@@ -370,7 +367,7 @@ void RomBrowserWidget::SetGridViewUniformSizes(bool value)
|
||||
|
||||
void RomBrowserWidget::SetToggleSearch(void)
|
||||
{
|
||||
const bool show = !this->searchLineEdit->isVisible();
|
||||
const bool show = !this->searchWidget->isVisible();
|
||||
|
||||
// do nothing when not in a valid view
|
||||
QWidget* currentWidget = this->stackedWidget->currentWidget();
|
||||
@@ -380,17 +377,17 @@ void RomBrowserWidget::SetToggleSearch(void)
|
||||
return;
|
||||
}
|
||||
|
||||
this->searchLineEdit->setVisible(show);
|
||||
this->searchWidget->setVisible(show);
|
||||
|
||||
if (show)
|
||||
{
|
||||
// set focus when it's being shown
|
||||
this->searchLineEdit->setFocus();
|
||||
this->searchWidget->FocusSearchText();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset search when hidden
|
||||
this->searchLineEdit->setText("");
|
||||
this->searchWidget->ClearSearchTerm();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,7 +662,7 @@ void RomBrowserWidget::timerEvent(QTimerEvent* event)
|
||||
{
|
||||
this->killTimer(event->timerId());
|
||||
this->stackedWidget->setCurrentWidget(this->currentViewWidget);
|
||||
this->searchLineEdit->setVisible(this->showSearchLineEdit);
|
||||
this->searchWidget->setVisible(this->showSearchLineEdit);
|
||||
}
|
||||
|
||||
void RomBrowserWidget::on_DoubleClicked(const QModelIndex& index)
|
||||
@@ -844,11 +841,10 @@ void RomBrowserWidget::generateStateMenu(void)
|
||||
this->menu_PlayGameWithSlot->setDisabled(this->menu_PlayGameWithSlot->isEmpty());
|
||||
}
|
||||
|
||||
void RomBrowserWidget::on_searchLineEdit_textChanged(const QString& text)
|
||||
void RomBrowserWidget::on_searchWidget_SearchTextChanged(const QString& text)
|
||||
{
|
||||
// TODO: I should really make a custom data
|
||||
// model at this point to save memory & CPU cycles...
|
||||
|
||||
this->listViewProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
this->listViewProxyModel->setFilterWildcard(text);
|
||||
this->listViewProxyModel->setFilterKeyColumn(0);
|
||||
@@ -1085,7 +1081,7 @@ void RomBrowserWidget::on_RomBrowserThread_Finished(bool canceled)
|
||||
}
|
||||
|
||||
this->stackedWidget->setCurrentWidget(this->currentViewWidget);
|
||||
this->searchLineEdit->setVisible(this->showSearchLineEdit);
|
||||
this->searchWidget->setVisible(this->showSearchLineEdit);
|
||||
}
|
||||
|
||||
void RomBrowserWidget::on_Action_PlayGame(void)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "RomBrowserListViewWidget.hpp"
|
||||
#include "RomBrowserGridViewWidget.hpp"
|
||||
#include "RomBrowserLoadingWidget.hpp"
|
||||
#include "RomBrowserSearchWidget.hpp"
|
||||
#include "RomBrowserEmptyWidget.hpp"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
@@ -72,8 +73,8 @@ class RomBrowserWidget : public QWidget
|
||||
QStandardItemModel* gridViewModel = nullptr;
|
||||
QSortFilterProxyModel* gridViewProxyModel = nullptr;
|
||||
|
||||
QLineEdit* searchLineEdit = nullptr;
|
||||
bool showSearchLineEdit = false;
|
||||
Widget::RomBrowserSearchWidget* searchWidget = nullptr;
|
||||
bool showSearchLineEdit = false;
|
||||
|
||||
QWidget* currentViewWidget = nullptr;
|
||||
|
||||
@@ -126,7 +127,7 @@ class RomBrowserWidget : public QWidget
|
||||
void generatePlayWithDiskMenu(void);
|
||||
void generateStateMenu(void);
|
||||
|
||||
void on_searchLineEdit_textChanged(const QString& text);
|
||||
void on_searchWidget_SearchTextChanged(const QString& text);
|
||||
|
||||
void on_listViewWidget_sortIndicatorChanged(int logicalIndex, Qt::SortOrder sortOrder);
|
||||
void on_listViewWidget_sectionResized(int logicalIndex, int oldWidth, int newWidth);
|
||||
|
||||
Reference in New Issue
Block a user