Skip to content
Snippets Groups Projects
Commit 227e02f7 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

New icons for InstrumentView switched on.

parent 9ba36238
No related branches found
No related tags found
No related merge requests found
...@@ -13,35 +13,74 @@ ...@@ -13,35 +13,74 @@
// ************************************************************************** // // ************************************************************************** //
#include "SessionDecorationModel.h" #include "SessionDecorationModel.h"
#include "SessionModel.h"
#include "MaterialItem.h" #include "MaterialItem.h"
#include "SessionModel.h"
#include <QColor> #include <QColor>
#include <QIcon> #include <QIcon>
#include <QPixmap> #include <QPixmap>
namespace { namespace
{
QIcon instrumentIcon() { struct IconCatalogue {
QIcon result; QIcon gisasIcon;
result.addPixmap(QPixmap(":/images/gisas_instrument_bw.png"), QIcon::Normal); QIcon offspecIcon;
result.addPixmap(QPixmap(":/images/gisas_instrument.png"), QIcon::Selected); QIcon specularIcon;
IconCatalogue()
{
gisasIcon.addPixmap(QPixmap(":/images/gisas_instrument.svg"), QIcon::Selected);
gisasIcon.addPixmap(QPixmap(":/images/gisas_instrument_shaded.svg"), QIcon::Normal);
offspecIcon.addPixmap(QPixmap(":/images/offspec_instrument.svg"), QIcon::Selected);
offspecIcon.addPixmap(QPixmap(":/images/offspec_instrument_shaded.svg"), QIcon::Normal);
specularIcon.addPixmap(QPixmap(":/images/specular_instrument.svg"), QIcon::Selected);
specularIcon.addPixmap(QPixmap(":/images/specular_instrument_shaded.svg"), QIcon::Normal);
}
};
IconCatalogue& iconCatalogue()
{
static IconCatalogue result;
return result; return result;
} }
QIcon materialIcon(const QColor& color) QIcon materialIcon(const QColor& color)
{ {
QIcon result; QIcon result;
QPixmap pixmap(10,10); QPixmap pixmap(10, 10);
pixmap.fill(color); pixmap.fill(color);
result.addPixmap(pixmap); result.addPixmap(pixmap);
return result; return result;
} }
QVariant itemIcon(const SessionItem* item)
{
QVariant result;
auto modelType = item->modelType();
auto& icons = iconCatalogue();
if (modelType == Constants::GISASInstrumentType) {
return QVariant(icons.gisasIcon);
} else if (modelType == Constants::OffSpecInstrumentType) {
return QVariant(icons.offspecIcon);
} else if (modelType == Constants::SpecularInstrumentType) {
return QVariant(icons.specularIcon);
} else if (modelType == Constants::MaterialType) {
auto materialItem = dynamic_cast<const MaterialItem*>(item);
return QVariant(materialIcon(materialItem->color()));
}
return result;
}
} }
SessionDecorationModel::SessionDecorationModel(QObject* parent, SessionModel* model) SessionDecorationModel::SessionDecorationModel(QObject* parent, SessionModel* model)
: QIdentityProxyModel(parent) : QIdentityProxyModel(parent), m_model(nullptr)
, m_model(nullptr)
{ {
setSessionModel(model); setSessionModel(model);
} }
...@@ -60,7 +99,7 @@ QVariant SessionDecorationModel::data(const QModelIndex& index, int role) const ...@@ -60,7 +99,7 @@ QVariant SessionDecorationModel::data(const QModelIndex& index, int role) const
return result; return result;
} }
if(role == Qt::TextColorRole) { if (role == Qt::TextColorRole) {
QVariant result = textColor(index); QVariant result = textColor(index);
if (result.isValid()) if (result.isValid())
return result; return result;
...@@ -69,25 +108,12 @@ QVariant SessionDecorationModel::data(const QModelIndex& index, int role) const ...@@ -69,25 +108,12 @@ QVariant SessionDecorationModel::data(const QModelIndex& index, int role) const
return QIdentityProxyModel::data(index, role); return QIdentityProxyModel::data(index, role);
} }
SessionModel* SessionDecorationModel::sessionModel()
{
return m_model;
}
QVariant SessionDecorationModel::createIcon(const QModelIndex& index) const QVariant SessionDecorationModel::createIcon(const QModelIndex& index) const
{ {
QVariant result; if (SessionItem* item = m_model->itemForIndex(index))
return itemIcon(item);
if (SessionItem* item = m_model->itemForIndex(index)) {
if (item->modelType() == Constants::GISASInstrumentType) {
return instrumentIcon();
} else if(item->modelType() == Constants::MaterialType) {
if (const MaterialItem *materialItem = dynamic_cast<const MaterialItem *>(item))
return materialIcon(materialItem->color());
}
}
return result; return QVariant();
} }
//! Returns text color. Disabled SessionItem's will appear in gray. //! Returns text color. Disabled SessionItem's will appear in gray.
......
...@@ -35,8 +35,6 @@ public: ...@@ -35,8 +35,6 @@ public:
QVariant data(const QModelIndex& index, int role) const; QVariant data(const QModelIndex& index, int role) const;
SessionModel* sessionModel();
private: private:
QVariant createIcon(const QModelIndex& index) const; QVariant createIcon(const QModelIndex& index) const;
QVariant textColor(const QModelIndex& index) const; QVariant textColor(const QModelIndex& index) const;
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
<file>images/closebutton.png</file> <file>images/closebutton.png</file>
<file>images/reset.png</file> <file>images/reset.png</file>
<file>images/darkclosebutton.png</file> <file>images/darkclosebutton.png</file>
<file>images/gisas_instrument.png</file>
<file>images/gisas_instrument_bw.png</file>
<file>mainwindow/tooltips.xml</file> <file>mainwindow/tooltips.xml</file>
<file>images/treeview-branch-closed.png</file> <file>images/treeview-branch-closed.png</file>
<file>images/treeview-branch-end.png</file> <file>images/treeview-branch-end.png</file>
...@@ -54,5 +52,11 @@ ...@@ -54,5 +52,11 @@
<file>images/caret-down.svg</file> <file>images/caret-down.svg</file>
<file>images/caret-right.svg</file> <file>images/caret-right.svg</file>
<file>images/toolbar16light_fft.svg</file> <file>images/toolbar16light_fft.svg</file>
<file>images/gisas_instrument.svg</file>
<file>images/gisas_instrument_shaded.svg</file>
<file>images/offspec_instrument.svg</file>
<file>images/offspec_instrument_shaded.svg</file>
<file>images/specular_instrument.svg</file>
<file>images/specular_instrument_shaded.svg</file>
</qresource> </qresource>
</RCC> </RCC>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment