// Author: Vitaly Smetannikov
#include "ModuleBase_WidgetChoice.h"
-#include <ModuleBase_Tools.h>
+#include "ModuleBase_Tools.h"
+#include "ModuleBase_IconFactory.h"
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Data.h>
ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
- const Config_WidgetAPI* theData,
- const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId), myCombo(0), myButtons(0)
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData), myCombo(0), myButtons(0)
{
QHBoxLayout* aLayout = new QHBoxLayout(this);
ModuleBase_Tools::adjustMargins(aLayout);
std::string aTypes = theData->getProperty("string_list");
QStringList aList = QString(aTypes.c_str()).split(' ');
+ if (theData->getBooleanAttribute("use_in_title", false))
+ myButtonTitles = QString(aTypes.c_str()).split(" ");
+
// Widget type can be combobox or radiobuttons
std::string aWgtType = theData->getProperty("widget_type");
if ((aWgtType.length() > 0) && (aWgtType == "radiobuttons")) {
int aId = 0;
foreach(QString aBtnTxt, aList) {
QToolButton* aBtn = new QToolButton(aGroupBox);
+ aBtn->setFocusPolicy(Qt::StrongFocus);
aBtn->setCheckable(true);
aBtn->setToolTip(aBtnTxt);
- QPixmap aIcon(aIconList.at(aId));
+ QPixmap aIcon = ModuleBase_IconFactory::loadPixmap(aIconList.at(aId));
aBtn->setIcon(aIcon);
aBtn->setIconSize(aIcon.size());
} else {
myLabel = new QLabel(aLabelText, this);
if (!aLabelIcon.isEmpty())
- myLabel->setPixmap(QPixmap(aLabelIcon));
+ myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
aLayout->addWidget(myLabel);
std::string aToolstr = theData->widgetTooltip();
{
}
-bool ModuleBase_WidgetChoice::storeValueCustom() const
+bool ModuleBase_WidgetChoice::storeValueCustom()
{
DataPtr aData = myFeature->data();
std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
bool isBlocked = myButtons->blockSignals(true);
myButtons->button(aIntAttr->value())->setChecked(true);
myButtons->blockSignals(isBlocked);
+ emit itemSelected(this, aIntAttr->value());
}
}
return true;
bool ModuleBase_WidgetChoice::focusTo()
{
if (myCombo)
- myCombo->setFocus();
+ ModuleBase_Tools::setFocus(myCombo, "ModuleBase_WidgetChoice::focusTo()");
else
- myButtons->button(0)->setFocus();
+ return false;
return true;
}
return aControls;
}
+QString ModuleBase_WidgetChoice::getPropertyPanelTitle(int theIndex)
+{
+ QString aTitle;
+ if (myButtonTitles.length() > theIndex)
+ aTitle = tr(myButtonTitles[theIndex].toStdString().c_str());
+ return aTitle;
+}
+
void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
{
emit valuesChanged();
// Don't transfer focus
// emit focusOutWidget(this);
+
+ emit itemSelected(this, theIndex);
}