Commit a18b0673 authored by Alessandro Portale's avatar Alessandro Portale Committed by hjk

Cleanup of Theming

A theme is supposed to provide colors, flags and images. This change
removes functions from Theme which do not just return simple data.
Also ManhattanStyle and Theme get separated a bit.

Change-Id: I2fab26ee38b858fefb55920eb219f84abcfaac18
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 4612cccb
......@@ -113,18 +113,15 @@ DetailsWidgetHeaderGradient\1\color=0
DetailsWidgetHeaderGradient\1\pos=1
DetailsWidgetHeaderGradient\size=1
[IconOverlay]
CSourceMimetype=:/cppeditor/images/dark_qt_c.png
CppHeaderMimetype=:/cppeditor/images/dark_qt_h.png
CppSourceMimetype=:/cppeditor/images/dark_qt_cpp.png
PrfMimetype=:/qtsupport/images/dark_qt_project.png
PriMimetype=:/qtsupport/images/dark_qt_project.png
ProMimetype=:/qtsupport/images/dark_qt_project.png
#TODO: needs to be ported to new ini format!
[StandardIcons]
SP_FileIcon=:/core/images/dark_fileicon.png
SP_DirIcon=:/core/images/dark_foldericon.png
[ImageFiles]
IconOverlayCSource=:/cppeditor/images/dark_qt_c.png
IconOverlayCppHeader=:/cppeditor/images/dark_qt_h.png
IconOverlayCppSource=:/cppeditor/images/dark_qt_cpp.png
IconOverlayPrf=:/qtsupport/images/dark_qt_project.png
IconOverlayPri=:/qtsupport/images/dark_qt_project.png
IconOverlayPro=:/qtsupport/images/dark_qt_project.png
StandardPixmapFileIcon=:/core/images/dark_fileicon.png
StandardPixmapDirIcon=:/core/images/dark_foldericon.png
[Style]
WidgetStyle=StyleFlat
......@@ -63,13 +63,6 @@ Theme::~Theme()
delete d;
}
void Theme::drawIndicatorBranch(QPainter *painter, const QRect &rect, QStyle::State state) const
{
Q_UNUSED(painter);
Q_UNUSED(rect);
Q_UNUSED(state);
}
Theme::WidgetStyle Theme::widgetStyle() const
{
return d->widgetStyle;
......@@ -85,48 +78,15 @@ QColor Theme::color(Theme::ColorRole role) const
return d->colors[role].first;
}
QGradientStops Theme::gradient(Theme::GradientRole role) const
{
return d->gradientStops[role];
}
QString Theme::iconOverlay(Theme::MimeType mimetype) const
{
return d->iconOverlays[mimetype];
}
QString Theme::dpiSpecificImageFile(const QString &fileName) const
QString Theme::imageFile(Theme::ImageFile imageFile, const QString &fallBack) const
{
return dpiSpecificImageFile(fileName, QLatin1String(""));
const QString &file = d->imageFiles.at(imageFile);
return file.isEmpty() ? fallBack : file;
}
QString Theme::dpiSpecificImageFile(const QString &fileName, const QString &themePrefix) const
QGradientStops Theme::gradient(Theme::GradientRole role) const
{
// See QIcon::addFile()
const QFileInfo fi(fileName);
bool at2x = (qApp->devicePixelRatio() > 1.0);
const QString at2xFileName = fi.path() + QStringLiteral("/")
+ fi.completeBaseName() + QStringLiteral("@2x.") + fi.suffix();
const QString themedAt2xFileName = fi.path() + QStringLiteral("/") + themePrefix
+ fi.completeBaseName() + QStringLiteral("@2x.") + fi.suffix();
const QString themedFileName = fi.path() + QStringLiteral("/") + themePrefix
+ fi.completeBaseName() + QStringLiteral(".") + fi.suffix();
if (at2x) {
if (QFile::exists(themedAt2xFileName))
return themedAt2xFileName;
else if (QFile::exists(themedFileName))
return themedFileName;
else if (QFile::exists(at2xFileName))
return at2xFileName;
return fileName;
} else {
if (QFile::exists(themedFileName))
return themedFileName;
return fileName;
}
return d->gradientStops[role];
}
QPair<QColor, QString> Theme::readNamedColor(const QString &color) const
......@@ -143,11 +103,6 @@ QPair<QColor, QString> Theme::readNamedColor(const QString &color) const
return qMakePair(QColor::fromRgba(rgba), QString());
}
QString Theme::imageFile(const QString &fileName) const
{
return fileName;
}
QString Theme::fileName() const
{
return d->fileName;
......@@ -202,6 +157,17 @@ void Theme::writeSettings(const QString &filename) const
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("ImageFiles"));
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("ImageFile"));
for (int i = 0, total = e.keyCount(); i < total; ++i) {
const QString key = QLatin1String(e.key(i));
const QString &var = d->imageFiles.at(i);
if (!var.isEmpty())
settings.setValue(key, var);
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("Gradients"));
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("GradientRole"));
......@@ -220,15 +186,6 @@ void Theme::writeSettings(const QString &filename) const
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("IconOverlay"));
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("MimeType"));
for (int i = 0, total = e.keyCount(); i < total; ++i) {
const QString key = QLatin1String(e.key(i));
settings.setValue(key, iconOverlay(static_cast<Theme::MimeType>(i)));
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("Flags"));
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Flag"));
......@@ -280,6 +237,15 @@ void Theme::readSettings(QSettings &settings)
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("ImageFiles"));
QMetaEnum e = m.enumerator(m.indexOfEnumerator("ImageFile"));
for (int i = 0, total = e.keyCount(); i < total; ++i) {
const QString key = QLatin1String(e.key(i));
d->imageFiles[i] = settings.value(key).toString();
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("Gradients"));
QMetaEnum e = m.enumerator(m.indexOfEnumerator("GradientRole"));
......@@ -300,16 +266,6 @@ void Theme::readSettings(QSettings &settings)
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("IconOverlay"));
QMetaEnum e = m.enumerator(m.indexOfEnumerator("MimeType"));
for (int i = 0, total = e.keyCount(); i < total; ++i) {
const QString key = QLatin1String(e.key(i));
QTC_ASSERT(settings.contains(key), return);;
d->iconOverlays[i] = settings.value(key).toString();
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("Flags"));
QMetaEnum e = m.enumerator(m.indexOfEnumerator("Flag"));
......@@ -322,14 +278,6 @@ void Theme::readSettings(QSettings &settings)
}
}
QIcon Theme::standardIcon(QStyle::StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const
{
Q_UNUSED(standardPixmap);
Q_UNUSED(opt);
Q_UNUSED(widget);
return QIcon();
}
QPalette Theme::palette(const QPalette &base) const
{
if (!flag(DerivePaletteFromTheme))
......
......@@ -47,6 +47,7 @@ class QTCREATOR_UTILS_EXPORT Theme : public QObject
Q_OBJECT
Q_ENUMS(ColorRole)
Q_ENUMS(ImageFile)
Q_ENUMS(GradientRole)
Q_ENUMS(MimeType)
Q_ENUMS(Flag)
......@@ -159,13 +160,22 @@ public:
Welcome_Button_GradientPressed
};
enum MimeType {
CppSourceMimetype,
CSourceMimetype,
CppHeaderMimetype,
ProMimetype,
PriMimetype,
PrfMimetype
enum ImageFile {
ProjectExplorerHeader,
ProjectExplorerSource,
ProjectExplorerForm,
ProjectExplorerResource,
ProjectExplorerQML,
ProjectExplorerOtherFiles,
ProjectFileIcon,
IconOverlayCSource,
IconOverlayCppHeader,
IconOverlayCppSource,
IconOverlayPri,
IconOverlayPrf,
IconOverlayPro,
StandardPixmapFileIcon,
StandardPixmapDirIcon
};
enum Flag {
......@@ -185,13 +195,9 @@ public:
WidgetStyle widgetStyle() const;
bool flag(Flag f) const;
QColor color(ColorRole role) const;
QString imageFile(ImageFile imageFile, const QString &fallBack) const;
QGradientStops gradient(GradientRole role) const;
QString iconOverlay(MimeType mimetype) const;
QPalette palette(const QPalette &base) const;
QString dpiSpecificImageFile(const QString &fileName) const;
void drawIndicatorBranch(QPainter *painter, const QRect &rect, QStyle::State state) const;
QIcon standardIcon(QStyle::StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const;
QString imageFile(const QString &fileName) const;
QString fileName() const;
void setName(const QString &name);
......@@ -203,9 +209,6 @@ public:
signals:
void changed();
protected:
QString dpiSpecificImageFile(const QString &fileName, const QString &themePrefix) const;
private:
QPair<QColor, QString> readNamedColor(const QString &color) const;
};
......
......@@ -39,8 +39,8 @@ ThemePrivate::ThemePrivate()
{
const QMetaObject &m = Theme::staticMetaObject;
colors.resize (m.enumerator(m.indexOfEnumerator("ColorRole")).keyCount());
imageFiles.resize (m.enumerator(m.indexOfEnumerator("ImageFile")).keyCount());
gradientStops.resize (m.enumerator(m.indexOfEnumerator("GradientRole")).keyCount());
iconOverlays.resize (m.enumerator(m.indexOfEnumerator("MimeType")).keyCount());
flags.resize (m.enumerator(m.indexOfEnumerator("Flag")).keyCount());
}
......
......@@ -47,7 +47,7 @@ public:
QString fileName;
QString name;
QVector<QPair<QColor, QString> > colors;
QVector<QString> iconOverlays;
QVector<QString> imageFiles;
QVector<QGradientStops> gradientStops;
QVector<bool> flags;
Theme::WidgetStyle widgetStyle;
......
......@@ -314,12 +314,17 @@ void ManhattanStyle::polish(QPalette &pal)
QProxyStyle::polish(pal);
}
QIcon ManhattanStyle::standardIcon(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const
QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
{
QIcon ico = creatorTheme()->standardIcon(standardPixmap, opt, widget);
if (!ico.isNull())
return ico;
return QProxyStyle::standardIcon(standardPixmap, opt, widget);
QIcon icon;
switch (standardIcon) {
case QStyle::SP_TitleBarCloseButton:
case QStyle::SP_ToolBarHorizontalExtensionButton:
return QIcon(standardPixmap(standardIcon, option, widget));
default:
icon = baseStyle()->standardIcon(standardIcon, option, widget);
}
return icon;
}
QPixmap ManhattanStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
......@@ -376,13 +381,8 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
if (!panelWidget(widget)) {
if (creatorTheme()->flag(Theme::DrawIndicatorBranch) && element == PE_IndicatorBranch) {
creatorTheme()->drawIndicatorBranch(painter, option->rect, option->state);
return;
}
if (!panelWidget(widget))
return QProxyStyle::drawPrimitive(element, option, painter, widget);
}
bool animating = (option->state & State_Animating);
int state = option->state;
......
......@@ -56,7 +56,6 @@ public:
SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget = 0) const;
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget = 0) const;
QIcon standardIcon(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget = 0) const;
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const;
QRect itemRect(QPainter *p, const QRect &r, int flags, bool enabled, const QPixmap *pixmap, const QString &text, int len = -1) const;
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const;
......@@ -72,6 +71,9 @@ public:
void unpolish(QWidget *widget);
void unpolish(QApplication *app);
protected slots:
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const;
private:
void drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const;
......
......@@ -65,7 +65,7 @@ int ThemeSettingsTableModel::sectionRowCount(int section) const
case SectionWidgetStyle: return 1;
case SectionColors: return m_colors->numColorRoles();
case SectionFlags: return m_flags.size();
case SectionIconOverlays: return m_iconOverlays.size();
case SectionImageFiles: return m_imageFiles.size();
default: return 0;
}
}
......@@ -110,11 +110,11 @@ QVariant ThemeSettingsTableModel::sectionBodyData(int section, int row, int colu
return QVariant::fromValue(makeDecoration(Qt::transparent));
return QVariant();
}
case SectionIconOverlays: {
case SectionImageFiles: {
if (column == 0 && role == Qt::DisplayRole)
return m_iconOverlays[row].first;
return m_imageFiles[row].first;
else if (column == 1 && role == Qt::DisplayRole)
return m_iconOverlays[row].second;
return m_imageFiles[row].second;
else if (column == 0 && role == Qt::DecorationRole)
return QVariant::fromValue(makeDecoration(Qt::transparent));
return QVariant();
......@@ -131,7 +131,7 @@ QVariant ThemeSettingsTableModel::sectionHeaderData(int section, int role) const
case SectionWidgetStyle: return tr("Widget Style");
case SectionColors: return tr("Colors");
case SectionFlags: return tr("Flags");
case SectionIconOverlays: return tr("Icon Overlays");
case SectionImageFiles: return tr("Image Files");
default: return QString();
}
}
......@@ -159,7 +159,7 @@ Qt::ItemFlags ThemeSettingsTableModel::sectionBodyFlags(int section, int row, in
case SectionFlags:
return (column == 0) ? Qt::ItemIsEnabled
: Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
case SectionIconOverlays:
case SectionImageFiles:
return Qt::ItemIsEnabled;
default: return Qt::ItemIsEnabled;
}
......@@ -225,12 +225,12 @@ void ThemeSettingsTableModel::initFrom(Theme *theme)
m_flags.append(qMakePair(key, theme->flag(static_cast<Theme::Flag>(i))));
}
}
// IconOverlays
// ImageFiles
{
QMetaEnum e = metaObject.enumerator(metaObject.indexOfEnumerator("MimeType"));
QMetaEnum e = metaObject.enumerator(metaObject.indexOfEnumerator("ImageFile"));
for (int i = 0, total = e.keyCount(); i < total; ++i) {
const QString key = QLatin1String(e.key(i));
m_iconOverlays.append(qMakePair(key, theme->iconOverlay(static_cast<Theme::MimeType>(i))));
m_imageFiles.append(qMakePair(key, theme->imageFile(static_cast<Theme::ImageFile>(i), QString())));
}
}
......@@ -256,12 +256,11 @@ void ThemeSettingsTableModel::toTheme(Theme *t) const
for (int i = 0; i < theme->flags.size(); ++i)
theme->flags[i] = m_flags[i].second;
}
// IconOveralys
// ImageFiles
{
const int nOverlays = theme->iconOverlays.size();
QTC_ASSERT(nOverlays == m_iconOverlays.size(), return);
for (int i = 0; i < nOverlays; ++i)
theme->iconOverlays[i] = m_iconOverlays[i].second;
const int nImageFiles = theme->imageFiles.size();
for (int i = 0; i < nImageFiles; ++i)
theme->imageFiles[i] = m_imageFiles.at(i).second;
}
theme->widgetStyle = m_widgetStyle;
......
......@@ -52,7 +52,7 @@ public:
SectionWidgetStyle,
SectionColors,
SectionFlags,
SectionIconOverlays,
SectionImageFiles,
SectionInvalid // end
};
......@@ -82,7 +82,7 @@ public:
public:
ThemeColors::Ptr m_colors;
QList<QPair<QString, bool> > m_flags;
QList<QPair<QString, QString> > m_iconOverlays;
QList<QPair<QString, QString> > m_imageFiles;
Utils::Theme::WidgetStyle m_widgetStyle;
bool m_hasChanges;
};
......
......@@ -105,9 +105,15 @@ public:
addHoverHandler(new CppHoverHandler);
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
FileIconProvider::registerIconOverlayForMimeType(creatorTheme()->iconOverlay(Theme::CppSourceMimetype).toLatin1().data(), Constants::CPP_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(creatorTheme()->iconOverlay(Theme::CSourceMimetype).toLatin1().data(), Constants::C_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(creatorTheme()->iconOverlay(Theme::CppHeaderMimetype).toLatin1().data(), Constants::CPP_HEADER_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(
QIcon(creatorTheme()->imageFile(Theme::IconOverlayCppSource, QLatin1String(":/cppeditor/images/qt_cpp.png"))),
Constants::CPP_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(
QIcon(creatorTheme()->imageFile(Theme::IconOverlayCSource, QLatin1String(":/cppeditor/images/qt_c.png"))),
Constants::C_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(
QIcon(creatorTheme()->imageFile(Theme::IconOverlayCppHeader, QLatin1String(":/cppeditor/images/qt_h.png"))),
Constants::CPP_HEADER_MIMETYPE);
}
}
};
......
......@@ -224,9 +224,13 @@ ProFileEditorFactory::ProFileEditorFactory()
addHoverHandler(new ProFileHoverHandler(keywords));
setSyntaxHighlighterCreator([keywords]() { return new ProFileHighlighter(keywords); });
Core::FileIconProvider::registerIconOverlayForSuffix(creatorTheme()->iconOverlay(Theme::ProMimetype).toLatin1().data(), "pro");
Core::FileIconProvider::registerIconOverlayForSuffix(creatorTheme()->iconOverlay(Theme::PriMimetype).toLatin1().data(), "pri");
Core::FileIconProvider::registerIconOverlayForSuffix(creatorTheme()->iconOverlay(Theme::PrfMimetype).toLatin1().data(), "prf");
const QString defaultOverlay = QLatin1String(QtSupport::Constants::ICON_QT_PROJECT);
Core::FileIconProvider::registerIconOverlayForSuffix(
creatorTheme()->imageFile(Theme::IconOverlayPro, defaultOverlay).toLatin1().data(), "pro");
Core::FileIconProvider::registerIconOverlayForSuffix(
creatorTheme()->imageFile(Theme::IconOverlayPri, defaultOverlay).toLatin1().data(), "pri");
Core::FileIconProvider::registerIconOverlayForSuffix(
creatorTheme()->imageFile(Theme::IconOverlayPrf, defaultOverlay).toLatin1().data(), "prf");
}
} // namespace Internal
......
......@@ -84,27 +84,28 @@ struct FileTypeDataStorage {
ProjectExplorer::FileType type;
const char *typeName;
const char *icon;
Theme::ImageFile themeImage;
};
static const FileTypeDataStorage fileTypeDataStorage[] = {
{ ProjectExplorer::HeaderType,
QT_TRANSLATE_NOOP("QmakeProjectManager::QmakePriFileNode", "Headers"),
":/qmakeprojectmanager/images/headers.png" },
":/qmakeprojectmanager/images/headers.png", Theme::ProjectExplorerHeader },
{ ProjectExplorer::SourceType,
QT_TRANSLATE_NOOP("QmakeProjectManager::QmakePriFileNode", "Sources"),
":/qmakeprojectmanager/images/sources.png" },
":/qmakeprojectmanager/images/sources.png", Theme::ProjectExplorerSource },
{ ProjectExplorer::FormType,
QT_TRANSLATE_NOOP("QmakeProjectManager::QmakePriFileNode", "Forms"),
":/qtsupport/images/forms.png" },
":/qtsupport/images/forms.png", Theme::ProjectExplorerForm },
{ ProjectExplorer::ResourceType,
QT_TRANSLATE_NOOP("QmakeProjectManager::QmakePriFileNode", "Resources"),
":/qtsupport/images/qt_qrc.png" },
":/qtsupport/images/qt_qrc.png", Theme::ProjectExplorerResource },
{ ProjectExplorer::QMLType,
QT_TRANSLATE_NOOP("QmakeProjectManager::QmakePriFileNode", "QML"),
":/qtsupport/images/qml.png" },
":/qtsupport/images/qml.png", Theme::ProjectExplorerQML },
{ ProjectExplorer::UnknownFileType,
QT_TRANSLATE_NOOP("QmakeProjectManager::QmakePriFileNode", "Other files"),
":/qmakeprojectmanager/images/unknown.png" }
":/qmakeprojectmanager/images/unknown.png", Theme::ProjectExplorerOtherFiles }
};
class SortByPath
......@@ -153,8 +154,8 @@ QmakeNodeStaticData::QmakeNodeStaticData()
for (unsigned i = 0 ; i < count; ++i) {
QIcon overlayIcon;
QString iconFile = QString::fromLatin1(fileTypeDataStorage[i].icon);
iconFile = creatorTheme()->imageFile(iconFile);
const QString iconFile = creatorTheme()->imageFile(fileTypeDataStorage[i].themeImage,
QString::fromLatin1(fileTypeDataStorage[i].icon));
overlayIcon = QIcon(iconFile);
const QPixmap folderPixmap =
Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
......@@ -166,8 +167,9 @@ QmakeNodeStaticData::QmakeNodeStaticData()
desc, folderIcon));
}
// Project icon
const QLatin1String fname(":/qtsupport/images/qt_project.png");
const QIcon projectBaseIcon(creatorTheme()->imageFile(fname));
const QString fileName = creatorTheme()->imageFile(Theme::ProjectFileIcon,
QLatin1String(":/qtsupport/images/qt_project.png"));
const QIcon projectBaseIcon(fileName);
const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
projectBaseIcon,
desiredSize);
......
......@@ -100,7 +100,6 @@ const char IOS_PLATFORM_TR[] = QT_TRANSLATE_NOOP("QtSupport", "iOS");
const char QML_WIZARD_ICON[] = ":/qmlproject/images/qml_wizard.png";
const char ICON_QT_PROJECT[] = ":/qtsupport/images/qt_project.png";
const char DARK_ICON_QT_PROJECT[] = ":/qtsupport/images/dark_qt_project.png";
} // namepsace Constants
} // namepsace QtSupport
......
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