Signed-off-by: Robin Burchell <virot...@viroteck.net> --- libseaside.pro | 2 + src/seasidelistitem.cpp | 171 +------------------- src/seasidelistitem.h | 24 +--- ...delistitemsmall.cpp => seasidelistitembase.cpp} | 112 +++----------- src/{seasidelistitem.h => seasidelistitembase.h} | 25 ++-- src/seasidelistitemlarge.cpp | 171 +------------------- src/seasidelistitemlarge.h | 24 +--- src/seasidelistitemsmall.cpp | 170 +------------------- src/seasidelistitemsmall.h | 24 +--- 9 files changed, 46 insertions(+), 677 deletions(-) copy src/{seasidelistitemsmall.cpp => seasidelistitembase.cpp} (57%) copy src/{seasidelistitem.h => seasidelistitembase.h} (78%)
diff --git a/libseaside.pro b/libseaside.pro index 0269ef3..f12d885 100644 --- a/libseaside.pro +++ b/libseaside.pro @@ -30,6 +30,7 @@ HEADERS += \ src/seasidelabel.h \ src/seasidelist.h \ src/seasidelistitem.h \ + src/seasidelistitembase.h \ src/seasidelistmodel.h \ src/seasideproxymodel.h \ src/seasidesyncmodel.h \ @@ -47,6 +48,7 @@ SOURCES += \ src/seasidelabel.cpp \ src/seasidelist.cpp \ src/seasidelistitem.cpp \ + src/seasidelistitembase.cpp \ src/seasidelistmodel.cpp \ src/seasidepersonmodel.cpp \ src/seasideproxymodel.cpp \ diff --git a/src/seasidelistitem.cpp b/src/seasidelistitem.cpp index 1f492ae..4a1de98 100644 --- a/src/seasidelistitem.cpp +++ b/src/seasidelistitem.cpp @@ -27,8 +27,7 @@ M_REGISTER_WIDGET(SeasideListItem); #define SCREEN_WIDTH 400 SeasideListItem::SeasideListItem(MWidget *parent, int mode) - : MWidgetController(parent) - , priv(new SeasideListItemPriv) + : SeasideListItemBase(parent) { setObjectName("SeasideListItem"); @@ -176,173 +175,5 @@ SeasideListItem::SeasideListItem(MWidget *parent, int mode) SeasideListItem::~SeasideListItem() { - delete priv; } -//REVISIT -void SeasideListItem::setPresence(const int presence){ - QString str= ""; - if(presence == Seaside::PresenceAvailable) - str = "icon-m-common-presence-online"; - else if(presence == Seaside::PresenceAway) - str = "icon-m-common-presence-away"; - else if(presence == Seaside::PresenceOffline) - str = "icon-m-common-presence-offline"; - else if(presence == Seaside::PresenceBusy) - str = "icon-m-common-presence-busy"; - else - str = "icon-m-common-presence-unknown"; - if(priv->presence) - priv->presence->setImage(str); -} - -void SeasideListItem::setFavorite(const bool& favorite){ - QString str= ""; - if(favorite) - str ="icon-s-common-favorite-mark"; - else - str = "icon-s-common-favorite-unmark"; - if(priv->favorite) - priv->favorite->setImage(str); -} - -void SeasideListItem::setButton(const QString & button){ - QString str= button; - if (str.isEmpty()) - str = "im-accounts-no-background"; - if(priv->button) - priv->button->setIconID(str); -} - -void SeasideListItem::setStatus(const QString& status){ - if(priv->status) - priv->status->setText(status); -} - -void SeasideListItem::setCommFlags(const int flags){ - if(!priv->call || !priv->email || !priv->im || !priv->sms) - return; - - if((flags & Seaside::CommCallDialed) == Seaside::CommCallDialed) - priv->call->setImage("icon-m-telephony-call-initiated"); - else if((flags & Seaside::CommCallReceived) == Seaside::CommCallReceived) - priv->call->setImage("icon-m-telephony-call-received"); - else if((flags & Seaside::CommCallMissed) == Seaside::CommCallMissed) - priv->call->setImage("icon-m-telephony-call-missed"); - if(((flags & Seaside::CommSmsSent) == Seaside::CommSmsSent) - || ((flags & Seaside::CommSmsReceived) == Seaside::CommSmsReceived)) - priv->sms->setImage("Icon-new-SMS"); - if(((flags & Seaside::CommEmailSent ) == Seaside::CommEmailSent) - || ((flags & Seaside::CommEmailReceived) == Seaside::CommEmailReceived)) - priv->email->setImage("Icon-email"); - if(((flags & Seaside::CommIMSent) == Seaside::CommIMSent) - || ((flags & Seaside::CommIMReceived) == Seaside::CommIMReceived)) - priv->im->setImage("Icon-messages"); -} - -void SeasideListItem::setThumbnail(const QString &thumbnail) -{ - QString str = thumbnail; - if (str.isEmpty()) - str= "icon-m-content-avatar-placeholder"; - if(priv->image) - priv->image->setPixmap(getAvatar(str)); -} - - -QPixmap SeasideListItem::getAvatar(QString avatar) -{ - const QPixmap *photo; - photo = MTheme::pixmap(avatar, QSize(64, 64)); - - - // create alpha mask - QImage mask(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter maskpainter(&mask); - //maskpainter.setRenderHint(QPainter::Antialiasing, true); - maskpainter.setCompositionMode(QPainter::CompositionMode_Source); - maskpainter.fillRect(mask.rect(), Qt::transparent); - maskpainter.setPen(QPen(Qt::transparent)); - maskpainter.setBrush(QBrush(Qt::white)); - maskpainter.drawRoundedRect(1.0, 1.0, 61.0, 61.0, 5.0, 5.0); - - // scale/crop photo - qreal x, y, w, h; - if (photo->width() > photo->height()) { - x = (photo->width() - photo->height()) / 2.0; - w = photo->height(); - y = 0.0; - h = photo->height(); - } else { - y = (photo->height() - photo->width()) / 2.0; - h = photo->width(); - x = 0.0; - w = photo->width(); - } - QImage tmp(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter tmppainter(&tmp); - //tmppainter.setRenderHint(QPainter::Antialiasing, true); - tmppainter.setCompositionMode(QPainter::CompositionMode_Source); - tmppainter.drawPixmap(tmp.rect(), *photo, QRectF(x, y, w, h)); - - // mask photo - tmppainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - tmppainter.drawImage(tmp.rect(), mask, mask.rect()); - - // create final image - QImage dst(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter painter(&dst); - //painter.setRenderHint(QPainter::Antialiasing, true); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(dst.rect(), Qt::transparent); - - // draw rounded rect background - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - QPen pen(QColor(0xB0, 0xB0, 0xB0)); - QBrush brush(Qt::white); - pen.setWidthF(1.0); - painter.setPen(pen); - painter.setBrush(brush); - painter.drawRoundedRect(0.0, 0.0, 63.0, 63.0, 5.0, 5.0); - - // draw masked photo - painter.drawImage(dst.rect(), tmp, tmp.rect()); - - - return QPixmap::fromImage(dst); -} - -void SeasideListItem::setName(const QString &name) -{ - if(priv->name) - priv->name->setText(name); -} - - void SeasideListItem::setDetails(const QStringList &details) -{ - if(!priv->detail) - return; - priv->detailList = new QStringList(details); - if(!details.isEmpty() && (details.count() > 0)){ - priv->detail->setText(details[0]); - } -} - - void SeasideListItem::setUuid(const QString &id) - { - if(!id.isNull()){ - priv->uuid = new QUuid(id); - } - } - -void SeasideListItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); -} - -void SeasideListItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); - if (sceneBoundingRect().contains(event->scenePos())) - emit clicked(); -} diff --git a/src/seasidelistitem.h b/src/seasidelistitem.h index 288394d..3665fcd 100644 --- a/src/seasidelistitem.h +++ b/src/seasidelistitem.h @@ -13,7 +13,7 @@ #include <MWidgetController> #include "seaside.h" -class SeasideListItemPriv; +#include "seasidelistitembase.h" /* * SeasideListItem: Styling Notes @@ -26,7 +26,7 @@ class SeasideListItemPriv; * */ -class SeasideListItem: public MWidgetController +class SeasideListItem : public SeasideListItemBase { Q_OBJECT @@ -34,27 +34,7 @@ public: SeasideListItem(MWidget *parent = NULL, int mode =0); virtual ~SeasideListItem(); - void setThumbnail(const QString& thumbnail); - void setName(const QString& name); - void setUuid(const QString& id); - void setDetails(const QStringList& detail); //REVISIT phone or email or IM - void setPresence(const int presence); - void setFavorite(const bool& favorite); - void setButton(const QString& hasButton); - void setStatus(const QString& status); - void setCommFlags(const int flags); - -signals: - void clicked(); - void buttonClicked(); - -protected slots: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - private: - SeasideListItemPriv *priv; - QPixmap getAvatar(QString avatar); Q_DISABLE_COPY(SeasideListItem); }; diff --git a/src/seasidelistitemsmall.cpp b/src/seasidelistitembase.cpp similarity index 57% copy from src/seasidelistitemsmall.cpp copy to src/seasidelistitembase.cpp index 8623c42..4e4d688 100644 --- a/src/seasidelistitemsmall.cpp +++ b/src/seasidelistitembase.cpp @@ -1,5 +1,5 @@ /* - * libseaside - Library that provides an interface to the Contacts application + * Libseaside - Library that provides an interface to the Contacts application * Copyright © 2010, Intel Corporation. * * This program is licensed under the terms and conditions of the @@ -8,101 +8,29 @@ * */ -#include <QGraphicsGridLayout> #include <QGraphicsSceneMouseEvent> -#include <QUuid> #include <MImageWidget> -#include <MLabel> #include <MButton> -#include "seasidelistitemsmall.h" +#include "seaside.h" +#include "seasidelistitembase.h" #include "seasidelistitem_p.h" -#include "seasidelabel.h" -#include <MWidgetCreator> -#include <QDebug> - -M_REGISTER_WIDGET(SeasideListItemSmall) - -#define SCREEN_WIDTH 400 - -SeasideListItemSmall::SeasideListItemSmall(MWidget *parent) +SeasideListItemBase::SeasideListItemBase(MWidget *parent) : MWidgetController(parent) , priv(new SeasideListItemPriv) { - setObjectName("SeasideListItemSmall"); - - QGraphicsGridLayout *grid = new QGraphicsGridLayout; - grid->setContentsMargins(0, 0, 0, 0); - grid->setSpacing(0); - setLayout(grid); - - priv->status = new SeasideLabel; - priv->button = new MButton; - priv->detail = new SeasideLabel; - - priv->image = new MImageWidget(); - priv->image->setObjectName("SeasideListItemSmallThumbnail"); - priv->image->setPreferredSize(64, 64); - priv->image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->image, 0, 0, 2, 2); - - priv->name = new SeasideLabel; - priv->name->setObjectName("SeasideListItemSmallName"); - priv->name->setPreferredWidth(SCREEN_WIDTH); - priv->name->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); - grid->addItem(priv->name, 0, 2, 1, 1); - - priv->favorite = new MImageWidget(); - priv->favorite->setObjectName("SeasideListItemSmallFavorite"); - priv->favorite->setPreferredSize(25, 25); - priv->favorite->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->favorite, 1, 3, 1, 1); - - priv->status = new SeasideLabel; - priv->status->setObjectName("SeasideListItemSmallStatus"); - priv->name->setPreferredWidth(SCREEN_WIDTH); - priv->name->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - grid->addItem(priv->status, 0, 4, 1, 3); - - priv->presence = new MImageWidget(); - priv->presence->setObjectName("SeasideListItemSmallPresence"); - priv->presence->setPreferredSize(25, 25); - priv->presence->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->presence, 1, 2, 1, 1); - - priv->email = new MImageWidget(); - priv->email->setObjectName("SeasideListItemSmallEmail"); - priv->email->setPreferredSize(25, 25); - priv->email->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->email, 1, 5, 1, 1); - - priv->sms = new MImageWidget(); - priv->sms->setObjectName("SeasideListItemSmallSMS"); - priv->sms->setPreferredSize(25, 25); - priv->sms->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->sms, 1,4, 1, 1); - - priv->im = new MImageWidget(); - priv->im->setObjectName("SeasideListItemSmallIM"); - priv->im->setPreferredSize(25, 25); - priv->im->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->im, 1, 3, 1, 1); - priv->call = new MImageWidget(); - priv->call->setObjectName("SeasideListItemSmallCall"); - priv->call->setPreferredSize(25, 25); - priv->call->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - grid->addItem(priv->call, 1, 6, 1, 1); } -SeasideListItemSmall::~SeasideListItemSmall() +SeasideListItemBase::~SeasideListItemBase() { delete priv; } -void SeasideListItemSmall::setPresence(const int presence){ +//REVISIT +void SeasideListItemBase::setPresence(const int presence){ QString str= ""; if(presence == Seaside::PresenceAvailable) str = "icon-m-common-presence-online"; @@ -118,17 +46,17 @@ void SeasideListItemSmall::setPresence(const int presence){ priv->presence->setImage(str); } -void SeasideListItemSmall::setFavorite(const bool& favorite){ +void SeasideListItemBase::setFavorite(const bool& favorite){ QString str= ""; if(favorite) - str ="icon-m-common-favorite-mark"; + str ="icon-s-common-favorite-mark"; else - str = ""; + str = "icon-s-common-favorite-unmark"; if(priv->favorite) priv->favorite->setImage(str); } -void SeasideListItemSmall::setButton(const QString & button){ +void SeasideListItemBase::setButton(const QString & button){ QString str= button; if (str.isEmpty()) str = "im-accounts-no-background"; @@ -136,12 +64,12 @@ void SeasideListItemSmall::setButton(const QString & button){ priv->button->setIconID(str); } -void SeasideListItemSmall::setStatus(const QString& status){ +void SeasideListItemBase::setStatus(const QString& status){ if(priv->status) priv->status->setText(status); } -void SeasideListItemSmall::setCommFlags(const int flags){ +void SeasideListItemBase::setCommFlags(const int flags){ if(!priv->call || !priv->email || !priv->im || !priv->sms) return; @@ -162,7 +90,7 @@ void SeasideListItemSmall::setCommFlags(const int flags){ priv->im->setImage("Icon-messages"); } -void SeasideListItemSmall::setThumbnail(const QString &thumbnail) +void SeasideListItemBase::setThumbnail(const QString &thumbnail) { QString str = thumbnail; if (str.isEmpty()) @@ -172,7 +100,7 @@ void SeasideListItemSmall::setThumbnail(const QString &thumbnail) } -QPixmap SeasideListItemSmall::getAvatar(QString avatar) +QPixmap SeasideListItemBase::getAvatar(QString avatar) { const QPixmap *photo; photo = MTheme::pixmap(avatar, QSize(64, 64)); @@ -234,13 +162,13 @@ QPixmap SeasideListItemSmall::getAvatar(QString avatar) return QPixmap::fromImage(dst); } -void SeasideListItemSmall::setName(const QString &name) +void SeasideListItemBase::setName(const QString &name) { if(priv->name) priv->name->setText(name); } - void SeasideListItemSmall::setDetails(const QStringList &details) + void SeasideListItemBase::setDetails(const QStringList &details) { if(!priv->detail) return; @@ -250,19 +178,19 @@ void SeasideListItemSmall::setName(const QString &name) } } - void SeasideListItemSmall::setUuid(const QString &id) + void SeasideListItemBase::setUuid(const QString &id) { if(!id.isNull()){ priv->uuid = new QUuid(id); } } -void SeasideListItemSmall::mousePressEvent(QGraphicsSceneMouseEvent *event) +void SeasideListItemBase::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); } -void SeasideListItemSmall::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void SeasideListItemBase::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); if (sceneBoundingRect().contains(event->scenePos())) diff --git a/src/seasidelistitem.h b/src/seasidelistitembase.h similarity index 78% copy from src/seasidelistitem.h copy to src/seasidelistitembase.h index 288394d..c722540 100644 --- a/src/seasidelistitem.h +++ b/src/seasidelistitembase.h @@ -8,13 +8,18 @@ * */ -#ifndef SEASIDELISTITEM_H -#define SEASIDELISTITEM_H +#ifndef SEASIDELISTITEMBASE_H +#define SEASIDELISTITEMBASE_H + +#include <QObject> +#include <QGraphicsSceneMouseEvent> +#include <QPixmap> #include <MWidgetController> -#include "seaside.h" -class SeasideListItemPriv; +struct SeasideListItemPriv; + + /* * SeasideListItem: Styling Notes * @@ -26,13 +31,13 @@ class SeasideListItemPriv; * */ -class SeasideListItem: public MWidgetController +class SeasideListItemBase : public MWidgetController { Q_OBJECT public: - SeasideListItem(MWidget *parent = NULL, int mode =0); - virtual ~SeasideListItem(); + SeasideListItemBase(MWidget *parent = NULL); + virtual ~SeasideListItemBase(); void setThumbnail(const QString& thumbnail); void setName(const QString& name); @@ -52,10 +57,10 @@ protected slots: void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); -private: +protected: SeasideListItemPriv *priv; QPixmap getAvatar(QString avatar); - Q_DISABLE_COPY(SeasideListItem); + Q_DISABLE_COPY(SeasideListItemBase); }; -#endif // SEASIDELISTITEM_H +#endif // SEASIDELISTITEMBASE_H diff --git a/src/seasidelistitemlarge.cpp b/src/seasidelistitemlarge.cpp index 8a6b10e..edac9da 100644 --- a/src/seasidelistitemlarge.cpp +++ b/src/seasidelistitemlarge.cpp @@ -28,8 +28,7 @@ M_REGISTER_WIDGET(SeasideListItemLarge); #define SCREEN_WIDTH 400 SeasideListItemLarge::SeasideListItemLarge(MWidget *parent) - : MWidgetController(parent) - , priv(new SeasideListItemPriv) + : SeasideListItemBase(parent) { setObjectName("SeasideListItemLarge"); @@ -110,173 +109,5 @@ SeasideListItemLarge::SeasideListItemLarge(MWidget *parent) SeasideListItemLarge::~SeasideListItemLarge() { - delete priv; } -//REVISIT -void SeasideListItemLarge::setPresence(const int presence){ - QString str= ""; - if(presence == Seaside::PresenceAvailable) - str = "icon-m-common-presence-online"; - else if(presence == Seaside::PresenceAway) - str = "icon-m-common-presence-away"; - else if(presence == Seaside::PresenceOffline) - str = "icon-m-common-presence-offline"; - else if(presence == Seaside::PresenceBusy) - str = "icon-m-common-presence-busy"; - else - str = "icon-m-common-presence-unknown"; - if(priv->presence) - priv->presence->setImage(str); -} - -void SeasideListItemLarge::setFavorite(const bool& favorite){ - QString str= ""; - if(favorite) - str ="icon-m-common-favorite-mark"; - else - str = ""; - if(priv->favorite) - priv->favorite->setImage(str); -} - -void SeasideListItemLarge::setButton(const QString & button){ - QString str= button; - if (str.isEmpty()) - str = "im-accounts-no-background"; - if(priv->button) - priv->button->setIconID(str); -} - -void SeasideListItemLarge::setStatus(const QString& status){ - if(priv->status) - priv->status->setText(status); -} - -void SeasideListItemLarge::setCommFlags(const int flags){ - if(!priv->call || !priv->email || !priv->im || !priv->sms) - return; - - if((flags & Seaside::CommCallDialed) == Seaside::CommCallDialed) - priv->call->setImage("icon-m-telephony-call-initiated"); - else if((flags & Seaside::CommCallReceived) == Seaside::CommCallReceived) - priv->call->setImage("icon-m-telephony-call-received"); - else if((flags & Seaside::CommCallMissed) == Seaside::CommCallMissed) - priv->call->setImage("icon-m-telephony-call-missed"); - if(((flags & Seaside::CommSmsSent) == Seaside::CommSmsSent) - || ((flags & Seaside::CommSmsReceived) == Seaside::CommSmsReceived)) - priv->sms->setImage("Icon-new-SMS"); - if(((flags & Seaside::CommEmailSent ) == Seaside::CommEmailSent) - || ((flags & Seaside::CommEmailReceived) == Seaside::CommEmailReceived)) - priv->email->setImage("Icon-email"); - if(((flags & Seaside::CommIMSent) == Seaside::CommIMSent) - || ((flags & Seaside::CommIMReceived) == Seaside::CommIMReceived)) - priv->im->setImage("Icon-messages"); -} - -void SeasideListItemLarge::setThumbnail(const QString &thumbnail) -{ - QString str = thumbnail; - if (str.isEmpty()) - str= "icon-m-content-avatar-placeholder"; - if(priv->image) - priv->image->setPixmap(getAvatar(str)); -} - - -QPixmap SeasideListItemLarge::getAvatar(QString avatar) -{ - const QPixmap *photo; - photo = MTheme::pixmap(avatar, QSize(64, 64)); - - - // create alpha mask - QImage mask(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter maskpainter(&mask); - //maskpainter.setRenderHint(QPainter::Antialiasing, true); - maskpainter.setCompositionMode(QPainter::CompositionMode_Source); - maskpainter.fillRect(mask.rect(), Qt::transparent); - maskpainter.setPen(QPen(Qt::transparent)); - maskpainter.setBrush(QBrush(Qt::white)); - maskpainter.drawRoundedRect(1.0, 1.0, 61.0, 61.0, 5.0, 5.0); - - // scale/crop photo - qreal x, y, w, h; - if (photo->width() > photo->height()) { - x = (photo->width() - photo->height()) / 2.0; - w = photo->height(); - y = 0.0; - h = photo->height(); - } else { - y = (photo->height() - photo->width()) / 2.0; - h = photo->width(); - x = 0.0; - w = photo->width(); - } - QImage tmp(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter tmppainter(&tmp); - //tmppainter.setRenderHint(QPainter::Antialiasing, true); - tmppainter.setCompositionMode(QPainter::CompositionMode_Source); - tmppainter.drawPixmap(tmp.rect(), *photo, QRectF(x, y, w, h)); - - // mask photo - tmppainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - tmppainter.drawImage(tmp.rect(), mask, mask.rect()); - - // create final image - QImage dst(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter painter(&dst); - //painter.setRenderHint(QPainter::Antialiasing, true); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(dst.rect(), Qt::transparent); - - // draw rounded rect background - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - QPen pen(QColor(0xB0, 0xB0, 0xB0)); - QBrush brush(Qt::white); - pen.setWidthF(1.0); - painter.setPen(pen); - painter.setBrush(brush); - painter.drawRoundedRect(0.0, 0.0, 63.0, 63.0, 5.0, 5.0); - - // draw masked photo - painter.drawImage(dst.rect(), tmp, tmp.rect()); - - - return QPixmap::fromImage(dst); -} - -void SeasideListItemLarge::setName(const QString &name) -{ - if(priv->name) - priv->name->setText(name); -} - - void SeasideListItemLarge::setDetails(const QStringList &details) -{ - if(!priv->detail) - return; - priv->detailList = new QStringList(details); - if(!details.isEmpty() && (details.count() > 0)){ - priv->detail->setText(details[0]); - } -} - - void SeasideListItemLarge::setUuid(const QString &id) - { - if(!id.isNull()){ - priv->uuid = new QUuid(id); - } - } - -void SeasideListItemLarge::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); -} - -void SeasideListItemLarge::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); - if (sceneBoundingRect().contains(event->scenePos())) - emit clicked(); -} diff --git a/src/seasidelistitemlarge.h b/src/seasidelistitemlarge.h index 812ac48..29418ff 100644 --- a/src/seasidelistitemlarge.h +++ b/src/seasidelistitemlarge.h @@ -13,7 +13,7 @@ #include <MWidgetController> #include "seaside.h" -struct SeasideListItemPriv; +#include "seasidelistitembase.h" /* * SeasideListItemLarge: Styling Notes @@ -26,7 +26,7 @@ struct SeasideListItemPriv; * */ -class SeasideListItemLarge: public MWidgetController +class SeasideListItemLarge : public SeasideListItemBase { Q_OBJECT @@ -34,27 +34,7 @@ public: SeasideListItemLarge(MWidget *parent = NULL); virtual ~SeasideListItemLarge(); - void setThumbnail(const QString& thumbnail); - void setName(const QString& name); - void setUuid(const QString& id); - void setDetails(const QStringList& detail); //REVISIT phone or email or IM - void setPresence(const int presence); - void setFavorite(const bool& favorite); - void setButton(const QString& hasButton); - void setStatus(const QString& status); - void setCommFlags(const int flags); - -signals: - void clicked(); - void buttonClicked(); - -protected slots: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - private: - SeasideListItemPriv *priv; - QPixmap getAvatar(QString avatar); Q_DISABLE_COPY(SeasideListItemLarge); }; diff --git a/src/seasidelistitemsmall.cpp b/src/seasidelistitemsmall.cpp index 8623c42..e0b3833 100644 --- a/src/seasidelistitemsmall.cpp +++ b/src/seasidelistitemsmall.cpp @@ -28,8 +28,7 @@ M_REGISTER_WIDGET(SeasideListItemSmall) #define SCREEN_WIDTH 400 SeasideListItemSmall::SeasideListItemSmall(MWidget *parent) - : MWidgetController(parent) - , priv(new SeasideListItemPriv) + : SeasideListItemBase(parent) { setObjectName("SeasideListItemSmall"); @@ -99,172 +98,5 @@ SeasideListItemSmall::SeasideListItemSmall(MWidget *parent) SeasideListItemSmall::~SeasideListItemSmall() { - delete priv; } -void SeasideListItemSmall::setPresence(const int presence){ - QString str= ""; - if(presence == Seaside::PresenceAvailable) - str = "icon-m-common-presence-online"; - else if(presence == Seaside::PresenceAway) - str = "icon-m-common-presence-away"; - else if(presence == Seaside::PresenceOffline) - str = "icon-m-common-presence-offline"; - else if(presence == Seaside::PresenceBusy) - str = "icon-m-common-presence-busy"; - else - str = "icon-m-common-presence-unknown"; - if(priv->presence) - priv->presence->setImage(str); -} - -void SeasideListItemSmall::setFavorite(const bool& favorite){ - QString str= ""; - if(favorite) - str ="icon-m-common-favorite-mark"; - else - str = ""; - if(priv->favorite) - priv->favorite->setImage(str); -} - -void SeasideListItemSmall::setButton(const QString & button){ - QString str= button; - if (str.isEmpty()) - str = "im-accounts-no-background"; - if(priv->button) - priv->button->setIconID(str); -} - -void SeasideListItemSmall::setStatus(const QString& status){ - if(priv->status) - priv->status->setText(status); -} - -void SeasideListItemSmall::setCommFlags(const int flags){ - if(!priv->call || !priv->email || !priv->im || !priv->sms) - return; - - if((flags & Seaside::CommCallDialed) == Seaside::CommCallDialed) - priv->call->setImage("icon-m-telephony-call-initiated"); - else if((flags & Seaside::CommCallReceived) == Seaside::CommCallReceived) - priv->call->setImage("icon-m-telephony-call-received"); - else if((flags & Seaside::CommCallMissed) == Seaside::CommCallMissed) - priv->call->setImage("icon-m-telephony-call-missed"); - if(((flags & Seaside::CommSmsSent) == Seaside::CommSmsSent) - || ((flags & Seaside::CommSmsReceived) == Seaside::CommSmsReceived)) - priv->sms->setImage("Icon-new-SMS"); - if(((flags & Seaside::CommEmailSent ) == Seaside::CommEmailSent) - || ((flags & Seaside::CommEmailReceived) == Seaside::CommEmailReceived)) - priv->email->setImage("Icon-email"); - if(((flags & Seaside::CommIMSent) == Seaside::CommIMSent) - || ((flags & Seaside::CommIMReceived) == Seaside::CommIMReceived)) - priv->im->setImage("Icon-messages"); -} - -void SeasideListItemSmall::setThumbnail(const QString &thumbnail) -{ - QString str = thumbnail; - if (str.isEmpty()) - str= "icon-m-content-avatar-placeholder"; - if(priv->image) - priv->image->setPixmap(getAvatar(str)); -} - - -QPixmap SeasideListItemSmall::getAvatar(QString avatar) -{ - const QPixmap *photo; - photo = MTheme::pixmap(avatar, QSize(64, 64)); - - - // create alpha mask - QImage mask(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter maskpainter(&mask); - //maskpainter.setRenderHint(QPainter::Antialiasing, true); - maskpainter.setCompositionMode(QPainter::CompositionMode_Source); - maskpainter.fillRect(mask.rect(), Qt::transparent); - maskpainter.setPen(QPen(Qt::transparent)); - maskpainter.setBrush(QBrush(Qt::white)); - maskpainter.drawRoundedRect(1.0, 1.0, 61.0, 61.0, 5.0, 5.0); - - // scale/crop photo - qreal x, y, w, h; - if (photo->width() > photo->height()) { - x = (photo->width() - photo->height()) / 2.0; - w = photo->height(); - y = 0.0; - h = photo->height(); - } else { - y = (photo->height() - photo->width()) / 2.0; - h = photo->width(); - x = 0.0; - w = photo->width(); - } - QImage tmp(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter tmppainter(&tmp); - //tmppainter.setRenderHint(QPainter::Antialiasing, true); - tmppainter.setCompositionMode(QPainter::CompositionMode_Source); - tmppainter.drawPixmap(tmp.rect(), *photo, QRectF(x, y, w, h)); - - // mask photo - tmppainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - tmppainter.drawImage(tmp.rect(), mask, mask.rect()); - - // create final image - QImage dst(64, 64, QImage::Format_ARGB32_Premultiplied); - QPainter painter(&dst); - //painter.setRenderHint(QPainter::Antialiasing, true); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(dst.rect(), Qt::transparent); - - // draw rounded rect background - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - QPen pen(QColor(0xB0, 0xB0, 0xB0)); - QBrush brush(Qt::white); - pen.setWidthF(1.0); - painter.setPen(pen); - painter.setBrush(brush); - painter.drawRoundedRect(0.0, 0.0, 63.0, 63.0, 5.0, 5.0); - - // draw masked photo - painter.drawImage(dst.rect(), tmp, tmp.rect()); - - - return QPixmap::fromImage(dst); -} - -void SeasideListItemSmall::setName(const QString &name) -{ - if(priv->name) - priv->name->setText(name); -} - - void SeasideListItemSmall::setDetails(const QStringList &details) -{ - if(!priv->detail) - return; - priv->detailList = new QStringList(details); - if(!details.isEmpty() && (details.count() > 0)){ - priv->detail->setText(details[0]); - } -} - - void SeasideListItemSmall::setUuid(const QString &id) - { - if(!id.isNull()){ - priv->uuid = new QUuid(id); - } - } - -void SeasideListItemSmall::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); -} - -void SeasideListItemSmall::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); - if (sceneBoundingRect().contains(event->scenePos())) - emit clicked(); -} diff --git a/src/seasidelistitemsmall.h b/src/seasidelistitemsmall.h index b1cba36..bc8c892 100644 --- a/src/seasidelistitemsmall.h +++ b/src/seasidelistitemsmall.h @@ -13,7 +13,7 @@ #include <MWidgetController> #include "seaside.h" -struct SeasideListItemPriv; +#include "seasidelistitembase.h" /* * SeasideListItemSmall: Styling Notes @@ -26,7 +26,7 @@ struct SeasideListItemPriv; * */ -class SeasideListItemSmall: public MWidgetController +class SeasideListItemSmall : public SeasideListItemBase { Q_OBJECT @@ -34,27 +34,7 @@ public: SeasideListItemSmall(MWidget *parent = NULL); virtual ~SeasideListItemSmall(); - void setThumbnail(const QString& thumbnail); - void setName(const QString& name); - void setUuid(const QString& id); - void setDetails(const QStringList& detail); //REVISIT phone or email or IM - void setPresence(const int presence); - void setFavorite(const bool& favorite); - void setButton(const QString& hasButton); - void setStatus(const QString& status); - void setCommFlags(const int flags); - -signals: - void clicked(); - void buttonClicked(); - -protected slots: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - private: - SeasideListItemPriv *priv; - QPixmap getAvatar(QString avatar); Q_DISABLE_COPY(SeasideListItemSmall); }; -- 1.7.4.1 _______________________________________________ MeeGo-dev mailing list MeeGo-dev@meego.com http://lists.meego.com/listinfo/meego-dev http://wiki.meego.com/Mailing_list_guidelines