diff options
Diffstat (limited to 'src/corelib/layout')
-rw-r--r-- | src/corelib/layout/mgridlayoutpolicy_p.cpp | 3 | ||||
-rw-r--r-- | src/corelib/layout/mlinearlayoutpolicy_p.cpp | 104 | ||||
-rw-r--r-- | src/corelib/layout/mlinearlayoutpolicy_p.h | 2 |
3 files changed, 44 insertions, 65 deletions
diff --git a/src/corelib/layout/mgridlayoutpolicy_p.cpp b/src/corelib/layout/mgridlayoutpolicy_p.cpp index b9b61efd..5217dce3 100644 --- a/src/corelib/layout/mgridlayoutpolicy_p.cpp +++ b/src/corelib/layout/mgridlayoutpolicy_p.cpp @@ -27,9 +27,6 @@ MGridLayoutPolicyPrivate::MGridLayoutPolicyPrivate(MLayout *l) : MAbstractLayoutPolicyPrivate(l), engineWidget(new QGraphicsWidget), engine(new QGraphicsGridLayout(engineWidget)) { - engineWidget->setContentsMargins(0, 0, 0, 0); - engineWidget->setMinimumSize(0, 0); - engineWidget->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); } MGridLayoutPolicyPrivate::~MGridLayoutPolicyPrivate() diff --git a/src/corelib/layout/mlinearlayoutpolicy_p.cpp b/src/corelib/layout/mlinearlayoutpolicy_p.cpp index 7d154337..29e2ee63 100644 --- a/src/corelib/layout/mlinearlayoutpolicy_p.cpp +++ b/src/corelib/layout/mlinearlayoutpolicy_p.cpp @@ -28,20 +28,17 @@ #include "mlayout.h" #include "mlayouthelper_p.h" MLinearLayoutPolicyPrivate::MLinearLayoutPolicyPrivate(MLayout *layout, Qt::Orientation orientation) : - MAbstractLayoutPolicyPrivate(layout), - engineWidget(new QGraphicsWidget), - engine(new QGraphicsLinearLayout(orientation, engineWidget)), + MAbstractLayoutPolicyPrivate(layout), + engineWidget(new QGraphicsWidget), + engine(new QGraphicsLinearLayout(orientation, engineWidget)), + rowCount(0), notifyWidgetsOfLayoutPositionEnabled(false) { - rowCount = 0; - engineWidget->setContentsMargins(0, 0, 0, 0); - engineWidget->setMinimumSize(0, 0); - engineWidget->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); } MLinearLayoutPolicyPrivate::~MLinearLayoutPolicyPrivate() { - delete engineWidget; //This deletes the engine, which in turn deletes all of its children + delete engineWidget; //This deletes the engine, which in turn deletes all of its proxy children (they are setOwnedByLayout(true)) } void MLinearLayoutPolicyPrivate::fixIndex(int *index) const @@ -85,109 +82,94 @@ void MLinearLayoutPolicyPrivate::refreshWidget() void MLinearLayoutPolicyPrivate::notifyWidgetOfLayoutPosition(int index, M::Position position) { MWidgetController* widget = dynamic_cast<MWidgetController*>(static_cast<ProxyItem *>(engine->itemAt(index))->proxiedItem()); - if( widget ) { + if (widget) widget->setLayoutPosition(position); - } } -void MLinearLayoutPolicyPrivate::notifyAffectedWidgetsOfLayoutPosition(int index, bool add ) +void MLinearLayoutPolicyPrivate::notifyAffectedWidgetsOfLayoutPosition(int index, bool add) { - if( !notifyWidgetsOfLayoutPositionEnabled ) + if (!notifyWidgetsOfLayoutPositionEnabled) return; - - //setup first, last and center positions based on layout direction (LTR or RTL) and orientation (VERT or HORIZ) + + //setup first, last and center positions based on layout direction (LTR or RTL) and orientation (VERT or HORIZ) M::Position first, last; - if( layout->layoutDirection() == Qt::LeftToRight ) { + if (layout->layoutDirection() == Qt::LeftToRight) { first = (engine->orientation() == Qt::Horizontal) ? M::HorizontalLeftPosition : M::VerticalTopPosition; last = (engine->orientation() == Qt::Horizontal) ? M::HorizontalRightPosition : M::VerticalBottomPosition; - } - else { + } else { first = (engine->orientation() == Qt::Horizontal) ? M::HorizontalRightPosition : M::VerticalTopPosition; last = (engine->orientation() == Qt::Horizontal) ? M::HorizontalLeftPosition : M::VerticalBottomPosition; } M::Position center = (engine->orientation() == Qt::Horizontal) ? M::HorizontalCenterPosition : M::VerticalCenterPosition; //added to index - if( add ) { + if (add) { //no more than three items in the layout, reposition them all - if( engine->count() <= 3 ) + if (engine->count() <= 3) { notifyAllWidgetsOfLayoutPosition(); - else { - //added as first - if( index == 0 ) { + } else { + if (index == 0) { + //added as first notifyWidgetOfLayoutPosition(0, first); notifyWidgetOfLayoutPosition(1, center); - } - //added as last - else if( index >= engine->count() - 1 ) { + } else if (index >= engine->count() - 1) { + //added as last notifyWidgetOfLayoutPosition(engine->count()-2, center); notifyWidgetOfLayoutPosition(engine->count()-1, last); - } - //added to middle - else { + } else { + //added to middle notifyWidgetOfLayoutPosition(index, center); } } - } - //removing item from index - else { + } else { + //removing item from index //remove positioning from the removed item notifyWidgetOfLayoutPosition(index, M::DefaultPosition); //change positioning of an affected item if item is removed from first or last position - if( engine->count()-1 > 0 ) { - //only one item remains after removal - if( engine->count()-1 == 1 ) { + if (engine->count()-1 > 0) { + if (engine->count() == 2) { + //only one item remains after removal notifyWidgetOfLayoutPosition((index == 0) ? 1 : 0, M::DefaultPosition); - } - else { - //item is removed from first position, mark second item as first - if( index == 0 ) { - notifyWidgetOfLayoutPosition(1, first); - } - //item is removed from last position, mark second last item as last - else if( index == engine->count()-1 ) { - notifyWidgetOfLayoutPosition(engine->count()-2, last); - } + } else if (index == 0) { + notifyWidgetOfLayoutPosition(1, first); + } else if (index == engine->count()-1) { + notifyWidgetOfLayoutPosition(engine->count()-2, last); } } } - - } void MLinearLayoutPolicyPrivate::notifyAllWidgetsOfLayoutPosition() { - if( notifyWidgetsOfLayoutPositionEnabled ) { - //setup first, last and center positions based on layout direction (LTR or RTL) and orientation (VERT or HORIZ) + if (notifyWidgetsOfLayoutPositionEnabled) { + //setup first, last and center positions based on layout direction (LTR or RTL) and orientation (VERT or HORIZ) M::Position first, last; - if( layout->layoutDirection() == Qt::LeftToRight ) { + if (layout->layoutDirection() == Qt::LeftToRight) { first = (engine->orientation() == Qt::Horizontal) ? M::HorizontalLeftPosition : M::VerticalTopPosition; last = (engine->orientation() == Qt::Horizontal) ? M::HorizontalRightPosition : M::VerticalBottomPosition; - } - else { + } else { first = (engine->orientation() == Qt::Horizontal) ? M::HorizontalRightPosition : M::VerticalTopPosition; last = (engine->orientation() == Qt::Horizontal) ? M::HorizontalLeftPosition : M::VerticalBottomPosition; } M::Position center = (engine->orientation() == Qt::Horizontal) ? M::HorizontalCenterPosition : M::VerticalCenterPosition;; - - //only one item in the layout - if( engine->count() == 1 ) { + if (engine->count() == 1) { + //only one item in the layout notifyWidgetOfLayoutPosition(0, M::DefaultPosition); - //more than one item in the layout - } else if( engine->count() > 1 ){ + } else if (engine->count() > 1) { + //more than one item in the layout notifyWidgetOfLayoutPosition(0, first); notifyWidgetOfLayoutPosition(engine->count()-1, last); - for( int i = 1; i < engine->count()-1; ++i ) { - notifyWidgetOfLayoutPosition(i, center); - } + for (int i = 1; i < engine->count()-1; ++i) { + notifyWidgetOfLayoutPosition(i, center); + } } //remove positioning from all the items } else { - for( int i = 0; i < engine->count(); ++i ) { + for (int i = 0; i < engine->count(); ++i) { notifyWidgetOfLayoutPosition(i, M::DefaultPosition); - } + } } } diff --git a/src/corelib/layout/mlinearlayoutpolicy_p.h b/src/corelib/layout/mlinearlayoutpolicy_p.h index 55131dde..3dc59c7c 100644 --- a/src/corelib/layout/mlinearlayoutpolicy_p.h +++ b/src/corelib/layout/mlinearlayoutpolicy_p.h @@ -58,7 +58,7 @@ public: * QGraphicsLinearLayout does not expose this information to us. This is * basically q->count() + the number of stretches added/inserted. */ int rowCount; - + bool notifyWidgetsOfLayoutPositionEnabled; }; |