Salome HOME
updated copyright message
[modules/med.git] / src / MEDCalc / gui / dialogs / DlgImageToMed.cxx
1 // Copyright (C) 2015-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 "DlgImageToMed.hxx"
21 #include "SALOME_GuiServices.hxx"
22
23 #include <SUIT_FileDlg.h>
24 #include <SUIT_Desktop.h>
25
26 #include <QString>
27 #include <QStringList>
28 #include <QPixmap>
29 #include <QIcon>
30
31 DlgImageToMed::DlgImageToMed(QDialog *parent) : GenericDialog(parent)
32 {
33   ui.setupUi(this->getPanel());
34
35   QString moduleName = "FIELDS";
36   QPixmap aPixmap = GUI::getResourcesManager()->loadPixmap( moduleName, tr("ICO_FOLDER") );
37   QIcon icon(aPixmap);
38   ui.btnImageFileChooser->setIcon(icon);
39   ui.btnMedFileChooser->setIcon(icon);
40
41   connect(ui.btnImageFileChooser,SIGNAL(clicked()),
42           this, SLOT(OnBtnImageFileChooser()));
43   connect(ui.btnMedFileChooser,SIGNAL(clicked()),
44           this, SLOT(OnBtnMedFileChooser()));
45
46   this->setWindowTitle("Créer un champ à partir d'une image");
47 }
48
49 QString DlgImageToMed::getImageFilepath() {
50   return ui.txtImageFile->text().trimmed();
51 }
52
53 QString DlgImageToMed::getMedFilepath() {
54   return ui.txtMedFile->text().trimmed();
55 }
56
57 void DlgImageToMed::setAutoLoaded(bool autoloaded) {
58   if ( autoloaded ) {
59     ui.chkAutoLoad->setCheckState(Qt::Checked);
60   }
61   else {
62     ui.chkAutoLoad->setCheckState(Qt::Unchecked);
63   }
64 }
65
66 bool DlgImageToMed::isAutoLoaded() {
67   Qt::CheckState state = ui.chkAutoLoad->checkState();
68   if ( state == Qt::Checked ) {
69     return true;
70   }
71   return false;
72 }
73
74 void DlgImageToMed::OnBtnImageFileChooser() {
75   QStringList filter;
76   filter.append(tr("FILE_FILTER_PNG"));
77   filter.append(tr("FILE_FILTER_JPG"));
78   filter.append(tr("FILE_FILTER_PGM"));
79   filter.append(tr("FILE_FILTER_ALL"));
80   QString filename = SUIT_FileDlg::getFileName(ui.btnImageFileChooser,
81                                                "",
82                                                filter,
83                                                tr("SELECT_IMAGE_FILE"),
84                                                true);
85   if ( filename.isEmpty() ) return;
86   ui.txtImageFile->setText(filename);
87
88   QString medFilename = (filename.remove(filename.size()-3,3))+"med";
89   ui.txtMedFile->setText(medFilename);
90 }
91
92 void DlgImageToMed::OnBtnMedFileChooser() {
93   QStringList filter;
94   filter.append(tr("FILE_FILTER_MED"));
95   QString filename = SUIT_FileDlg::getFileName(ui.btnMedFileChooser,
96                                                "",
97                                                filter,
98                                                tr("SPECIFY_MED_FILE"),
99                                                true);
100   if ( filename.isEmpty() ) return;
101   ui.txtMedFile->setText(filename);
102 }