summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2016-10-29 15:04:50 (GMT)
committerAleix Pol <aleixpol@kde.org>2016-10-29 15:04:50 (GMT)
commit109c4a4090ac5550c167709a485f1aad85e5af6d (patch)
tree753f16c4ec745d9cc144265ec3b7985b0b941597
parent9e87989adebe6596bd26c23053f3b30a805e327d (diff)
Improve Sidebar minimum size
Account for hidden elements Don't make it like we're calculating the whole geometry although we're not
-rw-r--r--ui/sidebar.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/ui/sidebar.cpp b/ui/sidebar.cpp
index 2948de5..94f610f 100644
--- a/ui/sidebar.cpp
+++ b/ui/sidebar.cpp
@@ -217,6 +217,14 @@ class SidebarListWidget : public QListWidget
SidebarListWidget( QWidget *parent = Q_NULLPTR );
~SidebarListWidget();
+ int countVisible() const {
+ int ret = 0;
+ for ( int i = 0, c = count(); i < c; ++i ) {
+ ret += !item(i)->isHidden();
+ }
+ return ret;
+ }
+
protected:
// from QListWidget
void mouseDoubleClickEvent( QMouseEvent *event );
@@ -429,10 +437,7 @@ public:
void Sidebar::Private::adjustListSize( bool recalc, bool expand )
{
- QRect bottomElemRect(
- QPoint( 0, 0 ),
- list->sizeHintForIndex( list->model()->index( list->count() - 1, 0 ) )
- );
+ QSize bottomElemSize( list->sizeHintForIndex( list->model()->index( list->count() - 1, 0 ) ) );
if ( recalc )
{
int w = 0;
@@ -442,15 +447,15 @@ void Sidebar::Private::adjustListSize( bool recalc, bool expand )
if ( s.width() > w )
w = s.width();
}
- bottomElemRect.setWidth( w );
+ bottomElemSize.setWidth( w );
}
- bottomElemRect.translate( 0, bottomElemRect.height() * ( list->count() - 1 ) );
- itemsHeight = bottomElemRect.height() * list->count();
+ itemsHeight = bottomElemSize.height() * list->countVisible();
list->setMinimumHeight( itemsHeight + list->frameWidth() * 2 );
+
int curWidth = list->minimumWidth();
int newWidth = expand
- ? qMax( bottomElemRect.width() + list->frameWidth() * 2, curWidth )
- : qMin( bottomElemRect.width() + list->frameWidth() * 2, curWidth );
+ ? qMax( bottomElemSize.width() + list->frameWidth() * 2, curWidth )
+ : qMin( bottomElemSize.width() + list->frameWidth() * 2, curWidth );
list->setFixedWidth( newWidth );
}