void ImportImageDlg::selectColor(const QPoint &p) { QSize trueSize(m_convertedImage.columns(), m_convertedImage.rows()); QRect pixmapRect = m_alphaSelect->pixmapRect(); delete m_alphaSelect; m_alphaSelect = nullptr; // convert p that is relative to the ScaledImageLabel to the pixmap size int x = (((p.x() - pixmapRect.left()) * trueSize.width()) / pixmapRect.width()); int y = (((p.y() - pixmapRect.top()) * trueSize.height()) / pixmapRect.height()); x = (x < 0) ? 0 : std::min(x, trueSize.width()); y = (y < 0) ? 0 : std::min(y, trueSize.height()); m_ignoreColorValue = m_convertedImage.pixelColor(x, y); QPixmap swatch(ui.ColorButton->size()); #if MAGICKCORE_QUANTUM_DEPTH == 8 swatch.fill(QColor(m_ignoreColorValue.redQuantum(), m_ignoreColorValue.greenQuantum(), m_ignoreColorValue.blueQuantum())); #else swatch.fill(QColor(m_ignoreColorValue.redQuantum() / 256, m_ignoreColorValue.greenQuantum() / 256, m_ignoreColorValue.blueQuantum() / 256)); #endif ui.ColorButton->setIcon(swatch); renderPixmap(); }
void CollectionListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.highlight()); painter->setPen(option.palette.highlightedText().color()); } QFont font = QApplication::font(); QFontMetrics fm(font); QFont subFont(font); subFont.setPointSize(font.pointSize() - 2); QFontMetrics sfm(subFont); QString headerText = index.data(CollectionItem::NameRole).toString(); QString subText = index.data(CollectionItem::SizeTextRole).toString() + " | " + \ "subdir: " + index.data(CollectionItem::SubdirTextRole).toString(); QSize trueSize(trueSizeHint(option, index)); QSize size(sizeHint(option, index)); if (trueSize.width() != size.width()) { int n = 0; if (fm.width(headerText) > size.width()) { for (n = headerText.size(); fm.width(QString(headerText.left(n) + "...")) > option.rect.width(); n--); headerText = headerText.left(n) + "..."; } } QTextOption textOption(Qt::AlignHCenter); QRect basicRect = option.rect; if (option.rect.width() > collectionListView->width()) { if (size.width() <= collectionListView->width()) { basicRect.setLeft(0); basicRect.setRight(collectionListView->width()); } } QRect headerRect = basicRect; headerRect.setTop(headerRect.top()+5); headerRect.setBottom(headerRect.top()+fm.height()); QRect subRect = basicRect; subRect.setTop(headerRect.bottom()); subRect.setBottom(subRect.top() + sfm.height()); painter->setFont(font); painter->drawText(headerRect,headerText, textOption); painter->setFont(subFont); painter->drawText(subRect,subText, textOption); painter->restore(); }