##// END OF EJS Templates
split legend layout to vertical and horizontal functions
sauimone -
r810:c712716bc681
parent child
Show More
@@ -106,6 +106,7 void BarChartItem::dataChanged()
106 }
106 }
107 }
107 }
108 }
108 }
109
109 QVector<QRectF> BarChartItem::calculateLayout()
110 QVector<QRectF> BarChartItem::calculateLayout()
110 {
111 {
111 QVector<QRectF> layout;
112 QVector<QRectF> layout;
@@ -507,20 +507,42 void QLegend::updateLayout()
507 return;
507 return;
508 }
508 }
509
509
510 // Find out widest item.
511 QSizeF markerMaxSize = maximumMarkerSize();
512 checkFirstMarkerBounds();
510 checkFirstMarkerBounds();
513
511
514 // Use max height as scroll button size
515 rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
516
517 qreal totalWidth = 0;
518 qreal totalHeight = 0;
519 switch (m_alignment)
512 switch (m_alignment)
520 {
513 {
521 // Both cases organise items horizontally
514 // Both cases organise items horizontally
522 case QLegend::AlignmentBottom:
515 case QLegend::AlignmentBottom:
523 case QLegend::AlignmentTop: {
516 case QLegend::AlignmentTop: {
517 layoutHorizontal();
518 break;
519 }
520 // Both cases organize items vertically
521 case QLegend::AlignmentLeft:
522 case QLegend::AlignmentRight: {
523 layoutVertical();
524 break;
525 }
526 default: {
527 break;
528 }
529 }
530
531 }
532
533 /*!
534 \internal Organizes markers horizontally.
535 Causes legend to be resized.
536 */
537 void QLegend::layoutHorizontal()
538 {
539 // Find out widest item.
540 QSizeF markerMaxSize = maximumMarkerSize();
541 // Use max height as scroll button size
542 rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
543
544 qreal totalWidth = 0;
545 qreal totalHeight = 0;
524
546
525 qreal xStep = markerMaxSize.width();
547 qreal xStep = markerMaxSize.width();
526 qreal x = m_pos.x() + m_margin;
548 qreal x = m_pos.x() + m_margin;
@@ -571,11 +593,24 void QLegend::updateLayout()
571 totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2;
593 totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2;
572 totalHeight = markerMaxSize.height() + m_margin * 2;
594 totalHeight = markerMaxSize.height() + m_margin * 2;
573
595
574 break;
596 m_size.setWidth(totalWidth);
597 m_size.setHeight(totalHeight);
575 }
598 }
576 // Both cases organize items vertically
599
577 case QLegend::AlignmentLeft:
600 /*!
578 case QLegend::AlignmentRight: {
601 \internal Organizes markers vertically.
602 Causes legend to be resized.
603 */
604 void QLegend::layoutVertical()
605 {
606 // Find out widest item.
607 QSizeF markerMaxSize = maximumMarkerSize();
608 // Use max height as scroll button size
609 rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
610
611 qreal totalWidth = 0;
612 qreal totalHeight = 0;
613
579 qreal yStep = markerMaxSize.height();
614 qreal yStep = markerMaxSize.height();
580 qreal x = m_pos.x() + m_margin;
615 qreal x = m_pos.x() + m_margin;
581 qreal y = m_pos.y() + m_margin;
616 qreal y = m_pos.y() + m_margin;
@@ -622,17 +657,9 void QLegend::updateLayout()
622
657
623 totalWidth += markerMaxSize.width() + m_margin * 2;
658 totalWidth += markerMaxSize.width() + m_margin * 2;
624 totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this
659 totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this
625 break;
626 }
627 default: {
628 break;
629 }
630 }
631
660
632 m_size.setWidth(totalWidth);
661 m_size.setWidth(totalWidth);
633 m_size.setHeight(totalHeight);
662 m_size.setHeight(totalHeight);
634
635 update();
636 }
663 }
637
664
638 /*!
665 /*!
@@ -109,6 +109,8 private:
109 void appendMarkers(QPieSeries *series);
109 void appendMarkers(QPieSeries *series);
110 void deleteMarkers(QSeries *series);
110 void deleteMarkers(QSeries *series);
111 void updateLayout();
111 void updateLayout();
112 void layoutHorizontal();
113 void layoutVertical();
112 void rescaleScrollButtons(const QSize &size);
114 void rescaleScrollButtons(const QSize &size);
113 QSizeF maximumMarkerSize();
115 QSizeF maximumMarkerSize();
114 void checkFirstMarkerBounds();
116 void checkFirstMarkerBounds();
General Comments 0
You need to be logged in to leave comments. Login now