File indexing completed on 2024-04-21 04:41:01
0001 /* This file is part of the KDE project 0002 Copyright (C) 2016 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KPropertyGenericSelectionEditor.h" 0021 0022 #include <QHBoxLayout> 0023 #include <QPushButton> 0024 0025 class Q_DECL_HIDDEN KPropertyGenericSelectionEditor::Private 0026 { 0027 public: 0028 Private() { 0029 } 0030 QHBoxLayout *lyr; 0031 QPushButton *btn; 0032 }; 0033 0034 KPropertyGenericSelectionEditor::KPropertyGenericSelectionEditor(QWidget *parent) 0035 : QWidget(parent), d(new Private) 0036 { 0037 setAutoFillBackground(true); 0038 d->lyr = new QHBoxLayout(this); 0039 d->lyr->setContentsMargins(0, 0, 0, 0); 0040 d->lyr->setSpacing(2); 0041 d->btn = new QPushButton(tr("...", "... button")); 0042 d->btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); 0043 d->btn->setFixedWidth(d->btn->fontMetrics().width(d->btn->text() + QLatin1String(" "))); 0044 d->btn->setFocusPolicy(Qt::NoFocus); 0045 connect(d->btn, &QPushButton::clicked, this, &KPropertyGenericSelectionEditor::selectButtonClicked); 0046 d->lyr->addWidget(d->btn); 0047 } 0048 0049 KPropertyGenericSelectionEditor::~KPropertyGenericSelectionEditor() 0050 { 0051 } 0052 0053 void KPropertyGenericSelectionEditor::setMainWidget(QWidget *widget) 0054 { 0055 if (d->lyr->count() > 1) { 0056 delete d->lyr->takeAt(0)->widget(); 0057 } 0058 if (widget) { 0059 d->lyr->insertWidget(0, widget); 0060 widget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); 0061 setFocusProxy(widget); 0062 } 0063 } 0064 0065 void KPropertyGenericSelectionEditor::setSelectionButtonVisible(bool set) 0066 { 0067 d->btn->setVisible(set); 0068 } 0069 0070 void KPropertyGenericSelectionEditor::selectButtonClicked() 0071 { 0072 }