Skip to content

Commit

Permalink
* printing in default colors done by re-rendering the document using …
Browse files Browse the repository at this point in the history
…the default colors

* minor refactoring

* scoreArea background color changed to be Light instead of Backroung color (in light theme, Background is light grey)

powertab#286
  • Loading branch information
mostafa-nabil committed Jun 12, 2020
1 parent a7902b2 commit 6b038eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
26 changes: 19 additions & 7 deletions source/app/scorearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ ScoreArea::ScoreArea(QWidget *parent)
: QGraphicsView(parent),
myScoreInfoBlock(nullptr),
myCaretPainter(nullptr),
myScorePalette(parent->palette()),
myClickPubSub(std::make_shared<ClickPubSub>())
{
setScene(&myScene);

// store the palette use by the app (currently the default system palette)
// for usage in rendering
scorePalette = this->palette();
setBackgroundBrush(scorePalette.background());
// set the palette colors to be used when printing
myPrintPalette.setColor(QPalette::Text,Qt::black);
myPrintPalette.setColor(QPalette::Light,Qt::white);
myPrintPalette.setColor(QPalette::Dark,Qt::lightGray);

setBackgroundBrush(myScorePalette.light());
}

void ScoreArea::renderDocument(const Document &document)
Expand All @@ -63,7 +66,7 @@ void ScoreArea::renderDocument(const Document &document)
auto start = std::chrono::high_resolution_clock::now();

myCaretPainter =
new CaretPainter(document.getCaret(), document.getViewOptions(), scorePalette.text().color());
new CaretPainter(document.getCaret(), document.getViewOptions(), myScorePalette.text().color());
myCaretPainter->subscribeToMovement([=]() {
adjustScroll();
});
Expand Down Expand Up @@ -168,9 +171,15 @@ void ScoreArea::print(QPrinter &printer)
QPainter painter;
painter.begin(&printer);

// use the printPalette for rendering
myScorePalette = myPrintPalette;

// Hide the caret when printing.
myCaretPainter->hide();

//render the document after the palette has been set to print colors
this->renderDocument(*myDocument);

QRectF target_rect(0, 0, painter.device()->width(),
painter.device()->height());

Expand All @@ -181,7 +190,6 @@ void ScoreArea::print(QPrinter &printer)
for (int i = 0, n = items.length(); i < n; ++i)
{
const QGraphicsItem *item = items[i];

const QRectF source_rect = item->sceneBoundingRect();
const float ratio =
std::min(target_rect.width() / source_rect.width(),
Expand Down Expand Up @@ -213,6 +221,10 @@ void ScoreArea::print(QPrinter &printer)

myCaretPainter->show();
painter.end();

// reuse the original app palette and render the document
myScorePalette = this->palette();
this->renderDocument(*myDocument);
}

std::shared_ptr<ClickPubSub> ScoreArea::getClickPubSub() const
Expand Down Expand Up @@ -254,5 +266,5 @@ void ScoreArea::refreshZoom()

QPalette ScoreArea::getPalette() const
{
return scorePalette;
return myScorePalette;
}
3 changes: 2 additions & 1 deletion source/app/scorearea.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ class ScoreArea : public QGraphicsView
const Document *myDocument;
QGraphicsItem *myScoreInfoBlock;
QList<QGraphicsItem *> myRenderedSystems;
QPalette scorePalette; // the palette used by scorearea
CaretPainter *myCaretPainter;
QPalette myScorePalette; // the palette used by scorearea
QPalette myPrintPalette; // the palette used by when printing

std::shared_ptr<ClickPubSub> myClickPubSub;
};
Expand Down

0 comments on commit 6b038eb

Please sign in to comment.