Skip to content

Commit

Permalink
Ensure correct filter bar height
Browse files Browse the repository at this point in the history
For #218
  • Loading branch information
svetter committed Jul 30, 2024
1 parent 47081d2 commit 7bbfa7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/main/filter_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ void FilterBar::insertFiltersIntoUI(const QList<Filter*>& filters)
connect(newFilterBox, &FilterBox::removeRequested, this, &FilterBar::handle_removeFilter);
}

QApplication::processEvents();
filtersScrollArea->setMinimumHeight(filtersScrollAreaWidget->height() + filtersScrollArea->height() - filtersScrollArea->maximumViewportSize().height());
updateScrollAreaHeight();

bool anyFilterEnabled = false;
for (const FilterBox* const filterBox : filterBoxes) {
Expand Down Expand Up @@ -178,6 +177,15 @@ void FilterBar::updateQuickFilterMenu()
}
}

void FilterBar::updateScrollAreaHeight()
{
QApplication::processEvents();
const int contentsHeight = filtersScrollAreaWidget->height();
const int currentHeight = filtersScrollArea->height();
const int viewportHeight = filtersScrollArea->maximumViewportSize().height();
filtersScrollArea->setMinimumHeight(contentsHeight + currentHeight - viewportHeight);
}

void FilterBar::updateIDCombos()
{
for (const FilterBox* const filterBox : filterBoxes) {
Expand All @@ -196,8 +204,7 @@ void FilterBar::removeFilter(FilterBox* filterBox)
filterBoxes.removeAll(filterBox);
delete filterBox;

QApplication::processEvents();
filtersScrollArea->setMinimumHeight(filtersScrollAreaWidget->height() + filtersScrollArea->height() - filtersScrollArea->maximumViewportSize().height());
updateScrollAreaHeight();

handle_filtersChanged();
}
Expand Down Expand Up @@ -257,8 +264,7 @@ void FilterBar::handle_filterWizardAccepted()
filterBoxes.append(newFilterBox);
filtersScrollAreaLayout->addWidget(newFilterBox);

QApplication::processEvents();
filtersScrollArea->setMinimumHeight(filtersScrollAreaWidget->height() + filtersScrollArea->height() - filtersScrollArea->maximumViewportSize().height());
updateScrollAreaHeight();
filtersScrollArea->ensureWidgetVisible(newFilterBox);

connect(newFilterBox, &FilterBox::filterChanged, this, &FilterBar::handle_filtersChanged);
Expand Down Expand Up @@ -296,8 +302,7 @@ void FilterBar::handle_quickFilterActionUsed()
filterBoxes.append(newFilterBox);
filtersScrollAreaLayout->addWidget(newFilterBox);

QApplication::processEvents();
filtersScrollArea->setMinimumHeight(filtersScrollAreaWidget->height() + filtersScrollArea->height() - filtersScrollArea->maximumViewportSize().height());
updateScrollAreaHeight();
filtersScrollArea->ensureWidgetVisible(newFilterBox);

connect(newFilterBox, &FilterBox::filterChanged, this, &FilterBar::handle_filtersChanged);
Expand Down Expand Up @@ -420,3 +425,11 @@ QList<Filter*> FilterBar::parseFiltersFromProjectSettings(const ItemTypesHandler
QList<Filter*> filters = Filter::decodeFromString(encodedFilters, typesHandler);
return filters;
}



void FilterBar::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
updateScrollAreaHeight();
}
4 changes: 4 additions & 0 deletions src/main/filter_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FilterBar : public QWidget, public Ui_FilterBar
// Update UI
private:
void updateQuickFilterMenu();
void updateScrollAreaHeight();
public:
void updateIDCombos();

Expand Down Expand Up @@ -105,6 +106,9 @@ private slots:
void saveFilters();
// Retrieving filters from project settings
QList<Filter*> parseFiltersFromProjectSettings(const ItemTypesHandler &typesHandler);

protected:
virtual void showEvent(QShowEvent* event) override;
};


Expand Down

0 comments on commit 7bbfa7a

Please sign in to comment.