aboutsummaryrefslogtreecommitdiff
path: root/src/views/minfobannereventview.cpp
blob: 00f59896ff695f5dd5315b5853eb257530931c06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

// TODO: Consider calculating size hint from the content

#include "minfobannereventview.h"
#include "minfobannereventview_p.h"

#include "minfobanner.h"
#include "mviewcreator.h"
#include "mimagewidget.h"
#include "mlabel.h"

#include <QGraphicsLinearLayout>
#include <QGraphicsSceneMouseEvent>

MInfoBannerEventViewPrivate::MInfoBannerEventViewPrivate(MInfoBanner *controller) :
    q_ptr(0), banner(controller), label(0), image(0), icon(0), layout(0),
    controller(controller)
{
}

MInfoBannerEventViewPrivate::~MInfoBannerEventViewPrivate()
{
}

void MInfoBannerEventViewPrivate::init()
{
    label = new MLabel();
    label->setAlignment(Qt::AlignCenter);
    label->setTextElide(true);
    label->setObjectName("EventInfoBannerBody");

    image = new MImageWidget();
    image->setObjectName("EventInfoBannerImage");
    icon = new MImageWidget();
    icon->setObjectName("EventInfoBannerIcon");

    layout = new QGraphicsLinearLayout(Qt::Horizontal);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);
    controller->setLayout(layout);

    layout->addItem(image);
    layout->addItem(label);
    layout->addItem(icon);
    layout->setAlignment(label, Qt::AlignCenter);

    QObject::connect(banner, SIGNAL(clicked()), controller, SLOT(dismiss()));
}

MInfoBannerEventView::MInfoBannerEventView(MInfoBanner *controller) :
    MSceneWindowView(controller),
    d_ptr(new MInfoBannerEventViewPrivate(controller))
{
    Q_D(MInfoBannerEventView);
    d->q_ptr = this;
    d->init();
}

MInfoBannerEventView::MInfoBannerEventView(MInfoBannerEventViewPrivate &dd, MInfoBanner *controller) :
    MSceneWindowView(controller),
    d_ptr(&dd)
{
    Q_D(MInfoBannerEventView);
    d->q_ptr = this;
    d->init();
}

MInfoBannerEventView::~MInfoBannerEventView()
{
    delete d_ptr;
}

void MInfoBannerEventView::updateData(const QList<const char *>& modifications)
{
    MSceneWindowView::updateData(modifications);

    Q_D(MInfoBannerEventView);
    const char *member;

    foreach(member, modifications) {
        if (member == MInfoBannerModel::BodyText) {
            d->label->setText(model()->bodyText());
        } else if (member == MInfoBannerModel::ImageID) {
            d->image->setImage(model()->imageID(), style()->imageSize());
        } else if (member == MInfoBannerModel::Pixmap) {
            d->image->setPixmap(model()->pixmap());
        } else if (member == MInfoBannerModel::IconID) {
            d->icon->setImage(model()->iconID(), style()->iconSize());
        }
    }
}

void MInfoBannerEventView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    Q_UNUSED(event);
}

void MInfoBannerEventView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(MInfoBannerEventView);

    QPointF touch = event->scenePos();
    QRectF rect  = d->controller->sceneBoundingRect();
    if (rect.contains(touch)) {
        d->banner->click();
    }
}

void MInfoBannerEventView::setupModel()
{
    MSceneWindowView::setupModel();

    Q_D(MInfoBannerEventView);

    d->label->setText(model()->bodyText());
    d->icon->setImage(model()->iconID(), style()->iconSize());

    if (!model()->imageID().isEmpty()) {
        d->image->setImage(model()->imageID(), style()->imageSize());
    } else {
        d->image->setPixmap(model()->pixmap());
    }
}

void MInfoBannerEventView::applyStyle()
{
    MSceneWindowView::applyStyle();

    Q_D(MInfoBannerEventView);

    if (!model()->imageID().isEmpty()) {
        d->image->setImage(model()->imageID(), style()->imageSize());
    } else {
        d->image->setPixmap(model()->pixmap());
    }

    d->icon->setImage(model()->iconID(), style()->iconSize());
}

M_REGISTER_VIEW_NEW(MInfoBannerEventView, MInfoBanner)