summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicslayout_p.cpp
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /src/gui/graphicsview/qgraphicslayout_p.cpp
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/gui/graphicsview/qgraphicslayout_p.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicslayout_p.cpp198
1 files changed, 198 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicslayout_p.cpp b/src/gui/graphicsview/qgraphicslayout_p.cpp
new file mode 100644
index 0000000000..c325602cc6
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicslayout_p.cpp
@@ -0,0 +1,198 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qglobal.h"
+
+#ifndef QT_NO_GRAPHICSVIEW
+
+#include "qgraphicslayout_p.h"
+#include "qgraphicslayout.h"
+#include "qgraphicswidget.h"
+#include "qapplication.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+
+ \a mw is the new parent. all items in the layout will be a child of \a mw.
+ */
+void QGraphicsLayoutPrivate::reparentChildItems(QGraphicsItem *newParent)
+{
+ Q_Q(QGraphicsLayout);
+ int n = q->count();
+ //bool mwVisible = mw && mw->isVisible();
+ for (int i = 0; i < n; ++i) {
+ QGraphicsLayoutItem *layoutChild = q->itemAt(i);
+ if (!layoutChild) {
+ // Skip stretch items
+ continue;
+ }
+ if (layoutChild->isLayout()) {
+ QGraphicsLayout *l = static_cast<QGraphicsLayout*>(layoutChild);
+ l->d_func()->reparentChildItems(newParent);
+ } else if (QGraphicsItem *itemChild = layoutChild->graphicsItem()){
+ QGraphicsItem *childParent = itemChild->parentItem();
+#ifdef QT_DEBUG
+ if (childParent && childParent != newParent && itemChild->isWidget() && qt_graphicsLayoutDebug()) {
+ QGraphicsWidget *w = static_cast<QGraphicsWidget*>(layoutChild);
+ qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent",
+ w->metaObject()->className(), w->objectName().toLocal8Bit().constData());
+ }
+#endif
+ if (childParent != newParent)
+ itemChild->setParentItem(newParent);
+ }
+ }
+}
+
+void QGraphicsLayoutPrivate::getMargin(qreal *result, qreal userMargin, QStyle::PixelMetric pm) const
+{
+ if (!result)
+ return;
+ Q_Q(const QGraphicsLayout);
+
+ QGraphicsLayoutItem *parent = q->parentLayoutItem();
+ if (userMargin >= 0.0) {
+ *result = userMargin;
+ } else if (!parent) {
+ *result = 0.0;
+ } else if (parent->isLayout()) { // sublayouts have 0 margin by default
+ *result = 0.0;
+ } else {
+ *result = 0.0;
+ if (QGraphicsItem *layoutParentItem = parentItem()) {
+ if (layoutParentItem->isWidget())
+ *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, 0);
+ }
+ }
+}
+
+Qt::LayoutDirection QGraphicsLayoutPrivate::visualDirection() const
+{
+ if (QGraphicsItem *maybeWidget = parentItem()) {
+ if (maybeWidget->isWidget())
+ return static_cast<QGraphicsWidget*>(maybeWidget)->layoutDirection();
+ }
+ return QApplication::layoutDirection();
+}
+
+static bool removeLayoutItemFromLayout(QGraphicsLayout *lay, QGraphicsLayoutItem *layoutItem)
+{
+ if (!lay)
+ return false;
+
+ for (int i = lay->count() - 1; i >= 0; --i) {
+ QGraphicsLayoutItem *child = lay->itemAt(i);
+ if (child && child->isLayout()) {
+ if (removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(child), layoutItem))
+ return true;
+ } else if (child == layoutItem) {
+ lay->removeAt(i);
+ return true;
+ }
+ }
+ return false;
+}
+
+/*!
+ \internal
+
+ This function is called from subclasses to add a layout item \a layoutItem
+ to a layout.
+
+ It takes care of automatically reparenting graphics items, if needed.
+
+ If \a layoutItem is a is already in a layout, it will remove it from that layout.
+
+*/
+void QGraphicsLayoutPrivate::addChildLayoutItem(QGraphicsLayoutItem *layoutItem)
+{
+ Q_Q(QGraphicsLayout);
+ if (QGraphicsLayoutItem *maybeLayout = layoutItem->parentLayoutItem()) {
+ if (maybeLayout->isLayout())
+ removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(maybeLayout), layoutItem);
+ }
+ layoutItem->setParentLayoutItem(q);
+ if (layoutItem->isLayout()) {
+ if (QGraphicsItem *parItem = parentItem()) {
+ static_cast<QGraphicsLayout*>(layoutItem)->d_func()->reparentChildItems(parItem);
+ }
+ } else {
+ if (QGraphicsItem *item = layoutItem->graphicsItem()) {
+ QGraphicsItem *newParent = parentItem();
+ QGraphicsItem *oldParent = item->parentItem();
+ if (oldParent == newParent || !newParent)
+ return;
+
+#ifdef QT_DEBUG
+ if (oldParent && item->isWidget()) {
+ QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item);
+ qWarning("QGraphicsLayout::addChildLayoutItem: %s \"%s\" in wrong parent; moved to correct parent",
+ w->metaObject()->className(), w->objectName().toLocal8Bit().constData());
+ }
+#endif
+
+ item->setParentItem(newParent);
+ }
+ }
+}
+
+void QGraphicsLayoutPrivate::activateRecursive(QGraphicsLayoutItem *item)
+{
+ if (item->isLayout()) {
+ QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(item);
+ if (layout->d_func()->activated)
+ layout->invalidate();
+
+ for (int i = layout->count() - 1; i >= 0; --i) {
+ QGraphicsLayoutItem *childItem = layout->itemAt(i);
+ if (childItem)
+ activateRecursive(childItem);
+ }
+ layout->d_func()->activated = true;
+ }
+}
+
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_GRAPHICSVIEW