void PropertyPanel::setTitleFont() { QFont titleFont = font(); titleFont.setPointSizeFloat( titleFont.pointSizeFloat()*1.5f ); moduleNameLabel->setFont( titleFont ); titleFont = font(); titleFont.setPointSizeFloat( titleFont.pointSizeFloat()*1.15f ); selectedLabel->setFont( titleFont ); }
/** * Update the count of unread messages. If there are unread messages, * overlay the count on top of a transparent version of the KMail icon. * If there is no unread mail, restore the normal KMail icon. */ void KMSystemTray::updateCount() { if(mCount != 0) { int oldPixmapWidth = pixmap()->size().width(); int oldPixmapHeight = pixmap()->size().height(); QString countString = QString::number( mCount ); QFont countFont = KGlobalSettings::generalFont(); countFont.setBold(true); // decrease the size of the font for the number of unread messages if the // number doesn't fit into the available space float countFontSize = countFont.pointSizeFloat(); QFontMetrics qfm( countFont ); int width = qfm.width( countString ); if( width > oldPixmapWidth ) { countFontSize *= float( oldPixmapWidth ) / float( width ); countFont.setPointSizeFloat( countFontSize ); } // Create an image which represents the number of unread messages // and which has a transparent background. // Unfortunately this required the following twisted code because for some // reason text that is drawn on a transparent pixmap is invisible // (apparently the alpha channel isn't changed when the text is drawn). // Therefore I have to draw the text on a solid background and then remove // the background by making it transparent with QPixmap::setMask. This // involves the slow createHeuristicMask() function (from the API docs: // "This function is slow because it involves transformation to a QImage, // non-trivial computations and a transformation back to a QBitmap."). Then // I have to convert the resulting QPixmap to a QImage in order to overlay // the light KMail icon with the number (because KIconEffect::overlay only // works with QImage). Finally the resulting QImage has to be converted // back to a QPixmap. // That's a lot of work for overlaying the KMail icon with the number of // unread messages, but every other approach I tried failed miserably. // IK, 2003-09-22 QPixmap numberPixmap( oldPixmapWidth, oldPixmapHeight ); numberPixmap.fill( Qt::white ); QPainter p( &numberPixmap ); p.setFont( countFont ); p.setPen( Qt::blue ); p.drawText( numberPixmap.rect(), Qt::AlignCenter, countString ); numberPixmap.setMask( numberPixmap.createHeuristicMask() ); QImage numberImage = numberPixmap.convertToImage(); // Overlay the light KMail icon with the number image QImage iconWithNumberImage = mLightIconImage.copy(); KIconEffect::overlay( iconWithNumberImage, numberImage ); QPixmap iconWithNumber; iconWithNumber.convertFromImage( iconWithNumberImage ); setPixmap( iconWithNumber ); } else { setPixmap( mDefaultIcon ); } }
// ------------------------------------------------------------- // Returns width of text (and height if pointer is not null). int ViewPainter::drawTextMapped(const QString& Text, int x1, int y1, int *Height) { QRect r; int y = 0; int x = 0; int h = 0; int w = 0; int i = 0; while (!Text[i].isNull()) { if ((Text[i].latin1() == '_' || Text[i].latin1() == '^') && !Text[i+1].isNull()) { bool is_sub = Text[i++].latin1() == '_'; int len = 0; if (Text[i] == '{') { i++; while (!Text[i+len].isNull() && Text[i+len].latin1() != '}') len++; } #ifdef __MINGW32__ float scale = 1.0; #else float scale = PrintScale; #endif QFont fbak = Painter->font(); QFont f = Painter->font(); f.setPointSizeFloat(f.pointSizeFloat()*0.8); Painter->setFont(f); Painter->drawText(x1+x, y1+y + (is_sub ? +0.6 : -0.3) * fbak.pointSizeFloat() * scale, 0, 0, Qt::DontClip, Text.mid(i, len ? len : 1), -1, &r); Painter->setFont(fbak); x += r.width(); if (x > w) w = x; i += len ? len + 1 : 1; } else { int len = 0; while (!Text[i+len].isNull() && Text[i+len].latin1() != '_' && Text[i+len].latin1() != '^' && Text[i+len].latin1() != '\n') len++; Painter->drawText(x1+x, y1+y, 0, 0, Qt::DontClip, Text.mid(i, len), -1, &r); if (h < r.height()) { h = r.height(); } x += r.width(); if (x > w) w = x; if (Text[i+len].latin1() == '\n') { y += h; x = 0; i++; } i += len; } } if(Height) *Height = y+h; return w; }
/** Draws the label */ int MLabelObject::draw(FLStylePainter *p) { // Draw the pixmap if (!paintFunction.isEmpty()) { FLDomNodeInterface *dni = 0; QSArgumentList l; l << QVariant(text); if (!domNodeData.isNull()) { dni = new FLDomNodeInterface(domNodeData); l << dni; } QSArgument v = aqApp->call(paintFunction, l, 0); QSArgument::Type tp = v.type(); if (tp != QSArgument::Invalid) { QPixmap pix; if (tp == QSArgument::VoidPointer) { QPixmap *vPix = static_cast<QPixmap *>(v.ptr()); if (vPix) pix = *vPix; } else if (tp == QSArgument::Variant) pix = v.variant().toPixmap(); if (!pix.isNull() && drawPixmap(p, &pix)) return (changeHeight ? height : 0); } } if (pixmap && pixmap->isNull()) { delete pixmap; pixmap = 0; } else if (pixmap && drawPixmap(p, pixmap)) return (changeHeight ? height : 0); if (text.isEmpty()) { drawBase(p); return 0; } #if defined(Q_OS_MACX) FLStylePainter *pt = new FLStylePainter; int retVal = 0; uint originalHeight = height; QFont fnt; int tf; // Horizontal switch (hAlignment) { case MLabelObject::Left: tf = QPainter::AlignLeft; break; case MLabelObject::Center: tf = QPainter::AlignHCenter; break; case MLabelObject::Right: tf = QPainter::AlignRight; } // Vertical switch (vAlignment) { case MLabelObject::Top: tf = tf | QPainter::AlignTop; break; case MLabelObject::Bottom: tf = tf | QPainter::AlignBottom; break; case MLabelObject::Middle: tf = tf | QPainter::AlignVCenter; } // Word wrap if (wordWrap) tf = tf | QPainter::WordBreak; int nw = width * 4; int nh = height * 4; QPixmap pm(nw, nh); pm.fill(backgroundColor); pt->painter()->begin(&pm); fnt.setFamily(fontFamily); fnt.setPointSizeFloat(fontSize * 4); fnt.setWeight(fontWeight); fnt.setItalic(fontItalic); pt->painter()->setFont(fnt); if (changeHeight) { QRect maxRect(p->painter()->boundingRect(0, 0, nw, nh, tf, text)); if (maxRect.height() > height) { height = maxRect.height(); retVal = height; } } drawBase(pt); pt->painter()->setPen(foregroundColor); if (!transparent) { pt->painter()->setBackgroundColor(backgroundColor); pt->painter()->setBackgroundMode(Qt::OpaqueMode); } if (adjustFontSize && !wordWrap && !changeHeight) { float factor = (float)nw / (float)p->painter()->fontMetrics().width(text); if (factor < 1.0) { QFont f = p->painter()->font(); f.setPointSizeFloat(f.pointSizeFloat() * factor); p->painter()->setFont(f); } } pt->painter()->drawText(0, 0, nw, nh, tf, text); pt->painter()->end(); delete pt; drawPixmap(p, &pm); height = originalHeight; return retVal; #else int retVal = 0; uint originalHeight = height; QFont fnt; int tf; Qt::BGMode oldBgMode; QColor oldBgColor; bool restoreBg = false; // Horizontal switch (hAlignment) { case MLabelObject::Left: tf = QPainter::AlignLeft; break; case MLabelObject::Center: tf = QPainter::AlignHCenter; break; case MLabelObject::Right: tf = QPainter::AlignRight; } // Vertical switch (vAlignment) { case MLabelObject::Top: tf = tf | QPainter::AlignTop; break; case MLabelObject::Bottom: tf = tf | QPainter::AlignBottom; break; case MLabelObject::Middle: tf = tf | QPainter::AlignVCenter; } // Word wrap if (wordWrap) tf = tf | QPainter::WordBreak; fnt.setFamily(fontFamily); fnt.setPointSizeFloat(fontSize); fnt.setWeight(fontWeight); fnt.setItalic(fontItalic); p->painter()->setFont(fnt); if (changeHeight) { QRect maxRect(p->painter()->boundingRect(0, 0, width, height, tf, text)); if (maxRect.height() > height) { height = maxRect.height(); retVal = height; } } drawBase(p); p->painter()->setPen(foregroundColor); if (!transparent) { restoreBg = true; oldBgMode = p->painter()->backgroundMode(); oldBgColor = p->painter()->backgroundColor(); p->painter()->setBackgroundColor(backgroundColor); p->painter()->setBackgroundMode(Qt::OpaqueMode); } if (!p->drawText(text, tf, this)) { bool restore = false; if (p->errCode() == FLStylePainter::IdNotFound) { p->painter()->save(QObject::name()); p->applyTransforms(); p->painter()->translate(xpos, ypos); restore = true; } if (adjustFontSize && !wordWrap && !changeHeight) { float factor = (float)width / (float)p->painter()->fontMetrics().width(text); if (factor < 1.0) { QFont f = p->painter()->font(); f.setPointSizeFloat(f.pointSizeFloat() * factor); p->painter()->setFont(f); } } p->painter()->drawText(0, 0, width, height, tf, text); if (restore) p->painter()->restore(); } if (restoreBg) { p->painter()->setBackgroundMode(oldBgMode); p->painter()->setBackgroundColor(oldBgColor); } height = originalHeight; return retVal; #endif }
toTreeWidgetItem *toListView::printPage(TOPrinter *printer, QPainter *painter, toTreeWidgetItem *top, int &column, int &level, int pageNo, bool paint) { Q3PaintDeviceMetrics wmetr(this); Q3PaintDeviceMetrics metrics(printer); double wpscalex = (double(metrics.width()) * wmetr.widthMM() / metrics.widthMM() / wmetr.width()); double wpscaley = (double(metrics.height()) * wmetr.heightMM() / metrics.heightMM() / wmetr.height()); painter->save(); QFont font = painter->font(); font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley)); painter->setFont(font); painter->scale(wpscalex, wpscaley); double mwidth = metrics.width() / wpscalex; double mheight = metrics.height() / wpscaley; double x = 0; if (paint) { QString numPage(tr("Page: %1").arg(pageNo)); painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex), header()->height(), Qt::SingleLine | Qt::AlignRight | Qt::AlignVCenter, numPage); painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex), header()->height(), Qt::SingleLine | Qt::AlignHCenter | Qt::AlignVCenter, middleString()); painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex), header()->height(), Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter, sqlName()); painter->drawLine(0, header()->height() - 1, int(mwidth), header()->height() - 1); } font = toListView::font(); font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley)); painter->setFont(font); for (int i = column; i < columns(); i++) { double width = columnWidth(i); if (width + x >= mwidth) { if (i == column) width = mwidth - x - 1; else break; } if (paint) painter->drawText(int(x), 0, int(width), header()->height(), Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter, header()->label(i)); x += width; } if (paint) painter->translate(0, header()->height()); double y = (header()->height() + 1) + header()->height(); int curLevel = level; int tree = rootIsDecorated() ? treeStepSize() : 0; int newCol = -1; toTreeWidgetItem *item = top; while (item && (y < mheight || item == top)) { if (column == 0) x = curLevel; else x = 0; painter->translate(x, 0); for (int i = column; i < columns(); i++) { double width = columnWidth(i); if (width + x >= mwidth) { if (i == column) width = mwidth - x - 1; else { newCol = i; break; } } if (i == 0) width -= curLevel; if (paint) { item->setSelected(false); item->paintCell(painter, qApp->palette().active(), i, int(width), columnAlignment(i)); painter->translate(width, 0); } x += width; } if (paint) painter->translate(-x, item->height()); y += item->height(); if (item->firstChild()) { item = item->firstChild(); curLevel += tree; } else if (item->nextSibling()) item = item->nextSibling(); else { do { item = item->parent(); curLevel -= tree; } while (item && !item->nextSibling()); if (item) item = item->nextSibling(); } } if (paint) painter->drawLine(0, 0, int(mwidth), 0); painter->restore(); if (newCol >= 0) { column = newCol; return top; } column = 0; level = curLevel; return item; }