src/platform/qt/MemoryModel.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_MEMORY_MODEL
7#define QGBA_MEMORY_MODEL
8
9#include <QAbstractScrollArea>
10#include <QFont>
11#include <QSize>
12#include <QStaticText>
13#include <QVector>
14#include <memory>
15
16extern "C" {
17#include "util/text-codec.h"
18}
19
20struct mCore;
21
22namespace QGBA {
23
24class GameController;
25
26class MemoryModel : public QAbstractScrollArea {
27Q_OBJECT
28
29public:
30 MemoryModel(QWidget* parent = nullptr);
31
32 void setController(GameController* controller);
33
34 void setRegion(uint32_t base, uint32_t size, const QString& name = QString(), int segment = -1);
35 void setSegment(int segment);
36
37 void setAlignment(int);
38 int alignment() const { return m_align; }
39
40 QByteArray serialize();
41 void deserialize(const QByteArray&);
42 QString decodeText(const QByteArray&);
43
44public slots:
45 void jumpToAddress(const QString& hex);
46 void jumpToAddress(uint32_t);
47
48 void loadTBL(const QString& path);
49 void loadTBL();
50
51 void copy();
52 void paste();
53 void save();
54 void load();
55
56signals:
57 void selectionChanged(uint32_t start, uint32_t end);
58
59protected:
60 void resizeEvent(QResizeEvent*) override;
61 void paintEvent(QPaintEvent*) override;
62 void wheelEvent(QWheelEvent*) override;
63 void mousePressEvent(QMouseEvent*) override;
64 void mouseMoveEvent(QMouseEvent*) override;
65 void keyPressEvent(QKeyEvent*) override;
66
67private:
68 void boundsCheck();
69
70 bool isInSelection(uint32_t address);
71 bool isEditing(uint32_t address);
72 void drawEditingText(QPainter& painter, const QPointF& origin);
73
74 void adjustCursor(int adjust, bool shift);
75
76 class TextCodecFree {
77 public:
78 void operator()(TextCodec*);
79 };
80
81 mCore* m_core;
82 std::unique_ptr<TextCodec, TextCodecFree> m_codec;
83 QFont m_font;
84 int m_cellHeight;
85 int m_letterWidth;
86 uint32_t m_base;
87 uint32_t m_size;
88 int m_top;
89 int m_align;
90 QMargins m_margins;
91 QVector<QStaticText> m_staticNumbers;
92 QVector<QStaticText> m_staticAscii;
93 QStaticText m_regionName;
94 QSizeF m_cellSize;
95 QPair<uint32_t, uint32_t> m_selection;
96 uint32_t m_selectionAnchor;
97 uint32_t m_buffer;
98 int m_bufferedNybbles;
99 int m_currentBank;
100};
101
102}
103
104#endif