EnrtyConfig: store iconPath, not QIcon. Keeps icon after rearranging entries
This commit is contained in:
parent
9daaba2543
commit
7bae1183c6
@ -56,7 +56,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
|
|||||||
}
|
}
|
||||||
if(key == "icon")
|
if(key == "icon")
|
||||||
{
|
{
|
||||||
result.icon = QIcon::fromTheme(args);
|
result.iconPath = args;
|
||||||
}
|
}
|
||||||
if(key == "exec")
|
if(key == "exec")
|
||||||
{
|
{
|
||||||
@ -159,7 +159,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
|||||||
}
|
}
|
||||||
if(key == "icon")
|
if(key == "icon")
|
||||||
{
|
{
|
||||||
result.icon = QIcon(splitted[1]);
|
result.iconPath = splitted[1];
|
||||||
}
|
}
|
||||||
if(key == "row")
|
if(key == "row")
|
||||||
{
|
{
|
||||||
@ -277,9 +277,9 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
|
|||||||
{
|
{
|
||||||
outStream << "command" << " " << config.command << endl;
|
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 << "row" << " " << config.row << endl;
|
||||||
outStream << "col" << " " << config.col << endl;
|
outStream << "col" << " " << config.col << endl;
|
||||||
@ -308,9 +308,9 @@ EntryConfig &EntryConfig::update(const EntryConfig &o)
|
|||||||
assignIfDestDefault(this->arguments, o.arguments);
|
assignIfDestDefault(this->arguments, o.arguments);
|
||||||
assignIfDestDefault(this->col, o.col);
|
assignIfDestDefault(this->col, o.col);
|
||||||
assignIfDestDefault(this->command, o.command);
|
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->key, o.key);
|
||||||
assignIfDestDefault(this->name, o.name);
|
assignIfDestDefault(this->name, o.name);
|
||||||
|
@ -24,8 +24,8 @@ class EntryConfig
|
|||||||
QString key;
|
QString key;
|
||||||
QString name;
|
QString name;
|
||||||
QString command;
|
QString command;
|
||||||
|
QString iconPath;
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
QIcon icon;
|
|
||||||
QString inherit;
|
QString inherit;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
@ -23,10 +23,11 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton()
|
|||||||
{
|
{
|
||||||
this->setText(config.name);
|
this->setText(config.name);
|
||||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
this->setIcon(config.icon);
|
QIcon icon = resolveIcon(config.iconPath);
|
||||||
if(!config.icon.availableSizes().isEmpty())
|
this->setIcon(icon);
|
||||||
|
if(!icon.availableSizes().isEmpty())
|
||||||
{
|
{
|
||||||
auto sizes = config.icon.availableSizes();
|
auto sizes = icon.availableSizes();
|
||||||
QSize maxSize = sizes.first();
|
QSize maxSize = sizes.first();
|
||||||
for(QSize ¤t : sizes)
|
for(QSize ¤t : sizes)
|
||||||
{
|
{
|
||||||
@ -44,6 +45,22 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton()
|
|||||||
userEntryMenu.addAction("Delete", [&] { emit deleteRequested(this->config); });
|
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()
|
void EntryPushButton::emitOwnClicked()
|
||||||
{
|
{
|
||||||
emit clicked(this->config);
|
emit clicked(this->config);
|
||||||
|
@ -45,6 +45,7 @@ class EntryPushButton : public QPushButton
|
|||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
QIcon resolveIcon(QString path);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EntryPushButton(const EntryConfig &config);
|
EntryPushButton(const EntryConfig &config);
|
||||||
|
@ -129,11 +129,10 @@ void Window::addToFavourites(const EntryPushButton &button)
|
|||||||
std::pair<int, int> cell = getNextFreeCell();
|
std::pair<int, int> cell = getNextFreeCell();
|
||||||
EntryConfig userConfig = button.getEntryConfig();
|
EntryConfig userConfig = button.getEntryConfig();
|
||||||
userConfig.userEntry = true;
|
userConfig.userEntry = true;
|
||||||
userConfig.icon = QIcon();
|
|
||||||
userConfig.row = cell.first;
|
userConfig.row = cell.first;
|
||||||
userConfig.col = cell.second;
|
userConfig.col = cell.second;
|
||||||
userConfig.inherit = userConfig.entryPath;
|
userConfig.inherit = button.getEntryConfig().entryPath;
|
||||||
QFileInfo fi{userConfig.entryPath};
|
QFileInfo fi{button.getEntryConfig().entryPath};
|
||||||
QString entryName = fi.completeBaseName() + ".qsrun";
|
QString entryName = fi.completeBaseName() + ".qsrun";
|
||||||
userConfig.entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName;
|
userConfig.entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName;
|
||||||
entryProvider->saveUserEntry(userConfig);
|
entryProvider->saveUserEntry(userConfig);
|
||||||
@ -208,7 +207,7 @@ void Window::addPATHSuggestion(const QString &text)
|
|||||||
e.col = 0;
|
e.col = 0;
|
||||||
e.row = 0;
|
e.row = 0;
|
||||||
e.command = suggestions[0];
|
e.command = suggestions[0];
|
||||||
e.icon = QIcon::fromTheme(suggestions[0]);
|
e.iconPath = suggestions[0];
|
||||||
EntryPushButton *button = createEntryButton(e);
|
EntryPushButton *button = createEntryButton(e);
|
||||||
clearGrid();
|
clearGrid();
|
||||||
grid->addWidget(button, 0, 0);
|
grid->addWidget(button, 0, 0);
|
||||||
@ -285,7 +284,7 @@ void Window::lineEditTextChanged(QString text)
|
|||||||
e.arguments = arguments.mid(1);
|
e.arguments = arguments.mid(1);
|
||||||
}
|
}
|
||||||
e.command = arguments[0];
|
e.command = arguments[0];
|
||||||
e.icon = QIcon::fromTheme("utilities-terminal");
|
e.iconPath = "utilities-terminal";
|
||||||
|
|
||||||
EntryPushButton *button = createEntryButton(e);
|
EntryPushButton *button = createEntryButton(e);
|
||||||
clearGrid();
|
clearGrid();
|
||||||
|
Loading…
Reference in New Issue
Block a user