window-importer.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /******************************************************************************
  2. Copyright (C) 2019-2020 by Dillon Pentz <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include "obs-app.hpp"
  16. #include "window-basic-main.hpp"
  17. #include <QPointer>
  18. #include <QStyledItemDelegate>
  19. #include <QFileInfo>
  20. #include "ui_OBSImporter.h"
  21. class ImporterModel;
  22. class OBSImporter : public QDialog {
  23. Q_OBJECT
  24. QPointer<ImporterModel> optionsModel;
  25. std::unique_ptr<Ui::OBSImporter> ui;
  26. public:
  27. explicit OBSImporter(QWidget *parent = nullptr);
  28. void addImportOption(QString path, bool automatic);
  29. protected:
  30. virtual void dropEvent(QDropEvent *ev) override;
  31. virtual void dragEnterEvent(QDragEnterEvent *ev) override;
  32. public slots:
  33. void browseImport();
  34. void importCollections();
  35. void dataChanged();
  36. };
  37. class ImporterModel : public QAbstractTableModel {
  38. Q_OBJECT
  39. friend class OBSImporter;
  40. public:
  41. ImporterModel(QObject *parent = 0) : QAbstractTableModel(parent) {}
  42. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  43. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  44. QVariant data(const QModelIndex &index, int role) const;
  45. QVariant headerData(int section, Qt::Orientation orientation,
  46. int role = Qt::DisplayRole) const;
  47. Qt::ItemFlags flags(const QModelIndex &index) const;
  48. bool setData(const QModelIndex &index, const QVariant &value, int role);
  49. private:
  50. struct ImporterEntry {
  51. QString path;
  52. QString program;
  53. QString name;
  54. bool selected;
  55. bool empty;
  56. };
  57. QList<ImporterEntry> options;
  58. void checkInputPath(int row);
  59. };
  60. class ImporterEntryPathItemDelegate : public QStyledItemDelegate {
  61. Q_OBJECT
  62. public:
  63. ImporterEntryPathItemDelegate();
  64. virtual QWidget *createEditor(QWidget *parent,
  65. const QStyleOptionViewItem & /* option */,
  66. const QModelIndex &index) const override;
  67. virtual void setEditorData(QWidget *editor,
  68. const QModelIndex &index) const override;
  69. virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
  70. const QModelIndex &index) const override;
  71. virtual void paint(QPainter *painter,
  72. const QStyleOptionViewItem &option,
  73. const QModelIndex &index) const override;
  74. private:
  75. const char *PATH_LIST_PROP = "pathList";
  76. void handleBrowse(QWidget *container);
  77. void handleClear(QWidget *container);
  78. private slots:
  79. void updateText();
  80. };