~sithlord48/hyne/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/****************************************************************************
 ** Hyne Final Fantasy VIII Save Editor
 ** Copyright (C) 2009-2013 Arzel Jérôme <myst6re@gmail.com>
 **
 ** This program is free software: you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation, either version 3 of the License, or
 ** (at your option) any later version.
 **
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 **
 ** You should have received a copy of the GNU General Public License
 ** along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************/

#ifndef DEF_SAVECARDVIEW
#define DEF_SAVECARDVIEW

#include "QtWidgets.h"
#include "SavecardData.h"
#include "SavecardWidget.h"

class SavecardWidget;

class SavecardView : public QWidget
{
	Q_OBJECT

public:
	SavecardView(SavecardWidget *parent=0);
	virtual ~SavecardView();

	void clear();

	SavecardData *savecard() const;
	void setSavecard(SavecardData *save);

	void moveCursor(int saveID);

	inline static QSize saveSize() {
		return QSize(saveWidth(), saveHeight());
	}
	inline QPoint savePoint(int saveID) {
		return QPoint((width() - saveWidth()) / 2,
					  saveID * saveHeight());
	}
	inline QRect saveRect(int saveID) {
		return QRect(savePoint(saveID), saveSize());
	}
	inline static int saveWidth() { return 672; }
	inline static int saveHeight() { return 106; }
	inline static int horizontalMargin() { return 36; }
	void updateSave(int saveID, bool withCursor=false);
	void updateSaves(const QList<int> &saveIDs, bool withCursor=false);
	virtual QSize sizeHint() const;
	virtual QSize minimumSizeHint() const;
	// public function to draw a save preview
	static void renderSave(QPainter *painter, const SaveData *saveData, int currentIconFrame=0, const QRect &sourceRect=QRect());
	static void renderSave(QPixmap *pixmap, const SaveData *saveData, int currentIconFrame=0, const QRect &sourceRect=QRect());
	static void drawFrame(QPainter *painter, int width, int height);
	static void num2pix(QPainter *painter, QImage *numberPixmap, int x, int y, quint32 num, quint8 space=1, QChar fill=QChar(' '), int color=0);
public slots:
	void properties(int saveID=-1);
private slots:
	void notifyFileChanged(const QString &path);
	void edit(int saveID=-1);
	void exportPC(int saveID=-1);
	void newGame(int saveID=-1);
	void removeSave(int saveID=-1);
	void refreshIcon(SaveData *saveData);
	void nextIcon();
	void drop();
signals:
	void changed();
	void released(SaveData *saveData);
private:
	void moveDraggedSave(int saveID);
	void replaceSaveData(int saveID, const QByteArray &mimeData);
	void setDropIndicator(int saveID);
	void setBlackSave(int saveID);
	int saveID(const QPoint &pos) const;
	void restore(int saveID);
	static void renderSave(QPainter *painter, const SaveData *saveData, const QPixmap &menuBg, const QPixmap &fontPixmap, QImage &numberPixmap, int currentIconFrame=0, const QRect &sourceRect=QRect());
	static void colors(QImage *image, int color);

	int cursorID, blackID, dropIndicatorID;
	bool isExternalDrag;
	int _dragStart;
	bool notify;
	SavecardData *_data;
	SavecardWidget *_parent;
	int mouseMove;
	QPoint startPos;
	QByteArray *lastDropData;
	int lastDropID;
	int currentSaveIconFrame;
protected:
	virtual void paintEvent(QPaintEvent *event);
	virtual void mousePressEvent(QMouseEvent *event);
	virtual void mouseMoveEvent(QMouseEvent *event);
	virtual void mouseReleaseEvent(QMouseEvent *event);
	virtual void contextMenuEvent(QContextMenuEvent *event);
	virtual void changeEvent(QEvent *event);
	virtual void dragEnterEvent(QDragEnterEvent *event);
	virtual void dragMoveEvent(QDragMoveEvent *event);
	virtual void dragLeaveEvent(QDragLeaveEvent *event);
	virtual void dropEvent(QDropEvent *event);
};

#endif // DEF_SAVECARDVIEW