Merge pull request #3172 from martinvanzijl/issue-2673-long-color-names-show-start

Always show start of name in color chips
This commit is contained in:
Rodney 2020-03-24 12:39:47 -05:00 committed by GitHub
commit 74c87f6979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -554,6 +554,27 @@ void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect,
}
}
//-----------------------------------------------------------------------------
/*! Draw the chip name \b name inside rectangle \b chipRect using painter \b p.
* If the name is too wide to fit on the chip, use left align - to show the
* start of the name. Otherwise, use center align.
*/
static void drawChipName(QPainter &p, const QRect &chipRect,
const std::wstring &name) {
const QString nameQString = QString::fromStdWString(name);
QRect textRect = p.boundingRect(chipRect, Qt::AlignCenter, nameQString);
if (chipRect.width() < textRect.width()) {
// align left if the name is too wide to fit on the chip
p.drawText(chipRect.adjusted(4, 0, -4, 0),
Qt::AlignLeft | Qt::AlignVCenter, nameQString);
}
else {
// otherwise align by center
p.drawText(chipRect, Qt::AlignCenter, nameQString);
}
}
//-----------------------------------------------------------------------------
/*! Pain current page styles using current view mode.
*/
@ -762,20 +783,19 @@ void PageViewer::paintEvent(QPaintEvent *e) {
// display the name (style name and original name) according to the name
// display mode
if (m_nameDisplayMode == Style)
p.drawText(chipRect, Qt::AlignCenter, QString::fromStdWString(name));
if (m_nameDisplayMode == Style) {
drawChipName(p, chipRect, name);
}
else if (m_nameDisplayMode == Original) {
if (origName != L"") {
tmpFont.setItalic(true);
p.setFont(tmpFont);
p.drawText(chipRect, Qt::AlignCenter,
QString::fromStdWString(origName));
drawChipName(p, chipRect, origName);
} else // if there is no original name, then display the style name
// in brackets
p.drawText(chipRect, Qt::AlignCenter,
QString::fromStdWString(L"( " + name + L" )"));
drawChipName(p, chipRect, L"( " + name + L" )");
} else if (m_nameDisplayMode == StyleAndOriginal) {
p.drawText(chipRect, Qt::AlignCenter, QString::fromStdWString(name));
drawChipName(p, chipRect, name);
// display original name only whne LargeChip view
if (m_viewMode == LargeChips && origName != L"") {