Enhance example qtbase/examples/widgets/widgets/mousebuttons
Add Display and QDebug() of Qt::MouseButtons values. (I.e., Buttons believed to be in 'Pressed' State by Qt.) Assists in platform plugin mouse software debug. Task-number: QTBUG-28603 Change-Id: I4a7a3ac44a8cc7eb1eceb9f348493b58b12dbd69 Reviewed-by: Oliver Wolff <oliver.wolff@digia.com> Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
This commit is contained in:
parent
fa7661d8b2
commit
4d6bf271c7
@ -44,26 +44,35 @@
|
|||||||
void ButtonTester::mousePressEvent(QMouseEvent *e)
|
void ButtonTester::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
int j = ButtonTester::buttonByNumber (e->button());
|
int j = ButtonTester::buttonByNumber (e->button());
|
||||||
QString result = "Mouse Press: raw button=" + QString::number(j) + " Qt=" + enumNameFromValue(e->button());
|
QString result = "Mouse Press: raw button=" + QString::number(j)
|
||||||
|
+ " Qt=" + enumNameFromValue(e->button());
|
||||||
|
QString buttonsString = ButtonTester::enumNamesFromMouseButtons(e->buttons());
|
||||||
|
result += "\n heldbuttons " + buttonsString;
|
||||||
qDebug() << result;
|
qDebug() << result;
|
||||||
this->setText(result);
|
this->setText(result);
|
||||||
if (j == 2) {
|
this->repaint();
|
||||||
this->repaint();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonTester::mouseReleaseEvent(QMouseEvent *e)
|
void ButtonTester::mouseReleaseEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
int j = ButtonTester::buttonByNumber (e->button());
|
int j = ButtonTester::buttonByNumber (e->button());
|
||||||
QString result = "Mouse Release: raw button=" + QString::number(j) + " Qt=" + enumNameFromValue(e->button());
|
QString result = "Mouse Release: raw button=" + QString::number(j)
|
||||||
|
+ " Qt=" + enumNameFromValue(e->button());
|
||||||
|
QString buttonsString = ButtonTester::enumNamesFromMouseButtons(e->buttons());
|
||||||
|
result += "\n heldbuttons " + buttonsString;
|
||||||
qDebug() << result;
|
qDebug() << result;
|
||||||
this->setText(result);
|
this->setText(result);
|
||||||
|
this->repaint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e)
|
void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
int j = ButtonTester::buttonByNumber (e->button());
|
int j = ButtonTester::buttonByNumber (e->button());
|
||||||
QString result = "Mouse DoubleClick: raw button=" + QString::number(j) + " Qt=" + enumNameFromValue(e->button());
|
QString result = "Mouse DoubleClick: raw button=" + QString::number(j)
|
||||||
|
+ " Qt=" + enumNameFromValue(e->button());
|
||||||
|
QString buttonsString = ButtonTester::enumNamesFromMouseButtons(e->buttons());
|
||||||
|
result += "\n heldbuttons" + buttonsString;
|
||||||
qDebug() << result;
|
qDebug() << result;
|
||||||
this->setText(result);
|
this->setText(result);
|
||||||
}
|
}
|
||||||
@ -172,3 +181,38 @@ QString ButtonTester::enumNameFromValue(const Qt::MouseButton button)
|
|||||||
qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value");
|
qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value");
|
||||||
return "NoButton";
|
return "NoButton";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ButtonTester::enumNamesFromMouseButtons(const Qt::MouseButtons buttons)
|
||||||
|
{
|
||||||
|
QString returnText = "";
|
||||||
|
if (buttons == Qt::NoButton) return "NoButton";
|
||||||
|
if (buttons & Qt::LeftButton) returnText += "LeftButton ";
|
||||||
|
if (buttons & Qt::RightButton) returnText += "RightButton ";
|
||||||
|
if (buttons & Qt::MiddleButton) returnText += "MiddleButton ";
|
||||||
|
if (buttons & Qt::BackButton) returnText += "BackButton ";
|
||||||
|
if (buttons & Qt::ForwardButton) returnText += "ForwardButton ";
|
||||||
|
if (buttons & Qt::TaskButton) returnText += "TaskButton ";
|
||||||
|
if (buttons & Qt::ExtraButton4) returnText += "ExtraButton4 ";
|
||||||
|
if (buttons & Qt::ExtraButton5) returnText += "ExtraButton5 ";
|
||||||
|
if (buttons & Qt::ExtraButton6) returnText += "ExtraButton6 ";
|
||||||
|
if (buttons & Qt::ExtraButton7) returnText += "ExtraButton7 ";
|
||||||
|
if (buttons & Qt::ExtraButton8) returnText += "ExtraButton8 ";
|
||||||
|
if (buttons & Qt::ExtraButton9) returnText += "ExtraButton9 ";
|
||||||
|
if (buttons & Qt::ExtraButton10) returnText += "ExtraButton10 ";
|
||||||
|
if (buttons & Qt::ExtraButton11) returnText += "ExtraButton11 ";
|
||||||
|
if (buttons & Qt::ExtraButton12) returnText += "ExtraButton12 ";
|
||||||
|
if (buttons & Qt::ExtraButton13) returnText += "ExtraButton13 ";
|
||||||
|
if (buttons & Qt::ExtraButton14) returnText += "ExtraButton14 ";
|
||||||
|
if (buttons & Qt::ExtraButton15) returnText += "ExtraButton15 ";
|
||||||
|
if (buttons & Qt::ExtraButton16) returnText += "ExtraButton16 ";
|
||||||
|
if (buttons & Qt::ExtraButton17) returnText += "ExtraButton17 ";
|
||||||
|
if (buttons & Qt::ExtraButton18) returnText += "ExtraButton18 ";
|
||||||
|
if (buttons & Qt::ExtraButton19) returnText += "ExtraButton19 ";
|
||||||
|
if (buttons & Qt::ExtraButton20) returnText += "ExtraButton20 ";
|
||||||
|
if (buttons & Qt::ExtraButton21) returnText += "ExtraButton21 ";
|
||||||
|
if (buttons & Qt::ExtraButton22) returnText += "ExtraButton22 ";
|
||||||
|
if (buttons & Qt::ExtraButton23) returnText += "ExtraButton23 ";
|
||||||
|
if (buttons & Qt::ExtraButton24) returnText += "ExtraButton24 ";
|
||||||
|
return returnText;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
int buttonByNumber(const Qt::MouseButton button);
|
int buttonByNumber(const Qt::MouseButton button);
|
||||||
QString enumNameFromValue(const Qt::MouseButton button);
|
QString enumNameFromValue(const Qt::MouseButton button);
|
||||||
|
QString enumNamesFromMouseButtons(const Qt::MouseButtons buttons);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BUTTONTESTER_H
|
#endif // BUTTONTESTER_H
|
||||||
|
@ -48,6 +48,10 @@ int main(int argv, char **args)
|
|||||||
|
|
||||||
ButtonTester *testArea = new ButtonTester;
|
ButtonTester *testArea = new ButtonTester;
|
||||||
testArea->setMinimumSize(500, 350);
|
testArea->setMinimumSize(500, 350);
|
||||||
|
|
||||||
|
// For this test, Qt::RightButton behaves like any other button.
|
||||||
|
testArea->setContextMenuPolicy(Qt::NoContextMenu);
|
||||||
|
testArea->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
testArea->setText("To test your mouse with Qt, press buttons in this area.\nYou may also scroll or tilt your mouse wheel.");
|
testArea->setText("To test your mouse with Qt, press buttons in this area.\nYou may also scroll or tilt your mouse wheel.");
|
||||||
QPushButton *quitButton = new QPushButton("Quit");
|
QPushButton *quitButton = new QPushButton("Quit");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user