X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fwidgets%2Fpopup.cpp;fp=pv%2Fwidgets%2Fpopup.cpp;h=ec6d29c981c235b86451353ca620d9c5cf147868;hp=13282cda25e458b6b624de563f09e1fc6668a6b5;hb=f52ffd9d82b45313836c5e612c7cc48982ced529;hpb=368130c06af6a0cbcf8026cb61fce6d6e2304544 diff --git a/pv/widgets/popup.cpp b/pv/widgets/popup.cpp index 13282cda..ec6d29c9 100644 --- a/pv/widgets/popup.cpp +++ b/pv/widgets/popup.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include "popup.hpp" @@ -37,6 +39,33 @@ const unsigned int Popup::ArrowLength = 10; const unsigned int Popup::ArrowOverlap = 3; const unsigned int Popup::MarginWidth = 6; + +QWidthAdjustingScrollArea::QWidthAdjustingScrollArea(QWidget* parent) : + QScrollArea(parent) +{ +} + +void QWidthAdjustingScrollArea::setWidget(QWidget* w) +{ + QScrollArea::setWidget(w); + // It happens that QScrollArea already filters widget events, + // but that's an implementation detail that we shouldn't rely on. + w->installEventFilter(this); +} + +bool QWidthAdjustingScrollArea::eventFilter(QObject* obj, QEvent* ev) +{ + if (obj == widget() && ev->type() == QEvent::Resize) { + if (widget()->height() > height()) + setMinimumWidth(widget()->width() + qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)); + else + setMinimumWidth(widget()->width()); + } + + return QScrollArea::eventFilter(obj, ev); +} + + Popup::Popup(QWidget *parent) : QWidget(parent, Qt::Popup | Qt::FramelessWindowHint), point_(),