X-Git-Url: http://git.maemo.org/git/?p=qtmads;a=blobdiff_plain;f=src%2Fqtmadsbannerad.cpp;fp=src%2Fqtmadsbannerad.cpp;h=5c5ea212118e6b076cbd548bd2a1da3d91b306fe;hp=0000000000000000000000000000000000000000;hb=e494cd05f1809789fd03d888c5592753d04f2031;hpb=4c87a3c868d40870d0eed21fb6e01c014acd3062 diff --git a/src/qtmadsbannerad.cpp b/src/qtmadsbannerad.cpp new file mode 100644 index 0000000..5c5ea21 --- /dev/null +++ b/src/qtmadsbannerad.cpp @@ -0,0 +1,133 @@ +/* + * 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 . + * + */ + +#include + +#include "qtmadsbannerad.h" + +#include +#include +#include +#include +#include + +#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 &ad) +{ + ParseState parseSuccess = parseFailed; + + QHash::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 &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(); +}