Revision: 6447
Author: nogu.dev
Date: Mon Jun 14 06:26:50 2010
Log: * qt4/immodule/abstractcandidatewindow.cpp
- New file.
* qt4/immodule/abstractcandidatewindow.h
- New file.
* qt4/immodule/candidatewindow.cpp
- (CandidateWindow): Inherit AbstractCandidateWindow.
* qt4/immodule/candidatewindow.h
- Ditto.
* qt4/immodule/quiminputcontext.cpp
- (QUimInputContext::QUimInputContext, QUimInputContext::savePreedit):
Use QUimInputContext::createCandidateWindow().
- (QUimInputContext::createCandidateWindow): New function.
* qt4/immodule/quiminputcontext.h
- (QUimInputContext::createCandidateWindow): New function.
* qt4/immodule/quiminputcontextplugin.pro.in
- Add abstractcandidatewindow.h and abstractcandidatewindow.cpp.
http://code.google.com/p/uim/source/detail?r=6447
Added:
/trunk/qt4/immodule/abstractcandidatewindow.cpp
/trunk/qt4/immodule/abstractcandidatewindow.h
Modified:
/trunk/qt4/immodule/candidatewindow.cpp
/trunk/qt4/immodule/candidatewindow.h
/trunk/qt4/immodule/quiminputcontext.cpp
/trunk/qt4/immodule/quiminputcontext.h
/trunk/qt4/immodule/quiminputcontextplugin.pro.in
=======================================
--- /dev/null
+++ /trunk/qt4/immodule/abstractcandidatewindow.cpp Mon Jun 14 06:26:50 2010
@@ -0,0 +1,386 @@
+/*
+
+ 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 "abstractcandidatewindow.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QDesktopWidget>
+#include <QtGui/QLabel>
+#include <QtGui/QMoveEvent>
+
+#include "quiminputcontext.h"
+
+const Qt::WindowFlags candidateFlag = (Qt::Window
+ | Qt::WindowStaysOnTopHint
+ | Qt::FramelessWindowHint
+ | Qt::Tool
+#if defined(Q_WS_X11)
+ | Qt::X11BypassWindowManagerHint
+#endif
+ );
+
+AbstractCandidateWindow::AbstractCandidateWindow(QWidget *parent)
+: QFrame(parent, candidateFlag), ic(0), nrCandidates(0), displayLimit(0),
+ candidateIndex(-1), pageIndex(-1), window(0), isAlwaysLeft(false)
+{
+ setFrameStyle(Raised|NoFrame);
+
+ // setup NumberLabel
+ numLabel = new QLabel;
+ numLabel->adjustSize();
+}
+
+AbstractCandidateWindow::~AbstractCandidateWindow()
+{
+ // clear stored candidate data
+ while (!stores.isEmpty()) {
+ uim_candidate cand = stores.takeFirst();
+ if (cand)
+ uim_candidate_free(cand);
+ }
+}
+
+void AbstractCandidateWindow::deactivateCandwin()
+{
+ hide();
+ clearCandidates();
+}
+
+void AbstractCandidateWindow::clearCandidates()
+{
+#ifdef ENABLE_DEBUG
+ qDebug("clear Candidates");
+#endif
+
+ candidateIndex = -1;
+ displayLimit = 0;
+ nrCandidates = 0;
+
+ // clear stored candidate data
+ while (!stores.isEmpty()) {
+ uim_candidate cand = stores.takeFirst();
+ if (cand)
+ uim_candidate_free(cand);
+ }
+}
+
+void AbstractCandidateWindow::popup()
+{
+ window = QApplication::focusWidget()->window();
+ window->installEventFilter(this);
+ raise();
+ show();
+}
+
+void AbstractCandidateWindow::layoutWindow(const QPoint &point,
+ const QRect &rect)
+{
+ const int x = point.x();
+ const int y = point.y();
+ const int h = rect.height();
+ int destX = x;
+ int destY = y + h;
+
+ int screenW = QApplication::desktop()->screenGeometry().width();
+ int screenH = QApplication::desktop()->screenGeometry().height();
+
+ if (destX + width() > screenW)
+ destX = screenW - width();
+
+ if (destY + height() > screenH)
+ destY = y - height();
+
+ move(destX, destY);
+}
+
+void AbstractCandidateWindow::candidateActivate(int nr, int displayLimit)
+{
+ QList<uim_candidate> list;
+
+#if !UIM_QT_USE_NEW_PAGE_HANDLING
+ activateCandwin(displayLimit);
+
+ // set candidates
+ uim_candidate cand;
+ for (int i = 0; i < nr; i++)
+ {
+ cand = uim_get_candidate(ic->uimContext(), i,
+ displayLimit ? i % displayLimit : i);
+ list.append(cand);
+ }
+ setCandidates(displayLimit, list);
+
+#else /* !UIM_QT_USE_NEW_PAGE_HANDLING */
+ nrPages = displayLimit ? (nr - 1) / displayLimit + 1 : 1;
+ pageFilled.clear();
+ for (int i = 0; i < nrPages; i++)
+ pageFilled.append(false);
+
+ setNrCandidates(nr, displayLimit);
+
+ // set page candidates
+ preparePageCandidates(0);
+ setPage(0);
+#endif /* !UIM_QT_USE_NEW_PAGE_HANDLING */
+ popup();
+}
+
+void AbstractCandidateWindow::candidateSelect(int index)
+{
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+ int new_page;
+
+ if (index >= nrCandidates)
+ index = 0;
+
+ if (index >= 0 && displayLimit)
+ new_page = index / displayLimit;
+ else
+ new_page = pageIndex;
+
+ preparePageCandidates(new_page);
+#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
+ setIndex(index);
+}
+
+void AbstractCandidateWindow::candidateShiftPage(bool forward)
+{
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+ int new_page, index;
+
+ index = forward ? pageIndex + 1 : pageIndex - 1;
+ if (index < 0)
+ new_page = nrPages - 1;
+ else if (index >= nrPages)
+ new_page = 0;
+ else
+ new_page = index;
+
+ preparePageCandidates(new_page);
+#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
+ shiftPage(forward);
+}
+
+void AbstractCandidateWindow::activateCandwin(int dLimit)
+{
+ candidateIndex = -1;
+ displayLimit = dLimit;
+ pageIndex = 0;
+}
+
+void AbstractCandidateWindow::shiftPage(bool forward)
+{
+#ifdef ENABLE_DEBUG
+ qDebug("candidateIndex = %d", candidateIndex);
+#endif
+
+ if (forward)
+ {
+ if (candidateIndex != -1)
+ candidateIndex += displayLimit;
+ setPage(pageIndex + 1);
+ }
+ else
+ {
+ if (candidateIndex != -1) {
+ if (candidateIndex < displayLimit)
+ candidateIndex = displayLimit * (nrCandidates /
displayLimit) + candidateIndex;
+ else
+ candidateIndex -= displayLimit;
+ }
+
+ setPage(pageIndex - 1);
+ }
+ if (ic && ic->uimContext() && candidateIndex != -1)
+ uim_set_candidate_index(ic->uimContext(), candidateIndex);
+}
+
+void AbstractCandidateWindow::setIndex(int totalindex)
+{
+#ifdef ENABLE_DEBUG
+ qDebug("setIndex : totalindex = %d", totalindex);
+#endif
+
+ // validity check
+ if (totalindex < 0)
+ candidateIndex = nrCandidates - 1;
+ else if (totalindex >= nrCandidates)
+ candidateIndex = 0;
+ else
+ candidateIndex = totalindex;
+
+ // set page
+ int newpage = 0;
+ if (displayLimit)
+ newpage = candidateIndex / displayLimit;
+ if (pageIndex != newpage)
+ setPage(newpage);
+}
+
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+void AbstractCandidateWindow::setNrCandidates(int nrCands, int dLimit)
+{
+#ifdef ENABLE_DEBUG
+ qDebug("setNrCandidates");
+#endif
+
+ // remove old data
+ if (!stores.isEmpty())
+ clearCandidates();
+
+ candidateIndex = -1;
+ displayLimit = dLimit;
+ nrCandidates = nrCands;
+ pageIndex = 0;
+
+ // setup dummy candidate
+ for (int i = 0; i < nrCandidates; i++)
+ {
+ uim_candidate d = 0;
+ stores.append(d);
+ }
+}
+#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
+
+void AbstractCandidateWindow::setCandidates(int dl,
+ const QList<uim_candidate> &candidates)
+{
+#ifdef ENABLE_DEBUG
+ qDebug("setCandidates");
+#endif
+
+ // remove old data
+ if (!stores.isEmpty())
+ clearCandidates();
+
+ // set defalt value
+ candidateIndex = -1;
+ nrCandidates = candidates.count();
+ displayLimit = dl;
+
+ if (candidates.isEmpty())
+ return ;
+
+ // set candidates
+ stores = candidates;
+
+ // shift to default page
+ setPage(0);
+}
+
+#if UIM_QT_USE_NEW_PAGE_HANDLING
+void AbstractCandidateWindow::setPageCandidates(int page,
+ const QList<uim_candidate> &candidates)
+{
+#ifdef ENABLE_DEBUG
+ qDebug("setPageCandidates");
+#endif
+
+ if (candidates.isEmpty())
+ return;
+
+ // set candidates
+ int start, pageNr;
+ start = page * displayLimit;
+
+ if (displayLimit && (nrCandidates - start) > displayLimit)
+ pageNr = displayLimit;
+ else
+ pageNr = nrCandidates - start;
+
+ for (int i = 0; i < pageNr; i++)
+ stores[start + i] = candidates[i];
+}
+
+void AbstractCandidateWindow::preparePageCandidates(int page)
+{
+ QList<uim_candidate> list;
+
+ if (page < 0)
+ return;
+
+ if (pageFilled[page])
+ return;
+
+ // set page candidates
+ uim_candidate cand;
+
+ int start = page * displayLimit;
+
+ int pageNr;
+ if (displayLimit && (nrCandidates - start) > displayLimit)
+ pageNr = displayLimit;
+ else
+ pageNr = nrCandidates - start;
+
+ for (int i = start; i < pageNr + start; i++)
+ {
+ cand = uim_get_candidate(ic->uimContext(), i,
+ displayLimit ? i % displayLimit : i);
+ list.append(cand);
+ }
+ pageFilled[page] = true;
+ setPageCandidates(page, list);
+}
+#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
+
+void AbstractCandidateWindow::updateLabel()
+{
+ QString indexString;
+ if (candidateIndex >= 0)
+ indexString = QString::number(candidateIndex + 1) + " / "
+ + QString::number(nrCandidates);
+ else
+ indexString = "- / " + QString::number(nrCandidates);
+
+ numLabel->setText(indexString);
+}
+
+bool AbstractCandidateWindow::eventFilter(QObject *obj, QEvent *event)
+{
+ if (obj == window) {
+ if (event->type() == QEvent::Move) {
+ QWidget *widget = QApplication::focusWidget();
+ if (widget) {
+ QRect rect
+ = widget->inputMethodQuery(Qt::ImMicroFocus).toRect();
+ QPoint p = widget->mapToGlobal(rect.topLeft());
+ layoutWindow(p, rect);
+ } else {
+ QMoveEvent *moveEvent = static_cast<QMoveEvent *>(event);
+ move(pos() + moveEvent->pos() - moveEvent->oldPos());
+ }
+ }
+ return false;
+ }
+ return QFrame::eventFilter(obj, event);
+}
=======================================
--- /dev/null
+++ /trunk/qt4/immodule/abstractcandidatewindow.h Mon Jun 14 06:26:50 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.
+
+*/
+#ifndef UIM_QT4_IMMODULE_ABSTRACT_CANDIDATE_WINDOW_H
+#define UIM_QT4_IMMODULE_ABSTRACT_CANDIDATE_WINDOW_H
+
+#include <QtCore/QList>
+#include <QtGui/QFrame>
+
+#include <uim/uim.h>
+
+#define UIM_QT_USE_NEW_PAGE_HANDLING 1
+
+class QLabel;
+
+class QUimInputContext;
+
+class AbstractCandidateWindow : public QFrame
+{
+ Q_OBJECT
+
+ public:
+ explicit AbstractCandidateWindow(QWidget *parent);
+ virtual ~AbstractCandidateWindow();
+
+ void deactivateCandwin();
+ void clearCandidates();
+ void popup();
+
+ void setAlwaysLeftPosition(bool left) { isAlwaysLeft = left; }
+ bool isAlwaysLeftPosition() const { return isAlwaysLeft; }
+
+ void layoutWindow(const QPoint &point, const QRect &rect);
+
+ void setQUimInputContext(QUimInputContext *m_ic) { ic = m_ic; }
+
+ void candidateActivate(int nr, int displayLimit);
+ void candidateSelect(int index);
+ void candidateShiftPage(bool forward);
+
+ protected:
+ virtual void activateCandwin(int dLimit);
+
+ virtual void setPage(int page) = 0;
+ virtual void shiftPage(bool forward);
+ virtual void setIndex(int totalindex);
+#ifdef UIM_QT_USE_NEW_PAGE_HANDLING
+ virtual void setNrCandidates(int nrCands, int dLimit);
+#endif
+ void updateLabel();
+
+ QUimInputContext *ic;
+
+ // widget
+ QLabel *numLabel;
+
+ // candidate data
+ QList<uim_candidate> stores;
+ int nrCandidates;
+ int displayLimit;
+ int candidateIndex;
+ int pageIndex;
+#ifdef UIM_QT_USE_NEW_PAGE_HANDLING
+ QList<bool> pageFilled;
+#endif
+
+ private:
+ void setCandidates(int displayLimit,
+ const QList<uim_candidate> &candidates);
+#ifdef UIM_QT_USE_NEW_PAGE_HANDLING
+ void setPageCandidates(int page,
+ const QList<uim_candidate> &candidates);
+ void preparePageCandidates(int page);
+#endif
+ bool eventFilter(QObject *obj, QEvent *event);
+
+ // widget
+ QWidget *window;
+
+ // candidate data
+#ifdef UIM_QT_USE_NEW_PAGE_HANDLING
+ int nrPages;
+#endif
+ // config
+ bool isAlwaysLeft;
+};
+
+#endif /* Not def: UIM_QT4_IMMODULE_ABSTRACT_CANDIDATE_WINDOW_H */
=======================================
--- /trunk/qt4/immodule/candidatewindow.cpp Sun May 23 07:54:44 2010
+++ /trunk/qt4/immodule/candidatewindow.cpp Mon Jun 14 06:26:50 2010
@@ -32,8 +32,6 @@
*/
#include "candidatewindow.h"
-#include <QtGui/QApplication>
-#include <QtGui/QDesktopWidget>
#include <QtGui/QFontMetrics>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
@@ -50,23 +48,10 @@
static const int CANDIDATE_COLUMN = 1;
static const int ANNOTATION_COLUMN = 2;
-const Qt::WindowFlags candidateFlag = ( Qt::Window
- | Qt::WindowStaysOnTopHint
- | Qt::FramelessWindowHint
- | Qt::Tool
-#if defined(Q_WS_X11)
- | Qt::X11BypassWindowManagerHint
-#endif
- );
-
CandidateWindow::CandidateWindow( QWidget *parent )
-: QFrame( parent, candidateFlag ), ic( 0 ), subWin( 0 ), window( 0 ),
- nrCandidates( 0 ), displayLimit( 0 ), candidateIndex( -1 ), pageIndex(
-1 ),
- isAlwaysLeft( false ), hasAnnotation( uim_scm_symbol_value_bool(
- "enable-annotation?" ) )
-{
- setFrameStyle( Raised | NoFrame );
-
+: AbstractCandidateWindow( parent ), subWin( 0 ),
+ hasAnnotation( uim_scm_symbol_value_bool( "enable-annotation?" ) )
+{
//setup CandidateList
cList = new CandidateListView;
cList->setSelectionMode( QAbstractItemView::SingleSelection );
@@ -87,10 +72,6 @@
connect( cList, SIGNAL( itemSelectionChanged() ),
this , SLOT( slotHookSubwindow() ) );
- //setup NumberLabel
- numLabel = new QLabel;
- numLabel->adjustSize();
-
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin( 0 );
layout->setSpacing( 0 );
@@ -98,133 +79,23 @@
layout->addWidget( numLabel );
setLayout( layout );
}
-
-CandidateWindow::~CandidateWindow()
-{
- // clear stored candidate data
- while ( !stores.isEmpty() ) {
- uim_candidate cand = stores.takeFirst();
- if ( cand )
- uim_candidate_free( cand );
- }
-}
-
-void CandidateWindow::popup()
-{
- window = QApplication::focusWidget()->window();
- window->installEventFilter( this );
- raise();
- show();
-}
void CandidateWindow::activateCandwin( int dLimit )
{
- candidateIndex = -1;
- displayLimit = dLimit;
- pageIndex = 0;
+ AbstractCandidateWindow::activateCandwin( dLimit );
if ( !subWin )
subWin = new SubWindow( this );
}
-
-void CandidateWindow::deactivateCandwin()
-{
- hide();
- clearCandidates();
-}
-
-void CandidateWindow::clearCandidates()
-{
-#ifdef ENABLE_DEBUG
- qDebug( "clear Candidates" );
-#endif
-
- candidateIndex = -1;
- displayLimit = 0;
- nrCandidates = 0;
-
- // clear stored candidate data
- while ( !stores.isEmpty() ) {
- uim_candidate cand = stores.takeFirst();
- if ( cand )
- uim_candidate_free( cand );
- }
-}
-
-
-void CandidateWindow::setCandidates( int dl, const QList<uim_candidate>
&candidates )
-{
-#ifdef ENABLE_DEBUG
- qDebug( "setCandidates" );
-#endif
-
- // remove old data
- if ( !stores.isEmpty() )
- clearCandidates();
-
- // set defalt value
- candidateIndex = -1;
- nrCandidates = candidates.count();
- displayLimit = dl;
-
- if ( candidates.isEmpty() )
- return ;
-
- // set candidates
- stores = candidates;
-
- // shift to default page
- setPage( 0 );
-}
#if UIM_QT_USE_NEW_PAGE_HANDLING
void CandidateWindow::setNrCandidates( int nrCands, int dLimit )
{
-#ifdef ENABLE_DEBUG
- qDebug( "setNrCandidates" );
-#endif
-
- // remove old data
- if ( !stores.isEmpty() )
- clearCandidates();
-
- candidateIndex = -1;
- displayLimit = dLimit;
- nrCandidates = nrCands;
- pageIndex = 0;
-
- // setup dummy candidate
- for ( int i = 0; i < nrCandidates; i++ )
- {
- uim_candidate d = 0;
- stores.append( d );
- }
+ AbstractCandidateWindow::setNrCandidates( nrCands, dLimit );
if ( !subWin )
subWin = new SubWindow( this );
}
-
-void CandidateWindow::setPageCandidates( int page, const
QList<uim_candidate> &candidates )
-{
-#ifdef ENABLE_DEBUG
- qDebug( "setPageCandidates" );
-#endif
-
- if ( candidates.isEmpty() )
- return;
-
- // set candidates
- int start, pageNr;
- start = page * displayLimit;
-
- if ( displayLimit && ( nrCandidates - start ) > displayLimit )
- pageNr = displayLimit;
- else
- pageNr = nrCandidates - start;
-
- for ( int i = 0; i < pageNr; i++ )
- stores[ start + i ] = candidates[ i ];
-}
#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
void CandidateWindow::setPage( int page )
@@ -339,24 +210,7 @@
void CandidateWindow::setIndex( int totalindex )
{
-#ifdef ENABLE_DEBUG
- qDebug( "setIndex : totalindex = %d", totalindex );
-#endif
-
- // validity check
- if ( totalindex < 0 )
- candidateIndex = nrCandidates - 1;
- else if ( totalindex >= nrCandidates )
- candidateIndex = 0;
- else
- candidateIndex = totalindex;
-
- // set page
- int newpage = 0;
- if ( displayLimit )
- newpage = candidateIndex / displayLimit;
- if ( pageIndex != newpage )
- setPage( newpage );
+ AbstractCandidateWindow::setIndex( totalindex );
// select item
if ( candidateIndex >= 0 )
@@ -389,166 +243,17 @@
void CandidateWindow::shiftPage( bool forward )
{
-#ifdef ENABLE_DEBUG
- qDebug( "candidateIndex = %d", candidateIndex );
-#endif
-
- if ( forward )
- {
- if ( candidateIndex != -1 )
- candidateIndex += displayLimit;
- setPage( pageIndex + 1 );
- }
- else
- {
- if (candidateIndex != -1 ) {
- if ( candidateIndex < displayLimit )
- candidateIndex = displayLimit * ( nrCandidates /
displayLimit ) + candidateIndex;
- else
- candidateIndex -= displayLimit;
- }
-
- setPage( pageIndex - 1 );
- }
-
+ AbstractCandidateWindow::shiftPage( forward );
if ( candidateIndex != -1 ) {
cList->clearSelection();
int idx = displayLimit ? candidateIndex % displayLimit :
candidateIndex;
cList->selectRow( idx );
}
- if ( ic && ic->uimContext() && candidateIndex != -1 )
- uim_set_candidate_index( ic->uimContext(), candidateIndex );
}
-void CandidateWindow::layoutWindow( const QPoint &point, const QRect &rect
)
-{
- const int x = point.x();
- const int y = point.y();
- const int h = rect.height();
- int destX = x;
- int destY = y + h;
-
- int screenW = QApplication::desktop() ->screenGeometry().width();
- int screenH = QApplication::desktop() ->screenGeometry().height();
-
- if ( destX + width() > screenW )
- destX = screenW - width();
-
- if ( destY + height() > screenH )
- destY = y - height();
-
- move( destX, destY );
-}
#if UIM_QT_USE_NEW_PAGE_HANDLING
-void CandidateWindow::preparePageCandidates( int page )
-{
- QList<uim_candidate> list;
-
- if ( page < 0 )
- return;
-
- if ( pageFilled[ page ] )
- return;
-
- // set page candidates
- uim_candidate cand;
-
- int start = page * displayLimit;
-
- int pageNr;
- if ( displayLimit && ( nrCandidates - start ) > displayLimit )
- pageNr = displayLimit;
- else
- pageNr = nrCandidates - start;
-
- for ( int i = start; i < ( pageNr + start ); i++ )
- {
- cand = uim_get_candidate( ic->uimContext(), i, displayLimit ? i %
displayLimit : i );
- list.append( cand );
- }
- pageFilled[ page ] = true;
- setPageCandidates( page, list );
-}
#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
-
-void CandidateWindow::candidateActivate( int nr, int displayLimit )
-{
- QList<uim_candidate> list;
-
-#if !UIM_QT_USE_NEW_PAGE_HANDLING
- activateCandwin( displayLimit );
-
- // set candidates
- uim_candidate cand;
- for ( int i = 0; i < nr; i++ )
- {
- cand = uim_get_candidate( ic->uimContext(), i, displayLimit ? i %
displayLimit : i );
- list.append( cand );
- }
- setCandidates( displayLimit, list );
-
-#else /* !UIM_QT_USE_NEW_PAGE_HANDLING */
- nrPages = displayLimit ? ( nr - 1 ) / displayLimit + 1 : 1;
- pageFilled.clear();
- for ( int i = 0; i < nrPages; i++ )
- pageFilled.append( false );
-
- setNrCandidates( nr, displayLimit );
-
- // set page candidates
- preparePageCandidates( 0 );
- setPage( 0 );
-#endif /* !UIM_QT_USE_NEW_PAGE_HANDLING */
- popup();
-}
-
-void CandidateWindow::candidateSelect( int index )
-{
-#if UIM_QT_USE_NEW_PAGE_HANDLING
- int new_page;
-
- if ( index >= nrCandidates )
- index = 0;
-
- if ( index >= 0 && displayLimit )
- new_page = index / displayLimit;
- else
- new_page = pageIndex;
-
- preparePageCandidates( new_page );
-#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
- setIndex( index );
-}
-
-void CandidateWindow::candidateShiftPage( bool forward )
-{
-#if UIM_QT_USE_NEW_PAGE_HANDLING
- int new_page, index;
-
- index = forward ? pageIndex + 1 : pageIndex - 1;
- if ( index < 0 )
- new_page = nrPages - 1;
- else if ( index >= nrPages )
- new_page = 0;
- else
- new_page = index;
-
- preparePageCandidates( new_page );
-#endif /* UIM_QT_USE_NEW_PAGE_HANDLING */
- shiftPage( forward );
-}
-
-void CandidateWindow::updateLabel()
-{
- QString indexString;
- if ( candidateIndex >= 0 )
- indexString = QString::number( candidateIndex + 1 ) + " / " +
QString::number( nrCandidates );
- else
- indexString = "- / " + QString::number( nrCandidates );
-
- numLabel->setText( indexString );
-}
void CandidateWindow::slotHookSubwindow()
{
@@ -605,26 +310,6 @@
return QSize( width, height );
}
-
-bool CandidateWindow::eventFilter( QObject *obj, QEvent *event )
-{
- if ( obj == window ) {
- if ( event->type() == QEvent::Move ) {
- QWidget *widget = QApplication::focusWidget();
- if ( widget ) {
- QRect rect
- = widget->inputMethodQuery( Qt::ImMicroFocus
).toRect();
- QPoint p = widget->mapToGlobal( rect.topLeft() );
- layoutWindow( p, rect );
- } else {
- QMoveEvent *moveEvent = static_cast<QMoveEvent *>( event );
- move( pos() + moveEvent->pos() - moveEvent->oldPos() );
- }
- }
- return false;
- }
- return QFrame::eventFilter( obj, event );
-}
QSize CandidateListView::sizeHint() const
{
=======================================
--- /trunk/qt4/immodule/candidatewindow.h Sun May 23 07:54:44 2010
+++ /trunk/qt4/immodule/candidatewindow.h Mon Jun 14 06:26:50 2010
@@ -33,93 +33,49 @@
#ifndef UIM_QT4_IMMODULE_CANDIDATE_WINDOW_H
#define UIM_QT4_IMMODULE_CANDIDATE_WINDOW_H
-#include <QtCore/QList>
#include <QtGui/QTableWidget>
-#include <uim/uim.h>
-
-#define UIM_QT_USE_NEW_PAGE_HANDLING 1
-
-class QLabel;
+#include "abstractcandidatewindow.h"
class CandidateListView;
-class QUimInputContext;
class SubWindow;
-class CandidateWindow : public QFrame
+class CandidateWindow : public AbstractCandidateWindow
{
Q_OBJECT
public:
explicit CandidateWindow( QWidget *parent );
- ~CandidateWindow();
-
- void deactivateCandwin();
- void clearCandidates();
- void popup();
-
- void setAlwaysLeftPosition( bool left ) { isAlwaysLeft = left; }
- bool isAlwaysLeftPosition() const { return isAlwaysLeft; }
-
- void layoutWindow( const QPoint &point, const QRect &rect );
-
- void setQUimInputContext( QUimInputContext* m_ic ) { ic = m_ic; }
-
- void candidateActivate( int nr, int displayLimit );
- void candidateSelect( int index );
- void candidateShiftPage( bool forward );
QSize sizeHint() const;
-protected slots:
+private slots:
void slotCandidateSelected( int row );
void slotHookSubwindow();
-protected:
+private:
void activateCandwin( int dLimit );
- void setCandidates( int displayLimit, const QList<uim_candidate>
&candidates );
void setPage( int page );
void shiftPage( bool forward );
void setIndex( int totalindex );
void setNrCandidates( int nrCands, int dLimit );
- void setPageCandidates( int page, const QList<uim_candidate>
&candidates );
-
-#ifdef UIM_QT_USE_NEW_PAGE_HANDLING
- void preparePageCandidates( int page );
-#endif
- void updateLabel();
// Moving and Resizing affects the position of Subwindow
virtual void moveEvent( QMoveEvent * );
virtual void resizeEvent( QResizeEvent * );
virtual void hideEvent( QHideEvent *event );
- bool eventFilter( QObject *obj, QEvent *event );
-
- QUimInputContext *ic;
-
// widgets
CandidateListView *cList;
- QLabel *numLabel;
SubWindow *subWin;
- QWidget *window;
+
// candidate data
- QList<uim_candidate> stores;
QList<QString> annotations;
- int nrCandidates;
- int displayLimit;
- int candidateIndex;
- int pageIndex;
-#ifdef UIM_QT_USE_NEW_PAGE_HANDLING
- QList<bool> pageFilled;
- int nrPages;
-#endif
// config
- bool isAlwaysLeft;
const bool hasAnnotation;
};
=======================================
--- /trunk/qt4/immodule/quiminputcontext.cpp Tue Jun 8 03:16:16 2010
+++ /trunk/qt4/immodule/quiminputcontext.cpp Mon Jun 14 06:26:50 2010
@@ -97,9 +97,7 @@
if ( imname )
m_uc = createUimContext( imname );
- cwin = new CandidateWindow( 0 );
- cwin->setQUimInputContext( this );
- cwin->hide();
+ createCandidateWindow();
#ifdef Q_WS_X11
if ( !mTreeTop )
@@ -129,7 +127,7 @@
foreach ( const uim_context uc, m_ucHash )
if ( uc )
uim_release_context( uc );
- foreach ( const CandidateWindow* window, cwinHash )
+ foreach ( const AbstractCandidateWindow* window, cwinHash )
delete window;
#endif
@@ -181,6 +179,13 @@
return uc;
}
+
+void QUimInputContext::createCandidateWindow()
+{
+ cwin = new CandidateWindow( 0 );
+ cwin->setQUimInputContext( this );
+ cwin->hide();
+}
#ifdef Q_WS_X11
bool QUimInputContext::x11FilterEvent( QWidget *keywidget, XEvent *event )
@@ -658,9 +663,7 @@
if ( imname )
m_uc = createUimContext( imname );
psegs.clear();
- cwin = new CandidateWindow( 0 );
- cwin->setQUimInputContext( this );
- cwin->hide();
+ createCandidateWindow();
}
void QUimInputContext::restorePreedit()
=======================================
--- /trunk/qt4/immodule/quiminputcontext.h Tue Jun 8 03:16:28 2010
+++ /trunk/qt4/immodule/quiminputcontext.h Mon Jun 14 06:26:50 2010
@@ -46,7 +46,7 @@
class QEvent;
-class CandidateWindow;
+class AbstractCandidateWindow;
class CaretStateIndicator;
class QUimHelperManager;
class QUimTextUtil;
@@ -109,6 +109,7 @@
protected:
uim_context createUimContext( const char *imname );
+ void createCandidateWindow();
bool isPreeditPreservationEnabled(); // not a QInputContext func
virtual void setFocus(); // not a QInputContext func
virtual void unsetFocus(); // not a QInputContext func
@@ -169,12 +170,12 @@
uim_context m_uc;
QList<PreeditSegment> psegs;
- CandidateWindow *cwin;
+ AbstractCandidateWindow *cwin;
#ifdef WORKAROUND_BROKEN_RESET_IN_QT4
QHash<QWidget*, uim_context> m_ucHash;
QHash<QWidget*, QList<PreeditSegment> > psegsHash;
- QHash<QWidget*, CandidateWindow*> cwinHash;
+ QHash<QWidget*, AbstractCandidateWindow*> cwinHash;
QHash<QWidget*, bool> visibleHash;
QWidget *focusedWidget;
=======================================
--- /trunk/qt4/immodule/quiminputcontextplugin.pro.in Thu Mar 25 03:20:54
2010
+++ /trunk/qt4/immodule/quiminputcontextplugin.pro.in Mon Jun 14 06:26:50
2010
@@ -23,7 +23,8 @@
# Input
-HEADERS += @srcdir@/candidatewindow.h \
+HEADERS += @srcdir@/abstractcandidatewindow.h \
+ @srcdir@/candidatewindow.h \
@srcdir@/caretstateindicator.h \
@srcdir@/plugin.h \
@srcdir@/qhelpermanager.h \
@@ -33,7 +34,8 @@
@srcdir@/quiminputcontext_compose.h \
@srcdir@/subwindow.h
-SOURCES += @srcdir@/candidatewindow.cpp \
+SOURCES += @srcdir@/abstractcandidatewindow.cpp \
+ @srcdir@/candidatewindow.cpp \
@srcdir@/caretstateindicator.cpp \
@srcdir@/plugin.cpp \
@srcdir@/qhelpermanager.cpp \