Beispiel #1
0
void AssetsWindow::Initialize()
{
    // Init main widget
    setAttribute(Qt::WA_DeleteOnClose);
    setWindowTitle(tr("Assets"));
    // Append asset type if we're viewing only assets of specific type.
    if (!assetType.isEmpty())
        setWindowTitle(windowTitle() + ": " + assetType);
    resize(300, 400);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setContentsMargins(5, 5, 5, 5);
    setLayout(layout);

    // Create child widgets
    treeWidget = new AssetTreeWidget(framework, this);
    treeWidget->setHeaderHidden(true);

    searchField = new QLineEdit(this);
    searchField->setText(tr("Search..."));
    searchField->setStyleSheet("color:grey;");
    searchField->installEventFilter(this);

    expandAndCollapseButton = new QPushButton(tr("Expand All"), this);

    QHBoxLayout *hlayout= new QHBoxLayout;
    hlayout->addWidget(searchField);
    hlayout->addWidget(expandAndCollapseButton);

    layout->addLayout(hlayout);
    layout->addWidget(treeWidget);

    connect(searchField, SIGNAL(textEdited(const QString &)), SLOT(Search(const QString &)));
    connect(expandAndCollapseButton, SIGNAL(clicked()), SLOT(ExpandOrCollapseAll()));

    connect(framework->Asset(), SIGNAL(AssetCreated(AssetPtr)), SLOT(AddAsset(AssetPtr)));
    connect(framework->Asset(), SIGNAL(AssetAboutToBeRemoved(AssetPtr)), SLOT(RemoveAsset(AssetPtr)));

    connect(treeWidget, SIGNAL(itemCollapsed(QTreeWidgetItem*)), SLOT(CheckTreeExpandStatus(QTreeWidgetItem*)));
    connect(treeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), SLOT(CheckTreeExpandStatus(QTreeWidgetItem*)));
}
SceneStructureWindow::SceneStructureWindow(Framework *fw, QWidget *parent) :
    QWidget(parent),
    framework(fw),
    showGroups(true),
    showComponents(true),
    attributeVisibility(ShowAssetReferences),
    treeWidget(0),
    expandAndCollapseButton(0),
    searchField(0),
    sortingCriteria(SortById)
{
    ConfigAPI &cfg = *framework->Config();
    showGroups = cfg.DeclareSetting(cShowGroupsSetting).toBool();
    showComponents = cfg.DeclareSetting(cShowComponentsSetting).toBool();
    attributeVisibility = static_cast<AttributeVisibilityType>(cfg.DeclareSetting(cAttributeVisibilitySetting).toUInt());

    // Init main widget
    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setContentsMargins(5, 5, 5, 5);
    layout->setSpacing(5);
    setLayout(layout);
    setWindowTitle(tr("Scene Structure"));
    resize(325, 400);

    // Create child widgets
    treeWidget = new SceneTreeWidget(fw, this);
    expandAndCollapseButton = new QPushButton(tr("Expand All"), this);
    expandAndCollapseButton->setFixedHeight(22);

    searchField = new QLineEdit(this);
    searchField->setPlaceholderText(tr("Search..."));
    searchField->setFixedHeight(20);

    QLabel *sortLabel = new QLabel(tr("Sort by"), this);
    QComboBox *sortComboBox = new QComboBox(this);
    sortComboBox->addItem(tr("ID"));
    sortComboBox->addItem(tr("Name"));
    sortComboBox->setFixedHeight(20);

    QCheckBox *groupCheckBox = new QCheckBox(tr("Groups"), this);
    groupCheckBox->setChecked(showGroups);

    QCheckBox *compCheckBox = new QCheckBox(tr("Components"), this);
    compCheckBox->setChecked(showComponents);

    QLabel *attributeLabel = new QLabel(tr("Attributes"), this);
    QComboBox *attributeComboBox = new QComboBox(this);
    attributeComboBox->addItem(tr("None"), DoNotShowAttributes);
    attributeComboBox->addItem(tr("Assets"), ShowAssetReferences);
    attributeComboBox->addItem(tr("Dynamic"), ShowDynamicAttributes);
//    attributeComboBox->addItem(tr("All"), ShowAllAttributes); /**< @todo Disabled temporarily until the performance problems have been solved. */
    attributeComboBox->setCurrentIndex(attributeVisibility);

    undoButton_ = new QToolButton();
    undoButton_->setPopupMode(QToolButton::MenuButtonPopup);
    undoButton_->setDisabled(true);

    redoButton_ = new QToolButton();
    redoButton_->setPopupMode(QToolButton::MenuButtonPopup);
    redoButton_->setDisabled(true);

    undoButton_->setIcon(QIcon(Application::InstallationDirectory() + "data/ui/images/icon/undo-icon.png"));
    redoButton_->setIcon(QIcon(Application::InstallationDirectory() + "data/ui/images/icon/redo-icon.png"));

    // Fill layouts
    QHBoxLayout *layoutFilterAndSort = new QHBoxLayout();
    layoutFilterAndSort->setContentsMargins(0,0,0,0);
    layoutFilterAndSort->setSpacing(5);
    layoutFilterAndSort->addWidget(searchField);
    layoutFilterAndSort->addWidget(sortLabel);
    layoutFilterAndSort->addWidget(sortComboBox);
    layoutFilterAndSort->addWidget(expandAndCollapseButton);

    QHBoxLayout *layoutSettingsVisibility = new QHBoxLayout();
    layoutSettingsVisibility->setContentsMargins(0,0,0,0);
    layoutSettingsVisibility->setSpacing(5);
    layoutSettingsVisibility->addWidget(undoButton_);
    layoutSettingsVisibility->addWidget(redoButton_);
    layoutSettingsVisibility->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed));
    layoutSettingsVisibility->addWidget(groupCheckBox);
    layoutSettingsVisibility->addWidget(compCheckBox);
    layoutSettingsVisibility->addWidget(attributeLabel);
    layoutSettingsVisibility->addWidget(attributeComboBox);

    layout->addLayout(layoutFilterAndSort);
    layout->addWidget(treeWidget);
    layout->addLayout(layoutSettingsVisibility);

    // Connect to widget signals
    connect(attributeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(SetAttributeVisibilityInternal(int)));
    connect(groupCheckBox, SIGNAL(toggled(bool)), SLOT(ShowGroups(bool)));
    connect(compCheckBox, SIGNAL(toggled(bool)), SLOT(ShowComponents(bool)));
    connect(sortComboBox, SIGNAL(currentIndexChanged(int)), SLOT(Sort(int)));
    connect(searchField, SIGNAL(textEdited(const QString &)), SLOT(Search(const QString &)));
    connect(expandAndCollapseButton, SIGNAL(clicked()), SLOT(ExpandOrCollapseAll()));
    connect(treeWidget, SIGNAL(itemCollapsed(QTreeWidgetItem*)), SLOT(CheckTreeExpandStatus(QTreeWidgetItem*)));
    connect(treeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), SLOT(CheckTreeExpandStatus(QTreeWidgetItem*)));

    connect(framework->Scene(), SIGNAL(SceneAboutToBeRemoved(Scene *, AttributeChange::Type)), SLOT(OnSceneRemoved(Scene *)));
}
Beispiel #3
0
ECEditorWindow::ECEditorWindow(Framework* fw, QWidget *parent) :
    QWidget(parent),
    framework(fw),
    toggleEntitiesButton(0),
    entityList(0),
    ecBrowser(0),
    hasFocus(true)
{
    QUiLoader loader;
    loader.setLanguageChangeEnabled(true);
    QFile file(Application::InstallationDirectory() + "data/ui/eceditor.ui");
    file.open(QFile::ReadOnly);
    if (!file.exists())
    {
        LogError("Cannot find " + Application::InstallationDirectory() + "data/ui/eceditor.ui file.");
        return;
    }

    QWidget *contents = loader.load(&file, this);
    if (!contents)
    {
        LogError("Could not load editor layout");
        return;
    }
    contents->installEventFilter(this);
    file.close();

    Scene *scene = fw->Scene()->MainCameraScene();
    assert(scene);
    undoManager_ = new UndoManager(scene->shared_from_this(), this);
    transformEditor = new TransformEditor(scene->shared_from_this(), undoManager_);

    QVBoxLayout *layout = new QVBoxLayout(this);
    undoButton_ = findChild<QToolButton *>("undoButton");
    undoButton_->setDisabled(true);
    redoButton_ = findChild<QToolButton *>("redoButton");
    redoButton_->setDisabled(true);

    undoButton_->setIcon(QIcon(Application::InstallationDirectory() + "data/ui/images/icon/undo-icon.png"));
    redoButton_->setIcon(QIcon(Application::InstallationDirectory() + "data/ui/images/icon/redo-icon.png"));

    undoButton_->setMenu(undoManager_->UndoMenu());
    redoButton_->setMenu(undoManager_->RedoMenu());

    layout->addWidget(contents);
    layout->setContentsMargins(0,0,0,0);
    setLayout(layout);
    setWindowTitle(contents->windowTitle());
    resize(contents->size());

    toggleEntitiesButton = findChild<QPushButton *>("but_show_entities");
    entityList = findChild<QListWidget*>("list_entities");
    QWidget *entity_widget = findChild<QWidget*>("entity_widget");
    if(entity_widget)
        entity_widget->hide();

    QWidget *browserWidget = findChild<QWidget*>("browser_widget");
    if (browserWidget)
    {
        ecBrowser = new ECBrowser(framework, this, browserWidget);
        ecBrowser->setMinimumWidth(100);
        QVBoxLayout *property_layout = dynamic_cast<QVBoxLayout *>(browserWidget->layout());
        if (property_layout)
            property_layout->addWidget(ecBrowser);
    }

    ECEditorModule *ecEditorModule = framework->GetModule<ECEditorModule>();
    if (ecBrowser)
    {
        // signals from attribute browser to editor window.
        connect(ecBrowser, SIGNAL(ShowXmlEditorForComponent(const QString &)), SLOT(ShowXmlEditorForComponent(const QString &)));
        connect(ecBrowser, SIGNAL(CreateNewComponent()), SLOT(CreateComponent()));
        connect(ecBrowser, SIGNAL(SelectionChanged(const QString&, const QString &, const QString&, const QString&)),
            SLOT(HighlightEntities(const QString&, const QString&)));
        connect(ecBrowser, SIGNAL(SelectionChanged(const QString&, const QString &, const QString&, const QString&)),
            SIGNAL(SelectionChanged(const QString&, const QString&, const QString&, const QString&)), Qt::UniqueConnection);

        ecBrowser->SetItemExpandMemory(ecEditorModule->ExpandMemory());
    }

    if (entityList)
    {
        entityList->setSelectionMode(QAbstractItemView::ExtendedSelection);
        connect(entityList, SIGNAL(itemSelectionChanged()), this, SLOT(RefreshPropertyBrowser()));
        connect(entityList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ShowEntityContextMenu(const QPoint &)));
    }

    if (toggleEntitiesButton)
        connect(toggleEntitiesButton, SIGNAL(pressed()), this, SLOT(ToggleEntityList()));

    QPushButton *expandOrCollapseButton = findChild<QPushButton *>("expandOrCollapseButton");
    if (expandOrCollapseButton && ecBrowser)
        connect(expandOrCollapseButton, SIGNAL(clicked()), ecBrowser, SLOT(ExpandOrCollapseAll()));

    connect(scene, SIGNAL(EntityRemoved(Entity*, AttributeChange::Type)), SLOT(RemoveEntity(Entity*)), Qt::UniqueConnection);
    connect(scene, SIGNAL(ActionTriggered(Entity *, const QString &, const QStringList &, EntityAction::ExecTypeField)),
        SLOT(OnActionTriggered(Entity *, const QString &, const QStringList &)), Qt::UniqueConnection);

    connect(this, SIGNAL(FocusChanged(ECEditorWindow *)), ecEditorModule, SLOT(ECEditorFocusChanged(ECEditorWindow*)));
    connect(this, SIGNAL(EditEntityXml(const QList<EntityPtr> &)), ecEditorModule, SLOT(CreateXmlEditor(const QList<EntityPtr> &)));
    connect(this, SIGNAL(EditComponentXml(const QList<ComponentPtr> &)), ecEditorModule, SLOT(CreateXmlEditor(const QList<ComponentPtr> &)));
    //connect(this, SIGNAL(AttributeAboutToBeEdited(IAttribute *)), this, SLOT(OnAboutToEditAttribute(IAttribute* )));
    connect(undoManager_, SIGNAL(CanUndoChanged(bool)), this, SLOT(OnUndoChanged(bool)));
    connect(undoManager_, SIGNAL(CanRedoChanged(bool)), this, SLOT(OnRedoChanged(bool)));
    connect(undoButton_, SIGNAL(clicked()), undoManager_, SLOT(Undo()));
    connect(redoButton_, SIGNAL(clicked()), undoManager_, SLOT(Redo()));
}
ECEditorWindow::ECEditorWindow(Framework* fw, QWidget *parent) :
    QWidget(parent),
    framework(fw),
    ecBrowser(0),
    hasFocus(true)
{
    /// @todo Create UI fully in code (very simple UI file).
    setupUi(this);
    installEventFilter(this);

    Scene *scene = fw->Scene()->MainCameraScene();
    assert(scene);
    undoManager_ = new UndoManager(scene->shared_from_this(), this);
    transformEditor = new TransformEditor(scene->shared_from_this(), undoManager_);

    undoButton->setDisabled(true);
    redoButton->setDisabled(true);

    undoButton->setIcon(QIcon(Application::InstallationDirectory() + "data/ui/images/icon/undo-icon.png"));
    redoButton->setIcon(QIcon(Application::InstallationDirectory() + "data/ui/images/icon/redo-icon.png"));

    undoButton->setMenu(undoManager_->UndoMenu());
    redoButton->setMenu(undoManager_->RedoMenu());

    entityWidget->hide();

    ecBrowser = new ECBrowser(framework, this, browserWidget);
    ecBrowser->setMinimumWidth(100);
    browserWidget->layout()->addWidget(ecBrowser);

    // signals from attribute browser to editor window.
    connect(ecBrowser, SIGNAL(ShowXmlEditorForComponent(const QString &)), SLOT(ShowXmlEditorForComponent(const QString &)));
    connect(ecBrowser, SIGNAL(CreateNewComponent()), SLOT(CreateComponent()));
    connect(ecBrowser, SIGNAL(SelectionChanged(const QString&, const QString &, const QString&, const QString&)),
        SLOT(HighlightEntities(const QString&, const QString&)));
    connect(ecBrowser, SIGNAL(SelectionChanged(const QString&, const QString &, const QString&, const QString&)),
        SIGNAL(SelectionChanged(const QString&, const QString&, const QString&, const QString&)), Qt::UniqueConnection);

    ECEditorModule *ecEditorModule = framework->Module<ECEditorModule>();
    ecBrowser->SetItemExpandMemory(ecEditorModule->ExpandMemory());

    entityList->setSelectionMode(QAbstractItemView::ExtendedSelection);
    connect(entityList, SIGNAL(itemSelectionChanged()), this, SLOT(Refresh()));
    connect(entityList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ShowEntityContextMenu(const QPoint &)));

    connect(toggleEntitiesButton, SIGNAL(pressed()), this, SLOT(ToggleEntityList()));
    connect(expandOrCollapseButton, SIGNAL(clicked()), ecBrowser, SLOT(ExpandOrCollapseAll()));

    connect(scene, SIGNAL(EntityRemoved(Entity*, AttributeChange::Type)), SLOT(RemoveEntity(Entity*)), Qt::UniqueConnection);
    connect(scene, SIGNAL(ActionTriggered(Entity *, const QString &, const QStringList &, EntityAction::ExecTypeField)),
        SLOT(OnActionTriggered(Entity *, const QString &, const QStringList &)), Qt::UniqueConnection);

    connect(this, SIGNAL(FocusChanged(ECEditorWindow *)), ecEditorModule, SLOT(ECEditorFocusChanged(ECEditorWindow*)));
    connect(this, SIGNAL(EditEntityXml(const QList<EntityPtr> &)), ecEditorModule, SLOT(CreateXmlEditor(const QList<EntityPtr> &)));
    connect(this, SIGNAL(EditComponentXml(const QList<ComponentPtr> &)), ecEditorModule, SLOT(CreateXmlEditor(const QList<ComponentPtr> &)));
    //connect(this, SIGNAL(AttributeAboutToBeEdited(IAttribute *)), this, SLOT(OnAboutToEditAttribute(IAttribute* )));
    connect(undoManager_, SIGNAL(CanUndoChanged(bool)), this, SLOT(OnUndoChanged(bool)));
    connect(undoManager_, SIGNAL(CanRedoChanged(bool)), this, SLOT(OnRedoChanged(bool)));
    connect(undoButton, SIGNAL(clicked()), undoManager_, SLOT(Undo()));
    connect(redoButton, SIGNAL(clicked()), undoManager_, SLOT(Redo()));

    connect(framework->Input()->TopLevelInputContext(), SIGNAL(KeyPressed(KeyEvent*)), SLOT(OnKeyEvent(KeyEvent*)));

    // Make sure the editor is cleared if the scene is cleared or removed.
    connect(scene, SIGNAL(SceneCleared(Scene *)), SLOT(OnSceneRemoved(Scene *)));
    connect(framework->Scene(), SIGNAL(SceneAboutToBeRemoved(Scene *, AttributeChange::Type)), SLOT(OnSceneRemoved(Scene *)));
}