1
0

gradientchoosedialog.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "gradientchoosedialog.h"
  2. #include <QtXml/QDomDocument>
  3. #include <QFile>
  4. #include <QResource>
  5. #include <QDir>
  6. //resource hacks
  7. static const std::string clouds_xml = "";
  8. std::map<std::string, std::string> GradientChooseDialog::presets {
  9. { "clouds", clouds_xml }
  10. };
  11. GradientChooseDialog::GradientChooseDialog()
  12. {
  13. gcd.setupUi(this);
  14. QFont f("unexistent");
  15. f.setStyleHint(QFont::Monospace);
  16. gcd.plainTextEdit->setFont(f);
  17. QFile qf(":/Almond/clouds");
  18. QString str = QString::fromUtf8(qf.readAll());
  19. printf("%s\n", str.toStdString().c_str());
  20. gcd.presets->addItem("clouds");
  21. gcd.presets->addItem("none");
  22. }
  23. #if 0
  24. <gradient>
  25. <color r="230" g="10" b="40" p="0" />
  26. <color r="30" g="230" b="80" p="100" />
  27. <color r="20" g="120" b="210" p="500" />
  28. </gradient>
  29. #endif
  30. void GradientChooseDialog::on_buttonBox_accepted()
  31. {
  32. QDomDocument xsr;
  33. xsr.setContent(gcd.plainTextEdit->toPlainText());
  34. auto elem = xsr.documentElement();
  35. auto colors = xsr.elementsByTagName("color");
  36. std::vector<std::pair<RGBColor, float>> colorArr;
  37. for (int i = 0; i < colors.length(); ++i) {
  38. auto child = colors.item(i).toElement();
  39. uint8_t r = child.attributeNode("r").value().toInt();
  40. uint8_t g = child.attributeNode("g").value().toInt();
  41. uint8_t b = child.attributeNode("b").value().toInt();
  42. float p = child.attributeNode("p").value().toInt();
  43. printf("rgb (%s): %d, %d, %d\n", child.text().toUtf8().data(), r, g, b);
  44. colorArr.push_back({ { r, g, b }, p });
  45. }
  46. chosenGradient = std::make_unique<Gradient>(colorArr);
  47. printf("yee: %s\n", elem.text().toUtf8().data());
  48. fflush(stdout);
  49. }
  50. void GradientChooseDialog::on_buttonBox_clicked(QAbstractButton *button)
  51. {
  52. }
  53. void GradientChooseDialog::on_presets_currentIndexChanged(const QString& index)
  54. {
  55. QResource gr(":/gradients/clouds.xml");
  56. QString str = QString::fromUtf8(reinterpret_cast<const char*>(gr.data()));
  57. emit gcd.plainTextEdit->setPlainText(str);
  58. }