Implement addToFavourites() and getNextFreeCell()
This commit is contained in:
父節點
653089c475
當前提交
6b924c0f53
@ -49,7 +49,7 @@ void EntryPushButton::emitOwnClicked()
|
||||
emit clicked(this->config);
|
||||
}
|
||||
|
||||
const EntryConfig &EntryPushButton::getEntryConfig()
|
||||
const EntryConfig &EntryPushButton::getEntryConfig() const
|
||||
{
|
||||
return this->config;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class EntryPushButton : public QPushButton
|
||||
|
||||
public:
|
||||
EntryPushButton(const EntryConfig &config);
|
||||
const EntryConfig &getEntryConfig();
|
||||
const EntryConfig &getEntryConfig() const;
|
||||
void setEntryConfig(const EntryConfig &config);
|
||||
void showShortcut();
|
||||
void showName();
|
||||
|
38
window.cpp
38
window.cpp
@ -124,6 +124,22 @@ void Window::buttonClick(const EntryPushButton &config)
|
||||
this->closeWindow();
|
||||
}
|
||||
|
||||
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};
|
||||
QString entryName = fi.completeBaseName() + ".qsrun";
|
||||
userConfig.entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName;
|
||||
entryProvider->saveUserEntry(userConfig);
|
||||
initFromConfig();
|
||||
}
|
||||
|
||||
void Window::closeWindow()
|
||||
{
|
||||
if(settingsProvider->singleInstanceMode())
|
||||
@ -137,6 +153,27 @@ void Window::closeWindow()
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<int, int> Window::getNextFreeCell()
|
||||
{
|
||||
int maxRow = 0;
|
||||
for(EntryPushButton *button : userEntryButtons)
|
||||
{
|
||||
if(button->getRow() > maxRow)
|
||||
{
|
||||
maxRow = button->getRow();
|
||||
}
|
||||
}
|
||||
int maxCols = this->settingsProvider->getMaxCols();
|
||||
for(int i = 1; i < maxCols; i++)
|
||||
{
|
||||
if(grid->itemAtPosition(maxRow, i) == 0)
|
||||
{
|
||||
return {maxRow, i + 1};
|
||||
}
|
||||
}
|
||||
return {maxRow + 1, 0};
|
||||
}
|
||||
|
||||
QStringList Window::generatePATHSuggestions(const QString &text)
|
||||
{
|
||||
QStringList results;
|
||||
@ -356,6 +393,7 @@ EntryPushButton *Window::createEntryButton(const EntryConfig &entry)
|
||||
{
|
||||
EntryPushButton *button = new EntryPushButton(entry);
|
||||
connect(button, &EntryPushButton::clicked, this, &Window::buttonClick);
|
||||
connect(button, &EntryPushButton::addToFavourites, this, &Window::addToFavourites);
|
||||
return button;
|
||||
}
|
||||
|
||||
|
3
window.h
3
window.h
@ -64,6 +64,7 @@ class Window : public QWidget
|
||||
QVector<EntryPushButton *> generateEntryButtons(const QVector<EntryConfig> &userEntryButtons);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void buttonClick(const EntryPushButton &config);
|
||||
void addToFavourites(const EntryPushButton &button);
|
||||
QLineEdit *lineEdit;
|
||||
QGridLayout *grid;
|
||||
EntryPushButton *createEntryButton(const EntryConfig &config);
|
||||
@ -74,6 +75,8 @@ class Window : public QWidget
|
||||
void initTreeWidgets();
|
||||
QStringList generatePATHSuggestions(const QString &text);
|
||||
void closeWindow();
|
||||
std::pair<int, int> getNextFreeCell();
|
||||
|
||||
private slots:
|
||||
void lineEditReturnPressed();
|
||||
void showCalculationResultContextMenu(const QPoint &point);
|
||||
|
Loading…
Reference in New Issue
Block a user