summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-10-29 20:14:09 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-11-04 23:28:09 (GMT)
commit52d737eb6f4b79cd0c7fc7ee1d041fb19d286a27 (patch)
treef40577f5884947aed6ce480e15bbdf106adb0f89 /src/gui
parent56c04b7f546babf5bbe64a6d0175f635cb2fd204 (diff)
downloadQt-52d737eb6f4b79cd0c7fc7ee1d041fb19d286a27.zip
Qt-52d737eb6f4b79cd0c7fc7ee1d041fb19d286a27.tar.gz
Qt-52d737eb6f4b79cd0c7fc7ee1d041fb19d286a27.tar.bz2
QGAL: Do not create sizeHint constraints for dependent anchors
Some anchors have their sizes linked directly to the size of others. That is the case for instance with center anchors where one half must have exactly the same size as the other. To make that more clear, adding "dependency" info to AnchorData and setting it accordingly. This is future proof in the sense that if someday we are allowed to anchor to other items in terms of percentages, like, anchor to 70% of an items' width, we would also need this notion. Knowing that, we no longer need to create size hint constraints for the slave anchors, only for the master ones. The size of slave anchors is enforced by the dependency constraint (sizeSlave = X * sizeMaster). Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp25
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h10
2 files changed, 25 insertions, 10 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index dbfce74..ad7d657 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -1080,12 +1080,14 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors(
c->variables.insert(data, 1.0);
addAnchor_helper(item, firstEdge, item, centerEdge, data);
data->isCenterAnchor = true;
+ data->dependency = AnchorData::Master;
data->refreshSizeHints(0);
data = new AnchorData;
c->variables.insert(data, -1.0);
addAnchor_helper(item, centerEdge, item, lastEdge, data);
data->isCenterAnchor = true;
+ data->dependency = AnchorData::Slave;
data->refreshSizeHints(0);
itemCenterConstraints[orientation].append(c);
@@ -2075,19 +2077,18 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
// Look for the layout edge. That can be either the first half in case the
// layout is split in two, or the whole layout anchor.
Orientation orient = Orientation(anchors.first()->orientation);
- AnchorData *layoutEdge1 = NULL;
- AnchorData *layoutEdge2 = NULL;
+ AnchorData *layoutEdge = NULL;
if (layoutCentralVertex[orient]) {
- layoutEdge1 = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]);
- layoutEdge2 = graph[orient].edgeData(layoutCentralVertex[orient], layoutLastVertex[orient]);
+ layoutEdge = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]);
} else {
- layoutEdge1 = graph[orient].edgeData(layoutFirstVertex[orient], layoutLastVertex[orient]);
+ layoutEdge = graph[orient].edgeData(layoutFirstVertex[orient], layoutLastVertex[orient]);
+
// If maxSize is less then "infinite", that means there are other anchors
// grouped together with this one. We can't ignore its maximum value so we
// set back the variable to NULL to prevent the continue condition from being
// satisfied in the loop below.
- if (layoutEdge1->maxSize < QWIDGETSIZE_MAX)
- layoutEdge1 = NULL;
+ if (layoutEdge->maxSize < QWIDGETSIZE_MAX)
+ layoutEdge = NULL;
}
// For each variable, create constraints based on size hints
@@ -2096,6 +2097,12 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
for (int i = 0; i < anchors.size(); ++i) {
AnchorData *ad = anchors[i];
+ // Anchors that have their size directly linked to another one don't need constraints
+ // For exammple, the second half of an item has exactly the same size as the first half
+ // thus constraining the latter is enough.
+ if (ad->dependency == AnchorData::Slave)
+ continue;
+
if ((ad->minSize == ad->maxSize) || qFuzzyCompare(ad->minSize, ad->maxSize)) {
QSimplexConstraint *c = new QSimplexConstraint;
c->variables.insert(ad, 1.0);
@@ -2113,7 +2120,7 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
// We avoid adding restrictions to the layout internal anchors. That's
// to prevent unnecessary fair distribution from happening due to this
// artificial restriction.
- if ((ad == layoutEdge1) || (ad == layoutEdge2))
+ if (ad == layoutEdge)
continue;
c = new QSimplexConstraint;
@@ -2128,7 +2135,7 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
// If no upper boundary restriction was added, add one to avoid unbounded problem
if (unboundedProblem) {
QSimplexConstraint *c = new QSimplexConstraint;
- c->variables.insert(layoutEdge1, 1.0);
+ c->variables.insert(layoutEdge, 1.0);
c->constant = QWIDGETSIZE_MAX;
c->ratio = QSimplexConstraint::LessOrEqual;
anchorConstraints += c;
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index 7d7bdb6..2f0237c 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -150,6 +150,12 @@ struct AnchorData : public QSimplexVariable {
Parallel
};
+ enum Dependency {
+ Independent = 0,
+ Master,
+ Slave
+ };
+
AnchorData()
: QSimplexVariable(), item(0), from(0), to(0),
minSize(0), prefSize(0), expSize(0), maxSize(0),
@@ -157,7 +163,8 @@ struct AnchorData : public QSimplexVariable {
sizeAtExpanding(0), sizeAtMaximum(0),
graphicsAnchor(0), skipInPreferred(0),
type(Normal), hasSize(true), isLayoutAnchor(false),
- isCenterAnchor(false), orientation(0) {}
+ isCenterAnchor(false), orientation(0),
+ dependency(Independent) {}
virtual void updateChildrenSizes() {}
virtual bool refreshSizeHints(const QLayoutStyleInfo *styleInfo);
@@ -212,6 +219,7 @@ struct AnchorData : public QSimplexVariable {
uint isLayoutAnchor : 1; // if this anchor is an internal layout anchor
uint isCenterAnchor : 1;
uint orientation : 1;
+ uint dependency : 2; // either Independent, Master or Slave
};
#ifdef QT_DEBUG