diff options
Diffstat (limited to 'src/designer/src/plugins/widgets/q3widgetstack')
6 files changed, 718 insertions, 0 deletions
diff --git a/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_container.cpp b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_container.cpp new file mode 100644 index 000000000..500185da5 --- /dev/null +++ b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_container.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** 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 Qt Designer 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 "q3widgetstack_container.h" +#include "qdesigner_q3widgetstack_p.h" + +#include <QtCore/qdebug.h> + +QT_BEGIN_NAMESPACE + +Q3WidgetStackContainer::Q3WidgetStackContainer(QDesignerQ3WidgetStack *widget, QObject *parent) + : QObject(parent), + m_widget(widget) +{} + +int Q3WidgetStackContainer::count() const +{ return m_pages.count(); } + +QWidget *Q3WidgetStackContainer::widget(int index) const +{ + if (index == -1) + return 0; + + return m_pages.at(index); +} + +int Q3WidgetStackContainer::currentIndex() const +{ return m_pages.indexOf(m_widget->visibleWidget()); } + +void Q3WidgetStackContainer::setCurrentIndex(int index) +{ m_widget->raiseWidget(m_pages.at(index)); } + +void Q3WidgetStackContainer::addWidget(QWidget *widget) +{ + m_pages.append(widget); + m_widget->addWidget(widget); +} + +void Q3WidgetStackContainer::insertWidget(int index, QWidget *widget) +{ + m_pages.insert(index, widget); + m_widget->addWidget(widget); + m_widget->setCurrentIndex(index); +} + +void Q3WidgetStackContainer::remove(int index) +{ + int current = currentIndex(); + m_widget->removeWidget(m_pages.at(index)); + m_pages.removeAt(index); + if (index == current) { + if (count() > 0) + m_widget->setCurrentIndex((index == count()) ? index-1 : index); + } else if (index < current) { + if (current > 0) + m_widget->setCurrentIndex(current-1); + } +} + +Q3WidgetStackContainerFactory::Q3WidgetStackContainerFactory(QExtensionManager *parent) + : QExtensionFactory(parent) +{ +} + +QObject *Q3WidgetStackContainerFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const +{ + if (iid != Q_TYPEID(QDesignerContainerExtension)) + return 0; + + if (QDesignerQ3WidgetStack *w = qobject_cast<QDesignerQ3WidgetStack*>(object)) + return new Q3WidgetStackContainer(w, parent); + + return 0; +} + + +QT_END_NAMESPACE diff --git a/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_container.h b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_container.h new file mode 100644 index 000000000..9c6324de0 --- /dev/null +++ b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_container.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 Qt Designer 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$ +** +****************************************************************************/ + +#ifndef Q3WIDGETSTACK_CONTAINER_H +#define Q3WIDGETSTACK_CONTAINER_H + +#include <QtDesigner/QDesignerContainerExtension> +#include <QtDesigner/QExtensionFactory> + +QT_BEGIN_NAMESPACE + +class QDesignerQ3WidgetStack; + +class Q3WidgetStackContainer: public QObject, public QDesignerContainerExtension +{ + Q_OBJECT + Q_INTERFACES(QDesignerContainerExtension) +public: + explicit Q3WidgetStackContainer(QDesignerQ3WidgetStack *widget, QObject *parent = 0); + + virtual int count() const; + virtual QWidget *widget(int index) const; + virtual int currentIndex() const; + virtual void setCurrentIndex(int index); + virtual void addWidget(QWidget *widget); + virtual void insertWidget(int index, QWidget *widget); + virtual void remove(int index); + +private: + QDesignerQ3WidgetStack *m_widget; + QList<QWidget*> m_pages; +}; + +class Q3WidgetStackContainerFactory: public QExtensionFactory +{ + Q_OBJECT +public: + explicit Q3WidgetStackContainerFactory(QExtensionManager *parent = 0); + +protected: + virtual QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const; +}; + +QT_END_NAMESPACE + +#endif // Q3WIDGETSTACK_CONTAINER_H diff --git a/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_plugin.cpp b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_plugin.cpp new file mode 100644 index 000000000..2fa87cc09 --- /dev/null +++ b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_plugin.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** 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 Qt Designer 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 "q3widgetstack_plugin.h" +#include "q3widgetstack_container.h" + +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/QExtensionManager> + +#include <QtCore/qplugin.h> +#include "qdesigner_q3widgetstack_p.h" + +QT_BEGIN_NAMESPACE + +Q3WidgetStackPlugin::Q3WidgetStackPlugin(const QIcon &icon, QObject *parent) + : QObject(parent), m_initialized(false), m_icon(icon) +{} + +QString Q3WidgetStackPlugin::name() const +{ return QLatin1String("Q3WidgetStack"); } + +QString Q3WidgetStackPlugin::group() const +{ return QLatin1String("Qt 3 Support"); } + +QString Q3WidgetStackPlugin::toolTip() const +{ return QString(); } + +QString Q3WidgetStackPlugin::whatsThis() const +{ return QString(); } + +QString Q3WidgetStackPlugin::includeFile() const +{ return QLatin1String("q3widgetstack.h"); } + +QIcon Q3WidgetStackPlugin::icon() const +{ return m_icon; } + +bool Q3WidgetStackPlugin::isContainer() const +{ return true; } + +QWidget *Q3WidgetStackPlugin::createWidget(QWidget *parent) +{ return new QDesignerQ3WidgetStack(parent); } + +bool Q3WidgetStackPlugin::isInitialized() const +{ return m_initialized; } + +void Q3WidgetStackPlugin::initialize(QDesignerFormEditorInterface *core) +{ + Q_UNUSED(core); + + if (m_initialized) + return; + + m_initialized = true; + QExtensionManager *mgr = core->extensionManager(); + mgr->registerExtensions(new Q3WidgetStackContainerFactory(mgr), Q_TYPEID(QDesignerContainerExtension)); +} + +QString Q3WidgetStackPlugin::codeTemplate() const +{ return QString(); } + +QString Q3WidgetStackPlugin::domXml() const +{ + return QLatin1String("\ +<ui language=\"c++\">\ + <widget class=\"Q3WidgetStack\" name=\"widgetStack\">\ + <property name=\"geometry\">\ + <rect>\ + <x>0</x>\ + <y>0</y>\ + <width>100</width>\ + <height>80</height>\ + </rect>\ + </property>\ + <widget class=\"QWidget\" name=\"page\"/>\ + <widget class=\"QWidget\" name=\"page_2\"/>\ + </widget>\ +</ui>"); +} + +QT_END_NAMESPACE diff --git a/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_plugin.h b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_plugin.h new file mode 100644 index 000000000..0e319c259 --- /dev/null +++ b/src/designer/src/plugins/widgets/q3widgetstack/q3widgetstack_plugin.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 Qt Designer 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$ +** +****************************************************************************/ + +#ifndef Q3WIDGETSTACK_PLUGIN_H +#define Q3WIDGETSTACK_PLUGIN_H + +#include <QtDesigner/QDesignerCustomWidgetInterface> + +QT_BEGIN_NAMESPACE + +class Q3WidgetStackPlugin: public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) +public: + explicit Q3WidgetStackPlugin(const QIcon &icon, QObject *parent = 0); + + virtual QString name() const; + virtual QString group() const; + virtual QString toolTip() const; + virtual QString whatsThis() const; + virtual QString includeFile() const; + virtual QIcon icon() const; + virtual bool isContainer() const; + virtual QWidget *createWidget(QWidget *parent); + virtual bool isInitialized() const; + virtual void initialize(QDesignerFormEditorInterface *core); + virtual QString codeTemplate() const; + virtual QString domXml() const; + +private: + bool m_initialized; + QIcon m_icon; +}; + +QT_END_NAMESPACE + +#endif // Q3WIDGETSTACK_PLUGIN_H diff --git a/src/designer/src/plugins/widgets/q3widgetstack/qdesigner_q3widgetstack.cpp b/src/designer/src/plugins/widgets/q3widgetstack/qdesigner_q3widgetstack.cpp new file mode 100644 index 000000000..a6bc34844 --- /dev/null +++ b/src/designer/src/plugins/widgets/q3widgetstack/qdesigner_q3widgetstack.cpp @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** 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 Qt Designer 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 "qdesigner_q3widgetstack_p.h" +#include "../../../lib/shared/qdesigner_propertycommand_p.h" + +#include <QtDesigner/QDesignerFormWindowInterface> +#include <QtDesigner/QDesignerContainerExtension> +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/QExtensionManager> + +#include <QtCore/QEvent> +#include <QtGui/QToolButton> + +QT_BEGIN_NAMESPACE + +namespace { + QToolButton *createToolButton(QWidget *parent, Qt::ArrowType at, const QString &name) { + QToolButton *rc = new QToolButton(); + rc->setAttribute(Qt::WA_NoChildEventsForParent, true); + rc->setParent(parent); + rc->setObjectName(name); + rc->setArrowType(at); + rc->setAutoRaise(true); + rc->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); + rc->setFixedSize(QSize(15, 15)); + return rc; + } +} + +QDesignerQ3WidgetStack::QDesignerQ3WidgetStack(QWidget *parent) : + Q3WidgetStack(parent), + m_prev(createToolButton(this, Qt::LeftArrow, QLatin1String("__qt__passive_prev"))), + m_next(createToolButton(this, Qt::RightArrow, QLatin1String("__qt__passive_next"))) +{ + connect(m_prev, SIGNAL(clicked()), this, SLOT(prevPage())); + connect(m_next, SIGNAL(clicked()), this, SLOT(nextPage())); + updateButtons(); + + connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); +} + +QDesignerFormWindowInterface *QDesignerQ3WidgetStack::formWindow() +{ + return QDesignerFormWindowInterface::findFormWindow(this); +} + +QDesignerContainerExtension *QDesignerQ3WidgetStack::container() +{ + if (formWindow()) { + QDesignerFormEditorInterface *core = formWindow()->core(); + return qt_extension<QDesignerContainerExtension*>(core->extensionManager(), this); + } + return 0; +} + +int QDesignerQ3WidgetStack::count() +{ + return container() ? container()->count() : 0; +} + +int QDesignerQ3WidgetStack::currentIndex() +{ + return container() ? container()->currentIndex() : -1; +} + +void QDesignerQ3WidgetStack::setCurrentIndex(int index) +{ + if (container() && (index >= 0) && (index < count())) { + container()->setCurrentIndex(index); + emit currentChanged(index); + } +} + +QWidget *QDesignerQ3WidgetStack::widget(int index) +{ + return container() ? container()->widget(index) : 0; +} + +void QDesignerQ3WidgetStack::updateButtons() +{ + if (m_prev) { + m_prev->move(width() - 31, 1); + m_prev->show(); + m_prev->raise(); + } + + if (m_next) { + m_next->move(width() - 16, 1); + m_next->show(); + m_next->raise(); + } +} + +void QDesignerQ3WidgetStack::gotoPage(int page) { + // Are we on a form or in a preview? + if (QDesignerFormWindowInterface *fw = formWindow()) { + qdesigner_internal::SetPropertyCommand *cmd = new qdesigner_internal::SetPropertyCommand(fw); + cmd->init(this, QLatin1String("currentIndex"), page); + fw->commandHistory()->push(cmd); + fw->emitSelectionChanged(); // Magically prevent an endless loop triggered by auto-repeat. + } else { + setCurrentIndex(page); + } + updateButtons(); +} + + +void QDesignerQ3WidgetStack::prevPage() +{ + if (count() > 1) { + int newIndex = currentIndex() - 1; + if (newIndex < 0) + newIndex = count() - 1; + gotoPage(newIndex); + } +} + +void QDesignerQ3WidgetStack::nextPage() +{ + if (count() > 1) + gotoPage((currentIndex() + 1) % count()); +} + +QString QDesignerQ3WidgetStack::currentPageName() +{ + if (currentIndex() == -1) + return QString(); + + return widget(currentIndex())->objectName(); +} + +void QDesignerQ3WidgetStack::setCurrentPageName(const QString &pageName) +{ + if (currentIndex() == -1) + return; + + if (QWidget *w = widget(currentIndex())) + w->setObjectName(pageName); +} + +bool QDesignerQ3WidgetStack::event(QEvent *e) +{ + if (e->type() == QEvent::LayoutRequest) { + updateButtons(); + } + + return Q3WidgetStack::event(e); +} + +void QDesignerQ3WidgetStack::childEvent(QChildEvent *e) +{ + Q3WidgetStack::childEvent(e); + updateButtons(); +} + +void QDesignerQ3WidgetStack::resizeEvent(QResizeEvent *e) +{ + Q3WidgetStack::resizeEvent(e); + updateButtons(); +} + +void QDesignerQ3WidgetStack::showEvent(QShowEvent *e) +{ + Q3WidgetStack::showEvent(e); + updateButtons(); +} + +void QDesignerQ3WidgetStack::slotCurrentChanged(int index) +{ + if (widget(index)) { + if (QDesignerFormWindowInterface *fw = formWindow()) { + fw->clearSelection(); + fw->selectWidget(this, true); + } + } +} + +QT_END_NAMESPACE diff --git a/src/designer/src/plugins/widgets/q3widgetstack/qdesigner_q3widgetstack_p.h b/src/designer/src/plugins/widgets/q3widgetstack/qdesigner_q3widgetstack_p.h new file mode 100644 index 000000000..53f90299f --- /dev/null +++ b/src/designer/src/plugins/widgets/q3widgetstack/qdesigner_q3widgetstack_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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 Qt Designer 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$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of Qt Designer. This header +// file may change from version to version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QDESIGNER_Q3WIDGETSTACK_P_H +#define QDESIGNER_Q3WIDGETSTACK_P_H + +#include <Qt3Support/Q3WidgetStack> + +QT_BEGIN_NAMESPACE + +class QDesignerFormWindowInterface; +class QDesignerContainerExtension; +class QToolButton; +class QChildEvent; +class QResizeEvent; +class QShowEvent; +class QEvent; + +class QDesignerQ3WidgetStack : public Q3WidgetStack +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex STORED false DESIGNABLE true) + Q_PROPERTY(QString currentPageName READ currentPageName WRITE setCurrentPageName STORED false DESIGNABLE true) +public: + QDesignerQ3WidgetStack(QWidget *parent = 0); + int currentIndex(); + QString currentPageName(); + +public slots: + void updateButtons(); + void setCurrentIndex(int index); + void setCurrentPageName(const QString &pageName); + +private slots: + void prevPage(); + void nextPage(); + void slotCurrentChanged(int index); + +signals: + void currentChanged(int index); + +protected: + virtual void childEvent(QChildEvent *e); + virtual void resizeEvent(QResizeEvent *e); + virtual void showEvent(QShowEvent *e); + virtual bool event(QEvent *e); + +private: + void gotoPage(int page); + QDesignerFormWindowInterface *formWindow(); + QDesignerContainerExtension *container(); + int count(); + QWidget *widget(int index); + QToolButton *m_prev, *m_next; +}; + +QT_END_NAMESPACE + +#endif // !QDESIGNER_Q3WIDGETSTACK_P_H |