61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#ifndef CONFIG_MGR_H
|
|
#define CONFIG_MGR_H
|
|
#include <memory>
|
|
#include <vector>
|
|
#include "cardbase.h"
|
|
#include <QDrag>
|
|
#include <QMimeData>
|
|
#include <QDragEnterEvent>
|
|
#include <QDebug>
|
|
#include <QListWidget>
|
|
|
|
class DraggableListWidget : public QListWidget {
|
|
public:
|
|
DraggableListWidget(QWidget *parent = nullptr) : QListWidget(parent) {
|
|
setDragEnabled(true);
|
|
}
|
|
|
|
protected:
|
|
void startDrag(Qt::DropActions supportedActions) override {
|
|
QListWidgetItem *item = currentItem();
|
|
if (!item) return;
|
|
|
|
QMimeData *mimeData = new QMimeData;
|
|
|
|
QString customData = item->data(Qt::UserRole).toString();
|
|
mimeData->setData("application/x-custom", customData.toUtf8());
|
|
|
|
QDrag *drag = new QDrag(this);
|
|
drag->setMimeData(mimeData);
|
|
drag->exec(Qt::CopyAction);
|
|
}
|
|
};
|
|
class ConfigMgr {
|
|
private:
|
|
static ConfigMgr *instance;
|
|
ConfigMgr() {
|
|
for (int i = 0; i < SLOT_NUM; ++i) {
|
|
card_type_[i] = kCardNone;
|
|
}
|
|
}
|
|
public:
|
|
int card_type_[15];
|
|
static ConfigMgr *Instance() {
|
|
if (instance == nullptr) {
|
|
instance = new ConfigMgr();
|
|
}
|
|
return instance;
|
|
}
|
|
~ConfigMgr();
|
|
void Save(QString & file_path);
|
|
void Load(QString filename);
|
|
std::shared_ptr<CardBase> GetSlotPtr(int slot);
|
|
void AddCard(std::shared_ptr<CardBase> ptr);
|
|
private:
|
|
QString filename_;
|
|
|
|
std::vector<std::shared_ptr<CardBase>> cards_;
|
|
};
|
|
|
|
#endif // CONFIG_MGR_H
|