void SimpleTableOfContentsWidget::prepareTemplateMenu() { m_previewGenerator.clear(); if (m_signalMapper) { delete m_signalMapper; m_signalMapper = 0; } qDeleteAll(m_templateList.begin(), m_templateList.end()); m_templateList.clear(); m_signalMapper = new QSignalMapper(); m_templateList = m_templateGenerator->templates(); connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(pixmapReady(int))); int index = 0; foreach (KoTableOfContentsGeneratorInfo *info, m_templateList) { TableOfContentsPreview *preview = new TableOfContentsPreview(); preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); preview->setPreviewSize(QSize(200,120)); preview->updatePreview(info); connect(preview, SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); m_signalMapper->setMapping(preview, index); m_previewGenerator.append(preview); ++index; //put dummy pixmaps until the actual pixmap previews are generated and added in pixmapReady() if (! widget.addToC->hasItemId(index)) { QPixmap pmm(QSize(200,120)); pmm.fill(Qt::white); widget.addToC->addItem(pmm, index); } }
void qDrawItem( QPainter *p, Qt::GUIStyle gs, int x, int y, int w, int h, int flags, const QColorGroup &g, bool enabled, const QPixmap *pixmap, const QString& text, int len , const QColor* penColor ) { p->setPen( penColor?*penColor:g.foreground() ); if ( pixmap ) { QPixmap pm( *pixmap ); bool clip = (flags & Qt::DontClip) == 0; if ( clip ) { if ( pm.width() < w && pm.height() < h ) clip = FALSE; else p->setClipRect( x, y, w, h ); } if ( (flags & Qt::AlignVCenter) == Qt::AlignVCenter ) y += h/2 - pm.height()/2; else if ( (flags & Qt::AlignBottom) == Qt::AlignBottom) y += h - pm.height(); if ( (flags & Qt::AlignRight) == Qt::AlignRight ) x += w - pm.width(); else if ( (flags & Qt::AlignHCenter) == Qt::AlignHCenter ) x += w/2 - pm.width()/2; else if ( ((flags & Qt::AlignLeft) != Qt::AlignLeft) && QApplication::reverseLayout() ) // AlignAuto && rightToLeft x += w - pm.width(); if ( !enabled ) { if ( pm.mask() ) { // pixmap with a mask if ( !pm.selfMask() ) { // mask is not pixmap itself QPixmap pmm( *pm.mask() ); pmm.setMask( *((QBitmap *)&pmm) ); pm = pmm; } } else if ( pm.depth() == 1 ) { // monochrome pixmap, no mask pm.setMask( *((QBitmap *)&pm) ); #ifndef QT_NO_IMAGE_HEURISTIC_MASK } else { // color pixmap, no mask QString k; k.sprintf( "$qt-drawitem-%x", pm.serialNumber() ); QPixmap *mask = QPixmapCache::find(k); bool del=FALSE; if ( !mask ) { mask = new QPixmap( pm.createHeuristicMask() ); mask->setMask( *((QBitmap*)mask) ); del = !QPixmapCache::insert( k, mask ); } pm = *mask; if (del) delete mask; #endif } if ( gs == Qt::WindowsStyle ) { p->setPen( g.light() ); p->drawPixmap( x+1, y+1, pm ); p->setPen( g.text() ); } } p->drawPixmap( x, y, pm ); if ( clip ) p->setClipping( FALSE ); } else if ( !text.isNull() ) { if ( gs == Qt::WindowsStyle && !enabled ) { p->setPen( g.light() ); p->drawText( x+1, y+1, w, h, flags, text, len ); p->setPen( g.text() ); } p->drawText( x, y, w, h, flags, text, len ); } }