From 579628b4c4cf65c5909da502cf98c691bfb9d603 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sun, 6 Jun 2010 16:06:38 +0200 Subject: [PATCH] save deck to clipboard --- cockatrice/src/window_deckeditor.cpp | 46 ++++++++++++++++++---------- cockatrice/src/window_deckeditor.h | 5 +-- common/decklist.cpp | 9 ++++-- common/decklist.h | 1 + 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp index b059732c..47f079a7 100644 --- a/cockatrice/src/window_deckeditor.cpp +++ b/cockatrice/src/window_deckeditor.cpp @@ -123,14 +123,18 @@ 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())); aSaveDeckAs = new QAction(tr("Save deck &as..."), this); // aSaveDeckAs->setShortcuts(QKeySequence::SaveAs); connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs())); + aLoadDeckFromClipboard = new QAction(tr("Load deck from cl&ipboard..."), this); + connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard())); + aLoadDeckFromClipboard->setShortcuts(QKeySequence::Paste); + aSaveDeckToClipboard = new QAction(tr("Save deck to cl&ipboard"), this); + connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard())); + aSaveDeckToClipboard->setShortcuts(QKeySequence::Copy); aPrintDeck = new QAction(tr("&Print deck..."), this); aPrintDeck->setShortcuts(QKeySequence::Print); connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck())); @@ -144,10 +148,12 @@ 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(); + deckMenu->addAction(aLoadDeckFromClipboard); + deckMenu->addAction(aSaveDeckToClipboard); + deckMenu->addSeparator(); deckMenu->addAction(aPrintDeck); deckMenu->addSeparator(); deckMenu->addAction(aClose); @@ -279,19 +285,6 @@ 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()) @@ -327,6 +320,27 @@ bool WndDeckEditor::actSaveDeckAs() return false; } +void WndDeckEditor::actLoadDeckFromClipboard() +{ + if (!confirmClose()) + return; + + DlgLoadDeckFromClipboard dlg; + if (!dlg.exec()) + return; + + setDeck(dlg.getDeckList()); + setWindowModified(true); +} + +void WndDeckEditor::actSaveDeckToClipboard() +{ + QString buffer; + QTextStream stream(&buffer); + deckModel->getDeckList()->saveToStream_Plain(stream); + QApplication::clipboard()->setText(buffer); +} + void WndDeckEditor::actPrintDeck() { QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this); diff --git a/cockatrice/src/window_deckeditor.h b/cockatrice/src/window_deckeditor.h index 4c095469..e14c1633 100644 --- a/cockatrice/src/window_deckeditor.h +++ b/cockatrice/src/window_deckeditor.h @@ -36,9 +36,10 @@ private slots: void actNewDeck(); void actLoadDeck(); - void actLoadDeckFromClipboard(); bool actSaveDeck(); bool actSaveDeckAs(); + void actLoadDeckFromClipboard(); + void actSaveDeckToClipboard(); void actPrintDeck(); void actEditSets(); @@ -71,7 +72,7 @@ private: DlgCardSearch *dlgCardSearch; QMenu *deckMenu, *dbMenu; - QAction *aNewDeck, *aLoadDeck, *aLoadDeckFromClipboard, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose; + QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aClose; QAction *aEditSets, *aSearch, *aClearSearch; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; public: diff --git a/common/decklist.cpp b/common/decklist.cpp index 58c161b4..4e120a0d 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -405,10 +405,9 @@ bool DeckList::loadFromFile_Plain(QIODevice *device) return loadFromStream_Plain(in); } -bool DeckList::saveToFile_Plain(QIODevice *device) +bool DeckList::saveToStream_Plain(QTextStream &out) { // Support for this is only possible if the internal structure doesn't get more complicated. - QTextStream out(device); for (int i = 0; i < root->size(); i++) { InnerDecklistNode *node = dynamic_cast(root->at(i)); for (int j = 0; j < node->size(); j++) { @@ -419,6 +418,12 @@ bool DeckList::saveToFile_Plain(QIODevice *device) return true; } +bool DeckList::saveToFile_Plain(QIODevice *device) +{ + QTextStream out(device); + return saveToStream_Plain(out); +} + bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt) { QFile file(fileName); diff --git a/common/decklist.h b/common/decklist.h index 39ec1efa..396594c3 100644 --- a/common/decklist.h +++ b/common/decklist.h @@ -140,6 +140,7 @@ public: bool saveToFile_Native(QIODevice *device); bool loadFromStream_Plain(QTextStream &stream); bool loadFromFile_Plain(QIODevice *device); + bool saveToStream_Plain(QTextStream &stream); bool saveToFile_Plain(QIODevice *device); bool loadFromFile(const QString &fileName, FileFormat fmt); bool saveToFile(const QString &fileName, FileFormat fmt);