예제 #1
0
QPixmap ThemeAccessor::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
    (void) requestedSize;

    QPixmap ret;

    if (id.startsWith("avatar/")) {
        return m_theme->trainerSprite(id.section("/", 1).toInt());
    }

    *size = ret.size();

    return ret;
}
예제 #2
0
QPixmap CloudImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize)
{
    QString rsrcid = ":/" + id;
    QPixmap image(rsrcid);
    QPixmap result;

    if (requestedSize.isValid()) {
        result = image.scaled(requestedSize, Qt::KeepAspectRatio);
    } else {
        result = image;
    }
    *size = result.size();
    return result;
}
예제 #3
0
void KMultiTabBarTab::computeMargins(int* hMargin, int* vMargin) const
{
	// Unfortunately, QStyle does not give us enough information to figure out
	// where to place things, so we try to reverse-engineer it
	QStyleOptionToolButton opt;
	initStyleOption(&opt);

	QPixmap iconPix = iconPixmap();
	QSize trialSize = iconPix.size();
	QSize expandSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, trialSize, this);

	*hMargin = (expandSize.width()  - trialSize.width())/2;
	*vMargin = (expandSize.height() - trialSize.height())/2;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void PipelineFilterWidget::mouseMoveEvent(QMouseEvent* event)
{
    if(!(event->buttons() & Qt::LeftButton))
    {
        return;
    }
    if((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance())
    {
        return;
    }
    // The user is dragging the filter widget so we should set it as selected.
    setIsSelected(true);
    QPixmap pixmap = grab();

    // Create new picture for transparent
    QPixmap transparent(pixmap.size());
    // Do transparency
    transparent.fill(Qt::transparent);
#if 1
    QPainter p;
    p.begin(&transparent);
    p.setOpacity(0.70);
    p.drawPixmap(0, 0, pixmap);
    p.end();
#endif

    QByteArray itemData;
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream << transparent << QPoint(event->pos());

    QMimeData* mimeData = new QMimeData;
    mimeData->setData("application/x-dnditemdata", itemData);

    QDrag* drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(transparent);
    drag->setHotSpot(event->pos());

    emit dragStarted(this);

    //  if(drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction)
    //  {
    //    qDebug() << "Drag should close the widget because it was MOVE" << "\n";
    //  }
    //  else
    //  {
    //    qDebug() << "Drag should leave Widget alone because it was COPY" << "\n";
    //  }
    drag->exec(Qt::MoveAction);
}
예제 #5
0
void ModelExportHelper::exportToPNG(ObjectsScene *scene, const QString &filename, bool show_grid, bool show_delim)
{
	if(!scene)
		throw Exception(ERR_ASG_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

	try
	{
		QPixmap pix;
		QRectF ret=scene->itemsBoundingRect();
		bool shw_grd, shw_dlm, align_objs;

		//Make a backup of the current scene options
		ObjectsScene::getGridOptions(shw_grd, align_objs, shw_dlm);

		//Sets the options passed by the user
		ObjectsScene::setGridOptions(show_grid, false, show_delim);

		//Ceils the width and height of scene rectangle in order to not draw dirty areas on pixmap
		ret.setWidth(ceilf(ret.width()));
		ret.setHeight(ceilf(ret.height()));

		//Creates the output pixmap
		pix=QPixmap(ret.size().toSize());
		QPainter p(&pix);

		//Setting optimizations on the painter
		p.setRenderHint(QPainter::Antialiasing, true);
		p.setRenderHint(QPainter::TextAntialiasing, true);
		p.setRenderHint(QPainter::SmoothPixmapTransform, true);

		//Render the entire scene onto the pixmap
		scene->clearSelection();
		scene->update();
		scene->render(&p, QRectF(QPointF(0,0), pix.size()), ret);

		//Restore the scene options
		ObjectsScene::setGridOptions(shw_grd, align_objs, shw_dlm);
		scene->update();

		//If the pixmap is not saved raises an error
		if(!pix.save(filename))
			throw Exception(Exception::getErrorMessage(ERR_FILE_NOT_WRITTEN).arg(Utf8String::create(filename)),
											ERR_FILE_NOT_WRITTEN,__PRETTY_FUNCTION__,__FILE__,__LINE__);
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
예제 #6
0
QPixmap GPSImageModel::getPixmapForIndex(const QPersistentModelIndex& itemIndex, const int size)
{
    if (itemIndex.isValid())
    {
        Q_ASSERT(itemIndex.model() == this);
    }

    // TODO: should we cache the pixmap on our own here or does the interface usually cache it for us?
    // TODO: do we need to make sure we do not request the same pixmap twice in a row?
    // construct the key under which we stored the pixmap in the cache:
    GPSImageItem* const imageItem = itemFromIndex(itemIndex);

    if (!imageItem)
        return QPixmap();

    QPixmap thumbnail;

    if (d->thumbnailLoadThread->find(ThumbnailIdentifier(imageItem->url().toLocalFile()), thumbnail, size))
    {
        return thumbnail.copy(1, 1, thumbnail.size().width()-2, thumbnail.size().height()-2);
    }

    return QPixmap();
}
예제 #7
0
void KWQTableDelegate::drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const
{
  if (pixmap.isNull() || !rect.isValid())
    return;
  QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), rect).topLeft();
  QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
  if (option.state & QStyle::State_Selected) {
    painter->fillRect(rect, option.palette.brush(cg, option.state & QStyle::State_HasFocus ?
          QPalette::Base : QPalette::Highlight));
    QPixmap *pm = selected(pixmap, option.palette, option.state & QStyle::State_Enabled);
    painter->drawPixmap(p, *pm);
  } else {
    painter->drawPixmap(p, pixmap);
  }
}
예제 #8
0
LinkLabel::LinkLabel(const QPixmap& upImg, const QPixmap& downImg, QString text, QWidget* parent)
    : QLabel(parent)
{
    _upImg = upImg;
    _downImg = downImg;
    setPixmap(_upImg);
    setFixedSize(upImg.size());
    _down = false;
    _enabled = true;
    _checkable = false;
    _type = false;
    _tooltip = text;
    _hyperlink = true;
    setMouseTracking(true);
}
예제 #9
0
    QPixmap GlobalImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
    {
        QPixmap image(id);
        QPixmap result;

        if (requestedSize.isValid()) {
            result = image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }
        else {
            result = image;
        }

        *size = result.size();
        return result;
    }
예제 #10
0
파일: MyScene.cpp 프로젝트: jbfiot/rangers
MyScene::MyScene() : QGraphicsScene()
{
	QString fichier = QFileDialog::getOpenFileName(0, "Ouvrir un fichier", QString(), "Images (*.png *.gif *.jpg *.jpeg)");
	QPixmap image = QPixmap(fichier);
	size = image.size();
	
	impix=addPixmap(image);

	point1 = QPointF();
	point2 = QPointF();
	numero=true;
	MyRectItem=new QGraphicsRectItem;
	rect = QRectF();

}
예제 #11
0
파일: MyScene.cpp 프로젝트: jbfiot/rangers
MyScene::MyScene(QString fileName) : QGraphicsScene()
{
	
	QPixmap image = QPixmap(fileName);
	size=image.size();
	impix=addPixmap(image);

	point1 = QPointF();
	point2 = QPointF();
	numero=true;
	MyRectItem=new QGraphicsRectItem;
	rect = QRectF();
	SceneSelection = new QGraphicsScene;
	Selection = SceneSelection->addPixmap(image);
}
예제 #12
0
QPixmap RoutingInputWidgetPrivate::addDropDownIndicator(const QPixmap &pixmap)
{
    QPixmap result( pixmap.size() + QSize( 8, pixmap.height() ) );
    result.fill( QColor( Qt::transparent ) );
    QPainter painter( &result );
    painter.drawPixmap( 0, 0, pixmap );
    QPoint const one( pixmap.width() + 1, pixmap.height() - 8 );
    QPoint const two( one.x() + 6, one.y() );
    QPoint const three( one.x() + 3, one.y() + 4 );
    painter.setRenderHint( QPainter::Antialiasing, true );
    painter.setPen( Qt::NoPen );
    painter.setBrush( QColor( Oxygen::aluminumGray4 ) );
    painter.drawConvexPolygon( QPolygon() << one << two << three );
    return result;
}
예제 #13
0
void GPSImageModel::slotThumbnailLoaded(const LoadingDescription& loadingDescription, const QPixmap& thumb)
{
    if (thumb.isNull())
    {
        return;
    }

    const QModelIndex currentIndex = indexFromUrl(QUrl::fromLocalFile(loadingDescription.filePath));

    if (currentIndex.isValid())
    {
        QPersistentModelIndex goodIndex(currentIndex);
        emit(signalThumbnailForIndexAvailable(goodIndex, thumb.copy(1, 1, thumb.size().width()-2, thumb.size().height()-2)));
    }
}
예제 #14
0
QPixmap * RazorDeskIconBase::initialPainting(QIcon::Mode mode)
{
    qDebug() << "RazorDeskIconBase::initialPainting";
    
    if (icon().isNull())
    {
        qDebug() << "RazorDeskIconBase::setPos - icon() is null. Skipping for now.";
        return 0;
    }
    
    QPixmap * pm = new QPixmap(70, 70);
    pm->fill(QColor(0,0,0,0));

    QPainter painter(pm);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::HighQualityAntialiasing);
    painter.setRenderHint(QPainter::NonCosmeticDefaultPen);
    
    // now the icon
    QPixmap appIcon = icon().pixmap(iconSize(), mode);
    // HACK: in some cases we can get larger icon than expected so rescale
    //       it with brute force if it's required...
    if (appIcon.size().width() > iconSize().width())
        appIcon = appIcon.scaled(iconSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation);

    QRect source(0, 0, 32, 32);
    int w = pm->width() / 2;
    int h = pm->height() / 2;
    int iw = iconSize().width() / 2;
    int ih = iconSize().height() / 2;
    QRect target(w - iw, h - ih - 10,
                 iconSize().width(), iconSize().height());
    painter.drawPixmap(target, appIcon, source);

    // text now - it has to follow potential QSS
    QColor txt = palette().color(QPalette::WindowText);
    painter.setPen(txt);
    painter.setBrush(palette().color(QPalette::Window));
    painter.drawText(QRectF(2, h+ih-10, pm->width()-4, pm->height()-h-ih+10),
                     Qt::AlignCenter | Qt::TextWordWrap | Qt::TextIncludeTrailingSpaces | Qt::TextDontClip,
                     text());
    painter.end();

    pm->setMask(pm->createHeuristicMask());
    setMask(pm->mask());
    
    return pm;
}
예제 #15
0
DialPanel::DialPanel(QWidget *parent)
    : XLet(parent)
{
    setTitle(tr("Dial"));
    setAccessibleName(tr("Dial Panel"));

    setAcceptDrops(true);

    m_input = new QComboBox(this);
    m_input->setObjectName("extension_input");
    m_input->setToolTip(tr("Input here the phone number to dial"));
    m_input->setEditable(true);
    m_input->setDuplicatesEnabled(false);
    m_input->setInsertPolicy(QComboBox::InsertAtTop);
    m_input->setMinimumContentsLength(15);
    m_input->lineEdit()->setMaxLength(30);

    m_lbl = new QLabel(tr("Enter &Number :"), this);
    m_lbl->setBuddy(m_input);

    loadHistory();
    m_input->clearEditText();

    QPixmap pmphone = QPixmap(":/images/sipphone.png");
    QPushButton * dialButton = new QPushButton(this);
    dialButton->setObjectName("dial_button");
    dialButton->setIcon(pmphone);
    dialButton->setIconSize(pmphone.size());

    QHBoxLayout * vlayout = new QHBoxLayout(this);
    vlayout->setMargin(0);
    vlayout->addStretch(1);
    vlayout->addWidget(m_lbl, 0, Qt::AlignCenter);
    vlayout->addWidget(m_input, 0, Qt::AlignCenter);
    vlayout->addWidget(dialButton, 0, Qt::AlignCenter);
    vlayout->addStretch(1);

    connect(dialButton, SIGNAL(clicked()),
            m_input->lineEdit(), SIGNAL(returnPressed()));
    connect(b_engine, SIGNAL(pasteToXlets(const QString &)),
            this, SLOT(setNumberToDial(const QString &)));
    connect(this, SIGNAL(textEdited(const QString &)),
            b_engine, SLOT(textEdited(const QString &)));
    connect(m_input->lineEdit(), SIGNAL(returnPressed()),
            this, SLOT(inputValidated()));
    connect(m_input, SIGNAL(editTextChanged(const QString &)),
            this, SIGNAL(textEdited(const QString &)));
}
예제 #16
0
파일: MontageView.cpp 프로젝트: Zitrax/peru
void MontageView::resetIcons()
{
  if( !m_dirty )
    return;

  m_dirty = false;

  // FixMe: This should be optimized by caching the old images instead
  for( QIconViewItem* item = firstItem(); item; item = item->nextItem() ) {
    QPixmap pm = *item->pixmap();
    QSize size = pm.size();
    QImage icon( item->text() );
    pm = icon.smoothScale( size );
  }

}
예제 #17
0
void tst_QPixmap::mask()
{
    QFETCH(QSize, size);

    QPixmap src = rasterPixmap(size);
    src.fill(Qt::transparent);
    {
        QPainter p(&src);
        p.drawLine(QPoint(0, 0), QPoint(src.width(), src.height()));
    }

    QBENCHMARK {
        QBitmap bitmap = src.mask();
        QVERIFY(bitmap.size() == src.size());
    }
}
예제 #18
0
/*!
  \since 5.1

  Returns a pixmap with the requested \a window \a size, \a mode, and \a
  state, generating one if necessary.

  The pixmap can be smaller than the requested size. If \a window is on
  a high-dpi display the pixmap can be larger. In that case it will have
  a devicePixelRatio larger than 1.

  \sa  actualSize(), paint()
*/
QPixmap QIcon::pixmap(QWindow *window, const QSize &size, Mode mode, State state) const
{
    if (!d)
        return QPixmap();

    qreal devicePixelRatio = qt_effective_device_pixel_ratio(window);

    // Handle the simple normal-dpi case:
    if (!(devicePixelRatio > 1.0))
        return d->engine->pixmap(size, mode, state);

    // Try get a pixmap that is big enough to be displayed at device pixel resolution.
    QPixmap pixmap = d->engine->pixmap(size * devicePixelRatio, mode, state);
    pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size()));
    return pixmap;
}
예제 #19
0
파일: widget.cpp 프로젝트: weiqifa0/sscom
void Widget::plotPic(QPrinter *printer)
{
    QDialog *myForm = myprinter;

    QPainter painter(printer);
    QPixmap image;

    image=image.grabWidget(myForm,0,0,400,300); /* 绘制窗口至画布 */
    QRect rect = painter.viewport();
    QSize size = image.size();
    size.scale(rect.size(), Qt::KeepAspectRatio);     //此处保证图片显示完整
    painter.setViewport(rect.x(), rect.y(),size.width(), size.height());
    painter.setWindow(image.rect());

    painter.drawPixmap(0,0,image); /* 数据显示至预览界面 */
}
예제 #20
0
QPixmap WebBridgeRS::getAvatarDetails(QString ssl_id){
    std::cout << "\navatar requested\n";
    if (1){//!avatars.contains(ssl_id)){
        std::cout << "not in cache\n";
        QPixmap avatar;
        AvatarDefs::getAvatarFromSslId(RsPeerId(ssl_id.toStdString()), avatar);
        //avatars.insert(ssl_id,avatar);
        std::cout << "null? " << avatar.isNull();
        std::cout << "\nwidth: " << avatar.size().width();
        std::cout << "\nadded to cache DONE\n\n";

        return avatar;
    }
    std::cout << "DONE in cache\n";
    return avatars[ssl_id];
}
예제 #21
0
void FavoriteTest::testGetImageSmall()
{
	QFile file(savePath("thumbs/tag1.png"));
	if (file.exists())
		file.remove();

	QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss");
	Favorite fav("tag1", 50, date);

	QPixmap img(QDir::currentPath() + "/tests/resources/image_1x1.png");
	fav.setImage(img);
	QPixmap actual = fav.getImage();

	QCOMPARE(actual.isNull(), false);
	QCOMPARE(actual.size(), QSize(150, 150));
}
예제 #22
0
GameButton::GameButton(QWidget * parent,
					   bool enable/* = true*/,
					   const QPixmap &enabledPixmap/* = QPixmap("images/button/enabled.png")*/,
					   const QPixmap &disabledPixmap/* = QPixmap("images/button/disabled.png")*/,
					   const QPixmap &pressedPixmap/* = QPixmap("images/button/pressed.png")*/)
	: QLabel(parent)
	, m_buttonEnabledPixmap(enabledPixmap)
	, m_buttonDisabledPixmap(disabledPixmap)
	, m_buttonPressedPixmap(pressedPixmap)
	, m_buttonEnabled(enable)
	, m_isPressed(false)
{
	setFixedSize(enabledPixmap.size());
	setFont(GUIStaticData::buttonFont);
	setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
예제 #23
0
HBITMAP QWinThumbnailToolBarPrivate::IconicPixmapCache::bitmap(const QSize &maxSize)
{
    if (m_pixmap.isNull())
        return 0;
    if (m_bitmap && m_size.width() <= maxSize.width() && m_size.height() <= maxSize.height())
        return m_bitmap;
    deleteBitmap();
    QPixmap pixmap = m_pixmap;
    if (pixmap.width() >= maxSize.width() || pixmap.height() >= maxSize.width())
        pixmap = pixmap.scaled(maxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    if (const HBITMAP bitmap = QtWin::toHBITMAP(pixmap, QtWin::HBitmapAlpha)) {
        m_size = pixmap.size();
        m_bitmap = bitmap;
    }
    return m_bitmap;
}
예제 #24
0
파일: hwmap.cpp 프로젝트: GhostAlgorithm/hw
void HWMap::onClientDisconnect()
{    
    QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128));
    linearGrad.setColorAt(1, QColor(0, 0, 192));
    linearGrad.setColorAt(0, QColor(66, 115, 225));

    if (readbuffer.size() == 128 * 32 + 1)
    {
        quint8 *buf = (quint8*) readbuffer.constData();
        QImage im(buf, 256, 128, QImage::Format_Mono);
        im.setNumColors(2);

        QPixmap px(QSize(256, 128));
        QPixmap pxres(px.size());
        QPainter p(&pxres);

        px.fill(Qt::yellow);
        QBitmap bm = QBitmap::fromImage(im);
        px.setMask(bm);

        p.fillRect(pxres.rect(), linearGrad);
        p.drawPixmap(0, 0, px);

        emit HHLimitReceived(buf[128 * 32]);
        emit ImageReceived(px);
    } else if (readbuffer.size() == 128 * 256 + 1)
    {
        QVector<QRgb> colorTable;
        colorTable.resize(256);
        for(int i = 0; i < 256; ++i)
            colorTable[i] = qRgba(255, 255, 0, i);

        const quint8 *buf = (const quint8*) readbuffer.constData();
        QImage im(buf, 256, 128, QImage::Format_Indexed8);
        im.setColorTable(colorTable);

        QPixmap px = QPixmap::fromImage(im, Qt::ColorOnly);
        QPixmap pxres(px.size());
        QPainter p(&pxres);

        p.fillRect(pxres.rect(), linearGrad);
        p.drawPixmap(0, 0, px);

        emit HHLimitReceived(buf[128 * 256]);
        emit ImageReceived(px);
    }
}
예제 #25
0
void ImageDisplayDialog::setPixmap(const QPixmap &image)
{
    if (! started)
    {
        started = true;
        myTimer.restart();
        overallTimer.restart();
        oldtitle = this->windowTitle();
        images = 0;
        cimages = 0;
    }

#ifdef RESIZEME
    QSize s = image.size();
    int maxval = 768;

    if ( s.width() > s.height())
        ui->label->setPixmap( image.scaledToWidth(maxval) );
    else
        ui->label->setPixmap (image.scaledToHeight(maxval) );
#else
    ui->label->setPixmap(image);
#endif

    images++;
    cimages++;

    if (images % 10 == 0)
    {
        QString fps;
        int time = myTimer.elapsed();
        int ctime = 1;
        if (time == 0)
            time = 1;

        if ( overallTimer.elapsed() > 2000 )
        {
            ctime = overallTimer.elapsed();
            fpsstr.sprintf("%5.2f", cimages * 1000.0 / ctime);
            cimages = 0;
            overallTimer.restart();
        }
        fps.sprintf(" - %s FPS - %d seconds running - %d images captured ", fpsstr.toStdString().c_str(), time / 1000, images);
        this->setWindowTitle(oldtitle + fps);
    }
}
예제 #26
0
QPixmap QGraphicsGlowEffect::applyEffectToPixmap(
  QPixmap src, QGraphicsEffect *effect, int extent)
{
    if (src.isNull()) return QPixmap();
    if (!effect) return src;
    QGraphicsScene scene;
    QGraphicsPixmapItem item;
    item.setPixmap(src);
    item.setGraphicsEffect(effect);
    scene.addItem(&item);
    QSize size = src.size() + QSize(extent * 2, extent * 2);
    QPixmap res(size.width(), size.height());
    res.fill(Qt::transparent);
    QPainter ptr(&res);
    scene.render(&ptr, QRectF(), QRectF(-extent, -extent, size.width(), size.height()));
    return res;
}
void VideoStackedWidget::setPixmap( QPixmap pixmap, bool newPixmap ) {
    _ui->_imageViewer->clear();

    if( newPixmap ) _origPixmap = pixmap;

    QWidget *playlistRegion = _shell->findRegion( "PlaylistRegion" )->widget();

    if( _origPixmap.width() > playlistRegion->width() || _origPixmap.height() > playlistRegion->height() ) {
        pixmap = _origPixmap.scaled( playlistRegion->width(), playlistRegion->height(), Qt::KeepAspectRatio,
                                     Qt::SmoothTransformation );
    }

    _ui->_imageViewer->setFixedSize( pixmap.size() );
    centerImageViewer();
    _ui->_imageViewer->setPixmap( pixmap );
    _isAnimationSet = false;
}
예제 #28
0
void PictureLabel::setOpacity(QPixmap &pix, qreal opacity) const
{
    if (pix.isNull() || 0 > opacity || 1 < opacity)
    {
        return;
    }

    QPixmap result(pix.size());
    result.fill(Qt::transparent);

    QPainter painter;
    painter.begin(&result);
    painter.setOpacity(opacity);
    painter.drawPixmap(0, 0, pix);
    painter.end();
    pix = result;
}
예제 #29
0
파일: gutil.cpp 프로젝트: jcome/opentoonz
QPixmap scalePixmapKeepingAspectRatio(QPixmap pixmap, QSize size,
                                      QColor color) {
  if (pixmap.isNull()) return pixmap;
  if (pixmap.devicePixelRatio() > 1.0) size *= pixmap.devicePixelRatio();
  if (pixmap.size() == size) return pixmap;
  QPixmap scaledPixmap =
      pixmap.scaled(size.width(), size.height(), Qt::KeepAspectRatio,
                    Qt::SmoothTransformation);
  QPixmap newPixmap(size);
  newPixmap.fill(color);
  QPainter painter(&newPixmap);
  painter.drawPixmap(double(size.width() - scaledPixmap.width()) * 0.5,
                     double(size.height() - scaledPixmap.height()) * 0.5,
                     scaledPixmap);
  newPixmap.setDevicePixelRatio(pixmap.devicePixelRatio());
  return newPixmap;
}
void DlgPreferencesImp::setupPages()
{
    // make sure that pages are ready to create
    GetWidgetFactorySupplier();
    for (std::list<TGroupPages>::iterator it = _pages.begin(); it != _pages.end(); ++it) {
        QTabWidget* tabWidget = new QTabWidget;
        ui->tabWidgetStack->addWidget(tabWidget);
        
        QByteArray group = it->first.c_str();
        QListWidgetItem *item = new QListWidgetItem(ui->listBox);
        item->setData(Qt::UserRole, QVariant(group));
        item->setText(QObject::tr(group.constData()));
        std::string fileName = it->first;
        for (std::string::iterator ch = fileName.begin(); ch != fileName.end(); ++ch) {
            if (*ch == ' ') *ch = '_';
            else *ch = tolower(*ch);
        }
        fileName = std::string("preferences-") + fileName;
        QPixmap icon = Gui::BitmapFactory().pixmapFromSvg(fileName.c_str(), QSize(96,96));
        if (icon.isNull()) {
            icon = Gui::BitmapFactory().pixmap(fileName.c_str());
            if (icon.isNull()) {
                qWarning() << "No group icon found for " << fileName.c_str();
            }
            else if (icon.size() != QSize(96,96)) {
                qWarning() << "Group icon for " << fileName.c_str() << " is not of size 96x96";
            }
        }
        item->setIcon(icon);
        item->setTextAlignment(Qt::AlignHCenter);
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        for (std::list<std::string>::iterator jt = it->second.begin(); jt != it->second.end(); ++jt) {
            PreferencePage* page = WidgetFactory().createPreferencePage(jt->c_str());
            if (page) {
                tabWidget->addTab(page, page->windowTitle());
                page->loadSettings();
            }
            else {
                Base::Console().Warning("%s is not a preference page\n", jt->c_str());
            }
        }
    }

    // show the first group
    ui->listBox->setCurrentRow(0);
}