Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
42531d90
Commit
42531d90
authored
Dec 20, 2009
by
Max-Wilhelm Bruker
Browse files
initial commit for card search dialog
parent
324be6b4
Changes
10
Show whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
42531d90
...
...
@@ -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
\
...
...
cockatrice/cockatrice.qrc
View file @
42531d90
...
...
@@ -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>
...
...
cockatrice/src/carddatabase.cpp
View file @
42531d90
...
...
@@ -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
();
}
cockatrice/src/carddatabase.h
View file @
42531d90
...
...
@@ -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
:
...
...
cockatrice/src/carddatabasemodel.cpp
View file @
42531d90
...
...
@@ -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
();
}
cockatrice/src/carddatabasemodel.h
View file @
42531d90
...
...
@@ -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
;
};
...
...
cockatrice/src/dlg_cardsearch.cpp
0 → 100644
View file @
42531d90
#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
);
}
cockatrice/src/dlg_cardsearch.h
0 → 100644
View file @
42531d90
#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
\ No newline at end of file
cockatrice/src/window_deckeditor.cpp
View file @
42531d90
...
...
@@ -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
())
...
...
cockatrice/src/window_deckeditor.h
View file @
42531d90
...
...
@@ -13,6 +13,7 @@ class QTreeView;
class
QTableView
;
class
CardInfoWidget
;
class
QTextEdit
;
class
DlgCardSearch
;
class
SearchLineEdit
:
public
QLineEdit
{
private:
...
...
@@ -41,6 +42,9 @@ private slots:
void
actEditSets
();
void
actSearch
();
void
actClearSearch
();
void
actAddCard
();
void
actAddCardToSideboard
();
void
actRemoveCard
();
...
...
@@ -63,10 +67,11 @@ private:
SearchLineEdit
*
searchEdit
;
QLineEdit
*
nameEdit
;
QTextEdit
*
commentsEdit
;
DlgCardSearch
*
dlgCardSearch
;
QMenu
*
deckMenu
,
*
sets
Menu
;
QMenu
*
deckMenu
,
*
db
Menu
;
QAction
*
aNewDeck
,
*
aLoadDeck
,
*
aSaveDeck
,
*
aSaveDeckAs
,
*
aPrintDeck
,
*
aClose
;
QAction
*
aEditSets
;
QAction
*
aEditSets
,
*
aSearch
,
*
aClearSearch
;
QAction
*
aAddCard
,
*
aAddCardToSideboard
,
*
aRemoveCard
,
*
aIncrement
,
*
aDecrement
;
public:
WndDeckEditor
(
QWidget
*
parent
=
0
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment