/** * Draws the left adornment to the graphics context aGc, in the rectangle aRect. The menu pane * flags determines the type of adornment to be drawn. */ EXPORT_C void LafMenuPane::DrawLeftAdornment(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuPane*/, CWindowGc& aGc, const TRect& aRect, const TItemAttributes& aItemAttributes) { // Brush the background of the rect. aGc.SetPenStyle(CGraphicsContext::ENullPen); aGc.DrawRect(aRect); aGc.SetPenStyle(CGraphicsContext::ESolidPen); const TInt itemFlags = aItemAttributes.iFlags; if (itemFlags&EEikMenuItemSymbolOn) { if (itemFlags&EEikMenuItemCheckBox) { TRect rect = aRect; rect.iTl.iY += aItemAttributes.iBaseLine; TBuf<1> buf; buf.Append(TChar(ESymFontTick)); aGc.UseFont(SymbolFont(aLafEnv)); aGc.SetPenStyle(CGraphicsContext::ESolidPen); // as the tick is big, ignore KPreLeftAdornment and steal 1 pixels from left. aGc.DrawText(buf,TPoint(rect.iTl.iX-1, rect.iTl.iY)); aGc.UseFont(NormalFont(aLafEnv)); } else if (itemFlags&KLafMenuItemRadio) { TUid bmpUid(TUid::Uid(KLafUidEikonOptiVal)); const CFbsBitmap* bitmap = aLafEnv.Bitmap(bmpUid); TSize bitsize = bitmap->SizeInPixels(); TRect butRect(TPoint(0,0), TPoint(bitsize.iWidth,bitsize.iHeight)); TInt yoffset = (aRect.Size().iHeight - bitsize.iHeight) / 2; TInt xoffset = KLafPreLeftAdornmentSpace; TPoint offset(xoffset,yoffset); if (aItemAttributes.iHighlightType == SLafMenuPane::EDrawHighlight) { bmpUid=TUid::Uid(KLafUidEikonOptihVal); bitmap = aLafEnv.Bitmap(bmpUid); } bmpUid=TUid::Uid(KLafUidEikonOptimVal); const CFbsBitmap* mask = aLafEnv.Bitmap(bmpUid); aGc.BitBltMasked((aRect.iTl+offset), bitmap, butRect, mask,ETrue); } } }
/** * Draws the cascade symbol into the graphics context aGc, in the rectangle aRect and sets * the pen color depending on whether the menu item is dimmed or focused. */ EXPORT_C void LafMenuPane::DrawRightAdornment(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuPane*/, CWindowGc& aGc, const TRect& aRect, const TItemAttributes& aItemAttributes) { const TInt cascadeSize=Min(KLafRightAdornmentSpace,aItemAttributes.iHeight); // Brush the background of the rect. aGc.SetPenStyle(CGraphicsContext::ENullPen); aGc.DrawRect(aRect); aGc.SetPenStyle(CGraphicsContext::ESolidPen); if (aItemAttributes.iInternalFlags&EMenuIsRightAdornment) { //Sort out rect for cascade symbol TRect cascadeRect=TRect(TPoint(aRect.iBr.iX-cascadeSize-PostRightAdornmentSpace(),aItemAttributes.iHPosition), TSize(cascadeSize,aItemAttributes.iHeight)); cascadeRect.iTl.iY+=((aItemAttributes.iHeight-cascadeSize)/2); cascadeRect.iBr.iY-=((aItemAttributes.iHeight-cascadeSize)/2); TBuf<1> cascade; cascade.Append(TChar(ESymFontMenuCascade)); aGc.UseFont(SymbolFont(aLafEnv)); aGc.DrawText(cascade,cascadeRect,cascadeRect.Height(),CGraphicsContext::ERight); aGc.UseFont(NormalFont(aLafEnv)); } }
void KstLabel::draw(QPainter &p, int px, int py, bool bJustify, bool doDraw) { int w; int h; int s; unsigned i; double dRotationRadians = 3.1415926535897932333796 * Rotation / 180.0; double x; double y; double y_upper; double y_lower; double x0; int i_g; bool is_greek; bool bTerminate = false; unsigned uiLength; QChar C; QRect rect; QRegion rgn; QString str; QString strOut; QString subProcessedText; QString processedText; QFont TextFont(FontName, fontSize(p), QFont::Normal, false); QFont SymbolFont(SymbolFontName, fontSize(p), QFont::Normal, false); int i_fp = 0; FPType fP[MAX_DEPTH_SUB_SUPER]; static const GreekCharType GC[] = {{"\\Alpha", "A"}, {"\\alpha", "a"}, {"\\Beta", "B"}, {"\\beta", "b"}, {"\\Chi", "C"}, {"\\chi", "c"}, {"\\Delta", "D"}, {"\\delta", "d"}, {"\\Epsilon", "E"}, {"\\epsilon", "e"}, {"\\Phi", "F"}, {"\\phi", "f"}, {"\\Gamma", "G"}, {"\\gamma", "g"}, {"\\Eta", "H"}, {"\\eta", "h"}, {"\\Iota", "I"}, {"\\iota", "i"}, {"\\Kappa", "K"}, {"\\kappa", "k"}, {"\\Lambda", "L"}, {"\\lambda", "l"}, {"\\Mu", "M"}, {"\\mu", "m"}, {"\\Nu", "N"}, {"\\nu", "n"}, {"\\Pi", "P"}, {"\\pi", "p"}, {"\\Theta", "Q"}, {"\\theta", "q"}, {"\\Rho", "R"}, {"\\rho", "r"}, {"\\Sigma", "S"}, {"\\sigma", "s"}, {"\\Tau", "T"}, {"\\tau", "t"}, {"\\Omega", "W"}, {"\\omega", "w"}, {"\\Psi", "Y"}, {"\\psi", "y"}, {"\\Zeta", "Z"}, {"\\zeta", "z"}, {"\\sum", "�"}, {"\\int", "�"} }; static const int N_GREEK = sizeof( GC ) / sizeof( GreekCharType ); p.save(); p.setFont(TextFont); p.translate(px, py); p.rotate(Rotation); p.setClipping(false); if(doDraw) { w = width(p); h = ascent(p); } else { w = h = 0; } fP[0].locked = true; fP[0].dy = 0; fP[0].size = 0; fP[0].x = 0; x = y = 0; if(bJustify) { switch (Justify) { case CxBy: x = -w/2; break; case CxTy: x = -w/2; y = h; break; case CxCy: x = -w/2; y = h/2; break; case LxBy: break; case LxTy: y = h; break; case LxCy: y = h/2; break; case RxBy: x = -w; break; case RxTy: x = -w; y = h; break; case RxCy: x = -w; y = h/2; break; default: KstDebug::self()->log(i18n("Undefined justification %1 in label \"%2\".").arg(Justify).arg(Text), KstDebug::Debug); break; } } y_upper = y; y_lower = y; x0 = x; processedText = Text; if (doScalarReplacement) { ScalarsUsed.clear(); KST::scalarList.lock().readLock(); for (KstScalarList::iterator it = KST::scalarList.begin(); it != KST::scalarList.end(); ++it) { if (processedText.contains((*it)->tagLabel())) { ScalarsUsed.append(*it); processedText.replace((*it)->tagLabel(), (*it)->label()); } } KST::scalarList.lock().readUnlock(); } uiLength = processedText.length(); for (i = 0; i < uiLength; i++) { C = processedText[i]; if( _interpret && (C == '^' || C == '_' || C == '{' || C == '}' || C == '\\') ) { if( !strOut.isEmpty() ) { p.setFont( TextFont ); if( doDraw ) { p.drawText(int(x),int(y + fP[i_fp].dy), strOut); } x += p.fontMetrics().width(strOut); if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) { y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent(); } if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) { y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent(); } strOut = QString::null; } if (C == '^') { // Superscript if (i_fp+1 < MAX_DEPTH_SUB_SUPER) { i_fp++; bTerminate = false; fP[i_fp].locked = false; fP[i_fp].size = fP[i_fp-1].size - 1; fP[i_fp].dy = fP[i_fp-1].dy - p.fontMetrics().ascent()*0.4; fP[i_fp].x = x; if (p.fontMetrics().rightBearing(C) < 0) { x -= 2.0 * p.fontMetrics().rightBearing(C); } s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size))); if (s < 5) { s = 5; // no smaller than 5pt font! } TextFont.setPointSize(s); } } else if (processedText[i] == '_') { // Subscript if (i_fp+1 < MAX_DEPTH_SUB_SUPER) { i_fp++; bTerminate = false; fP[i_fp].locked = false; fP[i_fp].size = fP[i_fp-1].size-1; fP[i_fp].dy = fP[i_fp-1].dy + p.fontMetrics().height()*0.2; fP[i_fp].x = x; s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size))); if (s < 5) { s = 5; // no smaller than 5pt font! } TextFont.setPointSize(s); } } else if (processedText[i] == '{') { fP[i_fp].locked = true; } else if (processedText[i] == '}') { if (i_fp > 0) { if (processedText[i+1] == '_' || processedText[i+1] == '^') { x = fP[i_fp].x; } i_fp--; } } else if( processedText[i] == '\\' ) { is_greek = false; subProcessedText = processedText.mid(i); for (i_g = 0; i_g < N_GREEK; i_g++) { if (subProcessedText.startsWith(GC[i_g].label)) { is_greek = true; str = GC[i_g].c; i += GC[i_g].label.length()-1; if (processedText[i+1] == ' ') { i++; } break; } } if (is_greek) { s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size))); if (s < 5) { s = 5; // no smaller than 5pt font! } SymbolFont.setPointSize(s); p.setFont(SymbolFont); bTerminate = true; if( doDraw ) { p.drawText(int(x),int(y + fP[i_fp].dy), str); } x += p.fontMetrics().width(str); if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) { y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent(); } if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) { y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent(); } } else { if (processedText.find( "it", i+1, FALSE ) == (int)i+1 ) { TextFont.setItalic(true); i += 2; if (processedText.at(i+1) == ' ') { i++; } } else if (processedText.find( "rm", i+1, FALSE ) == (int)i+1 ) { TextFont.setItalic(false); i += 2; if (processedText.at(i+1) == ' ') { i++; } } else { i++; bTerminate = true; strOut += processedText.at( i ); } } } } else { bTerminate = true; strOut += processedText[i]; } // // do we need to terminate a superscript or subscript? // if (_interpret && i_fp > 0 && fP[i_fp].locked == false && bTerminate ) { if( !strOut.isEmpty( ) ) { p.setFont( TextFont ); if( doDraw ) { p.drawText(int(x),int(y + fP[i_fp].dy), strOut); } x += p.fontMetrics().width(strOut); if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) { y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent(); } if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) { y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent(); } strOut = QString::null; } if (processedText.at(i+1) == '_' || processedText.at(i+1) == '^') { x = fP[i_fp].x; } i_fp--; s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size))); if (s < 5) { s = 5; // no smaller than 5pt font! } TextFont.setPointSize(s); } } if( !strOut.isEmpty( ) ) { p.setFont( TextFont ); if( doDraw ) { p.drawText(int(x),int(y + fP[i_fp].dy), strOut); } x += p.fontMetrics().width(strOut); if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) { y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent(); } if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) { y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent(); } } p.restore(); Width = x - x0; rect.setRect((int)(px + x0), (int)(py + y_upper), (int)Width, (int)(y_lower - y_upper + 1)); rect.normalize( ); v_offset = (int)(y - y_upper); if( Rotation == 0.0 ) { QRegion rgn( rect ); extents = rgn; } else { QPointArray points( 5 ); int ixBase = 0; int iyBase = 0; int ixOld = 0; int iyOld = 0; int ix; int iy; switch( Justify ){ case CxBy: ixBase = rect.left() + rect.width()/2; iyBase = rect.bottom(); break; case CxTy: ixBase = rect.left() + rect.width()/2; iyBase = rect.top(); break; case CxCy: ixBase = rect.left() + rect.width()/2; iyBase = rect.top() + rect.height()/2; break; case LxBy: ixBase = rect.left(); iyBase = rect.bottom(); break; case LxTy: ixBase = rect.left(); iyBase = rect.top(); break; case LxCy: ixBase = rect.left(); iyBase = rect.top() + rect.height()/2; break; case RxBy: ixBase = rect.right(); iyBase = rect.bottom(); break; case RxTy: ixBase = rect.right(); iyBase = rect.top(); break; case RxCy: ixBase = rect.right(); iyBase = rect.top() + rect.height()/2; break; default: ixBase = rect.left(); iyBase = rect.bottom(); break; } for( i=0; i<5; i++ ) { switch( i ) { case 0: case 4: ixOld = rect.left(); iyOld = rect.top(); break; case 1: ixOld = rect.right(); iyOld = rect.top(); break; case 2: ixOld = rect.right(); iyOld = rect.bottom(); break; case 3: ixOld = rect.left(); iyOld = rect.bottom(); break; } ix = ixBase + (int)((double)( ixOld - ixBase )*cos( -dRotationRadians ) + (double)( iyOld - iyBase)*sin( -dRotationRadians )); iy = iyBase + (int)((double)( ixOld - ixBase )*sin( dRotationRadians ) + (double)( iyOld - iyBase)*cos( -dRotationRadians )); points.setPoint( i, ix, iy ); } QRegion rgn( points ); extents = rgn; } }