Q3270
A Qt-based 3270 Terminal Emulator
Loading...
Searching...
No Matches
DisplayScreen.h
1/*
2 * Q3270 Terminal Emulator
3 *
4 * Copyright (c) 2020–2025 Andy Styles
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * This file is part of Q3270.
8 * See the LICENSE file in the project root for full license information.
9 */
10
11#ifndef DISPLAYSCREEN_H
12#define DISPLAYSCREEN_H
13
14#include <QGraphicsView>
15#include <QGraphicsSceneMouseEvent>
16#include <QString>
17#include <QDebug>
18#include <QtSvg>
19#include <QTimer>
20#include <QObject>
21
22#include "Cell.h"
23#include "CodePage.h"
24#include "Q3270.h"
25#include "Models/Colours.h"
26#include "Display/ClickableSvgItem.h"
27#include "Display/LockIndicator.h"
28
29class DisplayScreen : public QGraphicsObject
30{
31 Q_OBJECT
32
33 public:
34
35 explicit DisplayScreen(int screen_x, int screen_y, CodePage &cp, const Colours *palette);
37
38 void mousePressEvent(QGraphicsSceneMouseEvent *mEvent) override;
39 void mouseMoveEvent(QGraphicsSceneMouseEvent *mEvent) override;
40 void mouseReleaseEvent(QGraphicsSceneMouseEvent *mEvent) override;
41
42 QRectF boundingRect() const override;
43
44 void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) override;
45
46
47 int width() const;
48 int height() const;
49 qreal gridWidth() const;
50 qreal gridHeight() const;
51
52 void setSize(const int x, const int y);
53
54 void setChar(int pos, uchar c, bool fromKB);
55 void setCharAttr(unsigned char c, unsigned char d);
56
57 void resetExtendedHilite(int pos);
58 void resetExtended(int pos);
59 void resetCharAttr();
60 void resetColours();
61 void resetMDTs();
62
63 void setExtendedColour(int pos, bool foreground, unsigned char c);
64
65 void setExtendedBlink(int pos);
66 void setExtendedReverse(int pos);
67 void setExtendedUscore(int pos);
68
69 void setField(int pos, unsigned char c, bool sfe);
70 void setGraphicEscape();
71
72 void getModifiedFields(QByteArray &buffer);
73
74 int findNextUnprotectedField(int pos);
75 int findPrevUnprotectedField(int pos);
76
77 bool insertChar(unsigned char c, bool insertMode);
78
79 void eraseUnprotected(int start, int end, Q3270::EraseResetMDT resetMDT);
80
81 void setCursor(const int x, const int y);
82 void setCursor(int pos);
83 void showCursor();
84 void cascadeAttrs(int startpos);
85
86 bool isAskip(int pos) const;
87 bool isProtected(int pos) const;
88 bool isFieldStart(int pos) const;
89
90 void clear();
91 void setFont(const QFont &font);
92 void setFontTweak(const Q3270::FontTweak f);
93
94 void toggleRuler();
95 void setRuler();
96 void rulerMode(bool on);
97
98 void setRulerStyle(Q3270::RulerStyle rulerStyle);
99
100 void getScreen(QByteArray &buffer);
101 void readBuffer();
102
103 void addPosToBuffer(QByteArray &buffer, int pos);
104
105 void dumpFields();
106 void dumpDisplay();
107 void dumpInfo();
108
109 signals:
110
111 void bufferReady(QByteArray &buffer);
112 void cursorMoved(int x, int y);
113
114 public slots:
115
116 void blink();
117 void cursorBlink();
118
119 void setCursorColour(bool inherit);
120 void copyText();
121
122 void moveCursor(int x, int y);
123 void deleteChar();
124 void newline();
125 void tab(int offset);
126 void backtab();
127 void home();
128 void backspace();
129 void eraseEOF();
130 void endline();
131
132 void processAID(int aid, bool shortread);
133 void interruptProcess();
134
135 private:
136
137 const unsigned char twelveBitBufferAddress[64] = {
138 0x40, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, /* 00 0000 to 00 0011 */
139 0xC8, 0xC9, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, /* 00 0100 to 00 1111 */
140 0x50, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, /* 01 0000 to 01 0011 */
141 0xD8, 0xD9, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, /* 01 0100 to 01 1111 */
142 0x60, 0x61, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, /* 10 0000 to 10 0011 */
143 0xE8, 0xE9, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, /* 10 0100 to 10 1111 */
144 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, /* 11 0000 to 11 0011 */
145 0xF8, 0xF9, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, /* 11 0100 to 11 1111 */
146 };
147
148 const CodePage &cp;
149 const Colours *palette;
150
151 int screen_x; /* Max Columns */
152 int screen_y; /* Max Rows */
153 int screenPos_max; /* Max position on screen */
154
155 int cursor_pos; /* Cursor position */
156
157 QVector<Cell> cells; /* Screen slot */
158
159 bool blinkShow; /* Whether the character is shown/hidden for a given blink event */
160 bool cursorShow; /* Whether the cursor is shown/hidden for a given blink event */
161 bool cursorColour; // Whether cursor inherits the colour of the character underneath
162
163 bool geActive; // Next character is Graphic Escape
164
165 bool rulerOn; // Whether ruler is displayed
166 Q3270::RulerStyle ruler; // Style of ruler
167
168 bool unformatted; // True if no fields are defined
169
170 int lastAID; // Last attention key identifier
171
172 /* Character Attributes in effect */
173 bool useCharAttr;
174
175 struct {
176 Q3270::Highlight highlight;
177 bool highlight_default;
178
179 QBrush colour;
180 Q3270::Colour colNum;
181 bool colour_default;
182 } charAttr;
183
184 // Cursor
185 QGraphicsRectItem cursor;
186 QGraphicsLineItem crosshair_X;
187 QGraphicsLineItem crosshair_Y;
188
189 qreal gridSize_X;
190 qreal gridSize_Y;
191
192 QRegion blinkCells;
193 QGraphicsRectItem *myRb;
194 QPointF mouseStart;
195
196 QFont font;
197 Q3270::FontTweak fontTweak;
198
199 // Font tweak settings
200 QPoint dotOffset;
201 QPoint slashStart;
202 QPoint slashEnd;
203 int dotRadius;
204
205 int findField(int pos);
206 int findNextField(int pos);
207 void applyCharAttributes(int pos, Cell *field);
208 void updateFontMetrics();
209};
210
211#endif // DISPLAYSCREEN_H
Definition Cell.h:18
The CodePage class.
Definition CodePage.h:27
Definition DisplayScreen.h:30
void resetExtendedHilite(int pos)
DisplayScreen::resetExtendedHilite - reset the extended highlighting.
Definition DisplayScreen.cpp:573
void cursorBlink()
DisplayScreen::cursorBlink - blink the cursor.
Definition DisplayScreen.cpp:966
void tab(int offset)
DisplayScreen::tab - tab to the next field.
Definition DisplayScreen_Cursor.cpp:114
void resetCharAttr()
DisplayScreen::resetCharAttr - set character attributes to default.
Definition DisplayScreen.cpp:446
void moveCursor(int x, int y)
DisplayScreen::moveCursor - move the cursor.
Definition DisplayScreen_Cursor.cpp:66
int findNextUnprotectedField(int pos)
DisplayScreen::findNextUnprotectedField - find the next unprotected field.
Definition DisplayScreen.cpp:1047
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mEvent) override
DisplayScreen::mouseReleaseEvent - process a mouse release event.
Definition DisplayScreen_Mouse.cpp:103
void blink()
DisplayScreen::blink - blink the display.
Definition DisplayScreen.cpp:952
void setFont(const QFont &font)
DisplayScreen::setFont - change the font on the screen.
Definition DisplayScreen.cpp:161
void dumpDisplay()
DisplayScreen::dumpDisplay - print out a debug replication of the screen.
Definition DisplayScreen.cpp:1243
void resetColours()
DisplayScreen::resetColours - set the colours of each cell.
Definition DisplayScreen.cpp:225
bool insertChar(unsigned char c, bool insertMode)
DisplayScreen::insertChar - Inserts or overwrites the character at the specified position.
Definition DisplayScreen.cpp:663
void setFontTweak(const Q3270::FontTweak f)
DisplayScreen::setFontTweak - change the way zero is displayed.
Definition DisplayScreen.cpp:173
void backspace()
DisplayScreen::backspace - backspace one character.
Definition DisplayScreen_Cursor.cpp:194
int width() const
DisplayScreen::width - return the width of the screen.
Definition DisplayScreen.cpp:118
void cascadeAttrs(int startpos)
DisplayScreen::cascadeAttrs - cascade a field attribute to the cells in the field.
Definition DisplayScreen.cpp:533
void resetMDTs()
DisplayScreen::resetMDTs - reset all the MDTs on the screen.
Definition DisplayScreen.cpp:637
void mouseMoveEvent(QGraphicsSceneMouseEvent *mEvent) override
DisplayScreen::mouseMoveEvent - process a mouse move event.
Definition DisplayScreen_Mouse.cpp:51
void dumpInfo()
DisplayScreen::dumpInfo - display information about the Cell at pos.
Definition DisplayScreen.cpp:1273
void setField(int pos, unsigned char c, bool sfe)
DisplayScreen::setField - Start Field or Start Field Extended.
Definition DisplayScreen.cpp:490
void setExtendedReverse(int pos)
DisplayScreen::setExtendedReverse - switch reverse on.
Definition DisplayScreen.cpp:615
void setChar(int pos, uchar c, bool fromKB)
DisplayScreen::setChar - place a character on the screen.
Definition DisplayScreen.cpp:266
void setGraphicEscape()
DisplayScreen::setGraphicEscape - indicate that the next character is a graphic one.
Definition DisplayScreen.cpp:460
void setRuler()
DisplayScreen::setRuler - set the ruler style and redraw it in case it needs to move.
Definition DisplayScreen_Cursor.cpp:280
int height() const
DisplayScreen::height - return the height the screen.
Definition DisplayScreen.cpp:131
void rulerMode(bool on)
DisplayScreen::rulerMode - display/hide the ruler.
Definition DisplayScreen_Cursor.cpp:252
void processAID(int aid, bool shortread)
DisplayScreen::processAID - process an attention key.
Definition DisplayScreen.cpp:901
bool isFieldStart(int pos) const
DisplayScreen::isFieldStart - is this Cell a Field Start.
Definition DisplayScreen.cpp:784
int findPrevUnprotectedField(int pos)
DisplayScreen::findPrevUnprotectedField - find the previous unprotected field.
Definition DisplayScreen.cpp:1076
bool isAskip(int pos) const
DisplayScreen::isAskip - does this Cell have autoskip enabled.
Definition DisplayScreen.cpp:760
~DisplayScreen()
DisplayScreen::~DisplayScreen.
Definition DisplayScreen.cpp:100
void backtab()
DisplayScreen::backtab - back to the previous field start.
Definition DisplayScreen_Cursor.cpp:125
void clear()
DisplayScreen::clear - clear the screen.
Definition DisplayScreen.cpp:239
void getModifiedFields(QByteArray &buffer)
DisplayScreen::getModifiedFields - extract all modified fields from the screen.
Definition DisplayScreen.cpp:1111
void copyText()
DisplayScreen::copyText - copy the text within the rubberband to the clipboard.
Definition DisplayScreen_Mouse.cpp:131
void setCharAttr(unsigned char c, unsigned char d)
DisplayScreen::setCharAttr - set character attributes.
Definition DisplayScreen.cpp:361
void setExtendedColour(int pos, bool foreground, unsigned char c)
DisplayScreen::setExtendedColour - set the extended colour attributes.
Definition DisplayScreen.cpp:587
void setCursorColour(bool inherit)
DisplayScreen::setCursorColour - set the cursor colour.
Definition DisplayScreen_Cursor.cpp:218
void addPosToBuffer(QByteArray &buffer, int pos)
DisplayScreen::addPosToBuffer - insert 'pos' into 'buffer' as two bytes, doubling 0xFF if needed.
Definition DisplayScreen.cpp:1166
void resetExtended(int pos)
DisplayScreen::resetExtended - reset extended attributes ready for a Start Field Extended.
Definition DisplayScreen.cpp:553
void showCursor()
DisplayScreen::showCursor - display cursor.
Definition DisplayScreen_Cursor.cpp:84
void mousePressEvent(QGraphicsSceneMouseEvent *mEvent) override
DisplayScreen::mousePressEvent - process a mouse event.
Definition DisplayScreen_Mouse.cpp:21
void setCursor(const int x, const int y)
DisplayScreen::setCursor - position cursor.
Definition DisplayScreen_Cursor.cpp:36
void newline()
DisplayScreen::newline - move the cursor to the first input field after the current line.
Definition DisplayScreen_Cursor.cpp:94
void setExtendedBlink(int pos)
DisplayScreen::setExtendedBlink - switch blink on.
Definition DisplayScreen.cpp:604
void dumpFields()
DisplayScreen::dumpFields - debug routine to print out all fields.
Definition DisplayScreen.cpp:1207
void setRulerStyle(Q3270::RulerStyle rulerStyle)
DisplayScreen::setRulerStyle - change ruler style.
Definition DisplayScreen_Cursor.cpp:269
void home()
DisplayScreen::home - move the cursor to the first field on the screen.
Definition DisplayScreen_Cursor.cpp:178
void toggleRuler()
DisplayScreen::toggleRuler - toggle the ruler on or off.
Definition DisplayScreen_Cursor.cpp:238
void getScreen(QByteArray &buffer)
DisplayScreen::getScreen - place the screen buffer into the 3270 data stream.
Definition DisplayScreen.cpp:1314
void eraseEOF()
DisplayScreen::eraseEOF - clear the Cells starting at pos until the end of the field.
Definition DisplayScreen.cpp:834
bool isProtected(int pos) const
DisplayScreen::isProtected - is this Cell protected?
Definition DisplayScreen.cpp:772
void setExtendedUscore(int pos)
DisplayScreen::setExtendedUscore - switch underscore on.
Definition DisplayScreen.cpp:626
void interruptProcess()
ProcessDataStream::interruptProcess - interrupt the current process.
Definition DisplayScreen.cpp:937
void deleteChar()
DisplayScreen::deleteChar - delete the character at the specified position.
Definition DisplayScreen.cpp:797
void endline()
DisplayScreen::endline - move the cursor to the end of the current input field.
Definition DisplayScreen_Cursor.cpp:135
void eraseUnprotected(int start, int end, Q3270::EraseResetMDT resetMDT)
DisplayScreen::eraseUnprotected - erase unprotected fields between addresses.
Definition DisplayScreen.cpp:864
Definition Colours.h:19