kexi

kexipropertyeditorview.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this program; see the file COPYING.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kexipropertyeditorview.h"
00022 #include "keximainwindow.h"
00023 #include <koproperty/set.h>
00024 #include <koproperty/editor.h>
00025 #include <koproperty/property.h>
00026 
00027 #include <klocale.h>
00028 #include <kiconloader.h>
00029 
00030 #include <qlayout.h>
00031 #include <qlabel.h>
00032 
00033 KexiObjectInfoLabel::KexiObjectInfoLabel(QWidget* parent, const char* name)
00034  : QWidget(parent, name)
00035 {
00036     QHBoxLayout *hlyr = new QHBoxLayout(this);
00037     m_objectIconLabel = new QLabel(this);
00038     m_objectIconLabel->setMargin(2);
00039     setFixedHeight( IconSize(KIcon::Small) + 2 + 2 );
00040     hlyr->addWidget(m_objectIconLabel);
00041     m_objectNameLabel = new QLabel(this);
00042     m_objectNameLabel->setMargin(2);
00043     m_objectNameLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
00044     hlyr->addWidget(m_objectNameLabel);
00045 }
00046 
00047 KexiObjectInfoLabel::~KexiObjectInfoLabel()
00048 {
00049 }
00050 
00051 void KexiObjectInfoLabel::setObjectClassIcon(const QString& name)
00052 {
00053     m_classIcon = name;
00054     if (m_classIcon.isEmpty())
00055         m_objectIconLabel->setFixedWidth( 0 );
00056     else
00057         m_objectIconLabel->setFixedWidth( IconSize(KIcon::Small) + 2 + 2 );
00058     m_objectIconLabel->setPixmap( SmallIcon(name) );
00059 }
00060 
00061 void KexiObjectInfoLabel::setObjectClassName(const QString& name)
00062 {
00063     m_className = name;
00064     updateName();
00065 }
00066 
00067 void KexiObjectInfoLabel::setObjectName(const QString& name)
00068 {
00069     m_objectName = name;
00070     updateName();
00071 }
00072 
00073 void KexiObjectInfoLabel::updateName()
00074 {
00075     QString txt( m_className );
00076     if (txt.isEmpty())
00077         txt = m_objectName;
00078     else if (!m_objectName.isEmpty())
00079         txt += QString(" \"%1\"").arg(m_objectName);
00080     m_objectNameLabel->setText(txt);
00081 }
00082 
00083 void KexiObjectInfoLabel::setBuddy( QWidget * buddy )
00084 {
00085     m_objectNameLabel->setBuddy(buddy);
00086 }
00087 
00088 //------------------------------
00089 
00091 class KexiPropertyEditorView::Private
00092 {
00093     public:
00094         Private()
00095         {
00096         }
00097         KoProperty::Editor *editor;
00098 //      QLabel *objectIcon;
00099 //      QString iconName;
00100 //      QLabel *objectClassName;
00101         KexiObjectInfoLabel *objectInfoLabel;
00102 };
00103 
00104 //------------------------------
00105 
00106 KexiPropertyEditorView::KexiPropertyEditorView(KexiMainWindow *mainWin, QWidget* parent)
00107     : QWidget(parent, "KexiPropertyEditorView")
00108     , d(new Private())
00109 {
00110     setCaption(i18n("Properties"));
00111     //TODO: set a nice icon
00112     setIcon(*mainWin->icon());
00113 
00114     QVBoxLayout *lyr = new QVBoxLayout(this);
00115 
00116     //add object class info
00117     d->objectInfoLabel = new KexiObjectInfoLabel(this, "KexiObjectInfoLabel");
00118     lyr->addWidget(d->objectInfoLabel);
00119 
00120     /*
00121     QHBoxLayout *vlyr = new QHBoxLayout(lyr);
00122     d->objectIcon = new QLabel(this);
00123     d->objectIcon->setMargin(2);
00124     d->objectIcon->setFixedHeight( IconSize(KIcon::Small) + 2 + 2 );
00125     vlyr->addWidget(d->objectIcon);
00126     d->objectClassName = new QLabel(this);
00127     d->objectClassName->setMargin(2);
00128     d->objectClassName->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
00129     vlyr->addWidget(d->objectClassName);*/
00130 
00131     d->editor = new KoProperty::Editor(this, true /*AutoSync*/, "propeditor");
00132     lyr->addWidget(d->editor);
00133     setFocusProxy(d->editor);
00134     d->objectInfoLabel->setBuddy(d->editor);
00135     setFocusPolicy(WheelFocus);
00136 
00137     connect(d->editor, SIGNAL(propertySetChanged(KoProperty::Set*)), 
00138         this, SLOT(slotPropertySetChanged(KoProperty::Set*)));
00139 
00140 //  d->iconName = "dummy";
00141     slotPropertySetChanged(0);
00142 }
00143 
00144 KexiPropertyEditorView::~KexiPropertyEditorView()
00145 {
00146     delete d;
00147 }
00148 
00149 QSize KexiPropertyEditorView::sizeHint() const
00150 {
00151     return QSize(200,200);//m_editor->sizeHint();
00152 }
00153 
00154 QSize KexiPropertyEditorView::minimumSizeHint() const
00155 {
00156     return QSize(200,200);//m_editor->sizeHint();
00157 }
00158 
00159 /*void KexiPropertyEditorView::setGeometry ( const QRect &r )
00160 {
00161     QWidget::setGeometry(r);
00162 }
00163 
00164 void KexiPropertyEditorView::resize (  int w, int h  )
00165 {
00166     QWidget::resize( w, h );
00167 }*/
00168 
00169 KoProperty::Editor *KexiPropertyEditorView::editor() const
00170 {
00171     return d->editor;
00172 }
00173 
00181 void KexiPropertyEditorView::updateInfoLabelForPropertySet(KexiObjectInfoLabel *infoLabel, 
00182     KoProperty::Set* set, const QString& textToDisplayForNullSet)
00183 {
00184     QString className, iconName, objectName;
00185     if (set) {
00186         if (set->contains("this:classString"))
00187             className = (*set)["this:classString"].value().toString();
00188         if (set->contains("this:iconName"))
00189             iconName = (*set)["this:iconName"].value().toString();
00190         const bool useCaptionAsObjectName = set->contains("this:useCaptionAsObjectName")
00191             && (*set)["this:useCaptionAsObjectName"].value().toBool();
00192         if (set->contains(useCaptionAsObjectName ? "caption" : "name"))
00193             objectName = (*set)[useCaptionAsObjectName ? "caption" : "name"].value().toString();
00194     }
00195     if (!set || objectName.isEmpty()) {
00196         objectName = textToDisplayForNullSet;
00197         className = QString::null;
00198         iconName = QString::null;
00199     }
00200 
00201     if (className.isEmpty() && objectName.isEmpty())
00202         infoLabel->hide();
00203     else
00204         infoLabel->show();
00205 
00206     if (infoLabel->objectClassName() == className 
00207         && infoLabel->objectClassIcon() == iconName
00208         && infoLabel->objectName() == objectName)
00209         return;
00210 
00211     infoLabel->setObjectClassIcon(iconName);
00212     infoLabel->setObjectClassName(className);
00213     infoLabel->setObjectName(objectName);
00214 }
00215 
00216 void KexiPropertyEditorView::slotPropertySetChanged(KoProperty::Set* set)
00217 {
00218     //update information about selected object
00219     updateInfoLabelForPropertySet(d->objectInfoLabel, set);
00220     d->editor->setEnabled(set);
00221 }
00222 
00223 #include "kexipropertyeditorview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys