Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed init focus problem and click button focus problem #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions core_qui/quihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,18 +1013,39 @@ QString QUIHelper::getNetIP(const QString &html)
return ip;
}

const QString getHostServer()
{
QString ipAddress;

// 获取第一个本主机的 IPv4 地址
QList<QHostAddress> addresss = QNetworkInterface::allAddresses();
foreach (const QHostAddress &addr, addresss) {
if ((addr != QHostAddress::LocalHost) && (addr.protocol() == QAbstractSocket::IPv4Protocol)) {
ipAddress = addr.toString();
break;
}
}

// 如果没有找到,则以本地 IP 地址为准
if (ipAddress.isEmpty())
ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

return ipAddress;
}

QString QUIHelper::getLocalIP()
{
//优先取192开头的IP,如果获取不到IP则取127.0.0.1
QString ip = "127.0.0.1";
// QString ip = "127.0.0.1";

QString ip = getHostServer();
QStringList ips = getLocalIPs();
foreach (QString str, ips) {
if (str.startsWith("192.168.1") || str.startsWith("192")) {
ip = str;
break;
}
}

return ip;
}

Expand Down
7 changes: 7 additions & 0 deletions devicebutton/frmdevicebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ void frmDeviceButton::initForm()
foreach (QPushButton *btn, btnColor) {
connect(btn, SIGNAL(clicked(bool)), this, SLOT(changeColor()));
}

//初始化获取当前按钮类型,设置焦点
int initstatus = btn1->getButtonStyle();
if(initstatus >= DeviceButton::ButtonStyle_Circle || initstatus<= DeviceButton::ButtonStyle_Msg2)
btnStyle.at(initstatus)->setFocus();
}

void frmDeviceButton::changeStyle()
{
QPushButton *btn = (QPushButton *)sender();
int index = btnStyle.indexOf(btn);
btn->setFocus();
DeviceButton::ButtonStyle style = (DeviceButton::ButtonStyle)index;
btn1->setButtonStyle(style);
btn2->setButtonStyle(style);
Expand All @@ -56,6 +62,7 @@ void frmDeviceButton::changeColor()
{
QPushButton *btn = (QPushButton *)sender();
int index = btnColor.indexOf(btn);
btn->setFocus();
DeviceButton::ButtonColor style = (DeviceButton::ButtonColor)index;
btn1->setButtonColor(style);
btn2->setButtonColor(style);
Expand Down