2013-07-10 22:29:07 +00:00
|
|
|
#ifndef DATADISPLAYDELEGATE_HPP
|
|
|
|
#define DATADISPLAYDELEGATE_HPP
|
|
|
|
|
|
|
|
#include "enumdelegate.hpp"
|
|
|
|
|
2015-12-14 16:38:33 +00:00
|
|
|
namespace CSMPrefs
|
2013-07-10 22:29:07 +00:00
|
|
|
{
|
2015-12-14 16:38:33 +00:00
|
|
|
class Setting;
|
|
|
|
}
|
2013-07-10 22:29:07 +00:00
|
|
|
|
2015-12-14 16:38:33 +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;
|
2015-06-16 18:25:06 +00:00
|
|
|
int mHorizontalMargin;
|
2013-07-10 22:29:07 +00:00
|
|
|
int mTextLeftOffset;
|
|
|
|
|
2015-12-14 16:38:33 +00:00
|
|
|
std::string mSettingKey;
|
2014-04-25 12:16:40 +00:00
|
|
|
|
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;
|
2015-06-16 18:25:06 +00:00
|
|
|
|
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:
|
2014-04-25 12:16:40 +00:00
|
|
|
/// update the display mode based on a passed string
|
2022-09-22 18:26:05 +00:00
|
|
|
void updateDisplayMode(const std::string&);
|
2014-04-25 12:16:40 +00:00
|
|
|
|
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
|