void MetaQueryWidget::makeRatingSelection() { KRatingWidget* ratingWidget = new KRatingWidget(); ratingWidget->setRating( (int)m_filter.numValue ); connect( ratingWidget, SIGNAL(ratingChanged(int)), this, SLOT( numValueChanged(int) ) ); m_valueSelection1 = ratingWidget; if( m_filter.condition != Between ) return; // second KRatingWidget for the between selection KRatingWidget* ratingWidget2 = new KRatingWidget(); ratingWidget2->setRating( (int)m_filter.numValue2 ); connect( ratingWidget2, SIGNAL(ratingChanged(int)), this, SLOT(numValue2Changed(int)) ); m_valueSelection2 = ratingWidget2; }
void InlineEditorWidget::createChildWidgets() { QBoxLayout* boxLayout = qobject_cast<QBoxLayout*>( layout() ); Q_ASSERT( boxLayout ); boxLayout->setSpacing( 0 ); //For now, we don't allow editing of the "head" data, just the body LayoutItemConfig config = m_layout.layoutForItem( m_index ); const int rowCount = config.rows(); if( rowCount == 0 ) return; // we have to use the same metrics as the PrettyItemDelegate or else // the widgets will change places when editing const int horizontalSpace = style()->pixelMetric( QStyle::PM_LayoutHorizontalSpacing ); const int frameHMargin = style()->pixelMetric( QStyle::PM_FocusFrameHMargin ); const int frameVMargin = style()->pixelMetric( QStyle::PM_FocusFrameVMargin ); int rowOffsetX = frameHMargin; // keep the text a little bit away from the border const int coverHeight = m_widgetHeight - frameVMargin * 2; const bool showCover = config.showCover(); if( showCover ) rowOffsetX += coverHeight + horizontalSpace/* + frameHMargin * 2*/; const int contentHeight = m_widgetHeight - frameVMargin * 2; int rowHeight = contentHeight / rowCount; const int rowWidth = m_widgetWidth - rowOffsetX - frameHMargin * 2; if( showCover ) { QModelIndex coverIndex = m_index.model()->index( m_index.row(), CoverImage ); QPixmap albumPixmap = coverIndex.data( Qt::DisplayRole ).value<QPixmap>(); if( !albumPixmap.isNull() ) { if( albumPixmap.width() > albumPixmap.height() ) albumPixmap = albumPixmap.scaledToWidth( coverHeight ); else albumPixmap = albumPixmap.scaledToHeight( coverHeight ); QLabel *coverLabel = new QLabel( this ); coverLabel->setPixmap( albumPixmap ); if( albumPixmap.width() < coverHeight ) coverLabel->setContentsMargins( ( coverHeight - albumPixmap.width() ) / 2, 0, ( coverHeight - albumPixmap.width() + 1 ) / 2, 0 ); boxLayout->setStretchFactor( coverLabel, 0 ); boxLayout->addSpacing( horizontalSpace ); } } KVBox *rowsWidget = new KVBox( this ); // --- paint all the rows for( int i = 0; i < rowCount; i++ ) { LayoutItemConfigRow row = config.row( i ); const int elementCount = row.count(); QSplitter *rowWidget = new QSplitter( rowsWidget ); connect( rowWidget, SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int,int)) ); m_splitterRowMap.insert( rowWidget, i ); //we need to do a quick pass to figure out how much space is left for auto sizing elements qreal spareSpace = 1.0; int autoSizeElemCount = 0; for( int k = 0; k < elementCount; ++k ) { spareSpace -= row.element( k ).size(); if( row.element( k ).size() < 0.001 ) autoSizeElemCount++; } const qreal spacePerAutoSizeElem = spareSpace / (qreal)autoSizeElemCount; //give left over pixels to the first rows. Widgets are doing it the same. if( i == 0 ) rowHeight++; if( i == ( contentHeight % rowCount ) ) rowHeight--; QList<int> itemWidths; int currentItemX = 0; for( int j = 0; j < elementCount; ++j ) { LayoutItemConfigRowElement element = row.element( j ); // -- calculate the size qreal size; if( element.size() < 0.001 ) size = spacePerAutoSizeElem; else size = element.size(); int itemWidth; if( j == elementCount - 1 ) // use the full with for the last item itemWidth = rowWidth - currentItemX; else itemWidth = rowWidth * size; itemWidths.append( itemWidth ); int value = element.value(); QModelIndex textIndex = m_index.model()->index( m_index.row(), value ); QString text = textIndex.data( Qt::DisplayRole ).toString(); m_orgValues.insert( value, text ); QWidget *widget = 0; //special case for painting the rating... if( value == Rating ) { int rating = textIndex.data( Qt::DisplayRole ).toInt(); KRatingWidget* ratingWidget = new KRatingWidget( 0 ); ratingWidget->setAlignment( element.alignment() ); ratingWidget->setRating( rating ); ratingWidget->setAttribute( Qt::WA_NoMousePropagation, true ); connect( ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingValueChanged()) ); m_editorRoleMap.insert( ratingWidget, value ); widget = ratingWidget; } else if( value == Divider ) { QPixmap left = The::svgHandler()->renderSvg( "divider_left", 1, rowHeight, "divider_left" ); QPixmap right = The::svgHandler()->renderSvg( "divider_right", 1, rowHeight, "divider_right" ); QPixmap dividerPixmap( 2, rowHeight ); dividerPixmap.fill( Qt::transparent ); QPainter painter( ÷rPixmap ); painter.drawPixmap( 0, 0, left ); painter.drawPixmap( 1, 0, right ); QLabel* dividerLabel = new QLabel( 0 ); dividerLabel->setPixmap( dividerPixmap ); dividerLabel->setAlignment( element.alignment() ); widget = dividerLabel; } else if( value == Moodbar ) { //we cannot ask the model for the moodbar directly as we have no //way of asking for a specific size. Instead just get the track from //the model and ask the moodbar manager ourselves. Meta::TrackPtr track = m_index.data( TrackRole ).value<Meta::TrackPtr>(); QLabel* moodbarLabel = new QLabel( 0 ); moodbarLabel->setScaledContents( true ); if( The::moodbarManager()->hasMoodbar( track ) ) { QPixmap moodbar = The::moodbarManager()->getMoodbar( track, itemWidth, rowHeight - 8 ); moodbarLabel->setPixmap( moodbar ); } widget = moodbarLabel; } //actual playlist item text is drawn here else { QLineEdit * edit = new QLineEdit( text, 0 ); edit->setFrame( false ); edit->setAlignment( element.alignment() ); edit->installEventFilter(this); // -- set font bool bold = element.bold(); bool italic = element.italic(); bool underline = element.underline(); QFont font = edit->font(); font.setBold( bold ); font.setItalic( italic ); font.setUnderline( underline ); edit->setFont( font ); connect( edit, SIGNAL(editingFinished()), this, SLOT(editValueChanged()) ); //check if this is a column that is editable. If not, make the //line edit read only. if( !isEditableColumn( static_cast<Playlist::Column>(value) ) ) { edit->setReadOnly( true ); edit->setDisabled( true ); } m_editorRoleMap.insert( edit, value ); widget = edit; } widget->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ); // or else the widget size hint influences the space it get's which messes up the layout rowWidget->addWidget( widget ); // handles are nice, but if we don't compensate for their sizes the layout // would be different from the item delegate if( j > 0 ) widget->setContentsMargins( -( ( rowWidget->handleWidth() + 1 ) / 2 ), 0, 0, 0 ); if( j < elementCount - 1 ) widget->setContentsMargins( 0, 0, -( rowWidget->handleWidth() / 2 ), 0 ); currentItemX += itemWidth; } rowWidget->setSizes( itemWidths ); } }