void ScreenshotService::getScreenshot(TasCommandModel& model, TasResponse& response) { QListIterator<TasTarget*> i(model.targetList()); QString errorMsg = PARSE_ERROR; QImage screenshot; QString pictureFormat = "PNG"; while (i.hasNext()) { TasTarget* commandTarget = i.next(); QString targetId = commandTarget->id(); QString targetType = commandTarget->type(); TasCommand* command = commandTarget->findCommand("Screenshot"); // are required for command completion if (targetId.isEmpty() || targetType.isEmpty() || !command) { continue; } if (!command->parameter("format").isEmpty()) { pictureFormat = command->parameter("format"); } if (!isFormatSupported(pictureFormat)) { errorMsg = "Given format " + pictureFormat + "is not supported. Supported formats are: PNG, JPEG and BMP."; break; } bool draw = (command->parameter("draw") == "true"); QWidget* widget = 0; QQuickWindow* qtQuickWindow = 0; WId winId = 0; QRect rect(0,0,-1,-1); errorMsg = "Taking screenshot failed!"; if (targetType == TYPE_GRAPHICS_VIEW) { //TasLogger::logger()->debug("TYPE_GRAPHICS_VIEW Target id:" + targetId); QGraphicsItem* item = findGraphicsItem(targetId); if (item) { QGraphicsView* view = getViewForItem(item); if(view) { ItemLocationDetails locationDetails = TestabilityUtils::getItemLocationDetails(item); rect = QRect(locationDetails.windowPoint.x(), locationDetails.windowPoint.y(), locationDetails.width, locationDetails.height); if (draw) { widget = view->window(); } else { winId = view->window()->winId(); } } else { errorMsg = "Could not find a GraphicsView for the GraphicsItem!"; } } else { errorMsg = "Could not find the GraphicsItem!"; } } else if (targetType == TYPE_STANDARD_VIEW) { //TasLogger::logger()->debug("TYPE_STANDARD_VIEW about to find widget Target id:" + targetId); widget = findWidget(targetId); if (widget) { if ((widget->isWindow() && !draw) || widget->inherits("QDesktopWidget")) { winId = widget->winId(); widget = 0; } else if (!draw) { QPoint point = widget->mapToGlobal(QPoint(0,0)); QPoint windowPoint = widget->window()->mapFromGlobal(point); rect = QRect(windowPoint.x(), windowPoint.y(), widget->rect().width(), widget->rect().width()); winId = widget->window()->winId(); widget = 0; } } else { TasLogger::logger()->debug("ScreenshotService::executeService application has no visible ui!"); errorMsg = "Application has no visible ui!"; } } else if (targetType == TYPE_QSCENEGRAPH) { QQuickItem* item = TestabilityUtils::findQuickItem(targetId); if (item) { QPointF offset = item->mapToScene(QPointF(0,0)); rect = QRect(-offset.x(), -offset.y(), item->width(), item->height()); qtQuickWindow = item->window(); } } else { //TasLogger::logger()->debug("TYPE_APPLICATION_VIEW about to find application window Target id:" + targetId); widget = getApplicationWidget(); if (!widget) { QWindow *window = getApplicationWindow(); //in case no window false, return the desktop qtQuickWindow = qobject_cast<QQuickWindow *>(window); if (!window) { widget = qApp->desktop(); } } } if (widget) { screenshot = widget->grab(rect).toImage(); if (!screenshot.isNull()) { screenshot.setText("tas_id", objectId(widget)); } } else if (qtQuickWindow) { screenshot = qtQuickWindow->grabWindow(); if (!screenshot.isNull()) { screenshot.setText("tas_id", objectId(qtQuickWindow)); } } else if (winId) { screenshot = QPixmap::grabWindow(winId, rect.x(), rect.y(), rect.width(), rect.height()).toImage(); if (!screenshot.isNull()) { screenshot.setText("tas_id", QString::number(winId)); } } break; } if (!screenshot.isNull()) { QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); screenshot.save(&buffer, pictureFormat.toLatin1()); response.setData(bytes); buffer.close(); } else { response.setErrorMessage(errorMsg); } }
/************************************************ * Widget Listing: * Creation of the list of drawed lovely buttons ************************************************/ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent ) : QListWidget( _parent ) { /* We need the parent to know the options checked */ parent = qobject_cast<ToolbarEditDialog *>(_parent); assert( parent ); /* Normal options */ setViewMode( QListView::ListMode ); setTextElideMode( Qt::ElideNone ); setDragEnabled( true ); int icon_size = fontMetrics().height(); setIconSize( QSize( icon_size * 2, icon_size ) ); /* All the buttons do not need a special rendering */ for( int i = 0; i < BUTTON_MAX; i++ ) { QListWidgetItem *widgetItem = new QListWidgetItem( this ); widgetItem->setText( qtr( nameL[i] ) ); widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) ); widgetItem->setIcon( QIcon( iconL[i] ) ); widgetItem->setData( Qt::UserRole, QVariant( i ) ); widgetItem->setToolTip( widgetItem->text() ); addItem( widgetItem ); } /* Spacers are yet again a different thing */ QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space.svg" ), qtr( "Spacer" ), this ); widgetItem->setData( Qt::UserRole, WIDGET_SPACER ); widgetItem->setToolTip( widgetItem->text() ); widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) ); addItem( widgetItem ); widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space.svg" ), qtr( "Expanding Spacer" ), this ); widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND ); widgetItem->setToolTip( widgetItem->text() ); widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) ); addItem( widgetItem ); /** * For all other widgets, we create then, do a pseudo rendering in * a pixmaps for the view, and delete the object * * A lot of code is retaken from the Abstract, but not exactly... * So, rewrite. * They are better ways to deal with this, but I doubt that this is * necessary. If you feel like you have the time, be my guest. * -- * jb **/ for( int i = SPLITTER; i < SPECIAL_MAX; i++ ) { QWidget *widget = NULL; QListWidgetItem *widgetItem = new QListWidgetItem; widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) ); switch( i ) { case SPLITTER: { QFrame *line = new QFrame( this ); line->setFrameShape( QFrame::VLine ); line->setFrameShadow( QFrame::Raised ); line->setLineWidth( 0 ); line->setMidLineWidth( 1 ); widget = line; } widgetItem->setText( qtr("Splitter") ); break; case INPUT_SLIDER: { SeekSlider *slider = new SeekSlider( p_intf, Qt::Horizontal, this ); widget = slider; } widgetItem->setText( qtr("Time Slider") ); break; case VOLUME: { SoundWidget *snd = new SoundWidget( this, p_intf, parent->getOptions() & WIDGET_SHINY ); widget = snd; } widgetItem->setText( qtr("Volume") ); break; case VOLUME_SPECIAL: { QListWidgetItem *widgetItem = new QListWidgetItem( this ); widgetItem->setText( qtr("Small Volume") ); widgetItem->setIcon( QIcon( ":/toolbar/volume-medium.svg" ) ); widgetItem->setData( Qt::UserRole, QVariant( i ) ); addItem( widgetItem ); } continue; case TIME_LABEL: { QLabel *timeLabel = new QLabel( "12:42/2:12:42", this ); widget = timeLabel; } widgetItem->setText( qtr("Time") ); break; case MENU_BUTTONS: { QWidget *discFrame = new QWidget( this ); //discFrame->setLineWidth( 1 ); QHBoxLayout *discLayout = new QHBoxLayout( discFrame ); discLayout->setSpacing( 0 ); discLayout->setMargin( 0 ); QToolButton *prevSectionButton = new QToolButton( discFrame ); prevSectionButton->setIcon( QIcon( ":/toolbar/dvd_prev.svg" ) ); prevSectionButton->setToolTip( qtr("Previous Chapter/Title" ) ); discLayout->addWidget( prevSectionButton ); QToolButton *nextButton = new QToolButton( discFrame ); nextButton->setIcon( QIcon( ":/toolbar/dvd_next.svg" ) ); nextButton->setToolTip( qtr("Next Chapter/Title" ) ); discLayout->addWidget( nextButton ); QToolButton *menuButton = new QToolButton( discFrame ); menuButton->setIcon( QIcon( ":/toolbar/dvd_menu.svg" ) ); menuButton->setToolTip( qtr( "Menu" ) ); discLayout->addWidget( menuButton ); widget = discFrame; } widgetItem->setText( qtr("DVD menus") ); break; case TELETEXT_BUTTONS: { QWidget *telexFrame = new QWidget( this ); QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame ); telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 ); QToolButton *telexOn = new QToolButton( telexFrame ); telexOn->setIcon( QIcon( ":/toolbar/tv.svg" ) ); telexLayout->addWidget( telexOn ); QToolButton *telexTransparent = new QToolButton; telexTransparent->setIcon( QIcon( ":/toolbar/tvtelx.svg" ) ); telexTransparent->setToolTip( qtr("Teletext transparency") ); telexLayout->addWidget( telexTransparent ); QSpinBox *telexPage = new QSpinBox; telexLayout->addWidget( telexPage ); widget = telexFrame; } widgetItem->setText( qtr("Teletext") ); break; case ADVANCED_CONTROLLER: { AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this ); widget = advControls; } widgetItem->setText( qtr("Advanced Buttons") ); break; case PLAYBACK_BUTTONS: { widget = new QWidget; DeckButtonsLayout *layout = new DeckButtonsLayout( widget ); BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward ); BrowseButton *next = new BrowseButton( widget ); RoundButton *play = new RoundButton( widget ); layout->setBackwardButton( prev ); layout->setForwardButton( next ); layout->setRoundButton( play ); } widgetItem->setText( qtr("Playback Buttons") ); break; case ASPECT_RATIO_COMBOBOX: widget = new AspectRatioComboBox( p_intf, THEMIM->getAspectRatio() ); widgetItem->setText( qtr("Aspect ratio selector") ); break; case SPEED_LABEL: widget = new SpeedLabel( p_intf, this ); widgetItem->setText( qtr("Speed selector") ); break; case TIME_LABEL_ELAPSED: widget = new QLabel( "2:42", this ); widgetItem->setText( qtr("Elapsed time") ); break; case TIME_LABEL_REMAINING: widget = new QLabel( "-2:42", this ); widgetItem->setText( qtr("Total/Remaining time") ); break; default: msg_Warn( p_intf, "This should not happen %i", i ); break; } if( widget == NULL ) continue; widgetItem->setIcon( QIcon( widget->grab() ) ); widgetItem->setToolTip( widgetItem->text() ); widget->hide(); widgetItem->setData( Qt::UserRole, QVariant( i ) ); addItem( widgetItem ); delete widget; } }
QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag) : m_items(items) { enum { Alpha = 200 }; QPoint decorationTopLeft; switch (m_items.size()) { case 0: break; case 1: { QWidget *deco = m_items.first()->decoration(); decorationTopLeft = deco->pos(); const QPixmap widgetPixmap = deco->grab(QRect(0, 0, -1, -1)); #ifdef TRANSPARENT_DRAG_PIXMAP QImage image(widgetPixmap.size(), QImage::Format_ARGB32); image.fill(QColor(Qt::transparent).rgba()); QPainter painter(&image); painter.drawPixmap(QPoint(0, 0), widgetPixmap); painter.end(); setImageTransparency(image, Alpha); drag->setPixmap(QPixmap::fromImage(image)); #else drag->setPixmap(widgetPixmap); #endif } break; default: { // determine size of drag decoration by uniting all geometries const QDesignerDnDItems::const_iterator cend = m_items.constEnd(); QDesignerDnDItems::const_iterator it =m_items.constBegin(); QRect unitedGeometry = (*it)->decoration()->geometry(); for (++it; it != cend; ++it ) unitedGeometry = unitedGeometry .united((*it)->decoration()->geometry()); // paint with offset. At the same time, create a mask bitmap, containing widget rectangles. QImage image(unitedGeometry.size(), QImage::Format_ARGB32); image.fill(QColor(Qt::transparent).rgba()); QBitmap mask(unitedGeometry.size()); mask.clear(); // paint with offset, determine action QPainter painter(&image); QPainter maskPainter(&mask); decorationTopLeft = unitedGeometry.topLeft(); for (it = m_items.constBegin() ; it != cend; ++it ) { QWidget *w = (*it)->decoration(); const QPixmap wp = w->grab(QRect(0, 0, -1, -1)); const QPoint pos = w->pos() - decorationTopLeft; painter.drawPixmap(pos, wp); maskPainter.fillRect(QRect(pos, wp.size()), Qt::color1); } painter.end(); maskPainter.end(); #ifdef TRANSPARENT_DRAG_PIXMAP setImageTransparency(image, Alpha); #endif QPixmap pixmap = QPixmap::fromImage(image); pixmap.setMask(mask); drag->setPixmap(pixmap); } break; } // determine hot spot and reconstruct the exact starting position as form window // introduces some offset when detecting DnD m_globalStartPos = m_items.first()->decoration()->pos() + m_items.first()->hotSpot(); m_hotSpot = m_globalStartPos - decorationTopLeft; drag->setHotSpot(m_hotSpot); drag->setMimeData(this); }