1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "vegetable_settings_page.h"
23 #include "object_viewer_constants.h"
24 #include "../core/icore.h"
28 #include <QtGui/QWidget>
29 #include <QtCore/QSettings>
30 #include <QtGui/QMessageBox>
31 #include <QtGui/QFileDialog>
36 QString LastDir
= ".";
38 VegetableSettingsPage::VegetableSettingsPage(QObject
*parent
)
39 : IOptionsPage(parent
),
44 QString
VegetableSettingsPage::id() const
46 return QLatin1String("VegetablePage");
49 QString
VegetableSettingsPage::trName() const
51 return tr("Vegetable");
54 QString
VegetableSettingsPage::category() const
56 return QLatin1String(Constants::OBJECT_VIEWER_SECTION
);
59 QString
VegetableSettingsPage::trCategory() const
61 return tr("Object Viewer");
64 QIcon
VegetableSettingsPage::categoryIcon() const
69 QWidget
*VegetableSettingsPage::createPage(QWidget
*parent
)
71 m_page
= new QWidget(parent
);
74 QSettings
*settings
= Core::ICore::instance()->settings();
75 settings
->beginGroup(Constants::OBJECT_VIEWER_SECTION
);
77 m_ui
.tileBankLineEdit
->setText(settings
->value(Constants::VEGET_TILE_BANK
, "").toString());
78 m_ui
.tileFarBankLineEdit
->setText(settings
->value(Constants::VEGET_TILE_FAR_BANK
, "").toString());
79 m_ui
.vegetTextureLineEdit
->setText(settings
->value(Constants::VEGET_TEXTURE
, "").toString());
80 m_ui
.coarseLineEdit
->setText(settings
->value(Constants::COARSE_MESH_TEXTURE
, "").toString());
81 m_ui
.zonesListWidget
->addItems(settings
->value(Constants::VEGET_LANDSCAPE_ZONES
).toStringList());
85 connect(m_ui
.tileBankToolButton
, SIGNAL(clicked()), this, SLOT(setTileBank()));
86 connect(m_ui
.tileFarBankToolButton
, SIGNAL(clicked()), this, SLOT(setTileFarBank()));
87 connect(m_ui
.vegetTexToolButton
, SIGNAL(clicked()), this, SLOT(setTextureVegetable()));
88 connect(m_ui
.coarseToolButton
, SIGNAL(clicked()), this, SLOT(setCoarseMeshTexture()));
89 connect(m_ui
.addZoneToolButton
, SIGNAL(clicked()), this, SLOT(addZone()));
90 connect(m_ui
.removeZoneToolButton
, SIGNAL(clicked()), this, SLOT(removeZone()));
91 connect(m_ui
.clearButton
, SIGNAL(clicked()), m_ui
.zonesListWidget
, SLOT(clear()));
96 void VegetableSettingsPage::apply()
98 QSettings
*settings
= Core::ICore::instance()->settings();
99 settings
->beginGroup(Constants::OBJECT_VIEWER_SECTION
);
101 settings
->setValue(Constants::VEGET_TILE_BANK
, m_ui
.tileBankLineEdit
->text());
102 settings
->setValue(Constants::VEGET_TILE_FAR_BANK
, m_ui
.tileFarBankLineEdit
->text());
103 settings
->setValue(Constants::COARSE_MESH_TEXTURE
, m_ui
.coarseLineEdit
->text());
104 settings
->setValue(Constants::VEGET_TEXTURE
, m_ui
.vegetTextureLineEdit
->text());
107 for (sint i
= 0; i
< m_ui
.zonesListWidget
->count(); ++i
)
108 list
.push_back(m_ui
.zonesListWidget
->item(i
)->text());
110 settings
->setValue(Constants::VEGET_LANDSCAPE_ZONES
, list
);
112 settings
->endGroup();
116 void VegetableSettingsPage::finish()
120 void VegetableSettingsPage::setTileBank()
122 QString fileName
= QFileDialog::getOpenFileName(0, tr("Set new tile bank"),
123 m_ui
.tileBankLineEdit
->text(),
124 tr("Tile Bank file (*.smallbank *.bank);;"));
125 if (!fileName
.isEmpty())
127 m_ui
.tileBankLineEdit
->setText(fileName
);
131 void VegetableSettingsPage::setTileFarBank()
133 QString fileName
= QFileDialog::getOpenFileName(0, tr("Set new tile far bank"),
134 m_ui
.tileFarBankLineEdit
->text(),
135 tr("Tile Far Bank file (*.farbank);;"));
136 if (!fileName
.isEmpty())
138 m_ui
.tileFarBankLineEdit
->setText(fileName
);
142 void VegetableSettingsPage::setTextureVegetable()
144 QString fileName
= QFileDialog::getOpenFileName(0, tr("Set MicroVegetable texture"),
145 m_ui
.vegetTextureLineEdit
->text(),
146 tr("Texture file (*.tga *.png *.jpg *.dds);;"));
147 if (!fileName
.isEmpty())
149 m_ui
.vegetTextureLineEdit
->setText(fileName
);
153 void VegetableSettingsPage::setCoarseMeshTexture()
155 QString fileName
= QFileDialog::getOpenFileName(0, tr("Set Coarse Mesh texture"),
156 m_ui
.vegetTextureLineEdit
->text(),
157 tr("Texture file (*.tga *.png *.jpg *.dds);;"));
158 if (!fileName
.isEmpty())
160 m_ui
.coarseLineEdit
->setText(fileName
);
164 void VegetableSettingsPage::addZone()
166 QStringList fileNames
= QFileDialog::getOpenFileNames(0,
167 tr("Add zone files"), LastDir
,
168 tr("Zonel files (*.zonel *.zone);;"));
170 if (!fileNames
.isEmpty())
172 QStringList list
= fileNames
;
173 QStringList::Iterator it
= list
.begin();
174 while(it
!= list
.end())
176 QListWidgetItem
*newItem
= new QListWidgetItem
;
177 newItem
->setText(*it
);
178 newItem
->setFlags(Qt::ItemIsEditable
| Qt::ItemIsEnabled
| Qt::ItemIsSelectable
);
179 m_ui
.zonesListWidget
->addItem(newItem
);
185 void VegetableSettingsPage::removeZone()
187 QListWidgetItem
*removeItem
= m_ui
.zonesListWidget
->takeItem(m_ui
.zonesListWidget
->currentRow());
192 } /* namespace NLQT */