RedPanda-CPP/RedPandaIDE/qsynedit/TextPainter.h

91 lines
2.9 KiB
C
Raw Normal View History

2021-12-26 23:18:28 +08:00
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-05-14 23:56:43 +08:00
#ifndef TEXTPAINTER_H
#define TEXTPAINTER_H
#include <QColor>
#include <QPainter>
#include <QString>
#include "Types.h"
2021-05-16 20:36:00 +08:00
#include "highlighter/base.h"
2021-05-18 15:49:58 +08:00
#include "../utils.h"
2021-05-21 23:33:53 +08:00
#include "MiscClasses.h"
2021-05-14 23:56:43 +08:00
class SynEdit;
class SynEditTextPainter
{
2021-05-16 20:36:00 +08:00
struct SynTokenAccu {
int Columns;
int ColumnsBefore;
2021-05-14 23:56:43 +08:00
QString s;
QColor FG;
QColor BG;
SynFontStyles Style;
};
public:
2021-05-24 00:41:00 +08:00
SynEditTextPainter(SynEdit * edit,QPainter* painter,int FirstRow, int LastRow,
2021-05-21 23:33:53 +08:00
int FirstCol, int LastCol);
void paintTextLines(const QRect& clip);
void paintGutter(const QRect& clip);
2021-05-14 23:56:43 +08:00
2021-05-21 23:33:53 +08:00
private:
2021-05-14 23:56:43 +08:00
QColor colEditorBG();
2022-07-24 22:53:20 +08:00
void computeSelectionInfo();
void setDrawingColors(bool selected);
int columnToXValue(int col);
void paintToken(const QString& token, int tokenLen, int columnsBefore,
int first, int last, bool isSelection, const QFont& font,
const QFont& fontForNonAscii);
2022-07-24 22:53:20 +08:00
void paintEditAreas(const SynEditingAreaList& areaList);
void paintHighlightToken(bool bFillToEOL);
bool tokenIsSpaces(bool& bSpacesTest, const QString& token, bool& bIsSpaces);
void addHighlightToken(const QString& token, int columnsBefore, int tokenColumns,
2021-05-16 20:36:00 +08:00
int cLine, PSynHighlighterAttribute p_Attri);
2022-07-24 22:53:20 +08:00
void paintFoldAttributes();
void getBraceColorAttr(int level, PSynHighlighterAttribute &attr);
void paintLines();
2021-05-21 23:33:53 +08:00
2021-05-14 23:56:43 +08:00
private:
SynEdit* edit;
QPainter* painter;
bool bDoRightEdge; // right edge
int nRightEdge;
// selection info
bool bAnySelection; // any selection visible?
DisplayCoord vSelStart; // start of selected area
DisplayCoord vSelEnd; // end of selected area
// info about normal and selected text and background colors
bool bSpecialLine, bLineSelected, bCurrentLine;
QColor colFG, colBG;
QColor colSelFG, colSelBG;
QColor colSpFG, colSpBG;
2021-05-14 23:56:43 +08:00
// info about selection of the current line
int nLineSelStart, nLineSelEnd;
bool bComplexLine;
// painting the background and the text
QRect rcLine, rcToken;
int vFirstLine, vLastLine;
2021-05-16 20:36:00 +08:00
QRect AClip;
int aFirstRow, aLastRow, FirstCol, LastCol;
SynTokenAccu TokenAccu;
2021-05-14 23:56:43 +08:00
};
#endif // TEXTPAINTER_H