const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
const static char* ANY_WDG_ICON = FEATURE_ICON;
const static char* ANY_WDG_LABEL = "label";
+const static char* ANY_WDG_DEFAULT = "default";
const static char* SOURCE_FILE = "path";
const static char* VALIDATOR_PARAMETERS = "parameters";
const static char* DOUBLE_WDG_MIN = "min";
const static char* DOUBLE_WDG_MAX = "max";
const static char* DOUBLE_WDG_STEP = "step";
-const static char* DOUBLE_WDG_DEFAULT = "default";
const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed";
//toolbox/switch properties
SET(PROJECT_HEADERS
ModuleBase.h
+ ModuleBase_Tools.h
ModuleBase_IModule.h
ModuleBase_Operation.h
ModuleBase_OperationDescription.h
)
SET(PROJECT_SOURCES
+ ModuleBase_Tools.cpp
ModuleBase_Operation.cpp
ModuleBase_OperationDescription.cpp
ModuleBase_ModelWidget.cpp
#include <QEvent>
#include <QWidget>
+#include <QGraphicsDropShadowEffect>
+#include <QColor>
+#include <QLabel>
-ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
+ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId)
: QObject(theParent),
myParentId(theParentId)
}
}
+void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
+{
+ QList<QWidget*> aWidgetList = getControls();
+ foreach(QWidget* aWidget, aWidgetList) {
+ QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
+ // We won't set the effect to QLabels - it looks ugly
+ if(aLabel) continue;
+ if(isHighlighted) {
+ // If effect is the installed on a different widget, setGraphicsEffect() will
+ // remove the effect from the widget and install it on this widget.
+ // That's why we create a new effect for each widget
+ QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
+ aGlowEffect->setOffset(.0);
+ aGlowEffect->setBlurRadius(10.0);
+ aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
+ aWidget->setGraphicsEffect(aGlowEffect);
+ } else {
+ QGraphicsEffect* anEffect = aWidget->graphicsEffect();
+ if(anEffect)
+ anEffect->deleteLater();
+ aWidget->setGraphicsEffect(NULL);
+ }
+ }
+}
+
bool ModuleBase_ModelWidget::focusTo()
{
QList<QWidget*> aControls = getControls();
bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
{
- QWidget* aWidget = dynamic_cast<QWidget*>(theObject);
+ QWidget* aWidget = qobject_cast<QWidget*>(theObject);
if (theEvent->type() == QEvent::MouseButtonRelease &&
myFocusInWidgets.contains(aWidget)) {
emit focusInWidget(this);
/// Constructor
/// \theParent the parent object
/// \theData the widget configuation. The attribute of the model widget is obtained from
- ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
+ ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId);
/// Destructor
virtual ~ModuleBase_ModelWidget()
{
}
- /// Set the given wrapped value to the current widget
- /// This value should be processed in the widget according to the needs
- /// \param theValue the wrapped widget value
- virtual bool setValue(ModuleBase_WidgetValue* theValue)
- {
- return false;
- }
-
/// Returns the state whether the attribute of the feature is initialized
/// \param theObject a model feature to be checked
/// \return the boolean result
/// valid even if they are not initialized
bool isObligatory() { return myIsObligatory; }
+ /// Defines if it is supposed that the widget should interact with the viewer.
+ virtual bool isViewerSelector() { return false; }
+
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// \param theValue the wrapped widget value
+ virtual bool setValue(ModuleBase_WidgetValue* theValue)
+ {
+ return false;
+ }
+
/// Saves the internal parameters to the given feature
/// \param theObject a model feature to be changed
virtual bool storeValue() const = 0;
virtual bool restoreValue() = 0;
- void enableFocusProcessing();
/// Set focus to the first control of the current widget. The focus policy of the control is checked.
/// If the widget has the NonFocus focus policy, it is skipped.
/// \return the state whether the widget can accept the focus
virtual bool focusTo();
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ virtual QWidget* getControl() const = 0;
+
/// Returns list of widget controls
/// \return a control list
virtual QList<QWidget*> getControls() const = 0;
+
/// FocusIn events processing
virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
+
+ void enableFocusProcessing();
+
+ void setHighlighted(bool isHighlighted);
+
/// Returns the attribute name
/// \returns the string value
std::string attributeID() const
{
return myFeature;
}
+
void setFeature(const FeaturePtr& theFeature)
{
myFeature = theFeature;
}
- /// Defines if it is supposed that the widget should interact with the viewer.
- virtual bool isViewerSelector() { return false; }
-
signals:
/// The signal about widget values changed
void valuesChanged();
std::string myParentId; /// name of parent
FeaturePtr myFeature;
- bool myIsComputedDefault; /// Value should be computed on execute,
- /// like radius for circle's constraint (can not be zero)
- bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized
+ bool myIsComputedDefault; /// Value should be computed on execute,
+ /// like radius for circle's constraint (can not be zero)
+ bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized
private:
/// Contains a list of widgets that may accept focus
//******************************************************************
//******************************************************************
+
+void adjustMargins(QWidget* theWidget)
+{
+ if(!theWidget)
+ return;
+ adjustMargins(theWidget->layout());
+}
+
+void adjustMargins(QLayout* theLayout)
+{
+ if(!theLayout)
+ return;
+ theLayout->setContentsMargins(5, 5, 5, 5);
+ theLayout->setSpacing(5);
+}
+
+void zeroMargins(QWidget* theWidget)
+{
+ if(!theWidget)
+ return;
+ zeroMargins(theWidget->layout());
+}
+
+void zeroMargins(QLayout* theLayout)
+{
+ if(!theLayout)
+ return;
+ theLayout->setContentsMargins(0, 0, 0, 0);
+ theLayout->setSpacing(5);
+}
+
}
#include "ModuleBase.h"
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Feature.h>
+#include <QWidget>
+#include <QLayout>
class GeomAPI_Shape;
namespace ModuleBase_Tools {
-/**
- * Returns returns a shape if the result has a shape method. Otherwise returns NULL pointer
+/*
+ * Methods to adjust margins and spacings.
*/
-MODULEBASE_EXPORT boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult);
+MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
+MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
-MODULEBASE_EXPORT FeaturePtr feature(ObjectPtr theObject);
+MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
+MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
}
-;
#endif
{
QString aText = QString::fromStdString(theData->widgetLabel());
QString aToolTip = QString::fromStdString(theData->widgetTooltip());
- QString aDefault = QString::fromStdString(theData->getProperty("default"));
+ bool isChecked = theData->getBooleanAttribute(ANY_WDG_DEFAULT, false);
myCheckBox = new QCheckBox(aText, theParent);
myCheckBox->setToolTip(aToolTip);
- myCheckBox->setChecked(aDefault == "true");
+ myCheckBox->setChecked(isChecked);
connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
}
// Author: Vitaly Smetannikov
#include "ModuleBase_WidgetChoice.h"
+#include <ModuleBase_Tools.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Data.h>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
- aLayout->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aLayout);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
{
emit valuesChanged();
emit focusOutWidget(this);
-}
\ No newline at end of file
+}
#include <ModuleBase_WidgetDoubleValue.h>
#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
- aControlLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aControlLay);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
mySpinBox->setSingleStep(aStepVal);
}
- aProp = theData->getProperty(DOUBLE_WDG_DEFAULT);
+ aProp = theData->getProperty(ANY_WDG_DEFAULT);
double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
if (isOk) {
mySpinBox->setValue(aDefVal);
#include <ModuleBase_WidgetChoice.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_Tools.h>
+
#include <ModelAPI_Validator.h>
#include <Config_Keywords.h>
return;
QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
- aWidgetLay->setContentsMargins(2, 2, 2, 2);
do { //Iterate over each node
std::string aWdgType = myWidgetApi->widgetType();
//Create a widget (doublevalue, groupbox, toolbox, etc.
//if current widget is groupbox (container) process it's children recursively
QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
createWidget(aWidget);
+ ModuleBase_Tools::adjustMargins(aWidget);
QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
aGrBox->setTitle(aGroupName);
}
do {
QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
QWidget* aPage = new QWidget(aWidget);
+ ModuleBase_Tools::adjustMargins(aPage);
createWidget(aPage);
if (aWdgType == WDG_SWITCH) {
ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
#include <ModuleBase_WidgetValueFeature.h>
#include <ModuleBase_WidgetValue.h>
+#include <ModuleBase_Tools.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
- aControlLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aControlLay);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
myLabel = new QLabel(aLabelText, myContainer);
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModuleBase_WidgetFileSelector.h>
+#include <ModuleBase_Tools.h>
#include <Config_WidgetAPI.h>
myMainWidget = new QWidget(theParent);
QGridLayout* aMainLay = new QGridLayout(myMainWidget);
- aMainLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aMainLay);
QLabel* aTitleLabel = new QLabel(myTitle, myMainWidget);
aTitleLabel->setIndent(1);
aMainLay->addWidget(aTitleLabel, 0, 0);
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetValueFeature.h>
#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
: ModuleBase_ModelWidget(theParent, theData, theParentId)
{
myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
- myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
- theParent);
+ QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
+ myGroupBox = new QGroupBox(aPageName, theParent);
+ myGroupBox->setFlat(false);
+
QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
- aGroupLay->setContentsMargins(2, 0, 2, 0);
+ ModuleBase_Tools::adjustMargins(aGroupLay);
aGroupLay->setColumnStretch(1, 1);
{
QLabel* aLabel = new QLabel(myGroupBox);
// Author: Vitaly Smetannikov
#include "ModuleBase_WidgetShapeSelector.h"
-#include "ModuleBase_IWorkshop.h"
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_Tools.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+ ModuleBase_Tools::adjustMargins(aLayout);
- aLayout->setContentsMargins(0, 0, 0, 0);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
myLabel = new QLabel(aLabelText, myContainer);
void PartSet_OperationFeatureBase::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
{
+ if(myActiveWidget) {
+ myActiveWidget->setHighlighted(false);
+ }
+ if(theWidget) {
+ theWidget->setHighlighted(true);
+ }
+
myActiveWidget = theWidget;
activateByPreselection();
if (myInitFeature && myActiveWidget) {
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_SelectionValidator.h>
-#include "ModuleBase_WidgetFactory.h"
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_Tools.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
myPropertyPanel->cleanContent();
aFactory.createWidget(myPropertyPanel->contentWidget());
+ ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();