Commit 6b0e9a0a authored by Peter Penz's avatar Peter Penz
Browse files

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
parent d8732a59
......@@ -85,13 +85,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)
......
......@@ -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;
......
......@@ -62,6 +62,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(),
......@@ -145,7 +146,7 @@ void KFileItemModelRolesUpdater::setVisibleIndexRange(int index, int count)
}
}
void KFileItemModelRolesUpdater::setPreviewShown(bool show)
void KFileItemModelRolesUpdater::setPreviewsShown(bool show)
{
if (show == m_previewShown) {
return;
......@@ -156,30 +157,35 @@ void KFileItemModelRolesUpdater::setPreviewShown(bool show)
m_clearPreviews = true;
}
if (m_paused) {
m_previewChangedDuringPausing = true;
} else {
sortAndResolveAllRoles();
}
updateAllPreviews();
}
bool KFileItemModelRolesUpdater::isPreviewShown() const
bool KFileItemModelRolesUpdater::previewsShown() const
{
return m_previewShown;
}
void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList& list)
void KFileItemModelRolesUpdater::setEnlargeSmallPreviews(bool enlarge)
{
if (m_enabledPlugins == list) {
return;
if (enlarge != m_enlargeSmallPreviews) {
m_enlargeSmallPreviews = enlarge;
if (m_previewShown) {
updateAllPreviews();
}
}
}
m_enabledPlugins = list;
if (m_previewShown) {
if (m_paused) {
m_previewChangedDuringPausing = true;
} else {
sortAndResolveAllRoles();
bool KFileItemModelRolesUpdater::enlargeSmallPreviews() const
{
return m_enlargeSmallPreviews;
}
void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList& list)
{
if (m_enabledPlugins == list) {
m_enabledPlugins = list;
if (m_previewShown) {
updateAllPreviews();
}
}
}
......@@ -319,7 +325,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);
}
......@@ -843,4 +876,13 @@ int KFileItemModelRolesUpdater::subItemsCount(const QString& path) const
#endif
}
void KFileItemModelRolesUpdater::updateAllPreviews()
{
if (m_paused) {
m_previewChangedDuringPausing = true;
} else {
sortAndResolveAllRoles();
}
}
#include "kfileitemmodelrolesupdater.moc"
......@@ -64,8 +64,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.
......@@ -168,6 +176,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;
......@@ -178,9 +192,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().
......
......@@ -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);
}
......@@ -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
......
......@@ -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>
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment