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

« back to all changes in this revision

Viewing changes to src/windowgroup.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20130723194704-0o18p2ao0x9sa1zx
Tags: upstream-0.99.0+git20130615+97e8335
ImportĀ upstreamĀ versionĀ 0.99.0+git20130615+97e8335

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * This file is part of Maliit framework *
 
2
 *
 
3
 * Copyright (C) 2013 Openismus GmbH
 
4
 *
 
5
 * Contact: maliit-discuss@lists.maliit.org
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License version 2.1 as published by the Free Software Foundation
 
10
 * and appearing in the file LICENSE.LGPL included in the packaging
 
11
 * of this file.
 
12
 */
 
13
 
 
14
#include <QDebug>
 
15
 
 
16
#include "abstractplatform.h"
 
17
#include "windowgroup.h"
 
18
 
 
19
namespace Maliit
 
20
{
 
21
 
 
22
WindowGroup::WindowGroup(const QSharedPointer<AbstractPlatform> &platform)
 
23
    : m_platform(platform),
 
24
      m_active(false)
 
25
{
 
26
    m_hideTimer.setSingleShot(true);
 
27
    m_hideTimer.setInterval(2000);
 
28
    connect(&m_hideTimer, SIGNAL(timeout()), this, SLOT(hideWindows()));
 
29
}
 
30
 
 
31
WindowGroup::~WindowGroup()
 
32
{}
 
33
 
 
34
void WindowGroup::activate()
 
35
{
 
36
    m_active = true;
 
37
    m_hideTimer.stop();
 
38
}
 
39
 
 
40
void WindowGroup::deactivate(HideMode mode)
 
41
{
 
42
    if (m_active) {
 
43
        m_active = false;
 
44
 
 
45
        if (mode == HideImmediate) {
 
46
            hideWindows();
 
47
        } else {
 
48
            m_hideTimer.start();
 
49
        }
 
50
    }
 
51
}
 
52
 
 
53
void WindowGroup::setupWindow(QWindow *window, Maliit::Position position)
 
54
{
 
55
    if (window) {
 
56
        if (not containsWindow(window)) {
 
57
            QWindow *parent = window->parent ();
 
58
 
 
59
            if (parent and not containsWindow(parent)) {
 
60
                qWarning () << "Plugin is misbehaving - tried to register a window with yet-unregistered parent!";
 
61
                return;
 
62
            }
 
63
            m_window_list.append (WindowData(window, position));
 
64
 
 
65
            window->setFlags (Qt::FramelessWindowHint |
 
66
                              Qt::WindowStaysOnTopHint |
 
67
                              Qt::WindowDoesNotAcceptFocus);
 
68
 
 
69
            connect (window, SIGNAL (visibleChanged(bool)),
 
70
                     this, SLOT (onVisibleChanged(bool)));
 
71
            connect (window, SIGNAL (heightChanged(int)),
 
72
                     this, SLOT (updateInputMethodArea()));
 
73
            connect (window, SIGNAL (widthChanged(int)),
 
74
                     this, SLOT (updateInputMethodArea()));
 
75
            connect (window, SIGNAL (xChanged(int)),
 
76
                     this, SLOT (updateInputMethodArea()));
 
77
            connect (window, SIGNAL (yChanged(int)),
 
78
                     this, SLOT (updateInputMethodArea()));
 
79
            m_platform->setupInputPanel(window, position);
 
80
            updateInputMethodArea();
 
81
        }
 
82
    }
 
83
}
 
84
 
 
85
void WindowGroup::setScreenRegion(const QRegion &region, QWindow *window)
 
86
{
 
87
    if (window == 0 && m_window_list.size() > 0) {
 
88
        window = m_window_list.at(0).m_window.data();
 
89
    }
 
90
    m_platform->setInputRegion(window, region);
 
91
}
 
92
 
 
93
void WindowGroup::setInputMethodArea(const QRegion &region, QWindow *window)
 
94
{
 
95
    if (window == 0 && m_window_list.size() > 0) {
 
96
        window = m_window_list.at(0).m_window.data();
 
97
    }
 
98
 
 
99
    for (int i = 0; i < m_window_list.size(); ++i) {
 
100
        WindowData &data = m_window_list[i];
 
101
        if (data.m_window == window) {
 
102
            data.m_inputMethodArea = region;
 
103
            break;
 
104
        }
 
105
    }
 
106
 
 
107
    if (m_active) {
 
108
        updateInputMethodArea();
 
109
    }
 
110
}
 
111
 
 
112
void WindowGroup::setApplicationWindow(WId id)
 
113
{
 
114
    Q_FOREACH (const WindowData &data, m_window_list) {
 
115
        if (data.m_window and not data.m_window->parent()) {
 
116
            m_platform->setApplicationWindow(data.m_window, id);
 
117
        }
 
118
    }
 
119
}
 
120
 
 
121
void WindowGroup::onVisibleChanged(bool visible)
 
122
{
 
123
    if (m_active) {
 
124
        updateInputMethodArea();
 
125
    } else if (visible) {
 
126
        QWindow *window = qobject_cast<QWindow*>(sender());
 
127
 
 
128
        if (window) {
 
129
            qWarning () << "An inactive plugin is misbehaving - tried to show a window!";
 
130
            window->setVisible (false);
 
131
        }
 
132
    }
 
133
}
 
134
 
 
135
void WindowGroup::updateInputMethodArea()
 
136
{
 
137
    QRegion new_area;
 
138
 
 
139
    Q_FOREACH (const WindowData &data, m_window_list) {
 
140
        if (data.m_window and not data.m_window->parent() and
 
141
            data.m_window->isVisible() and
 
142
            not data.m_inputMethodArea.isEmpty()) {
 
143
            new_area |= data.m_inputMethodArea.translated(data.m_window->position());
 
144
        }
 
145
    }
 
146
 
 
147
    if (new_area != m_last_im_area) {
 
148
        m_last_im_area = new_area;
 
149
        Q_EMIT inputMethodAreaChanged(m_last_im_area);
 
150
    }
 
151
}
 
152
 
 
153
bool WindowGroup::containsWindow(QWindow *window)
 
154
{
 
155
    Q_FOREACH (const WindowData &data, m_window_list) {
 
156
        if (data.m_window == window) {
 
157
            return true;
 
158
        }
 
159
    }
 
160
 
 
161
    return false;
 
162
}
 
163
 
 
164
void WindowGroup::hideWindows()
 
165
{
 
166
    m_hideTimer.stop();
 
167
 
 
168
    Q_FOREACH (const WindowData &data, m_window_list) {
 
169
        if (data.m_window) {
 
170
            data.m_window->setVisible (false);
 
171
        }
 
172
    }
 
173
    updateInputMethodArea();
 
174
}
 
175
 
 
176
} // namespace Maliit