--- /dev/null
+/*
+ * Copyright (c) 2009 Eetu Lehmusvuo.
+ *
+ * This file is part of QtMAds.
+ *
+ * QtMAds is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * QtMAds is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with QtMAds. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtGui>
+
+#include "qtmadsbannerad.h"
+
+#include <QApplication>
+#include <QUrl>
+#include <QDebug>
+#include <QWebView>
+#include <QWebFrame>
+
+#include "qtmadsservice.h"
+
+QtmadsBannerAd::QtmadsBannerAd(QString serviceName, quint32 adGroupId, AdFit fitting, QWidget *parent)
+ : QtmadsAdWidget(serviceName, imageBannerAd, adGroupId, fitting, parent)
+{
+ this->webView = new QWebView(this);
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ this->setLayout(layout);
+ this->layout()->addWidget(webView);
+
+ this->webView->hide();
+
+ QPalette palette = this->webView->palette();
+ palette.setColor(QPalette::Background, QColor(Qt::transparent));
+ this->webView->setPalette(palette);
+
+ QPalette palette1 = this->webView->palette();
+ palette1.setColor(QPalette::Background, QColor(Qt::transparent));
+ this->webView->page()->setPalette(palette1);
+}
+
+QtmadsBannerAd::~QtmadsBannerAd()
+{
+ this->clearAd();
+}
+
+ParseState QtmadsBannerAd::parseFromParameters(QHash<QString, QVariant> &ad)
+{
+ ParseState parseSuccess = parseFailed;
+
+ QHash<QString, QVariant>::iterator iter;
+
+ for(iter = ad.begin(); iter != ad.end(); iter++){
+ qDebug() << "key: " << iter.key() << " value: " << iter.value().toString();
+ /*if(0 == iter.key().compare(TAG_URL)){
+ adUrl.setUrl(iter.value().toString());
+
+ }else */
+ if(0 == iter.key().compare(TAG_HTML)){
+ this->webView->setHtml(iter.value().toString());
+ connect(webView->page(), SIGNAL(linkClicked(const QUrl &)),this, SLOT(adClicked(const QUrl &)));
+ webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+ this->webView->show();
+
+ //TODO: correct margins; this is just hack to remove margins..
+ this->webView->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
+ this->webView->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
+ this->setContentsMargins(-17,-17,-17,-17);
+
+ parseSuccess = parseReady;
+
+ qDebug() << "##########font size: " << this->webView->palette().color(QPalette::Background).alpha();
+ qDebug() << "##########page color alpha: " << this->webView->page()->palette().color(QPalette::Background).alpha();
+
+ }else if(0 == iter.key().compare(TAG_ADTYPE)){
+ this->setAdType(this->service->getAdTypeFromString(iter.value().toString()));
+
+ }else{
+ qDebug() << "Unknown tag.";
+ }
+ }
+ qDebug() << "parseFromParameters(): " << parseSuccess;
+ return parseSuccess;
+}
+
+void QtmadsBannerAd::setAdFontSize(quint32 fontSize)
+{
+ this->webView->page()->settings()->setFontSize(QWebSettings::MinimumFontSize, fontSize);
+}
+
+void QtmadsBannerAd::getAdAsHash(QHash<QString, QVariant> &adParams)
+{
+ //adParams.insert("adsize", QVariant(this->sizeHint()));
+}
+
+void QtmadsBannerAd::setAsBannerAd(bool isOnlyBannerAd)
+{
+ if(isOnlyBannerAd){
+ this->service->setDefaultAdType(imageBannerAd);
+ }else{
+ //TODO: HASH it
+ if(this->service->defaultAdType() != imageBannerAd)
+ this->service->setDefaultAdType(anyAd);
+ }
+}
+
+
+void QtmadsBannerAd::setAsTextBannerAd(bool isOnlyTextBannerAd)
+{
+ if(isOnlyTextBannerAd){
+ this->service->setDefaultAdType(txtBannerAd);
+ }else{
+ //TODO: HASH it
+ if(this->service->defaultAdType() != txtBannerAd)
+ this->service->setDefaultAdType(anyAd);
+ }
+}
+
+void QtmadsBannerAd::clearAd()
+{
+ disconnect(webView->page(), SIGNAL(linkClicked(const QUrl &)),this, SLOT(adClicked(const QUrl &)));
+ this->webView->hide();
+}