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 <tdeapplication.h>
49static bool kofficeAppDirAdded =
false;
65 EditorPrivate(
Editor *editor)
66 : itemDict(101, false), justClickedItem(false)
71 itemToSelectLater = 0;
72 if (!kofficeAppDirAdded) {
73 kofficeAppDirAdded =
true;
74 TDEGlobal::iconLoader()->addAppDir(
"koffice");
76 previouslyCollapsedGroupItem = 0;
77 childFormPreviouslyCollapsedGroupItem = 0;
78 slotPropertyChanged_enabled =
true;
79 TQObject::connect(&changeSetLaterTimer, TQ_SIGNAL(timeout()),
80 editor, TQ_SLOT(changeSetLater()));
86 TQGuardedPtr<Set> set;
88 TQMap<Property*, Widget* > widgetCache;
89 TQGuardedPtr<Widget> currentWidget;
90 EditorItem *currentItem;
92 TQPushButton *undoButton;
93 EditorItem::Dict itemDict;
97 bool insideSlotValueChanged : 1;
100 TQTimer changeSetLaterTimer;
101 bool setListLater_set : 1;
102 bool preservePrevSelection_preservePrevSelection : 1;
103 TQCString preservePrevSelection_propertyToSelect;
106 bool justClickedItem : 1;
108 bool slotPropertyChanged_enabled : 1;
110 Set* setListLater_list;
112 EditorItem *itemToSelectLater;
114 TQListViewItem *previouslyCollapsedGroupItem;
115 TQListViewItem *childFormPreviouslyCollapsedGroupItem;
124 d =
new EditorPrivate(
this);
125 d->itemDict.setAutoDelete(
false);
131 d->insideSlotValueChanged =
false;
132 d->setListLater_set =
false;
133 d->preservePrevSelection_preservePrevSelection =
false;
134 d->setListLater_list = 0;
136 d->undoButton =
new TQPushButton(viewport());
137 d->undoButton->setFocusPolicy(TQWidget::NoFocus);
138 setFocusPolicy(TQWidget::ClickFocus);
139 d->undoButton->setMinimumSize(TQSize(5,5));
140 d->undoButton->setPixmap(SmallIcon(
"edit-undo"));
141 TQToolTip::add(d->undoButton, i18n(
"Undo changes"));
142 d->undoButton->hide();
143 connect(d->undoButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(
undo()));
145 installEventFilter(
this);
146 viewport()->installEventFilter(
this);
150 setAllColumnsShowFocus(
true);
151 setColumnWidthMode(0, TQListView::Maximum);
153 setShowSortIndicator(
false);
157 setItemMargin(KPROPEDITOR_ITEM_MARGIN);
158 header()->setMovingEnabled(
false );
159 setTreeStepSize(16 + 2 + 1);
164 connect(
this, TQ_SIGNAL(selectionChanged(TQListViewItem *)),
this, TQ_SLOT(
slotClicked(TQListViewItem *)));
165 connect(
this, TQ_SIGNAL(currentChanged(TQListViewItem *)),
this, TQ_SLOT(slotCurrentChanged(TQListViewItem *)));
166 connect(
this, TQ_SIGNAL(expanded(TQListViewItem *)),
this, TQ_SLOT(slotExpanded(TQListViewItem *)));
167 connect(
this, TQ_SIGNAL(collapsed(TQListViewItem *)),
this, TQ_SLOT(slotCollapsed(TQListViewItem *)));
168 connect(header(), TQ_SIGNAL(sizeChange(
int,
int,
int)),
this, TQ_SLOT(slotColumnSizeChanged(
int,
int,
int)));
171 connect(header(), TQ_SIGNAL(sectionHandleDoubleClicked (
int)),
this, TQ_SLOT(slotColumnSizeChanged(
int)));
172 updateGroupLabelsPosition();
185 setUpdatesEnabled(
false);
186 d->itemToSelectLater = 0;
187 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
189 TDEListView::clear();
194 setUpdatesEnabled(
true);
199 d->topItem =
new EditorDummyItem(
this);
201 const TQValueList<TQCString> groupNames = d->set->groupNames();
203 if(groupNames.count() == 1) {
205 const TQValueList<TQCString>& propertyNames = d->set->propertyNamesForGroup( groupNames.first() );
206 TQValueListConstIterator<TQCString> it = propertyNames.constBegin();
207 for( ; it != propertyNames.constEnd(); ++it)
211 EditorGroupItem *prevGroupItem = 0;
213 for (TQValueListConstIterator<TQCString> it = groupNames.constBegin(); it!=groupNames.constEnd();
216 const TQValueList<TQCString>& propertyNames = d->set->propertyNamesForGroup(*it);
217 EditorGroupItem *groupItem;
219 groupItem =
new EditorGroupItem(d->topItem, prevGroupItem,
220 d->set->groupDescription(*it), d->set->groupIcon(*it), sortOrder );
222 groupItem =
new EditorGroupItem(d->topItem,
223 d->set->groupDescription(*it), d->set->groupIcon(*it), sortOrder );
225 TQValueList<TQCString>::ConstIterator it2 = propertyNames.constBegin();
226 for( ; it2 != propertyNames.constEnd(); ++it2)
229 prevGroupItem = groupItem;
237 setCurrentItem(firstChild());
238 setSelected(firstChild(),
true);
240 updateGroupLabelsPosition();
242 setUpdatesEnabled(
true);
250 if(!d->set || !d->set->contains(name))
253 Property *
property = &(d->set->property(name));
254 if(!property || !property->isVisible()) {
258 TQListViewItem *last = parent ? parent->firstChild() : d->topItem->firstChild();
259 while(last && last->nextSibling())
260 last = last->nextSibling();
264 item =
new EditorItem(
this, parent, property, last);
266 item =
new EditorItem(
this, d->topItem, property, last);
267 d->itemDict.insert(name, item);
271 if(!property->children())
275 TQValueList<Property*>::ConstIterator endIt =
property->children()->constEnd();
276 for(TQValueList<Property*>::ConstIterator it = property->children()->constBegin(); it != endIt; ++it) {
278 if( *it && (*it)->isVisible() )
279 last =
new EditorItem(
this, item, *it, last);
298 if (d->insideSlotValueChanged) {
302 d->setListLater_list = set;
303 d->preservePrevSelection_preservePrevSelection = preservePrevSelection;
304 d->preservePrevSelection_propertyToSelect = propertyToSelect;
305 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
309 d->set->setPrevSelection( d->currentItem->property()->name() );
310 kdDebug() << d->set->prevSelection() << endl;
312 if (!d->setListLater_set) {
313 d->setListLater_set =
true;
314 d->changeSetLaterTimer.start(10,
true);
323 d->set->setPrevSelection( d->currentItem->property()->name() );
325 d->set->setPrevSelection(
"" );
326 d->set->disconnect(
this);
329 TQCString selectedPropertyName1 = propertyToSelect, selectedPropertyName2 = propertyToSelect;
330 if (preservePrevSelection) {
337 selectedPropertyName2 = d->set->prevSelection();
357 EditorItem * item = 0;
358 if (!selectedPropertyName2.isEmpty())
359 item = d->itemDict[selectedPropertyName2];
360 if (!item && !selectedPropertyName1.isEmpty())
361 item = d->itemDict[selectedPropertyName1];
364 d->itemToSelectLater = item;
365 TQTimer::singleShot(10,
this, TQ_SLOT(selectItemLater()));
375void Editor::selectItemLater()
377 if (!d->itemToSelectLater)
380 d->itemToSelectLater = 0;
381 setSelected(item,
true);
382 ensureItemVisible(item);
387Editor::changeSetLater()
389 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
390 if (kapp->hasPendingEvents()) {
391 d->changeSetLaterTimer.start(10,
true);
394 d->setListLater_set =
false;
395 if (!d->setListLater_list)
398 bool b = d->insideSlotValueChanged;
399 d->insideSlotValueChanged =
false;
400 changeSetInternal(d->setListLater_list, d->preservePrevSelection_preservePrevSelection,
401 d->preservePrevSelection_propertyToSelect);
402 d->insideSlotValueChanged = b;
408 d->itemToSelectLater = 0;
412 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
414 d->set->disconnect(
this);
416 TDEListView::clear();
425 if(!d->currentWidget || !d->currentItem || (d->set && d->set->isReadOnly()) || (d->currentWidget && d->currentWidget->isReadOnly()))
428 int propertySync = d->currentWidget->property()->autoSync();
429 bool sync = (propertySync != 0 && propertySync != 1) ?
430 d->sync : (propertySync!=0);
433 d->currentItem->property()->resetValue();
434 if (d->currentWidget && d->currentItem) {
435 d->currentWidget->setValue( d->currentItem->property()->value());
436 repaintItem(d->currentItem);
443 if (!d->slotPropertyChanged_enabled)
448 if (d->currentItem && d->currentItem->property() == &property) {
449 d->currentWidget->setValue(property.
value(),
false);
450 for(TQListViewItem *item = d->currentItem->firstChild(); item; item = item->nextSibling())
455 EditorItem *item = d->itemDict[
property.name()];
456 if(!item && property.
parent())
457 item = d->itemDict[
property.parent()->name()];
460 for(TQListViewItem *it = item->firstChild(); it; it = it->nextSibling())
468 const int delta =
property.value().toInt()-previousValue.toInt();
469 if (property.
type()==Rect_X) {
470 property.parent()->child(
"width")->setValue(delta,
false);
491Editor::slotPropertyReset(
Set& set,
Property& property)
496 if (d->currentItem && d->currentItem->
property() == &property) {
497 d->currentWidget->setValue(property.
value(),
false);
498 for(TQListViewItem *item = d->currentItem->firstChild(); item; item = item->nextSibling())
502 EditorItem *item = d->itemDict[
property.name()];
504 if(!item && property.
parent())
505 item = d->itemDict[
property.parent()->name()];
508 for(TQListViewItem *it = item->firstChild(); it; it = it->nextSibling())
513 showUndoButton(
false );
519 if(!widget || !d->set || (d->set && d->set->isReadOnly()) || (widget && widget->
isReadOnly()) || !widget->
property())
522 d->insideSlotValueChanged =
true;
524 TQVariant value = widget->
value();
526 bool sync = (propertySync != 0 && propertySync != 1) ?
527 d->sync : (propertySync!=0);
530 d->slotPropertyChanged_enabled =
false;
531 TQGuardedPtr<Widget> pWidget = widget;
534 showUndoButton( pWidget->property()->isModified() );
535 d->slotPropertyChanged_enabled =
true;
538 d->insideSlotValueChanged =
false;
550 if(!widget || !d->set || !widget->
property() || (d->set && d->set->isReadOnly()) || (widget && widget->
isReadOnly()))
559 if(!widget || !d->set)
568 d->previouslyCollapsedGroupItem = 0;
569 d->childFormPreviouslyCollapsedGroupItem = 0;
577 EditorItem *item =
static_cast<EditorItem*
>(it);
582 d->currentItem = item;
587 if (d->currentWidget) {
588 if (d->currentWidget->visibleFlag()) {
589 d->currentWidget->show();
590 if (
hasParent(
this, kapp->focusWidget() ))
591 d->currentWidget->setFocus();
595 d->justClickedItem =
true;
599Editor::slotCurrentChanged(TQListViewItem *item)
601 if (item == firstChild()) {
602 TQListViewItem *oldItem = item;
603 while (item && (!item->isSelectable() || !item->isVisible()))
604 item = item->itemBelow();
605 if (item && item != oldItem) {
606 setSelected(item,
true);
615 d->itemToSelectLater = 0;
616 if (d->currentWidget) {
618 d->currentWidget->setProperty(0);
634 TQGuardedPtr<Widget> widget = d->widgetCache[property];
641 d->widgetCache[property] = widget;
642 widget->setProperty(0);
644 connect(widget, TQ_SIGNAL(valueChanged(Widget*)),
648 connect(widget, TQ_SIGNAL(rejectInput(Widget*)),
653 updateEditorGeometry(d->currentItem, widget);
655 if(widget && (!widget->property() || changeWidgetProperty))
656 widget->setProperty(property);
669 for(TQMap<Property*, Widget*>::iterator it = d->widgetCache.begin(); it != d->widgetCache.end(); ++it)
670 it.data()->deleteLater();
672 d->widgetCache.clear();
676Editor::updateEditorGeometry(
bool forceUndoButtonSettings,
bool undoButtonVisible)
678 updateEditorGeometry(d->currentItem, d->currentWidget,
679 forceUndoButtonSettings, undoButtonVisible);
684 bool forceUndoButtonSettings,
bool undoButtonVisible)
689 int placeForUndoButton;
690 if (forceUndoButtonSettings ? undoButtonVisible : d->undoButton->isVisible())
691 placeForUndoButton = d->undoButton->width();
696 int y = itemPos(item);
697 r.setX(header()->sectionPos(1)-(widget->
hasBorders()?1:0));
699 r.setWidth(header()->sectionSize(1)+(widget->
hasBorders()?1:0)
700 - placeForUndoButton);
701 r.setHeight(item->height()+(widget->
hasBorders()?1:-1));
704 if (visibleWidth() < r.right())
705 r.setRight(visibleWidth());
707 moveChild(widget, r.x(), r.y());
708 widget->resize(r.size());
709 tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents);
713Editor::updateGroupLabelsPosition()
715 if(!d->topItem || d->itemDict.isEmpty())
718 EditorGroupItem *group =
dynamic_cast<EditorGroupItem*
>(d->topItem->firstChild());
720 TQRect r = itemRect((TQListViewItem*) group);
722 group->label()->setGeometry(r);
723 group->label()->repaint();
725 group =
dynamic_cast<EditorGroupItem*
>(group->nextSibling());
733 TQWidget *cw = d->currentWidget;
735 d->currentWidget = 0;
738 d->undoButton->hide();
742Editor::showUndoButton(
bool show )
744 if (!d->currentItem || !d->currentWidget || (d->currentWidget && d->currentWidget->isReadOnly()))
747 int y = viewportToContents(TQPoint(0, itemRect(d->currentItem).y())).y();
748 TQRect geometry(columnWidth(0), y, columnWidth(1) + 1, d->currentItem->height());
749 d->undoButton->resize(d->baseRowHeight, d->currentItem->height());
751 updateEditorGeometry(
true, show);
760 d->undoButton->hide();
764 TQPoint p = contentsToViewport(TQPoint(0, geometry.y()));
765 d->undoButton->move(geometry.x() + geometry.width()
766 -((d->currentWidget && d->currentWidget->hasBorders())?1:0)
767 - d->undoButton->width(), p.y());
772 d->undoButton->show();
776Editor::slotExpanded(TQListViewItem *item)
782 if (!selectedItem() &&
dynamic_cast<EditorGroupItem*
>(item) && d->previouslyCollapsedGroupItem == item
783 && d->childFormPreviouslyCollapsedGroupItem) {
784 setSelected(d->childFormPreviouslyCollapsedGroupItem,
true);
785 setCurrentItem(selectedItem());
788 updateEditorGeometry();
789 updateGroupLabelsPosition();
795Editor::slotCollapsed(TQListViewItem *item)
800 if (
dynamic_cast<EditorGroupItem*
>(item)) {
801 for (TQListViewItem *i = selectedItem(); i; i = i->parent()) {
802 if (i->parent()==item) {
803 d->previouslyCollapsedGroupItem = item;
804 d->childFormPreviouslyCollapsedGroupItem = selectedItem();
806 setSelected(selectedItem(),
false);
807 setSelected(item->nextSibling(),
true);
812 updateEditorGeometry();
813 updateGroupLabelsPosition();
819Editor::slotColumnSizeChanged(
int section,
int oldSize,
int newSize)
844 updateEditorGeometry();
849Editor::slotColumnSizeChanged(
int section)
851 setColumnWidth(1, viewport()->width() - columnWidth(0));
852 slotColumnSizeChanged(section, 0, header()->sectionSize(section));
862 if(d->undoButton->isVisible())
863 showUndoButton(
true);
865 updateEditorGeometry();
869Editor::sizeHint()
const
871 return TQSize( TQFontMetrics(font()).width(columnText(0)+columnText(1)+
" "),
872 TDEListView::sizeHint().height());
878 EditorItem *item =
static_cast<EditorItem *
>(selectedItem());
880 if (!d->justClickedItem)
881 ensureItemVisible(item);
882 d->justClickedItem =
false;
886 item =
static_cast<EditorItem *
>(itemAt(TQPoint(10,1)));
888 ensureItemVisible(item);
889 setSelected(item,
true);
892 if (d->currentWidget) {
894 d->currentWidget->setFocus();
898 TDEListView::setFocus();
903Editor::resizeEvent(TQResizeEvent *ev)
905 TDEListView::resizeEvent(ev);
906 if(d->undoButton->isVisible())
907 showUndoButton(
true);
909 updateGroupLabelsPosition();
913Editor::eventFilter( TQObject * watched, TQEvent * e )
915 if ((watched==
this || watched==viewport()) && e->type()==TQEvent::KeyPress) {
916 if (handleKeyPress(
static_cast<TQKeyEvent*
>(e)))
919 return TDEListView::eventFilter(watched, e);
923Editor::handleKeyPress(TQKeyEvent* ev)
925 const int k = ev->key();
926 const TQt::ButtonState s = ev->state();
929 TQListViewItem *item = 0;
931 if ( ((s == TQt::NoButton) && (k == Key_Up)) || (k==Key_BackTab) ) {
933 item = selectedItem() ? selectedItem()->itemAbove() : 0;
934 while (item && (!item->isSelectable() || !item->isVisible()))
935 item = item->itemAbove();
939 else if( (s == TQt::NoButton) && ((k == Key_Down) || (k == Key_Tab)) ) {
941 item = selectedItem() ? selectedItem()->itemBelow() : 0;
942 while (item && (!item->isSelectable() || !item->isVisible()))
943 item = item->itemBelow();
947 else if( (s==TQt::NoButton) && (k==Key_Home) ) {
948 if (d->currentWidget && d->currentWidget->hasFocus())
952 while (item && (!item->isSelectable() || !item->isVisible()))
953 item = item->itemBelow();
955 else if( (s==TQt::NoButton) && (k==Key_End) ) {
956 if (d->currentWidget && d->currentWidget->hasFocus())
959 item = selectedItem();
960 TQListViewItem *lastVisible = item;
962 item = item->itemBelow();
963 if (item && item->isSelectable() && item->isVisible())
971 ensureItemVisible(item);
972 setSelected(item,
true);
981 setFont(parentWidget()->font());
982 d->baseRowHeight = TQFontMetrics(parentWidget()->font()).height() + itemMargin() * 2;
984 d->undoButton->resize(d->baseRowHeight, d->baseRowHeight);
986 showUndoButton(d->undoButton->isVisible());
987 updateEditorGeometry();
989 updateGroupLabelsPosition();
993Editor::event( TQEvent * e )
995 if (e->type()==TQEvent::ParentFontChange) {
1002Editor::contentsMousePressEvent( TQMouseEvent * e )
1004 TQListViewItem *item = itemAt(e->pos());
1005 if (
dynamic_cast<EditorGroupItem*
>(item)) {
1006 setOpen( item, !isOpen(item) );
1013Editor::setSorting(
int column,
bool ascending )
1015 if (d->set && d->set->groupNames().count()>1)
1018 updateEditorGeometry();
1019 updateGroupLabelsPosition();
1024#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)
TDEListView(TQWidget *parent=0, const char *name=0)
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)