~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to maliit/preeditinjectionevent.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License version 2.1 as published by the Free Software Foundation
11
 
 * and appearing in the file LICENSE.LGPL included in the packaging
12
 
 * of this file.
13
 
 */
14
 
 
15
 
// Based on mpreeditinjectionevent.cpp from libmeegotouch
16
 
 
17
 
#include <QString>
18
 
#include <QMutex>
19
 
 
20
 
#include "preeditinjectionevent.h"
21
 
#include "preeditinjectionevent_p.h"
22
 
 
23
 
static int sPreeditEventNumber = -1;
24
 
static QMutex sPreeditInjectionMutex;
25
 
 
26
 
namespace Maliit {
27
 
 
28
 
PreeditInjectionEventPrivate::PreeditInjectionEventPrivate(const QString &preedit, int eventCursorPos)
29
 
    : preedit(preedit),
30
 
      eventCursorPosition(eventCursorPos),
31
 
      replacementStart(0),
32
 
      replacementLength(0)
33
 
{
34
 
    // nothing
35
 
}
36
 
 
37
 
 
38
 
PreeditInjectionEventPrivate::~PreeditInjectionEventPrivate()
39
 
{
40
 
    // nothing
41
 
}
42
 
 
43
 
 
44
 
///////////////////////
45
 
// class implementation
46
 
 
47
 
 
48
 
PreeditInjectionEvent::PreeditInjectionEvent(const QString &preedit)
49
 
    : QEvent(PreeditInjectionEvent::eventNumber()),
50
 
      d_ptr(new PreeditInjectionEventPrivate(preedit, -1))
51
 
{
52
 
    setAccepted(false);
53
 
}
54
 
 
55
 
PreeditInjectionEvent::PreeditInjectionEvent(const QString &preedit, int eventCursorPosition)
56
 
    : QEvent(PreeditInjectionEvent::eventNumber()),
57
 
      d_ptr(new PreeditInjectionEventPrivate(preedit, eventCursorPosition))
58
 
{
59
 
    setAccepted(false);
60
 
}
61
 
 
62
 
PreeditInjectionEvent::~PreeditInjectionEvent()
63
 
{
64
 
    delete d_ptr;
65
 
}
66
 
 
67
 
 
68
 
QString PreeditInjectionEvent::preedit() const
69
 
{
70
 
    Q_D(const PreeditInjectionEvent);
71
 
    return d->preedit;
72
 
}
73
 
 
74
 
int PreeditInjectionEvent::eventCursorPosition() const
75
 
{
76
 
    Q_D(const PreeditInjectionEvent);
77
 
    return d->eventCursorPosition;
78
 
}
79
 
 
80
 
void PreeditInjectionEvent::setReplacement(int replacementStart, int replacementLength)
81
 
{
82
 
    Q_D(PreeditInjectionEvent);
83
 
    d->replacementStart = replacementStart;
84
 
    d->replacementLength = replacementLength;
85
 
}
86
 
 
87
 
int PreeditInjectionEvent::replacementStart() const
88
 
{
89
 
    Q_D(const PreeditInjectionEvent);
90
 
    return d->replacementStart;
91
 
}
92
 
 
93
 
int PreeditInjectionEvent::replacementLength() const
94
 
{
95
 
    Q_D(const PreeditInjectionEvent);
96
 
    return d->replacementLength;
97
 
}
98
 
 
99
 
 
100
 
// static
101
 
QEvent::Type PreeditInjectionEvent::eventNumber()
102
 
{
103
 
    if (sPreeditEventNumber < 0) {
104
 
        // no event number yet registered, do it now
105
 
        sPreeditInjectionMutex.lock();
106
 
 
107
 
        if (sPreeditEventNumber < 0) {
108
 
            sPreeditEventNumber = QEvent::registerEventType();
109
 
        }
110
 
 
111
 
        sPreeditInjectionMutex.unlock();
112
 
    }
113
 
 
114
 
    return static_cast<QEvent::Type>(sPreeditEventNumber);
115
 
}
116
 
 
117
 
}