diff --git a/src/headers/macro-action-random.hpp b/src/headers/macro-action-random.hpp index 8011d1f2..bbeaead3 100644 --- a/src/headers/macro-action-random.hpp +++ b/src/headers/macro-action-random.hpp @@ -55,6 +55,8 @@ protected: std::shared_ptr _entryData; private: + void SetMacroListSize(); + MacroSelection *_macroSelection; QListWidget *_macroList; QPushButton *_add; diff --git a/src/headers/macro-action-run.hpp b/src/headers/macro-action-run.hpp index 95e92f9b..c6741eff 100644 --- a/src/headers/macro-action-run.hpp +++ b/src/headers/macro-action-run.hpp @@ -56,6 +56,8 @@ protected: std::shared_ptr _entryData; private: + void SetArgListSize(); + FileSelection *_filePath; QListWidget *_argList; QPushButton *_addArg; diff --git a/src/headers/utility.hpp b/src/headers/utility.hpp index 72719f69..9020caa5 100644 --- a/src/headers/utility.hpp +++ b/src/headers/utility.hpp @@ -55,6 +55,7 @@ void listAddClicked(QListWidget *list, QWidget *newWidget, QMetaObject::Connection *addHighlight = nullptr); bool listMoveUp(QListWidget *list); bool listMoveDown(QListWidget *list); +void setHeightToContentHeight(QListWidget *list); bool DisplayMessage(const QString &msg, bool question = false); void DisplayTrayMessage(const QString &title, const QString &msg); void addSelectionEntry(QComboBox *sel, const char *description, diff --git a/src/macro-action-random.cpp b/src/macro-action-random.cpp index 235f6a27..563994e7 100644 --- a/src/macro-action-random.cpp +++ b/src/macro-action-random.cpp @@ -155,6 +155,7 @@ void MacroActionRandomEdit::UpdateEntryData() QListWidgetItem *item = new QListWidgetItem(name, _macroList); item->setData(Qt::UserRole, name); } + SetMacroListSize(); } void MacroActionRandomEdit::MacroRemove(const QString &name) @@ -209,6 +210,7 @@ void MacroActionRandomEdit::AddMacro() std::lock_guard lock(switcher->m); _entryData->_macros.push_back(macro); + SetMacroListSize(); } void MacroActionRandomEdit::RemoveMacro() @@ -232,6 +234,7 @@ void MacroActionRandomEdit::RemoveMacro() } } delete item; + SetMacroListSize(); } int MacroActionRandomEdit::FindEntry(const std::string ¯o) @@ -261,3 +264,9 @@ void MacroActionRandomEdit::MacroSelectionChanged(int idx) QString name = item->text(); _macroSelection->SetCurrentMacro(GetMacroByName(name.toUtf8().data())); } + +void MacroActionRandomEdit::SetMacroListSize() +{ + setHeightToContentHeight(_macroList); + adjustSize(); +} diff --git a/src/macro-action-run.cpp b/src/macro-action-run.cpp index 9dd42b6d..4cfdefe0 100644 --- a/src/macro-action-run.cpp +++ b/src/macro-action-run.cpp @@ -137,6 +137,7 @@ void MacroActionRunEdit::UpdateEntryData() QListWidgetItem *item = new QListWidgetItem(arg, _argList); item->setData(Qt::UserRole, arg); } + SetArgListSize(); } void MacroActionRunEdit::PathChanged(const QString &text) @@ -175,6 +176,7 @@ void MacroActionRunEdit::AddArg() std::lock_guard lock(switcher->m); _entryData->_args << arg; + SetArgListSize(); } void MacroActionRunEdit::RemoveArg() @@ -195,6 +197,7 @@ void MacroActionRunEdit::RemoveArg() return; } delete item; + SetArgListSize(); } void MacroActionRunEdit::ArgUp() @@ -224,3 +227,9 @@ void MacroActionRunEdit::ArgDown() _entryData->_args.move(idx, idx + 1); } } + +void MacroActionRunEdit::SetArgListSize() +{ + setHeightToContentHeight(_argList); + adjustSize(); +} diff --git a/src/utility.cpp b/src/utility.cpp index d81bc074..61d1ecc5 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -962,3 +962,14 @@ bool listMoveDown(QListWidget *list) list->setCurrentRow(index + 1); return true; } + +void setHeightToContentHeight(QListWidget *list) +{ + auto nrItems = list->count(); + if (nrItems == 0) { + list->setMaximumHeight(0); + } else { + list->setMaximumHeight(list->sizeHintForRow(0) * nrItems + + 2 * list->frameWidth()); + } +}