mirror of https://github.com/PCSX2/pcsx2.git
DEV9: Move helper Qt classes into a separate file
This commit is contained in:
parent
4873165dbc
commit
3e76d380a1
|
@ -94,6 +94,8 @@ target_sources(pcsx2-qt PRIVATE
|
|||
Settings/DEV9SettingsWidget.cpp
|
||||
Settings/DEV9SettingsWidget.h
|
||||
Settings/DEV9SettingsWidget.ui
|
||||
Settings/DEV9UiCommon.cpp
|
||||
Settings/DEV9UiCommon.h
|
||||
Settings/HddCreateQt.cpp
|
||||
Settings/HddCreateQt.h
|
||||
Settings/SettingsDialog.cpp
|
||||
|
|
|
@ -55,71 +55,6 @@ static const char* s_dns_name[] = {
|
|||
|
||||
using PacketReader::IP::IP_Address;
|
||||
|
||||
#define IP_RANGE_INTER "([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5]|)"
|
||||
#define IP_RANGE_FINAL "([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"
|
||||
|
||||
// clang-format off
|
||||
const QRegularExpression IPValidator::intermediateRegex{QStringLiteral("^" IP_RANGE_INTER "\\." IP_RANGE_INTER "\\." IP_RANGE_INTER "\\." IP_RANGE_INTER "$")};
|
||||
const QRegularExpression IPValidator::finalRegex {QStringLiteral("^" IP_RANGE_FINAL "\\." IP_RANGE_FINAL "\\." IP_RANGE_FINAL "\\." IP_RANGE_FINAL "$")};
|
||||
// clang-format on
|
||||
|
||||
IPValidator::IPValidator(QObject* parent, bool allowEmpty)
|
||||
: QValidator(parent)
|
||||
, m_allowEmpty{allowEmpty}
|
||||
{
|
||||
}
|
||||
|
||||
QValidator::State IPValidator::validate(QString& input, int& pos) const
|
||||
{
|
||||
if (input.isEmpty())
|
||||
return m_allowEmpty ? Acceptable : Intermediate;
|
||||
|
||||
QRegularExpressionMatch m = finalRegex.match(input, 0, QRegularExpression::NormalMatch);
|
||||
if (m.hasMatch())
|
||||
return Acceptable;
|
||||
|
||||
m = intermediateRegex.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
|
||||
if (m.hasMatch() || m.hasPartialMatch())
|
||||
return Intermediate;
|
||||
else
|
||||
{
|
||||
pos = input.size();
|
||||
return Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
IPItemDelegate::IPItemDelegate(QObject* parent)
|
||||
: QItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget* IPItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QLineEdit* editor = new QLineEdit(parent);
|
||||
editor->setValidator(new IPValidator());
|
||||
return editor;
|
||||
}
|
||||
|
||||
void IPItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
QString value = index.model()->data(index, Qt::EditRole).toString();
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
line->setText(value);
|
||||
}
|
||||
|
||||
void IPItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
QString value = line->text();
|
||||
model->setData(index, value);
|
||||
}
|
||||
|
||||
void IPItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
|
||||
DEV9SettingsWidget::DEV9SettingsWidget(SettingsDialog* dialog, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_dialog{dialog}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <QtWidgets/QItemDelegate>
|
||||
#include <QtGui/QStandardItemModel>
|
||||
|
||||
#include "ui_DEV9SettingsWidget.h"
|
||||
|
@ -25,35 +24,6 @@
|
|||
|
||||
class SettingsDialog;
|
||||
|
||||
class IPValidator : public QValidator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IPValidator(QObject* parent = nullptr, bool allowEmpty = false);
|
||||
virtual State validate(QString& input, int& pos) const override;
|
||||
|
||||
private:
|
||||
static const QRegularExpression intermediateRegex;
|
||||
static const QRegularExpression finalRegex;
|
||||
|
||||
bool m_allowEmpty;
|
||||
};
|
||||
|
||||
class IPItemDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IPItemDelegate(QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
void setEditorData(QWidget* editor, const QModelIndex& index) const;
|
||||
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
||||
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
class DEV9SettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -86,13 +56,6 @@ protected:
|
|||
bool eventFilter(QObject* object, QEvent* event);
|
||||
|
||||
private:
|
||||
struct HostEntryUi
|
||||
{
|
||||
std::string Url;
|
||||
std::string Desc;
|
||||
std::string Address = "0.0.0.0";
|
||||
bool Enabled;
|
||||
};
|
||||
|
||||
void AddAdapter(const AdapterEntry& adapter);
|
||||
void RefreshHostList();
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/* PCSX2 - PS2 Emulator for PCs
|
||||
* Copyright (C) 2002-2022 PCSX2 Dev Team
|
||||
*
|
||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include <QtWidgets/QLineEdit>
|
||||
|
||||
#include "DEV9UiCommon.h"
|
||||
|
||||
#define IP_RANGE_INTER "([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5]|)"
|
||||
#define IP_RANGE_FINAL "([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"
|
||||
|
||||
// clang-format off
|
||||
const QRegularExpression IPValidator::intermediateRegex{QStringLiteral("^" IP_RANGE_INTER "\\." IP_RANGE_INTER "\\." IP_RANGE_INTER "\\." IP_RANGE_INTER "$")};
|
||||
const QRegularExpression IPValidator::finalRegex {QStringLiteral("^" IP_RANGE_FINAL "\\." IP_RANGE_FINAL "\\." IP_RANGE_FINAL "\\." IP_RANGE_FINAL "$")};
|
||||
// clang-format on
|
||||
|
||||
IPValidator::IPValidator(QObject* parent, bool allowEmpty)
|
||||
: QValidator(parent)
|
||||
, m_allowEmpty{allowEmpty}
|
||||
{
|
||||
}
|
||||
|
||||
QValidator::State IPValidator::validate(QString& input, int& pos) const
|
||||
{
|
||||
if (input.isEmpty())
|
||||
return m_allowEmpty ? Acceptable : Intermediate;
|
||||
|
||||
QRegularExpressionMatch m = finalRegex.match(input, 0, QRegularExpression::NormalMatch);
|
||||
if (m.hasMatch())
|
||||
return Acceptable;
|
||||
|
||||
m = intermediateRegex.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
|
||||
if (m.hasMatch() || m.hasPartialMatch())
|
||||
return Intermediate;
|
||||
else
|
||||
{
|
||||
pos = input.size();
|
||||
return Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
IPItemDelegate::IPItemDelegate(QObject* parent)
|
||||
: QItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget* IPItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QLineEdit* editor = new QLineEdit(parent);
|
||||
editor->setValidator(new IPValidator());
|
||||
return editor;
|
||||
}
|
||||
|
||||
void IPItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
QString value = index.model()->data(index, Qt::EditRole).toString();
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
line->setText(value);
|
||||
}
|
||||
|
||||
void IPItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
QString value = line->text();
|
||||
model->setData(index, value);
|
||||
}
|
||||
|
||||
void IPItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/* PCSX2 - PS2 Emulator for PCs
|
||||
* Copyright (C) 2002-2021 PCSX2 Dev Team
|
||||
*
|
||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtGui/QValidator>
|
||||
#include <QtWidgets/QItemDelegate>
|
||||
|
||||
struct HostEntryUi
|
||||
{
|
||||
std::string Url;
|
||||
std::string Desc;
|
||||
std::string Address = "0.0.0.0";
|
||||
bool Enabled;
|
||||
};
|
||||
|
||||
class IPValidator : public QValidator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IPValidator(QObject* parent = nullptr, bool allowEmpty = false);
|
||||
virtual State validate(QString& input, int& pos) const override;
|
||||
|
||||
private:
|
||||
static const QRegularExpression intermediateRegex;
|
||||
static const QRegularExpression finalRegex;
|
||||
|
||||
bool m_allowEmpty;
|
||||
};
|
||||
|
||||
class IPItemDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IPItemDelegate(QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
void setEditorData(QWidget* editor, const QModelIndex& index) const;
|
||||
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
||||
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
};
|
|
@ -155,6 +155,7 @@
|
|||
<ClCompile Include="Settings\AudioSettingsWidget.cpp" />
|
||||
<ClCompile Include="Settings\MemoryCardSettingsWidget.cpp" />
|
||||
<ClCompile Include="Settings\DEV9SettingsWidget.cpp" />
|
||||
<ClCompile Include="Settings\DEV9UiCommon.cpp" />
|
||||
<ClCompile Include="Settings\HddCreateQt.cpp" />
|
||||
<ClCompile Include="Settings\GameSummaryWidget.cpp" />
|
||||
<ClCompile Include="GameList\GameListModel.cpp" />
|
||||
|
@ -190,6 +191,7 @@
|
|||
<QtMoc Include="Settings\AudioSettingsWidget.h" />
|
||||
<QtMoc Include="Settings\MemoryCardSettingsWidget.h" />
|
||||
<QtMoc Include="Settings\DEV9SettingsWidget.h" />
|
||||
<QtMoc Include="Settings\DEV9UiCommon.h" />
|
||||
<ClInclude Include="Settings\HddCreateQt.h" />
|
||||
<QtMoc Include="Settings\GameSummaryWidget.h" />
|
||||
<QtMoc Include="Settings\CreateMemoryCardDialog.h" />
|
||||
|
@ -234,6 +236,7 @@
|
|||
<ClCompile Include="$(IntDir)Settings\moc_AudioSettingsWidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)Settings\moc_MemoryCardSettingsWidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)Settings\moc_DEV9SettingsWidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)Settings\moc_DEV9UiCommon.cpp" />
|
||||
<ClCompile Include="$(IntDir)Settings\moc_GameSummaryWidget.cpp" />
|
||||
<ClCompile Include="$(IntDir)GameList\moc_GameListModel.cpp" />
|
||||
<ClCompile Include="$(IntDir)GameList\moc_GameListRefreshThread.cpp" />
|
||||
|
|
|
@ -173,6 +173,9 @@
|
|||
<ClCompile Include="$(IntDir)Settings\moc_DEV9SettingsWidget.cpp">
|
||||
<Filter>moc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(IntDir)Settings\moc_DEV9UiCommon.cpp">
|
||||
<Filter>moc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Settings\GameSummaryWidget.cpp">
|
||||
<Filter>Settings</Filter>
|
||||
</ClCompile>
|
||||
|
@ -191,6 +194,9 @@
|
|||
<ClCompile Include="Settings\DEV9SettingsWidget.cpp">
|
||||
<Filter>Settings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Settings\DEV9UiCommon.cpp">
|
||||
<Filter>Settings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Settings\HddCreateQt.cpp">
|
||||
<Filter>Settings</Filter>
|
||||
</ClCompile>
|
||||
|
@ -294,6 +300,9 @@
|
|||
<QtMoc Include="Settings\DEV9SettingsWidget.h">
|
||||
<Filter>Settings</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="Settings\DEV9UiCommon.h">
|
||||
<Filter>Settings</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="AutoUpdaterDialog.h" />
|
||||
<QtMoc Include="Tools\InputRecording\NewInputRecordingDlg.h">
|
||||
<Filter>Tools\Input Recording</Filter>
|
||||
|
|
Loading…
Reference in New Issue