Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / ModuleBase / ModuleBase_PageBase.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 /*
3  * ModuleBase_PageBase.cpp
4  *
5  *  Created on: Mar 4, 2015
6  *      Author: sbh
7  */
8
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_ModelWidget.h>
11
12 #include <QLayout>
13
14 class QWidget;
15
16 ModuleBase_PageBase::ModuleBase_PageBase()
17 {
18
19 }
20
21 ModuleBase_PageBase::~ModuleBase_PageBase()
22 {
23
24 }
25
26 QWidget* ModuleBase_PageBase::pageWidget()
27 {
28   return dynamic_cast<QWidget*>(this);
29 }
30
31 void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget)
32 {
33   placeModelWidget(theWidget);
34   myWidgetList.append(theWidget);
35 }
36
37 void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage)
38 {
39   placePageWidget(thePage);
40 }
41
42 void ModuleBase_PageBase::addWidget(QWidget* theWidget)
43 {
44   placeWidget(theWidget);
45 }
46
47 void ModuleBase_PageBase::clearPage()
48 {
49   myWidgetList.clear();
50
51   QLayoutItem *aChild;
52   while ((aChild = pageLayout()->takeAt(0)) != 0) {
53     if(aChild->widget()) {
54       delete aChild->widget();
55     } else {
56       delete aChild;
57     }
58   }
59
60   // Issue #460: this patch is necessary since the row stretch information
61   // is stored independently on the items: when the items are removed
62   // from the layout the stretch information is kept, so in the next 
63   // filling of the layout some "additional" (old) rows may be stretched
64   // without necessity. 
65   // In this patch we clear the stretch information specifying the default value: 0.
66   QGridLayout* aLayout = dynamic_cast<QGridLayout*>( pageLayout() );
67   if( aLayout )
68   {
69     int r = aLayout->rowCount();
70     for( int i=0; i<r; i++ )
71       aLayout->setRowStretch( i, 0 );
72   }
73 }
74
75
76 bool ModuleBase_PageBase::takeFocus()
77 {
78   if(myWidgetList.isEmpty())
79     return false;
80
81   return myWidgetList.first()->focusTo();
82 }
83
84 QList<ModuleBase_ModelWidget*> ModuleBase_PageBase::modelWidgets() const
85 {
86   return myWidgetList;
87 }
88
89 void ModuleBase_PageBase::alignToTop()
90 {
91   bool hasExpanding = false;
92   QList<QWidget *> aListToCheck;
93   ModuleBase_ModelWidget* aModelWidget;
94   foreach(aModelWidget, myWidgetList) {
95     aListToCheck << aModelWidget->getControls();
96   }
97   foreach(QWidget* eachWidget, aListToCheck) {
98     QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
99     if(aVPolicy & QSizePolicy::ExpandFlag) {
100       hasExpanding = true;
101       break;
102     }
103   }
104   if(!hasExpanding) {
105     addPageStretch();
106   }
107 }
108
109 void ModuleBase_PageBase::placePageWidget(ModuleBase_PageBase* theWidget)
110 {
111   QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
112   placeWidget(aWidget);
113 }