mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Change colors of stars if widget has focus
Some widgets on the main tab don't show any kind of focus indicator on some systems (like Mac), so it's a good thing to provide another way to show that they indeed have focus. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
25273a3912
commit
b62cf45d59
2 changed files with 27 additions and 3 deletions
|
@ -31,6 +31,10 @@
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionFocusRect>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
struct GroupedLineEdit::Private {
|
struct GroupedLineEdit::Private {
|
||||||
struct Block {
|
struct Block {
|
||||||
|
|
|
@ -17,6 +17,25 @@ const QImage& StarWidget::starInactive()
|
||||||
return inactiveStar;
|
return inactiveStar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage focusedImage(const QImage& coloredImg)
|
||||||
|
{
|
||||||
|
QImage img = coloredImg;
|
||||||
|
for (int i = 0; i < img.width(); ++i) {
|
||||||
|
for (int j = 0; j < img.height(); ++j) {
|
||||||
|
QRgb rgb = img.pixel(i, j);
|
||||||
|
if (!rgb)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QColor c(rgb);
|
||||||
|
c = c.dark();
|
||||||
|
img.setPixel(i, j, c.rgb());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int StarWidget::currentStars() const
|
int StarWidget::currentStars() const
|
||||||
{
|
{
|
||||||
return current;
|
return current;
|
||||||
|
@ -44,13 +63,14 @@ void StarWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||||
void StarWidget::paintEvent(QPaintEvent *event)
|
void StarWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
QPixmap active = QPixmap::fromImage(starActive());
|
QImage star = hasFocus() ? focusedImage(starActive()) : starActive();
|
||||||
|
QPixmap selected = QPixmap::fromImage(star);
|
||||||
QPixmap inactive = QPixmap::fromImage(starInactive());
|
QPixmap inactive = QPixmap::fromImage(starInactive());
|
||||||
|
|
||||||
const IconMetrics& metrics = defaultIconMetrics();
|
const IconMetrics& metrics = defaultIconMetrics();
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < current; i++)
|
for (int i = 0; i < current; i++)
|
||||||
p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, active);
|
p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, selected);
|
||||||
|
|
||||||
for (int i = current; i < TOTALSTARS; i++)
|
for (int i = current; i < TOTALSTARS; i++)
|
||||||
p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, inactive);
|
p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, inactive);
|
||||||
|
|
Loading…
Add table
Reference in a new issue