diff --git a/egg-player.pri b/egg-player.pri index 369f683..83b8bd0 100644 --- a/egg-player.pri +++ b/egg-player.pri @@ -1,6 +1,6 @@ RC_ICONS = resource/images/egg/egg.ico -VERSION = 0.1.3.14 +VERSION = 0.1.4.0 QMAKE_TARGET = Egg Player QMAKE_TARGET_PRODUCT = Egg Player diff --git a/src/core/cache.hpp b/src/core/cache.hpp index 017f5ec..a745c18 100644 --- a/src/core/cache.hpp +++ b/src/core/cache.hpp @@ -25,6 +25,7 @@ class Cache bool insertCover(Audio *audio, int size = 200); bool contains(Audio *audio); + QPixmap cover(Audio *audio, int size = 200); private: diff --git a/src/core/config.cpp b/src/core/config.cpp index 3768b83..1eb8f51 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -17,7 +17,7 @@ void Config::App::setFontSize(double size) */ double Config::App::fontSize() { - return app()["fontSize"].toDouble(); + return app().value("fontSize").toDouble(); } /* @@ -37,7 +37,7 @@ void Config::App::setLog(bool log) */ bool Config::App::log() { - return app()["log"].toBool(); + return app().value("log").toBool(); } /* @@ -57,7 +57,7 @@ void Config::Bar::setGrooveHeight(int height) */ int Config::Bar::grooveHeight() { - return makeEven(scale(bar()["grooveHeight"].toInt())); + return makeEven(scale(bar().value("grooveHeight").toInt())); } /* @@ -77,7 +77,7 @@ void Config::Bar::setHandleSize(int size) */ int Config::Bar::handleSize() { - return makeEven(scale(bar()["handleSize"].toInt())); + return makeEven(scale(bar().value("handleSize").toInt())); } /* @@ -97,7 +97,7 @@ void Config::Bar::setHeight(int height) */ int Config::Bar::height() { - return makeEven(scale(bar()["height"].toInt())); + return makeEven(scale(bar().value("height").toInt())); } /* @@ -117,7 +117,7 @@ void Config::Bar::setIconSize(int size) */ int Config::Bar::iconSize() { - return makeEven(scale(bar()["iconSize"].toInt())); + return makeEven(scale(bar().value("iconSize").toInt())); } /* @@ -137,7 +137,7 @@ void Config::Bar::setMargin(int margin) */ int Config::Bar::margin() { - return scale(bar()["margin"].toInt()); + return scale(bar().value("margin").toInt()); } /* @@ -157,7 +157,7 @@ void Config::Bar::setSpacing(int spacing) */ int Config::Bar::spacing() { - return scale(bar()["spacing"].toInt()); + return scale(bar().value("spacing").toInt()); } /* @@ -187,7 +187,7 @@ void Config::Bar::setTimeWidth(int width) */ int Config::Bar::timeWidth() { - return scale(bar()["timeWidth"].toInt()); + return scale(bar().value("timeWidth").toInt()); } /* @@ -207,7 +207,7 @@ void Config::Bar::setTrackWidth(int width) */ int Config::Bar::trackWidth() { - return scale(bar()["trackWidth"].toInt()); + return scale(bar().value("trackWidth").toInt()); } /* @@ -227,7 +227,7 @@ void Config::Library::setCellPadding(int padding) */ int Config::Library::cellPadding() { - return scale(library()["cellPadding"].toInt()); + return scale(library().value("cellPadding").toInt()); } /* @@ -247,7 +247,7 @@ void Config::Library::setItemHeight(int height) */ int Config::Library::itemHeight() { - return scale(library()["itemHeight"].toInt()); + return scale(library().value("itemHeight").toInt()); } /* @@ -272,7 +272,7 @@ void Config::Library::setPaths(const StringList &paths) StringList Config::Library::paths() { StringList list; - for (const QJsonValue &element : library()["paths"].toArray()) + for (const QJsonValue &element : library().value("paths").toArray()) list << element.toString(); return list; @@ -295,7 +295,7 @@ void Config::Library::setScrollBarWidth(int width) */ int Config::Library::scrollBarWidth() { - return scale(library()["scrollBarWidth"].toInt()); + return scale(library().value("scrollBarWidth").toInt()); } /* @@ -315,7 +315,7 @@ void Config::Player::setLoop(bool loop) */ bool Config::Player::loop() { - return player()["loop"].toBool(); + return player().value("loop").toBool(); } /* @@ -335,7 +335,7 @@ void Config::Player::setShuffle(bool shuffle) */ bool Config::Player::shuffle() { - return player()["shuffle"].toBool(); + return player().value("shuffle").toBool(); } /* @@ -355,7 +355,7 @@ void Config::Player::setVolume(int volume) */ int Config::Player::volume() { - return player()["volume"].toInt(); + return player().value("volume").toInt(); } /* @@ -375,7 +375,7 @@ void Config::Shortcut::setNext(const QString &shortcut) */ QString Config::Shortcut::next() { - return shortcut()["next"].toString(); + return shortcut().value("next").toString(); } /* @@ -395,7 +395,7 @@ void Config::Shortcut::setPlayPause(const QString &shortcut) */ QString Config::Shortcut::playPause() { - return shortcut()["playPause"].toString(); + return shortcut().value("playPause").toString(); } /* @@ -415,7 +415,7 @@ void Config::Shortcut::setPrevious(const QString &shortcut) */ QString Config::Shortcut::previous() { - return shortcut()["previous"].toString(); + return shortcut().value("previous").toString(); } /* @@ -435,7 +435,7 @@ void Config::Shortcut::setVolumeDown(const QString &shortcut) */ QString Config::Shortcut::volumeDown() { - return shortcut()["volumeDown"].toString(); + return shortcut().value("volumeDown").toString(); } /* @@ -455,7 +455,7 @@ void Config::Shortcut::setVolumeUp(const QString &shortcut) */ QString Config::Shortcut::volumeUp() { - return shortcut()["volumeUp"].toString(); + return shortcut().value("volumeUp").toString(); } /* @@ -464,11 +464,11 @@ QString Config::Shortcut::volumeUp() void Config::saveObjects() { QJsonObject object = _json.object(); - object["app"] = _app; - object["bar"] = _bar; - object["library"] = _library; - object["player"] = _player; - object["shortcut"] = _shortcut; + object.insert("app", _app); + object.insert("bar", _bar); + object.insert("library", _library); + object.insert("player", _player); + object.insert("shortcut", _shortcut); _json.setObject(object); } @@ -478,11 +478,11 @@ void Config::saveObjects() void Config::loadObjects() { QJsonObject object = _json.object(); - _app = object["app"].toObject(); - _bar = object["bar"].toObject(); - _library = object["library"].toObject(); - _player = object["player"].toObject(); - _shortcut = object["shortcut"].toObject(); + _app = object.value("app").toObject(); + _bar = object.value("bar").toObject(); + _library = object.value("library").toObject(); + _player = object.value("player").toObject(); + _shortcut = object.value("shortcut").toObject(); } /* @@ -590,7 +590,7 @@ QJsonObject & Config::shortcut() */ void Config::setValue(QJsonObject &object, const QString &key, const QJsonValue &value) { - object[key] = value; + object.insert(key, value); save(); } diff --git a/src/core/library.cpp b/src/core/library.cpp index 44ea98e..83152c2 100644 --- a/src/core/library.cpp +++ b/src/core/library.cpp @@ -51,7 +51,8 @@ Library * Library::instance() } /* - * Setter for sorted property. + * Setter for sorted property. Setting this value does not sort the library. It + * is meant to be set before the load function gets called. * * :param sorted: sorted */ @@ -81,10 +82,9 @@ Audios Library::audios() const } /* - * Loads the library for multiple paths by creating audio builder threads. It - * checks if the paths have already been loaded and ignores them if they have. - * This function should not be called twice because it might create database - * problems. + * Loads the library in the background by creating an audio loader thread. If + * this function gets called mulitple times for the same paths it will have no + * effect. * * :param paths: paths */ @@ -95,7 +95,7 @@ void Library::load(const StringList &paths) } /* - * Inserts an audio into the library. Depeding on the sorted propery it will be + * Inserts an audio into the library. If the sorted property is true, it will be * inserted binary. * * :param audio: audio @@ -119,8 +119,8 @@ void Library::onAudioLoaderFinished() /* * Gets the lower bound for an audio using a binary search like approach. This - * function is used insead of std::lower_bound because it has a better - * complexity and returns an index instead. + * function is being used insead of std::lower_bound because it has a better + * complexity and returns an index instead of an iterator. * * :param audio: audio */ diff --git a/src/core/threading/cachebuilder.cpp b/src/core/threading/cachebuilder.cpp index 6df7924..0eaf58e 100644 --- a/src/core/threading/cachebuilder.cpp +++ b/src/core/threading/cachebuilder.cpp @@ -45,17 +45,13 @@ void CacheBuilder::setAudios(const Audios &audios) /* * Loads audio covers. */ -#include void CacheBuilder::run() { Cache cache; for (Audio *audio : m_audios) { if (isAbort()) - { - qDebug() << "aborted :|"; return; - } if (!cache.contains(audio)) cache.insertCover(audio); diff --git a/src/ui/components/rowhoverdelegate.cpp b/src/ui/components/rowhoverdelegate.cpp index 447e83e..f9e0ebb 100644 --- a/src/ui/components/rowhoverdelegate.cpp +++ b/src/ui/components/rowhoverdelegate.cpp @@ -11,7 +11,7 @@ RowHoverDelegate::RowHoverDelegate(QTableWidget *table, QObject *parent) : pm_table(static_cast(table)), m_row(-1) { - connect(pm_table, SIGNAL(rowChanged(int)), this, SLOT(onRowChanged(int))); + connect(pm_table, SIGNAL(hoverRowChanged(int)), this, SLOT(onRowChanged(int))); } /* diff --git a/src/ui/components/rowhoverdelegate.hpp b/src/ui/components/rowhoverdelegate.hpp index 0966e82..d15d498 100644 --- a/src/ui/components/rowhoverdelegate.hpp +++ b/src/ui/components/rowhoverdelegate.hpp @@ -13,7 +13,7 @@ class TableWidget : public QTableWidget Q_OBJECT signals: - void rowChanged(int); + void hoverRowChanged(int); }; class RowHoverDelegate : public QStyledItemDelegate diff --git a/src/ui/musicbar.cpp b/src/ui/musicbar.cpp index 50cb23a..2410b7d 100644 --- a/src/ui/musicbar.cpp +++ b/src/ui/musicbar.cpp @@ -183,8 +183,10 @@ ClickableSlider * MusicBar::volumeSlider() /* * Paint event for custom css. */ -void MusicBar::paintEvent(QPaintEvent *) +void MusicBar::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QStyleOption option; option.init(this); QPainter painter(this); diff --git a/src/ui/musicbar.hpp b/src/ui/musicbar.hpp index a4b3cb0..916ddc4 100644 --- a/src/ui/musicbar.hpp +++ b/src/ui/musicbar.hpp @@ -40,7 +40,7 @@ class MusicBar : public QWidget ClickableSlider * volumeSlider(); protected: - void paintEvent(QPaintEvent *); + void paintEvent(QPaintEvent *event); private slots: void onPlayerAudioChanged(Audio *audio); diff --git a/src/ui/musiclibrary.cpp b/src/ui/musiclibrary.cpp index 3df194d..f53267f 100644 --- a/src/ui/musiclibrary.cpp +++ b/src/ui/musiclibrary.cpp @@ -64,11 +64,11 @@ void MusicLibrary::insert(Audio *audio, int row) * Emits -1 to remove the row hover style. * * :param event: event - * :emit rowChanged: row + * :emit hoverRowChanged: row */ void MusicLibrary::leaveEvent(QEvent *event) { - emit rowChanged(-1); + emit hoverRowChanged(-1); QTableWidget::leaveEvent(event); } @@ -78,24 +78,24 @@ void MusicLibrary::leaveEvent(QEvent *event) * to get the cursor position for the resized widget. * * :param event: event - * :emit rowChanged: row + * :emit hoverRowChanged: row */ void MusicLibrary::resizeEvent(QResizeEvent *event) { QTableWidget::resizeEvent(event); - emit rowChanged(indexAt(mapFromGlobal(QCursor::pos())).row()); + emit hoverRowChanged(indexAt(mapFromGlobal(QCursor::pos())).row()); } /* * Emits the row of the entered item. * * :param index: index - * :emit rowChanged: row + * :emit hoverRowChanged: row */ void MusicLibrary::onEntered(QModelIndex index) { - emit rowChanged(index.row()); + emit hoverRowChanged(index.row()); } /* diff --git a/src/ui/musiclibrary.hpp b/src/ui/musiclibrary.hpp index e53a7e3..26cfda2 100644 --- a/src/ui/musiclibrary.hpp +++ b/src/ui/musiclibrary.hpp @@ -30,7 +30,7 @@ public slots: void insert(Audio *audio, int row = -1); signals: - void rowChanged(int); + void hoverRowChanged(int); protected: void leaveEvent(QEvent *event); @@ -54,7 +54,6 @@ private slots: QString audioText(Audio *audio, int column); - Library *pm_library; QVector m_columns; }; diff --git a/src/utils/colorutil.cpp b/src/utils/colorutil.cpp index 2be8d1f..a485ac4 100644 --- a/src/utils/colorutil.cpp +++ b/src/utils/colorutil.cpp @@ -2,7 +2,8 @@ /* * Calculates the dominant color of an image by creating heuristics for the HSV - * color space. If no colorful color can be found, a grey scale will be returned. + * color space. If no colorful color can be found, a grey scale will be + * returned. * * :param image: image * :return: dominant color @@ -98,8 +99,9 @@ QColor ColorUtil::dominant(const QImage &image) /* * Gets the dominant color of an image and edits some values to prevent too - * bright values. It also resizes the image to keep processing the constant. - * Tries to load a cached value if the id is valid. + * bright values. To prevent the algorithm from running mulitple times for the + * same image a id can be given. If the id has already been processed a saved + * value will be returned. * * :param image: image * :param id: id, default -1 @@ -108,8 +110,8 @@ QColor ColorUtil::dominant(const QImage &image) QColor ColorUtil::background(const QImage &image, int id) { if (id != -1) - if (_colorCache.contains(id)) - return _colorCache.value(id); + if (_colors.contains(id)) + return _colors.value(id); QColor color = dominant(Util::resize(image, 25, true)); qreal hue = color.hsvHueF(); @@ -118,7 +120,7 @@ QColor ColorUtil::background(const QImage &image, int id) color = QColor::fromHsvF(hue, saturation, value); if (id != -1) - _colorCache[id] = color; + _colors.insert(id, color); return color; } @@ -138,4 +140,4 @@ QColor ColorUtil::background(const QPixmap &pixmap, int id) /* * Background color cache. */ -QHash ColorUtil::_colorCache; +QHash ColorUtil::_colors; diff --git a/src/utils/colorutil.hpp b/src/utils/colorutil.hpp index 5e2e571..0582d2d 100644 --- a/src/utils/colorutil.hpp +++ b/src/utils/colorutil.hpp @@ -16,7 +16,7 @@ class ColorUtil static QColor background(const QPixmap &pixmap, int id = -1); private: - static QHash _colorCache; + static QHash _colors; }; #endif // COLORUTIL_HPP