|
| 1 | +/* |
| 2 | + splitterwidgetcontainer.cpp |
| 3 | +
|
| 4 | + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. |
| 5 | +
|
| 6 | + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] |
| 7 | + Author: Lova Widmark <[email protected]> |
| 8 | +
|
| 9 | + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in |
| 10 | + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. |
| 11 | +
|
| 12 | + Contact [email protected] if any conditions of this licensing are not clear to you. |
| 13 | +
|
| 14 | + This program is free software; you can redistribute it and/or modify |
| 15 | + it under the terms of the GNU General Public License as published by |
| 16 | + the Free Software Foundation, either version 2 of the License, or |
| 17 | + (at your option) any later version. |
| 18 | +
|
| 19 | + This program is distributed in the hope that it will be useful, |
| 20 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | + GNU General Public License for more details. |
| 23 | +
|
| 24 | + You should have received a copy of the GNU General Public License |
| 25 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 | +*/ |
| 27 | + |
| 28 | +#include "splitterwidgetcontainer_p.h" |
| 29 | + |
| 30 | +#include "declarativesplitter_p.h" |
| 31 | + |
| 32 | +#include <QSplitter> |
| 33 | +#include <QQmlInfo> |
| 34 | +#include <QQmlEngine> |
| 35 | + |
| 36 | +SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent) |
| 37 | + : DefaultWidgetContainer(qobject_cast<QSplitter*>(parent)) |
| 38 | +{ |
| 39 | + Q_ASSERT(m_widget); |
| 40 | +} |
| 41 | + |
| 42 | +void SplitterWidgetContainer::setLayout(QLayout *layout) |
| 43 | +{ |
| 44 | + Q_UNUSED(layout); |
| 45 | + qmlInfo(m_widget) << "Can not set a Layout to a Splitter"; |
| 46 | +} |
| 47 | + |
| 48 | +void SplitterWidgetContainer::addWidget(QWidget *widget) |
| 49 | +{ |
| 50 | + QObject *attachedProperties = qmlAttachedPropertiesObject<QSplitter>(widget, false); |
| 51 | + DeclarativeSplitterAttached *properties = qobject_cast<DeclarativeSplitterAttached*>(attachedProperties); |
| 52 | + if (properties) { |
| 53 | + QSizePolicy policy = widget->sizePolicy(); |
| 54 | + policy.setHorizontalStretch(properties->stretch()); |
| 55 | + policy.setVerticalStretch(properties->stretch()); |
| 56 | + widget->setSizePolicy(policy); |
| 57 | + } |
| 58 | + |
| 59 | + extendedSplitter()->addWidget(widget); |
| 60 | +} |
| 61 | + |
| 62 | +QSplitter *SplitterWidgetContainer::extendedSplitter() const |
| 63 | +{ |
| 64 | + return static_cast<QSplitter*>(m_widget); |
| 65 | +} |
0 commit comments