widgetfactory.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 493 行 · 第 1/2 页
CPP
493 行
} if (qobject_cast<QDesignerTabWidget*>(o)) return QLatin1String("QTabWidget"); else if (qobject_cast<QDesignerStackedWidget*>(o)) return QLatin1String("QStackedWidget"); else if (qobject_cast<QDesignerMenuBar*>(o)) return QLatin1String("QMenuBar"); else if (qobject_cast<QDesignerDockWidget*>(o)) return QLatin1String("QDockWidget"); else if (qobject_cast<QDesignerToolBox*>(o)) return QLatin1String("QToolBox"); else if (qobject_cast<QDesignerDialog*>(o)) return QLatin1String("QDialog"); else if (qobject_cast<QDesignerWidget*>(o)) return QLatin1String("QWidget"); else if (qstrcmp(o->metaObject()->className(), "QAxBase") == 0) return QLatin1String("QAxWidget"); else if (qstrcmp(o->metaObject()->className(), "QDesignerQ3WidgetStack") == 0) return QLatin1String("Q3WidgetStack"); return QLatin1String(o->metaObject()->className());}QLayout *WidgetFactory::createUnmanagedLayout(QWidget *parentWidget, int type){ switch (type) { case LayoutInfo::HBox: return new QHBoxLayout(parentWidget); case LayoutInfo::VBox: return new QVBoxLayout(parentWidget); case LayoutInfo::Grid: return new QGridLayout(parentWidget); default: Q_ASSERT(0); break; } return 0;}/*! Creates a layout on the widget \a widget of the type \a type which can be \c HBox, \c VBox or \c Grid.*/QLayout *WidgetFactory::createLayout(QWidget *widget, QLayout *parentLayout, int type) const // ### (sizepolicy){ QDesignerMetaDataBaseInterface *metaDataBase = core()->metaDataBase(); if (parentLayout == 0) { QWidget *page = containerOfWidget(widget); if (page) { widget = page; } else { const QString msg = QObject::tr("The current page of the container '%1' (%2) could not be determined while creating a layout.""This indicates an inconsistency in the ui-file, probably a layout being constructed on a container widget.").arg(widget->objectName()).arg(classNameOf(core(), widget)); designerWarning(msg); } } Q_ASSERT(metaDataBase->item(widget) != 0); // ensure the widget is managed if (parentLayout == 0 && metaDataBase->item(widget->layout()) == 0) { parentLayout = widget->layout(); } QWidget *parentWidget = parentLayout != 0 ? 0 : widget; QLayout *layout = createUnmanagedLayout(parentWidget, type); metaDataBase->add(layout); // add the layout in the MetaDataBase QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), layout); if (widget->inherits("Q3GroupBox")) { layout->setContentsMargins(widget->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), widget->style()->pixelMetric(QStyle::PM_LayoutTopMargin), widget->style()->pixelMetric(QStyle::PM_LayoutRightMargin), widget->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); QGridLayout *grid = qobject_cast<QGridLayout *>(layout); if (grid) { grid->setHorizontalSpacing(-1); grid->setVerticalSpacing(-1); } else { layout->setSpacing(-1); } layout->setAlignment(Qt::AlignTop); // Just to ensure; before 4.3 orientation property was always set (now only for QSplitter class). // Calling Q3GroupBox::setOrientation() invoked in turn setSpacing(0). Below fixes that widget->layout()->setSpacing(-1); } else if (widget->inherits("QLayoutWidget")) { sheet->setProperty(sheet->indexOf(QLatin1String("leftMargin")), 0); sheet->setProperty(sheet->indexOf(QLatin1String("topMargin")), 0); sheet->setProperty(sheet->indexOf(QLatin1String("rightMargin")), 0); sheet->setProperty(sheet->indexOf(QLatin1String("bottomMargin")), 0); } if (sheet) sheet->setChanged(sheet->indexOf(QLatin1String("alignment")), true); if (metaDataBase->item(widget->layout()) == 0) { Q_ASSERT(layout->parent() == 0); QBoxLayout *box = qobject_cast<QBoxLayout*>(widget->layout()); Q_ASSERT(box != 0); // we support only unmanaged box layouts box->addLayout(layout); } return layout;}/*! Returns the widget into which children should be inserted when \a w is a container known to designer. Usually, it is \a w itself, but there are exceptions (for example, a tabwidget is known to designer as a container, but the child widgets should be inserted into the current page of the tabwidget. In this case, the current page of the tabwidget would be returned.) */QWidget* WidgetFactory::containerOfWidget(QWidget *w) const{ if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), w)) return container->widget(container->currentIndex()); return w;}/*! Returns the actual designer widget of the container \a w. This is normally \a w itself, but it might be a parent or grand parent of \a w (for example, when working with a tabwidget and \a w is the container which contains and layouts children, but the actual widget known to designer is the tabwidget which is the parent of \a w. In this case, the tabwidget would be returned.)*/QWidget* WidgetFactory::widgetOfContainer(QWidget *w) const{ // ### cleanup if (!w) return 0; if (w->parentWidget() && w->parentWidget()->parentWidget() && w->parentWidget()->parentWidget()->parentWidget() && qobject_cast<QToolBox*>(w->parentWidget()->parentWidget()->parentWidget())) return w->parentWidget()->parentWidget()->parentWidget(); while (w != 0) { if (core()->widgetDataBase()->isContainer(w) || w && qobject_cast<QDesignerFormWindowInterface*>(w->parentWidget())) return w; w = w->parentWidget(); } return w;}QDesignerFormEditorInterface *WidgetFactory::core() const{ return m_core;}void WidgetFactory::initialize(QObject *object) const{ QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_core->extensionManager(), object); if (object->metaObject()->indexOfProperty("focusPolicy") != -1) object->setProperty("focusPolicy", Qt::NoFocus); if (!sheet) return; sheet->setChanged(sheet->indexOf(QLatin1String("objectName")), true); sheet->setChanged(sheet->indexOf(QLatin1String("geometry")), true); if (qobject_cast<Spacer*>(object)) sheet->setChanged(sheet->indexOf(QLatin1String("sizeHint")), true); int o = sheet->indexOf(QLatin1String("orientation")); if (o != -1 && object->inherits("QSplitter")) sheet->setChanged(o, true); if (QWidget *widget = qobject_cast<QWidget*>(object)) { QSize sz = widget->sizeHint(); if (qobject_cast<QFrame*>(object) && sz.width() <= 0 && sz.height() <= 0) widget->setMinimumSize(QSize(16, 16)); widget->setAttribute(Qt::WA_TransparentForMouseEvents, false); } if (QToolBar *toolBar = qobject_cast<QToolBar*>(object)) { sheet->setVisible(sheet->indexOf(QLatin1String("windowTitle")), true); toolBar->setFloatable(false); // prevent toolbars from being dragged off } if (qobject_cast<QDockWidget*>(object)) { sheet->setVisible(sheet->indexOf(QLatin1String("windowTitle")), true); sheet->setVisible(sheet->indexOf(QLatin1String("windowIcon")), true); } if (qobject_cast<QAction*>(object)) { sheet->setChanged(sheet->indexOf(QLatin1String("text")), true); } if (qobject_cast<QMenu*>(object)) { sheet->setChanged(sheet->indexOf(QLatin1String("geometry")), false); sheet->setChanged(sheet->indexOf(QLatin1String("title")), true); } if (qobject_cast<QMenu*>(object) || qobject_cast<QMenuBar*>(object)) { qobject_cast<QWidget*>(object)->setFocusPolicy(Qt::StrongFocus); }}bool WidgetFactory::isPassiveInteractor(QWidget *widget){ if (m_lastPassiveInteractor != 0 && (QWidget*)(*m_lastPassiveInteractor) == widget) return m_lastWasAPassiveInteractor; m_lastWasAPassiveInteractor = false; (*m_lastPassiveInteractor) = widget; if (QApplication::activePopupWidget()) // if a popup is open, we have to make sure that this one is closed, else X might do funny things return (m_lastWasAPassiveInteractor = true); else if (widget == 0) return m_lastWasAPassiveInteractor; if (qobject_cast<QTabBar*>(widget)) return (m_lastWasAPassiveInteractor = true); else if (qobject_cast<QSizeGrip*>(widget)) return (m_lastWasAPassiveInteractor = true); else if (qobject_cast<QAbstractButton*>(widget) && (qobject_cast<QTabBar*>(widget->parent()) || qobject_cast<QToolBox*>(widget->parent()))) return (m_lastWasAPassiveInteractor = true); else if (qobject_cast<QMenuBar*>(widget)) return (m_lastWasAPassiveInteractor = true); else if (qobject_cast<QToolBar*>(widget)) return (m_lastWasAPassiveInteractor = true); else if (qstrcmp(widget->metaObject()->className(), "QDockWidgetTitle") == 0) return (m_lastWasAPassiveInteractor = true); else if (widget->objectName().startsWith(QLatin1String("__qt__passive_"))) return (m_lastWasAPassiveInteractor = true); return m_lastWasAPassiveInteractor;}} // namespace qdesigner_internal
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?