1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
5 #include "QStringDialog.h"
8 #include <QDialogButtonBox>
10 QStringDialog::QStringDialog(const QString
& title
, QWidget
* pParent
/*= NULL*/, bool bFileNameLimitation
/*= false*/, bool bFileNameAsciiOnly
/*= false*/)
11 : CEditorDialog(QStringLiteral("QStringDialog"), pParent
? pParent
: QApplication::widgetAt(QCursor::pos()), false)
12 , m_bFileNameLimitation(bFileNameLimitation
)
13 , m_bFileNameAsciiOnly(bFileNameAsciiOnly
)
15 setWindowTitle(title
.isEmpty() ? tr("Enter a string") : title
);
17 m_pEdit
= new QLineEdit(this);
18 QDialogButtonBox
* okCancelButton
= new QDialogButtonBox(this);
19 okCancelButton
->setStandardButtons(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
);
20 connect(okCancelButton
, &QDialogButtonBox::accepted
, this, &QStringDialog::accept
);
21 connect(okCancelButton
, &QDialogButtonBox::rejected
, this, &QStringDialog::reject
);
23 QVBoxLayout
* layout
= new QVBoxLayout(this);
24 layout
->addWidget(m_pEdit
);
25 layout
->addWidget(okCancelButton
);
31 void QStringDialog::SetString(const char* str
)
33 m_pEdit
->setText(str
);
36 const string
QStringDialog::GetString()
38 return m_pEdit
->text().toUtf8().constData();
41 void QStringDialog::showEvent(QShowEvent
* event
)
43 CEditorDialog::showEvent(event
);
47 void QStringDialog::accept()
49 string str
= GetString();
51 if (m_bFileNameLimitation
)
53 const string
reservedCharacters("<>:\"/\\|?*}");
54 for (int i
= 0, iCount(reservedCharacters
.GetLength()); i
< iCount
; ++i
)
56 if (-1 != str
.Find(reservedCharacters
[i
]))
59 msg
.Format("This string can't contain %s characters", reservedCharacters
);
60 CryWarning(VALIDATOR_MODULE_EDITOR
, VALIDATOR_ERROR
, msg
);
65 if (m_bFileNameAsciiOnly
)
67 for (size_t i
= 0; i
< str
.GetLength(); ++i
)
69 if (static_cast<unsigned char>(str
[i
]) > 0x7F)
71 CryWarning(VALIDATOR_MODULE_EDITOR
, VALIDATOR_ERROR
, "This string can't contain non-ASCII characters");
77 if (m_check
&& !m_check(str
))
80 CEditorDialog::accept();