16 #include "colorgriditem.h" 
   18 #include <QMouseEvent> 
   22 #include <QStyleOptionViewItem> 
   23 #include "colorwheel.h" 
   25 static const int gridWidth = 16;
 
   28 ColorGridItem::ColorGridItem(
int id, QWidget *parent) :
 
   32     mColor(Qt::transparent),
 
   34     picker(QPixmap(
"iconset/ui/picker-cursor.png"))
 
   36     setContentsMargins(0,0,0,0);
 
   38     setMouseTracking(
true);
 
   42 void ColorGridItem::initMenu()
 
   44     menu.addAction(tr(
"Pick"), 
this,SLOT(onColorPicked()));
 
   45     menu.addAction(tr(
"Tint"),
this,SLOT(onColorDroped()));
 
   46     menu.addAction(tr(
"Clear"),
this,SLOT(onColorCleared()));
 
   47     menu.addAction(tr(
"Cancel"));
 
   50 void ColorGridItem::drawTransparent()
 
   52     mBackgroundImg = QPixmap(gridWidth,gridWidth);
 
   53     mBackgroundImg.fill(Qt::white);
 
   54     QPainter painter(&mBackgroundImg);
 
   55     painter.setPen(Qt::NoPen);
 
   56     painter.setBrush(QColor(224, 224, 224));
 
   58     painter.drawRect(k,0,k,k);
 
   59     painter.drawRect(0,k,k,k);
 
   60     painter.setBrush(QColor(240, 240, 240));
 
   61     painter.drawRect(0,0,k,k);
 
   62     painter.drawRect(k,k,k,k);
 
   65 void ColorGridItem::paintEvent(QPaintEvent *)
 
   67     QPalette pal = this->palette();
 
   68     QPen borderPen(pal.color(QPalette::WindowText));
 
   70     QPainter painter(
this);
 
   72     painter.setPen(Qt::NoPen);
 
   73     painter.fillRect(0,0,gridWidth, gridWidth, QBrush(Qt::white));
 
   75     if(mColor == QColor(Qt::transparent)){
 
   76         painter.drawPixmap(0,0,mBackgroundImg);
 
   79         painter.setBrush(mColor);
 
   80         painter.setPen(Qt::NoPen);
 
   81         painter.drawRect(0,0,gridWidth, gridWidth);
 
   85         painter.setPen(borderPen);
 
   86         painter.drawRect(0, 0, gridWidth-1, gridWidth-1);
 
   90 void ColorGridItem::enterEvent(QEvent* )
 
   97 void ColorGridItem::leaveEvent(QEvent* )
 
  104 void ColorGridItem::mousePressEvent(QMouseEvent *event)
 
  106     if(event->button() == Qt::RightButton){
 
  107         menu.popup(mapToGlobal(event->pos()));
 
  109         if(color() != Qt::transparent) onColorPicked();
 
  114 QColor ColorGridItem::color()
 
  119 void ColorGridItem::setColor(
const QColor& color)
 
  125 void ColorGridItem::onColorPicked()
 
  127     emit colorPicked(this->mGridId, this->mColor);
 
  130 void ColorGridItem::onColorDroped()
 
  132     emit colorDroped(this->mGridId);
 
  135 void ColorGridItem::onColorCleared()
 
  137     this->setColor(Qt::transparent);
 
  141 QSize ColorGridItem::sizeHint()
 const 
  143     return QSize(gridWidth, gridWidth);
 
  146 QSize ColorGridItem::minimumSizeHint()
 const 
  148     return QSize(gridWidth, gridWidth);