diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-05-03 00:27:28 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-05-03 00:27:28 +0200 |
commit | e1a530f84dce9b4c1b262669157359fbbd436428 (patch) | |
tree | cc372ad70b91977d1f038fe835a139cdf6bfb7d1 /api/gui/icons | |
parent | c50b3cdeec1ce30de7c67f62f026d689afe6930a (diff) | |
download | MultiMC-e1a530f84dce9b4c1b262669157359fbbd436428.tar MultiMC-e1a530f84dce9b4c1b262669157359fbbd436428.tar.gz MultiMC-e1a530f84dce9b4c1b262669157359fbbd436428.tar.lz MultiMC-e1a530f84dce9b4c1b262669157359fbbd436428.tar.xz MultiMC-e1a530f84dce9b4c1b262669157359fbbd436428.zip |
GH-1559 Fix FTB icons
This was caused by separation of GUI and logic. Now logic has an interface that GUI implements.
It should be expanded upon later.
Diffstat (limited to 'api/gui/icons')
-rw-r--r-- | api/gui/icons/IconList.cpp | 22 | ||||
-rw-r--r-- | api/gui/icons/IconList.h | 18 | ||||
-rw-r--r-- | api/gui/icons/MMCIcon.cpp | 32 | ||||
-rw-r--r-- | api/gui/icons/MMCIcon.h | 19 |
4 files changed, 42 insertions, 49 deletions
diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp index 99def3b7..4f9fb09f 100644 --- a/api/gui/icons/IconList.cpp +++ b/api/gui/icons/IconList.cpp @@ -33,7 +33,7 @@ IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstra for (auto file_info : file_info_list) { QString key = file_info.baseName(); - addIcon(key, key, file_info.absoluteFilePath(), MMCIcon::Builtin); + addIcon(key, key, file_info.absoluteFilePath(), IconType::Builtin); } m_watcher.reset(new QFileSystemWatcher()); @@ -70,9 +70,9 @@ void IconList::directoryChanged(const QString &path) QList<QString> current_list; for (auto &it : icons) { - if (!it.has(MMCIcon::FileBased)) + if (!it.has(IconType::FileBased)) continue; - current_list.push_back(it.m_images[MMCIcon::FileBased].filename); + current_list.push_back(it.m_images[IconType::FileBased].filename); } QSet<QString> current_set = current_list.toSet(); @@ -90,8 +90,8 @@ void IconList::directoryChanged(const QString &path) int idx = getIconIndex(key); if (idx == -1) continue; - icons[idx].remove(MMCIcon::FileBased); - if (icons[idx].type() == MMCIcon::ToBeDeleted) + icons[idx].remove(IconType::FileBased); + if (icons[idx].type() == IconType::ToBeDeleted) { beginRemoveRows(QModelIndex(), idx, idx); icons.remove(idx); @@ -111,7 +111,7 @@ void IconList::directoryChanged(const QString &path) qDebug() << "Adding " << add; QFileInfo addfile(add); QString key = addfile.baseName(); - if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased)) + if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased)) { m_watcher->addPath(add); emit iconUpdated(key); @@ -133,7 +133,7 @@ void IconList::fileChanged(const QString &path) if (!icon.availableSizes().size()) return; - icons[idx].m_images[MMCIcon::FileBased].icon = icon; + icons[idx].m_images[IconType::FileBased].icon = icon; dataChanged(index(idx), index(idx)); emit iconUpdated(key); } @@ -268,7 +268,7 @@ bool IconList::iconFileExists(QString key) { return false; } - return iconEntry->has(MMCIcon::FileBased); + return iconEntry->has(IconType::FileBased); } const MMCIcon *IconList::icon(QString key) @@ -285,14 +285,14 @@ bool IconList::deleteIcon(QString key) if (iconIdx == -1) return false; auto &iconEntry = icons[iconIdx]; - if (iconEntry.has(MMCIcon::FileBased)) + if (iconEntry.has(IconType::FileBased)) { - return QFile::remove(iconEntry.m_images[MMCIcon::FileBased].filename); + return QFile::remove(iconEntry.m_images[IconType::FileBased].filename); } return false; } -bool IconList::addIcon(QString key, QString name, QString path, MMCIcon::Type type) +bool IconList::addIcon(QString key, QString name, QString path, IconType type) { // replace the icon even? is the input valid? QIcon icon(path); diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h index 04dea2cd..7aeb7067 100644 --- a/api/gui/icons/IconList.h +++ b/api/gui/icons/IconList.h @@ -24,12 +24,13 @@ #include "MMCIcon.h" #include "settings/Setting.h" #include "Env.h" // there is a global icon list inside Env. +#include <icons/IIconList.h> #include "multimc_gui_export.h" class QFileSystemWatcher; -class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel +class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList { Q_OBJECT public: @@ -40,18 +41,17 @@ public: QIcon getBigIcon(QString key); int getIconIndex(QString key); - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; - bool addIcon(QString key, QString name, QString path, MMCIcon::Type type); + virtual bool addIcon(QString key, QString name, QString path, IconType type) override; bool deleteIcon(QString key); bool iconFileExists(QString key); - virtual QStringList mimeTypes() const; - virtual Qt::DropActions supportedDropActions() const; - virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, - const QModelIndex &parent); - virtual Qt::ItemFlags flags(const QModelIndex &index) const; + virtual QStringList mimeTypes() const override; + virtual Qt::DropActions supportedDropActions() const override; + virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; + virtual Qt::ItemFlags flags(const QModelIndex &index) const override; void installIcons(QStringList iconFiles); diff --git a/api/gui/icons/MMCIcon.cpp b/api/gui/icons/MMCIcon.cpp index 6b4eef39..f71281d0 100644 --- a/api/gui/icons/MMCIcon.cpp +++ b/api/gui/icons/MMCIcon.cpp @@ -16,19 +16,19 @@ #include "MMCIcon.h" #include <QFileInfo> -MMCIcon::Type operator--(MMCIcon::Type &t, int) +IconType operator--(IconType &t, int) { - MMCIcon::Type temp = t; + IconType temp = t; switch (t) { - case MMCIcon::Type::Builtin: - t = MMCIcon::Type::ToBeDeleted; + case IconType::Builtin: + t = IconType::ToBeDeleted; break; - case MMCIcon::Type::Transient: - t = MMCIcon::Type::Builtin; + case IconType::Transient: + t = IconType::Builtin; break; - case MMCIcon::Type::FileBased: - t = MMCIcon::Type::Transient; + case IconType::FileBased: + t = IconType::Transient; break; default: { @@ -37,7 +37,7 @@ MMCIcon::Type operator--(MMCIcon::Type &t, int) return temp; } -MMCIcon::Type MMCIcon::type() const +IconType MMCIcon::type() const { return m_current_type; } @@ -49,23 +49,23 @@ QString MMCIcon::name() const return m_key; } -bool MMCIcon::has(MMCIcon::Type _type) const +bool MMCIcon::has(IconType _type) const { return m_images[_type].present(); } QIcon MMCIcon::icon() const { - if (m_current_type == Type::ToBeDeleted) + if (m_current_type == IconType::ToBeDeleted) return QIcon(); return m_images[m_current_type].icon; } -void MMCIcon::remove(Type rm_type) +void MMCIcon::remove(IconType rm_type) { m_images[rm_type].filename = QString(); m_images[rm_type].icon = QIcon(); - for (auto iter = rm_type; iter != Type::ToBeDeleted; iter--) + for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--) { if (m_images[iter].present()) { @@ -73,13 +73,13 @@ void MMCIcon::remove(Type rm_type) return; } } - m_current_type = Type::ToBeDeleted; + m_current_type = IconType::ToBeDeleted; } -void MMCIcon::replace(MMCIcon::Type new_type, QIcon icon, QString path) +void MMCIcon::replace(IconType new_type, QIcon icon, QString path) { QFileInfo foo(path); - if (new_type > m_current_type || m_current_type == MMCIcon::ToBeDeleted) + if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) { m_current_type = new_type; } diff --git a/api/gui/icons/MMCIcon.h b/api/gui/icons/MMCIcon.h index 6f9617c2..4bc7ecdc 100644 --- a/api/gui/icons/MMCIcon.h +++ b/api/gui/icons/MMCIcon.h @@ -17,6 +17,7 @@ #include <QString> #include <QDateTime> #include <QIcon> +#include <icons/IIconList.h> #include "multimc_gui_export.h" @@ -33,23 +34,15 @@ struct MULTIMC_GUI_EXPORT MMCImage struct MULTIMC_GUI_EXPORT MMCIcon { - enum Type : unsigned - { - Builtin, - Transient, - FileBased, - ICONS_TOTAL, - ToBeDeleted - }; QString m_key; QString m_name; MMCImage m_images[ICONS_TOTAL]; - Type m_current_type = ToBeDeleted; + IconType m_current_type = ToBeDeleted; - Type type() const; + IconType type() const; QString name() const; - bool has(Type _type) const; + bool has(IconType _type) const; QIcon icon() const; - void remove(Type rm_type); - void replace(Type new_type, QIcon icon, QString path = QString()); + void remove(IconType rm_type); + void replace(IconType new_type, QIcon icon, QString path = QString()); }; |