21 #include <QWidgetAction>
23 #include "boost/bind.hpp"
33 BaseWidget(parent,
"BrowserWidget",
"Browser"),
37 mOptions =
profile()->getXmlSettings().descend(this->objectName());
41 void BrowserWidget::createGUI()
43 QVBoxLayout* layout =
new QVBoxLayout(
this);
45 layout->setSpacing(0);
57 connect(
mTreeView.data(), &QTreeView::collapsed,
this, &BrowserWidget::onNodeCollapsed);
58 connect(
mTreeView.data(), &QTreeView::expanded,
this, &BrowserWidget::onNodeExpanded);
63 layout->addWidget(mPopupWidget);
64 mPopupWidget->
setPopupVisible(this->getShowToolbarOption().readValue(QString::number(
false)).toInt());
67 mPropertiesWidget->setWidgetDeleteOld(
new QLabel(
"no\nproperties\nselected"));
70 layout->addWidget(mSplitter, 1);
74 this->createButtonWidget(mPopupWidget->
getToolbar());
77 void BrowserWidget::onNodeCollapsed(
const QModelIndex & index)
82 void BrowserWidget::onNodeExpanded(
const QModelIndex & index)
85 if (!mExpanded.contains(uid))
86 mExpanded.push_back(uid);
89 void BrowserWidget::onPopup()
108 void BrowserWidget::updateNodeName()
112 if (mName->actions().empty())
113 mName->addAction(node->getIcon(), QLineEdit::LeadingPosition);
115 mName->actions().front()->setIcon(node->getIcon());
118 mName->setText(node->getName());
121 int height = mName->height();
123 QFontMetrics fm(QFont(
"", 0));
124 mName->setFixedSize(fm.width(mName->text())+height*2, height);
130 void BrowserWidget::createButtonWidget(QWidget* widget)
132 QHBoxLayout* buttonLayout =
new QHBoxLayout(widget);
133 buttonLayout->setMargin(0);
134 buttonLayout->setSpacing(0);
136 StringListSelectWidget* visibility =
new StringListSelectWidget(
this,
mModel->
repo()->getVisibilityProperty());
137 visibility->showLabel(
false);
138 visibility->setIcon(QIcon(
":/icons/open_icon_library/arrange_vertical.png"));
139 buttonLayout->addWidget(visibility);
141 LabeledComboBoxWidget* mode =
new LabeledComboBoxWidget(
this,
mModel->
repo()->getModeProperty());
142 mode->showLabel(
false);
143 buttonLayout->addSpacing(8);
144 buttonLayout->addWidget(mode);
145 buttonLayout->setStretch(buttonLayout->count()-1, 0);
148 columns->showLabel(
false);
149 columns->setIcon(QIcon(
":/icons/open_icon_library/arrange_horizontal.png"));
150 buttonLayout->addWidget(columns);
152 buttonLayout->addSpacing(8);
155 buttonLayout->addStretch(1);
157 mRemoveButton =
new EraseDataToolButton(
this);
159 buttonLayout->addWidget(mRemoveButton);
161 mName =
new QLineEdit;
162 mName->setReadOnly(
true);
163 buttonLayout->addWidget(mName);
168 buttonLayout->addWidget(button);
172 buttonLayout->addWidget(button);
175 XmlOptionItem BrowserWidget::getShowToolbarOption()
177 return XmlOptionItem(
"show_toolbar", mOptions.
getElement());
180 void BrowserWidget::expandDefault(QModelIndex index)
183 if (!node->isDefaultExpanded())
189 for (
int r=0; r<rc; ++r)
192 this->expandDefault(child);
196 void BrowserWidget::expandRestore(QModelIndex index)
199 if (index.isValid() && !mExpanded.contains(node->getUid()))
206 for (
int r=0; r<rc; ++r)
209 this->expandRestore(child);
213 bool BrowserWidget::setCurrentNode(QString uid, QModelIndex index)
218 if (node && (node->getUid()==uid))
227 mTreeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
233 for (
int r=0; r<rc; ++r)
236 if (this->setCurrentNode(uid, child))
246 if (mExpanded.empty())
248 this->expandDefault(QModelIndex());
257 this->expandRestore(QModelIndex());
261 this->setCurrentNode(mActiveNodeUid, QModelIndex());
266 void BrowserWidget::onLoaded()
272 void BrowserWidget::onCurrentItemChanged()
278 if (node->getUid() == mActiveNodeUid)
280 if (node->getUid() ==
mModel->
repo()->getTopNode()->getUid())
283 mRemoveButton->setEnabled(node && node->isRemovable());
284 this->updateNodeName();
288 mActiveNodeUid = node->getUid();
290 boost::shared_ptr<QWidget> widget = node->createPropertiesWidget();
291 mPropertiesWidget->setWidget(widget);
298 void BrowserWidget::eraseCurrentNode()