EnrtyConfig: store iconPath, not QIcon. Keeps icon after rearranging entries
这个提交包含在:
父节点
9daaba2543
当前提交
7bae1183c6
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -129,11 +129,10 @@ void Window::addToFavourites(const EntryPushButton &button)
|
||||
std::pair<int, int> 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();
|
||||
|
正在加载...
在新工单中引用
屏蔽一个用户