##// 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 m_legendHeight->setMinimum(0);
142 m_legendHeight->setMinimum(0);
143 m_legendHeight->setMaximum(chartViewRect.height());
143 m_legendHeight->setMaximum(chartViewRect.height());
144 m_legendHeight->setValue(64);
144 m_legendHeight->setValue(75);
145 }
145 }
146
146
147 void MainWidget::hideLegendSpinbox()
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 if (!m_attachedToChart) {
338 if (!m_attachedToChart) {
339 scrollHorizontal = !scrollHorizontal;
339 scrollHorizontal = !scrollHorizontal;
340 }
340 }
341
341
342 // Limit offset between m_minOffset and m_maxOffset
342 if (scrollHorizontal) {
343 if (scrollHorizontal) {
343 if(m_width<=m_rect.width()) return;
344 if(m_width<=m_rect.width()) return;
344
345
345 if (x != m_offsetX) {
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 m_markers->setPos(-m_offsetX,m_rect.top());
348 m_markers->setPos(-m_offsetX,m_rect.top());
348 }
349 }
349 } else {
350 } else {
350 if(m_height<=m_rect.height()) return;
351 if(m_height<=m_rect.height()) return;
351
352
352 if (y != m_offsetY) {
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 m_markers->setPos(m_rect.left(),-m_offsetY);
355 m_markers->setPos(m_rect.left(),-m_offsetY);
355 }
356 }
356 }
357 }
@@ -420,12 +421,22 void QLegendPrivate::updateLayout()
420 break;
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 m_presenter->updateLayout();
429 m_presenter->updateLayout();
424 }
430 }
425
431
426 void QLegendPrivate::updateDetachedLayout()
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 m_offsetX=0;
438 m_offsetX=0;
439 m_offsetY=0;
429 QList<QGraphicsItem *> items = m_markers->childItems();
440 QList<QGraphicsItem *> items = m_markers->childItems();
430
441
431 if(items.isEmpty()) return;
442 if(items.isEmpty()) return;
@@ -459,6 +470,11 void QLegendPrivate::updateDetachedLayout()
459 }
470 }
460 m_markers->setPos(m_rect.topLeft());
471 m_markers->setPos(m_rect.topLeft());
461 m_width = m_minWidth;
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 break;
479 break;
464 case Qt::AlignBottom: {
480 case Qt::AlignBottom: {
@@ -486,6 +502,11 void QLegendPrivate::updateDetachedLayout()
486 }
502 }
487 m_markers->setPos(m_rect.topLeft());
503 m_markers->setPos(m_rect.topLeft());
488 m_width = m_minWidth;
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 break;
511 break;
491 case Qt::AlignLeft: {
512 case Qt::AlignLeft: {
@@ -501,7 +522,6 void QLegendPrivate::updateDetachedLayout()
501 m_minWidth = qMax(m_minWidth,rect.width());
522 m_minWidth = qMax(m_minWidth,rect.width());
502 m_minHeight = qMax(m_minHeight,h);
523 m_minHeight = qMax(m_minHeight,h);
503 maxWidth = qMax(maxWidth,w);
524 maxWidth = qMax(maxWidth,w);
504 m_width = qMax(m_width, maxWidth);
505 item->setPos(point.x(),point.y());
525 item->setPos(point.x(),point.y());
506 point.setY(point.y() + h);
526 point.setY(point.y() + h);
507 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
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 m_markers->setPos(m_rect.topLeft());
538 m_markers->setPos(m_rect.topLeft());
518 m_height = m_minHeight;
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 break;
546 break;
521 case Qt::AlignRight: {
547 case Qt::AlignRight: {
@@ -531,7 +557,6 void QLegendPrivate::updateDetachedLayout()
531 m_minWidth = qMax(m_minWidth,rect.width());
557 m_minWidth = qMax(m_minWidth,rect.width());
532 m_minHeight = qMax(m_minHeight,h);
558 m_minHeight = qMax(m_minHeight,h);
533 maxWidth = qMax(maxWidth,w);
559 maxWidth = qMax(maxWidth,w);
534 m_width = qMax(m_width, maxWidth);
535 item->setPos(point.x() - w,point.y());
560 item->setPos(point.x() - w,point.y());
536 point.setY(point.y() + h);
561 point.setY(point.y() + h);
537 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
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 m_markers->setPos(m_rect.topLeft());
573 m_markers->setPos(m_rect.topLeft());
548 m_height = m_minHeight;
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 break;
581 break;
551 default:
582 default:
@@ -67,6 +67,10 private:
67 QRectF m_rect;
67 QRectF m_rect;
68 qreal m_offsetX;
68 qreal m_offsetX;
69 qreal m_offsetY;
69 qreal m_offsetY;
70 qreal m_minOffsetX;
71 qreal m_minOffsetY;
72 qreal m_maxOffsetX;
73 qreal m_maxOffsetY;
70 qreal m_minWidth;
74 qreal m_minWidth;
71 qreal m_minHeight;
75 qreal m_minHeight;
72 qreal m_width;
76 qreal m_width;
General Comments 0
You need to be logged in to leave comments. Login now