Merge pull request #7619 from igorkorsukov/mu4/draw/paint_to_buf
[MU4] Added qpainter provider
This commit is contained in:
commit
1689ec28a1
|
@ -23,6 +23,8 @@
|
|||
#include "libmscore/chord.h"
|
||||
#include "libmscore/xml.h"
|
||||
|
||||
#include "libmscore/draw/qpainterprovider.h"
|
||||
|
||||
#include "commonscenetypes.h"
|
||||
|
||||
namespace Ms {
|
||||
|
@ -193,10 +195,8 @@ 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);
|
||||
p.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
p.setRenderHint(mu::draw::Painter::TextAntialiasing, true);
|
||||
mu::draw::Painter p(mu::draw::QPainterProvider::make(this));
|
||||
p.setAntialiasing(true);
|
||||
const QRect r(ev->rect());
|
||||
|
||||
drawBackground(&p, r);
|
||||
|
|
|
@ -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,16 +49,13 @@ 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.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
painter.setRenderHint(mu::draw::Painter::TextAntialiasing, true);
|
||||
painter.setAntialiasing(true);
|
||||
painter.setViewport(QRect(0.0, 0.0, size.width() * pdfWriter.logicalDpiX(),
|
||||
size.height() * pdfWriter.logicalDpiY()));
|
||||
painter.setWindow(QRect(0.0, 0.0, size.width() * DPI, size.height() * DPI));
|
||||
|
|
|
@ -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,10 +78,8 @@ 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);
|
||||
painter.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
painter.setRenderHint(mu::draw::Painter::TextAntialiasing, true);
|
||||
mu::draw::Painter painter(mu::draw::QPainterProvider::make(&image));
|
||||
painter.setAntialiasing(true);
|
||||
painter.scale(scaling, scaling);
|
||||
if (TRIM_MARGIN_SIZE >= 0) {
|
||||
painter.translate(-pageRect.topLeft());
|
||||
|
|
|
@ -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,10 +78,8 @@ 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);
|
||||
painter.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
painter.setRenderHint(mu::draw::Painter::TextAntialiasing, true);
|
||||
mu::draw::Painter painter(mu::draw::QPainterProvider::make(&printer));
|
||||
painter.setAntialiasing(true);
|
||||
if (TRIM_MARGINS_SIZE >= 0) {
|
||||
painter.translate(-pageRect.topLeft());
|
||||
}
|
||||
|
|
|
@ -354,6 +354,10 @@ set(MODULE_SRC
|
|||
xmlwriter.cpp
|
||||
draw/painter.cpp
|
||||
draw/painter.h
|
||||
draw/ipaintprovider.h
|
||||
draw/drawtypes.h
|
||||
draw/qpainterprovider.cpp
|
||||
draw/qpainterprovider.h
|
||||
)
|
||||
|
||||
set(MODULE_INCLUDE
|
||||
|
|
|
@ -221,7 +221,7 @@ void Beam::draw(mu::draw::Painter* painter) const
|
|||
return;
|
||||
}
|
||||
painter->setBrush(QBrush(curColor()));
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
qreal lw2 = point(score()->styleS(Sid::beamWidth)) * .5 * mag();
|
||||
|
||||
// make beam thickness independent of slant
|
||||
|
|
|
@ -244,7 +244,7 @@ void Bracket::draw(mu::draw::Painter* painter) const
|
|||
switch (bracketType()) {
|
||||
case BracketType::BRACE: {
|
||||
if (_braceSymbol == SymId::noSym) {
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
painter->setBrush(QBrush(curColor()));
|
||||
painter->drawPath(path);
|
||||
} else {
|
||||
|
|
29
src/libmscore/draw/drawtypes.h
Normal file
29
src/libmscore/draw/drawtypes.h
Normal 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
|
113
src/libmscore/draw/ipaintprovider.h
Normal file
113
src/libmscore/draw/ipaintprovider.h
Normal 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_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;
|
||||
|
||||
virtual QPaintDevice* device() const = 0;
|
||||
virtual QPainter* qpainter() const = 0;
|
||||
|
||||
virtual bool end() = 0;
|
||||
virtual bool isActive() const = 0;
|
||||
|
||||
virtual void setAntialiasing(bool arg) = 0;
|
||||
virtual void setCompositionMode(CompositionMode mode) = 0;
|
||||
|
||||
virtual void setFont(const QFont& f) = 0;
|
||||
virtual const QFont& font() const = 0;
|
||||
|
||||
virtual void setPen(const QColor& color) = 0;
|
||||
virtual void setPen(const QPen& pen) = 0;
|
||||
virtual void setNoPen() = 0;
|
||||
virtual const QPen& pen() const = 0;
|
||||
|
||||
virtual void setBrush(const QBrush& brush) = 0;
|
||||
virtual const QBrush& brush() const = 0;
|
||||
|
||||
virtual void save() = 0;
|
||||
virtual void restore() = 0;
|
||||
|
||||
virtual void setWorldTransform(const QTransform& matrix, bool combine = false) = 0;
|
||||
virtual const QTransform& worldTransform() const = 0;
|
||||
|
||||
virtual void setTransform(const QTransform& transform, bool combine = false) = 0;
|
||||
virtual const QTransform& transform() const = 0;
|
||||
|
||||
virtual void setMatrix(const QMatrix& matrix, bool combine = false) = 0;
|
||||
|
||||
virtual void scale(qreal sx, qreal sy) = 0;
|
||||
virtual void rotate(qreal a) = 0;
|
||||
|
||||
virtual void translate(const QPointF& offset) = 0;
|
||||
|
||||
virtual QRect window() const = 0;
|
||||
virtual void setWindow(const QRect& window) = 0;
|
||||
virtual QRect viewport() const = 0;
|
||||
virtual void setViewport(const QRect& viewport) = 0;
|
||||
|
||||
// drawing functions
|
||||
virtual void fillPath(const QPainterPath& path, const QBrush& brush) = 0;
|
||||
virtual void drawPath(const QPainterPath& path) = 0;
|
||||
|
||||
virtual void drawLines(const QLineF* lines, int lineCount) = 0;
|
||||
virtual void drawLines(const QPointF* pointPairs, int lineCount) = 0;
|
||||
|
||||
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;
|
||||
|
||||
virtual void drawEllipse(const QRectF& r) = 0;
|
||||
|
||||
virtual void drawPolyline(const QPointF* points, int pointCount) = 0;
|
||||
|
||||
virtual void drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill) = 0;
|
||||
virtual void drawConvexPolygon(const QPointF* points, int pointCount) = 0;
|
||||
|
||||
virtual void drawArc(const QRectF& rect, int a, int alen) = 0;
|
||||
|
||||
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;
|
||||
|
||||
virtual void drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun) = 0;
|
||||
|
||||
virtual void fillRect(const QRectF& r, const QColor& color) = 0;
|
||||
|
||||
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
|
|
@ -20,274 +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::setRenderHint(RenderHint hint, bool on)
|
||||
void Painter::setAntialiasing(bool arg)
|
||||
{
|
||||
m_painter->setRenderHint(static_cast<QPainter::RenderHint>(hint), on);
|
||||
m_provider->setAntialiasing(arg);
|
||||
}
|
||||
|
||||
void Painter::setCompositionMode(QPainter::CompositionMode mode)
|
||||
void Painter::setCompositionMode(CompositionMode mode)
|
||||
{
|
||||
m_painter->setCompositionMode(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::setPen(Qt::PenStyle style)
|
||||
void Painter::setNoPen()
|
||||
{
|
||||
m_painter->setPen(style);
|
||||
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);
|
||||
}
|
||||
|
||||
void Painter::setBrush(Qt::BrushStyle style)
|
||||
{
|
||||
m_painter->setBrush(style);
|
||||
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::strokePath(const QPainterPath& path, const QPen& pen)
|
||||
{
|
||||
m_painter->strokePath(path, pen);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void Painter::drawLines(const QLine* 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);
|
||||
}
|
||||
|
||||
void Painter::drawRects(const QRect* rects, int rectCount)
|
||||
{
|
||||
m_painter->drawRects(rects, rectCount);
|
||||
m_provider->drawRects(rects, rectCount);
|
||||
}
|
||||
|
||||
void Painter::drawEllipse(const QRectF& r)
|
||||
{
|
||||
m_painter->drawEllipse(r);
|
||||
}
|
||||
|
||||
void Painter::drawEllipse(const QRect& r)
|
||||
{
|
||||
m_painter->drawEllipse(r);
|
||||
m_provider->drawEllipse(r);
|
||||
}
|
||||
|
||||
void Painter::drawPolyline(const QPointF* points, int pointCount)
|
||||
{
|
||||
m_painter->drawPolyline(points, pointCount);
|
||||
}
|
||||
|
||||
void Painter::drawPolyline(const QPoint* 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);
|
||||
}
|
||||
|
||||
void Painter::drawPolygon(const QPoint* 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);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#ifndef MU_DOM_PAINTER_H
|
||||
#define MU_DOM_PAINTER_H
|
||||
#ifndef MU_DRAW_PAINTER_H
|
||||
#define MU_DRAW_PAINTER_H
|
||||
|
||||
#include <QPoint>
|
||||
#include <QPointF>
|
||||
|
@ -26,6 +26,9 @@
|
|||
#include <QFont>
|
||||
#include <QPainter>
|
||||
|
||||
#include "drawtypes.h"
|
||||
#include "ipaintprovider.h"
|
||||
|
||||
class QPaintDevice;
|
||||
class QImage;
|
||||
|
||||
|
@ -33,35 +36,26 @@ namespace mu::draw {
|
|||
class Painter
|
||||
{
|
||||
public:
|
||||
Painter(QPainter* painter);
|
||||
|
||||
enum RenderHint {
|
||||
Antialiasing = 0x01,
|
||||
TextAntialiasing = 0x02,
|
||||
SmoothPixmapTransform = 0x04,
|
||||
LosslessImageRendering = 0x40,
|
||||
};
|
||||
Painter(IPaintProviderPtr provider);
|
||||
|
||||
QPaintDevice* device() const;
|
||||
QPainter* qpainter() const;
|
||||
|
||||
bool begin(QPaintDevice*);
|
||||
bool end();
|
||||
bool isActive() const;
|
||||
|
||||
void setRenderHint(RenderHint hint, bool on = true);
|
||||
void setCompositionMode(QPainter::CompositionMode mode);
|
||||
void setAntialiasing(bool arg);
|
||||
void setCompositionMode(CompositionMode mode);
|
||||
|
||||
void setFont(const QFont& f);
|
||||
const QFont& font() const;
|
||||
|
||||
void setPen(const QColor& color);
|
||||
void setPen(const QPen& pen);
|
||||
void setPen(Qt::PenStyle style);
|
||||
void setNoPen();
|
||||
const QPen& pen() const;
|
||||
|
||||
void setBrush(const QBrush& brush);
|
||||
void setBrush(Qt::BrushStyle style);
|
||||
const QBrush& brush() const;
|
||||
|
||||
void save();
|
||||
|
@ -84,65 +78,56 @@ public:
|
|||
|
||||
QRect window() const;
|
||||
void setWindow(const QRect& window);
|
||||
inline void setWindow(int x, int y, int w, int h);
|
||||
|
||||
QRect viewport() const;
|
||||
void setViewport(const QRect& viewport);
|
||||
inline void setViewport(int x, int y, int w, int h);
|
||||
|
||||
// drawing functions
|
||||
void strokePath(const QPainterPath& path, const QPen& pen);
|
||||
void fillPath(const QPainterPath& path, const QBrush& brush);
|
||||
void drawPath(const QPainterPath& path);
|
||||
|
||||
inline void drawLine(const QLineF& line);
|
||||
inline void drawLine(const QPointF& p1, const QPointF& p2);
|
||||
|
||||
//! NOTE Potentially dangerous method.
|
||||
//! Most of them are cut with fractional values.
|
||||
//! Fractions are also passed to this method, and, accordingly, the fractional part is discarded.
|
||||
inline void drawLine(int x1, int y1, int x2, int y2);
|
||||
|
||||
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);
|
||||
|
||||
inline void drawRect(const QRectF& rect);
|
||||
|
||||
//! NOTE Potentially dangerous method.
|
||||
//! Most of them are cut with fractional values.
|
||||
//! Fractions are also passed to this method, and, accordingly, the fractional part is discarded.
|
||||
inline void drawRect(int x1, int y1, int w, int h);
|
||||
inline void drawRect(const QRect& rect);
|
||||
|
||||
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);
|
||||
|
||||
void drawRoundedRect(const QRectF& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize);
|
||||
inline void drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize);
|
||||
inline void drawRoundedRect(const QRect& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize);
|
||||
|
||||
void drawEllipse(const QRectF& r);
|
||||
void drawEllipse(const QRect& r);
|
||||
inline void drawEllipse(int x, int y, int w, int h);
|
||||
inline void drawEllipse(const QPointF& center, qreal rx, qreal ry);
|
||||
inline void drawEllipse(const QPoint& center, int rx, int ry);
|
||||
|
||||
void drawPolyline(const QPointF* points, int pointCount);
|
||||
inline void drawPolyline(const QPolygonF& polyline);
|
||||
void drawPolyline(const QPoint* points, int pointCount);
|
||||
inline void drawPolyline(const QPolygon& polygon);
|
||||
|
||||
void drawPolygon(const QPointF* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill);
|
||||
inline void drawPolygon(const QPolygonF& polygon, Qt::FillRule fillRule = Qt::OddEvenFill);
|
||||
void drawPolygon(const QPoint* points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill);
|
||||
inline void drawPolygon(const QPolygon& polygon, Qt::FillRule fillRule = Qt::OddEvenFill);
|
||||
|
||||
void drawConvexPolygon(const QPointF* points, int pointCount);
|
||||
inline void drawConvexPolygon(const QPolygonF& polygon);
|
||||
|
||||
void drawArc(const QRectF& rect, int a, int alen);
|
||||
inline void drawArc(const QRect&, int a, int alen);
|
||||
inline void drawArc(int x, int y, int w, int h, 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);
|
||||
inline void drawText(const QPoint& p, const QString& s);
|
||||
|
||||
//! NOTE Potentially dangerous method.
|
||||
//! Most of them are cut with fractional values.
|
||||
//! Fractions are also passed to this method, and, accordingly, the fractional part is discarded.
|
||||
inline void drawText(int x, int y, const QString& s);
|
||||
|
||||
void drawGlyphRun(const QPointF& position, const QGlyphRun& glyphRun);
|
||||
|
@ -150,12 +135,10 @@ public:
|
|||
void fillRect(const QRectF& r, const QColor& color);
|
||||
|
||||
void drawPixmap(const QPointF& p, const QPixmap& pm);
|
||||
inline void drawPixmap(int x, int y, const QPixmap& pm);
|
||||
|
||||
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)
|
||||
|
@ -165,17 +148,7 @@ inline void Painter::translate(qreal dx, qreal dy)
|
|||
|
||||
inline void Painter::translate(const QPoint& offset)
|
||||
{
|
||||
translate(offset.x(), offset.y());
|
||||
}
|
||||
|
||||
inline void Painter::setViewport(int x, int y, int w, int h)
|
||||
{
|
||||
setViewport(QRect(x, y, w, h));
|
||||
}
|
||||
|
||||
inline void Painter::setWindow(int x, int y, int w, int h)
|
||||
{
|
||||
setWindow(QRect(x, y, w, h));
|
||||
translate(QPointF(offset.x(), offset.y()));
|
||||
}
|
||||
|
||||
inline void Painter::drawLine(const QLineF& l)
|
||||
|
@ -190,7 +163,7 @@ inline void Painter::drawLine(const QPointF& p1, const QPointF& p2)
|
|||
|
||||
inline void Painter::drawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
QLine l(x1, y1, x2, y2);
|
||||
QLineF l(x1, y1, x2, y2);
|
||||
drawLines(&l, 1);
|
||||
}
|
||||
|
||||
|
@ -206,99 +179,34 @@ inline void Painter::drawRect(const QRectF& rect)
|
|||
|
||||
inline void Painter::drawRect(int x, int y, int w, int h)
|
||||
{
|
||||
QRect r(x, y, w, h);
|
||||
QRectF r(x, y, w, h);
|
||||
drawRects(&r, 1);
|
||||
}
|
||||
|
||||
inline void Painter::drawRect(const QRect& r)
|
||||
{
|
||||
drawRects(&r, 1);
|
||||
}
|
||||
|
||||
inline void Painter::drawRects(const QVector<QRectF>& rects)
|
||||
{
|
||||
drawRects(rects.constData(), rects.size());
|
||||
}
|
||||
|
||||
inline void Painter::drawRects(const QVector<QRect>& rects)
|
||||
{
|
||||
drawRects(rects.constData(), rects.size());
|
||||
}
|
||||
|
||||
inline void Painter::drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
|
||||
{
|
||||
drawRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
|
||||
}
|
||||
|
||||
inline void Painter::drawRoundedRect(const QRect& rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
|
||||
{
|
||||
drawRoundedRect(QRectF(rect), xRadius, yRadius, mode);
|
||||
}
|
||||
|
||||
inline void Painter::drawEllipse(int x, int y, int w, int h)
|
||||
{
|
||||
drawEllipse(QRect(x, y, w, h));
|
||||
}
|
||||
|
||||
inline void Painter::drawEllipse(const QPointF& center, qreal rx, qreal ry)
|
||||
{
|
||||
drawEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
|
||||
}
|
||||
|
||||
inline void Painter::drawEllipse(const QPoint& center, int rx, int ry)
|
||||
{
|
||||
drawEllipse(QRect(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
|
||||
}
|
||||
|
||||
inline void Painter::drawPolyline(const QPolygonF& polyline)
|
||||
{
|
||||
drawPolyline(polyline.constData(), polyline.size());
|
||||
}
|
||||
|
||||
inline void Painter::drawPolyline(const QPolygon& polyline)
|
||||
{
|
||||
drawPolyline(polyline.constData(), polyline.size());
|
||||
}
|
||||
|
||||
inline void Painter::drawPolygon(const QPolygonF& polygon, Qt::FillRule fillRule)
|
||||
{
|
||||
drawPolygon(polygon.constData(), polygon.size(), fillRule);
|
||||
}
|
||||
|
||||
inline void Painter::drawPolygon(const QPolygon& polygon, Qt::FillRule fillRule)
|
||||
{
|
||||
drawPolygon(polygon.constData(), polygon.size(), fillRule);
|
||||
}
|
||||
|
||||
inline void Painter::drawConvexPolygon(const QPolygonF& poly)
|
||||
{
|
||||
drawConvexPolygon(poly.constData(), poly.size());
|
||||
}
|
||||
|
||||
inline void Painter::drawArc(const QRect& r, int a, int alen)
|
||||
{
|
||||
drawArc(QRectF(r), a, alen);
|
||||
}
|
||||
|
||||
inline void Painter::drawArc(int x, int y, int w, int h, int a, int alen)
|
||||
{
|
||||
drawArc(QRectF(x, y, w, h), a, alen);
|
||||
}
|
||||
|
||||
inline void Painter::drawText(const QPoint& p, const QString& s)
|
||||
{
|
||||
drawText(QPointF(p), s);
|
||||
}
|
||||
|
||||
inline void Painter::drawText(int x, int y, const QString& s)
|
||||
{
|
||||
drawText(QPointF(x, y), s);
|
||||
}
|
||||
|
||||
inline void Painter::drawPixmap(int x, int y, const QPixmap& pm)
|
||||
{
|
||||
drawPixmap(QPointF(x, y), pm);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MU_DOM_PAINTER_H
|
||||
#endif // MU_DRAW_PAINTER_H
|
||||
|
|
280
src/libmscore/draw/qpainterprovider.cpp
Normal file
280
src/libmscore/draw/qpainterprovider.cpp
Normal 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);
|
||||
}
|
113
src/libmscore/draw/qpainterprovider.h
Normal file
113
src/libmscore/draw/qpainterprovider.h
Normal 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
|
|
@ -377,7 +377,7 @@ void FretDiagram::draw(mu::draw::Painter* painter) const
|
|||
case FretDotType::NORMAL:
|
||||
default:
|
||||
painter->setBrush(symPen.color());
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
painter->drawEllipse(QRectF(x, y, dotd, dotd));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1526,7 +1526,7 @@ void Harmony::draw(mu::draw::Painter* painter) const
|
|||
Qt::SquareCap, Qt::MiterJoin);
|
||||
painter->setPen(pen);
|
||||
} else {
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
}
|
||||
QColor bg(bgColor());
|
||||
painter->setBrush(bg.alpha() ? QBrush(bg) : Qt::NoBrush);
|
||||
|
|
|
@ -63,7 +63,7 @@ void Icon::layout()
|
|||
void Icon::draw(mu::draw::Painter* p) const
|
||||
{
|
||||
QPixmap pm(_icon.pixmap(_extent, QIcon::Normal, QIcon::On));
|
||||
p->drawPixmap(0, 0, pm);
|
||||
p->drawPixmap(QPointF(0, 0), pm);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "draw/qpainterprovider.h"
|
||||
|
||||
namespace Ms {
|
||||
//---------------------------------------------------------
|
||||
// writeMeasure
|
||||
|
@ -566,10 +568,8 @@ QImage Score::createThumbnail()
|
|||
double pr = MScore::pixelRatio;
|
||||
MScore::pixelRatio = 1.0;
|
||||
|
||||
QPainter qp(&pm);
|
||||
mu::draw::Painter p(&qp);
|
||||
p.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
p.setRenderHint(mu::draw::Painter::TextAntialiasing, true);
|
||||
mu::draw::Painter p(mu::draw::QPainterProvider::make(&pm));
|
||||
p.setAntialiasing(true);
|
||||
p.scale(mag, mag);
|
||||
print(&p, 0);
|
||||
p.end();
|
||||
|
|
|
@ -209,7 +209,7 @@ void Stem::draw(mu::draw::Painter* painter) const
|
|||
y += displ;
|
||||
}
|
||||
painter->setBrush(QBrush(curColor()));
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
painter->drawPath(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -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(QPainter::CompositionMode_HardLight);
|
||||
p->setCompositionMode(mu::draw::CompositionMode::HardLight);
|
||||
p->setBrush(bg);
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setNoPen();
|
||||
p->drawRect(r);
|
||||
p->setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
p->setCompositionMode(mu::draw::CompositionMode::SourceOver);
|
||||
p->setPen(textColor());
|
||||
}
|
||||
|
||||
|
@ -3380,11 +3380,10 @@ void TextBase::draw(mu::draw::Painter* p) const
|
|||
QColor fColor = curColor(visible(), frameColor());
|
||||
qreal frameWidthVal = frameWidth().val() * (sizeIsSpatiumDependent() ? spatium() : baseSpatium);
|
||||
|
||||
QPen pen(fColor, frameWidthVal, Qt::SolidLine,
|
||||
Qt::SquareCap, Qt::MiterJoin);
|
||||
QPen pen(fColor, frameWidthVal, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
||||
p->setPen(pen);
|
||||
} else {
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setNoPen();
|
||||
}
|
||||
QColor bg(bgColor());
|
||||
p->setBrush(bg.alpha() ? QBrush(bg) : Qt::NoBrush);
|
||||
|
|
|
@ -102,7 +102,7 @@ void Tremolo::draw(mu::draw::Painter* painter) const
|
|||
drawSymbol(SymId::buzzRoll, painter);
|
||||
} else {
|
||||
painter->setBrush(QBrush(curColor()));
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
painter->drawPath(path);
|
||||
}
|
||||
// for palette
|
||||
|
|
|
@ -1561,7 +1561,7 @@ void NotationInteraction::drawAnchorLines(mu::draw::Painter* painter)
|
|||
QRectF rect(-d, -d, 2 * d, 2 * d);
|
||||
|
||||
painter->setBrush(QBrush(dropAnchorColor));
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setNoPen();
|
||||
rect.moveCenter(anchor.p1());
|
||||
painter->drawEllipse(rect);
|
||||
rect.moveCenter(anchor.p2());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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,9 +1234,9 @@ 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.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
p.setAntialiasing(true);
|
||||
paintCell(p, r, mode == QIcon::Selected, state == QIcon::On);
|
||||
p.restore(); // return painter to saved initial state (undo any changes to pen, coordinates, font, etc.)
|
||||
}
|
||||
|
|
|
@ -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,9 +105,8 @@ void KeyCanvas::clear()
|
|||
|
||||
void KeyCanvas::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter qp(this);
|
||||
mu::draw::Painter painter(&qp);
|
||||
painter.setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
mu::draw::Painter painter(mu::draw::QPainterProvider::make(this));
|
||||
painter.setAntialiasing(true);
|
||||
qreal wh = double(height());
|
||||
qreal ww = double(width());
|
||||
double y = wh * .5 - 2 * mu::palette::PALETTE_SPATIUM * extraMag;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "libmscore/system.h"
|
||||
#include "libmscore/staff.h"
|
||||
|
||||
#include "libmscore/draw/qpainterprovider.h"
|
||||
|
||||
namespace Ms {
|
||||
namespace PluginAPI {
|
||||
//---------------------------------------------------------
|
||||
|
@ -171,15 +173,13 @@ void ScoreView::setScore(Ms::Score* s)
|
|||
|
||||
void ScoreView::paint(QPainter* qp)
|
||||
{
|
||||
mu::draw::Painter mup(qp);
|
||||
mu::draw::Painter* p = &mup;
|
||||
p->setRenderHint(mu::draw::Painter::Antialiasing, true);
|
||||
p->setRenderHint(mu::draw::Painter::TextAntialiasing, 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;
|
||||
|
@ -192,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue