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