コード例 #1
0
void DsgnRibbonStatusBarPlugin::widgetManaged(QWidget* widget)
{
    if (widget->metaObject()->className() == QString("Qtitan::RibbonStatusBar"))
    {
        QDesignerFormWindowInterface* formWindow = static_cast<QDesignerFormWindowInterface *>(sender());
        QDesignerFormEditorInterface* core = formWindow->core();
        QDesignerContainerExtension* container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), formWindow->mainContainer());
        formWindow->unmanageWidget(widget);

        QUndoStack* stack = formWindow->commandHistory();
        if (!stack->isClean())
        {
            //This code check the InsertWidget command on the stack.
            const QUndoCommand* command = stack->command(stack->index());
            if (command->childCount() == 0)
                return;
        }

        if (qobject_cast<QMainWindow *>(formWindow->mainContainer()) == 0)
        {
                QMessageBox::critical(
                    formWindow->mainContainer(),
                    tr("Can't add Ribbon StatusBar"), 
                    tr("You can add Ribbon StatusBar onto Qtitan::RibbonMainWindow or QMainWindow only."));
                widget->deleteLater();
                return;
        }

        for (int i = 0; i < container->count(); ++i)
        {
            QWidget* w = container->widget(i);
            if (w->metaObject()->className() == QString("Qtitan::RibbonStatusBar") ||
                w->metaObject()->className() == QString("QStatusBar"))
            {
                QMessageBox::critical(
                    formWindow->mainContainer(),
                    tr("Can't add Ribbon StatusBar"), 
                    tr("Only one instance of the Ribbon StatusBar can be adding to the main form."));
                widget->deleteLater();
                return;
            }
        }

        container->addWidget(widget);
        formWindow->core()->metaDataBase()->add(widget);
    }
}
コード例 #2
0
void RibbonStyleDsgnPlugin::widgetManaged(QWidget* widget)
{
    QDesignerFormWindowInterface* formWindow = static_cast<QDesignerFormWindowInterface *>(sender());
    QDesignerFormEditorInterface* core = formWindow->core();
    QDesignerContainerExtension* container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), formWindow->mainContainer());

    if (widget->metaObject()->className() == QString("Qtitan::RibbonStyle"))
    {
        formWindow->unmanageWidget(widget);

        QUndoStack* stack = formWindow->commandHistory();
        if (!stack->isClean())
        {
            //This code check the InsertWidget command on the stack.
            const QUndoCommand* command = stack->command(stack->index());
            if (command->childCount() == 0)
                return;
        }

        if (qobject_cast<QMainWindow *>(formWindow->mainContainer()) == 0)
        {
            QMessageBox::critical(formWindow->mainContainer(), tr("Can't add Ribbon Style"), 
                tr("You can't drag-drop the style to this QWidget form. The style can be placed only onto the form of QMainWindow successor."));
            widget->deleteLater();
            return;
        }

        QWidget* widgetStyle = Q_NULL;
        for (int i = 0; i < container->count() && widgetStyle == Q_NULL; ++i)
        {
            QWidget* w = container->widget(i);
            if (w->metaObject()->className() == QString("Qtitan::OfficeStyle") ||
                w->metaObject()->className() == QString("Qtitan::RibbonStyle"))
                widgetStyle = w;
        }

        if (widgetStyle && widgetStyle->metaObject()->className() == QString("Qtitan::RibbonStyle"))
        {
            QMessageBox::critical(
                formWindow->mainContainer(),
                tr("Can't add Ribbon Style"), 
                tr("Only one instance of the Ribbon Style can be adding to the main form."));
            widget->deleteLater();
            return;
        }

        if (widgetStyle)
        {
            g_removeBlock = true;
            const QString description = tr("Delete '%1'").arg(widgetStyle->objectName());
            formWindow->commandHistory()->beginMacro(description);

            DeleteStyleCommand* cmd = new DeleteStyleCommand(formWindow);
            cmd->init(widgetStyle);
            formWindow->commandHistory()->push(cmd);
            formWindow->commandHistory()->endMacro();
            g_removeBlock = false;
        }

        container->addWidget(widget);
        formWindow->core()->metaDataBase()->add(widget);
        widget->setCursor(Qt::PointingHandCursor);
    }
    else if (DesignerMainWindowStyleContainer* styelContainer = dynamic_cast<DesignerMainWindowStyleContainer*>(container))
    {
        if (QMainWindow* mainindow = static_cast<QMainWindow*>(styelContainer->mainWindow()))
        {
            if (Qtitan::CommonStyle* currentStyle = qobject_cast<Qtitan::CommonStyle*>(mainindow->style()))
                ::setChildStyle(widget, currentStyle);
        }
    }
}