File indexing completed on 2024-04-28 08:32:22
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> 0003 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net> 0004 Copyright (C) 2016-2018 Jarosław Staniek <staniek@kde.org> 0005 Copyright (C) 2018 Dmitry Baryshev <dmitrymq@gmail.com> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "KPropertyComposedUrlEditor.h" 0024 #include "KPropertyUrlEditor.h" // KPropertyUrlDelegate 0025 #include "KPropertyUrlEditor_p.h" 0026 0027 #include <QLineEdit> 0028 0029 KPropertyComposedUrlEditor::KPropertyComposedUrlEditor(const KProperty &property, QWidget *parent) 0030 : KPropertyGenericSelectionEditor(parent) 0031 , d(new KPropertyUrlEditorPrivate(this, property)) 0032 { 0033 setMainWidget(d->lineEdit); 0034 connect(d.data(), &KPropertyUrlEditorPrivate::commitData, this, 0035 [this] { emit commitData(this); }); 0036 } 0037 0038 KPropertyComposedUrlEditor::~KPropertyComposedUrlEditor() {} 0039 0040 KPropertyComposedUrl KPropertyComposedUrlEditor::value() const 0041 { 0042 return d->value.value<KPropertyComposedUrl>(); 0043 } 0044 0045 void KPropertyComposedUrlEditor::setValue(const KPropertyComposedUrl &value) 0046 { 0047 d->setValue(QVariant::fromValue(value)); 0048 const KPropertyUrlDelegate delegate; 0049 d->updateLineEdit(delegate.valueToString(d->value, locale())); 0050 } 0051 0052 void KPropertyComposedUrlEditor::selectButtonClicked() 0053 { 0054 QUrl url = d->getUrl(); 0055 if (url.isValid() && d->checkAndUpdate(&url)) { 0056 KPropertyComposedUrl composedUrl = value(); 0057 composedUrl.setAbsoluteUrl(url); 0058 setValue(composedUrl); 0059 emit commitData(this); 0060 } 0061 } 0062 0063 bool KPropertyComposedUrlEditor::eventFilter(QObject *o, QEvent *event) 0064 { 0065 d->processEvent(o, event); 0066 return KPropertyGenericSelectionEditor::eventFilter(o, event); 0067 }