NCL Composer  0.1.5
 All Classes Functions Variables Pages
PropertyButton.cpp
1 /*
2  * Copyright 2011-2012 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "PropertyButton.h"
19 
20 #include <QFileDialog>
21 #include <QToolButton>
22 #include <QApplication>
23 
24 #include <QDebug>
25 
26 #include <core/util/Utilities.h>
27 using namespace composer::core::util;
28 
29 PropertyButtons::PropertyButtons(QString propName, QWidget *parent)
30  : key(propName), LineEditWithButton(parent, ":/images/esf-search.png")
31 {
32  connect(mButton, SIGNAL(pressed()), SLOT(openfile()));
33 
34  connect(this, SIGNAL(lostFocus()), SLOT(emitNewValue()));
35 
36  qDebug() << "PropertyButtons" << propName;
37 }
38 
39 void PropertyButtons::openfile()
40 {
41  disconnect(this, SIGNAL(lostFocus()), this, SLOT(emitNewValue()));
42  QFileDialog dialog;
43  dialog.setFileMode(QFileDialog::AnyFile);
44 
45  QString filename = dialog.getOpenFileName(NULL, tr("Select file"),
46  Utilities::getLastFileDialogPath());
47 
48  if(!filename.isEmpty() && !filename.isNull())
49  {
50  Utilities::updateLastFileDialogPath(filename);
51  value = filename;
52  emitNewValue(value);
53  }
54 
55  connect(this, SIGNAL(lostFocus()), SLOT(emitNewValue()));
56 }
57 
58 void PropertyButtons::emitNewValue()
59 {
60  emit newValue(key, text());
61 }
62 
63 void PropertyButtons::emitNewValue(QString text)
64 {
65  emit newValue(key, text);
66 }
67