Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
a4908414
Commit
a4908414
authored
Feb 07, 2012
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code restructurization for document navigator.
parent
9c48fd20
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
118 deletions
+132
-118
UBDocumentNavigator.cpp
src/gui/UBDocumentNavigator.cpp
+48
-111
UBDocumentNavigator.h
src/gui/UBDocumentNavigator.h
+2
-7
UBThumbnailWidget.cpp
src/gui/UBThumbnailWidget.cpp
+56
-0
UBThumbnailWidget.h
src/gui/UBThumbnailWidget.h
+26
-0
No files found.
src/gui/UBDocumentNavigator.cpp
View file @
a4908414
...
...
@@ -99,17 +99,28 @@ void UBDocumentNavigator::setDocument(UBDocumentProxy *document)
*/
void
UBDocumentNavigator
::
generateThumbnails
()
{
QList
<
QGraphicsItem
*>
items
;
//QList<QUrl> itemsPath;
QStringList
labels
;
// Get the thumbnails
QList
<
QPixmap
>
thumbs
=
UBThumbnailAdaptor
::
load
(
mCrntDoc
);
for
(
int
i
=
0
;
i
<
thumbs
.
count
();
i
++
)
mThumbsWithLabels
.
clear
();
foreach
(
QGraphicsItem
*
it
,
mScene
->
items
())
{
mScene
->
removeItem
(
it
);
delete
it
;
}
for
(
int
i
=
0
;
i
<
thumbs
.
count
();
i
++
)
{
QPixmap
pix
=
thumbs
.
at
(
i
);
QGraphicsPixmapItem
*
pixmapItem
=
new
UBSceneThumbnailNavigPixmap
(
pix
,
mCrntDoc
,
i
);
UBThumbnailTextItem
*
labelItem
=
new
UBThumbnailTextItem
(
tr
(
"Page %0"
).
arg
(
i
+
1
));
UBImgTextThumbnailElement
thumbWithText
(
pixmapItem
,
labelItem
);
thumbWithText
.
setBorder
(
border
());
mThumbsWithLabels
.
append
(
thumbWithText
);
mScene
->
addItem
(
pixmapItem
);
mScene
->
addItem
(
labelItem
);
// Get the selected item
if
(
UBApplication
::
boardController
->
activeSceneIndex
()
==
i
)
...
...
@@ -117,13 +128,10 @@ void UBDocumentNavigator::generateThumbnails()
mCrntItem
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
pixmapItem
);
mCrntItem
->
setSelected
(
true
);
}
items
<<
pixmapItem
;
labels
<<
tr
(
"Page %0"
).
arg
(
i
+
1
);
}
// Draw the items
setGraphicsItems
(
items
,
labels
);
// Draw the items
refreshScene
(
);
}
/**
...
...
@@ -153,12 +161,12 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
if
(
pixmapItem
)
{
// Get the old thumbnail
QGraphicsItem
*
pItem
=
mThumb
nails
.
at
(
iPage
);
QGraphicsItem
*
pItem
=
mThumb
sWithLabels
.
at
(
iPage
).
getThumbnail
(
);
if
(
NULL
!=
pItem
)
{
mScene
->
removeItem
(
pItem
);
mScene
->
addItem
(
pixmapItem
);
mThumb
nails
.
replace
(
iPage
,
pixmapItem
);
mThumb
sWithLabels
[
iPage
].
setThumbnail
(
pixmapItem
);
delete
pItem
;
}
}
...
...
@@ -183,110 +191,20 @@ void UBDocumentNavigator::addNewPage()
}
}
/**
* \brief Set the graphics items of the scene
* @param items as the items list
* @param labels as the page labels
*/
void
UBDocumentNavigator
::
setGraphicsItems
(
QList
<
QGraphicsItem
*>
items
,
QStringList
labels
)
{
mThumbnails
=
items
;
mLab
=
labels
;
// First, clear the actual thumbnails
foreach
(
QGraphicsItem
*
it
,
mScene
->
items
())
{
mScene
->
removeItem
(
it
);
delete
it
;
}
// Add the new thumbnails
foreach
(
QGraphicsItem
*
it
,
items
)
{
mScene
->
addItem
(
it
);
}
// Add the labels
mLabels
.
clear
();
foreach
(
QString
lb
,
labels
)
{
UBThumbnailTextItem
*
labelItem
=
new
UBThumbnailTextItem
(
lb
);
mScene
->
addItem
(
labelItem
);
mLabels
<<
labelItem
;
}
// Refresh the scene
refreshScene
();
}
/**
* \brief Put the element in the right place in the scene.
*/
void
UBDocumentNavigator
::
refreshScene
()
{
int
labelSpacing
=
0
;
if
(
mLabels
.
size
()
>
0
)
{
QFontMetrics
fm
(
mLabels
.
at
(
0
)
->
font
());
labelSpacing
=
UBSettings
::
thumbnailSpacing
+
fm
.
height
();
}
qreal
thumbnailHeight
=
mThumbnailWidth
/
UBSettings
::
minScreenRatio
;
for
(
int
i
=
0
;
i
<
mThumb
nai
ls
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
mThumb
sWithLabe
ls
.
size
();
i
++
)
{
// Get the item
QGraphicsItem
*
item
=
mThumbnails
.
at
(
i
);
// Compute the scale factor
qreal
scaleWidth
=
mThumbnailWidth
/
item
->
boundingRect
().
width
();
qreal
scaleHeight
=
thumbnailHeight
/
item
->
boundingRect
().
height
();
qreal
scaleFactor
=
qMin
(
scaleWidth
,
scaleHeight
);
UBThumbnail
*
pix
=
dynamic_cast
<
UBThumbnail
*>
(
item
);
if
(
pix
)
{
scaleFactor
=
qMin
(
scaleFactor
,
1.0
);
}
QTransform
transform
;
transform
.
scale
(
scaleFactor
,
scaleFactor
);
// Apply the scaling
item
->
setTransform
(
transform
);
item
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
UBImgTextThumbnailElement
&
item
=
mThumbsWithLabels
[
i
];
int
columnIndex
=
i
%
mNbColumns
;
int
rowIndex
=
i
/
mNbColumns
;
if
(
pix
)
{
pix
->
setColumn
(
columnIndex
);
pix
->
setRow
(
rowIndex
);
}
int
w
=
item
->
boundingRect
().
width
();
int
h
=
item
->
boundingRect
().
height
();
QPointF
pos
(
border
()
+
(
mThumbnailWidth
-
w
*
scaleFactor
)
/
2
+
columnIndex
*
(
mThumbnailWidth
+
border
()),
border
()
+
rowIndex
*
(
thumbnailHeight
+
border
()
+
labelSpacing
)
+
(
thumbnailHeight
-
h
*
scaleFactor
)
/
2
);
item
->
setPos
(
pos
);
// Add the labels "Page x"
if
(
mLabels
.
size
()
>
i
)
{
QFontMetrics
fm
(
mLabels
.
at
(
i
)
->
font
(),
this
);
QString
elidedText
=
fm
.
elidedText
(
mLab
.
at
(
i
),
Qt
::
ElideRight
,
mThumbnailWidth
);
mLabels
.
at
(
i
)
->
setPlainText
(
elidedText
);
mLabels
.
at
(
i
)
->
setWidth
(
fm
.
width
(
elidedText
)
+
2
*
mLabels
.
at
(
i
)
->
document
()
->
documentMargin
());
pos
.
setY
(
pos
.
y
()
+
(
thumbnailHeight
+
h
*
scaleFactor
)
/
2
+
5
);
// What is this 5 ??
qreal
labelWidth
=
fm
.
width
(
elidedText
);
pos
.
setX
(
border
()
+
(
mThumbnailWidth
-
labelWidth
)
/
2
+
columnIndex
*
(
mThumbnailWidth
+
border
()));
mLabels
.
at
(
i
)
->
setPos
(
pos
);
}
item
.
Place
(
rowIndex
,
columnIndex
,
mThumbnailWidth
,
thumbnailHeight
);
}
}
...
...
@@ -378,7 +296,15 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
UBThumbnailTextItem
*
pTextItem
=
dynamic_cast
<
UBThumbnailTextItem
*>
(
pClickedItem
);
if
(
NULL
!=
pTextItem
)
{
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
mThumbnails
.
at
(
mLabels
.
indexOf
(
pTextItem
)));
for
(
int
i
=
0
;
i
<
mThumbsWithLabels
.
size
();
i
++
)
{
const
UBImgTextThumbnailElement
&
el
=
mThumbsWithLabels
.
at
(
i
);
if
(
el
.
getCaption
()
==
pTextItem
)
{
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
el
.
getThumbnail
());
break
;
}
}
}
}
else
...
...
@@ -386,7 +312,13 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
if
(
NULL
!=
mCrntItem
&&
mCrntItem
!=
pCrntItem
)
{
// Unselect the previous item
int
iOldPage
=
mThumbnails
.
indexOf
(
mCrntItem
);
int
iOldPage
=
-
1
;
for
(
int
i
=
0
;
i
<
mThumbsWithLabels
.
size
();
i
++
)
if
(
mThumbsWithLabels
.
at
(
i
).
getThumbnail
()
==
mCrntItem
)
{
iOldPage
=
i
;
break
;
}
updateSpecificThumbnail
(
iOldPage
);
mCrntItem
=
pCrntItem
;
}
...
...
@@ -410,7 +342,12 @@ int UBDocumentNavigator::selectedPageNumber()
if
(
NULL
!=
mCrntItem
)
{
nbr
=
mThumbnails
.
indexOf
(
mCrntItem
);
for
(
int
i
=
0
;
i
<
mThumbsWithLabels
.
size
();
i
++
)
if
(
mThumbsWithLabels
.
at
(
i
).
getThumbnail
()
==
mCrntItem
)
{
nbr
=
i
;
break
;
}
}
return
nbr
;
...
...
@@ -440,8 +377,8 @@ void UBDocumentNavigator::onSelectionChanged()
*/
void
UBDocumentNavigator
::
onMovedToIndex
(
int
index
)
{
if
(
index
<
mThumb
nai
ls
.
size
()){
UBSceneThumbnailNavigPixmap
*
pItem
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
mThumb
nails
.
at
(
index
));
if
(
index
<
mThumb
sWithLabe
ls
.
size
()){
UBSceneThumbnailNavigPixmap
*
pItem
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
mThumb
sWithLabels
.
at
(
index
).
getThumbnail
(
));
if
(
NULL
!=
pItem
)
{
if
(
mCrntItem
)
mCrntItem
->
setSelected
(
false
);
//deselecting previous one
...
...
src/gui/UBDocumentNavigator.h
View file @
a4908414
...
...
@@ -57,7 +57,6 @@ private slots:
void
generateThumbnails
();
private
:
void
setGraphicsItems
(
QList
<
QGraphicsItem
*>
items
,
QStringList
labels
);
void
refreshScene
();
void
updateSpecificThumbnail
(
int
iPage
);
int
border
();
...
...
@@ -69,12 +68,8 @@ private:
UBSceneThumbnailNavigPixmap
*
mCrntItem
;
/** The current document */
UBDocumentProxy
*
mCrntDoc
;
/** The list of current thumbnails */
QList
<
QGraphicsItem
*>
mThumbnails
;
/** The list of current label items */
QList
<
UBThumbnailTextItem
*>
mLabels
;
/** The list of current labels */
QStringList
mLab
;
/** The list of current thumbnails with labels*/
QList
<
UBImgTextThumbnailElement
>
mThumbsWithLabels
;
/** The current number of columns */
int
mNbColumns
;
/** The current thumbnails width */
...
...
src/gui/UBThumbnailWidget.cpp
View file @
a4908414
...
...
@@ -805,3 +805,59 @@ void UBSceneThumbnailNavigPixmap::moveDownPage()
{
UBApplication
::
documentController
->
moveSceneToIndex
(
proxy
(),
sceneIndex
(),
sceneIndex
()
+
1
);
}
void
UBImgTextThumbnailElement
::
Place
(
int
row
,
int
col
,
qreal
width
,
qreal
height
)
{
int
labelSpacing
=
0
;
if
(
this
->
caption
)
{
QFontMetrics
fm
(
this
->
caption
->
font
());
labelSpacing
=
UBSettings
::
thumbnailSpacing
+
fm
.
height
();
}
if
(
this
->
thumbnail
)
{
int
w
=
this
->
thumbnail
->
boundingRect
().
width
();
int
h
=
this
->
thumbnail
->
boundingRect
().
height
();
qreal
scaleWidth
=
width
/
w
;
qreal
scaleHeight
=
height
/
h
;
qreal
scaleFactor
=
qMin
(
scaleWidth
,
scaleHeight
);
UBThumbnail
*
pix
=
dynamic_cast
<
UBThumbnail
*>
(
this
->
thumbnail
);
if
(
pix
)
{
scaleFactor
=
qMin
(
scaleFactor
,
1.0
);
}
QTransform
transform
;
transform
.
scale
(
scaleFactor
,
scaleFactor
);
// Apply the scaling
this
->
thumbnail
->
setTransform
(
transform
);
this
->
thumbnail
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
if
(
pix
)
{
pix
->
setColumn
(
col
);
pix
->
setRow
(
row
);
}
QPointF
pos
(
border
+
(
width
-
w
*
scaleFactor
)
/
2
+
col
*
(
width
+
border
),
border
+
row
*
(
height
+
border
+
labelSpacing
)
+
(
height
-
h
*
scaleFactor
)
/
2
);
this
->
thumbnail
->
setPos
(
pos
);
if
(
this
->
caption
)
{
QFontMetrics
fm
(
this
->
caption
->
font
());
QString
elidedText
=
fm
.
elidedText
(
this
->
caption
->
toPlainText
(),
Qt
::
ElideRight
,
width
);
this
->
caption
->
setPlainText
(
elidedText
);
this
->
caption
->
setWidth
(
fm
.
width
(
elidedText
)
+
2
*
this
->
caption
->
document
()
->
documentMargin
());
pos
.
setY
(
pos
.
y
()
+
(
height
+
h
*
scaleFactor
)
/
2
+
5
);
// What is this 5 ??
qreal
labelWidth
=
fm
.
width
(
elidedText
);
pos
.
setX
(
border
+
(
width
-
labelWidth
)
/
2
+
col
*
(
width
+
border
));
this
->
caption
->
setPos
(
pos
);
}
}
}
src/gui/UBThumbnailWidget.h
View file @
a4908414
...
...
@@ -391,5 +391,31 @@ class UBThumbnailTextItem : public QGraphicsTextItem
bool
mIsHighlighted
;
};
class
UBImgTextThumbnailElement
{
private
:
QGraphicsItem
*
thumbnail
;
UBThumbnailTextItem
*
caption
;
int
border
;
public
:
UBImgTextThumbnailElement
(
QGraphicsItem
*
thumb
,
UBThumbnailTextItem
*
text
)
:
border
(
0
)
{
this
->
thumbnail
=
thumb
;
this
->
caption
=
text
;
}
QGraphicsItem
*
getThumbnail
()
const
{
return
this
->
thumbnail
;
}
void
setThumbnail
(
QGraphicsItem
*
newGItem
)
{
this
->
thumbnail
=
newGItem
;
}
UBThumbnailTextItem
*
getCaption
()
const
{
return
this
->
caption
;
}
void
setCaption
(
UBThumbnailTextItem
*
newcaption
)
{
this
->
caption
=
newcaption
;
}
void
Place
(
int
row
,
int
col
,
qreal
width
,
qreal
height
);
int
getBorder
()
const
{
return
this
->
border
;
}
void
setBorder
(
int
newBorder
)
{
this
->
border
=
newBorder
;
}
};
#endif
/* UBTHUMBNAILWIDGET_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment