##// END OF EJS Templates
fixed legend scrolling in detached mode. updated example
sauimone -
r1446:f8259d05b01f
parent child
Show More
@@ -141,7 +141,7 void MainWidget::showLegendSpinbox()
141 141
142 142 m_legendHeight->setMinimum(0);
143 143 m_legendHeight->setMaximum(chartViewRect.height());
144 m_legendHeight->setValue(64);
144 m_legendHeight->setValue(75);
145 145 }
146 146
147 147 void MainWidget::hideLegendSpinbox()
@@ -334,23 +334,24 void QLegendPrivate::setOffset(qreal x, qreal y)
334 334 }
335 335 }
336 336
337 // If detached, the scrolling and layout logic is inverted.
337 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
338 338 if (!m_attachedToChart) {
339 339 scrollHorizontal = !scrollHorizontal;
340 340 }
341 341
342 // Limit offset between m_minOffset and m_maxOffset
342 343 if (scrollHorizontal) {
343 344 if(m_width<=m_rect.width()) return;
344 345
345 346 if (x != m_offsetX) {
346 m_offsetX = qBound(qreal(0), x, m_width - m_rect.width());
347 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
347 348 m_markers->setPos(-m_offsetX,m_rect.top());
348 349 }
349 350 } else {
350 351 if(m_height<=m_rect.height()) return;
351 352
352 353 if (y != m_offsetY) {
353 m_offsetY = qBound(qreal(0), y, m_height - m_rect.height());
354 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
354 355 m_markers->setPos(m_rect.left(),-m_offsetY);
355 356 }
356 357 }
@@ -420,12 +421,22 void QLegendPrivate::updateLayout()
420 421 break;
421 422 }
422 423
424 m_minOffsetX = 0;
425 m_minOffsetY = 0;
426 m_maxOffsetX = m_width - m_rect.width();
427 m_maxOffsetY = m_height - m_rect.height();
428
423 429 m_presenter->updateLayout();
424 430 }
425 431
426 432 void QLegendPrivate::updateDetachedLayout()
427 433 {
434 // Detached layout is different.
435 // In detached mode legend may have multiple rows and columns, so layout calculations
436 // differ a log from attached mode.
437 // Also the scrolling logic is bit different.
428 438 m_offsetX=0;
439 m_offsetY=0;
429 440 QList<QGraphicsItem *> items = m_markers->childItems();
430 441
431 442 if(items.isEmpty()) return;
@@ -459,6 +470,11 void QLegendPrivate::updateDetachedLayout()
459 470 }
460 471 m_markers->setPos(m_rect.topLeft());
461 472 m_width = m_minWidth;
473
474 m_minOffsetX = 0;
475 m_minOffsetY = 0;
476 m_maxOffsetX = m_width - m_rect.width();
477 m_maxOffsetY = m_height - m_rect.height();
462 478 }
463 479 break;
464 480 case Qt::AlignBottom: {
@@ -486,6 +502,11 void QLegendPrivate::updateDetachedLayout()
486 502 }
487 503 m_markers->setPos(m_rect.topLeft());
488 504 m_width = m_minWidth;
505
506 m_minOffsetX = 0;
507 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
508 m_maxOffsetX = m_width - m_rect.width();
509 m_maxOffsetY = 0;
489 510 }
490 511 break;
491 512 case Qt::AlignLeft: {
@@ -501,7 +522,6 void QLegendPrivate::updateDetachedLayout()
501 522 m_minWidth = qMax(m_minWidth,rect.width());
502 523 m_minHeight = qMax(m_minHeight,h);
503 524 maxWidth = qMax(maxWidth,w);
504 m_width = qMax(m_width, maxWidth);
505 525 item->setPos(point.x(),point.y());
506 526 point.setY(point.y() + h);
507 527 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
@@ -514,8 +534,14 void QLegendPrivate::updateDetachedLayout()
514 534 }
515 535 }
516 536 }
537 m_width += maxWidth;
517 538 m_markers->setPos(m_rect.topLeft());
518 539 m_height = m_minHeight;
540
541 m_minOffsetX = 0;
542 m_minOffsetY = 0;
543 m_maxOffsetX = m_width - m_rect.width();
544 m_maxOffsetY = m_height - m_rect.height();
519 545 }
520 546 break;
521 547 case Qt::AlignRight: {
@@ -531,7 +557,6 void QLegendPrivate::updateDetachedLayout()
531 557 m_minWidth = qMax(m_minWidth,rect.width());
532 558 m_minHeight = qMax(m_minHeight,h);
533 559 maxWidth = qMax(maxWidth,w);
534 m_width = qMax(m_width, maxWidth);
535 560 item->setPos(point.x() - w,point.y());
536 561 point.setY(point.y() + h);
537 562 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
@@ -544,8 +569,14 void QLegendPrivate::updateDetachedLayout()
544 569 }
545 570 }
546 571 }
572 m_width += maxWidth;
547 573 m_markers->setPos(m_rect.topLeft());
548 574 m_height = m_minHeight;
575
576 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
577 m_minOffsetY = 0;
578 m_maxOffsetX = 0;
579 m_maxOffsetY = m_height - m_rect.height();
549 580 }
550 581 break;
551 582 default:
@@ -67,6 +67,10 private:
67 67 QRectF m_rect;
68 68 qreal m_offsetX;
69 69 qreal m_offsetY;
70 qreal m_minOffsetX;
71 qreal m_minOffsetY;
72 qreal m_maxOffsetX;
73 qreal m_maxOffsetY;
70 74 qreal m_minWidth;
71 75 qreal m_minHeight;
72 76 qreal m_width;
General Comments 0
You need to be logged in to leave comments. Login now