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 PowderButton::drawButton(QPainter *painter) { if (!PowderHandler::initialized()) return; bool active = m_client->isActive(); // int titleSize = PowderHandler::titleSize(); // int borderSize = PowderHandler::borderSize(); int buttonSize = PowderHandler::buttonSize(); int ofx = (buttonSize-18)/2; int ofy = ofx; QColor cottl = KDecoration::options()->color(KDecoration::ColorTitleBar, active); QPixmap pufferPixmap; pufferPixmap.resize(buttonSize, buttonSize); QPainter pufferPainter(&pufferPixmap); pufferPixmap.fill(cottl); QPixmap menu_icon; // Paint the little icon on the buttons. // Lotsa trouble with this! Stupid scope! if (hover && !isDown()) { // Hover if (m_type == ButtonMenu) { if (PowderHandler::styledMenu()==true) { pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_menu_hover : *Pixmaps::inactive_menu_hover); } else { menu_icon = m_client->icon().pixmap(QIconSet::Small, QIconSet::Normal); pufferPainter.drawPixmap(ofx, ofy, menu_icon); } } else if (m_type == ButtonHelp) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_hover : *Pixmaps::inactive_help_hover); else if (m_type == ButtonMax) { if (isMaximized) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_hover : *Pixmaps::inactive_restore_hover); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_hover : *Pixmaps::inactive_max_hover); } else if (m_type == ButtonMin) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_hover : *Pixmaps::inactive_min_hover); else if (m_type == ButtonClose) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_hover : *Pixmaps::inactive_close_hover); else if (m_type == ButtonOnAllDesktops) { if (isOnAllDesktops) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_hover : *Pixmaps::inactive_unsticky_hover); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_hover : *Pixmaps::inactive_sticky_hover); } else if (m_type == ButtonAbove) { if (m_client->keepAbove()) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unabove_hover : *Pixmaps::inactive_unabove_hover); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_hover : *Pixmaps::inactive_above_hover); } else if (m_type == ButtonBelow) { if (m_client->keepBelow()) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unbelow_hover : *Pixmaps::inactive_unbelow_hover); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_hover : *Pixmaps::inactive_below_hover); } } else if (isDown()) { // Sunken if (m_type == ButtonMenu) { if (PowderHandler::styledMenu()==true) { pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_menu_sunken : *Pixmaps::inactive_menu_sunken); } else { menu_icon = m_client->icon().pixmap(QIconSet::Small, QIconSet::Normal); pufferPainter.drawPixmap(ofx, ofy, menu_icon); } } else if (m_type == ButtonHelp) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_sunken : *Pixmaps::inactive_help_sunken); else if (m_type == ButtonMax) { if (isMaximized) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_sunken : *Pixmaps::inactive_restore_sunken); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_sunken : *Pixmaps::inactive_max_sunken); } else if (m_type == ButtonMin) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_sunken : *Pixmaps::inactive_min_sunken); else if (m_type == ButtonClose) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_sunken : *Pixmaps::inactive_close_sunken); else if (m_type == ButtonOnAllDesktops) { if (isOnAllDesktops) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_sunken : *Pixmaps::inactive_unsticky_sunken); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_sunken : *Pixmaps::inactive_sticky_sunken); } else if (m_type == ButtonAbove) { if (m_client->keepAbove()) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unabove_sunken : *Pixmaps::inactive_unabove_sunken); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_sunken : *Pixmaps::inactive_above_sunken); } else if (m_type == ButtonBelow) { if (m_client->keepBelow()) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unbelow_sunken : *Pixmaps::inactive_unbelow_sunken); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_sunken : *Pixmaps::inactive_below_sunken); } } else { // Normal if (m_type == ButtonMenu) { if (PowderHandler::styledMenu()==true) { pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_menu_normal : *Pixmaps::inactive_menu_normal); } else { menu_icon = m_client->icon().pixmap(QIconSet::Small, QIconSet::Normal); pufferPainter.drawPixmap(ofx, ofy, menu_icon); } } else if (m_type == ButtonHelp) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_normal : *Pixmaps::inactive_help_normal); else if (m_type == ButtonMax) { if (isMaximized) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_normal : *Pixmaps::inactive_restore_normal); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_normal : *Pixmaps::inactive_max_normal); } else if (m_type == ButtonMin) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_normal : *Pixmaps::inactive_min_normal); else if (m_type == ButtonClose) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_normal : *Pixmaps::inactive_close_normal); else if (m_type == ButtonOnAllDesktops) { if (isOnAllDesktops) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_normal : *Pixmaps::inactive_unsticky_normal); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_normal : *Pixmaps::inactive_sticky_normal); } else if (m_type == ButtonAbove) { if (m_client->keepAbove()) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unabove_normal : *Pixmaps::inactive_unabove_normal); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_normal : *Pixmaps::inactive_above_normal); } else if (m_type == ButtonBelow) { if (m_client->keepBelow()) pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unbelow_normal : *Pixmaps::inactive_unbelow_normal); else pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_normal : *Pixmaps::inactive_below_normal); } } pufferPainter.end(); painter->drawPixmap(0, 0, pufferPixmap); }