diff --git a/entryprovider.cpp b/entryprovider.cpp index 41e00e5..c5408b4 100644 --- a/entryprovider.cpp +++ b/entryprovider.cpp @@ -56,7 +56,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path) } if(key == "icon") { - result.icon = QIcon::fromTheme(args); + result.iconPath = args; } if(key == "exec") { @@ -159,7 +159,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path) } if(key == "icon") { - result.icon = QIcon(splitted[1]); + result.iconPath = splitted[1]; } if(key == "row") { @@ -277,9 +277,9 @@ void EntryProvider::saveUserEntry(const EntryConfig &config) { outStream << "command" << " " << config.command << endl; } - if(!config.icon.isNull()) + if(!config.iconPath.isEmpty()) { - outStream << "icon" << " " << config.icon.name() << endl; + outStream << "icon" << " " << config.iconPath << endl; } outStream << "row" << " " << config.row << endl; outStream << "col" << " " << config.col << endl; @@ -308,9 +308,9 @@ EntryConfig &EntryConfig::update(const EntryConfig &o) assignIfDestDefault(this->arguments, o.arguments); assignIfDestDefault(this->col, o.col); assignIfDestDefault(this->command, o.command); - if(this->icon.isNull()) + if(this->iconPath.isEmpty()) { - this->icon = o.icon; + this->iconPath = o.iconPath; } assignIfDestDefault(this->key, o.key); assignIfDestDefault(this->name, o.name); diff --git a/entryprovider.h b/entryprovider.h index 4a69a96..9f4ac1e 100644 --- a/entryprovider.h +++ b/entryprovider.h @@ -24,8 +24,8 @@ class EntryConfig QString key; QString name; QString command; + QString iconPath; QStringList arguments; - QIcon icon; QString inherit; int row = 0; int col = 0; diff --git a/entrypushbutton.cpp b/entrypushbutton.cpp index 36cac1c..d585b71 100644 --- a/entrypushbutton.cpp +++ b/entrypushbutton.cpp @@ -23,10 +23,11 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton() { this->setText(config.name); this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - this->setIcon(config.icon); - if(!config.icon.availableSizes().isEmpty()) + QIcon icon = resolveIcon(config.iconPath); + this->setIcon(icon); + if(!icon.availableSizes().isEmpty()) { - auto sizes = config.icon.availableSizes(); + auto sizes = icon.availableSizes(); QSize maxSize = sizes.first(); for(QSize ¤t : sizes) { @@ -44,6 +45,22 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton() userEntryMenu.addAction("Delete", [&] { emit deleteRequested(this->config); }); } +QIcon EntryPushButton::resolveIcon(QString path) +{ + if(!path.isEmpty()) + { + if(path[0] == '/') + { + return QIcon(path); + } + else + { + return QIcon::fromTheme(path); + } + } + return QIcon(); +} + void EntryPushButton::emitOwnClicked() { emit clicked(this->config); diff --git a/entrypushbutton.h b/entrypushbutton.h index d8655e2..f7e4626 100644 --- a/entrypushbutton.h +++ b/entrypushbutton.h @@ -45,6 +45,7 @@ class EntryPushButton : public QPushButton protected: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); + QIcon resolveIcon(QString path); public: EntryPushButton(const EntryConfig &config); diff --git a/window.cpp b/window.cpp index 84f3187..39ac963 100644 --- a/window.cpp +++ b/window.cpp @@ -129,11 +129,10 @@ void Window::addToFavourites(const EntryPushButton &button) std::pair cell = getNextFreeCell(); EntryConfig userConfig = button.getEntryConfig(); userConfig.userEntry = true; - userConfig.icon = QIcon(); userConfig.row = cell.first; userConfig.col = cell.second; - userConfig.inherit = userConfig.entryPath; - QFileInfo fi{userConfig.entryPath}; + userConfig.inherit = button.getEntryConfig().entryPath; + QFileInfo fi{button.getEntryConfig().entryPath}; QString entryName = fi.completeBaseName() + ".qsrun"; userConfig.entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName; entryProvider->saveUserEntry(userConfig); @@ -208,7 +207,7 @@ void Window::addPATHSuggestion(const QString &text) e.col = 0; e.row = 0; e.command = suggestions[0]; - e.icon = QIcon::fromTheme(suggestions[0]); + e.iconPath = suggestions[0]; EntryPushButton *button = createEntryButton(e); clearGrid(); grid->addWidget(button, 0, 0); @@ -285,7 +284,7 @@ void Window::lineEditTextChanged(QString text) e.arguments = arguments.mid(1); } e.command = arguments[0]; - e.icon = QIcon::fromTheme("utilities-terminal"); + e.iconPath = "utilities-terminal"; EntryPushButton *button = createEntryButton(e); clearGrid();