1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-19 23:41:51 +02:00

Add url click handler to push buttons in resolver configs

This commit is contained in:
Dominik Schmidt 2015-12-17 01:06:34 +01:00
parent 5a45bd0882
commit ea55329c67
2 changed files with 28 additions and 1 deletions

View File

@ -30,6 +30,8 @@
#include <QWidget>
#include <QUiLoader>
#include <QBoxLayout>
#include <QPushButton>
#include <QDesktopServices>
Tomahawk::ExternalResolverGui::ExternalResolverGui(const QString& filePath)
: Tomahawk::ExternalResolver(filePath)
@ -82,6 +84,28 @@ Tomahawk::ExternalResolverGui::addChildProperties( QObject* widget, QVariantMap&
}
void
Tomahawk::ExternalResolverGui::setupClickHandlerOnUrlButtons( QObject* widget )
{
if( !widget || !widget->isWidgetType() )
return;
if( qstrcmp( widget->metaObject()->className(), "QPushButton" ) == 0 && !widget->property( "url" ).isNull() )
{
QPushButton* button = qobject_cast< QPushButton* >( widget );
Q_ASSERT( button );
connect( button, &QPushButton::clicked, [=]() {
QDesktopServices::openUrl( widget->property( "url" ).toUrl() );
});
}
// and recurse
foreach( QObject* child, widget->children() )
setupClickHandlerOnUrlButtons( child );
}
AccountConfigWidget*
Tomahawk::ExternalResolverGui::widgetFromData( QByteArray& data, QWidget* parent )
{
@ -94,6 +118,8 @@ Tomahawk::ExternalResolverGui::widgetFromData( QByteArray& data, QWidget* parent
QBuffer b( &data );
QWidget* w = l.load( &b, configWidget );
setupClickHandlerOnUrlButtons( w );
// HACK: proper way would be to create a designer plugin for this widget type
configWidget->setLayout( new QBoxLayout( QBoxLayout::TopToBottom ) );
configWidget->layout()->addWidget( w );

View File

@ -50,7 +50,8 @@ protected:
QByteArray fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images );
private:
void addChildProperties( QObject* parent, QVariantMap& m );
void addChildProperties( QObject* widget, QVariantMap& m );
void setupClickHandlerOnUrlButtons( QObject* widget );
};
}; //ns