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 MISCPROCS_H
|
|
|
|
#define MISCPROCS_H
|
|
|
|
#include <QPoint>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <QString>
|
|
|
|
#include <QSet>
|
|
|
|
#include "highlighter/base.h"
|
|
|
|
#include <QPaintDevice>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QVector>
|
|
|
|
#include <initializer_list>
|
|
|
|
//#include <QRect>
|
|
|
|
//#include <QColor>
|
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
class QRect;
|
|
|
|
class QColor;
|
|
|
|
|
2021-09-11 18:42:49 +08:00
|
|
|
int minMax(int x, int mi, int ma);
|
|
|
|
int mulDiv(int a, int b, int c);
|
|
|
|
BufferCoord maxBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
|
|
|
|
BufferCoord minBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
|
2021-05-14 23:56:43 +08:00
|
|
|
|
2022-07-04 11:39:06 +08:00
|
|
|
int getEOL(const QString& Line, int start);
|
2021-05-14 23:56:43 +08:00
|
|
|
|
2022-07-02 14:06:10 +08:00
|
|
|
QStringList splitStrings(const QString& text);
|
|
|
|
|
2022-07-02 17:59:07 +08:00
|
|
|
int calSpanLines(const BufferCoord& startPos, const BufferCoord& endPos);
|
|
|
|
|
2021-05-14 23:56:43 +08:00
|
|
|
using HighlighterAttriProc = std::function<bool(PSynHighlighter Highlighter,
|
|
|
|
PSynHighlighterAttribute Attri, const QString& UniqueAttriName,
|
2021-06-12 22:36:23 +08:00
|
|
|
QList<void *> Params)>;
|
2021-05-14 23:56:43 +08:00
|
|
|
|
|
|
|
// Enums all child highlighters and their attributes of a TSynMultiSyn through a
|
|
|
|
// callback function.
|
|
|
|
// This function also handles nested TSynMultiSyns including their MarkerAttri.
|
2022-07-04 11:39:06 +08:00
|
|
|
bool enumHighlighterAttributes(PSynHighlighter Highlighter,
|
2021-05-14 23:56:43 +08:00
|
|
|
bool SkipDuplicates, HighlighterAttriProc highlighterAttriProc,
|
|
|
|
std::initializer_list<void *> Params);
|
|
|
|
|
2021-05-16 20:36:00 +08:00
|
|
|
SynFontStyles getFontStyles(const QFont& font);
|
|
|
|
|
2021-05-29 21:35:46 +08:00
|
|
|
/**
|
|
|
|
* Find the first occurency of word char in s, starting from startPos
|
|
|
|
* Note: the index of first char in s in 1
|
|
|
|
* @return index of the char founded , 0 if not found
|
|
|
|
*/
|
2022-07-04 11:39:06 +08:00
|
|
|
int findWordChar(const QString& s, int startPos);
|
2021-05-29 21:35:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the first occurency of non word char in s, starting from startPos
|
|
|
|
* Note: the index of first char in s in 1
|
|
|
|
* @return index of the char founded , 0 if not found
|
|
|
|
*/
|
2022-07-04 11:39:06 +08:00
|
|
|
int findNonWordChar(const QString& s, int startPos);
|
2021-05-29 21:35:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the first occurency of word char in s right to left, starting from startPos
|
|
|
|
* Note: the index of first char in s in 1
|
|
|
|
* @return index of the char founded , 0 if not found
|
|
|
|
*/
|
2022-07-04 11:39:06 +08:00
|
|
|
int findLastWordChar(const QString& s, int startPos);
|
2021-05-29 21:35:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the first occurency of non word char in s right to left, starting from startPos
|
|
|
|
* Note: the index of first char in s in 1
|
|
|
|
* @return index of the char founded , 0 if not found
|
|
|
|
*/
|
2022-07-04 11:39:06 +08:00
|
|
|
int findLastNonWordChar(const QString& s, int startPos);
|
2021-05-29 21:35:46 +08:00
|
|
|
|
2021-06-03 20:26:36 +08:00
|
|
|
void ensureNotAfter(BufferCoord& cord1, BufferCoord& cord2);
|
|
|
|
|
2021-08-31 14:41:48 +08:00
|
|
|
bool isWordChar(const QChar& ch);
|
|
|
|
|
2021-05-14 23:56:43 +08:00
|
|
|
#endif // MISCPROCS_H
|