-/*
- * ModuleBase_WidgetToolbox.cpp
- *
- * Created on: Feb 27, 2015
- * Author: sbh
- */
+// Copyright (C) 2014-2023 CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include <ModuleBase_WidgetToolbox.h>
#include <ModuleBase_PageBase.h>
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_ToolBox.h>
#include <ModelAPI_AttributeString.h>
#include <QWidget>
-#include <Qlist>
+#include <QList>
#include <QVBoxLayout>
+#include <QIcon>
-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<QWidget*>(parent());
+ while(aParent && !aHasContainerParent) {
+ ModuleBase_PagedContainer* aPagedContainer = dynamic_cast<ModuleBase_PagedContainer*>(aParent);
+ aHasContainerParent = aPagedContainer;
+ aParent = dynamic_cast<QWidget*>(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;"
}
int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
- const QString& theName, const QString& theCaseId)
+ const QString& theName,
+ const QString& theCaseId,
+ const QPixmap& theIcon,
+ const QString& theTooltip)
{
- myCaseIds << theCaseId;
- myPages << thePage;
+ ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon, theTooltip);
QFrame* aFrame = dynamic_cast<QFrame*>(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<QWidget*> ModuleBase_WidgetToolbox::getControls() const
-{
- QList<QWidget*> aResult;
- int idx = myToolBox->currentIndex();
- QList<ModuleBase_ModelWidget*> 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, translate(theName.toStdString()), 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();
-}