Revision: 6260
Author: nogu.dev
Date: Sat Mar 20 16:08:15 2010
Log: * qt4/immodule/Makefile.am
- (EXTRA_DIST): Add caretstateindicator.h and caretstateindicator.cpp.
* qt4/immodule/caretstateindicator.cpp
- (CaretStateIndicator): New class.
* qt4/immodule/caretstateindicator.h
- (CaretStateIndicator): New class.
* qt4/immodule/qhelpermanager.cpp
- (QUimHelperManager::update_prop_list_cb):
Call QUimInputContext::setupIndicator().
* qt4/immodule/quiminputcontext.cpp
- (QUimInputContext::QUimInputContext):
Construct instance of CaretStateIndicator.
- (QUimInputContext::setupIndicator): New function.
* qt4/immodule/quiminputcontext.h
- (QUimInputContext::setupIndicator): New function.
* qt4/immodule/quiminputcontextplugin.pro.in
- (HEADERS): Add caretstateindicator.h.
- (SOURCES): Add caretstateindicator.cpp.
http://code.google.com/p/uim/source/detail?r=6260
Added:
/trunk/qt4/immodule/caretstateindicator.cpp
/trunk/qt4/immodule/caretstateindicator.h
Modified:
/trunk/qt4/immodule/Makefile.am
/trunk/qt4/immodule/qhelpermanager.cpp
/trunk/qt4/immodule/quiminputcontext.cpp
/trunk/qt4/immodule/quiminputcontext.h
/trunk/qt4/immodule/quiminputcontextplugin.pro.in
=======================================
--- /dev/null
+++ /trunk/qt4/immodule/caretstateindicator.cpp Sat Mar 20 16:08:15 2010
@@ -0,0 +1,117 @@
+/*
+
+ Copyright (c) 2010 uim Project http://code.google.com/p/uim/
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of authors nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+#include "caretstateindicator.h"
+
+#include <QtCore/QRect>
+#include <QtCore/QStringList>
+#include <QtCore/QTimer>
+#include <QtCore/QVariant>
+#include <QtGui/QApplication>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QLabel>
+#include <QtGui/QMoveEvent>
+
+// caret state indicator is a state indicator nearby the caret.
+CaretStateIndicator::CaretStateIndicator(QWidget *parent):
+ QWidget(parent, Qt::ToolTip), window(0)
+{
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->setMargin(0);
+ layout->setSpacing(0);
+ setLayout(layout);
+
+ m_timer = new QTimer(this);
+ connect(m_timer, SIGNAL(timeout()), this, SLOT(hide()));
+}
+
+CaretStateIndicator::~CaretStateIndicator()
+{
+ while (!m_labelList.isEmpty())
+ delete m_labelList.takeFirst();
+}
+
+void CaretStateIndicator::update(const QString &str)
+{
+ if (!str.isEmpty()) {
+ QStringList lines = str.split('\n', QString::SkipEmptyParts);
+ QStringList cols;
+ for (int i = 0; i < lines.count(); i++) {
+ if (lines.at(i).startsWith(QLatin1String("branch\t"))) {
+ QStringList branchLines = lines.at(i).split('\t');
+ if (branchLines.count() > 2)
+ cols.append(branchLines.at(2));
+ }
+ }
+ int colsCount = cols.count();
+ int labelCount = m_labelList.count();
+ for (int i = labelCount; i < colsCount; i++) {
+ QLabel *label = new QLabel;
+ label->setFrameStyle(QFrame::Box | QFrame::Plain);
+ m_labelList.append(label);
+ layout()->addWidget(label);
+ }
+ for (int i = colsCount; i < labelCount; i++) {
+ QLabel *label = m_labelList.takeAt(colsCount);
+ layout()->removeWidget(label);
+ delete label;
+ }
+ for (int i = 0; i < colsCount; i++)
+ m_labelList[i]->setText(cols[i]);
+ }
+ QWidget *widget = QApplication::focusWidget();
+ if (widget) {
+ QRect rect = widget->inputMethodQuery(Qt::ImMicroFocus).toRect();
+ move(widget->mapToGlobal(rect.bottomLeft()));
+ window = widget->window();
+ window->installEventFilter(this);
+ }
+ setVisible(true);
+}
+
+void CaretStateIndicator::setTimeout(int second)
+{
+ if (m_timer->isActive())
+ m_timer->stop();
+ m_timer->start(1000 * second);
+}
+
+bool CaretStateIndicator::eventFilter(QObject *obj, QEvent *event)
+{
+ if (obj == window) {
+ if (event->type() == QEvent::Move) {
+ QMoveEvent *moveEvent = static_cast<QMoveEvent *>(event);
+ move(pos() + moveEvent->pos() - moveEvent->oldPos());
+ }
+ return false;
+ }
+ return QWidget::eventFilter(obj, event);
+}
=======================================
--- /dev/null
+++ /trunk/qt4/immodule/caretstateindicator.h Sat Mar 20 16:08:15 2010
@@ -0,0 +1,57 @@
+/*
+
+ Copyright (c) 2010 uim Project http://code.google.com/p/uim/
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of authors nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+#ifndef UIM_QT4_CARET_STATE_INDICATOR_H
+#define UIM_QT4_CARET_STATE_INDICATOR_H
+
+#include <QtGui/QLabel>
+
+class QLabel;
+class QTimer;
+
+class CaretStateIndicator : public QWidget {
+ Q_OBJECT
+
+ public:
+ explicit CaretStateIndicator(QWidget *parent = 0);
+ ~CaretStateIndicator();
+
+ void update(const QString &str);
+ void setTimeout(int second);
+
+ private:
+ bool eventFilter(QObject *obj, QEvent *event);
+ QList<QLabel *> m_labelList;
+ QTimer *m_timer;
+ QWidget *window;
+};
+
+#endif
=======================================
--- /trunk/qt4/immodule/Makefile.am Wed Mar 17 05:50:35 2010
+++ /trunk/qt4/immodule/Makefile.am Sat Mar 20 16:08:15 2010
@@ -23,6 +23,7 @@
quiminputcontext_with_slave.cpp
EXTRA_DIST += candidatewindow.h \
+ caretstateindicator.h \
debug.h \
plugin.h \
qhelpermanager.h \
@@ -33,6 +34,7 @@
subwindow.h
EXTRA_DIST += candidatewindow.cpp \
+ caretstateindicator.cpp \
plugin.cpp \
qhelpermanager.cpp \
qtextutil.cpp \
=======================================
--- /trunk/qt4/immodule/qhelpermanager.cpp Sat Mar 13 04:38:19 2010
+++ /trunk/qt4/immodule/qhelpermanager.cpp Sat Mar 20 16:08:15 2010
@@ -281,6 +281,8 @@
msg += QString::fromUtf8( str );
uim_helper_send_message( im_uim_fd, msg.toUtf8().data() );
+
+ ic->setupIndicator( msg );
}
void QUimHelperManager::update_prop_label_cb( void *ptr, const char *str )
=======================================
--- /trunk/qt4/immodule/quiminputcontext.cpp Sat Mar 20 16:08:06 2010
+++ /trunk/qt4/immodule/quiminputcontext.cpp Sat Mar 20 16:08:15 2010
@@ -47,6 +47,7 @@
#include <uim/uim-scm.h>
#include "candidatewindow.h"
+#include "caretstateindicator.h"
#include "debug.h"
#include "plugin.h"
#include "qhelpermanager.h"
@@ -111,6 +112,8 @@
// read configuration
readIMConf();
+
+ m_indicator = new CaretStateIndicator;
}
QUimInputContext::~QUimInputContext()
@@ -942,6 +945,28 @@
cwin->setAlwaysLeftPosition( false );
free( leftp );
}
+
+void QUimInputContext::setupIndicator( const QString &str )
+{
+ bool isEnabled = uim_scm_symbol_value_bool( "bridge-show-input-state?"
);
+ char *type
+ = uim_scm_c_symbol( uim_scm_symbol_value( "bridge-show-with?" ) );
+ bool isMode = ( strcmp( type, "mode" ) == 0 );
+ free( type );
+ bool isModeOn
+ = uim_scm_symbol_value_bool( "bridge-show-input-state-mode-on?" );
+ if ( isEnabled && !( isMode && !isModeOn ) ) {
+ m_indicator->update( str );
+ if ( !isMode ) {
+ int time = uim_scm_symbol_value_int(
+ "bridge-show-input-state-time-length" );
+ if ( time != 0 )
+ m_indicator->setTimeout( time );
+ }
+ } else if ( isMode && !isModeOn ) {
+ m_indicator->setVisible( false );
+ }
+}
static int unicodeToUKey (ushort c) {
int sym;
=======================================
--- /trunk/qt4/immodule/quiminputcontext.h Sun Feb 28 15:00:48 2010
+++ /trunk/qt4/immodule/quiminputcontext.h Sat Mar 20 16:08:15 2010
@@ -48,6 +48,7 @@
class QEvent;
class CandidateWindow;
+class CaretStateIndicator;
class QUimHelperManager;
class QUimTextUtil;
#ifdef Q_WS_X11
@@ -107,6 +108,8 @@
void saveContext();
void restoreContext();
+ void setupIndicator( const QString &str );
+
protected:
uim_context createUimContext( const char *imname );
virtual bool isPreeditPreservationEnabled(); // not a QInputContext
func
@@ -166,6 +169,8 @@
#endif
QUimTextUtil *mTextUtil;
+ CaretStateIndicator *m_indicator;
+
protected:
QString m_imname;
QString m_lang;
=======================================
--- /trunk/qt4/immodule/quiminputcontextplugin.pro.in Wed Mar 17 05:50:35
2010
+++ /trunk/qt4/immodule/quiminputcontextplugin.pro.in Sat Mar 20 16:08:15
2010
@@ -24,6 +24,7 @@
# Input
HEADERS += @srcdir@/candidatewindow.h \
+ @srcdir@/caretstateindicator.h \
@srcdir@/debug.h \
@srcdir@/plugin.h \
@srcdir@/qhelpermanager.h \
@@ -34,6 +35,7 @@
@srcdir@/subwindow.h
SOURCES += @srcdir@/candidatewindow.cpp \
+ @srcdir@/caretstateindicator.cpp \
@srcdir@/plugin.cpp \
@srcdir@/qhelpermanager.cpp \
@srcdir@/qtextutil.cpp \
To unsubscribe from this group, send email to uim-commit+unsubscribegooglegroups.com or
reply to this email with the words "REMOVE ME" as the subject.