~sil/ubuntu-keyboard/numbers-on-top-row

« back to all changes in this revision

Viewing changes to src/plugin/scenerectwatcher.cpp

  • Committer: Tarmac
  • Author(s): Guenter Schwann
  • Date: 2013-11-08 08:01:33 UTC
  • mfrom: (96.1.9 keyboard-size-in-mir)
  • Revision ID: tarmac-20131108080133-j08xha13k1kw2evl
Set the keyboard geometry from QML to C++, not the other way around. Fixes: https://bugs.launchpad.net/bugs/1245481.

Approved by Thomas Moenicke, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU Lesser General Public License as published by
6
 
 * the Free Software Foundation; version 3.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
#include <scenerectwatcher.h>
18
 
 
19
 
SceneRectWatcher::SceneRectWatcher(QObject *parent)
20
 
    : QObject(parent)
21
 
{
22
 
    m_sceneRectChangedTimer.setInterval(200);
23
 
    m_sceneRectChangedTimer.setSingleShot(true);
24
 
    connect(&m_sceneRectChangedTimer, &QTimer::timeout,
25
 
            this, &SceneRectWatcher::sceneRectChanged);
26
 
}
27
 
 
28
 
void SceneRectWatcher::setItem(QQuickItem *target)
29
 
{
30
 
    if (m_target == target)
31
 
        return;
32
 
 
33
 
    m_sceneRectChangedTimer.stop();
34
 
    m_target = target;
35
 
    listenToAscendantsChanges();
36
 
}
37
 
 
38
 
void SceneRectWatcher::listenToAscendantsChanges()
39
 
{
40
 
    disconnectFromAscendantsChanges();
41
 
 
42
 
    if (!m_target)
43
 
        return;
44
 
 
45
 
    QQuickItem* item = m_target.data();
46
 
 
47
 
    m_connections.append(connect(item, &QQuickItem::widthChanged,
48
 
                                 this, &SceneRectWatcher::notifySceneRectChange));
49
 
    m_connections.append(connect(item, &QQuickItem::heightChanged,
50
 
                                 this, &SceneRectWatcher::notifySceneRectChange));
51
 
 
52
 
    while (item != NULL) {
53
 
        m_connections.append(connect(item, &QQuickItem::parentChanged,
54
 
                                     this, &SceneRectWatcher::onAscendantChanged));
55
 
        m_connections.append(connect(item, &QQuickItem::xChanged,
56
 
                                     this, &SceneRectWatcher::notifySceneRectChange));
57
 
        m_connections.append(connect(item, &QQuickItem::yChanged,
58
 
                                     this, &SceneRectWatcher::notifySceneRectChange));
59
 
        m_connections.append(connect(item, &QQuickItem::transformOriginChanged,
60
 
                                     this, &SceneRectWatcher::notifySceneRectChange));
61
 
        m_connections.append(connect(item, &QQuickItem::rotationChanged,
62
 
                                     this, &SceneRectWatcher::notifySceneRectChange));
63
 
        m_connections.append(connect(item, &QQuickItem::scaleChanged,
64
 
                                     this, &SceneRectWatcher::notifySceneRectChange));
65
 
        item = item->parentItem();
66
 
    }
67
 
}
68
 
 
69
 
void SceneRectWatcher::disconnectFromAscendantsChanges()
70
 
{
71
 
    // disconnect all previously connected signals
72
 
    Q_FOREACH (QMetaObject::Connection connection, m_connections) {
73
 
        disconnect(connection);
74
 
    }
75
 
    m_connections.clear();
76
 
}
77
 
 
78
 
void SceneRectWatcher::onAscendantChanged()
79
 
{
80
 
    // Simple approach: Just rebuild connections from scratch.
81
 
    listenToAscendantsChanges();
82
 
 
83
 
    notifySceneRectChange();
84
 
}
85
 
 
86
 
void SceneRectWatcher::notifySceneRectChange()
87
 
{
88
 
    if (!m_sceneRectChangedTimer.isActive()) {
89
 
        m_sceneRectChangedTimer.start();
90
 
    }
91
 
}