Skip to content

Commit a78c258

Browse files
committed
Adds "Reduce to fit" scaling option to mythgallery scaling. The scaling options
now include: - scale to fit - scale to fill - reduce to fit. Reduce to fit is the same as scale to fit with the exception that it will never scale up a small picture. Scaling options can be cycled while viewing a picture by hitting the "FULLSCREEN" command (by default W key) Applied a reworked version of the patch from #5897. Thanks to Boleslaw Ciesielski <bolek-mythtv@curl.com> for the patch. closes #5897 git-svn-id: http://svn.mythtv.org/svn/trunk@25659 7dbf422c-18fa-0310-86e9-fd20926502f2
1 parent 75dc7cf commit a78c258

File tree

8 files changed

+45
-21
lines changed

8 files changed

+45
-21
lines changed

mythplugins/mythgallery/mythgallery/galleryutil.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ bool GalleryUtil::Rename(const QString &currDir, const QString &oldName,
450450
return false;
451451
}
452452

453-
QSize GalleryUtil::ScaleToDest(const QSize &src, const QSize &dest, bool scaleMax)
453+
QSize GalleryUtil::ScaleToDest(const QSize &src, const QSize &dest, ScaleMax scaleMax)
454454
{
455455
QSize sz = src;
456456

@@ -462,10 +462,12 @@ QSize GalleryUtil::ScaleToDest(const QSize &src, const QSize &dest, bool scaleMa
462462
if ((sz.width() > 0) && (sz.height() > 0))
463463
imageAspect = (double)sz.width() / (double)sz.height();
464464

465-
int scaleWidth;
466-
int scaleHeight;
467-
if (scaleMax)
465+
int scaleWidth = sz.width();
466+
int scaleHeight = sz.height();
467+
468+
switch (scaleMax)
468469
{
470+
case kScaleToFill:
469471
// scale-max to dest width for most images
470472
scaleWidth = dest.width();
471473
scaleHeight = (int)((float)dest.width() * pixelAspect / imageAspect);
@@ -475,9 +477,15 @@ QSize GalleryUtil::ScaleToDest(const QSize &src, const QSize &dest, bool scaleMa
475477
scaleWidth = (int)((float)dest.height() * imageAspect / pixelAspect);
476478
scaleHeight = dest.height();
477479
}
478-
}
479-
else
480-
{
480+
break;
481+
482+
case kReduceToFit:
483+
// Reduce to fit (but never enlarge)
484+
if (scaleWidth <= dest.width() && scaleHeight <= dest.height())
485+
break;
486+
// Fall through
487+
488+
case kScaleToFit:
481489
// scale-min to dest height for most images
482490
scaleWidth = (int)((float)dest.height() * imageAspect / pixelAspect);
483491
scaleHeight = dest.height();
@@ -487,9 +495,14 @@ QSize GalleryUtil::ScaleToDest(const QSize &src, const QSize &dest, bool scaleMa
487495
scaleWidth = dest.width();
488496
scaleHeight = (int)((float)dest.width() * pixelAspect / imageAspect);
489497
}
498+
break;
499+
500+
default:
501+
break;
490502
}
491503

492-
sz.scale(scaleWidth, scaleHeight, Qt::IgnoreAspectRatio);
504+
if (scaleWidth != sz.width() || scaleHeight != sz.height())
505+
sz.scale(scaleWidth, scaleHeight, Qt::KeepAspectRatio);
493506
return sz;
494507
}
495508

mythplugins/mythgallery/mythgallery/galleryutil.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424

2525
#include "iconview.h"
2626

27+
typedef enum {
28+
kScaleToFit,
29+
kScaleToFill,
30+
kReduceToFit,
31+
kScaleMaxCount // must be last
32+
} ScaleMax;
33+
2734
class GalleryUtil
2835
{
2936
public:
@@ -41,7 +48,7 @@ class GalleryUtil
4148
int sortorder, bool recurse,
4249
ThumbHash *itemHash, ThumbGenerator *thumbGen);
4350

44-
static QSize ScaleToDest(const QSize &sz, const QSize &dest, bool scaleMax);
51+
static QSize ScaleToDest(const QSize &sz, const QSize &dest, ScaleMax scaleMax);
4552

4653
static bool CopyMove(const QFileInfo &src, QFileInfo &dst, bool move)
4754
{ if (move) return Move(src, dst); else return Copy(src, dst); }

mythplugins/mythgallery/mythgallery/glsingleview.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ GLSingleView::GLSingleView(ThumbList itemList, int *pos, int slideShow,
7676
// General
7777
m_source_x(0.0f),
7878
m_source_y(0.0f),
79-
m_scaleMax(false),
79+
m_scaleMax(kScaleToFit),
8080

8181
// Texture variables (for display and effects)
8282
m_texMaxDim(512),
@@ -97,7 +97,7 @@ GLSingleView::GLSingleView(ThumbList itemList, int *pos, int slideShow,
9797
m_effect_cube_yrot(0.0f),
9898
m_effect_cube_zrot(0.0f)
9999
{
100-
m_scaleMax = (gCoreContext->GetNumSetting("GalleryScaleMax", 0) > 0);
100+
m_scaleMax = (ScaleMax) gCoreContext->GetNumSetting("GalleryScaleMax", 0);
101101

102102
m_slideshow_timer = new QTimer(this);
103103
RegisterEffects();
@@ -140,7 +140,7 @@ GLSingleView::GLSingleView(ThumbList itemList, int *pos, int slideShow,
140140
GLSingleView::~GLSingleView()
141141
{
142142
// save the current m_scaleMax setting so we can restore it later
143-
gCoreContext->SaveSetting("GalleryScaleMax", (m_scaleMax ? "1" : "0"));
143+
gCoreContext->SaveSetting("GalleryScaleMax", m_scaleMax);
144144
CleanUp();
145145
}
146146

@@ -458,7 +458,7 @@ void GLSingleView::keyPressEvent(QKeyEvent *e)
458458
}
459459
else if (action == "FULLSCREEN")
460460
{
461-
m_scaleMax = !m_scaleMax;
461+
m_scaleMax = (ScaleMax) ((m_scaleMax + 1) % kScaleMaxCount);
462462
m_source_x = 0;
463463
m_source_y = 0;
464464
SetZoom(1.0f);

mythplugins/mythgallery/mythgallery/glsingleview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class GLSingleView : public QGLWidget, public ImageView
107107
// General
108108
float m_source_x;
109109
float m_source_y;
110-
bool m_scaleMax;
110+
ScaleMax m_scaleMax;
111111

112112
// Texture variables (for display and effects)
113113
int m_texMaxDim;

mythplugins/mythgallery/mythgallery/gltexture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void GLTexture::MakeQuad(float alpha, float scale)
8484
glEnd();
8585
}
8686

87-
void GLTexture::ScaleTo(const QSize &dest, bool scaleMax)
87+
void GLTexture::ScaleTo(const QSize &dest, ScaleMax scaleMax)
8888
{
8989
QSize sz = GalleryUtil::ScaleToDest(GetSize(), dest, scaleMax);
9090
if ((sz.width() > 0) && (sz.height() > 0) &&

mythplugins/mythgallery/mythgallery/gltexture.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <QtOpenGL>
2828
#include <QSize>
2929

30+
// MythGallery headers
31+
#include "galleryutil.h"
32+
3033
class ThumbItem;
3134

3235
class GLTexture
@@ -50,7 +53,7 @@ class GLTexture
5053
{ width = sz.width(); height = sz.height(); }
5154
void SetScale(float x, float y)
5255
{ cx = x; cy = y; }
53-
void ScaleTo(const QSize &dest, bool scaleMax);
56+
void ScaleTo(const QSize &dest, ScaleMax scaleMax);
5457
void SetAngle(int newangle) { angle = newangle; }
5558

5659
// Gets

mythplugins/mythgallery/mythgallery/singleview.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ SingleView::SingleView(
5959
m_pixmap(NULL),
6060
m_angle(0),
6161
m_source_loc(0,0),
62-
m_scaleMax(false),
62+
m_scaleMax(kScaleToFit),
6363

6464
// Info variables
6565
m_info_pixmap(NULL),
@@ -91,7 +91,7 @@ SingleView::SingleView(
9191
m_effect_milti_circle_out_points(4),
9292
m_effect_circle_out_points(4)
9393
{
94-
m_scaleMax = (gCoreContext->GetNumSetting("GalleryScaleMax", 0) > 0);
94+
m_scaleMax = (ScaleMax) gCoreContext->GetNumSetting("GalleryScaleMax", 0);
9595

9696
m_slideshow_timer = new QTimer(this);
9797
RegisterEffects();
@@ -173,7 +173,7 @@ SingleView::~SingleView()
173173
}
174174

175175
// save the current m_scaleMax setting so we can restore it later
176-
gCoreContext->SaveSetting("GalleryScaleMax", (m_scaleMax ? "1" : "0"));
176+
gCoreContext->SaveSetting("GalleryScaleMax", m_scaleMax);
177177
}
178178

179179
void SingleView::paintEvent(QPaintEvent *)
@@ -514,7 +514,7 @@ void SingleView::keyPressEvent(QKeyEvent *e)
514514
}
515515
else if (action == "FULLSCREEN")
516516
{
517-
m_scaleMax = !m_scaleMax;
517+
m_scaleMax = (ScaleMax) ((m_scaleMax + 1) % kScaleMaxCount);
518518
m_source_loc = QPoint(0, 0);
519519
SetZoom(1.0f);
520520
}

mythplugins/mythgallery/mythgallery/singleview.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using namespace std;
3636
// MythTV plugin headers
3737
#include <mythdialogs.h>
3838

39+
#include "galleryutil.h"
3940
#include "imageview.h"
4041
#include "iconview.h"
4142
#include "sequence.h"
@@ -109,7 +110,7 @@ class SingleView : public MythDialog, public ImageView
109110
QImage m_image;
110111
int m_angle;
111112
QPoint m_source_loc;
112-
bool m_scaleMax;
113+
ScaleMax m_scaleMax;
113114

114115
// Info variables
115116
QPixmap *m_info_pixmap;

0 commit comments

Comments
 (0)