-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathsurfacedocument.cpp
More file actions
43 lines (35 loc) · 1.19 KB
/
surfacedocument.cpp
File metadata and controls
43 lines (35 loc) · 1.19 KB
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
#include "surfacedocument.h"
#include <QTextDocument>
#include <QTextCursor>
#include <QPainter>
#include <QWidget>
SurfaceDocument::SurfaceDocument(const RDContextPtr& ctx, rd_flag flags, QObject *parent) : SurfaceQt(ctx, flags, parent)
{
m_document = new QTextDocument(this);
m_document->setDefaultFont(this->widget()->font());
m_document->setUndoRedoEnabled(false);
m_document->setDocumentMargin(0);
}
void SurfaceDocument::renderTo(QPainter* painter) { m_document->drawContents(painter); }
void SurfaceDocument::render()
{
m_document->clear();
int rows = 0;
RDSurface_GetSize(this->handle(), &rows, nullptr);
QTextCursor textcursor(m_document);
const RDSurfaceCell* cells = nullptr;
QTextCharFormat cf;
for(int row = 0; row < rows; row++)
{
int maxcols = RDSurface_GetRow(this->handle(), row, &cells);
if(row) textcursor.insertBlock();
for(int col = 0; col < maxcols; col++)
{
auto& cell = cells[col];
cf.setBackground(this->getBackground(&cell));
cf.setForeground(this->getForeground(&cell));
textcursor.insertText(QString(cell.ch), cf);
}
}
SurfaceQt::render();
}