1 /**********************************************************************************************
2     Copyright (C) 2018 Oliver Eichler <oliver.eichler@gmx.de>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program 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
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "gis/wpt/CSetupIconAndName.h"
20 #include "helpers/CWptIconManager.h"
21 
22 #include <QtWidgets>
23 
CSetupIconAndName(QString & icon,QString & name,QWidget * parent)24 CSetupIconAndName::CSetupIconAndName(QString& icon, QString& name, QWidget* parent)
25     : QDialog(parent)
26     , icon(icon)
27     , name(name)
28 
29 {
30     setupUi(this);
31     toolIcon->setObjectName(icon);
32     QPointF focus;
33     toolIcon->setIcon(CWptIconManager::self().getWptIconByName(icon, focus));
34     lineName->setText(name);
35 
36     connect(lineName, &QLineEdit::textEdited, this, &CSetupIconAndName::slotEditName);
37     connect(toolIcon, &QToolButton::clicked, this, &CSetupIconAndName::slotChangeIcon);
38 
39     checkInput();
40 }
41 
slotEditName(const QString & str)42 void CSetupIconAndName::slotEditName(const QString& str)
43 {
44     checkInput();
45 }
46 
slotChangeIcon()47 void CSetupIconAndName::slotChangeIcon()
48 {
49     QString iconName = CWptIconManager::self().selectWptIcon(this);
50     if(!iconName.isEmpty())
51     {
52         QPointF focus;
53         toolIcon->setObjectName(iconName);
54         toolIcon->setIcon(CWptIconManager::self().getWptIconByName(iconName, focus));
55     }
56 }
57 
checkInput()58 void CSetupIconAndName::checkInput()
59 {
60     bool isEnabled = !lineName->text().isEmpty();
61     buttonBox->button(QDialogButtonBox::Ok)->setEnabled(isEnabled);
62 }
63 
accept()64 void CSetupIconAndName::accept()
65 {
66     icon = toolIcon->objectName();
67     name = lineName->text();
68 
69     QDialog::accept();
70 }
71 
reject()72 void CSetupIconAndName::reject()
73 {
74     name.clear();
75     icon.clear();
76 
77     QDialog::reject();
78 }
79 
80 
81