QTfrontend/model/ThemeModel.cpp
branchwebgl
changeset 8833 c13ebed437cb
parent 8475 f605bc59c603
child 9080 9b42757d7e71
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
    21  * @brief ThemeModel class implementation
    21  * @brief ThemeModel class implementation
    22  */
    22  */
    23 
    23 
    24 #include "physfs.h"
    24 #include "physfs.h"
    25 #include "ThemeModel.h"
    25 #include "ThemeModel.h"
       
    26 #include "hwconsts.h"
    26 
    27 
    27 ThemeModel::ThemeModel(QObject *parent) :
    28 ThemeModel::ThemeModel(QObject *parent) :
    28     QAbstractListModel(parent)
    29     QAbstractListModel(parent)
    29 {
    30 {
    30     m_data = QList<QMap<int, QVariant> >();
    31     m_data = QList<QMap<int, QVariant> >();
    48 }
    49 }
    49 
    50 
    50 
    51 
    51 void ThemeModel::loadThemes()
    52 void ThemeModel::loadThemes()
    52 {
    53 {
    53     const QString appDir = QString(PHYSFS_getBaseDir());
       
    54 
       
    55     beginResetModel();
    54     beginResetModel();
    56 
    55 
    57     DataManager & datamgr = DataManager::instance();
    56     DataManager & datamgr = DataManager::instance();
    58 
    57 
    59     QStringList themes =
    58     QStringList themes =
    75 
    74 
    76         QMap<int, QVariant> dataset;
    75         QMap<int, QVariant> dataset;
    77 
    76 
    78         // detect if theme is dlc
    77         // detect if theme is dlc
    79         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1/icon.png").arg(theme).toLocal8Bit().data());
    78         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1/icon.png").arg(theme).toLocal8Bit().data());
    80         dataset.insert(Qt::UserRole + 2, !themeDir.startsWith(appDir));
    79         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
       
    80         dataset.insert(IsDlcRole, isDLC);
    81 
    81 
    82         // set icon path
    82         // set icon path
    83         dataset.insert(Qt::UserRole + 1, iconpath);
    83         dataset.insert(IconPathRole, iconpath);
    84 
    84 
    85         // set name
    85         // set name
    86         dataset.insert(Qt::DisplayRole, theme);
    86         dataset.insert(ActualNameRole, theme);
    87 
    87 
    88         // load and set icon
    88         // set displayed name
    89         QIcon icon;
    89         dataset.insert(Qt::DisplayRole, (isDLC ? "*" : "") + theme);
    90         icon.addPixmap(QPixmap(iconpath), QIcon::Normal);
       
    91         icon.addPixmap(QPixmap(iconpath), QIcon::Disabled);
       
    92 
       
    93         dataset.insert(Qt::DecorationRole, icon);
       
    94 
    90 
    95         // load and set preview icon
    91         // load and set preview icon
    96         QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
    92         QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
    97         dataset.insert(Qt::UserRole, preview);
    93         dataset.insert(Qt::DecorationRole, preview);
    98 
    94 
    99         m_data.append(dataset);
    95         m_data.append(dataset);
   100     }
    96     }
   101 
    97 
   102 
    98