Use the height - 3 lines of text to make also very high pixmaps fit
This commit is contained in:
		
					parent
					
						
							
								e787a35330
							
						
					
				
			
			
				commit
				
					
						834bdfd82d
					
				
			
		
					 1 changed files with 20 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -75,6 +75,8 @@ namespace Danbooru {
 | 
			
		|||
 | 
			
		||||
        m_downloadButton->resize(m_buttonSize, m_buttonSize);
 | 
			
		||||
        m_viewButton->resize(m_buttonSize, m_buttonSize);
 | 
			
		||||
        m_downloadButton->setToolTip(i18n("Download image"));
 | 
			
		||||
        m_viewButton->setToolTip(i18n("View image"));
 | 
			
		||||
 | 
			
		||||
        // Signal-slot connections
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -98,11 +100,9 @@ namespace Danbooru {
 | 
			
		|||
 | 
			
		||||
        // Pixmap
 | 
			
		||||
 | 
			
		||||
        painter->save();
 | 
			
		||||
 | 
			
		||||
        QStyle *style = QApplication::style();
 | 
			
		||||
 | 
			
		||||
        style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0);
 | 
			
		||||
        style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0);
 | 
			
		||||
        painter->setRenderHint(QPainter::Antialiasing);
 | 
			
		||||
 | 
			
		||||
        QPixmap pixmap = index.data(Qt::DecorationRole).value<QPixmap>();
 | 
			
		||||
| 
						 | 
				
			
			@ -111,17 +111,22 @@ namespace Danbooru {
 | 
			
		|||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        QRect rect = option.rect;
 | 
			
		||||
        QFontMetrics metrics = option.fontMetrics;
 | 
			
		||||
        QRect rect = opt.rect;
 | 
			
		||||
        QFontMetrics metrics = opt.fontMetrics;
 | 
			
		||||
        QRect textRect(rect.left() + MARGIN, rect.bottom() - 3 * metrics.height(),
 | 
			
		||||
                       rect.width(), 3 * metrics.height());
 | 
			
		||||
 | 
			
		||||
        // Scaling is unavoidable to keep things in the right dimension
 | 
			
		||||
 | 
			
		||||
        QPixmap scaled = pixmap.scaled(rect.width() - MARGIN, rect.height() - MARGIN,
 | 
			
		||||
        QPixmap scaled;
 | 
			
		||||
        int maxHeight = rect.height() - 3 * metrics.height() - 2 * MARGIN;
 | 
			
		||||
 | 
			
		||||
        scaled = pixmap.scaled(rect.width() - 2 * MARGIN,
 | 
			
		||||
                               maxHeight,
 | 
			
		||||
                               Qt::KeepAspectRatio,
 | 
			
		||||
                               Qt::SmoothTransformation);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        QRect pixRect = scaled.rect();
 | 
			
		||||
        pixRect.moveCenter(rect.center());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -132,7 +137,6 @@ namespace Danbooru {
 | 
			
		|||
        pixRect.moveBottom(textRect.top() - MARGIN);
 | 
			
		||||
 | 
			
		||||
        painter->drawPixmap(pixRect, scaled);
 | 
			
		||||
        painter->restore();
 | 
			
		||||
 | 
			
		||||
        // Buttons
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -204,9 +208,15 @@ namespace Danbooru {
 | 
			
		|||
    QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option,
 | 
			
		||||
                                         const QModelIndex& index) const
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        Q_UNUSED(option)
 | 
			
		||||
        Q_UNUSED(index)
 | 
			
		||||
 | 
			
		||||
        if (!index.isValid()) {
 | 
			
		||||
            return QSize();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return m_itemView->gridSize();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QModelIndex DanbooruPostDelegate::hoveredIndex() const
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue