2022-01-04 23:07:50 +00:00
|
|
|
// @file PlatQt.h
|
2013-08-28 00:44:27 +00:00
|
|
|
// Copyright (c) 1990-2011, Scientific Toolworks, Inc.
|
|
|
|
//
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
//
|
|
|
|
// Author: Jason Haslam
|
|
|
|
//
|
|
|
|
// Additions Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware
|
|
|
|
// Scintilla platform layer for Qt
|
|
|
|
|
|
|
|
#ifndef PLATQT_H
|
|
|
|
#define PLATQT_H
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
2022-01-04 23:07:50 +00:00
|
|
|
#include <optional>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
#include "Debugging.h"
|
|
|
|
#include "Geometry.h"
|
|
|
|
#include "ScintillaTypes.h"
|
|
|
|
#include "ScintillaMessages.h"
|
2013-08-28 00:44:27 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <QUrl>
|
2013-08-28 00:44:27 +00:00
|
|
|
#include <QPaintDevice>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QHash>
|
2022-01-04 23:07:50 +00:00
|
|
|
#include <QTextCodec>
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
namespace Scintilla::Internal {
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
const char *CharacterSetID(Scintilla::CharacterSet characterSet);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
inline QColor QColorFromColourRGBA(ColourRGBA ca)
|
2019-05-04 18:14:48 +00:00
|
|
|
{
|
|
|
|
return QColor(ca.GetRed(), ca.GetGreen(), ca.GetBlue(), ca.GetAlpha());
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
inline QRect QRectFromPRect(PRectangle pr)
|
|
|
|
{
|
|
|
|
return QRect(pr.left, pr.top, pr.Width(), pr.Height());
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline QRectF QRectFFromPRect(PRectangle pr)
|
|
|
|
{
|
|
|
|
return QRectF(pr.left, pr.top, pr.Width(), pr.Height());
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRectangle PRectFromQRect(QRect qr)
|
|
|
|
{
|
|
|
|
return PRectangle(qr.x(), qr.y(), qr.x() + qr.width(), qr.y() + qr.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point PointFromQPoint(QPoint qp)
|
|
|
|
{
|
|
|
|
return Point(qp.x(), qp.y());
|
|
|
|
}
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
inline QPointF QPointFFromPoint(Point qp)
|
|
|
|
{
|
|
|
|
return QPointF(qp.x, qp.y);
|
|
|
|
}
|
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
constexpr PRectangle RectangleInset(PRectangle rc, XYPOSITION delta) noexcept {
|
|
|
|
return PRectangle(rc.left + delta, rc.top + delta, rc.right - delta, rc.bottom - delta);
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
class SurfaceImpl : public Surface {
|
|
|
|
private:
|
2022-01-04 23:07:50 +00:00
|
|
|
QPaintDevice *device = nullptr;
|
|
|
|
QPainter *painter = nullptr;
|
|
|
|
bool deviceOwned = false;
|
|
|
|
bool painterOwned = false;
|
|
|
|
SurfaceMode mode;
|
|
|
|
const char *codecName = nullptr;
|
|
|
|
QTextCodec *codec = nullptr;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void Clear();
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
public:
|
|
|
|
SurfaceImpl();
|
2022-01-04 23:07:50 +00:00
|
|
|
SurfaceImpl(int width, int height, SurfaceMode mode_);
|
2013-08-28 00:44:27 +00:00
|
|
|
virtual ~SurfaceImpl();
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void Init(WindowID wid) override;
|
|
|
|
void Init(SurfaceID sid, WindowID wid) override;
|
2022-01-04 23:07:50 +00:00
|
|
|
std::unique_ptr<Surface> AllocatePixMap(int width, int height) override;
|
|
|
|
|
|
|
|
void SetMode(SurfaceMode mode) override;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
void Release() noexcept override;
|
|
|
|
int SupportsFeature(Scintilla::Supports feature) noexcept override;
|
2019-05-04 18:14:48 +00:00
|
|
|
bool Initialised() override;
|
2022-01-04 23:07:50 +00:00
|
|
|
void PenColour(ColourRGBA fore);
|
|
|
|
void PenColourWidth(ColourRGBA fore, XYPOSITION strokeWidth);
|
2019-05-04 18:14:48 +00:00
|
|
|
int LogPixelsY() override;
|
2022-01-04 23:07:50 +00:00
|
|
|
int PixelDivisions() override;
|
2019-05-04 18:14:48 +00:00
|
|
|
int DeviceHeightFont(int points) override;
|
2022-01-04 23:07:50 +00:00
|
|
|
void LineDraw(Point start, Point end, Stroke stroke) override;
|
|
|
|
void PolyLine(const Point *pts, size_t npts, Stroke stroke) override;
|
|
|
|
void Polygon(const Point *pts, size_t npts, FillStroke fillStroke) override;
|
|
|
|
void RectangleDraw(PRectangle rc, FillStroke fillStroke) override;
|
|
|
|
void RectangleFrame(PRectangle rc, Stroke stroke) override;
|
|
|
|
void FillRectangle(PRectangle rc, Fill fill) override;
|
|
|
|
void FillRectangleAligned(PRectangle rc, Fill fill) override;
|
2019-05-04 18:14:48 +00:00
|
|
|
void FillRectangle(PRectangle rc, Surface &surfacePattern) override;
|
2022-01-04 23:07:50 +00:00
|
|
|
void RoundedRectangle(PRectangle rc, FillStroke fillStroke) override;
|
|
|
|
void AlphaRectangle(PRectangle rc, XYPOSITION cornerSize, FillStroke fillStroke) override;
|
2019-05-04 18:14:48 +00:00
|
|
|
void GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) override;
|
|
|
|
void DrawRGBAImage(PRectangle rc, int width, int height,
|
|
|
|
const unsigned char *pixelsImage) override;
|
2022-01-04 23:07:50 +00:00
|
|
|
void Ellipse(PRectangle rc, FillStroke fillStroke) override;
|
|
|
|
void Stadium(PRectangle rc, FillStroke fillStroke, Ends ends) override;
|
2019-05-04 18:14:48 +00:00
|
|
|
void Copy(PRectangle rc, Point from, Surface &surfaceSource) override;
|
|
|
|
|
|
|
|
std::unique_ptr<IScreenLineLayout> Layout(const IScreenLine *screenLine) override;
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
void DrawTextNoClip(PRectangle rc, const Font *font, XYPOSITION ybase,
|
|
|
|
std::string_view text, ColourRGBA fore, ColourRGBA back) override;
|
|
|
|
void DrawTextClipped(PRectangle rc, const Font *font, XYPOSITION ybase,
|
|
|
|
std::string_view text, ColourRGBA fore, ColourRGBA back) override;
|
|
|
|
void DrawTextTransparent(PRectangle rc, const Font *font, XYPOSITION ybase,
|
|
|
|
std::string_view text, ColourRGBA fore) override;
|
|
|
|
void MeasureWidths(const Font *font, std::string_view text,
|
|
|
|
XYPOSITION *positions) override;
|
|
|
|
XYPOSITION WidthText(const Font *font, std::string_view text) override;
|
|
|
|
|
|
|
|
void DrawTextNoClipUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase,
|
|
|
|
std::string_view text, ColourRGBA fore, ColourRGBA back) override;
|
|
|
|
void DrawTextClippedUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase,
|
|
|
|
std::string_view text, ColourRGBA fore, ColourRGBA back) override;
|
|
|
|
void DrawTextTransparentUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase,
|
|
|
|
std::string_view text, ColourRGBA fore) override;
|
|
|
|
void MeasureWidthsUTF8(const Font *font_, std::string_view text,
|
2019-05-04 18:14:48 +00:00
|
|
|
XYPOSITION *positions) override;
|
2022-01-04 23:07:50 +00:00
|
|
|
XYPOSITION WidthTextUTF8(const Font *font_, std::string_view text) override;
|
|
|
|
|
|
|
|
XYPOSITION Ascent(const Font *font) override;
|
|
|
|
XYPOSITION Descent(const Font *font) override;
|
|
|
|
XYPOSITION InternalLeading(const Font *font) override;
|
|
|
|
XYPOSITION Height(const Font *font) override;
|
|
|
|
XYPOSITION AverageCharWidth(const Font *font) override;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
|
|
|
void SetClip(PRectangle rc) override;
|
2022-01-04 23:07:50 +00:00
|
|
|
void PopClip() override;
|
2019-05-04 18:14:48 +00:00
|
|
|
void FlushCachedState() override;
|
2022-01-04 23:07:50 +00:00
|
|
|
void FlushDrawing() override;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
void BrushColour(ColourRGBA back);
|
|
|
|
void SetCodec(const Font *font);
|
|
|
|
void SetFont(const Font *font);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
QPaintDevice *GetPaintDevice();
|
|
|
|
void SetPainter(QPainter *painter);
|
|
|
|
QPainter *GetPainter();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|