main.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /****************************************************************************
  2. ** Artriculate: Art comes tumbling down
  3. ** Copyright (C) 2016 Chaos Reins
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ****************************************************************************/
  18. #include "picturemodel.h"
  19. #include <QGuiApplication>
  20. #include <QQmlApplicationEngine>
  21. #include <QQmlContext>
  22. #include <QSettings>
  23. #include <QSurfaceFormat>
  24. #include <QTimer>
  25. #include <QDir>
  26. #include <QFile>
  27. #include <QFileInfo>
  28. #include <QTextStream>
  29. #include <QDebug>
  30. class FileReader : public QObject {
  31. Q_OBJECT
  32. public:
  33. FileReader(QObject *p) : QObject(p) { /**/ }
  34. Q_INVOKABLE static QString readFile(const QString &fileName)
  35. {
  36. QString content;
  37. QFile file(fileName);
  38. if (file.open(QIODevice::ReadOnly)) {
  39. QTextStream stream(&file);
  40. content = stream.readAll();
  41. }
  42. return content;
  43. }
  44. };
  45. int main(int argc, char *argv[])
  46. {
  47. qsrand(time(NULL));
  48. QGuiApplication app(argc, argv);
  49. app.setOrganizationName("Chaos Reins");
  50. app.setApplicationName("Articulate");
  51. QSettings settings;
  52. if (settings.value("force32bpp", true).toBool()) {
  53. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  54. format.setAlphaBufferSize(8);
  55. format.setRedBufferSize(8);
  56. format.setGreenBufferSize(8);
  57. format.setBlueBufferSize(8);
  58. QSurfaceFormat::setDefaultFormat(format);
  59. }
  60. if (settings.value("forceSingleBuffer", false).toBool()) {
  61. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  62. format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
  63. QSurfaceFormat::setDefaultFormat(format);
  64. }
  65. if (settings.value("forceTripleBuffer", false).toBool()) {
  66. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  67. format.setSwapBehavior(QSurfaceFormat::TripleBuffer);
  68. QSurfaceFormat::setDefaultFormat(format);
  69. }
  70. QQmlApplicationEngine engine;
  71. qmlRegisterType<PictureModel>("PictureModel", 1, 0, "PictureModel");
  72. engine.rootContext()->setContextProperty("fileReader", new FileReader(&app));
  73. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  74. return app.exec();
  75. }
  76. #include "main.moc"