Skip to content

Commit

Permalink
Merge branch 'datadisplaydelegate' into 'master'
Browse files Browse the repository at this point in the history
React to scale or color changes in editor tables

See merge request OpenMW/openmw!4098
  • Loading branch information
psi29a committed Jun 22, 2024
2 parents 82285da + 204267d commit 0013a44
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/opencs/view/world/datadisplaydelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions apps/opencs/view/world/datadisplaydelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,6 +62,8 @@ namespace CSVWorld
QSize mIconSize;
int mHorizontalMargin;
int mTextLeftOffset;
QColor mPixmapsColor;
qreal mUiScale;

std::string mSettingKey;

Expand All @@ -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&);
Expand Down

0 comments on commit 0013a44

Please sign in to comment.