void KNThemeManager::loadThemeFiles(const QString &themeDirPath) { //Clear the previous theme list. m_themeList.clear(); //Add the default theme as the first item in the list. addTheme("Default", "://configure/default.json", QPixmap()); //The structure of a theme directory. /* Theme * |-<Theme Name> * | |-<Theme Name>.json * | |-<Theme Name>.png */ //Check the folder exist. If no, return. QDir themeFolder(themeDirPath); if(!themeFolder.exists()) { return; } //Get all the folder in the theme folder. QFileInfoList folderList=themeFolder.entryInfoList(); for(QFileInfoList::const_iterator i=folderList.constBegin(); i!=folderList.constEnd(); ++i) { QString themeName=(*i).fileName(); //Ignore if the current info is not folder, dot(.) and dot-dot(..). if(!(*i).isDir() || themeName=="." || themeName=="..") { continue; } //Get the theme file and the preview image. QFileInfo themeFile((*i).absoluteFilePath()+"/"+themeName+".json"), previewFile((*i).absoluteFilePath()+"/"+themeName+".png"); if(themeFile.exists()) { //Check the preview image. QPixmap previewImage; if(previewFile.exists()) { previewImage.load(previewFile.absoluteFilePath()); if(previewImage.isNull()) { //! FIXME: Set the preview to no image. ; } } else { //! FIXME: Set the preview to no image. ; } //Add the new theme addTheme(themeName, themeFile.absoluteFilePath(), previewImage); } } }
bool MainWindow::setTheme(const QString &theme) { QString themeFolder(QCoreApplication::applicationDirPath() + "/themes/" + theme); QDir::setSearchPaths("images", QStringList() << themeFolder << ":/images/buttons/" << ":/images/"); QFile file(themeFolder + "/tibiaeye.qss"); if(file.open(QFile::ReadOnly)) { mTheme = theme; QString styleSheet = QLatin1String(file.readAll()); file.close(); setStyleSheet(styleSheet); return true; } qCritical() << qPrintable(tr("Failed opening theme \"%1\".").arg(theme)); return false; }