Index: scribus/ui/pagepalette_widgets.h =================================================================== --- scribus/ui/pagepalette_widgets.h (after ARP1 v1.05) +++ scribus/ui/pagepalette_widgets.h (working copy) @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -209,7 +210,12 @@ int rowContentWidth(int rowId); int rowWidth(int rowId); int rowStartX(int rowId); + QRect rowSpreadRect(int row); QRect rectAt(int row, int col); + QRect masterLabelRect(int row, int col); + bool usesExternalMasterLabels() const; + QFont masterNameFont(bool inThumbnail) const; + QString elidedMasterName(const QString& name, int width) const; QSize dummyPageSize(); @@ -230,6 +236,7 @@ protected: + bool event(QEvent *event) override; void paintEvent(QPaintEvent *event) override; void resizeEvent(QResizeEvent *event) override; Index: scribus/ui/pagepalette_widgets.cpp =================================================================== --- scribus/ui/pagepalette_widgets.cpp (after ARP1 v1.05) +++ scribus/ui/pagepalette_widgets.cpp (working copy) @@ -11,7 +11,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -19,6 +21,7 @@ #include #include #include +#include #include #include "iconmanager.h" @@ -555,6 +558,88 @@ } +QRect PageGrid::rowSpreadRect(int row) +{ + if (m_pageLayout != PageLayout::doublePage || row < 0 || row >= rows()) + return QRect(); + + const int contentWidth = rowContentWidth(row); + if (contentWidth <= 0) + return QRect(); + + return QRect(rowStartX(row), + m_rowSpace + row * (rowHeight() + m_rowSpace), + contentWidth, pageHeight()); +} + +QRect PageGrid::masterLabelRect(int row, int col) +{ + if (!usesExternalMasterLabels() || row < 0 || row >= rows() || col < 0 || col >= columns()) + return QRect(); + + const int styleGap = style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr, this); + const int masterLabelGap = styleGap >= 0 ? styleGap : m_labelGap; + int left = 0; + int right = 0; + int top = m_rowSpace + row * (rowHeight() + m_rowSpace); + + if (m_pageLayout == PageLayout::singlePage) + { + QRect pageRect = rectAt(row, col); + if (pageRect.isEmpty()) + return QRect(); + + left = pageRect.right() + 1 + masterLabelGap; + right = width() - m_groupSpace - 1; + top = pageRect.top(); + } + else + { + const QRect spreadRect = rowSpreadRect(row); + if (spreadRect.isEmpty()) + return QRect(); + + top = spreadRect.top(); + if (col == 0) + { + left = m_groupSpace; + right = spreadRect.left() - masterLabelGap - 1; + } + else + { + left = spreadRect.right() + 1 + masterLabelGap; + right = width() - m_groupSpace - 1; + } + } + + const int availableWidth = right - left + 1; + if (availableWidth <= 0) + return QRect(); + + return QRect(left, top, availableWidth, pageHeight()); +} + +bool PageGrid::usesExternalMasterLabels() const +{ + return m_rowHeight != TileSize::Large + && (m_pageLayout == PageLayout::singlePage || m_pageLayout == PageLayout::doublePage); +} + +QFont PageGrid::masterNameFont(bool inThumbnail) const +{ + QFont masterFont(font()); + masterFont.setPointSizeF(inThumbnail ? m_fontSize * 0.75 : m_fontSize); + return masterFont; +} + +QString PageGrid::elidedMasterName(const QString& name, int width) const +{ + if (width <= 0) + return QString(); + + return QFontMetrics(masterNameFont(false)).elidedText(name, Qt::ElideRight, width); +} + QSize PageGrid::dummyPageSize() { double ratio = m_documentPageSize.width() / m_documentPageSize.height(); @@ -726,22 +811,11 @@ if (tile == nullptr) return; - QFont font(this->font().family(), m_fontSize, QFont::Normal); - QFont fontName(this->font().family(), m_fontSize * 0.8, QFont::Normal); + QFont font(this->font()); + font.setPointSize(m_fontSize); QRect rectPage(cellPosition.x(), cellPosition.y(), tile->pageWidthByHeight(pageHeight()), pageHeight()); QRect rectCell(cellPosition.x(), cellPosition.y(), tile->pageWidthByHeight(pageHeight()), m_rowHeight); - QString pageName = tile->pageName; - int pageNameHyphen = tile->pageName.indexOf("-"); - // Fail fast if no hyphen or nothing to the left of it - if (pageNameHyphen > 0) - { - // Trim whitespace and ensure at least 1-4 chars or ignore it - QString tmp = tile->pageName.left(pageNameHyphen).trimmed(); - if (tmp.length() > 0 && tmp.length() < 5) - pageName = tmp; - } - painter.save(); // Draw Page @@ -756,32 +830,46 @@ painter.setFont(font); // Draw Page Number - painter.setPen(QPen( labelColor )); - painter.drawText(rectCell, Qt::AlignHCenter|Qt::AlignBottom | Qt::TextWordWrap, tile->pageNumberDisplay); + painter.setPen(QPen(labelColor)); + painter.drawText(rectCell, Qt::AlignHCenter | Qt::AlignBottom | Qt::TextWordWrap, tile->pageNumberDisplay); - // Draw Page Name - painter.setFont((pageNameHyphen > 0) ? font : fontName); - if (m_rowHeight == TileSize::Small) - { - painter.setPen(Qt::black); - painter.drawText(rectPage.adjusted(1, 1, 0, 0), Qt::AlignVCenter | Qt::AlignCenter |Qt::TextWordWrap, pageName); - } - else - { - painter.setBackgroundMode(Qt::OpaqueMode); - painter.setBackground(QColor(102, 102, 102)); - painter.setPen(Qt::white); - painter.drawText(rectPage.adjusted(1, 1, 0, 0), Qt::AlignTop | ((isRight) ? Qt::AlignRight : Qt::AlignLeft) |Qt::TextWordWrap, pageName); - } + const bool supportedPageLayout = m_pageLayout == PageLayout::singlePage || m_pageLayout == PageLayout::doublePage; + const bool drawMasterNameInPage = m_rowHeight == TileSize::Large || !supportedPageLayout; + if (drawMasterNameInPage) + { + QString pageName = tile->pageName; + int pageNameHyphen = tile->pageName.indexOf("-"); + if (pageNameHyphen > 0) + { + QString tmp = tile->pageName.left(pageNameHyphen).trimmed(); + if (tmp.length() > 0 && tmp.length() < 5) + pageName = tmp; + } + // Small/Medium single- and facing-page previews use external labels. + // Large previews reuse Scribus' established in-thumbnail treatment. + if (supportedPageLayout) + painter.setFont(masterNameFont(true)); + else + { + QFont fontName(font); + fontName.setPointSizeF(m_fontSize * 0.8); + painter.setFont((pageNameHyphen > 0) ? font : fontName); + } - // Draw selection - // if(selected) - // { - // painter.setBrush(Qt::NoBrush); - // painter.setPen( QPen(m_colorSelection, 2) ); - // painter.drawRect(rectPage); - // } + if (m_rowHeight == TileSize::Small) + { + painter.setPen(Qt::black); + painter.drawText(rectPage.adjusted(1, 1, 0, 0), Qt::AlignVCenter | Qt::AlignCenter | Qt::TextWordWrap, pageName); + } + else + { + painter.setBackgroundMode(Qt::OpaqueMode); + painter.setBackground(QColor(102, 102, 102)); + painter.setPen(Qt::white); + painter.drawText(rectPage.adjusted(1, 1, 0, 0), Qt::AlignTop | ((isRight) ? Qt::AlignRight : Qt::AlignLeft) | Qt::TextWordWrap, pageName); + } + } // Draw hover if (hovered) @@ -790,7 +878,7 @@ colHover.setAlphaF(0.5); painter.setBackgroundMode(Qt::TransparentMode); painter.setBrush(colHover); - painter.setPen( Qt::NoPen ); + painter.setPen(Qt::NoPen); painter.drawRect(rectPage); } @@ -834,17 +922,72 @@ * * ********************************************************************************* */ +bool PageGrid::event(QEvent *event) +{ + if (event->type() == QEvent::ToolTip && pageCount() > 0 + && (m_pageLayout == PageLayout::singlePage || m_pageLayout == PageLayout::doublePage)) + { + QHelpEvent *helpEvent = static_cast(event); + const QPoint pos = helpEvent->pos(); + const int row = rowAt(pos); + + if (row >= 0) + { + for (int col = 0; col < columns(); ++col) + { + const int id = pageId(row, col, false); + if (!pageInRange(id)) + continue; + + PageCell *cell = getPageItem(id); + if (cell == nullptr) + continue; + + QRect pageRect = rectAt(row, col); + pageRect.setHeight(pageHeight()); + if (pageRect.contains(pos)) + { + QToolTip::showText(helpEvent->globalPos(), + tr("Page %1\nMaster page: %2").arg(cell->pageNumberDisplay, cell->pageName), + this, pageRect); + return true; + } + + const QRect labelRect = masterLabelRect(row, col); + if (!labelRect.isEmpty() && labelRect.contains(pos)) + { + const QString elidedName = elidedMasterName(cell->pageName, labelRect.width()); + if (!elidedName.isEmpty() && elidedName != cell->pageName) + { + QToolTip::showText(helpEvent->globalPos(), tr("Master page: %1").arg(cell->pageName), this, labelRect); + return true; + } + } + } + } + + QToolTip::hideText(); + event->ignore(); + return true; + } + + return QWidget::event(event); +} + void PageGrid::paintEvent(QPaintEvent *event) { int y = m_rowSpace; int offset = 0; QRect selectedPageRect; - QColor foregroundColor( PrefsManager::instance().appPrefs.displayPrefs.scratchColor.lightness() <= 128 ? Qt::white : Qt::black); + const QColor scratchColor = PrefsManager::instance().appPrefs.displayPrefs.scratchColor; + const QColor foregroundColor = scratchColor.lightness() <= 128 + ? palette().color(QPalette::BrightText) + : palette().color(QPalette::WindowText); QPainter painter(this); // Draw background - painter.fillRect(rect(), PrefsManager::instance().appPrefs.displayPrefs.scratchColor); + painter.fillRect(rect(), scratchColor); if (pageCount() == 0) return; @@ -910,6 +1053,41 @@ } } + if (usesExternalMasterLabels()) + { + painter.save(); + painter.setFont(masterNameFont(false)); + painter.setPen(QPen(foregroundColor)); + painter.setRenderHint(QPainter::TextAntialiasing, true); + + for (int c = 0; c < columns(); ++c) + { + const int id = pageId(r, c, false); + if (!pageInRange(id)) + continue; + + PageCell *cell = getPageItem(id); + const QRect labelRect = masterLabelRect(r, c); + if (cell == nullptr || labelRect.isEmpty()) + continue; + + const QString label = elidedMasterName(cell->pageName, labelRect.width()); + if (label.isEmpty()) + continue; + + Qt::Alignment alignment = Qt::AlignVCenter | Qt::AlignLeft; + if (m_pageLayout == PageLayout::doublePage && c == 0) + alignment = Qt::AlignVCenter | Qt::AlignRight; + + painter.save(); + painter.setClipRect(labelRect); + painter.drawText(labelRect, alignment | Qt::TextSingleLine, label); + painter.restore(); + } + + painter.restore(); + } + // Draw group border if (drawGroupRect) painter.drawRect( QRect(groupStart, y, groupWidth, pageHeight()) );