Crop box initial size issue fix
authorchitta ranjan <chitta.rs@samsung.com>
Sat, 6 Apr 2013 11:00:33 +0000 (20:00 +0900)
committerchitta ranjan <chitta.rs@samsung.com>
Sat, 6 Apr 2013 11:00:33 +0000 (20:00 +0900)
Change-Id: I5c859c37cddc0660506c57b78942ca9a9226c5ae
Signed-off-by: chitta ranjan <chitta.rs@samsung.com>
src/IvImageCropForm.cpp

index 093be06..a924685 100644 (file)
@@ -231,6 +231,30 @@ ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId&
                        }
                }
        }
+//     if (pArgs != null)
+//     {
+//             __sourceFilePath = *(static_cast<String*>(pArgs->GetAt(0)));
+//             __cropMode = *(static_cast<String*>(pArgs->GetAt(1)));
+//             delete pArgs;
+//     }
+//     else
+//     {
+//             __sourceFilePath = __pPresentationModel->GetFilePathAt(0);
+//     }
+/*     if (__sourceFilePath.IsEmpty() == false && __cropMode.IsEmpty() == false)
+       {
+               __cropMode.ToLowerCase();
+               result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
+               if (r == E_SUCCESS)
+               {
+                       __imageWidth = __imageBuffer.GetWidth();
+                       __imageHeight = __imageBuffer.GetHeight();
+                       __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
+               }
+               Image img;
+               __imageFormat = img.GetImageFormat(__sourceFilePath);
+       }*/
+       SetValue();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -306,10 +330,12 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                        }
                        ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
                        pList->Add(new (std::nothrow) String(destFilePath));
+                       AppLog("Manish %ls", destFilePath.GetPointer());
                        pSceneManager->GoBackward(BackwardSceneTransition(), pList);
                }
                else if(__cropMode == "fit-to-screen")
                {
+                       AppLog("Manish OnActionPerformed");
                        ImageBuffer* pCropBuffer = null;
                        result r = E_SUCCESS;
                        pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
@@ -367,36 +393,13 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                        }
                        else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
                        {
-                               int count = 1;
-                               int index = 0;
-                               String destFilePath;
-                               String stringToInsert = L"_";
-                               String delimiter = L".";
-                               if (__sourceFilePath.IsEmpty() == false)
-                               {
-                                       __sourceFilePath.Reverse();
-                                       __sourceFilePath.IndexOf(delimiter, 0, index);
-                                       __sourceFilePath.Reverse();
-                                       __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
-                                       destFilePath.Append(__sourceFilePath);
-                                       destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
-                                       while (File::IsFileExist(destFilePath) == true)
-                                       {
-                                               count++;
-                                               destFilePath.Clear();
-                                               destFilePath.Append(__sourceFilePath);
-                                               destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
-                                       }
-                               }
-                               r = pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
-                               ContentManager::ScanFile(destFilePath);
                                Contact* pContact = null;
                                AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
                                Addressbook* pAddressbook = null;
 
                                pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
                                pContact = pAddressbook->GetContactN(__contentId);
-                               pContact->SetThumbnail(destFilePath);
+                               pContact->SetThumbnail(__sourceFilePath);
                                pAddressbook->UpdateContact(*pContact);
 
                                delete pContact;
@@ -563,6 +566,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
        }
        else if (__cropMode != "auto")
        {
+               //AppLog("Manish Fit to screen");
                if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
                        || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
                {
@@ -575,6 +579,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
                                        && (__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)))
                                {
+                                       AppLog("Manish 0");
                                        __cropBox.x += deltaX;
                                        __cropBox.width = __cropBox.width - (2 * deltaX);
                                        __cropBox.height = height;
@@ -584,13 +589,16 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.width < __imageBox.width
                                                && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
                                {
+                                       AppLog("Manish 1");
                                        if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                && __cropBox.x + deltaX >= __imageBox.x)
                                        {
+                                               //AppLog("Manish 2");
                                                __cropBox.x += deltaX;
                                        }
                                        else
                                        {
+                                               AppLog("Manish 3");
                                                __cropBox.x = __cropBox.x + (2 * deltaX);
                                        }
                                        __cropBox.width = __cropBox.width - (2 * deltaX);
@@ -602,10 +610,12 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                {
                                        if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
                                        {
+                                               AppLog("Manish 4");
                                                __cropBox.x += deltaX;
                                        }
                                        else
                                        {
+                                               AppLog("Manish 5");
                                                __cropBox.x = __cropBox.x + (2 * deltaX);
                                        }
                                        __cropBox.width = __cropBox.width - (2 * deltaX);
@@ -628,6 +638,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
                                        {
+                                               AppLog("Manish 0");
                                                __cropBox.x += deltaX;
                                                __cropBox.width = __cropBox.width - (2 * deltaX);;
                                                __cropBox.height = height;
@@ -637,13 +648,16 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                        && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
                                                        && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
                                        {
+                                                       AppLog("Manish 1");
                                                if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                        && __cropBox.x + deltaX >= __imageBox.x)
                                                {
+                                                       AppLog("Manish 2");
                                                        __cropBox.x += deltaX;
                                                }
                                                else
                                                {
+                                                       AppLog("Manish 3");
                                                        __cropBox.width = __cropBox.width - (2 * deltaX);
                                                }
                                                __cropBox.width = __cropBox.width - (2 * deltaX);
@@ -653,8 +667,10 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
                                                        && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
                                        {
+                                               AppLog("Manish 25");
                                                if (__cropBox.x + deltaX >= __imageBox.x)
                                                {
+                                                       AppLog("Manish 4");
                                                        __cropBox.x += deltaX;
                                                }
                                                else
@@ -668,6 +684,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                        && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                        && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
                                        {
+                                               AppLog("Manish 999");
                                                __cropBox.x += deltaX;
                                                __cropBox.width = __cropBox.width - (2 * deltaX);
                                                __cropBox.height = height;
@@ -693,6 +710,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
                                        && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
                                {
+                                       AppLog("Manish 0");
                                        __cropBox.y += deltaY;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);
                                        __cropBox.width = width;
@@ -700,6 +718,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                }
                                else if (__cropBox.x - (temp / 2) < __imageBox.x)
                                {
+                                       AppLog("manish 55");
                                        if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
                                        {
                                                __cropBox.width = width;
@@ -710,12 +729,14 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        }
                                        if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
                                        {
+                                               AppLog("Manish 56");
                                                __cropBox.height = __cropBox.height - (2 * deltaY);
                                        }
                                }
                                else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
                                                && __cropBox.y + (2 * deltaY) >= __imageBox.y)
                                {
+                                       AppLog("Manish 1");
                                        if (__cropBox.x - temp >= __imageBox.x
                                                && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
                                        {
@@ -739,6 +760,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
                                                && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
                                {
+                                       AppLog("manish 58");
                                        __cropBox.x = __cropBox.x - temp;
                                        __cropBox.width = width;
                                        __cropBox.y += deltaY;
@@ -748,6 +770,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                }
                else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
                {
+                       AppLog("Manish INSIDE BOTTOM RECTANGLE");
                        deltaY = deltaY * (-1);
                        int temp = __cropBox.width;
                        int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
@@ -757,6 +780,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
                                        && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
                                {
+                                       AppLog("Manish 0");
                                        __cropBox.y += deltaY;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);;
                                        __cropBox.width = width;
@@ -765,6 +789,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
                                                && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
                                {
+                                       AppLog("Manish 1");
                                        __cropBox.x = __cropBox.x - (temp / 2);
                                        __cropBox.width = width;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);
@@ -773,6 +798,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
                                                && __cropBox.x - temp >= __imageBox.x)
                                {
+                                       AppLog("Manish 2");
                                        __cropBox.x = __cropBox.x - temp;
                                        __cropBox.y += deltaY;
                                        __cropBox.width = width;
@@ -782,6 +808,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
                                                && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
                                {
+                                       AppLog("Manish 3");
                                        __cropBox.x -= temp;
                                        __cropBox.width = width;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);
@@ -789,6 +816,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
                                                && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
                                {
+                                       AppLog("manish 4");
                                        if (__cropBox.y + deltaY >= __imageBox.y)
                                        {
                                                __cropBox.y += deltaY;
@@ -912,8 +940,11 @@ ImageCropForm::SetValue(void)
                __formHeight = Form::GetBounds().width;
                __formWidth = Form::GetBounds().height;
        }
+       AppLog("Manish h value %d", __formHeight);
+       AppLog("Manish w value %d", __formWidth);
 
        float clientAreaRatio = (GetClientAreaBoundsF().height - FOOTER_PANEL_HEIGHT) / GetClientAreaBoundsF().width;
+       AppLog("Manish %f", clientAreaRatio);
        if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT))
        {
                float imageRatio = __imageHeight / (float) __imageWidth;
@@ -945,6 +976,11 @@ ImageCropForm::SetValue(void)
                {
                        __cropBox.width = (2 * __imageBox.width) / 3;
                        __cropBox.height = (__formHeight * __cropBox.width / __formWidth);
+                       if (__cropBox.height > __imageBox.height)
+                       {
+                               __cropBox.height = (2 * __imageBox.height) / 3;
+                               __cropBox.width = (__cropBox.height * __formWidth) / __formHeight;
+                       }
                        __cropBox.y =  __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
                        __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
                }
@@ -952,6 +988,11 @@ ImageCropForm::SetValue(void)
                {
                        __cropBox.height = (2 *__imageBox.height) / 3;
                        __cropBox.width = (__formWidth * __cropBox.height / __formHeight);
+                       if (__cropBox.width > __imageBox.width)
+                       {
+                               __cropBox.width = (2 * __imageBox.width) / 3;
+                               __cropBox.height = (__formHeight * __cropBox.width) / __formWidth;
+                       }
                        __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
                        __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
                }
@@ -967,6 +1008,8 @@ ImageCropForm::SetValue(void)
                temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
                __cropBox.width = (temp + 0.5);
        }
+       AppLog("Manish %d %d", __imageBox.width, __imageBox.height);
+       AppLog("Manish %d %d", __cropBox.width, __cropBox.height);
        __pCanvas = GetCanvasN();
        __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
 }
@@ -974,6 +1017,9 @@ ImageCropForm::SetValue(void)
 void ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
 {
        AppLogDebug(" ENTER");
-       UiApp::GetInstance()->Terminate();
+       if (File::IsFileExist(__sourceFilePath) == false)
+       {
+               UiApp::GetInstance()->Terminate();
+       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }