}
+QWidget* ModuleBase_PageBase::pageWidget()
+{
+ return dynamic_cast<QWidget*>(this);
+}
+
void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget)
{
placeModelWidget(theWidget);
void ModuleBase_PageBase::clearPage()
{
- qDeleteAll(pageLayout()->children());
+ QLayoutItem *aChild;
+ while ((aChild = pageLayout()->takeAt(0)) != 0) {
+ if(aChild->widget()) {
+ aChild->widget()->deleteLater();
+ } else {
+ delete aChild;
+ }
+ }
myWidgetList.clear();
}
{
return myWidgetList;
}
+
+void ModuleBase_PageBase::alignToTop()
+{
+ bool hasExpanding = false;
+ QList<QWidget *> aListToCheck;
+ ModuleBase_ModelWidget* aModelWidget;
+ foreach(aModelWidget, myWidgetList) {
+ aListToCheck << aModelWidget->getControls();
+ }
+ foreach(QWidget* eachWidget, aListToCheck) {
+ QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
+ if(aVPolicy & QSizePolicy::ExpandFlag) {
+ hasExpanding = true;
+ break;
+ }
+ }
+ if(!hasExpanding) {
+ addPageStretch();
+ }
+}
public:
ModuleBase_PageBase();
virtual ~ModuleBase_PageBase();
+ QWidget* pageWidget();
void addModelWidget(ModuleBase_ModelWidget* theWidget);
void addPageWidget(ModuleBase_PageBase* theWidget);
void clearPage();
void takeFocus();
QList<ModuleBase_ModelWidget*> modelWidgets();
+ void alignToTop();
protected:
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0;
virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0;
virtual QLayout* pageLayout() = 0;
+ virtual void addPageStretch() = 0;
private:
QList<ModuleBase_ModelWidget*> myWidgetList;
{
}
+void ModuleBase_PageGroupBox::addPageStretch()
+{
+}
+
void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
{
const int kCol = 0;
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
virtual void placePageWidget(ModuleBase_PageBase* theWidget);
virtual QLayout* pageLayout();
+ virtual void addPageStretch();
private:
QGridLayout* myMainLayout;
{
}
+void ModuleBase_PageWidget::addPageStretch()
+{
+ myMainLayout->setRowStretch(myMainLayout->rowCount(), 1);
+}
+
void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget)
{
const int kCol = 0;
const int kRow = myMainLayout->count();
- myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+ myMainLayout->addWidget(theWidget, kRow, kCol);
}
void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget)
}
const int kCol = 0;
const int kRow = myMainLayout->count();
- myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+ myMainLayout->addWidget(aWidget, kRow, kCol);//, Qt::AlignTop | Qt::AlignLeft);
}
QLayout* ModuleBase_PageWidget::pageLayout()
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
virtual void placePageWidget(ModuleBase_PageBase* theWidget);
virtual QLayout* pageLayout();
+ virtual void addPageStretch();
private:
QGridLayout* myMainLayout;
if (!myWidgetApi->toChildWidget())
return;
- //bool isStretchLayout = false;
- QWidget* aPageWidget = dynamic_cast<QWidget*>(thePage);
- if(!aPageWidget) {
- #ifdef _DEBUG
- std::cout << "ModuleBase_WidgetFactory::createWidget: can not reinterpret_cast thePage" << std::endl;
- #endif
- }
do { //Iterate over each node
std::string aWdgType = myWidgetApi->widgetType();
// Create PageGroup TODO: extract
if (myWidgetApi->isGroupBoxWidget()) {
//if current widget is groupbox (container) process it's children recursively
QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
- ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(aPageWidget);
+ ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget());
aPage->setTitle(aGroupName);
createWidget(aPage);
thePage->addPageWidget(aPage);
} else {
// Create a ModelWidget
- ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, aPageWidget);
+ ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
if (aWidget) {
if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
thePage->addModelWidget(aWidget);
aSwitch->addPage(aCasePageWidget, aPageName);
} else if (aWdgType == WDG_TOOLBOX) {
ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
- aToolbox->addPage(aCasePageWidget, aPageName, aCaseId);
+ aToolbox->addPage(aPage, aPageName, aCaseId);
}
} while (myWidgetApi->toNextWidget());
}
}
-// if (aWidget && !isStretchLayout) {
-// isStretchLayout = !hasExpandingControls(aWidget);
-// }
} while (myWidgetApi->toNextWidget());
-// if (isStretchLayout) {
-// aWidgetLay->addStretch(1);
-// }
-}
-bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent)
-{
- bool result = false;
- QList<QWidget *> aListToCheck;
- aListToCheck << theParent;
- ModuleBase_ModelWidget* aModelWidget = qobject_cast<ModuleBase_ModelWidget*>(theParent);
- if(aModelWidget) {
- aListToCheck << aModelWidget->getControls();
- }
- foreach(QWidget* eachWidget, aListToCheck) {
- QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
- if(aVPolicy & QSizePolicy::ExpandFlag) {
- result = true;
- }
- }
- return result;
+ thePage->alignToTop();
}
ModuleBase_ModelWidget* ModuleBase_WidgetFactory
"border-color:#fff #505050 #505050 #fff;}";
myToolBox->setStyleSheet(css);
// default vertical size policy is preferred
- QSizePolicy aSizePolicy = myToolBox->sizePolicy();
- aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
- myToolBox->setSizePolicy(aSizePolicy);
aMainLayout->addWidget(myToolBox);
connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
{
}
-int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget,
+int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
const QString& theName, const QString& theCaseId)
{
myCaseIds << theCaseId;
- return myToolBox->addItem(theWidget, theName);
+ myPages << thePage;
+ QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
+ aFrame->setFrameShape(QFrame::Box);
+ aFrame->setFrameStyle(QFrame::Sunken);
+ return myToolBox->addItem(aFrame, theName);
}
bool ModuleBase_WidgetToolbox::restoreValue()
bool isSignalsBlocked = myToolBox->blockSignals(true);
myToolBox->setCurrentIndex(idx);
myToolBox->blockSignals(isSignalsBlocked);
+ focusTo();
return true;
}
bool ModuleBase_WidgetToolbox::focusTo()
{
- return false;
+ int idx = myToolBox->currentIndex();
+ if (idx > myPages.count())
+ return false;
+ myPages[idx]->takeFocus();
+ repaint();
+ return true;
+}
+
+void ModuleBase_WidgetToolbox::activateCustom()
+{
}
bool ModuleBase_WidgetToolbox::storeValueCustom() const
void ModuleBase_WidgetToolbox::onPageChanged()
{
storeValue();
+ focusTo();
}
virtual QList<QWidget*> getControls() const;
virtual bool focusTo();
- int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId);
+ int addPage(ModuleBase_PageBase* theWidget,
+ const QString& theName, const QString& theCaseId);
protected:
+ virtual void activateCustom();
virtual bool storeValueCustom() const;
protected slots:
private:
QToolBox* myToolBox;
QStringList myCaseIds;
+ QList<ModuleBase_PageBase*> myPages;
};
#endif /* MODULEBASE_WIDGETTOOLBOX_H_ */
return;
if (theFeature->isAction() || !theFeature->data())
return;
- foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
- {
+ foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
eachWidget->setFeature(theFeature);
eachWidget->restoreValue();
}
#include <ModuleBase_Tools.h>
#include <ModuleBase_IViewer.h>
#include<ModuleBase_FilterFactory.h>
+#include <ModuleBase_PageBase.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>