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
15#include <memory>
16
17#include <mgba-util/text-codec.h>
18
19struct mCore;
20
21namespace QGBA {
22
23class CoreController;
24
25class MemoryModel : public QAbstractScrollArea {
26Q_OBJECT
27
28public:
29 MemoryModel(QWidget* parent = nullptr);
30
31 void setController(std::shared_ptr<CoreController> controller);
32
33 void setRegion(uint32_t base, uint32_t size, const QString& name = QString(), int segment = -1);
34 void setSegment(int segment);
35
36 void setAlignment(int);
37 int alignment() const { return m_align; }
38
39 QByteArray serialize();
40 void deserialize(const QByteArray&);
41 QString decodeText(const QByteArray&);
42
43public slots:
44 void jumpToAddress(const QString& hex);
45 void jumpToAddress(uint32_t);
46
47 void loadTBLFromPath(const QString& path);
48 void loadTBL();
49
50 void copy();
51 void paste();
52 void save();
53 void load();
54
55signals:
56 void selectionChanged(uint32_t start, uint32_t end);
57
58protected:
59 void resizeEvent(QResizeEvent*) override;
60 void paintEvent(QPaintEvent*) override;
61 void wheelEvent(QWheelEvent*) override;
62 void mousePressEvent(QMouseEvent*) override;
63 void mouseMoveEvent(QMouseEvent*) override;
64 void keyPressEvent(QKeyEvent*) override;
65
66private:
67 void boundsCheck();
68
69 bool isInSelection(uint32_t address);
70 bool isEditing(uint32_t address);
71 void drawEditingText(QPainter& painter, const QPointF& origin);
72
73 void adjustCursor(int adjust, bool shift);
74
75 class TextCodecFree {
76 public:
77 void operator()(TextCodec*);
78 };
79
80 mCore* m_core = nullptr;
81 std::unique_ptr<TextCodec, TextCodecFree> m_codec;
82 QFont m_font;
83 int m_cellHeight;
84 int m_letterWidth;
85 uint32_t m_base;
86 uint32_t m_size;
87 int m_top = 0;
88 int m_align = 1;
89 QMargins m_margins;
90 QVector<QStaticText> m_staticNumbers;
91 QVector<QStaticText> m_staticLatin1;
92 QStaticText m_regionName;
93 QSizeF m_cellSize;
94 QPair<uint32_t, uint32_t> m_selection{0, 0};
95 uint32_t m_selectionAnchor = 0;
96 uint32_t m_buffer;
97 int m_bufferedNybbles;
98 int m_currentBank;
99};
100
101}
102
103#endif