implemented drawing multiple pages of notation
This commit is contained in:
parent
b407a2a2de
commit
f622c3f1b9
|
@ -47,7 +47,7 @@ public:
|
|||
virtual void setViewSize(const QSizeF& vs) = 0;
|
||||
virtual void setViewMode(const ViewMode& vm) = 0;
|
||||
virtual ViewMode viewMode() const = 0;
|
||||
virtual void paint(QPainter* painter) = 0;
|
||||
virtual void paint(QPainter* painter, const QRectF& frameRect) = 0;
|
||||
virtual QRectF previewRect() const = 0;
|
||||
|
||||
virtual ValCh<bool> opened() const = 0;
|
||||
|
|
|
@ -38,6 +38,10 @@ public:
|
|||
virtual QColor backgroundColor() const = 0;
|
||||
virtual async::Channel<QColor> backgroundColorChanged() const = 0;
|
||||
|
||||
virtual QColor pageColor() const = 0;
|
||||
virtual QColor borderColor() const = 0;
|
||||
virtual int borderWidth() const = 0;
|
||||
|
||||
virtual bool foregroundUseColor() const = 0;
|
||||
virtual QColor defaultForegroundColor() const = 0;
|
||||
virtual QColor foregroundColor() const = 0;
|
||||
|
|
|
@ -168,37 +168,91 @@ QRectF Notation::previewRect() const
|
|||
return pages.first()->bbox();
|
||||
}
|
||||
|
||||
void Notation::paint(QPainter* painter)
|
||||
void Notation::paint(QPainter* painter, const QRectF& frameRect)
|
||||
{
|
||||
const QList<Ms::Page*>& mspages = m_score->pages();
|
||||
|
||||
if (mspages.isEmpty()) {
|
||||
painter->drawText(10, 10, "no pages");
|
||||
const QList<Ms::Page*>& pages = score()->pages();
|
||||
if (pages.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ms::Page* page = mspages.first();
|
||||
switch (score()->layoutMode()) {
|
||||
case LayoutMode::LINE:
|
||||
case LayoutMode::SYSTEM: {
|
||||
bool paintBorders = false;
|
||||
paintPages(painter, frameRect, { pages.first() }, paintBorders);
|
||||
break;
|
||||
}
|
||||
case LayoutMode::FLOAT:
|
||||
case LayoutMode::PAGE: {
|
||||
bool paintBorders = !score()->printing();
|
||||
paintPages(painter, frameRect, pages, paintBorders);
|
||||
}
|
||||
}
|
||||
|
||||
page->draw(painter);
|
||||
m_interaction->paint(painter);
|
||||
}
|
||||
|
||||
painter->fillRect(page->bbox(), QColor("#ffffff"));
|
||||
void Notation::paintPages(QPainter* painter, const QRectF& frameRect, const QList<Ms::Page*>& pages, bool paintBorders) const
|
||||
{
|
||||
for (Ms::Page* page : pages) {
|
||||
QRectF pageRect(page->abbox().translated(page->pos()));
|
||||
|
||||
for (Ms::Element* element : page->elements()) {
|
||||
if (pageRect.right() < frameRect.left()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pageRect.left() > frameRect.right()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (paintBorders) {
|
||||
paintPageBorder(painter, page);
|
||||
}
|
||||
|
||||
QPointF pagePosition(page->pos());
|
||||
painter->translate(pagePosition);
|
||||
painter->fillRect(page->bbox(), configuration()->pageColor());
|
||||
paintElements(painter, page->elements());
|
||||
painter->translate(-pagePosition);
|
||||
}
|
||||
}
|
||||
|
||||
void Notation::paintPageBorder(QPainter* painter, const Page* page) const
|
||||
{
|
||||
QRectF boundingRect(page->canvasBoundingRect());
|
||||
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->setPen(QPen(configuration()->borderColor(), configuration()->borderWidth()));
|
||||
painter->drawRect(boundingRect);
|
||||
|
||||
if (!score()->showPageborders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->setPen(MScore::frameMarginColor);
|
||||
boundingRect.adjust(page->lm(), page->tm(), -page->rm(), -page->bm());
|
||||
painter->drawRect(boundingRect);
|
||||
|
||||
if (!page->isOdd()) {
|
||||
painter->drawLine(boundingRect.right(), 0.0, boundingRect.right(), boundingRect.bottom());
|
||||
}
|
||||
}
|
||||
|
||||
void Notation::paintElements(QPainter* painter, const QList<Element*>& elements) const
|
||||
{
|
||||
for (const Ms::Element* element : elements) {
|
||||
if (!element->visible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
element->itemDiscovered = false;
|
||||
QPointF pos(element->pagePos());
|
||||
|
||||
painter->translate(pos);
|
||||
QPointF elementPosition(element->pagePos());
|
||||
|
||||
painter->translate(elementPosition);
|
||||
element->draw(painter);
|
||||
|
||||
painter->translate(-pos);
|
||||
painter->translate(-elementPosition);
|
||||
}
|
||||
|
||||
m_interaction->paint(painter);
|
||||
}
|
||||
|
||||
mu::ValCh<bool> Notation::opened() const
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "igetscore.h"
|
||||
#include "async/asyncable.h"
|
||||
|
||||
#include "modularity/ioc.h"
|
||||
#include "inotationconfiguration.h"
|
||||
|
||||
namespace Ms {
|
||||
class MScore;
|
||||
class Score;
|
||||
|
@ -36,6 +39,8 @@ class NotationMidiInput;
|
|||
class NotationParts;
|
||||
class Notation : virtual public INotation, public IGetScore, public async::Asyncable
|
||||
{
|
||||
INJECT(notation, INotationConfiguration, configuration)
|
||||
|
||||
public:
|
||||
explicit Notation(Ms::Score* score = nullptr);
|
||||
~Notation() override;
|
||||
|
@ -47,7 +52,7 @@ public:
|
|||
void setViewSize(const QSizeF& vs) override;
|
||||
void setViewMode(const ViewMode& viewMode) override;
|
||||
ViewMode viewMode() const override;
|
||||
void paint(QPainter* painter) override;
|
||||
void paint(QPainter* painter, const QRectF& frameRect) override;
|
||||
QRectF previewRect() const override;
|
||||
|
||||
ValCh<bool> opened() const override;
|
||||
|
@ -79,6 +84,10 @@ protected:
|
|||
private:
|
||||
friend class NotationInteraction;
|
||||
|
||||
void paintPages(QPainter* painter, const QRectF& frameRect, const QList<Ms::Page*>& pages, bool paintBorders) const;
|
||||
void paintPageBorder(QPainter* painter, const Ms::Page* page) const;
|
||||
void paintElements(QPainter* painter, const QList<Element*>& elements) const;
|
||||
|
||||
QSizeF viewSize() const;
|
||||
|
||||
void notifyAboutNotationChanged();
|
||||
|
|
|
@ -105,6 +105,21 @@ Channel<QColor> NotationConfiguration::backgroundColorChanged() const
|
|||
return m_backgroundColorChanged;
|
||||
}
|
||||
|
||||
QColor NotationConfiguration::pageColor() const
|
||||
{
|
||||
return QColor("#ffffff");
|
||||
}
|
||||
|
||||
QColor NotationConfiguration::borderColor() const
|
||||
{
|
||||
return QColor(0, 0, 0, 102);
|
||||
}
|
||||
|
||||
int NotationConfiguration::borderWidth() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool NotationConfiguration::foregroundUseColor() const
|
||||
{
|
||||
return settings()->value(FOREGROUND_USE_COLOR).toBool();
|
||||
|
|
|
@ -39,6 +39,10 @@ public:
|
|||
QColor backgroundColor() const override;
|
||||
async::Channel<QColor> backgroundColorChanged() const override;
|
||||
|
||||
QColor pageColor() const override;
|
||||
QColor borderColor() const override;
|
||||
int borderWidth() const override;
|
||||
|
||||
bool foregroundUseColor() const override;
|
||||
QColor foregroundColor() const override;
|
||||
QColor defaultForegroundColor() const override;
|
||||
|
|
|
@ -199,19 +199,19 @@ void NotationPaintView::showContextMenu(const ElementType& elementType, const QP
|
|||
emit openContextMenuRequested(menuItems, pos);
|
||||
}
|
||||
|
||||
void NotationPaintView::paint(QPainter* p)
|
||||
void NotationPaintView::paint(QPainter* painter)
|
||||
{
|
||||
QRect rect(0, 0, width(), height());
|
||||
p->fillRect(rect, m_backgroundColor);
|
||||
painter->fillRect(rect, m_backgroundColor);
|
||||
|
||||
p->setTransform(m_matrix);
|
||||
painter->setTransform(m_matrix);
|
||||
|
||||
if (m_notation) {
|
||||
m_notation->paint(p);
|
||||
m_notation->paint(painter, toLogical(rect));
|
||||
|
||||
m_playbackCursor->paint(p);
|
||||
m_playbackCursor->paint(painter);
|
||||
} else {
|
||||
p->drawText(10, 10, "no notation");
|
||||
painter->drawText(10, 10, "no notation");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -234,6 +234,6 @@ void TemplatePaintView::paint(QPainter* painter)
|
|||
painter->scale(m_currentScaleFactor, m_currentScaleFactor);
|
||||
|
||||
if (m_notation) {
|
||||
m_notation->paint(painter);
|
||||
m_notation->paint(painter, rect);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue