Add No annotations export option w/ shortcut (#3013)
This commit is contained in:
parent
5757d60b1d
commit
ebec30dd1c
11 changed files with 1777 additions and 1662 deletions
|
@ -10,64 +10,64 @@ const QStringList DeckLoader::fileNameFilters = QStringList()
|
||||||
<< QObject::tr("Common deck formats (*.cod *.dec *.txt *.mwDeck)")
|
<< QObject::tr("Common deck formats (*.cod *.dec *.txt *.mwDeck)")
|
||||||
<< QObject::tr("All files (*.*)");
|
<< QObject::tr("All files (*.*)");
|
||||||
|
|
||||||
DeckLoader::DeckLoader()
|
DeckLoader::DeckLoader() : DeckList(), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||||
: DeckList(),
|
|
||||||
lastFileName(QString()),
|
|
||||||
lastFileFormat(CockatriceFormat),
|
|
||||||
lastRemoteDeckId(-1)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(const QString &nativeString)
|
DeckLoader::DeckLoader(const QString &nativeString) : DeckList(nativeString), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||||
: DeckList(nativeString),
|
|
||||||
lastFileName(QString()),
|
|
||||||
lastFileFormat(CockatriceFormat),
|
|
||||||
lastRemoteDeckId(-1)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(const DeckList &other)
|
DeckLoader::DeckLoader(const DeckList &other) : DeckList(other), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||||
: DeckList(other),
|
|
||||||
lastFileName(QString()),
|
|
||||||
lastFileFormat(CockatriceFormat),
|
|
||||||
lastRemoteDeckId(-1)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(const DeckLoader &other)
|
DeckLoader::DeckLoader(const DeckLoader &other) : DeckList(other), lastFileName(other.lastFileName), lastFileFormat(other.lastFileFormat), lastRemoteDeckId(other.lastRemoteDeckId)
|
||||||
: DeckList(other),
|
|
||||||
lastFileName(other.lastFileName),
|
|
||||||
lastFileFormat(other.lastFileFormat),
|
|
||||||
lastRemoteDeckId(other.lastRemoteDeckId)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt)
|
||||||
|
{
|
||||||
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
||||||
case CockatriceFormat:
|
case CockatriceFormat:
|
||||||
|
{
|
||||||
result = loadFromFile_Native(&file);
|
result = loadFromFile_Native(&file);
|
||||||
qDebug() << "Loaded from" << fileName << "-" << result;
|
qDebug() << "Loaded from" << fileName << "-" << result;
|
||||||
if (!result) {
|
if (!result)
|
||||||
|
{
|
||||||
qDebug() << "Retying as plain format";
|
qDebug() << "Retying as plain format";
|
||||||
file.seek(0);
|
file.seek(0);
|
||||||
result = loadFromFile_Plain(&file);
|
result = loadFromFile_Plain(&file);
|
||||||
fmt = PlainTextFormat;
|
fmt = PlainTextFormat;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (result) {
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
lastFileFormat = fmt;
|
lastFileFormat = fmt;
|
||||||
|
|
||||||
emit deckLoaded();
|
emit deckLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Deck was loaded -" << result;
|
qDebug() << "Deck was loaded -" << result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,8 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||||
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
||||||
{
|
{
|
||||||
bool result = loadFromString_Native(nativeString);
|
bool result = loadFromString_Native(nativeString);
|
||||||
if (result) {
|
if (result)
|
||||||
|
{
|
||||||
lastFileName = QString();
|
lastFileName = QString();
|
||||||
lastFileFormat = CockatriceFormat;
|
lastFileFormat = CockatriceFormat;
|
||||||
lastRemoteDeckId = remoteDeckId;
|
lastRemoteDeckId = remoteDeckId;
|
||||||
|
@ -89,14 +90,19 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt)
|
||||||
|
{
|
||||||
case PlainTextFormat: result = saveToFile_Plain(&file); break;
|
case PlainTextFormat: result = saveToFile_Plain(&file); break;
|
||||||
case CockatriceFormat: result = saveToFile_Native(&file); break;
|
case CockatriceFormat: result = saveToFile_Native(&file); break;
|
||||||
}
|
}
|
||||||
if (result) {
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
lastFileFormat = fmt;
|
lastFileFormat = fmt;
|
||||||
}
|
}
|
||||||
|
@ -112,20 +118,21 @@ struct FormatDeckListForExport
|
||||||
QString &mainBoardCards;
|
QString &mainBoardCards;
|
||||||
QString &sideBoardCards;
|
QString &sideBoardCards;
|
||||||
//create main operator for struct, allowing the foreachcard to work.
|
//create main operator for struct, allowing the foreachcard to work.
|
||||||
FormatDeckListForExport(
|
FormatDeckListForExport(QString &_mainBoardCards, QString &_sideBoardCards) : mainBoardCards(_mainBoardCards), sideBoardCards(_sideBoardCards){};
|
||||||
QString &_mainBoardCards, QString &_sideBoardCards
|
|
||||||
) : mainBoardCards(_mainBoardCards),
|
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const
|
||||||
sideBoardCards(_sideBoardCards){};
|
{
|
||||||
|
|
||||||
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const{
|
|
||||||
//Get the card name
|
//Get the card name
|
||||||
CardInfo * dbCard = db->getCard(card->getName());
|
CardInfo * dbCard = db->getCard(card->getName());
|
||||||
if (!dbCard || dbCard->getIsToken()){
|
if (!dbCard || dbCard->getIsToken())
|
||||||
|
{
|
||||||
//If it's a token, we don't care about the card.
|
//If it's a token, we don't care about the card.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if it's a sideboard card.
|
//Check if it's a sideboard card.
|
||||||
if(node->getName() == DECK_ZONE_SIDE){
|
if (node->getName() == DECK_ZONE_SIDE)
|
||||||
|
{
|
||||||
//Get the number of cards and add the card name
|
//Get the number of cards and add the card name
|
||||||
sideBoardCards+=QString::number(card->getNumber());
|
sideBoardCards+=QString::number(card->getNumber());
|
||||||
//Add a space between card num and name
|
//Add a space between card num and name
|
||||||
|
@ -135,8 +142,8 @@ struct FormatDeckListForExport
|
||||||
//Add a return at the end of the card
|
//Add a return at the end of the card
|
||||||
sideBoardCards+="%0A";
|
sideBoardCards+="%0A";
|
||||||
}
|
}
|
||||||
//If it's a mainboard card, do the same thing, but for the mainboard card string
|
else //If it's a mainboard card, do the same thing, but for the mainboard card string
|
||||||
else{
|
{
|
||||||
mainBoardCards+=QString::number(card->getNumber());
|
mainBoardCards+=QString::number(card->getNumber());
|
||||||
mainBoardCards+="%20";
|
mainBoardCards+="%20";
|
||||||
mainBoardCards+=card->getName();
|
mainBoardCards+=card->getName();
|
||||||
|
@ -172,22 +179,26 @@ QString DeckLoader::exportDeckToDecklist()
|
||||||
|
|
||||||
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
|
if (fileName.endsWith(".cod", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
return CockatriceFormat;
|
return CockatriceFormat;
|
||||||
}
|
}
|
||||||
return PlainTextFormat;
|
return PlainTextFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckLoader::saveToStream_Plain(QTextStream &out)
|
bool DeckLoader::saveToStream_Plain(QTextStream &out, bool addComments)
|
||||||
{
|
{
|
||||||
saveToStream_DeckHeader(out);
|
if (addComments)
|
||||||
|
{
|
||||||
|
saveToStream_DeckHeader(out);
|
||||||
|
}
|
||||||
|
|
||||||
// loop zones
|
// loop zones
|
||||||
for (int i = 0; i < getRoot()->size(); i++) {
|
for (int i = 0; i < getRoot()->size(); i++)
|
||||||
const InnerDecklistNode *zoneNode =
|
{
|
||||||
dynamic_cast<InnerDecklistNode *>(getRoot()->at(i));
|
const auto *zoneNode = dynamic_cast<InnerDecklistNode *>(getRoot()->at(i));
|
||||||
|
|
||||||
saveToStream_DeckZone(out, zoneNode);
|
saveToStream_DeckZone(out, zoneNode, addComments);
|
||||||
|
|
||||||
// end of zone
|
// end of zone
|
||||||
out << "\n";
|
out << "\n";
|
||||||
|
@ -198,88 +209,112 @@ bool DeckLoader::saveToStream_Plain(QTextStream &out)
|
||||||
|
|
||||||
void DeckLoader::saveToStream_DeckHeader(QTextStream &out)
|
void DeckLoader::saveToStream_DeckHeader(QTextStream &out)
|
||||||
{
|
{
|
||||||
if(!getName().isEmpty())
|
if (!getName().isEmpty())
|
||||||
|
{
|
||||||
out << "// " << getName() << "\n\n";
|
out << "// " << getName() << "\n\n";
|
||||||
if(!getComments().isEmpty())
|
}
|
||||||
|
|
||||||
|
if (!getComments().isEmpty())
|
||||||
{
|
{
|
||||||
QStringList commentRows = getComments().split(QRegExp("\n|\r\n|\r"));
|
QStringList commentRows = getComments().split(QRegExp("\n|\r\n|\r"));
|
||||||
foreach(QString row, commentRows)
|
foreach(QString row, commentRows)
|
||||||
|
{
|
||||||
out << "// " << row << "\n";
|
out << "// " << row << "\n";
|
||||||
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckLoader::saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode)
|
void DeckLoader::saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments)
|
||||||
{
|
{
|
||||||
// group cards by card type and count the subtotals
|
// group cards by card type and count the subtotals
|
||||||
QMultiMap<QString, DecklistCardNode*> cardsByType;
|
QMultiMap<QString, DecklistCardNode*> cardsByType;
|
||||||
QMap<QString, int> cardTotalByType;
|
QMap<QString, int> cardTotalByType;
|
||||||
int cardTotal = 0;
|
int cardTotal = 0;
|
||||||
|
|
||||||
for (int j = 0; j < zoneNode->size(); j++) {
|
for (int j = 0; j < zoneNode->size(); j++)
|
||||||
DecklistCardNode *card =
|
{
|
||||||
dynamic_cast<DecklistCardNode *>(
|
auto *card = dynamic_cast<DecklistCardNode *>(zoneNode->at(j));
|
||||||
zoneNode->at(j)
|
|
||||||
);
|
|
||||||
|
|
||||||
CardInfo *info = db->getCard(card->getName());
|
CardInfo *info = db->getCard(card->getName());
|
||||||
QString cardType = info ? info->getMainCardType() : "unknown";
|
QString cardType = info ? info->getMainCardType() : "unknown";
|
||||||
|
|
||||||
cardsByType.insert(cardType, card);
|
cardsByType.insert(cardType, card);
|
||||||
|
|
||||||
if(cardTotalByType.contains(cardType))
|
if (cardTotalByType.contains(cardType))
|
||||||
|
{
|
||||||
cardTotalByType[cardType] += card->getNumber();
|
cardTotalByType[cardType] += card->getNumber();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cardTotalByType[cardType] = card->getNumber();
|
cardTotalByType[cardType] = card->getNumber();
|
||||||
|
}
|
||||||
|
|
||||||
cardTotal += card->getNumber();
|
cardTotal += card->getNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "// " << cardTotal << " " << zoneNode->getVisibleName() << "\n";
|
if (addComments)
|
||||||
|
{
|
||||||
|
out << "// " << cardTotal << " " << zoneNode->getVisibleName() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
// print cards to stream
|
// print cards to stream
|
||||||
foreach(QString cardType, cardsByType.uniqueKeys())
|
foreach(QString cardType, cardsByType.uniqueKeys())
|
||||||
{
|
{
|
||||||
|
if (addComments)
|
||||||
|
{
|
||||||
|
out << "// " << cardTotalByType[cardType] << " " << cardType << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
out << "// " << cardTotalByType[cardType] << " " << cardType << "\n";
|
|
||||||
QList <DecklistCardNode*> cards = cardsByType.values(cardType);
|
QList <DecklistCardNode*> cards = cardsByType.values(cardType);
|
||||||
|
|
||||||
saveToStream_DeckZoneCards(out, zoneNode, cards);
|
saveToStream_DeckZoneCards(out, zoneNode, cards, addComments);
|
||||||
|
|
||||||
out << "\n";
|
if (addComments)
|
||||||
|
{
|
||||||
|
out << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards)
|
void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards, bool addComments)
|
||||||
{
|
{
|
||||||
// QMultiMap sorts values in reverse order
|
// QMultiMap sorts values in reverse order
|
||||||
for(int i = cards.size() - 1; i >= 0; --i)
|
for (int i = cards.size() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
DecklistCardNode* card = cards[i];
|
DecklistCardNode* card = cards[i];
|
||||||
|
|
||||||
if (zoneNode->getName() == DECK_ZONE_SIDE)
|
if (zoneNode->getName() == DECK_ZONE_SIDE && addComments)
|
||||||
|
{
|
||||||
out << "SB: ";
|
out << "SB: ";
|
||||||
|
}
|
||||||
|
|
||||||
out << card->getNumber() << " " << card->getName() << "\n";
|
out << card->getNumber() << " " << card->getName() << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneName)
|
QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneName)
|
||||||
{
|
{
|
||||||
CardInfo *card = db->getCard(cardName);
|
CardInfo *card = db->getCard(cardName);
|
||||||
|
|
||||||
if (card && card->getIsToken())
|
if (card && card->getIsToken())
|
||||||
|
{
|
||||||
return DECK_ZONE_TOKENS;
|
return DECK_ZONE_TOKENS;
|
||||||
|
}
|
||||||
|
|
||||||
return currentZoneName;
|
return currentZoneName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeckLoader::getCompleteCardName(const QString cardName) const
|
QString DeckLoader::getCompleteCardName(const QString cardName) const
|
||||||
{
|
{
|
||||||
if (db) {
|
if (db)
|
||||||
|
{
|
||||||
CardInfo *temp = db->getCardBySimpleName(cardName);
|
CardInfo *temp = db->getCardBySimpleName(cardName);
|
||||||
if (temp)
|
if (temp)
|
||||||
|
{
|
||||||
return temp->getName();
|
return temp->getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cardName;
|
return cardName;
|
||||||
}
|
}
|
|
@ -3,42 +3,46 @@
|
||||||
|
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
class DeckLoader : public DeckList {
|
class DeckLoader : public DeckList
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void deckLoaded();
|
void deckLoaded();
|
||||||
public:
|
|
||||||
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
|
||||||
static const QStringList fileNameFilters;
|
|
||||||
private:
|
|
||||||
QString lastFileName;
|
|
||||||
FileFormat lastFileFormat;
|
|
||||||
int lastRemoteDeckId;
|
|
||||||
public:
|
|
||||||
DeckLoader();
|
|
||||||
DeckLoader(const QString &nativeString);
|
|
||||||
DeckLoader(const DeckList &other);
|
|
||||||
DeckLoader(const DeckLoader &other);
|
|
||||||
const QString &getLastFileName() const { return lastFileName; }
|
|
||||||
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
|
||||||
int getLastRemoteDeckId() const { return lastRemoteDeckId; }
|
|
||||||
|
|
||||||
static FileFormat getFormatFromName(const QString &fileName);
|
|
||||||
|
|
||||||
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
|
||||||
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
|
||||||
bool saveToFile(const QString &fileName, FileFormat fmt);
|
|
||||||
QString exportDeckToDecklist();
|
|
||||||
|
|
||||||
// overload
|
public:
|
||||||
bool saveToStream_Plain(QTextStream &out);
|
enum FileFormat { PlainTextFormat, CockatriceFormat };
|
||||||
|
static const QStringList fileNameFilters;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
void saveToStream_DeckHeader(QTextStream &out);
|
QString lastFileName;
|
||||||
void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode);
|
FileFormat lastFileFormat;
|
||||||
void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards);
|
int lastRemoteDeckId;
|
||||||
virtual QString getCardZoneFromName(QString cardName, QString currentZoneName);
|
|
||||||
virtual QString getCompleteCardName(const QString cardName) const;
|
public:
|
||||||
|
DeckLoader();
|
||||||
|
DeckLoader(const QString &nativeString);
|
||||||
|
DeckLoader(const DeckList &other);
|
||||||
|
DeckLoader(const DeckLoader &other);
|
||||||
|
const QString &getLastFileName() const { return lastFileName; }
|
||||||
|
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
||||||
|
int getLastRemoteDeckId() const { return lastRemoteDeckId; }
|
||||||
|
|
||||||
|
static FileFormat getFormatFromName(const QString &fileName);
|
||||||
|
|
||||||
|
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
||||||
|
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
||||||
|
bool saveToFile(const QString &fileName, FileFormat fmt);
|
||||||
|
QString exportDeckToDecklist();
|
||||||
|
|
||||||
|
// overload
|
||||||
|
bool saveToStream_Plain(QTextStream &out, bool addComments = true);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void saveToStream_DeckHeader(QTextStream &out);
|
||||||
|
void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments = true);
|
||||||
|
void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards, bool addComments = true);
|
||||||
|
virtual QString getCardZoneFromName(QString cardName, QString currentZoneName);
|
||||||
|
virtual QString getCompleteCardName(const QString cardName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
SequenceEdit::SequenceEdit(QString _shorcutName, QWidget *parent) : QWidget(parent)
|
SequenceEdit::SequenceEdit(QString _shorcutName, QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
shorcutName = _shorcutName;
|
shorcutName = std::move(_shorcutName);
|
||||||
currentKey = 0;
|
currentKey = 0;
|
||||||
maxKeys = 4;
|
|
||||||
keys = 0;
|
keys = 0;
|
||||||
valid = false;
|
valid = false;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ SequenceEdit::SequenceEdit(QString _shorcutName, QWidget *parent) : QWidget(pare
|
||||||
clearButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
clearButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||||
defaultButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
defaultButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||||
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
auto *layout = new QHBoxLayout(this);
|
||||||
layout->setContentsMargins(0,0,0,0);
|
layout->setContentsMargins(0,0,0,0);
|
||||||
layout->setSpacing(1);
|
layout->setSpacing(1);
|
||||||
layout->addWidget(lineEdit);
|
layout->addWidget(lineEdit);
|
||||||
|
@ -53,14 +53,18 @@ QString SequenceEdit::getSecuence()
|
||||||
void SequenceEdit::removeLastShortcut()
|
void SequenceEdit::removeLastShortcut()
|
||||||
{
|
{
|
||||||
QString secuences = lineEdit->text();
|
QString secuences = lineEdit->text();
|
||||||
if(!secuences.isEmpty())
|
if (!secuences.isEmpty())
|
||||||
{
|
{
|
||||||
if(secuences.lastIndexOf(";") > 0){
|
if (secuences.lastIndexOf(";") > 0)
|
||||||
|
{
|
||||||
QString valid = secuences.left(secuences.lastIndexOf(";"));
|
QString valid = secuences.left(secuences.lastIndexOf(";"));
|
||||||
lineEdit->setText(valid);
|
lineEdit->setText(valid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
lineEdit->clear();
|
lineEdit->clear();
|
||||||
|
}
|
||||||
|
|
||||||
updateSettings();
|
updateSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,14 +87,19 @@ void SequenceEdit::clear()
|
||||||
|
|
||||||
bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
||||||
{
|
{
|
||||||
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
||||||
{
|
{
|
||||||
QKeyEvent * keyEvent = (QKeyEvent *) event;
|
auto *keyEvent = reinterpret_cast<QKeyEvent *>(event);
|
||||||
|
|
||||||
if(event->type() == QEvent::KeyPress && !keyEvent->isAutoRepeat())
|
if (event->type() == QEvent::KeyPress && !keyEvent->isAutoRepeat())
|
||||||
|
{
|
||||||
processKey(keyEvent);
|
processKey(keyEvent);
|
||||||
|
}
|
||||||
else if (event->type() == QEvent::KeyRelease && !keyEvent->isAutoRepeat())
|
else if (event->type() == QEvent::KeyRelease && !keyEvent->isAutoRepeat())
|
||||||
|
{
|
||||||
finishShortcut();
|
finishShortcut();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -99,16 +108,18 @@ bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
||||||
void SequenceEdit::processKey(QKeyEvent* e)
|
void SequenceEdit::processKey(QKeyEvent* e)
|
||||||
{
|
{
|
||||||
int key = e->key();
|
int key = e->key();
|
||||||
if(key != Qt::Key_Control && key != Qt::Key_Shift
|
if (key != Qt::Key_Control && key != Qt::Key_Shift && key != Qt::Key_Meta && key != Qt::Key_Alt)
|
||||||
&& key != Qt::Key_Meta && key != Qt::Key_Alt)
|
|
||||||
{
|
{
|
||||||
valid = true;
|
valid = true;
|
||||||
key |= translateModifiers(e->modifiers(), e->text());
|
key |= translateModifiers(e->modifiers(), e->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = key;
|
keys = key;
|
||||||
currentKey++;
|
currentKey++;
|
||||||
if(currentKey >= key)
|
if (currentKey >= key)
|
||||||
|
{
|
||||||
finishShortcut();
|
finishShortcut();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text)
|
int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text)
|
||||||
|
@ -120,29 +131,42 @@ int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString
|
||||||
!text.at(0).isPrint() ||
|
!text.at(0).isPrint() ||
|
||||||
text.at(0).isLetterOrNumber() ||
|
text.at(0).isLetterOrNumber() ||
|
||||||
text.at(0).isSpace()))
|
text.at(0).isSpace()))
|
||||||
|
{
|
||||||
result |= Qt::SHIFT;
|
result |= Qt::SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
if (state & Qt::ControlModifier)
|
if (state & Qt::ControlModifier)
|
||||||
|
{
|
||||||
result |= Qt::CTRL;
|
result |= Qt::CTRL;
|
||||||
|
}
|
||||||
|
|
||||||
if (state & Qt::MetaModifier)
|
if (state & Qt::MetaModifier)
|
||||||
|
{
|
||||||
result |= Qt::META;
|
result |= Qt::META;
|
||||||
|
}
|
||||||
|
|
||||||
if (state & Qt::AltModifier)
|
if (state & Qt::AltModifier)
|
||||||
|
{
|
||||||
result |= Qt::ALT;
|
result |= Qt::ALT;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SequenceEdit::finishShortcut()
|
void SequenceEdit::finishShortcut()
|
||||||
{
|
{
|
||||||
QKeySequence secuence(keys);
|
QKeySequence secuence(keys);
|
||||||
if(!secuence.isEmpty() && valid)
|
if (!secuence.isEmpty() && valid)
|
||||||
{
|
{
|
||||||
QString secuenceString = secuence.toString();
|
QString secuenceString = secuence.toString();
|
||||||
if(settingsCache->shortcuts().isValid(shorcutName,secuenceString))
|
if (settingsCache->shortcuts().isValid(shorcutName,secuenceString))
|
||||||
{
|
{
|
||||||
if(!lineEdit->text().isEmpty())
|
if (!lineEdit->text().isEmpty())
|
||||||
{
|
{
|
||||||
if(lineEdit->text().contains(secuenceString))
|
if (lineEdit->text().contains(secuenceString))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
lineEdit->setText(lineEdit->text() + ";");
|
lineEdit->setText(lineEdit->text() + ";");
|
||||||
}
|
}
|
||||||
lineEdit->setText(lineEdit->text() + secuenceString);
|
lineEdit->setText(lineEdit->text() + secuenceString);
|
||||||
|
@ -152,6 +176,7 @@ void SequenceEdit::finishShortcut()
|
||||||
QToolTip::showText(lineEdit->mapToGlobal(QPoint()), tr("Shortcut already in use"));
|
QToolTip::showText(lineEdit->mapToGlobal(QPoint()), tr("Shortcut already in use"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentKey = 0;
|
currentKey = 0;
|
||||||
keys = 0;
|
keys = 0;
|
||||||
valid = false;
|
valid = false;
|
||||||
|
@ -161,5 +186,4 @@ void SequenceEdit::finishShortcut()
|
||||||
void SequenceEdit::updateSettings()
|
void SequenceEdit::updateSettings()
|
||||||
{
|
{
|
||||||
settingsCache->shortcuts().setShortcuts(shorcutName,lineEdit->text());
|
settingsCache->shortcuts().setShortcuts(shorcutName,lineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,33 +11,32 @@ class QEvent;
|
||||||
class SequenceEdit : public QWidget
|
class SequenceEdit : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SequenceEdit(QString _shorcutName, QWidget *parent = 0);
|
SequenceEdit(QString _shorcutName, QWidget *parent = nullptr);
|
||||||
QString getSecuence();
|
QString getSecuence();
|
||||||
void refreshShortcut();
|
void refreshShortcut();
|
||||||
void clear();
|
void clear();
|
||||||
signals:
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void removeLastShortcut();
|
void removeLastShortcut();
|
||||||
void restoreDefault();
|
void restoreDefault();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *, QEvent *event);
|
bool eventFilter(QObject *, QEvent *event);
|
||||||
private:
|
|
||||||
QString shorcutName;
|
|
||||||
QLineEdit *lineEdit;
|
|
||||||
QPushButton *clearButton;
|
|
||||||
QPushButton *defaultButton;
|
|
||||||
int keys;
|
|
||||||
int currentKey;
|
|
||||||
int maxKeys;
|
|
||||||
bool valid;
|
|
||||||
|
|
||||||
void processKey(QKeyEvent *e);
|
private:
|
||||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
QString shorcutName;
|
||||||
void finishShortcut();
|
QLineEdit *lineEdit;
|
||||||
void updateSettings();
|
QPushButton *clearButton;
|
||||||
|
QPushButton *defaultButton;
|
||||||
|
int keys;
|
||||||
|
int currentKey;
|
||||||
|
bool valid;
|
||||||
|
|
||||||
|
void processKey(QKeyEvent *e);
|
||||||
|
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||||
|
void finishShortcut();
|
||||||
|
void updateSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SECUENCEEDIT_H
|
#endif // SECUENCEEDIT_H
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
#include "../settingscache.h"
|
#include "../settingscache.h"
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
ShortcutsTab::ShortcutsTab() :
|
ShortcutsTab::ShortcutsTab() : ui(new Ui::shortcutsTab)
|
||||||
ui(new Ui::shortcutsTab)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->btnResetAll,SIGNAL(clicked()),this,SLOT(resetShortcuts()));
|
connect(ui->btnResetAll,SIGNAL(clicked()),this,SLOT(resetShortcuts()));
|
||||||
|
@ -26,7 +25,7 @@ ShortcutsTab::~ShortcutsTab()
|
||||||
|
|
||||||
void ShortcutsTab::resetShortcuts()
|
void ShortcutsTab::resetShortcuts()
|
||||||
{
|
{
|
||||||
if(QMessageBox::question(this,tr("Restore all default shortcuts"),
|
if (QMessageBox::question(this,tr("Restore all default shortcuts"),
|
||||||
tr("Do you really want to restore all default shortcuts?")) == QMessageBox::Yes)
|
tr("Do you really want to restore all default shortcuts?")) == QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
settingsCache->shortcuts().resetAllShortcuts();
|
settingsCache->shortcuts().resetAllShortcuts();
|
||||||
|
@ -36,15 +35,15 @@ void ShortcutsTab::resetShortcuts()
|
||||||
void ShortcutsTab::refreshEdits()
|
void ShortcutsTab::refreshEdits()
|
||||||
{
|
{
|
||||||
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
|
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
|
||||||
for(int i= 0; i < edits.length(); ++i)
|
for (auto edit : edits)
|
||||||
{
|
{
|
||||||
edits.at(i)->refreshShortcut();
|
edit->refreshShortcut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutsTab::clearShortcuts()
|
void ShortcutsTab::clearShortcuts()
|
||||||
{
|
{
|
||||||
if(QMessageBox::question(this,tr("Clear all default shortcuts"),
|
if (QMessageBox::question(this,tr("Clear all default shortcuts"),
|
||||||
tr("Do you really want to clear all shortcuts?")) == QMessageBox::Yes)
|
tr("Do you really want to clear all shortcuts?")) == QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
settingsCache->shortcuts().clearAllShortcuts();
|
settingsCache->shortcuts().clearAllShortcuts();
|
||||||
|
@ -54,8 +53,8 @@ void ShortcutsTab::clearShortcuts()
|
||||||
void ShortcutsTab::afterClear()
|
void ShortcutsTab::afterClear()
|
||||||
{
|
{
|
||||||
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
|
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
|
||||||
for(int i= 0; i < edits.length(); ++i)
|
for (auto edit : edits)
|
||||||
{
|
{
|
||||||
edits.at(i)->clear();
|
edit->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,25 +5,27 @@
|
||||||
|
|
||||||
#include "../dlg_settings.h"
|
#include "../dlg_settings.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
class shortcutsTab;
|
{
|
||||||
|
class shortcutsTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ShortcutsTab : public AbstractSettingsPage
|
class ShortcutsTab : public AbstractSettingsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ShortcutsTab();
|
||||||
|
void retranslateUi();
|
||||||
|
~ShortcutsTab();
|
||||||
|
|
||||||
public:
|
private slots:
|
||||||
ShortcutsTab();
|
void resetShortcuts();
|
||||||
void retranslateUi();
|
void refreshEdits();
|
||||||
~ShortcutsTab();
|
void clearShortcuts();
|
||||||
private slots:
|
void afterClear();
|
||||||
void resetShortcuts();
|
|
||||||
void refreshEdits();
|
private:
|
||||||
void clearShortcuts();
|
Ui::shortcutsTab *ui;
|
||||||
void afterClear();
|
|
||||||
private:
|
|
||||||
Ui::shortcutsTab *ui;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHORTCUTSTAB_H
|
#endif // SHORTCUTSTAB_H
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,11 @@
|
||||||
#include "shortcutssettings.h"
|
#include "shortcutssettings.h"
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
ShortcutsSettings::ShortcutsSettings(QString settingsPath, QObject *parent) : QObject(parent)
|
ShortcutsSettings::ShortcutsSettings(QString settingsPath, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
this->settingsFilePath = settingsPath;
|
this->settingsFilePath = std::move(settingsPath);
|
||||||
this->settingsFilePath.append("shortcuts.ini");
|
this->settingsFilePath.append("shortcuts.ini");
|
||||||
fillDefaultShorcuts();
|
fillDefaultShorcuts();
|
||||||
shortCuts = QMap<QString,QList<QKeySequence> >(defaultShortCuts);
|
shortCuts = QMap<QString,QList<QKeySequence> >(defaultShortCuts);
|
||||||
|
@ -13,30 +14,35 @@ ShortcutsSettings::ShortcutsSettings(QString settingsPath, QObject *parent) : QO
|
||||||
|
|
||||||
QSettings shortCutsFile(settingsFilePath, QSettings::IniFormat);
|
QSettings shortCutsFile(settingsFilePath, QSettings::IniFormat);
|
||||||
|
|
||||||
if(exists){
|
if (exists)
|
||||||
|
{
|
||||||
shortCutsFile.beginGroup("Custom");
|
shortCutsFile.beginGroup("Custom");
|
||||||
const QStringList customKeys = shortCutsFile.allKeys();
|
const QStringList customKeys = shortCutsFile.allKeys();
|
||||||
|
|
||||||
for(QStringList::const_iterator it = customKeys.constBegin(); it != customKeys.constEnd(); ++it)
|
for(QStringList::const_iterator it = customKeys.constBegin(); it != customKeys.constEnd(); ++it)
|
||||||
{
|
{
|
||||||
QString stringSequence = shortCutsFile.value(*it).toString();
|
QString stringSequence = shortCutsFile.value(*it).toString();
|
||||||
QList<QKeySequence> SequenceList = parseSequenceString(stringSequence);
|
QList<QKeySequence> SequenceList = parseSequenceString(stringSequence);
|
||||||
shortCuts.insert(*it, SequenceList);
|
shortCuts.insert(*it, SequenceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
shortCutsFile.endGroup();
|
shortCutsFile.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QKeySequence> ShortcutsSettings::getShortcut(QString name)
|
QList<QKeySequence> ShortcutsSettings::getShortcut(QString name)
|
||||||
{
|
{
|
||||||
if(shortCuts.contains(name))
|
if (shortCuts.contains(name))
|
||||||
|
{
|
||||||
return shortCuts.value(name);
|
return shortCuts.value(name);
|
||||||
|
}
|
||||||
|
|
||||||
return defaultShortCuts.value(name, QList<QKeySequence>());
|
return defaultShortCuts.value(name, QList<QKeySequence>());
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeySequence ShortcutsSettings::getSingleShortcut(QString name)
|
QKeySequence ShortcutsSettings::getSingleShortcut(QString name)
|
||||||
{
|
{
|
||||||
return getShortcut(name).at(0);
|
return getShortcut(std::move(name)).at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ShortcutsSettings::getDefaultShortcutString(QString name)
|
QString ShortcutsSettings::getDefaultShortcutString(QString name)
|
||||||
|
@ -52,11 +58,13 @@ QString ShortcutsSettings::getShortcutString(QString name)
|
||||||
QString ShortcutsSettings::stringifySequence(QList<QKeySequence> Sequence) const
|
QString ShortcutsSettings::stringifySequence(QList<QKeySequence> Sequence) const
|
||||||
{
|
{
|
||||||
QString stringSequence;
|
QString stringSequence;
|
||||||
for(int i=0; i < Sequence.size(); ++i)
|
for (int i=0; i < Sequence.size(); ++i)
|
||||||
{
|
{
|
||||||
stringSequence.append(Sequence.at(i).toString(QKeySequence::PortableText));
|
stringSequence.append(Sequence.at(i).toString(QKeySequence::PortableText));
|
||||||
if(i < Sequence.size() - 1)
|
if (i < Sequence.size() - 1)
|
||||||
|
{
|
||||||
stringSequence.append(";");
|
stringSequence.append(";");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringSequence;
|
return stringSequence;
|
||||||
|
@ -66,7 +74,7 @@ QList<QKeySequence> ShortcutsSettings::parseSequenceString(QString stringSequenc
|
||||||
{
|
{
|
||||||
QStringList Sequences = stringSequence.split(";");
|
QStringList Sequences = stringSequence.split(";");
|
||||||
QList<QKeySequence> SequenceList;
|
QList<QKeySequence> SequenceList;
|
||||||
for(QStringList::const_iterator ss = Sequences.constBegin(); ss != Sequences.constEnd(); ++ss)
|
for (QStringList::const_iterator ss = Sequences.constBegin(); ss != Sequences.constEnd(); ++ss)
|
||||||
{
|
{
|
||||||
SequenceList.append(QKeySequence(*ss, QKeySequence::PortableText));
|
SequenceList.append(QKeySequence(*ss, QKeySequence::PortableText));
|
||||||
}
|
}
|
||||||
|
@ -88,12 +96,12 @@ void ShortcutsSettings::setShortcuts(QString name, QList<QKeySequence> Sequence)
|
||||||
|
|
||||||
void ShortcutsSettings::setShortcuts(QString name, QKeySequence Sequence)
|
void ShortcutsSettings::setShortcuts(QString name, QKeySequence Sequence)
|
||||||
{
|
{
|
||||||
setShortcuts(name, QList<QKeySequence>() << Sequence);
|
setShortcuts(std::move(name), QList<QKeySequence>() << Sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutsSettings::setShortcuts(QString name, QString Sequences)
|
void ShortcutsSettings::setShortcuts(QString name, QString Sequences)
|
||||||
{
|
{
|
||||||
setShortcuts(name,parseSequenceString(Sequences));
|
setShortcuts(std::move(name), parseSequenceString(std::move(Sequences)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShortcutsSettings::isValid(QString name, QString Sequences)
|
bool ShortcutsSettings::isValid(QString name, QString Sequences)
|
||||||
|
@ -103,16 +111,18 @@ bool ShortcutsSettings::isValid(QString name, QString Sequences)
|
||||||
QString checkSequence = Sequences.split(";").last();
|
QString checkSequence = Sequences.split(";").last();
|
||||||
|
|
||||||
QList<QString> allKeys = shortCuts.keys();
|
QList<QString> allKeys = shortCuts.keys();
|
||||||
for(int i=0; i < allKeys.size(); i++){
|
for (const auto &key : allKeys)
|
||||||
QString key = allKeys.at(i);
|
{
|
||||||
if(key.startsWith(checkKey) || key.startsWith("MainWindow") || checkKey.startsWith("MainWindow"))
|
if (key.startsWith(checkKey) || key.startsWith("MainWindow") || checkKey.startsWith("MainWindow"))
|
||||||
{
|
{
|
||||||
QString storedSequence = stringifySequence(shortCuts.value(key));
|
QString storedSequence = stringifySequence(shortCuts.value(key));
|
||||||
QStringList stringSequences = storedSequence.split(";");
|
QStringList stringSequences = storedSequence.split(";");
|
||||||
for(int j = 0; j < stringSequences.size(); j++)
|
for (int j = 0; j < stringSequences.size(); j++)
|
||||||
{
|
{
|
||||||
if(checkSequence == stringSequences.at(j))
|
if (checkSequence == stringSequences.at(j))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,8 +131,8 @@ bool ShortcutsSettings::isValid(QString name, QString Sequences)
|
||||||
|
|
||||||
void ShortcutsSettings::resetAllShortcuts()
|
void ShortcutsSettings::resetAllShortcuts()
|
||||||
{
|
{
|
||||||
for(QMap<QString,QList<QKeySequence> >::const_iterator it = defaultShortCuts.begin();
|
for (auto it = defaultShortCuts.begin(); it != defaultShortCuts.end(); ++it)
|
||||||
it != defaultShortCuts.end(); ++it){
|
{
|
||||||
setShortcuts(it.key(), it.value());
|
setShortcuts(it.key(), it.value());
|
||||||
}
|
}
|
||||||
emit allShortCutsReset();
|
emit allShortCutsReset();
|
||||||
|
@ -130,8 +140,8 @@ void ShortcutsSettings::resetAllShortcuts()
|
||||||
|
|
||||||
void ShortcutsSettings::clearAllShortcuts()
|
void ShortcutsSettings::clearAllShortcuts()
|
||||||
{
|
{
|
||||||
for(QMap<QString,QList<QKeySequence> >::const_iterator it = shortCuts.begin();
|
for(auto it = shortCuts.begin(); it != shortCuts.end(); ++it)
|
||||||
it != shortCuts.end(); ++it){
|
{
|
||||||
setShortcuts(it.key(), "");
|
setShortcuts(it.key(), "");
|
||||||
}
|
}
|
||||||
emit allShortCutsClear();
|
emit allShortCutsClear();
|
||||||
|
@ -169,6 +179,7 @@ void ShortcutsSettings::fillDefaultShorcuts()
|
||||||
defaultShortCuts["TabDeckEditor/aSaveDeck"] = parseSequenceString("Ctrl+S");
|
defaultShortCuts["TabDeckEditor/aSaveDeck"] = parseSequenceString("Ctrl+S");
|
||||||
defaultShortCuts["TabDeckEditor/aSaveDeckAs"] = parseSequenceString("");
|
defaultShortCuts["TabDeckEditor/aSaveDeckAs"] = parseSequenceString("");
|
||||||
defaultShortCuts["TabDeckEditor/aSaveDeckToClipboard"] = parseSequenceString("Ctrl+Shift+C");
|
defaultShortCuts["TabDeckEditor/aSaveDeckToClipboard"] = parseSequenceString("Ctrl+Shift+C");
|
||||||
|
defaultShortCuts["TabDeckEditor/aSaveDeckToClipboardRaw"] = parseSequenceString("Ctrl+Shift+R");
|
||||||
|
|
||||||
defaultShortCuts["DeckViewContainer/loadLocalButton"] = parseSequenceString("Ctrl+O");
|
defaultShortCuts["DeckViewContainer/loadLocalButton"] = parseSequenceString("Ctrl+O");
|
||||||
defaultShortCuts["DeckViewContainer/loadRemoteButton"] = parseSequenceString("Ctrl+Alt+O");
|
defaultShortCuts["DeckViewContainer/loadRemoteButton"] = parseSequenceString("Ctrl+Alt+O");
|
||||||
|
|
|
@ -9,36 +9,37 @@
|
||||||
class ShortcutsSettings : public QObject
|
class ShortcutsSettings : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ShortcutsSettings(QString settingsFilePath, QObject *parent = 0);
|
ShortcutsSettings(QString settingsFilePath, QObject *parent = nullptr);
|
||||||
~ShortcutsSettings() { }
|
|
||||||
|
|
||||||
QList<QKeySequence> getShortcut(QString name);
|
QList<QKeySequence> getShortcut(QString name);
|
||||||
QKeySequence getSingleShortcut(QString name);
|
QKeySequence getSingleShortcut(QString name);
|
||||||
|
|
||||||
QString getDefaultShortcutString(QString name);
|
QString getDefaultShortcutString(QString name);
|
||||||
QString getShortcutString(QString name);
|
QString getShortcutString(QString name);
|
||||||
|
|
||||||
void setShortcuts(QString name, QList<QKeySequence> Sequence);
|
void setShortcuts(QString name, QList<QKeySequence> Sequence);
|
||||||
void setShortcuts(QString name, QKeySequence Sequence);
|
void setShortcuts(QString name, QKeySequence Sequence);
|
||||||
void setShortcuts(QString name, QString Sequences);
|
void setShortcuts(QString name, QString Sequences);
|
||||||
|
|
||||||
bool isValid(QString name, QString Sequences);
|
bool isValid(QString name, QString Sequences);
|
||||||
|
|
||||||
void resetAllShortcuts();
|
void resetAllShortcuts();
|
||||||
void clearAllShortcuts();
|
void clearAllShortcuts();
|
||||||
signals:
|
|
||||||
void shortCutchanged();
|
|
||||||
void allShortCutsReset();
|
|
||||||
void allShortCutsClear();
|
|
||||||
private:
|
|
||||||
QString settingsFilePath;
|
|
||||||
QMap<QString,QList<QKeySequence> > shortCuts;
|
|
||||||
QMap<QString,QList<QKeySequence> > defaultShortCuts;
|
|
||||||
void fillDefaultShorcuts();
|
|
||||||
|
|
||||||
QString stringifySequence(QList<QKeySequence> Sequence) const;
|
signals:
|
||||||
QList<QKeySequence> parseSequenceString(QString stringSequence);
|
void shortCutchanged();
|
||||||
|
void allShortCutsReset();
|
||||||
|
void allShortCutsClear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString settingsFilePath;
|
||||||
|
QMap<QString,QList<QKeySequence> > shortCuts;
|
||||||
|
QMap<QString,QList<QKeySequence> > defaultShortCuts;
|
||||||
|
void fillDefaultShorcuts();
|
||||||
|
|
||||||
|
QString stringifySequence(QList<QKeySequence> Sequence) const;
|
||||||
|
QList<QKeySequence> parseSequenceString(QString stringSequence);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHORTCUTSSETTINGS_H
|
#endif // SHORTCUTSSETTINGS_H
|
||||||
|
|
|
@ -226,6 +226,9 @@ void TabDeckEditor::createMenus()
|
||||||
aSaveDeckToClipboard = new QAction(QString(), this);
|
aSaveDeckToClipboard = new QAction(QString(), this);
|
||||||
connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard()));
|
connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard()));
|
||||||
|
|
||||||
|
aSaveDeckToClipboardRaw = new QAction(QString(), this);
|
||||||
|
connect(aSaveDeckToClipboardRaw, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboardRaw()));
|
||||||
|
|
||||||
aPrintDeck = new QAction(QString(), this);
|
aPrintDeck = new QAction(QString(), this);
|
||||||
connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
|
connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
|
||||||
|
|
||||||
|
@ -254,6 +257,10 @@ void TabDeckEditor::createMenus()
|
||||||
aClearFilterOne->setIcon(QPixmap("theme:icons/decrement"));
|
aClearFilterOne->setIcon(QPixmap("theme:icons/decrement"));
|
||||||
connect(aClearFilterOne, SIGNAL(triggered()), this, SLOT(actClearFilterOne()));
|
connect(aClearFilterOne, SIGNAL(triggered()), this, SLOT(actClearFilterOne()));
|
||||||
|
|
||||||
|
saveDeckToClipboardMenu = new QMenu(this);
|
||||||
|
saveDeckToClipboardMenu->addAction(aSaveDeckToClipboard);
|
||||||
|
saveDeckToClipboardMenu->addAction(aSaveDeckToClipboardRaw);
|
||||||
|
|
||||||
deckMenu = new QMenu(this);
|
deckMenu = new QMenu(this);
|
||||||
deckMenu->addAction(aNewDeck);
|
deckMenu->addAction(aNewDeck);
|
||||||
deckMenu->addAction(aLoadDeck);
|
deckMenu->addAction(aLoadDeck);
|
||||||
|
@ -261,7 +268,7 @@ void TabDeckEditor::createMenus()
|
||||||
deckMenu->addAction(aSaveDeckAs);
|
deckMenu->addAction(aSaveDeckAs);
|
||||||
deckMenu->addSeparator();
|
deckMenu->addSeparator();
|
||||||
deckMenu->addAction(aLoadDeckFromClipboard);
|
deckMenu->addAction(aLoadDeckFromClipboard);
|
||||||
deckMenu->addAction(aSaveDeckToClipboard);
|
deckMenu->addMenu(saveDeckToClipboardMenu);
|
||||||
deckMenu->addSeparator();
|
deckMenu->addSeparator();
|
||||||
deckMenu->addAction(aPrintDeck);
|
deckMenu->addAction(aPrintDeck);
|
||||||
deckMenu->addMenu(analyzeDeckMenu);
|
deckMenu->addMenu(analyzeDeckMenu);
|
||||||
|
@ -470,7 +477,10 @@ void TabDeckEditor::refreshShortcuts()
|
||||||
aResetLayout->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aResetLayout"));
|
aResetLayout->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aResetLayout"));
|
||||||
aClearFilterAll->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterAll"));
|
aClearFilterAll->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterAll"));
|
||||||
aClearFilterOne->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterOne"));
|
aClearFilterOne->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterOne"));
|
||||||
|
|
||||||
aSaveDeckToClipboard->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aSaveDeckToClipboard"));
|
aSaveDeckToClipboard->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aSaveDeckToClipboard"));
|
||||||
|
aSaveDeckToClipboardRaw->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aSaveDeckToClipboardRaw"));
|
||||||
|
|
||||||
aClearFilterOne->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterOne"));
|
aClearFilterOne->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterOne"));
|
||||||
aClose->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClose"));
|
aClose->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClose"));
|
||||||
aRemoveCard->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aRemoveCard"));
|
aRemoveCard->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aRemoveCard"));
|
||||||
|
@ -552,7 +562,11 @@ void TabDeckEditor::retranslateUi()
|
||||||
aSaveDeck->setText(tr("&Save deck"));
|
aSaveDeck->setText(tr("&Save deck"));
|
||||||
aSaveDeckAs->setText(tr("Save deck &as..."));
|
aSaveDeckAs->setText(tr("Save deck &as..."));
|
||||||
aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard..."));
|
aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard..."));
|
||||||
aSaveDeckToClipboard->setText(tr("Save deck to clip&board"));
|
|
||||||
|
saveDeckToClipboardMenu->setTitle(tr("Save deck to clipboard"));
|
||||||
|
aSaveDeckToClipboard->setText(tr("Annotated"));
|
||||||
|
aSaveDeckToClipboardRaw->setText(tr("Not Annotated"));
|
||||||
|
|
||||||
aPrintDeck->setText(tr("&Print deck..."));
|
aPrintDeck->setText(tr("&Print deck..."));
|
||||||
|
|
||||||
analyzeDeckMenu->setTitle(tr("&Send deck to online service"));
|
analyzeDeckMenu->setTitle(tr("&Send deck to online service"));
|
||||||
|
@ -767,6 +781,15 @@ void TabDeckEditor::actSaveDeckToClipboard()
|
||||||
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabDeckEditor::actSaveDeckToClipboardRaw()
|
||||||
|
{
|
||||||
|
QString buffer;
|
||||||
|
QTextStream stream(&buffer);
|
||||||
|
deckModel->getDeckList()->saveToStream_Plain(stream, false);
|
||||||
|
QApplication::clipboard()->setText(buffer, QClipboard::Clipboard);
|
||||||
|
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
||||||
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actPrintDeck()
|
void TabDeckEditor::actPrintDeck()
|
||||||
{
|
{
|
||||||
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);
|
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);
|
||||||
|
|
|
@ -51,6 +51,7 @@ class TabDeckEditor : public Tab {
|
||||||
bool actSaveDeckAs();
|
bool actSaveDeckAs();
|
||||||
void actLoadDeckFromClipboard();
|
void actLoadDeckFromClipboard();
|
||||||
void actSaveDeckToClipboard();
|
void actSaveDeckToClipboard();
|
||||||
|
void actSaveDeckToClipboardRaw();
|
||||||
void actPrintDeck();
|
void actPrintDeck();
|
||||||
void actExportDeckDecklist();
|
void actExportDeckDecklist();
|
||||||
void actAnalyzeDeckDeckstats();
|
void actAnalyzeDeckDeckstats();
|
||||||
|
@ -111,8 +112,8 @@ private:
|
||||||
KeySignals filterViewKeySignals;
|
KeySignals filterViewKeySignals;
|
||||||
QWidget *filterBox;
|
QWidget *filterBox;
|
||||||
|
|
||||||
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *analyzeDeckMenu;
|
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *analyzeDeckMenu, *saveDeckToClipboardMenu;
|
||||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aExportDeckDecklist, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose;
|
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aSaveDeckToClipboardRaw, *aPrintDeck, *aExportDeckDecklist, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose;
|
||||||
QAction *aClearFilterAll, *aClearFilterOne;
|
QAction *aClearFilterAll, *aClearFilterOne;
|
||||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
||||||
QAction *aResetLayout;
|
QAction *aResetLayout;
|
||||||
|
|
Loading…
Reference in a new issue