Beispiel #1
0
void changeOneTool::activeImageClick(QMouseEvent* event) {

  const int x = event->x();
  const int y = event->y();
  const int originalImageWidth = parent()->curImage_->originalWidth();
  const int originalImageHeight = parent()->curImage_->originalHeight();
  squareImageLabel* label = parent()->activeSquareLabel();
  const int labelWidth = label->width();
  const int labelHeight = label->height();
  int originalX = (x * originalImageWidth)/labelWidth;
  int originalY = (y * originalImageHeight)/labelHeight;
  const int originalDimension = parent()->curImage_->originalDimension();
  const int boxX = originalX/originalDimension;
  const int boxY = originalY/originalDimension;
  const QRgb oldColor =
    ::colorFromScaledImageCoords(x, y, labelWidth, labelHeight,
                                 parent()->curImage_->image());
  const Qt::MouseButton mouseButton = event->button();
  if (mouseButton == Qt::LeftButton) {
    dragCache_.cacheIsActive = true;
    dragCache_.labelWidth = labelWidth;
    dragCache_.labelHeight = labelHeight;
    dragCache_.imageWidth = originalImageWidth;
    dragCache_.imageHeight = originalImageHeight;
    dragCache_.squareDim = originalDimension;
    // this won't be used until we actually drag
    QMatrix matrix;
    matrix.scale(static_cast<qreal>(labelWidth)/originalImageWidth,
                 static_cast<qreal>(labelHeight)/originalImageHeight);
    matrix = QImage::trueMatrix(matrix,
                                originalImageWidth, originalImageHeight);
    dragCache_.matrix = matrix;
    const pairOfInts boxCoordinates(boxX, boxY);
    const flossColor newColor = parent()->toolDock_->getToolLabelColor();
    dragCache_.newColor = newColor;
    dragCache_.squaresVisited.insert(boxCoordinates);
    label->setSquaresColor(newColor.qrgb());
    label->addSquare(boxCoordinates);
    const int d = parent()->roughCurDim();
    label->update(x-d, y-d, 2*d, 2*d);
  }
  else if (mouseButton == Qt::MidButton) {
    // make originals upper left corner of the square clicked
    originalX = boxX * originalDimension;
    originalY = boxY * originalDimension;
    parent()->requestSquareColor(originalX, originalY,
                                 originalDimension, oldColor);
  }
  else if (mouseButton == Qt::RightButton) {
    updateToolColor(oldColor);
  }
}
dockListUpdate mutableSquareImageContainer::fillRegion(int x, int y,
                                                       flossColor newColor) {

  const triC oldColor = image_.pixel(x, y);
  if (newColor == oldColor) {
    return dockListUpdate();
  }
  const QVector<pairOfInts> coordinates =
    ::fillRegion(&image_, x, y, newColor.qrgb(), originalDimension_);

  const bool colorAdded = addColor(newColor);
  const flossColor oldFlossColor = getFlossColorFromColor(oldColor);
  addToHistory(historyItemPtr(new fillRegionHistoryItem(oldFlossColor,
                                                        newColor,
                                                        colorAdded,
                                                        coordinates)));
  colorListCheckNeeded_ = true;
  return dockListUpdate(newColor.color(), colorAdded);
}
dockListUpdate mutableSquareImageContainer::
commitChangeOneDrag(const QSet<pairOfInts>& squares, flossColor newColor) {

  const QRgb newRgbColor = newColor.qrgb();
  const bool colorAdded = addColor(newColor);
  QVector<pixel> historyPixels;
  QVector<triC> pixelColors;
  for (QSet<pairOfInts>::const_iterator it = squares.begin(),
          end = squares.end(); it != end; ++it) {
    const int x = it->x() * originalDimension_;
    const int y = it->y() * originalDimension_;
    const QRgb thisColor = image_.pixel(x, y);
    pixelColors.push_back(thisColor);
    historyPixels.push_back(pixel(thisColor, pairOfInts(x, y)));
  }
  ::changeBlocks(&image_, historyPixels, newRgbColor, originalDimension_);
  addToHistory(historyItemPtr(new changeOneHistoryItem(newColor, colorAdded,
                                                       historyPixels)));
  colorListCheckNeeded_ = true;
  return dockListUpdate(newRgbColor, colorAdded);
}
Beispiel #4
0
void squareToolDock::setToolLabelColor(const flossColor& color) {

  fillToolColorSwatch(color.qrgb());
}