vorphanfileinfodialog.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "vorphanfileinfodialog.h"
  2. #include <QtWidgets>
  3. #include "vorphanfile.h"
  4. #include "vconfigmanager.h"
  5. #include "utils/vutils.h"
  6. #include "vlineedit.h"
  7. extern VConfigManager *g_config;
  8. VOrphanFileInfoDialog::VOrphanFileInfoDialog(const VOrphanFile *p_file, QWidget *p_parent)
  9. : QDialog(p_parent), m_file(p_file)
  10. {
  11. setupUI();
  12. connect(m_imageFolderEdit, &VLineEdit::textChanged,
  13. this, &VOrphanFileInfoDialog::handleInputChanged);
  14. handleInputChanged();
  15. }
  16. void VOrphanFileInfoDialog::setupUI()
  17. {
  18. QFormLayout *topLayout = new QFormLayout();
  19. QLabel *fileLabel = new QLabel(m_file->fetchPath());
  20. fileLabel->setTextInteractionFlags(fileLabel->textInteractionFlags() | Qt::TextSelectableByMouse);
  21. fileLabel->setWordWrap(true);
  22. topLayout->addRow(tr("File:"), fileLabel);
  23. m_imageFolderEdit = new VLineEdit(m_file->getImageFolder());
  24. m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
  25. .arg(g_config->getImageFolderExt()));
  26. QString imgFolderTip = tr("Set the path of the image folder to store images "
  27. "of this file.\nIf absolute path is used, "
  28. "VNote will not manage those images."
  29. "(empty to use global configuration)");
  30. m_imageFolderEdit->setToolTip(imgFolderTip);
  31. topLayout->addRow(tr("&Image folder:"), m_imageFolderEdit);
  32. // Ok is the default button.
  33. m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
  34. connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
  35. connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
  36. QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok);
  37. okBtn->setProperty("SpecialBtn", true);
  38. m_imageFolderEdit->setMinimumWidth(okBtn->sizeHint().width() * 3);
  39. QVBoxLayout *mainLayout = new QVBoxLayout();
  40. mainLayout->addLayout(topLayout);
  41. mainLayout->addWidget(m_btnBox);
  42. mainLayout->setSizeConstraint(QLayout::SetFixedSize);
  43. setLayout(mainLayout);
  44. setWindowTitle(tr("External File Information"));
  45. }
  46. QString VOrphanFileInfoDialog::getImageFolder() const
  47. {
  48. return m_imageFolderEdit->text();
  49. }
  50. void VOrphanFileInfoDialog::handleInputChanged()
  51. {
  52. bool ok = false;
  53. QString imgFolder = m_imageFolderEdit->text();
  54. if (imgFolder.isEmpty() || VUtils::checkPathLegal(imgFolder)) {
  55. ok = true;
  56. }
  57. QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok);
  58. okBtn->setEnabled(ok);
  59. }