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
3ba39526
Commit
3ba39526
authored
May 17, 2012
by
Max-Wilhelm Bruker
Browse files
fixed issue #37: add option to manually add token cards to the database
parent
d5a1032c
Changes
15
Hide whitespace changes
Inline
Side-by-side
cockatrice/CMakeLists.txt
View file @
3ba39526
...
...
@@ -9,6 +9,7 @@ SET(cockatrice_SOURCES
src/dlg_filter_games.cpp
src/dlg_connect.cpp
src/dlg_create_token.cpp
src/dlg_edit_tokens.cpp
src/abstractclient.cpp
src/remoteclient.cpp
src/main.cpp
...
...
@@ -85,6 +86,7 @@ SET(cockatrice_HEADERS
src/dlg_filter_games.h
src/dlg_connect.h
src/dlg_create_token.h
src/dlg_edit_tokens.h
src/gamesmodel.h
src/abstractclient.h
src/remoteclient.h
...
...
cockatrice/src/carddatabase.cpp
View file @
3ba39526
...
...
@@ -440,9 +440,11 @@ CardDatabase::CardDatabase(QObject *parent)
{
connect
(
settingsCache
,
SIGNAL
(
picsPathChanged
()),
this
,
SLOT
(
picsPathChanged
()));
connect
(
settingsCache
,
SIGNAL
(
cardDatabasePathChanged
()),
this
,
SLOT
(
loadCardDatabase
()));
connect
(
settingsCache
,
SIGNAL
(
tokenDatabasePathChanged
()),
this
,
SLOT
(
loadTokenDatabase
()));
connect
(
settingsCache
,
SIGNAL
(
picDownloadChanged
()),
this
,
SLOT
(
picDownloadChanged
()));
loadCardDatabase
();
loadTokenDatabase
();
pictureLoaderThread
=
new
QThread
;
pictureLoader
=
new
PictureLoader
(
settingsCache
->
getPicsPath
(),
settingsCache
->
getPicDownload
());
...
...
@@ -482,18 +484,31 @@ void CardDatabase::clear()
cardHash
.
clear
();
}
CardInfo
*
CardDatabase
::
getCard
(
const
QString
&
cardName
)
void
CardDatabase
::
addCard
(
CardInfo
*
card
)
{
cardHash
.
insert
(
card
->
getName
(),
card
);
emit
cardAdded
(
card
);
}
void
CardDatabase
::
removeCard
(
CardInfo
*
card
)
{
cardHash
.
remove
(
card
->
getName
());
emit
cardRemoved
(
card
);
}
CardInfo
*
CardDatabase
::
getCard
(
const
QString
&
cardName
,
bool
createIfNotFound
)
{
if
(
cardName
.
isEmpty
())
return
noCard
;
else
if
(
cardHash
.
contains
(
cardName
))
return
cardHash
.
value
(
cardName
);
else
{
else
if
(
createIfNotFound
)
{
CardInfo
*
newCard
=
new
CardInfo
(
this
,
cardName
,
true
);
newCard
->
addToSet
(
getSet
(
"TK"
));
cardHash
.
insert
(
cardName
,
newCard
);
return
newCard
;
}
}
else
return
0
;
}
CardSet
*
CardDatabase
::
getSet
(
const
QString
&
setName
)
...
...
@@ -601,14 +616,42 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
}
}
bool
CardDatabase
::
loadFromFile
(
const
QString
&
fileName
)
bool
CardDatabase
::
loadFromFile
(
const
QString
&
fileName
,
bool
tokens
)
{
QFile
file
(
fileName
);
file
.
open
(
QIODevice
::
ReadOnly
);
if
(
!
file
.
isOpen
())
return
false
;
if
(
tokens
)
{
QMutableHashIterator
<
QString
,
CardInfo
*>
i
(
cardHash
);
while
(
i
.
hasNext
())
{
i
.
next
();
if
(
i
.
value
()
->
getIsToken
())
{
delete
i
.
value
();
i
.
remove
();
}
}
}
else
{
QHashIterator
<
QString
,
CardSet
*>
setIt
(
setHash
);
while
(
setIt
.
hasNext
())
{
setIt
.
next
();
delete
setIt
.
value
();
}
setHash
.
clear
();
QMutableHashIterator
<
QString
,
CardInfo
*>
i
(
cardHash
);
while
(
i
.
hasNext
())
{
i
.
next
();
if
(
!
i
.
value
()
->
getIsToken
())
{
delete
i
.
value
();
i
.
remove
();
}
}
cardHash
.
clear
();
}
QXmlStreamReader
xml
(
&
file
);
clear
();
while
(
!
xml
.
atEnd
())
{
if
(
xml
.
readNext
()
==
QXmlStreamReader
::
StartElement
)
{
if
(
xml
.
name
()
!=
"cockatrice_carddatabase"
)
...
...
@@ -629,7 +672,7 @@ bool CardDatabase::loadFromFile(const QString &fileName)
return
!
cardHash
.
isEmpty
();
}
bool
CardDatabase
::
saveToFile
(
const
QString
&
fileName
)
bool
CardDatabase
::
saveToFile
(
const
QString
&
fileName
,
bool
tokens
)
{
QFile
file
(
fileName
);
if
(
!
file
.
open
(
QIODevice
::
WriteOnly
))
...
...
@@ -641,16 +684,21 @@ bool CardDatabase::saveToFile(const QString &fileName)
xml
.
writeStartElement
(
"cockatrice_carddatabase"
);
xml
.
writeAttribute
(
"version"
,
QString
::
number
(
versionNeeded
));
xml
.
writeStartElement
(
"sets"
);
QHashIterator
<
QString
,
CardSet
*>
setIterator
(
setHash
);
while
(
setIterator
.
hasNext
())
xml
<<
setIterator
.
next
().
value
();
xml
.
writeEndElement
();
// sets
if
(
!
tokens
)
{
xml
.
writeStartElement
(
"sets"
);
QHashIterator
<
QString
,
CardSet
*>
setIterator
(
setHash
);
while
(
setIterator
.
hasNext
())
xml
<<
setIterator
.
next
().
value
();
xml
.
writeEndElement
();
// sets
}
xml
.
writeStartElement
(
"cards"
);
QHashIterator
<
QString
,
CardInfo
*>
cardIterator
(
cardHash
);
while
(
cardIterator
.
hasNext
())
xml
<<
cardIterator
.
next
().
value
();
while
(
cardIterator
.
hasNext
())
{
CardInfo
*
card
=
cardIterator
.
next
().
value
();
if
(
card
->
getIsToken
()
==
tokens
)
xml
<<
card
;
}
xml
.
writeEndElement
();
// cards
xml
.
writeEndElement
();
// cockatrice_carddatabase
...
...
@@ -669,13 +717,13 @@ void CardDatabase::picDownloadChanged()
}
}
bool
CardDatabase
::
loadCardDatabase
(
const
QString
&
path
)
bool
CardDatabase
::
loadCardDatabase
(
const
QString
&
path
,
bool
tokens
)
{
bool
tempLoadSuccess
=
false
;
if
(
!
path
.
isEmpty
())
loadSuccess
=
loadFromFile
(
path
);
else
loadSuccess
=
false
;
tempLoadSuccess
=
loadFromFile
(
path
,
tokens
);
if
(
l
oadSuccess
)
{
if
(
tempL
oadSuccess
)
{
SetList
allSets
;
QHashIterator
<
QString
,
CardSet
*>
setsIterator
(
setHash
);
while
(
setsIterator
.
hasNext
())
...
...
@@ -687,12 +735,20 @@ bool CardDatabase::loadCardDatabase(const QString &path)
emit
cardListChanged
();
}
return
loadSuccess
;
if
(
!
tokens
)
loadSuccess
=
tempLoadSuccess
;
return
tempLoadSuccess
;
}
void
CardDatabase
::
loadCardDatabase
()
{
loadCardDatabase
(
settingsCache
->
getCardDatabasePath
(),
false
);
}
bool
CardDatabase
::
load
Card
Database
()
void
CardDatabase
::
load
Token
Database
()
{
return
loadCardDatabase
(
settingsCache
->
get
Card
DatabasePath
());
loadCardDatabase
(
settingsCache
->
get
Token
DatabasePath
()
,
true
);
}
QStringList
CardDatabase
::
getAllColors
()
const
...
...
cockatrice/src/carddatabase.h
View file @
3ba39526
...
...
@@ -130,7 +130,11 @@ public:
const
QString
&
getText
()
const
{
return
text
;
}
const
int
&
getLoyalty
()
const
{
return
loyalty
;
}
bool
getCipt
()
const
{
return
cipt
;
}
void
setText
(
const
QString
&
_text
)
{
text
=
_text
;
}
void
setManaCost
(
const
QString
&
_manaCost
)
{
manacost
=
_manaCost
;
emit
cardInfoChanged
(
this
);
}
void
setCardType
(
const
QString
&
_cardType
)
{
cardtype
=
_cardType
;
emit
cardInfoChanged
(
this
);
}
void
setPowTough
(
const
QString
&
_powTough
)
{
powtough
=
_powTough
;
emit
cardInfoChanged
(
this
);
}
void
setText
(
const
QString
&
_text
)
{
text
=
_text
;
emit
cardInfoChanged
(
this
);
}
void
setColors
(
const
QStringList
&
_colors
)
{
colors
=
_colors
;
emit
cardInfoChanged
(
this
);
}
const
QStringList
&
getColors
()
const
{
return
colors
;
}
QString
getPicURL
(
const
QString
&
set
)
const
{
return
picURLs
.
value
(
set
);
}
QString
getPicURLHq
(
const
QString
&
set
)
const
{
return
picURLsHq
.
value
(
set
);
}
...
...
@@ -141,7 +145,7 @@ public:
QString
getCorrectedName
()
const
;
int
getTableRow
()
const
{
return
tableRow
;
}
void
setTableRow
(
int
_tableRow
)
{
tableRow
=
_tableRow
;
}
void
setLoyalty
(
int
_loyalty
)
{
loyalty
=
_loyalty
;
}
void
setLoyalty
(
int
_loyalty
)
{
loyalty
=
_loyalty
;
emit
cardInfoChanged
(
this
);
}
void
setPicURL
(
const
QString
&
_set
,
const
QString
&
_picURL
)
{
picURLs
.
insert
(
_set
,
_picURL
);
}
void
setPicURLHq
(
const
QString
&
_set
,
const
QString
&
_picURL
)
{
picURLsHq
.
insert
(
_set
,
_picURL
);
}
void
setPicURLSt
(
const
QString
&
_set
,
const
QString
&
_picURL
)
{
picURLsSt
.
insert
(
_set
,
_picURL
);
}
...
...
@@ -155,6 +159,7 @@ public slots:
void
updatePixmapCache
();
signals:
void
pixmapUpdated
();
void
cardInfoChanged
(
CardInfo
*
card
);
};
class
CardDatabase
:
public
QObject
{
...
...
@@ -175,12 +180,14 @@ public:
CardDatabase
(
QObject
*
parent
=
0
);
~
CardDatabase
();
void
clear
();
CardInfo
*
getCard
(
const
QString
&
cardName
=
QString
());
void
addCard
(
CardInfo
*
card
);
void
removeCard
(
CardInfo
*
card
);
CardInfo
*
getCard
(
const
QString
&
cardName
=
QString
(),
bool
createIfNotFound
=
true
);
CardSet
*
getSet
(
const
QString
&
setName
);
QList
<
CardInfo
*>
getCardList
()
const
{
return
cardHash
.
values
();
}
SetList
getSetList
()
const
;
bool
loadFromFile
(
const
QString
&
fileName
);
bool
saveToFile
(
const
QString
&
fileName
);
bool
loadFromFile
(
const
QString
&
fileName
,
bool
tokens
=
false
);
bool
saveToFile
(
const
QString
&
fileName
,
bool
tokens
=
false
);
QStringList
getAllColors
()
const
;
QStringList
getAllMainCardTypes
()
const
;
bool
getLoadSuccess
()
const
{
return
loadSuccess
;
}
...
...
@@ -188,14 +195,18 @@ public:
void
loadImage
(
CardInfo
*
card
);
public
slots
:
void
clearPixmapCache
();
bool
loadCardDatabase
(
const
QString
&
path
);
bool
loadCardDatabase
();
bool
loadCardDatabase
(
const
QString
&
path
,
bool
tokens
=
false
);
private
slots
:
void
imageLoaded
(
CardInfo
*
card
,
QImage
image
);
void
picDownloadChanged
();
void
picsPathChanged
();
void
loadCardDatabase
();
void
loadTokenDatabase
();
signals:
void
cardListChanged
();
void
cardAdded
(
CardInfo
*
card
);
void
cardRemoved
(
CardInfo
*
card
);
};
#endif
cockatrice/src/carddatabasemodel.cpp
View file @
3ba39526
...
...
@@ -4,12 +4,13 @@ CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
:
QAbstractListModel
(
parent
),
db
(
_db
)
{
connect
(
db
,
SIGNAL
(
cardListChanged
()),
this
,
SLOT
(
updateCardList
()));
cardList
=
db
->
getCardList
();
connect
(
db
,
SIGNAL
(
cardAdded
(
CardInfo
*
)),
this
,
SLOT
(
cardAdded
(
CardInfo
*
)));
connect
(
db
,
SIGNAL
(
cardRemoved
(
CardInfo
*
)),
this
,
SLOT
(
cardRemoved
(
CardInfo
*
)));
updateCardList
();
}
CardDatabaseModel
::~
CardDatabaseModel
()
{
}
int
CardDatabaseModel
::
rowCount
(
const
QModelIndex
&
/*parent*/
)
const
...
...
@@ -66,10 +67,44 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
void
CardDatabaseModel
::
updateCardList
()
{
for
(
int
i
=
0
;
i
<
cardList
.
size
();
++
i
)
disconnect
(
cardList
[
i
],
0
,
this
,
0
);
cardList
=
db
->
getCardList
();
for
(
int
i
=
0
;
i
<
cardList
.
size
();
++
i
)
connect
(
cardList
[
i
],
SIGNAL
(
cardInfoChanged
(
CardInfo
*
)),
this
,
SLOT
(
cardInfoChanged
(
CardInfo
*
)));
reset
();
}
void
CardDatabaseModel
::
cardInfoChanged
(
CardInfo
*
card
)
{
const
int
row
=
cardList
.
indexOf
(
card
);
if
(
row
==
-
1
)
return
;
emit
dataChanged
(
index
(
row
,
0
),
index
(
row
,
4
));
}
void
CardDatabaseModel
::
cardAdded
(
CardInfo
*
card
)
{
beginInsertRows
(
QModelIndex
(),
cardList
.
size
(),
cardList
.
size
());
cardList
.
append
(
card
);
connect
(
card
,
SIGNAL
(
cardInfoChanged
(
CardInfo
*
)),
this
,
SLOT
(
cardInfoChanged
(
CardInfo
*
)));
endInsertRows
();
}
void
CardDatabaseModel
::
cardRemoved
(
CardInfo
*
card
)
{
const
int
row
=
cardList
.
indexOf
(
card
);
if
(
row
==
-
1
)
return
;
beginRemoveRows
(
QModelIndex
(),
row
,
row
);
cardList
.
removeAt
(
row
);
endRemoveRows
();
}
CardDatabaseDisplayModel
::
CardDatabaseDisplayModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
),
isToken
(
ShowAll
)
...
...
cockatrice/src/carddatabasemodel.h
View file @
3ba39526
...
...
@@ -16,12 +16,15 @@ public:
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
=
Qt
::
DisplayRole
)
const
;
CardInfo
const
*
getCard
(
int
index
)
const
{
return
cardList
[
index
];
}
CardInfo
*
getCard
(
int
index
)
const
{
return
cardList
[
index
];
}
private:
QList
<
CardInfo
*>
cardList
;
CardDatabase
*
db
;
private
slots
:
void
updateCardList
();
void
cardAdded
(
CardInfo
*
card
);
void
cardRemoved
(
CardInfo
*
card
);
void
cardInfoChanged
(
CardInfo
*
card
);
};
class
CardDatabaseDisplayModel
:
public
QSortFilterProxyModel
{
...
...
cockatrice/src/dlg_create_token.cpp
View file @
3ba39526
...
...
@@ -123,7 +123,7 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
void
DlgCreateToken
::
tokenSelectionChanged
(
const
QModelIndex
&
current
,
const
QModelIndex
&
/*previous*/
)
{
const
QModelIndex
realIndex
=
cardDatabaseDisplayModel
->
mapToSource
(
current
);
const
CardInfo
*
cardInfo
=
cardDatabaseModel
->
getCard
(
realIndex
.
row
());
const
CardInfo
*
cardInfo
=
current
.
row
()
>=
0
?
cardDatabaseModel
->
getCard
(
realIndex
.
row
())
:
db
->
getCard
()
;
nameEdit
->
setText
(
cardInfo
->
getName
());
const
QString
cardColor
=
cardInfo
->
getColors
().
isEmpty
()
?
QString
()
:
(
cardInfo
->
getColors
().
size
()
>
1
?
QString
(
"m"
)
:
cardInfo
->
getColors
().
first
());
...
...
cockatrice/src/dlg_edit_tokens.cpp
0 → 100644
View file @
3ba39526
#include
"dlg_edit_tokens.h"
#include
"carddatabasemodel.h"
#include
"main.h"
#include
<QDialogButtonBox>
#include
<QVBoxLayout>
#include
<QHBoxLayout>
#include
<QGridLayout>
#include
<QLabel>
#include
<QComboBox>
#include
<QLineEdit>
#include
<QGroupBox>
#include
<QTreeView>
#include
<QHeaderView>
#include
<QToolBar>
#include
<QAction>
#include
<QInputDialog>
#include
<QMessageBox>
DlgEditTokens
::
DlgEditTokens
(
QWidget
*
parent
)
:
QDialog
(
parent
),
currentCard
(
0
)
{
nameLabel
=
new
QLabel
(
tr
(
"&Name:"
));
nameEdit
=
new
QLineEdit
;
nameEdit
->
setEnabled
(
false
);
nameLabel
->
setBuddy
(
nameEdit
);
colorLabel
=
new
QLabel
(
tr
(
"C&olor:"
));
colorEdit
=
new
QComboBox
;
colorEdit
->
addItem
(
tr
(
"white"
),
"w"
);
colorEdit
->
addItem
(
tr
(
"blue"
),
"u"
);
colorEdit
->
addItem
(
tr
(
"black"
),
"b"
);
colorEdit
->
addItem
(
tr
(
"red"
),
"r"
);
colorEdit
->
addItem
(
tr
(
"green"
),
"g"
);
colorEdit
->
addItem
(
tr
(
"multicolor"
),
"m"
);
colorEdit
->
addItem
(
tr
(
"colorless"
),
QString
());
colorLabel
->
setBuddy
(
colorEdit
);
connect
(
colorEdit
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
colorChanged
(
int
)));
ptLabel
=
new
QLabel
(
tr
(
"&P/T:"
));
ptEdit
=
new
QLineEdit
;
ptLabel
->
setBuddy
(
ptEdit
);
connect
(
ptEdit
,
SIGNAL
(
textChanged
(
QString
)),
this
,
SLOT
(
ptChanged
(
QString
)));
annotationLabel
=
new
QLabel
(
tr
(
"&Annotation:"
));
annotationEdit
=
new
QLineEdit
;
annotationLabel
->
setBuddy
(
annotationEdit
);
connect
(
annotationEdit
,
SIGNAL
(
textChanged
(
QString
)),
this
,
SLOT
(
annotationChanged
(
QString
)));
QGridLayout
*
grid
=
new
QGridLayout
;
grid
->
addWidget
(
nameLabel
,
0
,
0
);
grid
->
addWidget
(
nameEdit
,
0
,
1
);
grid
->
addWidget
(
colorLabel
,
1
,
0
);
grid
->
addWidget
(
colorEdit
,
1
,
1
);
grid
->
addWidget
(
ptLabel
,
2
,
0
);
grid
->
addWidget
(
ptEdit
,
2
,
1
);
grid
->
addWidget
(
annotationLabel
,
3
,
0
);
grid
->
addWidget
(
annotationEdit
,
3
,
1
);
QGroupBox
*
tokenDataGroupBox
=
new
QGroupBox
(
tr
(
"Token data"
));
tokenDataGroupBox
->
setLayout
(
grid
);
cardDatabaseModel
=
new
CardDatabaseModel
(
db
,
this
);
cardDatabaseDisplayModel
=
new
CardDatabaseDisplayModel
(
this
);
cardDatabaseDisplayModel
->
setSourceModel
(
cardDatabaseModel
);
cardDatabaseDisplayModel
->
setIsToken
(
CardDatabaseDisplayModel
::
ShowTrue
);
chooseTokenView
=
new
QTreeView
;
chooseTokenView
->
setModel
(
cardDatabaseDisplayModel
);
chooseTokenView
->
setUniformRowHeights
(
true
);
chooseTokenView
->
setRootIsDecorated
(
false
);
chooseTokenView
->
setAlternatingRowColors
(
true
);
chooseTokenView
->
setSortingEnabled
(
true
);
chooseTokenView
->
sortByColumn
(
0
,
Qt
::
AscendingOrder
);
chooseTokenView
->
resizeColumnToContents
(
0
);
chooseTokenView
->
header
()
->
setStretchLastSection
(
false
);
chooseTokenView
->
header
()
->
hideSection
(
1
);
chooseTokenView
->
header
()
->
hideSection
(
2
);
chooseTokenView
->
header
()
->
setResizeMode
(
3
,
QHeaderView
::
ResizeToContents
);
chooseTokenView
->
header
()
->
setResizeMode
(
4
,
QHeaderView
::
ResizeToContents
);
connect
(
chooseTokenView
->
selectionModel
(),
SIGNAL
(
currentRowChanged
(
QModelIndex
,
QModelIndex
)),
this
,
SLOT
(
tokenSelectionChanged
(
QModelIndex
,
QModelIndex
)));
QAction
*
aAddToken
=
new
QAction
(
tr
(
"Add token"
),
this
);
aAddToken
->
setIcon
(
QIcon
(
":/resources/increment.svg"
));
connect
(
aAddToken
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actAddToken
()));
QAction
*
aRemoveToken
=
new
QAction
(
tr
(
"Remove token"
),
this
);
aRemoveToken
->
setIcon
(
QIcon
(
":/resources/decrement.svg"
));
connect
(
aRemoveToken
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actRemoveToken
()));
QToolBar
*
databaseToolBar
=
new
QToolBar
;
databaseToolBar
->
addAction
(
aAddToken
);
databaseToolBar
->
addAction
(
aRemoveToken
);
QVBoxLayout
*
leftVBox
=
new
QVBoxLayout
;
leftVBox
->
addWidget
(
chooseTokenView
);
leftVBox
->
addWidget
(
databaseToolBar
);
QHBoxLayout
*
hbox
=
new
QHBoxLayout
;
hbox
->
addLayout
(
leftVBox
);
hbox
->
addWidget
(
tokenDataGroupBox
);
QDialogButtonBox
*
buttonBox
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Close
);
connect
(
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
accept
()));
connect
(
buttonBox
,
SIGNAL
(
rejected
()),
this
,
SLOT
(
reject
()));
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addLayout
(
hbox
);
mainLayout
->
addWidget
(
buttonBox
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Edit tokens"
));
}
void
DlgEditTokens
::
tokenSelectionChanged
(
const
QModelIndex
&
current
,
const
QModelIndex
&
previous
)
{
const
QModelIndex
realIndex
=
cardDatabaseDisplayModel
->
mapToSource
(
current
);
CardInfo
*
cardInfo
=
current
.
row
()
>=
0
?
cardDatabaseModel
->
getCard
(
realIndex
.
row
())
:
db
->
getCard
();
if
(
!
cardInfo
->
getName
().
isEmpty
())
currentCard
=
cardInfo
;
else
currentCard
=
0
;
nameEdit
->
setText
(
cardInfo
->
getName
());
const
QString
cardColor
=
cardInfo
->
getColors
().
isEmpty
()
?
QString
()
:
(
cardInfo
->
getColors
().
size
()
>
1
?
QString
(
"m"
)
:
cardInfo
->
getColors
().
first
());
colorEdit
->
setCurrentIndex
(
colorEdit
->
findData
(
cardColor
,
Qt
::
UserRole
,
Qt
::
MatchFixedString
));
ptEdit
->
setText
(
cardInfo
->
getPowTough
());
annotationEdit
->
setText
(
cardInfo
->
getText
());
}
void
DlgEditTokens
::
actAddToken
()
{
QString
name
;
bool
askAgain
;
do
{
name
=
QInputDialog
::
getText
(
this
,
tr
(
"Add token"
),
tr
(
"Please enter the name of the token:"
));
if
(
!
name
.
isEmpty
()
&&
db
->
getCard
(
name
,
false
))
{
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"The chosen name conflicts with an existing card or token."
));
askAgain
=
true
;
}
else
askAgain
=
false
;
}
while
(
askAgain
);
if
(
name
.
isEmpty
())
return
;
CardInfo
*
card
=
new
CardInfo
(
db
,
name
,
true
);
card
->
addToSet
(
db
->
getSet
(
"TK"
));
card
->
setCardType
(
"Token"
);
db
->
addCard
(
card
);
}
void
DlgEditTokens
::
actRemoveToken
()
{
if
(
currentCard
)
{
db
->
removeCard
(
currentCard
);
delete
currentCard
;
currentCard
=
0
;
}
}
void
DlgEditTokens
::
colorChanged
(
int
colorIndex
)
{
if
(
currentCard
)
currentCard
->
setColors
(
QStringList
()
<<
colorEdit
->
itemData
(
colorIndex
).
toString
());
}
void
DlgEditTokens
::
ptChanged
(
const
QString
&
_pt
)
{
if
(
currentCard
)
currentCard
->
setPowTough
(
_pt
);
}
void
DlgEditTokens
::
annotationChanged
(
const
QString
&
_annotation
)
{
if
(
currentCard
)
currentCard
->
setText
(
_annotation
);
}
cockatrice/src/dlg_edit_tokens.h
0 → 100644
View file @
3ba39526
#ifndef DLG_EDIT_TOKENS_H
#define DLG_EDIT_TOKENS_H
#include
<QDialog>
class
QModelIndex
;
class
CardDatabaseModel
;
class
CardDatabaseDisplayModel
;
class
QLabel
;
class
QComboBox
;
class
QLineEdit
;
class
QTreeView
;
class
CardInfo
;
class
DlgEditTokens
:
public
QDialog
{
Q_OBJECT
private
slots
:
void
tokenSelectionChanged
(
const
QModelIndex
&
current
,
const
QModelIndex
&
previous
);
void
colorChanged
(
int
_colorIndex
);
void
ptChanged
(
const
QString
&
_pt
);
void
annotationChanged
(
const
QString
&
_annotation
);
void
actAddToken
();
void
actRemoveToken
();
private:
CardInfo
*
currentCard
;
CardDatabaseModel
*
cardDatabaseModel
;
CardDatabaseDisplayModel
*
cardDatabaseDisplayModel
;
QStringList
predefinedTokens
;
QLabel
*
nameLabel
,
*
colorLabel
,
*
ptLabel
,
*
annotationLabel
;
QComboBox
*
colorEdit
;
QLineEdit
*
nameEdit
,
*
ptEdit
,
*
annotationEdit
;
QTreeView
*
chooseTokenView
;
public:
DlgEditTokens
(
QWidget
*
parent
=
0
);
};
#endif
cockatrice/src/dlg_settings.cpp
View file @
3ba39526
...
...
@@ -27,8 +27,6 @@ GeneralSettingsPage::GeneralSettingsPage()
{
languageLabel
=
new
QLabel
;
languageBox
=
new
QComboBox
;
customTranslationButton
=
new
QPushButton
(
"..."
);
customTranslationButton
->
setMaximumWidth
(
50
);
QString
setLanguage
=
settingsCache
->
getLang
();
QStringList
qmFiles
=
findQmFiles
();
...
...
@@ -43,14 +41,12 @@ GeneralSettingsPage::GeneralSettingsPage()
picDownloadCheckBox
->
setChecked
(
settingsCache
->
getPicDownload
());
connect
(
languageBox
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
languageBoxChanged
(
int
)));
connect
(
customTranslationButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
customTranslationButtonClicked
()));
connect
(
picDownloadCheckBox
,
SIGNAL
(
stateChanged
(
int
)),
settingsCache
,
SLOT
(
setPicDownload
(
int
)));
QGridLayout
*
personalGrid
=
new
QGridLayout
;
personalGrid
->
addWidget
(
languageLabel
,
0
,
0
);
personalGrid
->
addWidget
(
languageBox
,
0
,
1
);
personalGrid
->
addWidget
(
customTranslationButton
,
0
,
2
);
personalGrid
->
addWidget
(
picDownloadCheckBox
,
1
,
0
,
1
,
3
);
personalGrid
->
addWidget
(
picDownloadCheckBox
,
1
,
0
,
1
,
2
);
personalGroupBox
=
new
QGroupBox
;
personalGroupBox
->
setLayout
(
personalGrid
);
...
...
@@ -79,6 +75,12 @@ GeneralSettingsPage::GeneralSettingsPage()
QPushButton
*
cardDatabasePathButton
=
new
QPushButton
(
"..."
);
connect
(
cardDatabasePathButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
cardDatabasePathButtonClicked
()));
tokenDatabasePathLabel
=
new
QLabel
;
tokenDatabasePathEdit
=
new
QLineEdit
(
settingsCache
->
getTokenDatabasePath
());
tokenDatabasePathEdit
->
setReadOnly
(
true
);
QPushButton
*
tokenDatabasePathButton
=
new
QPushButton
(
"..."
);
connect
(
tokenDatabasePathButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
tokenDatabasePathButtonClicked
()));
QGridLayout
*
pathsGrid
=
new
QGridLayout
;
pathsGrid
->
addWidget
(
deckPathLabel
,
0
,
0
);
pathsGrid
->
addWidget
(
deckPathEdit
,
0
,
1
);
...
...
@@ -92,6 +94,9 @@ GeneralSettingsPage::GeneralSettingsPage()
pathsGrid
->
addWidget
(
cardDatabasePathLabel
,
3
,
0
);
pathsGrid
->
addWidget
(
cardDatabasePathEdit
,
3
,
1
);
pathsGrid
->
addWidget
(
cardDatabasePathButton
,
3
,
2
);
pathsGrid
->
addWidget
(
tokenDatabasePathLabel
,
4
,
0
);
pathsGrid
->
addWidget
(
tokenDatabasePathEdit
,
4
,
1
);
pathsGrid
->
addWidget
(
tokenDatabasePathButton
,
4
,
2
);
pathsGroupBox
=
new
QGroupBox
;
pathsGroupBox
->
setLayout
(
pathsGrid
);
...
...
@@ -158,19 +163,19 @@ void GeneralSettingsPage::cardDatabasePathButtonClicked()
settingsCache
->
setCardDatabasePath
(
path
);
}
void
GeneralSettingsPage
::
languageBoxChanged
(
int
index
)
{
settingsCache
->
setCustomTranslationFile
(
QString
());
settingsCache
->
setLang
(
languageBox
->
itemData
(
index
).
toString
());
}
void
GeneralSettingsPage
::
customTranslationButtonClicked
()
void
GeneralSettingsPage
::
tokenDatabasePathButtonClicked
()
{
QString
path
=
QFileDialog
::
getOpenFileName
(
this
,
tr
(
"Choose path"
));
if
(
path
.
isEmpty
())
return
;
settingsCache
->
setCustomTranslationFile
(
path
);
tokenDatabasePathEdit
->
setText
(
path
);
settingsCache
->
setTokenDatabasePath
(
path
);
}
void
GeneralSettingsPage
::
languageBoxChanged
(
int
index
)
{
settingsCache
->
setLang
(
languageBox
->
itemData
(
index
).
toString
());
}
void
GeneralSettingsPage
::
retranslateUi
()
...
...
@@ -183,6 +188,7 @@ void GeneralSettingsPage::retranslateUi()
replaysPathLabel
->
setText
(
tr
(
"Replays directory:"
));
picsPathLabel
->
setText
(
tr
(
"Pictures directory:"
));
cardDatabasePathLabel
->
setText
(
tr
(
"Path to card database:"
));
tokenDatabasePathLabel
->
setText
(
tr
(
"Path to token database:"
));
}
AppearanceSettingsPage
::
AppearanceSettingsPage
()
...
...
@@ -590,7 +596,6 @@ DlgSettings::DlgSettings(QWidget *parent)
:
QDialog
(
parent
)
{
connect
(
settingsCache
,
SIGNAL
(
langChanged
()),
this
,
SLOT
(
updateLanguage
()));
connect
(
settingsCache
,
SIGNAL
(
customTranslationFileChanged
()),
this
,
SLOT
(
updateLanguage
()));
contentsWidget
=
new
QListWidget
;
contentsWidget
->
setViewMode
(
QListView
::
IconMode
);
...
...
cockatrice/src/dlg_settings.h
View file @
3ba39526
...
...
@@ -27,21 +27,20 @@ public:
GeneralSettingsPage
();
void
retranslateUi
();
private
slots
:
void
customTranslationButtonClicked
();
void
deckPathButtonClicked
();
void
replaysPathButtonClicked
();
void
picsPathButtonClicked
();
void
cardDatabasePathButtonClicked
();
void
tokenDatabasePathButtonClicked
();
void
languageBoxChanged
(
int
index
);
private:
QStringList
findQmFiles
();
QString
languageName
(
const
QString
&
qmFile
);
QPushButton
*
customTranslationButton
;
QLineEdit
*
deckPathEdit
,
*
replaysPathEdit
,
*
picsPathEdit
,
*
cardDatabasePathEdit
;
QLineEdit
*
deckPathEdit
,
*
replaysPathEdit
,
*
picsPathEdit
,
*
cardDatabasePathEdit
,
*
tokenDatabasePathEdit
;
QGroupBox
*
personalGroupBox
,
*
pathsGroupBox
;
QComboBox
*
languageBox
;
QCheckBox
*
picDownloadCheckBox
;
QLabel
*
languageLabel
,
*
deckPathLabel
,
*
replaysPathLabel
,
*
picsPathLabel
,
*
cardDatabasePathLabel
;
QLabel
*
languageLabel
,
*
deckPathLabel
,
*
replaysPathLabel
,
*
picsPathLabel
,
*
cardDatabasePathLabel
,
*
tokenDatabasePathLabel
;
};
class
AppearanceSettingsPage
:
public
AbstractSettingsPage
{
...
...
cockatrice/src/main.cpp
View file @
3ba39526
...
...
@@ -71,10 +71,7 @@ void installNewTranslator()
qApp
->
installTranslator
(
qtTranslator
);
if
(
!
translationPath
.
startsWith
(
"/"
))
translationPath
.
prepend
(
qApp
->
applicationDirPath
()
+
"/"
);
if
(
!
settingsCache
->
getCustomTranslationFile
().
isEmpty
())
translator
->
load
(
settingsCache
->
getCustomTranslationFile
());
else
translator
->
load
(
translationPrefix
+
"_"
+
lang
,
translationPath
);
translator
->
load
(
translationPrefix
+
"_"
+
lang
,
translationPath
);
qApp
->
installTranslator
(
translator
);
}
...
...
@@ -117,6 +114,8 @@ int main(int argc, char *argv[])
if
(
!
db
->
getLoadSuccess
())
if
(
db
->
loadCardDatabase
(
dataDir
+
"/cards.xml"
))
settingsCache
->
setCardDatabasePath
(
dataDir
+
"/cards.xml"
);
if
(
settingsCache
->
getTokenDatabasePath
().
isEmpty
())
settingsCache
->
setTokenDatabasePath
(
dataDir
+
"/tokens.xml"
);
if
(
!
QDir
(
settingsCache
->
getDeckPath
()).
exists
()
||
settingsCache
->
getDeckPath
().
isEmpty
())
{
QDir
().
mkpath
(
dataDir
+
"/decks"
);
settingsCache
->
setDeckPath
(
dataDir
+
"/decks"
);
...
...
cockatrice/src/settingscache.cpp
View file @
3ba39526
...
...
@@ -5,13 +5,13 @@ SettingsCache::SettingsCache()
{
settings
=
new
QSettings
(
this
);
customTranslationFile
=
settings
->
value
(
"personal/custom_translation"
).
toString
();
lang
=
settings
->
value
(
"personal/lang"
).
toString
();
deckPath
=
settings
->
value
(
"paths/decks"
).
toString
();
replaysPath
=
settings
->
value
(
"paths/replays"
).
toString
();
picsPath
=
settings
->
value
(
"paths/pics"
).
toString
();
cardDatabasePath
=
settings
->
value
(
"paths/carddatabase"
).
toString
();
tokenDatabasePath
=
settings
->
value
(
"paths/tokendatabase"
).
toString
();
handBgPath
=
settings
->
value
(
"zonebg/hand"
).
toString
();
stackBgPath
=
settings
->
value
(
"zonebg/stack"
).
toString
();
...
...
@@ -41,13 +41,6 @@ SettingsCache::SettingsCache()
ignoreUnregisteredUsers
=
settings
->
value
(
"chat/ignore_unregistered"
,
false
).
toBool
();
}
void
SettingsCache
::
setCustomTranslationFile
(
const
QString
&
_customTranslationFile
)
{
customTranslationFile
=
_customTranslationFile
;
settings
->
setValue
(
"personal/custom_translation"
,
customTranslationFile
);
emit
customTranslationFileChanged
();
}
void
SettingsCache
::
setLang
(
const
QString
&
_lang
)
{
lang
=
_lang
;
...
...
@@ -81,6 +74,13 @@ void SettingsCache::setCardDatabasePath(const QString &_cardDatabasePath)
emit
cardDatabasePathChanged
();
}
void
SettingsCache
::
setTokenDatabasePath
(
const
QString
&
_tokenDatabasePath
)
{
tokenDatabasePath
=
_tokenDatabasePath
;
settings
->
setValue
(
"paths/tokendatabase"
,
tokenDatabasePath
);
emit
tokenDatabasePathChanged
();
}
void
SettingsCache
::
setHandBgPath
(
const
QString
&
_handBgPath
)
{
handBgPath
=
_handBgPath
;
...
...
cockatrice/src/settingscache.h
View file @
3ba39526
...
...
@@ -8,10 +8,10 @@ class QSettings;
class
SettingsCache
:
public
QObject
{
Q_OBJECT
signals:
void
customTranslationFileChanged
();
void
langChanged
();
void
picsPathChanged
();
void
cardDatabasePathChanged
();
void
tokenDatabasePathChanged
();
void
handBgPathChanged
();
void
stackBgPathChanged
();
void
tableBgPathChanged
();
...
...
@@ -29,8 +29,8 @@ private:
QSettings
*
settings
;
QByteArray
mainWindowGeometry
;
QString
customTranslationFile
,
lang
;
QString
deckPath
,
replaysPath
,
picsPath
,
cardDatabasePath
;
QString
lang
;
QString
deckPath
,
replaysPath
,
picsPath
,
cardDatabasePath
,
tokenDatabasePath
;
QString
handBgPath
,
stackBgPath
,
tableBgPath
,
playerBgPath
,
cardBackPicturePath
;
bool
picDownload
;
bool
doubleClickToPlay
;
...
...
@@ -49,12 +49,12 @@ private:
public:
SettingsCache
();
const
QByteArray
&
getMainWindowGeometry
()
const
{
return
mainWindowGeometry
;
}
QString
getCustomTranslationFile
()
const
{
return
customTranslationFile
;
}
QString
getLang
()
const
{
return
lang
;
}
QString
getDeckPath
()
const
{
return
deckPath
;
}
QString
getReplaysPath
()
const
{
return
replaysPath
;
}
QString
getPicsPath
()
const
{
return
picsPath
;
}
QString
getCardDatabasePath
()
const
{
return
cardDatabasePath
;
}
QString
getTokenDatabasePath
()
const
{
return
tokenDatabasePath
;
}
QString
getHandBgPath
()
const
{
return
handBgPath
;
}
QString
getStackBgPath
()
const
{
return
stackBgPath
;
}
QString
getTableBgPath
()
const
{
return
tableBgPath
;
}
...
...
@@ -77,12 +77,12 @@ public:
bool
getIgnoreUnregisteredUsers
()
const
{
return
ignoreUnregisteredUsers
;
}
public
slots
:
void
setMainWindowGeometry
(
const
QByteArray
&
_mainWindowGeometry
);
void
setCustomTranslationFile
(
const
QString
&
_customTranslationFile
);
void
setLang
(
const
QString
&
_lang
);
void
setDeckPath
(
const
QString
&
_deckPath
);
void
setReplaysPath
(
const
QString
&
_replaysPath
);
void
setPicsPath
(
const
QString
&
_picsPath
);
void
setCardDatabasePath
(
const
QString
&
_cardDatabasePath
);
void
setTokenDatabasePath
(
const
QString
&
_tokenDatabasePath
);
void
setHandBgPath
(
const
QString
&
_handBgPath
);
void
setStackBgPath
(
const
QString
&
_stackBgPath
);
void
setTableBgPath
(
const
QString
&
_tableBgPath
);
...
...
cockatrice/src/tab_deck_editor.cpp
View file @
3ba39526
...
...
@@ -24,6 +24,7 @@
#include
"cardinfowidget.h"
#include
"dlg_cardsearch.h"
#include
"dlg_load_deck_from_clipboard.h"
#include
"dlg_edit_tokens.h"
#include
"main.h"
#include
"settingscache.h"
#include
"priceupdater.h"
...
...
@@ -41,7 +42,7 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
}
TabDeckEditor
::
TabDeckEditor
(
TabSupervisor
*
_tabSupervisor
,
QWidget
*
parent
)
:
Tab
(
_tabSupervisor
,
parent
)
:
Tab
(
_tabSupervisor
,
parent
)
,
modified
(
false
)
{
aSearch
=
new
QAction
(
QString
(),
this
);
aSearch
->
setIcon
(
QIcon
(
":/resources/icon_search.svg"
));
...
...
@@ -161,8 +162,6 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
mainLayout
->
addLayout
(
rightFrame
,
10
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Deck editor [*]"
));
aNewDeck
=
new
QAction
(
QString
(),
this
);
aNewDeck
->
setShortcuts
(
QKeySequence
::
New
);
connect
(
aNewDeck
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actNewDeck
()));
...
...
@@ -181,15 +180,16 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
aSaveDeckToClipboard
=
new
QAction
(
QString
(),
this
);
connect
(
aSaveDeckToClipboard
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actSaveDeckToClipboard
()));
aSaveDeckToClipboard
->
setShortcuts
(
QKeySequence
::
Copy
);
aPrintDeck
=
new
QAction
(
tr
(
"&Print deck..."
),
this
);
aPrintDeck
=
new
QAction
(
QString
(
),
this
);
aPrintDeck
->
setShortcuts
(
QKeySequence
::
Print
);
connect
(
aPrintDeck
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actPrintDeck
()));
aClose
=
new
QAction
(
tr
(
"&Close"
),
this
);
aClose
->
setShortcut
(
tr
(
"Ctrl+Q"
));
aClose
=
new
QAction
(
QString
(),
this
);
connect
(
aClose
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
closeRequest
()));
aEditSets
=
new
QAction
(
tr
(
"&Edit sets..."
),
this
);
aEditSets
=
new
QAction
(
QString
(
),
this
);
connect
(
aEditSets
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actEditSets
()));
aEditTokens
=
new
QAction
(
QString
(),
this
);
connect
(
aEditTokens
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actEditTokens
()));
deckMenu
=
new
QMenu
(
this
);
deckMenu
->
addAction
(
aNewDeck
);
...
...
@@ -207,6 +207,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
dbMenu
=
new
QMenu
(
this
);
dbMenu
->
addAction
(
aEditSets
);
dbMenu
->
addAction
(
aEditTokens
);
dbMenu
->
addSeparator
();
dbMenu
->
addAction
(
aSearch
);
dbMenu
->
addAction
(
aClearSearch
);
...
...
@@ -266,6 +267,9 @@ void TabDeckEditor::retranslateUi()
aSaveDeckAs
->
setText
(
tr
(
"Save deck &as..."
));
aLoadDeckFromClipboard
->
setText
(
tr
(
"Load deck from cl&ipboard..."
));
aSaveDeckToClipboard
->
setText
(
tr
(
"Save deck to clip&board"
));
aPrintDeck
->
setText
(
tr
(
"&Print deck..."
));
aClose
->
setText
(
tr
(
"&Close"
));
aClose
->
setShortcut
(
tr
(
"Ctrl+Q"
));
aAddCard
->
setText
(
tr
(
"Add card to &maindeck"
));
aAddCard
->
setShortcuts
(
QList
<
QKeySequence
>
()
<<
QKeySequence
(
tr
(
"Return"
))
<<
QKeySequence
(
tr
(
"Enter"
)));
...
...
@@ -280,12 +284,15 @@ void TabDeckEditor::retranslateUi()
deckMenu
->
setTitle
(
tr
(
"&Deck editor"
));
dbMenu
->
setTitle
(
tr
(
"C&ard database"
));
aEditSets
->
setText
(
tr
(
"&Edit sets..."
));
aEditTokens
->
setText
(
tr
(
"Edit &tokens..."
));
}
QString
TabDeckEditor
::
getTabText
()
const
{
QString
result
=
tr
(
"Deck: %1"
).
arg
(
nameEdit
->
text
());
if
(
isWindowM
odified
()
)
if
(
m
odified
)
result
.
prepend
(
"* "
);
return
result
;
}
...
...
@@ -293,13 +300,13 @@ QString TabDeckEditor::getTabText() const
void
TabDeckEditor
::
updateName
(
const
QString
&
name
)
{
deckModel
->
getDeckList
()
->
setName
(
name
);
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
updateComments
()
{
deckModel
->
getDeckList
()
->
setComments
(
commentsEdit
->
toPlainText
());
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
updateCardInfoLeft
(
const
QModelIndex
&
current
,
const
QModelIndex
&
/*previous*/
)
...
...
@@ -330,7 +337,7 @@ void TabDeckEditor::updateHash()
bool
TabDeckEditor
::
confirmClose
()
{
if
(
isWindowM
odified
()
)
{
if
(
m
odified
)
{
QMessageBox
::
StandardButton
ret
=
QMessageBox
::
warning
(
this
,
tr
(
"Are you sure?"
),
tr
(
"The decklist has been modified.
\n
Do you want to save the changes?"
),
QMessageBox
::
Save
|
QMessageBox
::
Discard
|
QMessageBox
::
Cancel
);
...
...
@@ -357,7 +364,7 @@ void TabDeckEditor::actNewDeck()
nameEdit
->
setText
(
QString
());
commentsEdit
->
setText
(
QString
());
hashLabel
->
setText
(
QString
());
set
Window
Modified
(
false
);
setModified
(
false
);
}
void
TabDeckEditor
::
actLoadDeck
()
...
...
@@ -386,7 +393,7 @@ void TabDeckEditor::saveDeckRemoteFinished(const Response &response)
if
(
response
.
response_code
()
!=
Response
::
RespOk
)
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"The deck could not be saved."
));
else
set
Window
Modified
(
false
);
setModified
(
false
);
}
bool
TabDeckEditor
::
actSaveDeck
()
...
...
@@ -405,7 +412,7 @@ bool TabDeckEditor::actSaveDeck()
}
else
if
(
deck
->
getLastFileName
().
isEmpty
())
return
actSaveDeckAs
();
else
if
(
deck
->
saveToFile
(
deck
->
getLastFileName
(),
deck
->
getLastFileFormat
()))
{
set
Window
Modified
(
false
);
setModified
(
false
);
return
true
;
}
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"The deck could not be saved.
\n
Please check that the directory is writable and try again."
));
...
...
@@ -431,7 +438,7 @@ bool TabDeckEditor::actSaveDeckAs()
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"The deck could not be saved.
\n
Please check that the directory is writable and try again."
));
return
false
;
}
set
Window
Modified
(
false
);
setModified
(
false
);
return
true
;
}
...
...
@@ -445,7 +452,7 @@ void TabDeckEditor::actLoadDeckFromClipboard()
return
;
setDeck
(
dlg
.
getDeckList
());
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
actSaveDeckToClipboard
()
...
...
@@ -471,6 +478,13 @@ void TabDeckEditor::actEditSets()
w
->
show
();
}
void
TabDeckEditor
::
actEditTokens
()
{
DlgEditTokens
dlg
;
dlg
.
exec
();
db
->
saveToFile
(
settingsCache
->
getTokenDatabasePath
(),
true
);
}
void
TabDeckEditor
::
actSearch
()
{
if
(
dlgCardSearch
->
exec
())
{
...
...
@@ -509,7 +523,7 @@ void TabDeckEditor::addCardHelper(QString zoneName)
recursiveExpand
(
newCardIndex
);
deckView
->
setCurrentIndex
(
newCardIndex
);
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
actAddCard
()
...
...
@@ -528,7 +542,7 @@ void TabDeckEditor::actRemoveCard()
if
(
!
currentIndex
.
isValid
()
||
deckModel
->
hasChildren
(
currentIndex
))
return
;
deckModel
->
removeRow
(
currentIndex
.
row
(),
currentIndex
.
parent
());
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
actIncrement
()
...
...
@@ -540,7 +554,7 @@ void TabDeckEditor::actIncrement()
const
int
count
=
deckModel
->
data
(
numberIndex
,
Qt
::
EditRole
).
toInt
();
deckView
->
setCurrentIndex
(
numberIndex
);
deckModel
->
setData
(
numberIndex
,
count
+
1
,
Qt
::
EditRole
);
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
actDecrement
()
...
...
@@ -555,7 +569,7 @@ void TabDeckEditor::actDecrement()
deckModel
->
removeRow
(
currentIndex
.
row
(),
currentIndex
.
parent
());
else
deckModel
->
setData
(
numberIndex
,
count
-
1
,
Qt
::
EditRole
);
set
Window
Modified
(
true
);
setModified
(
true
);
}
void
TabDeckEditor
::
actUpdatePrices
()
...
...
@@ -569,7 +583,7 @@ void TabDeckEditor::actUpdatePrices()
void
TabDeckEditor
::
finishedUpdatingPrices
()
{
deckModel
->
pricesUpdated
();
set
Window
Modified
(
true
);
setModified
(
true
);
aUpdatePrices
->
setDisabled
(
false
);
}
...
...
@@ -582,15 +596,15 @@ void TabDeckEditor::setDeck(DeckLoader *_deck)
updateHash
();
deckModel
->
sort
(
1
);
deckView
->
expandAll
();
set
Window
Modified
(
false
);
setModified
(
false
);
db
->
cacheCardPixmaps
(
deckModel
->
getDeckList
()
->
getCardList
());
deckView
->
expandAll
();
set
Window
Modified
(
false
);
setModified
(
false
);
}
void
TabDeckEditor
::
set
Window
Modified
(
bool
_
windowM
odified
)
void
TabDeckEditor
::
setModified
(
bool
_
m
odified
)
{
Tab
::
setWindowModified
(
_windowM
odified
)
;
modified
=
_m
odified
;
emit
tabTextChanged
(
this
,
getTabText
());
}
cockatrice/src/tab_deck_editor.h
View file @
3ba39526
...
...
@@ -46,6 +46,7 @@ private slots:
void
actPrintDeck
();
void
actEditSets
();
void
actEditTokens
();
void
actSearch
();
void
actClearSearch
();
...
...
@@ -82,15 +83,17 @@ private:
QMenu
*
deckMenu
,
*
dbMenu
;
QAction
*
aNewDeck
,
*
aLoadDeck
,
*
aSaveDeck
,
*
aSaveDeckAs
,
*
aLoadDeckFromClipboard
,
*
aSaveDeckToClipboard
,
*
aPrintDeck
,
*
aClose
;
QAction
*
aEditSets
,
*
aSearch
,
*
aClearSearch
;
QAction
*
aEditSets
,
*
aEditTokens
,
*
aSearch
,
*
aClearSearch
;
QAction
*
aAddCard
,
*
aAddCardToSideboard
,
*
aRemoveCard
,
*
aIncrement
,
*
aDecrement
,
*
aUpdatePrices
;
bool
modified
;
public:
TabDeckEditor
(
TabSupervisor
*
_tabSupervisor
,
QWidget
*
parent
=
0
);
~
TabDeckEditor
();
void
retranslateUi
();
QString
getTabText
()
const
;
void
setDeck
(
DeckLoader
*
_deckLoader
);
void
set
Window
Modified
(
bool
_windowModified
);
void
setModified
(
bool
_windowModified
);
public
slots
:
void
closeRequest
();
signals:
...
...
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