From 1d27fa9c035ac891be483b16350d52dde5cacc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20St=C4=99pie=C5=84?= Date: Wed, 21 Sep 2011 18:22:38 +0200 Subject: [PATCH] Add possibility to change colors in runtime. --- src/properties/downloadedpiecesbar.cpp | 15 ++++++++++++++- src/properties/downloadedpiecesbar.h | 4 ++++ src/properties/pieceavailabilitybar.cpp | 14 +++++++++++++- src/properties/pieceavailabilitybar.h | 4 ++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/properties/downloadedpiecesbar.cpp b/src/properties/downloadedpiecesbar.cpp index 469b66a7b..e980213b4 100644 --- a/src/properties/downloadedpiecesbar.cpp +++ b/src/properties/downloadedpiecesbar.cpp @@ -37,6 +37,7 @@ DownloadedPiecesBar::DownloadedPiecesBar(QWidget *parent): QWidget(parent) setFixedHeight(BAR_HEIGHT); bg_color = 0xffffff; + border_color = palette().color(QPalette::Dark).rgb(); piece_color = 0x0000ff; piece_color_dl = 0x00d000; @@ -228,8 +229,20 @@ void DownloadedPiecesBar::paintEvent(QPaintEvent *) QPainterPath border; border.addRect(0, 0, width() - 1, height() - 1); - painter.setPen(palette().color(QPalette::Dark)); + painter.setPen(border_color); painter.drawPath(border); } +void DownloadedPiecesBar::setColors(int background, int border, int complete, int incomplete) +{ + bg_color = background; + border_color = border; + piece_color = complete; + piece_color_dl = incomplete; + + updatePieceColors(); + updateImage(); + update(); +} + diff --git a/src/properties/downloadedpiecesbar.h b/src/properties/downloadedpiecesbar.h index d7b4b52a5..9e5324507 100644 --- a/src/properties/downloadedpiecesbar.h +++ b/src/properties/downloadedpiecesbar.h @@ -50,6 +50,8 @@ private: // background color int bg_color; + // border color + int border_color; // complete piece color int piece_color; // incomplete piece color @@ -76,6 +78,8 @@ public: void updatePieceColors(); void clear(); + void setColors(int background, int border, int complete, int incomplete); + protected: void paintEvent(QPaintEvent *); }; diff --git a/src/properties/pieceavailabilitybar.cpp b/src/properties/pieceavailabilitybar.cpp index 358c0ebf6..c155678a7 100644 --- a/src/properties/pieceavailabilitybar.cpp +++ b/src/properties/pieceavailabilitybar.cpp @@ -38,6 +38,7 @@ PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent) : setFixedHeight(BAR_HEIGHT); bg_color = 0xffffff; + border_color = palette().color(QPalette::Dark).rgb(); piece_color = 0x0000ff; updatePieceColors(); @@ -220,6 +221,17 @@ void PieceAvailabilityBar::paintEvent(QPaintEvent *) QPainterPath border; border.addRect(0, 0, width() - 1, height() - 1); - painter.setPen(palette().color(QPalette::Dark)); + painter.setPen(border_color); painter.drawPath(border); } + +void PieceAvailabilityBar::setColors(int background, int border, int available) +{ + bg_color = background; + border_color = border; + piece_color = available; + + updatePieceColors(); + updateImage(); + update(); +} diff --git a/src/properties/pieceavailabilitybar.h b/src/properties/pieceavailabilitybar.h index 6c568fe9e..585347f0a 100644 --- a/src/properties/pieceavailabilitybar.h +++ b/src/properties/pieceavailabilitybar.h @@ -50,6 +50,8 @@ private: // background color int bg_color; + // border color + int border_color; // complete piece color int piece_color; // buffered 256 levels gradient from bg_color to piece_color @@ -74,6 +76,8 @@ public: void updatePieceColors(); void clear(); + void setColors(int background, int border, int available); + protected: void paintEvent(QPaintEvent *);