Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add account window text clipping, enlarge text #4910

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions src/gui/wizard/slideshow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <QStyle>
#include <QStyleHints>

#define HASQT5_11 (QT_VERSION >= QT_VERSION_CHECK(5,11,0))

namespace OCC {

static const int Spacing = 6;
Expand All @@ -30,6 +28,7 @@ static const int SlideDistance = 400;
SlideShow::SlideShow(QWidget *parent) : QWidget(parent)
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setStyleSheet(QStringLiteral("font: bold 18pt"));
}

void SlideShow::addSlide(const QPixmap &pixmap, const QString &label)
Expand Down Expand Up @@ -87,20 +86,20 @@ void SlideShow::setCurrentSlide(int index)

QSize SlideShow::sizeHint() const
{
QFontMetrics fm = fontMetrics();
QSize labelSize(0, fm.height());
for (const QString &label : _labels) {
#if (HASQT5_11)
labelSize.setWidth(std::max(fm.horizontalAdvance(label), labelSize.width()));
#else
labelSize.setWidth(std::max(fm.width(label), labelSize.width()));
#endif
const auto fm = fontMetrics();
QSize labelSize;
for (const auto &label : _labels) {
const auto labelBoundingRect = fm.boundingRect(rect(), Qt::TextWordWrap, label);
labelSize.setWidth(std::max(labelBoundingRect.width(), labelSize.width()));
labelSize.setHeight(std::max(labelBoundingRect.height(), labelSize.height()));
}

QSize pixmapSize;
for (const QPixmap &pixmap : _pixmaps) {
for (const auto &pixmap : _pixmaps) {
pixmapSize.setWidth(std::max(pixmap.width(), pixmapSize.width()));
pixmapSize.setHeight(std::max(pixmap.height(), pixmapSize.height()));
}

return {
std::max(labelSize.width(), pixmapSize.width()),
labelSize.height() + Spacing + pixmapSize.height()
Expand Down Expand Up @@ -189,14 +188,29 @@ void SlideShow::maybeRestartTimer()
}

void SlideShow::drawSlide(QPainter *painter, int index)
{
QString label = _labels.value(index);
QRect labelRect = style()->itemTextRect(fontMetrics(), rect(), Qt::AlignBottom | Qt::AlignHCenter, isEnabled(), label);
style()->drawItemText(painter, labelRect, Qt::AlignCenter, palette(), isEnabled(), label, QPalette::WindowText);

QPixmap pixmap = _pixmaps.value(index);
QRect pixmapRect = style()->itemPixmapRect(QRect(0, 0, width(), labelRect.top() - Spacing), Qt::AlignCenter, pixmap);
style()->drawItemPixmap(painter, pixmapRect, Qt::AlignCenter, pixmap);
{
const auto label = _labels.value(index);
const auto labelRect = style()->itemTextRect(fontMetrics(),
rect(),
Qt::AlignBottom | Qt::AlignHCenter | Qt::TextWordWrap,
isEnabled(),
label);
style()->drawItemText(painter,
labelRect,
Qt::AlignCenter | Qt::TextWordWrap,
palette(),
isEnabled(),
label,
QPalette::WindowText);

const auto pixmap = _pixmaps.value(index);
const auto pixmapRect = style()->itemPixmapRect(QRect(0, 0, width(), labelRect.top() - Spacing),
Qt::AlignCenter,
pixmap);
style()->drawItemPixmap(painter,
pixmapRect,
Qt::AlignCenter,
pixmap);
}

} // namespace OCC