87 ___INFOLOG( QString(
"Taking shot: %1" ).arg( s.trimmed() ) );
88 QStringList words = s.trimmed().split( QRegExp(
"\\s+" ) );
89 if ( s.size() == 0 ) {
92 QString sCmd = words[ 0 ];
94 if ( sCmd.startsWith(
"#" ) || sCmd ==
"" ) {
96 }
else if ( sCmd.compare(
"fin", Qt::CaseInsensitive) == 0 ) {
104 QTimer::singleShot( 1, QApplication::instance(), &QApplication::closeAllWindows );
105 }
else if ( sCmd.compare(
"dump", Qt::CaseInsensitive) == 0 ) {
107 for ( QWidget *pTop : QApplication::topLevelWidgets() ) {
108 pTop->dumpObjectTree();
110 }
else if ( sCmd.compare(
"grab", Qt::CaseInsensitive ) == 0 ) {
112 if ( words.size() < 2 ) {
113 ___ERRORLOG( QString(
"Syntax: grab <widget> [as <filename>] [size w d] [offset x y ]." ) );
116 QString sWidgetName = words[0];
118 QRect rect( 0, 0, -1, -1 );
119 QString sFileName = QString(
"%1.png" ).arg( sWidgetName );
120 while ( !words.empty() ) {
121 if ( words[0] ==
"as" ) {
123 if ( words.size() < 1 ) {
124 ___ERRORLOG( QString(
"Syntax: grab ... as <filename>" ) );
126 sFileName = words[0];
129 }
else if ( words[0] ==
"size" ) {
131 if ( words.size() < 2 ) {
132 ___ERRORLOG( QString(
"Syntax: grab ... size <width> <height>" ) );
134 rect.setWidth( words[0].toInt() );
135 rect.setHeight( words[1].toInt() );
139 }
else if ( words[0] ==
"offset" ) {
141 if ( words.size() < 2 ) {
142 ___ERRORLOG( QString(
"Syntax: grab ... offset <width> <height>" ) );
144 rect.setX( words[0].toInt() );
145 rect.setY( words[1].toInt() );
150 ___ERRORLOG( QString(
"Syntax: grab <widget> [as <filename>] [size w d] [offset x y ]."
151 " Unexpected '%1'" ).arg( words[0] ) );
158 QPixmap p = pWidget->grab();
159 QRect oldRect = rect;
161 rect = QRect( rect.topLeft() * p.devicePixelRatio(),
162 rect.size() * p.devicePixelRatio() );
163 if ( rect.width() <= 0 ) {
164 rect.setWidth( p.rect().width() );
166 if ( rect.height() <= 0 ) {
167 rect.setHeight( p.rect().height() );
169 QRect grabRect = rect.intersected( p.rect() );
170 p.copy( grabRect ).save( sFileName );
171 ___INFOLOG( QString(
"Saved grabbed widget %1" ).arg( sFileName ) );
173 ___ERRORLOG( QString(
"Couldn't find widget named '%1' to grab" ).arg( sWidgetName ) );
177 }
else if ( sCmd.compare(
"slot", Qt::CaseInsensitive ) == 0 ) {
179 if ( words.size() >= 3 ) {
180 QString sWidgetName = words[ 1 ];
181 QString sMethodName = words[ 2 ];
185 ___INFOLOG( QString(
"Invoking '%1' on '%2'" ).arg( sMethodName, sWidgetName ) );
186 bool bSuccess =
false;
187 switch ( words.size() ) {
189 bSuccess = QMetaObject::invokeMethod( pWidget, sMethodName.toLocal8Bit().data(), Qt::DirectConnection );
192 bSuccess = QMetaObject::invokeMethod( pWidget, sMethodName.toLocal8Bit().data(), Qt::DirectConnection,
196 bSuccess = QMetaObject::invokeMethod( pWidget, sMethodName.toLocal8Bit().data(), Qt::DirectConnection,
197 Arg( words[3] ),
Arg( words[4] ) );
200 bSuccess = QMetaObject::invokeMethod( pWidget, sMethodName.toLocal8Bit().data(), Qt::DirectConnection,
201 Arg( words[3] ),
Arg( words[4] ),
Arg( words[5] ) );
204 ___ERRORLOG(
"Unsupported number of arguments in %0" );
208 ___ERRORLOG( QString(
"Couldn't invoke '%1' on '%2'" )
209 .arg( sMethodName, sWidgetName ) );
214 ___ERRORLOG( QString(
"Couldn't find widget named '%1' to invoke '%2' on" )
215 .arg( sWidgetName, sMethodName ) );
218 ___ERRORLOG( QString(
"Syntax: slot <widget> <method> [args]" ) );
221 ___ERRORLOG( QString(
"Unknown command '%1'").arg( sCmd ) );