From 35571f850ff7eeaa3e9940d0dc467cabbfbf13ac Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sat, 20 Dec 2014 20:06:43 -0800 Subject: [PATCH] Qt: Fix accordion frame height calculation. Change-Id: I32d2ea2ff34544e285b52e4e35e035306c33d3aa Reviewed-on: https://code.wireshark.org/review/5935 Reviewed-by: Gerald Combs --- ui/qt/accordion_frame.cpp | 44 +++++++++++++++++++++++++++++++-------- ui/qt/accordion_frame.h | 2 -- ui/qt/main_welcome.cpp | 7 ++++++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/ui/qt/accordion_frame.cpp b/ui/qt/accordion_frame.cpp index fe13c660f9..cbeb11ca06 100644 --- a/ui/qt/accordion_frame.cpp +++ b/ui/qt/accordion_frame.cpp @@ -32,12 +32,12 @@ AccordionFrame::AccordionFrame(QWidget *parent) : QFrame(parent) { QString subframe_style( - ".QFrame {" - " background: palette(window);" - " padding-top: 0.1em;" - " padding-bottom: 0.1em;" - " border-bottom: 1px solid palette(shadow);" - "}" +// ".QFrame {" +// " background: palette(window);" +// " padding-top: 0.1em;" +// " padding-bottom: 0.1em;" +// " border-bottom: 1px solid palette(shadow);" +// "}" "QLineEdit#goToLineEdit {" " max-width: 5em;" "}" @@ -52,16 +52,42 @@ AccordionFrame::AccordionFrame(QWidget *parent) : void AccordionFrame::animatedShow() { + if (isVisible()) { + show(); + return; + } + if (strlen (get_conn_cfilter()) < 1) { - animation_->setStartValue(0); - animation_->setEndValue(frame_height_); - animation_->start(); + QWidget *parent = parentWidget(); + + if (parent && parent->layout()) { + // Show this widget, tell our parent to calculate our size, and hide + // ourselves. We might need to call + // parent->layout()->update(); parent->layout()->activate(); + // or + // parent->layout()->invalidate(); + // as well + show(); + parent->adjustSize(); + frame_height_ = height(); + hide(); + } + if (frame_height_ > 0) { + animation_->setStartValue(0); + animation_->setEndValue(frame_height_); + animation_->start(); + } } show(); } void AccordionFrame::animatedHide() { + if (!isVisible()) { + hide(); + return; + } + if (strlen (get_conn_cfilter()) < 1) { animation_->setStartValue(frame_height_); animation_->setEndValue(0); diff --git a/ui/qt/accordion_frame.h b/ui/qt/accordion_frame.h index 59d9249a17..b205c6248f 100644 --- a/ui/qt/accordion_frame.h +++ b/ui/qt/accordion_frame.h @@ -35,8 +35,6 @@ public: signals: -public slots: - private: int frame_height_; QPropertyAnimation *animation_; diff --git a/ui/qt/main_welcome.cpp b/ui/qt/main_welcome.cpp index 58c023b42f..7aa41fe7c0 100644 --- a/ui/qt/main_welcome.cpp +++ b/ui/qt/main_welcome.cpp @@ -95,6 +95,7 @@ MainWelcome::MainWelcome(QWidget *parent) : welcome_ui_->interfaceTree->setAttribute(Qt::WA_MacShowFocusRect, false); #endif + welcome_ui_->openFrame->hide(); recent_files_->setStyleSheet( "QListWidget::item {" " padding-top: 0.2em;" @@ -199,7 +200,11 @@ void MainWelcome::updateRecentFiles() { while (recent_files_->count() > (int) prefs.gui_recent_files_count_max) { recent_files_->takeItem(recent_files_->count()); } - welcome_ui_->openFrame->setVisible(recent_files_->count() > 0); + if (recent_files_->count() > 0) { + welcome_ui_->openFrame->animatedShow(); + } else { + welcome_ui_->openFrame->animatedHide(); + } } void MainWelcome::openRecentItem(QListWidgetItem *item) {