/tools/designer/src/plugins/widgets/q3wizard/q3wizard_container.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 235 lines · 156 code · 39 blank · 40 comment · 20 complexity · 61036ef9d844346ad1ada4970a2b5c3a MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the Qt Designer of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include "q3wizard_container.h"
  42. #include <Qt3Support/Q3Wizard>
  43. #include <QtDesigner/QDesignerFormWindowInterface>
  44. #include <QtDesigner/private/ui4_p.h>
  45. #include <QtCore/qdebug.h>
  46. QT_BEGIN_NAMESPACE
  47. static const char *currentPageText = "currentPageText";
  48. Q3WizardHelper::Q3WizardHelper(Q3Wizard *wizard)
  49. : QObject(wizard),
  50. m_wizard(wizard)
  51. {
  52. connect(m_wizard, SIGNAL(selected(QString)), this, SLOT(slotCurrentChanged()));
  53. }
  54. void Q3WizardHelper::slotCurrentChanged()
  55. {
  56. if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(m_wizard)) {
  57. fw->clearSelection();
  58. fw->selectWidget(m_wizard, true);
  59. }
  60. }
  61. Q3WizardExtraInfo::Q3WizardExtraInfo(Q3Wizard *wizard, QDesignerFormEditorInterface *core, QObject *parent)
  62. : QObject(parent), m_wizard(wizard), m_core(core)
  63. {}
  64. QWidget *Q3WizardExtraInfo::widget() const
  65. { return m_wizard; }
  66. Q3Wizard *Q3WizardExtraInfo::wizard() const
  67. { return m_wizard; }
  68. QDesignerFormEditorInterface *Q3WizardExtraInfo::core() const
  69. { return m_core; }
  70. bool Q3WizardExtraInfo::saveUiExtraInfo(DomUI *ui)
  71. { Q_UNUSED(ui); return false; }
  72. bool Q3WizardExtraInfo::loadUiExtraInfo(DomUI *ui)
  73. { Q_UNUSED(ui); return false; }
  74. bool Q3WizardExtraInfo::saveWidgetExtraInfo(DomWidget *ui_widget)
  75. {
  76. int i = 0;
  77. foreach (DomWidget *ui_child, ui_widget->elementWidget()) {
  78. DomProperty *p = new DomProperty();
  79. p->setAttributeName(QLatin1String("title"));
  80. DomString *str = new DomString();
  81. str->setText(wizard()->title(wizard()->page(i)));
  82. p->setElementString(str);
  83. QList<DomProperty *> attributes = ui_child->elementAttribute();
  84. attributes.append(p);
  85. ui_child->setElementAttribute(attributes);
  86. i++;
  87. }
  88. return true;
  89. }
  90. bool Q3WizardExtraInfo::loadWidgetExtraInfo(DomWidget *ui_widget)
  91. {
  92. int i = 0;
  93. foreach (const DomWidget *ui_child, ui_widget->elementWidget()) {
  94. foreach (const DomProperty *ui_prop, ui_child->elementAttribute()) {
  95. if (ui_prop->attributeName() == QLatin1String("title")) {
  96. const DomString *ui_string = ui_prop->elementString();
  97. if (ui_string)
  98. wizard()->setTitle(wizard()->page(i), ui_string->text());
  99. }
  100. }
  101. i++;
  102. }
  103. return true;
  104. }
  105. Q3WizardExtraInfoFactory::Q3WizardExtraInfoFactory(QDesignerFormEditorInterface *core, QExtensionManager *parent)
  106. : QExtensionFactory(parent), m_core(core)
  107. {}
  108. QObject *Q3WizardExtraInfoFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
  109. {
  110. if (iid != Q_TYPEID(QDesignerExtraInfoExtension))
  111. return 0;
  112. if (Q3Wizard *w = qobject_cast<Q3Wizard *>(object))
  113. return new Q3WizardExtraInfo(w, m_core, parent);
  114. return 0;
  115. }
  116. Q3WizardContainer::Q3WizardContainer(Q3Wizard *wizard, QObject *parent)
  117. : QObject(parent),
  118. m_wizard(wizard)
  119. {}
  120. int Q3WizardContainer::count() const
  121. {
  122. return m_wizard->pageCount();
  123. }
  124. QWidget *Q3WizardContainer::widget(int index) const
  125. {
  126. Q_ASSERT(index != -1);
  127. return m_wizard->page(index);
  128. }
  129. int Q3WizardContainer::currentIndex() const
  130. {
  131. if (m_wizard->currentPage() == 0 && m_wizard->pageCount())
  132. m_wizard->showPage(widget(0));
  133. return m_wizard->indexOf(m_wizard->currentPage());
  134. }
  135. void Q3WizardContainer::setCurrentIndex(int index)
  136. {
  137. const bool blocked = m_wizard->signalsBlocked();
  138. m_wizard->blockSignals(true);
  139. m_wizard->showPage(widget(index));
  140. m_wizard->blockSignals(blocked);
  141. }
  142. void Q3WizardContainer::addWidget(QWidget *widget)
  143. {
  144. m_wizard->addPage(widget, tr("Page"));
  145. }
  146. void Q3WizardContainer::insertWidget(int index, QWidget *widget)
  147. {
  148. m_wizard->insertPage(widget, tr("Page"), index);
  149. }
  150. void Q3WizardContainer::remove(int index)
  151. {
  152. m_wizard->removePage(widget(index));
  153. }
  154. Q3WizardContainerFactory::Q3WizardContainerFactory(QExtensionManager *parent)
  155. : QExtensionFactory(parent)
  156. {
  157. }
  158. QObject *Q3WizardContainerFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
  159. {
  160. if (iid != Q_TYPEID(QDesignerContainerExtension))
  161. return 0;
  162. if (Q3Wizard *w = qobject_cast<Q3Wizard*>(object))
  163. return new Q3WizardContainer(w, parent);
  164. return 0;
  165. }
  166. Q3WizardPropertySheet::Q3WizardPropertySheet(Q3Wizard *object, QObject *parent)
  167. : QDesignerPropertySheet(object, parent), m_wizard(object)
  168. {
  169. createFakeProperty(QLatin1String(currentPageText), QString());
  170. }
  171. void Q3WizardPropertySheet::setProperty(int index, const QVariant &value)
  172. {
  173. const QString prop = propertyName(index);
  174. if (prop == QLatin1String(currentPageText)) {
  175. m_wizard->setTitle(m_wizard->currentPage(), value.toString());
  176. return;
  177. }
  178. QDesignerPropertySheet::setProperty(index, value);
  179. }
  180. QVariant Q3WizardPropertySheet::property(int index) const
  181. {
  182. const QString prop = propertyName(index);
  183. if (prop == QLatin1String(currentPageText))
  184. return m_wizard->title(m_wizard->currentPage());
  185. return QDesignerPropertySheet::property(index);
  186. }
  187. bool Q3WizardPropertySheet::reset(int index)
  188. {
  189. const QString prop = propertyName(index);
  190. if (prop == QLatin1String(currentPageText)) {
  191. m_wizard->setTitle(m_wizard->currentPage(), QString());
  192. return true;
  193. }
  194. return QDesignerPropertySheet::reset(index);
  195. }
  196. QT_END_NAMESPACE