mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
initial commit for card search dialog
This commit is contained in:
parent
324be6b40c
commit
42531d90e9
10 changed files with 220 additions and 8 deletions
|
|
@ -38,6 +38,7 @@ HEADERS += src/counter.h \
|
|||
src/window_sets.h \
|
||||
src/abstractgraphicsitem.h \
|
||||
src/dlg_settings.h \
|
||||
src/dlg_cardsearch.h \
|
||||
src/phasestoolbar.h \
|
||||
src/gamescene.h \
|
||||
src/arrowitem.h \
|
||||
|
|
@ -89,6 +90,7 @@ SOURCES += src/counter.cpp \
|
|||
src/window_sets.cpp \
|
||||
src/abstractgraphicsitem.cpp \
|
||||
src/dlg_settings.cpp \
|
||||
src/dlg_cardsearch.cpp \
|
||||
src/phasestoolbar.cpp \
|
||||
src/gamescene.cpp \
|
||||
src/arrowitem.cpp \
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
<file>resources/icon_phase_cleanup.svg</file>
|
||||
<file>resources/icon_nextturn.svg</file>
|
||||
<file>resources/pencil.svg</file>
|
||||
<file>resources/icon_search.svg</file>
|
||||
<file>resources/icon_clearsearch.svg</file>
|
||||
<file>resources/hr.jpg</file>
|
||||
<file>translations/cockatrice_de.qm</file>
|
||||
<file>translations/cockatrice_en.qm</file>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QUrl>
|
||||
#include <QSet>
|
||||
|
||||
CardSet::CardSet(const QString &_shortName, const QString &_longName)
|
||||
: shortName(_shortName), longName(_longName)
|
||||
|
|
@ -503,3 +504,24 @@ void CardDatabase::updateDatabasePath(const QString &path)
|
|||
if (!cardDatabasePath.isEmpty())
|
||||
loadFromFile(cardDatabasePath);
|
||||
}
|
||||
|
||||
QStringList CardDatabase::getAllColors() const
|
||||
{
|
||||
QSet<QString> colors;
|
||||
QHashIterator<QString, CardInfo *> cardIterator(cardHash);
|
||||
while (cardIterator.hasNext()) {
|
||||
const QStringList &cardColors = cardIterator.next().value()->getColors();
|
||||
for (int i = 0; i < cardColors.size(); ++i)
|
||||
colors.insert(cardColors[i]);
|
||||
}
|
||||
return colors.toList();
|
||||
}
|
||||
|
||||
QStringList CardDatabase::getAllMainCardTypes() const
|
||||
{
|
||||
QSet<QString> types;
|
||||
QHashIterator<QString, CardInfo *> cardIterator(cardHash);
|
||||
while (cardIterator.hasNext())
|
||||
types.insert(cardIterator.next().value()->getMainCardType());
|
||||
return types.toList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,6 +112,8 @@ public:
|
|||
bool saveToFile(const QString &fileName);
|
||||
const QString &getPicsPath() const { return picsPath; }
|
||||
void startPicDownload(CardInfo *card);
|
||||
QStringList getAllColors() const;
|
||||
QStringList getAllMainCardTypes() const;
|
||||
private slots:
|
||||
void picDownloadFinished(int id, bool error);
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -78,11 +78,30 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
|
|||
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
||||
return false;
|
||||
|
||||
if (!cardName.isEmpty())
|
||||
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
||||
return false;
|
||||
|
||||
if (!cardText.isEmpty())
|
||||
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
||||
return false;
|
||||
|
||||
if (!cardColors.isEmpty())
|
||||
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty())
|
||||
return false;
|
||||
|
||||
if (!cardTypes.isEmpty())
|
||||
if (!cardTypes.contains(info->getMainCardType()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CardDatabaseDisplayModel::setCardNameBeginning(const QString &_beginning)
|
||||
void CardDatabaseDisplayModel::clearSearch()
|
||||
{
|
||||
cardNameBeginning = _beginning;
|
||||
cardName.clear();
|
||||
cardText.clear();
|
||||
cardTypes.clear();
|
||||
cardColors.clear();
|
||||
invalidateFilter();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <QAbstractListModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
#include "carddatabase.h"
|
||||
|
||||
class CardDatabaseModel : public QAbstractListModel {
|
||||
|
|
@ -24,10 +25,16 @@ private:
|
|||
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString cardNameBeginning;
|
||||
QString cardNameBeginning, cardName, cardText;
|
||||
QSet<QString> cardTypes, cardColors;
|
||||
public:
|
||||
CardDatabaseDisplayModel(QObject *parent = 0);
|
||||
void setCardNameBeginning(const QString &_beginning);
|
||||
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidateFilter(); }
|
||||
void setCardName(const QString &_cardName) { cardName = _cardName; invalidateFilter(); }
|
||||
void setCardText(const QString &_cardText) { cardText = _cardText; invalidateFilter(); }
|
||||
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidateFilter(); }
|
||||
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidateFilter(); }
|
||||
void clearSearch();
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
};
|
||||
|
|
|
|||
95
cockatrice/src/dlg_cardsearch.cpp
Normal file
95
cockatrice/src/dlg_cardsearch.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QCheckBox>
|
||||
#include <QGridLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include "dlg_cardsearch.h"
|
||||
#include "carddatabase.h"
|
||||
#include "main.h"
|
||||
|
||||
DlgCardSearch::DlgCardSearch(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
QLabel *cardNameLabel = new QLabel(tr("Card name:"));
|
||||
cardNameEdit = new QLineEdit;
|
||||
|
||||
QLabel *cardTextLabel = new QLabel(tr("Card text:"));
|
||||
cardTextEdit = new QLineEdit;
|
||||
|
||||
QLabel *cardTypesLabel = new QLabel(tr("Card type (OR):"));
|
||||
const QStringList &cardTypes = db->getAllMainCardTypes();
|
||||
QVBoxLayout *cardTypesLayout = new QVBoxLayout;
|
||||
for (int i = 0; i < cardTypes.size(); ++i) {
|
||||
QCheckBox *cardTypeCheckBox = new QCheckBox(cardTypes[i]);
|
||||
cardTypeCheckBox->setChecked(true);
|
||||
cardTypeCheckBoxes.append(cardTypeCheckBox);
|
||||
cardTypesLayout->addWidget(cardTypeCheckBox);
|
||||
}
|
||||
|
||||
QLabel *cardColorsLabel = new QLabel(tr("Color (OR):"));
|
||||
const QStringList &cardColors = db->getAllColors();
|
||||
QHBoxLayout *cardColorsLayout = new QHBoxLayout;
|
||||
for (int i = 0; i < cardColors.size(); ++i) {
|
||||
QCheckBox *cardColorCheckBox = new QCheckBox(cardColors[i]);
|
||||
cardColorCheckBox->setChecked(true);
|
||||
cardColorCheckBoxes.append(cardColorCheckBox);
|
||||
cardColorsLayout->addWidget(cardColorCheckBox);
|
||||
}
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("O&K"));
|
||||
okButton->setDefault(true);
|
||||
okButton->setAutoDefault(true);
|
||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
QHBoxLayout *buttonHBox = new QHBoxLayout;
|
||||
buttonHBox->addStretch();
|
||||
buttonHBox->addWidget(okButton);
|
||||
buttonHBox->addWidget(cancelButton);
|
||||
|
||||
QGridLayout *optionsLayout = new QGridLayout;
|
||||
optionsLayout->addWidget(cardNameLabel, 0, 0);
|
||||
optionsLayout->addWidget(cardNameEdit, 0, 1);
|
||||
optionsLayout->addWidget(cardTextLabel, 1, 0);
|
||||
optionsLayout->addWidget(cardTextEdit, 1, 1);
|
||||
optionsLayout->addWidget(cardTypesLabel, 2, 0);
|
||||
optionsLayout->addLayout(cardTypesLayout, 2, 1);
|
||||
optionsLayout->addWidget(cardColorsLabel, 3, 0);
|
||||
optionsLayout->addLayout(cardColorsLayout, 3, 1);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(optionsLayout);
|
||||
mainLayout->addLayout(buttonHBox);
|
||||
setLayout(mainLayout);
|
||||
setWindowTitle(tr("Card search"));
|
||||
}
|
||||
|
||||
QString DlgCardSearch::getCardName() const
|
||||
{
|
||||
return cardNameEdit->text();
|
||||
}
|
||||
|
||||
QString DlgCardSearch::getCardText() const
|
||||
{
|
||||
return cardTextEdit->text();
|
||||
}
|
||||
|
||||
QSet<QString> DlgCardSearch::getCardTypes() const
|
||||
{
|
||||
QStringList result;
|
||||
for (int i = 0; i < cardTypeCheckBoxes.size(); ++i)
|
||||
if (cardTypeCheckBoxes[i]->isChecked())
|
||||
result.append(cardTypeCheckBoxes[i]->text());
|
||||
return QSet<QString>::fromList(result);
|
||||
}
|
||||
|
||||
QSet<QString> DlgCardSearch::getCardColors() const
|
||||
{
|
||||
QStringList result;
|
||||
for (int i = 0; i < cardColorCheckBoxes.size(); ++i)
|
||||
if (cardColorCheckBoxes[i]->isChecked())
|
||||
result.append(cardColorCheckBoxes[i]->text());
|
||||
return QSet<QString>::fromList(result);
|
||||
}
|
||||
23
cockatrice/src/dlg_cardsearch.h
Normal file
23
cockatrice/src/dlg_cardsearch.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef DLG_CARDSEARCH_H
|
||||
#define DLG_CARDSEARCH_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
|
||||
class QLineEdit;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgCardSearch : public QDialog {
|
||||
private:
|
||||
QLineEdit *cardNameEdit, *cardTextEdit;
|
||||
QList<QCheckBox *> cardTypeCheckBoxes, cardColorCheckBoxes;
|
||||
public:
|
||||
DlgCardSearch(QWidget *parent = 0);
|
||||
QString getCardName() const;
|
||||
QString getCardText() const;
|
||||
QSet<QString> getCardTypes() const;
|
||||
QSet<QString> getCardColors() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include "decklistmodel.h"
|
||||
#include "cardinfowidget.h"
|
||||
#include "deck_picturecacher.h"
|
||||
#include "dlg_cardsearch.h"
|
||||
#include "main.h"
|
||||
|
||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
|
|
@ -18,15 +19,28 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
|||
WndDeckEditor::WndDeckEditor(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
aSearch = new QAction(tr("&Search..."), this);
|
||||
aSearch->setIcon(QIcon(":/resources/icon_search.svg"));
|
||||
connect(aSearch, SIGNAL(triggered()), this, SLOT(actSearch()));
|
||||
aClearSearch = new QAction(tr("&Clear search"), this);
|
||||
aClearSearch->setIcon(QIcon(":/resources/icon_clearsearch.svg"));
|
||||
connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch()));
|
||||
|
||||
QLabel *searchLabel = new QLabel(tr("&Search for:"));
|
||||
searchEdit = new SearchLineEdit;
|
||||
searchLabel->setBuddy(searchEdit);
|
||||
connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &)));
|
||||
connect(searchEdit, SIGNAL(returnPressed()), this, SLOT(actAddCard()));
|
||||
QToolButton *searchButton = new QToolButton;
|
||||
searchButton->setDefaultAction(aSearch);
|
||||
QToolButton *clearSearchButton = new QToolButton;
|
||||
clearSearchButton->setDefaultAction(aClearSearch);
|
||||
|
||||
QHBoxLayout *searchLayout = new QHBoxLayout;
|
||||
searchLayout->addWidget(searchLabel);
|
||||
searchLayout->addWidget(searchEdit);
|
||||
searchLayout->addWidget(searchButton);
|
||||
searchLayout->addWidget(clearSearchButton);
|
||||
|
||||
databaseModel = new CardDatabaseModel(db, this);
|
||||
databaseDisplayModel = new CardDatabaseDisplayModel(this);
|
||||
|
|
@ -134,8 +148,11 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
|
|||
deckMenu->addSeparator();
|
||||
deckMenu->addAction(aClose);
|
||||
|
||||
setsMenu = menuBar()->addMenu(tr("&Sets"));
|
||||
setsMenu->addAction(aEditSets);
|
||||
dbMenu = menuBar()->addMenu(tr("&Card database"));
|
||||
dbMenu->addAction(aEditSets);
|
||||
dbMenu->addSeparator();
|
||||
dbMenu->addAction(aSearch);
|
||||
dbMenu->addAction(aClearSearch);
|
||||
|
||||
aAddCard = new QAction(tr("Add card to &maindeck"), this);
|
||||
aAddCard->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Return")) << QKeySequence(tr("Enter")));
|
||||
|
|
@ -164,6 +181,8 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
|
|||
verticalToolBar->addAction(aIncrement);
|
||||
verticalToolBar->addAction(aDecrement);
|
||||
|
||||
dlgCardSearch = new DlgCardSearch(this);
|
||||
|
||||
resize(950, 700);
|
||||
}
|
||||
|
||||
|
|
@ -305,6 +324,22 @@ void WndDeckEditor::actEditSets()
|
|||
w->show();
|
||||
}
|
||||
|
||||
void WndDeckEditor::actSearch()
|
||||
{
|
||||
if (dlgCardSearch->exec()) {
|
||||
searchEdit->clear();
|
||||
databaseDisplayModel->setCardName(dlgCardSearch->getCardName());
|
||||
databaseDisplayModel->setCardText(dlgCardSearch->getCardText());
|
||||
databaseDisplayModel->setCardTypes(dlgCardSearch->getCardTypes());
|
||||
databaseDisplayModel->setCardColors(dlgCardSearch->getCardColors());
|
||||
}
|
||||
}
|
||||
|
||||
void WndDeckEditor::actClearSearch()
|
||||
{
|
||||
databaseDisplayModel->clearSearch();
|
||||
}
|
||||
|
||||
void WndDeckEditor::recursiveExpand(const QModelIndex &index)
|
||||
{
|
||||
if (index.parent().isValid())
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class QTreeView;
|
|||
class QTableView;
|
||||
class CardInfoWidget;
|
||||
class QTextEdit;
|
||||
class DlgCardSearch;
|
||||
|
||||
class SearchLineEdit : public QLineEdit {
|
||||
private:
|
||||
|
|
@ -40,6 +41,9 @@ private slots:
|
|||
void actPrintDeck();
|
||||
|
||||
void actEditSets();
|
||||
|
||||
void actSearch();
|
||||
void actClearSearch();
|
||||
|
||||
void actAddCard();
|
||||
void actAddCardToSideboard();
|
||||
|
|
@ -63,10 +67,11 @@ private:
|
|||
SearchLineEdit *searchEdit;
|
||||
QLineEdit *nameEdit;
|
||||
QTextEdit *commentsEdit;
|
||||
DlgCardSearch *dlgCardSearch;
|
||||
|
||||
QMenu *deckMenu, *setsMenu;
|
||||
QMenu *deckMenu, *dbMenu;
|
||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose;
|
||||
QAction *aEditSets;
|
||||
QAction *aEditSets, *aSearch, *aClearSearch;
|
||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
||||
public:
|
||||
WndDeckEditor(QWidget *parent = 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue