23#include "editoritem.h"
29#include <tqpushbutton.h>
32#include <tqguardedptr.h>
34#include <tqasciidict.h>
36#include <tqapplication.h>
37#include <tqeventloop.h>
42#include <kiconloader.h>
44#include <tdeversion.h>
45#include <tdeapplication.h>
50static bool kofficeAppDirAdded =
false;
66 EditorPrivate(
Editor *editor)
67 : itemDict(101, false), justClickedItem(false)
72 itemToSelectLater = 0;
73 if (!kofficeAppDirAdded) {
74 kofficeAppDirAdded =
true;
75 TDEGlobal::iconLoader()->addAppDir(
"koffice");
77 previouslyCollapsedGroupItem = 0;
78 childFormPreviouslyCollapsedGroupItem = 0;
79 slotPropertyChanged_enabled =
true;
80 TQObject::connect(&changeSetLaterTimer, TQ_SIGNAL(timeout()),
81 editor, TQ_SLOT(changeSetLater()));
87 TQGuardedPtr<Set> set;
89 TQMap<Property*, Widget* > widgetCache;
90 TQGuardedPtr<Widget> currentWidget;
93 TQPushButton *undoButton;
94 EditorItem::Dict itemDict;
98 bool insideSlotValueChanged : 1;
101 TQTimer changeSetLaterTimer;
102 bool setListLater_set : 1;
103 bool preservePrevSelection_preservePrevSelection : 1;
104 TQCString preservePrevSelection_propertyToSelect;
107 bool justClickedItem : 1;
109 bool slotPropertyChanged_enabled : 1;
111 Set* setListLater_list;
115 TQListViewItem *previouslyCollapsedGroupItem;
116 TQListViewItem *childFormPreviouslyCollapsedGroupItem;
125 d =
new EditorPrivate(
this);
126 d->itemDict.setAutoDelete(
false);
132 d->insideSlotValueChanged =
false;
133 d->setListLater_set =
false;
134 d->preservePrevSelection_preservePrevSelection =
false;
135 d->setListLater_list = 0;
137 d->undoButton =
new TQPushButton(viewport());
138 d->undoButton->setFocusPolicy(TQWidget::NoFocus);
139 setFocusPolicy(TQWidget::ClickFocus);
140 d->undoButton->setMinimumSize(TQSize(5,5));
141 d->undoButton->setPixmap(SmallIcon(
"edit-undo"));
142 TQToolTip::add(d->undoButton, i18n(
"Undo changes"));
143 d->undoButton->hide();
144 connect(d->undoButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(
undo()));
146 installEventFilter(
this);
147 viewport()->installEventFilter(
this);
151 setAllColumnsShowFocus(
true);
152 setColumnWidthMode(0, TQListView::Maximum);
154 setShowSortIndicator(
false);
155#if KDE_IS_VERSION(3,3,9)
160 setItemMargin(KPROPEDITOR_ITEM_MARGIN);
161 header()->setMovingEnabled(
false );
162 setTreeStepSize(16 + 2 + 1);
167 connect(
this, TQ_SIGNAL(selectionChanged(TQListViewItem *)),
this, TQ_SLOT(
slotClicked(TQListViewItem *)));
168 connect(
this, TQ_SIGNAL(currentChanged(TQListViewItem *)),
this, TQ_SLOT(slotCurrentChanged(TQListViewItem *)));
169 connect(
this, TQ_SIGNAL(expanded(TQListViewItem *)),
this, TQ_SLOT(slotExpanded(TQListViewItem *)));
170 connect(
this, TQ_SIGNAL(collapsed(TQListViewItem *)),
this, TQ_SLOT(slotCollapsed(TQListViewItem *)));
171 connect(header(), TQ_SIGNAL(sizeChange(
int,
int,
int)),
this, TQ_SLOT(slotColumnSizeChanged(
int,
int,
int)));
174 connect(header(), TQ_SIGNAL(sectionHandleDoubleClicked (
int)),
this, TQ_SLOT(slotColumnSizeChanged(
int)));
175 updateGroupLabelsPosition();
188 setUpdatesEnabled(
false);
189 d->itemToSelectLater = 0;
190 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
192 TDEListView::clear();
197 setUpdatesEnabled(
true);
202 d->topItem =
new EditorDummyItem(
this);
204 const TQValueList<TQCString> groupNames = d->set->groupNames();
206 if(groupNames.count() == 1) {
208 const TQValueList<TQCString>& propertyNames = d->set->propertyNamesForGroup( groupNames.first() );
209 TQValueListConstIterator<TQCString> it = propertyNames.constBegin();
210 for( ; it != propertyNames.constEnd(); ++it)
214 EditorGroupItem *prevGroupItem = 0;
216 for (TQValueListConstIterator<TQCString> it = groupNames.constBegin(); it!=groupNames.constEnd();
219 const TQValueList<TQCString>& propertyNames = d->set->propertyNamesForGroup(*it);
220 EditorGroupItem *groupItem;
222 groupItem =
new EditorGroupItem(d->topItem, prevGroupItem,
223 d->set->groupDescription(*it), d->set->groupIcon(*it), sortOrder );
225 groupItem =
new EditorGroupItem(d->topItem,
226 d->set->groupDescription(*it), d->set->groupIcon(*it), sortOrder );
228 TQValueList<TQCString>::ConstIterator it2 = propertyNames.constBegin();
229 for( ; it2 != propertyNames.constEnd(); ++it2)
232 prevGroupItem = groupItem;
240 setCurrentItem(firstChild());
241 setSelected(firstChild(),
true);
243 updateGroupLabelsPosition();
245 setUpdatesEnabled(
true);
253 if(!d->set || !d->set->contains(name))
256 Property *
property = &(d->set->property(name));
257 if(!property || !property->isVisible()) {
261 TQListViewItem *last = parent ? parent->firstChild() : d->topItem->firstChild();
262 while(last && last->nextSibling())
263 last = last->nextSibling();
267 item =
new EditorItem(
this, parent, property, last);
269 item =
new EditorItem(
this, d->topItem, property, last);
270 d->itemDict.insert(name, item);
274 if(!property->children())
278 TQValueList<Property*>::ConstIterator endIt =
property->children()->constEnd();
279 for(TQValueList<Property*>::ConstIterator it = property->children()->constBegin(); it != endIt; ++it) {
281 if( *it && (*it)->isVisible() )
301 if (d->insideSlotValueChanged) {
305 d->setListLater_list = set;
306 d->preservePrevSelection_preservePrevSelection = preservePrevSelection;
307 d->preservePrevSelection_propertyToSelect = propertyToSelect;
308 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
312 d->set->setPrevSelection( d->currentItem->property()->name() );
313 kdDebug() << d->set->prevSelection() << endl;
315 if (!d->setListLater_set) {
316 d->setListLater_set =
true;
317 d->changeSetLaterTimer.start(10,
true);
326 d->set->setPrevSelection( d->currentItem->property()->name() );
328 d->set->setPrevSelection(
"" );
329 d->set->disconnect(
this);
332 TQCString selectedPropertyName1 = propertyToSelect, selectedPropertyName2 = propertyToSelect;
333 if (preservePrevSelection) {
340 selectedPropertyName2 = d->set->prevSelection();
361 if (!selectedPropertyName2.isEmpty())
362 item = d->itemDict[selectedPropertyName2];
363 if (!item && !selectedPropertyName1.isEmpty())
364 item = d->itemDict[selectedPropertyName1];
367 d->itemToSelectLater = item;
368 TQTimer::singleShot(10,
this, TQ_SLOT(selectItemLater()));
378void Editor::selectItemLater()
380 if (!d->itemToSelectLater)
383 d->itemToSelectLater = 0;
384 setSelected(item,
true);
385 ensureItemVisible(item);
390Editor::changeSetLater()
392 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
393 if (kapp->hasPendingEvents()) {
394 d->changeSetLaterTimer.start(10,
true);
397 d->setListLater_set =
false;
398 if (!d->setListLater_list)
401 bool b = d->insideSlotValueChanged;
402 d->insideSlotValueChanged =
false;
403 changeSetInternal(d->setListLater_list, d->preservePrevSelection_preservePrevSelection,
404 d->preservePrevSelection_propertyToSelect);
405 d->insideSlotValueChanged = b;
411 d->itemToSelectLater = 0;
415 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
417 d->set->disconnect(
this);
419 TDEListView::clear();
428 if(!d->currentWidget || !d->currentItem || (d->set && d->set->isReadOnly()) || (d->currentWidget && d->currentWidget->isReadOnly()))
431 int propertySync = d->currentWidget->property()->autoSync();
432 bool sync = (propertySync != 0 && propertySync != 1) ?
433 d->sync : (propertySync!=0);
436 d->currentItem->property()->resetValue();
437 if (d->currentWidget && d->currentItem) {
438 d->currentWidget->setValue( d->currentItem->property()->value());
439 repaintItem(d->currentItem);
446 if (!d->slotPropertyChanged_enabled)
451 if (d->currentItem && d->currentItem->property() == &property) {
452 d->currentWidget->setValue(property.
value(),
false);
453 for(TQListViewItem *item = d->currentItem->firstChild(); item; item = item->nextSibling())
458 EditorItem *item = d->itemDict[
property.name()];
459 if(!item && property.
parent())
460 item = d->itemDict[property.
parent()->
name()];
463 for(TQListViewItem *it = item->firstChild(); it; it = it->nextSibling())
471 const int delta =
property.value().toInt()-previousValue.toInt();
472 if (property.
type()==Rect_X) {
473 property.parent()->child(
"width")->setValue(delta,
false);
494Editor::slotPropertyReset(
Set& set,
Property& property)
499 if (d->currentItem && d->currentItem->property() == &property) {
500 d->currentWidget->setValue(property.
value(),
false);
501 for(TQListViewItem *item = d->currentItem->firstChild(); item; item = item->nextSibling())
505 EditorItem *item = d->itemDict[
property.name()];
507 if(!item && property.
parent())
508 item = d->itemDict[property.
parent()->
name()];
511 for(TQListViewItem *it = item->firstChild(); it; it = it->nextSibling())
516 showUndoButton(
false );
522 if(!widget || !d->set || (d->set && d->set->isReadOnly()) || (widget && widget->
isReadOnly()) || !widget->
property())
525 d->insideSlotValueChanged =
true;
527 TQVariant value = widget->
value();
529 bool sync = (propertySync != 0 && propertySync != 1) ?
530 d->sync : (propertySync!=0);
533 d->slotPropertyChanged_enabled =
false;
534 TQGuardedPtr<Widget> pWidget = widget;
537 showUndoButton( pWidget->property()->isModified() );
538 d->slotPropertyChanged_enabled =
true;
541 d->insideSlotValueChanged =
false;
553 if(!widget || !d->set || !widget->
property() || (d->set && d->set->isReadOnly()) || (widget && widget->
isReadOnly()))
562 if(!widget || !d->set)
571 d->previouslyCollapsedGroupItem = 0;
572 d->childFormPreviouslyCollapsedGroupItem = 0;
585 d->currentItem = item;
590 if (d->currentWidget) {
591 if (d->currentWidget->visibleFlag()) {
592 d->currentWidget->show();
593 if (
hasParent(
this, kapp->focusWidget() ))
594 d->currentWidget->setFocus();
598 d->justClickedItem =
true;
602Editor::slotCurrentChanged(TQListViewItem *item)
604 if (item == firstChild()) {
605 TQListViewItem *oldItem = item;
606 while (item && (!item->isSelectable() || !item->isVisible()))
607 item = item->itemBelow();
608 if (item && item != oldItem) {
609 setSelected(item,
true);
618 d->itemToSelectLater = 0;
619 if (d->currentWidget) {
621 d->currentWidget->setProperty(0);
637 TQGuardedPtr<Widget> widget = d->widgetCache[property];
644 d->widgetCache[property] = widget;
645 widget->setProperty(0);
647 connect(widget, TQ_SIGNAL(valueChanged(
Widget*)),
651 connect(widget, TQ_SIGNAL(rejectInput(
Widget*)),
656 updateEditorGeometry(d->currentItem, widget);
658 if(widget && (!widget->property() || changeWidgetProperty))
659 widget->setProperty(property);
672 for(TQMap<Property*, Widget*>::iterator it = d->widgetCache.begin(); it != d->widgetCache.end(); ++it)
673 it.data()->deleteLater();
675 d->widgetCache.clear();
679Editor::updateEditorGeometry(
bool forceUndoButtonSettings,
bool undoButtonVisible)
681 updateEditorGeometry(d->currentItem, d->currentWidget,
682 forceUndoButtonSettings, undoButtonVisible);
687 bool forceUndoButtonSettings,
bool undoButtonVisible)
692 int placeForUndoButton;
693 if (forceUndoButtonSettings ? undoButtonVisible : d->undoButton->isVisible())
694 placeForUndoButton = d->undoButton->width();
699 int y = itemPos(item);
700 r.setX(header()->sectionPos(1)-(widget->
hasBorders()?1:0));
702 r.setWidth(header()->sectionSize(1)+(widget->
hasBorders()?1:0)
703 - placeForUndoButton);
704 r.setHeight(item->height()+(widget->
hasBorders()?1:-1));
707 if (visibleWidth() < r.right())
708 r.setRight(visibleWidth());
710 moveChild(widget, r.x(), r.y());
711 widget->resize(r.size());
712 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
716Editor::updateGroupLabelsPosition()
718 if(!d->topItem || d->itemDict.isEmpty())
721 EditorGroupItem *group =
dynamic_cast<EditorGroupItem*
>(d->topItem->firstChild());
723 TQRect r = itemRect((TQListViewItem*) group);
725 group->label()->setGeometry(r);
726 group->label()->repaint();
728 group =
dynamic_cast<EditorGroupItem*
>(group->nextSibling());
736 TQWidget *cw = d->currentWidget;
738 d->currentWidget = 0;
741 d->undoButton->hide();
745Editor::showUndoButton(
bool show )
747 if (!d->currentItem || !d->currentWidget || (d->currentWidget && d->currentWidget->isReadOnly()))
750 int y = viewportToContents(TQPoint(0, itemRect(d->currentItem).y())).y();
751 TQRect geometry(columnWidth(0), y, columnWidth(1) + 1, d->currentItem->height());
752 d->undoButton->resize(d->baseRowHeight, d->currentItem->height());
754 updateEditorGeometry(
true, show);
763 d->undoButton->hide();
767 TQPoint p = contentsToViewport(TQPoint(0, geometry.y()));
768 d->undoButton->move(geometry.x() + geometry.width()
769 -((d->currentWidget && d->currentWidget->hasBorders())?1:0)
770 - d->undoButton->width(), p.y());
775 d->undoButton->show();
779Editor::slotExpanded(TQListViewItem *item)
785 if (!selectedItem() &&
dynamic_cast<EditorGroupItem*
>(item) && d->previouslyCollapsedGroupItem == item
786 && d->childFormPreviouslyCollapsedGroupItem) {
787 setSelected(d->childFormPreviouslyCollapsedGroupItem,
true);
788 setCurrentItem(selectedItem());
791 updateEditorGeometry();
792 updateGroupLabelsPosition();
798Editor::slotCollapsed(TQListViewItem *item)
803 if (
dynamic_cast<EditorGroupItem*
>(item)) {
804 for (TQListViewItem *i = selectedItem(); i; i = i->parent()) {
805 if (i->parent()==item) {
806 d->previouslyCollapsedGroupItem = item;
807 d->childFormPreviouslyCollapsedGroupItem = selectedItem();
809 setSelected(selectedItem(),
false);
810 setSelected(item->nextSibling(),
true);
815 updateEditorGeometry();
816 updateGroupLabelsPosition();
822Editor::slotColumnSizeChanged(
int section,
int oldSize,
int newSize)
847 updateEditorGeometry();
852Editor::slotColumnSizeChanged(
int section)
854 setColumnWidth(1, viewport()->width() - columnWidth(0));
855 slotColumnSizeChanged(section, 0, header()->sectionSize(section));
865 if(d->undoButton->isVisible())
866 showUndoButton(
true);
868 updateEditorGeometry();
872Editor::sizeHint()
const
874 return TQSize( TQFontMetrics(font()).width(columnText(0)+columnText(1)+
" "),
875 TDEListView::sizeHint().height());
883 if (!d->justClickedItem)
884 ensureItemVisible(item);
885 d->justClickedItem =
false;
889 item =
static_cast<EditorItem *
>(itemAt(TQPoint(10,1)));
891 ensureItemVisible(item);
892 setSelected(item,
true);
895 if (d->currentWidget) {
897 d->currentWidget->setFocus();
901 TDEListView::setFocus();
906Editor::resizeEvent(TQResizeEvent *ev)
908 TDEListView::resizeEvent(ev);
909 if(d->undoButton->isVisible())
910 showUndoButton(
true);
912 updateGroupLabelsPosition();
916Editor::eventFilter( TQObject * watched, TQEvent * e )
918 if ((watched==
this || watched==viewport()) && e->type()==TQEvent::KeyPress) {
919 if (handleKeyPress(
static_cast<TQKeyEvent*
>(e)))
922 return TDEListView::eventFilter(watched, e);
926Editor::handleKeyPress(TQKeyEvent* ev)
928 const int k = ev->key();
929 const TQt::ButtonState s = ev->state();
932 TQListViewItem *item = 0;
934 if ( ((s == TQt::NoButton) && (k == Key_Up)) || (k==Key_BackTab) ) {
936 item = selectedItem() ? selectedItem()->itemAbove() : 0;
937 while (item && (!item->isSelectable() || !item->isVisible()))
938 item = item->itemAbove();
942 else if( (s == TQt::NoButton) && ((k == Key_Down) || (k == Key_Tab)) ) {
944 item = selectedItem() ? selectedItem()->itemBelow() : 0;
945 while (item && (!item->isSelectable() || !item->isVisible()))
946 item = item->itemBelow();
950 else if( (s==TQt::NoButton) && (k==Key_Home) ) {
951 if (d->currentWidget && d->currentWidget->hasFocus())
955 while (item && (!item->isSelectable() || !item->isVisible()))
956 item = item->itemBelow();
958 else if( (s==TQt::NoButton) && (k==Key_End) ) {
959 if (d->currentWidget && d->currentWidget->hasFocus())
962 item = selectedItem();
963 TQListViewItem *lastVisible = item;
965 item = item->itemBelow();
966 if (item && item->isSelectable() && item->isVisible())
974 ensureItemVisible(item);
975 setSelected(item,
true);
984 setFont(parentWidget()->font());
985 d->baseRowHeight = TQFontMetrics(parentWidget()->font()).height() + itemMargin() * 2;
987 d->undoButton->resize(d->baseRowHeight, d->baseRowHeight);
989 showUndoButton(d->undoButton->isVisible());
990 updateEditorGeometry();
992 updateGroupLabelsPosition();
996Editor::event( TQEvent * e )
998 if (e->type()==TQEvent::ParentFontChange) {
1005Editor::contentsMousePressEvent( TQMouseEvent * e )
1007 TQListViewItem *item = itemAt(e->pos());
1008 if (
dynamic_cast<EditorGroupItem*
>(item)) {
1009 setOpen( item, !isOpen(item) );
1016Editor::setSorting(
int column,
bool ascending )
1018 if (d->set && d->set->groupNames().count()>1)
1021 updateEditorGeometry();
1022 updateGroupLabelsPosition();
1027#include "editor.moc"
Item for a single property displayed within Editor object.
A listview to edit properties Editor widgets use property options using Property::option(const char *...
void slotWidgetValueChanged(Widget *widget)
void slotSetWillBeDeleted()
Editor(TQWidget *parent=0, bool autoSync=true, const char *name=0)
void slotWidgetRejectInput(Widget *widget)
void changeSetInternal(Set *set, bool preservePrevSelection, const TQCString &propertyToSelect)
void slotClicked(TQListViewItem *item)
void slotWidgetAcceptInput(Widget *widget)
void slotSetWillBeCleared()
void addItem(const TQCString &name, EditorItem *parent)
void clear(bool editorOnly=false)
void propertySetChanged(KoProperty::Set *set)
Widget * createWidgetForProperty(Property *property, bool changeWidgetProperty=true)
void changeSet(Set *set, bool preservePrevSelection=false)
void slotPropertyChanged(KoProperty::Set &set, KoProperty::Property &property)
Widget * createWidgetForProperty(Property *property)
static FactoryManager * self()
The base class representing a single property.
Property * parent() const
void setValue(const TQVariant &value, bool rememberOldValue=true, bool useCustomProperty=true)
Lists holding properties in groups.
TQCString prevSelection() const
virtual void setTooltipColumn(int column)
virtual int addColumn(const TQString &label, int width=-1)
virtual bool event(TQEvent *)
void setFullWidth() TDE_DEPRECATED
void setShadeSortColumn(bool shadeSortColumn)
virtual void setSorting(int column, bool ascending=true)
virtual void contentsMousePressEvent(TQMouseEvent *e)
Namespace for a set of classes implementing generic properties framework.
@ Rect
rectangle (x,y, width, height)
bool hasParent(TQObject *par, TQObject *o)