1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 07:53:52 +00:00
openmw/apps/opencs/view/world/datadisplaydelegate.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.6 KiB
C++
Raw Normal View History

2013-07-10 22:29:07 +00:00
#ifndef DATADISPLAYDELEGATE_HPP
#define DATADISPLAYDELEGATE_HPP
#include "enumdelegate.hpp"
namespace CSMPrefs
2013-07-10 22:29:07 +00:00
{
class Setting;
}
2013-07-10 22:29:07 +00:00
namespace CSVWorld
{
2018-07-17 18:49:51 +00:00
struct Icon
{
int mValue;
QIcon mIcon;
QString mName;
};
2013-07-10 22:29:07 +00:00
class DataDisplayDelegate : public EnumDelegate
{
public:
2018-07-17 18:49:51 +00:00
typedef std::vector<Icon> IconList;
2022-09-22 18:26:05 +00:00
typedef std::vector<std::pair<int, QString>> ValueList;
2013-07-10 22:29:07 +00:00
protected:
enum DisplayMode
{
Mode_TextOnly,
Mode_IconOnly,
Mode_IconAndText
};
DisplayMode mDisplayMode;
IconList mIcons;
private:
2022-09-22 18:26:05 +00:00
std::vector<std::pair<int, QPixmap>> mPixmaps;
2013-07-10 22:29:07 +00:00
QSize mIconSize;
int mHorizontalMargin;
2013-07-10 22:29:07 +00:00
int mTextLeftOffset;
std::string mSettingKey;
2013-07-10 22:29:07 +00:00
public:
2022-09-22 18:26:05 +00:00
DataDisplayDelegate(const ValueList& values, const IconList& icons, CSMWorld::CommandDispatcher* dispatcher,
CSMDoc::Document& document, const std::string& pageName, const std::string& settingName, QObject* parent);
2013-07-10 22:29:07 +00:00
~DataDisplayDelegate();
2022-09-22 18:26:05 +00:00
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
2013-07-10 22:29:07 +00:00
2022-09-22 18:26:05 +00:00
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
2013-07-10 22:29:07 +00:00
/// pass a QSize defining height / width of icon. Default is QSize (16,16).
2022-09-22 18:26:05 +00:00
void setIconSize(const QSize& icon);
2013-07-10 22:29:07 +00:00
/// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels.
2022-09-22 18:26:05 +00:00
void setTextLeftOffset(int offset);
2013-07-10 22:29:07 +00:00
private:
/// update the display mode based on a passed string
2022-09-22 18:26:05 +00:00
void updateDisplayMode(const std::string&);
2013-07-10 22:29:07 +00:00
/// custom paint function for painting the icon. Mode_IconAndText and Mode_Icon only.
2022-09-22 18:26:05 +00:00
void paintIcon(QPainter* painter, const QStyleOptionViewItem& option, int i) const;
2013-07-10 22:29:07 +00:00
/// rebuild the list of pixmaps from the provided icons (called when icon size is changed)
void buildPixmaps();
2022-09-22 18:26:05 +00:00
void settingChanged(const CSMPrefs::Setting* setting) override;
2013-07-10 22:29:07 +00:00
};
class DataDisplayDelegateFactory : public EnumDelegateFactory
{
protected:
DataDisplayDelegate::IconList mIcons;
public:
2022-09-22 18:26:05 +00:00
CommandDelegate* makeDelegate(
CSMWorld::CommandDispatcher* dispatcher, CSMDoc::Document& document, QObject* parent) const override;
2013-07-10 22:29:07 +00:00
///< The ownership of the returned CommandDelegate is transferred to the caller.
protected:
2022-09-22 18:26:05 +00:00
void add(int enumValue, const QString& enumName, const QString& iconFilename);
2013-07-10 22:29:07 +00:00
};
}
#endif // DATADISPLAYDELEGATE_HPP