added qpainter provider

This commit is contained in:
Igor Korsukov 2021-03-02 15:21:29 +02:00
parent f653511ed8
commit cf0cc73520
17 changed files with 569 additions and 168 deletions

View file

@ -23,6 +23,8 @@
#include "libmscore/chord.h"
#include "libmscore/xml.h"
#include "libmscore/draw/qpainterprovider.h"
#include "commonscenetypes.h"
namespace Ms {
@ -193,8 +195,7 @@ void ExampleView::drawElements(mu::draw::Painter& painter, const QList<Element*>
void ExampleView::paintEvent(QPaintEvent* ev)
{
if (_score) {
QPainter qp(this);
mu::draw::Painter p(&qp);
mu::draw::Painter p(mu::draw::QPainterProvider::make(this));
p.setAntialiasing(true);
const QRect r(ev->rect());

View file

@ -22,9 +22,9 @@
#include "log.h"
#include "libmscore/score.h"
#include "libmscore/draw/qpainterprovider.h"
#include <QPdfWriter>
#include <QPainter>
using namespace mu::iex::imagesexport;
using namespace mu::system;
@ -49,13 +49,11 @@ mu::Ret PdfWriter::write(const notation::INotationPtr notation, IODevice& destin
pdfWriter.setTitle(documentTitle(*score));
pdfWriter.setPageMargins(QMarginsF());
QPainter qp;
if (!qp.begin(&pdfWriter)) {
mu::draw::Painter painter(mu::draw::QPainterProvider::make(&pdfWriter));
if (!painter.isActive()) {
return false;
}
mu::draw::Painter painter(&qp);
QSizeF size(score->styleD(Sid::pageWidth), score->styleD(Sid::pageHeight));
painter.setAntialiasing(true);
painter.setViewport(QRect(0.0, 0.0, size.width() * pdfWriter.logicalDpiX(),

View file

@ -26,8 +26,9 @@
#include "libmscore/score.h"
#include "libmscore/page.h"
#include "libmscore/draw/qpainterprovider.h"
#include <QImage>
#include <QPainter>
using namespace mu::iex::imagesexport;
using namespace mu::system;
@ -77,8 +78,7 @@ mu::Ret PngWriter::write(const notation::INotationPtr notation, IODevice& destin
double scaling = CANVAS_DPI / Ms::DPI;
Ms::MScore::pixelRatio = 1.0 / scaling;
QPainter qp(&image);
mu::draw::Painter painter(&qp);
mu::draw::Painter painter(mu::draw::QPainterProvider::make(&image));
painter.setAntialiasing(true);
painter.scale(scaling, scaling);
if (TRIM_MARGIN_SIZE >= 0) {

View file

@ -30,7 +30,7 @@
#include "libmscore/measure.h"
#include "libmscore/stafflines.h"
#include <QPainter>
#include "libmscore/draw/qpainterprovider.h"
using namespace mu::iex::imagesexport;
using namespace mu::system;
@ -78,8 +78,7 @@ mu::Ret SvgWriter::write(const notation::INotationPtr notation, IODevice& destin
printer.setSize(QSize(width, height));
printer.setViewBox(QRectF(0, 0, width, height));
QPainter qp(&printer);
mu::draw::Painter painter(&qp);
mu::draw::Painter painter(mu::draw::QPainterProvider::make(&printer));
painter.setAntialiasing(true);
if (TRIM_MARGINS_SIZE >= 0) {
painter.translate(-pageRect.topLeft());

View file

@ -355,6 +355,9 @@ set(MODULE_SRC
draw/painter.cpp
draw/painter.h
draw/ipaintprovider.h
draw/drawtypes.h
draw/qpainterprovider.cpp
draw/qpainterprovider.h
)
set(MODULE_INCLUDE

View file

@ -0,0 +1,29 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2021 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef MU_DRAW_DRAWTYPES_H
#define MU_DRAW_DRAWTYPES_H
namespace mu::draw {
enum class CompositionMode {
SourceOver,
HardLight
};
}
#endif // MU_DRAW_DRAWTYPES_H

View file

@ -19,107 +19,95 @@
#ifndef MU_DRAW_IPAINTPROVIDER_H
#define MU_DRAW_IPAINTPROVIDER_H
#include <memory>
#include <QPoint>
#include <QPointF>
#include <QPen>
#include <QColor>
#include <QFont>
#include <QGlyphRun>
#include "drawtypes.h"
namespace mu::draw {
class IPaintProvider
{
public:
virtual ~IPaintProvider() = default;
// QPaintDevice* device() const;
// QPainter* qpainter() const;
virtual QPaintDevice* device() const = 0;
virtual QPainter* qpainter() const = 0;
// bool begin(QPaintDevice*);
// bool end();
// bool isActive() const;
virtual bool end() = 0;
virtual bool isActive() const = 0;
// void setRenderHint(RenderHint hint, bool on = true);
// void setCompositionMode(QPainter::CompositionMode mode);
virtual void setAntialiasing(bool arg) = 0;
virtual void setCompositionMode(CompositionMode mode) = 0;
// void setFont(const QFont& f);
// const QFont& font() const;
virtual void setFont(const QFont& f) = 0;
virtual const QFont& font() const = 0;
// void setPen(const QColor& color);
// void setPen(const QPen& pen);
// void setPen(Qt::PenStyle style);
// const QPen& pen() const;
virtual void setPen(const QColor& color) = 0;
virtual void setPen(const QPen& pen) = 0;
virtual void setNoPen() = 0;
virtual const QPen& pen() const = 0;
// void setBrush(const QBrush& brush);
// void setBrush(Qt::BrushStyle style);
// const QBrush& brush() const;
virtual void setBrush(const QBrush& brush) = 0;
virtual const QBrush& brush() const = 0;
// void save();
// void restore();
virtual void save() = 0;
virtual void restore() = 0;
// void setWorldTransform(const QTransform& matrix, bool combine = false);
// const QTransform& worldTransform() const;
virtual void setWorldTransform(const QTransform& matrix, bool combine = false) = 0;
virtual const QTransform& worldTransform() const = 0;
// void setTransform(const QTransform& transform, bool combine = false);
// const QTransform& transform() const;
virtual void setTransform(const QTransform& transform, bool combine = false) = 0;
virtual const QTransform& transform() const = 0;
// void setMatrix(const QMatrix& matrix, bool combine = false);
virtual void setMatrix(const QMatrix& matrix, bool combine = false) = 0;
// void scale(qreal sx, qreal sy);
// void rotate(qreal a);
virtual void scale(qreal sx, qreal sy) = 0;
virtual void rotate(qreal a) = 0;
// void translate(const QPointF& offset);
// inline void translate(const QPoint& offset);
// inline void translate(qreal dx, qreal dy);
virtual void translate(const QPointF& offset) = 0;
// QRect window() const;
// void setWindow(const QRect& window);
// inline void setWindow(int x, int y, int w, int h);
virtual QRect window() const = 0;
virtual void setWindow(const QRect& window) = 0;
virtual QRect viewport() const = 0;
virtual void setViewport(const QRect& viewport) = 0;
// QRect viewport() const;
// void setViewport(const QRect& viewport);
// inline void setViewport(int x, int y, int w, int h);
// drawing functions
virtual void fillPath(const QPainterPath& path, const QBrush& brush) = 0;
virtual void drawPath(const QPainterPath& path) = 0;
// // drawing functions
// void strokePath(const QPainterPath& path, const QPen& pen);
// void fillPath(const QPainterPath& path, const QBrush& brush);
// void drawPath(const QPainterPath& path);
virtual void drawLines(const QLineF* lines, int lineCount) = 0;
virtual void drawLines(const QPointF* pointPairs, int lineCount) = 0;
// inline void drawLine(const QLineF& line);
// inline void drawLine(const QPointF& p1, const QPointF& p2);
// inline void drawLine(int x1, int y1, int x2, int y2);
virtual void drawRects(const QRectF* rects, int rectCount) = 0;
virtual void drawRoundedRect(const QRectF& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize) = 0;
// void drawLines(const QLineF* lines, int lineCount);
// inline void drawLines(const QVector<QLineF>& lines);
// void drawLines(const QLine* lines, int lineCount);
// void drawLines(const QPointF* pointPairs, int lineCount);
virtual void drawEllipse(const QRectF& r) = 0;
// inline void drawRect(const QRectF& rect);
// inline void drawRect(int x1, int y1, int w, int h);
// inline void drawRect(const QRect& rect);
virtual void drawPolyline(const QPointF* points, int pointCount) = 0;
// void drawRects(const QRectF* rects, int rectCount);
// inline void drawRects(const QVector<QRectF>& rectangles);
// void drawRects(const QRect* rects, int rectCount);
// inline void drawRects(const QVector<QRect>& rectangles);
virtual void drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill) = 0;
virtual void drawConvexPolygon(const QPointF* points, int pointCount) = 0;
// void drawRoundedRect(const QRectF& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize);
virtual void drawArc(const QRectF& rect, int a, int alen) = 0;
// void drawEllipse(const QRectF& r);
// void drawEllipse(const QRect& r);
virtual void drawText(const QPointF& p, const QString& s) = 0;
virtual void drawText(const QRectF& r, int flags, const QString& text, QRectF* br = nullptr) = 0;
// void drawPolyline(const QPointF* points, int pointCount);
// void drawPolyline(const QPoint* points, int pointCount);
virtual void drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun) = 0;
// void drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill);
// void drawPolygon(const QPoint* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill);
// void drawConvexPolygon(const QPointF* points, int pointCount);
virtual void fillRect(const QRectF& r, const QColor& color) = 0;
// void drawArc(const QRectF& rect, int a, int alen);
// void drawText(const QPointF& p, const QString& s);
// void drawText(const QRectF& r, int flags, const QString& text, QRectF* br = nullptr);
// void drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun);
// void fillRect(const QRectF& r, const QColor& color);
// void drawPixmap(const QPointF& p, const QPixmap& pm);
// void drawTiledPixmap(const QRectF& rect, const QPixmap& pm, const QPointF& offset = QPointF());
virtual void drawPixmap(const QPointF& p, const QPixmap& pm) = 0;
virtual void drawTiledPixmap(const QRectF& rect, const QPixmap& pm, const QPointF& offset = QPointF()) = 0;
};
using IPaintProviderPtr = std::shared_ptr<IPaintProvider>;
}
#endif // MU_DRAW_IPAINTPROVIDER_H

View file

@ -20,247 +20,234 @@
using namespace mu::draw;
Painter::Painter(QPainter* painter)
: m_painter(painter)
Painter::Painter(IPaintProviderPtr provider)
: m_provider(provider)
{
}
QPaintDevice* Painter::device() const
{
return m_painter->device();
return m_provider->device();
}
QPainter* Painter::qpainter() const
{
return m_painter;
}
bool Painter::begin(QPaintDevice* d)
{
return m_painter->begin(d);
return m_provider->qpainter();
}
bool Painter::end()
{
return m_painter->end();
return m_provider->end();
}
bool Painter::isActive() const
{
return m_painter->isActive();
return m_provider->isActive();
}
void Painter::setAntialiasing(bool arg)
{
m_painter->setRenderHint(QPainter::Antialiasing, arg);
m_painter->setRenderHint(QPainter::TextAntialiasing, arg);
m_provider->setAntialiasing(arg);
}
void Painter::setCompositionMode(CompositionMode mode)
{
auto toQPainter = [](CompositionMode mode) {
switch (mode) {
case CompositionMode::SourceOver: return QPainter::CompositionMode_SourceOver;
case CompositionMode::HardLight: return QPainter::CompositionMode_HardLight;
}
return QPainter::CompositionMode_SourceOver;
};
m_painter->setCompositionMode(toQPainter(mode));
m_provider->setCompositionMode(mode);
}
void Painter::setFont(const QFont& f)
{
m_painter->setFont(f);
m_provider->setFont(f);
}
const QFont& Painter::font() const
{
return m_painter->font();
return m_provider->font();
}
void Painter::setPen(const QColor& color)
{
m_painter->setPen(color);
m_provider->setPen(color);
}
void Painter::setPen(const QPen& pen)
{
m_painter->setPen(pen);
m_provider->setPen(pen);
}
void Painter::setNoPen()
{
m_painter->setPen(QPen(Qt::NoPen));
m_provider->setPen(QPen(Qt::NoPen));
}
const QPen& Painter::pen() const
{
return m_painter->pen();
return m_provider->pen();
}
void Painter::setBrush(const QBrush& brush)
{
m_painter->setBrush(brush);
m_provider->setBrush(brush);
}
const QBrush& Painter::brush() const
{
return m_painter->brush();
return m_provider->brush();
}
void Painter::save()
{
m_painter->save();
m_provider->save();
}
void Painter::restore()
{
m_painter->restore();
m_provider->restore();
}
void Painter::setWorldTransform(const QTransform& matrix, bool combine)
{
m_painter->setWorldTransform(matrix, combine);
m_provider->setWorldTransform(matrix, combine);
}
const QTransform& Painter::worldTransform() const
{
return m_painter->worldTransform();
return m_provider->worldTransform();
}
void Painter::setTransform(const QTransform& transform, bool combine)
{
m_painter->setTransform(transform, combine);
m_provider->setTransform(transform, combine);
}
const QTransform& Painter::transform() const
{
return m_painter->transform();
return m_provider->transform();
}
void Painter::setMatrix(const QMatrix& matrix, bool combine)
{
m_painter->setMatrix(matrix, combine);
m_provider->setMatrix(matrix, combine);
}
void Painter::scale(qreal sx, qreal sy)
{
m_painter->scale(sx, sy);
m_provider->scale(sx, sy);
}
void Painter::rotate(qreal a)
{
m_painter->rotate(a);
m_provider->rotate(a);
}
void Painter::translate(const QPointF& offset)
{
m_painter->translate(offset);
m_provider->translate(offset);
}
QRect Painter::window() const
{
return m_painter->window();
return m_provider->window();
}
void Painter::setWindow(const QRect& window)
{
m_painter->setWindow(window);
m_provider->setWindow(window);
}
QRect Painter::viewport() const
{
return m_painter->viewport();
return m_provider->viewport();
}
void Painter::setViewport(const QRect& viewport)
{
m_painter->setViewport(viewport);
m_provider->setViewport(viewport);
}
// drawing functions
void Painter::fillPath(const QPainterPath& path, const QBrush& brush)
{
m_painter->fillPath(path, brush);
m_provider->fillPath(path, brush);
}
void Painter::drawPath(const QPainterPath& path)
{
m_painter->drawPath(path);
m_provider->drawPath(path);
}
void Painter::drawLines(const QLineF* lines, int lineCount)
{
m_painter->drawLines(lines, lineCount);
m_provider->drawLines(lines, lineCount);
}
void Painter::drawLines(const QPointF* pointPairs, int lineCount)
{
m_painter->drawLines(pointPairs, lineCount);
m_provider->drawLines(pointPairs, lineCount);
}
void Painter::drawRects(const QRectF* rects, int rectCount)
{
m_painter->drawRects(rects, rectCount);
m_provider->drawRects(rects, rectCount);
}
void Painter::drawEllipse(const QRectF& r)
{
m_painter->drawEllipse(r);
m_provider->drawEllipse(r);
}
void Painter::drawPolyline(const QPointF* points, int pointCount)
{
m_painter->drawPolyline(points, pointCount);
m_provider->drawPolyline(points, pointCount);
}
void Painter::drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule)
{
m_painter->drawPolygon(points, pointCount, fillRule);
m_provider->drawPolygon(points, pointCount, fillRule);
}
void Painter::drawConvexPolygon(const QPointF* points, int pointCount)
{
m_painter->drawConvexPolygon(points, pointCount);
m_provider->drawConvexPolygon(points, pointCount);
}
void Painter::drawArc(const QRectF& rect, int a, int alen)
{
m_painter->drawArc(rect, a, alen);
m_provider->drawArc(rect, a, alen);
}
void Painter::drawRoundedRect(const QRectF& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
{
m_painter->drawRoundedRect(rect, xRadius, yRadius, mode);
m_provider->drawRoundedRect(rect, xRadius, yRadius, mode);
}
void Painter::drawText(const QPointF& p, const QString& s)
{
m_painter->drawText(p, s);
m_provider->drawText(p, s);
}
void Painter::drawText(const QRectF& r, int flags, const QString& text, QRectF* br)
{
m_painter->drawText(r, flags, text, br);
m_provider->drawText(r, flags, text, br);
}
void Painter::drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun)
{
m_painter->drawGlyphRun(position, glyphRun);
m_provider->drawGlyphRun(position, glyphRun);
}
void Painter::fillRect(const QRectF& r, const QColor& color)
{
m_painter->fillRect(r, color);
m_provider->fillRect(r, color);
}
void Painter::drawPixmap(const QPointF& p, const QPixmap& pm)
{
m_painter->drawPixmap(p, pm);
m_provider->drawPixmap(p, pm);
}
void Painter::drawTiledPixmap(const QRectF& rect, const QPixmap& pm, const QPointF& offset)
{
m_painter->drawTiledPixmap(rect, pm, offset);
m_provider->drawTiledPixmap(rect, pm, offset);
}

View file

@ -26,6 +26,9 @@
#include <QFont>
#include <QPainter>
#include "drawtypes.h"
#include "ipaintprovider.h"
class QPaintDevice;
class QImage;
@ -33,17 +36,11 @@ namespace mu::draw {
class Painter
{
public:
Painter(QPainter* painter);
enum class CompositionMode {
SourceOver,
HardLight
};
Painter(IPaintProviderPtr provider);
QPaintDevice* device() const;
QPainter* qpainter() const;
bool begin(QPaintDevice*);
bool end();
bool isActive() const;
@ -141,7 +138,7 @@ public:
void drawTiledPixmap(const QRectF& rect, const QPixmap& pm, const QPointF& offset = QPointF());
private:
QPainter* m_painter = nullptr;
IPaintProviderPtr m_provider;
};
inline void Painter::translate(qreal dx, qreal dy)

View file

@ -0,0 +1,280 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2021 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#include "qpainterprovider.h"
#include <QPainter>
using namespace mu::draw;
QPainterProvider::QPainterProvider(QPainter* painter, bool overship)
: m_painter(painter), m_overship(overship)
{
}
QPainterProvider::~QPainterProvider()
{
if (m_overship) {
delete m_painter;
}
}
IPaintProviderPtr QPainterProvider::make(QPaintDevice* dp)
{
return std::make_shared<QPainterProvider>(new QPainter(dp), true);
}
IPaintProviderPtr QPainterProvider::make(QPainter* qp, bool overship)
{
return std::make_shared<QPainterProvider>(qp, overship);
}
QPaintDevice* QPainterProvider::device() const
{
return m_painter->device();
}
QPainter* QPainterProvider::qpainter() const
{
return m_painter;
}
bool QPainterProvider::end()
{
return m_painter->end();
}
bool QPainterProvider::isActive() const
{
return m_painter->isActive();
}
void QPainterProvider::setAntialiasing(bool arg)
{
m_painter->setRenderHint(QPainter::Antialiasing, arg);
m_painter->setRenderHint(QPainter::TextAntialiasing, arg);
}
void QPainterProvider::setCompositionMode(CompositionMode mode)
{
auto toQPainter = [](CompositionMode mode) {
switch (mode) {
case CompositionMode::SourceOver: return QPainter::CompositionMode_SourceOver;
case CompositionMode::HardLight: return QPainter::CompositionMode_HardLight;
}
return QPainter::CompositionMode_SourceOver;
};
m_painter->setCompositionMode(toQPainter(mode));
}
void QPainterProvider::setFont(const QFont& f)
{
m_painter->setFont(f);
}
const QFont& QPainterProvider::font() const
{
return m_painter->font();
}
void QPainterProvider::setPen(const QColor& color)
{
m_painter->setPen(color);
}
void QPainterProvider::setPen(const QPen& pen)
{
m_painter->setPen(pen);
}
void QPainterProvider::setNoPen()
{
m_painter->setPen(QPen(Qt::NoPen));
}
const QPen& QPainterProvider::pen() const
{
return m_painter->pen();
}
void QPainterProvider::setBrush(const QBrush& brush)
{
m_painter->setBrush(brush);
}
const QBrush& QPainterProvider::brush() const
{
return m_painter->brush();
}
void QPainterProvider::save()
{
m_painter->save();
}
void QPainterProvider::restore()
{
m_painter->restore();
}
void QPainterProvider::setWorldTransform(const QTransform& matrix, bool combine)
{
m_painter->setWorldTransform(matrix, combine);
}
const QTransform& QPainterProvider::worldTransform() const
{
return m_painter->worldTransform();
}
void QPainterProvider::setTransform(const QTransform& transform, bool combine)
{
m_painter->setTransform(transform, combine);
}
const QTransform& QPainterProvider::transform() const
{
return m_painter->transform();
}
void QPainterProvider::setMatrix(const QMatrix& matrix, bool combine)
{
m_painter->setMatrix(matrix, combine);
}
void QPainterProvider::scale(qreal sx, qreal sy)
{
m_painter->scale(sx, sy);
}
void QPainterProvider::rotate(qreal a)
{
m_painter->rotate(a);
}
void QPainterProvider::translate(const QPointF& offset)
{
m_painter->translate(offset);
}
QRect QPainterProvider::window() const
{
return m_painter->window();
}
void QPainterProvider::setWindow(const QRect& window)
{
m_painter->setWindow(window);
}
QRect QPainterProvider::viewport() const
{
return m_painter->viewport();
}
void QPainterProvider::setViewport(const QRect& viewport)
{
m_painter->setViewport(viewport);
}
// drawing functions
void QPainterProvider::fillPath(const QPainterPath& path, const QBrush& brush)
{
m_painter->fillPath(path, brush);
}
void QPainterProvider::drawPath(const QPainterPath& path)
{
m_painter->drawPath(path);
}
void QPainterProvider::drawLines(const QLineF* lines, int lineCount)
{
m_painter->drawLines(lines, lineCount);
}
void QPainterProvider::drawLines(const QPointF* pointPairs, int lineCount)
{
m_painter->drawLines(pointPairs, lineCount);
}
void QPainterProvider::drawRects(const QRectF* rects, int rectCount)
{
m_painter->drawRects(rects, rectCount);
}
void QPainterProvider::drawEllipse(const QRectF& r)
{
m_painter->drawEllipse(r);
}
void QPainterProvider::drawPolyline(const QPointF* points, int pointCount)
{
m_painter->drawPolyline(points, pointCount);
}
void QPainterProvider::drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule)
{
m_painter->drawPolygon(points, pointCount, fillRule);
}
void QPainterProvider::drawConvexPolygon(const QPointF* points, int pointCount)
{
m_painter->drawConvexPolygon(points, pointCount);
}
void QPainterProvider::drawArc(const QRectF& rect, int a, int alen)
{
m_painter->drawArc(rect, a, alen);
}
void QPainterProvider::drawRoundedRect(const QRectF& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
{
m_painter->drawRoundedRect(rect, xRadius, yRadius, mode);
}
void QPainterProvider::drawText(const QPointF& p, const QString& s)
{
m_painter->drawText(p, s);
}
void QPainterProvider::drawText(const QRectF& r, int flags, const QString& text, QRectF* br)
{
m_painter->drawText(r, flags, text, br);
}
void QPainterProvider::drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun)
{
m_painter->drawGlyphRun(position, glyphRun);
}
void QPainterProvider::fillRect(const QRectF& r, const QColor& color)
{
m_painter->fillRect(r, color);
}
void QPainterProvider::drawPixmap(const QPointF& p, const QPixmap& pm)
{
m_painter->drawPixmap(p, pm);
}
void QPainterProvider::drawTiledPixmap(const QRectF& rect, const QPixmap& pm, const QPointF& offset)
{
m_painter->drawTiledPixmap(rect, pm, offset);
}

View file

@ -0,0 +1,113 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2021 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef MU_DRAW_QPAINTERPROVIDER_H
#define MU_DRAW_QPAINTERPROVIDER_H
#include "ipaintprovider.h"
class QPainter;
class QImage;
namespace mu::draw {
class QPainterProvider : public IPaintProvider
{
public:
QPainterProvider(QPainter* painter, bool overship = false);
~QPainterProvider();
static IPaintProviderPtr make(QPaintDevice* dp);
static IPaintProviderPtr make(QPainter* qp, bool overship = false);
QPaintDevice* device() const override;
QPainter* qpainter() const override;
bool end() override;
bool isActive() const override;
void setAntialiasing(bool arg) override;
void setCompositionMode(CompositionMode mode) override;
void setFont(const QFont& f) override;
const QFont& font() const override;
void setPen(const QColor& color) override;
void setPen(const QPen& pen) override;
void setNoPen() override;
const QPen& pen() const override;
void setBrush(const QBrush& brush) override;
const QBrush& brush() const override;
void save() override;
void restore() override;
void setWorldTransform(const QTransform& matrix, bool combine = false) override;
const QTransform& worldTransform() const override;
void setTransform(const QTransform& transform, bool combine = false) override;
const QTransform& transform() const override;
void setMatrix(const QMatrix& matrix, bool combine = false) override;
void scale(qreal sx, qreal sy) override;
void rotate(qreal a) override;
void translate(const QPointF& offset) override;
QRect window() const override;
void setWindow(const QRect& window) override;
QRect viewport() const override;
void setViewport(const QRect& viewport) override;
// drawing functions
void fillPath(const QPainterPath& path, const QBrush& brush) override;
void drawPath(const QPainterPath& path) override;
void drawLines(const QLineF* lines, int lineCount) override;
void drawLines(const QPointF* pointPairs, int lineCount) override;
void drawRects(const QRectF* rects, int rectCount) override;
void drawRoundedRect(const QRectF& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize) override;
void drawEllipse(const QRectF& r) override;
void drawPolyline(const QPointF* points, int pointCount) override;
void drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill) override;
void drawConvexPolygon(const QPointF* points, int pointCount) override;
void drawArc(const QRectF& rect, int a, int alen) override;
void drawText(const QPointF& p, const QString& s) override;
void drawText(const QRectF& r, int flags, const QString& text, QRectF* br = nullptr) override;
void drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun) override;
void fillRect(const QRectF& r, const QColor& color) override;
void drawPixmap(const QPointF& p, const QPixmap& pm) override;
void drawTiledPixmap(const QRectF& rect, const QPixmap& pm, const QPointF& offset = QPointF()) override;
private:
QPainter* m_painter = nullptr;
bool m_overship = false;
};
}
#endif // MU_DRAW_QPAINTERPROVIDER_H

View file

@ -54,6 +54,8 @@
#include <windows.h>
#endif
#include "draw/qpainterprovider.h"
namespace Ms {
//---------------------------------------------------------
// writeMeasure
@ -566,8 +568,7 @@ QImage Score::createThumbnail()
double pr = MScore::pixelRatio;
MScore::pixelRatio = 1.0;
QPainter qp(&pm);
mu::draw::Painter p(&qp);
mu::draw::Painter p(mu::draw::QPainterProvider::make(&pm));
p.setAntialiasing(true);
p.scale(mag, mag);
print(&p, 0);

View file

@ -1744,11 +1744,11 @@ TextBase::TextBase(const TextBase& st)
void TextBase::drawSelection(mu::draw::Painter* p, const QRectF& r) const
{
QBrush bg(QColor("steelblue"));
p->setCompositionMode(mu::draw::Painter::CompositionMode::HardLight);
p->setCompositionMode(mu::draw::CompositionMode::HardLight);
p->setBrush(bg);
p->setNoPen();
p->drawRect(r);
p->setCompositionMode(mu::draw::Painter::CompositionMode::SourceOver);
p->setCompositionMode(mu::draw::CompositionMode::SourceOver);
p->setPen(textColor());
}

View file

@ -19,6 +19,7 @@
#include "notationpaintview.h"
#include <QPainter>
#include "libmscore/draw/qpainterprovider.h"
#include "log.h"
#include "actions/actiontypes.h"
@ -323,7 +324,7 @@ void NotationPaintView::paint(QPainter* qp)
return;
}
mu::draw::Painter mup(qp);
mu::draw::Painter mup(mu::draw::QPainterProvider::make(qp));
mu::draw::Painter* painter = &mup;
QRect rect(0, 0, width(), height());

View file

@ -35,6 +35,8 @@
#include "libmscore/element.h"
#include "libmscore/bracket.h"
#include "libmscore/draw/qpainterprovider.h"
#include "thirdparty/qzip/qzipreader_p.h"
#include "thirdparty/qzip/qzipwriter_p.h"
@ -1232,7 +1234,7 @@ void PaletteCellIconEngine::paintCell(mu::draw::Painter& p, const QRect& r, bool
void PaletteCellIconEngine::paint(QPainter* qp, const QRect& r, QIcon::Mode mode, QIcon::State state)
{
mu::draw::Painter p(qp);
mu::draw::Painter p(mu::draw::QPainterProvider::make(qp));
p.save(); // so we can restore it later
p.setAntialiasing(true);
paintCell(p, r, mode == QIcon::Selected, state == QIcon::On);

View file

@ -34,6 +34,8 @@
#include "libmscore/mscore.h"
#include "libmscore/xml.h"
#include "libmscore/draw/qpainterprovider.h"
#include "commonscene/commonscenetypes.h"
#include "translation.h"
@ -103,8 +105,7 @@ void KeyCanvas::clear()
void KeyCanvas::paintEvent(QPaintEvent*)
{
QPainter qp(this);
mu::draw::Painter painter(&qp);
mu::draw::Painter painter(mu::draw::QPainterProvider::make(this));
painter.setAntialiasing(true);
qreal wh = double(height());
qreal ww = double(width());

View file

@ -30,6 +30,8 @@
#include "libmscore/system.h"
#include "libmscore/staff.h"
#include "libmscore/draw/qpainterprovider.h"
namespace Ms {
namespace PluginAPI {
//---------------------------------------------------------
@ -171,14 +173,13 @@ void ScoreView::setScore(Ms::Score* s)
void ScoreView::paint(QPainter* qp)
{
mu::draw::Painter mup(qp);
mu::draw::Painter* p = &mup;
p->setAntialiasing(true);
p->fillRect(QRect(0, 0, width(), height()), _color);
mu::draw::Painter p(mu::draw::QPainterProvider::make(qp));
p.setAntialiasing(true);
p.fillRect(QRect(0, 0, width(), height()), _color);
if (!score) {
return;
}
p->scale(mag, mag);
p.scale(mag, mag);
Ms::Page* page = score->pages()[_currentPage];
QList<const Ms::Element*> el;
@ -191,9 +192,9 @@ void ScoreView::paint(QPainter* qp)
foreach (const Ms::Element* e, el) {
QPointF pos(e->pagePos());
p->translate(pos);
e->draw(p);
p->translate(-pos);
p.translate(pos);
e->draw(&p);
p.translate(-pos);
}
}