void CrystalButton::drawButton(QPainter *painter) { if (!CrystalFactory::initialized()) return; QColorGroup group; float dx, dy; int dm=0; QPixmap pufferPixmap; pufferPixmap.resize(width(), height()); QPainter pufferPainter(&pufferPixmap); CrystalFactory *f=((CrystalFactory*)client_->factory()); QPixmap *background; if (f->transparency)background=f->image_holder->image(client_->isActive()); else background=NULL; WND_CONFIG *wndcfg=client_->isActive()?&f->active:&f->inactive; if (background && !background->isNull()) { QRect r=rect(); QPoint p=mapToGlobal(QPoint(0,0)); r.moveBy(p.x(),p.y()); pufferPainter.drawPixmap(QPoint(0,0),*background,r); }else{ group = client_->options()->colorGroup(KDecoration::ColorTitleBar, client_->isActive()); pufferPainter.fillRect(rect(), group.background()); } if (!wndcfg->overlay.isNull()) { pufferPainter.drawTiledPixmap(rect(),wndcfg->overlay,QPoint(x(),y())); } dm=0; if (image && (image->drawMode==1))dm=1; if (wndcfg->outlineMode) { // outline the frame pufferPainter.setPen(wndcfg->frameColor); if (wndcfg->outlineMode==2)pufferPainter.setPen(wndcfg->frameColor.dark(150)); if (wndcfg->outlineMode==3)pufferPainter.setPen(wndcfg->frameColor.light(150)); // top if ((client_->FullMax && client_->isShade() && (dm==0)) || ((dm==1)&&(!client_->FullMax || client_->isShade()))) pufferPainter.drawLine(0,0,width(),0); // left if (first && client_->FullMax && client_->isShade())pufferPainter.drawLine(0,0,0,height()); if (wndcfg->outlineMode==2)pufferPainter.setPen(wndcfg->frameColor.light(150)); if (wndcfg->outlineMode==3)pufferPainter.setPen(wndcfg->frameColor.dark(150)); // bottom if (client_->isShade() && ((dm==1)||(client_->FullMax)))pufferPainter.drawLine(0,height()-1,width(),height()-1); // right if (last && client_->FullMax && client_->isShade())pufferPainter.drawLine(width()-1,0,width()-1,height()); } if (wndcfg->inlineMode && (client_->FullMax||dm==1) && !client_->isShade()) { // inline the frame if (wndcfg->inlineMode==1)pufferPainter.setPen(wndcfg->inlineColor); if (wndcfg->inlineMode==2)pufferPainter.setPen(wndcfg->inlineColor.dark(150)); if (wndcfg->inlineMode==3)pufferPainter.setPen(wndcfg->inlineColor.light(150)); // buttons just need to draw the bottom line pufferPainter.drawLine(0,height()-1,width(),height()-1); } if (type_ == ButtonMenu && (!::factory->menuImage || image==NULL || (image!=NULL && !image->initialized()))) { // we paint the mini icon (which is 16 pixels high) dx = float(width() - 16) / 2.0; dy = float(height() - 16) / 2.0; if (dx<1 || dy<=1) { int m=(rect().width()-2<rect().height())?rect().width()-2:rect().height(); QRect r((rect().width()-m)/2,(rect().height()-m)/2,m,m); // if (isDown()) { r.moveBy(1,1); } pufferPainter.drawPixmap(r, client_->icon().pixmap(QIconSet::Small, QIconSet::Normal)); }else{ // if (isDown()) { dx++; dy++; } pufferPainter.drawPixmap((int)dx, (int)dy, client_->icon().pixmap(QIconSet::Small, QIconSet::Normal)); } } else if (image && image->initialized()) { // otherwise we paint the deco dx = float(width() - image->image_width) / 2.0; dy = float(height() - image->image_height) / 2.0; QImage *img=image->normal; if (::factory->hovereffect) { if (hover) { img=image->hovered; } if (::factory->animateHover) { img=image->getAnimated(animation); } } if (isDown()) { img=image->pressed; } if (img) if (dx<image->hSpace/2 || dy<0) { // Deco size is smaller than image, we need to stretch it int w,h; if (rect().width()-image->hSpace<rect().height()) { w=rect().width()-image->hSpace; h=(int)((float)w*(float)image->image_height/(float)image->image_width); }else{ h=rect().height(); w=(int)((float)h*(float)image->image_width/(float)image->image_height); } QRect r((rect().width()-w)/2,(rect().height()-h)/2,w,h); pufferPainter.drawImage(r,*img); if (type_ == ButtonMenu) drawMenuImage(&pufferPainter, r); }else{ // Otherwise we just paint it if (image->drawMode==1)dy=0; pufferPainter.drawImage(QPoint((int)dx,(int)dy),*img); if (type_ == ButtonMenu) drawMenuImage(&pufferPainter, QRect((int)dx,(int)dy,image->image_width,image->image_height)); } } pufferPainter.end(); painter->drawPixmap(0,0, pufferPixmap); }
void CrystalButton::drawButton(QPainter *painter) { int paddingLeft, paddingRight, paddingBottom, paddingTop; if (!CrystalFactory::initialized()) return; client_->padding(paddingLeft, paddingRight, paddingTop, paddingBottom); float dx, dy; int dm=0; // QPixmap pufferPixmap(width(), height()); // QPainter pufferPainter(&pufferPixmap); CrystalFactory *f=((CrystalFactory*)client_->factory()); WND_CONFIG *wndcfg=client_->isActive()?&f->active:&f->inactive; if (! client_->compositingActive()) { QColor color = client_->options()->color(KDecoration::ColorTitleBar, client_->isActive()); // color.setAlpha(96); painter->fillRect(rect(), color); if (!wndcfg->overlay.isNull()) { if (wndcfg->stretch_overlay == false) painter->drawTiledPixmap(rect(),wndcfg->overlay,QPoint(0, y() - paddingTop)); else { QRectF src( (float)x() * (float)wndcfg->overlay.width() / (float)client_->widget()->width(), (float)y(), (float)width() * (float)wndcfg->overlay.width() / (float)client_->widget()->width(), (float)height() ); painter->drawPixmap(QRect(0,0,width(),height()), wndcfg->overlay, src); } } } painter->setClipRect(this->rect()); dm=0; if (image && (image->drawMode==1))dm=1; if (wndcfg->outlineMode) { // outline the frame painter->setPen(wndcfg->frameColor); if (wndcfg->outlineMode==2)painter->setPen(wndcfg->frameColor.dark(150)); if (wndcfg->outlineMode==3)painter->setPen(wndcfg->frameColor.light(150)); // top if ((client_->FullMax && client_->isShade() && (dm==0)) || ((dm==1)&&(!client_->FullMax || client_->isShade()))) painter->drawLine(0,0,width(),0); // left if (first && client_->FullMax && client_->isShade()) painter->drawLine(0,0,0,height()); if (wndcfg->outlineMode==2)painter->setPen(wndcfg->frameColor.light(150)); if (wndcfg->outlineMode==3)painter->setPen(wndcfg->frameColor.dark(150)); // bottom if (client_->isShade() && ((dm==1)||(client_->FullMax))) painter->drawLine(0,height()-1,width(),height()-1); // right if (last && client_->FullMax && client_->isShade()) painter->drawLine(width()-1,0,width()-1,height()); } if (wndcfg->inlineMode && (client_->FullMax||dm==1) && !client_->isShade()) { // inline the frame if (wndcfg->inlineMode==1) painter->setPen(wndcfg->inlineColor); if (wndcfg->inlineMode==2) painter->setPen(wndcfg->inlineColor.dark(150)); if (wndcfg->inlineMode==3) painter->setPen(wndcfg->inlineColor.light(150)); // buttons just need to draw the bottom line painter->drawLine(0,height()-1,width(),height()-1); } if (type_ == MenuButton && (!::factory->menuImage || image==NULL || (image!=NULL && !image->initialized()))) { // we paint the mini icon (which is 16 pixels high) dx = float(width() - 16) / 2.0; dy = float(height() - 16) / 2.0; if (dx<1 || dy<=1) { int m=(rect().width()-2<rect().height())?rect().width()-2:rect().height(); QRect r((rect().width()-m)/2,(rect().height()-m)/2,m,m); // if (isDown()) { r.moveBy(1,1); } painter->drawPixmap(r, client_->icon().pixmap(16)); } else { // if (isDown()) { dx++; dy++; } painter->drawPixmap((int)dx, (int)dy, client_->icon().pixmap(16)); } } else if (image && image->initialized()) { // otherwise we paint the deco dx = float(width() - image->image_width) / 2.0; dy = float(height() - image->image_height) / 2.0; QImage *img=image->normal; if (::factory->hovereffect) { if (hover) { img=image->hovered; } if (::factory->animateHover) { img=image->getAnimated(animation); } } if (isDown()) { img=image->pressed; } if (img) { if (dx<image->hSpace/2 || dy<0) { // Deco size is smaller than image, we need to stretch it int w,h; if (rect().width()-image->hSpace<rect().height()) { w=rect().width()-image->hSpace; h=(int)((float)w*(float)image->image_height/(float)image->image_width); } else { h=rect().height(); w=(int)((float)h*(float)image->image_width/(float)image->image_height); } QRect r((rect().width()-w)/2,(rect().height()-h)/2,w,h); painter->drawImage(r,*img); if (type_ == MenuButton) drawMenuImage(painter, r); } else { // Otherwise we just paint it if (image->drawMode==1)dy=0; painter->drawImage(QPoint((int)dx,(int)dy),*img); if (type_ == MenuButton) drawMenuImage(painter, QRect((int)dx,(int)dy,image->image_width,image->image_height)); } } } // pufferPainter.end(); // painter->drawPixmap(0,0, pufferPixmap); }