Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ target_sources(${PROJECT_NAME} PRIVATE
UBThumbnailArranger.h
UBThumbnailScene.cpp
UBThumbnailScene.h
UBThumbnailTextItem.cpp
UBThumbnailTextItem.h
UBThumbnailsView.cpp
UBThumbnailsView.h
UBDocumentThumbnailsView.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/gui/UBDocumentThumbnailsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ double UBDocumentThumbnailsView::UBDocumentThumbnailArranger::thumbnailWidth() c
return mThumbnailWidth;
}

bool UBDocumentThumbnailsView::UBDocumentThumbnailArranger::isUIEnabled() const
{
return false;
}

void UBDocumentThumbnailsView::UBDocumentThumbnailArranger::setThumbnailWidth(int width)
{
mThumbnailWidth = width;
Expand Down
68 changes: 1 addition & 67 deletions src/gui/UBDocumentThumbnailsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class UBDocumentThumbnailsView : public UBThumbnailsView

virtual int columnCount() const override;
virtual double thumbnailWidth() const override;
virtual bool isUIEnabled() const override;

private:
void setThumbnailWidth(int width);
Expand All @@ -136,71 +137,4 @@ class UBDocumentThumbnailsView : public UBThumbnailsView
};


class UBThumbnailTextItem : public QGraphicsTextItem
{
Q_OBJECT

public:
UBThumbnailTextItem()
: QGraphicsTextItem()
{
}

UBThumbnailTextItem(int index)
: QGraphicsTextItem()
, mUnelidedText(toPlainText())
{
setPageNumber(index + 1);
}

UBThumbnailTextItem(const QString& text)
: QGraphicsTextItem(text)
, mUnelidedText(text)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}

QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}

void setWidth(qreal pWidth)
{
if (mWidth != pWidth)
{
prepareGeometryChange();
mWidth = pWidth;
computeText();

// center text
setTextWidth(mWidth);
document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
}
}

qreal width() {return mWidth;}

void setPageNumber(int i)
{
mUnelidedText = tr("Page %0").arg(i);
computeText();
}

void setText(const QString& text)
{
mUnelidedText = text;
computeText();
}

void computeText()
{
QFontMetricsF fm(font());
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideLeft, mWidth - 2 * document()->documentMargin() - 1);
setPlainText(elidedText);
}

private:
qreal mWidth{0};
QString mUnelidedText{};
};


#endif /* UBDOCUMENTTHUMBNAILSVIEW_H_ */
19 changes: 4 additions & 15 deletions src/gui/UBThumbnail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include "board/UBDrawingController.h"
#include "document/UBDocument.h"
#include "domain/UBGraphicsScene.h"
#include "gui/UBBoardThumbnailsView.h"
#include "gui/UBDocumentThumbnailsView.h"
#include "gui/UBThumbnailArranger.h"
#include "gui/UBThumbnailScene.h"
#include "gui/UBThumbnailTextItem.h"


constexpr int cSelectionWidth{8};
Expand Down Expand Up @@ -252,20 +252,9 @@ void UBThumbnail::hoverEnterEvent(QGraphicsSceneHoverEvent* event)

if (thumbnailScene)
{
for (const auto view : thumbnailScene->views())
{
if (view->isVisible())
{
bool isBoardThumbnailsView = dynamic_cast<UBBoardThumbnailsView*>(view) != nullptr;

if (isBoardThumbnailsView)
{
mEditable = true;
break;
}
}
}
mEditable = thumbnailScene->currentThumbnailArranger()->isUIEnabled();
}

QGraphicsRectItem::hoverEnterEvent(event);
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/UBThumbnailArranger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ QSizeF UBThumbnailArranger::spacing() const
const double spacing = UBSettings::thumbnailSpacing;
return {spacing, spacing};
}

bool UBThumbnailArranger::isUIEnabled() const
{
return true;
}
1 change: 1 addition & 0 deletions src/gui/UBThumbnailArranger.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class UBThumbnailArranger
virtual double availableViewWidth() const;
virtual QMarginsF margins() const;
virtual QSizeF spacing() const;
virtual bool isUIEnabled() const;

private:
UBThumbnailsView* mThumbnailView{nullptr};
Expand Down
89 changes: 89 additions & 0 deletions src/gui/UBThumbnailTextItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2015-2025 Département de l'Instruction Publique (DIP-SEM)
*
* This file is part of OpenBoard.
*
* OpenBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/


#include "UBThumbnailTextItem.h"

#include <QFontMetricsF>
#include <QTextDocument>
#include <QTextOption>

UBThumbnailTextItem::UBThumbnailTextItem()
: QGraphicsTextItem()
{
}

UBThumbnailTextItem::UBThumbnailTextItem(int index)
: QGraphicsTextItem()
, mUnelidedText(toPlainText())
{
setPageNumber(index + 1);
}

UBThumbnailTextItem::UBThumbnailTextItem(const QString& text)
: QGraphicsTextItem(text)
, mUnelidedText(text)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}

QRectF UBThumbnailTextItem::boundingRect() const
{
return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));
}

void UBThumbnailTextItem::setWidth(qreal pWidth)
{
if (mWidth != pWidth)
{
prepareGeometryChange();
mWidth = pWidth;
computeText();

// center text
setTextWidth(mWidth);
document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
}
}

qreal UBThumbnailTextItem::width()
{
return mWidth;
}

void UBThumbnailTextItem::setPageNumber(int i)
{
mUnelidedText = tr("Page %0").arg(i);
computeText();
}

void UBThumbnailTextItem::setText(const QString& text)
{
mUnelidedText = text;
computeText();
}

void UBThumbnailTextItem::computeText()
{
QFontMetricsF fm(font());
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideLeft, mWidth - 2 * document()->documentMargin() - 1);
setPlainText(elidedText);
}
48 changes: 48 additions & 0 deletions src/gui/UBThumbnailTextItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2015-2025 Département de l'Instruction Publique (DIP-SEM)
*
* This file is part of OpenBoard.
*
* OpenBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/


#pragma once

#include <QGraphicsTextItem>

class UBThumbnailTextItem : public QGraphicsTextItem
{
Q_OBJECT

public:
UBThumbnailTextItem();
UBThumbnailTextItem(int index);
UBThumbnailTextItem(const QString& text);

QRectF boundingRect() const;

void setWidth(qreal pWidth);
qreal width();

void setPageNumber(int i);
void setText(const QString& text);
void computeText();

private:
qreal mWidth{0};
QString mUnelidedText{};
};
2 changes: 2 additions & 0 deletions src/gui/gui.pri
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ HEADERS += \
src/gui/UBThumbnail.h \
src/gui/UBThumbnailArranger.h \
src/gui/UBThumbnailScene.h \
src/gui/UBThumbnailTextItem.h \
src/gui/UBThumbnailsView.h \
$$PWD/UBStartupHintsPalette.h \
src/gui/UBFloatingPalette.h \
Expand Down Expand Up @@ -50,6 +51,7 @@ SOURCES += \
src/gui/UBThumbnail.cpp \
src/gui/UBThumbnailArranger.cpp \
src/gui/UBThumbnailScene.cpp \
src/gui/UBThumbnailTextItem.cpp \
src/gui/UBThumbnailsView.cpp \
$$PWD/UBStartupHintsPalette.cpp \
src/gui/UBFloatingPalette.cpp \
Expand Down