mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-03 12:29:46 -08:00
Adverts widget supports population from web and from local files.
This commit is contained in:
@@ -13,22 +13,22 @@ CasinoCoinWebAPI::CasinoCoinWebAPI( QObject*a_pParent )
|
|||||||
|
|
||||||
void CasinoCoinWebAPI::GetActivePromotions()
|
void CasinoCoinWebAPI::GetActivePromotions()
|
||||||
{
|
{
|
||||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActivePromotions" );
|
Get( s_strServerAddress + s_strServerEndpoint + "/ActivePromotions" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CasinoCoinWebAPI::GetActiveCasinos()
|
void CasinoCoinWebAPI::GetActiveCasinos()
|
||||||
{
|
{
|
||||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActiveCasinos" );
|
Get( s_strServerAddress + s_strServerEndpoint + "/ActiveCasinos" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CasinoCoinWebAPI::GetActiveNewsItems()
|
void CasinoCoinWebAPI::GetActiveNewsItems()
|
||||||
{
|
{
|
||||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActiveNewsItems" );
|
Get( s_strServerAddress + s_strServerEndpoint + "/ActiveNewsItems" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CasinoCoinWebAPI::GetActiveExchanges()
|
void CasinoCoinWebAPI::GetActiveExchanges()
|
||||||
{
|
{
|
||||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActiveExchanges" );
|
Get( s_strServerAddress + s_strServerEndpoint + "/ActiveExchanges" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CasinoCoinWebAPI::Get( const QString& a_rUrl )
|
void CasinoCoinWebAPI::Get( const QString& a_rUrl )
|
||||||
@@ -43,10 +43,11 @@ void CasinoCoinWebAPI::slotParseNetworkResponse( QNetworkReply *finished )
|
|||||||
if ( finished->error() != QNetworkReply::NoError )
|
if ( finished->error() != QNetworkReply::NoError )
|
||||||
{
|
{
|
||||||
// A communication error has occurred
|
// A communication error has occurred
|
||||||
emit signalNetworkError( finished->error() );
|
qDebug() << finished->request().url();
|
||||||
|
emit signalNetworkError( finished->error(), finished->request().url() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray data = finished->readAll();
|
QByteArray data = finished->readAll();
|
||||||
emit signalResponseReady( data );
|
emit signalResponseReady( data );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalResponseReady( const QByteArray& a_rJsonFile );
|
void signalResponseReady( const QByteArray& a_rJsonFile );
|
||||||
void signalNetworkError( QNetworkReply::NetworkError a_eError );
|
void signalNetworkError
|
||||||
|
( QNetworkReply::NetworkError a_eError
|
||||||
|
, const QUrl a_rFailedUrl
|
||||||
|
);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slotParseNetworkResponse( QNetworkReply *finished );
|
void slotParseNetworkResponse( QNetworkReply *finished );
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
CasinoCoinWebAPIParser::CasinoCoinWebAPIParser( QObject* a_pParent )
|
CasinoCoinWebAPIParser::CasinoCoinWebAPIParser( QObject* a_pParent )
|
||||||
: QObject(a_pParent)
|
: QObject(a_pParent)
|
||||||
@@ -23,24 +25,37 @@ void CasinoCoinWebAPIParser::slotParseAnswer( const QByteArray& a_rJsonFile )
|
|||||||
QJsonObject jsonObjectResult = docAsObject.find( "Result" ).value().toObject();
|
QJsonObject jsonObjectResult = docAsObject.find( "Result" ).value().toObject();
|
||||||
if ( jsonObjectResult.find( "ActivePromotions" ).value().isArray() )
|
if ( jsonObjectResult.find( "ActivePromotions" ).value().isArray() )
|
||||||
{
|
{
|
||||||
|
StoreFile( "ActivePromotions", a_rJsonFile );
|
||||||
ParsePromotions( docAsObject );
|
ParsePromotions( docAsObject );
|
||||||
}
|
}
|
||||||
else if ( jsonObjectResult.find( "ActiveNewsItems" ).value().isArray() )
|
else if ( jsonObjectResult.find( "ActiveNewsItems" ).value().isArray() )
|
||||||
{
|
{
|
||||||
|
StoreFile( "ActiveNewsItems", a_rJsonFile );
|
||||||
ParseNewsItems( docAsObject );
|
ParseNewsItems( docAsObject );
|
||||||
}
|
}
|
||||||
else if ( jsonObjectResult.find( "ActiveCasinos" ).value().isArray() )
|
else if ( jsonObjectResult.find( "ActiveCasinos" ).value().isArray() )
|
||||||
{
|
{
|
||||||
|
StoreFile( "ActiveCasinos", a_rJsonFile );
|
||||||
ParseCasinos( docAsObject );
|
ParseCasinos( docAsObject );
|
||||||
}
|
}
|
||||||
else if ( jsonObjectResult.find( "ActiveExchanges" ).value().isArray() )
|
else if ( jsonObjectResult.find( "ActiveExchanges" ).value().isArray() )
|
||||||
{
|
{
|
||||||
|
StoreFile( "ActiveExchanges", a_rJsonFile );
|
||||||
ParseExchanges( docAsObject );
|
ParseExchanges( docAsObject );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CasinoCoinWebAPIParser::slotNetworkError( QNetworkReply::NetworkError a_eError
|
||||||
|
, const QUrl a_rFailedUrl
|
||||||
|
)
|
||||||
|
{
|
||||||
|
qDebug() << "network error: " << a_eError;
|
||||||
|
QString strAccessedUrl = a_rFailedUrl.toString().split("/").last();
|
||||||
|
slotParseAnswer( ReadFile( strAccessedUrl ) );
|
||||||
|
}
|
||||||
|
|
||||||
void CasinoCoinWebAPIParser::ParsePromotions( const QJsonObject& a_rJsonPromotions )
|
void CasinoCoinWebAPIParser::ParsePromotions( const QJsonObject& a_rJsonPromotions )
|
||||||
{
|
{
|
||||||
qDebug() << "ParsePromotions";
|
qDebug() << "ParsePromotions";
|
||||||
@@ -64,3 +79,41 @@ void CasinoCoinWebAPIParser::ParseNewsItems( const QJsonObject& a_rJsonNewsItems
|
|||||||
qDebug() << "Coming soon - ParseNewsItems";
|
qDebug() << "Coming soon - ParseNewsItems";
|
||||||
qDebug() << a_rJsonNewsItems;
|
qDebug() << a_rJsonNewsItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray CasinoCoinWebAPIParser::ReadFile( QString a_strSourcePath )
|
||||||
|
{
|
||||||
|
QByteArray strAnswer;
|
||||||
|
if ( !QDir( "offlineData" ).exists() )
|
||||||
|
{
|
||||||
|
QDir().mkdir( "offlineData" );
|
||||||
|
}
|
||||||
|
QFile fileOutput( QDir( "offlineData" ).absoluteFilePath( a_strSourcePath ) );
|
||||||
|
if ( !fileOutput.open( QIODevice::ReadOnly ) )
|
||||||
|
{
|
||||||
|
qWarning() << "cannot open file to read: " << QDir::current().relativeFilePath( a_strSourcePath );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strAnswer = fileOutput.readAll();
|
||||||
|
fileOutput.close();
|
||||||
|
}
|
||||||
|
return strAnswer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CasinoCoinWebAPIParser::StoreFile( QString a_strDestinationPath, const QByteArray& a_rJsonFile )
|
||||||
|
{
|
||||||
|
if ( !QDir( "offlineData" ).exists() )
|
||||||
|
{
|
||||||
|
QDir().mkdir( "offlineData" );
|
||||||
|
}
|
||||||
|
QFile fileOutput( QDir( "offlineData" ).absoluteFilePath( a_strDestinationPath ) );
|
||||||
|
if ( !fileOutput.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
||||||
|
{
|
||||||
|
qWarning() << "cannot open file to write: " << QDir::current().relativeFilePath( a_strDestinationPath );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileOutput.write( a_rJsonFile );
|
||||||
|
fileOutput.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "jsonactivepromotionsparser.h"
|
#include "jsonactivepromotionsparser.h"
|
||||||
#include "jsonsingleactivepromotion.h"
|
#include "jsonsingleactivepromotion.h"
|
||||||
|
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
class CasinoCoinWebAPIParser : public QObject
|
class CasinoCoinWebAPIParser : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -21,12 +23,18 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slotParseAnswer( const QByteArray& a_rJsonFile );
|
void slotParseAnswer( const QByteArray& a_rJsonFile );
|
||||||
|
void slotNetworkError
|
||||||
|
( QNetworkReply::NetworkError a_eError
|
||||||
|
, const QUrl a_rFailedUrl
|
||||||
|
);
|
||||||
private:
|
private:
|
||||||
void ParsePromotions( const QJsonObject& a_rJsonPromotions );
|
void ParsePromotions( const QJsonObject& a_rJsonPromotions );
|
||||||
void ParseCasinos ( const QJsonObject& a_rJsonCasinos );
|
void ParseCasinos ( const QJsonObject& a_rJsonCasinos );
|
||||||
void ParseExchanges ( const QJsonObject& a_rJsonExchanges );
|
void ParseExchanges ( const QJsonObject& a_rJsonExchanges );
|
||||||
void ParseNewsItems ( const QJsonObject& a_rJsonNewsItems );
|
void ParseNewsItems ( const QJsonObject& a_rJsonNewsItems );
|
||||||
|
|
||||||
|
QByteArray ReadFile( QString a_strSourcePath );
|
||||||
|
void StoreFile( QString a_strDestinationPath, const QByteArray& a_rJsonFile );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CASINOCOINWEBAPIPARSER_H
|
#endif // CASINOCOINWEBAPIPARSER_H
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "jsonactivepromotionsparser.h"
|
#include "jsonactivepromotionsparser.h"
|
||||||
|
#include "../qtquick_controls/cpp/qmlimageprovider.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ void JsonActivePromotionsParser::ResolvePromotionsArray()
|
|||||||
{
|
{
|
||||||
if ( singleCasinoDescriptor.isObject() )
|
if ( singleCasinoDescriptor.isObject() )
|
||||||
{
|
{
|
||||||
m_aActiveCasinos.append( JsonSingleActivePromotion( singleCasinoDescriptor.toObject() ) );
|
m_aActivePromotions.append( JsonSingleActivePromotion( singleCasinoDescriptor.toObject() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,10 +34,21 @@ void JsonActivePromotionsParser::ResolvePromotionsArray()
|
|||||||
|
|
||||||
const QList<JsonSingleActivePromotion>& JsonActivePromotionsParser::GetPromotions() const
|
const QList<JsonSingleActivePromotion>& JsonActivePromotionsParser::GetPromotions() const
|
||||||
{
|
{
|
||||||
return m_aActiveCasinos;
|
return m_aActivePromotions;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<JsonSingleActivePromotion>& JsonActivePromotionsParser::GetPromotions()
|
QList<JsonSingleActivePromotion>& JsonActivePromotionsParser::GetPromotions()
|
||||||
{
|
{
|
||||||
return m_aActiveCasinos;
|
return m_aActivePromotions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonActivePromotionsParser::AddImagesToPool( QmlImageProvider* a_pImageProvider )
|
||||||
|
{
|
||||||
|
if ( a_pImageProvider )
|
||||||
|
{
|
||||||
|
foreach( JsonSingleActivePromotion oPromotion, m_aActivePromotions )
|
||||||
|
{
|
||||||
|
a_pImageProvider->AddToImagePool( oPromotion.GetImageName(), oPromotion.GetAdvertImage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "jsonsingleactivepromotion.h"
|
#include "jsonsingleactivepromotion.h"
|
||||||
|
|
||||||
|
class QmlImageProvider;
|
||||||
|
|
||||||
class JsonActivePromotionsParser : public QJsonObject
|
class JsonActivePromotionsParser : public QJsonObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -17,11 +19,13 @@ public:
|
|||||||
|
|
||||||
const QList<JsonSingleActivePromotion>& GetPromotions() const;
|
const QList<JsonSingleActivePromotion>& GetPromotions() const;
|
||||||
QList<JsonSingleActivePromotion>& GetPromotions();
|
QList<JsonSingleActivePromotion>& GetPromotions();
|
||||||
private:
|
|
||||||
|
|
||||||
|
void AddImagesToPool( QmlImageProvider* a_pImageProvider );
|
||||||
|
|
||||||
|
private:
|
||||||
void ResolvePromotionsArray();
|
void ResolvePromotionsArray();
|
||||||
|
|
||||||
QList<JsonSingleActivePromotion> m_aActiveCasinos;
|
QList<JsonSingleActivePromotion> m_aActivePromotions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JSONACTIVEPROMOTIONSPARSER_H
|
#endif // JSONACTIVEPROMOTIONSPARSER_H
|
||||||
|
|||||||
@@ -14,40 +14,21 @@ JsonSingleActivePromotion::JsonSingleActivePromotion()
|
|||||||
JsonSingleActivePromotion::JsonSingleActivePromotion( const QJsonObject& a_rOther )
|
JsonSingleActivePromotion::JsonSingleActivePromotion( const QJsonObject& a_rOther )
|
||||||
: QJsonObject( a_rOther )
|
: QJsonObject( a_rOther )
|
||||||
{
|
{
|
||||||
|
m_strImageName = find( "promotion_title" ).value().toString().remove( GetRestrictedCharacters() );
|
||||||
StoreImage();
|
StoreImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JsonSingleActivePromotion::GetImagePath() const
|
QRegExp JsonSingleActivePromotion::GetRestrictedCharacters()
|
||||||
{
|
{
|
||||||
return QString( "file://" + QDir::currentPath() + "/" + GetImageRelativePath() );
|
return QRegExp( "[<,>|\\:()&;#?*% ]" );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JsonSingleActivePromotion::GetImageRelativePath() const
|
void JsonSingleActivePromotion::StoreImage()
|
||||||
{
|
{
|
||||||
return QString( "adverts/" + find( "promotion_title" ).value().toString().remove( " " ) + "." + find( "image_mime_type" ).value().toString().split( "/" ).last() );
|
|
||||||
}
|
|
||||||
|
|
||||||
QString JsonSingleActivePromotion::StoreImage()
|
|
||||||
{
|
|
||||||
QString strReturn = QString();
|
|
||||||
if ( find( "image_mime_type" ).value().toString().split( "/" ).first().contains( "image" ) )
|
if ( find( "image_mime_type" ).value().toString().split( "/" ).first().contains( "image" ) )
|
||||||
{
|
{
|
||||||
QString strFileName = GetImageRelativePath();
|
|
||||||
QByteArray binaryData = QByteArray::fromBase64( find( "promotion_image" ).value().toString().toLocal8Bit() );
|
QByteArray binaryData = QByteArray::fromBase64( find( "promotion_image" ).value().toString().toLocal8Bit() );
|
||||||
|
m_oAdvertImage = QImage::fromData( binaryData );
|
||||||
if ( !QDir( "adverts" ).exists() )
|
|
||||||
{
|
|
||||||
QDir().mkdir( "adverts" );
|
|
||||||
}
|
|
||||||
QFile imageOutputFile( strFileName );
|
|
||||||
QImage outputImage = QImage::fromData( binaryData, "JPEG" );
|
|
||||||
if ( imageOutputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
|
||||||
{
|
|
||||||
outputImage.save( &imageOutputFile, 0 );
|
|
||||||
imageOutputFile.close();
|
|
||||||
strReturn = strFileName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return strReturn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
class JsonSingleActivePromotion : public QJsonObject
|
class JsonSingleActivePromotion : public QJsonObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -12,11 +14,16 @@ public:
|
|||||||
JsonSingleActivePromotion( const QJsonObject& a_rOther );
|
JsonSingleActivePromotion( const QJsonObject& a_rOther );
|
||||||
virtual ~JsonSingleActivePromotion(){}
|
virtual ~JsonSingleActivePromotion(){}
|
||||||
|
|
||||||
QString GetImagePath() const;
|
QString GetImageName() const{ return m_strImageName; }
|
||||||
|
QImage GetAdvertImage() const { return m_oAdvertImage; }
|
||||||
private:
|
private:
|
||||||
QString GetImageRelativePath() const;
|
void StoreImage();
|
||||||
QString StoreImage();
|
|
||||||
|
static QRegExp GetRestrictedCharacters();
|
||||||
|
|
||||||
|
QString m_strImageName;
|
||||||
|
QImage m_oAdvertImage;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JSONSINGLEACTIVEPROMOTION_H
|
#endif // JSONSINGLEACTIVEPROMOTION_H
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void GUIBannerControl::InitializeAdvertsView( GUIBannerListView* a_pView )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIBannerControl::slotPopulateFromWeb( JsonActivePromotionsParser* a_pActivePromotions )
|
void GUIBannerControl::slotPopulateListView( JsonActivePromotionsParser* a_pActivePromotions )
|
||||||
{
|
{
|
||||||
if ( m_pAdvertsView )
|
if ( m_pAdvertsView )
|
||||||
{
|
{
|
||||||
@@ -39,13 +39,3 @@ void GUIBannerControl::slotPopulateFromWeb( JsonActivePromotionsParser* a_pActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIBannerControl::slotPopulateLocally()
|
|
||||||
{
|
|
||||||
if ( m_pAdvertsView )
|
|
||||||
{
|
|
||||||
QmlBannerListModel* pAdvertsModel = new QmlBannerListModel( 0 );
|
|
||||||
m_pAdvertsView->SetModel( pAdvertsModel );
|
|
||||||
qDebug() << "Coming soon";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ public:
|
|||||||
GUIBannerListView* GetAdvertsView() const { return m_pAdvertsView; }
|
GUIBannerListView* GetAdvertsView() const { return m_pAdvertsView; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slotPopulateFromWeb( JsonActivePromotionsParser* a_pActivePromotions );
|
void slotPopulateListView( JsonActivePromotionsParser* a_pActivePromotions );
|
||||||
void slotPopulateLocally();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ GUIBannerWidget::GUIBannerWidget(QWidget *parent)
|
|||||||
, m_pBannerControl( 0 )
|
, m_pBannerControl( 0 )
|
||||||
, m_pWebApiParserTemporary( new CasinoCoinWebAPIParser( this ) )
|
, m_pWebApiParserTemporary( new CasinoCoinWebAPIParser( this ) )
|
||||||
, m_pWebApiTemporary( new CasinoCoinWebAPI( this ) )
|
, m_pWebApiTemporary( new CasinoCoinWebAPI( this ) )
|
||||||
|
, m_pQmlImageProvider( 0 )
|
||||||
{
|
{
|
||||||
registerCustomQmlTypes();
|
registerCustomQmlTypes();
|
||||||
connect( m_pWebApiTemporary, SIGNAL( signalResponseReady(const QByteArray&)), m_pWebApiParserTemporary, SLOT( slotParseAnswer(const QByteArray&)), Qt::UniqueConnection );
|
connect( m_pWebApiTemporary, SIGNAL( signalResponseReady(const QByteArray&)), m_pWebApiParserTemporary, SLOT( slotParseAnswer(const QByteArray&)), Qt::UniqueConnection );
|
||||||
connect( m_pWebApiTemporary, SIGNAL( signalNetworkError(QNetworkReply::NetworkError)), this, SLOT( slotNetworkError(QNetworkReply::NetworkError)), Qt::UniqueConnection );
|
connect( m_pWebApiTemporary, SIGNAL( signalNetworkError(QNetworkReply::NetworkError,const QUrl)), m_pWebApiParserTemporary, SLOT( slotNetworkError(QNetworkReply::NetworkError,const QUrl)), Qt::UniqueConnection );
|
||||||
|
connect( m_pWebApiParserTemporary, SIGNAL( signalActivePromotionsParsed(JsonActivePromotionsParser*)), this, SLOT( slotPopulateFromWeb(JsonActivePromotionsParser*)), Qt::UniqueConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
GUIBannerWidget::~GUIBannerWidget()
|
GUIBannerWidget::~GUIBannerWidget()
|
||||||
@@ -36,14 +38,18 @@ void GUIBannerWidget::registerCustomQmlTypes()
|
|||||||
qmlRegisterType<GUIBannerControl>("CasinoCoinControls", 1, 0, "GUIBannerControl" );
|
qmlRegisterType<GUIBannerControl>("CasinoCoinControls", 1, 0, "GUIBannerControl" );
|
||||||
qmlRegisterType<GUIBannerListView>("CasinoCoinControls", 1, 0, "GUIBannerListView" );
|
qmlRegisterType<GUIBannerListView>("CasinoCoinControls", 1, 0, "GUIBannerListView" );
|
||||||
qmlRegisterType<QmlBannerListModel>("CasinoCoinControls", 1, 0, "QmlBannerListModel" );
|
qmlRegisterType<QmlBannerListModel>("CasinoCoinControls", 1, 0, "QmlBannerListModel" );
|
||||||
qmlRegisterType<QmlImageProvider>("CasinoCoinControls", 1, 0, "QmlImageProvider" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* GUIBannerWidget::dockQmlToWidget()
|
QWidget* GUIBannerWidget::dockQmlToWidget()
|
||||||
{
|
{
|
||||||
QQuickView* pBannerWindow = new QQuickView;
|
QQuickView* pBannerWindow = new QQuickView;
|
||||||
pBannerWindow->setSource( QUrl( QStringLiteral( "qrc:/qml/qtquick_controls/qml/QmlGUIBannerWindow.qml" ) ) );
|
pBannerWindow->setSource( QUrl( QStringLiteral( "qrc:/qml/qtquick_controls/qml/QmlGUIBannerWindow.qml" ) ) );
|
||||||
|
QQmlEngine* pEngine = pBannerWindow->engine();
|
||||||
|
if ( pEngine )
|
||||||
|
{
|
||||||
|
m_pQmlImageProvider = new QmlImageProvider();
|
||||||
|
pEngine->addImageProvider( "advertImages", m_pQmlImageProvider );
|
||||||
|
}
|
||||||
QWidget* pPlaceHolder = QWidget::createWindowContainer( pBannerWindow, this );
|
QWidget* pPlaceHolder = QWidget::createWindowContainer( pBannerWindow, this );
|
||||||
pPlaceHolder->setMinimumSize( 445, 120 );
|
pPlaceHolder->setMinimumSize( 445, 120 );
|
||||||
pPlaceHolder->setMaximumSize( 445, 120 );
|
pPlaceHolder->setMaximumSize( 445, 120 );
|
||||||
@@ -54,10 +60,6 @@ QWidget* GUIBannerWidget::dockQmlToWidget()
|
|||||||
m_pBannerControl = pRootObject->findChild<GUIBannerControl*>();
|
m_pBannerControl = pRootObject->findChild<GUIBannerControl*>();
|
||||||
if ( m_pBannerControl )
|
if ( m_pBannerControl )
|
||||||
{
|
{
|
||||||
if ( m_pWebApiParserTemporary )
|
|
||||||
{
|
|
||||||
connect( m_pWebApiParserTemporary, SIGNAL( signalActivePromotionsParsed(JsonActivePromotionsParser*)), m_pBannerControl, SLOT( slotPopulateFromWeb(JsonActivePromotionsParser*)), Qt::UniqueConnection );
|
|
||||||
}
|
|
||||||
m_pBannerControl->setWidth( ( 115 * 3 ) + ( 4 * 10 ) + 60 );
|
m_pBannerControl->setWidth( ( 115 * 3 ) + ( 4 * 10 ) + 60 );
|
||||||
m_pBannerControl->setHeight( 115 );
|
m_pBannerControl->setHeight( 115 );
|
||||||
}
|
}
|
||||||
@@ -74,15 +76,14 @@ void GUIBannerWidget::PopulateBannerFromWeb()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIBannerWidget::PopulateBannerLocally()
|
void GUIBannerWidget::slotPopulateFromWeb( JsonActivePromotionsParser* a_pPromotionsParser )
|
||||||
{
|
{
|
||||||
|
if ( a_pPromotionsParser )
|
||||||
|
{
|
||||||
|
a_pPromotionsParser->AddImagesToPool( m_pQmlImageProvider );
|
||||||
|
}
|
||||||
if ( m_pBannerControl )
|
if ( m_pBannerControl )
|
||||||
{
|
{
|
||||||
m_pBannerControl->slotPopulateLocally();
|
m_pBannerControl->slotPopulateListView( a_pPromotionsParser );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIBannerWidget::slotNetworkError( QNetworkReply::NetworkError a_eError )
|
|
||||||
{
|
|
||||||
PopulateBannerLocally();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
class CasinoCoinWebAPIParser;
|
class CasinoCoinWebAPIParser;
|
||||||
class CasinoCoinWebAPI;
|
class CasinoCoinWebAPI;
|
||||||
class GUIBannerControl;
|
class GUIBannerControl;
|
||||||
|
class QmlImageProvider;
|
||||||
|
class JsonActivePromotionsParser;
|
||||||
|
|
||||||
class GUIBannerWidget : public QWidget
|
class GUIBannerWidget : public QWidget
|
||||||
{
|
{
|
||||||
@@ -28,9 +30,9 @@ private:
|
|||||||
|
|
||||||
CasinoCoinWebAPIParser* m_pWebApiParserTemporary;
|
CasinoCoinWebAPIParser* m_pWebApiParserTemporary;
|
||||||
CasinoCoinWebAPI* m_pWebApiTemporary;
|
CasinoCoinWebAPI* m_pWebApiTemporary;
|
||||||
|
QmlImageProvider* m_pQmlImageProvider;
|
||||||
private slots:
|
private slots:
|
||||||
void slotNetworkError( QNetworkReply::NetworkError a_eError );
|
void slotPopulateFromWeb( JsonActivePromotionsParser* a_pPromotionsParser );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUIBANNERWIDGET_H
|
#endif // GUIBANNERWIDGET_H
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ QmlBannerListItem::QmlBannerListItem(QString a_strImageSource, QString a_strDest
|
|||||||
}
|
}
|
||||||
|
|
||||||
QmlBannerListItem::QmlBannerListItem( const JsonSingleActivePromotion& a_rCasinoDescription, QObject* a_pParent )
|
QmlBannerListItem::QmlBannerListItem( const JsonSingleActivePromotion& a_rCasinoDescription, QObject* a_pParent )
|
||||||
: QmlListItem( QVariant( a_rCasinoDescription.GetImagePath() ), a_rCasinoDescription.find( "access_url" ).value().toVariant(), a_rCasinoDescription.find( "description" ).value().toVariant(), a_pParent )
|
: QmlListItem( QVariant( a_rCasinoDescription.GetImageName() ), a_rCasinoDescription.find( "access_url" ).value().toVariant(), a_rCasinoDescription.find( "description" ).value().toVariant(), a_pParent )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,34 @@
|
|||||||
#include "qmlimageprovider.h"
|
#include "qmlimageprovider.h"
|
||||||
|
|
||||||
QmlImageProvider::QmlImageProvider( QQuickItem* a_pParent )
|
#include <QDebug>
|
||||||
: QQuickPaintedItem( a_pParent )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
QmlImageProvider::QmlImageProvider()
|
||||||
|
: QQuickImageProvider( QQuickImageProvider::Image )
|
||||||
QmlImageProvider::QmlImageProvider( const QImage& a_rImage, QQuickItem* a_pParent )
|
|
||||||
: QQuickPaintedItem( a_pParent )
|
|
||||||
, m_oImage( a_rImage )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlImageProvider::SetImage( const QImage& a_rImage )
|
void QmlImageProvider::AddToImagePool( QString a_strImageID, const QImage& a_rImage )
|
||||||
{
|
{
|
||||||
if ( a_rImage != m_oImage )
|
m_aImagePool.insert( a_strImageID, a_rImage );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlImageProvider::AddToImagePool( const QMap<QString, QImage>& a_aImages )
|
||||||
|
{
|
||||||
|
QMapIterator<QString,QImage> iter( a_aImages );
|
||||||
|
while( iter.hasNext() )
|
||||||
{
|
{
|
||||||
m_oImage = QImage( a_rImage );
|
iter.next();
|
||||||
emit signalImageChanged();
|
AddToImagePool( iter.key(), iter.value() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlImageProvider::paint( QPainter* a_pPainter )
|
QImage QmlImageProvider::requestImage( const QString& a_rImageID, QSize* a_pSize, const QSize& a_ra_rRequestedSize )
|
||||||
{
|
{
|
||||||
if ( a_pPainter )
|
QImage oImage( m_aImagePool.value( a_rImageID ) );
|
||||||
|
if ( a_pSize )
|
||||||
{
|
{
|
||||||
a_pPainter->drawImage( QPoint( 0, 0 ), m_oImage );
|
a_pSize->setWidth( oImage.width() );
|
||||||
}
|
a_pSize->setHeight( oImage.height() );
|
||||||
}
|
|
||||||
|
|
||||||
void QmlImageProvider::paintImage( const QImage& a_rImage, QPainter* a_pPainter )
|
|
||||||
{
|
|
||||||
SetImage( a_rImage );
|
|
||||||
if ( a_pPainter )
|
|
||||||
{
|
|
||||||
a_pPainter->drawImage( QPoint( 0, 0 ), m_oImage );
|
|
||||||
}
|
}
|
||||||
|
return oImage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,28 @@
|
|||||||
#ifndef QMLIMAGEPROVIDER_H
|
#ifndef QMLIMAGEPROVIDER_H
|
||||||
#define QMLIMAGEPROVIDER_H
|
#define QMLIMAGEPROVIDER_H
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
#include <QQuickImageProvider>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
class QmlImageProvider : public QQuickPaintedItem
|
class QmlImageProvider : public QQuickImageProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY( QImage p_oImage MEMBER m_oImage NOTIFY signalImageChanged )
|
|
||||||
public:
|
public:
|
||||||
explicit QmlImageProvider( QQuickItem* a_pParent = 0 );
|
explicit QmlImageProvider();
|
||||||
explicit QmlImageProvider( const QImage& a_rImage, QQuickItem* a_pParent = 0 );
|
|
||||||
|
|
||||||
void SetImage( const QImage& a_rImage );
|
void AddToImagePool( QString a_strImageID, const QImage& a_rImage );
|
||||||
virtual void paint( QPainter* a_pPainter );
|
void AddToImagePool( const QMap<QString,QImage>& a_aImages );
|
||||||
void paintImage( const QImage& a_rImage, QPainter* a_pPainter );
|
|
||||||
|
virtual QImage requestImage
|
||||||
|
( const QString& a_rImageID
|
||||||
|
, QSize* a_pSize
|
||||||
|
, const QSize& a_rRequestedSize
|
||||||
|
);
|
||||||
signals:
|
signals:
|
||||||
void signalImageChanged();
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage m_oImage;
|
QMap<QString,QImage> m_aImagePool;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QMLIMAGEPROVIDER_H
|
#endif // QMLIMAGEPROVIDER_H
|
||||||
|
|||||||
@@ -46,18 +46,11 @@ GUIBannerListView
|
|||||||
Image
|
Image
|
||||||
{
|
{
|
||||||
id: id_advertisementImage
|
id: id_advertisementImage
|
||||||
source: m_imageSource
|
source: "image://advertImages/" + m_imageSource
|
||||||
scale: ( id_listElement.width / width )
|
scale: ( id_listElement.width / width )
|
||||||
anchors.centerIn: id_listElement
|
anchors.centerIn: id_listElement
|
||||||
}
|
}
|
||||||
|
|
||||||
// coming soon
|
|
||||||
// QmlImageProvider
|
|
||||||
// {
|
|
||||||
// id: id_advertisementImage
|
|
||||||
// scale: ( id_listElement.width / width )
|
|
||||||
// anchors.centerIn: id_listElement
|
|
||||||
// }
|
|
||||||
MouseArea
|
MouseArea
|
||||||
{
|
{
|
||||||
id: id_leftItemMouseArea
|
id: id_leftItemMouseArea
|
||||||
|
|||||||
Reference in New Issue
Block a user