1
0

gradientchoosedialog.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "gradientchoosedialog.h"
  2. #include <QtXml/QDomDocument>
  3. GradientChooseDialog::GradientChooseDialog()
  4. {
  5. gcd.setupUi(this);
  6. QFont f("unexistent");
  7. f.setStyleHint(QFont::Monospace);
  8. gcd.plainTextEdit->setFont(f);
  9. }
  10. #if 0
  11. <gradient>
  12. <color r="230" g="10" b="40" p="0" />
  13. <color r="30" g="230" b="80" p="100" />
  14. <color r="20" g="120" b="210" p="500" />
  15. </gradient>
  16. #endif
  17. void GradientChooseDialog::on_buttonBox_accepted()
  18. {
  19. QDomDocument xsr;
  20. xsr.setContent(gcd.plainTextEdit->toPlainText());
  21. auto elem = xsr.documentElement();
  22. auto colors = xsr.elementsByTagName("color");
  23. std::vector<std::pair<RGBColor, float>> colorArr;
  24. for (int i = 0; i < colors.length(); ++i) {
  25. auto child = colors.item(i).toElement();
  26. uint8_t r = child.attributeNode("r").value().toInt();
  27. uint8_t g = child.attributeNode("g").value().toInt();
  28. uint8_t b = child.attributeNode("b").value().toInt();
  29. float p = child.attributeNode("p").value().toInt();
  30. printf("rgb (%s): %d, %d, %d\n", child.text().toUtf8().data(), r, g, b);
  31. colorArr.push_back({ { r, g, b }, p });
  32. }
  33. chosenGradient = std::make_unique<Gradient>(colorArr);
  34. printf("yee: %s\n", elem.text().toUtf8().data());
  35. fflush(stdout);
  36. }
  37. void GradientChooseDialog::on_buttonBox_clicked(QAbstractButton *button)
  38. {
  39. }