CRect SListBoxEx::GetItemRect( int iItem ) { CRect rcClient; GetClientRect(&rcClient); CRect rcRet(CPoint(0,iItem*m_nItemHei),CSize(rcClient.Width(),m_nItemHei)); rcRet.OffsetRect(rcClient.TopLeft()-m_ptOrigin); return rcRet; }
// Generated message map functions CRect CDuiScrollBar::GetPartRect(UINT uSBCode) { DUIASSERT(m_pSkin); int nTrackPos=m_si.nTrackPos; int nMax=m_si.nMax; if(nMax<m_si.nMin+(int)m_si.nPage-1) nMax=m_si.nMin+m_si.nPage-1; if(nTrackPos==-1) nTrackPos=m_si.nPos; int nLength=(IsVertical()?m_rcWindow.Height():m_rcWindow.Width()); int nInterHei=nLength-2*m_uAllowSize; if(nInterHei<0) nInterHei=0; int nSlideHei=m_si.nPage*nInterHei/(nMax-m_si.nMin+1); if(nMax==m_si.nMin+m_si.nPage-1) nSlideHei=nInterHei; if(nSlideHei<THUMB_MINSIZE) nSlideHei=THUMB_MINSIZE; if(nInterHei<THUMB_MINSIZE) nSlideHei=0; int nEmptyHei=nInterHei-nSlideHei; int nArrowHei=m_uAllowSize; if(nInterHei==0) nArrowHei=nLength/2; CRect rcRet(0,0,m_rcWindow.Width(),nArrowHei); if(uSBCode==SB_LINEUP) goto end; rcRet.top=rcRet.bottom; if((m_si.nMax-m_si.nMin-m_si.nPage+1)==0) rcRet.bottom+=nEmptyHei/2; else rcRet.bottom+=nEmptyHei*nTrackPos/(m_si.nMax-m_si.nMin-m_si.nPage+1); if(uSBCode==SB_PAGEUP) goto end; rcRet.top=rcRet.bottom; rcRet.bottom+=nSlideHei; if(uSBCode==SB_THUMBTRACK) goto end; rcRet.top=rcRet.bottom; rcRet.bottom=nLength-nArrowHei; if(uSBCode==SB_PAGEDOWN) goto end; rcRet.top=rcRet.bottom; rcRet.bottom=nLength; if(uSBCode==SB_LINEDOWN) goto end; end: if(!IsVertical()) { rcRet.left=rcRet.top; rcRet.right=rcRet.bottom; rcRet.top=0; rcRet.bottom=m_rcWindow.Height(); } rcRet.OffsetRect(m_rcWindow.TopLeft()); return rcRet; }
CRect CLayerStateWnd::GetItemRect(int nIndex) { CRect rcRet(0, 0, 0, 0); if(m_nItemPerLine == 0) return rcRet; int nLine = nIndex / m_nItemPerLine; int nCol = nIndex % m_nItemPerLine; rcRet.left = m_rcWork.left + (m_sizeItem.cx + m_nHDivider) * nCol; rcRet.right = rcRet.left + (m_sizeItem.cx + m_nHDivider); rcRet.top = m_rcWork.top + (m_sizeItem.cy + m_nVDivider) * nLine; rcRet.bottom = rcRet.top + (m_sizeItem.cy + m_nVDivider); return rcRet; };
QRect StyleHelper::drawText(QPainter* p, const QRect& rc, QString& str, int nLines, int nFlags, const QColor& color, const QFont& font, bool bElided) { if (str.isEmpty()) { qDebug() << "[WARNING]: the text should not be empty when drawing!"; return QRect(); } QFontMetrics fm(font); if (rc.height() < (fm.height() + fm.leading()) * nLines) { qDebug() << "[WARNING]: space is not enough for drawing! text: " << str.left(30) << "..."; } //if (rc.width() * nLines < fm.width(str)) { // qDebug() << "[WARNING]: width should bigger than font metrics when drawing! text:" << str.left(30) << "..."; //} p->save(); p->setPen(color); p->setFont(font); int nWidth = 0; int nHeight = 0; int nHeightLine = p->fontMetrics().height() + leading(); QRect rcRet(rc.x(), rc.y(), rc.width(), nHeightLine); rcRet.adjust(margin(), 0, -margin(), 0); QTextLayout textLayout(str, p->font()); QTextOption opt = textLayout.textOption(); opt.setWrapMode(QTextOption::WrapAnywhere); textLayout.setTextOption(opt); textLayout.beginLayout(); while (nLines) { QTextLine line = textLayout.createLine(); if (!line.isValid()) { break; } line.setLineWidth(rcRet.width()); QString lineText; if (nLines == 1 && bElided) { // the last line lineText = p->fontMetrics().elidedText(str, Qt::ElideRight, rcRet.width()); nWidth = qMax<int>(p->fontMetrics().width(lineText), nWidth); } else { lineText = str.left(line.textLength()); nWidth = qMax<int>(line.width(), nWidth); } str.remove(0, line.textLength()); p->drawText(rcRet, nFlags, lineText); nHeight += nHeightLine; rcRet.setRect(rc.x(), rc.y() + nHeight, nWidth, nHeightLine); rcRet.adjust(margin(), 0, -margin(), 0); nLines--; } textLayout.endLayout(); rcRet.setRect(rc.x() + margin(), rc.y(), nWidth + margin(), nHeight); //rcRet.adjust(margin(), 0, -margin(), 0); p->restore(); return rcRet; }