Skip to content

Commit 9a8abac

Browse files
authored
Merge pull request #1242 from letsfindaway/refactor-enable-ui
Refactor enable UI
2 parents bfc73c2 + c74f99d commit 9a8abac

9 files changed

Lines changed: 157 additions & 82 deletions

src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ target_sources(${PROJECT_NAME} PRIVATE
7575
UBThumbnailArranger.h
7676
UBThumbnailScene.cpp
7777
UBThumbnailScene.h
78+
UBThumbnailTextItem.cpp
79+
UBThumbnailTextItem.h
7880
UBThumbnailsView.cpp
7981
UBThumbnailsView.h
8082
UBDocumentThumbnailsView.cpp

src/gui/UBDocumentThumbnailsView.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ double UBDocumentThumbnailsView::UBDocumentThumbnailArranger::thumbnailWidth() c
550550
return mThumbnailWidth;
551551
}
552552

553+
bool UBDocumentThumbnailsView::UBDocumentThumbnailArranger::isUIEnabled() const
554+
{
555+
return false;
556+
}
557+
553558
void UBDocumentThumbnailsView::UBDocumentThumbnailArranger::setThumbnailWidth(int width)
554559
{
555560
mThumbnailWidth = width;

src/gui/UBDocumentThumbnailsView.h

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class UBDocumentThumbnailsView : public UBThumbnailsView
126126

127127
virtual int columnCount() const override;
128128
virtual double thumbnailWidth() const override;
129+
virtual bool isUIEnabled() const override;
129130

130131
private:
131132
void setThumbnailWidth(int width);
@@ -136,71 +137,4 @@ class UBDocumentThumbnailsView : public UBThumbnailsView
136137
};
137138

138139

139-
class UBThumbnailTextItem : public QGraphicsTextItem
140-
{
141-
Q_OBJECT
142-
143-
public:
144-
UBThumbnailTextItem()
145-
: QGraphicsTextItem()
146-
{
147-
}
148-
149-
UBThumbnailTextItem(int index)
150-
: QGraphicsTextItem()
151-
, mUnelidedText(toPlainText())
152-
{
153-
setPageNumber(index + 1);
154-
}
155-
156-
UBThumbnailTextItem(const QString& text)
157-
: QGraphicsTextItem(text)
158-
, mUnelidedText(text)
159-
{
160-
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
161-
}
162-
163-
QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}
164-
165-
void setWidth(qreal pWidth)
166-
{
167-
if (mWidth != pWidth)
168-
{
169-
prepareGeometryChange();
170-
mWidth = pWidth;
171-
computeText();
172-
173-
// center text
174-
setTextWidth(mWidth);
175-
document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
176-
}
177-
}
178-
179-
qreal width() {return mWidth;}
180-
181-
void setPageNumber(int i)
182-
{
183-
mUnelidedText = tr("Page %0").arg(i);
184-
computeText();
185-
}
186-
187-
void setText(const QString& text)
188-
{
189-
mUnelidedText = text;
190-
computeText();
191-
}
192-
193-
void computeText()
194-
{
195-
QFontMetricsF fm(font());
196-
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideLeft, mWidth - 2 * document()->documentMargin() - 1);
197-
setPlainText(elidedText);
198-
}
199-
200-
private:
201-
qreal mWidth{0};
202-
QString mUnelidedText{};
203-
};
204-
205-
206140
#endif /* UBDOCUMENTTHUMBNAILSVIEW_H_ */

src/gui/UBThumbnail.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include "board/UBDrawingController.h"
2929
#include "document/UBDocument.h"
3030
#include "domain/UBGraphicsScene.h"
31-
#include "gui/UBBoardThumbnailsView.h"
32-
#include "gui/UBDocumentThumbnailsView.h"
31+
#include "gui/UBThumbnailArranger.h"
3332
#include "gui/UBThumbnailScene.h"
33+
#include "gui/UBThumbnailTextItem.h"
3434

3535

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

253253
if (thumbnailScene)
254254
{
255-
for (const auto view : thumbnailScene->views())
256-
{
257-
if (view->isVisible())
258-
{
259-
bool isBoardThumbnailsView = dynamic_cast<UBBoardThumbnailsView*>(view) != nullptr;
260-
261-
if (isBoardThumbnailsView)
262-
{
263-
mEditable = true;
264-
break;
265-
}
266-
}
267-
}
255+
mEditable = thumbnailScene->currentThumbnailArranger()->isUIEnabled();
268256
}
257+
269258
QGraphicsRectItem::hoverEnterEvent(event);
270259
}
271260

src/gui/UBThumbnailArranger.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ QSizeF UBThumbnailArranger::spacing() const
6262
const double spacing = UBSettings::thumbnailSpacing;
6363
return {spacing, spacing};
6464
}
65+
66+
bool UBThumbnailArranger::isUIEnabled() const
67+
{
68+
return true;
69+
}

src/gui/UBThumbnailArranger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class UBThumbnailArranger
4747
virtual double availableViewWidth() const;
4848
virtual QMarginsF margins() const;
4949
virtual QSizeF spacing() const;
50+
virtual bool isUIEnabled() const;
5051

5152
private:
5253
UBThumbnailsView* mThumbnailView{nullptr};

src/gui/UBThumbnailTextItem.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2015-2025 Département de l'Instruction Publique (DIP-SEM)
3+
*
4+
* This file is part of OpenBoard.
5+
*
6+
* OpenBoard is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, version 3 of the License,
9+
* with a specific linking exception for the OpenSSL project's
10+
* "OpenSSL" library (or with modified versions of it that use the
11+
* same license as the "OpenSSL" library).
12+
*
13+
* OpenBoard is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
23+
#include "UBThumbnailTextItem.h"
24+
25+
#include <QFontMetricsF>
26+
#include <QTextDocument>
27+
#include <QTextOption>
28+
29+
UBThumbnailTextItem::UBThumbnailTextItem()
30+
: QGraphicsTextItem()
31+
{
32+
}
33+
34+
UBThumbnailTextItem::UBThumbnailTextItem(int index)
35+
: QGraphicsTextItem()
36+
, mUnelidedText(toPlainText())
37+
{
38+
setPageNumber(index + 1);
39+
}
40+
41+
UBThumbnailTextItem::UBThumbnailTextItem(const QString& text)
42+
: QGraphicsTextItem(text)
43+
, mUnelidedText(text)
44+
{
45+
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
46+
}
47+
48+
QRectF UBThumbnailTextItem::boundingRect() const
49+
{
50+
return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));
51+
}
52+
53+
void UBThumbnailTextItem::setWidth(qreal pWidth)
54+
{
55+
if (mWidth != pWidth)
56+
{
57+
prepareGeometryChange();
58+
mWidth = pWidth;
59+
computeText();
60+
61+
// center text
62+
setTextWidth(mWidth);
63+
document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
64+
}
65+
}
66+
67+
qreal UBThumbnailTextItem::width()
68+
{
69+
return mWidth;
70+
}
71+
72+
void UBThumbnailTextItem::setPageNumber(int i)
73+
{
74+
mUnelidedText = tr("Page %0").arg(i);
75+
computeText();
76+
}
77+
78+
void UBThumbnailTextItem::setText(const QString& text)
79+
{
80+
mUnelidedText = text;
81+
computeText();
82+
}
83+
84+
void UBThumbnailTextItem::computeText()
85+
{
86+
QFontMetricsF fm(font());
87+
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideLeft, mWidth - 2 * document()->documentMargin() - 1);
88+
setPlainText(elidedText);
89+
}

src/gui/UBThumbnailTextItem.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2015-2025 Département de l'Instruction Publique (DIP-SEM)
3+
*
4+
* This file is part of OpenBoard.
5+
*
6+
* OpenBoard is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, version 3 of the License,
9+
* with a specific linking exception for the OpenSSL project's
10+
* "OpenSSL" library (or with modified versions of it that use the
11+
* same license as the "OpenSSL" library).
12+
*
13+
* OpenBoard is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
23+
#pragma once
24+
25+
#include <QGraphicsTextItem>
26+
27+
class UBThumbnailTextItem : public QGraphicsTextItem
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
UBThumbnailTextItem();
33+
UBThumbnailTextItem(int index);
34+
UBThumbnailTextItem(const QString& text);
35+
36+
QRectF boundingRect() const;
37+
38+
void setWidth(qreal pWidth);
39+
qreal width();
40+
41+
void setPageNumber(int i);
42+
void setText(const QString& text);
43+
void computeText();
44+
45+
private:
46+
qreal mWidth{0};
47+
QString mUnelidedText{};
48+
};

src/gui/gui.pri

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ HEADERS += \
22
src/gui/UBThumbnail.h \
33
src/gui/UBThumbnailArranger.h \
44
src/gui/UBThumbnailScene.h \
5+
src/gui/UBThumbnailTextItem.h \
56
src/gui/UBThumbnailsView.h \
67
$$PWD/UBStartupHintsPalette.h \
78
src/gui/UBFloatingPalette.h \
@@ -50,6 +51,7 @@ SOURCES += \
5051
src/gui/UBThumbnail.cpp \
5152
src/gui/UBThumbnailArranger.cpp \
5253
src/gui/UBThumbnailScene.cpp \
54+
src/gui/UBThumbnailTextItem.cpp \
5355
src/gui/UBThumbnailsView.cpp \
5456
$$PWD/UBStartupHintsPalette.cpp \
5557
src/gui/UBFloatingPalette.cpp \

0 commit comments

Comments
 (0)