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
15struct mCore;
16
17namespace QGBA {
18
19class GameController;
20
21class MemoryModel : public QAbstractScrollArea {
22Q_OBJECT
23
24public:
25 MemoryModel(QWidget* parent = nullptr);
26
27 void setController(GameController* controller);
28
29 void setRegion(uint32_t base, uint32_t size, const QString& name = QString(), int segment = -1);
30 void setSegment(int segment);
31
32 void setAlignment(int);
33 int alignment() const { return m_align; }
34
35public slots:
36 void jumpToAddress(const QString& hex);
37 void jumpToAddress(uint32_t);
38
39 void copy();
40 void save();
41
42signals:
43 void selectionChanged(uint32_t start, uint32_t end);
44
45protected:
46 void resizeEvent(QResizeEvent*) override;
47 void paintEvent(QPaintEvent*) override;
48 void wheelEvent(QWheelEvent*) override;
49 void mousePressEvent(QMouseEvent*) override;
50 void mouseMoveEvent(QMouseEvent*) override;
51 void keyPressEvent(QKeyEvent*) override;
52
53private:
54 void boundsCheck();
55
56 bool isInSelection(uint32_t address);
57 bool isEditing(uint32_t address);
58 void drawEditingText(QPainter& painter, const QPointF& origin);
59
60 void adjustCursor(int adjust, bool shift);
61
62 void serialize(QDataStream* stream);
63
64 mCore* m_core;
65 QFont m_font;
66 int m_cellHeight;
67 int m_letterWidth;
68 uint32_t m_base;
69 uint32_t m_size;
70 int m_top;
71 int m_align;
72 QMargins m_margins;
73 QVector<QStaticText> m_staticNumbers;
74 QVector<QStaticText> m_staticAscii;
75 QStaticText m_regionName;
76 QSizeF m_cellSize;
77 QPair<uint32_t, uint32_t> m_selection;
78 uint32_t m_selectionAnchor;
79 uint32_t m_buffer;
80 int m_bufferedNybbles;
81 int m_currentBank;
82};
83
84}
85
86#endif