92 ___INFOLOG( QString(
"Taking shot: %1" ).arg( s.trimmed() ) );
93 QStringList words = s.trimmed().split(
94 QRegularExpression(
"\\s+" ) );
95 if ( s.size() == 0 ) {
98 QString sCmd = words[ 0 ];
100 if ( sCmd.startsWith(
"#" ) || sCmd ==
"" ) {
102 }
else if ( sCmd.compare(
"fin", Qt::CaseInsensitive) == 0 ) {
110 QTimer::singleShot( 1, QApplication::instance(), &QApplication::closeAllWindows );
111 }
else if ( sCmd.compare(
"dump", Qt::CaseInsensitive) == 0 ) {
113 for ( QWidget *pTop : QApplication::topLevelWidgets() ) {
114 pTop->dumpObjectTree();
116 }
else if ( sCmd.compare(
"grab", Qt::CaseInsensitive ) == 0 ) {
118 if ( words.size() < 2 ) {
119 ___ERRORLOG( QString(
"Syntax: grab <widget> [as <filename>] [size w d] [offset x y ]." ) );
122 QString sWidgetName = words[0];
124 QRect rect( 0, 0, -1, -1 );
125 QString sFileName = QString(
"%1.png" ).arg( sWidgetName );
126 while ( !words.empty() ) {
127 if ( words[0] ==
"as" ) {
129 if ( words.size() < 1 ) {
130 ___ERRORLOG( QString(
"Syntax: grab ... as <filename>" ) );
132 sFileName = words[0];
135 }
else if ( words[0] ==
"size" ) {
137 if ( words.size() < 2 ) {
138 ___ERRORLOG( QString(
"Syntax: grab ... size <width> <height>" ) );
140 rect.setWidth( words[0].toInt() );
141 rect.setHeight( words[1].toInt() );
145 }
else if ( words[0] ==
"offset" ) {
147 if ( words.size() < 2 ) {
148 ___ERRORLOG( QString(
"Syntax: grab ... offset <width> <height>" ) );
150 rect.setX( words[0].toInt() );
151 rect.setY( words[1].toInt() );
156 ___ERRORLOG( QString(
"Syntax: grab <widget> [as <filename>] [size w d] [offset x y ]."
157 " Unexpected '%1'" ).arg( words[0] ) );
164 QPixmap p = pWidget->grab();
165 QRect oldRect = rect;
167 rect = QRect( rect.topLeft() * p.devicePixelRatio(),
168 rect.size() * p.devicePixelRatio() );
169 if ( rect.width() <= 0 ) {
170 rect.setWidth( p.rect().width() );
172 if ( rect.height() <= 0 ) {
173 rect.setHeight( p.rect().height() );
175 QRect grabRect = rect.intersected( p.rect() );
176 p.copy( grabRect ).save( sFileName );
177 ___INFOLOG( QString(
"Saved grabbed widget %1" ).arg( sFileName ) );
179 ___ERRORLOG( QString(
"Couldn't find widget named '%1' to grab" ).arg( sWidgetName ) );
183 }
else if ( sCmd.compare(
"slot", Qt::CaseInsensitive ) == 0 ) {
185 if ( words.size() >= 3 ) {
186 QString sWidgetName = words[ 1 ];
187 QString sMethodName = words[ 2 ];
191 ___INFOLOG( QString(
"Invoking '%1' on '%2'" ).arg( sMethodName, sWidgetName ) );
192 bool bSuccess =
false;
193 const auto sMethodNameLocal8Bit = sMethodName.toLocal8Bit();
194 switch ( words.size() ) {
196 bSuccess = QMetaObject::invokeMethod(
197 pWidget, sMethodNameLocal8Bit.data(), Qt::DirectConnection );
200 bSuccess = QMetaObject::invokeMethod(
201 pWidget, sMethodNameLocal8Bit.data(), Qt::DirectConnection,
205 bSuccess = QMetaObject::invokeMethod(
206 pWidget, sMethodNameLocal8Bit.data(), Qt::DirectConnection,
207 Arg( words[3] ),
Arg( words[4] ) );
210 bSuccess = QMetaObject::invokeMethod(
211 pWidget, sMethodNameLocal8Bit.data(), Qt::DirectConnection,
212 Arg( words[3] ),
Arg( words[4] ),
Arg( words[5] ) );
215 ___ERRORLOG(
"Unsupported number of arguments in %0" );
219 ___ERRORLOG( QString(
"Couldn't invoke '%1' on '%2'" )
220 .arg( sMethodName, sWidgetName ) );
225 ___ERRORLOG( QString(
"Couldn't find widget named '%1' to invoke '%2' on" )
226 .arg( sWidgetName, sMethodName ) );
229 ___ERRORLOG( QString(
"Syntax: slot <widget> <method> [args]" ) );
232 ___ERRORLOG( QString(
"Unknown command '%1'").arg( sCmd ) );