diff --git a/cockatrice/cockatrice.pro b/cockatrice/cockatrice.pro index a4e04489..44102ead 100644 --- a/cockatrice/cockatrice.pro +++ b/cockatrice/cockatrice.pro @@ -26,6 +26,7 @@ HEADERS += src/counter.h \ src/gameview.h \ src/deck_picturecacher.h \ src/decklistmodel.h \ + src/dlg_load_deck_from_clipboard.h \ src/dlg_load_remote_deck.h \ src/cardinfowidget.h \ src/messagelogwidget.h \ @@ -81,6 +82,7 @@ SOURCES += src/counter.cpp \ src/gameview.cpp \ src/deck_picturecacher.cpp \ src/decklistmodel.cpp \ + src/dlg_load_deck_from_clipboard.cpp \ src/dlg_load_remote_deck.cpp \ src/cardinfowidget.cpp \ src/messagelogwidget.cpp \ diff --git a/cockatrice/src/dlg_creategame.cpp b/cockatrice/src/dlg_creategame.cpp index fe59fefa..41406cc5 100644 --- a/cockatrice/src/dlg_creategame.cpp +++ b/cockatrice/src/dlg_creategame.cpp @@ -24,7 +24,7 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent) spectatorsAllowedCheckBox->setChecked(true); connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int))); spectatorsNeedPasswordCheckBox = new QCheckBox(tr("Spectators &need a password to join")); - spectatorsCanTalkCheckBox = new QCheckBox(tr("Spectators can &talk")); + spectatorsCanTalkCheckBox = new QCheckBox(tr("Spectators can &chat")); spectatorsSeeEverythingCheckBox = new QCheckBox(tr("Spectators see &everything")); QVBoxLayout *spectatorsLayout = new QVBoxLayout; spectatorsLayout->addWidget(spectatorsAllowedCheckBox); diff --git a/cockatrice/src/dlg_load_deck_from_clipboard.cpp b/cockatrice/src/dlg_load_deck_from_clipboard.cpp new file mode 100644 index 00000000..36741590 --- /dev/null +++ b/cockatrice/src/dlg_load_deck_from_clipboard.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "dlg_load_deck_from_clipboard.h" +#include "decklist.h" + +DlgLoadDeckFromClipboard::DlgLoadDeckFromClipboard(QWidget *parent) + : QDialog(parent), deckList(0) +{ + contentsEdit = new QPlainTextEdit; + + refreshButton = new QPushButton(tr("&Refresh")); + refreshButton->setShortcut(QKeySequence("F5")); + okButton = new QPushButton(tr("&OK")); + okButton->setDefault(true); + cancelButton = new QPushButton(tr("&Cancel")); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(refreshButton); + buttonLayout->addStretch(); + buttonLayout->addWidget(okButton); + buttonLayout->addWidget(cancelButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(contentsEdit); + mainLayout->addLayout(buttonLayout); + + setLayout(mainLayout); + + setWindowTitle(tr("Load deck from clipboard")); + resize(500, 500); + + connect(refreshButton, SIGNAL(clicked()), this, SLOT(actRefresh())); + connect(okButton, SIGNAL(clicked()), this, SLOT(actOK())); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + + actRefresh(); +} + +void DlgLoadDeckFromClipboard::actRefresh() +{ + contentsEdit->setPlainText(QApplication::clipboard()->text()); +} + +void DlgLoadDeckFromClipboard::actOK() +{ + QString buffer = contentsEdit->toPlainText(); + QTextStream stream(&buffer); + + DeckList *l = new DeckList; + if (l->loadFromStream_Plain(stream)) { + deckList = l; + accept(); + } else { + QMessageBox::critical(this, tr("Error"), tr("Invalid deck list.")); + delete l; + } +} diff --git a/cockatrice/src/dlg_load_deck_from_clipboard.h b/cockatrice/src/dlg_load_deck_from_clipboard.h new file mode 100644 index 00000000..f3db6ce6 --- /dev/null +++ b/cockatrice/src/dlg_load_deck_from_clipboard.h @@ -0,0 +1,25 @@ +#ifndef DLG_LOAD_DECK_FROM_CLIPBOARD_H +#define DLG_LOAD_DECK_FROM_CLIPBOARD_H + +#include + +class DeckList; +class QPlainTextEdit; +class QPushButton; + +class DlgLoadDeckFromClipboard : public QDialog { + Q_OBJECT +private slots: + void actOK(); + void actRefresh(); +private: + DeckList *deckList; +public: + DlgLoadDeckFromClipboard(QWidget *parent = 0); + DeckList *getDeckList() const { return deckList; } +private: + QPlainTextEdit *contentsEdit; + QPushButton *refreshButton, *okButton, *cancelButton; +}; + +#endif diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp index 2d3492de..b059732c 100644 --- a/cockatrice/src/window_deckeditor.cpp +++ b/cockatrice/src/window_deckeditor.cpp @@ -7,6 +7,7 @@ #include "cardinfowidget.h" #include "deck_picturecacher.h" #include "dlg_cardsearch.h" +#include "dlg_load_deck_from_clipboard.h" #include "main.h" void SearchLineEdit::keyPressEvent(QKeyEvent *event) @@ -122,6 +123,8 @@ WndDeckEditor::WndDeckEditor(QWidget *parent) aLoadDeck = new QAction(tr("&Load deck..."), this); aLoadDeck->setShortcuts(QKeySequence::Open); connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck())); + aLoadDeckFromClipboard = new QAction(tr("Load deck from cl&ipboard..."), this); + connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard())); aSaveDeck = new QAction(tr("&Save deck"), this); aSaveDeck->setShortcuts(QKeySequence::Save); connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck())); @@ -141,6 +144,7 @@ WndDeckEditor::WndDeckEditor(QWidget *parent) deckMenu = menuBar()->addMenu(tr("&Deck")); deckMenu->addAction(aNewDeck); deckMenu->addAction(aLoadDeck); + deckMenu->addAction(aLoadDeckFromClipboard); deckMenu->addAction(aSaveDeck); deckMenu->addAction(aSaveDeckAs); deckMenu->addSeparator(); @@ -275,6 +279,19 @@ void WndDeckEditor::actLoadDeck() delete l; } +void WndDeckEditor::actLoadDeckFromClipboard() +{ + if (!confirmClose()) + return; + + DlgLoadDeckFromClipboard dlg; + if (!dlg.exec()) + return; + + setDeck(dlg.getDeckList()); + setWindowModified(true); +} + bool WndDeckEditor::actSaveDeck() { if (lastFileName.isEmpty()) diff --git a/cockatrice/src/window_deckeditor.h b/cockatrice/src/window_deckeditor.h index dc8b6fe4..4c095469 100644 --- a/cockatrice/src/window_deckeditor.h +++ b/cockatrice/src/window_deckeditor.h @@ -36,6 +36,7 @@ private slots: void actNewDeck(); void actLoadDeck(); + void actLoadDeckFromClipboard(); bool actSaveDeck(); bool actSaveDeckAs(); void actPrintDeck(); @@ -70,7 +71,7 @@ private: DlgCardSearch *dlgCardSearch; QMenu *deckMenu, *dbMenu; - QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose; + QAction *aNewDeck, *aLoadDeck, *aLoadDeckFromClipboard, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose; QAction *aEditSets, *aSearch, *aClearSearch; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; public: diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index 328e0a44..99c0f084 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -27,47 +27,57 @@ AppearanceSettingsPage - + Zone background pictures Hintergrundbilder für Kartenzonen - + Path to hand background: Hintergrundbild für die Hand: - + Path to table background: Hintergrundbild für das Spielfeld: - + Path to player info background: Hintergrundbild für den Spielerbereich: - + + Hand layout + Kartenhand + + + + Display hand horizontally (wastes space) + Hand horizonal anzeigen (verschwendet Platz) + + + Table grid layout Spielfeldraster - + Economic layout Platzsparende Anordnung - + Zone view layout Aussehen des Zonenbetrachters - + Sort by name nach Namen sortieren - + Sort by type nach Kartentypen sortieren @@ -76,9 +86,9 @@ standardmäßig alphabetisch sortieren - - - + + + Choose path Pfad auswählen @@ -486,9 +496,13 @@ Zuschauer brauchen &auch ein Passwort - Spectators can &talk - Zuschauer können sp&rechen + Zuschauer können sp&rechen + + + + Spectators can &chat + Zuschauer können s&chreiben @@ -561,6 +575,39 @@ Mitteilung hinzufügen + + DlgLoadDeckFromClipboard + + + &Refresh + &Aktualisieren + + + + &OK + &OK + + + + &Cancel + A&bbrechen + + + + Load deck from clipboard + Deck aus der Zwischenablage laden + + + + Error + Fehler + + + + Invalid deck list. + Ungültige Deckliste. + + DlgLoadRemoteDeck @@ -582,54 +629,54 @@ DlgSettings - - - + + + Error Fehler - + Your card database is invalid. Please check if the path is set correctly. Ihre Kartendatenbank ist ungültig. Bitte überprüfen Sie, ob der Pfad korrekt gesetzt ist. - + The path to your deck directory is invalid. Der Pfad zum Deckverzeichnis ist ungültig. - + The path to your card pictures directory is invalid. Der Pfad zum Kartenbilderverzeichnis ist ungültig. - + Settings Einstellungen - + General Allgemeines - + Appearance Erscheinungsbild - + User interface Bedienung - + Messages Nachrichten - + &Close S&chließen @@ -965,7 +1012,7 @@ GameView - + Esc Esc @@ -1808,12 +1855,12 @@ MessagesSettingsPage - + &Add &Hinzufügen - + &Remove &Entfernen @@ -1826,12 +1873,12 @@ Entfernen - + Add message Nachricht hinzufügen - + Message: Nachricht: @@ -1897,41 +1944,41 @@ Player - - - + + + Move to &top of library Oben auf die Biblio&thek legen - - - + + + Move to &bottom of library Unter die &Bibliothek legen - + &View library &Zeige Bibliothek - + F3 F3 - + View &top cards of library... Zeige die oberen Kar&ten der Bibliothek... - + &View graveyard &Zeige Friedhof - + F4 F4 @@ -1940,32 +1987,32 @@ Zeige ent&fernte Karten - + &View sideboard Zeige &Sideboard - + Player "%1" Spieler "%1" - + Take &mulligan &Mulligan nehmen - + &Hand &Hand - + &Library Bib&liothek - + &Graveyard &Friedhof @@ -1974,70 +2021,70 @@ Entfe&rnte Karten - + &Sideboard &Sideboard - + View top cards of library Zeige die obersten Karten der Bibliothek - + Number of cards: Anzahl der Karten: - + &Draw card Karte &ziehen - + &View exile &Zeige Exil - + &Exile &Exil - - + + Move to &hand auf die &Hand nehmen - - + + Move to g&raveyard auf den &Friedhof legen - - + + Move to &exile ins &Exil schicken - + Ctrl+W Ctrl+W - + Ctrl+D Ctrl+D - + D&raw cards... Ka&rten ziehen... - + Ctrl+E Ctrl+E @@ -2046,32 +2093,32 @@ &Mulligan nehmen... - + Ctrl+M Ctrl+M - + &Shuffle Mi&schen - + Ctrl+S Ctrl+S - + &Counters &Zähler - + &Untap all permanents &Enttappe alle bleibenden Karten - + Ctrl+U Ctrl+U @@ -2100,143 +2147,143 @@ Ctrl+L - + R&oll die... &Würfeln... - + Ctrl+I Ctrl+I - + &Create token... &Token erstellen... - + Ctrl+T Ctrl+T - + S&ay &Sagen - + C&ard &Karte - + &Tap &Tappen - + &Untap E&nttappen - + Toggle &normal untapping &Normales Enttappen umschalten - + &Flip &Umdrehen - + &Add counter Zählm&arke hinzufügen - + &Remove counter Zählma&rke entfernen - + &Set counters... &Setze Zählmarken... - + &top of library &auf die Bibliothek - + &bottom of library &unter die Bibliothek - + &graveyard in den &Friedhof - + Ctrl+Del Ctrl+Del - + &exile ins &Exil - + &Move to &Verschieben - + F5 F5 - + F6 F6 - + F7 F7 - + F8 F8 - + F9 F9 - + F10 F10 - + Draw cards Karten ziehen - - + + Number: Anzahl: - + Set counters Setze Zählmarken @@ -2249,22 +2296,22 @@ Neue Lebenspunkte insgesamt: - + Roll die Würfeln - + Number of sides: Anzahl der Seiten: - + Create token Token erstellen - + Name: Name: @@ -2573,7 +2620,7 @@ Bitte geben Sie einen Namen ein: Sind Sie sicher, dass Sie das Spiel verlassen möchten? - + Load deck Deck laden @@ -2609,12 +2656,12 @@ Bitte geben Sie einen Namen ein: UserInterfaceSettingsPage - + General interface settings Allgemeine Bedienung - + &Double-click cards to play them (instead of single-click) Karten durch &Doppelklick ausspielen (statt Einzelklick) @@ -2622,37 +2669,37 @@ Bitte geben Sie einen Namen ein: WndDeckEditor - + &Search for: &Suchen nach: - + Deck &name: Deck &Name: - + &Comments: &Kommentare: - + Deck editor [*] Deck-Editor [*] - + &New deck &Neues Deck - + &Load deck... Deck &laden... - + &Save deck Deck &speichern @@ -2661,32 +2708,32 @@ Bitte geben Sie einen Namen ein: Deck &speichern unter... - + Save deck &as... Deck s&peichern unter... - + &Print deck... Deck &drucken... - + &Close S&chließen - + Ctrl+Q Ctrl+Q - + &Edit sets... &Editionen bearbeiten... - + &Deck &Deck @@ -2695,27 +2742,27 @@ Bitte geben Sie einen Namen ein: &Editionen - + Add card to &maindeck Karte zu&m Hauptdeck hinzufügen - + Return Return - + Enter Enter - + Ctrl+Return Ctrl+Return - + Ctrl+Enter Ctrl+Enter @@ -2724,7 +2771,7 @@ Bitte geben Sie einen Namen ein: Ctrl+M - + Add card to &sideboard Karte zum &Sideboard hinzufügen @@ -2733,69 +2780,74 @@ Bitte geben Sie einen Namen ein: Ctrl+N - + &Search... &Suchen... - + &Clear search Suche a&ufheben - + + Load deck from cl&ipboard... + Deck aus &Zwischenablage laden... + + + &Card database &Kartendatenbank - + &Remove row Zeile entfe&rnen - + Del Entf - + &Increment number Anzahl er&höhen - + + + - + &Decrement number Anzahl v&erringern - + - - - + Are you sure? Bist du sicher? - + The decklist has been modified. Do you want to save the changes? Die Deckliste wurde verändert. Willst du die Änderungen speichern? - + Load deck Deck laden - + Save deck Deck speichern diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 2d9eba8b..00932289 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -4,54 +4,64 @@ AppearanceSettingsPage - + Zone background pictures - + Path to hand background: - + Path to table background: - + Path to player info background: - + + Hand layout + + + + + Display hand horizontally (wastes space) + + + + Table grid layout - + Economic layout - + Zone view layout - + Sort by name - + Sort by type - - - + + + Choose path @@ -407,7 +417,7 @@ - Spectators can &talk + Spectators can &chat @@ -446,6 +456,39 @@ + + DlgLoadDeckFromClipboard + + + &Refresh + + + + + &OK + + + + + &Cancel + + + + + Load deck from clipboard + + + + + Error + + + + + Invalid deck list. + + + DlgLoadRemoteDeck @@ -467,54 +510,54 @@ DlgSettings - - - + + + Error - + Your card database is invalid. Please check if the path is set correctly. - + The path to your deck directory is invalid. - + The path to your card pictures directory is invalid. - + Settings - + General - + Appearance - + User interface - + Messages - + &Close @@ -588,7 +631,7 @@ GameView - + Esc @@ -1135,22 +1178,22 @@ MessagesSettingsPage - + &Add - + &Remove - + Add message - + Message: @@ -1216,330 +1259,330 @@ Player - - - + + + Move to &top of library - - - + + + Move to &bottom of library - + &View library - + F3 - + View &top cards of library... - + &View graveyard - + F4 - + &View sideboard - + Player "%1" - + &Hand - + &Library - + &Graveyard - + &Sideboard - + View top cards of library - + Number of cards: - + &Draw card - + &View exile - + &Exile - - + + Move to &hand - - + + Move to g&raveyard - - + + Move to &exile - + Ctrl+W - + Ctrl+D - + D&raw cards... - + Ctrl+E - + Take &mulligan - + Ctrl+M - + &Shuffle - + Ctrl+S - + &Counters - + &Untap all permanents - + Ctrl+U - + R&oll die... - + Ctrl+I - + &Create token... - + Ctrl+T - + S&ay - + C&ard - + &Tap - + &Untap - + Toggle &normal untapping - + &Flip - + &Add counter - + &Remove counter - + &Set counters... - + &top of library - + &bottom of library - + &graveyard - + Ctrl+Del - + &exile - + &Move to - + F5 - + F6 - + F7 - + F8 - + F9 - + F10 - + Draw cards - - + + Number: - + Roll die - + Number of sides: - + Create token - + Name: - + Set counters @@ -1827,7 +1870,7 @@ Please enter a name: - + Load deck @@ -1848,12 +1891,12 @@ Please enter a name: UserInterfaceSettingsPage - + General interface settings - + &Double-click cards to play them (instead of single-click) @@ -1861,162 +1904,167 @@ Please enter a name: WndDeckEditor - + &Search for: - + Deck &name: - + &Comments: - + Deck editor [*] - + &New deck - + &Load deck... - - &Save deck + + Load deck from cl&ipboard... - Save deck &as... + &Save deck - &Print deck... + Save deck &as... + &Print deck... + + + + &Close - + Ctrl+Q - + &Edit sets... - + &Deck - + Load deck - + Save deck - + Add card to &maindeck - + Return - + Enter - + Ctrl+Return - + Ctrl+Enter - + Add card to &sideboard - + &Search... - + &Clear search - + &Card database - + &Remove row - + Del - + &Increment number - + + - + &Decrement number - + - - + Are you sure? - + The decklist has been modified. Do you want to save the changes? diff --git a/common/decklist.cpp b/common/decklist.cpp index 376a3298..58c161b4 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -359,11 +359,11 @@ bool DeckList::saveToFile_Native(QIODevice *device) return true; } -bool DeckList::loadFromFile_Plain(QIODevice *device) +bool DeckList::loadFromStream_Plain(QTextStream &in) { InnerDecklistNode *main = 0, *side = 0; - QTextStream in(device); + int okRows = 0; while (!in.atEnd()) { QString line = in.readLine().simplified(); if (line.startsWith("//")) @@ -393,9 +393,16 @@ bool DeckList::loadFromFile_Plain(QIODevice *device) int number = line.left(i).toInt(&ok); if (!ok) continue; + ++okRows; new DecklistCardNode(line.mid(i + 1), number, zone); } - return true; + return (okRows > 0); +} + +bool DeckList::loadFromFile_Plain(QIODevice *device) +{ + QTextStream in(device); + return loadFromStream_Plain(in); } bool DeckList::saveToFile_Plain(QIODevice *device) diff --git a/common/decklist.h b/common/decklist.h index e55bba30..39ec1efa 100644 --- a/common/decklist.h +++ b/common/decklist.h @@ -9,6 +9,7 @@ class CardDatabase; class QIODevice; +class QTextStream; class QXmlStreamReader; class QXmlStreamWriter; @@ -137,6 +138,7 @@ public: bool loadFromFile_Native(QIODevice *device); bool saveToFile_Native(QIODevice *device); + bool loadFromStream_Plain(QTextStream &stream); bool loadFromFile_Plain(QIODevice *device); bool saveToFile_Plain(QIODevice *device); bool loadFromFile(const QString &fileName, FileFormat fmt);