import and export runes
This commit is contained in:
parent
5aff7f431a
commit
17b244ec81
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class ClipboardPopup;
|
||||
}
|
||||
|
||||
class ClipboardPopup : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class Direction {
|
||||
Paste,
|
||||
Copy
|
||||
};
|
||||
|
||||
explicit ClipboardPopup(Direction dir, QWidget* parent = nullptr);
|
||||
~ClipboardPopup();
|
||||
|
||||
void setText(QString text);
|
||||
QString getText() const;
|
||||
|
||||
private slots:
|
||||
void textPasted();
|
||||
void copyButton();
|
||||
|
||||
private:
|
||||
Ui::ClipboardPopup *ui;
|
||||
|
||||
Direction direction;
|
||||
int lastKnownTextSize = 0;
|
||||
};
|
|
@ -50,6 +50,8 @@ private slots:
|
|||
void deleteCurrentItem();
|
||||
void editCurrentItem();
|
||||
void duplicateCurrentItem();
|
||||
void exportCurrentItem();
|
||||
void importItem();
|
||||
|
||||
private:
|
||||
void clearItems();
|
||||
|
|
|
@ -43,6 +43,7 @@ SOURCES += \
|
|||
src/clientaccess.cpp \
|
||||
src/clientapi_json.cpp \
|
||||
src/clientapi.cpp \
|
||||
src/clipboardpopup.cpp \
|
||||
src/config.cpp \
|
||||
src/datadragon.cpp \
|
||||
src/datadragonimagecache.cpp \
|
||||
|
@ -75,6 +76,7 @@ HEADERS += \
|
|||
include/champrow.h \
|
||||
include/clientaccess.h \
|
||||
include/clientapi.h \
|
||||
include/clipboardpopup.h \
|
||||
include/config.h \
|
||||
include/datadragon.h \
|
||||
include/datadragonimagecache.h \
|
||||
|
@ -97,6 +99,7 @@ HEADERS += \
|
|||
|
||||
FORMS += \
|
||||
ui/championsearch.ui \
|
||||
ui/clipboardpopup.ui \
|
||||
ui/mainwindow.ui \
|
||||
ui/runeaspektbutton.ui \
|
||||
ui/runedisplay.ui \
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include "clipboardpopup.h"
|
||||
#include "ui_clipboardpopup.h"
|
||||
|
||||
#include <QClipboard>
|
||||
|
||||
ClipboardPopup::ClipboardPopup(Direction dir, QWidget* parent) : QDialog(parent), ui(new Ui::ClipboardPopup), direction(dir) {
|
||||
ui->setupUi(this);
|
||||
|
||||
if(direction == Direction::Paste) {
|
||||
this->ui->copyButton->hide();
|
||||
this->ui->text->setPlaceholderText(ClipboardPopup::tr("Paste here"));
|
||||
this->ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
||||
|
||||
QObject::connect(this->ui->text, &QTextEdit::textChanged, this, &ClipboardPopup::textPasted);
|
||||
} else {
|
||||
// copy
|
||||
this->ui->text->setReadOnly(true);
|
||||
}
|
||||
|
||||
QObject::connect(this->ui->copyButton, &QPushButton::pressed, this, &ClipboardPopup::copyButton);
|
||||
}
|
||||
|
||||
ClipboardPopup::~ClipboardPopup() {
|
||||
delete this->ui;
|
||||
}
|
||||
|
||||
void ClipboardPopup::textPasted() {
|
||||
int newTextSize = this->getText().size();
|
||||
if(newTextSize - 1 > lastKnownTextSize && newTextSize > 1) {
|
||||
// asume that something was pasted
|
||||
accept();
|
||||
return;
|
||||
}
|
||||
|
||||
if(newTextSize > 0) {
|
||||
this->ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
||||
}
|
||||
|
||||
lastKnownTextSize = newTextSize;
|
||||
}
|
||||
|
||||
void ClipboardPopup::setText(QString text) {
|
||||
this->ui->text->setText(text);
|
||||
this->ui->text->selectAll();
|
||||
}
|
||||
|
||||
QString ClipboardPopup::getText() const {
|
||||
return this->ui->text->toPlainText();
|
||||
}
|
||||
|
||||
void ClipboardPopup::copyButton() {
|
||||
QClipboard* clip = qApp->clipboard();
|
||||
clip->setText(this->ui->text->toPlainText());
|
||||
|
||||
// close this dialog
|
||||
accept();
|
||||
}
|
|
@ -24,6 +24,8 @@ RuneEditor::~RuneEditor() {
|
|||
void RuneEditor::setClient(ClientAPI& client) {
|
||||
this->client = &client;
|
||||
|
||||
if(!this->client) return;
|
||||
|
||||
try {
|
||||
// build ui
|
||||
aspekts = client.getAllRuneAspekts();
|
||||
|
|
|
@ -109,9 +109,7 @@ void RuneManager::loadRunes() {
|
|||
|
||||
void RuneManager::setRunesEnabled(bool enabled) {
|
||||
this->ui->lblClientRunes->setEnabled(enabled);
|
||||
this->ui->lblaaRunes->setEnabled(enabled);
|
||||
this->ui->listClientRunes->setEnabled(enabled);
|
||||
this->ui->listaaRunes->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void RuneManager::saveRunePageClient(int id, QString name, const RunePage& rp) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QMimeData>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "clipboardpopup.h"
|
||||
#include "datadragon.h"
|
||||
#include "runeeditor.h"
|
||||
|
||||
|
@ -79,6 +80,8 @@ void RunePageList::openContextMenu(const QPoint& pos) {
|
|||
menu.addAction(QIcon::fromTheme("edit-delete"), RunePageList::tr("Delete"), this, &RunePageList::deleteCurrentItem);
|
||||
menu.addAction(QIcon::fromTheme("document-open"), RunePageList::tr("Edit (Beta)"), this, &RunePageList::editCurrentItem);
|
||||
menu.addAction(QIcon::fromTheme("edit-copy"), RunePageList::tr("Duplicate"), this, &RunePageList::duplicateCurrentItem);
|
||||
menu.addAction(QIcon::fromTheme("document-send"), RunePageList::tr("Export"), this, &RunePageList::exportCurrentItem);
|
||||
menu.addAction(QIcon::fromTheme("document-new"), RunePageList::tr("Import"), this, &RunePageList::importItem);
|
||||
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
@ -142,6 +145,46 @@ void RunePageList::duplicateCurrentItem() {
|
|||
emit runepageChanged(-1, name, *rp);
|
||||
}
|
||||
|
||||
void RunePageList::exportCurrentItem() {
|
||||
QListWidgetItem* item = currentItem();
|
||||
if(!item) return;
|
||||
|
||||
const RunePage* rp = (RunePage*) item->data(RolePointer).toULongLong();
|
||||
|
||||
Config::RunePageConfig rpc;
|
||||
rpc.name = item->text();
|
||||
rpc.runepage = *rp;
|
||||
|
||||
QJsonDocument rpcDoc(rpc); // cast to QJsonObject
|
||||
QByteArray jsonBytes = rpcDoc.toJson(QJsonDocument::Compact).toBase64();
|
||||
QString runePageString = QString::fromLocal8Bit(jsonBytes);
|
||||
|
||||
ClipboardPopup popup(ClipboardPopup::Direction::Copy);
|
||||
popup.setText(runePageString);
|
||||
popup.exec();
|
||||
}
|
||||
|
||||
void RunePageList::importItem() {
|
||||
ClipboardPopup popup(ClipboardPopup::Direction::Paste);
|
||||
if(popup.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString text = popup.getText();
|
||||
QByteArray jsonBytes = QByteArray::fromBase64(text.toLocal8Bit());
|
||||
QJsonDocument rpcDoc = QJsonDocument::fromJson(jsonBytes);
|
||||
if(rpcDoc.isObject()) {
|
||||
QJsonObject rpcJson = rpcDoc.object();
|
||||
Config::RunePageConfig rpc = rpcJson; // implicit cast
|
||||
|
||||
if(rpc.name.isEmpty() || !rpc.runepage) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit runepageChanged(-1, rpc.name, rpc.runepage);
|
||||
}
|
||||
}
|
||||
|
||||
void RunePageList::clearItems() {
|
||||
while(count()) {
|
||||
QListWidgetItem* item = takeItem(0);
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ClipboardPopup</class>
|
||||
<widget class="QDialog" name="ClipboardPopup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Clipboard Text</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="copyButton">
|
||||
<property name="text">
|
||||
<string>Copy To Clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QTextEdit" name="text"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ClipboardPopup</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ClipboardPopup</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Reference in New Issue