kis_dlg_file_layer.cpp 3.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* This file is part of the KDE project
 * Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2013
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "kis_dlg_file_layer.h"

#include <QLineEdit>
#include <QCheckBox>
24
#include <QDesktopServices>
25 26 27 28

#include <klineedit.h>
#include <klocale.h>

29
#include <kurl.h>
30

Yue Liu's avatar
Yue Liu committed
31
#include <KoFileDialog.h>
32
#include <KoApplication.h>
33 34 35 36 37 38
#include <KoFilterManager.h>

#include <kis_config_widget.h>
#include <kis_paint_device.h>
#include <kis_transaction.h>
#include <kis_node.h>
39
#include <kis_file_layer.h>
40

41
KisDlgFileLayer::KisDlgFileLayer(const QString &basePath, const QString & name, QWidget * parent)
42
    : KDialog(parent)
43
    , m_basePath(basePath)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    , m_customName(false)
    , m_freezeName(false)
{
    setButtons(Ok | Cancel);
    setDefaultButton(Ok);
    QWidget * page = new QWidget(this);
    dlgWidget.setupUi(page);
    setMainWidget(page);

    dlgWidget.txtLayerName->setText(name);
    connect(dlgWidget.txtLayerName, SIGNAL(textChanged(const QString &)),
            this, SLOT(slotNameChanged(const QString &)));
    connect(dlgWidget.bnGetFileName, SIGNAL(clicked()), SLOT(slotSelectFile()));
}

void KisDlgFileLayer::slotNameChanged(const QString & text)
{
    if (m_freezeName)
        return;

    m_customName = !text.isEmpty();
    enableButtonOk(m_customName);
}

QString KisDlgFileLayer::layerName() const
{
    return dlgWidget.txtLayerName->text();
}

73
KisFileLayer::ScalingMethod KisDlgFileLayer::scaleToImageResolution() const
74
{
75 76 77 78 79 80 81 82 83
    if (dlgWidget.radioDontScale->isChecked()) {
        return KisFileLayer::None;
    }
    else if (dlgWidget.radioScaleToImageSize->isChecked()) {
        return KisFileLayer::ToImageSize;
    }
    else {
        return KisFileLayer::ToImagePPI;
    }
84 85 86 87 88 89 90 91 92
}

QString KisDlgFileLayer::fileName() const
{
    return dlgWidget.txtFileName->text();
}

void KisDlgFileLayer::slotSelectFile()
{
93 94 95
    KoFileDialog dialog(this, KoFileDialog::OpenFile, "OpenDocument");
    dialog.setCaption(i18n("Select file to use as dynamic file layer."));
    dialog.setDefaultDir(m_basePath.isEmpty() ? QDesktopServices::storageLocation(QDesktopServices::PicturesLocation) : m_basePath);
96
    dialog.setMimeTypeFilters(KoFilterManager::mimeFilter("application/x-krita", KoFilterManager::Import));
97
    QString url = dialog.url();
98 99 100 101 102 103 104
    if (m_basePath.isEmpty()) {
        dlgWidget.txtFileName->setText(url);
    }
    else {
        QDir d(m_basePath);
        dlgWidget.txtFileName->setText(d.relativeFilePath(url));
    }
105 106 107
}

#include "kis_dlg_file_layer.moc"