mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Add url click handler to push buttons in resolver configs
This commit is contained in:
@@ -30,6 +30,8 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QUiLoader>
|
#include <QUiLoader>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
Tomahawk::ExternalResolverGui::ExternalResolverGui(const QString& filePath)
|
Tomahawk::ExternalResolverGui::ExternalResolverGui(const QString& filePath)
|
||||||
: Tomahawk::ExternalResolver(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*
|
AccountConfigWidget*
|
||||||
Tomahawk::ExternalResolverGui::widgetFromData( QByteArray& data, QWidget* parent )
|
Tomahawk::ExternalResolverGui::widgetFromData( QByteArray& data, QWidget* parent )
|
||||||
{
|
{
|
||||||
@@ -94,6 +118,8 @@ Tomahawk::ExternalResolverGui::widgetFromData( QByteArray& data, QWidget* parent
|
|||||||
QBuffer b( &data );
|
QBuffer b( &data );
|
||||||
QWidget* w = l.load( &b, configWidget );
|
QWidget* w = l.load( &b, configWidget );
|
||||||
|
|
||||||
|
setupClickHandlerOnUrlButtons( w );
|
||||||
|
|
||||||
// HACK: proper way would be to create a designer plugin for this widget type
|
// HACK: proper way would be to create a designer plugin for this widget type
|
||||||
configWidget->setLayout( new QBoxLayout( QBoxLayout::TopToBottom ) );
|
configWidget->setLayout( new QBoxLayout( QBoxLayout::TopToBottom ) );
|
||||||
configWidget->layout()->addWidget( w );
|
configWidget->layout()->addWidget( w );
|
||||||
|
@@ -50,7 +50,8 @@ protected:
|
|||||||
QByteArray fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images );
|
QByteArray fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addChildProperties( QObject* parent, QVariantMap& m );
|
void addChildProperties( QObject* widget, QVariantMap& m );
|
||||||
|
void setupClickHandlerOnUrlButtons( QObject* widget );
|
||||||
};
|
};
|
||||||
|
|
||||||
}; //ns
|
}; //ns
|
||||||
|
Reference in New Issue
Block a user