Commit 629a4778 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig

Fixes: Improved file icons

Details:
This patch makes use of system icons as a base
and draws overlay on top. This should blend a bit better
into the native icon theme.
parent ccfbdf5b
......@@ -32,6 +32,9 @@
***************************************************************************/
#include "fileiconprovider.h"
#include <QtGui/QApplication>
#include <QtGui/QStyle>
#include <QtGui/QPainter>
using namespace Core;
......@@ -48,7 +51,7 @@ using namespace Core;
FileIconProvider *FileIconProvider::m_instance = 0;
FileIconProvider::FileIconProvider()
: m_unknownFileIcon(QLatin1String(":/core/images/unknownfile.png"))
: m_unknownFileIcon(qApp->style()->standardIcon(QStyle::SP_FileIcon))
{
}
......@@ -76,7 +79,7 @@ QIcon FileIconProvider::icon(const QFileInfo &fileInfo)
// same suffix (Mac OS X), but should speed up the retrieval a lot ...
icon = m_systemIconProvider.icon(fileInfo);
if (!suffix.isEmpty())
registerIconForSuffix(icon, suffix);
registerIconOverlayForSuffix(icon, suffix);
#else
if (fileInfo.isDir()) {
icon = m_systemIconProvider.icon(fileInfo);
......@@ -89,11 +92,22 @@ QIcon FileIconProvider::icon(const QFileInfo &fileInfo)
return icon;
}
// Creates a pixmap with baseicon at size and overlayous overlayIcon over it.
QPixmap FileIconProvider::overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const
{
QPixmap iconPixmap = qApp->style()->standardIcon(baseIcon).pixmap(size);
QPainter painter(&iconPixmap);
painter.drawPixmap(0, 0, overlayIcon.pixmap(size));
painter.end();
return iconPixmap;
}
/*!
Registers an icon for a given suffix, overriding any existing icon.
Registers an icon for a given suffix, overlaying the system file icon
*/
void FileIconProvider::registerIconForSuffix(const QIcon &icon, const QString &suffix)
void FileIconProvider::registerIconOverlayForSuffix(const QIcon &icon, const QString &suffix)
{
QPixmap fileIconPixmap = overlayIcon(QStyle::SP_FileIcon, icon, QSize(16, 16));
// delete old icon, if it exists
QList<QPair<QString,QIcon> >::iterator iter = m_cache.begin();
for (; iter != m_cache.end(); ++iter) {
......@@ -103,7 +117,7 @@ void FileIconProvider::registerIconForSuffix(const QIcon &icon, const QString &s
}
}
QPair<QString,QIcon> newEntry(suffix, icon);
QPair<QString,QIcon> newEntry(suffix, fileIconPixmap);
m_cache.append(newEntry);
}
......
......@@ -40,6 +40,7 @@
#include <QtCore/QPair>
#include <QtGui/QFileIconProvider>
#include <QtGui/QIcon>
#include <QtGui/QStyle>
namespace Core {
......@@ -48,7 +49,8 @@ public:
~FileIconProvider(); // used to clear the cache
QIcon icon(const QFileInfo &fileInfo);
void registerIconForSuffix(const QIcon &icon, const QString &suffix);
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const;
void registerIconOverlayForSuffix(const QIcon &icon, const QString &suffix);
static FileIconProvider *instance();
......
......@@ -75,9 +75,9 @@ CppPluginEditorFactory::CppPluginEditorFactory(CppPlugin *owner) :
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconForSuffix(QIcon(":/cppeditor/images/qt_cpp.png"),
iconProvider->registerIconOverlayForSuffix(QIcon(":/cppeditor/images/qt_cpp.png"),
QLatin1String("cpp"));
iconProvider->registerIconForSuffix(QIcon(":/cppeditor/images/qt_h.png"),
iconProvider->registerIconOverlayForSuffix(QIcon(":/cppeditor/images/qt_h.png"),
QLatin1String("h"));
}
......
src/plugins/cppeditor/images/qt_cpp.png

561 Bytes | W: | H:

src/plugins/cppeditor/images/qt_cpp.png

282 Bytes | W: | H:

src/plugins/cppeditor/images/qt_cpp.png
src/plugins/cppeditor/images/qt_cpp.png
src/plugins/cppeditor/images/qt_cpp.png
src/plugins/cppeditor/images/qt_cpp.png
  • 2-up
  • Swipe
  • Onion skin
src/plugins/cppeditor/images/qt_h.png

448 Bytes | W: | H:

src/plugins/cppeditor/images/qt_h.png

492 Bytes | W: | H:

src/plugins/cppeditor/images/qt_h.png
src/plugins/cppeditor/images/qt_h.png
src/plugins/cppeditor/images/qt_h.png
src/plugins/cppeditor/images/qt_h.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -52,7 +52,7 @@ FormEditorFactory::FormEditorFactory()
m_mimeTypes(QLatin1String(FORM_MIMETYPE))
{
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconForSuffix(QIcon(":/formeditor/images/qt_ui.png"),
iconProvider->registerIconOverlayForSuffix(QIcon(":/formeditor/images/qt_ui.png"),
QLatin1String("ui"));
}
......
src/plugins/designer/images/qt_ui.png

666 Bytes | W: | H:

src/plugins/designer/images/qt_ui.png

806 Bytes | W: | H:

src/plugins/designer/images/qt_ui.png
src/plugins/designer/images/qt_ui.png
src/plugins/designer/images/qt_ui.png
src/plugins/designer/images/qt_ui.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -56,9 +56,9 @@ ProFileEditorFactory::ProFileEditorFactory(Qt4Manager *manager, TextEditor::Text
m_actionHandler(handler)
{
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconForSuffix(QIcon(":/qt4projectmanager/images/qt_project.png"),
iconProvider->registerIconOverlayForSuffix(QIcon(":/qt4projectmanager/images/qt_project.png"),
QLatin1String("pro"));
iconProvider->registerIconForSuffix(QIcon(":/qt4projectmanager/images/qt_project.png"),
iconProvider->registerIconOverlayForSuffix(QIcon(":/qt4projectmanager/images/qt_project.png"),
QLatin1String("pri"));
}
......
......@@ -43,6 +43,7 @@
#include <projectexplorer/nodesvisitor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
......@@ -60,6 +61,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>
#include <QtGui/QPainter>
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
......@@ -94,7 +96,17 @@ Qt4PriFileNode::Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNo
{
Q_ASSERT(project);
setFolderName(QFileInfo(filePath).baseName());
setIcon(QIcon(":/qt4projectmanager/images/qt_project.png"));
static QIcon dirIcon;
if (dirIcon.isNull()) {
// Create a custom Qt dir icon based on the system icon
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
QPixmap dirIconPixmap = iconProvider->overlayIcon(QStyle::SP_DirIcon,
QIcon(":/qt4projectmanager/images/qt_project.png"),
QSize(16, 16));
dirIcon.addPixmap(dirIconPixmap);
}
setIcon(dirIcon);
m_fileWatcher->addFile(filePath);
connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
this, SLOT(scheduleUpdate()));
......
src/plugins/resourceeditor/images/qt_qrc.png

622 Bytes | W: | H:

src/plugins/resourceeditor/images/qt_qrc.png

676 Bytes | W: | H:

src/plugins/resourceeditor/images/qt_qrc.png
src/plugins/resourceeditor/images/qt_qrc.png
src/plugins/resourceeditor/images/qt_qrc.png
src/plugins/resourceeditor/images/qt_qrc.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -55,8 +55,8 @@ ResourceEditorFactory::ResourceEditorFactory(ResourceEditorPlugin *plugin) :
m_context += Core::UniqueIDManager::instance()
->uniqueIdentifier(QLatin1String(ResourceEditor::Constants::C_RESOURCEEDITOR));
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconForSuffix(QIcon(":/resourceeditor/images/qt_qrc.png"),
QLatin1String("qrc"));
iconProvider->registerIconOverlayForSuffix(QIcon(":/resourceeditor/images/qt_qrc.png"),
QLatin1String("qrc"));
}
QString ResourceEditorFactory::kind() const
......
Markdown is supported
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