Skip to content

Commit

Permalink
Merge pull request #1308 from vgstef/ContinuousPanel
Browse files Browse the repository at this point in the history
Fix continuous panel  issues and panning
  • Loading branch information
lasconic committed Sep 13, 2014
2 parents 0749a30 + 3fba919 commit 87e15ae
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 33 deletions.
60 changes: 41 additions & 19 deletions mscore/continuouspanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Ms {
ContinuousPanel::ContinuousPanel(ScoreView* sv)
{
_sv = sv;
_active = true;
_visible = false;
_width = 0.0;
_oldWidth = 0.0;
Expand All @@ -45,6 +46,7 @@ ContinuousPanel::ContinuousPanel(ScoreView* sv)
_x = 0.0;
_y = 0.0;
_heightName = 0.0;
_lineHeightName = 0.0;
_widthClef = 0.0;
_widthKeySig = 0.0;
_widthTimeSig = 0.0;
Expand All @@ -65,20 +67,27 @@ ContinuousPanel::ContinuousPanel(ScoreView* sv)

void ContinuousPanel::paint(const QRect& /*r*/, QPainter& p)
{
if (!_visible)
if (!_active) {
_visible = false;
return;
}

Measure* measure = _score->tick2measure(0);
if (measure == 0)
if (measure == 0){
_visible = false;
return;
}

if (measure->mmRest()) {
measure = measure->mmRest();
_mmRestCount = measure->mmRestCount();
}

System* system = measure->system();
if (system == 0)
if (system == 0) {
_visible = false;
return;
}

Segment* s = _score->tick2segment(0);
double _spatium = _score->spatium();
Expand All @@ -89,13 +98,15 @@ void ContinuousPanel::paint(const QRect& /*r*/, QPainter& p)
//
// Don't show panel if staff names are visible
//
if (_sv->xoffset() / _sv->mag() + _width >= 0)
return;
if (_sv->xoffset() / _sv->mag() + _width >= 0) {
_visible = false;
return;
}

//
// Set panel height for whole system
//
_height = 6 * _spatium;
_height = 6 * _spatium;
_y = system->staffYpage(0) + system->page()->pos().y();
double y2 = 0.0;
for (int i = 0; i < _score->nstaves(); ++i) {
Expand All @@ -115,8 +126,10 @@ void ContinuousPanel::paint(const QRect& /*r*/, QPainter& p)
//qDebug() << "width=" << _width << "_y="<< _y << "_offsetPanel=" << _offsetPanel << "_sv->xoffset()" << _sv->xoffset() << "_sv->mag()" << _sv->mag() <<"_spatium" << _spatium << "s->canvasPos().x()" << s->canvasPos().x() << "s->x()" << s->x();
Page* page = _score->pages().front();
QList<Element*> elementsCurrent = page->items(_rect);
if (elementsCurrent.empty())
if (elementsCurrent.empty()) {
_visible = false;
return;
}
qStableSort(elementsCurrent.begin(), elementsCurrent.end(), elementLessThan);

_currentMeasure = nullptr;
Expand Down Expand Up @@ -149,6 +162,7 @@ void ContinuousPanel::paint(const QRect& /*r*/, QPainter& p)
return;
findElementWidths(elementsCurrent);
draw(p, elementsCurrent);
_visible = true;
}


Expand All @@ -162,6 +176,7 @@ void ContinuousPanel::findElementWidths(const QList<Element*>& el) {
// The first pass serves to get the maximum width for each elements
//
_heightName = 0;
_lineHeightName = 0;
_widthClef = 0;
_widthKeySig = 0;
_widthTimeSig = 0;
Expand Down Expand Up @@ -233,6 +248,9 @@ void ContinuousPanel::findElementWidths(const QList<Element*>& el) {
if ((newName->height() > _heightName) && (newName->text() != ""))
_heightName = newName->height();

if ((newName->lineHeight() > _lineHeightName) && (newName->text() != ""))
_lineHeightName = newName->lineHeight();

if (newClef->width() > _widthClef)
_widthClef = newClef->width();

Expand Down Expand Up @@ -336,6 +354,18 @@ void ContinuousPanel::draw(QPainter& painter, const QList<Element*>& el) {
Staff* currentStaff = _score->staff(e->staffIdx());
Segment* parent = _score->tick2segment(_currentMeasureTick);

//
// Get barline height (used to center instrument name
//
BarLine* newBarLine = new BarLine(_score);
newBarLine->setBarLineType(BarLineType::NORMAL);
newBarLine->setParent(parent);
newBarLine->setTrack(e->track());
newBarLine->setSpan(currentStaff->barLineSpan());
newBarLine->setSpanFrom(currentStaff->barLineFrom());
newBarLine->setSpanTo(currentStaff->barLineTo());
newBarLine->layout();

//
// Draw the current staff name
//
Expand All @@ -353,14 +383,14 @@ void ContinuousPanel::draw(QPainter& painter, const QList<Element*>& el) {
newName->layout();
pos = QPointF (_offsetPanel, e->pagePos().y());
painter.translate(pos);
//qDebug() << "_heightName=" << _heightName << " newName->height=" << newName->height() << " staff (e->height)=" << e->height() << " newName->width()=" << newName->width() << " newName->linespace()=" << newName->lineSpacing() << " newName->lineHeight()=" << newName->lineHeight();

if (currentStaff->primaryStaff()) {
//if (currentStaff->part()->startTrack() == currentStaff->idx() * VOICES) {
if (currentStaff->part()->staff(0) == currentStaff) {
painter.rotate(-90);
int nbLines = newName->height() / newName->lineHeight();
pos = QPointF (-e->height() + (e->height() - newName->width()) / 2, _heightName - (_heightName - _heightName / nbLines) - newName->lineSpacing() * 0.1); // Because we rotate the canvas, height and width are swaped
pos = QPointF (- newBarLine->height() / 2 - newName->width() / 2, _heightName - newName->height() + _lineHeightName * 0.8); // Because we rotate the canvas, height and width are swaped
painter.translate(pos);
newName->draw(&painter);
//qDebug() << "_heightName=" << _heightName << "Barline height=" << newBarLine->height() << " newName->height=" << newName->height() << " staff (e->height)=" << e->height() << " newName->width()=" << newName->width() << " newName->linespace()=" << newName->lineSpacing() << " newName->lineHeight()=" << newName->lineHeight() << " pos (" << pos.x() << "," << pos.y() << ")";
painter.translate(-pos);
painter.rotate(90);
}
Expand All @@ -382,14 +412,6 @@ void ContinuousPanel::draw(QPainter& painter, const QList<Element*>& el) {
//
// Draw barline
//
BarLine* newBarLine = new BarLine(_score);
newBarLine->setBarLineType(BarLineType::NORMAL);
newBarLine->setParent(parent);
newBarLine->setTrack(e->track());
newBarLine->setSpan(currentStaff->barLineSpan());
newBarLine->setSpanFrom(currentStaff->barLineFrom());
newBarLine->setSpanTo(currentStaff->barLineTo());
newBarLine->layout();
newBarLine->draw(&painter);
delete newBarLine;

Expand Down
9 changes: 6 additions & 3 deletions mscore/continuouspanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class ContinuousPanel {
ScoreView* _sv;
Score* _score;
QRectF _rect;
bool _visible;
bool _active; // Used to active or desactive the panel
bool _visible; // False if beginning of the score is visible
const Measure* _currentMeasure;
int _currentMeasureTick;
int _currentMeasureNo;
Expand All @@ -40,6 +41,7 @@ class ContinuousPanel {
qreal _measureWidth;
qreal _height;
qreal _heightName;
qreal _lineHeightName;
qreal _widthName;
qreal _widthClef;
qreal _widthKeySig;
Expand All @@ -58,8 +60,9 @@ class ContinuousPanel {

QRectF rect() const { return _rect; }
void setRect(const QRectF& r) { _rect = r; }
bool visible() const { return _visible; }
void setVisible(bool val) { _visible = val; }
bool active() const { return _active; }
void setActive(bool val) { _active = val; }
bool visible() { return _active ? _visible : false; }
void setScore(Score* s) { _score = s; }
qreal width() { return _width; }

Expand Down
49 changes: 38 additions & 11 deletions mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ ScoreView::ScoreView(QWidget* parent)
_cursor = new PositionCursor(this);
_cursor->setType(CursorType::POS);
_continuousPanel = new ContinuousPanel(this);
_continuousPanel->setVisible(true);
_continuousPanel->setActive(true);

shadowNote = 0;
grips = 0;
Expand Down Expand Up @@ -3693,19 +3693,46 @@ void ScoreView::adjustCanvasPosition(const Element* el, bool playBack)
// printf("adjustCanvasPosition <%s>\n", el->name());

if (score()->layoutMode() == LayoutMode::LINE) {
qreal xo; // new x offset
qreal curPosR = _cursor->rect().right();
qreal curPosL = _cursor->rect().left();
qreal curPosMagR = curPosR * mag() + xoffset();
qreal curPosMagL = curPosL * mag() + xoffset();

if (curPosMagR >= width() * 0.90) { // leaves 10% margin to the right
xo = xoffset() - curPosMagL + width() * 0.05;
if (!el)
return;

/* Not used, because impossible to get panel width beforehand
const MeasureBase *m = 0;
if (el->type() == Element::Type::MEASURE)
m = static_cast<const MeasureBase*>(el);
else
m = static_cast<const Measure*>(el->parent()->findMeasure());
*/

qreal xo = 0.0; // new x offset
qreal curPosR = _cursor->rect().right(); // Position on the canvas
qreal curPosL = _cursor->rect().left(); // Position on the canvas
qreal curPosMagR = curPosR * mag() + xoffset(); // Position in the screen
qreal curPosMagL = curPosL * mag() + xoffset(); // Position in the screen
qreal marginLeft = width() * 0.05;
qreal marginRight = width() * 0.05; // leaves 5% margin to the right

if (_continuousPanel->visible())
marginLeft += _continuousPanel->width();

if (round(curPosMagR) > round(width() - marginRight)) {
xo = -curPosL * mag() + marginLeft;

// Keeps the score up to the right to avoid blank gap on the right.
qreal scoreEnd = score()->pages().front()->width() * mag() + xo;
if (scoreEnd < width())
xo += width() - scoreEnd;

setOffset(xo, yoffset());
update();
}
else if (curPosMagL < width() * 0.05) { // leaves 5% margin to the left
xo = -curPosL*mag() + width() * 0.05;
else if (round(curPosMagL) < round(marginLeft) ) {
xo = -curPosR * mag() + width() - marginRight;

// Bring back the score to the left to avoid blank gap on the left.
if (xo > 0)
xo = 0;

setOffset(xo, yoffset());
update();
}
Expand Down

0 comments on commit 87e15ae

Please sign in to comment.