mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-16 08:42:23 +00:00
Merge branch 'datadisplaydelegate' into 'master'
React to scale or color changes in editor tables See merge request OpenMW/openmw!4098
This commit is contained in:
commit
0013a44b71
@ -41,14 +41,44 @@ CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList& values, cons
|
|||||||
, mIconSize(QSize(16, 16))
|
, mIconSize(QSize(16, 16))
|
||||||
, mHorizontalMargin(QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1)
|
, mHorizontalMargin(QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1)
|
||||||
, mTextLeftOffset(8)
|
, mTextLeftOffset(8)
|
||||||
|
, mPixmapsColor(QApplication::palette().text().color())
|
||||||
|
, mUiScale(static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio())
|
||||||
, mSettingKey(pageName + '/' + settingName)
|
, mSettingKey(pageName + '/' + settingName)
|
||||||
{
|
{
|
||||||
|
parent->installEventFilter(this);
|
||||||
|
|
||||||
buildPixmaps();
|
buildPixmaps();
|
||||||
|
|
||||||
if (!pageName.empty())
|
if (!pageName.empty())
|
||||||
updateDisplayMode(CSMPrefs::get()[pageName][settingName].toString());
|
updateDisplayMode(CSMPrefs::get()[pageName][settingName].toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSVWorld::DataDisplayDelegate::eventFilter(QObject* target, QEvent* event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Resize)
|
||||||
|
{
|
||||||
|
auto uiScale = static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio();
|
||||||
|
if (mUiScale != uiScale)
|
||||||
|
{
|
||||||
|
mUiScale = uiScale;
|
||||||
|
|
||||||
|
buildPixmaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (event->type() == QEvent::PaletteChange)
|
||||||
|
{
|
||||||
|
QColor themeColor = QApplication::palette().text().color();
|
||||||
|
if (themeColor != mPixmapsColor)
|
||||||
|
{
|
||||||
|
mPixmapsColor = themeColor;
|
||||||
|
|
||||||
|
buildPixmaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void CSVWorld::DataDisplayDelegate::buildPixmaps()
|
void CSVWorld::DataDisplayDelegate::buildPixmaps()
|
||||||
{
|
{
|
||||||
if (!mPixmaps.empty())
|
if (!mPixmaps.empty())
|
||||||
|
@ -41,6 +41,7 @@ namespace CSVWorld
|
|||||||
|
|
||||||
class DataDisplayDelegate : public EnumDelegate
|
class DataDisplayDelegate : public EnumDelegate
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
typedef std::vector<Icon> IconList;
|
typedef std::vector<Icon> IconList;
|
||||||
typedef std::vector<std::pair<int, QString>> ValueList;
|
typedef std::vector<std::pair<int, QString>> ValueList;
|
||||||
@ -61,6 +62,8 @@ namespace CSVWorld
|
|||||||
QSize mIconSize;
|
QSize mIconSize;
|
||||||
int mHorizontalMargin;
|
int mHorizontalMargin;
|
||||||
int mTextLeftOffset;
|
int mTextLeftOffset;
|
||||||
|
QColor mPixmapsColor;
|
||||||
|
qreal mUiScale;
|
||||||
|
|
||||||
std::string mSettingKey;
|
std::string mSettingKey;
|
||||||
|
|
||||||
@ -80,6 +83,8 @@ namespace CSVWorld
|
|||||||
/// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels.
|
/// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels.
|
||||||
void setTextLeftOffset(int offset);
|
void setTextLeftOffset(int offset);
|
||||||
|
|
||||||
|
bool eventFilter(QObject* target, QEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// update the display mode based on a passed string
|
/// update the display mode based on a passed string
|
||||||
void updateDisplayMode(const std::string&);
|
void updateDisplayMode(const std::string&);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user