file_path_editor.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* file_path_editor.cpp - edit file path with open dialogue
  2. * Copyright (C) 2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <QLayout>
  18. #include <QToolButton>
  19. #include <QFileDialog>
  20. #include <generic/custom_widgets.h>
  21. #include <generic/node_editor_widget.h>
  22. #include <util/strings.h>
  23. #include "file_path_editor.h"
  24. namespace rainynite::studio {
  25. FilePathEditor::FilePathEditor(QWidget* parent) :
  26. QWidget(parent)
  27. {
  28. auto open_button = new QToolButton();
  29. open_button->setIcon(QIcon::fromTheme("document-open"));
  30. auto hlayout = new QHBoxLayout();
  31. hlayout->addWidget(open_button);
  32. setLayout(hlayout);
  33. connect(open_button, &QToolButton::clicked, [this]() {
  34. // TODO: use correct dir
  35. auto fname = QFileDialog::getOpenFileName(this, "Edit file path", "", "RainyNite file (*.rnite)(*.rnite);;All files(*)");
  36. if (fname.isEmpty())
  37. return;
  38. path = util::str(fname);
  39. Q_EMIT editingFinished();
  40. });
  41. }
  42. using FilePathEditWidget = NodeEditorWidget<FilePathEditor, core::fs::Path::path_t>;
  43. REGISTER_CUSTOM_WIDGET(FilePathEdit, core::fs::Path::path_t, FilePathEditWidget);
  44. } // namespace rainynite::studio