X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetToolbox.cpp;h=16a00dabe7846bd4b58a6120f90f82e6d5a057c9;hb=d0add0e964478b0c8f08a577ffe3a8dc0a7fd60d;hp=c2e816e8def7cc62560d8cfba373523c5ba29d2f;hpb=2727f05d03a3971bdb389ed0b4a237e8ce40d0d7;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp index c2e816e8d..16a00dabe 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp @@ -1,3 +1,4 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D /* * ModuleBase_WidgetToolbox.cpp * @@ -9,22 +10,32 @@ #include #include #include +#include #include #include -#include +#include #include +#include -ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId) -: ModuleBase_ModelWidget(theParent, theData, theParentId), - myIsPassFocusToCurrentPage(false) +ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_PagedContainer(theParent, theData) { QVBoxLayout* aMainLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aMainLayout); - myToolBox = new QToolBox(this); + + bool aHasContainerParent = false; + QWidget* aParent = dynamic_cast(parent()); + while(aParent && !aHasContainerParent) { + ModuleBase_PagedContainer* aPagedContainer = dynamic_cast(aParent); + aHasContainerParent = aPagedContainer; + aParent = dynamic_cast(aParent->parent()); + } + myToolBox = new ModuleBase_ToolBox(this, aHasContainerParent); // Dark-grey rounded tabs with button-like border #and bold font + // TODO: apply style to custom widget QString css = "QToolBox::tab{background-color:#c8c8c8;" "border-radius:5px;" "border:1px inset;" @@ -42,83 +53,26 @@ ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox() } int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage, - const QString& theName, const QString& theCaseId) + const QString& theName, + const QString& theCaseId, + const QPixmap& theIcon ) { - myCaseIds << theCaseId; - myPages << thePage; + ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon); QFrame* aFrame = dynamic_cast(thePage); - aFrame->setFrameShape(QFrame::Box); - aFrame->setFrameStyle(QFrame::Sunken); - return myToolBox->addItem(aFrame, theName); -} - -bool ModuleBase_WidgetToolbox::restoreValue() -{ - // A rare case when plugin was not loaded. - if(!myFeature) - return false; - DataPtr aData = myFeature->data(); - AttributeStringPtr aStringAttr = aData->string(attributeID()); - QString aCaseId = QString::fromStdString(aStringAttr->value()); - int idx = myCaseIds.indexOf(aCaseId); - if (idx == -1) - return false; - bool isSignalsBlocked = myToolBox->blockSignals(true); - myToolBox->setCurrentIndex(idx); - myToolBox->blockSignals(isSignalsBlocked); - return true; -} - -QList ModuleBase_WidgetToolbox::getControls() const -{ - QList aResult; - int idx = myToolBox->currentIndex(); - QList aModelWidgets = myPages[idx]->modelWidgets(); - foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) { - aResult << eachModelWidget->getControls(); - } - return aResult; -} - -bool ModuleBase_WidgetToolbox::focusTo() -{ - int idx = myToolBox->currentIndex(); - if (idx > myPages.count()) - return false; - return myPages[idx]->takeFocus(); -} - -void ModuleBase_WidgetToolbox::setHighlighted(bool) -{ - //page containers sould not be highlighted, do nothing + myToolBox->addItem(aFrame, theName, theIcon ); + return myToolBox->count(); } -void ModuleBase_WidgetToolbox::enableFocusProcessing() +int ModuleBase_WidgetToolbox::currentPageIndex() const { - myIsPassFocusToCurrentPage = true; + return myToolBox->currentIndex(); } - -void ModuleBase_WidgetToolbox::activateCustom() +void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex) { - // activate current page - focusTo(); + bool isSignalsBlocked = myToolBox->blockSignals(true); + myToolBox->setCurrentIndex(theIndex); + myToolBox->blockSignals(isSignalsBlocked); } -bool ModuleBase_WidgetToolbox::storeValueCustom() const -{ - // A rare case when plugin was not loaded. - if(!myFeature) - return false; - DataPtr aData = myFeature->data(); - AttributeStringPtr aStringAttr = aData->string(attributeID()); - QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex()); - aStringAttr->setValue(aWidgetValue.toStdString()); - return true; -} -void ModuleBase_WidgetToolbox::onPageChanged() -{ - storeValue(); - if (myIsPassFocusToCurrentPage) focusTo(); -}