Use the common search syntax window method in visual database display (#5829)

This commit is contained in:
RickyRister 2025-04-15 15:09:36 -07:00 committed by GitHub
parent e9d05e6271
commit 181bef0057
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 39 deletions

View file

@ -237,42 +237,6 @@ void DeckEditorDatabaseDisplayWidget::saveDbHeaderState()
SettingsCache::instance().layouts().setDeckEditorDbHeaderState(databaseView->header()->saveState());
}
void DeckEditorDatabaseDisplayWidget::showSearchSyntaxHelp()
{
QFile file("theme:help/search.md");
if (!file.open(QFile::ReadOnly | QFile::Text)) {
return;
}
QTextStream in(&file);
QString text = in.readAll();
file.close();
// Poor Markdown Converter
auto opts = QRegularExpression::MultilineOption;
text = text.replace(QRegularExpression("^(###)(.*)", opts), "<h3>\\2</h3>")
.replace(QRegularExpression("^(##)(.*)", opts), "<h2>\\2</h2>")
.replace(QRegularExpression("^(#)(.*)", opts), "<h1>\\2</h1>")
.replace(QRegularExpression("^------*", opts), "<hr />")
.replace(QRegularExpression(R"(\[([^[]+)\]\(([^\)]+)\))", opts), R"(<a href='\2'>\1</a>)");
auto browser = new QTextBrowser;
browser->setParent(this, Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint |
Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint);
browser->setWindowTitle("Search Help");
browser->setReadOnly(true);
browser->setMinimumSize({500, 600});
QString sheet = QString("a { text-decoration: underline; color: rgb(71,158,252) };");
browser->document()->setDefaultStyleSheet(sheet);
browser->setHtml(text);
connect(browser, &QTextBrowser::anchorClicked, [this](const QUrl &link) { searchEdit->setText(link.fragment()); });
browser->show();
}
void DeckEditorDatabaseDisplayWidget::setFilterTree(FilterTree *filterTree)
{
databaseDisplayModel->setFilterTree(filterTree);

View file

@ -22,7 +22,6 @@ public:
CardDatabaseDisplayModel *databaseDisplayModel;
public slots:
void showSearchSyntaxHelp();
CardInfoPtr currentCardInfo() const;
void setFilterTree(FilterTree *filterTree);
void clearAllDatabaseFilters();

View file

@ -4,6 +4,7 @@
#include "../../../../game/cards/card_database.h"
#include "../../../../game/cards/card_database_manager.h"
#include "../../../../game/filters/filter_tree_model.h"
#include "../../../../game/filters/syntax_help.h"
#include "../../../../settings/cache_settings.h"
#include "../../../../utility/card_info_comparator.h"
#include "../../pixel_map_generator.h"
@ -53,6 +54,7 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
searchEdit->setClearButtonEnabled(true);
searchEdit->addAction(loadColorAdjustedPixmap("theme:icons/search"), QLineEdit::LeadingPosition);
auto help = searchEdit->addAction(QPixmap("theme:icons/info"), QLineEdit::TrailingPosition);
connect(help, &QAction::triggered, this, [this] { createSearchSyntaxHelpWindow(searchEdit); });
searchEdit->installEventFilter(&searchKeySignals);
setFocusProxy(searchEdit);
@ -74,8 +76,6 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
connect(&searchKeySignals, SIGNAL(onCtrlAltEnter()), this, SLOT(actAddCardToSideboard()));
connect(&searchKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard()));
connect(&searchKeySignals, SIGNAL(onCtrlC()), this, SLOT(copyDatabaseCellContents()));*/
connect(help, &QAction::triggered, deckEditor->databaseDisplayDockWidget,
&DeckEditorDatabaseDisplayWidget::showSearchSyntaxHelp);
databaseView = new QTreeView(this);
databaseView->setObjectName("databaseView");