From 22d09b8c58f42a260d05bb7781f59d05c5fb56e5 Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Mon, 21 Jan 2013 20:52:39 +0100 Subject: [PATCH] Ported scroll area --- lib/declarativescrollarea.cpp | 47 --------------------------- lib/declarativescrollarea_p.h | 40 ----------------------- lib/declarativescrollareaextension.cpp | 54 ++++++++++++++++++++++++++++++++ lib/declarativescrollareaextension_p.h | 47 +++++++++++++++++++++++++++ lib/declarativewidgetsdocument.cpp | 4 +- lib/lib.pro | 4 +- 6 files changed, 105 insertions(+), 91 deletions(-) delete mode 100644 lib/declarativescrollarea.cpp delete mode 100644 lib/declarativescrollarea_p.h create mode 100644 lib/declarativescrollareaextension.cpp create mode 100644 lib/declarativescrollareaextension_p.h diff --git a/lib/declarativescrollarea.cpp b/lib/declarativescrollarea.cpp deleted file mode 100644 index e59ad36..0000000 --- a/lib/declarativescrollarea.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Krammer, krake@kdab.com - Author: Tobias Koenig, tokoe@kdab.com - - 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, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "declarativescrollarea_p.h" - -DeclarativeScrollArea::DeclarativeScrollArea(QObject *parent) - : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeScrollArea::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - if (m_proxiedObject->widget()) { - qmlInfo(declarativeObject) << "Can not add multiple Widgets to ScrollArea"; - } else { - m_proxiedObject->setWidget(widget); - } - - m_children.append(declarativeObject); -} - -void DeclarativeScrollArea::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not add Layout to ScrollArea"; -} - -CUSTOM_METAOBJECT(DeclarativeScrollArea, QScrollArea) diff --git a/lib/declarativescrollarea_p.h b/lib/declarativescrollarea_p.h deleted file mode 100644 index c75de57..0000000 --- a/lib/declarativescrollarea_p.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Krammer, krake@kdab.com - Author: Tobias Koenig, tokoe@kdab.com - - 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, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef DECLARATIVESCROLLAREA_P_H -#define DECLARATIVESCROLLAREA_P_H - -#include "declarativewidgetproxy_p.h" - -#include - -class DeclarativeScrollArea : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - explicit DeclarativeScrollArea(QObject *parent = 0); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -#endif diff --git a/lib/declarativescrollareaextension.cpp b/lib/declarativescrollareaextension.cpp new file mode 100644 index 0000000..e03af76 --- /dev/null +++ b/lib/declarativescrollareaextension.cpp @@ -0,0 +1,54 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativescrollareaextension_p.h" + +#include +#include + +DeclarativeScrollAreaExtension::DeclarativeScrollAreaExtension(QObject *parent) + : DeclarativeWidgetExtension(parent) +{ +} + +QScrollArea *DeclarativeScrollAreaExtension::extendedScrollArea() const +{ + QScrollArea *scrollArea = qobject_cast(extendedWidget()); + Q_ASSERT(scrollArea); + + return scrollArea; +} + +void DeclarativeScrollAreaExtension::addWidget(QWidget *widget) +{ + QScrollArea *scrollArea = extendedScrollArea(); + + if (scrollArea->widget()) { + qmlInfo(scrollArea) << "Can not add multiple Widgets to ScrollArea"; + } else { + scrollArea->setWidget(widget); + } +} + +void DeclarativeScrollAreaExtension::setLayout(QLayout *layout) +{ + Q_UNUSED(layout); + qmlInfo(extendedScrollArea()) << "Can not add Layout to ScrollArea"; +} diff --git a/lib/declarativescrollareaextension_p.h b/lib/declarativescrollareaextension_p.h new file mode 100644 index 0000000..cc33c1c --- /dev/null +++ b/lib/declarativescrollareaextension_p.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESCROLLAREAEXTENSION_P_H +#define DECLARATIVESCROLLAREAEXTENSION_P_H + +#include "declarativewidgetextension.h" + +class QScrollArea; + +class DeclarativeScrollAreaExtension : public DeclarativeWidgetExtension +{ + Q_OBJECT + + // repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class + Q_PROPERTY(QDeclarativeListProperty data READ data DESIGNABLE false) + + Q_CLASSINFO("DefaultProperty", "data") + + public: + explicit DeclarativeScrollAreaExtension(QObject *parent = 0); + + QScrollArea *extendedScrollArea() const; + + protected: + void addWidget(QWidget *widget); + void setLayout(QLayout *layout); +}; + +#endif diff --git a/lib/declarativewidgetsdocument.cpp b/lib/declarativewidgetsdocument.cpp index 95005c4..aaa7f74 100644 --- a/lib/declarativewidgetsdocument.cpp +++ b/lib/declarativewidgetsdocument.cpp @@ -47,7 +47,7 @@ #include "declarativemessagebox_p.h" #include "declarativeplaintextedit_p.h" #include "declarativeprogressbar_p.h" -#include "declarativescrollarea_p.h" +#include "declarativescrollareaextension_p.h" #include "declarativescrollbar_p.h" #include "declarativeseparator_p.h" #include "declarativespinbox_p.h" @@ -121,7 +121,6 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject qmlRegisterType("QtGui", 1, 0, "LCDNumber"); qmlRegisterType("QtGui", 1, 0, "PlainTextEdit"); qmlRegisterType("QtGui", 1, 0, "ProgressBar"); - qmlRegisterType("QtGui", 1, 0, "ScrollArea"); qmlRegisterType("QtGui", 1, 0, "ScrollBar"); qmlRegisterType("QtGui", 1, 0, "SpinBox"); qmlRegisterType("QtGui", 1, 0, "StackedWidget"); @@ -169,6 +168,7 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject qmlRegisterExtendedType("QtGui", 1, 0, "MessageBox"); qmlRegisterExtendedType("QtGui", 1, 0, "PushButton"); qmlRegisterExtendedType("QtGui", 1, 0, "RadioButton"); + qmlRegisterExtendedType("QtGui", 1, 0, "ScrollArea"); qmlRegisterExtendedType("QtGui", 1, 0, "Slider"); qmlRegisterExtendedType("QtGui", 1, 0, "StatusBar"); qmlRegisterExtendedType("QtGui", 1, 0, "TableView"); diff --git a/lib/lib.pro b/lib/lib.pro index f277dcf..d490438 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -37,7 +37,7 @@ HEADERS = \ declarativeobjectproxy_p.h \ declarativeplaintextedit_p.h \ declarativeprogressbar_p.h \ - declarativescrollarea_p.h \ + declarativescrollareaextension_p.h \ declarativescrollbar_p.h \ declarativeseparator_p.h \ declarativespinbox_p.h \ @@ -88,7 +88,7 @@ SOURCES = \ declarativeobjectextension.cpp \ declarativeplaintextedit.cpp \ declarativeprogressbar.cpp \ - declarativescrollarea.cpp \ + declarativescrollareaextension.cpp \ declarativescrollbar.cpp \ declarativeseparator.cpp \ declarativespinbox.cpp \ -- 1.7.2.5