File indexing completed on 2024-05-12 08:34:05
0001 /* ============================================================ 0002 * Date : 2010-07-07 0003 * Description : Save location settings dialog. 0004 * 0005 * SPDX-FileCopyrightText: 2010-2012 Kare Sars <kare.sars@iki.fi> 0006 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks 0007 * 0008 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0009 * 0010 * ============================================================ */ 0011 0012 #include "SaveLocation.h" 0013 #include "ui_SaveLocation.h" 0014 0015 #include <QFileDialog> 0016 #include <QPushButton> 0017 #include <QComboBox> 0018 #include <QShowEvent> 0019 #include <QTimer> 0020 0021 SaveLocation::SaveLocation(QWidget *parent) 0022 : QDialog(parent) 0023 { 0024 m_ui = new Ui_SaveLocation(); 0025 m_ui->setupUi(this); 0026 0027 m_ui->u_urlRequester->setMode(KFile::Directory); 0028 connect(m_ui->u_urlRequester, &KUrlRequester::textChanged, this, &SaveLocation::updateGui); 0029 connect(m_ui->u_imgPrefix, &QLineEdit::textChanged, this, &SaveLocation::updateGui); 0030 connect(m_ui->u_imgFormat, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::textActivated), this, &SaveLocation::updateGui); 0031 connect(m_ui->u_numStartFrom, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &SaveLocation::updateGui); 0032 } 0033 0034 SaveLocation::~SaveLocation() 0035 { 0036 } 0037 0038 void SaveLocation::updateGui() 0039 { 0040 if (sender() != m_ui->u_numStartFrom) { 0041 m_ui->u_numStartFrom->setValue(1); // Reset the counter whenever the directory or the prefix is changed 0042 } 0043 const QString name = QStringLiteral("%1%2.%3") 0044 .arg(m_ui->u_imgPrefix->text()) 0045 .arg(m_ui->u_numStartFrom->value(), 4, 10, QLatin1Char('0')) 0046 .arg(m_ui->u_imgFormat->currentText()); 0047 0048 QUrl folderUrl = m_ui->u_urlRequester->url(); 0049 folderUrl.setPath(folderUrl.path() + QLatin1Char('/')); 0050 m_ui->u_resultValue->setText(folderUrl.toString(QUrl::PreferLocalFile | QUrl::NormalizePathSegments)+name); 0051 } 0052 0053 QUrl SaveLocation::folderUrl() const 0054 { 0055 QUrl folderUrl = m_ui->u_urlRequester->url(); 0056 folderUrl.setPath(folderUrl.path() + QLatin1Char('/')); 0057 return folderUrl.adjusted(QUrl::NormalizePathSegments); 0058 } 0059 0060 QString SaveLocation::imagePrefix() const 0061 { 0062 return m_ui->u_imgPrefix->text(); 0063 } 0064 0065 QString SaveLocation::imageMimetype() const 0066 { 0067 return m_ui->u_imgFormat->currentData().toString(); 0068 } 0069 0070 QString SaveLocation::imageSuffix() const 0071 { 0072 return m_ui->u_imgFormat->currentText().toLower(); 0073 } 0074 0075 int SaveLocation::startNumber() const 0076 { 0077 return m_ui->u_numStartFrom->value(); 0078 } 0079 0080 int SaveLocation::startNumberMax() const 0081 { 0082 return m_ui->u_numStartFrom->maximum(); 0083 } 0084 0085 void SaveLocation::setFolderUrl(const QUrl &url) 0086 { 0087 m_ui->u_urlRequester->setUrl(url); 0088 } 0089 0090 void SaveLocation::setImagePrefix(const QString &prefix) 0091 { 0092 m_ui->u_imgPrefix->setText(prefix); 0093 } 0094 0095 void SaveLocation::addImageFormat(const QString &suffix, const QString &mimetype) 0096 { 0097 m_ui->u_imgFormat->addItem(suffix, mimetype); 0098 } 0099 0100 void SaveLocation::setImageFormatIndex(int index) 0101 { 0102 m_ui->u_imgFormat->setCurrentIndex(index); 0103 } 0104 0105 void SaveLocation::setImageFormat(const QString &suffix) 0106 { 0107 int index = m_ui->u_imgFormat->findText(suffix); 0108 if (index >= 0) { 0109 m_ui->u_imgFormat->setCurrentIndex(index); 0110 } 0111 } 0112 0113 void SaveLocation::setStartNumber(int number) 0114 { 0115 m_ui->u_numStartFrom->setValue(number); 0116 } 0117 0118 void SaveLocation::setOpenRequesterOnShow(bool open) 0119 { 0120 m_openRequesterOnShow = open; 0121 } 0122 0123 void SaveLocation::showEvent(QShowEvent *event) 0124 { 0125 QDialog::showEvent(event); 0126 0127 if (m_openRequesterOnShow) { 0128 QTimer::singleShot(0, this, [this]() { m_ui->u_urlRequester->button()->click(); }); 0129 } 0130 } 0131 0132 #include "moc_SaveLocation.cpp"