save deck to clipboard

This commit is contained in:
Max-Wilhelm Bruker 2010-06-06 16:06:38 +02:00
parent 37de620e93
commit 579628b4c4
4 changed files with 41 additions and 20 deletions

View file

@ -123,14 +123,18 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
aLoadDeck = new QAction(tr("&Load deck..."), this); aLoadDeck = new QAction(tr("&Load deck..."), this);
aLoadDeck->setShortcuts(QKeySequence::Open); aLoadDeck->setShortcuts(QKeySequence::Open);
connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck())); 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 = new QAction(tr("&Save deck"), this);
aSaveDeck->setShortcuts(QKeySequence::Save); aSaveDeck->setShortcuts(QKeySequence::Save);
connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck())); connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck()));
aSaveDeckAs = new QAction(tr("Save deck &as..."), this); aSaveDeckAs = new QAction(tr("Save deck &as..."), this);
// aSaveDeckAs->setShortcuts(QKeySequence::SaveAs); // aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs())); 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 = new QAction(tr("&Print deck..."), this);
aPrintDeck->setShortcuts(QKeySequence::Print); aPrintDeck->setShortcuts(QKeySequence::Print);
connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck())); connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
@ -144,10 +148,12 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
deckMenu = menuBar()->addMenu(tr("&Deck")); deckMenu = menuBar()->addMenu(tr("&Deck"));
deckMenu->addAction(aNewDeck); deckMenu->addAction(aNewDeck);
deckMenu->addAction(aLoadDeck); deckMenu->addAction(aLoadDeck);
deckMenu->addAction(aLoadDeckFromClipboard);
deckMenu->addAction(aSaveDeck); deckMenu->addAction(aSaveDeck);
deckMenu->addAction(aSaveDeckAs); deckMenu->addAction(aSaveDeckAs);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aLoadDeckFromClipboard);
deckMenu->addAction(aSaveDeckToClipboard);
deckMenu->addSeparator();
deckMenu->addAction(aPrintDeck); deckMenu->addAction(aPrintDeck);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aClose); deckMenu->addAction(aClose);
@ -279,19 +285,6 @@ void WndDeckEditor::actLoadDeck()
delete l; delete l;
} }
void WndDeckEditor::actLoadDeckFromClipboard()
{
if (!confirmClose())
return;
DlgLoadDeckFromClipboard dlg;
if (!dlg.exec())
return;
setDeck(dlg.getDeckList());
setWindowModified(true);
}
bool WndDeckEditor::actSaveDeck() bool WndDeckEditor::actSaveDeck()
{ {
if (lastFileName.isEmpty()) if (lastFileName.isEmpty())
@ -327,6 +320,27 @@ bool WndDeckEditor::actSaveDeckAs()
return false; 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() void WndDeckEditor::actPrintDeck()
{ {
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this); QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);

View file

@ -36,9 +36,10 @@ private slots:
void actNewDeck(); void actNewDeck();
void actLoadDeck(); void actLoadDeck();
void actLoadDeckFromClipboard();
bool actSaveDeck(); bool actSaveDeck();
bool actSaveDeckAs(); bool actSaveDeckAs();
void actLoadDeckFromClipboard();
void actSaveDeckToClipboard();
void actPrintDeck(); void actPrintDeck();
void actEditSets(); void actEditSets();
@ -71,7 +72,7 @@ private:
DlgCardSearch *dlgCardSearch; DlgCardSearch *dlgCardSearch;
QMenu *deckMenu, *dbMenu; 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 *aEditSets, *aSearch, *aClearSearch;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
public: public:

View file

@ -405,10 +405,9 @@ bool DeckList::loadFromFile_Plain(QIODevice *device)
return loadFromStream_Plain(in); 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. // 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++) { for (int i = 0; i < root->size(); i++) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i)); InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
for (int j = 0; j < node->size(); j++) { for (int j = 0; j < node->size(); j++) {
@ -419,6 +418,12 @@ bool DeckList::saveToFile_Plain(QIODevice *device)
return true; return true;
} }
bool DeckList::saveToFile_Plain(QIODevice *device)
{
QTextStream out(device);
return saveToStream_Plain(out);
}
bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt) bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt)
{ {
QFile file(fileName); QFile file(fileName);

View file

@ -140,6 +140,7 @@ public:
bool saveToFile_Native(QIODevice *device); bool saveToFile_Native(QIODevice *device);
bool loadFromStream_Plain(QTextStream &stream); bool loadFromStream_Plain(QTextStream &stream);
bool loadFromFile_Plain(QIODevice *device); bool loadFromFile_Plain(QIODevice *device);
bool saveToStream_Plain(QTextStream &stream);
bool saveToFile_Plain(QIODevice *device); bool saveToFile_Plain(QIODevice *device);
bool loadFromFile(const QString &fileName, FileFormat fmt); bool loadFromFile(const QString &fileName, FileFormat fmt);
bool saveToFile(const QString &fileName, FileFormat fmt); bool saveToFile(const QString &fileName, FileFormat fmt);