Esempio n. 1
0
void Progress::Dialog::OnSetRange ()
{
	if (_dlgHandle.IsNull ())
	{
		// Create progress meter dialog
		if (_parentWin.IsNull ())
		{
			// Showing progress meter on the desktop -- don't delay
			// progress meter dialog display
			_dlgData.SetInitialDelay (0);
		}
		std::auto_ptr<::Dialog::ModelessController> ctrl
			(new Progress::DialogController (*GetControlHandler (),
											 _msgPrepro,
											 _dlgId));
		::Dialog::ModelessMaker progressMeter (*GetControlHandler (), ctrl);
		::Dialog::Template dlgTemplate;
		CreateDialogTemplate (dlgTemplate);
		_dlgHandle = progressMeter.Create (_parentWin, dlgTemplate);
	}
	else
	{
		// Progress meter dialog already created
		Progress::CtrlHandler * ctrlHandler = GetControlHandler ();
		if (ctrlHandler != 0)
			ctrlHandler->Refresh ();
	}
}
Esempio n. 2
0
bool patternPrinter::drawPatternPages() {

  if (!portrait_) { // draw landscape
    int temp = printerWidth_;
    printerWidth_ = printerHeight_;
    printerHeight_ = temp;
    // you can't change the orientation under Windows, so we'll just
    // draw sideways instead
    painter_.rotate(-90);
    painter_.translate(-printerWidth_, 0);
  }

  painter_.setPen(QPen(Qt::black, 1));
  // image width to use on a particular page (last page may be smaller)
  int widthToUse = widthPerPage_;
  int heightToUse = heightPerPage_;
  const int f = 5; // fudge room for grid number separation from the grid
  const QHash<QRgb, QPixmap> symbolMap =
    imageContainer_->symbolsNoBorder(pdfSymbolDim_);
  QProgressDialog progressMeter(QObject::tr("Creating pdf..."),
                                QObject::tr("Cancel"), 0,
                                (xPages_ * yPages_)/5);
  progressMeter.setMinimumDuration(4000);
  progressMeter.setWindowModality(Qt::WindowModal);
  progressMeter.move(PROGRESS_X_COORDINATE, PROGRESS_Y_COORDINATE);
  progressMeter.show();
  for (int x = 1; x <= xPages_; ++x) {
    for (int y = 1; y <= yPages_; ++y) {
      if (progressMeter.wasCanceled()) {
        return true;
      }
      const int pageNum = yPages_ * (x-1) + y;
      // draw the page number
      painter_.drawText(printerWidth_ - sWidth(pageNum), sHeight(pageNum) - 5,
                        ::itoqs(pageNum));
      if (pageNum % 5 == 0) {
        progressMeter.setValue(pageNum / 5);
      }
      widthToUse = widthPerPage_;
      if (x * widthPerPage_ > patternImageWidth_) {
        widthToUse = patternImageWidth_ - (x-1) * widthPerPage_;
      }
      heightToUse = heightPerPage_;
      if (y * heightPerPage_ > patternImageHeight_) {
        heightToUse = patternImageHeight_ - (y-1) * heightPerPage_;
      }

      // draw this page's image
      const int patternXBoxStart = ((x-1) * widthPerPage_)/pdfSymbolDim_;
      const int patternXBoxEnd = patternXBoxStart + (widthToUse/pdfSymbolDim_);
      const int patternYBoxStart = ((y-1) * heightPerPage_)/pdfSymbolDim_;
      const int patternYBoxEnd = patternYBoxStart + (heightToUse/pdfSymbolDim_);
      for (int j = patternYBoxStart, jj = 0; j < patternYBoxEnd;
            ++j, ++jj) {
        for (int i = patternXBoxStart, ii = 0; i < patternXBoxEnd;
              ++i, ++ii) {
          const QPixmap& thisSymbol =
            symbolMap[squareImage_.pixel(i * squareDim_, j * squareDim_)];
          painter_.drawPixmap(margin_ + ii * pdfSymbolDim_,
                              margin_ + jj * pdfSymbolDim_, thisSymbol);
        }
      }

      //// draw grid lines and counts (thick every 5, thin every 1)
      const int thickCount = 5;
      //// x grid lines
      painter_.setPen(QPen(Qt::black, 1));
      int tx = 0;
      //// draw the thin x grid lines
      while (tx * pdfSymbolDim_ <= widthToUse) {
        painter_.drawLine(tx * pdfSymbolDim_ + margin_, margin_,
                          tx * pdfSymbolDim_ + margin_, heightToUse + margin_);
        ++tx;
      }
      bool lastXLine = false;
      if ((x-1) * widthPerPage_ + tx * pdfSymbolDim_ > patternImageWidth_) {
        lastXLine = true; // the last x line is drawn on this page
      }
      //// draw the thin y grid lines
      int ty = 0;
      while (ty * pdfSymbolDim_ <= heightToUse) {
        painter_.drawLine(margin_, ty * pdfSymbolDim_ + margin_,
                          widthToUse + margin_, ty * pdfSymbolDim_ + margin_);
        ++ty;
      }
      bool lastYLine = false;
      if ((y-1) * heightPerPage_ + ty * pdfSymbolDim_ >
          patternImageHeight_) {
        lastYLine = true; // the last y line is drawn on this page
      }

      //// thick lines
      tx = 0; // x grid count for this page
      if ((x-1) * xBoxesPerPage_ % thickCount != 0) {
        // to the next multiple of thickCount
        tx = thickCount - ((x-1) * xBoxesPerPage_ % thickCount);
      }

      const int savedTx = tx;
      // draw the x grid counts
      painter_.setPen(QPen(Qt::black, 1));
      while (tx * pdfSymbolDim_ <= widthToUse) {
        const int tgridx = (x-1) * xBoxesPerPage_ + tx;
        if (tx == 0) { // avoid collision
          painter_.drawText(margin_ + tx * pdfSymbolDim_, margin_ - f,
                            ::itoqs(tgridx));
        }
        else {
          painter_.drawText(margin_ + tx * pdfSymbolDim_ - sWidth(tgridx),
                            margin_ - f, ::itoqs(tgridx));
        }
        tx += thickCount;
      }

      // draw the thick x grid lines
      tx = savedTx;
      painter_.setPen(QPen(Qt::black, 3));
      while (tx * pdfSymbolDim_ <= widthToUse) {
        painter_.drawLine(tx * pdfSymbolDim_ + margin_, margin_,
                          tx * pdfSymbolDim_ + margin_, heightToUse + margin_);
        tx += thickCount;
      }
      tx -= thickCount;

      // draw the final line
      if (lastXLine) {
        painter_.setPen(QPen(Qt::black, 1));
        painter_.drawText(margin_ + widthToUse - sWidth(xBoxes_), margin_ - f,
                          ::itoqs(xBoxes_));
        painter_.setPen(QPen(Qt::black, 3));
        painter_.drawLine(widthToUse + margin_, margin_, widthToUse + margin_,
                          heightToUse + margin_);
      }

      ty = 0; // y grid count for this page
      if ((y-1) * yBoxesPerPage_ % thickCount != 0) {
        // to the next multiple of 5
        ty = thickCount - ((y-1) * yBoxesPerPage_ % thickCount);
      }

      const int savedTy = ty;
      // draw the y grid counts
      painter_.setPen(QPen(Qt::black, 1));
      while (ty * pdfSymbolDim_ <= heightToUse) {
        const int tgridy = (y-1) * yBoxesPerPage_ + ty;
        if (ty == 0) { // avoid confusion
          painter_.drawText(margin_ - sWidth(tgridy) - f,
                            ty * pdfSymbolDim_ + margin_ + sHeight(tgridy),
                            ::itoqs(tgridy));
        }
        else {
          painter_.drawText(margin_ - sWidth(tgridy) - f,
                            ty * pdfSymbolDim_ + margin_,
                            ::itoqs(tgridy));
        }
        ty += thickCount;
      }

      // draw the thick y grid lines
      ty = savedTy;
      painter_.setPen(QPen(Qt::black, 3));
      while (ty * pdfSymbolDim_ <= heightToUse) {
        painter_.drawLine(margin_, ty * pdfSymbolDim_ + margin_,
                          widthToUse + margin_, ty * pdfSymbolDim_ + margin_);
        ty += thickCount;
      }

      // draw the final line
      if (lastYLine) {
        painter_.setPen(QPen(Qt::black, 1));
        painter_.drawText(margin_ - sWidth(yBoxes_) - f, heightToUse + margin_,
                          ::itoqs(yBoxes_));
        painter_.setPen(QPen(Qt::black, 3));
        painter_.drawLine(margin_, heightToUse + margin_, widthToUse + margin_,
                          heightToUse + margin_);
      }

      painter_.setPen(QPen(Qt::black, 1)); // reset

      if (x < xPages_ || y < yPages_) {
        printer_.newPage();
      }
    }
  }
  return false;
}
Esempio n. 3
0
void windowManager::openProject() {

  //const QString fileString = "test.out";
  const QString fileString =
    QFileDialog::getOpenFileName(activeWindow(), tr("Open project"), ".",
                                 "Cstitch files (*.xst)\nAll files (*.*)");
  if (fileString.isEmpty()) {
    return;
  }

  QFile inFile(fileString);
  inFile.open(QIODevice::ReadOnly);
  // the save file starts with xml text, so read that first
  QTextStream textInStream(&inFile);
  QString inString;
  inString = textInStream.readLine() + "\n";
  // (A day after the initial release I changed the program name from
  // stitch to cstitch, so check for either...)
  QRegExp rx("^<(cstitch|stitch) version=");
  rx.indexIn(inString);
  const QString programName = rx.cap(1);
  if (programName != "cstitch" && programName != "stitch") { // uh oh
    QMessageBox::critical(NULL, tr("Bad project file"),
                          tr("Sorry, ") + fileString +
                          tr(" is not a valid project file ") +
                          tr("(diagnostic: wrong first line)"));
    return;
  }

  int lineCount = 0;
  const int maxLineCount = 100000;
  const QString endTag = "</" + programName + ">";
  QString thisString = "";
  do {
    thisString = textInStream.readLine();
    inString += thisString + "\n";
    ++lineCount;
    if (lineCount > maxLineCount) {
      QMessageBox::critical(NULL, tr("Bad project file"),
                            tr("Sorry, ") + fileString +
                            tr(" appears to be corrupted ") +
                            tr("(diagnostic: bad separator)"));
      return;
    }
  } while (thisString != endTag);

  QDomDocument doc;
  const bool xmlLoadSuccess = doc.setContent(inString);
  if (!xmlLoadSuccess) {
    QMessageBox::critical(NULL, tr("Bad project file"),
                          tr("Sorry, ") + fileString +
                          tr(" appears to be corrupted ") +
                          tr("(diagnostic: parse failed)"));
    return;
  }
  // a blank line between the xml and the image
  inString += textInStream.readLine() + "\n";

  // hide everything except progress meters while we regenerate this project
  hideWindows_ = true;
  hideWindows();

  // how many total images are we restoring?
  int imageCount = 1; // one colorChooser image
  imageCount += doc.elementsByTagName("color_compare_image").size();
  imageCount += doc.elementsByTagName("square_window_image").size();
  imageCount += doc.elementsByTagName("pattern_window_image").size();
  groupProgressDialog progressMeter(imageCount);
  progressMeter.setMinimumDuration(2000);
  progressMeter.setWindowModality(Qt::WindowModal);
  progressMeter.show();
  progressMeter.bumpCount();
  altMeter::setGroupMeter(&progressMeter);

  // read the image file name
  const QString fileName = ::getElementText(doc, "image_name");
  // read the project version number
  setProjectVersion(::getElementAttribute(doc, "cstitch", "version"));
  // now read the binary data image
  inFile.seek(inString.length());
  QDataStream imageStream(&inFile);
  QImage newImage;
  imageStream >> newImage;
  inFile.seek(inString.length());
  QDataStream imageData(&inFile);
  QByteArray imageByteArray;
  imageData >> imageByteArray;
  reset(newImage, imageByteArray, fileName);

  //// colorChooser
  colorChooser_.window()->setNewImage(newImage);
  progressMeter.bumpCount();

  //// colorCompare
  QDomElement colorCompareElement =
    doc.elementsByTagName("color_compare").item(0).toElement();
  if (!colorCompareElement.isNull()) {
    colorChooser* colorChooserObject = colorChooser_.window();
    QDomNodeList compareImagesList(colorCompareElement.
                                   elementsByTagName("color_compare_image"));
    for (int i = 0, size = compareImagesList.size(); i < size; ++i) {
      QDomElement thisCompareElement(compareImagesList.item(i).toElement());
      const int hiddenColorCompareIndex = colorChooserObject->
        recreateImage(colorCompareSaver(thisCompareElement));
      progressMeter.bumpCount();
      //// squareWindow
      colorCompare* colorCompareObject = colorCompareWindow_.window();
      QDomNodeList squareImagesList(thisCompareElement.
                                    elementsByTagName("square_window_image"));
      if (!squareImagesList.isEmpty()) {
        for (int ii = 0, iiSize = squareImagesList.size(); ii < iiSize; ++ii) {
          QDomElement thisSquareElement(squareImagesList.item(ii).toElement());
          const int hiddenSquareImageIndex = colorCompareObject->
            recreateImage(squareWindowSaver(thisSquareElement));
          progressMeter.bumpCount();
          squareWindow* squareWindowObject = squareWindow_.window();
          //// patternWindow
          // restore this square image's children before restoring its history
          // (the children may have their own different histories)
          QDomNodeList
            patternImageList(thisSquareElement.
                             elementsByTagName("pattern_window_image"));
          if (!patternImageList.isEmpty()) {
            for (int iii = 0, iiiSize = patternImageList.size();
                 iii < iiiSize; ++iii) {
              QDomElement thisPatternElement(patternImageList.item(iii).
                                             toElement());
              squareWindowObject->
                recreatePatternImage(patternWindowSaver(thisPatternElement));
              patternWindow_.window()->updateHistory(thisPatternElement);
              progressMeter.bumpCount();
            }
          }
          squareWindowObject->updateImageHistory(thisSquareElement);
          // if this image was only created so that one of its children could be
          // recreated, remove it (its data has already been stored away)
          if (hiddenSquareImageIndex != -1) {
            squareWindowObject->removeImage(hiddenSquareImageIndex);
          }
        }
      }
      // if this image was only created so that one of its children could be
      // recreated, remove it (its data has already been stored away)
      if (hiddenColorCompareIndex != -1) {
        colorCompareObject->removeImage(hiddenColorCompareIndex);
      }
    }
  }

  //// restore window wide settings that are independent of a particular image
  QDomElement windowGlobals(doc.elementsByTagName("global_settings").
                            item(0).toElement());
  if (colorChooserAction_->isEnabled() && colorChooser_.window()) {
    colorChooser_.window()->updateCurrentSettings(windowGlobals);
  }
  if (colorCompareAction_->isEnabled() && colorCompareWindow_.window()) {
    colorCompareWindow_.window()->updateCurrentSettings(windowGlobals);
  }
  if (squareWindowAction_->isEnabled() && squareWindow_.window()) {
    squareWindow_.window()->updateCurrentSettings(windowGlobals);
    squareWindow_.window()->checkAllColorLists();
  }
  if (patternWindowAction_->isEnabled() && patternWindow_.window()) {
    patternWindow_.window()->updateCurrentSettings(windowGlobals);
  }
  // read the image number of colors (before the reset)
  const int colorCount = ::getElementText(doc, "color_count").toInt();
  originalImageColorCount_ = colorCount;
  // call while hideWindows_ (if colorCount wasn't 0 it won't be recalculated)
  startOriginalImageColorCount();
  hideWindows_ = false;
  altMeter::setGroupMeter(NULL);
  projectFilename_ = fileString;
  setWindowTitles(QFileInfo(projectFilename_).fileName());
  setNewWidgetGeometryAndRaise(colorChooser_.window());
}