2013-07-10 22:29:07 +00:00
|
|
|
#ifndef DATADISPLAYDELEGATE_HPP
|
|
|
|
#define DATADISPLAYDELEGATE_HPP
|
|
|
|
|
|
|
|
#include <QTextOption>
|
|
|
|
#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;
|
2013-07-10 22:29:07 +00:00
|
|
|
typedef std::vector<std::pair<int, QString> > ValueList;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
enum DisplayMode
|
|
|
|
{
|
|
|
|
Mode_TextOnly,
|
|
|
|
Mode_IconOnly,
|
|
|
|
Mode_IconAndText
|
|
|
|
};
|
|
|
|
|
|
|
|
DisplayMode mDisplayMode;
|
|
|
|
IconList mIcons;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::vector <std::pair <int, QPixmap> > mPixmaps;
|
|
|
|
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:
|
2015-01-15 13:24:33 +00:00
|
|
|
DataDisplayDelegate (const ValueList & values, const IconList & icons,
|
|
|
|
CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document,
|
2015-12-14 16:38:33 +00:00
|
|
|
const std::string& pageName, const std::string& settingName, QObject *parent);
|
2013-07-10 22:29:07 +00:00
|
|
|
|
|
|
|
~DataDisplayDelegate();
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2013-07-10 22:29:07 +00:00
|
|
|
|
2020-10-16 18:18:54 +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).
|
2014-09-26 15:12:48 +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.
|
|
|
|
void setTextLeftOffset (int offset);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-04-25 12:16:40 +00:00
|
|
|
/// update the display mode based on a passed string
|
2015-12-14 16:38:33 +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.
|
|
|
|
void paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int i) const;
|
|
|
|
|
|
|
|
/// rebuild the list of pixmaps from the provided icons (called when icon size is changed)
|
|
|
|
void buildPixmaps();
|
|
|
|
|
2020-10-16 18:18:54 +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:
|
|
|
|
|
2020-10-16 18:18:54 +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:
|
|
|
|
|
2016-01-03 17:20:34 +00:00
|
|
|
void add (int enumValue, const QString& enumName, const QString& iconFilename);
|
2013-07-10 22:29:07 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DATADISPLAYDELEGATE_HPP
|