PDA

View Full Version : Custom Style based on Cleanlooks



Tux-Slack
20th September 2007, 22:31
I've made a custom style based on the existing cleanlooks style. I've got almoast everything the way I want, only I can not change the scroll bar. At least not the way I would like it.

I have to scrollbar images, one for vertical and one for horizontal scrollbar. But when I try to add them the whole scroll bar get's that image instead of just the scrollbar slider.

This is the code where I drawComplexControl():

void mediaArchiverStyle::drawComplexControl(ComplexCont rol control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget) const
{
switch (control) {
case CC_ScrollBar:
{
int delta = (option->state & State_MouseOver) ? 64 : 0;
QColor slightlyOpaqueBlack(100, 100, 100, 63);
QColor semiTransparentWhite(255, 255, 255, 127 + delta);
QColor semiTransparentBlack(10, 10, 10, 127 - delta);

int x, y, width, height;
option->rect.getRect(&x, &y, &width, &height);

QPainterPath roundRect = roundRectPath(option->rect);
int radius = qMin(width, height) / 2;

QBrush brush;
bool darker;

const QStyleOptionSlider *sliderOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
if (sliderOption) {
if (sliderOption->orientation == Qt::Vertical)
brush = option->palette.light();
else
brush = option->palette.midlight();
darker = false;
}

QStyleOptionSlider mySliderOption;
if (sliderOption) {
mySliderOption = *sliderOption;
if (mySliderOption.palette.currentColorGroup() != QPalette::Disabled) {
if (mySliderOption.state & (State_Enabled)) {
mySliderOption.palette.setBrush(QPalette::ButtonTe xt,
mySliderOption.palette.brightText());
}
}
}
QCleanlooksStyle::drawComplexControl(control, &mySliderOption, painter, widget);

painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->fillPath(roundRect, brush);
if (darker)
painter->fillPath(roundRect, slightlyOpaqueBlack);

int penWidth;
if (radius < 10)
penWidth = 3;
else if (radius < 20)
penWidth = 5;
else
penWidth = 7;

QPen topPen(semiTransparentWhite, penWidth);
QPen bottomPen(semiTransparentBlack, penWidth);

if (option->state & (State_Enabled))
qSwap(topPen, bottomPen);

int x1 = x;
int x2 = x + radius;
int x3 = x + width - radius;
int x4 = x + width;

if (option->direction == Qt::RightToLeft) {
qSwap(x1, x4);
qSwap(x2, x3);
}

QPolygon topHalf;
topHalf << QPoint(x1, y)
<< QPoint(x4, y)
<< QPoint(x3, y + radius)
<< QPoint(x2, y + height - radius)
<< QPoint(x1, y + height);

painter->setClipPath(roundRect);
painter->setClipRegion(topHalf, Qt::IntersectClip);
painter->setPen(topPen);
painter->drawPath(roundRect);

QPolygon bottomHalf = topHalf;
bottomHalf[0] = QPoint(x4, y + height);

painter->setClipPath(roundRect);
painter->setClipRegion(bottomHalf, Qt::IntersectClip);
painter->setPen(bottomPen);
painter->drawPath(roundRect);

painter->setPen(option->palette.foreground().color());
painter->setClipping(false);
painter->drawPath(roundRect);

painter->restore();
}
break;
default:
QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
}
}

Thank you for your help!

wysota
21st September 2007, 00:19
I think you should call drawControl() and you should draw the scrollbar slider from within there.

Tux-Slack
21st September 2007, 00:55
I tried that to.
But CE_ScrollBarSlider never gets "triggered".
I put a qDebug() in it and start the app but nothing appears on the console.

Funy part is, that if I inherit from QMotifStyle class the srollbar gets styled well, only the images are a bit mixed up. But I don't like motif very much and I would like to do it with cleanlooks.

wysota
21st September 2007, 00:58
You probably have to call it yourself from within drawComplexControl.

Tux-Slack
21st September 2007, 10:22
You mean calling drawControl and pass it the CE?
Doesn't do much good.
It just changes the whole scrollbar, again, instead of the slider.