void KoResourcePopupAction::indexChanged(const QModelIndex &modelIndex) { if (! modelIndex.isValid()) { return; } d->menu->hide(); KoResource *resource = static_cast<KoResource*>(modelIndex.internalPointer()); if(resource) { KoAbstractGradient *gradient = dynamic_cast<KoAbstractGradient*>(resource); KoPattern *pattern = dynamic_cast<KoPattern*>(resource); if (gradient) { QGradient *qg = gradient->toQGradient(); qg->setCoordinateMode(QGradient::ObjectBoundingMode); d->background = QSharedPointer<KoShapeBackground>(new KoGradientBackground(qg)); } else if (pattern) { KoImageCollection *collection = new KoImageCollection(); d->background = QSharedPointer<KoShapeBackground>(new KoPatternBackground(collection)); qSharedPointerDynamicCast<KoPatternBackground>(d->background)->setPattern(pattern->pattern()); } emit resourceSelected(d->background); updateIcon(); } }
void KoResourceSelector::indexChanged( int ) { QModelIndex index = view()->currentIndex(); if( ! index.isValid() ) return; KoResource * resource = static_cast<KoResource*>( index.internalPointer() ); if( resource ) emit resourceSelected( resource ); }
/**************************************************************************** ** ** Copyright (C) 2016 - 2017 ** ** This file is generated by the Magus toolkit ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ****************************************************************************/ // Include #include "material_browser.h" #include "material_tree.h" //****************************************************************************/ MaterialTreeDockWidget::MaterialTreeDockWidget(const QString& iconDir, const QString& title, QMainWindow* parent, Qt::WindowFlags flags) : QDockWidget (title, parent, flags), mParent(parent) { mIconDir = iconDir; mEmptyString = ""; mResourceTreeWidget = new Magus::QtResourceTreeWidget(iconDir); mResourceTreeWidget->mActionDuplicateAssetText = QString("Clone material"); mResourceTreeWidget->mActionDeleteResourceText = QString("Remove from list"); mResourceTreeWidget->setAddAssetAfterDuplicateAssetSelected(false); // Do not duplicate automatically mResourceTreeWidget->setCreateTopLevelGroupContextMenuItemEnabled(false); mResourceTreeWidget->setDeleteTopLevelGroupEnabled(false); mResourceTreeWidget->setTopLevelGroupItemEditable(false); mResourceTreeWidget->setSubLevelGroupItemEditable(true); mResourceTreeWidget->setCreateAssetContextMenuItemEnabled(false); mResourceTreeWidget->setAssetItemEditable(false); mResourceTreeWidget->setDeleteResourceContextMenuItemEnabled(true); mResourceTreeWidget->setImportAssetContextMenuItemEnabled(false); mResourceTreeWidget->setDuplicateAssetContextMenuItemEnabled(true); // Miscellanious settings mResourceTreeWidget->addCustomContextMenuItem(ACTION_EDIT); // Listen to events. // Note, that although the 'create asset' context menu is disabled, the MaterialTreeDockWidget must still handle the 'resourceAdded' // signal, because it is also emitted when a subgroup is created in the mResourceTreeWidget; the subgroup must be added to // mSourceInfo after creation, to be able to recursively delete any assets resided in subgroups (these assets must also be // properly deleted from the MaterialThumbsDockWidget). connect(mResourceTreeWidget, SIGNAL(resourceSelected(int)), this, SLOT(handleResourceSelected(int))); connect(mResourceTreeWidget, SIGNAL(resourceDoubleClicked(int)), this, SLOT(handleResourceDoubleClicked(int))); connect(mResourceTreeWidget, SIGNAL(resourceAdded(int)), this, SLOT(handleResourceAdded(int))); connect(mResourceTreeWidget, SIGNAL(resourceDeleted(int)), this, SLOT(handleResourceDeleted(int))); connect(mResourceTreeWidget, SIGNAL(resourceMoved(int)), this, SLOT(handleResourceMoved(int))); connect(mResourceTreeWidget, SIGNAL(resourceSearched(QString)), this, SLOT(handleResourceSearched(QString))); connect(mResourceTreeWidget, SIGNAL(resourceSearchReset()), this, SLOT(handleResourceSearchReset())); connect(mResourceTreeWidget, SIGNAL(assetDuplicated(int)), this, SLOT(handleResourceDuplicated(int))); connect(mResourceTreeWidget, SIGNAL(customContextMenuItemSelected(QString,int)), this, SLOT(handleCustomContextMenuItemSelected(QString, int))); mInnerMain = new QMainWindow(); mInnerMain->setMinimumSize(100,100); mInnerMain->setCentralWidget(mResourceTreeWidget); setWidget(mInnerMain); QWidget* oldTitleBar = titleBarWidget(); setTitleBarWidget(new QWidget()); delete oldTitleBar; // Add toplevel groups initializeResourceTree(); } //****************************************************************************/ void MaterialTreeDockWidget::initializeResourceTree (void) { // Initialize; add toplevel groups to the mResourceTreeWidget up front QtSourcesInfo info; // HLMS PBS mResourceTreeWidget->addResource (TOOL_SOURCES_LEVEL_X000_PBS, TOOL_SOURCES_LEVEL_X000_PBS, 0, QString("PBS"), QString("PBS"), ICON_PBS_DATABLOCK_NO_PATH); info.toplevelId = TOOL_SOURCES_LEVEL_X000_PBS; info.resourceId = TOOL_SOURCES_LEVEL_X000_PBS; info.resourceType = Magus::TOOL_RESOURCETREE_KEY_TYPE_TOPLEVEL_GROUP; info.parentId = 0; info.fileName = QString("PBS"); info.baseName = info.fileName; //info.filter = TOOL_SOURCES_FORMAT_PBS; info.filter = QString(""); info.baseNameThumb = ICON_PBS_DATABLOCK; mSourceInfo[TOOL_SOURCES_LEVEL_X000_PBS] = info; // HLMS UNLIT mResourceTreeWidget->addResource (TOOL_SOURCES_LEVEL_X000_UNLIT, TOOL_SOURCES_LEVEL_X000_UNLIT, 0, QString("Unlit"), QString("Unlit"), ICON_UNLIT_DATABLOCK_NO_PATH); info.toplevelId = TOOL_SOURCES_LEVEL_X000_UNLIT; info.resourceId = TOOL_SOURCES_LEVEL_X000_UNLIT; info.resourceType = Magus::TOOL_RESOURCETREE_KEY_TYPE_TOPLEVEL_GROUP; info.parentId = 0; info.fileName = QString("Unlit"); info.baseName = info.fileName; //info.filter = TOOL_SOURCES_FORMAT_UNLIT; info.filter = QString(""); info.baseNameThumb = ICON_UNLIT_DATABLOCK; mSourceInfo[TOOL_SOURCES_LEVEL_X000_UNLIT] = info; // Determine what is enabled/disabled if a toplevelgroup is selected mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(mResourceTreeWidget->mActionCreateToplevelGroupText, false); mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(mResourceTreeWidget->mActionCreateSubGroupText, true); mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(mResourceTreeWidget->mActionCreateAssetText, false); mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(mResourceTreeWidget->mActionImportAssetText, false); mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(mResourceTreeWidget->mActionDuplicateAssetText, false); mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(mResourceTreeWidget->mActionDeleteResourceText, false); mResourceTreeWidget->enableContextMenuItemForTopLevelGroup(ACTION_EDIT, false); // Determine what is enabled/disabled if a subgroup is selected mResourceTreeWidget->enableContextMenuItemForSubGroup(mResourceTreeWidget->mActionCreateToplevelGroupText, false); mResourceTreeWidget->enableContextMenuItemForSubGroup(mResourceTreeWidget->mActionCreateSubGroupText, true); mResourceTreeWidget->enableContextMenuItemForSubGroup(mResourceTreeWidget->mActionCreateAssetText, false); mResourceTreeWidget->enableContextMenuItemForSubGroup(mResourceTreeWidget->mActionImportAssetText, false); mResourceTreeWidget->enableContextMenuItemForSubGroup(mResourceTreeWidget->mActionDuplicateAssetText, false); mResourceTreeWidget->enableContextMenuItemForSubGroup(mResourceTreeWidget->mActionDeleteResourceText, true); mResourceTreeWidget->enableContextMenuItemForSubGroup(ACTION_EDIT, false); // Determine what is enabled/disabled if an asset is selected mResourceTreeWidget->enableContextMenuItemForAsset(mResourceTreeWidget->mActionCreateToplevelGroupText, false); mResourceTreeWidget->enableContextMenuItemForAsset(mResourceTreeWidget->mActionCreateSubGroupText, false); mResourceTreeWidget->enableContextMenuItemForAsset(mResourceTreeWidget->mActionCreateAssetText, false); mResourceTreeWidget->enableContextMenuItemForAsset(mResourceTreeWidget->mActionImportAssetText, false); mResourceTreeWidget->enableContextMenuItemForAsset(mResourceTreeWidget->mActionDuplicateAssetText, true); mResourceTreeWidget->enableContextMenuItemForAsset(mResourceTreeWidget->mActionDeleteResourceText, true); mResourceTreeWidget->enableContextMenuItemForAsset(ACTION_EDIT, true); } //****************************************************************************/ MaterialTreeDockWidget::~MaterialTreeDockWidget(void) { } //****************************************************************************/ QVector<Magus::QtResourceInfo*>& MaterialTreeDockWidget::getResources (void) { // Delegate to mResourceTreeWidget; this is the component that actually retrieves the data return mResourceTreeWidget->getResources(); } //****************************************************************************/ void MaterialTreeDockWidget::setResources(const QVector<Magus::QtResourceInfo*>& resources) { // Add resources to the resource tree mResourceTreeWidget->setResources(resources, true); // Iterate again through the list to make sure that the thumb info is set QVectorIterator<Magus::QtResourceInfo*> it(resources); it.toFront(); Magus::QtResourceInfo* resourceInfo; while (it.hasNext()) { resourceInfo = it.next(); QtSourcesInfo info; info.toplevelId = resourceInfo->topLevelId; info.resourceId = resourceInfo->resourceId; info.resourceType = resourceInfo->resourceType; info.parentId = resourceInfo->parentId; info.fileName = resourceInfo->fullQualifiedName; info.baseName = resourceInfo->resourceName; info.baseNameThumb = resourceInfo->resourceName + QString (".png"); // Do not forget mSourceInfo[resourceInfo->resourceId] = info; } mResourceTreeWidget->expandAll(); } //****************************************************************************/ const QString& MaterialTreeDockWidget::getSelectedFullQualifiedName(void) { QTreeWidgetItem* item = mResourceTreeWidget->getSelectedResourceItem (); if (item) { if (mResourceTreeWidget->isItemAsset(item)) return mResourceTreeWidget->getFullQualifiedNameFromItem(item); } return mEmptyString; } //****************************************************************************/ bool MaterialTreeDockWidget::addMaterial(const QString& baseNameJson, const QString& fullNameJson, const QString& baseNameThumb, EditorHlmsTypes type) { switch (type) { case HLMS_PBS: { return addAssetQuiet(TOOL_SOURCES_LEVEL_X000_PBS, fullNameJson, baseNameJson, baseNameThumb); } break; case HLMS_UNLIT: { return addAssetQuiet(TOOL_SOURCES_LEVEL_X000_UNLIT, fullNameJson, baseNameJson, baseNameThumb); } break; } } //****************************************************************************/ void MaterialTreeDockWidget::selectTopLevel(int toplevelId) { mResourceTreeWidget->selectResource(toplevelId, false); } //****************************************************************************/ void MaterialTreeDockWidget::clearContent(void) { mResourceTreeWidget->clear(); initializeResourceTree(); } //****************************************************************************/ bool MaterialTreeDockWidget::addAssetQuiet(int toplevelId, const QString& name, const QString& baseName, const QString& baseNameThumb) { // Always add it even if the resource exists (sometimes the resourcetree and mSourceInfo are out-of-sync) if (isResourceExisting(baseName)) { // delete it first deleteAssetQuiet(toplevelId, name, baseName); } // Suppress the signal that a resource was added, otherwise the signal causes the asset to // be added to the asset widget int resourceId = mResourceTreeWidget->addResource(toplevelId, baseName, name, name, true, true); mResourceTreeWidget->expand(toplevelId); // Also add/set it to mSourceInfo QtSourcesInfo info; info.toplevelId = toplevelId; info.resourceId = resourceId; info.resourceType = Magus::TOOL_RESOURCETREE_KEY_TYPE_ASSET; // It is an asset info.parentId = toplevelId; info.fileName = name; info.baseName = baseName; info.baseNameThumb = baseNameThumb; mSourceInfo[resourceId] = info; return true; } //****************************************************************************/ const QString& MaterialTreeDockWidget::setSelectAssetQuiet(const QString& baseNameThumb) { int id = getResourceId(baseNameThumb); if (id != -1) { mResourceTreeWidget->selectResource(id, false); return mSourceInfo[id].fileName; } return mEmptyString; } //****************************************************************************/ const QString& MaterialTreeDockWidget::doubleClicked(const QString& baseNameThumb) { int id = getResourceId(baseNameThumb); if (id != -1) { return mSourceInfo[id].fileName; } return mEmptyString; } //****************************************************************************/ void MaterialTreeDockWidget::deleteAssetQuiet(int toplevelId, const QString& name, const QString& baseName) { // First, delete it from mResourceTreeWidget int resourceId = mResourceTreeWidget->getResourceIdFromToplevelIdAndName(toplevelId, name); if (resourceId < 0) return; mResourceTreeWidget->deleteResource(resourceId, true); // find the underlying asset (filenames) + delete it from the mSourceInfo mSourceInfo.remove(resourceId); } //****************************************************************************/ void MaterialTreeDockWidget::deleteAssetQuiet(const QString& baseNameThumb) { int id = getResourceId(baseNameThumb); if (id != -1) { QtSourcesInfo info = mSourceInfo[id]; mSourceInfo.remove(id); mResourceTreeWidget->deleteResource(info.toplevelId, info.fileName, true); } } //****************************************************************************/ void MaterialTreeDockWidget::handleResourceSelected(int resourceId) { // Determine which type is selected QMap<int, QtSourcesInfo>::iterator it = mSourceInfo.find(resourceId); if (it != mSourceInfo.end()) { QtSourcesInfo info = it.value(); mResourceTreeWidget->setSubgroupIconName(determineSubgroupIcon(info.toplevelId)); emit resourceSelected(info.toplevelId, info.parentId, info.resourceId, info.fileName, info.baseNameThumb); //QMessageBox::information(0, QString("this"), QVariant(info.toplevelId).toString()); // test } }
ResourceSelector::ResourceSelector() { // TODO: Duplicated code. // Select the first element as the current one. if( count() > 0 ){ setCurrentIndex( 0 ); } // Whenever the current index changes, emit a signal with the associated // ResourceID. void (QComboBox::*signal)( int ) = &ResourceSelector::activated; QObject::connect( this, signal, [this]( int index ){ emit resourceSelected( resourcesIDs_.at( index ) ); }); }
ResourceSelector::ResourceSelector( const ResourcesList resourcesList ) { resourcesIDs_.reserve( resourcesList.size() ); for( auto category : resourcesList ){ insertResource( category.first, category.second ); } // Select the first element as the current one. if( count() > 0 ){ setCurrentIndex( 0 ); } // Whenever the current index changes, emit a signal with the associated // ResourceID. void (QComboBox::*signal)( int ) = &ResourceSelector::activated; QObject::connect( this, signal, [this]( int index ){ emit resourceSelected( resourcesIDs_.at( index ) ); }); }
void SelectionDialog:: initSelectors() { connect( resourceSelector, SIGNAL( resourceSelected( QString, QString, QString, QString ) ), this, SLOT( addConstraint(QString,QString, QString,QString) ) ); connect( resourceSelector, SIGNAL( resourceTypeSelected( QString ) ), this, SLOT( addResourceType( QString ) ) ); // Connect requests for data from the resource selector to // the slots in the data server connect( resourceSelector, SIGNAL( needResourcesByType( QString, QString, void * ) ), dataSource, SLOT( findResourcesByType( QString, QString, void * ) ) ); connect( resourceSelector, SIGNAL( needAttributesByType( QString, QString, void * ) ), dataSource, SLOT( findAttributesByType( QString, QString, void * ) ) ); connect( resourceSelector, SIGNAL( needResourcesByParent( QString, QString, QString, SelectionListItem * ) ), dataSource, SLOT( findResourcesByParent( QString, QString, QString, SelectionListItem * ) ) ); connect( resourceSelector, SIGNAL( needAttributesByName( QString, QString, SelectionListItem * ) ), dataSource, SLOT( findAttributesByName( QString, QString, SelectionListItem * ) ) ); connect( resourceSelector, SIGNAL( needAttributesByResourceName( QString, SelectionListItem * ) ), dataSource, SLOT( findAttributesByResourceName( QString, SelectionListItem * ) ) ); connect( resourceSelector, SIGNAL( needExecutionResourcesByName( QString, SelectionListItem * ) ), dataSource, SLOT( findExecutionResourcesByName( QString, SelectionListItem * ) ) ); // Connect the data coming from the data server to the selector connect( dataSource, SIGNAL( foundAttributesByType( QString, QStringList, void * ) ), resourceSelector, SLOT( setAttributeList( QString, QStringList, void * ) ) ); connect( dataSource, SIGNAL( foundResourcesByType( QString, QMap<QString,int>, void * ) ), resourceSelector, SLOT( setTopLevelResources( QString, QMap<QString,int>, void * ) ) ); connect( dataSource, SIGNAL( foundResourcesByParent( QString, QMap<QString,int>, SelectionListItem * ) ), resourceSelector, SLOT( setChildResources( QString, QMap<QString,int>, SelectionListItem * ) ) ); connect( dataSource, SIGNAL( foundAttributesByName( QString, QStringList, SelectionListItem * ) ), resourceSelector, SLOT( setAttributeValues( QString, QStringList, SelectionListItem * ) ) ); connect( dataSource, SIGNAL( foundAttributesByResourceName( AttrListMap, SelectionListItem * ) ), resourceSelector, SLOT( setItemAttributesMap( AttrListMap, SelectionListItem * ) ) ); connect( dataSource, SIGNAL( foundExecutionResources( Q3ValueList<QPair<QString,QString> >, SelectionListItem * ) ), resourceSelector, SLOT( setItemExecutionResources( Q3ValueList<QPair<QString,QString> >, SelectionListItem * ) ) ); }