58 lines
3.1 KiB
C++
58 lines
3.1 KiB
C++
|
|
#include "usercoordinatewidget.h"
|
||
|
|
#include "robotclient.h"
|
||
|
|
#include "applicationstyle.h"
|
||
|
|
#include <QApplication>
|
||
|
|
#include <QLineEdit>
|
||
|
|
#include <QPushButton>
|
||
|
|
#include <QTimer>
|
||
|
|
#include <QComboBox>
|
||
|
|
#include <QWheelEvent>
|
||
|
|
#include <QDoubleSpinBox>
|
||
|
|
#include <QSpinBox>
|
||
|
|
#include <QDateTimeEdit>
|
||
|
|
#include <QDialog>
|
||
|
|
int main(int argc,char **argv) {
|
||
|
|
QApplication app(argc,argv);app.setApplicationName("Coordinate UI Test");
|
||
|
|
ApplicationStyle::install(app);
|
||
|
|
QComboBox combo;combo.setAttribute(Qt::WA_DontShowOnScreen);
|
||
|
|
combo.addItems({"one","two","three"});combo.setCurrentIndex(1);combo.show();combo.setFocus();
|
||
|
|
QWheelEvent wheel(QPointF(5,5),combo.mapToGlobal(QPoint(5,5)),QPoint(),QPoint(0,-120),Qt::NoButton,Qt::NoModifier,Qt::NoScrollPhase,false);
|
||
|
|
QApplication::sendEvent(&combo,&wheel);
|
||
|
|
if(combo.currentIndex()!=1)return 4;
|
||
|
|
QDialog inputs;inputs.setAttribute(Qt::WA_DontShowOnScreen);
|
||
|
|
QSpinBox integer(&inputs);integer.setRange(-100,100);integer.setValue(7);
|
||
|
|
QDoubleSpinBox decimal(&inputs);decimal.setRange(-100,100);decimal.setValue(1.25);
|
||
|
|
QDateTimeEdit dateTime(&inputs);dateTime.setDateTime(QDateTime(QDate(2026,11,3),QTime(12,30)));
|
||
|
|
inputs.show();
|
||
|
|
const auto originalDateTime=dateTime.dateTime();
|
||
|
|
const auto wheelAt=[&](QWidget* target){
|
||
|
|
for(int direction:{-120,120}) {
|
||
|
|
QWheelEvent e(QPointF(5,5),target->mapToGlobal(QPoint(5,5)),QPoint(),QPoint(0,direction),Qt::NoButton,Qt::NoModifier,Qt::NoScrollPhase,false);
|
||
|
|
QApplication::sendEvent(target,&e);
|
||
|
|
if(integer.value()!=7||decimal.value()!=1.25||dateTime.dateTime()!=originalDateTime)return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
};
|
||
|
|
for(auto* input:{static_cast<QAbstractSpinBox*>(&integer),static_cast<QAbstractSpinBox*>(&decimal),static_cast<QAbstractSpinBox*>(&dateTime)}){
|
||
|
|
input->setFocus();if(!wheelAt(input)||!wheelAt(input->findChild<QLineEdit*>()))return 5;
|
||
|
|
if(integer.value()!=7||decimal.value()!=1.25||dateTime.dateTime()!=originalDateTime)return 5;
|
||
|
|
}
|
||
|
|
RobotClient client;
|
||
|
|
UserCoordinateWidget widget(&client);
|
||
|
|
widget.setContext("test.invalid:50052","aubo_test",false);
|
||
|
|
for(auto *button:widget.findChildren<QPushButton*>())
|
||
|
|
if(button->text()==QStringLiteral("新建三点坐标系"))button->click();
|
||
|
|
widget.findChild<QLineEdit*>("userCoordinateName")->setText(QStringLiteral("正方形"));
|
||
|
|
const double points[3][6]={{-721.09,308.47,781.55,-1.56,.01,.69},{-432.38,542.77,783,-1.59,0,.65},{-439.08,537.72,322,-1.57,.01,.69}};
|
||
|
|
for(int j=0;j<3;++j)for(int i=0;i<6;++i)widget.findChild<QDoubleSpinBox*>(QString("coordinatePoint%1_%2").arg(j).arg(i))->setValue(points[j][i]);
|
||
|
|
for(auto *button:widget.findChildren<QPushButton*>())
|
||
|
|
if((button->text().contains("MoveL") || button->text().contains(QStringLiteral("应用并"))) && button->isEnabled()) return 2;
|
||
|
|
widget.setAttribute(Qt::WA_DontShowOnScreen);
|
||
|
|
widget.resize(1400,1000);widget.show();
|
||
|
|
QTimer::singleShot(400,&widget,[&]{
|
||
|
|
const bool ok=widget.grab().save(argc>1?QString::fromLocal8Bit(argv[1]):QStringLiteral("coordinates.png"));
|
||
|
|
app.exit(ok?0:3);
|
||
|
|
});
|
||
|
|
return app.exec();
|
||
|
|
}
|