bool imageCompareBase::eventFilter(QObject* watched, QEvent* event) {

  // make sure we setCur on an image click
  if (event->type() == QEvent::FocusIn) {
    if (watched == leftScroll_) {
      setCur(leftImage());
    }
    else {
      setCur(rightImage());
    }
  }
  else if (event->type() == QEvent::KeyPress) {
    QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
    return filterKeyEvent(keyEvent);
  }
  else if (event->type() == QEvent::Wheel) {
    QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
    // shift scroll should give a horizontal scroll
    if (wheelEvent->modifiers() == Qt::ShiftModifier) {
      // must check both the scroll and its viewport
      if (watched == rightScroll_ || watched == rightScroll_->viewport()) {
        rightScroll_->horizontalScrollBar()->event(event);
        return true;
      }
      else if (watched == leftScroll_ || watched == leftScroll_->viewport()) {
        leftScroll_->horizontalScrollBar()->event(event);
        return true;
      }
    }
  }
  return imageSaverWindow::eventFilter(watched, event);
}
bool imageCompareBase::filterKeyEvent(QKeyEvent* event) {

  if (event->key() == Qt::Key_Left &&
      (event->modifiers() & Qt::ShiftModifier) && leftImage() &&
      leftScroll_->isVisible() && curImage() != leftImage()) {
    setCur(leftImage());
    return true;
  }
  else if (event->key() == Qt::Key_Right &&
           (event->modifiers() & Qt::ShiftModifier) && rightImage() &&
           rightScroll_->isVisible() && curImage() != rightImage()) {
    setCur(rightImage());
    return true;
  }
  else if ((event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
           && (event->modifiers() & Qt::ShiftModifier)
           && (leftScroll_->isVisible() || rightScroll_->isVisible())) {
    comboBox* curBox =
      (leftImage() == curImage()) ? leftImageListBox_ : rightImageListBox_;
    if (event->key() == Qt::Key_Up) {
      curBox->moveToPreviousItem();
    }
    else {
      curBox->moveToNextItem();
    }
    return true;
  }
  return false;
}
Exemple #3
0
void render(MATPTR rend, MATPTR matrix)
{
	POINT point = getCur();
	for (int i = 0; i < HEIGHT; ++i)
		for (int j = 0; j < WIDTH; ++j)
			if ((*rend)[i][j] ^ (*matrix)[i][j])
			{
				setCur(j * 2 + 2, i + 1);
				(*rend)[i][j] = (*matrix)[i][j];
				setColor(BLUE);
				(*rend)[i][j] ? printBlock(FULL) : printBlock(EMPTY);
				setColor(NONE);
			}
	setCur(point.x, point.y);
}
void imageCompareBase::showLR(const leftRightAccessor& lra) {

  if (lra.image()) {
    setCur(lra.image());
  } else {
    qWarning() << "No image on show";
  }
}
Exemple #5
0
void patternWindow::processImageListMenu(QAction* action) {

  if (! action->data().isNull() &&
      action->data().canConvert<patternImagePtr>()) {
    patternImagePtr container =
      action->data().value<patternImagePtr>();
    setCur(container);
  }
}
void imageCompareBase::setLeftToOriginalImage() {

  imagePtr container =
    getImageFromIndex(imageNameToIndex(Original()));

  if (container) {
    setLeftImage(container);
    setCur(container);
  }
}
void imageCompareBase::switchSides() {

  if (leftScroll_->isVisible() && rightScroll_->isVisible()) {
    imagePtr tmpContainer;

    tmpContainer = rightImage();
    setRightImage(leftImage());
    setLeftImage(tmpContainer);

    // setCur on both sides to make sure they're both updated
    if (curImage() == leftImage()) {
      setCur(rightImage());
      setCur(leftImage());
    }
    else {
      setCur(leftImage());
      setCur(rightImage());
    }
  }
}
void imageCompareBase::hideLR(const leftRightAccessor& lra) {

  lra.scroll()->hide();
  lra.toolbarLabel()->off();
  lra.showHideAction()->setEnabled(true);
  lra.showHideAction()->setChecked(false);
  if (lra.oppositeScroll()->isVisible()) {
    setCur(lra.oppositeImage());
  }
  else {
    qWarning() << "Failure in hideLR" << lra.image()->name();
    showLR(lra);
  }
}
void imageCompareBase::deleteLR(const leftRightAccessor& lra) {

  // don't delete original
  const QString imageName = lra.image()->name();
  if (!lra.image()->isOriginal()) {
    deleteImageActions(imageName);
    // determine the replacement image
    comboBox* box = lra.imageListBox();
    box->removeItem(box->findText(imageName));
    QString replacement;
    if (box->findText(Original()) != -1) {
      replacement = Original();
    }
    else if (box->count() > 0) {
      // the most recent image
      replacement = box->itemText(box->count() - 1);
    }
    if (!replacement.isNull()) {
      if (leftImage() && leftImage()->name() == imageName) {
        setLeftImage(getImageFromName(replacement));
        setCur(leftImage());
      }
      else if (rightImage() && rightImage()->name() == imageName) {
        setRightImage(getImageFromName(replacement));
        setCur(rightImage());
      }
      else {
        qWarning() << "Deleting an image not shown:" << imageName;
      }
    }
    else {
      imageListEmpty();
      return;
    }
  }
}
Exemple #10
0
QString patternWindow::updateCurrentSettings(const QDomElement& xml) {

  QDomElement settings(xml.firstChildElement("pattern_window_settings"));
  if (settings.isNull()) {
    return QString();
  }
  imageLabel_->setGridColor(::xmlStringToRgb(::getElementText(settings,
                                                           "grid_color")));
  processGridChange(::stringToBool(::getElementText(settings, "grid_on")));


  // TODO: De-duplicate this from the imageCompareBase version.  :-(
  // Seems like imagePtr and patternImagePtr should be related, but they're not
  // (because imageContainer and patternImageContainer aren't either, and really
  // don't share a common interface, which is what makes this a mess), and so
  // functions here "common" to imageCompareBase and patternWindow like
  // getImageFromIndex and setCur can't be virtualized into a common base.
  // getImageFromIndex could/maybe should be templated and factored down, but
  // setCur can't be - we could template this code as well and pass a
  // doubly-templated functor to call the right setCur on the right object, but
  // yuk.  Live with the duplication for now.
  QString errorMessage;
  if (!settings.firstChildElement("current_index").isNull()) {
    // KEEP THIS IN SYNC WITH imageCompareBase
    bool parseOk = false;
    const int curIndex =
      ::getElementText(settings, "current_index").toInt(&parseOk);
    if (parseOk) {
      patternImagePtr curImage = getImageFromIndex(curIndex);
      if (curImage) {
        setCur(curImage);
      }
      else {
        errorMessage +=
          tr("Pattern Window setting error(s):<br />"
             "Image Missing error: image %1").arg(curIndex);
      }
    }
    else {
      errorMessage += tr("Pattern Window setting error(s):<br />"
                         "Parse error parsing \"%1\" for index")
        .arg(::getElementText(settings, "current_index"));
    }
  }

  return errorMessage;
}
Exemple #11
0
void patternWindow::addImage(const QImage& squareImage, int squareDimension,
                             const QVector<flossColor>& colors, QRgb gridColor,
                             int imageIndex) {

  patternImageContainer* container =
    new patternImageContainer(squareImage, imageNameFromIndex(imageIndex),
                              squareDimension, basePatternDim_, colors);
  const patternImagePtr imagePtr(container);
  connect(container, SIGNAL(symbolChanged(QRgb , const QPixmap& )),
          listDock_, SLOT(changeSymbol(QRgb , const QPixmap& )));
  QAction* menuAction = new QAction(container->name(), this);
  menuAction->setData(QVariant::fromValue(imagePtr));
  imageListMenu_->addAction(menuAction);
  imageListBox_->addItem(container->name());
  imageLabel_->setGridColor(gridColor);
  setCur(imagePtr);
}
Exemple #12
0
void imageCompareBase::
processImageMenuTriggerLR(QAction* action, const leftRightAccessor& lra) {

  if (!action->data().isNull()) {
    imagePtr container = action->data().value<imagePtr>();
    if (lra.image() == leftImage()) {
      setLeftImage(container);
    }
    else if (lra.image() == rightImage()) {
      setRightImage(container);
    }
    else {
      qWarning() << "Left/right mismatch:" << lra.image() <<
        leftImage() << rightImage();
      return;
    }
    setCur(container);
  }
}
void patternWindow::updateCurrentSettings(const QDomElement& xml) {

  QDomElement settings(xml.firstChildElement("pattern_window_settings"));
  if (settings.isNull()) {
    return;
  }
  imageLabel_->setGridColor(::xmlStringToRgb(::getElementText(settings,
                                                           "grid_color")));
  processGridChange(::stringToBool(::getElementText(settings, "grid_on")));
  const int currentIndex =
    ::getElementText(settings, "current_index").toInt();
  patternImagePtr container = getImageFromIndex(currentIndex);
  if (container) {
    setCur(container);
  }
  else {
    qWarning() << "Misplaced container on patternUpdateSettings:" <<
      currentIndex;
  }
}
Exemple #14
0
void patternWindow::processDelete() {

  QAction* action =
    ::actionFromImageName(imageListMenu_->actions(),
                          findPatternActionName(curImage_->name()));
  delete action;
  imageListBox_->removeItem(imageListBox_->findText(curImage_->name()));
  int removedImageIndex = imageNameToIndex(curImage_->name());
  curImage_ = patternImagePtr(NULL);
  winManager()->patternWindowImageDeleted(removedImageIndex);
  // find a new image - just show the last image since we have no
  // reason to favor any particular image
  const QAction* lastAction = imageListMenu_->actions().last();
  if (! lastAction->data().isNull() &&
      lastAction->data().canConvert<patternImagePtr>()) {
    setCur(lastAction->data().value<patternImagePtr>());
  }
  else {
    // close up shop if there are no images left
    hide();
    winManager()->patternWindowEmpty();
  }
}
Exemple #15
0
void imageCompareBase::focusLR(const leftRightAccessor& lra) {

  if (lra.image()) {
    setCur(lra.image());
  }
}