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