@@ -35,16 +35,38 @@ SOFTWARE.*/
3535#include < QResizeEvent>
3636#include < QPixmap>
3737#include < QPainter>
38+ #include < QScrollBar>
3839#include " PluginListWidget.h"
3940#include " PluginManager.h"
4041#include " DlgPluginRepo.h"
4142
43+ // A custom scroll area that only shows a vertical scrollbar, and resizes the viewport to fit the width of the contents
44+ class VerticalScrollArea : public QScrollArea
45+ {
46+ public:
47+ explicit VerticalScrollArea (QWidget *parent = nullptr )
48+ {
49+ setWidgetResizable (true );
50+ setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
51+ setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
52+ }
53+
54+ bool eventFilter (QObject *o, QEvent *e) override
55+ {
56+ // This works because QScrollArea::setWidget installs an eventFilter on the widget
57+ if (o && o == widget () && e->type () == QEvent::Resize)
58+ setMinimumWidth (widget ()->minimumSizeHint ().width () + verticalScrollBar ()->width ());
59+
60+ return QScrollArea::eventFilter (o, e);
61+ }
62+ };
63+
4264class Ui ::PluginThumbnail
4365{
4466public:
4567 QLabel* imageLabel;
4668 QLabel* nameLabel;
47- QLabel* ownerLabel ;
69+ QLabel* centerLabel ;
4870 QLabel* statusLabel;
4971
5072public:
@@ -75,11 +97,11 @@ class Ui::PluginThumbnail
7597 layout->setAlignment (Qt::AlignHCenter);
7698
7799 nameLabel = new QLabel;
78- ownerLabel = new QLabel (" <b>Connecting...</b>" );
100+ centerLabel = new QLabel (" <b>Connecting...</b>" );
79101 statusLabel = new QLabel;
80102
81103 layout->addWidget (nameLabel, 0 , Qt::AlignHCenter);
82- layout->addWidget (ownerLabel , 0 , Qt::AlignHCenter);
104+ layout->addWidget (centerLabel , 0 , Qt::AlignHCenter);
83105 layout->addWidget (statusLabel, 0 , Qt::AlignHCenter);
84106
85107 m_parent->setLayout (layout);
@@ -101,18 +123,18 @@ class Ui::PluginThumbnail
101123 nameFont.setBold (true );
102124 nameLabel->setFont (nameFont);
103125
104- ownerLabel = new QLabel ( QString::fromStdString ( " <i> " + plugin-> owner + " </i> " )) ;
105- ownerLabel ->setAlignment (Qt::AlignLeft);
106- QFont ownerFont = ownerLabel ->font ();
126+ centerLabel = new QLabel;
127+ centerLabel ->setAlignment (Qt::AlignLeft);
128+ QFont ownerFont = centerLabel ->font ();
107129 ownerFont.setItalic (true );
108- ownerLabel ->setFont (ownerFont);
130+ centerLabel ->setFont (ownerFont);
109131
110132 statusLabel = new QLabel (QString::fromStdString (plugin->description ));
111133 statusLabel->setAlignment (Qt::AlignLeft);
112134 QFont statusFont = statusLabel->font ();
113135
114136 infoLayout->addWidget (nameLabel);
115- infoLayout->addWidget (ownerLabel );
137+ infoLayout->addWidget (centerLabel );
116138 infoLayout->addWidget (statusLabel);
117139
118140 // In order to get the appropriate size for the image label, we need
@@ -214,11 +236,14 @@ void PluginThumbnail::SetProgress(float progress)
214236
215237void PluginThumbnail::SetErrorText (const QString& text)
216238{
217- ui->ownerLabel ->setText (text);
239+ ui->centerLabel ->setText (text);
240+ ui->centerLabel ->show ();
218241}
219242
220243void PluginThumbnail::SetStatus (int status)
221244{
245+ ui->centerLabel ->hide ();
246+
222247 ui->imageLabel ->setPixmap (ui->pixmap );
223248
224249 QPixmap pluginImg = ui->imageLabel ->pixmap ();
@@ -254,7 +279,6 @@ void PluginThumbnail::SetStatus(int status)
254279 case PLUGIN_LOCAL:
255280 setToolTip (" This plugin in not part of the repository, but was loaded from a local file." );
256281 ui->statusLabel ->setText (" Local Plugin" );
257- ui->ownerLabel ->hide ();
258282 break ;
259283 case PLUGIN_DOWNLOADING:
260284 setToolTip (" Downloading..." );
@@ -339,7 +363,7 @@ class Ui::PluginListWidget
339363 QVBoxLayout* mainLayout = new QVBoxLayout;
340364 mainLayout->setContentsMargins (0 , 0 , 0 , 0 );
341365
342- QScrollArea * scrollArea = new QScrollArea ;
366+ VerticalScrollArea * scrollArea = new VerticalScrollArea ;
343367 QWidget* scrollWidget = new QWidget;
344368 QVBoxLayout* scrollLayout = new QVBoxLayout;
345369 scrollLayout->setContentsMargins (0 ,0 ,0 ,0 );
@@ -380,8 +404,6 @@ class Ui::PluginListWidget
380404 mainLayout->addWidget (scrollArea);
381405
382406 parent->setLayout (mainLayout);
383-
384- parent->setMinimumWidth (250 );
385407 }
386408
387409 void updateUi (int repoStatus = CPluginManager::CONNECTED)
0 commit comments