1
/* * This file is part of Maliit framework *
3
* Copyright (C) 2013 Openismus GmbH
5
* Contact: maliit-discuss@lists.maliit.org
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
16
#include "abstractplatform.h"
17
#include "windowgroup.h"
22
WindowGroup::WindowGroup(const QSharedPointer<AbstractPlatform> &platform)
23
: m_platform(platform),
26
m_hideTimer.setSingleShot(true);
27
m_hideTimer.setInterval(2000);
28
connect(&m_hideTimer, SIGNAL(timeout()), this, SLOT(hideWindows()));
31
WindowGroup::~WindowGroup()
34
void WindowGroup::activate()
40
void WindowGroup::deactivate(HideMode mode)
45
if (mode == HideImmediate) {
53
void WindowGroup::setupWindow(QWindow *window, Maliit::Position position)
56
if (not containsWindow(window)) {
57
QWindow *parent = window->parent ();
59
if (parent and not containsWindow(parent)) {
60
qWarning () << "Plugin is misbehaving - tried to register a window with yet-unregistered parent!";
63
m_window_list.append (WindowData(window, position));
65
window->setFlags (Qt::FramelessWindowHint |
66
Qt::WindowStaysOnTopHint |
67
Qt::WindowDoesNotAcceptFocus);
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();
85
void WindowGroup::setScreenRegion(const QRegion ®ion, QWindow *window)
87
if (window == 0 && m_window_list.size() > 0) {
88
window = m_window_list.at(0).m_window.data();
90
m_platform->setInputRegion(window, region);
93
void WindowGroup::setInputMethodArea(const QRegion ®ion, QWindow *window)
95
if (window == 0 && m_window_list.size() > 0) {
96
window = m_window_list.at(0).m_window.data();
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;
108
updateInputMethodArea();
112
void WindowGroup::setApplicationWindow(WId id)
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);
121
void WindowGroup::onVisibleChanged(bool visible)
124
updateInputMethodArea();
125
} else if (visible) {
126
QWindow *window = qobject_cast<QWindow*>(sender());
129
qWarning () << "An inactive plugin is misbehaving - tried to show a window!";
130
window->setVisible (false);
135
void WindowGroup::updateInputMethodArea()
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());
147
if (new_area != m_last_im_area) {
148
m_last_im_area = new_area;
149
Q_EMIT inputMethodAreaChanged(m_last_im_area);
153
bool WindowGroup::containsWindow(QWindow *window)
155
Q_FOREACH (const WindowData &data, m_window_list) {
156
if (data.m_window == window) {
164
void WindowGroup::hideWindows()
168
Q_FOREACH (const WindowData &data, m_window_list) {
170
data.m_window->setVisible (false);
173
updateInputMethodArea();
176
} // namespace Maliit