kexi
kexipropertyeditorview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00099
00100
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
00112 setIcon(*mainWin->icon());
00113
00114 QVBoxLayout *lyr = new QVBoxLayout(this);
00115
00116
00117 d->objectInfoLabel = new KexiObjectInfoLabel(this, "KexiObjectInfoLabel");
00118 lyr->addWidget(d->objectInfoLabel);
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 d->editor = new KoProperty::Editor(this, true , "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
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);
00152 }
00153
00154 QSize KexiPropertyEditorView::minimumSizeHint() const
00155 {
00156 return QSize(200,200);
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
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
00219 updateInfoLabelForPropertySet(d->objectInfoLabel, set);
00220 d->editor->setEnabled(set);
00221 }
00222
00223 #include "kexipropertyeditorview.moc"
|