⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uniselect.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	    updateCellForIndex(mHighlighted);	mHighlighted = glyphindex;	if (mHighlighted != -1)	    updateCellForIndex(mHighlighted);    }}uint UScrollView::character() const{    if (mCurrent == -1) {	return 0;    } else if (mCurrent < (int)mSpecials.count()) {	return mSpecials[mCurrent].code;    } else {	return mGlyphMap[mCurrent-mSpecials.count()];    }}QString UScrollView::text() const{    if (mCurrent == -1) {	return QString::null;    } else if (mCurrent < (int)mSpecials.count()) {	return mSpecials[mCurrent].name;    } else {	ushort code = mGlyphMap[mCurrent-mSpecials.count()];	return QChar(code);    }}void UScrollView::drawContents(QPainter *p, int x, int y, int w, int h){    int startrow = y ? y / glyphSize : 0;    int endrow = (y+h) ? (y+h) / glyphSize : 0;    int startcol = x ? x / glyphSize : 0;    startcol = QMIN(glyphsPerRow-1, startcol);    int endcol = (x+w) ? (x+w) / glyphSize : 0;    endcol = QMIN(glyphsPerRow-1, endcol);    for (int row = startrow; row <= endrow; ++row) {	if (row < (int)mSpecials.count()) {	    drawCell(p, bounds(row), mSpecials[row].name, row);	} else {	    int glyphrow = row - mSpecials.count();	    for (int col = startcol; col <= endcol; ++col) {		int glyphindex = glyphrow*glyphsPerRow+col;		if (glyphindex < numGlyphs()) {		    QChar glyph = mGlyphMap[glyphindex];		    int index = glyphindex + mSpecials.count();		    drawCell(p, bounds(index), glyph, index);		} 	    }	}    }}void UScrollView::drawCell(QPainter *p, const QRect &b,	const QString &text, int glyphindex){    QRect bounds = b;    if (glyphindex == mCurrent) {	p->setBrush(colorGroup().text()); #ifdef QTOPIA_PHONE	if (!Global::mousePreferred() && isModalEditing()) {	    p->setPen(colorGroup().highlight()); 	    p->drawRect(bounds);	    bounds.setRect(bounds.x()+1, bounds.y()+1, 		    bounds.width()-2,bounds.height()-2);	    p->drawRect(bounds);	    p->setPen(colorGroup().base()); 	} else#endif	{	    p->setPen(colorGroup().base()); 	    p->drawRect(bounds);	}    } else if (glyphindex == mHighlighted) {	p->setBrush(colorGroup().highlight()); 	p->setPen(colorGroup().highlightedText()); 	p->drawRect(bounds);    } else {	p->setBrush(colorGroup().base()); 	p->setPen(colorGroup().text()); 	p->drawRect(bounds);    }    p->drawText(bounds, AlignCenter, text);}void UScrollView::updateCellForIndex(int ind){    updateContents(bounds(ind));}QRect UScrollView::bounds(int ind) const{    if (ind < (int)mSpecials.count())	return QRect(0, ind*glyphSize, glyphSize*glyphsPerRow, glyphSize);    else {	ind -= mSpecials.count();	int srow = ind ? ind / glyphsPerRow: 0;	int scol = ind ? ind % glyphsPerRow: 0;	srow += mSpecials.count();	return QRect(scol*glyphSize, srow*glyphSize, glyphSize, glyphSize);    }}int UScrollView::index(const QPoint &pos) const{    int row = pos.y() ? pos.y() / glyphSize : 0;    int col = pos.x() ? pos.x() / glyphSize : 0;    if (col >= glyphsPerRow) {	return -1;    } else if (row < (int)mSpecials.count()) {	return row;    } else {	row -= mSpecials.count();	return (row*glyphsPerRow)+col+mSpecials.count();    }}void UScrollView::coordToIndex(int row, int col, int &ind) const{    if (col >= glyphsPerRow) {	ind = -1;    } else if (row < (int)mSpecials.count()) {	ind = row;    } else {	row -= mSpecials.count();	ind = (row*glyphsPerRow)+col+mSpecials.count();    }    if (ind < 0 || ind >= (int)(mGlyphMap.count() + mSpecials.count()))	ind = -1;}void UScrollView::indexToCoord(int ind, int &srow, int &scol) const{    if (ind < (int)mSpecials.count()) {	srow = ind;	scol = 0;    } else {	ind -= mSpecials.count();	srow = ind ? ind / glyphsPerRow : 0;	scol = ind ? ind % glyphsPerRow : 0;	srow += mSpecials.count();    }}void UScrollView::contentsMousePressEvent(QMouseEvent *e){    setHighlighted(index(e->pos()));    QScrollView::contentsMousePressEvent(e);}void UScrollView::contentsMouseMoveEvent(QMouseEvent *e){    setHighlighted(index(e->pos()));    QScrollView::contentsMouseMoveEvent(e);}void UScrollView::contentsMouseReleaseEvent(QMouseEvent *e){    setHighlighted(-1);    setIndex(index(e->pos()));    QScrollView::contentsMouseReleaseEvent(e);}void UScrollView::resizeEvent(QResizeEvent *){    layoutGlyphs();}void UScrollView::fontChange(const QFont &){    fillMap();    layoutGlyphs();}int UScrollView::numGlyphs() const{    return mGlyphMap.size();}// Assume same name isn't already present.void UScrollView::addSpecial(uint code, const QString &name){    if ( (code & 0x0000FFFF) == 0 ) {	if (mSpecials.count() == 0) {	    addNonPrinting();	}	// ok to add	SpecialChar sp;	sp.code = code;	sp.name = name;	mSpecials.append(sp);	// resizeContents for extra row.	resizeContents(contentsWidth(), contentsHeight() + glyphSize);	// update entire contents since at beginning.	updateContents(0,0, contentsWidth(), contentsHeight());	if (mCurrent > (int)mSpecials.count())	    setIndex(mCurrent+1);    }}void UScrollView::clearSpecials(){    if (mSpecials.count() > 0) {	for (int i = mSpecials.count(); i > 0; i--) {	    uniSelect->mSetSelect->removeItem(0);	}	int countwas = mSpecials.count();	resizeContents(contentsWidth(), contentsHeight() - (mSpecials.count() * glyphSize));	mSpecials.clear();	updateContents(0,0, contentsWidth(), contentsHeight());	if (mCurrent < countwas && mCurrent != -1)	    setIndex(0);    }}void UScrollView::updateSelectedSet(int x, int y){    setSetForIndex(index(QPoint(x,y)));}void UScrollView::setSetForIndex(int ind){    if (updatingCurrent)	return;    QMap<int,int>::Iterator it;    for( it = mSetMap.begin(); it != mSetMap.end(); ++it ) {	int index = it.data() + mSpecials.count();	int cindex = it.key();	if (mSpecials.count() > 0)	    cindex++;	if (ind < index) {	    // set to previous...	    if (cindex > 0) {		uniSelect->mSetSelect->blockSignals(TRUE);		uniSelect->mSetSelect->setCurrentItem(cindex-1);		uniSelect->mSetSelect->blockSignals(FALSE);	    }	    break;	}    }}void UScrollView::selectSet(int item){    if (mSpecials.count()) {	if (item == 0) {	    setIndex(0);	    return;	}	item--;    }    if (mSetMap.contains(item)) {	setIndex(mSetMap[item]+mSpecials.count());    }}void UScrollView::addNonPrinting(){    uniSelect->mSetSelect->insertItem(tr("Non printing"), 0);}void UScrollView::fillMap(){    uniSelect->mSetSelect->clear();    // fill with the specials    if ( mSpecials.count() > 0 ) {	addNonPrinting();    }    mGlyphMap.resize(0xffff);    QFontMetrics fm(font());    int index = 0; // index into array    int cindex = 0; // index into combo box (ignores nonprinting)    int bindex = 0; // index into named sets (blockMap)    for (ushort candidate = 0x0000; candidate < 0xffff; ++candidate) {	QChar glyph = candidate;	if (glyph.isPrint() && fm.inFont(glyph)) {	    while (blockMap[bindex].stop < candidate) {		bindex++;	    }	    if (blockMap[bindex].start <= candidate) {		uniSelect->mSetSelect->insertItem(tr(blockMap[bindex].name));		mSetMap[cindex] = index;		cindex++;		bindex++;	    }		    mGlyphMap[index] = candidate;	    index++;	}    }    mGlyphMap.resize(index);    mCurrent = (index > 0 || mSpecials.count() > 0) ? 0 : -1;}/*   XXX still need to deal with font changes properly. */UniSelect::UniSelect(QWidget *parent, const char *name, int flags): QWidget(parent, name, flags){    QVBoxLayout *vl = new QVBoxLayout(this);    vl->setSpacing(4);    mSetSelect = new QComboBox(this);    vl->addWidget(mSetSelect);    mGlyphSelect = new UScrollView(this);    vl->addWidget(mGlyphSelect);    connect(mSetSelect, SIGNAL(activated(int)), mGlyphSelect, SLOT(selectSet(int)));    connect(mGlyphSelect, SIGNAL(selected(uint)),	    this, SIGNAL(selected(uint)));    connect(mGlyphSelect, SIGNAL(selected(const QString &)),	    this, SIGNAL(selected(const QString &)));}UniSelect::~UniSelect(){}void UniSelect::addSpecial(uint val, const QString &name){    mGlyphSelect->addSpecial(val, name);}void UniSelect::clearSpecials(){    mGlyphSelect->clearSpecials();}uint UniSelect::character() const{    return mGlyphSelect->character();}QString UniSelect::text() const{    return mGlyphSelect->text();}#include "uniselect.moc"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -