Qt 4.8
qinputcontext.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 /****************************************************************************
43 **
44 ** Implementation of QInputContext class
45 **
46 ** Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
47 **
48 ** This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
49 ** license. You may use this file under your Qt license. Following
50 ** description is copied from their original file headers. Contact
51 ** immodule-qt@freedesktop.org if any conditions of this licensing are
52 ** not clear to you.
53 **
54 ****************************************************************************/
55 
56 //#define QT_NO_IM_PREEDIT_RELOCATION
57 
58 #include "qinputcontext.h"
59 #include "qinputcontext_p.h"
60 
61 #ifndef QT_NO_IM
62 
63 #include "qplatformdefs.h"
64 
65 #include "qapplication.h"
66 #include "qmenu.h"
67 #include "qtextformat.h"
68 #include "qpalette.h"
69 
70 #include <stdlib.h>
71 #include <limits.h>
72 
74 
145  : QObject(*new QInputContextPrivate, parent)
146 {
147 }
148 
149 
154 {
155 }
156 
171 {
172  Q_D(const QInputContext);
173  return d->focusWidget;
174 }
175 
176 
186 {
187  Q_ASSERT(!widget || widget->testAttribute(Qt::WA_InputMethodEnabled));
189  d->focusWidget = widget;
190 }
191 
248 bool QInputContext::filterEvent(const QEvent * /*event*/)
249 {
250  return false;
251 }
252 
269 {
270  // route events over input context parents to make chaining possible.
272  if (p) {
273  p->sendEvent(event);
274  return;
275  }
276 
277  QWidget *focus = focusWidget();
278  if (!focus)
279  return;
280 
281  QInputMethodEvent e(event);
282  QApplication::sendEvent(focus, &e);
283 }
284 
285 
304 {
305  // Default behavior for simple ephemeral input contexts. Some
306  // complex input contexts should not be reset here.
307  if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick)
308  reset();
309 }
310 
311 
316 {
317  Q_D(const QInputContext);
318  if (!d->focusWidget)
319  return QApplication::font();
320 
321  return qvariant_cast<QFont>(d->focusWidget->inputMethodQuery(Qt::ImFont));
322 }
323 
330 {
331 }
332 
339 {
341  if (widget == d->focusWidget)
342  setFocusWidget(0);
343 }
344 
418 {
419  return QList<QAction *>();
420 }
421 
436 {
437  QWidget *focus = focusWidget();
438  const QPalette &pal = focus ? focus->palette() : QApplication::palette();
439 
440  QTextCharFormat fmt;
441  QColor bg;
442  switch (s) {
445  break;
446  }
448  bg = pal.text().color();
449  fmt.setBackground(QBrush(bg));
450  fmt.setForeground(pal.background());
451  break;
452  }
453  }
454  return fmt;
455 }
456 
457 #ifdef Q_WS_X11
458 
476 bool QInputContext::x11FilterEvent(QWidget * /*keywidget*/, XEvent * /*event*/)
477 {
478  return false;
479 }
480 #endif // Q_WS_X11
481 
482 #ifdef Q_OS_SYMBIAN
483 
506 bool QInputContext::symbianFilterEvent(QWidget * /*keywidget*/, const QSymbianEvent * /*event*/)
507 {
508  return false;
509 }
510 #endif // Q_OS_SYMBIAN
511 
513 
514 #endif //Q_NO_IM
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QPointer< QWidget > widget
const QBrush & background() const
Use window() instead.
Definition: qpalette.h:134
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QPalette palette()
Returns the application palette.
void setBackground(const QBrush &brush)
Sets the brush use to paint the document&#39;s background to the brush specified.
Definition: qtextformat.h:343
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QList< QAction * > actions()
This is a preliminary interface for Qt 4.
static QFont font()
Returns the default application font.
union _XEvent XEvent
Definition: qwindowdefs.h:116
QInputContext(QObject *parent=0)
Constructs an input context with the given parent.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void widgetDestroyed(QWidget *w)
This virtual function is called when the specified widget is destroyed.
virtual void update()
This virtual function is called when a state in the focus widget has changed.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
QTextFormat standardFormat(StandardFormat s) const
Returns a QTextFormat object that specifies the format for component s.
virtual ~QInputContext()
Destroys the input context.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
virtual void mouseHandler(int x, QMouseEvent *event)
This function can be reimplemented in a subclass to handle mouse press, release, double-click, and move events within the preedit text.
virtual QFont font() const
Returns the font of the current input widget.
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void sendEvent(const QInputMethodEvent &event)
Sends an input method event specified by event to the current focus widget.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual void reset()=0
This function can be reimplemented in a subclass to reset the state of the input method.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
virtual bool x11FilterEvent(QWidget *keywidget, XEvent *event)
This function may be overridden only if input method is depending on X11 and you need raw XEvent...
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
virtual void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
void setUnderlineStyle(UnderlineStyle style)
Sets the style of underlining the text to style.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
virtual bool filterEvent(const QEvent *event)
This function can be reimplemented in a subclass to filter input events.
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition: qpalette.h:129
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61