Closed codic12 closed 4 years ago
I'll eventually get around to adding the breeze features.
As for circles. Modify Button.cpp
to change background from a Rect to an Ellipse. Take a look at SierraBreezeEnhanced as it has a bunch of styles.
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawEllipse(buttonRect.center(), 11, 11);
painter->setRenderHint(QPainter::Antialiasing, false);
I recommend using make && sudo make install && kcmshell5 kwindecoration
for testing.
Thank you!
Wait, it seems like I need to use drawEllipse for drawing ellipses, but the switch-case statement uses the paintIcon method from each icon namespace (eg closeButton::paintIcon)...
The background/hover is drawn above the switch statement. Look for the painter->drawRect(buttonRect);
which you'll replace with the ellipse.
https://github.com/Zren/material-decoration/blob/master/src/Button.cc#L161-L164
Thanks! I got it working - almost. The circle is a bit streched but playing around should fix that. Bigger issue is that it's pixelated. I saw that you had a call to painter->setRenderHints() which changed QPainter::Antialiasing to false. I changed it to true, but now all the buttons are kind of blurry. Any way to turn it on only for the close button?
Sorry for all these questions haha, I'm new to QT
You'll notice I change antialiasing on, paint the ellipse, then turn it off in my example above.
I also used drawEllipse(QPoint center, int rx, int ry)
with rx == ry
so that it draws a circle instead of an oval. The buttonRect
is wider than it is tall, so don't use that.
Worked like a charm! As for drawEllipse, I have a QRectF, not a QPoint. I'm not sure where to get that... do I cast my buttonRect
to a QPoint?
Note that I might change shadow strength to 0-100 instead of 0-255. It's just easier to have a max of 255 atm as I'm not certain how to easily convert the value in the QSpinBox to value/100 * 255
.
I used buttonRect.center()
in my example above which gets the center QPointF
Thanks so much, I got it all working! All I need to do now is change the color on hover, and the color on press, for the close button... which file is that defined in?
Button::backgroundColor()
controls the colors for all button types.
You'll notice we mix colors with KColorUtils::mix(normalColor, pressedColor, m_opacity)
. m_opacity
is misnamed, it's how far into the hover animation tween we are. You'll want to edit the normalColor
.
//--- Normal
const QColor hoveredColor = KColorUtils::mix(
deco->titleBarBackgroundColor(),
deco->titleBarForegroundColor(),
0.2);
QColor normalColor = QColor(hoveredColor);
normalColor.setAlphaF(0);
Notice how I set normalColor to be hoveredColor
, but with alpha=0
.
Awesome, I got it to work just how I wanted it by setting a new QColor instance. thanks!
Personally, I feel like the current one is just a bit too large.
Also, this is a unrelated question, but if I wanted to make the hover effect on the close button circular, and always have a circle surrounding it even when it wasn't hovering, how could I do this?