mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-04 12:29:46 -08:00
Adverts widget supports population from web and from local files.
This commit is contained in:
@@ -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 )
|
||||
{
|
||||
@@ -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; }
|
||||
|
||||
public slots:
|
||||
void slotPopulateFromWeb( JsonActivePromotionsParser* a_pActivePromotions );
|
||||
void slotPopulateLocally();
|
||||
void slotPopulateListView( JsonActivePromotionsParser* a_pActivePromotions );
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
@@ -20,10 +20,12 @@ GUIBannerWidget::GUIBannerWidget(QWidget *parent)
|
||||
, m_pBannerControl( 0 )
|
||||
, m_pWebApiParserTemporary( new CasinoCoinWebAPIParser( this ) )
|
||||
, m_pWebApiTemporary( new CasinoCoinWebAPI( this ) )
|
||||
, m_pQmlImageProvider( 0 )
|
||||
{
|
||||
registerCustomQmlTypes();
|
||||
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()
|
||||
@@ -36,14 +38,18 @@ void GUIBannerWidget::registerCustomQmlTypes()
|
||||
qmlRegisterType<GUIBannerControl>("CasinoCoinControls", 1, 0, "GUIBannerControl" );
|
||||
qmlRegisterType<GUIBannerListView>("CasinoCoinControls", 1, 0, "GUIBannerListView" );
|
||||
qmlRegisterType<QmlBannerListModel>("CasinoCoinControls", 1, 0, "QmlBannerListModel" );
|
||||
qmlRegisterType<QmlImageProvider>("CasinoCoinControls", 1, 0, "QmlImageProvider" );
|
||||
}
|
||||
|
||||
QWidget* GUIBannerWidget::dockQmlToWidget()
|
||||
{
|
||||
QQuickView* pBannerWindow = new QQuickView;
|
||||
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 );
|
||||
pPlaceHolder->setMinimumSize( 445, 120 );
|
||||
pPlaceHolder->setMaximumSize( 445, 120 );
|
||||
@@ -54,10 +60,6 @@ QWidget* GUIBannerWidget::dockQmlToWidget()
|
||||
m_pBannerControl = pRootObject->findChild<GUIBannerControl*>();
|
||||
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->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 )
|
||||
{
|
||||
m_pBannerControl->slotPopulateLocally();
|
||||
m_pBannerControl->slotPopulateListView( a_pPromotionsParser );
|
||||
}
|
||||
}
|
||||
|
||||
void GUIBannerWidget::slotNetworkError( QNetworkReply::NetworkError a_eError )
|
||||
{
|
||||
PopulateBannerLocally();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
class CasinoCoinWebAPIParser;
|
||||
class CasinoCoinWebAPI;
|
||||
class GUIBannerControl;
|
||||
class QmlImageProvider;
|
||||
class JsonActivePromotionsParser;
|
||||
|
||||
class GUIBannerWidget : public QWidget
|
||||
{
|
||||
@@ -28,9 +30,9 @@ private:
|
||||
|
||||
CasinoCoinWebAPIParser* m_pWebApiParserTemporary;
|
||||
CasinoCoinWebAPI* m_pWebApiTemporary;
|
||||
|
||||
QmlImageProvider* m_pQmlImageProvider;
|
||||
private slots:
|
||||
void slotNetworkError( QNetworkReply::NetworkError a_eError );
|
||||
void slotPopulateFromWeb( JsonActivePromotionsParser* a_pPromotionsParser );
|
||||
};
|
||||
|
||||
#endif // GUIBANNERWIDGET_H
|
||||
|
||||
@@ -8,7 +8,7 @@ QmlBannerListItem::QmlBannerListItem(QString a_strImageSource, QString a_strDest
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
QmlImageProvider::QmlImageProvider( QQuickItem* a_pParent )
|
||||
: QQuickPaintedItem( a_pParent )
|
||||
{
|
||||
#include <QDebug>
|
||||
|
||||
}
|
||||
|
||||
QmlImageProvider::QmlImageProvider( const QImage& a_rImage, QQuickItem* a_pParent )
|
||||
: QQuickPaintedItem( a_pParent )
|
||||
, m_oImage( a_rImage )
|
||||
QmlImageProvider::QmlImageProvider()
|
||||
: QQuickImageProvider( QQuickImageProvider::Image )
|
||||
{
|
||||
}
|
||||
|
||||
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 );
|
||||
emit signalImageChanged();
|
||||
iter.next();
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
void QmlImageProvider::paintImage( const QImage& a_rImage, QPainter* a_pPainter )
|
||||
{
|
||||
SetImage( a_rImage );
|
||||
if ( a_pPainter )
|
||||
{
|
||||
a_pPainter->drawImage( QPoint( 0, 0 ), m_oImage );
|
||||
a_pSize->setWidth( oImage.width() );
|
||||
a_pSize->setHeight( oImage.height() );
|
||||
}
|
||||
return oImage;
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
#ifndef QMLIMAGEPROVIDER_H
|
||||
#define QMLIMAGEPROVIDER_H
|
||||
|
||||
#include <QQuickPaintedItem>
|
||||
#include <QQuickImageProvider>
|
||||
#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:
|
||||
explicit QmlImageProvider( QQuickItem* a_pParent = 0 );
|
||||
explicit QmlImageProvider( const QImage& a_rImage, QQuickItem* a_pParent = 0 );
|
||||
explicit QmlImageProvider();
|
||||
|
||||
void SetImage( const QImage& a_rImage );
|
||||
virtual void paint( QPainter* a_pPainter );
|
||||
void paintImage( const QImage& a_rImage, QPainter* a_pPainter );
|
||||
void AddToImagePool( QString a_strImageID, const QImage& a_rImage );
|
||||
void AddToImagePool( const QMap<QString,QImage>& a_aImages );
|
||||
|
||||
virtual QImage requestImage
|
||||
( const QString& a_rImageID
|
||||
, QSize* a_pSize
|
||||
, const QSize& a_rRequestedSize
|
||||
);
|
||||
signals:
|
||||
void signalImageChanged();
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QImage m_oImage;
|
||||
QMap<QString,QImage> m_aImagePool;
|
||||
};
|
||||
|
||||
#endif // QMLIMAGEPROVIDER_H
|
||||
|
||||
Reference in New Issue
Block a user