diff options
author | mitchell <unknown> | 2018-05-25 17:44:28 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-05-25 17:44:28 -0400 |
commit | fba451a1d76be9b6945c9d5d7e219f7d7d1a4260 (patch) | |
tree | 0e1aa6f197c34e6c1a9782e264359c220ed014a7 /qt/ScintillaEditBase/PlatQt.cpp | |
parent | 9f00df4e57e917035d2f939ce70ccf2ee83a9725 (diff) | |
download | scintilla-mirror-fba451a1d76be9b6945c9d5d7e219f7d7d1a4260.tar.gz |
Backport: Add GradientRectangle method to Surface to draw rectangles with vertical or horizontal gradients.
Backport of changeset 6965:90c71d69e3b6.
Diffstat (limited to 'qt/ScintillaEditBase/PlatQt.cpp')
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index 26890e4b7..1f4c3fb05 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -349,6 +349,26 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, GetPainter()->drawRoundedRect(rect, radius, radius); } +void SurfaceImpl::GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) { + QRectF rect = QRectFFromPRect(rc); + QLinearGradient linearGradient; + switch (options) { + case GradientOptions::leftToRight: + linearGradient = QLinearGradient(rc.left, rc.top, rc.right, rc.top); + break; + case GradientOptions::topToBottom: + default: + linearGradient = QLinearGradient(rc.left, rc.top, rc.left, rc.bottom); + break; + } + linearGradient.setSpread(QGradient::RepeatSpread); + for (const ColourStop &stop : stops) { + linearGradient.setColorAt(stop.position, QColorFromColourAlpha(stop.colour)); + } + QBrush brush = QBrush(linearGradient); + GetPainter()->fillRect(rect, brush); +} + static std::vector<unsigned char> ImageByteSwapped(int width, int height, const unsigned char *pixelsImage) { // Input is RGBA, but Format_ARGB32 is BGRA, so swap the red bytes and blue bytes |