Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Splitter #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/declarativewidgets_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "menubarwidgetcontainer_p.h"
#include "menuwidgetcontainer_p.h"
#include "scrollareawidgetcontainer_p.h"
#include "splitterwidgetcontainer_p.h"
#include "stackedwidgetwidgetcontainer_p.h"
#include "toolbarwidgetcontainer_p.h"

Expand Down Expand Up @@ -98,6 +99,7 @@
#include <QScrollBar>
#include <QStackedWidget>
#include <QStringListModel>
#include <QSplitter>
#include <QTableView>
#include <QTextBrowser>
#include <QTimer>
Expand Down Expand Up @@ -206,4 +208,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri)
qmlRegisterExtendedType<QWebEngineView, DeclarativeWidgetExtension>(uri, 1, 0, "WebEngineView");
#endif
qmlRegisterExtendedType<QWidget, DeclarativeWidgetExtension>(uri, 1, 0, "Widget");
qmlRegisterExtendedType<QSplitter, DeclarativeContainerWidgetExtension<SplitterWidgetContainer>>(uri, 1, 0, "Splitter");
}
53 changes: 53 additions & 0 deletions src/splitterwidgetcontainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
splitterwidgetcontainer.cpp

This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.

Copyright (C) 2013-2018 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 <QQmlInfo>
#include <QSplitter>

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)
{
extendedSplitter()->addWidget(widget);
}

QSplitter *SplitterWidgetContainer::extendedSplitter() const
{
return static_cast<QSplitter*>(m_widget);
}
52 changes: 52 additions & 0 deletions src/splitterwidgetcontainer_p.h
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-2018 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
6 changes: 4 additions & 2 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ HEADERS = \
staticdialogmethodattached_p.h \
toolbarwidgetcontainer_p.h \
widgetcontainerinterface_p.h \
declarativesizepolicy_p.h
declarativesizepolicy_p.h \
splitterwidgetcontainer_p.h

SOURCES = \
abstractdeclarativeobject.cpp \
Expand Down Expand Up @@ -137,4 +138,5 @@ SOURCES = \
stackedwidgetwidgetcontainer.cpp \
staticdialogmethodattached.cpp \
toolbarwidgetcontainer.cpp \
declarativesizepolicy.cpp
declarativesizepolicy.cpp \
splitterwidgetcontainer.cpp
1 change: 1 addition & 0 deletions tests/auto/instantiatetypes/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@
<file>qml/uncreatable/ItemSelectionModel.qml</file>
<file>qml/uncreatable/TextDocument.qml</file>
<file>qml/creatable/webenginewidgets/WebEngineView.qml</file>
<file>qml/creatable/widgets/Splitter.qml</file>
</qresource>
</RCC>
32 changes: 32 additions & 0 deletions tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml
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) 2018 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 {

}
9 changes: 6 additions & 3 deletions tests/auto/layouts/layouts.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ SOURCES += tst_layouts.cpp \
formlayoutwidget.cpp \
gridlayoutwidget.cpp \
stackedlayoutwidget.cpp \
stackedwidget.cpp
stackedwidget.cpp \
splitter.cpp

RESOURCES += \
qml.qrc
Expand All @@ -16,12 +17,14 @@ FORMS += \
vboxlayout.ui \
formlayout.ui \
gridlayout.ui \
stackedwidget.ui
stackedwidget.ui \
splitter.ui

HEADERS += \
hboxlayoutwidget.h \
vboxlayoutwidget.h \
formlayoutwidget.h \
gridlayoutwidget.h \
stackedlayoutwidget.h \
stackedwidget.h
stackedwidget.h \
splitter.h
1 change: 1 addition & 0 deletions tests/auto/layouts/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<file>qml/GridLayoutTest.qml</file>
<file>qml/StackedLayoutTest.qml</file>
<file>qml/StackedWidgetTest.qml</file>
<file>qml/SplitterTest.qml</file>
</qresource>
</RCC>
37 changes: 37 additions & 0 deletions tests/auto/layouts/qml/SplitterTest.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
SplitterTest.qml

This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.

Copyright (C) 2018 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 {
Label {
text: "Label 1"
}
Label {
text: "Label 2"
}
}
42 changes: 42 additions & 0 deletions tests/auto/layouts/splitter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
splitter.cpp

This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.

Copyright (C) 2018 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 "splitter.h"

#include "ui_splitter.h"

Splitter::Splitter(QWidget *parent)
: QSplitter(parent)
, ui(new Ui::Splitter)
{
ui->setupUi(this);
}

Splitter::~Splitter()
{
delete ui;
}
52 changes: 52 additions & 0 deletions tests/auto/layouts/splitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
splitter.h

This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.

Copyright (C) 2018 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 SPLITTER_H
#define SPLITTER_H

#include <QSplitter>

QT_BEGIN_NAMESPACE
namespace Ui
{
class Splitter;
}
QT_END_NAMESPACE

class Splitter : public QSplitter
{
Q_OBJECT

public:
explicit Splitter(QWidget *parent = Q_NULLPTR);
~Splitter();

private:
Ui::Splitter *ui;
};

#endif // SPLITTER_H
18 changes: 18 additions & 0 deletions tests/auto/layouts/splitter.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Splitter</class>
<widget class="QSplitter" name="Splitter">
<widget class="QLabel" name="label">
<property name="text">
<string>Label 1</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Label 2</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Loading