Playing with colors.

This commit is contained in:
2025-12-21 23:20:22 +01:00
parent c88c57ad32
commit 42525014f2
18 changed files with 125 additions and 49 deletions

View File

@@ -141,7 +141,7 @@ QSize BCItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelI
} }
void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
/* /*
// 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen // 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
@@ -193,17 +193,57 @@ void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
if (m_rowOpacities.contains(row)) if (m_rowOpacities.contains(row))
{ {
/*
qreal opacity = m_rowOpacities.value(row); qreal opacity = m_rowOpacities.value(row);
if (opacity > 0.01) { if (opacity > 0.01)
{
painter->save(); painter->save();
painter->setOpacity(opacity); painter->setOpacity(opacity);
painter->fillRect(option.rect, QColor(255, 140, 0, 120)); painter->fillRect(option.rect, QColor(255, 140, 0, 120));
painter->restore(); painter->restore();
} }
*/
paintHighlightRow(painter,option,index);
} }
} }
void BCItemDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
int row = index.row();
qreal opacity = m_rowOpacities.value(row);
painter->setOpacity(opacity);
// Margin von 4px
QRect itemRect = option.rect.adjusted(4, 4, -4, -4);
// Border von 2px berücksichtigen (nach innen)
QRect contentRect = itemRect.adjusted(2, 2, -2, -2);
// Hintergrund (weiß)
painter->setBrush(Qt::white);
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(itemRect, 8, 8);
// Border (2px solid #2196F3)
QPen borderPen( Qt::red, 2);
painter->setPen(borderPen);
painter->setBrush(Qt::NoBrush);
painter->drawRoundedRect(itemRect, 8, 8);
// Padding von 8px für den Content
QRect textRect = contentRect.adjusted(8, 8, -8, -8);
// Text zeichnen
painter->setPen(Qt::black); // oder option.palette.color(QPalette::Text)
QString text = index.data(Qt::DisplayRole).toString();
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
painter->restore();
}
void BCItemDelegate::onHighlightRow(int row) void BCItemDelegate::onHighlightRow(int row)
{ {

View File

@@ -40,6 +40,7 @@ public:
emit viewUpdateNeeded(); emit viewUpdateNeeded();
} }
void clearAllHighlights(); void clearAllHighlights();
public slots: public slots:
@@ -55,6 +56,7 @@ private:
void updateRow(int row); void updateRow(int row);
QString formatDisplayString(const QModelIndex &index) const; QString formatDisplayString(const QModelIndex &index) const;
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
int _highlightedRow{-1}; int _highlightedRow{-1};
qreal _opacity{1.0}; qreal _opacity{1.0};
@@ -63,10 +65,9 @@ private:
private: private:
QHash<int, qreal> m_rowOpacities; QHash<int, qreal> m_rowOpacities;
QHash<int, QVariantAnimation*> m_rowAnimations; QHash<int, QVariantAnimation*> m_rowAnimations;
}; };

View File

@@ -78,12 +78,74 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>18</height> <height>22</height>
</rect> </rect>
</property> </property>
</widget> </widget>
<widget class="QStatusBar" name="_statusbar"/> <widget class="QStatusBar" name="_statusbar"/>
<action name="_actionPimp">
<property name="icon">
<iconset>
<normaloff>:restart.png</normaloff>:restart.png</iconset>
</property>
<property name="text">
<string>pimp</string>
</property>
<property name="toolTip">
<string>Pimp my Ride</string>
</property>
</action>
<action name="_actionMotor">
<property name="icon">
<iconset>
<normaloff>:bionx_motor.png</normaloff>:bionx_motor.png</iconset>
</property>
<property name="text">
<string>motor</string>
</property>
<property name="toolTip">
<string>Show motor settings</string>
</property>
</action>
<action name="_actionBattery">
<property name="icon">
<iconset>
<normaloff>:bionx_akku.png</normaloff>:bionx_akku.png</iconset>
</property>
<property name="text">
<string>battery</string>
</property>
<property name="toolTip">
<string>Show battery settings</string>
</property>
</action>
<action name="_actionConsole">
<property name="icon">
<iconset>
<normaloff>:bionx_console.png</normaloff>:bionx_console.png</iconset>
</property>
<property name="text">
<string>console</string>
</property>
<property name="toolTip">
<string>Show console settings</string>
</property>
</action>
<action name="_actionExit">
<property name="icon">
<iconset>
<normaloff>:exit.png</normaloff>:exit.png</iconset>
</property>
<property name="text">
<string>Exit</string>
</property>
<property name="toolTip">
<string>Exit</string>
</property>
</action>
</widget> </widget>
<resources/> <resources>
<include location="bionxcontrol.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@@ -1,16 +1,16 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file alias="bikeinfo.xml">data/bikeinfo.xml</file> <file alias="bikeinfo.xml">resources/bikeinfo.xml</file>
<file alias="bionxcontrol.qss">data/bionxcontrol.qss</file> <file alias="bionxcontrol.qss">resources/bionxcontrol.qss</file>
<file alias="bionx_akku.png">images/bionx_akku.png</file> <file alias="bionx_akku.png">resources/bionx_akku.png</file>
<file alias="bionx_console.png">images/bionx_console.png</file> <file alias="bionx_console.png">resources/bionx_console.png</file>
<file alias=bionx_motor.png">images/bionx_motor.png</file> <file alias="bionx_motor.png">resources/bionx_motor.png</file>
<file alias="exit.png">images/exit.png</file> <file alias="exit.png">resources/exit.png</file>
<file alias="important.png">images/important.png</file> <file alias="important.png">resources/important.png</file>
<file alias="restart.png">images/restart.png</file> <file alias="restart.png">resources/restart.png</file>
<file alias="splash.png">images/splash.png</file> <file alias="splash.png">resources/splash.png</file>
<file alias="connect.png">images/connect.png</file> <file alias="connect.png">resources/connect.png</file>
<file alias="connected.png">images/connected.png</file> <file alias="connected.png">resources/connected.png</file>
<file alias="disconnected.png">images/disconnected.png</file> <file alias="disconnected.png">resources/disconnected.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@@ -84,37 +84,8 @@ bool setApplicationStyleSheet( QAnyStringView path )
// 2. Datei öffnen und lesen // 2. Datei öffnen und lesen
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
auto x = BC::ID::Motor_Status_Main;
enum class Color : uint8_t { Red, Green, Blue };
QMap<Color, QString> map;
map.insert(Color::Red, QStringLiteral("rot"));
map[Color::Green] = QStringLiteral("grün");
qDebug() << " --- sach bloss das geht: " << x << " ui: " << uint8_t(x) << " : " << map[Color::Red];
QApplication app(argc, argv); QApplication app(argc, argv);
//setApplicationStyleSheet( ":/BionxControl.qss"_L1 ); setApplicationStyleSheet( ":/bionxcontrol.qss"_L1 );
QMetaEnum metaEnum = QMetaEnum::fromType<BC::ID>();
bool ok = false;
QString inputString = "x3";
BC::ID yyy{};
// keyToValue parst den String ("x1") und liefert den int-Wert
int intVal = metaEnum.keyToValue(inputString.toLatin1().constData(), &ok);
if (ok)
yyy = static_cast<BC::ID>(intVal);
auto xxx = BC::ID::Battery_Config_Force_Done;
//QString result = fullString.section("::", -1);
qDebug() << " schön: " << xxx << " -- " << uint8_t(xxx) << " : " << yyy;
qDebug() << " nice: " << metaEnum.enumName() << " : " <<metaEnum.name() << ": " << metaEnum.enclosingMetaObject()->className();
BCMainWindow w; BCMainWindow w;
w.show(); w.show();

View File

Before

Width:  |  Height:  |  Size: 109 KiB

After

Width:  |  Height:  |  Size: 109 KiB

View File

Before

Width:  |  Height:  |  Size: 139 KiB

After

Width:  |  Height:  |  Size: 139 KiB

View File

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -70,9 +70,11 @@ QListView::item:selected:hover
QListView::item:focus QListView::item:focus
{ {
// outline: none; /* Entfernt das Focus-Rectangle */ /*
// outline: none; Entfernt das Focus-Rectangle
// border-color: green; // border-color: green;
// background-color: #ffe0b2; // background-color: #ffe0b2;
*/
border: 2px solid gray; border: 2px solid gray;
border-style: inset; border-style: inset;
background-color: white; background-color: white;

View File

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 514 KiB

After

Width:  |  Height:  |  Size: 514 KiB