").appendTo(container);
@@ -458,6 +457,7 @@ function importData(data){
}
});
container.appendTo("#data");
+ checkCorrectness(all_imgs);
}
}
}
@@ -520,7 +520,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -531,7 +531,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -561,9 +561,9 @@ function addCategory(obj){
$("
").appendTo(imgs_container);
$("
").appendTo(imgs_container);
imgs_container.attr("ondragenter", "return false;")
- .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);");
+ .attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
+ .attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
+ .attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
}
//add new container
@@ -686,8 +686,7 @@ function returnId(){
}
//a func for checking when smth will drop
-function checkOnDrop(dest, source){
- dest.append(source);
+function checkOnDrop(dest){
var tmp_count = dest.find("input[name='count']").val();
var tmp_mask = dest.find("input[name='mask']").val();
if(dest.find(".img_block").size() == tmp_count){
@@ -697,47 +696,35 @@ function checkOnDrop(dest, source){
tmp_right = false;
});
if(tmp_right)
- dest.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
+ dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
} else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
}
//checking source on correctness
function checkCorrectness(source){
if(!source.hasClass("all_imgs")){
- var tmp_count = source.find("input[name='count']").val();
- var tmp_mask = source.find("input[name='mask']").val();
- if(source.find(".img_block").size() == tmp_count){
- var tmp_right = true;
- source.find(".img_block").each(function(){
- if($(this).find("input").val() != tmp_mask)
- tmp_right = false;
- });
-
- if(tmp_right)
- source.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
- } else if(source.find(".img_block").size() == 0)
- source.addClass("def_cont")
- .removeClass("green_cont")
- .removeClass("red_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ }
+ } else {
+ if(source.find(".img_block").size() > 0){
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ }
}
}
diff --git a/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js b/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js
index ab48d98b..aad7172e 100644
--- a/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js
+++ b/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js
@@ -130,7 +130,7 @@ function start(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -358,7 +358,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -430,7 +430,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -475,6 +475,7 @@ function importData(data){
}
});
container.appendTo("#data");
+ checkCorrectness(all_imgs);
}
}
}
@@ -537,7 +538,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -548,7 +549,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -578,9 +579,9 @@ function addCategory(obj){
$("
").appendTo(imgs_container);
$("
").appendTo(imgs_container);
imgs_container.attr("ondragenter", "return false;")
- .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);");
+ .attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
+ .attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
+ .attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
}
//add new container
@@ -599,9 +600,9 @@ function addContainer(){
$("
").appendTo(imgs_container);
$("
").appendTo(imgs_container);
imgs_container.attr("ondragenter", "return false;")
- .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);");
+ .attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
+ .attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
+ .attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
container.insertBefore($(".add_block"));
}
@@ -704,8 +705,7 @@ function returnId(){
}
//a func for checking when smth will drop
-function checkOnDrop(dest, source){
- dest.append(source);
+function checkOnDrop(dest){
var tmp_count = dest.find("input[name='count']").val();
var tmp_mask = dest.find("input[name='mask']").val();
if(dest.find(".img_block").size() == tmp_count){
@@ -715,47 +715,35 @@ function checkOnDrop(dest, source){
tmp_right = false;
});
if(tmp_right)
- dest.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
+ dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
} else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
}
//checking source on correctness
function checkCorrectness(source){
if(!source.hasClass("all_imgs")){
- var tmp_count = source.find("input[name='count']").val();
- var tmp_mask = source.find("input[name='mask']").val();
- if(source.find(".img_block").size() == tmp_count){
- var tmp_right = true;
- source.find(".img_block").each(function(){
- if($(this).find("input").val() != tmp_mask)
- tmp_right = false;
- });
-
- if(tmp_right)
- source.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
- } else if(source.find(".img_block").size() == 0)
- source.addClass("def_cont")
- .removeClass("green_cont")
- .removeClass("red_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ }
+ } else {
+ if(source.find(".img_block").size() > 0){
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ }
}
}
diff --git a/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js b/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js
index 367e5630..dc92f1e6 100644
--- a/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js
+++ b/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js
@@ -111,7 +111,7 @@ function start(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -342,7 +342,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -414,7 +414,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -459,6 +459,7 @@ function importData(data){
}
});
container.appendTo("#data");
+ checkCorrectness(all_imgs);
}
}
}
@@ -521,7 +522,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -532,7 +533,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -562,9 +563,9 @@ function addCategory(obj){
$("
").appendTo(imgs_container);
$("
").appendTo(imgs_container);
imgs_container.attr("ondragenter", "return false;")
- .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);");
+ .attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
+ .attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
+ .attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
}
//add new container
@@ -583,9 +584,9 @@ function addContainer(){
$("
").appendTo(imgs_container);
$("
").appendTo(imgs_container);
imgs_container.attr("ondragenter", "return false;")
- .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;")
- .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);");
+ .attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
+ .attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
+ .attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
container.insertBefore($(".add_block"));
}
@@ -688,8 +689,7 @@ function returnId(){
}
//a func for checking when smth will drop
-function checkOnDrop(dest, source){
- dest.append(source);
+function checkOnDrop(dest){
var tmp_count = dest.find("input[name='count']").val();
var tmp_mask = dest.find("input[name='mask']").val();
if(dest.find(".img_block").size() == tmp_count){
@@ -699,47 +699,35 @@ function checkOnDrop(dest, source){
tmp_right = false;
});
if(tmp_right)
- dest.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
+ dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
} else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
}
//checking source on correctness
function checkCorrectness(source){
if(!source.hasClass("all_imgs")){
- var tmp_count = source.find("input[name='count']").val();
- var tmp_mask = source.find("input[name='mask']").val();
- if(source.find(".img_block").size() == tmp_count){
- var tmp_right = true;
- source.find(".img_block").each(function(){
- if($(this).find("input").val() != tmp_mask)
- tmp_right = false;
- });
-
- if(tmp_right)
- source.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
- } else if(source.find(".img_block").size() == 0)
- source.addClass("def_cont")
- .removeClass("green_cont")
- .removeClass("red_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ }
+ } else {
+ if(source.find(".img_block").size() > 0){
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ }
}
}
diff --git a/resources/library/interactivities/Cat text.wgt/js/script.js b/resources/library/interactivities/Cat text.wgt/js/script.js
index 12653ac4..0dededfa 100644
--- a/resources/library/interactivities/Cat text.wgt/js/script.js
+++ b/resources/library/interactivities/Cat text.wgt/js/script.js
@@ -120,7 +120,7 @@ function start(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -339,7 +339,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -410,12 +410,11 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
- });
- checkCorrectness(imgs_container);
+ });
}
all_imgs = $("
").appendTo(container);
@@ -452,7 +451,8 @@ function importData(data){
}
}
}
- });
+ });
+ checkCorrectness(all_imgs);
}
}
}
@@ -516,7 +516,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -527,7 +527,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -685,8 +685,7 @@ function changeStyle(val){
}
//a func for checking when smth will drop
-function checkOnDrop(dest, source){
- dest.append(source);
+function checkOnDrop(dest){
var tmp_count = dest.find("input[name='count']").val();
var tmp_mask = dest.find("input[name='mask']").val();
if(dest.find(".img_block").size() == tmp_count){
@@ -696,46 +695,34 @@ function checkOnDrop(dest, source){
tmp_right = false;
});
if(tmp_right)
- dest.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
+ dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
} else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
}
//checking source on correctness
function checkCorrectness(source){
if(!source.hasClass("all_imgs")){
- var tmp_count = source.find("input[name='count']").val();
- var tmp_mask = source.find("input[name='mask']").val();
- if(source.find(".img_block").size() == tmp_count){
- var tmp_right = true;
- source.find(".img_block").each(function(){
- if($(this).find("input").val() != tmp_mask)
- tmp_right = false;
- });
-
- if(tmp_right)
- source.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
- } else if(source.find(".img_block").size() == 0)
- source.addClass("def_cont")
- .removeClass("green_cont")
- .removeClass("red_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ }
+ } else {
+ if(source.find(".img_block").size() > 0){
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ }
}
}
diff --git a/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js b/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js
index 8d7149ed..606f4a4a 100644
--- a/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js
+++ b/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js
@@ -141,7 +141,7 @@ function start(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -360,7 +360,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -431,7 +431,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -473,7 +473,8 @@ function importData(data){
}
}
}
- });
+ });
+ checkCorrectness(all_imgs);
}
}
}
@@ -537,7 +538,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -548,7 +549,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -706,8 +707,7 @@ function changeStyle(val){
}
//a func for checking when smth will drop
-function checkOnDrop(dest, source){
- dest.append(source);
+function checkOnDrop(dest){
var tmp_count = dest.find("input[name='count']").val();
var tmp_mask = dest.find("input[name='mask']").val();
if(dest.find(".img_block").size() == tmp_count){
@@ -717,46 +717,34 @@ function checkOnDrop(dest, source){
tmp_right = false;
});
if(tmp_right)
- dest.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
+ dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
} else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
}
//checking source on correctness
function checkCorrectness(source){
if(!source.hasClass("all_imgs")){
- var tmp_count = source.find("input[name='count']").val();
- var tmp_mask = source.find("input[name='mask']").val();
- if(source.find(".img_block").size() == tmp_count){
- var tmp_right = true;
- source.find(".img_block").each(function(){
- if($(this).find("input").val() != tmp_mask)
- tmp_right = false;
- });
-
- if(tmp_right)
- source.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
- } else if(source.find(".img_block").size() == 0)
- source.addClass("def_cont")
- .removeClass("green_cont")
- .removeClass("red_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ }
+ } else {
+ if(source.find(".img_block").size() > 0){
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ }
}
}
diff --git a/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js b/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js
index dade5268..86bef6bd 100644
--- a/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js
+++ b/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js
@@ -120,7 +120,7 @@ function start(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -339,7 +339,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -410,7 +410,7 @@ function importData(data){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -452,7 +452,8 @@ function importData(data){
}
}
}
- });
+ });
+ checkCorrectness(all_imgs);
}
}
}
@@ -516,7 +517,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -527,7 +528,7 @@ function showExample(){
drop: function(event, ui) {
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
var tmp_ui = $(ui.draggable).parent();
- checkOnDrop($(this), $(ui.draggable));
+ $(this).append($(ui.draggable));
checkCorrectness(tmp_ui);
}
}
@@ -685,8 +686,7 @@ function changeStyle(val){
}
//a func for checking when smth will drop
-function checkOnDrop(dest, source){
- dest.append(source);
+function checkOnDrop(dest){
var tmp_count = dest.find("input[name='count']").val();
var tmp_mask = dest.find("input[name='mask']").val();
if(dest.find(".img_block").size() == tmp_count){
@@ -696,46 +696,34 @@ function checkOnDrop(dest, source){
tmp_right = false;
});
if(tmp_right)
- dest.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
+ dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
} else
- dest.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
}
//checking source on correctness
function checkCorrectness(source){
if(!source.hasClass("all_imgs")){
- var tmp_count = source.find("input[name='count']").val();
- var tmp_mask = source.find("input[name='mask']").val();
- if(source.find(".img_block").size() == tmp_count){
- var tmp_right = true;
- source.find(".img_block").each(function(){
- if($(this).find("input").val() != tmp_mask)
- tmp_right = false;
- });
-
- if(tmp_right)
- source.removeClass("def_cont")
- .removeClass("red_cont")
- .addClass("green_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
- } else if(source.find(".img_block").size() == 0)
- source.addClass("def_cont")
- .removeClass("green_cont")
- .removeClass("red_cont");
- else
- source.removeClass("def_cont")
- .removeClass("green_cont")
- .addClass("red_cont");
+ if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ }
+ } else {
+ if(source.find(".img_block").size() > 0){
+ source.parent().find(".imgs_cont").each(function(){
+ $(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
+ })
+ } else {
+ source.parent().find(".imgs_cont").each(function(){
+ checkOnDrop($(this))
+ })
+ }
}
}
\ No newline at end of file
diff --git a/resources/sankore.qrc b/resources/sankore.qrc
index 8965e022..fcefa2e8 100644
--- a/resources/sankore.qrc
+++ b/resources/sankore.qrc
@@ -165,6 +165,7 @@
images/toolPalette/triangleTool.png
images/toolPalette/protractorTool.png
images/toolPalette/compassTool.png
+ images/toolPalette/aristoTool.png
images/toolPalette/maskTool.png
images/toolPalette/magnifierTool.png
images/extraPalette/blackout.png
@@ -365,6 +366,6 @@
images/teacherGuide/pencil.svg
images/duplicateDisabled.svg
images/teacherGuide/flash_24x24.svg
- images/toque.png
+ images/toque.svg
diff --git a/src/adaptors/UBImportDocument.cpp b/src/adaptors/UBImportDocument.cpp
index 0bf32c82..ca5944f3 100644
--- a/src/adaptors/UBImportDocument.cpp
+++ b/src/adaptors/UBImportDocument.cpp
@@ -171,8 +171,11 @@ UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString&
return NULL;
}
-
- UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup);
+ bool addTitlePage = false;
+ if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool() && !QFile(documentRootFolder+"/page000.svg").exists())
+ addTitlePage=true;
+
+ UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup, "", false, addTitlePage);
UBApplication::showMessage(tr("Import successful."));
return newDocument;
}
diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp
index bcfa5199..cabc74ad 100644
--- a/src/adaptors/UBSvgSubsetAdaptor.cpp
+++ b/src/adaptors/UBSvgSubsetAdaptor.cpp
@@ -941,18 +941,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
readGroupRoot();
}
-// else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){
-// sTeacherGuideNode.clear();
-// sTeacherGuideNode += "";
-// sTeacherGuideNode += "\n";
-// }
-// else if (mXmlReader.name() == "media" || mXmlReader.name() == "link" || mXmlReader.name() == "title" || mXmlReader.name() == "comment" || mXmlReader.name() == "action")
-// {
-// sTeacherGuideNode += "<" + mXmlReader.name().toString() + " ";
-// foreach(QXmlStreamAttribute attribute, mXmlReader.attributes())
-// sTeacherGuideNode += attribute.name().toString() + "=\"" + attribute.value().toString() + "\" ";
-// sTeacherGuideNode += " />\n";
-// }
else
{
// NOOP
@@ -976,17 +964,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mGroupDarkBackgroundColor = QColor();
mGroupLightBackgroundColor = QColor();
}
-// else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){
-// sTeacherGuideNode += "";
-// qDebug() << sTeacherGuideNode;
-// QMap elements = getAdditionalElementToStore();
-// IDataStorage* storageClass = elements.value("teacherGuide");
-// if(storageClass){
-// storageClass->load(sTeacherGuideNode);
-// }
-// }
-
-
}
}
@@ -1147,17 +1124,10 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
QDomElement groupRoot = groupDomDocument.createElement(tGroups);
groupDomDocument.appendChild(groupRoot);
-
- static int i = 0;
- qDebug() << "persist call no is " << ++i;
-
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
mXmlWriter.setDevice(&buffer);
- //Unused variable
- //QTime timer = QTime::currentTime();
-
mXmlWriter.setAutoFormatting(true);
mXmlWriter.writeStartDocument();
@@ -3120,7 +3090,7 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg()
UBGraphicsCache* UBSvgSubsetAdaptor::UBSvgSubsetReader::cacheFromSvg()
{
- UBGraphicsCache* pCache = new UBGraphicsCache();
+ UBGraphicsCache* pCache = UBGraphicsCache::instance(mScene);
pCache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
graphicsItemFromSvg(pCache);
diff --git a/src/adaptors/UBThumbnailAdaptor.cpp b/src/adaptors/UBThumbnailAdaptor.cpp
index 1a90f108..556dc340 100644
--- a/src/adaptors/UBThumbnailAdaptor.cpp
+++ b/src/adaptors/UBThumbnailAdaptor.cpp
@@ -23,7 +23,12 @@
#include "core/UBApplication.h"
#include "core/UBSettings.h"
+
+#include "gui/UBDockTeacherGuideWidget.h"
+#include "gui/UBTeacherGuideWidget.h"
+
#include "board/UBBoardController.h"
+#include "board/UBBoardPaletteManager.h"
#include "document/UBDocumentProxy.h"
@@ -120,7 +125,7 @@ void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* p
QFile thumbFile(fileName);
- if (pScene->isModified() || overrideModified || !thumbFile.exists())
+ if (pScene->isModified() || overrideModified || !thumbFile.exists() || UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())
{
qreal nominalWidth = pScene->nominalSize().width();
qreal nominalHeight = pScene->nominalSize().height();
@@ -152,6 +157,12 @@ void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* p
pScene->render(&painter, imageRect, sceneRect, Qt::KeepAspectRatio);
+ if(UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()){
+ QPixmap toque(":images/toque.svg");
+ painter.setOpacity(0.6);
+ painter.drawPixmap(QPoint(width - toque.width(),0),toque);
+ }
+
pScene->setRenderingContext(UBGraphicsScene::Screen);
pScene->setRenderingQuality(UBItem::RenderingQualityNormal);
diff --git a/src/api/UBLibraryAPI.cpp b/src/api/UBLibraryAPI.cpp
index 8d75a568..073ed404 100644
--- a/src/api/UBLibraryAPI.cpp
+++ b/src/api/UBLibraryAPI.cpp
@@ -40,7 +40,7 @@ UBLibraryAPI::~UBLibraryAPI()
void UBLibraryAPI::addObject(QString pUrl, int width, int height, int x, int y, bool background)
{
if (UBApplication::boardController)
- UBApplication::boardController->downloadURL(QUrl(pUrl), QPointF(x, y), QSize(width, height), background);
+ UBApplication::boardController->downloadURL(QUrl(pUrl), QString(), QPointF(x, y), QSize(width, height), background);
}
diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp
index b86e7aa1..32c62f32 100644
--- a/src/api/UBWidgetUniboardAPI.cpp
+++ b/src/api/UBWidgetUniboardAPI.cpp
@@ -201,7 +201,7 @@ void UBWidgetUniboardAPI::addObject(QString pUrl, int width, int height, int x,
if (UBApplication::boardController->activeScene() != mScene)
return;
- UBApplication::boardController->downloadURL(QUrl(pUrl), QPointF(x, y), QSize(width, height), background);
+ UBApplication::boardController->downloadURL(QUrl(pUrl), QString(), QPointF(x, y), QSize(width, height), background);
}
@@ -506,7 +506,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event)
sDownloadFileDesc desc;
desc.dest = sDownloadFileDesc::graphicsWidget;
desc.modal = true;
- desc.url = url;
+ desc.srcUrl = url;
desc.currentSize = 0;
desc.name = QFileInfo(url).fileName();
desc.totalSize = 0; // The total size will be retrieved during the download
diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp
index 544f92e9..b269b8fa 100644
--- a/src/board/UBBoardController.cpp
+++ b/src/board/UBBoardController.cpp
@@ -95,6 +95,7 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow)
, mCleanupDone(false)
, mCacheWidgetIsEnabled(false)
, mDeletingSceneIndex(-1)
+ , mMovingSceneIndex(-1)
, mActionGroupText(tr("Group"))
, mActionUngroupText(tr("Ungroup"))
{
@@ -131,7 +132,7 @@ void UBBoardController::init()
, this, SLOT(lastWindowClosed()));
connect(UBDownloadManager::downloadManager(), SIGNAL(downloadModalFinished()), this, SLOT(onDownloadModalFinished()));
- connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToBoard(bool,QUrl,QString,QByteArray,QPointF,QSize,bool)), this, SLOT(downloadFinished(bool,QUrl,QString,QByteArray,QPointF,QSize,bool)));
+ connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToBoard(bool,QUrl,QUrl,QString,QByteArray,QPointF,QSize,bool)), this, SLOT(downloadFinished(bool,QUrl,QUrl,QString,QByteArray,QPointF,QSize,bool)));
UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument();
@@ -562,7 +563,12 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
}
UBMimeType::Enum itemMimeType;
- QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(item->sourceUrl().toLocalFile());
+
+ QString srcFile = item->sourceUrl().toLocalFile();
+ if (srcFile.isEmpty())
+ srcFile = item->sourceUrl().toString();
+
+ QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(srcFile);
if(NULL != qgraphicsitem_cast(commonItem))
itemMimeType = UBMimeType::Group;
else
@@ -587,8 +593,9 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
if (mitem)
{
sourceUrl = mitem->mediaFileUrl();
+ downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false);
}
- }break;
+ }return NULL; // async operation
case UBMimeType::VectorImage:
{
@@ -661,7 +668,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
if (retItem)
return retItem;
- UBItem *createdItem = downloadFinished(true, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false);
+ UBItem *createdItem = downloadFinished(true, sourceUrl, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false);
if (createdItem)
{
createdItem->setSourceUrl(item->sourceUrl());
@@ -675,6 +682,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
retItem = dynamic_cast(createdItem);
}
+
return retItem;
}
@@ -960,7 +968,7 @@ void UBBoardController::groupButtonClicked()
}
}
-void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const QSize& pSize, bool isBackground, bool internalData)
+void UBBoardController::downloadURL(const QUrl& url, QString contentSourceUrl, const QPointF& pPos, const QSize& pSize, bool isBackground, bool internalData)
{
qDebug() << "something has been dropped on the board! Url is: " << url.toString();
QString sUrl = url.toString();
@@ -971,7 +979,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
if(sUrl.startsWith("uniboardTool://"))
{
- downloadFinished(true, url, "application/vnd.mnemis-uniboard-tool", QByteArray(), pPos, pSize, isBackground);
+ downloadFinished(true, url, QUrl(), "application/vnd.mnemis-uniboard-tool", QByteArray(), pPos, pSize, isBackground);
}
else if (sUrl.startsWith("file://") || sUrl.startsWith("/"))
{
@@ -984,22 +992,37 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
|| contentType.startsWith("application/widget")
|| contentType.startsWith("application/vnd.apple-widget");
- QFile file(fileName);
-
if (shouldLoadFileData)
+ {
+ QFile file(fileName);
file.open(QIODevice::ReadOnly);
-
- downloadFinished(true, formedUrl, contentType, file.readAll(), pPos, pSize, isBackground, internalData);
-
- if (shouldLoadFileData)
+ downloadFinished(true, formedUrl, QUrl(), contentType, file.readAll(), pPos, pSize, isBackground, internalData);
file.close();
+ }
+ else
+ {
+ // media items should be copyed in separate thread
+
+ sDownloadFileDesc desc;
+ desc.modal = false;
+ desc.srcUrl = sUrl;
+ desc.originalSrcUrl = contentSourceUrl;
+ desc.currentSize = 0;
+ desc.name = QFileInfo(url.toString()).fileName();
+ desc.totalSize = 0; // The total size will be retrieved during the download
+ desc.pos = pPos;
+ desc.size = pSize;
+ desc.isBackground = isBackground;
+
+ UBDownloadManager::downloadManager()->addFileToDownload(desc);
+ }
}
else
{
// When we fall there, it means that we are dropping something from the web to the board
sDownloadFileDesc desc;
desc.modal = true;
- desc.url = url.toString();
+ desc.srcUrl = url.toString();
desc.currentSize = 0;
desc.name = QFileInfo(url.toString()).fileName();
desc.totalSize = 0; // The total size will be retrieved during the download
@@ -1022,7 +1045,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
}
-UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader,
+UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader,
QByteArray pData, QPointF pPos, QSize pSize,
bool isBackground, bool internalData)
{
@@ -1157,11 +1180,9 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
qDebug() << "accepting mime type" << mimeType << "as video";
UBGraphicsMediaItem *mediaVideoItem = 0;
-
+ QUuid uuid = QUuid::createUuid();
if (pData.length() > 0)
{
- QUuid uuid = QUuid::createUuid();
-
QString destFile;
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
sourceUrl.toString(),
@@ -1178,16 +1199,19 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
QUrl url = QUrl::fromLocalFile(destFile);
mediaVideoItem = mActiveScene->addMedia(url, false, pPos);
-
- mediaVideoItem->setSourceUrl(sourceUrl);
- mediaVideoItem->setUuid(uuid);
}
else
{
- mediaVideoItem = addVideo(sourceUrl, false, pPos);
+ qDebug() << sourceUrl.toString();
+ mediaVideoItem = addVideo(sourceUrl, false, pPos, true);
}
if(mediaVideoItem){
+ if (contentUrl.isEmpty())
+ mediaVideoItem->setSourceUrl(sourceUrl);
+ else
+ mediaVideoItem->setSourceUrl(contentUrl);
+ mediaVideoItem->setUuid(uuid);
connect(this, SIGNAL(activeSceneChanged()), mediaVideoItem, SLOT(activeSceneChanged()));
}
@@ -1201,10 +1225,9 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
UBGraphicsMediaItem *audioMediaItem = 0;
+ QUuid uuid = QUuid::createUuid();
if (pData.length() > 0)
{
- QUuid uuid = QUuid::createUuid();
-
QString destFile;
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
sourceUrl.toString(),
@@ -1221,16 +1244,18 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
QUrl url = QUrl::fromLocalFile(destFile);
audioMediaItem = mActiveScene->addMedia(url, false, pPos);
-
- audioMediaItem->setSourceUrl(sourceUrl);
- audioMediaItem->setUuid(uuid);
}
else
{
- audioMediaItem = addAudio(sourceUrl, false, pPos);
+ audioMediaItem = addAudio(sourceUrl, false, pPos, true);
}
if(audioMediaItem){
+ if (contentUrl.isEmpty())
+ audioMediaItem->setSourceUrl(sourceUrl);
+ else
+ audioMediaItem->setSourceUrl(contentUrl);
+ audioMediaItem->setUuid(uuid);
connect(this, SIGNAL(activeSceneChanged()), audioMediaItem, SLOT(activeSceneChanged()));
}
@@ -1362,6 +1387,11 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
mActiveScene->addMask(pPos);
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
}
+ else if (sourceUrl.toString() == UBToolsManager::manager()->aristo.id)
+ {
+ mActiveScene->addAristo(pPos);
+ UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
+ }
else
{
showMessage(tr("Unknown tool type %1").arg(sourceUrl.toString()));
@@ -1450,9 +1480,6 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
{
freezeW3CWidgets(true);
- if(sceneChange)
- emit activeSceneWillChange();
-
persistCurrentScene();
ClearUndoStack();
@@ -1500,14 +1527,17 @@ void UBBoardController::moveSceneToIndex(int source, int target)
{
if (selectedDocument())
{
+
persistCurrentScene();
UBDocumentContainer::movePageToIndex(source, target);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument());
-
+ mMovingSceneIndex = source;
setActiveDocumentScene(target);
+ mMovingSceneIndex = -1;
+
}
}
@@ -1786,6 +1816,13 @@ qreal UBBoardController::currentZoom()
return 1.0;
}
+void UBBoardController::removeTool(UBToolWidget* toolWidget)
+{
+ toolWidget->hide();
+
+ delete toolWidget;
+}
+
void UBBoardController::hide()
{
UBApplication::mainWindow->actionLibrary->setChecked(false);
@@ -1800,11 +1837,9 @@ void UBBoardController::persistCurrentScene()
{
if(UBPersistenceManager::persistenceManager()
&& selectedDocument() && mActiveScene && mActiveSceneIndex != mDeletingSceneIndex
- && (mActiveSceneIndex >= 0)
+ && (mActiveSceneIndex >= 0) && mActiveSceneIndex != mMovingSceneIndex
&& (mActiveScene->isModified() || (UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())))
{
- emit activeSceneWillBePersisted();
-
UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex);
updatePage(mActiveSceneIndex);
}
@@ -2016,23 +2051,28 @@ void UBBoardController::grabScene(const QRectF& pSceneRect)
}
}
-UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos)
+UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos, bool bUseSource)
{
QUuid uuid = QUuid::createUuid();
QUrl concreteUrl = pSourceUrl;
- QString destFile;
- bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
- pSourceUrl.toLocalFile(),
- UBPersistenceManager::videoDirectory,
- uuid,
- destFile);
- if (!b)
+ // media file is not in document folder yet
+ if (!bUseSource)
{
- showMessage(tr("Add file operation failed: file copying error"));
- return NULL;
- }
- concreteUrl = QUrl::fromLocalFile(destFile);
+ QString destFile;
+ bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
+ pSourceUrl.toLocalFile(),
+ UBPersistenceManager::videoDirectory,
+ uuid,
+ destFile);
+ if (!b)
+ {
+ showMessage(tr("Add file operation failed: file copying error"));
+ return NULL;
+ }
+ concreteUrl = QUrl::fromLocalFile(destFile);
+ }// else we just use source Url.
+
UBGraphicsMediaItem* vi = mActiveScene->addMedia(concreteUrl, startPlay, pos);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@@ -2046,23 +2086,27 @@ UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st
}
-UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos)
+UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos, bool bUseSource)
{
QUuid uuid = QUuid::createUuid();
QUrl concreteUrl = pSourceUrl;
- QString destFile;
- bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
- pSourceUrl.toLocalFile(),
- UBPersistenceManager::audioDirectory,
- uuid,
- destFile);
- if (!b)
+ // media file is not in document folder yet
+ if (!bUseSource)
{
- showMessage(tr("Add file operation failed: file copying error"));
- return NULL;
- }
- concreteUrl = QUrl::fromLocalFile(destFile);
+ QString destFile;
+ bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
+ pSourceUrl.toLocalFile(),
+ UBPersistenceManager::audioDirectory,
+ uuid,
+ destFile);
+ if (!b)
+ {
+ showMessage(tr("Add file operation failed: file copying error"));
+ return NULL;
+ }
+ concreteUrl = QUrl::fromLocalFile(destFile);
+ }// else we just use source Url.
UBGraphicsMediaItem* ai = mActiveScene->addMedia(concreteUrl, startPlay, pos);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@@ -2236,7 +2280,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if("" != url)
{
- downloadURL(url, pPos);
+ downloadURL(url, QString(), pPos);
return;
}
}
@@ -2256,7 +2300,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
foreach(const QUrl url, urls){
QPointF pos(pPos + QPointF(index * 15, index * 15));
- downloadURL(url, pos, QSize(), false, internalData);
+ downloadURL(url, QString(), pos, QSize(), false, internalData);
index++;
}
@@ -2282,7 +2326,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
// Sometimes, it is possible to have an URL as text. we check here if it is the case
QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]"));
if(qsTmp.startsWith("http")){
- downloadURL(QUrl(qsTmp), pPos);
+ downloadURL(QUrl(qsTmp), QString(), pPos);
}
else{
mActiveScene->addTextHtml(pMimeData->html(), pPos);
@@ -2296,7 +2340,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
QString qsUrl = UBPlatformUtils::urlFromClipboard();
if("" != qsUrl){
// We finally got the url of the dropped ressource! Let's import it!
- downloadURL(qsUrl, pPos);
+ downloadURL(qsUrl, qsUrl, pPos);
return;
}
#endif
@@ -2313,31 +2357,32 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{
- graphicsWidget->remove();
-
mActiveScene->setURStackEnable(false);
- UBGraphicsItem *toolW3C = duplicateItem(dynamic_cast(graphicsWidget));
- UBGraphicsWidgetItem *copyedGraphicsWidget = NULL;
-
- if (UBGraphicsWidgetItem::Type == toolW3C->type())
- copyedGraphicsWidget = static_cast(toolW3C);
-
- UBToolWidget *toolWidget = new UBToolWidget(copyedGraphicsWidget);
- mActiveScene->addItem(toolWidget);
- qreal ssf = 1 / UBApplication::boardController->systemScaleFactor();
-
- toolWidget->setScale(ssf);
- toolWidget->setPos(graphicsWidget->scenePos());
+ graphicsWidget->remove(false);
+ mActiveScene->addItemToDeletion(graphicsWidget);
+
+ UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget, mControlView);
mActiveScene->setURStackEnable(true);
+
+ QPoint controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center());
+ toolWidget->centerOn(mControlView->mapTo(mControlContainer, controlViewPos));
+ toolWidget->show();
}
void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
{
- UBGraphicsWidgetItem *graphicsWidgetItem = addW3cWidget(toolWidget->graphicsWidgetItem()->widgetUrl(), QPointF(0, 0));
- graphicsWidgetItem->setPos(toolWidget->pos());
+ UBGraphicsWidgetItem *widgetToScene = toolWidget->toolWidget();
+
+ widgetToScene->resetTransform();
+
+ QPoint mainWindowCenter = toolWidget->mapTo(mMainWindow, QPoint(toolWidget->width(), toolWidget->height()) / 2);
+ QPoint controlViewCenter = mControlView->mapFrom(mMainWindow, mainWindowCenter);
+ QPointF scenePos = mControlView->mapToScene(controlViewCenter);
+
+ mActiveScene->addGraphicsWidget(widgetToScene, scenePos);
+
toolWidget->remove();
- graphicsWidgetItem->setSelected(true);
}
diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h
index ed40b26a..d7f44e37 100644
--- a/src/board/UBBoardController.h
+++ b/src/board/UBBoardController.h
@@ -193,8 +193,8 @@ class UBBoardController : public UBDocumentContainer
void firstScene();
void lastScene();
void groupButtonClicked();
- void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false);
- UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader,
+ void downloadURL(const QUrl& url, QString contentSourceUrl = QString(), const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false);
+ UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pHeader,
QByteArray pData, QPointF pPos, QSize pSize,
bool isBackground = false, bool internalData = false);
void changeBackground(bool isDark, bool isCrossed);
@@ -203,14 +203,15 @@ class UBBoardController : public UBDocumentContainer
void hideMessage();
void setDisabled(bool disable);
void setColorIndex(int pColorIndex);
+ void removeTool(UBToolWidget* toolWidget);
void hide();
void show();
void setWidePageSize(bool checked);
void setRegularPageSize(bool checked);
void stylusToolChanged(int tool);
void grabScene(const QRectF& pSceneRect);
- UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos);
- UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos);
+ UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
+ UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
void cut();
@@ -228,8 +229,6 @@ class UBBoardController : public UBDocumentContainer
signals:
void newPageAdded();
- void activeSceneWillBePersisted();
- void activeSceneWillChange();
void activeSceneChanged();
void zoomChanged(qreal pZoomFactor);
void systemScaleFactorChanged(qreal pSystemScaleFactor);
@@ -285,6 +284,7 @@ class UBBoardController : public UBDocumentContainer
bool mCacheWidgetIsEnabled;
QGraphicsItem* mLastCreatedItem;
int mDeletingSceneIndex;
+ int mMovingSceneIndex;
QString mActionGroupText;
QString mActionUngroupText;
diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp
index 2652bb15..612813cd 100644
--- a/src/board/UBBoardPaletteManager.cpp
+++ b/src/board/UBBoardPaletteManager.cpp
@@ -995,6 +995,7 @@ void UBBoardPaletteManager::startDownloads()
mDownloadInProgress = true;
mpDownloadWidget->setVisibleState(true);
mRightPalette->addTab(mpDownloadWidget);
+ mpDownloadWidget;
}
}
diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index 3ccc7640..1d68cc8a 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -61,6 +61,7 @@
#include "tools/UBGraphicsCache.h"
#include "tools/UBGraphicsTriangle.h"
#include "tools/UBGraphicsProtractor.h"
+#include "tools/UBGraphicsAristo.h"
#include "core/memcheck.h"
@@ -307,7 +308,6 @@ UBBoardView::event (QEvent * e)
if (gestureEvent)
{
QSwipeGesture* swipe = dynamic_cast (gestureEvent->gesture (Qt::SwipeGesture));
-
if (swipe)
{
if (swipe->horizontalDirection () == QSwipeGesture::Left)
@@ -362,9 +362,7 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
QPointF scenePos = viewportTransform ().inverted ().map (tabletPos);
qreal pressure = 1.0;
- if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line)
- && mPenPressureSensitive)
- || (currentTool == UBStylusTool::Marker && mMarkerPressureSensitive))
+ if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line) && mPenPressureSensitive) || (currentTool == UBStylusTool::Marker && mMarkerPressureSensitive))
pressure = event->pressure ();
@@ -521,6 +519,7 @@ Here we determines cases when items should to get mouse press event at pressing
case UBGraphicsTriangle::Type:
case UBGraphicsCompass::Type:
case UBGraphicsCache::Type:
+ case UBGraphicsAristo::Type:
return true;
case UBGraphicsDelegateFrame::Type:
@@ -553,8 +552,8 @@ Here we determines cases when items should to get mouse press event at pressing
return false;
break;
- case UBToolWidget::Type:
- return true;
+ //case UBToolWidget::Type:
+ // return true;
case QGraphicsWebView::Type:
return true;
@@ -1123,7 +1122,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
DelegateButton::Type != movingItem->type() &&
QGraphicsSvgItem::Type != movingItem->type() &&
UBGraphicsDelegateFrame::Type != movingItem->type() &&
- UBToolWidget::Type != movingItem->type() &&
+// UBToolWidget::Type != movingItem->type() &&
UBGraphicsCache::Type != movingItem->type() &&
QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools.
!(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()))
@@ -1364,6 +1363,11 @@ void UBBoardView::dropEvent (QDropEvent *event)
event->acceptProposedAction();
}
}
+ //prevent features in UBFeaturesWidget deletion from the model when event is processing inside
+ //Qt base classes
+ if (event->dropAction() == Qt::MoveAction) {
+ event->setDropAction(Qt::CopyAction);
+ }
}
void
diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp
index a9bbeb08..049ee301 100644
--- a/src/board/UBFeaturesController.cpp
+++ b/src/board/UBFeaturesController.cpp
@@ -711,7 +711,7 @@ void UBFeaturesController::addItemToPage(const UBFeature &item)
void UBFeaturesController::addItemAsBackground(const UBFeature &item)
{
- UBApplication::boardController->downloadURL( item.getFullPath(), QPointF(), QSize(), true );
+ UBApplication::boardController->downloadURL( item.getFullPath(), QString(), QPointF(), QSize(), true );
}
UBFeature UBFeaturesController::getDestinationFeatureForUrl( const QUrl &url )
diff --git a/src/core/UB.h b/src/core/UB.h
index 716df59c..aeb619d2 100644
--- a/src/core/UB.h
+++ b/src/core/UB.h
@@ -145,6 +145,7 @@ struct UBGraphicsItemType
TriangleItemType,
MagnifierItemType,
cacheItemType,
+ AristoItemType,
groupContainerType,
ToolWidgetItemType,
GraphicsWidgetItemType,
diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp
index deb11c6e..a2043121 100644
--- a/src/core/UBApplication.cpp
+++ b/src/core/UBApplication.cpp
@@ -130,6 +130,8 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing
|| args.contains("log");
+ setupTranslators(args);
+
UBResources::resources();
if (!undoStack)
@@ -139,8 +141,6 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing
UBSettings *settings = UBSettings::settings();
- setupTranslators(args);
-
connect(settings->appToolBarPositionedAtTop, SIGNAL(changed(QVariant)), this, SLOT(toolBarPositionChanged(QVariant)));
connect(settings->appToolBarDisplayText, SIGNAL(changed(QVariant)), this, SLOT(toolBarDisplayTextChanged(QVariant)));
updateProtoActionsState();
diff --git a/src/core/UBDownloadManager.cpp b/src/core/UBDownloadManager.cpp
index 4127851f..e120038a 100644
--- a/src/core/UBDownloadManager.cpp
+++ b/src/core/UBDownloadManager.cpp
@@ -14,12 +14,79 @@
*/
#include "UBDownloadManager.h"
#include "core/UBApplication.h"
+#include "core/UBPersistenceManager.h"
#include "gui/UBMainWindow.h"
#include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h"
+#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h"
+
+UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent)
+: QThread(parent)
+, mDesc(desc)
+, m_bAborting(false)
+{
+
+}
+
+UBAsyncLocalFileDownloader *UBAsyncLocalFileDownloader::download()
+{
+ if (!QFile::exists(QUrl(mDesc.srcUrl).toLocalFile())) {
+ qDebug() << "file" << mDesc.srcUrl << "does not present in fs";
+ return this;
+ }
+
+ start();
+
+ return this;
+}
+
+void UBAsyncLocalFileDownloader::run()
+{
+
+ QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl);
+
+ int position=mimeType.indexOf(";");
+ if(position != -1)
+ mimeType=mimeType.left(position);
+
+ UBMimeType::Enum itemMimeType = UBFileSystemUtils::mimeTypeFromString(mimeType);
+
+
+ QString destDirectory;
+ if (UBMimeType::Video == itemMimeType)
+ destDirectory = UBPersistenceManager::videoDirectory;
+ else
+ if (UBMimeType::Audio == itemMimeType)
+ destDirectory = UBPersistenceManager::audioDirectory;
+
+ if (mDesc.originalSrcUrl.isEmpty())
+ mDesc.originalSrcUrl = mDesc.srcUrl;
+
+ QString uuid = QUuid::createUuid();
+ UBPersistenceManager::persistenceManager()->addFileToDocument(UBApplication::boardController->selectedDocument(),
+ QUrl(mDesc.srcUrl).toLocalFile(),
+ destDirectory,
+ uuid,
+ mTo,
+ NULL);
+
+ if (m_bAborting)
+ {
+ if (QFile::exists(mTo))
+ QFile::remove(mTo);
+ }
+ else
+ emit signal_asyncCopyFinished(mDesc.id, !mTo.isEmpty(), QUrl::fromLocalFile(mTo), QUrl::fromLocalFile(mDesc.originalSrcUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground);
+}
+
+void UBAsyncLocalFileDownloader::abort()
+{
+ m_bAborting = true;
+}
+
/** The unique instance of the download manager */
static UBDownloadManager* pInstance = NULL;
@@ -100,7 +167,7 @@ void UBDownloadManager::init()
{
mCrntDL.clear();
mPendingDL.clear();
- mReplies.clear();
+ mDownloads.clear();
mLastID = 1;
mDLAvailability.clear();
for(int i=0; iget(url, desc.pos, desc.size, desc.isBackground);
+ if (desc.srcUrl.startsWith("file://") || desc.srcUrl.startsWith("/"))
+ {
+ UBAsyncLocalFileDownloader * cpHelper = new UBAsyncLocalFileDownloader(desc, this);
+ connect(cpHelper, SIGNAL(signal_asyncCopyFinished(int, bool, QUrl, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QUrl,QString, QByteArray, QPointF, QSize, bool)));
+ QObject *res = dynamic_cast(cpHelper->download());
+ if (!res)
+ delete res;
+ else
+ mDownloads[desc.id] = res;
+ }
+ else
+ {
+ UBDownloadHttpFile* http = new UBDownloadHttpFile(desc.id, this);
+ connect(http, SIGNAL(downloadProgress(int, qint64,qint64)), this, SLOT(onDownloadProgress(int,qint64,qint64)));
+ connect(http, SIGNAL(downloadFinished(int, bool, QUrl, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QUrl, QString, QByteArray, QPointF, QSize, bool)));
+
+ //the desc.srcUrl is encoded. So we have to decode it before.
+ QUrl url;
+ url.setEncodedUrl(desc.srcUrl.toUtf8());
+ // We send here the request and store its reply in order to be able to cancel it if needed
+ mDownloads[desc.id] = dynamic_cast(http->get(url, desc.pos, desc.size, desc.isBackground));
+ }
}
/**
@@ -356,10 +437,18 @@ void UBDownloadManager::checkIfModalRemains()
void UBDownloadManager::cancelDownloads()
{
// Stop the current downloads
- QMap::iterator it = mReplies.begin();
- for(; it!=mReplies.end();it++)
+ QMap::iterator it = mDownloads.begin();
+ for(; it!=mDownloads.end();it++)
{
- dynamic_cast(it.value())->abort();
+ QNetworkReply *netReply = dynamic_cast(it.value());
+ if (netReply)
+ netReply->abort();
+ else
+ {
+ UBAsyncLocalFileDownloader *localDownload = dynamic_cast(it.value());
+ if (localDownload)
+ localDownload->abort();
+ }
}
// Clear all the lists
@@ -372,7 +461,8 @@ void UBDownloadManager::cancelDownloads()
void UBDownloadManager::onDownloadError(int id)
{
- QNetworkReply* pReply = mReplies.value(id);
+ QNetworkReply *pReply = dynamic_cast(mDownloads.value(id));
+
if(NULL != pReply)
{
// Check which error occured:
@@ -402,9 +492,25 @@ void UBDownloadManager::finishDownloads(bool cancel)
void UBDownloadManager::cancelDownload(int id)
{
+ if (!mDownloads.size())
+ return;
+
// Stop the download
- mReplies[id]->abort();
- mReplies.remove(id);
+
+ QNetworkReply *pNetworkDownload = dynamic_cast(mDownloads[id]);
+ if (pNetworkDownload)
+ pNetworkDownload->abort();
+ else
+ {
+ UBAsyncLocalFileDownloader *pLocalDownload = dynamic_cast(mDownloads[id]);
+ if (pLocalDownload)
+ {
+ if (pLocalDownload->isRunning())
+ pLocalDownload->abort();
+ }
+ }
+
+ mDownloads.remove(id);
// Remove the canceled download from the download lists
bool bFound = false;
@@ -494,7 +600,7 @@ void UBDownloadHttpFile::onDownloadFinished(bool pSuccess, QUrl sourceUrl, QStri
if(pSuccess)
{
// Notify the end of the download
- emit downloadFinished(mId, pSuccess, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground);
+ emit downloadFinished(mId, pSuccess, sourceUrl, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground);
}
else
{
diff --git a/src/core/UBDownloadManager.h b/src/core/UBDownloadManager.h
index 2b5c52c0..cefa8f40 100644
--- a/src/core/UBDownloadManager.h
+++ b/src/core/UBDownloadManager.h
@@ -52,7 +52,8 @@ struct sDownloadFileDesc
int id;
int totalSize;
int currentSize;
- QString url;
+ QString srcUrl;
+ QString originalSrcUrl;
QString contentTypeHeader;
bool modal;
QPointF pos; // For board drop only
@@ -75,7 +76,7 @@ public:
signals:
void downloadProgress(int id, qint64 current,qint64 total);
- void downloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
+ void downloadFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void downloadError(int id);
private slots:
@@ -86,6 +87,28 @@ private:
int mId;
};
+class UBAsyncLocalFileDownloader : public QThread
+{
+ Q_OBJECT
+public:
+ UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0);
+
+ UBAsyncLocalFileDownloader *download();
+ void run();
+ void abort();
+
+signals:
+ void finished(QString srcUrl, QString resUrl);
+ void signal_asyncCopyFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
+
+
+private:
+ sDownloadFileDesc mDesc;
+ bool m_bAborting;
+ QString mFrom;
+ QString mTo;
+};
+
class UBDownloadManager : public QObject
{
Q_OBJECT
@@ -108,7 +131,7 @@ signals:
void downloadFinished(bool pSuccess, int id, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData);
void downloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData);
void downloadModalFinished();
- void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
+ void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void addDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData);
void cancelAllDownloads();
void allDownloadsFinished();
@@ -116,7 +139,7 @@ signals:
private slots:
void onUpdateDownloadLists();
void onDownloadProgress(int id, qint64 received, qint64 total);
- void onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
+ void onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void onDownloadError(int id);
private:
@@ -138,7 +161,7 @@ private:
/** The current download availability (-1 = free, otherwise the file ID is recorded)*/
QVector mDLAvailability;
/** A map containing the replies of the GET operations */
- QMap mReplies;
+ QMap mDownloads;
};
#endif // UBDOWNLOADMANAGER_H
diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp
index 21733038..f1806705 100644
--- a/src/core/UBPersistenceManager.cpp
+++ b/src/core/UBPersistenceManager.cpp
@@ -265,7 +265,7 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName,
return doc;
}
-UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName, const QString& pName, bool withEmptyPage)
+UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName, const QString& pName, bool withEmptyPage, bool addTitlePage)
{
checkIfDocumentRepositoryExists();
@@ -280,7 +280,8 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
{
doc->setMetaData(UBSettings::documentName, pName);
}
- if (withEmptyPage) createDocumentSceneAt(doc, 0);
+ if(withEmptyPage) createDocumentSceneAt(doc, 0);
+ if(addTitlePage) persistDocumentScene(doc, mSceneCache.createScene(doc, 0, false), 0);
QMap metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory);
@@ -463,11 +464,6 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL
}
}
-
- foreach(int index, compactedIndexes)
- {
- emit documentSceneDeleted(proxy, index);
- }
}
@@ -576,8 +572,6 @@ void UBPersistenceManager::moveSceneToIndex(UBDocumentProxy* proxy, int source,
thumb.rename(proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", target));
mSceneCache.moveScene(proxy, source, target);
-
- emit documentSceneMoved(proxy, target);
}
@@ -612,7 +606,7 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
UBBoardPaletteManager* paletteManager = UBApplication::boardController->paletteManager();
bool teacherGuideModified = false;
- if(paletteManager->teacherGuideDockWidget())
+ if(UBApplication::app()->boardController->currentPage() == pSceneIndex && paletteManager->teacherGuideDockWidget())
teacherGuideModified = paletteManager->teacherGuideDockWidget()->teacherGuideWidget()->isModified();
if (pDocumentProxy->isModified() || teacherGuideModified)
@@ -628,8 +622,6 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
}
mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene);
-
- emit documentCommitted(pDocumentProxy);
}
diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h
index c38e9895..6a514bcb 100644
--- a/src/core/UBPersistenceManager.h
+++ b/src/core/UBPersistenceManager.h
@@ -47,7 +47,7 @@ class UBPersistenceManager : public QObject
static void destroy();
virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true);
- virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = false);
+ virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = false, bool addTitlePage = false);
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy);
@@ -117,13 +117,10 @@ class UBPersistenceManager : public QObject
void documentCreated(UBDocumentProxy* pDocumentProxy);
void documentMetadataChanged(UBDocumentProxy* pDocumentProxy);
- void documentCommitted(UBDocumentProxy* pDocumentProxy);
void documentWillBeDeleted(UBDocumentProxy* pDocumentProxy);
void documentSceneCreated(UBDocumentProxy* pDocumentProxy, int pIndex);
- void documentSceneMoved(UBDocumentProxy* pDocumentProxy, int pIndex);
void documentSceneWillBeDeleted(UBDocumentProxy* pDocumentProxy, int pIndex);
- void documentSceneDeleted(UBDocumentProxy* pDocumentProxy, int pDeletedIndex);
private:
diff --git a/src/core/main.cpp b/src/core/main.cpp
index 28a631b7..55c4e0a8 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -129,7 +129,7 @@ int main(int argc, char *argv[])
QObject::connect(&app, SIGNAL(messageReceived(const QString&)), &app, SLOT(handleOpenMessage(const QString&)));
- qDebug() << fileToOpen;
+ qDebug() << "file name argument" << fileToOpen;
int result = app.exec(fileToOpen);
app.cleanup();
diff --git a/src/document/UBDocumentContainer.cpp b/src/document/UBDocumentContainer.cpp
index ce8549a7..3fe49207 100644
--- a/src/document/UBDocumentContainer.cpp
+++ b/src/document/UBDocumentContainer.cpp
@@ -94,7 +94,6 @@ void UBDocumentContainer::updatePage(int index)
void UBDocumentContainer::deleteThumbPage(int index)
{
mDocumentThumbs.removeAt(index);
- emit documentPageDeleted(index);
}
void UBDocumentContainer::updateThumbPage(int index)
@@ -106,7 +105,6 @@ void UBDocumentContainer::updateThumbPage(int index)
void UBDocumentContainer::insertThumbPage(int index)
{
mDocumentThumbs.insert(index, UBThumbnailAdaptor::get(mCurrentDocument, index));
- emit documentPageAdded(index);
}
void UBDocumentContainer::reloadThumbnails()
diff --git a/src/document/UBDocumentContainer.h b/src/document/UBDocumentContainer.h
index b1c2aba1..d5694ae0 100644
--- a/src/document/UBDocumentContainer.h
+++ b/src/document/UBDocumentContainer.h
@@ -58,8 +58,6 @@ class UBDocumentContainer : public QObject
signals:
void documentSet(UBDocumentProxy* document);
- void documentPageAdded(int index);
- void documentPageDeleted(int index);
void documentPageUpdated(int index);
void documentThumbnailsUpdated(UBDocumentContainer* source);
};
diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp
index 89d1e95f..cc0505cd 100644
--- a/src/domain/UBGraphicsDelegateFrame.cpp
+++ b/src/domain/UBGraphicsDelegateFrame.cpp
@@ -563,8 +563,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mTranslateX += fixedPoint.x() - bottomRight.x();
mTranslateY += fixedPoint.y() - bottomRight.y();
}
- else if (moving() || rotating())
- delegated()->setTransform(tr);
+ delegated()->setTransform(buildTransform());
}
else // resizing/resizing horizontally
{
diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp
index 0b23509f..a1d57202 100644
--- a/src/domain/UBGraphicsItemDelegate.cpp
+++ b/src/domain/UBGraphicsItemDelegate.cpp
@@ -58,6 +58,7 @@ DelegateButton::DelegateButton(const QString & fileName, QGraphicsItem* pDelegat
{
setAcceptedMouseButtons(Qt::LeftButton);
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
+ setCacheMode(QGraphicsItem::NoCache); /* because of SANKORE-1017: this allows pixmap to be refreshed when grabbing window, thus teacher screen is synchronized with main screen. */
}
DelegateButton::~DelegateButton()
diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp
index 1faba0ce..9d3c8705 100644
--- a/src/domain/UBGraphicsMediaItem.cpp
+++ b/src/domain/UBGraphicsMediaItem.cpp
@@ -73,7 +73,11 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
mMediaObject = new Phonon::MediaObject(this);
- if (pMediaFileUrl.toLocalFile().contains("videos"))
+ QString mediaPath = pMediaFileUrl.toString();
+ if ("" == mediaPath)
+ mediaPath = pMediaFileUrl.toLocalFile();
+
+ if (mediaPath.toLower().contains("videos"))
{
mMediaType = mediaType_Video;
@@ -91,7 +95,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
haveLinkedImage = true;
}
else
- if (pMediaFileUrl.toLocalFile().contains("audios"))
+ if (mediaPath.toLower().contains("audios"))
{
mMediaType = mediaType_Audio;
mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
@@ -191,7 +195,7 @@ void UBGraphicsMediaItem::setSourceUrl(const QUrl &pSourceUrl)
UBAudioPresentationWidget* pAudioWidget = dynamic_cast(mAudioWidget);
if (pAudioWidget)
{
- pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toString()));
+ pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toLocalFile()));
}
UBItem::setSourceUrl(pSourceUrl);
diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp
index 90b40f61..621dc9a4 100644
--- a/src/domain/UBGraphicsScene.cpp
+++ b/src/domain/UBGraphicsScene.cpp
@@ -39,6 +39,7 @@
#include "tools/UBGraphicsTriangle.h"
#include "tools/UBGraphicsCurtainItem.h"
#include "tools/UBGraphicsCache.h"
+#include "tools/UBGraphicsAristo.h"
#include "document/UBDocumentProxy.h"
@@ -581,8 +582,8 @@ bool UBGraphicsScene::inputDeviceRelease()
addItem(pStrokes);
mDrawWithCompass = false;
- }else if (mCurrentStroke)
- {
+ }
+ else if (mCurrentStroke){
UBGraphicsStrokesGroup* pStrokes = new UBGraphicsStrokesGroup();
// Remove the strokes that were just drawn here and replace them by a stroke item
@@ -628,8 +629,8 @@ bool UBGraphicsScene::inputDeviceRelease()
if (mCurrentStroke && mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
+ mCurrentStroke = NULL;
}
- mCurrentStroke = NULL;
return accepted;
}
@@ -1216,6 +1217,11 @@ void UBGraphicsScene::textUndoCommandAdded(UBGraphicsTextItem *textItem)
}
UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos)
{
+ qDebug() << pMediaFileUrl.toLocalFile();
+ if (!QFile::exists(pMediaFileUrl.toLocalFile()))
+ if (!QFile::exists(pMediaFileUrl.toString()))
+ return NULL;
+
UBGraphicsMediaItem* mediaItem = new UBGraphicsMediaItem(pMediaFileUrl);
if(mediaItem){
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), mediaItem, SLOT(activeSceneChanged()));
@@ -1310,7 +1316,7 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co
if (graphicsWidget->canBeContent())
{
-// graphicsWidget->widgetWebView()->loadMainHtml();
+ graphicsWidget->loadMainHtml();
graphicsWidget->setSelected(true);
if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented
@@ -1602,6 +1608,9 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
--mItemCount;
mFastAccessItems.removeAll(item);
+ /* delete the item if it is cache to allow its reinstanciation, because Cache implements design pattern Singleton. */
+ if (dynamic_cast(item))
+ UBCoreGraphicsScene::deleteItem(item);
}
void UBGraphicsScene::removeItems(const QSet& items)
@@ -1937,19 +1946,35 @@ void UBGraphicsScene::addCompass(QPointF center)
compass->setVisible(true);
}
-void UBGraphicsScene::addCache()
+void UBGraphicsScene::addAristo(QPointF center)
{
- UBGraphicsCache* cache = new UBGraphicsCache();
- mTools << cache;
+ UBGraphicsAristo* aristo = new UBGraphicsAristo();
+ mTools << aristo;
- addItem(cache);
+ aristo->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
- cache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
+ addItem(aristo);
- cache->setVisible(true);
- cache->setSelected(true);
- UBApplication::boardController->notifyCache(true);
- UBApplication::boardController->notifyPageChanged();
+ QPointF itemSceneCenter = aristo->sceneBoundingRect().center();
+ aristo->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y());
+
+ aristo->setVisible(true);
+ setModified(true);
+}
+
+void UBGraphicsScene::addCache()
+{
+ UBGraphicsCache* cache = UBGraphicsCache::instance(this);
+ if (!items().contains(cache)) {
+ addItem(cache);
+
+ cache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
+
+ cache->setVisible(true);
+ cache->setSelected(true);
+ UBApplication::boardController->notifyCache(true);
+ UBApplication::boardController->notifyPageChanged();
+ }
}
void UBGraphicsScene::addMask(const QPointF ¢er)
@@ -2277,10 +2302,12 @@ void UBGraphicsScene::setToolCursor(int tool)
if (mCurrentStroke && mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
+ mCurrentStroke = NULL;
}
- mCurrentStroke = NULL;
+
}
-void UBGraphicsScene::initStroke(){
+void UBGraphicsScene::initStroke()
+{
mCurrentStroke = new UBGraphicsStroke();
}
diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h
index 1c9c847f..6d496369 100644
--- a/src/domain/UBGraphicsScene.h
+++ b/src/domain/UBGraphicsScene.h
@@ -216,6 +216,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void addCompass(QPointF center);
void addTriangle(QPointF center);
void addMagnifier(UBMagnifierParams params);
+ void addAristo(QPointF center);
void addMask(const QPointF ¢er = QPointF());
void addCache();
diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp
index 5bd2b725..53ecc53a 100644
--- a/src/domain/UBGraphicsWidgetItem.cpp
+++ b/src/domain/UBGraphicsWidgetItem.cpp
@@ -563,7 +563,8 @@ void UBGraphicsWidgetItem::injectInlineJavaScript()
void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
- if (scene()->renderingContext() != UBGraphicsScene::Screen)
+
+ if (scene() && scene()->renderingContext() != UBGraphicsScene::Screen)
{
painter->drawPixmap(0, 0, snapshot());
}
@@ -622,52 +623,52 @@ void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok)
update(boundingRect());
}
-void UBGraphicsWidgetItem::wheelEvent(QGraphicsSceneWheelEvent *event)
-{
- if (Delegate()->weelEvent(event))
- {
- QGraphicsWebView::wheelEvent(event);
- event->accept();
- }
-}
-
-QVariant UBGraphicsWidgetItem::itemChange(GraphicsItemChange change, const QVariant &value)
-{
- if ((change == QGraphicsItem::ItemSelectedHasChanged) && scene()) {
- if (isSelected())
- scene()->setActiveWindow(this);
- else
- if(scene()->activeWindow() == this)
- scene()->setActiveWindow(0);
- }
-
- QVariant newValue = Delegate()->itemChange(change, value);
- return QGraphicsWebView::itemChange(change, newValue);
-}
-
-void UBGraphicsWidgetItem::resize(qreal w, qreal h)
-{
- UBGraphicsWidgetItem::resize(QSizeF(w, h));
-}
-
-
-void UBGraphicsWidgetItem::resize(const QSizeF & pSize)
-{
- if (pSize != size()) {
- QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height());
- QGraphicsWebView::resize(pSize.width(), pSize.height());
- if (Delegate())
- Delegate()->positionHandles();
- if (scene())
- scene()->setModified(true);
- }
-}
-
-QSizeF UBGraphicsWidgetItem::size() const
-{
- return QGraphicsWebView::size();
-}
-
+void UBGraphicsWidgetItem::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+ if (Delegate()->weelEvent(event))
+ {
+ QGraphicsWebView::wheelEvent(event);
+ event->accept();
+ }
+}
+
+QVariant UBGraphicsWidgetItem::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if ((change == QGraphicsItem::ItemSelectedHasChanged) && scene()) {
+ if (isSelected())
+ scene()->setActiveWindow(this);
+ else
+ if(scene()->activeWindow() == this)
+ scene()->setActiveWindow(0);
+ }
+
+ QVariant newValue = Delegate()->itemChange(change, value);
+ return QGraphicsWebView::itemChange(change, newValue);
+}
+
+void UBGraphicsWidgetItem::resize(qreal w, qreal h)
+{
+ UBGraphicsWidgetItem::resize(QSizeF(w, h));
+}
+
+
+void UBGraphicsWidgetItem::resize(const QSizeF & pSize)
+{
+ if (pSize != size()) {
+ QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height());
+ QGraphicsWebView::resize(pSize.width(), pSize.height());
+ if (Delegate())
+ Delegate()->positionHandles();
+ if (scene())
+ scene()->setModified(true);
+ }
+}
+
+QSizeF UBGraphicsWidgetItem::size() const
+{
+ return QGraphicsWebView::size();
+}
+
UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent)
diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp
index 36a61945..2bde7364 100644
--- a/src/frameworks/UBFileSystemUtils.cpp
+++ b/src/frameworks/UBFileSystemUtils.cpp
@@ -19,7 +19,6 @@
#include "core/UBApplication.h"
-#include "board/UBBoardController.h"
#include "document/UBDocumentContainer.h"
#include "globals/UBGlobals.h"
@@ -854,5 +853,4 @@ QString UBFileSystemUtils::readTextFile(QString path)
}
return "";
-}
-
+}
\ No newline at end of file
diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h
index 13c82dbf..6a0597f6 100644
--- a/src/frameworks/UBFileSystemUtils.h
+++ b/src/frameworks/UBFileSystemUtils.h
@@ -17,14 +17,17 @@
#define UBFILESYSTEMUTILS_H_
#include
+#include
#include "core/UB.h"
class QuaZipFile;
class UBProcessingProgressListener;
-class UBFileSystemUtils
+class UBFileSystemUtils : public QObject
{
+ Q_OBJECT
+
public:
UBFileSystemUtils();
diff --git a/src/frameworks/UBPlatformUtils_linux.cpp b/src/frameworks/UBPlatformUtils_linux.cpp
index 8c10c4c9..5566116a 100644
--- a/src/frameworks/UBPlatformUtils_linux.cpp
+++ b/src/frameworks/UBPlatformUtils_linux.cpp
@@ -17,6 +17,7 @@
#include
+#include
#include
#include
diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp
index 90b45615..4faaa83b 100644
--- a/src/gui/UBDocumentNavigator.cpp
+++ b/src/gui/UBDocumentNavigator.cpp
@@ -89,27 +89,9 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
{
const QPixmap* pix = source->pageAt(i);
- QPixmap result(pix->width(),pix->height());
int pageIndex = UBDocumentContainer::pageFromSceneIndex(i);
- QPainter composePainter;
- composePainter.begin(&result);
- composePainter.drawPixmap(QPoint(0,0),*pix);
-
- if(pageIndex == UBApplication::boardController->currentPage() &&
- ((pageIndex == 0 && UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) ||
- (pageIndex && UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()))
- ) {
- if(UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()){
- QPixmap toque(":images/toque.png");
- composePainter.setOpacity(0.6);
- composePainter.drawPixmap(QPoint(pix->width() - toque.width(),0),toque);
- }
- }
-
- composePainter.end();
-
- UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(result, source->selectedDocument(), i);
+ UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i);
QString label = pageIndex == 0 ? tr("Title page") : tr("Page %0").arg(pageIndex);
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label);
@@ -128,7 +110,6 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
void UBDocumentNavigator::onScrollToSelectedPage(int index)
{
- qDebug() << "Selection in widget: " << index;
int c = 0;
foreach(UBImgTextThumbnailElement el, mThumbsWithLabels)
{
@@ -286,7 +267,6 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
break;
}
}
- qDebug() << "Selected Scene: " << index;
UBApplication::boardController->setActiveDocumentScene(index);
}
QGraphicsView::mousePressEvent(event);
diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp
index ee052027..e5e6ab69 100644
--- a/src/gui/UBFeaturesWidget.cpp
+++ b/src/gui/UBFeaturesWidget.cpp
@@ -12,10 +12,6 @@
const char *UBFeaturesWidget::objNamePathList = "PathList";
const char *UBFeaturesWidget::objNameFeatureList = "FeatureList";
-const QString UBFeaturesNewFolderDialog::acceptText = tr("Accept");
-const QString UBFeaturesNewFolderDialog::cancelText = tr("Cancel");
-const QString UBFeaturesNewFolderDialog::labelText = tr("Enter a new folder name");
-
const QMargins FeatureListMargins(0, 0, 0, 30);
const int FeatureListBorderOffset = 10;
const char featureTypeSplitter = ':';
@@ -198,7 +194,6 @@ void UBFeaturesWidget::lockIt(bool pLock)
mActionBar->setEnabled(!pLock);
pathListView->setEnabled(!pLock);
centralWidget->setLockedExcludingAdditional(pLock);
-// pathListView->setLocked(true);
}
void UBFeaturesWidget::addToFavorite( const UBFeaturesMimeData * mimeData )
@@ -578,6 +573,9 @@ void UBFeaturesCentralWidget::scanFinished()
}
UBFeaturesNewFolderDialog::UBFeaturesNewFolderDialog(QWidget *parent) : QWidget(parent)
+ , acceptText(tr("Accept"))
+ , cancelText(tr("Cancel"))
+ , labelText(tr("Enter a new folder name"))
{
this->setStyleSheet("background:white;");
@@ -1048,8 +1046,8 @@ void UBFeatureProperties::onAddToLib()
desc.modal = false;
desc.name = QFileInfo( mpElement->getFullPath().toString()).fileName();
qDebug() << desc.name;
- desc.url = mpElement->getFullPath().toString();
- qDebug() << desc.url;
+ desc.srcUrl = mpElement->getFullPath().toString();
+ qDebug() << desc.srcUrl;
UBDownloadManager::downloadManager()->addFileToDownload(desc);
}
}
diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h
index a86f6697..e4fb9775 100644
--- a/src/gui/UBFeaturesWidget.h
+++ b/src/gui/UBFeaturesWidget.h
@@ -193,9 +193,9 @@ public:
void setLockedExcludingAdditional(bool pLock);
QStackedWidget *mStackedWidget;
- UBFeaturesNavigatorWidget *mNavigator;
- UBFeatureProperties *mFeatureProperties;
- UBFeaturesWebView *webView;
+ UBFeaturesNavigatorWidget *mNavigator;
+ UBFeatureProperties *mFeatureProperties;
+ UBFeaturesWebView *webView;
QStackedWidget *mAdditionalDataContainer;
@@ -226,10 +226,6 @@ class UBFeaturesNewFolderDialog : public QWidget
Q_OBJECT
public:
- static const QString acceptText;
- static const QString cancelText;
- static const QString labelText;
-
UBFeaturesNewFolderDialog(QWidget *parent = 0);
void setRegexp(const QRegExp pRegExp);
bool validString(const QString &pStr);
@@ -249,7 +245,9 @@ private:
QRegExpValidator *mValidator;
QStringList mFileNameList;
QPushButton *acceptButton;
-
+ const QString acceptText;
+ const QString cancelText;
+ const QString labelText;
};
class UBFeaturesProgressInfo: public QWidget {
diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp
index 0a6a0121..db2d8bf7 100644
--- a/src/gui/UBTeacherGuideWidgetsTools.cpp
+++ b/src/gui/UBTeacherGuideWidgetsTools.cpp
@@ -230,10 +230,8 @@ void UBTGAdaptableText::bottomMargin(int newValue)
void UBTGAdaptableText::focusInEvent(QFocusEvent* e)
{
- qDebug() << "pippa";
if(isReadOnly()){
e->ignore();
- qDebug() << "ignored";
}
managePlaceholder(true);
QTextEdit::focusInEvent(e);
@@ -247,7 +245,6 @@ void UBTGAdaptableText::focusOutEvent(QFocusEvent* e){
void UBTGAdaptableText::managePlaceholder(bool focus){
if(focus){
if(toPlainText() == mPlaceHolderText){
- qDebug() << "Place holder found";
setTextColor(QColor(Qt::black));
setPlainText("");
}
diff --git a/src/gui/UBToolWidget.cpp b/src/gui/UBToolWidget.cpp
index 5b8a601b..84afd33d 100644
--- a/src/gui/UBToolWidget.cpp
+++ b/src/gui/UBToolWidget.cpp
@@ -32,32 +32,32 @@ QPixmap* UBToolWidget::sClosePixmap = 0;
QPixmap* UBToolWidget::sUnpinPixmap = 0;
-UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent)
- : QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
+UBToolWidget::UBToolWidget(const QUrl& pUrl, QWidget *pParent)
+ : QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mShouldMoveWidget(false)
, mContentMargin(0)
, mFrameWidth(0)
- , mGraphicsWebView(0)
- , mGraphicsWidgetItem(0)
+ , mWebView(0)
+ , mToolWidget(0)
{
int widgetType = UBGraphicsWidgetItem::widgetType(pUrl);
if (widgetType == UBWidgetType::Apple)
- mGraphicsWidgetItem = new UBGraphicsAppleWidgetItem(pUrl, this);
+ mToolWidget = new UBGraphicsAppleWidgetItem(pUrl);
else if (widgetType == UBWidgetType::W3C)
- mGraphicsWidgetItem = new UBGraphicsW3CWidgetItem(pUrl, this);
+ mToolWidget = new UBGraphicsW3CWidgetItem(pUrl);
else
qDebug() << "UBToolWidget::UBToolWidget: Unknown widget Type";
initialize();
}
-UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent)
- : QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
+UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QWidget *pParent)
+ : QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mShouldMoveWidget(false)
, mContentMargin(0)
, mFrameWidth(0)
- , mGraphicsWebView(0)
- , mGraphicsWidgetItem(pWidget)
+ , mWebView(0)
+ , mToolWidget(pWidget)
{
initialize();
javaScriptWindowObjectCleared();
@@ -76,50 +76,66 @@ void UBToolWidget::initialize()
if(!sUnpinPixmap)
sUnpinPixmap = new QPixmap(":/images/unpin.svg");
- UBGraphicsScene *wscene = dynamic_cast(mGraphicsWidgetItem->scene());
+ UBGraphicsScene *wscene = dynamic_cast(mToolWidget->scene());
if (wscene)
{
- wscene->removeItemFromDeletion(mGraphicsWidgetItem);
- wscene->removeItem(mGraphicsWidgetItem);
+ wscene->removeItemFromDeletion(mToolWidget);
+ wscene->removeItem(mToolWidget);
}
- mGraphicsWidgetItem->setParent(this);
-
- QGraphicsLinearLayout *graphicsLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
+ mWebView = new QWebView(this);
+
+ QPalette palette = mWebView->page()->palette();
+ palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
+ mWebView->page()->setPalette(palette);
+
+
+ mWebView->installEventFilter(this);
+
mFrameWidth = UBSettings::settings()->objectFrameWidth;
mContentMargin = sClosePixmap->width() / 2 + mFrameWidth;
- graphicsLayout->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin);
- setPreferredSize(mGraphicsWidgetItem->preferredWidth() + mContentMargin * 2, mGraphicsWidgetItem->preferredHeight() + mContentMargin * 2);
+ setLayout(new QVBoxLayout());
+ layout()->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin);
+ layout()->addWidget(mWebView);
- mGraphicsWebView = new QGraphicsWebView(this);
- connect(mGraphicsWebView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
- mGraphicsWebView->load(mGraphicsWidgetItem->mainHtml());
- graphicsLayout->addItem(mGraphicsWebView);
+ setFixedSize(mToolWidget->boundingRect().width() + mContentMargin * 2, mToolWidget->boundingRect().height() + mContentMargin * 2);
- mGraphicsWebView->setAcceptDrops(false);
- mGraphicsWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
- mGraphicsWebView->setAttribute(Qt::WA_OpaquePaintEvent, false);
+ connect(mWebView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
+ mWebView->load(mToolWidget->mainHtml());
- QPalette palette = mGraphicsWebView->page()->palette();
- palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
- mGraphicsWebView->page()->setPalette(palette);
- setLayout(graphicsLayout);
+ mWebView->setAcceptDrops(false);
+ mWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
+ mWebView->setAttribute(Qt::WA_OpaquePaintEvent, false);
+
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared()));
}
-bool UBToolWidget::event(QEvent *event)
+
+bool UBToolWidget::eventFilter(QObject *obj, QEvent *event)
{
- if (event->type() == QEvent::ShortcutOverride)
- event->accept();
- return QGraphicsWidget::event(event);
+ if (mShouldMoveWidget && obj == mWebView && event->type() == QEvent::MouseMove)
+ {
+ QMouseEvent *mouseMoveEvent = static_cast(event);
+
+ if (mouseMoveEvent->buttons() & Qt::LeftButton)
+ {
+ move(pos() - mMousePressPos + mWebView->mapTo(this, mouseMoveEvent->pos()));
+
+ event->accept();
+ return true;
+ }
+ }
+
+ // standard event processing
+ return QObject::eventFilter(obj, event);
}
-void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
+void UBToolWidget::mousePressEvent(QMouseEvent *event)
{
- QGraphicsWidget::mousePressEvent(event);
+ QWidget::mousePressEvent(event);
/* did webkit consume the mouse press ? */
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
@@ -128,108 +144,92 @@ void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
update();
}
-void UBToolWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+void UBToolWidget::mouseMoveEvent(QMouseEvent *event)
{
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) {
- setPos(pos() - mMousePressPos + event->pos());
+ move(pos() - mMousePressPos + event->pos());
event->accept();
}
- QGraphicsWidget::mouseMoveEvent(event);
+ QWidget::mouseMoveEvent(event);
}
-void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+void UBToolWidget::mouseReleaseEvent(QMouseEvent *event)
{
mShouldMoveWidget = false;
if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width() && event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height()) {
- remove();
+ UBApplication::boardController->removeTool(this);
event->accept();
}
- else if (mGraphicsWidgetItem->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width() && event->pos().y() >= 0 && event->pos().y() < sUnpinPixmap->height()) {
+ else if (mToolWidget->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width() && event->pos().y() >= 0 && event->pos().y() < sUnpinPixmap->height()) {
UBApplication::boardController->moveToolWidgetToScene(this);
event->accept();
}
else
- QGraphicsWidget::mouseReleaseEvent(event); /* don't propgate to parent, the widget is deleted in UBApplication */
+ QWidget::mouseReleaseEvent(event); /* don't propgate to parent, the widget is deleted in UBApplication */
}
-void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+void UBToolWidget::paintEvent(QPaintEvent *event)
{
- QGraphicsWidget::paint(painter, option, widget);
-
- /* painting lightweight toolbar */
- if (isActiveWindow()) {
- painter->setRenderHint(QPainter::Antialiasing);
- painter->setPen(Qt::NoPen);
- painter->setBrush(QColor(127, 127, 127, 127));
-
- painter->drawRoundedRect(QRectF(sClosePixmap->width() / 2, sClosePixmap->height() / 2, preferredWidth() - sClosePixmap->width(), mFrameWidth), mFrameWidth / 2, mFrameWidth / 2);
- painter->drawPixmap(0, 0, *sClosePixmap);
- if (mGraphicsWidgetItem->canBeContent())
- painter->drawPixmap(mContentMargin, 0, *sUnpinPixmap);
+ QWidget::paintEvent(event);
+
+ //if (isActiveWindow())
+ {
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(QColor(127, 127, 127, 127));
+
+ painter.drawRoundedRect(QRectF(sClosePixmap->width() / 2
+ , sClosePixmap->height() / 2
+ , width() - sClosePixmap->width()
+ , mFrameWidth)
+ , mFrameWidth / 2
+ , mFrameWidth / 2);
+
+ painter.drawPixmap(0, 0, *sClosePixmap);
+
+ if (mToolWidget->canBeContent())
+ painter.drawPixmap(mContentMargin, 0, *sUnpinPixmap);
}
}
void UBToolWidget::javaScriptWindowObjectCleared()
{
- UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene(), mGraphicsWidgetItem);
+ UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene(), mToolWidget);
- mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI);
+ mWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI);
- UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast(mGraphicsWidgetItem);
+ UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast(mToolWidget);
if (graphicsW3cWidgetItem)
{
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem);
- mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI);
+ mWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI);
}
}
-UBGraphicsWidgetItem* UBToolWidget::graphicsWidgetItem() const
+UBGraphicsWidgetItem* UBToolWidget::toolWidget() const
{
- return mGraphicsWidgetItem;
+ return mToolWidget;
}
-QPointF UBToolWidget::naturalCenter() const
+QPoint UBToolWidget::naturalCenter() const
{
- if (mGraphicsWebView)
- return mGraphicsWebView->geometry().center();
+ if (mWebView)
+ return mWebView->geometry().center();
else
- return QPointF(0, 0);
-}
-
-void UBToolWidget::centerOn(const QPointF& pos)
-{
- QGraphicsWidget::setPos(pos - QPointF(preferredWidth() / 2, preferredHeight() / 2));
+ return QPoint(0, 0);
}
void UBToolWidget::remove()
{
- mGraphicsWebView->setHtml(QString());
- scene()->removeItem(this);
-}
-
-UBGraphicsScene* UBToolWidget::scene()
-{
- return qobject_cast(QGraphicsItem::scene());
-}
-
-QPointF UBToolWidget::pos() const
-{
- return QPointF(QGraphicsItem::pos().x() + mContentMargin * scale(), QGraphicsItem::pos().y() + mContentMargin * scale());
-}
-
-void UBToolWidget::setPos(const QPointF &point)
-{
- UBToolWidget::setPos(point.x(), point.y());
-}
-
-void UBToolWidget::setPos(qreal x, qreal y)
-{
- QGraphicsItem::setPos(x - mContentMargin * scale(), y - mContentMargin * scale());
+ mToolWidget = NULL;
+ hide();
+ deleteLater();
}
-int UBToolWidget::type() const
+void UBToolWidget::centerOn(const QPoint& pos)
{
- return Type;
+ QWidget::move(pos - QPoint(width() / 2, height() / 2));
}
diff --git a/src/gui/UBToolWidget.h b/src/gui/UBToolWidget.h
index 94939d0f..3e413dff 100644
--- a/src/gui/UBToolWidget.h
+++ b/src/gui/UBToolWidget.h
@@ -17,60 +17,52 @@
#define UBTOOLWIDGET_H_
#include
-#include
-#include "core/UB.h"
-class UBGraphicsScene;
class UBGraphicsWidgetItem;
+class QWidget;
+class UBGraphicsScene;
+class QWebView;
-class UBToolWidget : public QGraphicsWidget
+class UBToolWidget : public QWidget
{
- Q_OBJECT
+ Q_OBJECT;
public:
- UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent = 0);
- UBToolWidget(UBGraphicsWidgetItem* pGraphicsWidgetItem, QGraphicsItem *pParent = 0);
+ UBToolWidget(const QUrl& pUrl, QWidget* pParent = 0);
+ UBToolWidget(UBGraphicsWidgetItem* pWidget, QWidget* pParent = 0);
virtual ~UBToolWidget();
- UBGraphicsWidgetItem* graphicsWidgetItem() const;
- QPointF naturalCenter() const;
-
- void centerOn(const QPointF& pos);
void remove();
+ void centerOn(const QPoint& pos);
- virtual UBGraphicsScene* scene();
- virtual QPointF pos() const;
- virtual void setPos(const QPointF &point);
- virtual void setPos(qreal x, qreal y);
- virtual int type() const;
-
- enum
- {
- Type = UBGraphicsItemType::ToolWidgetItemType
- };
+ QPoint naturalCenter() const;
+
+ UBGraphicsWidgetItem *toolWidget() const;
protected:
void initialize();
+ virtual void paintEvent(QPaintEvent *event);
+
+ virtual void mousePressEvent(QMouseEvent *event);
+ virtual void mouseMoveEvent(QMouseEvent *event);
+ virtual void mouseReleaseEvent(QMouseEvent *event);
- virtual bool event(QEvent *event);
- virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual bool eventFilter(QObject *obj, QEvent *event);
private slots:
void javaScriptWindowObjectCleared();
protected:
- bool mShouldMoveWidget;
- int mContentMargin;
- int mFrameWidth;
- QGraphicsWebView *mGraphicsWebView;
- UBGraphicsWidgetItem *mGraphicsWidgetItem;
- QPointF mMousePressPos;
+ QWebView *mWebView;
+ UBGraphicsWidgetItem *mToolWidget;
static QPixmap *sClosePixmap;
static QPixmap *sUnpinPixmap;
+
+ QPoint mMousePressPos;
+ bool mShouldMoveWidget;
+ int mContentMargin;
+ int mFrameWidth;
};
#endif /* UBTOOLWIDGET_H_ */
diff --git a/src/tools/UBGraphicsAristo.cpp b/src/tools/UBGraphicsAristo.cpp
new file mode 100644
index 00000000..61762774
--- /dev/null
+++ b/src/tools/UBGraphicsAristo.cpp
@@ -0,0 +1,828 @@
+/*
+ * 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 .
+ */
+
+#include "UBGraphicsAristo.h"
+#include "board/UBBoardController.h"
+#include "board/UBDrawingController.h"
+#include "core/UBApplication.h"
+#include "domain/UBGraphicsScene.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "core/memcheck.h"
+
+const QRectF UBGraphicsAristo::sDefaultRect = QRectF(0, 0, 800, 500);
+const UBGraphicsAristo::Orientation UBGraphicsAristo::sDefaultOrientation = UBGraphicsAristo::Bottom;
+
+UBGraphicsAristo::UBGraphicsAristo()
+ : UBAbstractDrawRuler()
+ , QGraphicsPathItem()
+ , mMarking(false)
+ , mResizing(false)
+ , mRotating(false)
+ , mOrientation(Undefined)
+ , mRotatedAngle(0)
+ , mMarkerAngle(0)
+ , mStartAngle(0)
+ , mSpan(180)
+ , mHFlipSvgItem(0)
+ , mMarkerSvgItem(0)
+ , mResizeSvgItem(0)
+ , mRotateSvgItem(0)
+{
+ mHFlipSvgItem = new QGraphicsSvgItem(":/images/vflipTool.svg", this);
+ mHFlipSvgItem->setVisible(false);
+ mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
+
+ mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this);
+ mResizeSvgItem->setVisible(false);
+ mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
+
+ mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
+ mRotateSvgItem->setVisible(false);
+ mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
+
+ mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this);
+ mMarkerSvgItem->setVisible(false);
+ mMarkerSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
+ mMarkerSvgItem->setVisible(true);
+
+ create(*this);
+ setBoundingRect(sDefaultRect);
+ setOrientation(sDefaultOrientation);
+}
+
+UBGraphicsAristo::~UBGraphicsAristo()
+{
+ /* NOOP */
+}
+
+/*
+ * setOrientation() modify the tool orientation.
+ * makeGeometryChange() is called so points are recomputed, control items are positionnated and shape is determined according to this modification.
+ */
+void UBGraphicsAristo::setOrientation(Orientation orientation)
+{
+ mOrientation = orientation;
+ makeGeometryChange();
+}
+
+/* calculatePoints() is used to calculate polygon's apexes coordinates.
+ * This function handles orientation changes too.
+ */
+void UBGraphicsAristo::calculatePoints()
+{
+ switch (mOrientation) {
+ case Bottom:
+ C.setX(boundingRect().center().x());
+ C.setY(boundingRect().bottom());
+
+ A.setX(boundingRect().left());
+ A.setY(boundingRect().bottom() - boundingRect().width() / 2);
+
+ B.setX(boundingRect().right());
+ B.setY(boundingRect().bottom() - boundingRect().width() / 2);
+ break;
+ case Top:
+ C.setX(boundingRect().center().x());
+ C.setY(boundingRect().top());
+
+ A.setX(boundingRect().left());
+ A.setY(boundingRect().top() + boundingRect().width() / 2);
+
+ B.setX(boundingRect().right());
+ B.setY(boundingRect().top() + boundingRect().width() / 2);
+ break;
+ default:
+ break;
+ }
+}
+
+/*
+ * setItemsPos() places control items according to A, B and C positions.
+ * Call this function after A, B or C position modification, mostly after calling calculatePoints().
+ * These positions has to be set when calling setPath() to allow hover events on items which are not into the main polygon.
+ */
+void UBGraphicsAristo::setItemsPos()
+{
+ mCloseSvgItem->setPos(closeButtonRect().topLeft() + rotationCenter());
+ mHFlipSvgItem->setPos(hFlipRect().topLeft() + rotationCenter());
+ mRotateSvgItem->setPos(rotateRect().topLeft() + rotationCenter());
+ mResizeSvgItem->setPos(resizeButtonRect().topLeft() + rotationCenter());
+ mMarkerSvgItem->setPos(markerButtonRect().topLeft() + rotationCenter());
+}
+
+/*
+ * determinePath() modify the shape according to apexes coordinates and control item positions.
+ * This is useful when orientation is modified.
+ * Returns the painter path corresponding to object parameters.
+ */
+QPainterPath UBGraphicsAristo::determinePath()
+{
+ QPainterPath path;
+
+ QPolygonF polygon;
+ polygon << A << B << C;
+ path.addPolygon(polygon);
+
+ path.addPath(mResizeSvgItem->shape().translated(mResizeSvgItem->pos()));
+ path.addPath(mMarkerSvgItem->shape().translated(mMarkerSvgItem->pos()));
+
+ return path;
+}
+
+/*
+ * setBoundingRect() is a helper to set the given rectangle as the new shape to limit apexes coordinates.
+ * This is useful when instanciating or resizing the object.
+ * makeGeometryChange() is called so points are recomputed, control items are positionnated and shape is determined according to this modification.
+ * Setting bounds' width less than 300 is not allowed.
+ */
+void UBGraphicsAristo::setBoundingRect(QRectF boundingRect)
+{
+ if (boundingRect.width() < 300)
+ return;
+
+ QPainterPath path;
+ path.addRect(boundingRect);
+ setPath(path);
+ if (mOrientation != Undefined)
+ makeGeometryChange();
+}
+
+void UBGraphicsAristo::makeGeometryChange()
+{
+ calculatePoints();
+ setItemsPos();
+ setPath(determinePath());
+}
+
+
+UBItem* UBGraphicsAristo::deepCopy(void) const
+{
+ UBGraphicsAristo* copy = new UBGraphicsAristo();
+ copyItemParameters(copy);
+ return copy;
+}
+
+void UBGraphicsAristo::copyItemParameters(UBItem *copy) const
+{
+ UBGraphicsAristo* cp = dynamic_cast(copy);
+ if (cp)
+ {
+ /* TODO: copy all members */
+ cp->setPos(this->pos());
+ cp->setTransform(this->transform());
+ cp->setBoundingRect(boundingRect());
+ cp->setOrientation(mOrientation);
+ cp->mRotatedAngle = mRotatedAngle;
+ cp->mMarkerAngle = mMarkerAngle;
+ }
+}
+
+
+void UBGraphicsAristo::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPolygonF polygon;
+
+ painter->setBrush(fillBrush());
+ painter->setPen(drawColor());
+
+ polygon << A << B << C;
+ painter->drawPolygon(polygon);
+ polygon.clear();
+
+ paintGraduations(painter);
+ paintMarker(painter);
+}
+
+QBrush UBGraphicsAristo::fillBrush() const
+{
+ QColor fillColor = edgeFillColor();// scene()->isDarkBackground() ? sDarkBackgroundFillColor : sFillColor;
+ QColor fillColorCenter = middleFillColor();//scene()->isDarkBackground() ? sDarkBackgroundFillColorCenter : sFillColorCenter;
+ QColor transparentWhite = Qt::white;
+ transparentWhite.setAlpha(scene()->isDarkBackground() ? sDrawTransparency : sFillTransparency);
+ QRadialGradient radialGradient(boundingRect().center(), radius(), boundingRect().center());
+ radialGradient.setColorAt(0, fillColorCenter);
+ radialGradient.setColorAt(1, fillColor);
+ return radialGradient;
+}
+
+/* paintGraduations() paints graduations on the ruler side (length graduations) and the two other sides (angle graduation) */
+void UBGraphicsAristo::paintGraduations(QPainter *painter)
+{
+ paintRulerGraduations(painter);
+ paintProtractorGraduations(painter);
+}
+
+void UBGraphicsAristo::paintRulerGraduations(QPainter *painter)
+{
+ /* defining useful constants */
+ const int centimeterGraduationHeight = 15;
+ const int halfCentimeterGraduationHeight = 10;
+ const int millimeterGraduationHeight = 5;
+ const int millimetersPerCentimeter = 10;
+ const int millimetersPerHalfCentimeter = 5;
+
+ painter->save();
+ painter->setFont(font());
+ QFontMetricsF fontMetrics(painter->font());
+
+ /* Browsing milliters in half width of ruler side */
+ for (int millimeters = 0; millimeters < (boundingRect().width() / 2 - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++)
+ {
+ /* defining graduationHeight ; values are different to draw bigger lines if millimiter considered is a centimeter or a half centimeter */
+ int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ?
+ centimeterGraduationHeight :
+ ((0 == millimeters % millimetersPerHalfCentimeter) ?
+ halfCentimeterGraduationHeight : millimeterGraduationHeight);
+
+ /* correcting graduationHeight: draw the line in the other direction in case ruler is top-oriented, to stay inside the tool and inside the rect */
+ graduationHeight = mOrientation == Bottom ? graduationHeight : - graduationHeight;
+
+ /* drawing graduation to the left and to the right of origin, which is the center of graduated side */
+ painter->drawLine(QLine(rotationCenter().x() + sPixelsPerMillimeter * millimeters, rotationCenter().y(), rotationCenter().x() + sPixelsPerMillimeter * millimeters, rotationCenter().y() + graduationHeight));
+ if (millimeters != 0)
+ painter->drawLine(QLine(rotationCenter().x() - sPixelsPerMillimeter * millimeters, rotationCenter().y(), rotationCenter().x() - sPixelsPerMillimeter * millimeters, rotationCenter().y() + graduationHeight));
+
+ /* drawing associated value if considered graduation is a centimeter */
+ if (0 == millimeters % millimetersPerCentimeter)
+ {
+ /* defining graduation value */
+ QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter));
+
+ /* staying inside polygon */
+ if (rotationCenter().x() + sPixelsPerMillimeter * millimeters + fontMetrics.width(text) / 2 < boundingRect().right())
+ {
+ qreal textWidth = fontMetrics.width(text);
+ qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5;
+
+ /* text y-coordinate is different according to tool's orientation */
+ qreal textY = mOrientation == Bottom ? A.y() + 5 + centimeterGraduationHeight : A.y() - 5 - centimeterGraduationHeight + graduationHeight;
+
+ /* if text's rect is not out of polygon's bounds, drawing value below or above graduation */
+ QPointF intersectionPoint;
+
+ bool paint = false;
+
+ if (mOrientation == Bottom && QLineF(QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters - textWidth / 2, rotationCenter().y()), QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters - textWidth / 2, textY + textHeight)).intersect(QLineF(A, C), &intersectionPoint) != QLineF::BoundedIntersection && QLineF(QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters + textWidth / 2, rotationCenter().y()), QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters + textWidth / 2, textY + textHeight)).intersect(QLineF(A, C), &intersectionPoint) != QLineF::BoundedIntersection) {
+ paint = true;
+ }
+ else if (mOrientation == Top && QLineF(QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters - textWidth / 2, rotationCenter().y()), QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters - textWidth / 2, textY - textHeight)).intersect(QLineF(A, C), &intersectionPoint) != QLineF::BoundedIntersection && QLineF(QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters + textWidth / 2, rotationCenter().y()), QPointF(rotationCenter().x() - sPixelsPerMillimeter * millimeters + textWidth / 2, textY - textHeight)).intersect(QLineF(A, C), &intersectionPoint) != QLineF::BoundedIntersection) {
+ paint = true;
+ }
+
+ if (paint) {
+ painter->drawText(
+ QRectF(rotationCenter().x() + sPixelsPerMillimeter * millimeters - textWidth / 2, textY, textWidth, textHeight),
+ Qt::AlignVCenter, text);
+ if (millimeters != 0)
+ painter->drawText(
+ QRectF(rotationCenter().x() - sPixelsPerMillimeter * millimeters - textWidth / 2, textY, textWidth, textHeight),
+ Qt::AlignVCenter, text);
+ }
+ }
+ }
+ }
+ painter->restore();
+}
+
+void UBGraphicsAristo::paintProtractorGraduations(QPainter* painter)
+{
+ /* defining useful constants */
+ const int tenDegreeGraduationLength = 15;
+ const int fiveDegreeGraduationLength = 10;
+ const int oneDegreeGraduationLength = 5;
+
+ painter->save();
+
+ QFont font1 = painter->font();
+#ifdef Q_WS_MAC
+ font1.setPointSizeF(font1.pointSizeF() - 3);
+#endif
+ QFontMetricsF fm1(font1);
+
+ //Font for internal arc
+ QFont font2 = painter->font();
+ font2.setPointSizeF(font1.pointSizeF()/1.5);
+ QFontMetricsF fm2(font2);
+
+ /* defining virtual arc diameter */
+ qreal rad = radius();
+
+ QPointF center = rotationCenter();
+
+ /* browsing angles */
+ for (int angle = 1; angle < mSpan; angle++)
+ {
+ int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength);
+
+ qreal co = cos(((qreal)angle + mStartAngle) * PI/180);
+ qreal si = sin(((qreal)angle + mStartAngle) * PI/180);
+
+ /* inverse sinus according to the orientation, to draw graduations on the polygon */
+ si = mOrientation == Bottom ? -si : si;
+
+ /* drawing the graduation around the virtual arc */
+ if (angle >= sArcAngleMargin && angle <= mSpan - sArcAngleMargin)
+ painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
+ QPointF(center.x()+ (rad/2 + graduationLength)*co,
+ center.y() - (rad/2 + graduationLength)*si)));
+
+
+ QPointF intersectionPoint;
+ QLineF referenceLine;
+ if (angle < 90)
+ referenceLine.setP1(B);
+ else
+ referenceLine.setP1(A);
+ referenceLine.setP2(C);
+
+ /* if angle is 10-multiple, drawing it's value, rotated to be easily red */
+ if (0 == angle % 10) {
+ QString grad = QString("%1").arg((int)(angle));
+ QString grad2 = QString("%1").arg((int)mSpan - angle);
+
+ painter->setFont(font2);
+
+ painter->save();
+ painter->translate(center.x() + (rad/2 + graduationLength*1.5)*co, center.y() - (rad/2 + graduationLength*1.5)*si);
+ int degrees = mOrientation == Bottom ? angle : -angle;
+ painter->rotate(-90 + degrees);
+ painter->drawText(- fm2.width(grad)/2, - fm2.height()/2, fm2.width(grad), fm2.height(), Qt::AlignCenter, grad);
+ painter->restore();
+
+ painter->setFont(font1);
+
+
+ /* drawing the graduation near tool's side */
+ if (QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
+ QPointF(center.x()+ (rad/2 + graduationLength)*co,
+ center.y() - (rad/2 + graduationLength)*si)).intersect(referenceLine, &intersectionPoint) == QLineF::UnboundedIntersection)
+
+ painter->drawLine(QLineF(QPointF(center.x() + (rad/2 + graduationLength*1.5 + fm2.width(grad)/2)*co,
+ center.y() - (rad/2 + graduationLength*1.5 + fm2.height()/2)*si),
+ intersectionPoint));
+
+ }
+
+ /* drawing the graduation near tool's side */
+ else
+ if (QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
+ QPointF(center.x()+ (rad/2 + graduationLength)*co,
+ center.y() - (rad/2 + graduationLength)*si)).intersect(referenceLine, &intersectionPoint) == QLineF::UnboundedIntersection)
+
+ painter->drawLine(QLineF(QPointF(intersectionPoint.x() - (graduationLength*1.5)*co,
+ intersectionPoint.y() + (graduationLength*1.5)*si),
+ intersectionPoint));
+ }
+
+ painter->restore();
+}
+
+/* paintMarker() adjust marker button according to the current angle, draw the line allowing user to set precisely the angle, and draw the current angle's value. */
+void UBGraphicsAristo::paintMarker(QPainter *painter)
+{
+ /* adjusting marker button */
+ mMarkerSvgItem->resetTransform();
+ mMarkerSvgItem->translate(-markerButtonRect().left(), -markerButtonRect().top());
+ mMarkerSvgItem->rotate(mMarkerAngle);
+ mMarkerSvgItem->translate(markerButtonRect().left(), markerButtonRect().top());
+
+
+ qreal co = cos((mMarkerAngle) * PI/180);
+ qreal si = sin((mMarkerAngle) * PI/180);
+
+ /* Setting point composing the line (from point C) which intersects the line we want to draw. */
+ QPointF referencePoint;
+ if (mOrientation == Bottom) {
+ if ((int)mMarkerAngle % 360 < 90)
+ referencePoint = B;
+ else
+ referencePoint = A;
+ }
+ else if (mOrientation == Top) {
+ if ((int)mMarkerAngle % 360 < 270 && (int)mMarkerAngle % 360 > 0)
+ referencePoint = A;
+ else
+ referencePoint = B;
+ }
+
+ /* getting intersection point to draw the wanted line */
+ QLineF intersectedLine(rotationCenter(), QPointF(rotationCenter().x()+co, rotationCenter().y()+si));
+ QPointF intersectionPoint;
+ if (intersectedLine.intersect(QLineF(referencePoint, C), &intersectionPoint))
+ painter->drawLine(QLineF(intersectionPoint, rotationCenter()));
+
+ /* drawing angle value */
+ qreal rightAngle = mOrientation == Bottom ? mMarkerAngle : 360 - mMarkerAngle;
+
+
+ QString angleText = QString("%1°").arg(rightAngle, 0, 'f', 1);
+
+ QFont font1 = painter->font();
+#ifdef Q_WS_MAC
+ font1.setPointSizeF(font1.pointSizeF() - 3);
+#endif
+ QFontMetricsF fm1(font1);
+
+ if (mOrientation == Bottom)
+ painter->drawText(rotationCenter().x() - fm1.width(angleText)/2 - radius()/8, rotationCenter().y() + radius()/8 - fm1.height()/2, fm1.width(angleText), fm1.height(), Qt::AlignCenter, angleText);
+ else
+ painter->drawText(rotationCenter().x() - fm1.width(angleText)/2 - radius()/8, rotationCenter().y() - radius()/8 - fm1.height()/2, fm1.width(angleText), fm1.height(), Qt::AlignCenter, angleText);
+}
+
+
+void UBGraphicsAristo::rotateAroundCenter(qreal angle)
+{
+ qreal oldAngle = mRotatedAngle;
+ mRotatedAngle = angle;
+ QTransform transform;
+ rotateAroundCenter(transform, rotationCenter());
+ setTransform(transform, true);
+ mRotatedAngle = oldAngle + angle; // We have to store absolute value for FLIP case
+}
+
+void UBGraphicsAristo::rotateAroundCenter(QTransform& transform, QPointF center)
+{
+ transform.translate(center.x(), center.y());
+ transform.rotate(mRotatedAngle);
+ transform.translate(- center.x(), - center.y());
+}
+
+void UBGraphicsAristo::resize(qreal factor)
+{
+ prepareGeometryChange();
+ translate(rotationCenter().x(), rotationCenter().y());
+ scale(factor, factor);
+ translate(-rotationCenter().x(), -rotationCenter().y());
+}
+
+
+QPointF UBGraphicsAristo::rotationCenter() const
+{
+ return QPointF((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
+}
+
+QRectF UBGraphicsAristo::closeButtonRect() const
+{
+ qreal y = radius() / 4 + hFlipRect().height() + 3 + rotateRect().height() + 3;
+ if (mOrientation == Top)
+ y = -y;
+ return QRectF(- mCloseSvgItem->boundingRect().width() / 2, y, mCloseSvgItem->boundingRect().width(), mCloseSvgItem->boundingRect().height());
+}
+
+QRectF UBGraphicsAristo::hFlipRect() const
+{
+ qreal y = radius() / 4;
+ if (mOrientation == Top)
+ y = -y;
+
+ return QRectF(- mHFlipSvgItem->boundingRect().width() / 2, y, mHFlipSvgItem->boundingRect().width(), mHFlipSvgItem->boundingRect().height());
+}
+
+QRectF UBGraphicsAristo::markerButtonRect() const
+{
+ return QRectF (radius()/2 - mMarkerSvgItem->boundingRect().width(), - mMarkerSvgItem->boundingRect().height()/2, mMarkerSvgItem->boundingRect().width(), mMarkerSvgItem->boundingRect().height());
+}
+
+QRectF UBGraphicsAristo::resizeButtonRect() const
+{
+ return QRectF((B - rotationCenter()).x() - 100 - mResizeSvgItem->boundingRect().width()/2, - mResizeSvgItem->boundingRect().height()/2, mResizeSvgItem->boundingRect().width(), mResizeSvgItem->boundingRect().height());
+}
+
+QRectF UBGraphicsAristo::rotateRect() const
+{
+ qreal y = radius() / 4 + hFlipRect().height() + 3;
+ if (mOrientation == Top)
+ y = -y;
+ return QRectF(- mRotateSvgItem->boundingRect().width() / 2, y, mRotateSvgItem->boundingRect().width(), mRotateSvgItem->boundingRect().height());
+
+}
+
+QCursor UBGraphicsAristo::flipCursor() const
+{
+ return Qt::ArrowCursor;
+}
+
+QCursor UBGraphicsAristo::markerCursor() const
+{
+ return Qt::ArrowCursor;
+}
+
+QCursor UBGraphicsAristo::resizeCursor() const
+{
+ return Qt::ArrowCursor;
+}
+
+
+void UBGraphicsAristo::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ switch (toolFromPos(event->pos())) {
+ case Rotate:
+ mRotating = true;
+ event->accept();
+ break;
+ case Resize:
+ mResizing = true;
+ event->accept();
+ break;
+ case MoveMarker:
+ mMarking = true;
+ event->accept();
+ break;
+ default:
+ QGraphicsItem::mousePressEvent(event);
+ break;
+ }
+
+ mShowButtons = false;
+ mHFlipSvgItem->setVisible(false);
+ mCloseSvgItem->setVisible(false);
+ mRotateSvgItem->setVisible(mRotating);
+ mResizeSvgItem->setVisible(mResizing);
+ update();
+}
+
+void UBGraphicsAristo::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+
+ if (!mResizing && !mRotating && !mMarking)
+ {
+ QGraphicsItem::mouseMoveEvent(event);
+ }
+ else
+ {
+ QLineF currentLine(rotationCenter(), event->pos());
+ QLineF lastLine(rotationCenter(), event->lastPos());
+
+ if (mRotating) {
+
+ rotateAroundCenter(currentLine.angleTo(lastLine));
+ }
+ else if (mResizing) {
+ QPointF delta = event->pos() - event->lastPos();
+ setBoundingRect(QRectF(boundingRect().topLeft(), QSizeF(boundingRect().width() + delta.x(), boundingRect().height() + delta.x())));
+ }
+ else if(mMarking) {
+ qreal angle = currentLine.angleTo(lastLine);
+
+ mMarkerAngle += angle;
+ mMarkerAngle -= (int)(mMarkerAngle/360)*360;
+
+ if (mOrientation == Bottom) {
+ if (mMarkerAngle >= 270)
+ mMarkerAngle = 0;
+ else if (mMarkerAngle > 180)
+ mMarkerAngle = 180;
+ }
+ else if (mOrientation == Top) {
+ if (mMarkerAngle < 90)
+ mMarkerAngle = 360;
+ else if (mMarkerAngle < 180)
+ mMarkerAngle = 180;
+ }
+ update();
+ }
+
+ event->accept();
+ }
+}
+
+void UBGraphicsAristo::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (mResizing || mRotating || mMarking)
+ {
+ mResizing = false;
+ mRotating = false;
+ mMarking = false;
+ event->accept();
+ }
+ else
+ {
+ switch (toolFromPos(event->pos())) {
+ case Close :
+ hide();
+ emit hidden();
+ break;
+ case HorizontalFlip:
+ /* substracting difference to zero [2pi] twice, to obtain the desired angle */
+ mMarkerAngle -= 2 * (mMarkerAngle - (int)(mMarkerAngle/360)*360) - 360;
+ /* setting new orientation */
+ switch(mOrientation) {
+ case Bottom:
+ setOrientation(Top);
+ break;
+ case Top:
+ setOrientation(Bottom);
+ break;
+ default:
+ break;
+ }
+ default:
+ QGraphicsItem::mouseReleaseEvent(event);
+ break;
+ }
+ }
+
+ mShowButtons = true;
+ update();
+ if (scene())
+ scene()->setModified(true);
+}
+
+void UBGraphicsAristo::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+{
+ UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
+
+ if (currentTool == UBStylusTool::Selector) {
+ mShowButtons = true;
+ mHFlipSvgItem->setVisible(true);
+ mRotateSvgItem->setVisible(true);
+ mResizeSvgItem->setVisible(true);
+ mCloseSvgItem->setVisible(true);
+
+ switch (toolFromPos(event->pos())) {
+ case HorizontalFlip:
+ setCursor(flipCursor());
+ break;
+ case Rotate:
+ setCursor(rotateCursor());
+ break;
+ case Resize:
+ setCursor(resizeCursor());
+ break;
+ case MoveMarker:
+ setCursor(markerCursor());
+ break;
+ case Close:
+ setCursor(closeCursor());
+ break;
+ default:
+ setCursor(moveCursor());
+ break;
+ }
+
+ event->accept();
+ update();
+
+ } else if (UBDrawingController::drawingController()->isDrawingTool()) {
+ setCursor(drawRulerLineCursor());
+ UBDrawingController::drawingController()->mActiveRuler = this;
+ event->accept();
+ }
+}
+
+void UBGraphicsAristo::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+{
+ mShowButtons = false;
+ setCursor(Qt::ArrowCursor);
+ mHFlipSvgItem->setVisible(false);
+ mRotateSvgItem->setVisible(false);
+ mResizeSvgItem->setVisible(false);
+ mCloseSvgItem->setVisible(false);
+ UBDrawingController::drawingController()->mActiveRuler = NULL;
+ event->accept();
+ update();
+}
+
+void UBGraphicsAristo::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+{
+ UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
+
+ if (currentTool == UBStylusTool::Selector)
+ {
+ mShowButtons = true;
+ mHFlipSvgItem->setVisible(true);
+ mRotateSvgItem->setVisible(true);
+ mResizeSvgItem->setVisible(true);
+ mCloseSvgItem->setVisible(true);
+
+ switch (toolFromPos(event->pos())) {
+ case HorizontalFlip:
+ setCursor(flipCursor());
+ break;
+ case Rotate:
+ setCursor(rotateCursor());
+ break;
+ case Resize:
+ setCursor(resizeCursor());
+ break;
+ case MoveMarker:
+ setCursor(markerCursor());
+ break;
+ case Close:
+ setCursor(closeCursor());
+ break;
+ default:
+ setCursor(moveCursor());
+ break;
+ }
+
+ event->accept();
+ }
+ else if (UBDrawingController::drawingController()->isDrawingTool())
+ event->accept();
+}
+
+/*
+ * toolfromPos() returns the item type corresponding to the given position.
+ * This method is used to reduce the amount of code in each event function and improve class' maintainability.
+ * pos: event's position ; a rotation is done to counter elements rotation, like the marker button.
+ */
+UBGraphicsAristo::Tool UBGraphicsAristo::toolFromPos(QPointF pos)
+{
+ pos = pos - rotationCenter();
+
+ qreal rotationAngle = mOrientation == Bottom ? - mMarkerAngle : Top ? 360 * (int)(mMarkerAngle / 360 + 1) - mMarkerAngle : 0;
+
+ QTransform t;
+ t.rotate(rotationAngle);
+ QPointF p2 = t.map(pos);
+
+ if (resizeButtonRect().contains(pos))
+ return Resize;
+ else if (closeButtonRect().contains(pos))
+ return Close;
+ else if (rotateRect().contains(pos))
+ return Rotate;
+ else if (markerButtonRect().contains(p2))
+ return MoveMarker;
+ else if (hFlipRect().contains(pos))
+ return HorizontalFlip;
+ else if (shape().contains(pos))
+ return Move;
+ else
+ return None;
+}
+
+
+void UBGraphicsAristo::StartLine(const QPointF &scenePos, qreal width)
+{
+ QPointF itemPos = mapFromScene(scenePos);
+
+ qreal y;
+
+ y = rotationCenter().y();
+
+ if (itemPos.x() < boundingRect().x() + sLeftEdgeMargin)
+ itemPos.setX(boundingRect().x() + sLeftEdgeMargin);
+ if (itemPos.x() > boundingRect().x() + boundingRect().width() - sLeftEdgeMargin)
+ itemPos.setX(boundingRect().x() + boundingRect().width() - sLeftEdgeMargin);
+
+ itemPos.setY(y);
+ itemPos = mapToScene(itemPos);
+
+ scene()->moveTo(itemPos);
+ scene()->drawLineTo(itemPos, width, true);
+}
+
+void UBGraphicsAristo::DrawLine(const QPointF &scenePos, qreal width)
+{
+ QPointF itemPos = mapFromScene(scenePos);
+
+ qreal y;
+
+ y = rotationCenter().y();
+
+ if (itemPos.x() < boundingRect().x() + sLeftEdgeMargin)
+ itemPos.setX(boundingRect().x() + sLeftEdgeMargin);
+ if (itemPos.x() > boundingRect().x() + boundingRect().width() - sLeftEdgeMargin)
+ itemPos.setX(boundingRect().x() + boundingRect().width() - sLeftEdgeMargin);
+
+ itemPos.setY(y);
+ itemPos = mapToScene(itemPos);
+
+ // We have to use "pointed" line for marker tool
+ scene()->drawLineTo(itemPos, width,
+ UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker);
+}
+
+void UBGraphicsAristo::EndLine()
+{
+ /* NOOP */
+}
+
+
+UBGraphicsScene* UBGraphicsAristo::scene() const
+{
+ return static_cast(QGraphicsPathItem::scene());
+}
diff --git a/src/tools/UBGraphicsAristo.h b/src/tools/UBGraphicsAristo.h
new file mode 100644
index 00000000..8d23d7e5
--- /dev/null
+++ b/src/tools/UBGraphicsAristo.h
@@ -0,0 +1,156 @@
+/*
+ * 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 .
+ */
+
+#ifndef UBGRAPHICSARISTO_H_
+#define UBGRAPHICSARISTO_H_
+
+#include "core/UB.h"
+#include "domain/UBItem.h"
+#include "domain/UBGraphicsScene.h"
+#include "tools/UBAbstractDrawRuler.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+class UBGraphicsAristo : public UBAbstractDrawRuler, public QGraphicsPathItem, public UBItem
+{
+Q_OBJECT
+
+public:
+ UBGraphicsAristo();
+ virtual ~UBGraphicsAristo();
+
+ enum {
+ Type = UBGraphicsItemType::AristoItemType
+ };
+
+ enum Tool {
+ None,
+ Move,
+ Resize,
+ Rotate,
+ Close,
+ MoveMarker,
+ HorizontalFlip
+ };
+
+ enum Orientation
+ {
+ Bottom = 0,
+ Top,
+ Undefined
+ };
+
+ void setOrientation(Orientation orientation);
+ void setBoundingRect(QRectF boundingRect);
+
+ virtual UBItem* deepCopy() const;
+ virtual void copyItemParameters(UBItem *copy) const;
+
+ virtual void StartLine(const QPointF& scenePos, qreal width);
+ virtual void DrawLine(const QPointF& position, qreal width);
+ virtual void EndLine();
+
+ virtual int type() const
+ {
+ return Type;
+ }
+ UBGraphicsScene* scene() const;
+
+protected:
+ virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
+
+ virtual void rotateAroundCenter(qreal angle);
+ virtual void resize(qreal factor);
+
+ virtual QPointF rotationCenter() const;
+
+ virtual QRectF closeButtonRect() const;
+ QRectF hFlipRect() const;
+ QRectF markerButtonRect() const;
+ QRectF resizeButtonRect () const;
+ QRectF rotateRect() const;
+
+ QCursor flipCursor() const;
+ QCursor markerCursor() const;
+ QCursor resizeCursor() const;
+
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
+
+private:
+ Tool toolFromPos(QPointF pos);
+
+ QTransform calculateRotationTransform();
+ void rotateAroundCenter(QTransform& transform, QPointF center);
+
+ void calculatePoints();
+ QPainterPath determinePath();
+ void setItemsPos();
+ void makeGeometryChange();
+
+ QBrush fillBrush() const;
+ void paintGraduations(QPainter *painter);
+ void paintMarker(QPainter *painter);
+ void paintProtractorGraduations(QPainter* painter);
+ void paintRulerGraduations(QPainter *painter);
+
+ inline qreal radius () const
+ {
+ return sqrt(((B.x() - A.x())*(B.x() - A.x()))+((B.y() - A.y())*(B.y() - A.y()))) * 9 / 16 - 20;
+ }
+
+ bool mMarking;
+ bool mResizing;
+ bool mRotating;
+
+ Orientation mOrientation;
+
+ qreal mRotatedAngle;
+ qreal mMarkerAngle;
+ qreal mStartAngle;
+
+ qreal mSpan;
+
+ QGraphicsSvgItem* mHFlipSvgItem;
+ QGraphicsSvgItem* mMarkerSvgItem;
+ QGraphicsSvgItem* mResizeSvgItem;
+ QGraphicsSvgItem* mRotateSvgItem;
+
+ QPointF A, B, C;
+
+ static const int sArcAngleMargin = 5;
+ static const Orientation sDefaultOrientation;
+ static const QRectF sDefaultRect;
+};
+
+#endif /* UBGRAPHICSARISTO_H_ */
diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp
index 7a89c534..dfde3b4f 100644
--- a/src/tools/UBGraphicsCache.cpp
+++ b/src/tools/UBGraphicsCache.cpp
@@ -24,11 +24,21 @@
#include "core/memcheck.h"
-UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem()
+QMap UBGraphicsCache::sInstances;
+
+UBGraphicsCache* UBGraphicsCache::instance(UBGraphicsScene *scene)
+{
+ if (!sInstances.contains(scene))
+ sInstances.insert(scene, new UBGraphicsCache(scene));
+ return sInstances[scene];
+}
+
+UBGraphicsCache::UBGraphicsCache(UBGraphicsScene *scene) : QGraphicsRectItem()
, mMaskColor(Qt::black)
, mMaskShape(eMaskShape_Circle)
, mShapeWidth(100)
, mDrawMask(false)
+ , mScene(scene)
{
// Get the board size and pass it to the shape
QRect boardRect = UBApplication::boardController->displayView()->rect();
@@ -39,11 +49,12 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem()
UBGraphicsCache::~UBGraphicsCache()
{
+ sInstances.remove(mScene);
}
UBItem* UBGraphicsCache::deepCopy() const
{
- UBGraphicsCache* copy = new UBGraphicsCache();
+ UBGraphicsCache* copy = new UBGraphicsCache(mScene);
copyItemParameters(copy);
diff --git a/src/tools/UBGraphicsCache.h b/src/tools/UBGraphicsCache.h
index 9ca07d0d..413aa352 100644
--- a/src/tools/UBGraphicsCache.h
+++ b/src/tools/UBGraphicsCache.h
@@ -30,7 +30,7 @@ typedef enum
class UBGraphicsCache : public QGraphicsRectItem, public UBItem
{
public:
- UBGraphicsCache();
+ static UBGraphicsCache* instance(UBGraphicsScene *scene);
~UBGraphicsCache();
enum { Type = UBGraphicsItemType::cacheItemType };
@@ -55,8 +55,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
- void init();
- QRectF updateRect(QPointF currentPoint);
+ static QMap sInstances;
QColor mMaskColor;
eMaskShape mMaskShape;
@@ -65,6 +64,13 @@ private:
QPointF mShapePos;
int mOldShapeWidth;
QPointF mOldShapePos;
+ UBGraphicsScene* mScene;
+
+
+ UBGraphicsCache(UBGraphicsScene *scene);
+
+ void init();
+ QRectF updateRect(QPointF currentPoint);
};
#endif // UBGRAPHICSCACHE_H
diff --git a/src/tools/UBToolsManager.cpp b/src/tools/UBToolsManager.cpp
index 95b40eec..d30e4fa1 100644
--- a/src/tools/UBToolsManager.cpp
+++ b/src/tools/UBToolsManager.cpp
@@ -91,6 +91,12 @@ UBToolsManager::UBToolsManager(QObject *parent)
mDescriptors << cache;
// --------------------------------------------------------------------------------
+ aristo.id = "uniboardTool://uniboard.mnemis.com/aristo";
+ aristo.icon = QPixmap(":/images/toolPalette/aristoTool.png");
+ aristo.label = tr("Aristo");
+ aristo.version = "1.0";
+ mToolsIcon.insert(aristo.id, ":/images/toolPalette/aristoTool.png");
+ mDescriptors << aristo;
}
UBToolsManager::~UBToolsManager()
diff --git a/src/tools/UBToolsManager.h b/src/tools/UBToolsManager.h
index eee12d61..410b224f 100644
--- a/src/tools/UBToolsManager.h
+++ b/src/tools/UBToolsManager.h
@@ -76,6 +76,7 @@ class UBToolsManager : public QObject
UBToolDescriptor triangle;
UBToolDescriptor magnifier;
UBToolDescriptor cache;
+ UBToolDescriptor aristo;
QString iconFromToolId(QString id) { return mToolsIcon.value(id);}
diff --git a/src/tools/tools.pri b/src/tools/tools.pri
index 90e69659..0196f84d 100644
--- a/src/tools/tools.pri
+++ b/src/tools/tools.pri
@@ -1,20 +1,21 @@
-
-HEADERS += src/tools/UBGraphicsRuler.h \
- src/tools/UBGraphicsTriangle.h \
+HEADERS += src/tools/UBGraphicsRuler.h \
+ src/tools/UBGraphicsTriangle.h \
src/tools/UBGraphicsProtractor.h \
src/tools/UBGraphicsCompass.h \
+ src/tools/UBGraphicsAristo.h \
src/tools/UBToolsManager.h \
src/tools/UBGraphicsCurtainItem.h \
src/tools/UBGraphicsCurtainItemDelegate.h \
src/tools/UBAbstractDrawRuler.h \
- src/tools/UBGraphicsCache.h
-
-SOURCES += src/tools/UBGraphicsRuler.cpp \
- src/tools/UBGraphicsTriangle.cpp \
+ src/tools/UBGraphicsCache.h
+
+SOURCES += src/tools/UBGraphicsRuler.cpp \
+ src/tools/UBGraphicsTriangle.cpp \
src/tools/UBGraphicsProtractor.cpp \
src/tools/UBGraphicsCompass.cpp \
+ src/tools/UBGraphicsAristo.cpp \
src/tools/UBToolsManager.cpp \
src/tools/UBGraphicsCurtainItem.cpp \
src/tools/UBGraphicsCurtainItemDelegate.cpp \
src/tools/UBAbstractDrawRuler.cpp \
- src/tools/UBGraphicsCache.cpp
+ src/tools/UBGraphicsCache.cpp
diff --git a/src/web/UBTrapFlashController.cpp b/src/web/UBTrapFlashController.cpp
index 25cb37e9..6458f203 100644
--- a/src/web/UBTrapFlashController.cpp
+++ b/src/web/UBTrapFlashController.cpp
@@ -200,7 +200,7 @@ void UBTrapFlashController::createWidget()
// flash widget
UBWebKitUtils::HtmlObject selectedObject = mAvailableFlashes.at(selectedIndex - 1);
UBApplication::applicationController->showBoard();
- UBApplication::boardController->downloadURL(QUrl(selectedObject.source), QPoint(0, 0), QSize(selectedObject.width, selectedObject.height));
+ UBApplication::boardController->downloadURL(QUrl(selectedObject.source), QString(), QPoint(0, 0), QSize(selectedObject.width, selectedObject.height));
}
QString freezedWidgetPath = UBPlatformUtils::applicationResourcesDirectory() + "/etc/freezedWidgetWrapper.html";
diff --git a/src/web/browser/WBWebTrapWebView.cpp b/src/web/browser/WBWebTrapWebView.cpp
index 971ed75c..2c97626c 100644
--- a/src/web/browser/WBWebTrapWebView.cpp
+++ b/src/web/browser/WBWebTrapWebView.cpp
@@ -281,7 +281,7 @@ void WBWebTrapWebView::trapElementAtPos(const QPoint& pos)
emit objectCaptured(QUrl(page()->currentFrame()->url().toString() + "/" + source), type,
htr.boundingRect().width(), htr.boundingRect().height());
- UBApplication::boardController->downloadURL(QUrl(source), QPointF(0.0, 0.0));
+ UBApplication::boardController->downloadURL(QUrl(source));
UBApplication::applicationController->showBoard();
}
}