Allow to specify whether an upscaling of images should be done

The option is currently hidden as up to now only Nuno requested it,
but it seems to be urgent: "my icon making productivity has drop subtantialy"
((c) 2012 Nuno)

As I don't want to get blamed for an outdated Oxygen-icon-set I have
no other choice ;-)

CCMAIL: nuno.pinheiro@kdab.com
This commit is contained in:
Peter Penz 2012-04-06 23:06:05 +02:00
parent 107f129eb6
commit 99e4eb0f3a
8 changed files with 115 additions and 23 deletions

View file

@ -82,13 +82,25 @@ KFileItemListView::~KFileItemListView()
void KFileItemListView::setPreviewsShown(bool show)
{
if (m_modelRolesUpdater) {
m_modelRolesUpdater->setPreviewShown(show);
m_modelRolesUpdater->setPreviewsShown(show);
}
}
bool KFileItemListView::previewsShown() const
{
return m_modelRolesUpdater->isPreviewShown();
return m_modelRolesUpdater ? m_modelRolesUpdater->previewsShown() : false;
}
void KFileItemListView::setEnlargeSmallPreviews(bool enlarge)
{
if (m_modelRolesUpdater) {
m_modelRolesUpdater->setEnlargeSmallPreviews(enlarge);
}
}
bool KFileItemListView::enlargeSmallPreviews() const
{
return m_modelRolesUpdater ? m_modelRolesUpdater->enlargeSmallPreviews() : false;
}
void KFileItemListView::setItemLayout(Layout layout)

View file

@ -54,6 +54,14 @@ public:
void setPreviewsShown(bool show);
bool previewsShown() const;
/**
* If enabled a small preview gets upscaled to the icon size in case where
* the icon size is larger than the preview. Per default enlarging is
* enabled.
*/
void setEnlargeSmallPreviews(bool enlarge);
bool enlargeSmallPreviews() const;
void setItemLayout(Layout layout);
Layout itemLayout() const;

View file

@ -67,6 +67,7 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
m_iconSizeChangedDuringPausing(false),
m_rolesChangedDuringPausing(false),
m_previewShown(false),
m_enlargeSmallPreviews(true),
m_clearPreviews(false),
m_model(model),
m_iconSize(),
@ -155,7 +156,7 @@ void KFileItemModelRolesUpdater::setVisibleIndexRange(int index, int count)
}
}
void KFileItemModelRolesUpdater::setPreviewShown(bool show)
void KFileItemModelRolesUpdater::setPreviewsShown(bool show)
{
if (show == m_previewShown) {
return;
@ -166,30 +167,35 @@ void KFileItemModelRolesUpdater::setPreviewShown(bool show)
m_clearPreviews = true;
}
if (m_paused) {
m_previewChangedDuringPausing = true;
} else {
sortAndResolveAllRoles();
updateAllPreviews();
}
bool KFileItemModelRolesUpdater::previewsShown() const
{
return m_previewShown;
}
void KFileItemModelRolesUpdater::setEnlargeSmallPreviews(bool enlarge)
{
if (enlarge != m_enlargeSmallPreviews) {
m_enlargeSmallPreviews = enlarge;
if (m_previewShown) {
updateAllPreviews();
}
}
}
bool KFileItemModelRolesUpdater::isPreviewShown() const
bool KFileItemModelRolesUpdater::enlargeSmallPreviews() const
{
return m_previewShown;
return m_enlargeSmallPreviews;
}
void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList& list)
{
if (m_enabledPlugins == list) {
return;
}
m_enabledPlugins = list;
if (m_previewShown) {
if (m_paused) {
m_previewChangedDuringPausing = true;
} else {
sortAndResolveAllRoles();
m_enabledPlugins = list;
if (m_previewShown) {
updateAllPreviews();
}
}
}
@ -390,7 +396,34 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
const int slashIndex = mimeType.indexOf(QLatin1Char('/'));
const QString mimeTypeGroup = mimeType.left(slashIndex);
if (mimeTypeGroup == QLatin1String("image")) {
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
if (m_enlargeSmallPreviews) {
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
} else {
// Assure that small previews don't get enlarged. Instead they
// should be shown centered within the frame.
const QSize contentSize = KPixmapModifier::sizeInsideFrame(m_iconSize);
const bool enlargingRequired = scaledPixmap.width() < contentSize.width() &&
scaledPixmap.height() < contentSize.height();
if (enlargingRequired) {
QSize frameSize = scaledPixmap.size();
frameSize.scale(m_iconSize, Qt::KeepAspectRatio);
QPixmap largeFrame(frameSize);
largeFrame.fill(Qt::transparent);
KPixmapModifier::applyFrame(largeFrame, frameSize);
QPainter painter(&largeFrame);
painter.drawPixmap((largeFrame.width() - scaledPixmap.width()) / 2,
(largeFrame.height() - scaledPixmap.height()) / 2,
scaledPixmap);
scaledPixmap = largeFrame;
} else {
// The image must be shrinked as it is too large to fit into
// the available icon size
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
}
}
} else {
KPixmapModifier::scale(scaledPixmap, m_iconSize);
}
@ -968,4 +1001,13 @@ int KFileItemModelRolesUpdater::subItemsCount(const QString& path) const
#endif
}
void KFileItemModelRolesUpdater::updateAllPreviews()
{
if (m_paused) {
m_previewChangedDuringPausing = true;
} else {
sortAndResolveAllRoles();
}
}
#include "kfileitemmodelrolesupdater.moc"

View file

@ -81,8 +81,16 @@ public:
* of the file. If \a show is false the MIME type icon will be used for the "iconPixmap"
* role.
*/
void setPreviewShown(bool show);
bool isPreviewShown() const;
void setPreviewsShown(bool show);
bool previewsShown() const;
/**
* If enabled a small preview gets upscaled to the icon size in case where
* the icon size is larger than the preview. Per default enlarging is
* enabled.
*/
void setEnlargeSmallPreviews(bool enlarge);
bool enlargeSmallPreviews() const;
/**
* If \a paused is set to true the asynchronous resolving of roles will be paused.
@ -187,6 +195,12 @@ private:
*/
int subItemsCount(const QString& path) const;
/**
* Must be invoked if a property has been changed that affects
* the look of the preview. Takes care to update all previews.
*/
void updateAllPreviews();
private:
// Property for setPaused()/isPaused().
bool m_paused;
@ -197,9 +211,12 @@ private:
bool m_iconSizeChangedDuringPausing;
bool m_rolesChangedDuringPausing;
// Property for setPreviewShown()/previewShown().
// Property for setPreviewsShown()/previewsShown().
bool m_previewShown;
// Property for setEnlargeSmallPreviews()/enlargeSmallPreviews()
bool m_enlargeSmallPreviews;
// True if the role "iconPixmap" should be cleared when resolving the next
// role with resolveRole(). Is necessary if the preview gets disabled
// during the roles-updater has been paused by setPaused().

View file

@ -392,3 +392,9 @@ void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize)
icon = framedIcon;
}
QSize KPixmapModifier::sizeInsideFrame(const QSize& frameSize)
{
return QSize(frameSize.width() - TileSet::LeftMargin - TileSet::RightMargin,
frameSize.height() - TileSet::TopMargin - TileSet::BottomMargin);
}

View file

@ -30,6 +30,7 @@ class LIBDOLPHINPRIVATE_EXPORT KPixmapModifier
public:
static void scale(QPixmap& pixmap, const QSize& scaledSize);
static void applyFrame(QPixmap& icon, const QSize& scaledSize);
static QSize sizeInsideFrame(const QSize& frameSize);
};
#endif

View file

@ -83,5 +83,9 @@
<label>Lock the layout of the panels</label>
<default>true</default>
</entry>
<entry name="EnlargeSmallPreviews" type="Bool">
<label>Enlarge Small Previews</label>
<default>true</default>
</entry>
</group>
</kcfg>

View file

@ -48,9 +48,11 @@ DolphinItemListContainer::DolphinItemListContainer(KDirLister* dirLister,
controller()->setModel(new KFileItemModel(dirLister, this));
m_fileItemListView = new KFileItemListView();
controller()->setView(m_fileItemListView);
m_fileItemListView->setWidgetCreator(new KItemListWidgetCreator<DolphinFileItemListWidget>());
m_fileItemListView->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
controller()->setView(m_fileItemListView);
m_fileItemListView->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
updateAutoActivationDelay();
updateFont();