예제 #1
0
void SymbolWidget::updateSample()
{
    SymbolThumbnail thumbnailCreator(60, 4);
    thumbnailCreator.setBackground(Qt::white);
    QPixmap sample = thumbnailCreator.createSymbolThumbnail(symbol(), m_type);
    m_sample->setPixmap(sample);
    m_sample->setMinimumSize(sample.rect().size());
}
예제 #2
0
int main(int argc, char** argv) {
  srand(time(NULL));  // init rand;

#if PORTAL
  Portal p(Segment(10, 40, 10, 20), Segment(40, 10, 20, 10));
  std::vector<Segment> lines(p.deviateLine(Segment(20, 40, 0, 30)));
  for (const Segment& line: lines)
    std::cerr << line << std::endl;
#endif

#if Thumbnail


  QApplication app(argc, argv);

  PolygonList polygonList;
  //polygonList << poc::Polygon(30, 250, 21, 260, 5);
  poc::Polygon polygon;
  polygon << Point2d(55, 55)
  << Point2d(455, 55)
  << Point2d(455, 455)
  << Point2d(155, 455)
  << Point2d(155, 255)
  << Point2d(255, 255)
  << Point2d(255, 355)
  << Point2d(355, 355)
  << Point2d(355, 155)
  << Point2d(55, 155);
  polygonList << polygon;
  qDebug() << polygonList;
  ThumbnailCreator thumbnailCreator(polygonList);
  QImage thumbnail = thumbnailCreator.makeThumbnail();

  QLabel* label = new QLabel;
  label->setPixmap(QPixmap::fromImage(thumbnail));
  label->show();

  return app.exec();
#endif

#if TESTPOINT
  Test::test<< Point2d();
#endif

#if TESTVECTOR
  Test::testVector2d();
#endif

#if TESTPOLYGON
  Test::testPolygon();
#endif

#if GUI
  QApplication app(argc, argv);

//  QFontDatabase::addApplicationFont("../PieceOfCake/fonts/edosz.ttf");
//  QFontDatabase::addApplicationFont("../PieceOfCake/fonts/watermark.ttf");

  qmlRegisterType<GameInfo>("gameinfo", 1, 0, "GameInfo");
  qmlRegisterType<LevelInfo>("levelinfo", 1, 0, "LevelInfo");

  MainWindow window;
  window.show();

  return app.exec();
#endif

#if QML
  QGuiApplication app(argc, argv);

  QQmlApplicationEngine engine;
  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

  return app.exec();
#endif

#if GNUPLOT
  // poc::Polygon polygon;
  // polygon << << Point2d() << << Point2d(0, 1) << << Point2d(1, 1) << << Point2d(1);

  poc::Polygon polygon(0, 100, 0, 100, 7);
  //    std::vector<Point2d> vertices = polygon.getVertices();
  //    for (unsigned int k = 0; k < vertices.size(); ++k)
  //        std::cerr << vertices.at(k).getX() << " " << vertices.at(k).getY() << " " << -10 << std::endl;

  float size = 300;
  float delta = 10;
  int max = size/delta;

  float** matrix = polygon.surface(size, delta);
  for (int i = 0; i < max; ++i) {
    for (int j = 0; j < max; ++j) {
      std::cerr << i << " " << j << " " << matrix[i][j] << std::endl;
    }
    delete[] matrix[i];
  }
  delete[] matrix;

#endif

#if XML
  Test::testXML();
#else
  return EXIT_SUCCESS;
#endif
}
void LevelDesignerController::saveLevel(const QString& fileName) {
  // Write xml file
  ParserXML parser;
  parser.initFileName(fileName);

  PolygonList polygonList(_model->getPolygonList());
  for (const poc::Polygon& polygon: polygonList) {
    parser.addPolygon(polygon);
  }

  parser.setLinesCount(_model->getLinesCount());
  parser.setPartsCount(_model->getPartsCount());
  parser.setMaxGapToWin(_model->getMaxGapToWin());
  parser.setStarsCount(0);
  parser.setTolerances(0);

  parser.writeXML();

  // Rename fileName
  QString newFileName = "resources/levels/"+fileName.split("resources/levels/").last();

  // Create thumbbnail
  ThumbnailCreator thumbnailCreator(_model->getPolygonList());
  QString thumbnailName = newFileName;
  thumbnailName.replace(QRegExp(".xml"), ".png");
  thumbnailCreator.makeThumbnail("../PieceOfCake/"+thumbnailName);

  // Update levels file
  QStringList levelPackPath = newFileName.split("/");
  levelPackPath.removeLast();
  QString xmlFileName = "../PieceOfCake/"+levelPackPath.join("/")+"/levels.xml";

  QFile XMLDoc(xmlFileName);
  if (!XMLDoc.exists()) {
    qDebug() << "Error:" << xmlFileName << "file not found";
    return;
  }

  if(!XMLDoc.open(QIODevice::ReadOnly | QIODevice::Text)) {
    qDebug() << "Cannot open XML file in LevelDesignerController::saveLevel(const QString& fileName)";
    return;
  }

  QDomDocument doc("PieceOfCakeLevelsML");
  if(!doc.setContent(&XMLDoc)) {
    XMLDoc.close();
    qDebug() << "Cannot set content of dom in LevelDesignerController::saveLevel(const QString& fileName)";
    return;
  }

  XMLDoc.close();

  QDomElement root = doc.firstChildElement("levels");

  QDomNodeList levelList = root.elementsByTagName("level");
  for (int k = 0; k < levelList.size(); ++k) {
    QDomElement level = levelList.at(k).toElement();
    // No need to register several times the same level,
    // especially if this method is called to update thumbnail and level.xml file
    if (level.attribute("image").split("/").last() == thumbnailName.split("/").last()) {
      qDebug() << "No need to update levels.xml";
      return;
    }
  }

  QDomElement level = doc.createElement("level");
  level.setAttribute("id", root.elementsByTagName("level").size());
  level.setAttribute("stars", "0");
  level.setAttribute("image", thumbnailName);
  level.setAttribute("name", newFileName);

  root.appendChild(level);

  if(!XMLDoc.open(QIODevice::WriteOnly | QIODevice::Text)) {
    qDebug() << "Cannot open XML file in LevelDesignerController::saveLevel(const QString& fileName)";
    return;
  }

  QTextStream inFile(&XMLDoc);
  inFile << doc.toString(2);

  XMLDoc.close();
}