WebNotificationPresenter.cpp [plain text]
#include "WebNotificationPresenter.h"
WebNotificationWidget::WebNotificationWidget()
: QWidget()
{
}
WebNotificationWidget::~WebNotificationWidget()
{
}
void WebNotificationWidget::showNotification(const QWebNotificationData* data)
{
QPixmap mask;
QPainter painter(&mask);
painter.fillRect(0, 0, 300, 100, Qt::lightGray);
QBitmap bitmap(mask);
setMask(bitmap);
QGridLayout* layout = new QGridLayout(this);
layout->addWidget(new QLabel(data->title()), 0, 0, 1, 5);
int messagePosition = 0;
QPixmap pixmap;
if (data->iconData().length() && pixmap.loadFromData(data->iconData())) {
QLabel* label = new QLabel;
label->setPixmap(pixmap);
layout->addWidget(label, 1, 0, 1, 1);
messagePosition++;
}
QLabel* messageLabel = new QLabel(data->message());
messageLabel->setMask(bitmap);
messageLabel->setWordWrap(true);
layout->addWidget(messageLabel, 1, messagePosition, 1, 5 - messagePosition);
setLayout(layout);
setFixedSize(300, 100);
show();
}
bool WebNotificationWidget::event(QEvent* ev)
{
if (ev->type() == QEvent::MouseButtonRelease) {
emit notificationClicked();
return true;
}
if (ev->type() == QEvent::Close) {
emit notificationClosed();
return true;
}
return QWidget::event(ev);
}