-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtextureentry.cpp
More file actions
67 lines (57 loc) · 1.96 KB
/
textureentry.cpp
File metadata and controls
67 lines (57 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "textureentry.h"
#include "ui_textureentry.h"
#include <QFileDialog>
TextureEntry::TextureEntry(QWidget *parent) :
QWidget(parent),
ui(new Ui::TextureEntry)
{
ui->setupUi(this);
}
TextureEntry::~TextureEntry()
{
delete ui;
}
void TextureEntry::SetID(int ID) { ui->id_le->setText(QString::number(ID)); }
QString TextureEntry::GetName() { return ui->name_le->text(); }
QString TextureEntry::GetPath() { return ui->path_le->text(); }
QFileInfo TextureEntry::GetFileInfo()
{
QFileInfo fileInfo(ui->path_le->text());
return fileInfo;
}
QString TextureEntry::GetNewFileNameWithExtension()
{
if(ui->name_le->text() == "")
ui->name_le->setText(GetFileInfo().completeBaseName());
return ui->name_le->text() + "." + GetFileInfo().suffix();
}
void TextureEntry::on_search_pb_clicked()
{
static QString lastDirSelected = QDir::homePath();
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Texture File"), lastDirSelected, tr("Image Files (*.png *.tga);;"
"PNG Files (*.png);;"
"Nitro TGA Files (*.tga)"));
if(fileName == "")
return;
lastDirSelected = fileName;
ui->path_le->setText(fileName);
ui->name_le->setText(GetFileInfo().completeBaseName());
}
void TextureEntry::on_name_le_textChanged()
{
QLineEdit* sender = qobject_cast<QLineEdit*>(QObject::sender());
int cursorPos = sender->cursorPosition();
QString newText;
for(QChar character : sender->text())
{
if(!((character >= 'A' && character <= 'Z') ||
(character >= 'a' && character <= 'z') ||
(character >= '0' && character <= '9')))
{
character = '_';
}
newText.append(character);
}
sender->setText(newText);
sender->setCursorPosition(cursorPos);
}