FormFolderBrowseEditWidget.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <FormFolderBrowseEditWidget.h>
  9. #include <AzQtComponents/Components/StyledLineEdit.h>
  10. #include <QFileDialog>
  11. #include <QLineEdit>
  12. #include <QStandardPaths>
  13. namespace O3DE::ProjectManager
  14. {
  15. FormFolderBrowseEditWidget::FormFolderBrowseEditWidget(
  16. const QString& labelText,
  17. const QString& valueText,
  18. const QString& placeholderText,
  19. const QString& errorText,
  20. QWidget* parent)
  21. : FormBrowseEditWidget(labelText, valueText, placeholderText, errorText, parent)
  22. {
  23. setText(valueText);
  24. }
  25. FormFolderBrowseEditWidget::FormFolderBrowseEditWidget(const QString& labelText, const QString& valueText, QWidget* parent)
  26. : FormFolderBrowseEditWidget(labelText, valueText, "", "", parent)
  27. {
  28. }
  29. void FormFolderBrowseEditWidget::HandleBrowseButton()
  30. {
  31. QString defaultPath = m_lineEdit->text();
  32. if (defaultPath.isEmpty())
  33. {
  34. defaultPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
  35. }
  36. QString directory = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this, tr("Browse"), defaultPath));
  37. if (!directory.isEmpty())
  38. {
  39. setText(directory);
  40. }
  41. }
  42. void FormFolderBrowseEditWidget::setText(const QString& text)
  43. {
  44. QString path = QDir::toNativeSeparators(text);
  45. FormBrowseEditWidget::setText(path);
  46. }
  47. } // namespace O3DE::ProjectManager