//------------------------------------------------------------------------------------ OFS::ofs64 ExtractThread::generateList(OFS::FileList& list) { unsigned int list_max = list.size(); OFS::ofs64 file_size = 0; std::string tmpSaveCurrentDir; OFS::FileList subList; for(unsigned int i = 0;i < list_max;i++) { list[i].name = currentDir + list[i].name; file_size += list[i].file_size; if(list[i].flags & OFS::OFS_DIR) { tmpSaveCurrentDir = currentDir; currentDir = list[i].name + "/"; subList = ofsFile->listFiles(currentDir.c_str()); file_size += generateList(subList); for(unsigned int z = 0;z < subList.size();z++) list.push_back(subList[z]); currentDir = tmpSaveCurrentDir; } } return file_size; }
//---------------------------------------------------------------------------------------- void OfsTreeWidget::fillTree(QTreeWidgetItem *pItem, std::string path) { OFS::FileList list = mFile->listFiles(path.c_str(), OFS::OFS_DIR); std::sort(list.begin(), list.end(), OFS::FileEntry::Compare); for(unsigned int i = 0;i < list.size();i++) { Ogre::String name = list[i].name; QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str()))); item->setIcon(0, mOgitorMainWindow->mIconProvider.icon(QFileIconProvider::Folder)); item->setTextColor(0, Qt::blue); std::string fullpath = path + name + "/"; item->setWhatsThis(0, QString(fullpath.c_str())); if(mCapabilities & CAP_SHOW_COLORS) { bool isReadOnly = (list[i].flags & OFS::OFS_READONLY) > 0; bool isHidden = (list[i].flags & OFS::OFS_HIDDEN) > 0; QColor textColor = Qt::black; if(isReadOnly && isHidden) textColor = QColor(255, 210, 210); else if(isReadOnly) textColor = QColor(255, 0, 0); else if(isHidden) textColor = QColor(210, 210, 210); if(list[i].flags & OFS::OFS_LINK) textColor.setBlue(255); item->setTextColor(0, textColor); } pItem->addChild(item); mItemMap.insert(NameTreeWidgetMap::value_type(fullpath, item)); fillTree(item, fullpath); } if(path != "/" && list.size() == 0) { QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("."))); item->setTextColor(0, Qt::black); item->setWhatsThis(0, QString(path.c_str())); pItem->addChild(item); } }
//----------------------------------------------------------------------------- void Ogitors::COFSSceneSerializer::_upgradeOgsceneFileFrom3To4(TiXmlNode* ogsceneRootNode) { TiXmlElement* element = ogsceneRootNode->FirstChildElement(); OFS::OfsPtr& mFile = OgitorsRoot::getSingletonPtr()->GetProjectFile(); OgitorsSystem *mSystem = OgitorsSystem::getSingletonPtr(); OFS::FileList list; mFile->listFilesRecursive("/", list); Ogre::StringVector terFiles; for( unsigned int i = 0;i < list.size(); i++ ) { if(list[i].flags && OFS::OFS_FILE) { if(list[i].name.substr(list[i].name.size() - 4, 4) == ".ogt") { terFiles.push_back( list[i].name ); } } } if( terFiles.size() > 0 ) { Ogre::SceneManager *pUpgSM = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "UpgradeSCM"); for( unsigned int i = 0;i < terFiles.size(); i++ ) { Ogre::String filenameorig = terFiles[i]; Ogre::String filenamebackup = filenameorig + ".backup"; mFile->renameFile( filenameorig.c_str(), filenamebackup.c_str() ); OFS::OFSHANDLE *filebackup = new OFS::OFSHANDLE(); OFS::OFSHANDLE *fileorig = new OFS::OFSHANDLE(); mFile->createFile(*fileorig, filenameorig.c_str()); mFile->openFile(*filebackup, filenamebackup.c_str(), OFS::OFS_READ); { OgreTerrainConverter conv; Ogre::DataStreamPtr stream_in = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mFile, filebackup)); Ogre::DataStreamPtr stream_out = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mFile, fileorig)); Ogre::DataStreamPtr compressStream(OGRE_NEW Ogre::DeflateStream(filenameorig, stream_in)); Ogre::StreamSerialiser ser_in(compressStream); Ogre::StreamSerialiser ser_out(stream_out); conv.Upgrade( ser_in, ser_out ); } } Ogre::Root::getSingletonPtr()->destroySceneManager(pUpgSM); } }
//---------------------------------------------------------------------------- void extractOFS(Ogre::String path) { unsigned int MAX_BUFFER_SIZE = 16 * 1024 * 1024; char *tmp_buffer = new char[MAX_BUFFER_SIZE]; OFS::OfsPtr& ofsFile = OgitorsRoot::getSingletonPtr()->GetProjectFile(); OFS::FileList list; ofsFile->listFilesRecursive("/", list); std::sort(list.begin(), list.end(), OFS::FileEntry::Compare); std::ofstream out_handle; OFS::OFSHANDLE in_handle; for(unsigned int i = 0; i < list.size(); i++) { std::string file_path = path + list[i].name; if(list[i].flags & OFS::OFS_DIR) { OgitorsSystem::getSingletonPtr()->MakeDirectory(file_path); } else { std::string file_ofs_path = list[i].name; out_handle.open(file_path.c_str(), std::ofstream::out | std::ofstream::binary); if(out_handle.is_open()) { try { OFS::OfsResult ret = ofsFile->openFile(in_handle, file_ofs_path.c_str()); if(ret != OFS::OFS_OK) { out_handle.close(); continue; } unsigned int total = list[i].file_size; while(total > 0) { if(total < MAX_BUFFER_SIZE) { ofsFile->read(in_handle, tmp_buffer, total); out_handle.write(tmp_buffer, total); total = 0; } else { ofsFile->read(in_handle, tmp_buffer, MAX_BUFFER_SIZE); out_handle.write(tmp_buffer, MAX_BUFFER_SIZE); total -= MAX_BUFFER_SIZE; } } } catch(OFS::Exception&) { } out_handle.close(); ofsFile->closeFile(in_handle); } } } delete [] tmp_buffer; }
//------------------------------------------------------------------------------------ void ExtractThread::extractFiles(QString path, const OFS::FileList& list) { std::ofstream out_handle; OFS::OFSHANDLE in_handle; unsigned int output_amount = 0; mutex.lock(); currentPos = 0.0f; msgProgress = ""; mutex.unlock(); for(unsigned int i = 0;i < list.size();i++) { if(list[i].flags & OFS::OFS_DIR) { QString dir_path = path + QString("/") + QString(list[i].name.c_str()); QDir directory(dir_path); directory.mkpath(dir_path); } else { std::string file_path = path.toStdString() + std::string("/") + list[i].name; std::string file_ofs_path = list[i].name; QFileInfo info(QString(file_path.c_str())); QDir directory(info.absolutePath()); directory.mkpath(info.absolutePath()); mutex.lock(); msgProgress = file_ofs_path.c_str(); mutex.unlock(); out_handle.open(file_path.c_str(), std::ofstream::out | std::ofstream::binary); if(out_handle.is_open()) { try { OFS::OfsResult ret = ofsFile->openFile(in_handle, file_ofs_path.c_str()); if(ret != OFS::OFS_OK) { out_handle.close(); continue; } unsigned int total = list[i].file_size; while(total > 0) { if(total < MAX_BUFFER_SIZE) { ofsFile->read(in_handle, tmp_buffer, total); out_handle.write(tmp_buffer, total); output_amount += total; total = 0; } else { ofsFile->read(in_handle, tmp_buffer, MAX_BUFFER_SIZE); out_handle.write(tmp_buffer, MAX_BUFFER_SIZE); total -= MAX_BUFFER_SIZE; output_amount += MAX_BUFFER_SIZE; } if(mTotalFileSize > 0) { mutex.lock(); currentPos = (float)output_amount / (float)mTotalFileSize; mutex.unlock(); } } } catch(OFS::Exception& e) { QMessageBox::information(QApplication::activeWindow(),"Ofs Exception:", tr("Error Extracting File : ") + QString(file_ofs_path.c_str()) + QString("\n") + QString(e.getDescription().c_str()), QMessageBox::Ok); } out_handle.close(); ofsFile->closeFile(in_handle); } } } mutex.lock(); currentPos = 1.0f; msgProgress = tr("Finished Extracting"); mutex.unlock(); }
//------------------------------------------------------------------------------------ void MainWindow::showFiles() { while(mFileListWidget->rowCount() > 0) mFileListWidget->removeRow(0); mCurrentFiles.clear(); QIcon folderIcon = mIconProvider.icon(QFileIconProvider::Folder); if(mOfsFile.valid()) { OFS::FileList dirs = mOfsFile->listFiles(mCurrentDir.c_str(), OFS::OFS_DIR); OFS::FileList files = mOfsFile->listFiles(mCurrentDir.c_str(), OFS::OFS_FILE); std::sort(dirs.begin(), dirs.end(), OFS::FileEntry::Compare); std::sort(files.begin(), files.end(), OFS::FileEntry::Compare); int current_row = 0; if(mCurrentDir.size() > 1) { mFileListWidget->insertRow(current_row); mFileListWidget->setRowHeight(current_row, mRowHeight); QTableWidgetItem *witem = new QTableWidgetItem(folderIcon, QString("..")); mFileListWidget->setItem(0, 0, witem); witem = new QTableWidgetItem(""); mFileListWidget->setItem(current_row, 1, witem); witem = new QTableWidgetItem(tr("Directory")); mFileListWidget->setItem(current_row, 2, witem); witem = new QTableWidgetItem(""); mFileListWidget->setItem(current_row, 3, witem); witem = new QTableWidgetItem(""); mFileListWidget->setItem(current_row, 4, witem); current_row++; OFS::FileEntry updata; updata.flags = OFS::OFS_DIR; updata.name = ".."; updata.file_size = 0; mCurrentFiles.push_back(updata); } mDirUpButton->setEnabled(mCurrentDir.size() > 1); for(unsigned int i = 0;i < dirs.size();i++) { mFileListWidget->insertRow(current_row); mFileListWidget->setRowHeight(current_row, mRowHeight); bool isReadOnly = (dirs[i].flags & OFS::OFS_READONLY) > 0; bool isHidden = (dirs[i].flags & OFS::OFS_HIDDEN) > 0; if(isHidden && (actViewShowHidden->isChecked() == false)) continue; QColor textColor = Qt::black; if(isReadOnly && isHidden) textColor = QColor(255, 210, 210); else if(isReadOnly) textColor = QColor(255, 0, 0); else if(isHidden) textColor = QColor(210, 210, 210); QTableWidgetItem *witem = new QTableWidgetItem(folderIcon, QString(dirs[i].name.c_str())); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 0, witem); witem = new QTableWidgetItem(""); mFileListWidget->setItem(current_row, 1, witem); witem = new QTableWidgetItem(tr("Directory")); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 2, witem); witem = new QTableWidgetItem(QDateTime::fromTime_t(dirs[i].create_time).toString()); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 3, witem); witem = new QTableWidgetItem(QString("{ ") + QString(dirs[i].uuid.toString().c_str()) + QString(" }")); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 4, witem); current_row++; mCurrentFiles.push_back(dirs[i]); } for(unsigned int i = 0;i < files.size();i++) { mFileListWidget->insertRow(current_row); mFileListWidget->setRowHeight(current_row, mRowHeight); std::string ext_name = files[i].name; bool isReadOnly = (files[i].flags & OFS::OFS_READONLY) > 0; bool isHidden = (files[i].flags & OFS::OFS_HIDDEN) > 0; if(isHidden && (actViewShowHidden->isChecked() == false)) continue; QColor textColor = Qt::black; if(isReadOnly && isHidden) textColor = QColor(255, 210, 210); else if(isReadOnly) textColor = QColor(255, 0, 0); else if(isHidden) textColor = QColor(210, 210, 210); QIcon icon = mUnknownFileIcon; int ext_pos = ext_name.find_last_of("."); if(ext_pos > 0) { ext_name.erase(0, ext_pos); FileIconMap::iterator it = mFileIconMap.find(ext_name); if(it == mFileIconMap.end()) { std::string filename = "./qtOfs_icontest"; filename += ext_name; std::fstream stream; stream.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::trunc); stream.close(); QFileInfo info(QString(filename.c_str())); icon = mIconProvider.icon(info); if(icon.isNull()) icon = mUnknownFileIcon; mFileIconMap.insert(FileIconMap::value_type(ext_name, icon)); QFile::remove(QString(filename.c_str())); } else icon = it->second; } QTableWidgetItem *witem = new QTableWidgetItem(icon, QString(files[i].name.c_str())); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 0, witem); unsigned int file_size = files[i].file_size; QString size_str = QString("%1").arg(file_size); int len = size_str.length(); int runs = (len - 1) / 3; for(int j = 0;j < runs;j++) { size_str.insert(len - (3 * j) - 3, '.'); } witem = new QTableWidgetItem(size_str + QString(" ")); witem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 1, witem); witem = new QTableWidgetItem(tr("File")); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 2, witem); witem = new QTableWidgetItem(QDateTime::fromTime_t(files[i].create_time).toString()); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 3, witem); witem = new QTableWidgetItem(QString("{ ") + QString(files[i].uuid.toString().c_str()) + QString(" }")); witem->setTextColor(textColor); mFileListWidget->setItem(current_row, 4, witem); ++current_row; mCurrentFiles.push_back(files[i]); } if(mCurrentDir.size() > 1) --current_row; mTotalEntriesLabel->setText(tr("Total Entries : ") + QString("%1").arg(current_row)); mDirectoryDisplay->setText(QString(mCurrentDir.c_str())); } }
//----------------------------------------------------------------------------------------- bool CTerrainGroupEditor::load(bool async) { if(mLoaded->get()) return true; if(!getParent()->load()) return false; Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::String terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory; terrainDir = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + terrainDir + "/"; mngr->addResourceLocation(terrainDir + "textures/normalheight", "Ofs", "TerrainGroupNormalHeight"); mngr->initialiseResourceGroup("TerrainGroupNormalHeight"); mngr->addResourceLocation(terrainDir + "textures/diffusespecular", "Ofs", "TerrainGroupDiffuseSpecular"); mngr->initialiseResourceGroup("TerrainGroupDiffuseSpecular"); mngr->addResourceLocation(terrainDir + "plants", "Ofs", "TerrainGroupPlants"); mngr->initialiseResourceGroup("TerrainGroupPlants"); OgitorsRoot::getSingletonPtr()->PrepareTerrainResources(); OgitorsRoot::getSingletonPtr()->ReloadUserResources(); mDecalFrustum = OGRE_NEW Ogre::Frustum(); mDecalNode = getSceneManager()->getRootSceneNode()->createChildSceneNode("OgitorTerrainDecalNode"); mDecalNode->setPosition(99999, -99999, 99999); mDecalNode->attachObject(mDecalFrustum); mDecalFrustum->setProjectionType(Ogre::PT_ORTHOGRAPHIC); mDecalNode->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X)); mDecalFrustum->setFOVy(Ogre::Degree(45)); mDecalFrustum->setNearClipDistance(10); mDecalFrustum->setOrthoWindow(10, 10); mDecalFrustum->setVisible(false); mDecalTexture = Ogre::TextureManager::getSingletonPtr()->createManual("OgitorDecalTexture", "TerrainResources", Ogre::TEX_TYPE_2D, 256, 256, 1, 1, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY, this); mBrushData = OGRE_ALLOC_T(float, BRUSH_DATA_SIZE * BRUSH_DATA_SIZE, Ogre::MEMCATEGORY_GEOMETRY); mTerrainGlobalOptions->setMaxPixelError(mMaxPixelError->get()); mTerrainGlobalOptions->setCompositeMapSize(mCompositeMapTextureSize->get()); mTerrainGlobalOptions->setCompositeMapDistance(mCompositeMapDistance->get()); mTerrainGlobalOptions->setLightMapSize(mLightMapTextureSize->get()); mTerrainGlobalOptions->setLayerBlendMapSize(mBlendMapTextureSize->get()); mTerrainGlobalOptions->setUseVertexCompressionWhenAvailable(false); mTerrainGlobalOptions->setSkirtSize(mSkirtSize->get()); mTerrainGlobalOptions->setUseRayBoxDistanceCalculation(mUseRayBoxDistanceCalculation->get()); if(mMaterialGeneratorType->get() == 1) { Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorC(this, mDecalFrustum)); mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr); mMaxLayersAllowed = 10; } else { Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorB(this, mDecalFrustum)); mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr); mMaxLayersAllowed = 6; } CSceneManagerEditor *mSceneMgr = static_cast<CSceneManagerEditor*>(mOgitorsRoot->GetSceneManagerEditor()); if(mSceneMgr->getShadowsEnabled()) { if(mMaterialGeneratorType->get() == 1) { Ogre::TerrainMaterialGeneratorC::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorC::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile()); matProfile->setReceiveDynamicShadowsEnabled(true); matProfile->setReceiveDynamicShadowsLowLod(false); matProfile->setReceiveDynamicShadowsDepth(true); matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get())); } else { Ogre::TerrainMaterialGeneratorB::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorB::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile()); matProfile->setReceiveDynamicShadowsEnabled(true); matProfile->setReceiveDynamicShadowsLowLod(false); matProfile->setReceiveDynamicShadowsDepth(true); matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get())); } } CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::enabled", CTerrainGroupEditor, onShadowsChange, mShadowsConnection[0]); CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::technique", CTerrainGroupEditor, onShadowsTechniqueChange, mShadowsConnection[1]); mHandle = OGRE_NEW Ogre::TerrainGroup(mOgitorsRoot->GetSceneManager(), Ogre::Terrain::ALIGN_X_Z, mMapSize->get(), mWorldSize->get()); mHandle->setOrigin(Ogre::Vector3::ZERO); mHandle->setResourceGroup("TerrainResources"); mHandle->setFilenameConvention(mPageNamePrefix->get(), "ogt"); StaticGroupPtr = mHandle; mPGHandle = new PagedGeometry(mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera(), mPGPageSize->get()); mPGHandle->addDetailLevel<GrassPage>(mPGDetailDistance->get()); //Create a GrassLoader object mGrassLoaderHandle = new GrassLoader(mPGHandle); mGrassLoaderHandle->setVisibilityFlags(1 << mLayer->get()); //Assign the "grassLoader" to be used to load geometry for the PagedGrass instance mPGHandle->setPageLoader(mGrassLoaderHandle); //Supply a height function to GrassLoader so it can calculate grass Y values mGrassLoaderHandle->setHeightFunction(OgitorTerrainGroupHeightFunction); Ogre::Vector3 vDir; Ogre::ColourValue cDiffuse; Ogre::SceneManager::MovableObjectIterator mit = mOgitorsRoot->GetSceneManager()->getMovableObjectIterator("Light"); while(mit.hasMoreElements()) { Ogre::Light *l = static_cast<Ogre::Light*>(mit.getNext()); if(l->getType() == Ogre::Light::LT_DIRECTIONAL && l->getCastShadows()) { vDir = l->getDerivedDirection(); cDiffuse = l->getDiffuseColour(); break; } } mTerrainGlobalOptions->setLightMapDirection(vDir); mTerrainGlobalOptions->setCompositeMapAmbient(mOgitorsRoot->GetSceneManager()->getAmbientLight()); mTerrainGlobalOptions->setCompositeMapDiffuse(cDiffuse); terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory + "/terrain/"; OFS::FileList TGAList = mOgitorsRoot->GetProjectFile()->listFiles(terrainDir.c_str(), OFS::OFS_FILE); for(unsigned int t = 0; t < TGAList.size(); t++) { int pos = TGAList[t].name.find("_density.tga"); if(pos > 0) { Ogre::Image _img; Ogre::String sLoc = terrainDir + TGAList[t].name; // Block to ensure streams are freed when exiting the block { OFS::OFSHANDLE *iHandle = new OFS::OFSHANDLE(); mOgitorsRoot->GetProjectFile()->openFile( *iHandle, sLoc.c_str() ); Ogre::DataStreamPtr img_stream = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mOgitorsRoot->GetProjectFile(), iHandle)); _img.load(img_stream); } Ogre::String nLoc = terrainDir + TGAList[t].name.substr(0, pos); nLoc += "_density.png"; OgitorsUtils::SaveImageOfs( _img, nLoc ); mOgitorsRoot->GetProjectFile()->deleteFile( sLoc.c_str() ); } } registerForUpdates(); mLoaded->set(true); return true; }
//---------------------------------------------------------------------------------------- void OfsTreeWidget::fillRecycleBin(QTreeWidgetItem *pItem) { OFS::FileList list = mFile->listRecycleBinFiles(); if( list.size() > 0 ) pItem->setIcon(0, QIcon(":/icons/recyclebin_full.svg")); else pItem->setIcon(0, QIcon(":/icons/recyclebin_empty.svg")); std::sort(list.begin(), list.end(), OFS::FileEntry::Compare); for(unsigned int i = 0;i < list.size();i++) { Ogre::String name = list[i].name; Ogre::String ext_name = name; QIcon icon = mUnknownFileIcon; if( list[i].flags & OFS::OFS_DIR ) icon = mOgitorMainWindow->mIconProvider.icon(QFileIconProvider::Folder); else { int ext_pos = ext_name.find_last_of("."); if(ext_pos > 0) { ext_name.erase(0, ext_pos); FileIconMap::iterator it = mOgitorMainWindow->mFileIconMap.find(ext_name); if(it == mOgitorMainWindow->mFileIconMap.end()) { std::string filename = "./qtOgitor_icontest"; filename += ext_name; std::fstream stream; stream.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::trunc); stream.close(); QFileInfo info(QString(filename.c_str())); icon = mOgitorMainWindow->mIconProvider.icon(info); if(icon.isNull()) icon = mUnknownFileIcon; mOgitorMainWindow->mFileIconMap.insert(FileIconMap::value_type(ext_name, icon)); QFile::remove(QString(filename.c_str())); } else icon = it->second; } } QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str()))); item->setIcon(0, icon); item->setTextColor(0, Qt::black); item->setWhatsThis(0, QString("%1").arg(list[i].id)); item->setToolTip(0, QString(name.c_str()) + QString(" (%1)").arg(list[i].id)); pItem->addChild(item); } }
//---------------------------------------------------------------------------------------- void OfsTreeWidget::fillTreeFiles(QTreeWidgetItem *pItem, std::string path) { OFS::FileList list = mFile->listFiles(path.c_str(), OFS::OFS_FILE); std::sort(list.begin(), list.end(), OFS::FileEntry::Compare); for(unsigned int i = 0;i < list.size();i++) { Ogre::String name = list[i].name; Ogre::String ext_name = name; QIcon icon = mUnknownFileIcon; int ext_pos = ext_name.find_last_of("."); if(ext_pos > 0) { ext_name.erase(0, ext_pos); FileIconMap::iterator it = mOgitorMainWindow->mFileIconMap.find(ext_name); if(it == mOgitorMainWindow->mFileIconMap.end()) { std::string filename = "./qtOgitor_icontest"; filename += ext_name; std::fstream stream; stream.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::trunc); stream.close(); QFileInfo info(QString(filename.c_str())); icon = mOgitorMainWindow->mIconProvider.icon(info); if(icon.isNull()) icon = mUnknownFileIcon; mOgitorMainWindow->mFileIconMap.insert(FileIconMap::value_type(ext_name, icon)); QFile::remove(QString(filename.c_str())); } else icon = it->second; } QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str()))); item->setIcon(0, icon); item->setTextColor(0, Qt::black); std::string fullpath = path + name; item->setWhatsThis(0, QString(fullpath.c_str())); if(mCapabilities & CAP_SHOW_COLORS) { bool isReadOnly = (list[i].flags & OFS::OFS_READONLY) > 0; bool isHidden = (list[i].flags & OFS::OFS_HIDDEN) > 0; QColor textColor = Qt::black; if(isReadOnly && isHidden) textColor = QColor(255, 210, 210); else if(isReadOnly) textColor = QColor(255, 0, 0); else if(isHidden) textColor = QColor(210, 210, 210); if(list[i].flags & OFS::OFS_LINK) textColor.setBlue(255); item->setTextColor(0, textColor); } pItem->addChild(item); mItemMap.insert(NameTreeWidgetMap::value_type(fullpath, item)); } }