23 #include <tdelocale.h> 25 #include <kiconloader.h> 27 #include "compat_tools.h" 32 #include <tqpainter.h> 33 #include <tqptrlist.h> 34 #include <tqvaluelist.h> 35 #include <tqpushbutton.h> 43 class PropertyItem:
public TDEListViewItem{
45 PropertyItem(PropertyEditor *parent, MultiProperty *property)
46 :TDEListViewItem(parent, property->description()), m_editor(parent), m_property(property),
51 PropertyItem(PropertyEditor *editor, TDEListViewItem *parent, MultiProperty *property)
52 :TDEListViewItem(parent, property->description()), m_editor(editor),
53 m_property(property), m_changed(false)
67 MultiProperty *property()
const 72 virtual void paintCell(TQPainter *p,
const TQColorGroup &cg,
int column,
int width,
int align)
74 if ((column == 0) && m_changed)
79 p->setBrush(cg.highlight());
80 p->setPen(cg.highlightedText());
84 TQRect r(0, 0, m_editor->header()->sectionSize(1), height());
86 TQVariant valueToDraw;
88 valueToDraw = m_property->findValueDescription();
90 valueToDraw = m_property->value();
93 icg.setColor(TQColorGroup::Background, backgroundColor(column));
95 icg.setColor(TQColorGroup::Background, white);
97 m_editor->machine(m_property)->propertyEditor->drawViewer(p, icg, r, valueToDraw);
100 TDEListViewItem::paintCell(p, cg, column, width, align);
105 TDEListViewItem::setup();
106 setHeight(static_cast<int>(height()*1.5));
109 void setChanged(
bool changed)
115 PropertyEditor *m_editor;
116 MultiProperty *m_property;
121 class PropertyGroupItem:
public TDEListViewItem{
123 PropertyGroupItem(TDEListView *parent,
const TQString &name)
124 :TDEListViewItem(parent, name)
128 PropertyGroupItem(TDEListViewItem *parent,
const TQString &name)
129 :TDEListViewItem(parent, name)
134 virtual void paintCell(TQPainter *p,
const TQColorGroup &cg,
int column,
int width,
int align)
141 p->setBrush(cg.highlight());
142 p->setPen(cg.highlightedText());
144 TDEListViewItem::paintCell(p, cg, column, width, align);
148 TDEListViewItem::setup();
149 setHeight(static_cast<int>(height()*1.4));
159 class SeparatorItem:
public TDEListViewItem{
161 SeparatorItem(TDEListView *parent)
162 :TDEListViewItem(parent)
164 setSelectable(
false);
168 :TDEListView(parent, name)
172 addColumn(i18n(
"Name"));
173 addColumn(i18n(
"Value"));
174 setAllColumnsShowFocus(
true);
175 setColumnWidthMode(0, TQListView::Maximum);
176 setResizeMode(TQListView::LastColumn);
178 header()->setClickEnabled(
false);
180 connect(header(), TQT_SIGNAL(sizeChange(
int,
int,
int)),
181 this, TQT_SLOT(updateEditorSize()));
182 connect(
this, TQT_SIGNAL(currentChanged(TQListViewItem*)),
185 m_currentEditItem = 0;
186 m_doubleClickForEdit =
true;
187 m_lastClickedItem = 0;
188 m_currentEditWidget = 0;
191 m_currentEditArea =
new TQWidget(viewport());
192 m_currentEditArea->hide();
193 m_undoButton =
new TQPushButton(m_currentEditArea);
195 m_undoButton->setPixmap(SmallIcon(
"edit-undo"));
197 m_undoButton->setPixmap( TQPixmap(
"undo.xpm") );
199 m_undoButton->setSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::MinimumExpanding);
200 m_undoButton->resize(m_undoButton->height(), m_undoButton->height());
201 m_undoButton->hide();
202 connect(m_undoButton, TQT_SIGNAL(clicked()),
this, TQT_SLOT(
undo()));
203 m_currentEditLayout =
new TQGridLayout(m_currentEditArea, 1, 2, 0, 0);
207 PropertyEditor::~PropertyEditor()
218 const TQValueList<TQPair<TQString, TQValueList<TQString> > >& groups = m_list->
propertiesOfGroup();
219 for (TQValueList<TQPair<TQString, TQValueList<TQString> > >::const_iterator it = groups.begin();
220 it != groups.end(); ++it)
223 PropertyGroupItem *group = 0;
224 if ( (!(*it).first.isEmpty()) && ((*it).second.count() > 0) )
225 group =
new PropertyGroupItem(
this, (*it).first);
226 const TQValueList<TQString> &properties = (*it).second;
227 for (TQValueList<TQString>::const_iterator it2 = properties.begin(); it2 != properties.end(); ++it2)
231 addProperty(group, *it2);
238 setCurrentItem(firstChild());
239 setSelected(firstChild(),
true);
244 void PropertyEditor::addProperty(PropertyGroupItem *group,
const TQString &name)
246 if ((*m_list)[name] == 0)
249 PropertyItem *pitem =
new PropertyItem(
this, group, (*m_list)[name]);
250 addChildProperties(pitem);
253 void PropertyEditor::addProperty(
const TQString &name)
255 if ((*m_list)[name] == 0)
258 PropertyItem *pitem =
new PropertyItem(
this, (*m_list)[name]);
259 addChildProperties(pitem);
262 void PropertyEditor::addChildProperties(PropertyItem *parent)
266 if ( !m_registeredForType.contains(prop->
name())
275 parent->setOpen(
true);
276 for (TQValueList<ChildProperty>::iterator it = prop->
details.begin(); it != prop->
details.end(); ++it)
279 new PropertyItem(
this, parent,
new MultiProperty(&m_detailedList, &(*it)));
285 m_detailedList.
clear();
300 if (m_currentEditWidget->
propertyName() ==
property->name())
305 TQListViewItemIterator it(
this);
308 repaintItem(it.current());
319 tqWarning(
"editor: assign %s to %s", property->
name().latin1(), value.toString().latin1());
320 property->setValue(value,
false);
323 if (m_currentEditItem && (m_currentEditItem->property() == property))
325 m_currentEditItem->setChanged(
true);
326 repaintItem(m_currentEditItem);
337 void PropertyEditor::hideEditor()
339 m_lastClickedItem = 0;
340 m_currentEditItem = 0;
341 if (m_currentEditWidget)
343 m_currentEditLayout->remove(m_currentEditWidget);
344 m_currentEditWidget->hide();
346 m_currentEditLayout->remove(m_undoButton);
347 m_undoButton->hide();
348 m_currentEditArea->hide();
349 m_currentEditWidget = 0;
352 void PropertyEditor::showEditor(PropertyItem *item)
354 m_currentEditItem = item;
356 m_currentEditWidget->show();
357 m_undoButton->show();
358 m_currentEditArea->show();
361 void PropertyEditor::placeEditor(PropertyItem *item)
363 TQRect r = itemRect(item);
364 if (!r.size().isValid())
366 ensureItemVisible(item);
370 r.setX(header()->sectionPos(1));
371 r.setWidth(header()->sectionSize(1));
374 if (visibleWidth() < r.right())
375 r.setRight(visibleWidth());
377 r = TQRect(viewportToContents(r.topLeft()), r.size());
381 r.setX(r.x() + item->pixmap(1)->width());
386 m_currentEditLayout->addWidget(editor, 0, 0);
387 m_currentEditLayout->addWidget(m_undoButton, 0, 1);
388 m_currentEditArea->resize(r.size());
390 moveChild(m_currentEditArea, r.x(), r.y());
391 m_currentEditWidget = editor;
405 editorWidget =
machine(item->property())->propertyEditor;
408 editorWidget->
setValueList(item->property()->valueList());
409 editorWidget->
setValue(item->property()->value(),
false);
414 void PropertyEditor::updateEditorSize()
416 if (m_currentEditItem)
417 placeEditor(m_currentEditItem);
427 if (item != m_lastClickedItem)
430 PropertyItem *it =
dynamic_cast<PropertyItem*
>(item);
437 m_lastClickedItem = item;
443 TQString name =
property->name();
444 TQMap<TQString, TQVariant> values =
property->valueList();
445 if (m_registeredForType[name] == 0)
450 m_registeredForType[name]->propertyEditor->reparent(m_currentEditArea, 0, m_currentEditArea->childrenRect().topLeft());
451 m_registeredForType[name]->propertyEditor->hide();
453 return m_registeredForType[name];
458 for (TQMap<TQString, Machine* >::iterator it = m_registeredForType.begin(); it != m_registeredForType.end(); ++it)
462 m_registeredForType.clear();
467 if ((m_currentEditItem == 0) || (m_currentEditWidget == 0)
468 || (!m_currentEditWidget->isVisible()))
471 m_currentEditWidget->
undo();
472 m_currentEditItem->setChanged(
false);
473 repaintItem(m_currentEditItem);
479 #include "propertyeditor.moc" void clearProperties()
Clears property list, disconnects accessor from the editor and deletes it.
void clearMachineCache()
Deletes cached machines.
virtual const TQValueList< TQPair< TQString, TQValueList< TQString > > > & propertiesOfGroup() const
Namespace which contain property editing classes.
Contains PropertyLib::PropertyMachineFactory class and PropertyLib::Machine structure.
void propertyValueChanged(Property *property)
Updates property widget in the editor.
int type() const
Returns the type of a property.
Contains PropertyLib::MultiProperty class.
Contains PropertyLib::Property class and PropertyLib::Property::PropertyType enum.
TQValueList< ChildProperty > details
The list of child properties.
static PropertyMachineFactory * getInstance()
void slotClicked(TQListViewItem *item)
Shows property editor.
void undo()
Undoes the last change in property editor.
TQString name() const
Returns the name of a property.
virtual TQVariant value() const
void populateProperties(PropertyList *list)
Shows properties from a list.
Contains PropertyLib::PropertyEditor class.
void propertyChanged(MultiProperty *property, const TQVariant &value)
Updates property in the list when new value is selected in the editor.
virtual void clear()
Clears the list of properties.
PropertyEditor(TQWidget *parent=0, const char *name=0)
Constructs the property editor.
Holds a list of properties with the same name and type.
Machine * machineForProperty(MultiProperty *property)
Creates and returns the editor for given property type.
Machine for a property type.
Machine * machine(MultiProperty *property)
void changed()
Emitted when something is changed in property editor.