Ticket #10193: mythui_rotate_zoom.patch
File mythui_rotate_zoom.patch, 8.3 KB (added by , 12 years ago) |
---|
-
mythtv/libs/libmythui/mythuiimage.cpp
old new 321 321 322 322 m_isGreyscale = false; 323 323 324 m_isRotated = false; 325 m_rotationAngle = 0; 326 m_isZoomed = false; 327 m_zoomPercent = 0; 328 324 329 m_preserveAspect = false; 325 330 326 331 m_animationCycle = kCycleStart; … … 425 430 if (m_isGreyscale && !img->isGrayscale()) 426 431 img->ToGreyscale(); 427 432 433 if (m_isRotated && !img->IsRotated() && m_rotationAngle != 0) 434 img->Rotate(m_rotationAngle, m_ForceSize); 435 436 if (m_isZoomed && !img->IsZoomed() && m_zoomPercent != 0) 437 img->Zoom(m_zoomPercent); 438 428 439 if (m_ForceSize.isNull()) 429 440 SetSize(img->size()); 430 441 … … 481 492 if (m_isGreyscale && !im->isGrayscale()) 482 493 im->ToGreyscale(); 483 494 495 if (m_isRotated && !im->IsRotated() && m_rotationAngle != 0) 496 im->Rotate(m_rotationAngle, m_ForceSize); 497 498 if (m_isZoomed && !im->IsZoomed() && m_zoomPercent != 0) 499 im->Zoom(m_zoomPercent); 500 484 501 m_ImagesLock.lock(); 485 502 m_Images[m_Images.size()] = im; 486 503 m_ImagesLock.unlock(); … … 520 537 } 521 538 522 539 /** 540 * \brief Rotates the first image in the widget 541 */ 542 void MythUIImage::SetRotation(int rotationAngle) 543 { 544 LOG(VB_GENERAL, LOG_INFO, 545 QString("Rotating image %1 by %2") 546 .arg(m_Filename) 547 .arg(rotationAngle)); 548 549 m_isRotated = true; 550 m_rotationAngle = rotationAngle; 551 } 552 553 /** 554 * \brief Zooms the first image in the widget 555 */ 556 void MythUIImage::SetZoom(int zoomPercent) 557 { 558 LOG(VB_GENERAL, LOG_INFO, 559 QString("Zooming image %1 by %2") 560 .arg(m_Filename) 561 .arg(zoomPercent)); 562 563 m_isZoomed = true; 564 m_zoomPercent = zoomPercent; 565 } 566 567 /** 523 568 * \brief Set the size of the widget 524 569 */ 525 570 void MythUIImage::SetSize(int width, int height) … … 576 621 if (m_isGreyscale) 577 622 s_Attrib += "greyscale"; 578 623 624 if (m_isRotated) 625 { 626 s_Attrib += "rotated"; 627 s_Attrib += QString("%1").arg(m_rotationAngle); 628 } 629 630 if (m_isZoomed) 631 { 632 s_Attrib += "zoomed"; 633 s_Attrib += QString("%1").arg(m_zoomPercent); 634 } 635 579 636 imagelabel = QString("%1-%2-%3x%4.png") 580 637 .arg(filename) 581 638 .arg(s_Attrib) … … 814 871 if (m_isReflected) 815 872 image->setIsReflected(true); 816 873 874 if (m_isRotated) 875 image->setIsRotated(true); 876 877 if (m_isZoomed) 878 image->setIsZoomed(true); 879 817 880 QRect rect(GetFullArea()); 818 881 rect.setSize(image->size()); 819 882 SetMinArea(rect); … … 892 955 if (m_isGreyscale) 893 956 image->ToGreyscale(); 894 957 958 if (m_isRotated) 959 image->Rotate(m_rotationAngle, m_ForceSize); 960 961 if (m_isZoomed) 962 image->Zoom(m_zoomPercent); 963 895 964 if (!imageReader.supportsAnimation()) 896 965 GetMythUI()->CacheImage(imagelabel, image); 897 966 } … … 1146 1215 if (x > 0 || y > 0) 1147 1216 area.translate(x, y); 1148 1217 1218 // The image is already centered on the screen. But if the 1219 // image is zoomed its size could be larger than the screen. In 1220 // this case the area needs to be centered within the screen area. 1221 if (m_isZoomed && m_zoomPercent > 0) 1222 { 1223 // Get the dimensions (x- and y-resolution) of the screen. 1224 int screenWidth, screenHeight; 1225 float screenWidthMult, screenHeightMult; 1226 GetMythUI()->GetScreenSettings(screenWidth, screenWidthMult, 1227 screenHeight, screenHeightMult); 1228 1229 if (area.width() > screenWidth) 1230 x = (screenWidth - area.width()) / 2; 1231 1232 if (area.height() > screenHeight) 1233 y = (screenHeight - area.height()) / 2; 1234 1235 area.translate(x, y); 1236 } 1237 1149 1238 QRect srcRect; 1150 1239 m_cropRect.CalculateArea(GetFullArea()); 1151 1240 … … 1329 1418 { 1330 1419 m_isGreyscale = parseBool(element); 1331 1420 } 1421 else if (element.tagName() == "rotate") 1422 { 1423 m_isRotated = true; 1424 QString tmp = element.attribute("angle"); 1425 1426 if (!tmp.isEmpty()) 1427 m_rotationAngle = tmp.toInt(); 1428 } 1429 else if (element.tagName() == "zoom") 1430 { 1431 m_isZoomed = true; 1432 QString tmp = element.attribute("percent"); 1433 1434 if (!tmp.isEmpty()) 1435 m_zoomPercent = tmp.toInt(); 1436 } 1332 1437 else 1333 1438 { 1334 1439 return MythUIType::ParseElement(filename, element, showWarnings); … … 1387 1492 1388 1493 m_isGreyscale = im->m_isGreyscale; 1389 1494 1495 m_isRotated = im->m_isRotated; 1496 m_isZoomed = im->m_isZoomed; 1497 1498 m_rotationAngle = im->m_rotationAngle; 1499 m_zoomPercent = im->m_zoomPercent; 1500 1390 1501 m_animationCycle = im->m_animationCycle; 1391 1502 m_animatedImage = im->m_animatedImage; 1392 1503 -
mythtv/libs/libmythui/mythuiimage.h
old new 59 59 60 60 virtual void LoadNow(void); 61 61 62 void SetZoom(int zoomPercent); 63 void SetRotation(int rotationAngle); 64 62 65 protected: 63 66 virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, 64 67 int alphaMod, QRect clipRect); … … 119 122 int m_reflectLength; 120 123 int m_reflectSpacing; 121 124 125 bool m_isRotated; 126 int m_rotationAngle; 127 bool m_isZoomed; 128 int m_zoomPercent; 129 122 130 MythImage *m_maskImage; 123 131 bool m_isMasked; 124 132 -
mythtv/libs/libmythui/mythimage.cpp
old new 41 41 m_gradAlpha = 255; 42 42 m_gradDirection = FillTopToBottom; 43 43 44 m_isZoomed = false; 45 m_isRotated = false; 44 46 m_isReflected = false; 45 47 m_isYUV = false; 46 48 … … 124 126 Assign(pix.toImage()); 125 127 } 126 128 129 void MythImage::Rotate(int rotationAngle, QSize size) 130 { 131 if (m_isRotated) 132 return; 133 134 QMatrix matrix; 135 matrix.rotate(rotationAngle); 136 Assign(transformed(matrix, Qt::SmoothTransformation)); 137 138 // The rotated image is higher than the parent area 139 // the image needs to be resized to be with the areas dimensions 140 141 // TODO: If the image is rotated not by multiple of 90 degrees 142 // calculate the new dimensions by using the pythagoras 143 if (!size.isNull()) 144 { 145 Resize(size, true); 146 } 147 148 m_isRotated = true; 149 } 150 151 void MythImage::Zoom(int zoomPercent) 152 { 153 if (m_isZoomed) 154 return; 155 156 float factor = (100.0 + zoomPercent) / 100.0; 157 int newWidth = (int)(width() * factor); 158 int newHeight = (int)(height() * factor); 159 160 Assign(scaled(QSize(newWidth, newHeight), 161 Qt::KeepAspectRatio, Qt::SmoothTransformation)); 162 163 m_isZoomed = true; 164 } 165 127 166 void MythImage::Resize(const QSize &newSize, bool preserveAspect) 128 167 { 129 168 if ((size() == newSize) && !isNull()) -
mythtv/libs/libmythui/mythimage.h
old new 44 44 45 45 bool IsGradient() const { return m_isGradient; } 46 46 bool IsReflected() const { return m_isReflected; } 47 bool IsRotated() const { return m_isRotated; } 48 bool IsZoomed() const { return m_isZoomed; } 47 49 48 50 void SetToYUV(void) { m_isYUV = true; } 49 51 void ConvertToYUV(void); … … 54 56 bool Load(MythImageReader &reader); 55 57 bool Load(const QString &filename, bool scale = true); 56 58 59 void Rotate(int rotationAngle, QSize size); 60 void Zoom(int zoomPercent); 57 61 void Resize(const QSize &newSize, bool preserveAspect = false); 58 62 void Reflect(ReflectAxis axis, int shear, int scale, int length, 59 63 int spacing = 0); … … 78 82 QString GetFileName(void) const { return m_FileName; } 79 83 80 84 void setIsReflected(bool reflected) { m_isReflected = reflected; } 85 void setIsRotated(bool rotated) { m_isRotated = rotated; } 86 void setIsZoomed(bool zoomed) { m_isZoomed = zoomed; } 81 87 82 88 void SetIsInCache(bool bCached); 83 89 … … 100 106 int m_gradAlpha; 101 107 FillDirection m_gradDirection; 102 108 109 bool m_isRotated; 110 bool m_isZoomed; 103 111 bool m_isReflected; 104 112 bool m_isYUV; 105 113