From 1bd6ebef9cd5ea3ed24d5daa24b975c713c8e1e2 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 15 Dec 2012 18:26:57 +0100 Subject: [PATCH] wrapped QSearchField for use in QML --- src/libtomahawk/CMakeLists.txt | 2 ++ .../thirdparty/Qocoa/qsearchfield.h | 2 +- src/libtomahawk/widgets/DeclarativeView.cpp | 3 +++ .../widgets/SearchFieldQmlProxy.cpp | 12 ++++++++++++ src/libtomahawk/widgets/SearchFieldQmlProxy.h | 18 ++++++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/libtomahawk/widgets/SearchFieldQmlProxy.cpp create mode 100644 src/libtomahawk/widgets/SearchFieldQmlProxy.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 77328cef5..87958d586 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -161,6 +161,8 @@ set( libGuiSources widgets/searchlineedit/LineEdit.cpp widgets/searchlineedit/SearchButton.cpp widgets/searchlineedit/SearchLineEdit.cpp + widgets/SearchFieldQmlProxy.cpp + ) IF(QCA2_FOUND) diff --git a/src/libtomahawk/thirdparty/Qocoa/qsearchfield.h b/src/libtomahawk/thirdparty/Qocoa/qsearchfield.h index 0b429972f..083ab133f 100644 --- a/src/libtomahawk/thirdparty/Qocoa/qsearchfield.h +++ b/src/libtomahawk/thirdparty/Qocoa/qsearchfield.h @@ -14,7 +14,7 @@ class DLLEXPORT QSearchField : public QWidget Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText); public: - explicit QSearchField(QWidget *parent); + explicit QSearchField(QWidget *parent = 0); QString text() const; QString placeholderText() const; diff --git a/src/libtomahawk/widgets/DeclarativeView.cpp b/src/libtomahawk/widgets/DeclarativeView.cpp index 646a16fdf..de6e60c54 100644 --- a/src/libtomahawk/widgets/DeclarativeView.cpp +++ b/src/libtomahawk/widgets/DeclarativeView.cpp @@ -20,6 +20,7 @@ #include "playlist/PlayableItem.h" #include "DeclarativeCoverArtProvider.h" #include "utils/TomahawkUtilsGui.h" +#include "widgets/SearchFieldQmlProxy.h" #include #include @@ -37,6 +38,7 @@ DeclarativeView::DeclarativeView( QWidget *parent ): // This types seem to be needed everywhere anyways, lets the register here qmlRegisterType( "tomahawk", 1, 0, "PlayableItem"); + qmlRegisterType("tomahawk", 1, 0, "SearchField"); // QML image providers will be deleted by the view engine()->addImageProvider( "albumart", new DeclarativeCoverArtProvider() ); @@ -46,6 +48,7 @@ DeclarativeView::DeclarativeView( QWidget *parent ): rootContext()->setContextProperty( "defaultFontSize", TomahawkUtils::defaultFontSize() ); rootContext()->setContextProperty( "defaultFontHeight", TomahawkUtils::defaultFontHeight() ); + } DeclarativeView::~DeclarativeView() diff --git a/src/libtomahawk/widgets/SearchFieldQmlProxy.cpp b/src/libtomahawk/widgets/SearchFieldQmlProxy.cpp new file mode 100644 index 000000000..f65998882 --- /dev/null +++ b/src/libtomahawk/widgets/SearchFieldQmlProxy.cpp @@ -0,0 +1,12 @@ +#include "SearchFieldQmlProxy.h" + +#include "thirdparty/Qocoa/qsearchfield.h" + +SearchFieldQmlProxy::SearchFieldQmlProxy(QGraphicsItem *parent) : + QGraphicsProxyWidget(parent) +{ + m_searchField = new QSearchField(); + m_searchField->setAttribute(Qt::WA_NoSystemBackground); + setWidget(m_searchField); + +} diff --git a/src/libtomahawk/widgets/SearchFieldQmlProxy.h b/src/libtomahawk/widgets/SearchFieldQmlProxy.h new file mode 100644 index 000000000..359b562b4 --- /dev/null +++ b/src/libtomahawk/widgets/SearchFieldQmlProxy.h @@ -0,0 +1,18 @@ +#ifndef SEARCHFIELDQMLPROXY +#define SEARCHFIELDQMLPROXY + +#include + +class QSearchField; + +class SearchFieldQmlProxy: public QGraphicsProxyWidget +{ + Q_OBJECT +public: + SearchFieldQmlProxy(QGraphicsItem* parent = 0); + +private: + QSearchField *m_searchField; +}; + +#endif