static void PaintBars(toTreeWidgetItem *item, QPainter *p, const QColorGroup & cg, int width, std::list<double> &val, std::list<double> &maxExt, std::list<double> &curExt) { #if 0 // disabled, wrong override if ( val.empty() ) { p->fillRect(0, 0, width, item->height(), QBrush(item->isSelected() ? cg.highlight() : cg.base())); } else { int num = 0; int lastHeight = 0; std::list<double>::iterator j = curExt.begin(); std::list<double>::iterator k = maxExt.begin(); for (std::list<double>::iterator i = val.begin(); i != val.end() && j != curExt.end() && k != maxExt.end(); i++, j++, k++) { num++; QBrush bg(item->isSelected() ? cg.highlight() : cg.base()); QBrush fg(num % 2 ? Qt::blue : Qt::red); double start = (*i); double end = (*j); if (BarsAlignLeft) { end -= start; start = 0; if (end < 0) end += (*k); } int height = item->height() * num / val.size(); int pos = int(start * width / (*k)); int posEnd = int(end * width / (*k)); if (start > end) { p->fillRect(0, lastHeight, posEnd, height, fg); p->fillRect(posEnd, lastHeight, pos, height, bg); p->fillRect(pos, lastHeight, width, height, fg); } else { p->fillRect(0, lastHeight, pos, height, bg); p->fillRect(pos, lastHeight, posEnd, height, fg); p->fillRect(posEnd, lastHeight, width, height, bg); } lastHeight = height; } } #endif }
void FancyItem::paintCell(QPainter *p, const QColorGroup &cg, int c, int w, int) { int h = height(); QFontMetrics fm(p->font()); if(isSelected()) p->fillRect(0, 0, w, h-1, cg.highlight()); else p->fillRect(0, 0, w, h, cg.base()); int x = 0; const QPixmap *pix = pixmap(c); if(pix) { p->drawPixmap(4, (h - pix->height()) / 2, *pix); x += pix->width(); } else x += 16; x += 8; int y = ((h - fm.height()) / 2) + fm.ascent(); p->setPen(isSelected() ? cg.highlightedText() : cg.text()); p->drawText(x, y, text(c)); p->setPen(QPen(QColor(0xE0, 0xE0, 0xE0), 0, Qt::DotLine)); p->drawLine(0, h-1, w-1, h-1); }
void TeQtBigTable::paintCell(QPainter *painter, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg) { QRect rect(0, 0, cr.width(), cr.height()); if (selected) { painter->fillRect(rect, cg.highlight()); painter->setPen(cg.highlightedText()); } else { painter->fillRect(rect, cg.base()); painter->setPen(cg.text()); } QTable::paintCell(painter, row, col, cr, selected, cg); QVariant v(dataSource_->cell(row, col)); if (v.type() == QVariant::Pixmap) { QPixmap p = v.toPixmap(); painter->drawPixmap(0, 0, p); } else if (v.type() == QVariant::String || v.type() == QVariant::CString) { QString qs = v.toString(); bool ok; qs.toDouble(&ok); if (ok) painter->drawText(0, 0, cr.width()-10, cr.height(), Qt::AlignRight | Qt::SingleLine, v.toString()); else painter->drawText(0, 0, cr.width()-10, cr.height(), Qt::AlignLeft | Qt::SingleLine, v.toString()); } }
virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) { #if 0 // disabled - not overriding correct method if (column == 2) { toProfilerUnits *units = dynamic_cast<toProfilerUnits *>(listView()); if (!units) { toTreeWidgetItem::paintCell(p, cg, column, width, alignment); return ; } double total = allText(column).toDouble(); QString timstr = FormatTime(total / 1E9); double val = total / units->total(); p->fillRect(0, 0, int(val*width), height(), QBrush(Qt::blue)); p->fillRect(int(val*width), 0, width, height(), QBrush(isSelected() ? cg.highlight() : cg.base())); QPen pen(isSelected() ? cg.highlightedText() : cg.foreground()); p->setPen(pen); p->drawText(0, 0, width, height(), Qt::AlignRight, timstr); } else { toTreeWidgetItem::paintCell(p, cg, column, width, alignment); } #endif }
void ListListViewItem::paintCell(QPainter *p,const QColorGroup &cg,int column, int width,int align) { if(column!=list_track_column) { Q3ListViewItem::paintCell(p,cg,column,width,align); return; } QColor fg=cg.text(); QColor bg=cg.base(); if(isSelected()) { fg=cg.highlightedText(); bg=cg.highlight(); } QString str=QString().sprintf("%u / %u",list_tracks,list_total_tracks); QPixmap *icon=list_whiteball_map; if(list_total_tracks>0) { if(list_tracks==list_total_tracks) { icon=list_greenball_map; } else { icon=list_redball_map; } } QFontMetrics *m=new QFontMetrics(p->font()); p->setBackgroundColor(bg); p->eraseRect(0,0,width,height()); p->setPen(fg); p->drawPixmap(list_parent->itemMargin(),(height()-icon->size().height())/2, *icon); p->drawText(icon->size().width()+10,3*(height()-m->height())/2,str); delete m; }
void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) { KstMatrixList matrices = KST::matrixList; KstMatrixPtr matrix = *matrices.findTag(_strMatrix); QString str; double value; painter->eraseRect( 0, 0, cr.width(), cr.height() ); if (selected) { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() ); painter->setPen(cg.highlightedText()); } else { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() ); painter->setPen(cg.text()); } if (matrix) { bool ok; value = matrix->valueRaw(col, row, &ok); if (ok) { str.setNum(value, 'g', 16); } } painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str); }
void KWTextImage::drawCustomItem( QPainter* p, int x, int y, int wpix, int hpix, int /*ascentpix*/, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected, int /*offset*/, bool drawingShadow) { if ( drawingShadow ) return; // (x,y) is the position of the inline item (in pixels) // (wpix,hpix) is the size of the inline item (in pixels) // (cx,cy,cw,ch) is the rectangle to be painted, in pixels too if ( m_image.isNull() ) { kdDebug() << "KWTextImage::draw null image!" << endl; p->fillRect( x, y, 50, 50, cg.dark() ); return; } QSize imgSize( wpix, hpix ); QRect rect( QPoint(x, y), imgSize ); if ( !rect.intersects( QRect( cx, cy, cw, ch ) ) ) return; QPixmap pixmap=m_image.generatePixmap( imgSize, true ); //if ( placement() == PlaceInline ) p->drawPixmap( x, y, pixmap ); //else // p->drawPixmap( cx, cy, pixmap, cx - x, cy - y, cw, ch ); if ( selected && placement() == PlaceInline && p->device()->devType() != QInternal::Printer ) { p->fillRect( rect , QBrush( cg.highlight(), QBrush::Dense4Pattern) ); } }
void UserViewItemBase::paintCell(QPainter *p, const QColorGroup &cg, int, int width, int) { UserListBase *view = static_cast<UserListBase*>(listView()); width = view->width() - 4; QScrollBar *vBar = view->verticalScrollBar(); if (vBar->isVisible()) width -= vBar->width(); if (width < 1) width = 1; QPixmap bg(width, height()); QPainter pp(&bg); int margin = 0; if (isSelected() && view->hasFocus() && CorePlugin::m_plugin->getUseDblClick()){ pp.fillRect(QRect(0, 0, width, height()), cg.highlight()); pp.setPen(cg.highlightedText()); }else{ pp.fillRect(QRect(0, 0, width, height()), cg.base()); PaintView pv; pv.p = &pp; pv.pos = view->viewport()->mapToParent(view->itemRect(this).topLeft()); pv.size = QSize(width, height()); pv.win = view; pv.isStatic = false; pv.height = height(); pv.margin = 0; if (CorePlugin::m_plugin->getUseSysColors()){ pp.setPen(cg.text()); }else{ pp.setPen(QColor(CorePlugin::m_plugin->getColorOnline())); } Event e(EventPaintView, &pv); e.process(); view->setStaticBackground(pv.isStatic); margin = pv.margin; } view->drawItem(this, &pp, cg, width, margin); pp.end(); if (view->m_pressedItem == this){ p->drawPixmap(QPoint(1, 1), bg); if (CorePlugin::m_plugin->getUseSysColors()){ p->setPen(cg.text()); }else{ p->setPen(QColor(CorePlugin::m_plugin->getColorOnline())); } p->moveTo(0, 0); p->lineTo(width - 1, 0); p->lineTo(width - 1, height() - 1); p->lineTo(0, height() - 1); p->lineTo(0, 0); p->setPen(cg.shadow()); p->moveTo(width - 2, 1); p->lineTo(1, 1); p->lineTo(1, height() - 2); }else{ p->drawPixmap(QPoint(0, 0), bg); } }
HTMLColors() { map["black"] = "#000000"; map["green"] = "#008000"; map["silver"] = "#c0c0c0"; map["lime"] = "#00ff00"; map["gray"] = "#808080"; map["olive"] = "#808000"; map["white"] = "#ffffff"; map["yellow"] = "#ffff00"; map["maroon"] = "#800000"; map["navy"] = "#000080"; map["red"] = "#ff0000"; map["blue"] = "#0000ff"; map["purple"] = "#800080"; map["teal"] = "#008080"; map["fuchsia"] = "#ff00ff"; map["aqua"] = "#00ffff"; map["crimson"] = "#dc143c"; map["indigo"] = "#4b0082"; #ifdef __BEOS__ printf( "Warning: HTMLColors::HTMLColors() not initiating all colors\n" ); #else // ### react to style changes // see http://www.richinstyle.com for details QColorGroup cg = kapp->palette().active(); map["activeborder"] = cg.light(); // bordercolor of an active window map["activecaption"] = cg.text(); // caption color of an active window map["appworkspace"] = cg.background(); // background color of an MDI interface map["highlight"] = cg.highlight(); map["highlighttext"] = cg.highlightedText(); cg = kapp->palette().inactive(); map["background"] = cg.background(); // desktop background color map["buttonface"] = cg.button(); // Button background color map["buttonhighlight"] = cg.light(); map["buttonshadow"] = cg.shadow(); map["buttontext"] = cg.buttonText(); map["captiontext"] = cg.text(); map["infobackground"] = QToolTip::palette().inactive().background(); map["menu"] = cg.background(); map["menutext"] = cg.foreground(); map["scrollbar"] = cg.background(); map["threeddarkshadow"] = cg.dark(); map["threedface"] = cg.button(); map["threedhighlight"] = cg.light(); map["threedlightshadow"] = cg.midlight(); map["window"] = cg.background(); map["windowframe"] = cg.background(); map["text"] = cg.text(); cg = kapp->palette().disabled(); map["inactiveborder"] = cg.background(); map["inactivecaption"] = cg.background(); map["inactivecaptiontext"] = cg.text(); map["graytext"] = cg.text(); #endif };
void IconViewItemExt::paintItem(QPainter* p,const QColorGroup& cg) { if(isSelected()) { p->setBrush(cg.highlight()); p->drawRect(textRect(false)); p->setPen(QPen(cg.highlightedText())); p->setBackgroundColor(cg.highlight()); p->setBackgroundMode(Qt::OpaqueMode); p->drawText(textRect(false),Qt::AlignHCenter|Qt::WordBreak,text()); p->setPen(QPen(cg.dark(),4)); p->drawRect(pixmapRect(false)); p->drawPixmap(pixmapRect(false).x(),pixmapRect(false).y(),*pixmap()); } else { QIconViewItem::paintItem ( p,cg); } }
////////////////////////////////////////////////////////////////////////////////////////// /// CLASS QueueItem ////////////////////////////////////////////////////////////////////////////////////////// void QueueItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) { KListViewItem::paintCell( p, cg, column, width, align ); QString str = QString::number( ( static_cast<KListView *>( listView() ) )->itemIndex( this ) + 1 ); //draw the symbol's outline uint fw = p->fontMetrics().width( str ) + 2; const uint w = 16; //keep this even const uint h = height() - 2; p->setBrush( cg.highlight() ); p->setPen( cg.highlight().dark() ); //TODO blend with background color p->drawEllipse( width - fw - w/2, 1, w, h ); p->drawRect( width - fw, 1, fw, h ); p->setPen( cg.highlight() ); p->drawLine( width - fw, 2, width - fw, h - 1 ); fw += 2; //add some more padding p->setPen( cg.highlightedText() ); p->drawText( width - fw, 2, fw, h-1, Qt::AlignCenter, str ); }
/*! \brief Returns a palette with colored scrollbars * * This method creates a palette with skin specific scrollbar colors. * Parent should be a widget that holds a "default" active palette, which will * be used as base for the resulting palette. * The returned QPalette is a copy of the parent palette but with modified * scrollbar colors: QColorGroup::Highlight, QColorGroup::Button, * QColorGroup::Foreground, QColorGroup::Background and QColorGroup::ButtonText. */ QPalette CSkin::palette(QWidget *parent) { QPalette pal; QColorGroup cg; cg = parent->QWidget::palette().active(); // copy active palette from parent // ButtonText + arrow of scrollbar if (colors.btnTxt) { cg.setColor(QColorGroup::ButtonText, QColor(colors.btnTxt)); cg.setColor(QColorGroup::Foreground, cg.buttonText()); } // Scrollbar if (colors.scrollbar) { cg.setColor(QColorGroup::Highlight, QColor(colors.scrollbar)); cg.setColor(QColorGroup::Button, cg.highlight()); cg.setColor(QColorGroup::Background, cg.highlight()); } pal.setActive(cg); pal.setInactive(cg); pal.setDisabled(cg); return pal; }
virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) { #if 0 // disabled - not overriding correct class if (column == 1 || column == 2 || column == 3 || column == 4) { toProfilerSource *source = dynamic_cast<toProfilerSource *>(listView()); if (!source) { toTreeWidgetItem::paintCell(p, cg, column, width, alignment); return ; } double total = allText(column).toDouble(); double val; switch (column) { case 1: val = total / source->TotalOccur; break; case 2: val = total / source->TotalTime; break; case 3: val = total / source->MaxTime; break; case 4: val = total / source->MinTime; break; default: val = 0; } p->fillRect(0, 0, int(val*width), height(), QBrush(Qt::blue)); p->fillRect(int(val*width), 0, width, height(), QBrush(isSelected() ? cg.highlight() : cg.base())); QPen pen(isSelected() ? cg.highlightedText() : cg.foreground()); p->setPen(pen); p->drawText(0, 0, width, height(), Qt::AlignRight, text(column)); } else { toTreeWidgetItem::paintCell(p, cg, column, width, alignment); } #endif }
void DriverItem::paintCell(QPainter *p, const QColorGroup &cg, int, int width, int) { // background p->fillRect(0, 0, width, height(), cg.base()); // highlight rectangle if(isSelected()) p->fillRect(0, 0, /*2+p->fontMetrics().width(text(0))+(pixmap(0) ? pixmap(0)->width()+2 : 0)*/ width, height(), (m_conflict ? red : cg.highlight())); // draw pixmap int w(0); if(pixmap(0) && !pixmap(0)->isNull()) { int h((height() - pixmap(0)->height()) / 2); p->drawPixmap(w, h, *pixmap(0)); w += (pixmap(0)->width() + 2); } // draw Text if(!m_item || !m_item->isOption() || isSelected()) { p->setPen((isSelected() ? cg.highlightedText() : (m_conflict ? red : cg.text()))); p->drawText(w, 0, width - w, height(), Qt::AlignLeft | Qt::AlignVCenter, text(0)); } else { int w1(0); QString s(m_item->get("text") + ": <"); w1 = p->fontMetrics().width(s); p->setPen(cg.text()); p->drawText(w, 0, w1, height(), Qt::AlignLeft | Qt::AlignVCenter, s); w += w1; p->setPen((m_conflict ? red : darkGreen)); s = m_item->prettyText(); w1 = p->fontMetrics().width(s); p->drawText(w, 0, w1, height(), Qt::AlignLeft | Qt::AlignVCenter, s); w += w1; p->setPen(cg.text()); s = QString::fromLatin1(">"); w1 = p->fontMetrics().width(s); p->drawText(w, 0, w1, height(), Qt::AlignLeft | Qt::AlignVCenter, s); } }
void PlaylistItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align) { if(!m_playingItems.contains(this)) return KListViewItem::paintCell(p, cg, column, width, align); QColorGroup colorGroup = cg; QColor base = colorGroup.base(); QColor selection = colorGroup.highlight(); int r = (base.red() + selection.red()) / 2; int b = (base.blue() + selection.blue()) / 2; int g = (base.green() + selection.green()) / 2; QColor c(r, g, b); colorGroup.setColor(QColorGroup::Base, c); QListViewItem::paintCell(p, colorGroup, column, width, align); }
void KstVectorTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) { KstVectorPtr vector = *KST::vectorList.findTag(_strVector); QString str; painter->eraseRect( 0, 0, cr.width(), cr.height() ); if (selected) { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() ); painter->setPen(cg.highlightedText()); } else { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() ); painter->setPen(cg.text()); } if( col == 0 && vector) { str.setNum(vector->value(row), 'g', 16); } painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str); }
void KstScalarTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) { KstScalarList::iterator it = KST::scalarList.begin(); QString str; if (selected) { painter->eraseRect( 0, 0, cr.width(), cr.height() ); painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() ); painter->setPen(cg.highlightedText()); } else { painter->eraseRect( 0, 0, cr.width(), cr.height() ); painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() ); painter->setPen(cg.text()); } it += row; if( col == 0 ) { str = (*it)->tagName(); } else if( col == 1 ) { str = (*it)->label(); } painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str); }
/*! \reimp */ void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &g, SFlags flags, const QStyleOption& opt ) { switch ( element ) { case CE_PopupMenuItem: { if (! widget || opt.isDefault()) break; const QPopupMenu *popupmenu = (const QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = !(flags & Style_Enabled); bool checkable = popupmenu->isCheckable(); bool act = flags & Style_Active; int x, y, w, h; r.rect( &x, &y, &w, &h ); QColorGroup itemg = g; if ( checkable ) maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks int checkcol = maxpmw; if ( mi && mi->isSeparator() ) { // draw separator p->setPen( g.dark() ); p->drawLine( x, y, x+w, y ); p->setPen( g.light() ); p->drawLine( x, y+1, x+w, y+1 ); return; } QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x, y, w, h, fill); if ( !mi ) return; if ( mi->isChecked() ) { if ( act && !dis ) { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Button ) ); } else { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); } } else if ( !act ) { p->fillRect(x, y, checkcol , h, g.brush( QColorGroup::Button )); } if ( mi->iconSet() ) { // draw iconset QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; if (act && !dis ) mode = QIconSet::Active; QPixmap pixmap; if ( checkable && mi->isChecked() ) pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On ); else pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); if ( act && !dis ) { if ( !mi->isChecked() ) qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); } QRect cr( x, y, checkcol, h ); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( cr.center() ); p->setPen( itemg.text() ); p->drawPixmap( pmr.topLeft(), pixmap ); QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); } else if ( checkable ) { // just "checking"... int mw = checkcol + motifItemFrame; int mh = h - 2*motifItemFrame; if ( mi->isChecked() ) { SFlags cflags = Style_Default; if (! dis) cflags |= Style_Enabled; if (act) cflags |= Style_On; drawPrimitive( PE_CheckMark, p, QRect(x + motifItemFrame + 2, y + motifItemFrame, mw, mh), itemg, cflags, opt ); } } p->setPen( act ? g.highlightedText() : g.buttonText() ); QColor discol; if ( dis ) { discol = itemg.text(); p->setPen( discol ); } int xm = motifItemFrame + checkcol + motifItemHMargin; if ( mi->custom() ) { int m = motifItemVMargin; p->save(); if ( dis && !act ) { p->setPen( g.light() ); mi->custom()->paint( p, itemg, act, !dis, x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); p->setPen( discol ); } mi->custom()->paint( p, itemg, act, !dis, x+xm, y+m, w-xm-tab+1, h-2*m ); p->restore(); } QString s = mi->text(); if ( !s.isNull() ) { // draw text int t = s.find( '\t' ); int m = motifItemVMargin; const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; if ( t >= 0 ) { // draw tab text if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); p->setPen( discol ); } p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); s = s.left( t ); } if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); p->setPen( discol ); } p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); } else if ( mi->pixmap() ) { // draw pixmap QPixmap *pixmap = mi->pixmap(); if ( pixmap->depth() == 1 ) p->setBackgroundMode( OpaqueMode ); p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); if ( pixmap->depth() == 1 ) p->setBackgroundMode( TransparentMode ); } if ( mi->popup() ) { // draw sub menu arrow int dim = (h-2*motifItemFrame) / 2; if ( act ) { if ( !dis ) discol = white; QColorGroup g2( discol, g.highlight(), white, white, dis ? discol : white, discol, white ); drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim), g2, Style_Enabled); } else { drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim), g, !dis ? Style_Enabled : Style_Default); } } } break; default: QWindowsStyle::drawControl( element, p, widget, r, g, flags, opt ); break; } }
/** Render the document */ void reportView::render(){ QFont generalFont = KGlobalSettings::generalFont(); QString fntFamily = generalFont.family(); int fntSize = generalFont.pointSize(); if (fntSize == -1) fntSize = QFontInfo(generalFont).pointSize(); QString textColor = KGlobalSettings::textColor().name(); QString baseColor = KGlobalSettings::baseColor().name(); QColorGroup cg = palette().active(); QString bgColor = cg.background().name(); QString hlColor = cg.highlight().name(); QString hlTextColor = cg.highlightedText().name(); QString locationName = m_weatherService->stationName(m_locationCode); QString countryName = m_weatherService->stationCountry(m_locationCode); QString temp = m_weatherService->temperature(m_locationCode); QString dewPoint = m_weatherService->dewPoint( m_locationCode); QString relHumidity = m_weatherService->relativeHumidity(m_locationCode ); QString heatIndex = m_weatherService->heatIndex(m_locationCode ); QString windChill = m_weatherService->windChill(m_locationCode ); QString pressure = m_weatherService->pressure(m_locationCode ); QString wind = m_weatherService->wind(m_locationCode ); QString sunRiseTime = m_weatherService->sunRiseTime(m_locationCode ); QString sunSetTime = m_weatherService->sunSetTime(m_locationCode ); QString date = m_weatherService->date(m_locationCode ); QString icon = m_weatherService->iconFileName(m_locationCode ); QStringList cover = m_weatherService->cover(m_locationCode ); QStringList weather = m_weatherService->weather(m_locationCode ); setCaption(i18n("Weather Report - %1").arg( locationName ) ); QString weatherText = "<ul>\n"; if ( m_weatherService->stationNeedsMaintenance( m_locationCode ) ) { weatherText += "<li>" + i18n( "Station reports that it needs maintenance" ) + " \n"; } for (QStringList::const_iterator it = cover.begin(); it != cover.end(); ++it) weatherText += "<li>" + *it + "\n"; for (QStringList::const_iterator it = weather.begin(); it != weather.end(); ++it) weatherText += "<li>" + *it + "\n"; weatherText += "</ul>\n"; QString contents = "<html><head><style type=\"text/css\">" + QString("body { font-family: \"%1\"; font-size: %2pt; color: %3; background-color: %4; }\n") .arg(fntFamily).arg(fntSize).arg(textColor).arg(baseColor) + QString("div.headerTitle { background-color: %1; color: %2; padding: 4px; font-size: 120%; border: solid %3 1px; }\n") .arg(hlColor).arg(hlTextColor).arg(textColor) + QString("div.headerMsg { background-color: %1; color: %2; border-bottom: solid %3 1px; " "border-left: solid %4 1px; border-right: solid %5 1px; margin-bottom: 1em; padding: 2px; }\n") .arg(bgColor).arg(textColor).arg(textColor).arg(textColor).arg(textColor) + QString("</style><title></title></head><body dir=\"%1\">").arg( QApplication::reverseLayout()?"rtl":"ltr") + "<div class=\"headerTitle\"><b>" + i18n( "Weather Report - %1 - %2" ).arg( locationName ).arg( countryName ) + "</b></div>\n"; if ( ! date.isEmpty() ) contents += "<div class=\"headerMsg\"><b>" + i18n( "Latest data from %1" ).arg(date) + "</b></div>\n"; contents += QString( "<table><tr><td width=\"60\" style=\"text-align: center; border: dotted %1 1px;\">" "<img width=\"64\" height=\"64\" src=\"%2\" /></td>" "<td style=\"vertical-align: top\">%3</td></tr>") .arg(bgColor).arg(KURL(icon).url()).arg(weatherText) + "</table><table>" + QString("<tr><th style=\"text-align: right\">" + i18n( "Temperature:" ) + "</th><td>%1</td>" "<td width=\"50\"> </td>" "<th style=\"text-align: right\">" + i18n( "Dew Point:" ) + "</th><td>%2</td></tr>" "<tr><th style=\"text-align: right\">" + i18n( "Air Pressure:" ) + "</th><td>%3</td>" "<td width=\"50\"> </td>" "<th style=\"text-align: right\">" + i18n( "Rel. Humidity:" ) + "</th><td>%4</td></tr>" "<tr><th style=\"text-align: right\">" + i18n( "Wind Speed:" ) + "</th><td>%5</td>") .arg(temp).arg(dewPoint).arg(pressure).arg(relHumidity) .arg(wind) + "<td width=\"50\"> </td>"; if (!heatIndex.isEmpty()) contents += QString("<th style=\"text-align: right\">" + i18n( "Heat Index:" ) + "</th><td>%1</td>").arg(heatIndex); else if (!windChill.isEmpty()) contents += QString("<th style=\"text-align: right\">" + i18n( "Wind Chill:" ) + "</th><td>%1</td>").arg(windChill); else contents += "<td> </td><td> </td>"; contents += "</tr>"; contents += QString("<tr><th style=\"text-align: right\">" + i18n( "Sunrise:" ) + "</th><td>%1</td>" + "<td width=\"50\"> </td><th style=\"text-align: right\">" + i18n( "Sunset:" ) + "</th><td>%2</td>") .arg(sunRiseTime).arg(sunSetTime); contents += "</tr></table></body></html>"; m_reportView->begin(); m_reportView->write( contents ); m_reportView->end(); QScrollView *view = m_reportView->view(); kdDebug() << "Size " << view->size().height() << "," << view->size().width() << endl; kdDebug() << "Size " << view->visibleHeight() << "," << view->visibleWidth() << endl; m_reportView->view()->resize(view->size().width(), view->size().height()); }
void DataViewTable::paintCell(QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg) { if (selector_ == NULL || row < 0 || col < 0) return; QRect rect(0, 0, cr.width(), cr.height()); if (selected) { painter->fillRect(rect, cg.highlight()); painter->setPen(cg.highlightedText()); } else { if (row % 2) { painter->fillRect(rect, cg.base()); } else { painter->fillRect(rect, cg.background().light(135)); } painter->setPen(cg.text()); } const SelectList &flist = selector_->pickList(); // Check for row out of bounds. int max_row_id = flist.size() - 1; if (row > max_row_id) return; // determine if table has optional col for the feature id bool show_id = Preferences::getConfig().dataViewShowFID; if (show_id && col == 0) { painter->drawText(rect, Qt::AlignRight, QString::number(flist[row])); return; } if (!selector_->HasAttrib()) { // we don't have anny attribs, bail now return; } // we don't have to worry about fails attribute fetches since we are anly // asking for records that are already in our select list and they cannot // get into the select list w/o a valid record. gstRecordHandle rec; try { rec = theSourceManager->GetAttributeOrThrow( UniqueFeatureId(selector_->getSourceID(), selector_->layer(), flist[row])); } catch (...) { // silently ignore. see comment before 'try' return; } int num_fields = static_cast<int>(rec->NumFields()); // Check for column out of bounds. int max_column_id = show_id ? num_fields : num_fields - 1; if (col > max_column_id) return; gstValue* val = rec->Field(show_id ? col - 1 : col); int tf = val->IsNumber() ? Qt::AlignRight : Qt::AlignLeft; int rowHeight = this->rowHeight(row); int colWidth = this->columnWidth(col); QRect bounding_rect = fontMetrics().boundingRect(val->ValueAsUnicode()); // fontMetrics should account for the font descenders, but it // seems to be broken. // I accounted for the descenders by adding a margin of 4 around the cell // contents to account for errors in the fontMetrics // height estimation for font descenders, e.g., the tail of // the "y" or "p") . This seems to work for even large fonts and // is readable for smaller fonts. int added_cell_margin = 4; int cellWidth = bounding_rect.width() + added_cell_margin * 2; int cellHeight = bounding_rect.height() + added_cell_margin * 2; if (cellHeight > rowHeight) { setRowHeight(row, cellHeight); } if (cellWidth > colWidth) { setColumnWidth(col, cellWidth); } // When drawing, we're going to force the horizontal margin here. QRect text_rect(added_cell_margin, 0, cr.width() - added_cell_margin, cr.height()); painter->drawText(text_rect, tf, val->ValueAsUnicode()); }
/*!\reimp */ void QPlatinumStyle::drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, SCFlags sub, SCFlags subActive, const QStyleOption& opt ) const { switch ( control ) { case CC_ComboBox: { int x, y, w, h; r.rect( &x, &y, &w, &h ); p->fillRect( x + 2, y + 2, w - 4, h - 4, cg.brush(QColorGroup::Button) ); // the bright side p->setPen(cg.shadow()); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.light() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( x + 2, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 2, x + w - 2, y + h - 2 ); p->setPen (cg.shadow() ); p->drawLine( x + 1, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen( cg.background() ); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + 1 ); p->setPen( white ); p->drawPoint( x + 3, y + 3 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); if ( sub & SC_ComboBoxArrow ) { QRect rTmp = querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow, opt ); int xx = rTmp.x(), yy = rTmp.y(), ww = rTmp.width(), hh = rTmp.height(); // the bright side p->setPen( cg.mid() ); p->drawLine( xx, yy+2, xx, yy+hh-3 ); p->setPen( cg.button() ); p->drawLine( xx+1, yy+1, xx+ww-2, yy+1 ); p->drawLine( xx+1, yy+1, xx+1, yy+hh-2 ); p->setPen( cg.light() ); p->drawLine( xx+2, yy+2, xx+2, yy+hh-2 ); p->drawLine( xx+2, yy+2, xx+ww-2, yy+2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( xx+3, yy+hh-3 ,xx+ww-3, yy+hh-3 ); p->drawLine( xx+ww-3, yy+3, xx+ww-3, yy+hh-3 ); p->setPen( cg.dark() ); p->drawLine( xx+2, yy+hh-2 ,xx+ww-2, yy+hh-2 ); p->drawLine( xx+ww-2, yy+2, xx+ww-2, yy+hh-2 ); p->setPen( cg.shadow() ); p->drawLine( xx+1, yy+hh-1,xx+ww-1, yy+hh-1 ); p->drawLine( xx+ww-1, yy, xx+ww-1, yy+hh-1 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( xx + ww - 1, yy ); p->drawPoint( xx + ww - 2, yy ); p->drawPoint( xx + ww - 1, yy + 1 ); p->setPen( cg.shadow() ); p->drawPoint( xx + ww - 2, yy + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( xx + ww - 1, yy + hh - 1 ); p->drawPoint( xx + ww - 2, yy + hh - 1 ); p->drawPoint( xx + ww - 1, yy + hh - 2 ); p->setPen( cg.shadow() ); p->drawPoint( xx + ww - 2, yy + hh - 2 ); p->setPen( cg.dark() ); p->drawPoint( xx + ww - 3, yy + hh - 3 ); p->setPen( cg.mid() ); p->drawPoint( xx + ww - 4, yy + hh - 4 ); // and the arrows p->setPen( cg.foreground() ); QPointArray a ; a.setPoints( 7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2 ); a.translate( xx + ww / 2, yy + hh / 2 - 3 ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 ); a.translate( xx + ww / 2, yy + hh / 2 + 2 ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } #ifndef QT_NO_COMBOBOX if ( sub & SC_ComboBoxEditField ) { const QComboBox *cmb; cmb = (const QComboBox*)widget; // sadly this is pretty much the windows code, except // for the first fillRect call... QRect re = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxEditField ), widget ); if ( cmb->hasFocus() && !cmb->editable() ) p->fillRect( re.x() + 1, re.y() + 1, re.width() - 2, re.height() - 2, cg.brush( QColorGroup::Highlight ) ); if ( cmb->hasFocus() ) { p->setPen( cg.highlightedText() ); p->setBackgroundColor( cg.highlight() ); } else { p->setPen( cg.text() ); p->setBackgroundColor( cg.background() ); } if ( cmb->hasFocus() && !cmb->editable() ) { QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cmb ), widget ); drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); } if ( cmb->editable() ) { // need this for the moment... // was the code in comboButton rect QRect ir( x + 3, y + 3, w - 6 - 16, h - 6 ); if ( QApplication::reverseLayout() ) ir.moveBy( 16, 0 ); // end comboButtonRect... ir.setRect( ir.left() - 1, ir.top() - 1, ir.width() + 2, ir.height() + 2 ); qDrawShadePanel( p, ir, cg, TRUE, 2, 0 ); } } #endif break; } case CC_Slider: { #ifndef QT_NO_SLIDER const QSlider *slider = (const QSlider *) widget; int thickness = pixelMetric( PM_SliderControlThickness, widget ); int len = pixelMetric( PM_SliderLength, widget ); int ticks = slider->tickmarks(); QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, opt), handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, opt); if ((sub & SC_SliderGroove) && groove.isValid()) { p->fillRect( groove, cg.brush(QColorGroup::Background) ); int x, y, w, h; int mid = thickness / 2; if ( ticks & QSlider::Above ) mid += len / 8; if ( ticks & QSlider::Below ) mid -= len / 8; if ( slider->orientation() == Horizontal ) { x = 0; y = groove.y() + mid - 3; w = slider->width(); h = 7; } else { x = groove.x() + mid - 3; y = 0; w = 7; h = slider->height(); } p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark )); // the dark side p->setPen( cg.dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1); p->setPen( cg.shadow() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the bright side! p->setPen(cg.shadow()); p->drawLine( x + 1, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 ); p->setPen( cg.light() ); p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen(cg.background()); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen(cg.shadow()); p->drawPoint( x + 1, y + 1 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.light() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.light() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); // ### end slider groove if ( how & Style_HasFocus ) drawPrimitive( PE_FocusRect, p, groove, cg ); } if ((sub & SC_SliderHandle) && handle.isValid()) { const QColor c0 = cg.shadow(); const QColor c1 = cg.dark(); const QColor c3 = cg.light(); int x1 = handle.x(); int x2 = handle.x() + handle.width() - 1; int y1 = handle.y(); int y2 = handle.y() + handle.height() - 1; int mx = handle.width() / 2; int my = handle.height() / 2; if ( slider->orientation() == Vertical ) { // Background QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); p->setPen( NoPen ); QPointArray a(6); a.setPoint( 0, x1 + 1, y1 + 1 ); a.setPoint( 1, x2 - my + 2, y1 + 1 ); a.setPoint( 2, x2 - 1, y1 + my - 1 ); a.setPoint( 3, x2 - 1, y2 - my + 1 ); a.setPoint( 4, x2 - my + 2, y2 - 1 ); a.setPoint( 5, x1 + 1, y2 - 1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); // shadow border p->setPen( c0 ); p->drawLine( x1, y1 + 1, x1,y2 - 1 ); p->drawLine( x2 - my + 2, y1, x2, y1 + my - 2 ); p->drawLine( x2 - my + 2, y2, x2, y1 + my + 2 ); p->drawLine( x2, y1 + my - 2, x2, y1 + my + 2 ); p->drawLine( x1 + 1, y1, x2 - my + 2, y1 ); p->drawLine( x1 + 1, y2, x2 - my + 2, y2 ); // light shadow p->setPen( c3 ); p->drawLine( x1 + 1, y1 + 2, x1 + 1, y2 - 2 ); p->drawLine( x1 + 1, y1 + 1, x2 - my + 2, y1 + 1 ); p->drawLine( x2 - my + 2, y1 + 1, x2 - 1, y1 + my - 2 ); // dark shadow p->setPen(c1); p->drawLine( x2 - 1, y1 + my - 2, x2 - 1, y1 + my + 2 ); p->drawLine( x2 - my + 2, y2 - 1, x2 - 1, y1 + my + 2 ); p->drawLine( x1 + 1, y2 - 1, x2 -my + 2, y2 - 1 ); drawRiffles( p, handle.x(), handle.y() + 2, handle.width() - 3, handle.height() - 4, cg, TRUE ); } else { // Horizontal QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); p->setPen( NoPen ); QPointArray a(6); a.setPoint( 0, x2 - 1, y1 + 1 ); a.setPoint( 1, x2 - 1, y2 - mx + 2 ); a.setPoint( 2, x2 - mx + 1, y2 - 1 ); a.setPoint( 3, x1 + mx - 1, y2 - 1 ); a.setPoint( 4, x1 + 1, y2 - mx + 2 ); a.setPoint( 5, x1 + 1, y1 + 1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); // shadow border p->setPen( c0 ); p->drawLine( x1 + 1, y1, x2 - 1, y1 ); p->drawLine( x1, y2 - mx + 2, x1 + mx - 2, y2 ); p->drawLine( x2, y2 - mx + 2, x1 + mx + 2, y2 ); p->drawLine( x1 + mx - 2, y2, x1 + mx + 2, y2 ); p->drawLine( x1, y1 + 1, x1, y2 - mx + 2 ); p->drawLine( x2, y1 + 1, x2, y2 - mx + 2 ); // light shadow p->setPen(c3); p->drawLine( x1 + 1, y1 + 1, x2 - 1, y1 + 1 ); p->drawLine( x1 + 1, y1 + 1, x1 + 1, y2 - mx + 2 ); // dark shadow p->setPen(c1); p->drawLine( x2 - 1, y1 + 1, x2 - 1, y2 - mx + 2 ); p->drawLine( x1 + 1, y2 - mx + 2, x1 + mx - 2, y2 - 1 ); p->drawLine( x2 - 1, y2 - mx + 2, x1 + mx + 2, y2 - 1 ); p->drawLine( x1 + mx - 2, y2 - 1, x1 + mx + 2, y2 - 1 ); drawRiffles( p, handle.x() + 2, handle.y(), handle.width() - 4, handle.height() - 5, cg, FALSE ); } } if ( sub & SC_SliderTickmarks ) QCommonStyle::drawComplexControl( control, p, widget, r, cg, how, SC_SliderTickmarks, subActive, opt ); #endif break; } default: QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how, sub, subActive, opt ); break; } }
void PlaylistItem::paintCell( QPainter *painter, const QColorGroup &cg, int column, int width, int align ) { //TODO add spacing on either side of items //p->translate( 2, 0 ); width -= 3; // Don't try to draw if width or height is 0, as this crashes Qt if( !painter || !listView() || width <= 0 || height() == 0 ) return; static const QImage currentTrackLeft = locate( "data", "amarok/images/currenttrack_bar_left.png" ); static const QImage currentTrackMid = locate( "data", "amarok/images/currenttrack_bar_mid.png" ); static const QImage currentTrackRight = locate( "data", "amarok/images/currenttrack_bar_right.png" ); if( column == Mood && !moodbar().dataExists() ) moodbar().load(); // Only has an effect the first time // The moodbar column can have text in it, like "Calculating". // moodbarType is 0 if column != Mood, 1 if we're displaying // a moodbar, and 2 if we're displaying text const int moodbarType = column != Mood ? 0 : moodbar().state() == Moodbar::Loaded ? 1 : 2; const QString colText = text( column ); const bool isCurrent = this == listView()->currentTrack(); QPixmap buf( width, height() ); QPainter p( &buf, true ); if( isCurrent ) { static paintCacheItem paintCache[NUM_COLUMNS]; // Convert intensity to string, so we can use it as a key const QString colorKey = QString::number( glowIntensity ); const bool cacheValid = paintCache[column].width == width && paintCache[column].height == height() && paintCache[column].text == colText && paintCache[column].font == painter->font() && paintCache[column].color == glowBase && paintCache[column].selected == isSelected() && !s_pixmapChanged; // If any parameter changed, we must regenerate all pixmaps if ( !cacheValid ) { for( int i = 0; i < NUM_COLUMNS; ++i) paintCache[i].map.clear(); s_pixmapChanged = false; } // Determine if we need to repaint the pixmap, or paint from cache if ( paintCache[column].map.find( colorKey ) == paintCache[column].map.end() ) { // Update painting cache paintCache[column].width = width; paintCache[column].height = height(); paintCache[column].text = colText; paintCache[column].font = painter->font(); paintCache[column].color = glowBase; paintCache[column].selected = isSelected(); QColor bg; if( isSelected() ) bg = listView()->colorGroup().highlight(); else bg = isAlternate() ? listView()->alternateBackground() : listView()->viewport()->backgroundColor(); buf.fill( bg ); // Draw column divider line p.setPen( listView()->viewport()->colorGroup().mid() ); p.drawLine( width - 1, 0, width - 1, height() - 1 ); // Here we draw the background bar graphics for the current track: // // Illustration of design, L = Left, M = Middle, R = Right: // <LMMMMMMMMMMMMMMMR> int leftOffset = 0; int rightOffset = 0; int margin = listView()->itemMargin(); const float colorize = 0.8; const double intensity = 1.0 - glowIntensity * 0.021; // Left part if( column == listView()->m_firstColumn ) { QImage tmpImage = currentTrackLeft.smoothScale( 1, height(), QImage::ScaleMax ); KIconEffect::colorize( tmpImage, glowBase, colorize ); imageTransparency( tmpImage, intensity ); p.drawImage( 0, 0, tmpImage, 0, 0, tmpImage.width() - 1 ); //HACK leftOffset = tmpImage.width() - 1; //HACK Subtracting 1, to work around the black line bug margin += 6; } // Right part else if( column == Playlist::instance()->mapToLogicalColumn( Playlist::instance()->numVisibleColumns() - 1 ) ) { QImage tmpImage = currentTrackRight.smoothScale( 1, height(), QImage::ScaleMax ); KIconEffect::colorize( tmpImage, glowBase, colorize ); imageTransparency( tmpImage, intensity ); p.drawImage( width - tmpImage.width(), 0, tmpImage ); rightOffset = tmpImage.width(); margin += 6; } // Middle part // Here we scale the one pixel wide middel image to stretch to the full column width. QImage tmpImage = currentTrackMid.copy(); KIconEffect::colorize( tmpImage, glowBase, colorize ); imageTransparency( tmpImage, intensity ); tmpImage = tmpImage.smoothScale( width - leftOffset - rightOffset, height() ); p.drawImage( leftOffset, 0, tmpImage ); // Draw the pixmap, if present int leftMargin = margin; if ( pixmap( column ) ) { p.drawPixmap( leftMargin, height() / 2 - pixmap( column )->height() / 2, *pixmap( column ) ); leftMargin += pixmap( column )->width() + 2; } if( align != Qt::AlignCenter ) align |= Qt::AlignVCenter; if( column != Rating && moodbarType != 1 ) { // Draw the text static QFont font; static int minbearing = 1337 + 666; if( minbearing == 2003 || font != painter->font() ) { font = painter->font(); minbearing = painter->fontMetrics().minLeftBearing() + painter->fontMetrics().minRightBearing(); } const bool italic = font.italic(); int state = EngineController::engine()->state(); if( state == Engine::Playing || state == Engine::Paused ) font.setItalic( !italic ); p.setFont( font ); p.setPen( cg.highlightedText() ); // paint.setPen( glowText ); const int _width = width - leftMargin - margin + minbearing - 1; // -1 seems to be necessary const QString _text = KStringHandler::rPixelSqueeze( colText, painter->fontMetrics(), _width ); p.drawText( leftMargin, 0, _width, height(), align, _text ); font.setItalic( italic ); p.setFont( font ); } paintCache[column].map[colorKey] = buf; } else p.drawPixmap( 0, 0, paintCache[column].map[colorKey] ); if( column == Rating ) drawRating( &p ); if( moodbarType == 1 ) drawMood( &p, width, height() ); } else { const QColorGroup _cg = ( !exists() || !isEnabled() ) ? listView()->palette().disabled() : listView()->palette().active(); QColor bg = isSelected() ? _cg.highlight() : isAlternate() ? listView()->alternateBackground() : listView()->viewport()->backgroundColor(); #if KDE_IS_VERSION( 3, 3, 91 ) if( listView()->shadeSortColumn() && !isSelected() && listView()->columnSorted() == column ) { /* from klistview.cpp Copyright (C) 2000 Reginald Stadlbauer <*****@*****.**> Copyright (C) 2000,2003 Charles Samuels <*****@*****.**> Copyright (C) 2000 Peter Putzer */ if ( bg == Qt::black ) bg = QColor(55, 55, 55); // dark gray else { int h,s,v; bg.hsv(&h, &s, &v); if ( v > 175 ) bg = bg.dark(104); else bg = bg.light(120); } } #endif const QColor textc = isSelected() ? _cg.highlightedText() : _cg.text(); buf.fill( bg ); // Draw column divider line if( !isSelected() ) { p.setPen( listView()->viewport()->colorGroup().mid() ); p.drawLine( width - 1, 0, width - 1, height() - 1 ); } // Draw the pixmap, if present int margin = listView()->itemMargin(), leftMargin = margin; if ( pixmap( column ) ) { p.drawPixmap( leftMargin, height() / 2 - pixmap( column )->height() / 2, *pixmap( column ) ); leftMargin += pixmap( column )->width(); } if( align != Qt::AlignCenter ) align |= Qt::AlignVCenter; if( column == Rating ) drawRating( &p ); else if( moodbarType == 1 ) drawMood( &p, width, height() ); else { // Draw the text static QFont font; static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely if( minbearing == 2003 || font != painter->font() ) { font = painter->font(); //getting your bearings can be expensive, so we cache them minbearing = painter->fontMetrics().minLeftBearing() + painter->fontMetrics().minRightBearing(); } p.setFont( font ); p.setPen( ( m_isNew && isEnabled() && !isSelected() ) ? AmarokConfig::newPlaylistItemsColor() : textc ); const int _width = width - leftMargin - margin + minbearing - 1; // -1 seems to be necessary const QString _text = KStringHandler::rPixelSqueeze( colText, painter->fontMetrics(), _width ); p.drawText( leftMargin, 0, _width, height(), align, _text ); } } /// Track action symbols const int queue = listView()->m_nextTracks.findRef( this ) + 1; const bool stop = ( this == listView()->m_stopAfterTrack ); const bool repeat = Amarok::repeatTrack() && isCurrent; const uint num = ( queue ? 1 : 0 ) + ( stop ? 1 : 0 ) + ( repeat ? 1 : 0 ); static const QPixmap pixstop = Amarok::getPNG( "currenttrack_stop_small" ), pixrepeat = Amarok::getPNG( "currenttrack_repeat_small" ); //figure out if we are in the actual physical first column if( column == listView()->m_firstColumn && num ) { //margin, height const uint m = 2, h = height() - m; const QString str = QString::number( queue ); const uint qw = painter->fontMetrics().width( str ), sw = pixstop.width(), rw = pixrepeat.width(), qh = painter->fontMetrics().height(), sh = pixstop.height(), rh = pixrepeat.height(); //maxwidth const uint mw = kMax( qw, kMax( rw, sw ) ); //width of first & second column of pixmaps const uint w1 = ( num == 3 ) ? kMax( qw, rw ) : ( num == 2 && isCurrent ) ? kMax( repeat ? rw : 0, kMax( stop ? sw : 0, queue ? qw : 0 ) ) : ( num == 2 ) ? qw : queue ? qw : repeat ? rw : stop ? sw : 0, w2 = ( num == 3 ) ? sw : ( num == 2 && !isCurrent ) ? sw : 0; //phew //ellipse width, total width const uint ew = 16, tw = w1 + w2 + m * ( w2 ? 2 : 1 ); p.setBrush( cg.highlight() ); p.setPen( cg.highlight().dark() ); //TODO blend with background color p.drawEllipse( width - tw - ew/2, m / 2, ew, h ); p.drawRect( width - tw, m / 2, tw, h ); p.setPen( cg.highlight() ); p.drawLine( width - tw, m/2 + 1, width - tw, h - m/2 ); int x = width - m - mw, y = height() / 2, tmp = 0; const bool multi = ( isCurrent && num >= 2 ); if( queue ) { //draw the shadowed inner text //NOTE we can't set an arbituary font size or family, these settings are already optional //and user defaults should also take presidence if no playlist font has been selected //const QFont smallFont( "Arial", (playNext > 9) ? 9 : 12 ); //p->setFont( smallFont ); //TODO the shadow is hard to do well when using a dark font color //TODO it also looks cluttered for small font sizes //p->setPen( cg.highlightedText().dark() ); //p->drawText( width - w + 2, 3, w, h-1, Qt::AlignCenter, str ); if( !multi ) tmp = -(qh / 2); y += tmp; p.setPen( cg.highlightedText() ); p.drawText( x, y, -x + width, multi ? h/2 : qh, Qt::AlignCenter, str ); y -= tmp; if( isCurrent ) y -= height() / 2; else x -= m + w2; } if( repeat ) { if( multi ) tmp = (h/2 - rh)/2 + ( num == 2 && stop ? 0 : 1 ); else tmp = -(rh / 2); y += tmp; p.drawPixmap( x, y, pixrepeat ); y -= tmp; if( num == 3 ) { x -= m + w2 + 2; y = height() / 2; } else y -= height() / 2; } if( stop ) { if( multi && num != 3 ) tmp = m + (h/2 - sh)/2; else tmp = -(sh / 2); y += tmp; p.drawPixmap( x, y, pixstop ); y -= tmp; } } if( this != listView()->currentTrack() && !isSelected() ) { p.setPen( QPen( cg.mid(), 0, Qt::SolidLine ) ); p.drawLine( width - 1, 0, width - 1, height() - 1 ); } p.end(); painter->drawPixmap( 0, 0, buf ); }
QColorGroup PropertyPanel::highlightColorGroup( QColorGroup cg ) { cg.setColor( QColorGroup::Foreground, cg.highlightedText() ); cg.setColor( QColorGroup::Background, cg.highlight() ); return cg; }
void PlaylistItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) { //TODO add spacing on either side of items //p->translate( 2, 0 ); width -= 3; const bool isCurrent = this == listView()->currentTrack(); if( isCurrent && !isSelected() ) { static paintCacheItem paintCache[NUM_COLUMNS]; // Convert QColor to string for use as key in QMap const QString colorKey = QString::number( glowBase.red() ) + QString::number( glowBase.green() ) + QString::number( glowBase.blue() ); const bool cacheValid = paintCache[column].width == width && paintCache[column].height == height() && paintCache[column].text == text( column ) && paintCache[column].font == p->font() && !s_pixmapChanged; // If any parameter changed, we must regenerate all pixmaps if ( !cacheValid ) { for( int i = 0; i < NUM_COLUMNS; ++i) paintCache[i].map.clear(); s_pixmapChanged = false; } // Determine if we need to repaint the pixmap, or paint from cache if ( paintCache[column].map.find( colorKey ) == paintCache[column].map.end() ) { // Update painting cache paintCache[column].width = width; paintCache[column].height = height(); paintCache[column].text = text( column ); paintCache[column].font = p->font(); paintCache[column].map[colorKey] = QPixmap( width, height() ); // Don't try to draw if width or height is 0, as this crashes Qt if ( paintCache[column].map[colorKey].isNull() ) return; QPainter paint( &paintCache[column].map[colorKey], true ); // Here we draw the shaded background int h, s, v; glowBase.getHsv( &h, &s, &v ); QColor col; for ( int i = 0; i < height(); i++ ) { col.setHsv( h, s, static_cast<int>( sin( (float)i / ( (float)height() / 4 ) ) * 32.0 + 196 ) ); paint.setPen( col ); paint.drawLine( 0, i, width, i ); } // Draw the pixmap, if present const int margin = listView()->itemMargin(); int leftMargin = margin; if ( pixmap( column ) ) { paint.drawPixmap( leftMargin, height() / 2 - pixmap( column )->height() / 2, *pixmap( column ) ); leftMargin += pixmap( column )->width() + margin; } if( align != Qt::AlignCenter ) align |= Qt::AlignVCenter; // Draw the text static QFont font; static int minbearing = 1337 + 666; if( minbearing == 2003 || font != p->font() ) { font = p->font(); minbearing = p->fontMetrics().minLeftBearing() + p->fontMetrics().minRightBearing(); } paint.setFont( font ); paint.setPen( glowText ); const int _width = width - leftMargin - margin + minbearing - 1; // -1 seems to be necessary *shrug* const QString _text = KStringHandler::rPixelSqueeze( text( column ), p->fontMetrics(), _width ); paint.drawText( leftMargin, 0, _width, height(), align, _text ); paint.end(); } p->drawPixmap( 0, 0, paintCache[column].map[colorKey] ); } else { QColorGroup _cg = cg; //FIXME not acceptable to hardcode the colour QColor disabledText = QColor( 172, 172, 172 ); if( m_missing || !m_enabled ) _cg.setColor( QColorGroup::Text, disabledText ); KListViewItem::paintCell( p, _cg, column, width, align ); } /// Track action symbols const int queue = listView()->m_nextTracks.findRef( this ) + 1; const bool stop = ( this == listView()->m_stopAfterTrack ); const bool repeat = AmarokConfig::repeatTrack() && isCurrent; const uint num = ( queue ? 1 : 0 ) + ( stop ? 1 : 0 ) + ( repeat ? 1 : 0 ); static const QPixmap pixstop = amaroK::getPNG( "currenttrack_stop_small" ), pixrepeat = amaroK::getPNG( "currenttrack_repeat_small" ); //figure out if we are in the actual physical first column if( column == listView()->m_firstColumn && num ) { //margin, height const uint m = 2, h = height() - m; const QString str = QString::number( queue ); const uint qw = p->fontMetrics().width( str ), sw = pixstop.width(), rw = pixrepeat.width(), qh = p->fontMetrics().height(), sh = pixstop.height(), rh = pixrepeat.height(); //maxwidth const uint mw = kMax( qw, kMax( rw, sw ) ); //width of first & second column of pixmaps const uint w1 = ( num == 3 ) ? kMax( qw, rw ) : ( num == 2 && isCurrent ) ? kMax( repeat ? rw : 0, kMax( stop ? sw : 0, queue ? qw : 0 ) ) : ( num == 2 ) ? qw : queue ? qw : repeat ? rw : stop ? sw : 0, w2 = ( num == 3 ) ? sw : ( num == 2 && !isCurrent ) ? sw : 0; //phew //ellipse width, total width const uint ew = 16, tw = w1 + w2 + m * ( w2 ? 2 : 1 ); p->setBrush( cg.highlight() ); p->setPen( cg.highlight().dark() ); //TODO blend with background color p->drawEllipse( width - tw - ew/2, m / 2, ew, h ); p->drawRect( width - tw, m / 2, tw, h ); p->setPen( cg.highlight() ); p->drawLine( width - tw, m/2 + 1, width - tw, h - m/2 ); int x = width - m - mw, y = height() / 2, tmp = 0; const bool multi = ( isCurrent && num >= 2 ); if( queue ) { //draw the shadowed inner text //NOTE we can't set an arbituary font size or family, these settings are already optional //and user defaults should also take presidence if no playlist font has been selected //const QFont smallFont( "Arial", (playNext > 9) ? 9 : 12 ); //p->setFont( smallFont ); //TODO the shadow is hard to do well when using a dark font color //TODO it also looks cluttered for small font sizes //p->setPen( cg.highlightedText().dark() ); //p->drawText( width - w + 2, 3, w, h-1, Qt::AlignCenter, str ); if( !multi ) tmp = -(qh / 2); y += tmp; p->setPen( cg.highlightedText() ); p->drawText( x, y, -x + width, multi ? h/2 : qh, Qt::AlignCenter, str ); y -= tmp; if( isCurrent ) y -= height() / 2; else x -= m + w2; } if( repeat ) { if( multi ) tmp = (h/2 - rh)/2 + ( num == 2 && stop ? 0 : 1 ); else tmp = -(rh / 2); y += tmp; p->drawPixmap( x, y, pixrepeat ); y -= tmp; if( num == 3 ) { x -= m + w2 + 2; y = height() / 2; } else y -= height() / 2; } if( stop ) { if( multi && num != 3 ) tmp = m + (h/2 - sh)/2; else tmp = -(sh / 2); y += tmp; p->drawPixmap( x, y, pixstop ); y -= tmp; } } if( this != listView()->currentTrack() && !isSelected() ) { p->setPen( QPen( cg.mid(), 0, Qt::SolidLine ) ); p->drawLine( width - 1, 0, width - 1, height() - 1 ); } }
void EditorItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align) { //int margin = static_cast<Editor*>(listView())->itemMargin(); if(!d->property) return; if(column == 0) { QFont font = listView()->font(); if(d->property->isModified()) font.setBold(true); p->setFont(font); p->setBrush(cg.highlight()); p->setPen(cg.highlightedText()); KListViewItem::paintCell(p, cg, column, width, align); p->fillRect(parent() ? 0 : 50, 0, width, height()-1, QBrush(isSelected() ? cg.highlight() : backgroundColor())); p->setPen(isSelected() ? cg.highlightedText() : cg.text()); int delta = -20+KPROPEDITOR_ITEM_MARGIN; if ((firstChild() && dynamic_cast<EditorGroupItem*>(parent()))) { delta = -KPROPEDITOR_ITEM_MARGIN-1; } if (dynamic_cast<EditorDummyItem*>(parent())) { delta = KPROPEDITOR_ITEM_MARGIN*2; } else if (parent() && dynamic_cast<EditorDummyItem*>(parent()->parent())) { if (dynamic_cast<EditorGroupItem*>(parent())) delta += KPROPEDITOR_ITEM_MARGIN*2; else delta += KPROPEDITOR_ITEM_MARGIN*5; } p->drawText( QRect(delta,2, width+listView()->columnWidth(1)-KPROPEDITOR_ITEM_MARGIN*2, height()), Qt::AlignLeft | Qt::AlignTop /*| Qt::SingleLine*/, text(0)); p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); p->drawLine(width-1, 0, width-1, height()-1); p->drawLine(0, -1, width-1, -1); p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); //! \todo custom color? if (dynamic_cast<EditorDummyItem*>(parent())) p->drawLine(0, 0, 0, height()-1 ); } else if(column == 1) { QColorGroup icg(cg); icg.setColor(QColorGroup::Background, backgroundColor()); p->setBackgroundColor(backgroundColor()); Widget *widget = d->editor->createWidgetForProperty(d->property, false /*don't change Widget::property() */); if(widget) { QRect r(0, 0, d->editor->header()->sectionSize(1), height() - (widget->hasBorders() ? 0 : 1)); p->setClipRect(r, QPainter::CoordPainter); p->setClipping(true); widget->drawViewer(p, icg, r, d->property->value()); p->setClipping(false); } } p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); //! \todo custom color? p->drawLine(0, height()-1, width, height()-1 ); }
void EditorItem::paintBranches(QPainter *p, const QColorGroup &cg, int w, int y, int h) { p->eraseRect(0,0,w,h); KListViewItem *item = static_cast<KListViewItem*>(firstChild()); if(!item) return; QColor backgroundColor; p->save(); p->translate(0,y); QFont font = listView()->font(); while(item) { if(item->isSelected()) backgroundColor = cg.highlight(); else { if (dynamic_cast<EditorGroupItem*>(item)) backgroundColor = cg.base(); else backgroundColor = item->backgroundColor(); } // p->fillRect(-50,0,50, item->height(), QBrush(backgroundColor)); p->save(); p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); int delta = 0; int fillWidth = w; int x = 0; if (dynamic_cast<EditorGroupItem*>(item->parent())) { delta = 0;//-19; fillWidth += 19; } else { if (dynamic_cast<EditorGroupItem*>(item) || /*for flat mode*/ dynamic_cast<EditorDummyItem*>(item->parent())) x = 19; else x = -19; fillWidth += 19; } if (dynamic_cast<EditorDummyItem*>(item->parent())) { x = 19; } else if (item->parent() && dynamic_cast<EditorDummyItem*>(item->parent()->parent())) { x = 0; } p->fillRect(x+1, 0, fillWidth-1, item->height()-1, QBrush(backgroundColor)); p->drawLine(x, item->height()-1, w, item->height()-1 ); if (!dynamic_cast<EditorGroupItem*>(item)) p->drawLine(x, 0, x, item->height()-1 ); p->restore(); // for (int i=0; i<10000000; i++) // ; // if(item->isSelected()) { // p->fillRect(parent() ? 0 : 50, 0, w, item->height()-1, QBrush(cg.highlight())); // p->fillRect(-50,0,50, item->height(), QBrush(cg.highlight())); // } //sorry, but we need to draw text here again font.setBold( dynamic_cast<EditorGroupItem*>(item) || (static_cast<EditorItem*>(item)->property() && static_cast<EditorItem*>(item)->property()->isModified()) ); p->setFont(font); p->setPen(item->isSelected() ? cg.highlightedText() : cg.text()); if (item->firstChild() && dynamic_cast<EditorGroupItem*>(item->parent())) { delta = 19-KPROPEDITOR_ITEM_MARGIN-1; } else if (dynamic_cast<EditorDummyItem*>(item->parent())) { delta = 19; } if (item->parent() && dynamic_cast<EditorDummyItem*>(item->parent()->parent())) { if (dynamic_cast<EditorGroupItem*>(item->parent())) delta += KPROPEDITOR_ITEM_MARGIN*2; else delta += KPROPEDITOR_ITEM_MARGIN*5; } if (!dynamic_cast<EditorDummyItem*>(item->parent())) p->drawText(QRect(delta+1,0, w+listView()->columnWidth(1), item->height()), Qt::AlignLeft | Qt::AlignVCenter /*| Qt::SingleLine*/, item->text(0)); if(item->firstChild()) { paintListViewExpander(p, listView(), item->height(), cg, item->isOpen()); } // draw icon (if there is one) EditorItem *editorItem = dynamic_cast<EditorItem*>(item); if (editorItem && editorItem->property() && !editorItem->property()->icon().isEmpty()) { //int margin = listView()->itemMargin(); QPixmap pix = SmallIcon(editorItem->property()->icon()); if (!pix.isNull()) p->drawPixmap(-19+(19-pix.width())/2, (item->height() - pix.height()) / 2, pix); } p->translate(0, item->totalHeight()); item = (KListViewItem*)item->nextSibling(); } p->restore(); }
void UserView::drawItem(UserViewItemBase *base, QPainter *p, const QColorGroup &cg, int width, int margin) { if (base->type() == GRP_ITEM){ GroupItem *item = static_cast<GroupItem*>(base); QFont f(font()); int size = f.pixelSize(); if (size <= 0){ size = f.pointSize(); f.setPointSize(size * 3 / 4); }else{ f.setPixelSize(size * 3 / 4); } f.setBold(true); p->setFont(f); QString text; if (item->id()){ Group *grp = getContacts()->group(item->id()); if (grp){ text = grp->getName(); }else{ text = "???"; } }else{ text = i18n("Not in list"); } if (item->m_nContacts){ text += " ("; if (item->m_nContactsOnline){ text += QString::number(item->m_nContactsOnline); text += "/"; } text += QString::number(item->m_nContacts); text += ")"; } const QPixmap &pict = Pict(item->isOpen() ? "expanded" : "collapsed"); p->drawPixmap(2 + margin, (item->height() - pict.height()) / 2, pict); int x = 24 + margin; if (!item->isOpen() && item->m_unread){ CommandDef *def = CorePlugin::m_plugin->messageTypes.find(item->m_unread); if (def){ const QPixmap &pict = Pict(def->icon); if (m_bUnreadBlink) p->drawPixmap(x, (item->height() - pict.height()) / 2, pict); x += pict.width() + 2; } } if (!CorePlugin::m_plugin->getUseSysColors()) p->setPen(CorePlugin::m_plugin->getColorGroup()); x = item->drawText(p, x, width, text); if (CorePlugin::m_plugin->getGroupSeparator()) item->drawSeparator(p, x, width, cg); return; } if (base->type() == USR_ITEM){ ContactItem *item = static_cast<ContactItem*>(base); QFont f(font()); if (item->style() & CONTACT_ITALIC) f.setItalic(true); if (item->style() & CONTACT_UNDERLINE) f.setUnderline(true); if (item->style() & CONTACT_STRIKEOUT) f.setStrikeOut(true); if (item->m_bBlink){ f.setBold(true); }else{ f.setBold(false); } p->setFont(f); string icons = item->text(CONTACT_ICONS).latin1(); string icon = getToken(icons, ','); if (item->m_unread && m_bUnreadBlink){ CommandDef *def = CorePlugin::m_plugin->messageTypes.find(item->m_unread); if (def) icon = def->icon; } int x = margin; if (icon.length()){ const QPixmap &pict = Pict(icon.c_str()); x += 2; p->drawPixmap(x, (item->height() - pict.height()) / 2, pict); x += pict.width() + 2; } if (x < 24) x = 24; if (!item->isSelected() || !hasFocus() || !CorePlugin::m_plugin->getUseDblClick()){ if (CorePlugin::m_plugin->getUseSysColors()){ if (item->status() != STATUS_ONLINE) p->setPen(palette().disabled().text()); }else{ switch (item->status()){ case STATUS_ONLINE: break; case STATUS_AWAY: p->setPen(CorePlugin::m_plugin->getColorAway()); break; case STATUS_NA: p->setPen(CorePlugin::m_plugin->getColorNA()); break; case STATUS_DND: p->setPen(CorePlugin::m_plugin->getColorDND()); break; default: p->setPen(CorePlugin::m_plugin->getColorOffline()); break; } } } QString highlight; QString text = item->text(CONTACT_TEXT); if (!m_search.isEmpty()){ if (text.left(m_search.length()).upper() == m_search.upper()) highlight = text.left(m_search.length()); } int save_x = x; x = item->drawText(p, x, width, text); x += 2; if (!highlight.isEmpty()){ QPen oldPen = p->pen(); QColor oldBg = p->backgroundColor(); p->setBackgroundMode(OpaqueMode); if (item == m_searchItem){ if ((item == currentItem()) && CorePlugin::m_plugin->getUseDblClick()){ p->setBackgroundColor(cg.highlightedText()); p->setPen(cg.highlight()); }else{ p->setBackgroundColor(cg.highlight()); p->setPen(cg.highlightedText()); } }else{ p->setBackgroundColor(oldPen.color()); p->setPen(oldBg); } item->drawText(p, save_x, width, highlight); p->setPen(oldPen); p->setBackgroundColor(oldBg); p->setBackgroundMode(TransparentMode); } unsigned xIcon = width; while (icons.length()){ icon = getToken(icons, ','); const QPixmap &pict = Pict(icon.c_str()); xIcon -= pict.width() + 2; if (xIcon < (unsigned)x) break; p->drawPixmap(xIcon, (item->height() - pict.height()) / 2, pict); } return; } UserListBase::drawItem(base, p, cg, width, margin); }
/****************************************************************************** * Paint one value in one of the columns in the list view. */ void AlarmListViewItem::paintCell(QPainter *painter, const QColorGroup &cg, int column, int width, int /*align*/) { const AlarmListView *listView = alarmListView(); int margin = listView->itemMargin(); QRect box(margin, margin, width - margin * 2, height() - margin * 2); // area within which to draw bool selected = isSelected(); QColor bgColour = selected ? cg.highlight() : cg.base(); QColor fgColour = selected ? cg.highlightedText() : !event().enabled() ? Preferences::disabledColour() : event().expired() ? Preferences::expiredColour() : cg.text(); painter->setPen(fgColour); painter->fillRect(0, 0, width, height(), bgColour); if(column == listView->column(AlarmListView::TIME_COLUMN)) { int i = -1; QString str = text(column); if(mTimeHourPos >= 0) { // Need to pad out spacing to align times without leading zeroes i = str.find(" ~"); if(i >= 0) { if(mDigitWidth < 0) mDigitWidth = painter->fontMetrics().width("0"); QString date = str.left(i + 1); int w = painter->fontMetrics().width(date) + mDigitWidth; painter->drawText(box, AlignVCenter, date); box.setLeft(box.left() + w); painter->drawText(box, AlignVCenter, str.mid(i + 2)); } } if(i < 0) painter->drawText(box, AlignVCenter, str); } else if(column == listView->column(AlarmListView::TIME_TO_COLUMN)) painter->drawText(box, AlignVCenter | AlignRight, text(column)); else if(column == listView->column(AlarmListView::REPEAT_COLUMN)) painter->drawText(box, AlignVCenter | AlignHCenter, text(column)); else if(column == listView->column(AlarmListView::COLOUR_COLUMN)) { // Paint the cell the colour of the alarm message if(event().action() == KAEvent::MESSAGE || event().action() == KAEvent::FILE) painter->fillRect(box, event().bgColour()); } else if(column == listView->column(AlarmListView::TYPE_COLUMN)) { // Display the alarm type icon, horizontally and vertically centred in the cell QPixmap *pixmap = eventIcon(); QRect pixmapRect = pixmap->rect(); int diff = box.height() - pixmap->height(); if(diff < 0) { pixmapRect.setTop(-diff / 2); pixmapRect.setHeight(box.height()); } QPoint iconTopLeft(box.left() + (box.width() - pixmapRect.width()) / 2, box.top() + (diff > 0 ? diff / 2 : 0)); painter->drawPixmap(iconTopLeft, *pixmap, pixmapRect); } else if(column == listView->column(AlarmListView::MESSAGE_COLUMN)) { if(!selected && listView->drawMessageInColour()) { painter->fillRect(box, event().bgColour()); painter->setBackgroundColor(event().bgColour()); // painter->setPen(event().fgColour()); } QString txt = text(column); painter->drawText(box, AlignVCenter, txt); mMessageColWidth = listView->fontMetrics().boundingRect(txt).width(); } }
void PropertyEditorItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align) { if ( depth() == 0 ) return; int margin = listView()->itemMargin(); QColor bgColor = backgroundColor(0); if(column == 1) { switch(m_property->type()) { // case QVariant::Pixmap: // { // p->fillRect(0,0,width,height(),QBrush(backgroundColor())); // p->drawPixmap(margin, margin, m_property->value().toPixmap()); // break; // } case Variant::Type::Color: { p->fillRect(0,0,width,height(), QBrush(bgColor)); QColor ncolor = m_property->value().toColor(); p->setBrush(ncolor); p->drawRect(margin, margin, width - 2*margin, height() - 2*margin); QColorGroup nGroup(cg); break; } case Variant::Type::Bool: { p->fillRect(0,0,width,height(), QBrush(bgColor)); if(m_property->value().toBool()) { p->drawPixmap(margin, height()/2 -8, SmallIcon("button_ok")); p->drawText(QRect(margin+20,0,width,height()-1), Qt::AlignVCenter, i18n("Yes")); } else { p->drawPixmap(margin, height()/2 -8, SmallIcon("button_cancel")); p->drawText(QRect(margin+20,0,width,height()-1), Qt::AlignVCenter, i18n("No")); } break; } case Variant::Type::PenStyle: { p->fillRect(0,0,width,height(), QBrush(bgColor)); PenStyle style = DrawPart::nameToPenStyle( m_property->value().toString() ); int penWidth = 3; QPen pen( black, penWidth, style ); p->setPen( pen ); p->drawLine( height()/2, height()/2-1, width-height()/2, height()/2-1 ); break; } #if 0 case Variant::Type::PenCapStyle: { p->fillRect(0,0,width,height(), QBrush(bgColor)); PenCapStyle style = DrawPart::nameToPenCapStyle( m_property->value().toString() ); int penWidth = 6; QPen pen( black, penWidth, SolidLine, style, MiterJoin ); p->setPen( pen ); p->drawLine( width/2-10, height()/2-2, width/2+10, height()/2-2 ); break; } #endif case Variant::Type::None: case Variant::Type::Int: case Variant::Type::Raw: case Variant::Type::Double: case Variant::Type::String: case Variant::Type::Multiline: case Variant::Type::RichText: case Variant::Type::Select: case Variant::Type::Combo: case Variant::Type::FileName: case Variant::Type::VarName: case Variant::Type::PenCapStyle: case Variant::Type::Port: case Variant::Type::Pin: case Variant::Type::SevenSegment: case Variant::Type::KeyPad: { KListViewItem::paintCell(p, cg, column, width, align); break; } } } else { if(isSelected()) { p->fillRect(0,0,width, height(), QBrush(cg.highlight())); p->setPen(cg.highlightedText()); } else p->fillRect(0,0,width, height(), QBrush(bgColor)); QFont f = listView()->font(); p->save(); if ( m_property->changed() ) f.setBold(true); p->setFont(f); p->drawText(QRect(margin,0,width, height()-1), Qt::AlignVCenter, text(0)); p->restore(); p->setPen( QColor(200,200,200) ); //like in table view p->drawLine(width-1, 0, width-1, height()-1); } p->setPen( QColor(200,200,200) ); //like in t.v. p->drawLine(-50, height()-1, width, height()-1 ); }