aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/widgets/mlabel.cpp
blob: 514c9d6a4c25757c61076a5e9bdb58eed2c3fc31 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************
**
** 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.
**
****************************************************************************/

#include "mlabel.h"
#include "mlabel_p.h"
#include "mwidgetview.h"
#include "mlabelhighlighter.h"

#include <QGraphicsSceneContextMenuEvent>

//#include "mlabelview.h"

#include "mwidgetcreator.h"
M_REGISTER_WIDGET(MLabel)

MLabel::MLabel(QGraphicsItem *parent, MLabelModel *model) :
    MWidgetController(new MLabelPrivate, model == NULL ? new MLabelModel : model, parent)
{
    grabGestureWithCancelPolicy(Qt::TapAndHoldGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureFinished);
}

MLabel::MLabel(QString const &text, QGraphicsItem *parent) :
    MWidgetController(new MLabelPrivate, new MLabelModel, parent)
{
    grabGestureWithCancelPolicy(Qt::TapAndHoldGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureFinished);
    setText(text);
}

MLabel::~MLabel()
{
}

void MLabel::setupModel()
{
    MWidgetController::setupModel();
    connect(model(), SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
}

void MLabel::changeEvent(QEvent *event)
{
    //TODO Would probably be more proper to handle the changeEvent()
    //     in the view side because MWidgetController is
    //     forwarding the event there as well. It just means
    //     a bit more work due to WEIRD implementation of the label
    //     views. There is existing implementation for handling the
    //     changing of the direction through model so will use that
    //     for now.
    MWidgetController::changeEvent(event);
}

void MLabel::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    Q_UNUSED(event);
    event->ignore();
}

void MLabel::setText(const QString &text)
{
    model()->setText(text);
}

void MLabel::setAlignment(Qt::Alignment alignment)
{
    model()->beginTransaction();
    model()->setAlignment(alignment);
    model()->setAlignmentFromStyle(false);
    model()->commitTransaction();
}

Qt::Alignment MLabel::alignment() const
{
    return model()->alignment();
}

void MLabel::setWrapMode(QTextOption::WrapMode wrapMode)
{
    model()->setWrapMode(wrapMode);
}

void MLabel::setWordWrap(bool wrap)
{
    model()->setWordWrap(wrap);
}

QString MLabel::text() const
{
    return model()->text();
}

bool MLabel::wordWrap() const
{
    return model()->wordWrap();
}

QTextOption::WrapMode MLabel::wrapMode() const
{
    return model()->wrapMode();
}

void MLabel::setTextElide(bool elide)
{
    model()->setTextElide(elide);
}

bool MLabel::textElide() const
{
    return model()->textElide();
}

void MLabel::setFont(const QFont &font)
{
    model()->setUseModelFont(true);
    model()->setFont(font);
    QGraphicsWidget::setFont(font);
}

QFont MLabel::font() const
{
    if (!model()->useModelFont()) {
        if (view())
            return view()->font();
    }
    return model()->font();
}

void MLabel::setColor(const QColor &color)
{
    model()->setColor(color);
}

QColor MLabel::color() const
{
    /*if( !model()->color().isValid() ) {
        if( view() )
            return view()->color();
    }*/
    return model()->color();
}

void MLabel::setTextFormat(Qt::TextFormat textFormat)
{
    model()->setTextFormat(textFormat);
}
 
Qt::TextFormat MLabel::textFormat() const
{
    return model()->textFormat();
}

void MLabel::addHighlighter(MLabelHighlighter *highlighter)
{
    model()->addHighlighter(highlighter);
}

void MLabel::removeHighlighter(MLabelHighlighter *highlighter)
{
    model()->removeHighlighter(highlighter);
}

void MLabel::removeAllHighlighters()
{
    model()->setHighlighters(QList<MLabelHighlighter *>());
}