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 *))); }