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
d8bc5839
Commit
d8bc5839
authored
Apr 10, 2012
by
Ivan Ilin
Browse files
Options
Browse Files
Download
Plain Diff
Delete button is now available
parents
da61ebad
80bfc86a
Changes
37
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
886 additions
and
593 deletions
+886
-593
Sankore_3.1.pro
Sankore_3.1.pro
+1
-1
UBCFFAdaptor.pro
plugins/cffadaptor/UBCFFAdaptor.pro
+8
-6
languages.js
.../library/interactivities/Choisir.wgt/scripts/languages.js
+23
-23
script.js
.../library/interactivities/associer_images.wgt/js/script.js
+1
-1
script.js
...teractivities/associer_images.wgt/locales/fr/js/script.js
+2
-2
script.js
...teractivities/associer_sounds.wgt/locales/fr/js/script.js
+3
-3
script.js
...brary/interactivities/categoriser_images.wgt/js/script.js
+1
-1
script.js
...activities/categoriser_images.wgt/locales/fr/js/script.js
+3
-3
script.js
...library/interactivities/categoriser_text.wgt/js/script.js
+2
-2
script.js
...eractivities/categoriser_text.wgt/locales/fr/js/script.js
+3
-3
script.js
resources/library/interactivities/etudier.wgt/js/script.js
+2
-2
script.js
...brary/interactivities/etudier.wgt/locales/fr/js/script.js
+3
-3
template2.js
...activities/ord-phrases.wgt/locales/fr/script/template2.js
+2
-2
template2.js
...ractivities/ord-words.wgt/locales/fr/scripts/template2.js
+2
-2
script.js
...ctivities/ordonner_des_images.wgt/locales/fr/js/script.js
+3
-3
script.js
...tivities/ordonner_des_letters.wgt/locales/fr/js/script.js
+3
-3
script.js
.../interactivities/selectionner.wgt/locales/fr/js/script.js
+2
-2
wcontainer.js
...ctivities/spl-phrase.wgt/locales/fr/scripts/wcontainer.js
+2
-2
wcontainer.js
...ractivities/spl-text.wgt/locales/fr/scripts/wcontainer.js
+1
-1
wcontainer.js
...ractivities/spl-word.wgt/locales/fr/scripts/wcontainer.js
+1
-1
UBBoardController.cpp
src/board/UBBoardController.cpp
+3
-2
UBBoardView.cpp
src/board/UBBoardView.cpp
+4
-1
UBSettings.cpp
src/core/UBSettings.cpp
+3
-0
UBSettings.h
src/core/UBSettings.h
+3
-2
UBDesktopAnnotationController.cpp
src/desktop/UBDesktopAnnotationController.cpp
+1
-0
UBAngleWidget.cpp
src/domain/UBAngleWidget.cpp
+46
-0
UBAngleWidget.h
src/domain/UBAngleWidget.h
+25
-0
UBGraphicsDelegateFrame.cpp
src/domain/UBGraphicsDelegateFrame.cpp
+137
-27
UBGraphicsDelegateFrame.h
src/domain/UBGraphicsDelegateFrame.h
+14
-3
UBGraphicsItemDelegate.cpp
src/domain/UBGraphicsItemDelegate.cpp
+8
-2
UBGraphicsItemDelegate.h
src/domain/UBGraphicsItemDelegate.h
+2
-0
UBGraphicsPixmapItem.cpp
src/domain/UBGraphicsPixmapItem.cpp
+1
-1
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+62
-2
UBGraphicsScene.h
src/domain/UBGraphicsScene.h
+6
-1
domain.pri
src/domain/domain.pri
+4
-2
UBMagnifer.cpp
src/gui/UBMagnifer.cpp
+402
-388
UBMagnifer.h
src/gui/UBMagnifer.h
+97
-96
No files found.
Sankore_3.1.pro
View file @
d8bc5839
...
...
@@ -131,7 +131,7 @@ win32 {
}
macx {
LIBS += "-Lplugins/cffadaptor/lib/mac" "-lCFF_Adaptor"
LIBS += "-Lplugins/cffadaptor/lib/mac
x
" "-lCFF_Adaptor"
LIBS += -framework Foundation
LIBS += -lcrypto
LIBS += -framework AppKit
...
...
plugins/cffadaptor/UBCFFAdaptor.pro
View file @
d8bc5839
...
...
@@ -10,14 +10,16 @@ linux-g++: SUB_DIR = linux
linux
-
g
++-
32
:
SUB_DIR
=
linux
linux
-
g
++-
64
:
SUB_DIR
=
linux
QUAZIP_DIR
=
"$$PWD/../../../Sankore-ThirdParty/quazip"
ZLIB_DIR
=
"$$PWD/../../../Sankore-ThirdParty/zlib
"
THIRD_PARTY_PATH
=
..
/../../
Sankore
-
ThirdParty
QUAZIP_DIR
=
"$$PWD/../../../Sankore-ThirdParty/quazip/quazip-0.3
"
INCLUDEPATH
+=
src
\
"$$QUAZIP_DIR/quazip-0.3"
\
"$$ZLIB_DIR/1.2.3/include"
INCLUDEPATH
+=
src
LIBS
+=
"-L$$QUAZIP_DIR/lib/$$SUB_DIR"
"-lquazip"
DEPENDPATH
+=
$$
THIRD_PARTY_PATH
/
quazip
/
INCLUDEPATH
+=
$$
THIRD_PARTY_PATH
/
quazip
/
include
(
$$
THIRD_PARTY_PATH
/
quazip
/
quazip
.
pri
)
LIBS
+=
"-L$$THIRD_PARTY_PATH/quazip/lib/$$SUB_DIR"
"-lquazip"
QT
+=
xml
xmlpatterns
core
QT
+=
gui
...
...
resources/library/interactivities/Choisir.wgt/scripts/languages.js
View file @
d8bc5839
...
...
@@ -6,20 +6,20 @@ var sankoreLang = {
"example_question"
:
"This is an example of the question"
,
"answer"
:
"This is an example of the answer"
,
"q"
:
"Q"
,
"add_new_question"
:
"Add new question ..."
,
"add_new_question"
:
"Add
a
new question ..."
,
"options"
:
"Options"
,
"close"
:
"Close"
,
"delete_question"
:
"Delete question"
,
"delete_answer"
:
"Delete a
nswer
"
,
"delete_question"
:
"Delete
the
question"
,
"delete_answer"
:
"Delete a
possibility
"
,
"right_answer"
:
"Right answer"
,
"template_question"
:
"Enter
your
question here ..."
,
"template_answer"
:
"Enter
the answer
here ..."
,
"add_answer"
:
"Add a
nswer
"
,
"template_question"
:
"Enter
a
question here ..."
,
"template_answer"
:
"Enter
a possibility
here ..."
,
"add_answer"
:
"Add a
possibility
"
,
"select_text"
:
"Choose the right answer"
,
"options_desc"
:
"
You can choose any of these three options of displaying your answers. See a short their description.
"
,
"radio_desc"
:
"
This option allow to choose one answer only and the answer
s are displayed as radio buttons."
,
"checkbox_desc"
:
"
This option allow to choose several answers and the answer
s are displayed as checkboxes."
,
"select_desc"
:
"
This option allow to chose one answer only and the answer
s are displayed as pull-down menu."
,
"options_desc"
:
"
Types of question
"
,
"radio_desc"
:
"
Option 1 : one right answer, possibilitie
s are displayed as radio buttons."
,
"checkbox_desc"
:
"
Option 2 : several right answers, possibilitie
s are displayed as checkboxes."
,
"select_desc"
:
"
Option 3 : one right answer, possibilitie
s are displayed as pull-down menu."
,
"a"
:
"A"
},
"ru"
:{
...
...
@@ -49,23 +49,23 @@ var sankoreLang = {
"edit"
:
"Modifier"
,
"display"
:
"Afficher"
,
"question"
:
"La question"
,
"example_question"
:
"Ceci est un exemple de
la
question"
,
"answer"
:
"Ceci est un exemple de
la
réponse"
,
"example_question"
:
"Ceci est un exemple de question"
,
"answer"
:
"Ceci est un exemple de réponse"
,
"q"
:
"Q"
,
"add_new_question"
:
"Ajouter nouvelle question ..."
,
"options"
:
"
Les o
ptions"
,
"add_new_question"
:
"Ajouter
une
nouvelle question ..."
,
"options"
:
"
O
ptions"
,
"close"
:
"Fermer"
,
"delete_question"
:
"Supprimer la question"
,
"delete_answer"
:
"Supprimer
réponse
"
,
"delete_answer"
:
"Supprimer
la possibilité
"
,
"right_answer"
:
"Bonne réponse"
,
"template_question"
:
"Saisi
ssez votre
question ici ..."
,
"template_answer"
:
"
Entrez la réponse
ici ..."
,
"add_answer"
:
"Ajouter une
réponse
"
,
"select_text"
:
"Choisi
ssez
la bonne réponse"
,
"options_desc"
:
"
Vous pouvez choisir n'importe lequel de ces trois options d'affichage de vos réponses. Voir un court leur description.
"
,
"radio_desc"
:
"
Cette option permet de choisir une seule réponse et les réponse
s sont affichées sous forme de boutons radio."
,
"checkbox_desc"
:
"
Cette option permet de choisir plusieurs réponses et les réponses sont affichées comme des
cases à cocher."
,
"select_desc"
:
"
Cette option permet de choisir une seule réponse et les réponse
s sont affichées sous forme de menu déroulant."
,
"template_question"
:
"Saisi
r la
question ici ..."
,
"template_answer"
:
"
Saisir une possibilité
ici ..."
,
"add_answer"
:
"Ajouter une
possibilité
"
,
"select_text"
:
"Choisi
r
la bonne réponse"
,
"options_desc"
:
"
Types de questions
"
,
"radio_desc"
:
"
Option 1 : une seule bonne réponse, les possibilité
s sont affichées sous forme de boutons radio."
,
"checkbox_desc"
:
"
Option 2 : plusieurs bonnes réponses, les possibilités sont affichées sous forme de
cases à cocher."
,
"select_desc"
:
"
Option 3 : une seule bonne réponse, les possibilité
s sont affichées sous forme de menu déroulant."
,
"a"
:
"R"
}
};
...
...
resources/library/interactivities/associer_images.wgt/js/script.js
View file @
d8bc5839
...
...
@@ -3,7 +3,7 @@ var sankoreLang = {
edit
:
"Edit"
,
short_desc
:
"Select the number
\"
three
\"
."
,
add
:
"Add new block"
,
enter
:
"Enter
your condition
here ..."
enter
:
"Enter
what to do
here ..."
};
//main function
...
...
resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"Affich
age
"
,
display
:
"Affich
er
"
,
edit
:
"Modifier"
,
short_desc
:
"Sélectionner le numéro «trois»."
,
add
:
"Nouveau bloc"
,
enter
:
"Saisi
ssez
la consigne ici ..."
enter
:
"Saisi
r
la consigne ici ..."
};
//main function
...
...
resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"
D'affichage
"
,
display
:
"
Afficher
"
,
edit
:
"Modifier"
,
short_desc
:
"Combien de signaux entendez-vous?"
,
short_desc
:
"Combien de signaux
sonores
entendez-vous?"
,
add
:
"Nouveau bloc"
,
enter
:
"
Entrez
votre description ici ..."
enter
:
"
Saisir
votre description ici ..."
};
//main function
...
...
resources/library/interactivities/categoriser_images.wgt/js/script.js
View file @
d8bc5839
...
...
@@ -3,7 +3,7 @@ var sankoreLang = {
edit
:
"Edit"
,
first_desc
:
"Odd numbers"
,
second_desc
:
"Even numbers"
,
enter
:
"Enter
your
category name here ..."
,
enter
:
"Enter
a
category name here ..."
,
add
:
"Add new block"
};
...
...
resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"
D'affichage
"
,
display
:
"
Afficher
"
,
edit
:
"Modifier"
,
first_desc
:
"Les nombres impairs"
,
second_desc
:
"
Même les chiffre
s"
,
enter
:
"
Entrez votr
e nom de la catégorie ici ..."
,
second_desc
:
"
Les nombres pair
s"
,
enter
:
"
Saisir l
e nom de la catégorie ici ..."
,
add
:
"Nouveau bloc"
};
...
...
resources/library/interactivities/categoriser_text.wgt/js/script.js
View file @
d8bc5839
...
...
@@ -3,12 +3,12 @@ var sankoreLang = {
edit
:
"Edit"
,
first_desc
:
"Fruits"
,
second_desc
:
"Vegetables"
,
potatoes
:
"Potato
es
"
,
potatoes
:
"Potato"
,
carrot
:
"Carrot"
,
onion
:
"Onion"
,
apple
:
"Apple"
,
pear
:
"Pear"
,
enter
:
"Enter
your
category name here ..."
,
enter
:
"Enter
a
category name here ..."
,
add
:
"Add new block"
,
text
:
"Some text"
};
...
...
resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"
D'affichage
"
,
display
:
"
Afficher
"
,
edit
:
"Modifier"
,
first_desc
:
"Fruits"
,
second_desc
:
"Légumes"
,
potatoes
:
"Pomme
s
de terre"
,
potatoes
:
"Pomme de terre"
,
carrot
:
"Carotte"
,
onion
:
"Oignon"
,
apple
:
"Pomme"
,
pear
:
"Poire"
,
enter
:
"
Entrez votr
e nom de la catégorie ici ..."
,
enter
:
"
Saisir l
e nom de la catégorie ici ..."
,
add
:
"Nouveau bloc"
,
text
:
"Texte"
};
...
...
resources/library/interactivities/etudier.wgt/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"Display"
,
edit
:
"Edit"
,
text_content
:
"This is an example. Instead of this text you can put your own content
.
"
,
text_content
:
"This is an example. Instead of this text you can put your own content
or drag an drop a picture or an audio file
"
,
new_txt
:
"New text block"
,
new_slide
:
"This is new slide."
new_slide
:
"This is
a
new slide."
};
//some flags
...
...
resources/library/interactivities/etudier.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"
D'affichage
"
,
display
:
"
Afficher
"
,
edit
:
"Modifier"
,
text_content
:
"Ceci est un exemple. Au lieu de ce texte, vous pouvez
mettre votre propre contenu
."
,
text_content
:
"Ceci est un exemple. Au lieu de ce texte, vous pouvez
saisir votre propre texte ou glisser-dposer une image, un son.
"
,
new_txt
:
"Nouveau bloc de texte"
,
new_slide
:
"C
'
est une nouvelle diapositive."
new_slide
:
"C
eci
est une nouvelle diapositive."
};
//some flags
...
...
resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js
View file @
d8bc5839
...
...
@@ -26,9 +26,9 @@ function checkResponse()
*/
var
sankoreLang
=
{
view
:
"
D'affichage
"
,
view
:
"
Afficher
"
,
edit
:
"Modifier"
,
example
:
"
il
\n
s'agit
\n
d'une
\n
phrase
\n
d'exemple
"
example
:
"
Cette phrase
\n
est un
\n
exemple.
"
};
...
...
resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js
View file @
d8bc5839
...
...
@@ -27,9 +27,9 @@ function checkResponse()
*/
var
sankoreLang
=
{
view
:
"
D'affichage
"
,
view
:
"
Afficher
"
,
edit
:
"Modifier"
,
example
:
"
une*longue*,*il*ya*bien*longtemp
s*..."
example
:
"
Il*était*une*foi
s*..."
};
var
word
=
""
;
...
...
resources/library/interactivities/ordonner_des_images.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"Affich
age
"
,
display
:
"Affich
er
"
,
edit
:
"Modifier"
,
short_desc
:
"Place
z
les photos dans l'ordre croissant."
,
short_desc
:
"Place
r
les photos dans l'ordre croissant."
,
add
:
"Nouveau bloc"
,
enter
:
"Saisi
ssez
votre texte ici ..."
enter
:
"Saisi
r
votre texte ici ..."
};
//main function
...
...
resources/library/interactivities/ordonner_des_letters.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"
D'affichage
"
,
display
:
"
Afficher
"
,
edit
:
"Modifier"
,
short_desc
:
"Ecoute
z le son et faire le bon mot
."
,
short_desc
:
"Ecoute
r le son et replacer les lettres dans l'ordre
."
,
add
:
"Nouveau bloc"
,
enter
:
"
Entrez votre description
ici ..."
,
enter
:
"
Saisir la consigne
ici ..."
,
example
:
"exemple"
};
...
...
resources/library/interactivities/selectionner.wgt/locales/fr/js/script.js
View file @
d8bc5839
var
sankoreLang
=
{
display
:
"Affichage"
,
edit
:
"Modifier"
,
short_desc
:
"Sélectionne
z les animaux de la liste suivante
:"
,
short_desc
:
"Sélectionne
r les animaux dans la liste suivante
:"
,
add
:
"Nouveau bloc"
,
enter
:
"Saisi
ssez votr
e texte ici ..."
,
enter
:
"Saisi
r l
e texte ici ..."
,
cat
:
"chat"
,
ball
:
"balle"
,
shovel
:
"pelle"
,
...
...
resources/library/interactivities/spl-phrase.wgt/locales/fr/scripts/wcontainer.js
View file @
d8bc5839
var
sankoreLang
=
{
view
:
"
D'affichage
"
,
view
:
"
Afficher
"
,
edit
:
"Modifier"
,
example
:
"
c'est un tas de mots qui ne devraient être répartis à par
t"
example
:
"
Ceci est une série de mots à séparer correctemen
t"
};
// if use the "view/edit" button or rely on the api instead
...
...
resources/library/interactivities/spl-text.wgt/locales/fr/scripts/wcontainer.js
View file @
d8bc5839
var
sankoreLang
=
{
view
:
"
D'affichage
"
,
view
:
"
Afficher
"
,
edit
:
"Modifier"
,
example
:
"bonjour, ceci est la première phrase. salut, c'est la deuxième phrase. bonjour à nouveau, c'est la troisième phrase. bonjour, c'est la quatrième phrase. salut, désolé, je suis en retard, je suis la cinquième phrase."
};
...
...
resources/library/interactivities/spl-word.wgt/locales/fr/scripts/wcontainer.js
View file @
d8bc5839
var
sankoreLang
=
{
view
:
"
D'affichage
"
,
view
:
"
Afficher
"
,
edit
:
"Modifier"
,
example
:
"so*phis*ti*qué"
};
...
...
src/board/UBBoardController.cpp
View file @
d8bc5839
...
...
@@ -664,6 +664,7 @@ void UBBoardController::zoom(const qreal ratio, QPointF scenePoint)
UBApplication
::
applicationController
->
adjustDisplayView
();
emit
controlViewportChanged
();
mActiveScene
->
setBackgroundZoomFactor
(
mControlView
->
transform
().
m11
());
}
...
...
@@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
mControlView
->
setScene
(
mActiveScene
);
mDisplayView
->
setScene
(
mActiveScene
);
mActiveScene
->
setBackgroundZoomFactor
(
mControlView
->
transform
().
m11
());
pDocumentProxy
->
setDefaultDocumentSize
(
mActiveScene
->
nominalSize
());
updatePageSizeState
();
...
...
@@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor()
mControlView
->
setTransform
(
scalingTransform
);
mControlView
->
horizontalScrollBar
()
->
setValue
(
viewState
.
horizontalPosition
);
mControlView
->
verticalScrollBar
()
->
setValue
(
viewState
.
verticalPostition
);
}
mActiveScene
->
setBackgroundZoomFactor
(
mControlView
->
transform
().
m11
());
}
void
UBBoardController
::
setWidePageSize
(
bool
checked
)
...
...
src/board/UBBoardView.cpp
View file @
d8bc5839
...
...
@@ -54,6 +54,7 @@
#include "tools/UBGraphicsCompass.h"
#include "tools/UBGraphicsCache.h"
#include "tools/UBGraphicsTriangle.h"
#include "core/memcheck.h"
...
...
@@ -425,7 +426,9 @@ UBBoardView::mousePressEvent (QMouseEvent *event)
||
movingItem
->
type
()
==
UBGraphicsCompass
::
Type
||
movingItem
->
type
()
==
UBGraphicsPDFItem
::
Type
||
movingItem
->
type
()
==
UBGraphicsPolygonItem
::
Type
||
movingItem
->
type
()
==
UBGraphicsCache
::
Type
)
||
movingItem
->
type
()
==
UBGraphicsCache
::
Type
||
movingItem
->
type
()
==
UBGraphicsTriangle
::
Type
||
movingItem
==
this
->
scene
()
->
backgroundObject
())
{
movingItem
=
NULL
;
QGraphicsView
::
mousePressEvent
(
event
);
...
...
src/core/UBSettings.cpp
View file @
d8bc5839
...
...
@@ -378,6 +378,8 @@ void UBSettings::init()
KeyboardLocale
=
new
UBSetting
(
this
,
"Board"
,
"StartupKeyboardLocale"
,
0
);
swapControlAndDisplayScreens
=
new
UBSetting
(
this
,
"App"
,
"SwapControlAndDisplayScreens"
,
false
);
angleTolerance
=
new
UBSetting
(
this
,
"App"
,
"AngleTolerance"
,
4
);
}
...
...
@@ -1140,3 +1142,4 @@ QString UBSettings::replaceWildcard(QString& path)
return
result
;
}
src/core/UBSettings.h
View file @
d8bc5839
...
...
@@ -97,8 +97,7 @@ class UBSettings : public QObject
void
setCommunityPassword
(
const
QString
&
password
);
void
init
();
//user directories
static
QString
userDataDirectory
();
static
QString
userDocumentDirectory
();
...
...
@@ -327,6 +326,8 @@ class UBSettings : public QObject
UBSetting
*
KeyboardLocale
;
UBSetting
*
swapControlAndDisplayScreens
;
UBSetting
*
angleTolerance
;
public
slots
:
void
setPenWidthIndex
(
int
index
);
...
...
src/desktop/UBDesktopAnnotationController.cpp
View file @
d8bc5839
...
...
@@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingScene
=
new
UBGraphicsScene
(
0
);
mTransparentDrawingView
->
setScene
(
mTransparentDrawingScene
);
mTransparentDrawingScene
->
setDrawingMode
(
true
);
// mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView);
//mRightPalette = new UBRightPalette(mTransparentDrawingView);
...
...
src/domain/UBAngleWidget.cpp
0 → 100644
View file @
d8bc5839
#include "UBAngleWidget.h"
#include <QPainter>
UBAngleWidget
::
UBAngleWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
{
this
->
setFixedSize
(
45
,
30
);
this
->
setWindowFlags
(
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
);
this
->
setAttribute
(
Qt
::
WA_TranslucentBackground
);
QImage
mask_img
(
width
(),
height
(),
QImage
::
Format_Mono
);
mask_img
.
fill
(
0xff
);
QPainter
mask_ptr
(
&
mask_img
);
mask_ptr
.
setBrush
(
QBrush
(
QColor
(
0
,
0
,
0
)
)
);
mask_ptr
.
drawRoundedRect
(
0
,
0
,
this
->
geometry
().
width
()
-
6
,
this
->
geometry
().
height
()
-
6
,
1
,
1
);
bmpMask
=
QBitmap
::
fromImage
(
mask_img
);
this
->
setMask
(
bmpMask
);
}
UBAngleWidget
::~
UBAngleWidget
()
{
}
void
UBAngleWidget
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
);
this
->
move
(
this
->
cursor
().
pos
().
x
(),
this
->
cursor
().
pos
().
y
()
-
30
);
QPainter
painter
(
this
);
painter
.
setRenderHints
(
QPainter
::
Antialiasing
|
QPainter
::
SmoothPixmapTransform
);
QBrush
brush
(
Qt
::
white
);
painter
.
setBrush
(
brush
);
painter
.
drawRoundedRect
(
1
,
1
,
this
->
geometry
().
width
()
-
10
,
this
->
geometry
().
height
()
-
10
,
1
,
1
);
painter
.
setPen
(
QColor
(
85
,
50
,
127
));
painter
.
setFont
(
QFont
(
"Arial"
,
10
));
painter
.
drawText
(
1
,
1
,
this
->
geometry
().
width
()
-
10
,
this
->
geometry
().
height
()
-
10
,
Qt
::
AlignCenter
,
text
);
}
void
UBAngleWidget
::
setText
(
QString
newText
)
{
text
=
newText
;
text
.
append
(
QChar
(
176
));
}
\ No newline at end of file
src/domain/UBAngleWidget.h
0 → 100644
View file @
d8bc5839
#ifndef UBANGLEWIDGET_H
#define UBANGLEWIDGET_H
#include <QWidget>
#include <QBitmap>
class
UBAngleWidget
:
public
QWidget
{
Q_OBJECT
public
:
UBAngleWidget
(
QWidget
*
parent
=
0
);
~
UBAngleWidget
();
void
setText
(
QString
);
protected
:
void
paintEvent
(
QPaintEvent
*
event
);
private
:
QString
text
;
QBitmap
bmpMask
;
};
#endif // UBANGLEWIDGET_H
src/domain/UBGraphicsDelegateFrame.cpp
View file @
d8bc5839
...
...
@@ -29,8 +29,6 @@
#include "core/memcheck.h"
qreal
const
UBGraphicsDelegateFrame
::
mAngleTolerance
=
6
;
UBGraphicsDelegateFrame
::
UBGraphicsDelegateFrame
(
UBGraphicsItemDelegate
*
pDelegate
,
QRectF
pRect
,
qreal
pFrameWidth
,
bool
respectRatio
)
:
QGraphicsRectItem
(),
QObject
(
pDelegate
)
,
mCurrentTool
(
None
)
...
...
@@ -48,7 +46,11 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
,
mTotalTranslateX
(
0
)
,
mTotalTranslateY
(
0
)
,
mOperationMode
(
Scaling
)
,
mMirrorX
(
false
)
,
mMirrorY
(
false
)
{
mAngleTolerance
=
UBSettings
::
settings
()
->
angleTolerance
->
get
().
toReal
();
setFlag
(
QGraphicsItem
::
ItemSendsGeometryChanges
,
true
);
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
...
...
@@ -69,9 +71,11 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
mBottomResizeGrip
=
new
QGraphicsRectItem
(
this
);
mBottomResizeGrip
->
setPen
(
Qt
::
NoPen
);
mLeftResizeGrip
=
new
QGraphicsRectItem
(
this
);
mLeftResizeGrip
->
setToolTip
(
"left"
);
mLeftResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRightResizeGrip
=
new
QGraphicsRectItem
(
this
);
mRightResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRightResizeGrip
->
setToolTip
(
"Right"
);
mTopResizeGrip
=
new
QGraphicsRectItem
(
this
);
mTopResizeGrip
->
setPen
(
Qt
::
NoPen
);
...
...
@@ -86,11 +90,14 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
positionHandles
();
this
->
setAcceptHoverEvents
(
true
);
angleWidget
=
new
UBAngleWidget
();
}
UBGraphicsDelegateFrame
::~
UBGraphicsDelegateFrame
()
{
delete
angleWidget
;
// NOOP
}
...
...
@@ -156,14 +163,39 @@ void UBGraphicsDelegateFrame::initializeTransform()
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
qreal
horizontalFlip
=
(
topLeft
.
x
()
>
topRight
.
x
())
?
-
1
:
1
;
mMirrorX
=
horizontalFlip
<
0
;
if
(
horizontalFlip
<
0
){
// why this is because of the way of calculating the translations that checks which side is the most is the
// nearest instead of checking which one is the left side.
QPointF
tmp
=
topLeft
;
topLeft
=
topRight
;
topRight
=
tmp
;
// because of the calculation of the height is done by lenght and not deltaY
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
}
qreal
verticalFlip
=
(
bottomLeft
.
y
()
<
topLeft
.
y
())
?
-
1
:
1
;
// not sure that is usefull
mMirrorY
=
verticalFlip
<
0
;
if
(
verticalFlip
<
0
&&
!
mMirrorX
){
topLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
topRight
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
bottomLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
}
QLineF
topLine
(
topLeft
,
topRight
);
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
width
=
topLine
.
length
();
qreal
height
=
leftLine
.
length
();
mAngle
=
topLine
.
angle
();
mTotalScaleX
=
width
/
itemRect
.
width
();
mTotalScaleY
=
height
/
itemRect
.
height
();
//the fact the the lenght is used we loose the horizontalFlip information
// a better way to do this is using DeltaX that preserve the direction information.
mTotalScaleX
=
(
width
/
itemRect
.
width
())
*
horizontalFlip
;
mTotalScaleY
=
height
/
itemRect
.
height
()
*
verticalFlip
;
QTransform
tr
;
QPointF
center
=
delegated
()
->
boundingRect
().
center
();
...
...
@@ -192,6 +224,7 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
mAngleOffset
=
0
;
mInitialTransform
=
buildTransform
();
mCurrentTool
=
toolFromPos
(
event
->
pos
());
event
->
accept
();
...
...
@@ -205,9 +238,16 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
qreal
moveY
=
-
move
.
length
()
*
sin
((
move
.
angle
()
-
mAngle
)
*
PI
/
180
);
qreal
width
=
delegated
()
->
boundingRect
().
width
()
*
mTotalScaleX
;
qreal
height
=
delegated
()
->
boundingRect
().
height
()
*
mTotalScaleY
;
mTranslateX
=
moveX
;
if
(
mOperationMode
==
Scaling
)
{
// // Hide the buttons
// mDelegate->setButtonsVisible(false);
// mResizing = true;
// Perform the resize
if
(
resizingBottomRight
())
{
// -----------------------------------------------------
...
...
@@ -243,8 +283,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
scaleX
=
(
width
+
moveX
)
/
width
;
}
if
(
mDelegate
->
isFlippable
()
&&
qAbs
(
scaleX
)
!=
0
){
if
((
width
*
qAbs
(
scaleX
))
<
2
*
mFrameWidth
){
if
((
qAbs
(
width
*
scaleX
))
<
2
*
mFrameWidth
){
bool
negative
=
(
scaleX
<
0
)
?
true
:
false
;
//mMirrorX = (negative?mMirrorX:!mMirrorX);
if
(
negative
){
scaleX
=
-
2
*
mFrameWidth
/
width
;
}
else
{
...
...
@@ -269,8 +310,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
if
(
mDelegate
->
isFlippable
()
&&
qAbs
(
scaleY
)
!=
0
){
if
((
height
*
qAbs
(
scaleY
))
<
2
*
mFrameWidth
){
if
((
qAbs
(
height
*
scaleY
))
<
2
*
mFrameWidth
){
bool
negative
=
(
scaleY
<
0
)
?
true
:
false
;
//mMirrorY = (negative?mMirrorY:!mMirrorY);
if
(
negative
){
scaleY
=
-
2
*
mFrameWidth
/
width
;
}
else
{
...
...
@@ -281,7 +323,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
else
if
(
scaleY
>
1
||
(
height
*
scaleY
)
>
2
*
mFrameWidth
)
{
mScaleY
=
scaleY
;
mTranslateY
=
moveY
;
if
(
resizingTop
()){
mTranslateY
=
moveY
;
}
}
}
}
...
...
@@ -331,7 +375,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QLineF
startLine
(
sceneBoundingRect
().
center
(),
event
->
lastScenePos
());
QLineF
currentLine
(
sceneBoundingRect
().
center
(),
event
->
scenePos
());
mAngle
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngle
%
45
>=
45
-
mAngleTolerance
||
(
int
)
mAngle
%
45
<=
mAngleTolerance
)
if
((
int
)
mAngle
%
45
>=
45
-
mAngleTolerance
||
(
int
)
mAngle
%
45
<=
mAngleTolerance
)
{
mAngle
=
qRound
(
mAngle
/
45
)
*
45
;
mAngleOffset
+=
startLine
.
angleTo
(
currentLine
);
...
...
@@ -341,6 +387,23 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mAngleOffset
=
0
;
}
}
else
if
((
int
)
mAngle
%
30
>=
30
-
mAngleTolerance
||
(
int
)
mAngle
%
30
<=
mAngleTolerance
)
{
mAngle
=
qRound
(
mAngle
/
30
)
*
30
;
mAngleOffset
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngleOffset
%
360
>
mAngleTolerance
&&
(
int
)
mAngleOffset
%
360
<
360
-
mAngleTolerance
)
{
mAngle
+=
mAngleOffset
;
mAngleOffset
=
0
;
}
}
if
(
!
angleWidget
->
isVisible
())
angleWidget
->
show
();
angleWidget
->
setText
(
QString
::
number
((
int
)
mAngle
%
360
));
angleWidget
->
update
();
}
else
if
(
moving
())
...
...
@@ -410,6 +473,9 @@ QTransform UBGraphicsDelegateFrame::buildTransform()
void
UBGraphicsDelegateFrame
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
angleWidget
->
isVisible
())
angleWidget
->
hide
();
updateResizeCursors
();
mDelegate
->
commitUndoStep
();
...
...
@@ -421,6 +487,12 @@ void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
mCurrentTool
=
None
;
QGraphicsRectItem
::
mouseReleaseEvent
(
event
);
// Show the buttons
if
(
isResizing
()){
mResizing
=
false
;
}
mDelegate
->
setButtonsVisible
(
true
);
}
...
...
@@ -464,6 +536,14 @@ void UBGraphicsDelegateFrame::positionHandles()
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QPointF
center
=
itemTransform
.
map
(
itemRect
.
center
());
// Handle the mirroring
if
(
topLeft
.
x
()
>
topRight
.
x
()){
QPointF
tmp
=
topRight
;
topRight
=
topLeft
;
topLeft
=
tmp
;
bottomLeft
.
setX
(
topLeft
.
x
());
}
QLineF
topLine
(
topLeft
,
topRight
);
qreal
angle
=
topLine
.
angle
();
qreal
width
=
topLine
.
length
();
...
...
@@ -507,17 +587,8 @@ void UBGraphicsDelegateFrame::positionHandles()
mBottomRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
brRect
.
width
(),
rect
().
bottom
()
-
brRect
.
height
());
mBottomResizeGripSvgItem
->
setPos
(
rect
().
center
().
x
()
-
bRect
.
width
()
/
2
,
rect
().
bottom
()
-
bRect
.
height
());
if
(
0
<=
mScaleX
){
mLeftResizeGripSvgItem
->
setPos
(
rect
().
left
(),
rect
().
center
().
y
()
-
lRect
.
height
()
/
2
);
mRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
rRect
.
width
(),
rect
().
center
().
y
()
-
rRect
.
height
()
/
2
);
}
else
{
mLeftResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
rRect
.
width
(),
rect
().
center
().
y
()
-
lRect
.
height
()
/
2
);
mRightResizeGripSvgItem
->
setPos
(
rect
().
left
()
,
rect
().
center
().
y
()
-
rRect
.
height
()
/
2
);
}
if
(
0
<
mScaleY
){
}
mLeftResizeGripSvgItem
->
setPos
(
rect
().
left
(),
rect
().
center
().
y
()
-
lRect
.
height
()
/
2
);
mRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
rRect
.
width
(),
rect
().
center
().
y
()
-
rRect
.
height
()
/
2
);
mTopResizeGripSvgItem
->
setPos
(
rect
().
center
().
x
()
-
trRect
.
width
()
/
2
,
rect
().
y
());
mRotateButton
->
setPos
(
rect
().
right
()
-
mFrameWidth
-
5
,
rect
().
top
()
+
5
);
...
...
@@ -571,14 +642,35 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF
return
None
;
else
if
(
bottomRightResizeGripRect
().
contains
(
pos
))
return
ResizeBottomRight
;
else
if
(
bottomResizeGripRect
().
contains
(
pos
))
return
ResizeBottom
;
else
if
(
leftResizeGripRect
().
contains
(
pos
))
return
ResizeLeft
;
else
if
(
rightResizeGripRect
().
contains
(
pos
))
return
ResizeRight
;
else
if
(
topResizeGripRect
().
contains
(
pos
))
return
ResizeTop
;
else
if
(
bottomResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorY
){
return
ResizeTop
;
}
else
{
return
ResizeBottom
;
}
}
else
if
(
leftResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorX
){
return
ResizeRight
;
}
else
{
return
ResizeLeft
;
}
return
ResizeLeft
;
}
else
if
(
rightResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorX
){
return
ResizeLeft
;
}
else
{
return
ResizeRight
;
}
}
else
if
(
topResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorY
){
return
ResizeBottom
;
}
else
{
return
ResizeTop
;
}
}
else
if
(
rotateButtonBounds
().
contains
(
pos
)
&&
mDelegate
&&
mDelegate
->
canRotate
())
return
Rotate
;
else
...
...
@@ -621,3 +713,21 @@ QRectF UBGraphicsDelegateFrame::rotateButtonBounds() const
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
top
(),
mFrameWidth
,
mFrameWidth
);
}
void
UBGraphicsDelegateFrame
::
refreshGeometry
()
{
// Here we want to have the left on the left, the right on the right, the top on the top and the bottom on the bottom!
QRectF
itemRect
=
delegated
()
->
boundingRect
();
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QPointF
center
=
itemTransform
.
map
(
itemRect
.
center
());
QLineF
topLine
(
topLeft
,
topRight
);
qreal
angle
=
topLine
.
angle
();
qreal
width
=
topLine
.
length
();
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
height
=
leftLine
.
length
();
setRect
(
topRight
.
x
()
-
mFrameWidth
,
topLeft
.
y
()
-
mFrameWidth
,
width
+
2
*
mFrameWidth
,
height
+
2
*
mFrameWidth
);
}
src/domain/UBGraphicsDelegateFrame.h
View file @
d8bc5839
...
...
@@ -18,6 +18,7 @@
#include <QtGui>
#include "core/UB.h"
#include "domain/UBAngleWidget.h"
class
QGraphicsSceneMouseEvent
;
class
UBGraphicsItemDelegate
;
...
...
@@ -47,6 +48,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
enum
OperationMode
{
Scaling
,
Resizing
};
void
setOperationMode
(
OperationMode
pMode
)
{
mOperationMode
=
pMode
;}
bool
isResizing
(){
return
mResizing
;}
private
:
QRectF
bottomRightResizeGripRect
()
const
;
...
...
@@ -69,8 +71,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
void
initializeTransform
();
enum
FrameTool
{
None
,
Move
,
Rotate
,
ResizeBottomRight
,
ResizeTop
,
ResizeRight
,
ResizeBottom
,
ResizeLeft
};
FrameTool
toolFromPos
(
QPointF
pos
);
FrameTool
toolFromPos
(
QPointF
pos
);
void
refreshGeometry
(
);
FrameTool
mCurrentTool
;
UBGraphicsItemDelegate
*
mDelegate
;
...
...
@@ -90,7 +92,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
qreal
mTranslateY
;
qreal
mTotalTranslateX
;
qreal
mTotalTranslateY
;
static
const
qreal
mAngleTolerance
;
qreal
mAngleTolerance
;
QRect
mAngleRect
;
QPointF
mStartingPoint
;
QTransform
mInitialTransform
;
...
...
@@ -111,5 +114,13 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
OperationMode
mOperationMode
;
QGraphicsItem
*
delegated
();
bool
mMirrorX
;
bool
mMirrorY
;
bool
mResizing
;
bool
mMirroredXAtStart
;
bool
mMirroredYAtStart
;
UBAngleWidget
*
angleWidget
;
};
#endif
/* UBGRAPHICSDELEGATEFRAME_H_ */
src/domain/UBGraphicsItemDelegate.cpp
View file @
d8bc5839
...
...
@@ -268,7 +268,6 @@ void UBGraphicsItemDelegate::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
// }
}
void
UBGraphicsItemDelegate
::
positionHandles
()
{
if
(
mDelegated
->
isSelected
())
{
...
...
@@ -560,7 +559,7 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
mDelegated
->
scene
()
->
addItem
(
mDeleteButton
);
}
if
(
showUpdated
)
if
(
showUpdated
/*&& mFrame->isResizing()*/
)
mDeleteButton
->
show
();
int
i
=
1
,
j
=
0
,
k
=
0
;
...
...
@@ -587,3 +586,10 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
}
}
}
void
UBGraphicsItemDelegate
::
setButtonsVisible
(
bool
visible
)
{
foreach
(
DelegateButton
*
pButton
,
mButtons
){
pButton
->
setVisible
(
visible
);
}
}
src/domain/UBGraphicsItemDelegate.h
View file @
d8bc5839
...
...
@@ -136,6 +136,8 @@ class UBGraphicsItemDelegate : public QObject
void
setFlippable
(
bool
flippable
);
bool
isFlippable
();
void
setButtonsVisible
(
bool
visible
);
signals
:
void
showOnDisplayChanged
(
bool
shown
);
void
lockChanged
(
bool
locked
);
...
...
src/domain/UBGraphicsPixmapItem.cpp
View file @
d8bc5839
...
...
@@ -32,7 +32,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent)
mDelegate
->
init
();
// NOTE: Do not remove this code, I'm just doing a backup of my changes! thx..
//
mDelegate->setFlippable(true);
mDelegate
->
setFlippable
(
true
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
UBItemLayerType
::
Object
);
setTransformationMode
(
Qt
::
SmoothTransformation
);
...
...
src/domain/UBGraphicsScene.cpp
View file @
d8bc5839
...
...
@@ -268,6 +268,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
,
magniferControlViewWidget
(
0
)
,
magniferDisplayViewWidget
(
0
)
,
mZLayerController
(
new
UBZLayerController
(
this
))
,
mIsDesktopMode
(
false
)
{
#ifdef __ppc__
...
...
@@ -292,8 +293,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
UBGraphicsScene
::~
UBGraphicsScene
()
{
DisposeMagnifierQWidgets
();
if
(
mCurrentStroke
)
if
(
mCurrentStroke
->
polygons
().
empty
())
delete
mCurrentStroke
;
...
...
@@ -846,6 +845,15 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed)
}
}
void
UBGraphicsScene
::
setBackgroundZoomFactor
(
qreal
zoom
)
{
mZoomFactor
=
zoom
;
}
void
UBGraphicsScene
::
setDrawingMode
(
bool
bModeDesktop
)
{
mIsDesktopMode
=
bModeDesktop
;
}
void
UBGraphicsScene
::
recolorAllItems
()
{
...
...
@@ -2005,6 +2013,58 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems,
}
}
void
UBGraphicsScene
::
drawBackground
(
QPainter
*
painter
,
const
QRectF
&
rect
)
{
if
(
mIsDesktopMode
)
{
QGraphicsScene
::
drawBackground
(
painter
,
rect
);
return
;
}
bool
darkBackground
=
isDarkBackground
();
if
(
darkBackground
)
{
painter
->
fillRect
(
rect
,
QBrush
(
QColor
(
Qt
::
black
)));
}
else
{
painter
->
fillRect
(
rect
,
QBrush
(
QColor
(
Qt
::
white
)));
}
if
(
mZoomFactor
>
0.5
)
{
QColor
bgCrossColor
;
if
(
darkBackground
)
bgCrossColor
=
UBSettings
::
crossDarkBackground
;
else
bgCrossColor
=
UBSettings
::
crossLightBackground
;
if
(
mZoomFactor
<
1.0
)
{
int
alpha
=
255
*
mZoomFactor
/
2
;
bgCrossColor
.
setAlpha
(
alpha
);
// fade the crossing on small zooms
}
painter
->
setPen
(
bgCrossColor
);
if
(
isCrossedBackground
())
{
qreal
firstY
=
((
int
)
(
rect
.
y
()
/
UBSettings
::
crossSize
))
*
UBSettings
::
crossSize
;
for
(
qreal
yPos
=
firstY
;
yPos
<
rect
.
y
()
+
rect
.
height
();
yPos
+=
UBSettings
::
crossSize
)
{
painter
->
drawLine
(
rect
.
x
(),
yPos
,
rect
.
x
()
+
rect
.
width
(),
yPos
);
}
qreal
firstX
=
((
int
)
(
rect
.
x
()
/
UBSettings
::
crossSize
))
*
UBSettings
::
crossSize
;
for
(
qreal
xPos
=
firstX
;
xPos
<
rect
.
x
()
+
rect
.
width
();
xPos
+=
UBSettings
::
crossSize
)
{
painter
->
drawLine
(
xPos
,
rect
.
y
(),
xPos
,
rect
.
y
()
+
rect
.
height
());
}
}
}
}
void
UBGraphicsScene
::
keyReleaseEvent
(
QKeyEvent
*
keyEvent
)
{
...
...
src/domain/UBGraphicsScene.h
View file @
d8bc5839
...
...
@@ -292,7 +292,8 @@ public slots:
void
hideEraser
();
void
setBackground
(
bool
pIsDark
,
bool
pIsCrossed
);
void
setBackgroundZoomFactor
(
qreal
zoom
);
void
setDrawingMode
(
bool
bModeDesktop
);
void
deselectAllItems
();
UBGraphicsPixmapItem
*
addPixmap
(
const
QPixmap
&
pPixmap
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
),
qreal
scaleFactor
=
1
.
0
,
bool
pUseAnimation
=
false
);
...
...
@@ -335,6 +336,8 @@ public slots:
QGraphicsItem
*
rootItem
(
QGraphicsItem
*
item
)
const
;
virtual
void
drawBackground
(
QPainter
*
painter
,
const
QRectF
&
rect
);
private
:
void
setDocumentUpdated
();
void
createEraiser
();
...
...
@@ -350,6 +353,8 @@ public slots:
bool
mDarkBackground
;
bool
mCrossedBackground
;
bool
mIsDesktopMode
;
qreal
mZoomFactor
;
bool
mIsModified
;
...
...
src/domain/domain.pri
View file @
d8bc5839
...
...
@@ -22,7 +22,8 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBGraphicsMediaItem.h \
src/domain/UBGraphicsAudioItem.h \
src/domain/UBGraphicsAudioItemDelegate.h \
src/domain/UBAbstractUndoCommand.h
src/domain/UBAbstractUndoCommand.h\
src/domain/UBAngleWidget.h
HEADERS += src/domain/UBGraphicsItemDelegate.h \
src/domain/UBGraphicsVideoItemDelegate.h \
...
...
@@ -54,7 +55,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBGraphicsMediaItem.cpp \
src/domain/UBGraphicsAudioItem.cpp \
src/domain/UBGraphicsAudioItemDelegate.cpp \
src/domain/UBAbstractUndoCommand.cpp
src/domain/UBAbstractUndoCommand.cpp \
src/domain/UBAngleWidget.cpp
SOURCES += src/domain/UBGraphicsItemDelegate.cpp \
src/domain/UBGraphicsVideoItemDelegate.cpp \
...
...
src/gui/UBMagnifer.cpp
View file @
d8bc5839
/*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include "UBMagnifer.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h"
UBMagnifier
::
UBMagnifier
(
QWidget
*
parent
,
bool
isInteractive
)
:
QWidget
(
parent
,
parent
?
Qt
::
Widget
:
Qt
::
Tool
|
(
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
|
Qt
::
X11BypassWindowManagerHint
))
,
mShouldMoveWidget
(
false
)
,
mShouldResizeWidget
(
false
)
,
inTimer
(
false
)
,
borderPen
(
Qt
::
darkGray
)
,
gView
(
0
)
,
mView
(
0
)
{
isCusrsorAlreadyStored
=
false
;
setMouseTracking
(
true
);
//--------------------------------------------------//
QPixmap
pix
(
":/images/cursors/resize.png"
);
QTransform
tr
;
tr
.
rotate
(
45
);
mResizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
//--------------------------------------------------//
params
.
sizePercentFromScene
=
20
;
m_isInteractive
=
isInteractive
;
sClosePixmap
=
new
QPixmap
(
":/images/close.svg"
);
sIncreasePixmap
=
new
QPixmap
(
":/images/increase.svg"
);
sDecreasePixmap
=
new
QPixmap
(
":/images/decrease.svg"
);
mResizeItem
=
new
QPixmap
(
":/images/resize.svg"
);
if
(
parent
)
{
setAttribute
(
Qt
::
WA_NoMousePropagation
);
}
else
{
// standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
// setAttribute(Qt::WA_TranslucentBackground);
setAttribute
(
Qt
::
WA_MacAlwaysShowToolWindow
);
#endif
#ifdef Q_WS_MAC
setAttribute
(
Qt
::
WA_MacAlwaysShowToolWindow
);
setAttribute
(
Qt
::
WA_MacNonActivatingToolWindow
);
setAttribute
(
Qt
::
WA_MacNoShadow
);
#endif
}
}
UBMagnifier
::~
UBMagnifier
()
{
if
(
timerUpdate
!=
0
)
{
killTimer
(
timerUpdate
);
timerUpdate
=
0
;
}
if
(
sClosePixmap
)
{
delete
sClosePixmap
;
sClosePixmap
=
NULL
;
}
if
(
sIncreasePixmap
)
{
delete
sIncreasePixmap
;
sIncreasePixmap
=
NULL
;
}
if
(
sDecreasePixmap
)
{
delete
sDecreasePixmap
;
sDecreasePixmap
=
NULL
;
}
}
void
UBMagnifier
::
setSize
(
qreal
percentFromScene
)
{
if
(
gView
==
NULL
||
mView
==
NULL
)
return
;
// calculate object size
params
.
sizePercentFromScene
=
percentFromScene
;
QSize
sceneSize
=
mView
->
size
();
qreal
size
=
params
.
sizePercentFromScene
*
sceneSize
.
width
()
/
100
;
QRect
currGeom
=
geometry
();
if
(
currGeom
.
width
()
==
currGeom
.
height
())
{
QPoint
newPos
=
mView
->
mapFromGlobal
(
updPointMove
);
setGeometry
(
newPos
.
x
()
-
size
/
2
,
newPos
.
y
()
-
size
/
2
,
size
,
size
);
}
else
setGeometry
(
0
,
0
,
size
,
size
);
// prepare transparent bit mask
QImage
mask_img
(
width
(),
height
(),
QImage
::
Format_Mono
);
mask_img
.
fill
(
0xff
);
QPainter
mask_ptr
(
&
mask_img
);
mask_ptr
.
setBrush
(
QBrush
(
QColor
(
0
,
0
,
0
)
)
);
mask_ptr
.
drawEllipse
(
QPointF
(
size
/
2
,
size
/
2
),
size
/
2
-
sClosePixmap
->
width
(),
size
/
2
-
sClosePixmap
->
width
());
bmpMask
=
QBitmap
::
fromImage
(
mask_img
);
// prepare general image
pMap
=
QPixmap
(
width
(),
height
());
pMap
.
fill
(
Qt
::
transparent
);
pMap
.
setMask
(
bmpMask
);
}
void
UBMagnifier
::
setZoom
(
qreal
zoom
)
{
params
.
zoom
=
zoom
;
}
void
UBMagnifier
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
);
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
painter
.
setPen
(
Qt
::
NoPen
);
if
(
m_isInteractive
)
{
painter
.
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
.
drawRoundedRect
(
QRectF
(
size
().
width
()
/
2
,
size
().
height
()
/
2
,
(
size
().
width
()
-
sClosePixmap
->
width
()
)
/
2
,
(
size
().
height
()
-
sClosePixmap
->
width
()
)
/
2
),
15
,
15
);
painter
.
setBrush
(
QColor
(
190
,
190
,
190
,
255
));
painter
.
drawEllipse
(
QPoint
(
size
().
width
()
/
2
,
size
().
height
()
/
2
),
(
size
().
width
()
-
sClosePixmap
->
width
()
)
/
2
,
(
size
().
height
()
-
sClosePixmap
->
height
()
)
/
2
);
painter
.
drawPixmap
(
size
().
width
()
-
sClosePixmap
->
width
(),
size
().
height
()
/
2
+
sClosePixmap
->
height
()
*
1
,
*
sClosePixmap
);
painter
.
drawPixmap
(
size
().
width
()
-
sIncreasePixmap
->
width
(),
size
().
height
()
/
2
+
sIncreasePixmap
->
height
()
*
2.5
,
*
sIncreasePixmap
);
painter
.
drawPixmap
(
size
().
width
()
-
sDecreasePixmap
->
width
(),
size
().
height
()
/
2
+
sDecreasePixmap
->
height
()
*
3.6
,
*
sDecreasePixmap
);
painter
.
drawPixmap
(
size
().
width
()
-
mResizeItem
->
width
()
-
20
,
size
().
height
()
-
mResizeItem
->
height
()
-
20
,
*
mResizeItem
);
}
else
{
painter
.
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
.
drawEllipse
(
QPoint
(
size
().
width
()
/
2
,
size
().
height
()
/
2
),
(
size
().
width
()
-
sClosePixmap
->
width
()
)
/
2
,
(
size
().
height
()
-
sClosePixmap
->
height
()
)
/
2
);
}
painter
.
drawPixmap
(
0
,
0
,
pMap
);
}
void
UBMagnifier
::
mousePressEvent
(
QMouseEvent
*
event
)
{
if
(
m_isInteractive
)
{
QWidget
::
mousePressEvent
(
event
);
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
mResizeItem
->
width
()
-
20
&&
event
->
pos
().
x
()
<
size
().
width
()
-
20
&&
event
->
pos
().
y
()
>=
size
().
height
()
-
mResizeItem
->
height
()
-
20
&&
event
->
pos
().
y
()
<
size
().
height
()
-
-
20
)
{
mShouldResizeWidget
=
true
;
}
else
{
mShouldMoveWidget
=
!
event
->
isAccepted
()
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
);
}
mMousePressPos
=
event
->
pos
();
mMousePressDelta
=
(
qreal
)
updPointGrab
.
x
()
+
(
qreal
)
size
().
width
()
/
2
-
(
qreal
)
event
->
globalPos
().
x
();
event
->
accept
();
update
();
}
else
event
->
ignore
();
}
void
UBMagnifier
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
if
(
m_isInteractive
)
{
if
(
mShouldMoveWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
move
(
pos
()
-
mMousePressPos
+
event
->
pos
());
event
->
accept
();
QWidget
::
mouseMoveEvent
(
event
);
emit
magnifierMoved_Signal
(
QPoint
(
this
->
pos
().
x
()
+
size
().
width
()
/
2
,
this
->
pos
().
y
()
+
size
().
height
()
/
2
));
return
;
}
if
(
mShouldResizeWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
QPoint
currGlobalPos
=
event
->
globalPos
();
qreal
cvW
=
mView
->
width
();
qreal
newXSize
=
(
currGlobalPos
.
x
()
+
mMousePressDelta
-
updPointGrab
.
x
()
)
*
2
;
qreal
newPercentSize
=
newXSize
*
100
/
cvW
;
emit
magnifierResized_Signal
(
newPercentSize
);
event
->
ignore
();
return
;
}
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
mResizeItem
->
width
()
-
20
&&
event
->
pos
().
x
()
<
size
().
width
()
-
20
&&
event
->
pos
().
y
()
>=
size
().
height
()
-
mResizeItem
->
height
()
-
20
&&
event
->
pos
().
y
()
<
size
().
height
()
-
-
20
&&
isCusrsorAlreadyStored
==
false
)
{
mOldCursor
=
cursor
();
isCusrsorAlreadyStored
=
true
;
setCursor
(
mResizeCursor
);
}
}
else
event
->
ignore
();
}
void
UBMagnifier
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
if
(
m_isInteractive
)
{
mShouldMoveWidget
=
false
;
mShouldResizeWidget
=
false
;
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
sClosePixmap
->
width
()
&&
event
->
pos
().
x
()
<
size
().
width
()
&&
event
->
pos
().
y
()
>=
size
().
height
()
/
2
+
sClosePixmap
->
height
()
*
1
&&
event
->
pos
().
y
()
<
size
().
height
()
/
2
+
sClosePixmap
->
height
()
*
2
)
{
event
->
accept
();
emit
magnifierClose_Signal
();
}
else
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
sIncreasePixmap
->
width
()
&&
event
->
pos
().
x
()
<
size
().
width
()
&&
event
->
pos
().
y
()
>=
size
().
height
()
/
2
+
sIncreasePixmap
->
height
()
*
2.5
&&
event
->
pos
().
y
()
<
size
().
height
()
/
2
+
sIncreasePixmap
->
height
()
*
3.5
)
{
event
->
accept
();
emit
magnifierZoomIn_Signal
();
}
else
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
sDecreasePixmap
->
width
()
&&
event
->
pos
().
x
()
<
size
().
width
()
&&
event
->
pos
().
y
()
>=
size
().
height
()
/
2
+
sDecreasePixmap
->
height
()
*
3.6
&&
event
->
pos
().
y
()
<
size
().
height
()
/
2
+
sDecreasePixmap
->
height
()
*
4.6
)
{
event
->
accept
();
emit
magnifierZoomOut_Signal
();
}
else
QWidget
::
mouseReleaseEvent
(
event
);
// don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
}
else
event
->
ignore
();
}
void
UBMagnifier
::
timerEvent
(
QTimerEvent
*
e
)
{
if
(
inTimer
)
return
;
if
(
e
->
timerId
()
==
timerUpdate
)
{
inTimer
=
true
;
if
(
!
(
updPointGrab
.
isNull
()))
grabPoint
(
updPointGrab
);
if
(
isCusrsorAlreadyStored
)
{
QPoint
globalCursorPos
=
QCursor
::
pos
();
QPoint
cursorPos
=
mapFromGlobal
(
globalCursorPos
);
if
(
cursorPos
.
x
()
<
size
().
width
()
-
mResizeItem
->
width
()
-
20
||
cursorPos
.
x
()
>
size
().
width
()
-
20
||
cursorPos
.
y
()
<
size
().
height
()
-
mResizeItem
->
height
()
-
20
||
cursorPos
.
y
()
>
size
().
height
()
-
-
20
)
{
isCusrsorAlreadyStored
=
false
;
setCursor
(
mOldCursor
);
}
}
inTimer
=
false
;
}
}
void
UBMagnifier
::
grabPoint
()
{
QPointF
itemPos
=
gView
->
mapFromGlobal
(
updPointGrab
);
qreal
zWidth
=
size
().
width
()
/
params
.
zoom
;
qreal
zWidthHalf
=
zWidth
/
2
;
qreal
zHeight
=
size
().
height
()
/
params
.
zoom
;
qreal
zHeightHalf
=
zHeight
/
2
;
int
x
=
itemPos
.
x
()
-
zWidthHalf
;
int
y
=
itemPos
.
y
()
-
zHeightHalf
;
QPixmap
newPixMap
(
QSize
(
zWidth
,
zHeight
));
((
QWidget
*
)
gView
)
->
render
(
&
newPixMap
,
QPoint
(
0
,
0
),
QRegion
(
x
,
y
,
zWidth
,
zHeight
));
UBApplication
::
boardController
->
activeScene
()
->
update
();
pMap
.
fill
(
Qt
::
transparent
);
pMap
=
newPixMap
.
scaled
(
QSize
(
width
(),
height
()));
pMap
.
setMask
(
bmpMask
);
update
();
}
void
UBMagnifier
::
grabPoint
(
const
QPoint
&
pGrab
)
{
updPointGrab
=
pGrab
;
QPointF
itemPos
=
gView
->
mapFromGlobal
(
pGrab
);
qreal
zWidth
=
size
().
width
()
/
params
.
zoom
;
qreal
zWidthHalf
=
zWidth
/
2
;
qreal
zHeight
=
size
().
height
()
/
params
.
zoom
;
qreal
zHeightHalf
=
zHeight
/
2
;
int
x
=
itemPos
.
x
()
-
zWidthHalf
;
int
y
=
itemPos
.
y
()
-
zHeightHalf
;
QPixmap
newPixMap
(
QSize
(
zWidth
,
zHeight
));
((
QWidget
*
)
gView
)
->
render
(
&
newPixMap
,
QPoint
(
0
,
0
),
QRegion
(
x
,
y
,
zWidth
,
zHeight
));
UBApplication
::
boardController
->
activeScene
()
->
update
();
pMap
.
fill
(
Qt
::
transparent
);
pMap
=
newPixMap
.
scaled
(
QSize
(
width
(),
height
()));
pMap
.
setMask
(
bmpMask
);
update
();
}
// from global
void
UBMagnifier
::
grabNMove
(
const
QPoint
&
pGrab
,
const
QPoint
&
pMove
,
bool
needGrab
,
bool
needMove
)
{
updPointGrab
=
pGrab
;
updPointMove
=
pMove
;
if
(
needGrab
)
grabPoint
(
pGrab
);
if
(
needMove
)
{
QPoint
movePos
=
mView
->
mapFromGlobal
(
pMove
);
move
(
movePos
.
x
()
-
width
()
/
2
,
movePos
.
y
()
-
height
()
/
2
);
// move(itemPos.x(), itemPos.y());
}
}
void
UBMagnifier
::
setGrabView
(
QWidget
*
view
)
{
if
(
timerUpdate
!=
0
)
killTimer
(
timerUpdate
);
gView
=
view
;
timerUpdate
=
startTimer
(
200
);
}
/*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include "UBMagnifer.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardView.h"
#include "core/memcheck.h"
UBMagnifier
::
UBMagnifier
(
QWidget
*
parent
,
bool
isInteractive
)
:
QWidget
(
parent
,
parent
?
Qt
::
Widget
:
Qt
::
Tool
|
(
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
|
Qt
::
X11BypassWindowManagerHint
))
,
mShouldMoveWidget
(
false
)
,
mShouldResizeWidget
(
false
)
,
borderPen
(
Qt
::
darkGray
)
,
gView
(
0
)
,
mView
(
0
)
{
isCusrsorAlreadyStored
=
false
;
setMouseTracking
(
true
);
//--------------------------------------------------//
QPixmap
pix
(
":/images/cursors/resize.png"
);
QTransform
tr
;
tr
.
rotate
(
45
);
mResizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
//--------------------------------------------------//
params
.
sizePercentFromScene
=
20
;
m_isInteractive
=
isInteractive
;
sClosePixmap
=
new
QPixmap
(
":/images/close.svg"
);
sIncreasePixmap
=
new
QPixmap
(
":/images/increase.svg"
);
sDecreasePixmap
=
new
QPixmap
(
":/images/decrease.svg"
);
mResizeItem
=
new
QPixmap
(
":/images/resize.svg"
);
if
(
parent
)
{
setAttribute
(
Qt
::
WA_NoMousePropagation
);
}
else
{
// standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
// setAttribute(Qt::WA_TranslucentBackground);
setAttribute
(
Qt
::
WA_MacAlwaysShowToolWindow
);
#endif
#ifdef Q_WS_MAC
setAttribute
(
Qt
::
WA_MacAlwaysShowToolWindow
);
setAttribute
(
Qt
::
WA_MacNonActivatingToolWindow
);
setAttribute
(
Qt
::
WA_MacNoShadow
);
#endif
}
connect
(
&
mRefreshTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
slot_refresh
()));
}
UBMagnifier
::~
UBMagnifier
()
{
if
(
sClosePixmap
)
{
delete
sClosePixmap
;
sClosePixmap
=
NULL
;
}
if
(
sIncreasePixmap
)
{
delete
sIncreasePixmap
;
sIncreasePixmap
=
NULL
;
}
if
(
sDecreasePixmap
)
{
delete
sDecreasePixmap
;
sDecreasePixmap
=
NULL
;
}
}
void
UBMagnifier
::
setSize
(
qreal
percentFromScene
)
{
if
(
gView
==
NULL
||
mView
==
NULL
)
return
;
// calculate object size
params
.
sizePercentFromScene
=
percentFromScene
;
QSize
sceneSize
=
mView
->
size
();
qreal
size
=
params
.
sizePercentFromScene
*
sceneSize
.
width
()
/
100
;
QRect
currGeom
=
geometry
();
if
(
currGeom
.
width
()
==
currGeom
.
height
())
{
QPoint
newPos
=
mView
->
mapFromGlobal
(
updPointMove
);
setGeometry
(
newPos
.
x
()
-
size
/
2
,
newPos
.
y
()
-
size
/
2
,
size
,
size
);
}
else
setGeometry
(
0
,
0
,
size
,
size
);
// prepare transparent bit mask
QImage
mask_img
(
width
(),
height
(),
QImage
::
Format_Mono
);
mask_img
.
fill
(
0xff
);
QPainter
mask_ptr
(
&
mask_img
);
mask_ptr
.
setBrush
(
QBrush
(
QColor
(
0
,
0
,
0
)
)
);
mask_ptr
.
drawEllipse
(
QPointF
(
size
/
2
,
size
/
2
),
size
/
2
-
sClosePixmap
->
width
(),
size
/
2
-
sClosePixmap
->
width
());
bmpMask
=
QBitmap
::
fromImage
(
mask_img
);
// prepare general image
pMap
=
QPixmap
(
width
(),
height
());
pMap
.
fill
(
Qt
::
transparent
);
pMap
.
setMask
(
bmpMask
);
}
void
UBMagnifier
::
setZoom
(
qreal
zoom
)
{
params
.
zoom
=
zoom
;
}
void
UBMagnifier
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
);
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
painter
.
setPen
(
Qt
::
NoPen
);
if
(
m_isInteractive
)
{
painter
.
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
.
drawRoundedRect
(
QRectF
(
size
().
width
()
/
2
,
size
().
height
()
/
2
,
(
size
().
width
()
-
sClosePixmap
->
width
()
)
/
2
,
(
size
().
height
()
-
sClosePixmap
->
width
()
)
/
2
),
15
,
15
);
painter
.
setBrush
(
QColor
(
190
,
190
,
190
,
255
));
painter
.
drawEllipse
(
QPoint
(
size
().
width
()
/
2
,
size
().
height
()
/
2
),
(
size
().
width
()
-
sClosePixmap
->
width
()
)
/
2
,
(
size
().
height
()
-
sClosePixmap
->
height
()
)
/
2
);
painter
.
drawPixmap
(
size
().
width
()
-
sClosePixmap
->
width
(),
size
().
height
()
/
2
+
sClosePixmap
->
height
()
*
1
,
*
sClosePixmap
);
painter
.
drawPixmap
(
size
().
width
()
-
sIncreasePixmap
->
width
(),
size
().
height
()
/
2
+
sIncreasePixmap
->
height
()
*
2.5
,
*
sIncreasePixmap
);
painter
.
drawPixmap
(
size
().
width
()
-
sDecreasePixmap
->
width
(),
size
().
height
()
/
2
+
sDecreasePixmap
->
height
()
*
3.6
,
*
sDecreasePixmap
);
painter
.
drawPixmap
(
size
().
width
()
-
mResizeItem
->
width
()
-
20
,
size
().
height
()
-
mResizeItem
->
height
()
-
20
,
*
mResizeItem
);
}
else
{
painter
.
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
.
drawEllipse
(
QPoint
(
size
().
width
()
/
2
,
size
().
height
()
/
2
),
(
size
().
width
()
-
sClosePixmap
->
width
()
)
/
2
,
(
size
().
height
()
-
sClosePixmap
->
height
()
)
/
2
);
}
painter
.
drawPixmap
(
0
,
0
,
pMap
);
}
void
UBMagnifier
::
mousePressEvent
(
QMouseEvent
*
event
)
{
if
(
m_isInteractive
)
{
QWidget
::
mousePressEvent
(
event
);
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
mResizeItem
->
width
()
-
20
&&
event
->
pos
().
x
()
<
size
().
width
()
-
20
&&
event
->
pos
().
y
()
>=
size
().
height
()
-
mResizeItem
->
height
()
-
20
&&
event
->
pos
().
y
()
<
size
().
height
()
-
-
20
)
{
mShouldResizeWidget
=
true
;
}
else
{
mShouldMoveWidget
=
!
event
->
isAccepted
()
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
);
}
mMousePressPos
=
event
->
pos
();
mMousePressDelta
=
(
qreal
)
updPointGrab
.
x
()
+
(
qreal
)
size
().
width
()
/
2
-
(
qreal
)
event
->
globalPos
().
x
();
event
->
accept
();
update
();
}
else
event
->
ignore
();
}
void
UBMagnifier
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
if
(
m_isInteractive
)
{
if
(
mShouldMoveWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
move
(
pos
()
-
mMousePressPos
+
event
->
pos
());
event
->
accept
();
QWidget
::
mouseMoveEvent
(
event
);
emit
magnifierMoved_Signal
(
QPoint
(
this
->
pos
().
x
()
+
size
().
width
()
/
2
,
this
->
pos
().
y
()
+
size
().
height
()
/
2
));
return
;
}
if
(
mShouldResizeWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
QPoint
currGlobalPos
=
event
->
globalPos
();
qreal
cvW
=
mView
->
width
();
qreal
newXSize
=
(
currGlobalPos
.
x
()
+
mMousePressDelta
-
updPointGrab
.
x
()
)
*
2
;
qreal
newPercentSize
=
newXSize
*
100
/
cvW
;
emit
magnifierResized_Signal
(
newPercentSize
);
event
->
ignore
();
return
;
}
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
mResizeItem
->
width
()
-
20
&&
event
->
pos
().
x
()
<
size
().
width
()
-
20
&&
event
->
pos
().
y
()
>=
size
().
height
()
-
mResizeItem
->
height
()
-
20
&&
event
->
pos
().
y
()
<
size
().
height
()
-
-
20
&&
isCusrsorAlreadyStored
==
false
)
{
mOldCursor
=
cursor
();
isCusrsorAlreadyStored
=
true
;
setCursor
(
mResizeCursor
);
}
}
else
event
->
ignore
();
}
void
UBMagnifier
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
if
(
m_isInteractive
)
{
mShouldMoveWidget
=
false
;
mShouldResizeWidget
=
false
;
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
sClosePixmap
->
width
()
&&
event
->
pos
().
x
()
<
size
().
width
()
&&
event
->
pos
().
y
()
>=
size
().
height
()
/
2
+
sClosePixmap
->
height
()
*
1
&&
event
->
pos
().
y
()
<
size
().
height
()
/
2
+
sClosePixmap
->
height
()
*
2
)
{
event
->
accept
();
emit
magnifierClose_Signal
();
}
else
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
sIncreasePixmap
->
width
()
&&
event
->
pos
().
x
()
<
size
().
width
()
&&
event
->
pos
().
y
()
>=
size
().
height
()
/
2
+
sIncreasePixmap
->
height
()
*
2.5
&&
event
->
pos
().
y
()
<
size
().
height
()
/
2
+
sIncreasePixmap
->
height
()
*
3.5
)
{
event
->
accept
();
emit
magnifierZoomIn_Signal
();
}
else
if
(
event
->
pos
().
x
()
>=
size
().
width
()
-
sDecreasePixmap
->
width
()
&&
event
->
pos
().
x
()
<
size
().
width
()
&&
event
->
pos
().
y
()
>=
size
().
height
()
/
2
+
sDecreasePixmap
->
height
()
*
3.6
&&
event
->
pos
().
y
()
<
size
().
height
()
/
2
+
sDecreasePixmap
->
height
()
*
4.6
)
{
event
->
accept
();
emit
magnifierZoomOut_Signal
();
}
else
QWidget
::
mouseReleaseEvent
(
event
);
// don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
}
else
event
->
ignore
();
}
void
UBMagnifier
::
slot_refresh
()
{
if
(
!
(
updPointGrab
.
isNull
()))
grabPoint
(
updPointGrab
);
if
(
isCusrsorAlreadyStored
)
{
QPoint
globalCursorPos
=
QCursor
::
pos
();
QPoint
cursorPos
=
mapFromGlobal
(
globalCursorPos
);
if
(
cursorPos
.
x
()
<
size
().
width
()
-
mResizeItem
->
width
()
-
20
||
cursorPos
.
x
()
>
size
().
width
()
-
20
||
cursorPos
.
y
()
<
size
().
height
()
-
mResizeItem
->
height
()
-
20
||
cursorPos
.
y
()
>
size
().
height
()
-
-
20
)
{
isCusrsorAlreadyStored
=
false
;
setCursor
(
mOldCursor
);
}
}
}
void
UBMagnifier
::
grabPoint
()
{
QMatrix
transM
=
UBApplication
::
boardController
->
controlView
()
->
matrix
();
QPointF
itemPos
=
gView
->
mapFromGlobal
(
updPointGrab
);
qreal
zWidth
=
width
()
/
(
params
.
zoom
*
transM
.
m11
());
qreal
zWidthHalf
=
zWidth
/
2
;
qreal
zHeight
=
height
()
/
(
params
.
zoom
*
transM
.
m22
());
qreal
zHeightHalf
=
zHeight
/
2
;
QPointF
pfScLtF
(
UBApplication
::
boardController
->
controlView
()
->
mapToScene
(
QPoint
(
itemPos
.
x
(),
itemPos
.
y
())));
QRect
magnifierRect
=
rect
();
float
x
=
pfScLtF
.
x
()
-
zWidthHalf
;
float
y
=
pfScLtF
.
y
()
-
zHeightHalf
;
QPointF
leftTop
(
x
,
y
);
QPointF
rightBottom
(
x
+
zWidth
,
y
+
zHeight
);
QRectF
srcRect
(
leftTop
,
rightBottom
);
QPixmap
newPixMap
(
QSize
(
width
(),
height
()));
QPainter
painter
(
&
newPixMap
);
UBApplication
::
boardController
->
activeScene
()
->
render
(
&
painter
,
QRectF
(
0
,
0
,
width
(),
height
()),
srcRect
);
painter
.
end
();
pMap
.
fill
(
Qt
::
transparent
);
pMap
=
newPixMap
.
scaled
(
QSize
(
width
(),
height
()));
pMap
.
setMask
(
bmpMask
);
update
();
}
void
UBMagnifier
::
grabPoint
(
const
QPoint
&
pGrab
)
{
QMatrix
transM
=
UBApplication
::
boardController
->
controlView
()
->
matrix
();
updPointGrab
=
pGrab
;
QPointF
itemPos
=
gView
->
mapFromGlobal
(
pGrab
);
qreal
zWidth
=
width
()
/
(
params
.
zoom
*
transM
.
m11
());
qreal
zWidthHalf
=
zWidth
/
2
;
qreal
zHeight
=
height
()
/
(
params
.
zoom
*
transM
.
m22
());
qreal
zHeightHalf
=
zHeight
/
2
;
QPointF
pfScLtF
(
UBApplication
::
boardController
->
controlView
()
->
mapToScene
(
QPoint
(
itemPos
.
x
(),
itemPos
.
y
())));
QRect
magnifierRect
=
rect
();
float
x
=
pfScLtF
.
x
()
-
zWidthHalf
;
float
y
=
pfScLtF
.
y
()
-
zHeightHalf
;
QPointF
leftTop
(
x
,
y
);
QPointF
rightBottom
(
x
+
zWidth
,
y
+
zHeight
);
QRectF
srcRect
(
leftTop
,
rightBottom
);
QPixmap
newPixMap
(
QSize
(
width
(),
height
()));
QPainter
painter
(
&
newPixMap
);
UBApplication
::
boardController
->
activeScene
()
->
render
(
&
painter
,
QRectF
(
0
,
0
,
width
(),
height
()),
srcRect
);
painter
.
end
();
// pMap.fill(Qt::transparent);
pMap
=
newPixMap
;
pMap
.
setMask
(
bmpMask
);
update
();
}
// from global
void
UBMagnifier
::
grabNMove
(
const
QPoint
&
pGrab
,
const
QPoint
&
pMove
,
bool
needGrab
,
bool
needMove
)
{
updPointGrab
=
pGrab
;
updPointMove
=
pMove
;
if
(
needGrab
)
grabPoint
(
pGrab
);
if
(
needMove
)
{
QPoint
movePos
=
mView
->
mapFromGlobal
(
pMove
);
move
(
movePos
.
x
()
-
width
()
/
2
,
movePos
.
y
()
-
height
()
/
2
);
// move(itemPos.x(), itemPos.y());
}
}
void
UBMagnifier
::
setGrabView
(
QWidget
*
view
)
{
gView
=
view
;
mRefreshTimer
.
setInterval
(
40
);
mRefreshTimer
.
start
();
}
src/gui/UBMagnifer.h
View file @
d8bc5839
/*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H
#include <QtGui>
class
UBMagnifierParams
{
public
:
int
x
;
int
y
;
qreal
zoom
;
qreal
sizePercentFromScene
;
};
class
UBMagnifier
:
public
QWidget
{
Q_OBJECT
public
:
UBMagnifier
(
QWidget
*
parent
=
0
,
bool
isInteractive
=
false
);
~
UBMagnifier
();
void
setSize
(
qreal
percentFromScene
);
void
setZoom
(
qreal
zoom
);
void
setGrabView
(
QWidget
*
view
);
void
setMoveView
(
QWidget
*
view
)
{
mView
=
view
;}
void
grabPoint
();
void
grabPoint
(
const
QPoint
&
point
);
void
grabNMove
(
const
QPoint
&
pGrab
,
const
QPoint
&
pMove
,
bool
needGrab
=
true
,
bool
needMove
=
true
);
UBMagnifierParams
params
;
signals
:
void
magnifierMoved_Signal
(
QPoint
newPos
);
void
magnifierClose_Signal
();
void
magnifierZoomIn_Signal
();
void
magnifierZoomOut_Signal
();
void
magnifierResized_Signal
(
qreal
newPercentSize
);
protected
:
void
paintEvent
(
QPaintEvent
*
);
void
timerEvent
(
QTimerEvent
*
);
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
QPoint
mMousePressPos
;
qreal
mMousePressDelta
;
bool
mShouldMoveWidget
;
bool
mShouldResizeWidget
;
QPixmap
*
sClosePixmap
;
QPixmap
*
sIncreasePixmap
;
QPixmap
*
sDecreasePixmap
;
QPixmap
*
mResizeItem
;
bool
isCusrsorAlreadyStored
;
QCursor
mOldCursor
;
QCursor
mResizeCursor
;
private
:
bool
inTimer
;
bool
m_isInteractive
;
int
timerUpdate
;
QPoint
updPointGrab
;
QPoint
updPointMove
;
QPixmap
pMap
;
QBitmap
bmpMask
;
QPen
borderPen
;
QWidget
*
gView
;
QWidget
*
mView
;
};
#endif // UBMAGNIFIER_H
/*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H
#include <QtGui>
class
UBMagnifierParams
{
public
:
int
x
;
int
y
;
qreal
zoom
;
qreal
sizePercentFromScene
;
};
class
UBMagnifier
:
public
QWidget
{
Q_OBJECT
public
:
UBMagnifier
(
QWidget
*
parent
=
0
,
bool
isInteractive
=
false
);
~
UBMagnifier
();
void
setSize
(
qreal
percentFromScene
);
void
setZoom
(
qreal
zoom
);
void
setGrabView
(
QWidget
*
view
);
void
setMoveView
(
QWidget
*
view
)
{
mView
=
view
;}
void
grabPoint
();
void
grabPoint
(
const
QPoint
&
point
);
void
grabNMove
(
const
QPoint
&
pGrab
,
const
QPoint
&
pMove
,
bool
needGrab
=
true
,
bool
needMove
=
true
);
UBMagnifierParams
params
;
signals
:
void
magnifierMoved_Signal
(
QPoint
newPos
);
void
magnifierClose_Signal
();
void
magnifierZoomIn_Signal
();
void
magnifierZoomOut_Signal
();
void
magnifierResized_Signal
(
qreal
newPercentSize
);
public
slots
:
void
slot_refresh
();
protected
:
void
paintEvent
(
QPaintEvent
*
);
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
QPoint
mMousePressPos
;
qreal
mMousePressDelta
;
bool
mShouldMoveWidget
;
bool
mShouldResizeWidget
;
QPixmap
*
sClosePixmap
;
QPixmap
*
sIncreasePixmap
;
QPixmap
*
sDecreasePixmap
;
QPixmap
*
mResizeItem
;
bool
isCusrsorAlreadyStored
;
QCursor
mOldCursor
;
QCursor
mResizeCursor
;
private
:
QTimer
mRefreshTimer
;
bool
m_isInteractive
;
QPoint
updPointGrab
;
QPoint
updPointMove
;
QPixmap
pMap
;
QBitmap
bmpMask
;
QPen
borderPen
;
QWidget
*
gView
;
QWidget
*
mView
;
};
#endif // UBMAGNIFIER_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