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
b5ebaf19
Commit
b5ebaf19
authored
Sep 12, 2011
by
Claudio Valerio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed issue:
http://188.165.53.52/jira/browse/SANKORE-241
parent
c7c4bca7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
134 deletions
+135
-134
UBDocumentNavigator.cpp
src/gui/UBDocumentNavigator.cpp
+133
-133
UBDocumentNavigator.h
src/gui/UBDocumentNavigator.h
+2
-1
No files found.
src/gui/UBDocumentNavigator.cpp
View file @
b5ebaf19
...
@@ -37,13 +37,13 @@
...
@@ -37,13 +37,13 @@
* @param name as the object name
* @param name as the object name
*/
*/
UBDocumentNavigator
::
UBDocumentNavigator
(
QWidget
*
parent
,
const
char
*
name
)
:
QGraphicsView
(
parent
)
UBDocumentNavigator
::
UBDocumentNavigator
(
QWidget
*
parent
,
const
char
*
name
)
:
QGraphicsView
(
parent
)
,
mScene
(
NULL
)
,
mScene
(
NULL
)
,
mCrntItem
(
NULL
)
,
mCrntItem
(
NULL
)
,
mCrntDoc
(
NULL
)
,
mCrntDoc
(
NULL
)
,
mNbColumns
(
1
)
,
mNbColumns
(
1
)
,
mThumbnailWidth
(
0
)
,
mThumbnailWidth
(
0
)
,
mThumbnailMinWidth
(
100
)
,
mThumbnailMinWidth
(
100
)
,
bNavig
(
false
)
,
bNavig
(
false
)
{
{
setObjectName
(
name
);
setObjectName
(
name
);
mScene
=
new
QGraphicsScene
(
this
);
mScene
=
new
QGraphicsScene
(
this
);
...
@@ -52,6 +52,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
...
@@ -52,6 +52,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
mThumbnailWidth
=
width
()
-
2
*
border
();
mThumbnailWidth
=
width
()
-
2
*
border
();
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
addNewPage
()));
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
addNewPage
()));
connect
(
UBApplication
::
boardController
,
SIGNAL
(
setDocOnPageNavigator
(
UBDocumentProxy
*
)),
this
,
SLOT
(
generateThumbnails
()));
connect
(
mScene
,
SIGNAL
(
selectionChanged
()),
this
,
SLOT
(
onSelectionChanged
()));
connect
(
mScene
,
SIGNAL
(
selectionChanged
()),
this
,
SLOT
(
onSelectionChanged
()));
}
}
...
@@ -62,14 +63,14 @@ UBDocumentNavigator::~UBDocumentNavigator()
...
@@ -62,14 +63,14 @@ UBDocumentNavigator::~UBDocumentNavigator()
{
{
if
(
NULL
!=
mCrntItem
)
if
(
NULL
!=
mCrntItem
)
{
{
delete
mCrntItem
;
delete
mCrntItem
;
mCrntItem
=
NULL
;
mCrntItem
=
NULL
;
}
}
if
(
NULL
!=
mScene
)
if
(
NULL
!=
mScene
)
{
{
delete
mScene
;
delete
mScene
;
mScene
=
NULL
;
mScene
=
NULL
;
}
}
}
}
...
@@ -83,8 +84,8 @@ void UBDocumentNavigator::setDocument(UBDocumentProxy *document)
...
@@ -83,8 +84,8 @@ void UBDocumentNavigator::setDocument(UBDocumentProxy *document)
// content and add all the pages of the given document.
// content and add all the pages of the given document.
if
(
document
)
if
(
document
)
{
{
mCrntDoc
=
document
;
mCrntDoc
=
document
;
generateThumbnails
();
generateThumbnails
();
}
}
}
}
...
@@ -103,20 +104,19 @@ void UBDocumentNavigator::generateThumbnails()
...
@@ -103,20 +104,19 @@ void UBDocumentNavigator::generateThumbnails()
for
(
int
i
=
0
;
i
<
thumbs
.
count
();
i
++
)
for
(
int
i
=
0
;
i
<
thumbs
.
count
();
i
++
)
{
{
QPixmap
pix
=
thumbs
.
at
(
i
);
QPixmap
pix
=
thumbs
.
at
(
i
);
QGraphicsPixmapItem
*
pixmapItem
=
new
UBSceneThumbnailPixmap
(
pix
,
mCrntDoc
,
i
);
QGraphicsPixmapItem
*
pixmapItem
=
new
UBSceneThumbnailPixmap
(
pix
,
mCrntDoc
,
i
);
// Get the selected item
// Get the selected item
if
(
UBApplication
::
boardController
->
activeSceneIndex
()
==
i
)
if
(
UBApplication
::
boardController
->
activeSceneIndex
()
==
i
)
{
{
selection
=
pixmapItem
;
selection
=
pixmapItem
;
mCrntItem
=
dynamic_cast
<
UBSceneThumbnailPixmap
*>
(
pixmapItem
);
mCrntItem
=
dynamic_cast
<
UBSceneThumbnailPixmap
*>
(
pixmapItem
);
mCrntItem
->
setSelected
(
true
);
mCrntItem
->
setSelected
(
true
);
}
}
items
<<
pixmapItem
;
items
<<
pixmapItem
;
labels
<<
tr
(
"Page %0"
).
arg
(
i
+
1
);
labels
<<
tr
(
"Page %0"
).
arg
(
i
+
1
);
//itemsPath.append(QUrl::fromLocalFile(mCrntDoc->persistencePath() + QString("/pages/%0").arg(i + 1)));
}
}
// Draw the items
// Draw the items
...
@@ -134,27 +134,27 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
...
@@ -134,27 +134,27 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
if
(
NULL
!=
pScene
)
if
(
NULL
!=
pScene
)
{
{
// Save the current state of the scene
// Save the current state of the scene
pScene
->
setModified
(
true
);
pScene
->
setModified
(
true
);
UBSvgSubsetAdaptor
::
persistScene
(
mCrntDoc
,
pScene
,
iPage
);
UBSvgSubsetAdaptor
::
persistScene
(
mCrntDoc
,
pScene
,
iPage
);
UBThumbnailAdaptor
::
persistScene
(
mCrntDoc
->
persistencePath
(),
pScene
,
iPage
);
UBThumbnailAdaptor
::
persistScene
(
mCrntDoc
->
persistencePath
(),
pScene
,
iPage
);
// Load it
// Load it
QList
<
QPixmap
>
thumbs
=
UBThumbnailAdaptor
::
load
(
mCrntDoc
);
QList
<
QPixmap
>
thumbs
=
UBThumbnailAdaptor
::
load
(
mCrntDoc
);
QPixmap
pix
=
thumbs
.
at
(
iPage
);
QPixmap
pix
=
thumbs
.
at
(
iPage
);
QGraphicsPixmapItem
*
pixmapItem
=
new
UBSceneThumbnailPixmap
(
pix
,
mCrntDoc
,
iPage
);
QGraphicsPixmapItem
*
pixmapItem
=
new
UBSceneThumbnailPixmap
(
pix
,
mCrntDoc
,
iPage
);
if
(
pixmapItem
)
if
(
pixmapItem
)
{
{
// Get the old thumbnail
// Get the old thumbnail
QGraphicsItem
*
pItem
=
mThumbnails
.
at
(
iPage
);
QGraphicsItem
*
pItem
=
mThumbnails
.
at
(
iPage
);
if
(
NULL
!=
pItem
)
if
(
NULL
!=
pItem
)
{
{
mScene
->
removeItem
(
pItem
);
mScene
->
removeItem
(
pItem
);
mScene
->
addItem
(
pixmapItem
);
mScene
->
addItem
(
pixmapItem
);
mThumbnails
.
replace
(
iPage
,
pixmapItem
);
mThumbnails
.
replace
(
iPage
,
pixmapItem
);
}
}
}
}
}
}
}
}
...
@@ -169,10 +169,10 @@ void UBDocumentNavigator::addNewPage()
...
@@ -169,10 +169,10 @@ void UBDocumentNavigator::addNewPage()
if
(
!
bNavig
)
if
(
!
bNavig
)
{
{
generateThumbnails
();
generateThumbnails
();
if
(
NULL
!=
mCrntItem
)
if
(
NULL
!=
mCrntItem
)
{
{
mCrntItem
->
setSelected
(
true
);
mCrntItem
->
setSelected
(
true
);
}
}
}
}
}
}
...
@@ -188,24 +188,24 @@ void UBDocumentNavigator::setGraphicsItems(QList<QGraphicsItem *> items, QString
...
@@ -188,24 +188,24 @@ void UBDocumentNavigator::setGraphicsItems(QList<QGraphicsItem *> items, QString
// First, clear the actual thumbnails
// First, clear the actual thumbnails
foreach
(
QGraphicsItem
*
it
,
mScene
->
items
())
foreach
(
QGraphicsItem
*
it
,
mScene
->
items
())
{
{
mScene
->
removeItem
(
it
);
mScene
->
removeItem
(
it
);
delete
it
;
delete
it
;
}
}
// Add the new thumbnails
// Add the new thumbnails
foreach
(
QGraphicsItem
*
it
,
items
)
foreach
(
QGraphicsItem
*
it
,
items
)
{
{
mScene
->
addItem
(
it
);
mScene
->
addItem
(
it
);
}
}
// Add the labels
// Add the labels
mLabels
.
clear
();
mLabels
.
clear
();
foreach
(
QString
lb
,
labels
)
foreach
(
QString
lb
,
labels
)
{
{
UBThumbnailTextItem
*
labelItem
=
new
UBThumbnailTextItem
(
lb
);
UBThumbnailTextItem
*
labelItem
=
new
UBThumbnailTextItem
(
lb
);
mScene
->
addItem
(
labelItem
);
mScene
->
addItem
(
labelItem
);
mLabels
<<
labelItem
;
mLabels
<<
labelItem
;
}
}
// Refresh the scene
// Refresh the scene
...
@@ -221,71 +221,71 @@ void UBDocumentNavigator::refreshScene()
...
@@ -221,71 +221,71 @@ void UBDocumentNavigator::refreshScene()
if
(
mLabels
.
size
()
>
0
)
if
(
mLabels
.
size
()
>
0
)
{
{
QFontMetrics
fm
(
mLabels
.
at
(
0
)
->
font
());
QFontMetrics
fm
(
mLabels
.
at
(
0
)
->
font
());
labelSpacing
=
UBSettings
::
thumbnailSpacing
+
fm
.
height
();
labelSpacing
=
UBSettings
::
thumbnailSpacing
+
fm
.
height
();
}
}
qreal
thumbnailHeight
=
mThumbnailWidth
/
UBSettings
::
minScreenRatio
;
qreal
thumbnailHeight
=
mThumbnailWidth
/
UBSettings
::
minScreenRatio
;
for
(
int
i
=
0
;
i
<
mThumbnails
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
mThumbnails
.
size
();
i
++
)
{
{
// Get the item
// Get the item
QGraphicsItem
*
item
=
mThumbnails
.
at
(
i
);
QGraphicsItem
*
item
=
mThumbnails
.
at
(
i
);
// Compute the scale factor
// Compute the scale factor
qreal
scaleWidth
=
mThumbnailWidth
/
item
->
boundingRect
().
width
();
qreal
scaleWidth
=
mThumbnailWidth
/
item
->
boundingRect
().
width
();
qreal
scaleHeight
=
thumbnailHeight
/
item
->
boundingRect
().
height
();
qreal
scaleHeight
=
thumbnailHeight
/
item
->
boundingRect
().
height
();
qreal
scaleFactor
=
qMin
(
scaleWidth
,
scaleHeight
);
qreal
scaleFactor
=
qMin
(
scaleWidth
,
scaleHeight
);
UBThumbnail
*
pix
=
dynamic_cast
<
UBThumbnail
*>
(
item
);
UBThumbnail
*
pix
=
dynamic_cast
<
UBThumbnail
*>
(
item
);
if
(
pix
)
if
(
pix
)
{
{
scaleFactor
=
qMin
(
scaleFactor
,
1.0
);
scaleFactor
=
qMin
(
scaleFactor
,
1.0
);
}
}
QTransform
transform
;
QTransform
transform
;
transform
.
scale
(
scaleFactor
,
scaleFactor
);
transform
.
scale
(
scaleFactor
,
scaleFactor
);
// Apply the scaling
// Apply the scaling
item
->
setTransform
(
transform
);
item
->
setTransform
(
transform
);
item
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
item
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
int
columnIndex
=
i
%
mNbColumns
;
int
columnIndex
=
i
%
mNbColumns
;
int
rowIndex
=
i
/
mNbColumns
;
int
rowIndex
=
i
/
mNbColumns
;
if
(
pix
)
if
(
pix
)
{
{
pix
->
setColumn
(
columnIndex
);
pix
->
setColumn
(
columnIndex
);
pix
->
setRow
(
rowIndex
);
pix
->
setRow
(
rowIndex
);
}
}
int
w
=
item
->
boundingRect
().
width
();
int
w
=
item
->
boundingRect
().
width
();
int
h
=
item
->
boundingRect
().
height
();
int
h
=
item
->
boundingRect
().
height
();
QPointF
pos
(
border
()
+
(
mThumbnailWidth
-
w
*
scaleFactor
)
/
2
+
columnIndex
*
(
mThumbnailWidth
+
border
()),
QPointF
pos
(
border
()
+
(
mThumbnailWidth
-
w
*
scaleFactor
)
/
2
+
columnIndex
*
(
mThumbnailWidth
+
border
()),
border
()
+
rowIndex
*
(
thumbnailHeight
+
border
()
+
labelSpacing
)
+
(
thumbnailHeight
-
h
*
scaleFactor
)
/
2
);
border
()
+
rowIndex
*
(
thumbnailHeight
+
border
()
+
labelSpacing
)
+
(
thumbnailHeight
-
h
*
scaleFactor
)
/
2
);
item
->
setPos
(
pos
);
item
->
setPos
(
pos
);
// Add the labels "Page x"
// Add the labels "Page x"
if
(
mLabels
.
size
()
>
i
)
if
(
mLabels
.
size
()
>
i
)
{
{
QFontMetrics
fm
(
mLabels
.
at
(
i
)
->
font
(),
this
);
QFontMetrics
fm
(
mLabels
.
at
(
i
)
->
font
(),
this
);
QString
elidedText
=
fm
.
elidedText
(
mLab
.
at
(
i
),
Qt
::
ElideRight
,
mThumbnailWidth
);
QString
elidedText
=
fm
.
elidedText
(
mLab
.
at
(
i
),
Qt
::
ElideRight
,
mThumbnailWidth
);
mLabels
.
at
(
i
)
->
setPlainText
(
elidedText
);
mLabels
.
at
(
i
)
->
setPlainText
(
elidedText
);
mLabels
.
at
(
i
)
->
setWidth
(
fm
.
width
(
elidedText
)
+
2
*
mLabels
.
at
(
i
)
->
document
()
->
documentMargin
());
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 ??
pos
.
setY
(
pos
.
y
()
+
(
thumbnailHeight
+
h
*
scaleFactor
)
/
2
+
5
);
// What is this 5 ??
qreal
labelWidth
=
fm
.
width
(
elidedText
);
qreal
labelWidth
=
fm
.
width
(
elidedText
);
pos
.
setX
(
border
()
+
(
mThumbnailWidth
-
labelWidth
)
/
2
+
columnIndex
*
(
mThumbnailWidth
+
border
()));
pos
.
setX
(
border
()
+
(
mThumbnailWidth
-
labelWidth
)
/
2
+
columnIndex
*
(
mThumbnailWidth
+
border
()));
mLabels
.
at
(
i
)
->
setPos
(
pos
);
mLabels
.
at
(
i
)
->
setPos
(
pos
);
}
}
}
}
QScrollBar
*
vertScrollBar
=
verticalScrollBar
();
QScrollBar
*
vertScrollBar
=
verticalScrollBar
();
int
scrollBarThickness
=
0
;
int
scrollBarThickness
=
0
;
if
(
vertScrollBar
&&
vertScrollBar
->
isVisible
())
if
(
vertScrollBar
&&
vertScrollBar
->
isVisible
())
scrollBarThickness
=
vertScrollBar
->
width
();
scrollBarThickness
=
vertScrollBar
->
width
();
}
}
/**
/**
...
@@ -345,12 +345,12 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
...
@@ -345,12 +345,12 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
mThumbnailWidth
=
(
width
()
>
mThumbnailMinWidth
)
?
width
()
-
2
*
border
()
:
mThumbnailMinWidth
;
mThumbnailWidth
=
(
width
()
>
mThumbnailMinWidth
)
?
width
()
-
2
*
border
()
:
mThumbnailMinWidth
;
// Update the scene rect
// Update the scene rect
// QRect sceneRect;
// QRect sceneRect;
// sceneRect.setWidth(width() - 2*border());
// sceneRect.setWidth(width() - 2*border());
// sceneRect.setHeight(height() - 2*border());
// sceneRect.setHeight(height() - 2*border());
// sceneRect.moveLeft(border());
// sceneRect.moveLeft(border());
// sceneRect.moveTop(border());
// sceneRect.moveTop(border());
// scene()->setSceneRect(sceneRect);
// scene()->setSceneRect(sceneRect);
// Refresh the scene
// Refresh the scene
refreshScene
();
refreshScene
();
...
@@ -365,20 +365,20 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
...
@@ -365,20 +365,20 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
QGraphicsItem
*
pClickedItem
=
itemAt
(
event
->
pos
());
QGraphicsItem
*
pClickedItem
=
itemAt
(
event
->
pos
());
if
(
NULL
!=
pClickedItem
)
if
(
NULL
!=
pClickedItem
)
{
{
bNavig
=
true
;
bNavig
=
true
;
// First, select the clicked item
// First, select the clicked item
UBSceneThumbnailPixmap
*
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailPixmap
*>
(
pClickedItem
);
UBSceneThumbnailPixmap
*
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailPixmap
*>
(
pClickedItem
);
if
(
NULL
==
pCrntItem
)
if
(
NULL
==
pCrntItem
)
{
{
// If we fall here we may have clicked on the label instead of the thumbnail
// If we fall here we may have clicked on the label instead of the thumbnail
UBThumbnailTextItem
*
pTextItem
=
dynamic_cast
<
UBThumbnailTextItem
*>
(
pClickedItem
);
UBThumbnailTextItem
*
pTextItem
=
dynamic_cast
<
UBThumbnailTextItem
*>
(
pClickedItem
);
if
(
NULL
!=
pTextItem
)
if
(
NULL
!=
pTextItem
)
{
{
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailPixmap
*>
(
mThumbnails
.
at
(
mLabels
.
indexOf
(
pTextItem
)));
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailPixmap
*>
(
mThumbnails
.
at
(
mLabels
.
indexOf
(
pTextItem
)));
}
}
}
}
else
else
{
{
if
(
NULL
!=
mCrntItem
&&
mCrntItem
!=
pCrntItem
)
if
(
NULL
!=
mCrntItem
&&
mCrntItem
!=
pCrntItem
)
...
@@ -396,7 +396,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
...
@@ -396,7 +396,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
emit
changeCurrentPage
();
emit
changeCurrentPage
();
refreshScene
();
refreshScene
();
}
}
bNavig
=
false
;
bNavig
=
false
;
}
}
}
}
...
@@ -410,7 +410,7 @@ int UBDocumentNavigator::selectedPageNumber()
...
@@ -410,7 +410,7 @@ int UBDocumentNavigator::selectedPageNumber()
if
(
NULL
!=
mCrntItem
)
if
(
NULL
!=
mCrntItem
)
{
{
nbr
=
mThumbnails
.
indexOf
(
mCrntItem
);
nbr
=
mThumbnails
.
indexOf
(
mCrntItem
);
}
}
return
nbr
;
return
nbr
;
...
@@ -430,6 +430,6 @@ UBDocumentProxy* UBDocumentNavigator::currentDoc()
...
@@ -430,6 +430,6 @@ UBDocumentProxy* UBDocumentNavigator::currentDoc()
*/
*/
void
UBDocumentNavigator
::
onSelectionChanged
()
void
UBDocumentNavigator
::
onSelectionChanged
()
{
{
// QList<QGraphicsItem*> qlItems = mScene->selectedItems();
// QList<QGraphicsItem*> qlItems = mScene->selectedItems();
// qDebug() << "The number of selected items is " << qlItems.count();
// qDebug() << "The number of selected items is " << qlItems.count();
}
}
src/gui/UBDocumentNavigator.h
View file @
b5ebaf19
...
@@ -51,13 +51,14 @@ protected:
...
@@ -51,13 +51,14 @@ protected:
private
slots
:
private
slots
:
void
addNewPage
();
void
addNewPage
();
void
onSelectionChanged
();
void
onSelectionChanged
();
void
generateThumbnails
();
private
:
private
:
void
setGraphicsItems
(
QList
<
QGraphicsItem
*>
items
,
QStringList
labels
);
void
setGraphicsItems
(
QList
<
QGraphicsItem
*>
items
,
QStringList
labels
);
void
refreshScene
();
void
refreshScene
();
void
updateSpecificThumbnail
(
int
iPage
);
void
updateSpecificThumbnail
(
int
iPage
);
int
border
();
int
border
();
void
generateThumbnails
();
/** The scene */
/** The scene */
QGraphicsScene
*
mScene
;
QGraphicsScene
*
mScene
;
...
...
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