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-2005 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 QCString& 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 QCString& name)
00068 {
00069     m_objectName = name;
00070     updateName();
00071 }
00072 
00073 void KexiObjectInfoLabel::updateName()
00074 {
00075     QString txt = m_className;
00076     if (!m_objectName.isEmpty())
00077         txt += QString(" \"%1\"").arg(m_objectName);
00078     m_objectNameLabel->setText(txt);
00079 }
00080 
00081 //------------------------------
00082 
00084 class KexiPropertyEditorView::Private
00085 {
00086     public:
00087         Private()
00088         {
00089         }
00090         KoProperty::Editor *editor;
00091 //      QLabel *objectIcon;
00092 //      QString iconName;
00093 //      QLabel *objectClassName;
00094         KexiObjectInfoLabel *objectInfoLabel;
00095 };
00096 
00097 //------------------------------
00098 
00099 KexiPropertyEditorView::KexiPropertyEditorView(KexiMainWindow *mainWin, QWidget* parent)
00100     : QWidget(parent, "KexiPropertyEditorView")
00101     , d(new Private())
00102 {
00103     setCaption(i18n("Properties"));
00104     //TODO: set a nice icon
00105     setIcon(*mainWin->icon());
00106 
00107     QVBoxLayout *lyr = new QVBoxLayout(this);
00108 
00109     //add object class info
00110     d->objectInfoLabel = new KexiObjectInfoLabel(this, "KexiObjectInfoLabel");
00111     lyr->addWidget(d->objectInfoLabel);
00112 
00113     /*
00114     QHBoxLayout *vlyr = new QHBoxLayout(lyr);
00115     d->objectIcon = new QLabel(this);
00116     d->objectIcon->setMargin(2);
00117     d->objectIcon->setFixedHeight( IconSize(KIcon::Small) + 2 + 2 );
00118     vlyr->addWidget(d->objectIcon);
00119     d->objectClassName = new QLabel(this);
00120     d->objectClassName->setMargin(2);
00121     d->objectClassName->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
00122     vlyr->addWidget(d->objectClassName);*/
00123 
00124     d->editor = new KoProperty::Editor(this, true /*AutoSync*/, "propeditor");
00125     lyr->addWidget(d->editor);
00126     setFocusProxy(d->editor);
00127 
00128     connect(d->editor, SIGNAL(propertySetChanged(KoProperty::Set*)), 
00129         this, SLOT(slotPropertySetChanged(KoProperty::Set*)));
00130 
00131 //  d->iconName = "dummy";
00132     slotPropertySetChanged(0);
00133 }
00134 
00135 KexiPropertyEditorView::~KexiPropertyEditorView()
00136 {
00137     delete d;
00138 }
00139 
00140 QSize KexiPropertyEditorView::sizeHint() const
00141 {
00142     return QSize(200,200);//m_editor->sizeHint();
00143 }
00144 
00145 QSize KexiPropertyEditorView::minimumSizeHint() const
00146 {
00147     return QSize(200,200);//m_editor->sizeHint();
00148 }
00149 
00150 /*void KexiPropertyEditorView::setGeometry ( const QRect &r )
00151 {
00152     QWidget::setGeometry(r);
00153 }
00154 
00155 void KexiPropertyEditorView::resize (  int w, int h  )
00156 {
00157     QWidget::resize( w, h );
00158 }*/
00159 
00160 KoProperty::Editor *KexiPropertyEditorView::editor() const
00161 {
00162     return d->editor;
00163 }
00164 
00165 void KexiPropertyEditorView::slotPropertySetChanged(KoProperty::Set* set)
00166 {
00167     //update information about selected object
00168     QString className;
00169     QCString iconName, objectName;
00170     if (set) {
00171         if (set->contains("this:classString"))
00172             className = (*set)["this:classString"].value().toString();
00173         if (set->contains("this:iconName"))
00174             iconName = (*set)["this:iconName"].value().toCString();
00175         if (set->contains("name"))
00176             objectName = (*set)["name"].value().toCString();
00177     }
00178 
00179     if (className.isEmpty()) {
00180         d->objectInfoLabel->hide();
00181     }
00182     else {
00183         d->objectInfoLabel->show();
00184     }
00185 
00186     if (d->objectInfoLabel->objectClassName() == className 
00187         && d->objectInfoLabel->objectClassIcon() == iconName
00188         && d->objectInfoLabel->objectName() == objectName)
00189         return;
00190 
00191     d->objectInfoLabel->setObjectClassIcon(iconName);
00192     d->objectInfoLabel->setObjectClassName(className);
00193     d->objectInfoLabel->setObjectName(objectName);
00194 
00195 /*
00196     if (className.isEmpty()) {
00197         d->objectClassName->hide();
00198         d->objectIcon->hide();
00199         d->objectIcon->setFixedWidth( 0 );
00200     }
00201     else {
00202         if (iconName.isEmpty()) {
00203             d->objectIcon->setFixedWidth( 0 );
00204             d->objectIcon->hide();
00205             d->objectIcon->setPixmap(QPixmap());
00206         }
00207         else {
00208             d->objectIcon->setFixedWidth( IconSize(KIcon::Small) + 2 + 2 );
00209             d->objectIcon->setPixmap(SmallIcon(iconName));
00210         }
00211         d->objectClassName->setText(className);
00212         d->objectClassName->show();
00213         d->objectIcon->show();
00214     }*/
00215 }
00216 
00217 #include "kexipropertyeditorview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys