Skip to content

Commit

Permalink
Merge pull request #4034 from Holzhaus/sidebar-icon-name
Browse files Browse the repository at this point in the history
SidebarModel: Add basic support for icon names
  • Loading branch information
daschuer authored Jun 29, 2021
2 parents 521ab45 + 580153d commit e9fd98d
Show file tree
Hide file tree
Showing 38 changed files with 89 additions and 147 deletions.
3 changes: 1 addition & 2 deletions src/library/analysisfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ AnalyzerModeFlags getAnalyzerModeFlags(
AnalysisFeature::AnalysisFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
: LibraryFeature(pLibrary, pConfig),
: LibraryFeature(pLibrary, pConfig, QStringLiteral("prepare")),
m_baseTitle(tr("Analyze")),
m_icon(":/images/library/ic_library_prepare.svg"),
m_pTrackAnalysisScheduler(TrackAnalysisScheduler::NullPointer()),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_pAnalysisView(nullptr),
Expand Down
5 changes: 0 additions & 5 deletions src/library/analysisfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class AnalysisFeature : public LibraryFeature {
return m_title;
}

QIcon getIcon() override {
return m_icon;
}

bool dropAccept(const QList<QUrl>& urls, QObject* pSource) override;
bool dragMoveAccept(const QUrl& url) override;
void bindLibraryWidget(WLibrary* libraryWidget,
Expand Down Expand Up @@ -65,7 +61,6 @@ class AnalysisFeature : public LibraryFeature {
void setTitleProgress(int currentTrackNumber, int totalTracksCount);

const QString m_baseTitle;
const QIcon m_icon;

TrackAnalysisScheduler::Pointer m_pTrackAnalysisScheduler;

Expand Down
9 changes: 2 additions & 7 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ namespace {
AutoDJFeature::AutoDJFeature(Library* pLibrary,
UserSettingsPointer pConfig,
PlayerManagerInterface* pPlayerManager)
: LibraryFeature(pLibrary, pConfig),
: LibraryFeature(pLibrary, pConfig, QStringLiteral("autodj")),
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()),
m_playlistDao(m_pTrackCollection->getPlaylistDAO()),
m_iAutoDJPlaylistId(findOrCrateAutoDjPlaylistId(m_playlistDao)),
m_pAutoDJProcessor(nullptr),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_pAutoDJView(nullptr),
m_autoDjCratesDao(m_iAutoDJPlaylistId, pLibrary->trackCollectionManager(), m_pConfig),
m_icon(":/images/library/ic_library_autodj.svg") {
m_autoDjCratesDao(m_iAutoDJPlaylistId, pLibrary->trackCollectionManager(), m_pConfig) {
qRegisterMetaType<AutoDJProcessor::AutoDJState>("AutoDJState");
m_pAutoDJProcessor = new AutoDJProcessor(this,
m_pConfig,
Expand Down Expand Up @@ -111,10 +110,6 @@ QVariant AutoDJFeature::title() {
return tr("Auto DJ");
}

QIcon AutoDJFeature::getIcon() {
return m_icon;
}

void AutoDJFeature::bindLibraryWidget(
WLibrary* libraryWidget,
KeyboardEventFilter* keyboard) {
Expand Down
3 changes: 0 additions & 3 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <QAction>
#include <QIcon>
#include <QList>
#include <QModelIndex>
#include <QObject>
Expand Down Expand Up @@ -35,7 +34,6 @@ class AutoDJFeature : public LibraryFeature {
virtual ~AutoDJFeature();

QVariant title() override;
QIcon getIcon() override;

bool dropAccept(const QList<QUrl>& urls, QObject* pSource) override;
bool dragMoveAccept(const QUrl& url) override;
Expand Down Expand Up @@ -84,7 +82,6 @@ class AutoDJFeature : public LibraryFeature {
// auto-DJ list.
QAction *m_pRemoveCrateFromAutoDj;

QIcon m_icon;
QPointer<WLibrarySidebar> m_pSidebarWidget;

private slots:
Expand Down
9 changes: 2 additions & 7 deletions src/library/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ const QString BansheeFeature::BANSHEE_MOUNT_KEY = "mixxx.BansheeFeature.mount";
QString BansheeFeature::m_databaseFile;

BansheeFeature::BansheeFeature(Library* pLibrary, UserSettingsPointer pConfig)
: BaseExternalLibraryFeature(pLibrary, pConfig),
: BaseExternalLibraryFeature(pLibrary, pConfig, QStringLiteral("banshee")),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_cancelImport(false),
m_icon(":/images/library/ic_library_banshee.svg") {
m_cancelImport(false) {
Q_UNUSED(pConfig);
m_pBansheePlaylistModel = new BansheePlaylistModel(
this, m_pLibrary->trackCollectionManager(), &m_connection);
Expand Down Expand Up @@ -59,10 +58,6 @@ QVariant BansheeFeature::title() {
return m_title;
}

QIcon BansheeFeature::getIcon() {
return m_icon;
}

void BansheeFeature::activate() {
//qDebug("BansheeFeature::activate()");

Expand Down
2 changes: 0 additions & 2 deletions src/library/banshee/bansheefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class BansheeFeature : public BaseExternalLibraryFeature {
static void prepareDbPath(UserSettingsPointer pConfig);

virtual QVariant title();
virtual QIcon getIcon();

virtual TreeItemModel* sidebarModel() const;

Expand All @@ -50,7 +49,6 @@ class BansheeFeature : public BaseExternalLibraryFeature {
QFuture<TreeItem*> m_future;
QString m_title;
bool m_cancelImport;
QIcon m_icon;

static QString m_databaseFile;

Expand Down
5 changes: 3 additions & 2 deletions src/library/baseexternallibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ const mixxx::Logger kLogger("BaseExternalLibraryFeature");

BaseExternalLibraryFeature::BaseExternalLibraryFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
: LibraryFeature(pLibrary, pConfig),
UserSettingsPointer pConfig,
const QString& iconName)
: LibraryFeature(pLibrary, pConfig, iconName),
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()) {
m_pAddToAutoDJAction = make_parented<QAction>(tr("Add to Auto DJ Queue (bottom)"), this);
connect(m_pAddToAutoDJAction,
Expand Down
3 changes: 2 additions & 1 deletion src/library/baseexternallibraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class BaseExternalLibraryFeature : public LibraryFeature {
public:
BaseExternalLibraryFeature(
Library* pLibrary,
UserSettingsPointer pConfig);
UserSettingsPointer pConfig,
const QString& iconName);
~BaseExternalLibraryFeature() override = default;

public slots:
Expand Down
9 changes: 2 additions & 7 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ BrowseFeature::BrowseFeature(
Library* pLibrary,
UserSettingsPointer pConfig,
RecordingManager* pRecordingManager)
: LibraryFeature(pLibrary, pConfig),
: LibraryFeature(pLibrary, pConfig, QString("computer")),
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()),
m_browseModel(this, pLibrary->trackCollectionManager(), pRecordingManager),
m_proxyModel(&m_browseModel),
m_pSidebarModel(new FolderTreeModel(this)),
m_pLastRightClickedItem(nullptr),
m_icon(":/images/library/ic_library_computer.svg") {
m_pLastRightClickedItem(nullptr) {
connect(this,
&BrowseFeature::requestAddDir,
pLibrary,
Expand Down Expand Up @@ -214,10 +213,6 @@ void BrowseFeature::slotRemoveQuickLink() {
saveQuickLinks();
}

QIcon BrowseFeature::getIcon() {
return m_icon;
}

TreeItemModel* BrowseFeature::sidebarModel() const {
return m_pSidebarModel;
}
Expand Down
18 changes: 8 additions & 10 deletions src/library/browse/browsefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ class BrowseFeature : public LibraryFeature {
RecordingManager* pRecordingManager);
virtual ~BrowseFeature();

QVariant title();
QIcon getIcon();
QVariant title() override;

void bindLibraryWidget(WLibrary* libraryWidget,
KeyboardEventFilter* keyboard);
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget);
KeyboardEventFilter* keyboard) override;
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget) override;

TreeItemModel* sidebarModel() const;
TreeItemModel* sidebarModel() const override;

public slots:
void slotAddQuickLink();
void slotRemoveQuickLink();
void slotAddToLibrary();
void activate();
void activateChild(const QModelIndex& index);
void onRightClickChild(const QPoint& globalPos, const QModelIndex& index);
void onLazyChildExpandation(const QModelIndex& index);
void activate() override;
void activateChild(const QModelIndex& index) override;
void onRightClickChild(const QPoint& globalPos, const QModelIndex& index) override;
void onLazyChildExpandation(const QModelIndex& index) override;
void slotLibraryScanStarted();
void slotLibraryScanFinished();

Expand All @@ -73,6 +72,5 @@ class BrowseFeature : public LibraryFeature {
TreeItem* m_pLastRightClickedItem;
TreeItem* m_pQuickLinkItem;
QStringList m_quickLinkList;
QIcon m_icon;
QPointer<WLibrarySidebar> m_pSidebarWidget;
};
9 changes: 2 additions & 7 deletions src/library/itunes/itunesfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ QString localhost_token() {
} // anonymous namespace

ITunesFeature::ITunesFeature(Library* pLibrary, UserSettingsPointer pConfig)
: BaseExternalLibraryFeature(pLibrary, pConfig),
: BaseExternalLibraryFeature(pLibrary, pConfig, QStringLiteral("itunes")),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_cancelImport(false),
m_icon(":/images/library/ic_library_itunes.svg") {
m_cancelImport(false) {
QString tableName = "itunes_library";
QString idColumn = "id";
QStringList columns;
Expand Down Expand Up @@ -153,10 +152,6 @@ QVariant ITunesFeature::title() {
return m_title;
}

QIcon ITunesFeature::getIcon() {
return m_icon;
}

void ITunesFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
// store the sidebar widget pointer for later use in onRightClick()
m_pSidebarWidget = pSidebarWidget;
Expand Down
2 changes: 0 additions & 2 deletions src/library/itunes/itunesfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ITunesFeature : public BaseExternalLibraryFeature {
static bool isSupported();

QVariant title() override;
QIcon getIcon() override;
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget) override;

TreeItemModel* sidebarModel() const override;
Expand Down Expand Up @@ -70,5 +69,4 @@ class ITunesFeature : public BaseExternalLibraryFeature {

QSharedPointer<BaseTrackCache> m_trackSource;
QPointer<WLibrarySidebar> m_pSidebarWidget;
QIcon m_icon;
};
10 changes: 8 additions & 2 deletions src/library/libraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@
namespace {

const mixxx::Logger kLogger("LibraryFeature");
const QString kIconPath = QStringLiteral(":/images/library/ic_library_%1.svg");

} // anonymous namespace

LibraryFeature::LibraryFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
UserSettingsPointer pConfig,
const QString& iconName)
: QObject(pLibrary),
m_pLibrary(pLibrary),
m_pConfig(pConfig) {
m_pConfig(pConfig),
m_iconName(iconName) {
if (!m_iconName.isEmpty()) {
m_icon = QIcon(kIconPath.arg(m_iconName));
}
}

QStringList LibraryFeature::getPlaylistFiles(QFileDialog::FileMode mode) const {
Expand Down
21 changes: 19 additions & 2 deletions src/library/libraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ class LibraryFeature : public QObject {
public:
LibraryFeature(
Library* pLibrary,
UserSettingsPointer pConfig);
UserSettingsPointer pConfig,
const QString& iconName);
~LibraryFeature() override = default;

virtual QVariant title() = 0;
virtual QIcon getIcon() = 0;

/// Returns the icon name.
///
/// This is useful for QML skins that need to build a URL anyway and may use their own icon theme.
QString iconName() const {
return m_iconName;
}

/// Returns the icon.
///
/// This is used by legacy QWidget skins that display a QIcon directly.
QIcon icon() const {
return m_icon;
}

virtual bool dropAccept(const QList<QUrl>& urls, QObject* pSource) {
Q_UNUSED(urls);
Expand Down Expand Up @@ -134,4 +148,7 @@ class LibraryFeature : public QObject {

private:
QStringList getPlaylistFiles(QFileDialog::FileMode mode) const;

QString m_iconName;
QIcon m_icon;
};
7 changes: 1 addition & 6 deletions src/library/mixxxlibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ const QStringList DEFAULT_COLUMNS = {

MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary,
UserSettingsPointer pConfig)
: LibraryFeature(pLibrary, pConfig),
: LibraryFeature(pLibrary, pConfig, QStringLiteral("tracks")),
kMissingTitle(tr("Missing Tracks")),
kHiddenTitle(tr("Hidden Tracks")),
m_icon(":/images/library/ic_library_tracks.svg"),
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()),
m_pLibraryTableModel(nullptr),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
Expand Down Expand Up @@ -145,10 +144,6 @@ QVariant MixxxLibraryFeature::title() {
return tr("Tracks");
}

QIcon MixxxLibraryFeature::getIcon() {
return m_icon;
}

TreeItemModel* MixxxLibraryFeature::sidebarModel() const {
return m_pSidebarModel;
}
Expand Down
2 changes: 0 additions & 2 deletions src/library/mixxxlibraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MixxxLibraryFeature final : public LibraryFeature {
~MixxxLibraryFeature() override = default;

QVariant title() override;
QIcon getIcon() override;
bool dropAccept(const QList<QUrl>& urls, QObject* pSource) override;
bool dragMoveAccept(const QUrl& url) override;
TreeItemModel* sidebarModel() const override;
Expand Down Expand Up @@ -67,7 +66,6 @@ class MixxxLibraryFeature final : public LibraryFeature {
private:
const QString kMissingTitle;
const QString kHiddenTitle;
const QIcon m_icon;
TrackCollection* const m_pTrackCollection;

QSharedPointer<BaseTrackCache> m_pBaseTrackCache;
Expand Down
7 changes: 1 addition & 6 deletions src/library/recording/recordingfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ const QString kViewName = QStringLiteral("Recording");
RecordingFeature::RecordingFeature(Library* pLibrary,
UserSettingsPointer pConfig,
RecordingManager* pRecordingManager)
: LibraryFeature(pLibrary, pConfig),
: LibraryFeature(pLibrary, pConfig, QStringLiteral("recordings")),
m_pRecordingManager(pRecordingManager),
m_icon(":/images/library/ic_library_recordings.svg"),
m_pSidebarModel(new FolderTreeModel(this)) {
}

QVariant RecordingFeature::title() {
return QVariant(tr("Recordings"));
}

QIcon RecordingFeature::getIcon() {
return m_icon;
}

TreeItemModel* RecordingFeature::sidebarModel() const {
return m_pSidebarModel;
}
Expand Down
2 changes: 0 additions & 2 deletions src/library/recording/recordingfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class RecordingFeature final : public LibraryFeature {
~RecordingFeature() override = default;

QVariant title() override;
QIcon getIcon() override;

void bindLibraryWidget(WLibrary* libraryWidget,
KeyboardEventFilter* keyboard) override;
Expand All @@ -37,7 +36,6 @@ class RecordingFeature final : public LibraryFeature {

private:
RecordingManager* const m_pRecordingManager;
const QIcon m_icon;

FolderTreeModel* m_pSidebarModel;
};
Loading

0 comments on commit e9fd98d

Please sign in to comment.