666 HsWidgetPresentationData presentation; |
666 HsWidgetPresentationData presentation; |
667 presentation.orientation = orientation; |
667 presentation.orientation = orientation; |
668 |
668 |
669 HsPageVisual *pageVisual = visual(); |
669 HsPageVisual *pageVisual = visual(); |
670 HsWidgetHostVisual *visual(0); |
670 HsWidgetHostVisual *visual(0); |
671 #ifdef HSWIDGETORGANIZER_ALGORITHM |
671 QList<HsWidgetHost*> newWidgets; |
672 QList<HsWidgetHost*> newWidgets; |
|
673 #endif //HSWIDGETORGANIZER_ALGORITHM |
|
674 foreach (HsWidgetHost *widget, mWidgets) { |
672 foreach (HsWidgetHost *widget, mWidgets) { |
675 visual = widget->visual(); |
673 visual = widget->visual(); |
676 if ( pageVisual->isAncestorOf(visual)) { |
674 if ( pageVisual->isAncestorOf(visual)) { |
677 if (!widget->getPresentation(presentation)) { |
675 if (!widget->getPresentation(presentation)) { |
678 #ifndef HSWIDGETORGANIZER_ALGORITHM |
|
679 QList<QRectF> geometries = converter->convert( |
|
680 from, QList<QRectF>() << visual->geometry(), to); |
|
681 visual->setGeometry(geometries.first()); |
|
682 widget->savePresentation(); |
|
683 #else //HSWIDGETORGANIZER_ALGORITHM |
|
684 newWidgets << widget; |
676 newWidgets << widget; |
685 #endif //HSWIDGETORGANIZER_ALGORITHM |
|
686 } else { |
677 } else { |
687 QRectF adjustWidgetPosition; |
678 QRectF adjustWidgetPosition; |
688 adjustWidgetPosition = visual->geometry(); |
679 adjustWidgetPosition = visual->geometry(); |
689 adjustWidgetPosition.moveTopLeft(presentation.pos()); |
680 adjustWidgetPosition.moveTopLeft(presentation.pos()); |
690 visual->setPos(adjustedWidgetPosition(adjustWidgetPosition)); |
681 visual->setPos(adjustedWidgetPosition(adjustWidgetPosition)); |
691 visual->setZValue(presentation.zValue); |
682 visual->setZValue(presentation.zValue); |
692 widget->savePresentation(); //Needed to follow pageMargin dynamic change |
683 widget->savePresentation(); //Needed to follow pageMargin dynamic change |
693 } |
684 } |
694 } |
685 } |
695 } |
686 } |
696 |
|
697 #ifdef HSWIDGETORGANIZER_ALGORITHM |
|
698 // sort new widgets in order |
|
699 if (newWidgets.count()) { |
687 if (newWidgets.count()) { |
700 // TODO: read from configuration? or just use height for portrait and width for landscape (currently only height is used) |
|
701 sortOrder order(height); |
|
702 if(orientation == Qt::Horizontal) { |
|
703 order = width; |
|
704 } |
|
705 sortWidgets(order, newWidgets); |
|
706 // get rects for new widgets |
688 // get rects for new widgets |
707 QList<QRectF> newRects; |
689 QList<QRectF> newRects; |
708 foreach (HsWidgetHost *newWidget, newWidgets) { |
690 foreach (HsWidgetHost *newWidget, newWidgets) { |
709 newRects << QRectF(QPointF(), newWidget->visual()->preferredSize()); |
691 newRects << QRectF(QPointF(), newWidget->visual()->preferredSize()); |
710 } |
692 } |
714 |
696 |
715 // scan existing widgets rects |
697 // scan existing widgets rects |
716 QList<QRectF> existingRects; |
698 QList<QRectF> existingRects; |
717 foreach (HsWidgetHost *widget, mWidgets) { |
699 foreach (HsWidgetHost *widget, mWidgets) { |
718 if (!newWidgets.contains(widget)) { |
700 if (!newWidgets.contains(widget)) { |
719 existingRects << QRectF(widget->visual()->pos(), widget->visual()->preferredSize()); |
701 existingRects << QRectF(widget->visual()->geometry()); |
720 } |
702 } |
721 } |
703 } |
722 |
704 |
723 // calculate new widget positions with "stuck 'em all"-algorithm |
705 // calculate new widget positions with "stuck 'em all"-algorithm |
724 HsWidgetPositioningOnWidgetAdd *algorithm = |
706 HsWidgetPositioningOnWidgetAdd *algorithm = |
725 HsWidgetPositioningOnWidgetAdd::instance(); |
707 HsWidgetPositioningOnWidgetAdd::instance(); |
726 QList<QRectF> calculatedRects = |
708 QList<QRectF> calculatedRects = |
727 algorithm->convert(pageRect, existingRects, newRects, QPointF()); |
709 algorithm->convert(pageRect, existingRects, newRects, QPointF()); |
728 |
710 |
729 for ( int i=0; i<newWidgets.count(); i++) { |
711 for (int i=0; i<newWidgets.count(); i++) { |
730 int j = mWidgets.indexOf(newWidgets.at(i)); |
712 int j = mWidgets.indexOf(newWidgets.at(i)); |
731 mWidgets.at(j)->visual()->setGeometry(calculatedRects.at(i)); |
713 mWidgets.at(j)->visual()->setGeometry(calculatedRects.at(i)); |
732 mWidgets.at(j)->savePresentation(); |
714 mWidgets.at(j)->savePresentation(); |
733 } |
715 } |
734 } |
716 } |
735 #endif //HSWIDGETORGANIZER_ALGORITHM |
|
736 |
|
737 } |
717 } |
738 |
718 |
739 void HsPage::onPageMarginChanged(const QString &value) |
719 void HsPage::onPageMarginChanged(const QString &value) |
740 { |
720 { |
741 if (value == "pageMargin") { |
721 if (value == "pageMargin") { |
756 widget->savePresentation(); |
736 widget->savePresentation(); |
757 } |
737 } |
758 } |
738 } |
759 } |
739 } |
760 } |
740 } |
761 #ifdef HSWIDGETORGANIZER_ALGORITHM |
|
762 // TODO: sorting should be done in algorithm class, make widget<->rect mapping here and move sortWidgets function to algorithm side |
|
763 /*! |
|
764 Sorts widgets in height/width order |
|
765 */ |
|
766 void HsPage::sortWidgets(sortOrder order, QList<HsWidgetHost*> &widgets) |
|
767 { |
|
768 QList<HsWidgetHost*> tmpWidgets; |
|
769 |
|
770 for ( int i = 0; i < widgets.count(); i++) { |
|
771 int index = 0; |
|
772 // add first widget to sorted list |
|
773 if (i == 0) { |
|
774 tmpWidgets << widgets.at(i); |
|
775 } else { |
|
776 // go through existing widgets in the sorted list |
|
777 for ( int j = 0; j < tmpWidgets.count(); j++) { |
|
778 // sort widgets in height order |
|
779 if (order == height) { |
|
780 /* if widgets heigth is smaller on already |
|
781 existing ones in the list -> increment index |
|
782 */ |
|
783 if (widgets.at(i)->visual()->preferredHeight() <= tmpWidgets.at(j)->visual()->preferredHeight()) { |
|
784 index++; |
|
785 } |
|
786 // sort widgets in width order |
|
787 } else { |
|
788 /* if widgets width is smaller on already |
|
789 existing ones in the sorted list -> increment index |
|
790 */ |
|
791 if (widgets.at(i)->visual()->preferredWidth() <= tmpWidgets.at(j)->visual()->preferredWidth()) { |
|
792 index++; |
|
793 } |
|
794 } |
|
795 } |
|
796 // add widget to its correct index in sorted list |
|
797 tmpWidgets.insert(index, widgets.at(i)); |
|
798 } |
|
799 } |
|
800 widgets = tmpWidgets; |
|
801 } |
|
802 #endif //HSWIDGETORGANIZER_ALGORITHM |
|