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:
parent
5a45bd0882
commit
ea55329c67
@ -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 );
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user