void CandidateWindow::showPage( const QStringList &list ) { #if defined(ENABLE_DEBUG) qDebug( "uim-candwin-qt: showPage()" ); #endif const int page = list[ 1 ].toInt(); setPage( page ); adjustCandidateWindowSize(); show(); }
void CandidateWindow::setPage( int page ) { // clear items cList->clear(); // calculate page int newpage, lastpage; if ( displayLimit ) lastpage = nrCandidates / displayLimit; else lastpage = 0; if ( page < 0 ) { newpage = lastpage; } else if ( page > lastpage ) { newpage = 0; } else { newpage = page; } pageIndex = newpage; // calculate index int newindex; if ( displayLimit ) { if ( candidateIndex >= 0 ) newindex = ( newpage * displayLimit ) + ( candidateIndex % displayLimit ); else newindex = -1; } else { newindex = candidateIndex; } if ( newindex >= nrCandidates ) newindex = nrCandidates - 1; // set cand items // // If we switch to last page, the number of items to be added // is lower than displayLimit. // // ex. if nrCandidate==14 and displayLimit==10, the number of // last page's item==4 int ncandidates = displayLimit; if ( newpage == lastpage ) ncandidates = nrCandidates - displayLimit * lastpage; for ( int i = ncandidates - 1; i >=0 ; i-- ) { QString headString = stores[ displayLimit * newpage + i ].label; QString candString = stores[ displayLimit * newpage + i ].str; // insert new item to the candidate list new QListViewItem( cList, headString, candString ); } // set index if ( newindex != candidateIndex ) setIndex( newindex ); else updateLabel(); // set candwin size adjustCandidateWindowSize(); }
void XimCandidateWindow::setPage(int page) { // clear items cList->clearContents(); // calculate page int newpage, lastpage; if (displayLimit) lastpage = nrCandidates / displayLimit; else lastpage = 0; if (page < 0) { newpage = lastpage; } else if (page > lastpage) { newpage = 0; } else { newpage = page; } pageIndex = newpage; // calculate index int newindex; if (displayLimit) { if (candidateIndex >= 0) newindex = (newpage * displayLimit) + (candidateIndex % displayLimit); else newindex = -1; } else { newindex = candidateIndex; } if (newindex >= nrCandidates) newindex = nrCandidates - 1; // set cand items // // If we switch to last page, the number of items to be added // is lower than displayLimit. // // ex. if nrCandidate==14 and displayLimit==10, the number of // last page's item==4 int ncandidates = displayLimit; if (newpage == lastpage) ncandidates = nrCandidates - displayLimit * lastpage; cList->setRowCount(ncandidates); for (int i = 0; i < ncandidates ; i++) { QString headString = stores[displayLimit * newpage + i].headingLabel; QString candString = stores[displayLimit * newpage + i].str; // insert new item to the candidate list QTableWidgetItem *headItem = new QTableWidgetItem; headItem->setText(headString); headItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); QTableWidgetItem *candItem = new QTableWidgetItem; candItem->setText(candString); candItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); cList->setItem(i, HEADING_COLUMN, headItem); cList->setItem(i, CANDIDATE_COLUMN, candItem); cList->setRowHeight(i, QFontMetrics(cList->font()).height() + 2); } // set index if (newindex != candidateIndex) setIndex(newindex); else updateLabel(); // set candwin size adjustCandidateWindowSize(); }
void CandidateWindow::activateCand( const QStringList &list ) { #if defined(ENABLE_DEBUG) qDebug( "uim-candwin-qt: activateCand()" ); #endif /** * format: activate\fcharset=$charset\fdisplay_limit=$value\fhead1\acand1\aannot1\fhead2\acand2\aannot2\fhead3\acand3\aannot3\f */ // remove old data cList->clear(); stores.clear(); // get charset and create codec QTextCodec *codec = NULL; if ( !list[ 1 ].isEmpty() && list[ 1 ].startsWith( "charset" ) ) { const QStringList l = QStringList::split( "=", list[ 1 ] ); codec = QTextCodec::codecForName( l[ 1 ] ); } // get display_limit if ( !list[ 2 ].isEmpty() && list[ 2 ].startsWith( "display_limit" ) ) { const QStringList l = QStringList::split( "=", list[ 2 ] ); displayLimit = l[ 1 ].toInt(); } for ( int i = 3; !list[ i ].isNull(); i++ ) { // case list[i] = "" if ( list[ i ].isEmpty() ) break; // split heading_label and cand_str QStringList l = QStringList::split( "\a", list [ i ], true ); // store data CandData d; QString headString; if ( codec ) headString = codec->toUnicode( l [ 0 ] ); else headString = l [ 0 ]; d.label = headString; l.pop_front(); QString candString = l [ 0 ]; if ( codec ) d.str = codec->toUnicode( candString ); else d.str = candString; l.pop_front(); QString annotString = l [ 0 ]; stores.append( d ); } // set default value candidateIndex = -1; nrCandidates = stores.count(); // shift to default page setPage( 0 ); adjustCandidateWindowSize(); show(); isActive = true; }
void XimCandidateWindow::activateCand(const QStringList &list) { #if defined(ENABLE_DEBUG) qDebug("uim-candwin-qt4: activateCand()"); #endif /** * format: activate\fcharset=$charset\fdisplay_limit=$value\fhead1\acand1\aannot1\fhead2\acand2\aannot2\fhead3\acand3\aannot3\f */ // remove old data cList->clearContents(); cList->setRowCount(0); stores.clear(); // get charset and create codec QTextCodec *codec = 0; if (!list[1].isEmpty() && list[1].startsWith(QLatin1String("charset"))) { const QStringList l = list[1].split('=', QString::SkipEmptyParts); codec = QTextCodec::codecForName(l[1].toLatin1()); } // get display_limit if (!list[2].isEmpty() && list[2].startsWith(QLatin1String("display_limit"))) { const QStringList l = list[2].split('=', QString::SkipEmptyParts); displayLimit = l[1].toInt(); } for (int i = 3; i < list.count(); i++) { // case list[i] = "" if (list[i].isEmpty()) break; // split heading_label and cand_str QStringList l = list[i].split('\a'); int count = l.count(); if (count < 2) continue; // store data CandData d; QString headString; if (codec) headString = codec->toUnicode(l[0].toLatin1()); else headString = l [0]; d.headingLabel = headString; l.pop_front(); QString candString = l [0]; if (codec) d.str = codec->toUnicode(candString.toLatin1()); else d.str = candString; if (count >= 3) { l.pop_front(); QString annotString = l [0]; } stores.append(d); } // set default value candidateIndex = -1; nrCandidates = stores.count(); // shift to default page setPage(0); adjustCandidateWindowSize(); show(); isActive = true; }