chore: Adapter Qt5.11

This commit is contained in:
leiyu 2021-12-03 14:24:31 +08:00
commit 11c76d5c2c
5 changed files with 51 additions and 30 deletions

View file

@ -116,9 +116,17 @@ QStringList AdbProcess::getDevicesSerialFromStdOut()
{ {
// get devices serial by adb devices // get devices serial by adb devices
QStringList serials; QStringList serials;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QStringList devicesInfoList = m_standardOutput.split(QRegExp("\r\n|\n"), Qt::SkipEmptyParts); QStringList devicesInfoList = m_standardOutput.split(QRegExp("\r\n|\n"), Qt::SkipEmptyParts);
#else
QStringList devicesInfoList = m_standardOutput.split(QRegExp("\r\n|\n"), QString::SkipEmptyParts);
#endif
for (QString deviceInfo : devicesInfoList) { for (QString deviceInfo : devicesInfoList) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QStringList deviceInfos = deviceInfo.split(QRegExp("\t"), Qt::SkipEmptyParts); QStringList deviceInfos = deviceInfo.split(QRegExp("\t"), Qt::SkipEmptyParts);
#else
QStringList deviceInfos = deviceInfo.split(QRegExp("\t"), QString::SkipEmptyParts);
#endif
if (2 == deviceInfos.count() && 0 == deviceInfos[1].compare("device")) { if (2 == deviceInfos.count() && 0 == deviceInfos[1].compare("device")) {
serials << deviceInfos[0]; serials << deviceInfos[0];
} }
@ -131,7 +139,7 @@ QString AdbProcess::getDeviceIPFromStdOut()
QString ip = ""; QString ip = "";
#if 0 #if 0
QString strIPExp = "inet [\\d.]*"; QString strIPExp = "inet [\\d.]*";
QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive); QRegExp ipRegExp(strIPExp, Qt::CaseInsensitive);
if (ipRegExp.indexIn(m_standardOutput) != -1) { if (ipRegExp.indexIn(m_standardOutput) != -1) {
ip = ipRegExp.cap(0); ip = ipRegExp.cap(0);
ip = ip.right(ip.size() - 5); ip = ip.right(ip.size() - 5);

View file

@ -47,9 +47,9 @@ void InputConvertNormal::mouseEvent(const QMouseEvent *from, const QSize &frameS
} }
controlMsg->setInjectTouchMsgData( controlMsg->setInjectTouchMsgData(
static_cast<quint64>(POINTER_ID_MOUSE), action, static_cast<quint64>(POINTER_ID_MOUSE), action,
convertMouseButtons(from->buttons()), convertMouseButtons(from->buttons()),
QRect(pos.toPoint(), frameSize), QRect(pos.toPoint(), frameSize),
AMOTION_EVENT_ACTION_DOWN == action? 1.0f : 0.0f); AMOTION_EVENT_ACTION_DOWN == action ? 1.0f : 0.0f);
sendControlMsg(controlMsg); sendControlMsg(controlMsg);
} }
@ -64,7 +64,11 @@ void InputConvertNormal::wheelEvent(const QWheelEvent *from, const QSize &frameS
qint32 vScroll = from->angleDelta().y() == 0 ? 0 : from->angleDelta().y() / abs(from->angleDelta().y()) * 2; qint32 vScroll = from->angleDelta().y() == 0 ? 0 : from->angleDelta().y() / abs(from->angleDelta().y()) * 2;
// pos // pos
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QPointF pos = from->position(); QPointF pos = from->position();
#else
QPointF pos = from->posF();
#endif
// convert pos // convert pos
pos.setX(pos.x() * frameSize.width() / showSize.width()); pos.setX(pos.x() * frameSize.width() / showSize.width());
pos.setY(pos.y() * frameSize.height() / showSize.height()); pos.setY(pos.y() * frameSize.height() / showSize.height());

View file

@ -627,6 +627,7 @@ void VideoForm::mouseDoubleClickEvent(QMouseEvent *event)
void VideoForm::wheelEvent(QWheelEvent *event) void VideoForm::wheelEvent(QWheelEvent *event)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
if (m_videoWidget->geometry().contains(event->position().toPoint())) { if (m_videoWidget->geometry().contains(event->position().toPoint())) {
if (!m_device) { if (!m_device) {
return; return;
@ -634,6 +635,17 @@ void VideoForm::wheelEvent(QWheelEvent *event)
QPointF pos = m_videoWidget->mapFrom(this, event->position().toPoint()); QPointF pos = m_videoWidget->mapFrom(this, event->position().toPoint());
QWheelEvent wheelEvent( QWheelEvent wheelEvent(
pos, event->globalPosition(), event->pixelDelta(), event->angleDelta(), event->buttons(), event->modifiers(), event->phase(), event->inverted()); pos, event->globalPosition(), event->pixelDelta(), event->angleDelta(), event->buttons(), event->modifiers(), event->phase(), event->inverted());
#else
if (m_videoWidget->geometry().contains(event->pos())) {
if (!m_device) {
return;
}
QPointF pos = m_videoWidget->mapFrom(this, event->pos());
QWheelEvent wheelEvent(
pos, event->globalPosF(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(),
event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted());
#endif
emit m_device->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size()); emit m_device->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size());
} }
} }

View file

@ -89,11 +89,11 @@ Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
m_hideIcon->setContextMenu(m_menu); m_hideIcon->setContextMenu(m_menu);
m_hideIcon->show(); m_hideIcon->show();
connect(m_showWindow, &QAction::triggered, this, &Dialog::slotShow); connect(m_showWindow, &QAction::triggered, this, &Dialog::slotShow);
connect(m_quit, &QAction::triggered, this, [this](){ connect(m_quit, &QAction::triggered, this, [this]() {
m_hideIcon->hide(); m_hideIcon->hide();
qApp->quit(); qApp->quit();
}); });
connect(m_hideIcon, &QSystemTrayIcon::activated,this,&Dialog::slotActivated); connect(m_hideIcon, &QSystemTrayIcon::activated, this, &Dialog::slotActivated);
} }
Dialog::~Dialog() Dialog::~Dialog()
@ -152,9 +152,9 @@ void Dialog::updateBootConfig(bool toView)
if (toView) { if (toView) {
UserBootConfig config = Config::getInstance().getUserBootConfig(); UserBootConfig config = Config::getInstance().getUserBootConfig();
if(config.bitRate == 0) { if (config.bitRate == 0) {
ui->bitRateBox->setCurrentText("Mbps"); ui->bitRateBox->setCurrentText("Mbps");
} else if(config.bitRate % 1000000 == 0) { } else if (config.bitRate % 1000000 == 0) {
ui->bitRateEdit->setText(QString::number(config.bitRate / 1000000)); ui->bitRateEdit->setText(QString::number(config.bitRate / 1000000));
ui->bitRateBox->setCurrentText("Mbps"); ui->bitRateBox->setCurrentText("Mbps");
} else { } else {
@ -203,7 +203,11 @@ void Dialog::execAdbCmd()
} }
QString cmd = ui->adbCommandEdt->text().trimmed(); QString cmd = ui->adbCommandEdt->text().trimmed();
outLog("adb " + cmd, false); outLog("adb " + cmd, false);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
m_adb.execute(ui->serialBox->currentText().trimmed(), cmd.split(" ", Qt::SkipEmptyParts)); m_adb.execute(ui->serialBox->currentText().trimmed(), cmd.split(" ", Qt::SkipEmptyParts));
#else
m_adb.execute(ui->serialBox->currentText().trimmed(), cmd.split(" ", QString::SkipEmptyParts));
#endif
} }
void Dialog::delayMs(int ms) void Dialog::delayMs(int ms)
@ -249,9 +253,9 @@ void Dialog::closeEvent(QCloseEvent *event)
{ {
this->hide(); this->hide();
m_hideIcon->showMessage(tr("Notice"), m_hideIcon->showMessage(tr("Notice"),
tr("Hidden here!"), tr("Hidden here!"),
QSystemTrayIcon::Information, QSystemTrayIcon::Information,
3000); 3000);
event->ignore(); event->ignore();
} }
@ -521,14 +525,13 @@ void Dialog::on_usbConnectBtn_clicked()
on_startServerBtn_clicked(); on_startServerBtn_clicked();
} }
int Dialog::findDeviceFromeSerialBox(bool wifi) { int Dialog::findDeviceFromeSerialBox(bool wifi)
{
QRegExp regIP("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\:([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])\\b"); QRegExp regIP("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\:([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])\\b");
for (int i = 0; i < ui->serialBox->count(); ++i) for (int i = 0; i < ui->serialBox->count(); ++i) {
{
bool isWifi = regIP.exactMatch(ui->serialBox->itemText(i)); bool isWifi = regIP.exactMatch(ui->serialBox->itemText(i));
bool found = wifi ? isWifi : !isWifi; bool found = wifi ? isWifi : !isWifi;
if(found) if (found) {
{
return i; return i;
} }
} }
@ -582,8 +585,8 @@ void Dialog::on_connectedPhoneList_itemDoubleClicked(QListWidgetItem *item)
void Dialog::on_updateNameBtn_clicked() void Dialog::on_updateNameBtn_clicked()
{ {
if(ui->serialBox->count()!=0) { if (ui->serialBox->count() != 0) {
if(ui->userNameEdt->text().isEmpty()) { if (ui->userNameEdt->text().isEmpty()) {
Config::getInstance().setNickName(ui->serialBox->currentText(), "Phone"); Config::getInstance().setNickName(ui->serialBox->currentText(), "Phone");
} else { } else {
Config::getInstance().setNickName(ui->serialBox->currentText(), ui->userNameEdt->text()); Config::getInstance().setNickName(ui->serialBox->currentText(), ui->userNameEdt->text());
@ -591,30 +594,27 @@ void Dialog::on_updateNameBtn_clicked()
on_updateDevice_clicked(); on_updateDevice_clicked();
qDebug()<<"Update OK!"; qDebug() << "Update OK!";
} else { } else {
qWarning()<<"No device is connected!"; qWarning() << "No device is connected!";
} }
} }
void Dialog::on_useSingleModeCheck_clicked() void Dialog::on_useSingleModeCheck_clicked()
{ {
if(ui->useSingleModeCheck->isChecked()) if (ui->useSingleModeCheck->isChecked()) {
{
ui->configGroupBox->hide(); ui->configGroupBox->hide();
ui->adbGroupBox->hide(); ui->adbGroupBox->hide();
ui->wirelessGroupBox->hide(); ui->wirelessGroupBox->hide();
ui->usbGroupBox->hide(); ui->usbGroupBox->hide();
} } else {
else
{
ui->configGroupBox->show(); ui->configGroupBox->show();
ui->adbGroupBox->show(); ui->adbGroupBox->show();
ui->wirelessGroupBox->show(); ui->wirelessGroupBox->show();
ui->usbGroupBox->show(); ui->usbGroupBox->show();
} }
QTimer::singleShot(0, this, [this](){ QTimer::singleShot(0, this, [this]() {
resize(width(), layout()->sizeHint().height()); resize(width(), layout()->sizeHint().height());
}); });
} }
@ -627,5 +627,5 @@ void Dialog::on_serialBox_currentIndexChanged(const QString &arg1)
quint32 Dialog::getBitRate() quint32 Dialog::getBitRate()
{ {
return ui->bitRateEdit->text().trimmed().toUInt() * return ui->bitRateEdit->text().trimmed().toUInt() *
(ui->bitRateBox->currentText() == QString("Mbps") ? 1000000 : 1000); (ui->bitRateBox->currentText() == QString("Mbps") ? 1000000 : 1000);
} }

View file

@ -207,9 +207,6 @@
<property name="currentText"> <property name="currentText">
<string notr="true">Mbps</string> <string notr="true">Mbps</string>
</property> </property>
<property name="placeholderText">
<string notr="true"/>
</property>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">Mbps</string> <string notr="true">Mbps</string>