1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +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.

118 lines
3.0 KiB
C++
Raw Normal View History

2013-07-10 17:29:07 -05:00
#ifndef DATADISPLAYDELEGATE_HPP
#define DATADISPLAYDELEGATE_HPP
#include "enumdelegate.hpp"
2022-10-19 19:02:00 +02:00
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
class QModelIndex;
class QObject;
class QPainter;
class QPixmap;
namespace CSMDoc
{
class Document;
}
namespace CSMWorld
{
class CommandDispatcher;
}
namespace CSMPrefs
2013-07-10 17:29:07 -05:00
{
class Setting;
}
2013-07-10 17:29:07 -05:00
namespace CSVWorld
{
2022-10-19 19:02:00 +02:00
class CommandDelegate;
2018-07-17 22:49:51 +04:00
struct Icon
{
int mValue;
QIcon mIcon;
QString mName;
};
2013-07-10 17:29:07 -05:00
class DataDisplayDelegate : public EnumDelegate
{
Q_OBJECT
2013-07-10 17:29:07 -05:00
public:
2018-07-17 22:49:51 +04:00
typedef std::vector<Icon> IconList;
2013-07-10 17:29:07 -05: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;
int mHorizontalMargin;
2013-07-10 17:29:07 -05:00
int mTextLeftOffset;
QColor mPixmapsColor;
qreal mUiScale;
2013-07-10 17:29:07 -05:00
std::string mSettingKey;
2013-07-10 17:29:07 -05:00
public:
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 17:29:07 -05:00
~DataDisplayDelegate() = default;
2013-07-10 17:29:07 -05:00
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
2013-07-10 17:29:07 -05:00
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
2013-07-10 17:29:07 -05:00
/// pass a QSize defining height / width of icon. Default is QSize (16,16).
2014-09-26 17:12:48 +02:00
void setIconSize(const QSize& icon);
2013-07-10 17:29:07 -05:00
/// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels.
void setTextLeftOffset(int offset);
bool eventFilter(QObject* target, QEvent* event) override;
2013-07-10 17:29:07 -05:00
private:
/// update the display mode based on a passed string
void updateDisplayMode(const std::string&);
2013-07-10 17:29:07 -05: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();
void settingChanged(const CSMPrefs::Setting* setting) override;
2013-07-10 17:29:07 -05:00
};
class DataDisplayDelegateFactory : public EnumDelegateFactory
{
protected:
DataDisplayDelegate::IconList mIcons;
public:
CommandDelegate* makeDelegate(
CSMWorld::CommandDispatcher* dispatcher, CSMDoc::Document& document, QObject* parent) const override;
2013-07-10 17:29:07 -05:00
///< The ownership of the returned CommandDelegate is transferred to the caller.
protected:
2016-01-03 18:20:34 +01:00
void add(int enumValue, const QString& enumName, const QString& iconFilename);
2013-07-10 17:29:07 -05:00
};
}
#endif // DATADISPLAYDELEGATE_HPP