Skip to content

Commit

Permalink
Fix add account text clipping, enlarge text
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
  • Loading branch information
claucambra authored and backportbot-nextcloud[bot] committed Sep 10, 2022
1 parent 1be339b commit 093ddbe
Showing 1 changed file with 33 additions and 19 deletions.
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

0 comments on commit 093ddbe

Please sign in to comment.