diff --git a/cockatrice/cockatrice.pro b/cockatrice/cockatrice.pro
index 196b64bc8..3dab527f5 100644
--- a/cockatrice/cockatrice.pro
+++ b/cockatrice/cockatrice.pro
@@ -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 \
diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc
index d58a31bdd..8f5f51b09 100644
--- a/cockatrice/cockatrice.qrc
+++ b/cockatrice/cockatrice.qrc
@@ -17,6 +17,8 @@
resources/icon_phase_cleanup.svg
resources/icon_nextturn.svg
resources/pencil.svg
+ resources/icon_search.svg
+ resources/icon_clearsearch.svg
resources/hr.jpg
translations/cockatrice_de.qm
translations/cockatrice_en.qm
diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp
index e77d36f0d..821c968b2 100644
--- a/cockatrice/src/carddatabase.cpp
+++ b/cockatrice/src/carddatabase.cpp
@@ -7,6 +7,7 @@
#include
#include
#include
+#include
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 colors;
+ QHashIterator 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 types;
+ QHashIterator cardIterator(cardHash);
+ while (cardIterator.hasNext())
+ types.insert(cardIterator.next().value()->getMainCardType());
+ return types.toList();
+}
diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h
index 225773e54..c3fab1285 100644
--- a/cockatrice/src/carddatabase.h
+++ b/cockatrice/src/carddatabase.h
@@ -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:
diff --git a/cockatrice/src/carddatabasemodel.cpp b/cockatrice/src/carddatabasemodel.cpp
index 9772c6da8..3f8e42d17 100644
--- a/cockatrice/src/carddatabasemodel.cpp
+++ b/cockatrice/src/carddatabasemodel.cpp
@@ -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::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();
}
diff --git a/cockatrice/src/carddatabasemodel.h b/cockatrice/src/carddatabasemodel.h
index 0649d18b9..6d651d4c7 100644
--- a/cockatrice/src/carddatabasemodel.h
+++ b/cockatrice/src/carddatabasemodel.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
#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 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 &_cardTypes) { cardTypes = _cardTypes; invalidateFilter(); }
+ void setCardColors(const QSet &_cardColors) { cardColors = _cardColors; invalidateFilter(); }
+ void clearSearch();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
};
diff --git a/cockatrice/src/dlg_cardsearch.cpp b/cockatrice/src/dlg_cardsearch.cpp
new file mode 100644
index 000000000..55d9419cf
--- /dev/null
+++ b/cockatrice/src/dlg_cardsearch.cpp
@@ -0,0 +1,95 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#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 DlgCardSearch::getCardTypes() const
+{
+ QStringList result;
+ for (int i = 0; i < cardTypeCheckBoxes.size(); ++i)
+ if (cardTypeCheckBoxes[i]->isChecked())
+ result.append(cardTypeCheckBoxes[i]->text());
+ return QSet::fromList(result);
+}
+
+QSet DlgCardSearch::getCardColors() const
+{
+ QStringList result;
+ for (int i = 0; i < cardColorCheckBoxes.size(); ++i)
+ if (cardColorCheckBoxes[i]->isChecked())
+ result.append(cardColorCheckBoxes[i]->text());
+ return QSet::fromList(result);
+}
diff --git a/cockatrice/src/dlg_cardsearch.h b/cockatrice/src/dlg_cardsearch.h
new file mode 100644
index 000000000..86073fe0a
--- /dev/null
+++ b/cockatrice/src/dlg_cardsearch.h
@@ -0,0 +1,23 @@
+#ifndef DLG_CARDSEARCH_H
+#define DLG_CARDSEARCH_H
+
+#include
+#include
+#include
+
+class QLineEdit;
+class QCheckBox;
+
+class DlgCardSearch : public QDialog {
+private:
+ QLineEdit *cardNameEdit, *cardTextEdit;
+ QList cardTypeCheckBoxes, cardColorCheckBoxes;
+public:
+ DlgCardSearch(QWidget *parent = 0);
+ QString getCardName() const;
+ QString getCardText() const;
+ QSet getCardTypes() const;
+ QSet getCardColors() const;
+};
+
+#endif
\ No newline at end of file
diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp
index 0981d30c7..2d3492de5 100644
--- a/cockatrice/src/window_deckeditor.cpp
+++ b/cockatrice/src/window_deckeditor.cpp
@@ -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(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())
diff --git a/cockatrice/src/window_deckeditor.h b/cockatrice/src/window_deckeditor.h
index ea326d839..dc8b6fe46 100644
--- a/cockatrice/src/window_deckeditor.h
+++ b/cockatrice/src/window_deckeditor.h
@@ -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);