Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_PageBase.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <ModuleBase_PageBase.h>
21 #include <ModuleBase_ModelWidget.h>
22
23 #include <QLayout>
24
25 class QWidget;
26
27 ModuleBase_PageBase::ModuleBase_PageBase()
28 {
29
30 }
31
32 ModuleBase_PageBase::~ModuleBase_PageBase()
33 {
34
35 }
36
37 QWidget* ModuleBase_PageBase::pageWidget()
38 {
39   return dynamic_cast<QWidget*>(this);
40 }
41
42 void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget)
43 {
44   placeModelWidget(theWidget);
45   myWidgetList.append(theWidget);
46 }
47
48 void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage)
49 {
50   placePageWidget(thePage);
51 }
52
53 void ModuleBase_PageBase::addWidget(QWidget* theWidget)
54 {
55   placeWidget(theWidget);
56 }
57
58 void ModuleBase_PageBase::clearPage()
59 {
60   myWidgetList.clear();
61
62   QLayoutItem *aChild;
63   while ((aChild = pageLayout()->takeAt(0)) != 0) {
64     if(aChild->widget()) {
65       delete aChild->widget();
66     } else {
67       delete aChild;
68     }
69   }
70
71   // Issue #460: this patch is necessary since the row stretch information
72   // is stored independently on the items: when the items are removed
73   // from the layout the stretch information is kept, so in the next
74   // filling of the layout some "additional" (old) rows may be stretched
75   // without necessity.
76   // In this patch we clear the stretch information specifying the default value: 0.
77   QGridLayout* aLayout = dynamic_cast<QGridLayout*>( pageLayout() );
78   if( aLayout )
79   {
80     int r = aLayout->rowCount();
81     for( int i=0; i<r; i++ )
82       aLayout->setRowStretch( i, 0 );
83   }
84 }
85
86
87 bool ModuleBase_PageBase::takeFocus()
88 {
89   if(myWidgetList.isEmpty())
90     return false;
91
92   return myWidgetList.first()->focusTo();
93 }
94
95 QList<ModuleBase_ModelWidget*> ModuleBase_PageBase::modelWidgets() const
96 {
97   return myWidgetList;
98 }
99
100 void ModuleBase_PageBase::alignToTop()
101 {
102   bool hasExpanding = false;
103   QList<QWidget *> aListToCheck;
104   ModuleBase_ModelWidget* aModelWidget;
105   foreach(aModelWidget, myWidgetList) {
106     aListToCheck << aModelWidget->getControls();
107   }
108   foreach(QWidget* eachWidget, aListToCheck) {
109     QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
110     if(aVPolicy & QSizePolicy::ExpandFlag) {
111       hasExpanding = true;
112       break;
113     }
114   }
115   if(!hasExpanding) {
116     addPageStretch();
117   }
118 }
119
120 void ModuleBase_PageBase::placePageWidget(ModuleBase_PageBase* theWidget)
121 {
122   QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
123   placeWidget(aWidget);
124 }