mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-11 06:40:34 +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))
|
||||
, mHorizontalMargin(QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1)
|
||||
, mTextLeftOffset(8)
|
||||
, mPixmapsColor(QApplication::palette().text().color())
|
||||
, mUiScale(static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio())
|
||||
, mSettingKey(pageName + '/' + settingName)
|
||||
{
|
||||
parent->installEventFilter(this);
|
||||
|
||||
buildPixmaps();
|
||||
|
||||
if (!pageName.empty())
|
||||
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()
|
||||
{
|
||||
if (!mPixmaps.empty())
|
||||
|
@ -41,6 +41,7 @@ namespace CSVWorld
|
||||
|
||||
class DataDisplayDelegate : public EnumDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef std::vector<Icon> IconList;
|
||||
typedef std::vector<std::pair<int, QString>> ValueList;
|
||||
@ -61,6 +62,8 @@ namespace CSVWorld
|
||||
QSize mIconSize;
|
||||
int mHorizontalMargin;
|
||||
int mTextLeftOffset;
|
||||
QColor mPixmapsColor;
|
||||
qreal mUiScale;
|
||||
|
||||
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.
|
||||
void setTextLeftOffset(int offset);
|
||||
|
||||
bool eventFilter(QObject* target, QEvent* event) override;
|
||||
|
||||
private:
|
||||
/// update the display mode based on a passed string
|
||||
void updateDisplayMode(const std::string&);
|
||||
|
Loading…
x
Reference in New Issue
Block a user