2 * Copyright (c) 2009 Eetu Lehmusvuo.
4 * This file is part of QtMAds.
6 * QtMAds is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * QtMAds is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with QtMAds. If not, see <http://www.gnu.org/licenses/>.
23 #include "qtmadsbannerad.h"
25 #include <QApplication>
31 #include "qtmadsservice.h"
33 QtmadsBannerAd::QtmadsBannerAd(QString serviceName, quint32 adGroupId, AdFit fitting, QWidget *parent)
34 : QtmadsAdWidget(serviceName, imageBannerAd, adGroupId, fitting, parent)
36 this->webView = new QWebView(this);
37 QHBoxLayout *layout = new QHBoxLayout(this);
38 this->setLayout(layout);
39 this->layout()->addWidget(webView);
41 this->webView->hide();
43 QPalette palette = this->webView->palette();
44 palette.setColor(QPalette::Background, QColor(Qt::transparent));
45 this->webView->setPalette(palette);
47 QPalette palette1 = this->webView->palette();
48 palette1.setColor(QPalette::Background, QColor(Qt::transparent));
49 this->webView->page()->setPalette(palette1);
52 QtmadsBannerAd::~QtmadsBannerAd()
57 ParseState QtmadsBannerAd::parseFromParameters(QHash<QString, QVariant> &ad)
59 ParseState parseSuccess = parseFailed;
61 QHash<QString, QVariant>::iterator iter;
63 for(iter = ad.begin(); iter != ad.end(); iter++){
64 qDebug() << "key: " << iter.key() << " value: " << iter.value().toString();
65 /*if(0 == iter.key().compare(TAG_URL)){
66 adUrl.setUrl(iter.value().toString());
69 if(0 == iter.key().compare(TAG_HTML)){
70 this->webView->setHtml(iter.value().toString());
71 connect(webView->page(), SIGNAL(linkClicked(const QUrl &)),this, SLOT(adClicked(const QUrl &)));
72 webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
73 this->webView->show();
75 //TODO: correct margins; this is just hack to remove margins..
76 this->webView->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
77 this->webView->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
78 this->setContentsMargins(-17,-17,-17,-17);
80 parseSuccess = parseReady;
82 qDebug() << "##########font size: " << this->webView->palette().color(QPalette::Background).alpha();
83 qDebug() << "##########page color alpha: " << this->webView->page()->palette().color(QPalette::Background).alpha();
85 }else if(0 == iter.key().compare(TAG_ADTYPE)){
86 this->setAdType(this->service->getAdTypeFromString(iter.value().toString()));
89 qDebug() << "Unknown tag.";
92 qDebug() << "parseFromParameters(): " << parseSuccess;
96 void QtmadsBannerAd::setAdFontSize(quint32 fontSize)
98 this->webView->page()->settings()->setFontSize(QWebSettings::MinimumFontSize, fontSize);
101 void QtmadsBannerAd::getAdAsHash(QHash<QString, QVariant> &adParams)
103 //adParams.insert("adsize", QVariant(this->sizeHint()));
106 void QtmadsBannerAd::setAsBannerAd(bool isOnlyBannerAd)
109 this->service->setDefaultAdType(imageBannerAd);
112 if(this->service->defaultAdType() != imageBannerAd)
113 this->service->setDefaultAdType(anyAd);
118 void QtmadsBannerAd::setAsTextBannerAd(bool isOnlyTextBannerAd)
120 if(isOnlyTextBannerAd){
121 this->service->setDefaultAdType(txtBannerAd);
124 if(this->service->defaultAdType() != txtBannerAd)
125 this->service->setDefaultAdType(anyAd);
129 void QtmadsBannerAd::clearAd()
131 disconnect(webView->page(), SIGNAL(linkClicked(const QUrl &)),this, SLOT(adClicked(const QUrl &)));
132 this->webView->hide();