This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
323 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
declarativesplitter.cpp | ||
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. | ||
Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
Author: Lova Widmark <[email protected]> | ||
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in | ||
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. | ||
Contact [email protected] if any conditions of this licensing are not clear to you. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "declarativesplitter_p.h" | ||
|
||
#include <QPointer> | ||
#include <QWidget> | ||
#include <QQmlInfo> | ||
|
||
class DeclarativeSplitterAttached::Private | ||
{ | ||
public: | ||
Private(QWidget *w) | ||
: stretch(0) | ||
, widget(w) | ||
{ | ||
} | ||
|
||
int stretch; | ||
|
||
QPointer<QWidget> widget; | ||
}; | ||
|
||
DeclarativeSplitterAttached::DeclarativeSplitterAttached(QWidget *widget, QObject *parent) | ||
: QObject(parent) | ||
, d(new Private(widget)) | ||
{ | ||
} | ||
|
||
DeclarativeSplitterAttached::~DeclarativeSplitterAttached() | ||
{ | ||
delete d; | ||
} | ||
|
||
void DeclarativeSplitterAttached::setStretch(int stretch) | ||
{ | ||
if (stretch == d->stretch) | ||
return; | ||
|
||
d->stretch = stretch; | ||
|
||
emit stretchChanged(stretch); | ||
} | ||
|
||
int DeclarativeSplitterAttached::stretch() const | ||
{ | ||
return d->stretch; | ||
} | ||
|
||
DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) | ||
: QSplitter(parent) | ||
{ | ||
} | ||
|
||
DeclarativeSplitterAttached *DeclarativeSplitter::qmlAttachedProperties(QObject *parent) | ||
{ | ||
QWidget *widget = qobject_cast<QWidget*>(parent); | ||
if (widget) | ||
return new DeclarativeSplitterAttached(widget, parent); | ||
|
||
qmlInfo(parent) << "Can only attach Splitter to widgets"; | ||
|
||
return Q_NULLPTR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
declarativesplitter_p.h | ||
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. | ||
Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
Author: Lova Widmark <[email protected]> | ||
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in | ||
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. | ||
Contact [email protected] if any conditions of this licensing are not clear to you. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef DECLARATIVESPLITTER_P_H | ||
#define DECLARATIVESPLITTER_P_H | ||
|
||
#include <QtGlobal> | ||
#include <QObject> | ||
#include <QSplitter> | ||
#include <QtQml> | ||
|
||
class DeclarativeSplitterAttached : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) | ||
|
||
public: | ||
DeclarativeSplitterAttached(QWidget *widget, QObject *parent); | ||
~DeclarativeSplitterAttached(); | ||
|
||
void setStretch(int stretch); | ||
int stretch() const; | ||
|
||
Q_SIGNALS: | ||
void stretchChanged(int stretch); | ||
|
||
private: | ||
class Private; | ||
Private *const d; | ||
}; | ||
|
||
class DeclarativeSplitter : public QSplitter | ||
{ | ||
public: | ||
DeclarativeSplitter(QWidget *parent = Q_NULLPTR); | ||
|
||
static DeclarativeSplitterAttached *qmlAttachedProperties(QObject *parent); | ||
}; | ||
|
||
QML_DECLARE_TYPEINFO(DeclarativeSplitter, QML_HAS_ATTACHED_PROPERTIES) | ||
|
||
#endif // DECLARATIVESPLITTER_P_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
splitterwidgetcontainer.cpp | ||
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. | ||
Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
Author: Lova Widmark <[email protected]> | ||
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in | ||
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. | ||
Contact [email protected] if any conditions of this licensing are not clear to you. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "splitterwidgetcontainer_p.h" | ||
|
||
#include "declarativesplitter_p.h" | ||
|
||
#include <QSplitter> | ||
#include <QQmlInfo> | ||
#include <QQmlEngine> | ||
|
||
SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent) | ||
: DefaultWidgetContainer(qobject_cast<QSplitter*>(parent)) | ||
{ | ||
Q_ASSERT(m_widget); | ||
} | ||
|
||
void SplitterWidgetContainer::setLayout(QLayout *layout) | ||
{ | ||
Q_UNUSED(layout); | ||
qmlInfo(m_widget) << "Can not set a Layout to a Splitter"; | ||
} | ||
|
||
void SplitterWidgetContainer::addWidget(QWidget *widget) | ||
{ | ||
QObject *attachedProperties = qmlAttachedPropertiesObject<QSplitter>(widget, false); | ||
DeclarativeSplitterAttached *properties = qobject_cast<DeclarativeSplitterAttached*>(attachedProperties); | ||
if (properties) { | ||
QSizePolicy policy = widget->sizePolicy(); | ||
policy.setHorizontalStretch(properties->stretch()); | ||
policy.setVerticalStretch(properties->stretch()); | ||
widget->setSizePolicy(policy); | ||
} | ||
|
||
extendedSplitter()->addWidget(widget); | ||
} | ||
|
||
QSplitter *SplitterWidgetContainer::extendedSplitter() const | ||
{ | ||
return static_cast<QSplitter*>(m_widget); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
splitterwidgetcontainer_p.h | ||
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. | ||
Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
Author: Lova Widmark <[email protected]> | ||
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in | ||
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. | ||
Contact [email protected] if any conditions of this licensing are not clear to you. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef SPLITTERWIDGETCONTAINER_P_H | ||
#define SPLITTERWIDGETCONTAINER_P_H | ||
|
||
#include <QtGlobal> | ||
|
||
#include "defaultwidgetcontainer.h" | ||
|
||
QT_BEGIN_NAMESPACE | ||
class QSplitter; | ||
class QObject; | ||
QT_END_NAMESPACE | ||
|
||
class SplitterWidgetContainer : public DefaultWidgetContainer | ||
{ | ||
public: | ||
explicit SplitterWidgetContainer(QObject *parent = Q_NULLPTR); | ||
|
||
void setLayout(QLayout *layout) Q_DECL_OVERRIDE; | ||
void addWidget(QWidget *widget) Q_DECL_OVERRIDE; | ||
|
||
private: | ||
QSplitter *extendedSplitter() const; | ||
}; | ||
|
||
#endif // SPLITTERWIDGETCONTAINER_P_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Splitter.qml | ||
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. | ||
Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
Author: Lova Widmark <[email protected]> | ||
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in | ||
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. | ||
Contact [email protected] if any conditions of this licensing are not clear to you. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import QtWidgets 1.0 | ||
|
||
Splitter { | ||
|
||
} |