Back to index

salome-geom  6.5.0
GEOMToolsGUI_LineWidthDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  GEOM GEOMGUI : GUI for Geometry component
00021 //  File   : GEOMToolsGUI_LineWidthDlg.cxx
00022 //  Author : OCC Team
00023 //
00024 #include "GEOMToolsGUI_LineWidthDlg.h"
00025 #include <GeometryGUI.h>
00026 #include <GEOM_Constants.h>
00027 #include <LightApp_Application.h>
00028 #include <SalomeApp_IntSpinBox.h>
00029 
00030 #include <SUIT_MessageBox.h>
00031 #include <SUIT_ResourceMgr.h>
00032 #include <SUIT_Session.h>
00033 #include <SUIT_Tools.h>
00034 
00035 #include <QLabel>
00036 #include <QChar>
00037 #include <QPushButton>
00038 #include <QGroupBox>
00039 #include <QGridLayout>
00040 #include <QKeyEvent>
00041 
00042 //=================================================================================
00043 // class    : GEOMToolsGUI_LineWidthDlg()
00044 // purpose  : Constructs a GEOMToolsGUI_LineWidthDlg which is a child of 'parent', with the
00045 //            name 'name' and widget flags set to 'f'.
00046 //            The dialog will by default be modeless, unless you set 'modal' to
00047 //            TRUE to construct a modal dialog.
00048 //=================================================================================
00049 
00050 GEOMToolsGUI_LineWidthDlg::GEOMToolsGUI_LineWidthDlg (QWidget* parent, const QString& title)
00051   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
00052 {
00053   setObjectName("GEOMToolsGUI_LineWidthDlg");
00054   setModal(true);
00055 
00056   setWindowTitle(tr(title.toLatin1().constData()));
00057   setSizeGripEnabled(TRUE);
00058   QGridLayout* MyDialogLayout = new QGridLayout(this);
00059   MyDialogLayout->setSpacing(6);
00060   MyDialogLayout->setMargin(11);
00061 
00062 
00063   /***************************************************************/
00064   QGroupBox* GroupC1 = new QGroupBox (this);
00065   GroupC1->setObjectName("GroupC1");
00066   QGridLayout* GroupC1Layout = new QGridLayout (GroupC1);
00067   GroupC1Layout->setAlignment(Qt::AlignTop);
00068   GroupC1Layout->setSpacing(6);
00069   GroupC1Layout->setMargin(11);
00070 
00071   QLabel* TextLabel1 = new QLabel (GroupC1);
00072   TextLabel1->setObjectName("TextLabel1");
00073   TextLabel1->setText(tr("GEOM_LINE_WIDTH"));
00074   GroupC1Layout->addWidget(TextLabel1, 0, 0);
00075 
00076 
00077   mySpinBox = new SalomeApp_IntSpinBox (GroupC1);
00078   mySpinBox->setRange( 1, 5 );
00079   mySpinBox->setSingleStep( 1 );
00080  
00081   mySpinBox->setObjectName("SpinBoxU");
00082   mySpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
00083   mySpinBox->setValue(1);
00084   GroupC1Layout->addWidget(mySpinBox, 0, 1);
00085 
00086 
00087   /***************************************************************/
00088   QGroupBox* GroupButtons = new QGroupBox (this);
00089   GroupButtons->setObjectName("GroupButtons");
00090   QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
00091   GroupButtonsLayout->setAlignment(Qt::AlignTop);
00092   GroupButtonsLayout->setSpacing(6);
00093   GroupButtonsLayout->setMargin(11);
00094 
00095   QPushButton* buttonOk = new QPushButton (GroupButtons);
00096   buttonOk->setObjectName("buttonOk");
00097   buttonOk->setText(tr("GEOM_BUT_OK"));
00098   buttonOk->setAutoDefault(TRUE);
00099   buttonOk->setDefault(TRUE);
00100   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
00101 
00102   GroupButtonsLayout->addItem(new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
00103 
00104   QPushButton* buttonCancel = new QPushButton (GroupButtons);
00105   buttonCancel->setObjectName("buttonCancel");
00106   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
00107   buttonCancel->setAutoDefault(TRUE);
00108   GroupButtonsLayout->addWidget(buttonCancel, 0, 1);
00109 
00110   QPushButton* buttonHelp = new QPushButton (GroupButtons);
00111   buttonHelp->setObjectName("buttonHelp");
00112   buttonHelp->setText(tr("GEOM_BUT_HELP"));
00113   buttonHelp->setAutoDefault(TRUE);
00114   GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
00115   /***************************************************************/
00116 
00117   MyDialogLayout->addWidget(GroupC1, 0, 0);
00118   MyDialogLayout->addWidget(GroupButtons, 1, 0);
00119 
00120   myHelpFileName = "line_width_page.html";
00121 
00122   // signals and slots connections
00123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
00124   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00125   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00126 
00127   // Move widget on the botton right corner of main widget
00128   SUIT_Tools::centerWidget(this, parent);
00129 }
00130 
00131 
00132 //=================================================================================
00133 // function : ~GEOMToolsGUI_LineWidthDlg()
00134 // purpose  : Destroys the object and frees any allocated resources
00135 //=================================================================================
00136 GEOMToolsGUI_LineWidthDlg::~GEOMToolsGUI_LineWidthDlg()
00137 {
00138   // no need to delete child widgets, Qt does it all for us
00139 }
00140 
00141 int GEOMToolsGUI_LineWidthDlg::getTheLW() const
00142 {
00143   return mySpinBox->text().toInt();
00144 }
00145 
00146 void GEOMToolsGUI_LineWidthDlg::setTheLW (const int v)
00147 {
00148   mySpinBox->setValue(v);
00149 }
00150 
00151 
00152 //=================================================================================
00153 // function : ClickOnHelp()
00154 // purpose  :
00155 //=================================================================================
00156 void GEOMToolsGUI_LineWidthDlg::ClickOnHelp()
00157 {
00158   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00159   if (app) {
00160     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>(app->module("Geometry"));
00161     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
00162   }
00163   else {
00164     QString platform;
00165 #ifdef WIN32
00166     platform = "winapplication";
00167 #else
00168     platform = "application";
00169 #endif
00170     SUIT_MessageBox::warning
00171       (0, QObject::tr("WRN_WARNING"),
00172        QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00173        arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
00174        QObject::tr("BUT_OK"));
00175   }
00176 }
00177 
00178 //=================================================================================
00179 // function : keyPressEvent()
00180 // purpose  :
00181 //=================================================================================
00182 void GEOMToolsGUI_LineWidthDlg::keyPressEvent (QKeyEvent* e)
00183 {
00184   QDialog::keyPressEvent(e);
00185   if (e->isAccepted())
00186     return;
00187 
00188   if (e->key() == Qt::Key_F1) {
00189     e->accept();
00190     ClickOnHelp();
00191   }
00192 }