mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-13 01:24:46 -07:00
load deck from clipboard; closing feature request 0000019
This commit is contained in:
parent
e6e20cb048
commit
ca12aeb5a7
10 changed files with 498 additions and 280 deletions
|
|
@ -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);
|
||||
|
|
|
|||
64
cockatrice/src/dlg_load_deck_from_clipboard.cpp
Normal file
64
cockatrice/src/dlg_load_deck_from_clipboard.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <QClipboard>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QKeySequence>
|
||||
#include <QApplication>
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
25
cockatrice/src/dlg_load_deck_from_clipboard.h
Normal file
25
cockatrice/src/dlg_load_deck_from_clipboard.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef DLG_LOAD_DECK_FROM_CLIPBOARD_H
|
||||
#define DLG_LOAD_DECK_FROM_CLIPBOARD_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
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
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue