File indexing completed on 2024-05-12 16:40:55

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004-2009 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program 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 program 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 program; see the file COPYING.  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 "KexiObjectInfoLabel.h"
0021 
0022 #include <QLabel>
0023 #include <QHBoxLayout>
0024 #include <QIcon>
0025 
0026 #include <KIconLoader>
0027 #include <KLocalizedString>
0028 
0029 class Q_DECL_HIDDEN KexiObjectInfoLabel::Private
0030 {
0031 public:
0032     Private() {}
0033     QString className;
0034     QString classIconName;
0035     QString objectName;
0036     QLabel *objectIconLabel;
0037     QLabel *objectNameLabel;
0038 };
0039 
0040 KexiObjectInfoLabel::KexiObjectInfoLabel(QWidget* parent)
0041         : QWidget(parent)
0042         , d( new Private )
0043 {
0044     QWidget::setObjectName("KexiObjectInfoLabel");
0045     QHBoxLayout *hlyr = new QHBoxLayout(this);
0046     hlyr->setContentsMargins(0, 0, 0, 0);
0047     hlyr->setSpacing(2);
0048     d->objectIconLabel = new QLabel(this);
0049     d->objectIconLabel->setMargin(2);
0050     setMinimumHeight(KIconLoader::global()->currentSize(KIconLoader::Small) + 2 + 2);
0051     hlyr->addWidget(d->objectIconLabel);
0052     d->objectNameLabel = new QLabel(this);
0053     d->objectNameLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
0054     hlyr->addWidget(d->objectNameLabel);
0055 }
0056 
0057 KexiObjectInfoLabel::~KexiObjectInfoLabel()
0058 {
0059     delete d;
0060 }
0061 
0062 QString KexiObjectInfoLabel::objectClassIconName() const
0063 {
0064     return d->classIconName;
0065 }
0066 
0067 void KexiObjectInfoLabel::setObjectClassIconName(const QString &iconName)
0068 {
0069     d->classIconName = iconName;
0070     if (d->classIconName.isEmpty()) {
0071         d->objectIconLabel->setFixedWidth(0);
0072     }
0073     else {
0074         d->objectIconLabel->setFixedWidth(KIconLoader::global()->currentSize(KIconLoader::Small) + 2 + 2);
0075     }
0076     const QIcon icon(QIcon::fromTheme(iconName));
0077     d->objectIconLabel->setPixmap(
0078         icon.pixmap(KIconLoader::global()->currentSize(KIconLoader::Small)));
0079 }
0080 
0081 QString KexiObjectInfoLabel::objectClassName() const
0082 {
0083     return d->className;
0084 }
0085 
0086 void KexiObjectInfoLabel::setObjectClassName(const QString& name)
0087 {
0088     d->className = name;
0089     updateName();
0090 }
0091 
0092 QString KexiObjectInfoLabel::objectName() const
0093 {
0094     return d->objectName;
0095 }
0096 
0097 void KexiObjectInfoLabel::setObjectName(const QString& name)
0098 {
0099     d->objectName = name;
0100     updateName();
0101 }
0102 
0103 void KexiObjectInfoLabel::updateName()
0104 {
0105     QString txt(d->className);
0106     if (txt.isEmpty()) {
0107         txt = d->objectName;
0108     }
0109     else if (!d->objectName.isEmpty()) {
0110         txt = xi18nc("Object class \"objectName\", e.g. Text editor \"text\"", "%1 <resource>%2</resource>",
0111             txt, d->objectName);
0112     }
0113     d->objectNameLabel->setText(txt);
0114 }
0115 
0116 void KexiObjectInfoLabel::setBuddy(QWidget * buddy)
0117 {
0118     d->objectNameLabel->setBuddy(buddy);
0119 }