📄 pickboardcfg.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "pickboardcfg.h"#include "pickboardpicks.h"#include <qtopia/global.h>#include <qpainter.h>#include <qlist.h>#include <qbitmap.h>#include <qlayout.h>#include <qvbox.h>#include <qdialog.h>#include <qscrollview.h>#include <qpopupmenu.h>#include <qhbuttongroup.h>#include <qpushbutton.h>#include <qmessagebox.h>#ifdef QWS#include <qwindowsystem_qws.h>#endifconst int intermatchmargin=5;PickboardConfig::~PickboardConfig() { }void PickboardConfig::updateRows(int from, int to){ if ( from != to ) { // (all) parent->update(); } else { QFontMetrics fm = parent->fontMetrics(); parent->update(QRect(0,1+fm.descent() + from * fm.lineSpacing(), parent->width(), fm.lineSpacing())); }}void PickboardConfig::updateItem(int r, int){ updateRows(r,r);}void PickboardConfig::changeMode(int m){ parent->setMode(m);}void PickboardConfig::generateText(const QString& s){#if defined(Q_WS_QWS) || defined(_WS_QWS_) for (int i=0; i<(int)s.length(); i++) { uint code = 0; if ( s[i].unicode() >= 'a' && s[i].unicode() <= 'z' ) { code = s[i].unicode() - 'a' + Key_A; } parent->emitKey(s[i].unicode(), code, 0, true, false); parent->emitKey(s[i].unicode(), code, 0, false, false); }#endif }void PickboardConfig::generateKey( int k ){#if defined(Q_WS_QWS) || defined(_WS_QWS_) parent->emitKey(0, k, 0, true, false); parent->emitKey(0, k, 0, false, false);#endif}void PickboardConfig::pickPoint(const QPoint& p, bool press){ if ( press ) { int ls=parent->height()/nrows; int y=0; pressx = -1; for (int r=0; r<nrows; r++) { if ( p.y() >= y && p.y() < y+ls ) { pressrow = r; pressx = p.x(); pickInRow( pressrow, pressx, TRUE ); return; } y += ls; } } else if ( pressx >= 0 ) { pickInRow( pressrow, pressx, FALSE ); pressx = -1; }}void PickboardConfig::fillMenu(QPopupMenu& menu){ menu.insertItem(tr("Reset"),100); menu.insertSeparator(); menu.insertItem(tr("Help"),1);}void PickboardConfig::doMenu(int i){ switch (i) { case 100: if ( parent->currentMode() ) { changeMode(0); updateRows(0,1); } break; }}void StringConfig::draw(QPainter* p){ QFontMetrics fm = p->fontMetrics(); for (int r=0; r<nrows; r++) { p->translate(0,fm.lineSpacing()); p->setPen(rowColor(r)); int tw=0; QString s; int i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s); tw += w; } bool spread = spreadRow(r);// && parent->width() > tw; int xw = spread ? (parent->width()-tw)/(i-1) : 3; int x = spread ? (parent->width()-tw-xw*(i-1))/2 : 2; i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s)+xw; if ( highlight(r,i) ) { p->fillRect(x-xw/2,1+fm.descent()-fm.lineSpacing(),w,fm.lineSpacing(),Qt::black); p->setPen(Qt::white); }else{ p->setPen(Qt::black); } p->drawText(x,-fm.descent()-1,s); x += w; } }}void StringConfig::pickInRow(int r, int xpos, bool press){ QFontMetrics fm = parent->fontMetrics(); int tw=0; QString s; int i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s); tw += w; } bool spread = spreadRow(r) && parent->width() > tw; int xw = spread ? (parent->width()-tw)/(i-1) : 3; int x = spread ? (parent->width()-tw-xw*(i-1))/2 : 2; i=0; for (; !(s=text(r,i)).isNull(); ++i) { int x2 = x + fm.width(s)+xw; if ( xpos >= x && xpos < x2 ) { pick(press, r, i); return; } x = x2; }}void StringConfig::updateItem(int r, int item){ QFontMetrics fm = parent->fontMetrics(); int y = r * fm.lineSpacing(); int tw=0; QString s; int i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s); tw += w; } bool spread = spreadRow(r) && parent->width() > tw; int xw = spread ? (parent->width()-tw)/(i-1) : 3; int x = spread ? (parent->width()-tw-xw*(i-1))/2 : 2; i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s)+xw; if ( i == item ) { parent->update(QRect(x-xw/2,y+1+fm.descent(),w,fm.lineSpacing())); return; } x += w; }}bool StringConfig::highlight(int,int) const{ return FALSE;}LetterButton::LetterButton(const QChar& letter, QWidget* parent) : QPushButton(letter,parent){ setToggleButton(TRUE); setAutoDefault(FALSE); connect(this,SIGNAL(clicked()),this,SLOT(toggleCase())); skip=TRUE;}void LetterButton::toggleCase(){ if ( skip ) { // Don't toggle case the first time skip=FALSE; return; } QChar ch = text()[0]; QChar nch = ch.lower(); if ( ch == nch ) nch = ch.upper(); setText(nch);}LetterChoice::LetterChoice(QWidget* parent, const QString& set) : QButtonGroup(parent){ QHBoxLayout *l = new QHBoxLayout(this); setFrameStyle(0); setExclusive(TRUE); for (int i=0; i<(int)set.length(); i++) { LetterButton* b = new LetterButton(set[i],this); l->addWidget(b,1,AlignCenter); connect(b,SIGNAL(clicked()),this,SLOT(change())); }}void LetterChoice::change(){ LetterButton* b = (LetterButton*)sender(); ch = b->text()[0]; emit changed();}PickboardAdd::PickboardAdd(QWidget* owner, const QStringList& setlist) : QDialog( owner, 0, TRUE ){ QVBoxLayout* l = new QVBoxLayout(this); l->setAutoAdd(TRUE); QScrollView *sv = new QScrollView(this); sv->setResizePolicy(QScrollView::AutoOneFit); setMaximumHeight(200); // ### QDialog shouldn't allow us to be bigger than the screen QVBox *letters = new QVBox(sv); letters->setSpacing(0); lc = new LetterChoice*[setlist.count()]; nlc = (int)setlist.count(); for (int i=0; i<nlc; i++) { lc[i] = new LetterChoice(letters,setlist[i]); connect(lc[i],SIGNAL(changed()),this,SLOT(checkAllDone())); } sv->addChild(letters); QHBox* hb = new QHBox(this); hb->setSpacing(0); yes = new QPushButton(tr("OK"),hb); yes->setEnabled(FALSE); QPushButton *no = new QPushButton(tr("Cancel"),hb); connect(yes, SIGNAL(clicked()), this, SLOT(accept())); connect(no, SIGNAL(clicked()), this, SLOT(reject()));}PickboardAdd::~PickboardAdd(){ delete [] lc;}QString PickboardAdd::word() const{ QString str; for (int i=0; i<nlc; i++) { str += lc[i]->choice(); } return str;}bool PickboardAdd::exec(){ QPoint pos = parentWidget()->mapToGlobal(QPoint(0,0)); pos.ry() -= height(); if ( QDialog::exec() ) { Global::addWords(QStringList(word())); return TRUE; } else { return FALSE; }}void PickboardAdd::checkAllDone(){ if ( !yes->isEnabled() ) { for (int i=0; i<nlc; i++) { if ( lc[i]->choice().isNull() ) return; } yes->setEnabled(TRUE); }}void DictFilterConfig::doMenu(int i){ switch (i) { case 300: if ( input.count() == 0 ) { QMessageBox::information(0, tr("Adding Words"), tr("<qt>To add words, pick the letters, then " "open the Add dialog. In that dialog, tap " "the correct letters from the list " "(tap twice for capitals).</qt>")); } else { PickboardAdd add(parent,capitalize(input)); if ( add.exec() ) generateText(add.word()); input.clear(); matches.clear(); updateRows(0,0); } break; case 100: if ( !input.isEmpty() ) { input.clear(); matches.clear(); StringConfig::doMenu(i); updateRows(0,1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -