bool NetworkConfigurationForm
::eventFilter(QObject *target,
QEvent *event
) {
// if the mouse/ts area is pressed on the group box or edit line then show numpad
// start the lineEdit at the beginning, make sure there is no selected text
QLineEdit *textEdit
= qobject_cast<QLineEdit
*>
(target
);
QGroupBox *groupBox
= qobject_cast<QGroupBox
*>
(target
);
if (event
->type
() == QEvent::MouseButtonPress) {
// should only be QlineEdit or GroupBox
// but if more filters are added, this needs to be here
if (textEdit || groupBox)
{
// if groupbox widget was touched ignore if same widget, otherwise
// clear font on old widget, set bold on new widget
if(groupBox)
{
qDebug() << groupBox << "GROUPBOX";
// if mousepress on the same widget, ignore it
// Otherwise clear font on old item, set on new item.
if(currentTextSelection)
{
if(currentTextSelection->parentWidget() == groupBox)
return true;
parent = currentTextSelection->parentWidget();
font = parent->font();
font.setBold(false);
parent->setFont(font);
}
font = groupBox->font();
font.setBold(true);
groupBox->setFont(font);
if (ui.ServerIPText->parentWidget() == groupBox)
currentTextSelection = ui.ServerIPText;
else if (ui.TerminalIPText->parentWidget() == groupBox)
currentTextSelection = ui.TerminalIPText;
else if (ui.SubnetText->parentWidget() == groupBox)
currentTextSelection = ui.SubnetText;
else if (ui.GatewayText->parentWidget() == groupBox)
currentTextSelection = ui.GatewayText;
else if (ui.PortText->parentWidget() == groupBox)
currentTextSelection = ui.PortText;
}
// if textEdit widget was touched ignore if same widget, otherwise
// clear font on old widget, set bold on new widget
if (textEdit)
{
qDebug() << textEdit << "textEdit";
if(currentTextSelection)
{
if (textEdit == currentTextSelection)
return true;
parent = currentTextSelection->parentWidget();
font = parent->font();
font.setBold(false);
parent->setFont(font);
}
parent = textEdit->parentWidget();
font = parent->font();
font.setBold(true);
parent->setFont(font);
currentTextSelection = textEdit; // switch to new widget
}
// Start at the beginning of the text
ui.ServerIPText->home(true);
ui.TerminalIPText->home(true);
ui.SubnetText->home(true);
ui.GatewayText->home(true);
// make sure no text has been selected by mistake
ui.ServerIPText->deselect();
ui.TerminalIPText->deselect();
ui.SubnetText->deselect();
ui.GatewayText->deselect();
if(currentTextSelection)
{
if(currentTextSelection != ui.ServerIPText && currentTextSelection != ui.PortText)
padEntry->move(400,0);
else
padEntry->move(0,0);
padEntry->show();
}
return true;
}
}
// this prevents a mouse moving event(dragging) which selects the text
else if (event
->type
() == QEvent::MouseMove) return true;
return false;
}
// slot for key entered - from number pad widget //
void NetworkConfigurationForm
::keyEntered(QKeyEvent *event
) {
if(event->key() == Qt::Key_Enter)
{
currentTextSelection->clearFocus();
currentTextSelection = 0;
padEntry->hide();
}
}
Bookmarks