44 #include <QGridLayout>
48 #include <QToolButton>
59 void init(QWidget* parent);
90 void insertRow(QGridLayout* layout,
int row)
const;
91 void removeRow(QGridLayout* layout,
int row)
const;
94 void setExpanded(
WidgetItem* item,
bool expanded);
95 QToolButton* createButton(QWidget* panret = 0)
const;
97 QMap<QtBrowserItem*, WidgetItem*> m_indexToItem;
98 QMap<WidgetItem*, QtBrowserItem*> m_itemToIndex;
99 QMap<QWidget*, WidgetItem*> m_widgetToItem;
100 QMap<QObject*, WidgetItem*> m_buttonToItem;
101 QGridLayout* m_mainLayout;
102 QList<WidgetItem*> m_children;
103 QList<WidgetItem*> m_recreateQueue;
106 QToolButton* QtButtonPropertyBrowserPrivate::createButton(QWidget* parent)
const
108 QToolButton* button =
new QToolButton(parent);
109 button->setCheckable(
true);
110 button->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
111 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
112 button->setArrowType(Qt::DownArrow);
113 button->setIconSize(QSize(3, 16));
123 int QtButtonPropertyBrowserPrivate::gridRow(
WidgetItem* item)
const
125 QList<WidgetItem*> siblings;
133 siblings = m_children;
137 QListIterator<WidgetItem*> it(siblings);
148 row += gridSpan(sibling);
154 int QtButtonPropertyBrowserPrivate::gridSpan(
WidgetItem* item)
const
166 m_mainLayout =
new QGridLayout();
167 parent->setLayout(m_mainLayout);
168 QLayoutItem* item =
new QSpacerItem(0, 0,
169 QSizePolicy::Fixed, QSizePolicy::Expanding);
170 m_mainLayout->addItem(item, 0, 0);
175 QWidget* editor = qobject_cast<QWidget*>(q_ptr->sender());
182 if (!m_widgetToItem.contains(editor))
187 m_widgetToItem[editor]->widget = 0;
188 m_widgetToItem.remove(editor);
193 QListIterator<WidgetItem*> itItem(m_recreateQueue);
195 while (itItem.hasNext())
202 const int oldRow = gridRow(item);
222 item->
label =
new QLabel(w);
223 item->
label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
224 l->addWidget(item->
label, oldRow, 0, 1, span);
229 m_recreateQueue.clear();
232 void QtButtonPropertyBrowserPrivate::setExpanded(WidgetItem* item,
bool expanded)
234 if (item->expanded == expanded)
239 if (!item->container)
244 item->expanded = expanded;
245 const int row = gridRow(item);
246 WidgetItem* parent = item->parent;
260 insertRow(l, row + 1);
261 l->addWidget(item->container, row + 1, 0, 1, 2);
262 item->container->show();
266 l->removeWidget(item->container);
267 item->container->hide();
268 removeRow(l, row + 1);
271 item->button->setChecked(expanded);
272 item->button->setArrowType(expanded ? Qt::UpArrow : Qt::DownArrow);
277 WidgetItem* item = m_buttonToItem.value(q_ptr->sender());
284 setExpanded(item, checked);
288 emit q_ptr->
expanded(m_itemToIndex.value(item));
292 emit q_ptr->
collapsed(m_itemToIndex.value(item));
296 void QtButtonPropertyBrowserPrivate::updateLater()
298 QTimer::singleShot(0, q_ptr, SLOT(
slotUpdate()));
303 WidgetItem* afterItem = m_indexToItem.value(afterIndex);
307 newItem->
parent = parentItem;
309 QGridLayout* layout = 0;
310 QWidget* parentWidget = 0;
319 parentItem->
children.insert(0, newItem);
323 m_children.insert(0, newItem);
328 row = gridRow(afterItem) + gridSpan(afterItem);
332 parentItem->
children.insert(parentItem->
children.indexOf(afterItem) + 1, newItem);
336 m_children.insert(m_children.indexOf(afterItem) + 1, newItem);
342 layout = m_mainLayout;
343 parentWidget = q_ptr;
349 m_recreateQueue.removeAll(parentItem);
352 const int oldRow = gridRow(parentItem);
363 QFrame* container =
new QFrame();
364 container->setFrameShape(QFrame::Panel);
365 container->setFrameShadow(QFrame::Raised);
367 parentItem->
button = createButton();
368 m_buttonToItem[parentItem->
button] = parentItem;
369 q_ptr->connect(parentItem->
button, SIGNAL(toggled(
bool)), q_ptr, SLOT(
slotToggled(
bool)));
370 parentItem->
layout =
new QGridLayout();
371 container->setLayout(parentItem->
layout);
373 if (parentItem->
label)
375 l->removeWidget(parentItem->
label);
376 delete parentItem->
label;
377 parentItem->
label = 0;
387 l->addWidget(parentItem->
button, oldRow, 0, 1, span);
388 updateItem(parentItem);
391 layout = parentItem->
layout;
395 newItem->
label =
new QLabel(parentWidget);
396 newItem->
label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
402 m_widgetToItem[newItem->
widget] = newItem;
404 else if (
index->property()->hasValue())
407 newItem->
widgetLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
410 insertRow(layout, row);
415 layout->addWidget(newItem->
widget, row, 1);
426 layout->addWidget(newItem->
label, row, 0, span, 1);
428 m_itemToIndex[newItem] =
index;
429 m_indexToItem[
index] = newItem;
438 m_indexToItem.remove(
index);
439 m_itemToIndex.remove(item);
443 const int row = gridRow(item);
451 m_children.removeAt(m_children.indexOf(item));
454 const int colSpan = gridSpan(item);
456 m_buttonToItem.remove(item->
button);
485 removeRow(m_mainLayout, row);
489 removeRow(m_mainLayout, row);
492 else if (parentItem->
children.count() != 0)
494 removeRow(parentItem->
layout, row);
498 removeRow(parentItem->
layout, row);
515 const int parentRow = gridRow(parentItem);
516 const int parentSpan = gridSpan(parentItem);
518 l->removeWidget(parentItem->
button);
520 delete parentItem->
button;
526 if (!m_recreateQueue.contains(parentItem))
528 m_recreateQueue.append(parentItem);
533 removeRow(l, parentRow + 1);
539 m_recreateQueue.removeAll(item);
544 void QtButtonPropertyBrowserPrivate::insertRow(QGridLayout* layout,
int row)
const
546 QMap<QLayoutItem*, QRect> itemToPos;
549 while (idx < layout->count())
552 layout->getItemPosition(idx, &r, &
c, &rs, &cs);
556 itemToPos[layout->takeAt(idx)] = QRect(r + 1,
c, rs, cs);
564 const QMap<QLayoutItem*, QRect>::ConstIterator icend = itemToPos.constEnd();
566 for (QMap<QLayoutItem*, QRect>::ConstIterator it = itemToPos.constBegin(); it != icend; ++it)
568 const QRect r = it.value();
569 layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height());
573 void QtButtonPropertyBrowserPrivate::removeRow(QGridLayout* layout,
int row)
const
575 QMap<QLayoutItem*, QRect> itemToPos;
578 while (idx < layout->count())
581 layout->getItemPosition(idx, &r, &
c, &rs, &cs);
585 itemToPos[layout->takeAt(idx)] = QRect(r - 1,
c, rs, cs);
593 const QMap<QLayoutItem*, QRect>::ConstIterator icend = itemToPos.constEnd();
595 for (QMap<QLayoutItem*, QRect>::ConstIterator it = itemToPos.constBegin(); it != icend; ++it)
597 const QRect r = it.value();
598 layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height());
609 void QtButtonPropertyBrowserPrivate::updateItem(WidgetItem* item)
611 QtProperty*
property = m_itemToIndex[item]->property();
615 QFont font = item->button->font();
616 font.setUnderline(property->isModified());
617 item->button->setFont(font);
618 item->button->setText(property->propertyName());
619 item->button->setToolTip(property->toolTip());
620 item->button->setStatusTip(property->statusTip());
621 item->button->setWhatsThis(property->whatsThis());
622 item->button->setEnabled(property->isEnabled());
627 QFont font = item->label->font();
628 font.setUnderline(property->isModified());
629 item->label->setFont(font);
630 item->label->setText(property->propertyName());
631 item->label->setToolTip(property->toolTip());
632 item->label->setStatusTip(property->statusTip());
633 item->label->setWhatsThis(property->whatsThis());
634 item->label->setEnabled(property->isEnabled());
637 if (item->widgetLabel)
639 QFont font = item->widgetLabel->font();
640 font.setUnderline(
false);
641 item->widgetLabel->setFont(font);
642 item->widgetLabel->setText(property->valueText());
643 item->widgetLabel->setToolTip(property->valueText());
644 item->widgetLabel->setEnabled(property->isEnabled());
649 QFont font = item->widget->font();
650 font.setUnderline(
false);
651 item->widget->setFont(font);
652 item->widget->setEnabled(property->isEnabled());
653 item->widget->setToolTip(property->valueText());
725 const QMap<QtButtonPropertyBrowserPrivate::WidgetItem*, QtBrowserItem*>::ConstIterator icend = d_ptr->m_itemToIndex.constEnd();
727 for (QMap<QtButtonPropertyBrowserPrivate::WidgetItem*, QtBrowserItem*>::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it)
795 #include "moc_qtbuttonpropertybrowser.cpp"