#include "hvstyleplastique.h"

template <typename T>
struct HexString
{
    inline HexString(const T t)
            : val(t)
    {}

    inline void write(QChar *&dest) const
    {
        const ushort hexChars[] =
            { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
            };
        const char *c = reinterpret_cast<const char *>(&val);
        for (uint i = 0; i < sizeof(T); ++i)
        {
            *dest++ = hexChars[*c & 0xf];
            *dest++ = hexChars[(*c & 0xf0) >> 4];
            ++c;
        }
    }
    const T val;
};

template <typename T>
struct QConcatenable<HexString<T> >
{
    typedef HexString<T> type;
    enum { ExactSize = true };
    static int size(const HexString<T> &)
    {
        return sizeof(T) * 2;
    }
    static inline void appendTo(const HexString<T> &str, QChar *&out)
    {
        str.write(out);
    }
    typedef QString ConvertTo;
};

static const int windowsItemFrame        =  2; // menu item frame width
static const int windowsItemHMargin      =  3; // menu item hor text margin
static const int windowsItemVMargin      =  2; // menu item ver text margin
static const int windowsRightBorder      = 15; // right border on windows



static const bool AnimateBusyProgressBar = true;



#define Q_PI 3.14159265358
#define BEGIN_STYLE_PIXMAPCACHE(a) \
    QRect rect = option->rect; \
    QPixmap internalPixmapCache; \
    QImage imageCache; \
    QPainter *p = painter; \
    QString unique = QStyleHelper1::uniqueName((a), option, option->rect.size()); \
    int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
    bool doPixmapCache = txType <= QTransform::TxTranslate; \
    if (doPixmapCache && QPixmapCache::find(unique, &internalPixmapCache)) { \
        painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
    } else { \
        if (doPixmapCache) { \
            rect.setRect(0, 0, option->rect.width(), option->rect.height()); \
            imageCache = QImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); \
            imageCache.fill(0); \
            p = new QPainter(&imageCache); \
        }



#define END_STYLE_PIXMAPCACHE \
        if (doPixmapCache) { \
            p->end(); \
            delete p; \
            internalPixmapCache = QPixmap::fromImage(imageCache); \
            painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
            QPixmapCache::insert(unique, internalPixmapCache); \
        } \
    }

namespace QStyleHelper1
{

QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
{
    const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option);
    QString tmp = key % HexString<uint>(option->state)
                  % HexString<uint>(option->direction)
                  % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u)
                  % HexString<quint64>(option->palette.cacheKey())
                  % HexString<uint>(size.width())
                  % HexString<uint>(size.height());

#ifndef QT_NO_SPINBOX
    if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option))
    {
        tmp = tmp % HexString<uint>(spinBox->buttonSymbols)
              % HexString<uint>(spinBox->stepEnabled)
              % QLatin1Char(spinBox->frame ? '1' : '0');
        ;
    }
#endif // QT_NO_SPINBOX
    return tmp;
}
/*
qreal dpiScaled(qreal value)
{
    static qreal scale = -1;
    if (scale < 0)
    {
        scale = 1.0;
#if defined(Q_WS_WIN)
        {
            HDC hdcScreen = GetDC(0);
            int dpi = GetDeviceCaps(hdcScreen, LOGPIXELSX);
            ReleaseDC(0, hdcScreen);
            scale = dpi/96.0;
        }
#elif defined(Q_WS_MAC)
        scale = qt_mac_get_scalefactor();
#endif
    }
    return value * scale;
}
*/

#ifndef QT_NO_DIAL

int calcBigLineSize(int radius)
{
    int bigLineSize = radius / 6;
    if (bigLineSize < 4)
        bigLineSize = 4;
    if (bigLineSize > radius / 2)
        bigLineSize = radius / 2;
    return bigLineSize;
}

static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset)
{
    const int width = dial->rect.width();
    const int height = dial->rect.height();
    const int r = qMin(width, height) / 2;
    const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
    qreal a = 0;
    if (dial->maximum == dial->minimum)
        a = Q_PI / 2;
    else if (dial->dialWrapping)
        a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI
            / (dial->maximum - dial->minimum);
    else
        a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI
             / (dial->maximum - dial->minimum)) / 6;
    qreal xc = width / 2.0;
    qreal yc = height / 2.0;
    qreal len = r - QStyleHelper1::calcBigLineSize(r) - 3;
    qreal back = offset * len;
    QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a)));
    return pos;
}
/*
qreal angle(const QPointF &p1, const QPointF &p2)
{
    static const qreal rad_factor = 180 / Q_PI;
    qreal _angle = 0;

    if (p1.x() == p2.x())
    {
        if (p1.y() < p2.y())
            _angle = 270;
        else
            _angle = 90;
    }
    else
    {
        qreal x1, x2, y1, y2;

        if (p1.x() <= p2.x())
        {
            x1 = p1.x();
            y1 = p1.y();
            x2 = p2.x();
            y2 = p2.y();
        }
        else
        {
            x2 = p1.x();
            y2 = p1.y();
            x1 = p2.x();
            y1 = p2.y();
        }

        qreal m = -(y2 - y1) / (x2 - x1);
        _angle = qAtan(m) *  rad_factor;

        if (p1.x() < p2.x())
            _angle = 180 - _angle;
        else
            _angle = -_angle;
    }
    return _angle;
}
*/
QPolygonF calcLines(const QStyleOptionSlider *dial)
{
    QPolygonF poly;
    int width = dial->rect.width();
    int height = dial->rect.height();
    qreal r = qMin(width, height) / 2;
    int bigLineSize = calcBigLineSize(int(r));

    qreal xc = width / 2 + 0.5;
    qreal yc = height / 2 + 0.5;
    const int ns = dial->tickInterval;
    if (!ns) // Invalid values may be set by Qt Designer.
        return poly;
    int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
    if (notches <= 0)
        return poly;
    if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000)
    {
        int maximum = dial->minimum + 1000;
        notches = (maximum + ns - 1 - dial->minimum) / ns;
    }

    poly.resize(2 + 2 * notches);
    int smallLineSize = bigLineSize / 2;
    for (int i = 0; i <= notches; ++i)
    {
        qreal angle1 = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
                       : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
        qreal s = qSin(angle1);
        qreal c = qCos(angle1);
        if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0))
        {
            poly[2 * i] = QPointF(xc + (r - bigLineSize) * c,
                                  yc - (r - bigLineSize) * s);
            poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s);
        }
        else
        {
            poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c,
                                  yc - (r - 1 - smallLineSize) * s);
            poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s);
        }
    }
    return poly;
}

// This will draw a nice and shiny QDial for us. We don't want
// all the shinyness in QWindowsStyle, hence we place it here

void drawDial(const QStyleOptionSlider *option, QPainter *painter)
{
    QPalette pal = option->palette;
    QColor buttonColor = pal.button().color();
    const int width = option->rect.width();
    const int height = option->rect.height();
    const bool enabled = option->state & QStyle::State_Enabled;
    qreal r = qMin(width, height) / 2;
    r -= r/50;
    const qreal penSize = r/20.0;

    painter->save();
    painter->setRenderHint(QPainter::Antialiasing);

    // Draw notches
    if (option->subControls & QStyle::SC_DialTickmarks)
    {
        painter->setPen(option->palette.dark().color().darker(120));
        painter->drawLines(QStyleHelper1::calcLines(option));
    }

    // Cache dial background
    BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial"));
    p->setRenderHint(QPainter::Antialiasing);

    const qreal d_ = r / 6;
    const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1;
    const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1;

    QRectF br = QRectF(dx + 0.5, dy + 0.5,
                       int(r * 2 - 2 * d_ - 2),
                       int(r * 2 - 2 * d_ - 2));
    buttonColor.setHsv(buttonColor .hue(),
                       qMin(140, buttonColor .saturation()),
                       qMax(180, buttonColor.value()));
    //QColor shadowColor(0, 0, 0, 20);

    if (enabled)
    {
        // Drop shadow
        qreal shadowSize = qMax(1.0, penSize/2.0);
        QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
                                       2*shadowSize, 2*shadowSize);
        QRadialGradient shadowGradient(shadowRect.center().x(),
                                       shadowRect.center().y(), shadowRect.width()/2.0,
                                       shadowRect.center().x(), shadowRect.center().y());
        shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40));
        shadowGradient.setColorAt(qreal(1.0), Qt::transparent);
        p->setBrush(shadowGradient);
        p->setPen(Qt::NoPen);
        p->translate(shadowSize, shadowSize);
        p->drawEllipse(shadowRect);
        p->translate(-shadowSize, -shadowSize);

        // Main gradient
        QRadialGradient gradient(br.center().x() - br.width()/3, dy,
                                 br.width()*1.3, br.center().x(),
                                 br.center().y() - br.height()/2);
        gradient.setColorAt(0, buttonColor.lighter(110));
        gradient.setColorAt(qreal(0.5), buttonColor);
        gradient.setColorAt(qreal(0.501), buttonColor.darker(102));
        gradient.setColorAt(1, buttonColor.darker(115));
        p->setBrush(gradient);
    }
    else
    {
        p->setBrush(Qt::NoBrush);
    }

    p->setPen(QPen(buttonColor.darker(280)));
    p->drawEllipse(br);
    p->setBrush(Qt::NoBrush);
    p->setPen(buttonColor.lighter(110));
    p->drawEllipse(br.adjusted(1, 1, -1, -1));

    if (option->state & QStyle::State_HasFocus)
    {
        QColor highlight = pal.highlight().color();
        highlight.setHsv(highlight.hue(),
                         qMin(160, highlight.saturation()),
                         qMax(230, highlight.value()));
        highlight.setAlpha(127);
        p->setPen(QPen(highlight, 2.0));
        p->setBrush(Qt::NoBrush);
        p->drawEllipse(br.adjusted(-1, -1, 1, 1));
    }

    END_STYLE_PIXMAPCACHE

    QPointF dp = calcRadialPos(option, qreal(0.70));
    buttonColor = buttonColor.lighter(104);
    buttonColor.setAlphaF(qreal(0.8));
    const qreal ds = r/qreal(7.0);
    QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds);
    QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2,
                                 dialRect.center().y() + dialRect.width(),
                                 dialRect.width()*2,
                                 dialRect.center().x(), dialRect.center().y());
    dialGradient.setColorAt(1, buttonColor.darker(140));
    dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120));
    dialGradient.setColorAt(0, buttonColor.darker(110));
    if (penSize > 3.0)
    {
        painter->setPen(QPen(QColor(0, 0, 0, 25), penSize));
        painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96)));
    }

    painter->setBrush(dialGradient);
    painter->setPen(QColor(255, 255, 255, 150));
    painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1));
    painter->setPen(QColor(0, 0, 0, 80));
    painter->drawEllipse(dialRect);
    painter->restore();
}
#endif //QT_NO_DIAL
/*
void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect,
                      int left, int top, int right,
                      int bottom)
{
    QSize size = pixmap.size();
    //painter->setRenderHint(QPainter::SmoothPixmapTransform);

    //top
    if (top > 0)
    {
        painter->drawPixmap(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), pixmap,
                            QRect(left, 0, size.width() -right - left, top));

        //top-left
        if (left > 0)
            painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap,
                                QRect(0, 0, left, top));

        //top-right
        if (right > 0)
            painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap,
                                QRect(size.width() - right, 0, right, top));
    }

    //left
    if (left > 0)
        painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap,
                            QRect(0, top, left, size.height() - bottom - top));

    //center
    painter->drawPixmap(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
                              rect.height() - bottom - top), pixmap,
                        QRect(left, top, size.width() -right -left,
                              size.height() - bottom - top));
    //right
    if (right > 0)
        painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap,
                            QRect(size.width() - right, top, right, size.height() - bottom - top));

    //bottom
    if (bottom > 0)
    {
        painter->drawPixmap(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
                                  rect.width() - right - left, bottom), pixmap,
                            QRect(left, size.height() - bottom,
                                  size.width() - right - left, bottom));
        //bottom-left
        if (left > 0)
            painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap,
                                QRect(0, size.height() - bottom, left, bottom));

        //bottom-right
        if (right > 0)
            painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap,
                                QRect(size.width() - right, size.height() - bottom, right, bottom));

    }
}
*/

}//QStyleHelper1 namespace end

static const char * const qt_toolbarhandle[] =
    {
        "6 6 4 1",
        "       c None",
        ".      c #C5C5C5",
        "+      c #EEEEEE",
        "@      c #FAFAFA",
        "..    ",
        ".+@   ",
        " @@   ",
        "   .. ",
        "   .+@",
        "    @@"
    };
static const char * const qt_scrollbar_button_arrow_left[] =
    {
        "4 7 2 1",
        "   c None",
        "*  c #BFBFBF",
        "   *",
        "  **",
        " ***",
        "****",
        " ***",
        "  **",
        "   *"
    };

static const char * const qt_scrollbar_button_arrow_right[] =
    {
        "4 7 2 1",
        "   c None",
        "*  c #BFBFBF",
        "*   ",
        "**  ",
        "*** ",
        "****",
        "*** ",
        "**  ",
        "*   "
    };

static const char * const qt_scrollbar_button_arrow_up[] =
    {
        "7 4 2 1",
        "   c None",
        "*  c #BFBFBF",
        "   *   ",
        "  ***  ",
        " ***** ",
        "*******"
    };

static const char * const qt_scrollbar_button_arrow_down[] =
    {
        "7 4 2 1",
        "   c None",
        "*  c #BFBFBF",
        "*******",
        " ***** ",
        "  ***  ",
        "   *   "
    };

static const char * const qt_scrollbar_button_left[] =
    {
        "16 16 6 1",
        "   c None",
        ".  c #BFBFBF",
        "+  c #979797",
        "#  c #FAFAFA",
        "<  c #FAFAFA",
        "*  c #FAFAFA",
        " .+++++++++++++.",
        ".+#############+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        ".+<<<<<<<<<<<<<+",
        " .+++++++++++++."
    };

static const char * const qt_scrollbar_button_right[] =
    {
        "16 16 6 1",
        "   c None",
        ".  c #BFBFBF",
        "+  c #979797",
        "#  c #FAFAFA",
        "<  c #FAFAFA",
        "*  c #FAFAFA",
        ".+++++++++++++. ",
        "+#############+.",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+<<<<<<<<<<<<<+.",
        ".+++++++++++++. "
    };

static const char * const qt_scrollbar_button_up[] =
    {
        "16 16 6 1",
        "   c None",
        ".  c #BFBFBF",
        "+  c #979797",
        "#  c #FAFAFA",
        "<  c #FAFAFA",
        "*  c #FAFAFA",
        " .++++++++++++. ",
        ".+############+.",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+<<<<<<<<<<<<<<+",
        ".++++++++++++++."
    };

static const char * const qt_scrollbar_button_down[] =
    {
        "16 16 6 1",
        "   c None",
        ".  c #BFBFBF",
        "+  c #979797",
        "#  c #FAFAFA",
        "<  c #FAFAFA",
        "*  c #FAFAFA",
        "++++++++++++++++",
        "+##############+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        "+#            <+",
        ".+<<<<<<<<<<<<+.",
        " .++++++++++++. "
    };

static const char * const qt_scrollbar_slider_pattern_vertical[] =
    {
        "10 18 3 1",
        "   c None",
        ".  c #BFBFBF",
        "+  c #979797",
        "..  ..  ..",
        ".+  .+  .+",
        "          ",
        "          ",
        "..  ..  ..",
        ".+  .+  .+",
        "          ",
        "          ",
        "..  ..  ..",
        ".+  .+  .+",
        "          ",
        "          ",
        "..  ..  ..",
        ".+  .+  .+",
        "          ",
        "          ",
        "..  ..  ..",
        ".+  .+  .+"
    };

static const char * const qt_scrollbar_slider_pattern_horizontal[] =
    {
        "18 10 3 1",
        "   c None",
        ".  c #BFBFBF",
        "+  c #979797",
        "..  ..  ..  ..  ..",
        ".+  .+  .+  .+  .+",
        "                  ",
        "                  ",
        "..  ..  ..  ..  ..",
        ".+  .+  .+  .+  .+",
        "                  ",
        "                  ",
        "..  ..  ..  ..  ..",
        ".+  .+  .+  .+  .+"
    };

static const char * const qt_simple_toolbarhandle[] =
    {
        "3 3 4 1",
        "       c None",
        ".      c #C5C5C5",
        "+      c #EEEEEE",
        "@      c #FAFAFA",
        ".. ",
        ".+@",
        " @@"
    };

static const char * const qt_plastique_slider_verticalhandle[] =
    {
        "15 11 6 1",
        "   c None",
        "+  c #979797",
        "@  c #C9C9C9",
        "$  c #C1C1C1",
        "b  c None",
        "d  c None",
        " $++++++++$    ",
        "$+bbbbbbbb+$   ",
        "+b $$      +$  ",
        "+b $@       +$ ",
        "+b           +$",
        "+b           d+",
        "+b          d+$",
        "+b $$      d+$ ",
        "+b $@     d+$  ",
        "$+dddddddd+$   ",
        " $++++++++$    "
    };

static const char * const qt_plastique_slider_verticalhandle_left[] =
    {
        "15 11 6 1",
        "   c None",
        "+  c #979797",
        "@  c #C9C9C9",
        "$  c #C1C1C1",
        "b  c None",
        "d  c None",
        "    $++++++++$ ",
        "   $+bbbbbbbb+$",
        "  $+b     $$ d+",
        " $+b      $@ d+",
        "$+b          d+",
        "+b           d+",
        "$+           d+",
        " $+       $$ d+",
        "  $+      $@ d+",
        "   $+dddddddd+$",
        "    $++++++++$ "
    };

static const char * const qt_plastique_slider_horizontalhandle[] =
    {
        "11 15 6 1",
        "   c None",
        "+  c #979797",
        "@  c #C9C9C9",
        "$  c #C1C1C1",
        "b  c None",
        "d  c None",
        " $+++++++$ ",
        "$+bbbbbbb+$",
        "+b       d+",
        "+b$$   $$d+",
        "+b$@   $@d+",
        "+b       d+",
        "+b       d+",
        "+b       d+",
        "+b       d+",
        "+b       d+",
        "$+      d+$",
        " $+    d+$ ",
        "  $+  d+$  ",
        "   $+d+$   ",
        "    $+$    "
    };

static const char * const qt_plastique_slider_horizontalhandle_up[] =
    {
        "11 15 6 1",
        "   c None",
        "+  c #979797",
        "@  c #C9C9C9",
        "$  c #C1C1C1",
        "b  c None",
        "d  c None",
        "    $+$    ",
        "   $+b+$   ",
        "  $+b  +$  ",
        " $+b    +$ ",
        "$+b      +$",
        "+b       d+",
        "+b       d+",
        "+b       d+",
        "+b       d+",
        "+b       d+",
        "+b$$   $$d+",
        "+b$@   $@d+",
        "+b       d+",
        "$+ddddddd+$",
        " $+++++++$ "
    };

static const char * const qt_titlebar_context_help[] =
    {
        "27 27 5 1",
        "  c None",
        ". c #0A0C12",
        "+ c #1B202D",
        "@ c #293144",
        "# c #3C435D",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "           +@##@+          ",
        "         .@@@.+@@..        ",
        "         .##+  +@@+.       ",
        "         .##@  @#@+.       ",
        "         ....  +@+..       ",
        "            .@+@@..        ",
        "            +#@@+          ",
        "            .##.           ",
        "            .++.           ",
        "            .++.           ",
        "            +##+           ",
        "            .@@.           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           "
    };


HvStylePlastique::HvStylePlastique(bool f)//:
//: QCommonStyle(*new HvStylePlastiquePrivate)
//: HvPublicStyle(QStyleFactory::create("windows"))//,(*new HvStylePlastiquePrivate)
{
    f_dark_style = f;

    //NorwegianWoodStyle::NorwegianWoodStyle() :
    // QProxyStyle(QStyleFactory::create("windows"))

    //QApplication::setStyle(new QWindowsVistaStyle);
    //QStyle* fusion = QStyleFactory::create("fusion");
    //QApplication::setStyle(QStyleFactory::create("Fusion"));
    //QStyleFactory::create("Fusion");
    //this->setst

    //QString App_Path = (QCoreApplication::applicationDirPath());
    //int nFont = QFontDatabase::addApplicationFont(":font/arial.ttf");//registriram fonta//  xsuni
    //int nFont = QFontDatabase::addApplicationFont (App_Path+"/settings/font/times.ttf");
    //int nFont = QFontDatabase::addApplicationFont (App_Path+"/settings/font/xsuni.ttf");
    //int nFont = QFontDatabase::addApplicationFont (App_Path+"/settings/font/cour.ttf");
    //QStringList fontList = QFontDatabase::applicationFontFamilies(nFont);
    //QString szFont = fontList[0];

    /*
    #if defined _WIN32_
        QFont font(szFont, 9);
    #endif
    #if defined _LINUX_
        QFont font(szFont, 10);
    #endif
    */
    //QFont font(fontList[0],9);
    //QApplication::setFont(font);
    //QApplication::setStyleSheet("color: black; font-family: Arial; font-size: 14px");
    //QApplication:: painter.setFont(font);
    // painter->setFont(font);


}
HvStylePlastique::~HvStylePlastique()
{}
int HvStylePlastique::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
{
    switch (pm)
    {
    case  PM_LayoutVerticalSpacing:
        return 5; // raztoianieto m/u layoutite / v id3 info
    case PM_FocusFrameVMargin:
        return 0;// na buton 6irinata ot dolu
    case PM_FocusFrameHMargin:
        return 4; //treeview otpred pred rowa
    case  PM_DefaultFrameWidth:
        return 2; // dalzinata na row v treeview i bordera
    case PM_HeaderGripMargin:
        return 5; // raztoianieto ot koeto se pokazva splitera za resize
    case PM_HeaderMargin:
        return 2;// goleminata na headera
    case PM_MenuBarVMargin:
        return 0;//1
    case PM_MenuBarItemSpacing:
        return 2;
        //case PM_TitleBarHeight:
        //return 20;
    case PM_ScrollBarSliderMin:
        return 26;
    case PM_ScrollBarExtent:
        return 16;
    default:
        return HvPublicStyle::pixelMetric(pm, opt, widget);
    }

    /* int ret;

       switch (pm) {
       case PM_ButtonDefaultIndicator:
       case PM_ButtonShiftHorizontal:
       case PM_ButtonShiftVertical:
       case PM_MenuHMargin:
       case PM_MenuVMargin:
           ret = 1;
           break;
    #ifndef QT_NO_TABBAR
       case PM_TabBarTabShiftHorizontal:
           ret = 0;
           break;
       case PM_TabBarTabShiftVertical:
           ret = 2;
           break;
    #endif
       case PM_MaximumDragDistance:
    #if defined(Q_WS_WIN)
           {
               HDC hdcScreen = GetDC(0);
               int dpi = GetDeviceCaps(hdcScreen, LOGPIXELSX);
               ReleaseDC(0, hdcScreen);
               ret = (int)(dpi * 1.375);
           }
    #else
           ret = 60;
    #endif
           break;

    #ifndef QT_NO_SLIDER
       case PM_SliderLength:
           ret = int(QStyleHelper1::dpiScaled(11.));
           break;

           // Returns the number of pixels to use for the business part of the
           // slider (i.e., the non-tickmark portion). The remaining space is shared
           // equally between the tickmark regions.
       case PM_SliderControlThickness:
           if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
               int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
               int ticks = sl->tickPosition;
               int n = 0;
               if (ticks & QSlider::TicksAbove)
                   ++n;
               if (ticks & QSlider::TicksBelow)
                   ++n;
               if (!n) {
                   ret = space;
                   break;
               }

               int thick = 6;        // Magic constant to get 5 + 16 + 5
               if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
                   thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4;

               space -= thick;
               if (space > 0)
                   thick += (space * 2) / (n + 2);
               ret = thick;
           } else {
               ret = 0;
           }
           break;
    #endif // QT_NO_SLIDER

    #ifndef QT_NO_MENU
       case PM_MenuBarHMargin:
           ret = 0;
           break;

       case PM_MenuBarVMargin:
           ret = 0;
           break;

       case PM_MenuBarPanelWidth:
           ret = 0;
           break;

       case PM_SmallIconSize:
           ret = int(QStyleHelper1::dpiScaled(16.));
           break;

       case PM_LargeIconSize:
           ret = int(QStyleHelper1::dpiScaled(32.));
           break;

       case PM_IconViewIconSize:
           ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
           break;

       case PM_DockWidgetTitleMargin:
           ret = int(QStyleHelper1::dpiScaled(2.));
           break;
       case PM_DockWidgetTitleBarButtonMargin:
           ret = int(QStyleHelper1::dpiScaled(4.));
           break;
    #if defined(Q_WS_WIN)
       case PM_DockWidgetFrameWidth:
    #if defined(Q_OS_WINCE)
           ret = GetSystemMetrics(SM_CXDLGFRAME);
    #else
           ret = GetSystemMetrics(SM_CXFRAME);
    #endif
           break;
    #else
       case PM_DockWidgetFrameWidth:
           ret = 4;
           break;
    #endif // Q_WS_WIN
       break;

    #endif // QT_NO_MENU


    #if defined(Q_WS_WIN)
       case PM_TitleBarHeight:
    #ifdef QT3_SUPPORT
           // qt3 dockwindow height should be equal to tool windows
           if (widget && widget->inherits("Q3DockWindowTitleBar")) {
               ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
           } else
    #endif
           if (widget && (widget->windowType() == Qt::Tool)) {
               // MS always use one less than they say
    #if defined(Q_OS_WINCE)
               ret = GetSystemMetrics(SM_CYCAPTION) - 1;
    #else
               ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
    #endif
           } else {
               ret = GetSystemMetrics(SM_CYCAPTION) - 1;
           }

           break;

       case PM_ScrollBarExtent:
           {
    #ifndef Q_OS_WINCE
               NONCLIENTMETRICS ncm;
               ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT);
               if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0))
                   ret = qMax(ncm.iScrollHeight, ncm.iScrollWidth);
               else
    #endif
                   ret = QCommonStyle::pixelMetric(pm, opt, widget);
           }
           break;
    #endif // Q_WS_WIN

       case PM_SplitterWidth:
           ret = qMax(4, QApplication::globalStrut().width());
           break;

    #if defined(Q_WS_WIN)
       case PM_MdiSubWindowFrameWidth:
    #if defined(Q_OS_WINCE)
           ret = GetSystemMetrics(SM_CYDLGFRAME);
    #else
           ret = GetSystemMetrics(SM_CYFRAME);
    #endif
           break;
       case PM_TextCursorWidth: {
           DWORD caretWidth = 1;
    #if defined(SPI_GETCARETWIDTH)
           SystemParametersInfo(SPI_GETCARETWIDTH, 0, &caretWidth, 0);
    #endif
           ret = (int)caretWidth;
           break; }
    #endif
       case PM_ToolBarItemMargin:
           ret = 1;
           break;
       case PM_ToolBarItemSpacing:
           ret = 0;
           break;
       case PM_ToolBarHandleExtent:
           ret = int(QStyleHelper1::dpiScaled(10.));
           break;
       default:
           ret = QCommonStyle::pixelMetric(pm, opt, widget);
           break;
       }

       return ret; */



    /*  int ret = -1;
      switch (pm) {
      case PM_MenuVMargin:
      case PM_MenuHMargin:
          ret = 0;
          break;
      case PM_ButtonShiftHorizontal:
      case PM_ButtonShiftVertical:
          ret = 1;
          break;
      case PM_ButtonDefaultIndicator:
          ret = 0;
          break;
    #ifndef QT_NO_SLIDER
      case PM_SliderThickness:
          ret = 15;
          break;
      case PM_SliderLength:
      case PM_SliderControlThickness:
          ret = 11;
          break;
      case PM_SliderTickmarkOffset:
          ret = 5;
          break;
      case PM_SliderSpaceAvailable:
          if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
              int size = 15;
              if (slider->tickPosition & QSlider::TicksBelow)
                  ++size;
              if (slider->tickPosition & QSlider::TicksAbove)
                  ++size;
              ret = size;
              break;
          }
    #endif // QT_NO_SLIDER
      case PM_ScrollBarExtent:
          ret = 16;
          break;
      case PM_ScrollBarSliderMin:
          ret = 26;
          break;
      case PM_ProgressBarChunkWidth:
          ret = 1;
          break;
      case PM_MenuBarItemSpacing:
          ret = 3;
          break;
      case PM_MenuBarVMargin:
          ret = 2;
          break;
      case PM_MenuBarHMargin:
          ret = 0;
          break;
      case PM_MenuBarPanelWidth:
          ret = 1;
          break;
      case PM_ToolBarHandleExtent:
          ret = 9;
          break;
      case PM_ToolBarSeparatorExtent:
          ret = 2;
          break;
      case PM_ToolBarItemSpacing:
          ret = 1;
          break;
      case PM_ToolBarItemMargin:
          ret = 1;
          break;
      case PM_ToolBarFrameWidth:
          ret = 2;
          break;
      case PM_SplitterWidth:
          ret = 6;
          break;
      case PM_DockWidgetSeparatorExtent:
          ret = 6;
          break;
      case PM_DockWidgetHandleExtent:
          ret = 20;
          break;
      case PM_DefaultFrameWidth:
    #ifndef QT_NO_MENU
          if (qobject_cast<const QMenu *>(widget)) {
              ret = 1;
              break;
          }
    #endif
          ret = 2;
          break;
      case PM_MdiSubWindowFrameWidth:
          ret = 4;
          break;
      case PM_TitleBarHeight:
    #ifdef QT3_SUPPORT
          if (widget && widget->inherits("Q3DockWindowTitleBar")) {
              // Q3DockWindow has smaller title bars than QDockWidget
              ret = qMax(widget->fontMetrics().height(), 20);
          } else
    #endif
          ret = qMax(widget ? widget->fontMetrics().height() :
                     (opt ? opt->fontMetrics.height() : 0), 30);
          break;
      case PM_MaximumDragDistance:
          return -1;
      case PM_DockWidgetTitleMargin:
          return 2;
      case PM_LayoutHorizontalSpacing:
      case PM_LayoutVerticalSpacing:
          return -1;  // rely on layoutHorizontalSpacing()
      case PM_LayoutLeftMargin:
      case PM_LayoutTopMargin:
      case PM_LayoutRightMargin:
      case PM_LayoutBottomMargin:
          {
              bool isWindow = false;
              if (opt) {
                  isWindow = (opt->state & State_Window);
              } else if (widget) {
                  isWindow = widget->isWindow();
              }

              if (isWindow) {
                  ret = 11;
              } else {
                  ret = 9;
              }
          }
      default:
          break;
      }

      return ret != -1 ? ret : HvPublicStyle::pixelMetric(pm, opt, widget);*/
}

QRect HvStylePlastique::subElementRect ( SubElement element, const QStyleOption * option, const QWidget * widget ) const
{
    /* switch (element)
       {
       case SE_ItemViewItemText:
       {
           QRect rect = HvPublicStyle::subElementRect( SE_ItemViewItemText, option, widget );
           rect.adjust( 0, 1, 0, 1 );//poziciata na text na row
           return rect;
       }
       case SE_HeaderLabel:
       {
           QRect rect = HvPublicStyle::subElementRect(SE_HeaderLabel, option, widget );
           rect.adjust( 0, 1, 0, 1);//poziciata na text na headera
           return rect;
       }
       default:
           return HvPublicStyle::subElementRect (element, option, widget);
       }*/

    QRect rect;
    switch (element)
    {
    case SE_RadioButtonIndicator:
        rect = visualRect(option->direction, option->rect,
                          HvPublicStyle::subElementRect(element, option, widget)).adjusted(0, 0, 1, 1);
        break;

        //lz2hv implamentations
    case SE_ItemViewItemText:
        rect = HvPublicStyle::subElementRect( SE_ItemViewItemText, option, widget );
        rect.adjust( 0, 1, 0, 1 );//poziciata na text na row
        break;
    case SE_HeaderLabel:
        rect = HvPublicStyle::subElementRect(SE_HeaderLabel, option, widget );
        rect.adjust( 0, 1, 0, 1);//poziciata na text na headera
        break;
        //////////// end hv //////

#ifndef QT_NO_PROGRESSBAR
    case SE_ProgressBarLabel:
    case SE_ProgressBarContents:
    case SE_ProgressBarGroove:
        return option->rect;
#endif // QT_NO_PROGRESSBAR
    default:
        return HvPublicStyle::subElementRect(element, option, widget);
    }

    return visualRect(option->direction, option->rect, rect);
}

static const int blueFrameWidthsb   =  2;  //2.26 fontcombo box with of line edit focus frame
static const int blueFrameWidthcb =  0;  //2.26 fontcombo box with of line edit focus frame
QRect HvStylePlastique::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
                                       SubControl subControl, const QWidget *widget) const
{
    QRect rect = HvPublicStyle::subControlRect(control, option, subControl, widget);

    switch (control)
    {
#ifndef QT_NO_SLIDER
    case CC_Slider:
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);

            switch (subControl)
            {
            case SC_SliderHandle:
                if (slider->orientation == Qt::Horizontal)
                {
                    rect.setWidth(11);
                    rect.setHeight(15);
                    int centerY = slider->rect.center().y() - rect.height() / 2;
                    if (slider->tickPosition & QSlider::TicksAbove)
                        centerY += tickSize;
                    if (slider->tickPosition & QSlider::TicksBelow)
                        centerY -= tickSize;
                    rect.moveTop(centerY);
                }
                else
                {
                    rect.setWidth(15);
                    rect.setHeight(11);
                    int centerX = slider->rect.center().x() - rect.width() / 2;
                    if (slider->tickPosition & QSlider::TicksAbove)
                        centerX += tickSize;
                    if (slider->tickPosition & QSlider::TicksBelow)
                        centerX -= tickSize;
                    rect.moveLeft(centerX);
                }
                break;
            case SC_SliderGroove:
            {
                QPoint grooveCenter = slider->rect.center();
                if (slider->orientation == Qt::Horizontal)
                {
                    rect.setHeight(14);
                    --grooveCenter.ry();
                    if (slider->tickPosition & QSlider::TicksAbove)
                        grooveCenter.ry() += tickSize;
                    if (slider->tickPosition & QSlider::TicksBelow)
                        grooveCenter.ry() -= tickSize;
                }
                else
                {
                    rect.setWidth(14);
                    --grooveCenter.rx();
                    if (slider->tickPosition & QSlider::TicksAbove)
                        grooveCenter.rx() += tickSize;
                    if (slider->tickPosition & QSlider::TicksBelow)
                        grooveCenter.rx() -= tickSize;
                }
                rect.moveCenter(grooveCenter);
                break;
            }
            default:
                break;
            }
        }
        break;
#endif // QT_NO_SLIDER
#ifndef QT_NO_SCROLLBAR
    case CC_ScrollBar:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollBar, widget);
            int sliderMaxLength = ((scrollBar->orientation == Qt::Horizontal) ?
                                   scrollBar->rect.width() : scrollBar->rect.height()) - (scrollBarExtent * 3);
            int sliderMinLength = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget);
            int sliderLength;

            // calculate slider length
            if (scrollBar->maximum != scrollBar->minimum)
            {
                uint valueRange = scrollBar->maximum - scrollBar->minimum;
                sliderLength = (scrollBar->pageStep * sliderMaxLength) / (valueRange + scrollBar->pageStep);

                if (sliderLength < sliderMinLength || valueRange > INT_MAX / 2)
                    sliderLength = sliderMinLength;
                if (sliderLength > sliderMaxLength)
                    sliderLength = sliderMaxLength;
            }
            else
            {
                sliderLength = sliderMaxLength;
            }

            int sliderStart = scrollBarExtent + sliderPositionFromValue(scrollBar->minimum,
                              scrollBar->maximum,
                              scrollBar->sliderPosition,
                              sliderMaxLength - sliderLength,
                              scrollBar->upsideDown);

            QRect scrollBarRect = scrollBar->rect;

            switch (subControl)
            {
            case SC_ScrollBarSubLine: // top/left button
                if (scrollBar->orientation == Qt::Horizontal)
                {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarRect.width() - scrollBarExtent, scrollBarRect.height());
                }
                else
                {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarRect.width(), scrollBarRect.height() - scrollBarExtent);
                }
                break;
            case SC_ScrollBarAddLine: // bottom/right button
                if (scrollBar->orientation == Qt::Horizontal)
                {
                    rect.setRect(scrollBarRect.right() - (scrollBarExtent - 1), scrollBarRect.top(), scrollBarExtent, scrollBarRect.height());
                }
                else
                {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.bottom() - (scrollBarExtent - 1), scrollBarRect.width(), scrollBarExtent);
                }
                break;
            case SC_ScrollBarSubPage:
                if (scrollBar->orientation == Qt::Horizontal)
                {
                    rect.setRect(scrollBarRect.left() + scrollBarExtent, scrollBarRect.top(),
                                 sliderStart - (scrollBarRect.left() + scrollBarExtent), scrollBarRect.height());
                }
                else
                {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.top() + scrollBarExtent,
                                 scrollBarRect.width(), sliderStart - (scrollBarRect.left() + scrollBarExtent));
                }
                break;
            case SC_ScrollBarAddPage:
                if (scrollBar->orientation == Qt::Horizontal)
                    rect.setRect(sliderStart + sliderLength, 0,
                                 sliderMaxLength - sliderStart - sliderLength + scrollBarExtent, scrollBarRect.height());
                else
                    rect.setRect(0, sliderStart + sliderLength,
                                 scrollBarRect.width(), sliderMaxLength - sliderStart - sliderLength + scrollBarExtent);
                break;
            case SC_ScrollBarGroove:
                if (scrollBar->orientation == Qt::Horizontal)
                {
                    rect = scrollBarRect.adjusted(scrollBarExtent, 0, -2 * scrollBarExtent, 0);
                }
                else
                {
                    rect = scrollBarRect.adjusted(0, scrollBarExtent, 0, -2 * scrollBarExtent);
                }
                break;
            case SC_ScrollBarSlider:
                if (scrollBar->orientation == Qt::Horizontal)
                {
                    rect.setRect(sliderStart, 0, sliderLength, scrollBarRect.height());
                }
                else
                {
                    rect.setRect(0, sliderStart, scrollBarRect.width(), sliderLength);
                }
                break;
            default:
                break;
            }
            rect = visualRect(scrollBar->direction, scrollBarRect, rect);
        }
        break;
#endif // QT_NO_SCROLLBAR
#ifndef QT_NO_SPINBOX
    case CC_SpinBox:
        if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option))
        {
            int center = spinBox->rect.height() / 2;
            switch (subControl)
            {
            case SC_SpinBoxUp:
                if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
                    return QRect();
                rect = visualRect(spinBox->direction, spinBox->rect, rect);
                rect.setRect(spinBox->rect.right() - 16, spinBox->rect.top(), 17, center + 1);
                rect = visualRect(spinBox->direction, spinBox->rect, rect);
                break;
            case SC_SpinBoxDown:
                if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
                    return QRect();
                rect = visualRect(spinBox->direction, spinBox->rect, rect);
                rect.setRect(spinBox->rect.right() - 16, spinBox->rect.top() + center, 17, spinBox->rect.height() - center);
                rect = visualRect(spinBox->direction, spinBox->rect, rect);
                break;
            case SC_SpinBoxEditField:
                if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons)
                {
                    rect = spinBox->rect.adjusted(0, 0, -16, 0);
                }
                else
                {
                    rect = spinBox->rect;
                }
                rect.adjust(blueFrameWidthsb, blueFrameWidthsb, -blueFrameWidthsb, -blueFrameWidthsb);
                rect = visualRect(spinBox->direction, spinBox->rect, rect);
                break;
            default:
                break;
            }
        }
        break;
#endif // QT_NO_SPINBOX
#ifndef QT_NO_COMBOBOX
    case CC_ComboBox:
        switch (subControl)
        {
        case SC_ComboBoxArrow:
            rect = visualRect(option->direction, option->rect, rect);
            rect.setRect(rect.right() - 17, rect.top() - 2,
                         19, rect.height() + 4);
            rect = visualRect(option->direction, option->rect, rect);
            break;
        case SC_ComboBoxEditField:
        {
            if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option))
            {
                int frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth);
                rect = visualRect(option->direction, option->rect, rect);

                if (box->editable)
                {
                    rect = box->rect.adjusted(blueFrameWidthcb, blueFrameWidthcb, -blueFrameWidthcb, -blueFrameWidthcb);
                    rect.setRight(rect.right() - 16); // Overlaps the combobox button by 2 pixels
                }
                else
                {
                    rect.setRect(option->rect.left() + frameWidth, option->rect.top() + frameWidth,
                                 option->rect.width() - 16 - 2 * frameWidth,
                                 option->rect.height() - 2 * frameWidth);
                    rect.setLeft(rect.left() + 2);
                    rect.setRight(rect.right() - 2);
                    if (box->state & (State_Sunken | State_On))
                        rect.translate(1, 1);
                }
                rect = visualRect(option->direction, option->rect, rect);
            }
            break;
        }
        default:
            break;
        }
        break;
#endif // QT_NO_COMBOBOX
    case CC_TitleBar:
        if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option))
        {
            SubControl sc = subControl;
            QRect &ret = rect;
            const int indent = 3;
            const int controlTopMargin = 4;
            const int controlBottomMargin = 3;
            const int controlWidthMargin = 1;
            const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin;
            const int delta = controlHeight + controlWidthMargin;
            int offset = 0;

            bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
            bool isMaximized = tb->titleBarState & Qt::WindowMaximized;

            switch (sc)
            {
            case SC_TitleBarLabel:
                if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint))
                {
                    ret = tb->rect;
                    if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
                        ret.adjust(delta, 0, -delta, 0);
                    if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
                        ret.adjust(0, 0, -delta, 0);
                    if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
                        ret.adjust(0, 0, -delta, 0);
                    if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
                        ret.adjust(0, 0, -delta, 0);
                    if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
                        ret.adjust(0, 0, -delta, 0);
                    ret = ret.adjusted(indent, 0, -indent, 0);// 2.26
                }
                break;
            case SC_TitleBarContextHelpButton:
                if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
                    offset += delta;
                //else
                //{}
                break;
            case SC_TitleBarMinButton:
                if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
                    offset += delta;
                else if (sc == SC_TitleBarMinButton)
                {}
                break;
            case SC_TitleBarNormalButton:
                if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
                    offset += delta;
                else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
                    offset += delta;
                else if (sc == SC_TitleBarNormalButton)
                {}
                break;
            case SC_TitleBarMaxButton:
                if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
                    offset += delta;
                else if (sc == SC_TitleBarMaxButton)
                {}
                break;
            case SC_TitleBarShadeButton:
                if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
                    offset += delta;
                else if (sc == SC_TitleBarShadeButton)
                {}
                break;
            case SC_TitleBarUnshadeButton:
                if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
                    offset += delta;
                else if (sc == SC_TitleBarUnshadeButton)
                {}
                break;
            case SC_TitleBarCloseButton:
                if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
                    offset += delta;
                else if (sc == SC_TitleBarCloseButton)
                    break;
                ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
                            controlHeight, controlHeight);
                break;
            case SC_TitleBarSysMenu:
                if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
                {
                    ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
                                controlHeight, controlHeight);
                }
                break;
            default:
                break;
            }
            ret = visualRect(tb->direction, tb->rect, ret);
        }
        break;
    default:
        break;
    }

    return rect;
}

QSize HvStylePlastique::sizeFromContents(ContentsType type, const QStyleOption * option, const QSize & size, const QWidget * widget ) const
{
    QSize newSize = HvPublicStyle::sizeFromContents(type, option, size, widget);
    int windowsItemHMargin=3;
    int windowsItemVMargin=2;

    switch (type)
    {
    case CT_ItemViewItem://hv
        newSize = HvPublicStyle::sizeFromContents( CT_ItemViewItem, option, size, widget  );
        //size.setHeight(size.height()+1) ;//na gore marda goleminata na row se edno margin QTreeView
        newSize.setWidth(size.width()+4);//otpred marda goleminata na row se edno margin QTreeView
        break;
    case CT_RadioButton:
        ++newSize.rheight();
        ++newSize.rwidth();
        break;
#ifndef QT_NO_SLIDER
    case CT_Slider:
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
            if (slider->tickPosition & QSlider::TicksBelow)
            {
                if (slider->orientation == Qt::Horizontal)
                    newSize.rheight() += tickSize;
                else
                    newSize.rwidth() += tickSize;
            }
            if (slider->tickPosition & QSlider::TicksAbove)
            {
                if (slider->orientation == Qt::Horizontal)
                    newSize.rheight() += tickSize;
                else
                    newSize.rwidth() += tickSize;
            }
        }
        break;
#endif // QT_NO_SLIDER
#ifndef QT_NO_SCROLLBAR
    case CT_ScrollBar:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
            int scrollBarSliderMinimum = proxy()->pixelMetric(PM_ScrollBarSliderMin, option, widget);
            if (scrollBar->orientation == Qt::Horizontal)
            {
                newSize = QSize(scrollBarExtent * 3 + scrollBarSliderMinimum, scrollBarExtent);
            }
            else
            {
                newSize = QSize(scrollBarExtent, scrollBarExtent * 3 + scrollBarSliderMinimum);
            }
        }
        break;
#endif // QT_NO_SCROLLBAR
#ifndef QT_NO_SPINBOX
    case CT_SpinBox:
        // Make sure the size is odd
        newSize.setHeight(sizeFromContents(CT_LineEdit, option, size, widget).height());
        //newSize.rheight() -= ((1 - newSize.rheight()) & 1);
        newSize += QSize(2,4);
        break;
#endif
#ifndef QT_NO_TOOLBUTTON
    case CT_ToolButton:
        newSize.rheight() += 3;
        newSize.rwidth() += 3;
        break;
#endif
#ifndef QT_NO_COMBOBOX
    case CT_ComboBox:
        newSize = sizeFromContents(CT_PushButton, option, size, widget);
        newSize.rwidth() += 30; //HV importent -> Make room for drop-down indicator
        newSize.rheight() += 4;
        break;
#endif
//#ifndef QT_NO_MENU
    case CT_MenuItem:
        if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
        {
            if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
                newSize.setHeight(menuItem->text.isEmpty() ? 2 : menuItem->fontMetrics.height());
            //2.69 for Context Menu Items
            int w = size.width();
            /*if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
            {
                newSize = QSize(10,9);
            }
            else if (menuItem->icon.isNull())
            {
                newSize.setHeight(newSize.height() - 2);
                w -= 6;
            }
            if (menuItem->menuItemType != QStyleOptionMenuItem::Separator && !menuItem->icon.isNull())
            {
                int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
                newSize.setHeight(qMax(newSize.height(),
                                       menuItem->icon.actualSize(QSize(iconExtent, iconExtent)).height()
                                       + 2 * 2));
            }*/
            int tabSpacing = 20;
            if (menuItem->text.contains(QLatin1Char('\t'))) w += tabSpacing;
            else if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) w += 2 * 2;
            else if (menuItem->menuItemType == QStyleOptionMenuItem::DefaultItem)
            {
                // adjust the font and add the difference in size.
                // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
                QFontMetrics fm(menuItem->font);
                QFont fontBold = menuItem->font;
                fontBold.setBold(true);
                QFontMetrics fmBold(fontBold);                
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) //w += fmBold.width(menuItem->text) - fm.width(menuItem->text);
                w += fmBold.horizontalAdvance(menuItem->text) - fm.horizontalAdvance(menuItem->text);
#else
                w += fmBold.width(menuItem->text) - fm.width(menuItem->text);
#endif
            }
            int maxpmw = menuItem->maxIconWidth;
            int checkcol = qMax<int>(maxpmw,12); // Windows always shows a check column
            w += checkcol;
            w += 10 + 10;
            newSize.setWidth(w);
            //end 2.69 for Context Menu Items
        }
        break;
//#endif // QT_NO_MENU
//#ifndef QT_NO_MENUBAR
    case CT_MenuBarItem:
        //newSize.setHeight(newSize.height());
        if (!newSize.isEmpty())
            newSize += QSize(windowsItemHMargin * 4, windowsItemVMargin * 2);
        break;
//#endif
    case CT_PushButton:
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option))
        {
            if (!btn->text.isEmpty() && newSize.width() < 60)//2.33 min width buttons old=80
                newSize.setWidth(60);
            if (!btn->icon.isNull() && btn->iconSize.height() > 16)
                newSize -= QSize(0, 2);
        }
        break;
    default:
        break;
    }

    return newSize;

    /* QSize sz(size);
    switch (type) {
    case CT_PushButton:
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
            sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
            int w = sz.width(),
                h = sz.height();
            int defwidth = 0;
            if (btn->features & QStyleOptionButton::AutoDefaultButton)
                defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
            int minwidth = int(QStyleHelper::dpiScaled(75.));
            int minheight = int(QStyleHelper::dpiScaled(23.));

    #ifndef QT_QWS_SMALL_PUSHBUTTON
            if (w < minwidth + defwidth && !btn->text.isEmpty())
                w = minwidth + defwidth;
            if (h < minheight + defwidth)
                h = minheight + defwidth;
    #endif
            sz = QSize(w, h);
        }
        break;
    #ifndef QT_NO_MENU
    case CT_MenuItem:
        if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
            int w = sz.width();
            sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);

            if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
                sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
            }
            else if (mi->icon.isNull()) {
                sz.setHeight(sz.height() - 2);
                w -= 6;
            }

            if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
                int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
                sz.setHeight(qMax(sz.height(),
                                  mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
                                  + 2 * QWindowsStylePrivate::windowsItemFrame));
            }
            int maxpmw = mi->maxIconWidth;
            int tabSpacing = 20;
            if (mi->text.contains(QLatin1Char('\t')))
                w += tabSpacing;
            else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
                w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
            else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
                // adjust the font and add the difference in size.
                // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
                QFontMetrics fm(mi->font);
                QFont fontBold = mi->font;
                fontBold.setBold(true);
                QFontMetrics fmBold(fontBold);
                w += fmBold.width(mi->text) - fm.width(mi->text);
            }

            int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
            w += checkcol;
            w += int(QWindowsStylePrivate::windowsRightBorder) + 10;
            sz.setWidth(w);
        }
        break;
    #endif // QT_NO_MENU
    #ifndef QT_NO_MENUBAR
    case CT_MenuBarItem:
        if (!sz.isEmpty())
            sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
        break;
    #endif
                // Otherwise, fall through
    case CT_ToolButton:
        if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
            return sz += QSize(7, 6);
        // Otherwise, fall through

    default:
        sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
    }
    return sz;*/
}

static QLinearGradient qMapGradientToRect(const QLinearGradient &gradient, const QRectF &rect)
{
    QLinearGradient tmpGrad(rect.center().x(), rect.top(),
                            rect.center().x(), rect.bottom());
    tmpGrad.setStops(gradient.stops());
    return tmpGrad;
}

static QBrush qMapBrushToRect(const QBrush &brush, const QRectF &rect)
{
    if (!brush.gradient())
        return brush;

    // ### Ugly assumption that it's a linear gradient
    QBrush tmp(qMapGradientToRect(*static_cast<const QLinearGradient *>(brush.gradient()), rect));
    return tmp;
}

static void qBrushSetAlphaF(QBrush *brush, qreal alpha)
{
    if (const QGradient *gradient = brush->gradient())
    {
        // Use the gradient. Call QColor::setAlphaF() on all color stops.
        QGradientStops stops = gradient->stops();
        QMutableVectorIterator<QGradientStop> it(stops);
        QColor tmpColor;
        while (it.hasNext())
        {
            it.next();
            tmpColor = it.value().second;
            tmpColor.setAlphaF(alpha * tmpColor.alphaF());
            it.setValue(QPair<qreal, QColor>(it.value().first, tmpColor));
        }

        switch (gradient->type())
        {
        case QGradient::RadialGradient:
            {
                QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
                grad.setStops(stops);
                *brush = QBrush(grad);
                break;
            }
        case QGradient::ConicalGradient:
            {
                QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
                grad.setStops(stops);
                *brush = QBrush(grad);
                break;
            }
        default:
            /*qWarning("QPlastiqueStyle::qBrushLight() - unknown gradient type"
                     " - falling back to QLinearGradient");*/
        case QGradient::LinearGradient:
            {
                QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
                grad.setStops(stops);
                *brush = QBrush(grad);
                break;
            }
        }
    }
    else if (!brush->texture().isNull())
    {
        // Modify the texture - ridiculously expensive.
        QPixmap texture = brush->texture();
        QPixmap pixmap;
        QString name = QLatin1Literal("qbrushtexture-alpha")
                       % HexString<qreal>(alpha)
                       % HexString<qint64>(texture.cacheKey());
        if (!QPixmapCache::find(name, &pixmap))
        {
            QImage image = texture.toImage();
            QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
            int pixels = image.width() * image.height();
            QColor tmpColor;
            while (pixels--)
            {
                tmpColor.setRgb(*rgb);
                tmpColor.setAlphaF(alpha * tmpColor.alphaF());
                *rgb++ = tmpColor.rgba();
            }
            pixmap = QPixmap::fromImage(image);
            QPixmapCache::insert(name, pixmap);
        }
        brush->setTexture(pixmap);
    }
    else
    {
        // Use the color
        QColor tmpColor = brush->color();
        tmpColor.setAlphaF(alpha * tmpColor.alphaF());
        brush->setColor(tmpColor);
    }
}
static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart,
                                       const QColor &gradientStop)
{
    QString gradientName = QLatin1Literal("qplastique-g")
                           % HexString<int>(rect.width())
                           % HexString<int>(rect.height())
                           % HexString<QRgb>(gradientStart.rgba())
                           % HexString<QRgb>(gradientStop.rgba());

    QPixmap cache;
    QPainter *p = painter;
    QRect r = rect;

    //bool doPixmapCache = painter->deviceTransform().isIdentity() && painter->worldMatrix().isIdentity();
    bool doPixmapCache = painter->deviceTransform().isIdentity() && painter->worldTransform().isIdentity();//2.56

    if (doPixmapCache && QPixmapCache::find(gradientName, &cache))
    {
        painter->drawPixmap(rect, cache);
    }
    else
    {
        if (doPixmapCache)
        {
            cache = QPixmap(rect.size());
            cache.fill(Qt::transparent);
            p = new QPainter(&cache);
            r = QRect(0, 0, rect.width(), rect.height());
        }

        int x = r.center().x();
        QLinearGradient gradient(x, r.top(), x, r.bottom());
        gradient.setColorAt(0, gradientStart);
        gradient.setColorAt(1, gradientStop);
        p->fillRect(r, gradient);

        if (doPixmapCache)
        {
            p->end();
            delete p;
            painter->drawPixmap(rect, cache);
            QPixmapCache::insert(gradientName, cache);
        }
    }
}

static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
{
    const int maxFactor = 100;
    QColor tmp = colorA;
    tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
    tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
    tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
    return tmp;
}
static void qt_plastique_drawFrame(QPainter *painter, const QStyleOption *option, const QWidget *widget)
{
    QRect rect = option->rect;
    QPen oldPen = painter->pen();

    QColor borderColor = option->palette.window().color().darker(178);
    QColor gradientStartColor = option->palette.button().color().lighter(104);
    QColor gradientStopColor = option->palette.button().color().darker(105);
    QColor alphaCornerColor;
    if (widget)
    {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    }
    else
    {
        alphaCornerColor = mergedColors(option->palette.window().color(), borderColor);
    }

    QLine lines[4];
    QPoint points[8];

    // outline / border
    painter->setPen(borderColor);
    lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
    lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
    lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
    lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
    painter->drawLines(lines, 4);

    points[0] = QPoint(rect.left() + 1, rect.top() + 1);
    points[1] = QPoint(rect.right() - 1, rect.top() + 1);
    points[2] = QPoint(rect.left() + 1, rect.bottom() - 1);
    points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
    painter->drawPoints(points, 4);

    painter->setPen(alphaCornerColor);

    points[0] = QPoint(rect.left() + 1, rect.top());
    points[1] = QPoint(rect.right() - 1, rect.top());
    points[2] = QPoint(rect.left() + 1, rect.bottom());
    points[3] = QPoint(rect.right() - 1, rect.bottom());
    points[4] = QPoint(rect.left(), rect.top() + 1);
    points[5] = QPoint(rect.right(), rect.top() + 1);
    points[6] = QPoint(rect.left(), rect.bottom() - 1);
    points[7] = QPoint(rect.right(), rect.bottom() - 1);
    painter->drawPoints(points, 8);

    // inner border
    if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
        painter->setPen(option->palette.button().color().darker(118));
    else
        painter->setPen(gradientStartColor);

    lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, option->rect.top() + 1);
    lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, option->rect.bottom() - 2);
    painter->drawLines(lines, 2);

    if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
        painter->setPen(option->palette.button().color().darker(110));
    else
        painter->setPen(gradientStopColor.darker(102));

    lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1);
    lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
    painter->drawLines(lines, 2);

    painter->setPen(oldPen);
}
static void qt_plastique_drawShadedPanel(QPainter *painter, const QStyleOption *option, bool base,
        const QWidget *widget)
{
    QRect rect = option->rect;
    QPen oldPen = painter->pen();

    QColor gradientStartColor = option->palette.button().color().lighter(104);
    QColor gradientStopColor = option->palette.button().color().darker(105);

    // gradient fill
    if ((option->state & QStyle::State_Enabled) || !(option->state & QStyle::State_AutoRaise))
    {
        if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
        {
            qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1),
                                       option->palette.button().color().darker(114),
                                       option->palette.button().color().darker(106));
        }
        else
        {
            qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1),
                                       base ? option->palette.window().color().lighter(105) : gradientStartColor,
                                       base ? option->palette.window().color().darker(102) : gradientStopColor);
        }
    }

    qt_plastique_drawFrame(painter, option, widget);

    painter->setPen(oldPen);
}
static QBrush qBrushDark(QBrush brush, int dark)
{
    if (const QGradient *gradient = brush.gradient())
    {
        // Use the gradient. Call QColor::darker() on all color stops.
        QGradientStops stops = gradient->stops();
        QMutableVectorIterator<QGradientStop> it(stops);
        while (it.hasNext())
        {
            it.next();
            it.setValue(QPair<qreal, QColor>(it.value().first, it.value().second.darker(dark)));
        }

        switch (gradient->type())
        {
        case QGradient::RadialGradient:
            {
                QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
                grad.setStops(stops);
                brush = QBrush(grad);
                break;
            }
        case QGradient::ConicalGradient:
            {
                QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
                grad.setStops(stops);
                brush = QBrush(grad);
                break;
            }
        default:
            /*qWarning("QPlastiqueStyle::qBrushDark() - unknown gradient type"
                     " - falling back to QLinearGradient");*/
        case QGradient::LinearGradient:
            {
                QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
                grad.setStops(stops);
                brush = QBrush(grad);
                break;
            }
        }
    }
    else if (!brush.texture().isNull())
    {
        // Modify the texture - ridiculously expensive.
        QPixmap texture = brush.texture();
        QPixmap pixmap;
        QString name = QLatin1Literal("qbrushtexture-dark")
                       % HexString<int>(dark)
                       % HexString<qint64>(texture.cacheKey());

        if (!QPixmapCache::find(name, &pixmap))
        {
            QImage image = texture.toImage();
            QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
            int pixels = image.width() * image.height();
            QColor tmpColor;
            while (pixels--)
            {
                tmpColor.setRgb(*rgb);
                *rgb++ = tmpColor.darker(dark).rgba();
            }
            pixmap = QPixmap::fromImage(image);
            QPixmapCache::insert(name, pixmap);
        }
        brush.setTexture(pixmap);
    }
    else
    {
        // Use the color
        brush.setColor(brush.color().darker(dark));
    }
    return brush;
}
static void qt_plastique_draw_frame(QPainter *painter, const QRect &rect, const QStyleOption *option,
                                    QFrame::Shadow shadow = QFrame::Plain)
{
    QPen oldPen = painter->pen();
    QBrush border;
    QBrush corner;
    QBrush innerTopLeft;
    QBrush innerBottomRight;

    if (shadow != QFrame::Plain && (option->state & QStyle::State_HasFocus))
    {
        border = option->palette.highlight();
        qBrushSetAlphaF(&border, qreal(0.8));
        corner = option->palette.highlight();
        qBrushSetAlphaF(&corner, 0.5);
        innerTopLeft = qBrushDark(option->palette.highlight(), 125);
        innerBottomRight = option->palette.highlight();
        qBrushSetAlphaF(&innerBottomRight, qreal(0.65));
    }
    else
    {
        border = option->palette.shadow();
        qBrushSetAlphaF(&border, qreal(0.4));
        corner = option->palette.shadow();
        qBrushSetAlphaF(&corner, 0.25);
        innerTopLeft = option->palette.shadow();
        innerBottomRight = option->palette.shadow();
        if (shadow == QFrame::Sunken)
        {
            qBrushSetAlphaF(&innerTopLeft, qreal(0.23));
            qBrushSetAlphaF(&innerBottomRight, qreal(0.075));
        }
        else
        {
            qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
            qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
        }
    }

    QLine lines[4];
    QPoint points[8];

    // Opaque corner lines
    painter->setPen(QPen(border, 0));
    lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
    lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
    lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
    lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
    painter->drawLines(lines, 4);

    // Opaque corner dots
    points[0] = QPoint(rect.left() + 1, rect.top() + 1);
    points[1] = QPoint(rect.left() + 1, rect.bottom() - 1);
    points[2] = QPoint(rect.right() - 1, rect.top() + 1);
    points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
    painter->drawPoints(points, 4);

    // Shaded corner dots
    painter->setPen(QPen(corner, 0));
    points[0] = QPoint(rect.left(), rect.top() + 1);
    points[1] = QPoint(rect.left(), rect.bottom() - 1);
    points[2] = QPoint(rect.left() + 1, rect.top());
    points[3] = QPoint(rect.left() + 1, rect.bottom());
    points[4] = QPoint(rect.right(), rect.top() + 1);
    points[5] = QPoint(rect.right(), rect.bottom() - 1);
    points[6] = QPoint(rect.right() - 1, rect.top());
    points[7] = QPoint(rect.right() - 1, rect.bottom());
    painter->drawPoints(points, 8);

    // Shadows
    if (shadow != QFrame::Plain)
    {
        painter->setPen(QPen(innerTopLeft, 0));
        lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1);
        lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
        painter->drawLines(lines, 2);
        painter->setPen(QPen(innerBottomRight, 0));
        lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1);
        lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
        painter->drawLines(lines, 2);
    }

    painter->setPen(oldPen);
}

static QBrush qBrushLight(QBrush brush, int light)
{
    if (const QGradient *gradient = brush.gradient())
    {
        // Use the gradient. Call QColor::lighter() on all color stops.
        QGradientStops stops = gradient->stops();
        QMutableVectorIterator<QGradientStop> it(stops);
        while (it.hasNext())
        {
            it.next();
            it.setValue(QPair<qreal, QColor>(it.value().first, it.value().second.lighter(light)));
        }

        switch (gradient->type())
        {
        case QGradient::RadialGradient:
            {
                QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
                grad.setStops(stops);
                brush = QBrush(grad);
                break;
            }
        case QGradient::ConicalGradient:
            {
                QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
                grad.setStops(stops);
                brush = QBrush(grad);
                break;
            }
        default:
            /*qWarning("QPlastiqueStyle::qBrushLight() - unknown gradient type"
                     " - falling back to QLinearGradient");*/
        case QGradient::LinearGradient:
            {
                QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
                grad.setStops(stops);
                brush = QBrush(grad);
                break;
            }
        }
    }
    else if (!brush.texture().isNull())
    {
        // Modify the texture - ridiculously expensive.
        QPixmap texture = brush.texture();
        QPixmap pixmap;
        QString name = QLatin1Literal("qbrushtexture-light")
                       % HexString<int>(light)
                       % HexString<qint64>(texture.cacheKey());

        if (!QPixmapCache::find(name, &pixmap))
        {
            QImage image = texture.toImage();
            QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
            int pixels = image.width() * image.height();
            QColor tmpColor;
            while (pixels--)
            {
                tmpColor.setRgb(*rgb);
                *rgb++ = tmpColor.lighter(light).rgba();
            }
            pixmap = QPixmap::fromImage(image);
            QPixmapCache::insert(name, pixmap);
        }
        brush.setTexture(pixmap);
    }
    else
    {
        // Use the color
        brush.setColor(brush.color().lighter(light));
    }
    return brush;
}
#if !defined(QT_NO_DOCKWIDGET) || !defined(QT_NO_SPLITTER)
static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option,
                                     const QRect &rect, Qt::Orientation orientation,
                                     const QWidget *widget)
{
    QColor borderColor = option->palette.window().color().darker(178);
    QColor alphaCornerColor;
    if (widget)
    {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    }
    else
    {
        alphaCornerColor = mergedColors(option->palette.window().color(), borderColor);
    }
    QImage handle(qt_simple_toolbarhandle);
    alphaCornerColor.setAlpha(170);
    handle.setColor(1, alphaCornerColor.rgba());
    handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
    handle.setColor(3, option->palette.light().color().rgba());

    const int spacing = 2;

    if (orientation == Qt::Vertical)
    {
        int nchunks = rect.width() / (handle.width() + spacing);
        for (int i = 0; i < nchunks; ++i)
            painter->drawImage(QPoint(rect.left() + i * (handle.width() + spacing), rect.top()), handle);
    }
    else
    {
        int nchunks = rect.height() / (handle.height() + spacing);
        for (int i = 0; i < nchunks; ++i)
            painter->drawImage(QPoint(rect.left(), rect.top() + i * (handle.height() + spacing)), handle);
    }
}
#endif

static void qt_plastique_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
{
    if (tmp.isNull())
        return;
    bool active = (option->titleBarState & QStyle::State_Active);

    // ### use palette colors instead
    QColor mdiButtonGradientStartColor;
    QColor mdiButtonGradientStopColor;
    if (active)
    {
        mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x7d8bb1 : 0x55689a);
        mdiButtonGradientStopColor = QColor((hover || sunken) ? 0x939ebe : 0x7381ab);
    }
    else
    {
        mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x9e9e9e : 0x818181);
        mdiButtonGradientStopColor = QColor((hover || sunken) ? 0xababab : 0x929292);
    }

    qt_plastique_draw_gradient(painter, tmp.adjusted(1, 1, -1, -1),
                               mdiButtonGradientStartColor, mdiButtonGradientStopColor);

    QColor mdiButtonBorderColor;
    if (active)
    {
        mdiButtonBorderColor = (hover || sunken) ? QColor(0x627097) : QColor(0x324577);
    }
    else
    {
        mdiButtonBorderColor = (hover || sunken) ? QColor(0x838383) : QColor(0x5e5e5e);
    }
    painter->setPen(QPen(mdiButtonBorderColor, 1));

    const QLine lines[4] =
        {
            QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
            QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
            QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
            QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2)
        };
    painter->drawLines(lines, 4);

    const QPoint points[4] =
        {
            QPoint(tmp.left() + 1, tmp.top() + 1),
            QPoint(tmp.right() - 1, tmp.top() + 1),
            QPoint(tmp.left() + 1, tmp.bottom() - 1),
            QPoint(tmp.right() - 1, tmp.bottom() - 1)
        };
    painter->drawPoints(points, 4);
}
#ifndef QT_NO_DOCKWIDGET
static QString elliditide(const QString &text, const QFontMetrics &fontMetrics, const QRect &rect, int *textWidth = 0)
{
    // Chop and insert ellide into title if text is too wide
    QString title = text;
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)//2.56
    int width = textWidth ? *textWidth : fontMetrics.horizontalAdvance(text);
#else
    int width = textWidth ? *textWidth : fontMetrics.width(text);
#endif
    QString ellipsis = QLatin1String("...");
    if (width > rect.width())
    {
        QString leftHalf = title.left(title.size() / 2);
        QString rightHalf = title.mid(leftHalf.size() + 1);
        while (!leftHalf.isEmpty() && !rightHalf.isEmpty())
        {
            leftHalf.chop(1);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)//2.56
            int width = fontMetrics.horizontalAdvance(leftHalf + ellipsis + rightHalf);
#else
            int width = fontMetrics.width(leftHalf + ellipsis + rightHalf);
#endif
            if (width < rect.width())
            {
                title = leftHalf + ellipsis + rightHalf;
                width = width;
                break;
            }
            rightHalf.remove(0, 1);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)//2.56
            width = fontMetrics.horizontalAdvance(leftHalf + ellipsis + rightHalf);
#else
            width = fontMetrics.width(leftHalf + ellipsis + rightHalf);
#endif
            if (width < rect.width())
            {
                title = leftHalf + ellipsis + rightHalf;
                width = width;
                break;
            }
        }
    }
    if (textWidth)
        *textWidth = width;
    return title;
}
#endif

void HvStylePlastique::drawControl(ControlElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const
{

    //painter->setFont(QApplication::font());//lz2hv

    QColor borderColor = option->palette.window().color().darker(178);
    QColor alphaCornerColor;
    if (widget)
    {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    }
    else
    {
        alphaCornerColor = mergedColors(option->palette.window().color(), borderColor);
    }

    QColor gradientStartColor = option->palette.button().color().lighter(104);
    QColor gradientStopColor = option->palette.button().color().darker(105);

    QColor highlightedGradientStartColor = option->palette.button().color().lighter(101);
    QColor highlightedGradientStopColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 85);

    QColor lightShadowGradientStartColor = highlightedGradientStartColor.lighter(105);
    QColor lightShadowGradientStopColor = highlightedGradientStopColor.lighter(105);

    QColor highlightedDarkInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 35);
    QColor highlightedLightInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 58);

    QColor alphaInnerColor = mergedColors(highlightedDarkInnerBorderColor, option->palette.base().color());

    switch (element)
    {
#ifndef QT_NO_TABBAR
    case CE_TabBarTabShape:
        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option))
        {

            if (tab->shape != QTabBar::RoundedNorth && tab->shape != QTabBar::RoundedWest &&
                    tab->shape != QTabBar::RoundedSouth && tab->shape != QTabBar::RoundedEast)
            {
                HvPublicStyle::drawControl(element, option, painter, widget);
                break;
            }

            painter->save();

            // Set up some convenience variables
            bool disabled = !(tab->state & State_Enabled);
            bool onlyTab = tab->position == QStyleOptionTab::OnlyOneTab;
            bool selected = tab->state & State_Selected;
            bool mouseOver = (tab->state & State_MouseOver) && !selected && !disabled;
            bool previousSelected = tab->selectedPosition == QStyleOptionTab::PreviousIsSelected;
            bool nextSelected = tab->selectedPosition == QStyleOptionTab::NextIsSelected;
            bool leftCornerWidget = (tab->cornerWidgets & QStyleOptionTab::LeftCornerWidget);
            bool reverse = (tab->direction == Qt::RightToLeft);

            int lowerTop = selected ? 0 : 3; // to make the selected tab bigger than the rest
            bool atEnd = (tab->position == QStyleOptionTab::End) || onlyTab;
            bool atBeginning = ((tab->position == QStyleOptionTab::Beginning) || onlyTab)
                               && !leftCornerWidget;
            bool reverseShadow = false;

            int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
            int marginLeft = 0;
            if ((atBeginning && !selected) || (selected && leftCornerWidget && ((tab->position == QStyleOptionTab::Beginning) || onlyTab)))
            {
                marginLeft = 1;
            }

            // I've set the names based on the natural coordinate system. Vectors are used to rotate everything
            // if the orientation of the tab bare is different than north.
            {
                // Coordinates of corners of rectangle for transformation
                QPoint topLeft;
                QPoint topRight;
                QPoint bottomLeft;
                QPoint bottomRight;

                // Fill with normalized vectors in the direction of the coordinate system
                // (down and right should be complement of up and left, or it will look odd)
                QPoint vectorUp;
                QPoint vectorDown;
                QPoint vectorLeft;
                QPoint vectorRight;

                QBrush border = option->palette.shadow();
                qBrushSetAlphaF(&border, qreal(0.4));
                QBrush innerTopLeft = option->palette.shadow();
                qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
                QBrush innerBottomRight = option->palette.shadow();
                qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
                QBrush corner = option->palette.shadow();
                qBrushSetAlphaF(&corner, qreal(0.25));

                QBrush baseColor1;
                QBrush baseColor2;

                switch (tab->shape)
                {
                case QTabBar::RoundedNorth:
                    vectorUp = QPoint(0, -1);
                    vectorDown = QPoint(0, 1);

                    if (reverse)
                    {
                        vectorLeft = QPoint(1, 0);
                        vectorRight = QPoint(-1, 0);
                        reverseShadow = true;
                    }
                    else
                    {
                        vectorLeft = QPoint(-1, 0);
                        vectorRight = QPoint(1, 0);
                    }

                    if (reverse)
                    {
                        topLeft = tab->rect.topRight();
                        topRight = tab->rect.topLeft();
                        bottomLeft = tab->rect.bottomRight();
                        bottomRight = tab->rect.bottomLeft();
                    }
                    else
                    {
                        topLeft = tab->rect.topLeft();
                        topRight = tab->rect.topRight();
                        bottomLeft = tab->rect.bottomLeft();
                        bottomRight = tab->rect.bottomRight();
                    }


                    baseColor1 = border;
                    baseColor2 = innerTopLeft;
                    break ;
                case QTabBar::RoundedWest:
                    vectorUp = QPoint(-1, 0);
                    vectorDown = QPoint(1, 0);
                    vectorLeft = QPoint(0, -1);
                    vectorRight = QPoint(0, 1);

                    topLeft = tab->rect.topLeft();
                    topRight = tab->rect.bottomLeft();
                    bottomLeft = tab->rect.topRight();
                    bottomRight = tab->rect.bottomRight();

                    baseColor1 = border;
                    baseColor2 = innerTopLeft;
                    break ;
                case QTabBar::RoundedEast:
                    vectorUp = QPoint(1, 0);
                    vectorDown = QPoint(-1, 0);
                    vectorLeft = QPoint(0, -1);
                    vectorRight = QPoint(0, 1);

                    topLeft = tab->rect.topRight();
                    topRight = tab->rect.bottomRight();
                    bottomLeft = tab->rect.topLeft();
                    bottomRight = tab->rect.bottomLeft();

                    baseColor1 = border;
                    baseColor2 = innerBottomRight;
                    break ;
                case QTabBar::RoundedSouth:
                    vectorUp = QPoint(0, 1);
                    vectorDown = QPoint(0, -1);

                    if (reverse)
                    {
                        vectorLeft = QPoint(1, 0);
                        vectorRight = QPoint(-1, 0);
                        reverseShadow = true;

                        topLeft = tab->rect.bottomRight();
                        topRight = tab->rect.bottomLeft();
                        bottomLeft = tab->rect.topRight();
                        bottomRight = tab->rect.topLeft();
                    }
                    else
                    {
                        vectorLeft = QPoint(-1, 0);
                        vectorRight = QPoint(1, 0);

                        topLeft = tab->rect.bottomLeft();
                        topRight = tab->rect.bottomRight();
                        bottomLeft = tab->rect.topLeft();
                        bottomRight = tab->rect.topRight();
                    }

                    baseColor1 = border;
                    baseColor2 = innerBottomRight;
                    break ;
                default:
                    break;
                }

                // Make the tab smaller when it's at the end, so that we are able to draw the corner
                if (atEnd)
                {
                    topRight += vectorLeft;
                    bottomRight += vectorLeft;
                }

                {
                    // Outer border
                    QLine topLine;
                    {
                        QPoint adjustTopLineLeft = (vectorRight * (marginLeft + (previousSelected ? 0 : 1))) +
                                                   (vectorDown * lowerTop);
                        QPoint adjustTopLineRight = (vectorDown * lowerTop);
                        if (atBeginning || selected)
                            adjustTopLineLeft += vectorRight;
                        if (atEnd || selected)
                            adjustTopLineRight += 2 * vectorLeft;

                        topLine = QLine(topLeft + adjustTopLineLeft, topRight + adjustTopLineRight);
                    }

                    QLine leftLine;
                    {
                        QPoint adjustLeftLineTop = (vectorRight * marginLeft) + (vectorDown * (lowerTop + 1));
                        QPoint adjustLeftLineBottom = (vectorRight * marginLeft) + (vectorUp * borderThickness);
                        if (atBeginning || selected)
                            adjustLeftLineTop += vectorDown; // Make place for rounded corner
                        if (atBeginning && selected)
                            adjustLeftLineBottom += borderThickness * vectorDown;
                        else if (selected)
                            adjustLeftLineBottom += vectorUp;

                        leftLine = QLine(topLeft + adjustLeftLineTop, bottomLeft + adjustLeftLineBottom);
                    }

                    QLine rightLine;
                    {
                        QPoint adjustRightLineTop = vectorDown * (2 + lowerTop);
                        QPoint adjustRightLineBottom = vectorUp * borderThickness;
                        if (selected)
                            adjustRightLineBottom += vectorUp;

                        rightLine = QLine(topRight + adjustRightLineTop, bottomRight + adjustRightLineBottom);
                    }

                    // Background
                    QPoint startPoint = topLine.p1() + vectorDown + vectorLeft;
                    if (mouseOver)
                        startPoint += vectorDown;
                    QPoint endPoint = rightLine.p2();

                    if (tab->state & State_Enabled)
                    {
                        QRect fillRect = QRect(startPoint, endPoint).normalized();
                        if (fillRect.isValid())
                        {
                            if (selected)
                            {
                                fillRect = QRect(startPoint, endPoint + vectorLeft + vectorDown * 3).normalized();
                                painter->fillRect(fillRect, option->palette.window());

                                // Connect to the base
                                painter->setPen(QPen(option->palette.window(), 0));
                                QVarLengthArray<QPoint, 6> points;
                                points.append(rightLine.p2() + vectorDown);
                                points.append(rightLine.p2() + vectorDown + vectorDown);
                                points.append(rightLine.p2() + vectorDown + vectorDown + vectorRight);
                                if (tab->position != QStyleOptionTab::Beginning)
                                {
                                    points.append(leftLine.p2() + vectorDown);
                                    points.append(leftLine.p2() + vectorDown + vectorDown);
                                    points.append(leftLine.p2() + vectorDown + vectorDown + vectorLeft);
                                }
                                painter->drawPoints(points.constData(), points.size());
                            }
                            else
                            {
                                QBrush buttonGradientBrush;
                                QBrush buttonBrush = qMapBrushToRect(option->palette.button(), fillRect);
                                if (buttonBrush.gradient() || !buttonBrush.texture().isNull())
                                {
                                    buttonGradientBrush = buttonBrush;
                                }
                                else
                                {
                                    // Generate gradients
                                    QLinearGradient buttonGradient(fillRect.topLeft(), fillRect.bottomLeft());
                                    buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
                                    buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
                                    buttonGradientBrush = QBrush(buttonGradient);
                                }

                                painter->fillRect(fillRect, buttonGradientBrush);
                            }
                        }
                    }

                    QPoint rightCornerDot = topRight + vectorLeft + (lowerTop + 1)*vectorDown;
                    QPoint leftCornerDot = topLeft + (marginLeft + 1)*vectorRight + (lowerTop + 1)*vectorDown;
                    QPoint bottomRightConnectToBase = rightLine.p2() + vectorRight + vectorDown;
                    QPoint bottomLeftConnectToBase = leftLine.p2() + vectorLeft + vectorDown;

                    painter->setPen(QPen(border, 0));

                    QVarLengthArray<QLine, 3> lines;
                    QVarLengthArray<QPoint, 7> points;

                    lines.append(topLine);

                    if (mouseOver)
                    {
                        painter->drawLines(lines.constData(), lines.count());
                        lines.clear();

                        QLine secondHoverLine = QLine(topLine.p1() + vectorDown * 2 + vectorLeft, topLine.p2() + vectorDown * 2 + vectorRight);
                        painter->setPen(highlightedLightInnerBorderColor);
                        painter->drawLine(secondHoverLine);
                    }

                    if (mouseOver)
                        painter->setPen(QPen(border, 0));

                    if (!previousSelected)
                        lines.append(leftLine);
                    if (atEnd || selected)
                    {
                        lines.append(rightLine);
                        points.append(rightCornerDot);
                    }
                    if (atBeginning || selected)
                        points.append(leftCornerDot);
                    if (selected)
                    {
                        points.append(bottomRightConnectToBase);
                        points.append(bottomLeftConnectToBase);
                    }
                    if (lines.size() > 0)
                    {
                        painter->drawLines(lines.constData(), lines.size());
                        lines.clear();
                    }
                    if (points.size() > 0)
                    {
                        painter->drawPoints(points.constData(), points.size());
                        points.clear();
                    }

                    // Antialiasing
                    painter->setPen(QPen(corner, 0));
                    if (atBeginning || selected)
                        points.append(topLine.p1() + vectorLeft);
                    if (!previousSelected)
                        points.append(leftLine.p1() + vectorUp);
                    if (atEnd || selected)
                    {
                        points.append(topLine.p2() + vectorRight);
                        points.append(rightLine.p1() + vectorUp);
                    }

                    if (selected)
                    {
                        points.append(bottomRightConnectToBase + vectorLeft);
                        if (!atBeginning)
                        {
                            points.append(bottomLeftConnectToBase + vectorRight);

                            if (((tab->position == QStyleOptionTab::Beginning) || onlyTab) && leftCornerWidget)
                            {
                                // A special case: When the first tab is selected and
                                // has a left corner widget, it needs to do more work
                                // to connect to the base
                                QPoint p1 = bottomLeftConnectToBase + vectorDown;

                                points.append(p1);
                            }
                        }
                    }
                    if (points.size() > 0)
                    {
                        painter->drawPoints(points.constData(), points.size());
                        points.clear();
                    }

                    // Inner border
                    QLine innerTopLine = QLine(topLine.p1() + vectorDown, topLine.p2() + vectorDown);
                    if (!selected)
                    {
                        QLinearGradient topLineGradient(innerTopLine.p1(),innerTopLine.p2());
                        topLineGradient.setColorAt(0, lightShadowGradientStartColor);
                        topLineGradient.setColorAt(1, lightShadowGradientStopColor);
                        painter->setPen(QPen(mouseOver ? QBrush(highlightedDarkInnerBorderColor) : QBrush(topLineGradient), 1));
                    }
                    else
                    {
                        painter->setPen(QPen(innerTopLeft, 0));
                    }
                    painter->drawLine(innerTopLine);

                    QLine innerLeftLine = QLine(leftLine.p1() + vectorRight + vectorDown, leftLine.p2() + vectorRight);
                    QLine innerRightLine = QLine(rightLine.p1() + vectorLeft + vectorDown, rightLine.p2() + vectorLeft);

                    if (selected)
                    {
                        innerRightLine = QLine(innerRightLine.p1() + vectorUp, innerRightLine.p2());
                        innerLeftLine = QLine(innerLeftLine.p1() + vectorUp, innerLeftLine.p2());
                    }

                    if (selected || atBeginning)
                    {
                        QBrush leftLineGradientBrush;
                        QRect rect = QRect(innerLeftLine.p1(), innerLeftLine.p2()).normalized();
                        QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
                        if (buttonBrush.gradient() || !buttonBrush.texture().isNull())
                        {
                            leftLineGradientBrush = qBrushLight(buttonBrush, 105);
                        }
                        else
                        {
                            QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft());
                            buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
                            buttonGradient3.setColorAt(1.0, buttonBrush.color());
                            leftLineGradientBrush = QBrush(buttonGradient3);
                        }

                        if (!selected)
                            painter->setPen(QPen(leftLineGradientBrush, 0));

                        // Assume the sun is on the same side in Right-To-Left layouts and draw the
                        // light shadow on the left side always (the right line is on the left side in
                        // reverse layouts for north and south)
                        if (reverseShadow)
                            painter->drawLine(innerRightLine);
                        else
                            painter->drawLine(innerLeftLine);
                    }

                    if (atEnd || selected)
                    {
                        if (!selected)
                        {
                            QBrush rightLineGradientBrush;
                            QRect rect = QRect(innerRightLine.p1(), innerRightLine.p2()).normalized();
                            QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
                            if (buttonBrush.gradient() || !buttonBrush.texture().isNull())
                            {
                                rightLineGradientBrush = qBrushDark(buttonBrush, 105);
                            }
                            else
                            {
                                QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft());
                                buttonGradient4.setColorAt(0.0, buttonBrush.color());
                                buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
                                rightLineGradientBrush = QBrush(buttonGradient4);
                            }

                            painter->setPen(QPen(rightLineGradientBrush, 0));
                        }
                        else
                        {
                            painter->setPen(QPen(innerBottomRight, 0));
                        }

                        if (reverseShadow)
                            painter->drawLine(innerLeftLine);
                        else
                            painter->drawLine(innerRightLine);
                    }


                    // Base
                    QLine baseLine = QLine(bottomLeft + marginLeft * 2 * vectorRight, bottomRight);
                    {

                        QPoint adjustedLeft;
                        QPoint adjustedRight;

                        if (atEnd && !selected)
                        {
                            baseLine = QLine(baseLine.p1(), baseLine.p2() + vectorRight);
                        }

                        if (nextSelected)
                        {
                            adjustedRight += vectorLeft;
                            baseLine = QLine(baseLine.p1(), baseLine.p2() + vectorLeft);
                        }
                        if (previousSelected)
                        {
                            adjustedLeft += vectorRight;
                            baseLine = QLine(baseLine.p1() + vectorRight, baseLine.p2());
                        }
                        if (atBeginning)
                            adjustedLeft += vectorRight;

                        painter->setPen(QPen(baseColor2, 0));
                        if (!selected)
                            painter->drawLine(baseLine);

                        if (atEnd && !selected)
                            painter->drawPoint(baseLine.p2() + vectorRight);

                        if (atBeginning && !selected)
                            adjustedLeft = vectorRight;
                        else
                            adjustedLeft = QPoint(0, 0);
                        painter->setPen(QPen(baseColor1, 0));
                        if (!selected)
                            painter->drawLine(bottomLeft + vectorUp + adjustedLeft, baseLine.p2() + vectorUp);

                        QPoint endPoint = bottomRight + vectorUp;
                        if (atEnd && !selected)
                            painter->drawPoint(endPoint);

                        // For drawing a lower left "fake" corner on the base when the first tab is unselected
                        if (atBeginning && !selected)
                        {
                            painter->drawPoint(baseLine.p1() + vectorLeft);
                        }

                        painter->setPen(QPen(corner, 0));
                        if (nextSelected)
                            painter->drawPoint(endPoint);
                        else if (selected)
                            painter->drawPoint(endPoint + vectorRight);

                        // For drawing a lower left "fake" corner on the base when the first tab is unselected
                        if (atBeginning && !selected)
                        {
                            painter->drawPoint(baseLine.p1() + 2 * vectorLeft);
                        }
                    }
                }
            }

            // Yay we're done

            painter->restore();
        }
        break;
#endif // QT_NO_TABBAR
#ifndef QT_NO_PROGRESSBAR
    case CE_ProgressBarGroove:
        if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option))
        {
            QRect rect = bar->rect;
            QPen oldPen = painter->pen();

            QLine lines[4];

            // outline
            painter->setPen(borderColor);
            lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
            lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
            lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
            lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
            painter->drawLines(lines, 4);

            QPoint points[8];
            points[0] = QPoint(rect.left() + 1, rect.top() + 1);
            points[1] = QPoint(rect.right() - 1, rect.top() + 1);
            points[2] = QPoint(rect.left() + 1, rect.bottom() - 1);
            points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
            painter->drawPoints(points, 4);

            // alpha corners
            painter->setPen(alphaCornerColor);
            points[0] = QPoint(rect.left(), rect.top() + 1);
            points[1] = QPoint(rect.left() + 1, rect.top());
            points[2] = QPoint(rect.right(), rect.top() + 1);
            points[3] = QPoint(rect.right() - 1, rect.top());
            points[4] = QPoint(rect.left(), rect.bottom() - 1);
            points[5] = QPoint(rect.left() + 1, rect.bottom());
            points[6] = QPoint(rect.right(), rect.bottom() - 1);
            points[7] = QPoint(rect.right() - 1, rect.bottom());
            painter->drawPoints(points, 8);

            // inner outline, north-west
            painter->setPen(gradientStartColor.darker(105));
            lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1);
            lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
            painter->drawLines(lines, 2);

            // base of the groove
            painter->setPen(QPen());
            painter->fillRect(rect.adjusted(2, 2, -2, -1), QBrush(bar->palette.base().color()));
            painter->setPen(bar->palette.base().color());
            painter->drawLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);

            painter->setPen(oldPen);
        }
        break;
    case CE_ProgressBarLabel:
        if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option))
        {
            // The busy indicator doesn't draw a label
            if (bar->minimum == 0 && bar->maximum == 0)
                return;

            painter->save();

            QRect rect = bar->rect;
            QRect leftRect;

            QFont font;
            font.setBold(true);
            painter->setFont(font);
            painter->setPen(bar->palette.text().color());

            bool vertical = false;
            bool inverted = false;
            bool bottomToTop = false;
            // Get extra style options if version 2 lz2hv removed
            //if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
            //vertical = (bar2->orientation == Qt::Vertical);
            //inverted = bar2->invertedAppearance;
            //bottomToTop = bar2->bottomToTop;
            //}

            if (vertical)
            {
                rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
                QTransform m;
                if (bottomToTop)
                {
                    m.translate(0.0, rect.width());
                    m.rotate(-90);
                }
                else
                {
                    m.translate(rect.height(), 0.0);
                    m.rotate(90);
                }
                painter->setTransform(m, true);
            }

            int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum) * rect.width();

            bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted)
                                       || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop)));
            if (flip)
            {
                int indicatorPos = rect.width() - progressIndicatorPos;
                if (indicatorPos >= 0 && indicatorPos <= rect.width())
                {
                    painter->setPen(bar->palette.base().color());
                    leftRect = QRect(rect.left(), rect.top(), indicatorPos, rect.height());
                }
                else if (indicatorPos > rect.width())
                {
                    painter->setPen(bar->palette.text().color());
                }
                else
                {
                    painter->setPen(bar->palette.base().color());
                }
            }
            else
            {
                if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
                {
                    leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
                }
                else if (progressIndicatorPos > rect.width())
                {
                    painter->setPen(bar->palette.base().color());
                }
                else
                {
                    painter->setPen(bar->palette.text().color());
                }
            }

            QRegion rightRect = rect;
            rightRect = rightRect.subtracted(leftRect);
            painter->setClipRegion(rightRect);
            painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
            if (!leftRect.isNull())
            {
                painter->setPen(flip ? bar->palette.text().color() : bar->palette.base().color());
                painter->setClipRect(leftRect);
                painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
            }

            painter->restore();
        }
        break;
    case CE_ProgressBarContents:
        if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option))
        {
            //Q_D(const QPlastiqueStyle);
            QRect rect = bar->rect;
            bool vertical = false;
            bool inverted = false;
            bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
            if (!indeterminate && bar->progress == -1)
                break;

            painter->save();

            // Get extra style options if version 2
            //stop 2.26 qt5 gcc7.3.1 Linux problem
            /*if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option))
            {
                vertical = (bar2->orientation == Qt::Vertical);
                inverted = bar2->invertedAppearance;
            }*/

            // If the orientation is vertical, we use a transform to rotate
            // the progress bar 90 degrees clockwise.  This way we can use the
            // same rendering code for both orientations.
            if (vertical)
            {
                rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
                QTransform m = QTransform::fromTranslate(rect.height()-1, 0);
                m.rotate(90.0);
                painter->setTransform(m, true);
            }

            int maxWidth = rect.width() - 4;
            int minWidth = 4;
            qint64 progress = qMax<qint64>(bar->progress, bar->minimum); // workaround for bug in QProgressBar
            double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(double(1.0), double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
            int width = indeterminate ? maxWidth : qMax(int(vc6_workaround), minWidth);
            bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
            if (inverted)
                reverse = !reverse;

            QRect progressBar;
            if (!indeterminate)
            {
                if (!reverse)
                {
                    progressBar.setRect(rect.left() + 2, rect.top() + 2, width, rect.height() - 4);
                }
                else
                {
                    progressBar.setRect(rect.right() - 1 - width, rect.top() + 2, width, rect.height() - 4);
                }
            }
            else
            {
                /*int slideWidth = ((rect.width() - 4) * 2) / 3;
                int step = ((d->animateStep * slideWidth) / ProgressBarFps) % slideWidth;
                if ((((d->animateStep * slideWidth) / ProgressBarFps) % (2 * slideWidth)) >= slideWidth)
                    step = slideWidth - step;
                progressBar.setRect(rect.left() + 2 + step, rect.top() + 2,
                                    slideWidth / 2, rect.height() - 4);*/
            }

            // outline
            painter->setPen(highlightedDarkInnerBorderColor);

            QVarLengthArray<QLine, 4> lines;
            QVarLengthArray<QPoint, 8> points;
            if (!reverse)
            {
                if (width == minWidth)
                {
                    points.append(QPoint(progressBar.left() + 1, progressBar.top()));
                    points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
                }
                else
                {
                    if (indeterminate)
                    {
                        lines.append(QLine(progressBar.left() + 2, progressBar.top(),
                                           progressBar.right() - 2, progressBar.top()));
                        lines.append(QLine(progressBar.left() + 2, progressBar.bottom(),
                                           progressBar.right() - 2, progressBar.bottom()));
                    }
                    else
                    {
                        lines.append(QLine(progressBar.left() + 1, progressBar.top(),
                                           progressBar.right() - 2, progressBar.top()));
                        lines.append(QLine(progressBar.left() + 1, progressBar.bottom(),
                                           progressBar.right() - 2, progressBar.bottom()));
                    }
                }

                if (indeterminate)
                {
                    lines.append(QLine(progressBar.left(), progressBar.top() + 2,
                                       progressBar.left(), progressBar.bottom() - 2));
                }
                else
                {
                    lines.append(QLine(progressBar.left(), progressBar.top() + 1,
                                       progressBar.left(), progressBar.bottom() - 1));
                }
                lines.append(QLine(progressBar.right(), progressBar.top() + 2,
                                   progressBar.right(), progressBar.bottom() - 2));
            }
            else
            {
                if (width == minWidth)
                {
                    points.append(QPoint(progressBar.right() - 1, progressBar.top()));
                    points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
                }
                else
                {
                    if (indeterminate)
                    {
                        lines.append(QLine(progressBar.right() - 2, progressBar.top(),
                                           progressBar.left() + 2, progressBar.top()));
                        lines.append(QLine(progressBar.right() - 2, progressBar.bottom(),
                                           progressBar.left() + 2, progressBar.bottom()));
                    }
                    else
                    {
                        lines.append(QLine(progressBar.right() - 1, progressBar.top(),
                                           progressBar.left() + 2, progressBar.top()));
                        lines.append(QLine(progressBar.right() - 1, progressBar.bottom(),
                                           progressBar.left() + 2, progressBar.bottom()));
                    }
                }
                if (indeterminate)
                {
                    lines.append(QLine(progressBar.right(), progressBar.top() + 2,
                                       progressBar.right(), progressBar.bottom() - 2));
                }
                else
                {
                    lines.append(QLine(progressBar.right(), progressBar.top() + 1,
                                       progressBar.right(), progressBar.bottom() - 1));
                }
                lines.append(QLine(progressBar.left(), progressBar.top() + 2,
                                   progressBar.left(), progressBar.bottom() - 2));
            }

            if (points.size() > 0)
            {
                painter->drawPoints(points.constData(), points.size());
                points.clear();
            }
            painter->drawLines(lines.constData(), lines.size());
            lines.clear();

            // alpha corners
            painter->setPen(alphaInnerColor);
            if (!reverse)
            {
                if (indeterminate)
                {
                    points.append(QPoint(progressBar.left() + 1, progressBar.top()));
                    points.append(QPoint(progressBar.left(), progressBar.top() + 1));
                    points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
                    points.append(QPoint(progressBar.left(), progressBar.bottom() - 1));
                }
                else
                {
                    points.append(QPoint(progressBar.left(), progressBar.top()));
                    points.append(QPoint(progressBar.left(), progressBar.bottom()));
                }
                points.append(QPoint(progressBar.right() - 1, progressBar.top()));
                points.append(QPoint(progressBar.right(), progressBar.top() + 1));
                points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
                points.append(QPoint(progressBar.right(), progressBar.bottom() - 1));
            }
            else
            {
                if (indeterminate)
                {
                    points.append(QPoint(progressBar.right() - 1, progressBar.top()));
                    points.append(QPoint(progressBar.right(), progressBar.top() + 1));
                    points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
                    points.append(QPoint(progressBar.right(), progressBar.bottom() - 1));
                }
                else
                {
                    points.append(QPoint(progressBar.right(), progressBar.top()));
                    points.append(QPoint(progressBar.right(), progressBar.bottom()));
                }
                points.append(QPoint(progressBar.left() + 1, progressBar.top()));
                points.append(QPoint(progressBar.left(), progressBar.top() + 1));
                points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
                points.append(QPoint(progressBar.left(), progressBar.bottom() - 1));
            }

            painter->drawPoints(points.constData(), points.size());
            points.clear();

            // contents
            painter->setPen(QPen());

            QString progressBarName = QStyleHelper1::uniqueName(QLatin1String("progressBarContents"),
                                      option, rect.size());
            QPixmap cache;
            if (!QPixmapCache::find(progressBarName, &cache) && rect.height() > 7)
            {
                QSize size = rect.size();
                cache = QPixmap(QSize(size.width() - 6 + 30, size.height() - 6));
                cache.fill(Qt::white);
                QPainter cachePainter(&cache);
                QRect pixmapRect(0, 0, cache.width(), cache.height());

                int leftEdge = 0;
                bool flip = false;
                while (leftEdge < cache.width() + 1)
                {
                    QColor rectColor = option->palette.highlight().color();
                    QColor lineColor = option->palette.highlight().color();
                    if (flip)
                    {
                        flip = false;
                        rectColor = rectColor.lighter(105);
                        lineColor = lineColor.lighter(105);
                    }
                    else
                    {
                        flip = true;
                    }

                    cachePainter.setPen(lineColor);
                    const QLine cacheLines[2] =
                        {
                            QLine(pixmapRect.left() + leftEdge - 1, pixmapRect.top(),
                                  pixmapRect.left() + leftEdge + 9, pixmapRect.top()),
                            QLine(pixmapRect.left() + leftEdge - 1, pixmapRect.bottom(),
                                  pixmapRect.left() + leftEdge + 9, pixmapRect.bottom())
                        };
                    cachePainter.drawLines(cacheLines, 2);
                    cachePainter.fillRect(QRect(pixmapRect.left() + leftEdge, pixmapRect.top(),
                                                10, pixmapRect.height()), rectColor);

                    leftEdge += 10;
                }

                QPixmapCache::insert(progressBarName, cache);
            }
            painter->setClipRect(progressBar.adjusted(1, 0, -1, -1));

            if (!vertical)
                progressBar.adjust(0, 1, 0, 1);
            if (!indeterminate)
            {
                int step = 10;//(AnimateProgressBar || (indeterminate && AnimateBusyProgressBar)) ? (d->animateStep % 20) : 0;
                if (reverse)
                    painter->drawPixmap(progressBar.left() - 25 + step, progressBar.top(), cache);
                else
                    painter->drawPixmap(progressBar.left() - 25 - step + width % 20, progressBar.top(), cache);
            }
            else
            {
                painter->drawPixmap(progressBar.left(), progressBar.top(), cache);
            }

            painter->restore();
        }
        break;
#endif // QT_NO_PROGRESSBAR
    case CE_HeaderSection:
        // Draws the header in tables.
        if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option))
        {
            QPixmap cache;
            QString pixmapName = QStyleHelper1::uniqueName(QLatin1String("headersection"), option, option->rect.size());
            pixmapName += QString::number(- int(header->position));
            pixmapName += QString::number(- int(header->orientation));

            if (!QPixmapCache::find(pixmapName, &cache))
            {
                cache = QPixmap(option->rect.size());
                cache.fill(Qt::white);
                QRect pixmapRect(0, 0, option->rect.width(), option->rect.height());
                QPainter cachePainter(&cache);

                bool sunken = (header->state & State_Enabled) && (header->state & State_Sunken);

                QColor headerGradientStart = sunken ? option->palette.window().color().darker(114) : gradientStartColor;
                QColor headerGradientStop = sunken ? option->palette.window().color().darker(106) : gradientStopColor;

                QColor lightLine = sunken ? option->palette.window().color().darker(118) : gradientStartColor;
                QColor darkLine = sunken ? option->palette.window().color().darker(110) : gradientStopColor.darker(105);

                qt_plastique_draw_gradient(&cachePainter, pixmapRect,
                                           headerGradientStart, headerGradientStop);

                cachePainter.setPen(borderColor);
                cachePainter.drawRect(pixmapRect.adjusted(0, 0, -1, -1));
                cachePainter.setPen(alphaCornerColor);

                const QPoint points[4] =
                    {
                        pixmapRect.topLeft(), pixmapRect.topRight(),
                        pixmapRect.bottomLeft(), pixmapRect.bottomRight()
                    };
                cachePainter.drawPoints(points, 4);

                QLine lines[2];

                // inner lines
                cachePainter.setPen(lightLine);
                lines[0] = QLine(pixmapRect.left() + 2, pixmapRect.top() + 1,
                                 pixmapRect.right() - 2, pixmapRect.top() + 1);
                lines[1] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 2,
                                 pixmapRect.left() + 1, pixmapRect.bottom() - 2);
                cachePainter.drawLines(lines, 2);

                cachePainter.setPen(darkLine);
                lines[0] = QLine(pixmapRect.left() + 2, pixmapRect.bottom() - 1,
                                 pixmapRect.right() - 2, pixmapRect.bottom() - 1);
                lines[1] = QLine(pixmapRect.right() - 1, pixmapRect.bottom() - 2,
                                 pixmapRect.right() - 1, pixmapRect.top() + 2);
                cachePainter.drawLines(lines, 2);

                cachePainter.end();
                QPixmapCache::insert(pixmapName, cache);
            }
            painter->drawPixmap(option->rect.topLeft(), cache);

        }
        break;

#ifndef QT_NO_MENU
    case CE_MenuItem:
        // Draws one item in a popup menu.
        if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
        {
            painter->save();
            QBrush textBrush;
            if (option->palette.resolve() & (1 << QPalette::ButtonText))
                textBrush = option->palette.buttonText();
            else
                textBrush = option->palette.windowText(); // KDE uses windowText rather than buttonText for menus

            if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
            {
                painter->fillRect(menuItem->rect, option->palette.window().color().lighter(103));

                int w = 0;
                if (!menuItem->text.isEmpty())
                {
                    painter->setFont(menuItem->font);
                    proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
                                          menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
                                          QPalette::Text);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)//2.56
                    w = menuItem->fontMetrics.horizontalAdvance(menuItem->text) + 5;
#else
                    w = menuItem->fontMetrics.width(menuItem->text) + 5;
#endif
                }

                painter->setPen(alphaCornerColor);
                bool reverse = menuItem->direction == Qt::RightToLeft;
                painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
                                  menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());

                painter->restore();
                break;
            }

            bool selected = menuItem->state & State_Selected;
            bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
            bool checked = menuItem->checked;

            if (selected)
            {
                qt_plastique_draw_gradient(painter, menuItem->rect,
                                           option->palette.highlight().color().lighter(105),
                                           option->palette.highlight().color().darker(110));

                painter->setPen(option->palette.highlight().color().lighter(110));
                painter->drawLine(option->rect.topLeft(), option->rect.topRight());
                painter->setPen(option->palette.highlight().color().darker(115));
                painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
            }
            else
            {
                painter->fillRect(option->rect, option->palette.window().color().lighter(103));
            }

            // Check
            QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 13, 13);
            checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
            if (checkable)
            {
                if ((menuItem->checkType & QStyleOptionMenuItem::Exclusive) && menuItem->icon.isNull())
                {
                    QStyleOptionButton button;
                    button.rect = checkRect;
                    button.state = menuItem->state;
                    if (checked)
                        button.state |= State_On;
                    button.palette = menuItem->palette;
                    proxy()->drawPrimitive(PE_IndicatorRadioButton, &button, painter, widget);
                }
                else
                {
                    if (menuItem->icon.isNull())
                    {
                        QStyleOptionButton button;
                        button.rect = checkRect;
                        button.state = menuItem->state;
                        if (checked)
                            button.state |= State_On;
                        button.palette = menuItem->palette;
                        proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
                    }
                    else if (checked)
                    {
                        int iconSize = qMax(menuItem->maxIconWidth, 20);
                        QRect sunkenRect(option->rect.left() + 1,
                                         option->rect.top() + (option->rect.height() - iconSize) / 2 + 1,
                                         iconSize, iconSize);
                        sunkenRect = visualRect(menuItem->direction, menuItem->rect, sunkenRect);

                        QStyleOption opt = *option;
                        opt.state |= State_Sunken;
                        opt.rect = sunkenRect;
                        qt_plastique_drawShadedPanel(painter, &opt, false, widget);
                    }
                }
            }

            // Text and icon, ripped from windows style
            bool dis = !(menuItem->state & State_Enabled);
            bool act = menuItem->state & State_Selected;
            const QStyleOption *opt = option;
            const QStyleOptionMenuItem *menuitem = menuItem;
            int checkcol = qMax(menuitem->maxIconWidth, 20);
            QPainter *p = painter;
            QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
                                          QRect(menuitem->rect.x(), menuitem->rect.y(),
                                                checkcol, menuitem->rect.height()));
            if (!menuItem->icon.isNull())
            {
                QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
                if (act && !dis)
                    mode = QIcon::Active;
                QPixmap pixmap;
                if (checked)
                    pixmap = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On);
                else
                    pixmap = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize, option, widget), mode);
                int pixw = pixmap.width();
                int pixh = pixmap.height();

                QRect pmr(0, 0, pixw, pixh);
                pmr.moveCenter(vCheckRect.center());
                painter->setPen(textBrush.color());
                if (checkable && checked)
                    painter->drawPixmap(QPoint(pmr.left() + 1, pmr.top() + 1), pixmap);
                else
                    painter->drawPixmap(pmr.topLeft(), pixmap);
            }

            if (selected)
            {
                painter->setPen(menuItem->palette.highlightedText().color());
            }
            else
            {
                painter->setPen(textBrush.color());
            }
            int x, y, w, h;
            menuitem->rect.getRect(&x, &y, &w, &h);
            int tab = menuitem->tabWidth;
            QColor discol;
            if (dis)
            {
                discol = textBrush.color();
                p->setPen(discol);
            }
            int xm = windowsItemFrame + checkcol + windowsItemHMargin;
            int xpos = menuitem->rect.x() + xm;
            QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
            QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
            QString s = menuitem->text;
            if (!s.isEmpty())
            {                     // draw text
                p->save();
                int t = s.indexOf(QLatin1Char('\t'));
                int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
                if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
                    text_flags |= Qt::TextHideMnemonic;
                text_flags |= Qt::AlignLeft;
                if (t >= 0)
                {
                    QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
                                                     QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
                    if (dis && !act && styleHint(SH_EtchDisabledText, option, widget))
                    {
                        p->setPen(menuitem->palette.light().color());
                        p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
                        p->setPen(discol);
                    }
                    p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
                    s = s.left(t);
                }
                QFont font = menuitem->font;
                if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
                    font.setBold(true);
                //QFont fff("arial",11);
                //p->setFont(fff);
                p->setFont(font);
                //p->setFont(painter->font());

                if (dis && !act && styleHint(SH_EtchDisabledText, option, widget))
                {
                    p->setPen(menuitem->palette.light().color());
                    p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
                    p->setPen(discol);
                }
                p->drawText(vTextRect, text_flags, s.left(t));
                p->restore();
            }

            // Arrow
            if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu)
            {// draw sub menu arrow
                int dim = (menuItem->rect.height() - 4) / 2;
                PrimitiveElement arrow;
                arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
                int xpos = menuItem->rect.left() + menuItem->rect.width() - 6 - 2 - dim;
                QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
                                                 QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
                QStyleOptionMenuItem newMI = *menuItem;
                newMI.rect = vSubMenuRect;
                newMI.state = option->state & State_Enabled;
                if (selected)
                    newMI.palette.setColor(QPalette::ButtonText,
                                           newMI.palette.highlightedText().color());
                else
                    newMI.palette.setColor(QPalette::ButtonText, textBrush.color());
                proxy()->drawPrimitive(arrow, &newMI, painter, widget);
            }

            painter->restore();
        }
        break;
#endif // QT_NO_MENU

#ifndef QT_NO_MENUBAR
    case CE_MenuBarItem:
        // Draws a menu bar item; File, Edit, Help etc..
        if ((option->state & State_Selected))
        {
            QPixmap cache;
            QString pixmapName = QStyleHelper1::uniqueName(QLatin1String("menubaritem"), option, option->rect.size());
            if (!QPixmapCache::find(pixmapName, &cache))
            {
                cache = QPixmap(option->rect.size());
                cache.fill(Qt::white);
                QRect pixmapRect(0, 0, option->rect.width(), option->rect.height());
                QPainter cachePainter(&cache);

                QRect rect = pixmapRect;

                // gradient fill
                if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
                {
                    qt_plastique_draw_gradient(&cachePainter, rect.adjusted(1, 1, -1, -1),
                                               option->palette.button().color().darker(114),
                                               option->palette.button().color().darker(106));
                }
                else
                {
                    qt_plastique_draw_gradient(&cachePainter, rect.adjusted(1, 1, -1, -1),
                                               option->palette.window().color().lighter(105),
                                               option->palette.window().color().darker(102));
                }

                // outer border and corners
                cachePainter.setPen(borderColor);
                cachePainter.drawRect(rect.adjusted(0, 0, -1, -1));
                cachePainter.setPen(alphaCornerColor);

                const QPoint points[4] =
                    {
                        rect.topLeft(),
                        rect.topRight(),
                        rect.bottomLeft(),
                        rect.bottomRight()
                    };
                cachePainter.drawPoints(points, 4);

                // inner border
                if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
                    cachePainter.setPen(option->palette.button().color().darker(118));
                else
                    cachePainter.setPen(gradientStartColor);

                QLine lines[2];
                lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1);
                lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
                cachePainter.drawLines(lines, 2);

                if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
                    cachePainter.setPen(option->palette.button().color().darker(114));
                else
                    cachePainter.setPen(gradientStopColor.darker(102));
                lines[0] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1);
                lines[1] = QLine(rect.right() - 1, rect.top() + 1, rect.right() - 1, rect.bottom() - 2);
                cachePainter.drawLines(lines, 2);
                cachePainter.end();
                QPixmapCache::insert(pixmapName, cache);
            }
            painter->drawPixmap(option->rect.topLeft(), cache);
        }
        else
        {
            painter->fillRect(option->rect, option->palette.window());
        }
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
        {
            QStyleOptionMenuItem newMI = *mbi;
            if (!(option->palette.resolve() & (1 << QPalette::ButtonText))) //KDE uses windowText rather than buttonText for menus
                newMI.palette.setColor(QPalette::ButtonText, newMI.palette.windowText().color());
            //QFont fff("arial",11);
            // QFont fff = mbi->font;
            //qDebug()<<"FFFFF="<<fff.family();
            //painter->setFont(QApplication::font());
            //painter->font().setFamily("arial");
            //qDebug()<<"CE_MenuBarItem="<<painter->font().family();

            HvPublicStyle::drawControl(element, &newMI, painter, widget);
        }
        break;

#ifndef QT_NO_MAINWINDOW
    case CE_MenuBarEmptyArea:
        if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget()))
        {
            painter->fillRect(option->rect, option->palette.window());
            QPen oldPen = painter->pen();
            painter->setPen(QPen(option->palette.dark().color()));
            painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
            painter->setPen(oldPen);
        }
        break;
#endif // QT_NO_MAINWINDOW

#endif // QT_NO_MENUBAR

#ifndef QT_NO_TOOLBOX
    case CE_ToolBoxTabShape:
        if (const QStyleOptionToolBox *toolBox = qstyleoption_cast<const QStyleOptionToolBox *>(option))
        {
            painter->save();

            int width = toolBox->rect.width();
            int diag = toolBox->rect.height() - 2;

            // The essential points
            QPoint rightMost;
            QPoint rightEdge;
            QPoint leftEdge;
            QPoint leftMost;
            QPoint leftOne;
            QPoint rightOne;
            QPoint upOne(0, -1);
            QPoint downOne(0, 1);

            if (toolBox->direction != Qt::RightToLeft)
            {
                rightMost = QPoint(toolBox->rect.right(), toolBox->rect.bottom() - 2);
                rightEdge = QPoint(toolBox->rect.right() - width / 10, toolBox->rect.bottom() - 2);
                leftEdge = QPoint(toolBox->rect.right() - width / 10 - diag, toolBox->rect.top());
                leftMost = QPoint(toolBox->rect.left(), toolBox->rect.top());
                leftOne = QPoint(-1, 0);
                rightOne = QPoint(1, 0);
            }
            else
            {
                rightMost = QPoint(toolBox->rect.left(), toolBox->rect.bottom() - 2);
                rightEdge = QPoint(toolBox->rect.left() + width / 10, toolBox->rect.bottom() - 2);
                leftEdge = QPoint(toolBox->rect.left() + width / 10 + diag, toolBox->rect.top());
                leftMost = QPoint(toolBox->rect.right(), toolBox->rect.top());
                leftOne = QPoint(1, 0);
                rightOne = QPoint(-1, 0);
            }

            QLine lines[3];

            // Draw the outline
            painter->setPen(borderColor);
            lines[0] = QLine(rightMost, rightEdge);
            lines[1] = QLine(rightEdge + leftOne, leftEdge);
            lines[2] = QLine(leftEdge + leftOne, leftMost);
            painter->drawLines(lines, 3);
            painter->setPen(toolBox->palette.base().color());
            lines[0] = QLine(rightMost + downOne, rightEdge + downOne);
            lines[1] = QLine(rightEdge + leftOne + downOne, leftEdge + downOne);
            lines[2] = QLine(leftEdge + leftOne + downOne, leftMost + downOne);
            painter->drawLines(lines, 3);

            painter->restore();
        }
        break;
#endif // QT_NO_TOOLBOX
#ifndef QT_NO_SPLITTER
    case CE_Splitter:
        if ((option->state & State_Enabled) && (option->state & State_MouseOver))
            painter->fillRect(option->rect, QColor(255, 255, 255, 128));
        if (option->state & State_Horizontal)
        {
            int height = option->rect.height() / 3;
            QRect rect(option->rect.left() + (option->rect.width() / 2 - 1),
                       option->rect.center().y() - height / 2, 3, height);
            qt_plastique_draw_handle(painter, option, rect, Qt::Horizontal, widget);
        }
        else
        {
            int width = option->rect.width() / 3;
            QRect rect(option->rect.center().x() - width / 2,
                       option->rect.top() + (option->rect.height() / 2) - 1, width, 3);
            qt_plastique_draw_handle(painter, option, rect, Qt::Vertical, widget);
        }
        break;
#endif // QT_NO_SPLITTER
#ifndef QT_NO_DOCKWIDGET
    case CE_DockWidgetTitle:
        if (const QStyleOptionDockWidget *dockWidget = qstyleoption_cast<const QStyleOptionDockWidget *>(option))
        {
            painter->save();

            //const QStyleOptionDockWidgetV2 *v2 lz2hv removed
            //= qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dockWidget);
            //bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
            bool verticalTitleBar = false; // lz2hv added
            // Find text width and title rect
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)//2.56
            int textWidth = option->fontMetrics.horizontalAdvance(dockWidget->title);
#else
            int textWidth = option->fontMetrics.width(dockWidget->title);
#endif
            int margin = 4;
            QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
            QRect rect = dockWidget->rect;

            if (verticalTitleBar)
            {
                QRect r = rect;
                QSize s = r.size();
                s.transpose();
                r.setSize(s);

                titleRect = QRect(r.left() + rect.bottom()
                                  - titleRect.bottom(),
                                  r.top() + titleRect.left() - rect.left(),
                                  titleRect.height(), titleRect.width());

                painter->translate(r.left(), r.top() + r.width());
                painter->rotate(-90);
                painter->translate(-r.left(), -r.top());

                rect = r;
            }

            // Chop and insert ellide into title if text is too wide
            QString title = elliditide(dockWidget->title, dockWidget->fontMetrics, titleRect, &textWidth);

            // Draw the toolbar handle pattern to the left and right of the text
            QImage handle(qt_toolbarhandle);
            alphaCornerColor.setAlpha(170);
            handle.setColor(1, alphaCornerColor.rgba());
            handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
            handle.setColor(3, option->palette.light().color().rgba());

            if (title.isEmpty())
            {
                // Joint handle if there's no title
                QRect r;
#ifdef QT3_SUPPORT
                // Q3DockWindow doesn't need space for buttons
                if (widget && widget->inherits("Q3DockWindowTitleBar"))
                {
                    r = rect;
                }
                else
#endif
                    r.setRect(titleRect.left(), titleRect.top(), titleRect.width(), titleRect.bottom());
                int nchunks = (r.width() / handle.width()) - 1;
                int indent = (r.width() - (nchunks * handle.width())) / 2;
                for (int i = 0; i < nchunks; ++i)
                {
                    painter->drawImage(QPoint(r.left() + indent + i * handle.width(),
                                              r.center().y() - handle.height() / 2),
                                       handle);
                }
            }
            else
            {
                // Handle pattern to the left of the title
                QRect leftSide(titleRect.left(), titleRect.top(),
                               titleRect.width() / 2 - textWidth / 2 - margin, titleRect.bottom());
                int nchunks = leftSide.width() / handle.width();
                int indent = (leftSide.width() - (nchunks * handle.width())) / 2;
                for (int i = 0; i < nchunks; ++i)
                {
                    painter->drawImage(QPoint(leftSide.left() + indent
                                              + i * handle.width(),
                                              leftSide.center().y()
                                              - handle.height() / 2),
                                       handle);
                }

                // Handle pattern to the right of the title
                QRect rightSide = titleRect.adjusted(titleRect.width() / 2 + textWidth / 2 + margin, 0, 0, 0);
                nchunks = rightSide.width() / handle.width();
                indent = (rightSide.width() - (nchunks * handle.width())) / 2;
                for (int j = 0; j < nchunks; ++j)
                {
                    painter->drawImage(QPoint(rightSide.left() + indent + j * handle.width(),
                                              rightSide.center().y() - handle.height() / 2),
                                       handle);
                }
            }

            // Draw the text centered
            QFont font = painter->font();
            font.setPointSize(QFontInfo(font).pointSize() - 1);
            painter->setFont(font);
            painter->setPen(dockWidget->palette.windowText().color());
            painter->drawText(titleRect,
                              int(Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextShowMnemonic),
                              title);

            painter->restore();
        }

        break;
#endif // QT_NO_DOCKWIDGET
#ifndef QT_NO_TOOLBAR
    case CE_ToolBar:
        if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option))
        {
            // Draws the light line above and the dark line below menu bars and
            // tool bars.
            QPen oldPen = painter->pen();
            if (toolBar->toolBarArea == Qt::TopToolBarArea)
            {
                if (toolBar->positionOfLine == QStyleOptionToolBar::End
                        || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne)
                {
                    // The end and onlyone top toolbar lines draw a double
                    // line at the bottom to blend with the central
                    // widget.
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
                                      option->rect.right(), option->rect.bottom() - 1);
                }
                else
                {
                    // All others draw a single dark line at the bottom.
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
                }
                // All top toolbar lines draw a light line at the top.
                painter->setPen(option->palette.window().color().lighter(104));
                painter->drawLine(option->rect.topLeft(), option->rect.topRight());
            }
            else if (toolBar->toolBarArea == Qt::BottomToolBarArea)
            {
                if (toolBar->positionOfLine == QStyleOptionToolBar::End
                        || toolBar->positionOfLine == QStyleOptionToolBar::Middle)
                {
                    // The end and middle bottom tool bar lines draw a dark
                    // line at the bottom.
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
                }
                if (toolBar->positionOfLine == QStyleOptionToolBar::Beginning
                        || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne)
                {
                    // The beginning and only one tool bar lines draw a
                    // double line at the bottom to blend with the
                    // status bar.
                    // ### The styleoption could contain whether the
                    // main window has a menu bar and a status bar, and
                    // possibly dock widgets.
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
                                      option->rect.right(), option->rect.bottom() - 1);
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
                }
                if (toolBar->positionOfLine == QStyleOptionToolBar::End)
                {
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.topLeft(), option->rect.topRight());
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.left(), option->rect.top() + 1,
                                      option->rect.right(), option->rect.top() + 1);

                }
                else
                {
                    // All other bottom toolbars draw a light line at the top.
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.topLeft(), option->rect.topRight());
                }
            }
            if (toolBar->toolBarArea == Qt::LeftToolBarArea)
            {
                if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
                        || toolBar->positionOfLine == QStyleOptionToolBar::End)
                {
                    // The middle and left end toolbar lines draw a light
                    // line to the left.
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
                }
                if (toolBar->positionOfLine == QStyleOptionToolBar::End)
                {
                    // All other left toolbar lines draw a dark line to the right
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.right() - 1, option->rect.top(),
                                      option->rect.right() - 1, option->rect.bottom());
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
                }
                else
                {
                    // All other left toolbar lines draw a dark line to the right
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
                }
            }
            else if (toolBar->toolBarArea == Qt::RightToolBarArea)
            {
                if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
                        || toolBar->positionOfLine == QStyleOptionToolBar::End)
                {
                    // Right middle and end toolbar lines draw the dark right line
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
                }
                if (toolBar->positionOfLine == QStyleOptionToolBar::End
                        || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne)
                {
                    // The right end and single toolbar draws the dark
                    // line on its left edge
                    painter->setPen(alphaCornerColor);
                    painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
                    // And a light line next to it
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.left() + 1, option->rect.top(),
                                      option->rect.left() + 1, option->rect.bottom());
                }
                else
                {
                    // Other right toolbars draw a light line on its left edge
                    painter->setPen(option->palette.window().color().lighter(104));
                    painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
                }
            }
            painter->setPen(oldPen);
        }
        break;
#endif // QT_NO_TOOLBAR
#ifndef QT_NO_SCROLLBAR
    case CE_ScrollBarAddLine:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {

            bool horizontal = scrollBar->orientation == Qt::Horizontal;
            bool reverse = scrollBar->direction == Qt::RightToLeft;
            bool sunken = scrollBar->state & State_Sunken;

            QString addLinePixmapName = QStyleHelper1::uniqueName(QLatin1String("scrollbar_addline"), option, option->rect.size());
            QPixmap cache;
            if (!QPixmapCache::find(addLinePixmapName, &cache))
            {
                cache = QPixmap(option->rect.size());
                cache.fill(Qt::white);
                QRect pixmapRect(0, 0, cache.width(), cache.height());
                QPainter addLinePainter(&cache);
                addLinePainter.fillRect(pixmapRect, option->palette.window());

                if (option->state & State_Enabled)
                {
                    // Gradient
                    QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top() + 2,
                                             pixmapRect.center().x(), pixmapRect.bottom() - 2);
                    if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
                    {
                        gradient.setColorAt(0, gradientStopColor);
                        gradient.setColorAt(1, gradientStopColor);
                    }
                    else
                    {
                        gradient.setColorAt(0, gradientStartColor.lighter(105));
                        gradient.setColorAt(1, gradientStopColor);
                    }
                    addLinePainter.fillRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
                                            pixmapRect.right() - 3, pixmapRect.bottom() - 3,
                                            gradient);
                }

                // Details
                QImage addButton;
                if (horizontal)
                {
                    addButton = QImage(reverse ? qt_scrollbar_button_left : qt_scrollbar_button_right);
                }
                else
                {
                    addButton = QImage(qt_scrollbar_button_down);
                }
                addButton.setColor(1, alphaCornerColor.rgba());
                addButton.setColor(2, borderColor.rgba());
                if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
                {
                    addButton.setColor(3, gradientStopColor.rgba());
                    addButton.setColor(4, gradientStopColor.rgba());
                }
                else
                {
                    addButton.setColor(3, gradientStartColor.lighter(105).rgba());
                    addButton.setColor(4, gradientStopColor.rgba());
                }
                addButton.setColor(5, scrollBar->palette.text().color().rgba());
                addLinePainter.drawImage(pixmapRect, addButton);

                // Arrow
                if (horizontal)
                {
                    QImage arrow(reverse ? qt_scrollbar_button_arrow_left : qt_scrollbar_button_arrow_right);
                    arrow.setColor(1, scrollBar->palette.windowText().color().rgba());

                    if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
                        addLinePainter.translate(1, 1);
                    addLinePainter.drawImage(QPoint(pixmapRect.center().x() - 2, pixmapRect.center().y() - 3), arrow);
                }
                else
                {
                    QImage arrow(qt_scrollbar_button_arrow_down);
                    arrow.setColor(1, scrollBar->palette.windowText().color().rgba());

                    if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
                        addLinePainter.translate(1, 1);
                    addLinePainter.drawImage(QPoint(pixmapRect.center().x() - 3, pixmapRect.center().y() - 2), arrow);
                }
                addLinePainter.end();
                QPixmapCache::insert(addLinePixmapName, cache);
            }
            painter->drawPixmap(option->rect.topLeft(), cache);
        }
        break;
    case CE_ScrollBarSubPage:
    case CE_ScrollBarAddPage:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            bool sunken = scrollBar->state & State_Sunken;
            bool horizontal = scrollBar->orientation == Qt::Horizontal;

            QString groovePixmapName = QStyleHelper1::uniqueName(QLatin1String("scrollbar_groove"), option, option->rect.size());
            if (sunken)
                groovePixmapName += QLatin1String("-sunken");
            if (element == CE_ScrollBarAddPage)
                groovePixmapName += QLatin1String("-addpage");

            QPixmap cache;
            if (!QPixmapCache::find(groovePixmapName, &cache))
            {
                cache = QPixmap(option->rect.size());
                cache.fill(option->palette.window().color());
                QPainter groovePainter(&cache);
                QRect pixmapRect = QRect(0, 0, option->rect.width(), option->rect.height());
                QColor color = scrollBar->palette.base().color().darker(sunken ? 125 : 100);
                groovePainter.setBrushOrigin((element == CE_ScrollBarAddPage) ? pixmapRect.width() : 0,
                                             (element == CE_ScrollBarAddPage) ? pixmapRect.height() : 0);
                groovePainter.fillRect(pixmapRect, QBrush(color, Qt::Dense4Pattern));

                QColor edgeColor = scrollBar->palette.base().color().darker(125);
                if (horizontal)
                {
                    groovePainter.setBrushOrigin((element == CE_ScrollBarAddPage) ? pixmapRect.width() : 1, 0);
                    groovePainter.fillRect(QRect(pixmapRect.topLeft(), QSize(pixmapRect.width(), 1)),
                                           QBrush(edgeColor, Qt::Dense4Pattern));
                    groovePainter.fillRect(QRect(pixmapRect.bottomLeft(), QSize(pixmapRect.width(), 1)),
                                           QBrush(edgeColor, Qt::Dense4Pattern));
                }
                else
                {
                    groovePainter.setBrushOrigin(0, (element == CE_ScrollBarAddPage) ? pixmapRect.height() : 1);
                    groovePainter.fillRect(QRect(pixmapRect.topLeft(), QSize(1, pixmapRect.height())),
                                           QBrush(edgeColor, Qt::Dense4Pattern));
                    groovePainter.fillRect(QRect(pixmapRect.topRight(), QSize(1, pixmapRect.height())),
                                           QBrush(edgeColor, Qt::Dense4Pattern));
                }

                groovePainter.end();
                QPixmapCache::insert(groovePixmapName, cache);
            }
            painter->drawPixmap(option->rect.topLeft(), cache);
        }
        break;
    case CE_ScrollBarSubLine:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            QRect scrollBarSubLine = scrollBar->rect;

            bool horizontal = scrollBar->orientation == Qt::Horizontal;
            bool isEnabled = scrollBar->state & State_Enabled;
            bool reverse = scrollBar->direction == Qt::RightToLeft;
            bool sunken = scrollBar->state & State_Sunken;

            // The SubLine (up/left) buttons
            QRect button1;
            QRect button2;
            int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
            if (horizontal)
            {
                button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), scrollBarExtent, scrollBarSubLine.height());
                button2.setRect(scrollBarSubLine.right() - (scrollBarExtent - 1), scrollBarSubLine.top(), scrollBarExtent, scrollBarSubLine.height());
            }
            else
            {
                button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), scrollBarSubLine.width(), scrollBarExtent);
                button2.setRect(scrollBarSubLine.left(), scrollBarSubLine.bottom() - (scrollBarExtent - 1), scrollBarSubLine.width(), scrollBarExtent);
            }

            QString subLinePixmapName = QStyleHelper1::uniqueName(QLatin1String("scrollbar_subline"), option, button1.size());
            QPixmap cache;
            if (!QPixmapCache::find(subLinePixmapName, &cache))
            {
                cache = QPixmap(button1.size());
                cache.fill(Qt::white);
                QRect pixmapRect(0, 0, cache.width(), cache.height());
                QPainter subLinePainter(&cache);
                subLinePainter.fillRect(pixmapRect, option->palette.window());

                if (isEnabled)
                {
                    // Gradients
                    if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
                    {
                        qt_plastique_draw_gradient(&subLinePainter,
                                                   QRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
                                                         pixmapRect.right() - 3, pixmapRect.bottom() - 3),
                                                   gradientStopColor,
                                                   gradientStopColor);
                    }
                    else
                    {
                        qt_plastique_draw_gradient(&subLinePainter,
                                                   QRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
                                                         pixmapRect.right() - 3, pixmapRect.bottom() - 3),
                                                   gradientStartColor.lighter(105),
                                                   gradientStopColor);
                    }
                }

                // Details
                QImage subButton;
                if (horizontal)
                {
                    subButton = QImage(reverse ? qt_scrollbar_button_right : qt_scrollbar_button_left);
                }
                else
                {
                    subButton = QImage(qt_scrollbar_button_up);
                }
                subButton.setColor(1, alphaCornerColor.rgba());
                subButton.setColor(2, borderColor.rgba());
                if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
                {
                    subButton.setColor(3, gradientStopColor.rgba());
                    subButton.setColor(4, gradientStopColor.rgba());
                }
                else
                {
                    subButton.setColor(3, gradientStartColor.lighter(105).rgba());
                    subButton.setColor(4, gradientStopColor.rgba());
                }
                subButton.setColor(5, scrollBar->palette.text().color().rgba());
                subLinePainter.drawImage(pixmapRect, subButton);

                // Arrows
                if (horizontal)
                {
                    QImage arrow(reverse ? qt_scrollbar_button_arrow_right : qt_scrollbar_button_arrow_left);
                    arrow.setColor(1, scrollBar->palette.windowText().color().rgba());

                    if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
                        subLinePainter.translate(1, 1);
                    subLinePainter.drawImage(QPoint(pixmapRect.center().x() - 2, pixmapRect.center().y() - 3), arrow);
                }
                else
                {
                    QImage arrow(qt_scrollbar_button_arrow_up);
                    arrow.setColor(1, scrollBar->palette.windowText().color().rgba());

                    if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
                        subLinePainter.translate(1, 1);
                    subLinePainter.drawImage(QPoint(pixmapRect.center().x() - 3, pixmapRect.center().y() - 2), arrow);
                }
                subLinePainter.end();
                QPixmapCache::insert(subLinePixmapName, cache);
            }
            painter->drawPixmap(button1.topLeft(), cache);
            painter->drawPixmap(button2.topLeft(), cache);
        }
        break;
    case CE_ScrollBarSlider:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            bool horizontal = scrollBar->orientation == Qt::Horizontal;
            bool isEnabled = scrollBar->state & State_Enabled;

            // The slider
            if (option->rect.isValid())
            {
                QString sliderPixmapName = QStyleHelper1::uniqueName(QLatin1String("scrollbar_slider"), option, option->rect.size());
                if (horizontal)
                    sliderPixmapName += QLatin1String("-horizontal");

                QPixmap cache;
                if (!QPixmapCache::find(sliderPixmapName, &cache))
                {
                    cache = QPixmap(option->rect.size());
                    cache.fill(Qt::white);
                    QRect pixmapRect(0, 0, cache.width(), cache.height());
                    QPainter sliderPainter(&cache);
                    bool sunken = (scrollBar->state & State_Sunken);

                    if (isEnabled)
                    {
                        QLinearGradient gradient(pixmapRect.left(), pixmapRect.center().y(),
                                                 pixmapRect.right(), pixmapRect.center().y());
                        if (horizontal)
                            gradient = QLinearGradient(pixmapRect.center().x(), pixmapRect.top(),
                                                       pixmapRect.center().x(), pixmapRect.bottom());

                        if (sunken)
                        {
                            gradient.setColorAt(0, gradientStartColor.lighter(110));
                            gradient.setColorAt(1, gradientStopColor.lighter(105));
                        }
                        else
                        {
                            gradient.setColorAt(0, gradientStartColor.lighter(105));
                            gradient.setColorAt(1, gradientStopColor);
                        }
                        sliderPainter.fillRect(pixmapRect.adjusted(2, 2, -2, -2), gradient);
                    }
                    else
                    {
                        sliderPainter.fillRect(pixmapRect.adjusted(2, 2, -2, -2), option->palette.window());
                    }

                    sliderPainter.setPen(borderColor);
                    sliderPainter.drawRect(pixmapRect.adjusted(0, 0, -1, -1));
                    sliderPainter.setPen(alphaCornerColor);
                    QPoint points[4] = {
                                           QPoint(pixmapRect.left(), pixmapRect.top()),
                                           QPoint(pixmapRect.left(), pixmapRect.bottom()),
                                           QPoint(pixmapRect.right(), pixmapRect.top()),
                                           QPoint(pixmapRect.right(), pixmapRect.bottom()) };
                    sliderPainter.drawPoints(points, 4);

                    QLine lines[2];
                    sliderPainter.setPen(sunken ? gradientStartColor.lighter(110) : gradientStartColor.lighter(105));
                    lines[0] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 1,
                                     pixmapRect.right() - 1, pixmapRect.top() + 1);
                    lines[1] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 2,
                                     pixmapRect.left() + 1, pixmapRect.bottom() - 2);
                    sliderPainter.drawLines(lines, 2);

                    sliderPainter.setPen(sunken ? gradientStopColor.lighter(105) : gradientStopColor);
                    lines[0] = QLine(pixmapRect.left() + 1, pixmapRect.bottom() - 1,
                                     pixmapRect.right() - 1, pixmapRect.bottom() - 1);
                    lines[1] = QLine(pixmapRect.right() - 1, pixmapRect.top() + 2,
                                     pixmapRect.right() - 1, pixmapRect.bottom() - 1);
                    sliderPainter.drawLines(lines, 2);

                    int sliderMinLength = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget);
                    if ((horizontal && scrollBar->rect.width() > sliderMinLength)
                            || (!horizontal && scrollBar->rect.height() > sliderMinLength))
                    {
                        QImage pattern(horizontal ? qt_scrollbar_slider_pattern_horizontal
                                       : qt_scrollbar_slider_pattern_vertical);
                        pattern.setColor(1, alphaCornerColor.rgba());
                        pattern.setColor(2, (sunken ? gradientStartColor.lighter(110) : gradientStartColor.lighter(105)).rgba());

                        if (horizontal)
                        {
                            sliderPainter.drawImage(pixmapRect.center().x() - pattern.width() / 2 + 1,
                                                    pixmapRect.center().y() - 4,
                                                    pattern);
                        }
                        else
                        {
                            sliderPainter.drawImage(pixmapRect.center().x() - 4,
                                                    pixmapRect.center().y() - pattern.height() / 2 + 1,
                                                    pattern);
                        }
                    }
                    sliderPainter.end();
                    // insert the slider into the cache
                    QPixmapCache::insert(sliderPixmapName, cache);
                }
                painter->drawPixmap(option->rect.topLeft(), cache);
            }
        }
        break;
#endif
#ifndef QT_NO_COMBOBOX
    case CE_ComboBoxLabel:
        if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option))
        {
            painter->save();
            if (!comboBox->editable)
            {
                // Plastique's non-editable combo box is drawn as a button, so
                // we need the label to be drawn using ButtonText where it
                // would usually use Text.
                painter->setPen(QPen(comboBox->palette.buttonText(), 0));
                HvPublicStyle::drawControl(element, option, painter, widget);
            }
            else if (!comboBox->currentIcon.isNull())
            {
                {
                    QRect editRect = proxy()->subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
                    if (comboBox->direction == Qt::RightToLeft)
                        editRect.adjust(0, 2, -2, -2);
                    else
                        editRect.adjust(2, 2, 0, -2);
                    painter->save();
                    painter->setClipRect(editRect);
                    if (!comboBox->currentIcon.isNull())
                    {
                        QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal
                                           : QIcon::Disabled;
                        QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
                        QRect iconRect(editRect);
                        iconRect.setWidth(comboBox->iconSize.width() + 5);
                        iconRect = alignedRect(comboBox->direction,
                                               Qt::AlignLeft | Qt::AlignVCenter,
                                               iconRect.size(), editRect);
                        painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
                        proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
                    }
                    painter->restore();
                }
            }
            else
            {
                HvPublicStyle::drawControl(element, option, painter, widget);
            }

            painter->restore();
        }
        break;
#endif
    default:
        HvPublicStyle::drawControl(element, option, painter, widget);
        break;
    }
}

void HvStylePlastique::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    /*if (element == HvPublicStyle::PE_IndicatorBranch)// || QStyle::State_Open|| QStyle::PE_Frame
    {
        painter->save();
        painter->setPen(QPen(QColor(255,207,0), 1, Qt::SolidLine));//vazno da e Qt::SolidLine ina4e nakasva liniata pri lazli4ni razmeri Qt::white, 1, Qt::DashLine
        HvPublicStyle::drawPrimitive(element, option, painter, widget);
        painter->restore();
    }
    HvPublicStyle::drawPrimitive(element, option, painter, widget);
    return;*/

    Q_ASSERT(option);
    //painter->setFont(QApplication::font());

    QColor borderColor = option->palette.window().color().darker(178);
    QColor alphaCornerColor;
    if (widget)
    {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    }
    else
    {
        alphaCornerColor = mergedColors(option->palette.window().color(), borderColor);
    }
    QColor alphaTextColor = mergedColors(option->palette.window().color(), option->palette.text().color());

    switch (element)
    {
    case PE_IndicatorButtonDropDown:
        proxy()->drawPrimitive(PE_PanelButtonTool, option, painter, widget);
        break;
    case PE_FrameDefaultButton:
    {
        if (!(option->state & QStyle::State_Enabled))
            break;
        painter->setPen(QPen(QColor(0, 0, 0, 127), 0));
        const QLine lines[4] =
            {
                QLine(option->rect.left() + 2, option->rect.top(),
                      option->rect.right() - 2, option->rect.top()),
                QLine(option->rect.left() + 2, option->rect.bottom(),
                      option->rect.right() - 2, option->rect.bottom()),
                QLine(option->rect.left(), option->rect.top() + 2,
                      option->rect.left(), option->rect.bottom() - 2),
                QLine(option->rect.right(), option->rect.top() + 2,
                      option->rect.right(), option->rect.bottom() - 2)
            };
        painter->drawLines(lines, 4);

        QPoint points[8];
        points[0] = QPoint(option->rect.left() + 1, option->rect.top() + 1);
        points[1] = QPoint(option->rect.right() - 1, option->rect.top() + 1);
        points[2] = QPoint(option->rect.left() + 1, option->rect.bottom() - 1);
        points[3] = QPoint(option->rect.right() - 1, option->rect.bottom() - 1);
        painter->drawPoints(points, 4);

        painter->setPen(QPen(QColor(0, 0, 0, 63), 0));
        points[0] = QPoint(option->rect.left() + 1, option->rect.top());
        points[1] = QPoint(option->rect.right() - 1, option->rect.top());
        points[2] = QPoint(option->rect.left(), option->rect.top() + 1);
        points[3] = QPoint(option->rect.right(), option->rect.top() + 1);
        points[4] = QPoint(option->rect.left() + 1, option->rect.bottom());
        points[5] = QPoint(option->rect.right() - 1, option->rect.bottom());
        points[6] = QPoint(option->rect.left(), option->rect.bottom() - 1);
        points[7] = QPoint(option->rect.right(), option->rect.bottom() - 1);
        painter->drawPoints(points, 8);

        break;
    }
#ifndef QT_NO_TABWIDGET
    case PE_FrameTabWidget:
        if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option))
        {
            if (twf->shape != QTabBar::RoundedNorth && twf->shape != QTabBar::RoundedWest &&
                    twf->shape != QTabBar::RoundedSouth && twf->shape != QTabBar::RoundedEast)
            {
                HvPublicStyle::drawPrimitive(element, option, painter, widget);
                break;
            }

            int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, twf, widget);
            bool reverse = (twf->direction == Qt::RightToLeft);

            painter->save();

            // Start by filling the contents of the tab widget frame (which is
            // actually a panel).
            painter->fillRect(option->rect.adjusted(1, 1, -1, -1), option->palette.window());

            QRect tabBarRect;
            switch (twf->shape)
            {
            case QTabBar::RoundedNorth:
                if (reverse)
                    tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1, twf->rect.top(), twf->tabBarSize.width(), borderThickness);
                else
                    tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(), twf->rect.top(), twf->tabBarSize.width(), borderThickness);
                break ;
            case QTabBar::RoundedWest:
                tabBarRect = QRect(twf->rect.left(), twf->rect.top() + twf->leftCornerWidgetSize.height(), borderThickness, twf->tabBarSize.height());
                break ;
            case QTabBar::RoundedEast:
                tabBarRect = QRect(twf->rect.right() - borderThickness + 1, twf->rect.top()  + twf->leftCornerWidgetSize.height(),
                                   borderThickness, twf->tabBarSize.height());
                break ;
            case QTabBar::RoundedSouth:
                if (reverse)
                    tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1,
                                       twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness);
                else
                    tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
                                       twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness);
                break ;
            default:
                break;
            }

            QRegion region(twf->rect);
            region -= tabBarRect;
            painter->setClipRegion(region);

            // Outer border
            QLine leftLine = QLine(twf->rect.topLeft() + QPoint(0, 2), twf->rect.bottomLeft() - QPoint(0, 2));
            QLine rightLine = QLine(twf->rect.topRight() + QPoint(0, 2), twf->rect.bottomRight() - QPoint(0, 2));
            QLine bottomLine = QLine(twf->rect.bottomLeft() + QPoint(2, 0), twf->rect.bottomRight() - QPoint(2, 0));
            QLine topLine = QLine(twf->rect.topLeft() + QPoint(2, 0), twf->rect.topRight() - QPoint(2, 0));

            QBrush border = option->palette.shadow();
            qBrushSetAlphaF(&border, qreal(0.4));
            painter->setPen(QPen(border, 0));

            QVarLengthArray<QLine, 4> lines;
            QVarLengthArray<QPoint, 8> points;

            lines.append(topLine);

            // Inner border
            QLine innerLeftLine = QLine(leftLine.p1() + QPoint(1, 0), leftLine.p2() + QPoint(1, 0));
            QLine innerRightLine = QLine(rightLine.p1() - QPoint(1, 0), rightLine.p2() - QPoint(1, 0));
            QLine innerBottomLine = QLine(bottomLine.p1() - QPoint(0, 1), bottomLine.p2() - QPoint(0, 1));
            QLine innerTopLine = QLine(topLine.p1() + QPoint(0, 1), topLine.p2() + QPoint(0, 1));

            // Rounded Corner
            QPoint leftBottomOuterCorner = QPoint(innerLeftLine.p2() + QPoint(0, 1));
            QPoint leftBottomInnerCorner1 = QPoint(leftLine.p2() + QPoint(0, 1));
            QPoint leftBottomInnerCorner2 = QPoint(bottomLine.p1() - QPoint(1, 0));
            QPoint rightBottomOuterCorner = QPoint(innerRightLine.p2() + QPoint(0, 1));
            QPoint rightBottomInnerCorner1 = QPoint(rightLine.p2() + QPoint(0, 1));
            QPoint rightBottomInnerCorner2 = QPoint(bottomLine.p2() + QPoint(1, 0));
            QPoint rightTopOuterCorner = QPoint(innerRightLine.p1() - QPoint(0, 1));
            QPoint rightTopInnerCorner1 = QPoint(rightLine.p1() - QPoint(0, 1));
            QPoint rightTopInnerCorner2 = QPoint(topLine.p2() + QPoint(1, 0));
            QPoint leftTopOuterCorner = QPoint(innerLeftLine.p1() - QPoint(0, 1));
            QPoint leftTopInnerCorner1 = QPoint(leftLine.p1() - QPoint(0, 1));
            QPoint leftTopInnerCorner2 = QPoint(topLine.p1() - QPoint(1, 0));

            lines.append(leftLine);
            lines.append(rightLine);
            lines.append(bottomLine);

            painter->drawLines(lines.constData(), lines.size());
            lines.clear();

            points.append(leftBottomOuterCorner);
            points.append(rightBottomOuterCorner);
            points.append(rightTopOuterCorner);
            points.append(leftTopOuterCorner);

            painter->drawPoints(points.constData(), points.size());
            points.clear();

            QBrush innerTopLeft = option->palette.shadow();
            qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
            painter->setPen(QPen(innerTopLeft, 0));

            lines.append(innerLeftLine);
            lines.append(innerTopLine);
            painter->drawLines(lines.constData(), lines.size());
            lines.clear();

            QBrush innerBottomRight = option->palette.shadow();
            qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
            painter->setPen(QPen(innerBottomRight, 0));
            lines.append(innerRightLine);
            lines.append(innerBottomLine);
            painter->drawLines(lines.constData(), lines.size());
            lines.clear();

            QBrush corner = option->palette.shadow();
            qBrushSetAlphaF(&corner, 0.25);
            painter->setPen(QPen(corner, 0));
            points.append(leftBottomInnerCorner1);
            points.append(leftBottomInnerCorner2);
            points.append(rightBottomInnerCorner1);
            points.append(rightBottomInnerCorner2);
            points.append(rightTopInnerCorner1);
            points.append(rightTopInnerCorner2);
            points.append(leftTopInnerCorner1);
            points.append(leftTopInnerCorner2);
            painter->drawPoints(points.constData(), points.size());
            points.clear();

            painter->restore();
        }
        break ;
#endif // QT_NO_TABWIDGET
#ifndef QT_NO_TABBAR
    case PE_FrameTabBarBase:
        if (const QStyleOptionTabBarBase *tbb = qstyleoption_cast<const QStyleOptionTabBarBase *>(option))
        {
            if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedWest &&
                    tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedEast)
            {
                HvPublicStyle::drawPrimitive(element, option, painter, widget);
                break;
            }

            painter->save();

            QRegion region(tbb->rect);
            region -= tbb->tabBarRect;
            painter->setClipRegion(region);

            QLine topLine = QLine(tbb->rect.bottomLeft() - QPoint(0, 1), tbb->rect.bottomRight() - QPoint(0, 1));
            QLine bottomLine = QLine(tbb->rect.bottomLeft(), tbb->rect.bottomRight());

            QBrush border = option->palette.shadow();
            qBrushSetAlphaF(&border, qreal(0.4));
            QBrush innerTopLeft = option->palette.shadow();
            qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
            QBrush innerBottomRight = option->palette.shadow();
            qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
            QBrush corner = option->palette.shadow();
            qBrushSetAlphaF(&corner, 0.25);

            if (tbb->shape == QTabBar::RoundedSouth)
                painter->setPen(QPen(corner, 0));
            else
                painter->setPen(QPen(border, 0));
            painter->drawLine(topLine);

            if (tbb->shape != QTabBar::RoundedSouth)
                painter->setPen(QPen(innerTopLeft, 0));
            else
                painter->setPen(QPen(border, 0));
            painter->drawLine(bottomLine);

            painter->restore();
        }
        break ;
#endif // QT_NO_TABBAR
#ifndef QT_NO_GROUPBOX //2.26 lz2hv qt5 on
    case PE_FrameGroupBox:
        if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option))
        {
            //QStyleOptionFrameV2 frameV2(*frame);
            //if (frameV2.features & QStyleOptionFrameV2::Flat)
            QStyleOptionFrame frameV2(*frame);
            if (frameV2.features & QStyleOptionFrame::Flat)
            {
                QPen oldPen = painter->pen();
                painter->setPen(borderColor);
                painter->drawLine(frameV2.rect.topLeft(), frameV2.rect.topRight());
                painter->setPen(oldPen);
            }
            else
            {
                frameV2.state &= ~(State_Sunken | State_HasFocus);
                proxy()->drawPrimitive(PE_Frame, &frameV2, painter, widget);
            }
        }
        break;
#endif // QT_NO_GROUPBOX
    case PE_Frame:
    {
        QFrame::Shadow shadow = QFrame::Plain;
        if (option->state & State_Sunken)
            shadow = QFrame::Sunken;
        else if (option->state & State_Raised)
            shadow = QFrame::Raised;
        qt_plastique_draw_frame(painter, option->rect, option, shadow);
        break;
    }
#ifndef QT_NO_LINEEDIT
    case PE_FrameLineEdit:
        qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
        break;
    case PE_PanelLineEdit:
        if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option))
        {
            // Panel of a line edit inside combo box or spin box is drawn in CC_ComboBox and CC_SpinBox
            if (widget)
            {
#ifndef QT_NO_SPINBOX
                // Spinbox doesn't need a separate palette for the lineedit
                if (qobject_cast<const QAbstractSpinBox *>(widget->parentWidget()))
                    break;
#endif
            }

            painter->save();

            // Fill the line edit insides
            QRect filledRect = lineEdit->rect.adjusted(1, 1, -1, -1);
            QBrush baseBrush = qMapBrushToRect(lineEdit->palette.base(), filledRect);
            painter->setBrushOrigin(filledRect.topLeft());
            painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush);

            painter->setPen(QPen(baseBrush, 0));
            const QLine lines[4] =
                {
                    QLine(filledRect.left(), filledRect.top() + 1,
                          filledRect.left(), filledRect.bottom() - 1),
                    QLine(filledRect.right(), filledRect.top() + 1,
                          filledRect.right(), filledRect.bottom() - 1),
                    QLine(filledRect.left() + 1, filledRect.top(),
                          filledRect.right() - 1, filledRect.top()),
                    QLine(filledRect.left() + 1, filledRect.bottom(),
                          filledRect.right() - 1, filledRect.bottom())
                };
            painter->drawLines(lines, 4);

            if (lineEdit->lineWidth > 0)
                qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);

            painter->restore();
            break;
        }
        break;
#endif // QT_NO_LINEEDIT
    case PE_FrameDockWidget:

    case PE_FrameMenu:

    case PE_FrameStatusBarItem:
    {
        // Draws the frame around a popup menu.
        QPen oldPen = painter->pen();
        painter->setPen(borderColor);
        painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
        painter->setPen(alphaCornerColor);
        const QPoint points[4] =
            {
                QPoint(option->rect.topLeft()),
                QPoint(option->rect.topRight()),
                QPoint(option->rect.bottomLeft()),
                QPoint(option->rect.bottomRight())
            };
        painter->drawPoints(points, 4);
        painter->setPen(oldPen);
        break;
    }
#ifdef QT3_SUPPORT
    case PE_Q3DockWindowSeparator:
    {
        QPen oldPen = painter->pen();
        painter->setPen(alphaCornerColor);
        QRect rect = option->rect;
        if (option->state & State_Horizontal)
        {
            painter->drawLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 1);
        }
        else
        {
            painter->drawLine(rect.left() + 2, rect.bottom(), rect.right() - 1, rect.bottom());
        }
        painter->setPen(oldPen);
        break;
    }
    case PE_Q3Separator:
    {
        QPen oldPen = painter->pen();
        painter->setPen(alphaCornerColor);
        if ((option->state & State_Horizontal) == 0)
            painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
        else
            painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
        painter->setPen(option->palette.window().color().lighter(104));
        if ((option->state & State_Horizontal) == 0)
            painter->drawLine(option->rect.topLeft(), option->rect.topRight());
        else
            painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
        painter->setPen(oldPen);
        break;
    }
#endif // QT3_SUPPORT
#ifndef QT_NO_MAINWINDOW
    case PE_PanelMenuBar:
        if ((widget && qobject_cast<const QMainWindow *>(widget->parentWidget()))
#ifdef QT3_SUPPORT
                || (widget && widget->parentWidget() && widget->parentWidget()->inherits("Q3MainWindow"))
#endif
           )
        {
            // Draws the light line above and the dark line below menu bars and
            // tool bars.
            QPen oldPen = painter->pen();
            if (element == PE_PanelMenuBar || (option->state & State_Horizontal))
            {
                painter->setPen(alphaCornerColor);
                painter->drawLine(option->rect.left(), option->rect.bottom(),
                                  option->rect.right(), option->rect.bottom());
                painter->setPen(option->palette.window().color().lighter(104));
                painter->drawLine(option->rect.left(), option->rect.top(),
                                  option->rect.right(), option->rect.top());
            }
            else
            {
                painter->setPen(option->palette.window().color().lighter(104));
                painter->drawLine(option->rect.left(), option->rect.top(),
                                  option->rect.left(), option->rect.bottom());
                painter->setPen(alphaCornerColor);
                painter->drawLine(option->rect.right(), option->rect.top(),
                                  option->rect.right(), option->rect.bottom());
            }
            painter->setPen(oldPen);
            //QFont fff("arial",11);
            //painter->setFont(fff);
        }
        break;
#endif // QT_NO_MAINWINDOW
    case PE_IndicatorHeaderArrow:
    {
        bool usedAntialiasing = painter->renderHints() & QPainter::Antialiasing;
        if (!usedAntialiasing)
            painter->setRenderHint(QPainter::Antialiasing);
        HvPublicStyle::drawPrimitive(element, option, painter, widget);
        if (!usedAntialiasing)
            painter->setRenderHint(QPainter::Antialiasing, false);
        break;
    }
    case PE_PanelButtonTool:
        // Draws a tool button (f.ex., in QToolBar and QTabBar)
        if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise))
            qt_plastique_drawShadedPanel(painter, option, true, widget);
        break;
#ifndef QT_NO_TOOLBAR
    case PE_IndicatorToolBarHandle:
    {
        QPixmap cache;
        QRect rect = option->rect;
#ifdef QT3_SUPPORT
        if (widget && widget->inherits("Q3DockWindowHandle") && widget->parentWidget()->inherits("Q3DockWindow"))
        {
            if (!(option->state & State_Horizontal))
                rect.adjust(2, 0, -2, 0);
        }
#endif
        QString pixmapName = QStyleHelper1::uniqueName(QLatin1String("toolbarhandle"), option, rect.size());
        if (!QPixmapCache::find(pixmapName, &cache))
        {
            cache = QPixmap(rect.size());
            cache.fill(Qt::transparent);
            QPainter cachePainter(&cache);
            QRect cacheRect(QPoint(0, 0), rect.size());
            if (widget)
                cachePainter.fillRect(cacheRect, option->palette.brush(widget->backgroundRole()));
            else
                cachePainter.fillRect(cacheRect, option->palette.window());

            QImage handle(qt_toolbarhandle);
            alphaCornerColor.setAlpha(170);
            handle.setColor(1, alphaCornerColor.rgba());
            handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
            handle.setColor(3, option->palette.light().color().rgba());

            if (option->state & State_Horizontal)
            {
                int nchunks = cacheRect.height() / handle.height();
                int indent = (cacheRect.height() - (nchunks * handle.height())) / 2;
                for (int i = 0; i < nchunks; ++i)
                    cachePainter.drawImage(QPoint(cacheRect.left() + 3, cacheRect.top() + indent + i * handle.height()),
                                           handle);
            }
            else
            {
                int nchunks = cacheRect.width() / handle.width();
                int indent = (cacheRect.width() - (nchunks * handle.width())) / 2;
                for (int i = 0; i < nchunks; ++i)
                    cachePainter.drawImage(QPoint(cacheRect.left() + indent + i * handle.width(), cacheRect.top() + 3),
                                           handle);
            }
            cachePainter.end();
            QPixmapCache::insert(pixmapName, cache);
        }
        painter->drawPixmap(rect.topLeft(), cache);
        break;
    }
    case PE_IndicatorToolBarSeparator:
    {
        QPen oldPen = painter->pen();
        painter->setPen(alphaCornerColor);
        if (option->state & State_Horizontal)
        {
            painter->drawLine(option->rect.left(), option->rect.top() + 1, option->rect.left(), option->rect.bottom() - 2);
            painter->setPen(option->palette.base().color());
            painter->drawLine(option->rect.right(), option->rect.top() + 1, option->rect.right(), option->rect.bottom() - 2);
        }
        else
        {
            painter->drawLine(option->rect.left() + 1, option->rect.top(), option->rect.right() - 2, option->rect.top());
            painter->setPen(option->palette.base().color());
            painter->drawLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 2, option->rect.bottom());
        }
        painter->setPen(oldPen);
        break;
    }
#endif // QT_NO_TOOLBAR
    case PE_PanelButtonCommand:
        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option))
        {
            bool sunken = (button->state & State_Sunken) || (button->state & State_On);
            if ((button->features & QStyleOptionButton::Flat) && !sunken)
                break;

            bool defaultButton = (button->features & (QStyleOptionButton::DefaultButton
                                  | QStyleOptionButton::AutoDefaultButton));

            BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(defaultButton))

            QPen oldPen = p->pen();
            bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);

            // Give the painter a different brush origin for sunken buttons
            if (sunken)
            {
                // ### No such function
                // p->setPenOrigin(rect.left() + 1, rect.top() + 1);
                p->setBrushOrigin(rect.left() + 1, rect.top() + 1);
            }

            // Draw border
            qt_plastique_draw_frame(p, rect, option);

            // Fill the panel
            QRectF fillRect = rect.adjusted(2, 2, -2, -2);

            // Button colors
            QBrush alphaCornerBrush = qMapBrushToRect(qBrushDark(option->palette.button(), 165), rect);
            qBrushSetAlphaF(&alphaCornerBrush, 0.5);
            QBrush buttonGradientBrush;
            QBrush leftLineGradientBrush;
            QBrush rightLineGradientBrush;
            QBrush sunkenButtonGradientBrush;
            QBrush sunkenLeftLineGradientBrush;
            QBrush sunkenRightLineGradientBrush;
            QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
            if (buttonBrush.gradient() || !buttonBrush.texture().isNull())
            {
                buttonGradientBrush = buttonBrush;
                sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108);
                leftLineGradientBrush = qBrushLight(buttonBrush, 105);
                rightLineGradientBrush = qBrushDark(buttonBrush, 105);
                sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110);
                sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106);
            }
            else
            {
                // Generate gradients
                QLinearGradient buttonGradient(rect.topLeft(), rect.bottomLeft());
                if (hover)
                {
                    buttonGradient.setColorAt(0.0, mergedColors(option->palette.highlight().color(),
                                              buttonBrush.color().lighter(104), 6));
                    buttonGradient.setColorAt(1.0, mergedColors(option->palette.highlight().color(),
                                              buttonBrush.color().darker(110), 6));
                }
                else
                {
                    buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
                    buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
                }
                buttonGradientBrush = QBrush(buttonGradient);

                QLinearGradient buttonGradient2(rect.topLeft(), rect.bottomLeft());
                buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113));
                buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103));
                sunkenButtonGradientBrush = QBrush(buttonGradient2);

                QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft());
                buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
                buttonGradient3.setColorAt(1.0, buttonBrush.color());
                leftLineGradientBrush = QBrush(buttonGradient3);

                QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft());
                buttonGradient4.setColorAt(0.0, buttonBrush.color());
                buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
                rightLineGradientBrush = QBrush(buttonGradient4);

                QLinearGradient buttonGradient5(rect.topLeft(), rect.bottomLeft());
                buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113));
                buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107));
                sunkenLeftLineGradientBrush = QBrush(buttonGradient5);

                QLinearGradient buttonGradient6(rect.topLeft(), rect.bottomLeft());
                buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108));
                buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103));
                sunkenRightLineGradientBrush = QBrush(buttonGradient6);
            }

            // Main fill
            p->fillRect(fillRect,
                        qMapBrushToRect(sunken ? sunkenButtonGradientBrush
                                        : buttonGradientBrush, rect));

            // Top line
            p->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
                                       : buttonGradientBrush, rect), 105), 0));
            p->drawLine(QPointF(rect.left() + 2, rect.top() + 1),
                        QPointF(rect.right() - 2, rect.top() + 1));

            // Bottom line
            p->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
                                      : buttonGradientBrush, rect), 105), 0));
            p->drawLine(QPointF(rect.left() + 2, rect.bottom() - 1),
                        QPointF(rect.right() - 2, rect.bottom() - 1));

            // Left line
            p->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush
                                           : leftLineGradientBrush, rect), 1));
            p->drawLine(QPointF(rect.left() + 1, rect.top() + 2),
                        QPointF(rect.left() + 1, rect.bottom() - 2));

            // Right line
            p->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush
                                           : rightLineGradientBrush, rect), 1));
            p->drawLine(QPointF(rect.right() - 1, rect.top() + 2),
                        QPointF(rect.right() - 1, rect.bottom() - 2));

            // Hovering
            if (hover && !sunken)
            {
                QBrush hover = qMapBrushToRect(option->palette.highlight(), rect);
                QBrush hoverOuter = hover;
                qBrushSetAlphaF(&hoverOuter, qreal(0.7));

                QLine lines[2];

                p->setPen(QPen(hoverOuter, 0));
                lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1);
                lines[1] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1);
                p->drawLines(lines, 2);

                QBrush hoverInner = hover;
                qBrushSetAlphaF(&hoverInner, qreal(0.45));
                p->setPen(QPen(hoverInner, 0));
                lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.right() - 1, rect.top() + 2);
                lines[1] = QLine(rect.left() + 1, rect.bottom() - 2, rect.right() - 1, rect.bottom() - 2);
                p->drawLines(lines, 2);

                QBrush hoverSide = hover;
                qBrushSetAlphaF(&hoverSide, qreal(0.075));
                p->setPen(QPen(hoverSide, 0));
                lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
                lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
                p->drawLines(lines, 2);
            }

            p->setPen(oldPen);

            END_STYLE_PIXMAPCACHE
        }
        break;
    case PE_IndicatorCheckBox:
        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option))
        {
            BEGIN_STYLE_PIXMAPCACHE(QLatin1String("checkbox"))

            p->save();

            // Outline
            QBrush border = option->palette.shadow();
            qBrushSetAlphaF(&border, qreal(0.4));
            p->setPen(QPen(border, 0));
            const QLine lines[4] =
                {
                    QLine(rect.left() + 1, rect.top(), rect.right() - 1, rect.top()),
                    QLine(rect.left() + 1, rect.bottom(), rect.right() - 1, rect.bottom()),
                    QLine(rect.left(), rect.top() + 1, rect.left(), rect.bottom() - 1),
                    QLine(rect.right(), rect.top() + 1, rect.right(), rect.bottom() - 1)
                };
            p->drawLines(lines, 4);

            QBrush corner = option->palette.shadow();
            qBrushSetAlphaF(&corner, qreal(0.2));
            p->setPen(QPen(corner, 0));
            const QPoint points[4] =
                {
                    rect.topLeft(), rect.topRight(),
                    rect.bottomLeft(), rect.bottomRight()
                };
            p->drawPoints(points, 4);

            // Fill
            QBrush baseBrush = qMapBrushToRect(button->palette.base(), rect);
            if (!baseBrush.gradient() && baseBrush.texture().isNull())
            {
                QLinearGradient gradient(rect.center().x(), rect.top(), rect.center().x(), rect.bottom());
                gradient.setColorAt(0, baseBrush.color());
                gradient.setColorAt(1, baseBrush.color().darker(105));
                baseBrush = gradient;
            }
            p->fillRect(rect.adjusted(1, 1, -1, -1), baseBrush);

            // Hover
            if ((button->state & State_Enabled) && (button->state & State_MouseOver))
            {
                QBrush pen = qMapBrushToRect(button->palette.highlight(), rect);
                qBrushSetAlphaF(&pen, qreal(0.8));
                p->setPen(QPen(pen, 0));
                p->drawRect(rect.adjusted(1, 1, -2, -2));
                qBrushSetAlphaF(&pen, 0.5);
                p->setPen(QPen(pen, 0));
                p->drawRect(rect.adjusted(2, 2, -3, -3));

                qBrushSetAlphaF(&pen, qreal(0.2));
                p->setBrush(pen);
                p->drawRect(rect.adjusted(2, 2, -3, -3));
            }

            // Indicator
            bool on = button->state & State_On;
            bool sunken = button->state & State_Sunken;
            bool unchanged = button->state & State_NoChange;
            bool enabled = button->state & State_Enabled;
            if (on || (enabled && sunken) || unchanged)
            {
                p->setRenderHint(QPainter::Antialiasing);
                QBrush pointBrush = qMapBrushToRect(button->palette.text(), rect);
                if (sunken)
                    qBrushSetAlphaF(&pointBrush, qreal(0.5));
                else if (unchanged)
                    qBrushSetAlphaF(&pointBrush, qreal(0.3));
                p->setPen(QPen(pointBrush, 3));
                const QLine lines[2] =
                    {
                        QLine(rect.left() + 4, rect.top() + 4, rect.right() - 3, rect.bottom() - 3),
                        QLine(rect.right() - 3, rect.top() + 4, rect.left() + 4, rect.bottom() - 3)
                    };
                p->drawLines(lines, 2);
            }

            p->restore();
            END_STYLE_PIXMAPCACHE
        }
        break;
    case PE_IndicatorRadioButton:
        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option))
        {
            BEGIN_STYLE_PIXMAPCACHE(QLatin1String("radiobutton"))

            p->save();
            p->setRenderHint(QPainter::Antialiasing);

            // The the filled ellipse
            QBrush border = qMapBrushToRect(option->palette.shadow(), rect);
            qBrushSetAlphaF(&border, qreal(0.51));
            p->setPen(QPen(border, 0));

            QBrush baseBrush = qMapBrushToRect(button->palette.base(), rect);
            if (!baseBrush.gradient() && baseBrush.texture().isNull())
            {
                QLinearGradient gradient(rect.center().x(), rect.top(), rect.center().x(), rect.bottom());
                gradient.setColorAt(0, baseBrush.color());
                gradient.setColorAt(1, baseBrush.color().darker(105));
                baseBrush = gradient;
            }
            p->setBrush(baseBrush);
            p->drawEllipse(QRectF(rect).adjusted(1, 1, -1, -1));

            // Hover
            if ((button->state & State_Enabled) && (button->state & State_MouseOver))
            {
                QBrush pen = qMapBrushToRect(button->palette.highlight(), rect);
                qBrushSetAlphaF(&pen, qreal(0.8));
                p->setPen(QPen(pen, 0));
                qBrushSetAlphaF(&pen, qreal(0.2));
                p->setBrush(pen);
                p->drawEllipse(QRectF(rect).adjusted(2, 2, -2, -2));
            }

            // Indicator
            bool on = button->state & State_On;
            bool sunken = button->state & State_Sunken;
            bool enabled = button->state & State_Enabled;
            if (on || (enabled && sunken))
            {
                p->setPen(Qt::NoPen);
                QBrush pointBrush = qMapBrushToRect(button->palette.text(), rect);
                if (sunken)
                    qBrushSetAlphaF(&pointBrush, 0.5);
                p->setBrush(pointBrush);
                p->drawEllipse(QRectF(rect).adjusted(3, 3, -3, -3));
            }

            p->restore();
            END_STYLE_PIXMAPCACHE
        }
        break;
#ifndef QT_NO_DOCKWIDGET
    case PE_IndicatorDockWidgetResizeHandle:
        if ((option->state & State_Enabled) && (option->state & State_MouseOver))
            painter->fillRect(option->rect, QColor(255, 255, 255, 128));
        if (option->state & State_Horizontal)
        {
            int width = option->rect.width() / 3;
            QRect rect(option->rect.center().x() - width / 2,
                       option->rect.top() + (option->rect.height() / 2) - 1, width, 3);
            qt_plastique_draw_handle(painter, option, rect, Qt::Vertical, widget);
        }
        else
        {
            int height = option->rect.height() / 3;
            QRect rect(option->rect.left() + (option->rect.width() / 2 - 1),
                       option->rect.center().y() - height / 2, 3, height);
            qt_plastique_draw_handle(painter, option, rect, Qt::Horizontal, widget);
        }
        break;
    case PE_FrameFocusRect: // punktira na butonite hv
        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(option))
        {
            //### check for d->alt_down
            if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, option))
                return;
            QRect r = option->rect;
            painter->save();
            painter->setBackgroundMode(Qt::TransparentMode);
            QColor bg_col = fropt->backgroundColor;
            if (!bg_col.isValid())
                bg_col = painter->background().color();
            // Create an "XOR" color.
            QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
                              (bg_col.green() ^ 0xff) & 0xff,
                              (bg_col.blue() ^ 0xff) & 0xff,127);// , 127 <- prozra4nost
            painter->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
            painter->setBrushOrigin(r.topLeft());
            painter->setPen(Qt::NoPen);
            //lz2hv stop button rect ......
            painter->drawRect(r.left(), r.top(), r.width(), 1);    // Top
            painter->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
            painter->drawRect(r.left(), r.top(), 1, r.height());   // Left
            painter->drawRect(r.right(), r.top(), 1, r.height());  // Right
            //lz2hv stop button rect end ......
            painter->restore();
        }
        /* if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
              //### check for d->alt_down
              if (!(fropt->state & State_KeyboardFocusChange))
                  return;
              QRect rect = option->rect;

              painter->save();
              painter->setRenderHint(QPainter::Antialiasing, true);
              painter->translate(0.5, 0.5);
              //QColor fillcolor = highlightedOutline;
              QColor fillcolor(255,0,0);
              fillcolor.setAlpha(80);
              painter->setPen(fillcolor.darker(120));
              fillcolor.setAlpha(30);
              QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
              gradient.setColorAt(0, fillcolor.lighter(160));
              gradient.setColorAt(1, fillcolor);
              painter->setBrush(gradient);
              painter->drawRoundedRect(option->rect.adjusted(0, 0, -1, -1), 1, 1);
              painter->restore();
          }*/
        break;
#endif // QT_NO_DOCKWIDGET
    case PE_IndicatorViewItemCheck:
    {
        QStyleOptionButton button;
        button.QStyleOption::operator=(*option);
        button.state &= ~State_MouseOver;
        proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
        break;
    }
    case PE_FrameWindow:
    {
        painter->save();
        bool active = (option->state & State_Active);
        int titleBarStop = option->rect.top() + proxy()->pixelMetric(PM_TitleBarHeight, option, widget);

        QPalette palette = option->palette;
        if (!active)
            palette.setCurrentColorGroup(QPalette::Disabled);

        // Frame and rounded corners
        painter->setPen(mergedColors(palette.highlight().color(), Qt::black, 50));

        QLine lines[3];
        QPoint points[4];

        // bottom border line
        lines[0] = QLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 1, option->rect.bottom());

        // bottom left and right side border lines
        lines[1] = QLine(option->rect.left(), titleBarStop, option->rect.left(), option->rect.bottom() - 1);
        lines[2] = QLine(option->rect.right(), titleBarStop, option->rect.right(), option->rect.bottom() - 1);
        painter->drawLines(lines, 3);
        points[0] = QPoint(option->rect.left() + 1, option->rect.bottom() - 1);
        points[1] = QPoint(option->rect.right() - 1, option->rect.bottom() - 1);
        painter->drawPoints(points, 2);

#ifdef QT3_SUPPORT
        if (widget && widget->inherits("Q3DockWindow"))
        {
            // also draw the frame on the title bar
            lines[0] = QLine(option->rect.left() + 1, option->rect.top(),
                             option->rect.right() - 1, option->rect.top());
            lines[1] = QLine(option->rect.left(), option->rect.top() + 1,
                             option->rect.left(), titleBarStop);
            lines[2] = QLine(option->rect.right(), option->rect.top() + 1,
                             option->rect.right(), titleBarStop);
            painter->drawLines(lines, 3);
        }
#endif

        // alpha corners
        painter->setPen(mergedColors(palette.highlight().color(), palette.window().color(), 55));
        points[0] = QPoint(option->rect.left() + 2, option->rect.bottom() - 1);
        points[1] = QPoint(option->rect.left() + 1, option->rect.bottom() - 2);
        points[2] = QPoint(option->rect.right() - 2, option->rect.bottom() - 1);
        points[3] = QPoint(option->rect.right() - 1, option->rect.bottom() - 2);
        painter->drawPoints(points, 4);

#ifdef QT3_SUPPORT
        if (widget && widget->inherits("Q3DockWindow"))
        {
            // also draw the frame on the title bar
            points[0] = option->rect.topLeft();
            points[1] = option->rect.topRight();
            painter->drawPoints(points, 2);
        }
#endif

        // upper and lower left inner
        painter->setPen(active ? mergedColors(palette.highlight().color(), palette.window().color()) : palette.window().color().darker(120));
        painter->drawLine(option->rect.left() + 1, titleBarStop, option->rect.left() + 1, option->rect.bottom() - 2);

#ifdef QT3_SUPPORT
        if (widget && widget->inherits("Q3DockWindow"))
        {
            // also draw the frame on the title bar
            lines[0] = QLine(option->rect.left() + 1, option->rect.top() + 1,
                             option->rect.left() + 1, titleBarStop);
            lines[1] = QLine(option->rect.right() - 1, option->rect.top() + 1,
                             option->rect.right() - 1, titleBarStop);
            lines[2] = QLine(option->rect.left() + 1, option->rect.top() + 1,
                             option->rect.right() - 1, option->rect.top() + 1);
            painter->drawLines(lines, 3);
        }
#endif

        painter->setPen(active ? mergedColors(palette.highlight().color(), palette.window().color(), 57) : palette.window().color().darker(130));
        lines[0] = QLine(option->rect.right() - 1, titleBarStop, option->rect.right() - 1, option->rect.bottom() - 2);
        lines[1] = QLine(option->rect.left() + 1, option->rect.bottom() - 1, option->rect.right() - 1, option->rect.bottom() - 1);
        painter->drawLines(lines, 2);

        painter->restore();
    }
    break;
    case PE_IndicatorBranch:
    {
        int mid_h = option->rect.x() + option->rect.width() / 2;
        int mid_v = option->rect.y() + option->rect.height() / 2;
        int bef_h = mid_h;
        int bef_v = mid_v;
        int aft_h = mid_h;
        int aft_v = mid_v;
        QBrush brush(option->palette.dark().color(), Qt::Dense4Pattern);
        if (option->state & State_Item)
        {
            if (option->direction == Qt::RightToLeft)
                painter->fillRect(option->rect.left(), mid_v, bef_h - option->rect.left(), 1, brush);
            else
                painter->fillRect(aft_h, mid_v, option->rect.right() - aft_h + 1, 1, brush);
        }
        if (option->state & State_Sibling)
            painter->fillRect(mid_h, aft_v, 1, option->rect.bottom() - aft_v + 1, brush);
        if (option->state & (State_Open | State_Children | State_Item | State_Sibling))
            painter->fillRect(mid_h, option->rect.y(), 1, bef_v - option->rect.y(), brush);

        if (option->state & State_Children)
        {
            painter->save();
            QPoint center = option->rect.center();
            // border
            QRect fullRect(center.x() - 4, center.y() - 4, 9, 9);
            painter->setPen(borderColor);

            const QLine lines[4] =
                {
                    QLine(fullRect.left() + 1, fullRect.top(),
                          fullRect.right() - 1, fullRect.top()),
                    QLine(fullRect.left() + 1, fullRect.bottom(),
                          fullRect.right() - 1, fullRect.bottom()),
                    QLine(fullRect.left(), fullRect.top() + 1,
                          fullRect.left(), fullRect.bottom() - 1),
                    QLine(fullRect.right(), fullRect.top() + 1,
                          fullRect.right(), fullRect.bottom() - 1)
                };
            painter->drawLines(lines, 4);

            // "antialiased" corners
            painter->setPen(alphaCornerColor);
            const QPoint points[4] =
                {
                    fullRect.topLeft(),
                    fullRect.topRight(),
                    fullRect.bottomLeft(),
                    fullRect.bottomRight()
                };
            painter->drawPoints(points, 4);

            // fill
            QRect adjustedRect = fullRect;
            QRect gradientRect(adjustedRect.left() + 1, adjustedRect.top() + 1,
                               adjustedRect.right() - adjustedRect.left() - 1,
                               adjustedRect.bottom() - adjustedRect.top() - 1);
            if (option->palette.base().style() == Qt::SolidPattern)
            {
                QColor baseGradientStartColor = option->palette.base().color().darker(101);
                QColor baseGradientStopColor = option->palette.base().color().darker(106);
                qt_plastique_draw_gradient(painter, gradientRect, baseGradientStartColor, baseGradientStopColor);
            }
            else
            {
                painter->fillRect(gradientRect, option->palette.base());
            }
            // draw "+" or "-"
            painter->setPen(alphaTextColor);
            painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
            if (!(option->state & State_Open))
                painter->drawLine(center.x(), center.y() - 2, center.x(), center.y() + 2);
            painter->restore();
        }

    }
    break;
    default:
        HvPublicStyle::drawPrimitive(element, option, painter, widget);
        break;
    }
}

void HvStylePlastique::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
        QPainter *painter, const QWidget *widget) const
{

    //painter->setFont(QApplication::font());

    QColor borderColor = option->palette.window().color().darker(178);
    QColor alphaCornerColor;
    if (widget)
    {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    }
    else
    {
        alphaCornerColor = mergedColors(option->palette.window().color(), borderColor);
    }
    QColor gradientStartColor = option->palette.button().color().lighter(104);
    QColor gradientStopColor = option->palette.button().color().darker(105);

    switch (control)
    {
#ifndef QT_NO_SLIDER
    case CC_Slider:
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            QRect grooveRegion = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
            QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
            bool horizontal = slider->orientation == Qt::Horizontal;
            bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
            bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;

            QRect groove;
            //The clickable region is 5 px wider than the visible groove for improved usability
            if (grooveRegion.isValid())
                groove = horizontal ? grooveRegion.adjusted(0, 5, 0, -5) : grooveRegion.adjusted(5, 0, -5, 0);


            QPixmap cache;

            if ((option->subControls & SC_SliderGroove) && groove.isValid())
            {
                BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("slider_groove-%0-%1").arg(ticksAbove).arg(ticksBelow))
                p->fillRect(groove, option->palette.window());

                // draw groove
                if (horizontal)
                {
                    p->setPen(borderColor);
                    const QLine lines[4] =
                        {
                            QLine(groove.left() + 1, groove.top(),
                                  groove.right() - 1, groove.top()),
                            QLine(groove.left() + 1, groove.bottom(),
                                  groove.right() - 1, groove.bottom()),
                            QLine(groove.left(), groove.top() + 1,
                                  groove.left(), groove.bottom() - 1),
                            QLine(groove.right(), groove.top() + 1,
                                  groove.right(), groove.bottom() - 1)
                        };
                    p->drawLines(lines, 4);

                    p->setPen(alphaCornerColor);
                    const QPoint points[4] =
                        {
                            QPoint(groove.left(), groove.top()),
                            QPoint(groove.left(), groove.bottom()),
                            QPoint(groove.right(), groove.top()),
                            QPoint(groove.right(), groove.bottom())
                        };
                    p->drawPoints(points, 4);
                }
                else
                {
                    p->setPen(borderColor);
                    const QLine lines[4] =
                        {
                            QLine(groove.left() + 1, groove.top(),
                                  groove.right() - 1, groove.top()),
                            QLine(groove.left() + 1, groove.bottom(),
                                  groove.right() - 1, groove.bottom()),
                            QLine(groove.left(), groove.top() + 1,
                                  groove.left(), groove.bottom() - 1),
                            QLine(groove.right(), groove.top() + 1,
                                  groove.right(), groove.bottom() - 1)
                        };
                    p->drawLines(lines, 4);

                    p->setPen(alphaCornerColor);
                    const QPoint points[4] =
                        {
                            QPoint(groove.left(), groove.top()),
                            QPoint(groove.right(), groove.top()),
                            QPoint(groove.left(), groove.bottom()),
                            QPoint(groove.right(), groove.bottom())
                        };
                    p->drawPoints(points, 4);
                }
                END_STYLE_PIXMAPCACHE
            }

            if ((option->subControls & SC_SliderHandle) && handle.isValid())
            {
                QString handlePixmapName = QStyleHelper1::uniqueName(QLatin1String("slider_handle"), option, handle.size());
                if (ticksAbove && !ticksBelow)
                    handlePixmapName += QLatin1String("-flipped");
                if ((option->activeSubControls & SC_SliderHandle) && (option->state & State_Sunken))
                    handlePixmapName += QLatin1String("-sunken");

                if (!QPixmapCache::find(handlePixmapName, &cache))
                {
                    cache = QPixmap(handle.size());
                    cache.fill(Qt::white);
                    QRect pixmapRect(0, 0, handle.width(), handle.height());
                    QPainter handlePainter(&cache);
                    handlePainter.fillRect(pixmapRect, option->palette.window());

                    // draw handle
                    if (horizontal)
                    {
                        QPainterPath path;
                        if (ticksAbove && !ticksBelow)
                        {
                            path.moveTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
                            path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom() - 10));
                            path.lineTo(QPoint(pixmapRect.right() - 5, pixmapRect.bottom() - 14));
                            path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom() - 10));
                            path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom()));
                            path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
                        }
                        else
                        {
                            path.moveTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
                            path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 10));
                            path.lineTo(QPoint(pixmapRect.right() - 5, pixmapRect.top() + 14));
                            path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 10));
                            path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
                            path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
                        }
                        if (slider->state & State_Enabled)
                        {
                            QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
                                                     pixmapRect.center().x(), pixmapRect.bottom());
                            if ((option->activeSubControls & SC_SliderHandle) && (option->state & State_Sunken))
                            {
                                gradient.setColorAt(0, gradientStartColor.lighter(110));
                                gradient.setColorAt(1, gradientStopColor.lighter(110));
                            }
                            else
                            {
                                gradient.setColorAt(0, gradientStartColor);
                                gradient.setColorAt(1, gradientStopColor);
                            }
                            handlePainter.fillPath(path, gradient);
                        }
                        else
                        {
                            handlePainter.fillPath(path, slider->palette.window());
                        }
                    }
                    else
                    {
                        QPainterPath path;
                        if (ticksAbove && !ticksBelow)
                        {
                            path.moveTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
                            path.lineTo(QPoint(pixmapRect.right() - 10, pixmapRect.top() + 1));
                            path.lineTo(QPoint(pixmapRect.right() - 14, pixmapRect.top() + 5));
                            path.lineTo(QPoint(pixmapRect.right() - 10, pixmapRect.bottom()));
                            path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
                            path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
                        }
                        else
                        {
                            path.moveTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
                            path.lineTo(QPoint(pixmapRect.left() + 10, pixmapRect.top() + 1));
                            path.lineTo(QPoint(pixmapRect.left() + 14, pixmapRect.top() + 5));
                            path.lineTo(QPoint(pixmapRect.left() + 10, pixmapRect.bottom()));
                            path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom()));
                            path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
                        }
                        if (slider->state & State_Enabled)
                        {
                            QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
                                                     pixmapRect.center().x(), pixmapRect.bottom());
                            gradient.setColorAt(0, gradientStartColor);
                            gradient.setColorAt(1, gradientStopColor);
                            handlePainter.fillPath(path, gradient);
                        }
                        else
                        {
                            handlePainter.fillPath(path, slider->palette.window());
                        }
                    }

                    QImage image;
                    if (horizontal)
                    {
                        image = QImage((ticksAbove && !ticksBelow) ? qt_plastique_slider_horizontalhandle_up : qt_plastique_slider_horizontalhandle);
                    }
                    else
                    {
                        image = QImage((ticksAbove && !ticksBelow) ? qt_plastique_slider_verticalhandle_left : qt_plastique_slider_verticalhandle);
                    }

                    image.setColor(1, borderColor.rgba());
                    image.setColor(2, gradientStartColor.rgba());
                    image.setColor(3, alphaCornerColor.rgba());
                    if (option->state & State_Enabled)
                    {
                        image.setColor(4, 0x80ffffff);
                        image.setColor(5, 0x25000000);
                    }
                    handlePainter.drawImage(pixmapRect, image);
                    handlePainter.end();
                    QPixmapCache::insert(handlePixmapName, cache);
                }

                painter->drawPixmap(handle.topLeft(), cache);

                if (slider->state & State_HasFocus)
                {
                    QStyleOptionFocusRect fropt;
                    fropt.QStyleOption::operator=(*slider);
                    fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
                    proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
                }
            }

            if (option->subControls & SC_SliderTickmarks)
            {
                QPen oldPen = painter->pen();
                painter->setPen(borderColor);
                int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
                int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
                int interval = slider->tickInterval;
                if (interval <= 0)
                {
                    interval = slider->singleStep;
                    if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
                                                        available)
                            - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
                                                              0, available) < 3)
                        interval = slider->pageStep;
                }
                if (interval <= 0)
                    interval = 1;

                int v = slider->minimum;
                int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
                QVarLengthArray<QLine, 32> lines;
                while (v <= slider->maximum + 1)
                {
                    if (v == slider->maximum + 1 && interval == 1)
                        break;
                    const int v_ = qMin(v, slider->maximum);
                    int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
                                                      v_, (horizontal
                                                           ? slider->rect.width()
                                                           : slider->rect.height()) - len,
                                                      slider->upsideDown) + len / 2;

                    int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);

                    if (horizontal)
                    {
                        if (ticksAbove)
                        {
                            lines.append(QLine(pos, slider->rect.top() + extra,
                                               pos, slider->rect.top() + tickSize));
                        }
                        if (ticksBelow)
                        {
                            lines.append(QLine(pos, slider->rect.bottom() - extra,
                                               pos, slider->rect.bottom() - tickSize));
                        }
                    }
                    else
                    {
                        if (ticksAbove)
                        {
                            lines.append(QLine(slider->rect.left() + extra, pos,
                                               slider->rect.left() + tickSize, pos));
                        }
                        if (ticksBelow)
                        {
                            lines.append(QLine(slider->rect.right() - extra, pos,
                                               slider->rect.right() - tickSize, pos));
                        }
                    }

                    // in the case where maximum is max int
                    int nextInterval = v + interval;
                    if (nextInterval < v)
                        break;
                    v = nextInterval;
                }
                painter->drawLines(lines.constData(), lines.size());
                painter->setPen(oldPen);
            }
        }
        break;
#endif // QT_NO_SLIDER
#ifndef QT_NO_SPINBOX
    case CC_SpinBox:
        if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option))
        {
            painter->save();
            bool upSunken = (spinBox->activeSubControls & SC_SpinBoxUp) && (spinBox->state & (State_Sunken | State_On));
            bool downSunken = (spinBox->activeSubControls & SC_SpinBoxDown) && (spinBox->state & (State_Sunken | State_On));
            bool reverse = (spinBox->direction == Qt::RightToLeft);

            // Rects
            QRect upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
            QRect downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
            QRect buttonRect = upRect | downRect;

            // Brushes
            QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
            qBrushSetAlphaF(&corner, qreal(0.25));
            QBrush border = qMapBrushToRect(option->palette.shadow(), buttonRect);
            qBrushSetAlphaF(&border, qreal(0.4));

            QVarLengthArray<QPoint, 4> points;

            //Q_D(const HvStylePlastique);
            //if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
            {
                //hv org v1.35 QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
                QRect filledRect = option->rect.adjusted(0, 0, -0, -0);
                QBrush baseBrush = qMapBrushToRect(option->palette.base(), filledRect);
                painter->setBrushOrigin(filledRect.topLeft());
                painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush);
                qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
            }// else {
            // d->drawPartialFrame(painter,
            //  option,
            //  proxy()->subControlRect(CC_SpinBox, spinBox, SC_SpinBoxEditField, widget),
            //  widget);
            //}
            // Paint buttons
            if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
            {
                painter->restore();
                break;
            }
            // Button outlines
            painter->setPen(QPen(border, 0));
            if (!reverse)
                painter->drawLine(buttonRect.topLeft() + QPoint(0, 1), buttonRect.bottomLeft() + QPoint(0, -1));
            else
                painter->drawLine(buttonRect.topRight() + QPoint(0, -1), buttonRect.bottomRight() + QPoint(0, 1));

            if (!reverse)
            {
                const QLine lines[4] =
                    {
                        QLine(upRect.left(), upRect.top(), upRect.right() - 2, upRect.top()),
                        QLine(upRect.left() + 1, upRect.bottom(), upRect.right() - 1, upRect.bottom()),
                        QLine(downRect.left(), downRect.bottom(), downRect.right() - 2, downRect.bottom()),
                        QLine(buttonRect.right(), buttonRect.top() + 2, buttonRect.right(), buttonRect.bottom() - 2)
                    };
                painter->drawLines(lines, 4);

                points.append(QPoint(upRect.right() - 1, upRect.top() + 1));
                points.append(QPoint(downRect.right() - 1, downRect.bottom() - 1));
                painter->drawPoints(points.constData(), points.size());
                points.clear();
                painter->setPen(QPen(corner, 0));
                points.append(QPoint(upRect.right() - 1, upRect.top()));
                points.append(QPoint(upRect.right(), upRect.top() + 1));
                points.append(QPoint(upRect.right(), downRect.bottom() - 1));
                points.append(QPoint(upRect.right() - 1, downRect.bottom()));
            }
            else
            {
                const QLine lines[4] =
                    {
                        QLine(upRect.right(), upRect.top(), upRect.left() + 2, upRect.top()),
                        QLine(upRect.right() - 1, upRect.bottom(), upRect.left() + 1, upRect.bottom()),
                        QLine(downRect.right(), downRect.bottom(), downRect.left() + 2, downRect.bottom()),
                        QLine(buttonRect.left(), buttonRect.top() + 2, buttonRect.left(), buttonRect.bottom() - 2)
                    };
                painter->drawLines(lines, 4);

                points.append(QPoint(upRect.left() + 1, upRect.top() + 1));
                points.append(QPoint(downRect.left() + 1, downRect.bottom() - 1));
                painter->drawPoints(points.constData(), points.size());
                points.clear();
                painter->setPen(QPen(corner, 0));
                points.append(QPoint(upRect.left() + 1, upRect.top()));
                points.append(QPoint(upRect.left(), upRect.top() + 1));
                points.append(QPoint(upRect.left(), downRect.bottom() - 1));
                points.append(QPoint(upRect.left() + 1, downRect.bottom()));
            }
            painter->drawPoints(points.constData(), points.size());
            points.clear();

            // Button colors
            QBrush buttonGradientBrush;
            QBrush leftLineGradientBrush;
            QBrush rightLineGradientBrush;
            QBrush sunkenButtonGradientBrush;
            QBrush sunkenLeftLineGradientBrush;
            QBrush sunkenRightLineGradientBrush;
            QBrush buttonBrush = qMapBrushToRect(option->palette.button(), buttonRect);
            if (buttonBrush.gradient() || !buttonBrush.texture().isNull())
            {
                buttonGradientBrush = buttonBrush;
                sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108);
                leftLineGradientBrush = qBrushLight(buttonBrush, 105);
                rightLineGradientBrush = qBrushDark(buttonBrush, 105);
                sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110);
                sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106);
            }
            else
            {
                // Generate gradients
                QLinearGradient buttonGradient(buttonRect.topLeft(), buttonRect.bottomLeft());
                buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
                buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
                buttonGradientBrush = QBrush(buttonGradient);

                QLinearGradient buttonGradient2(buttonRect.topLeft(), buttonRect.bottomLeft());
                buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113));
                buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103));
                sunkenButtonGradientBrush = QBrush(buttonGradient2);

                QLinearGradient buttonGradient3(buttonRect.topLeft(), buttonRect.bottomLeft());
                buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
                buttonGradient3.setColorAt(1.0, buttonBrush.color());
                leftLineGradientBrush = QBrush(buttonGradient3);

                QLinearGradient buttonGradient4(buttonRect.topLeft(), buttonRect.bottomLeft());
                buttonGradient4.setColorAt(0.0, buttonBrush.color());
                buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
                rightLineGradientBrush = QBrush(buttonGradient4);

                QLinearGradient buttonGradient5(buttonRect.topLeft(), buttonRect.bottomLeft());
                buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113));
                buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107));
                sunkenLeftLineGradientBrush = QBrush(buttonGradient5);

                QLinearGradient buttonGradient6(buttonRect.topLeft(), buttonRect.bottomLeft());
                buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108));
                buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103));
                sunkenRightLineGradientBrush = QBrush(buttonGradient6);
            }

            // Main fill
            painter->fillRect(upRect.adjusted(2, 2, -2, -2),
                              qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
                                              : buttonGradientBrush, upRect));
            painter->fillRect(downRect.adjusted(2, 2, -2, -2),
                              qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
                                              : buttonGradientBrush, downRect));

            // Top line
            painter->setPen(QPen(qBrushLight(qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
                                             : buttonGradientBrush, upRect), 105), 0));
            if (!reverse)
            {
                painter->drawLine(upRect.left() + 1, upRect.top() + 1,
                                  upRect.right() - 2, upRect.top() + 1);
            }
            else
            {
                painter->drawLine(upRect.right() - 1, upRect.top() + 1,
                                  upRect.left() + 2, upRect.top() + 1);
            }
            painter->setPen(QPen(qBrushLight(qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
                                             : buttonGradientBrush, downRect), 105), 0));
            if (!reverse)
            {
                painter->drawLine(downRect.left() + 1, downRect.top() + 1,
                                  downRect.right() - 1, downRect.top() + 1);
            }
            else
            {
                painter->drawLine(downRect.right() - 1, downRect.top() + 1,
                                  downRect.left() + 1, downRect.top() + 1);
            }

            // Left line
            painter->setPen(QPen(qMapBrushToRect(upSunken ? sunkenLeftLineGradientBrush
                                                 : leftLineGradientBrush, upRect), 1));
            if (!reverse)
            {
                painter->drawLine(upRect.left() + 1, upRect.top() + 2,
                                  upRect.left() + 1, upRect.bottom() - 1);
            }
            else
            {
                painter->drawLine(upRect.left() + 1, upRect.top() + 2,
                                  upRect.left() + 1, upRect.bottom() - 1);
            }
            painter->setPen(QPen(qMapBrushToRect(downSunken ? sunkenLeftLineGradientBrush
                                                 : leftLineGradientBrush, downRect), 1));
            if (!reverse)
            {
                painter->drawLine(downRect.left() + 1, downRect.top() + 2,
                                  downRect.left() + 1, downRect.bottom() - 1);
            }
            else
            {
                painter->drawLine(downRect.left() + 1, downRect.top() + 1,
                                  downRect.left() + 1, downRect.bottom() - 2);
            }

            // Bottom line
            painter->setPen(QPen(qBrushDark(qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
                                            : buttonGradientBrush, upRect), 105), 0));
            if (!reverse)
            {
                painter->drawLine(upRect.left() + 2, upRect.bottom() - 1,
                                  upRect.right() - 1, upRect.bottom() - 1);
            }
            else
            {
                painter->drawLine(upRect.right() - 2, upRect.bottom() - 1,
                                  upRect.left() + 1, upRect.bottom() - 1);
            }
            painter->setPen(QPen(qBrushDark(qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
                                            : buttonGradientBrush, downRect), 105), 0));
            if (!reverse)
            {
                painter->drawLine(downRect.left() + 2, downRect.bottom() - 1,
                                  downRect.right() - 2, downRect.bottom() - 1);
            }
            else
            {
                painter->drawLine(downRect.right() - 2, downRect.bottom() - 1,
                                  downRect.left() + 2, downRect.bottom() - 1);
            }

            // Right line
            painter->setPen(QPen(qMapBrushToRect(upSunken ? sunkenRightLineGradientBrush
                                                 : rightLineGradientBrush, upRect), 1));
            if (!reverse)
            {
                painter->drawLine(upRect.right() - 1, upRect.top() + 2,
                                  upRect.right() - 1, upRect.bottom() - 1);
            }
            else
            {
                painter->drawLine(upRect.right() - 1, upRect.top() + 2,
                                  upRect.right() - 1, upRect.bottom() - 1);
            }
            painter->setPen(QPen(qMapBrushToRect(downSunken ? sunkenRightLineGradientBrush
                                                 : rightLineGradientBrush, downRect), 1));
            if (!reverse)
            {
                painter->drawLine(downRect.right() - 1, downRect.top() + 1,
                                  downRect.right() - 1, downRect.bottom() - 2);
            }
            else
            {
                painter->drawLine(downRect.right() - 1, downRect.top() + 2,
                                  downRect.right() - 1, downRect.bottom() - 1);
            }

            QBrush indicatorBrush = qMapBrushToRect(option->palette.buttonText(), buttonRect);
            painter->setPen(QPen(indicatorBrush, 0));
            if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus)
            {
                QPoint center;
                if (spinBox->subControls & SC_SpinBoxUp)
                {
                    // .......
                    // ...X...
                    // ...X...
                    // .XXXXX.
                    // ...X...
                    // ...X...
                    // .......
                    center = upRect.center();
                    if (upSunken)
                    {
                        ++center.rx();
                        ++center.ry();
                    }
                    painter->drawLine(center.x(), center.y() - 2, center.x(), center.y() + 2);
                    painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
                }
                if (spinBox->subControls & SC_SpinBoxDown)
                {
                    // .......
                    // .......
                    // .......
                    // .XXXXX.
                    // .......
                    // .......
                    // .......
                    center = downRect.center();
                    if (downSunken)
                    {
                        ++center.rx();
                        ++center.ry();
                    }
                    painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
                }
            }
            else
            {
                int offset;
                int centerX;
                if (spinBox->subControls & SC_SpinBoxUp)
                {
                    // ...........
                    // .....X.....
                    // ....XXX....
                    // ...XXXXX...
                    // ..XXXXXXX..
                    // ...........
                    offset = upSunken ? 1 : 0;
                    QRect upArrowRect(upRect.center().x() - 3 + offset, upRect.center().y() - 2 + offset, 7, 4);
                    centerX = upArrowRect.center().x();
                    painter->drawPoint(centerX, upArrowRect.top());
                    const QLine lines[3] =
                        {
                            QLine(centerX - 1, upArrowRect.top() + 1, centerX + 1, upArrowRect.top() + 1),
                            QLine(centerX - 2, upArrowRect.top() + 2, centerX + 2, upArrowRect.top() + 2),
                            QLine(centerX - 3, upArrowRect.top() + 3, centerX + 3, upArrowRect.top() + 3)
                        };
                    painter->drawLines(lines, 3);
                }
                if (spinBox->subControls & SC_SpinBoxDown)
                {
                    // ...........
                    // ..XXXXXXX..
                    // ...XXXXX...
                    // ....XXX....
                    // .....X.....
                    // ...........
                    offset = downSunken ? 1 : 0;
                    QRect downArrowRect(downRect.center().x() - 3 + offset, downRect.center().y() - 2 + offset + 1, 7, 4);
                    centerX = downArrowRect.center().x();
                    const QLine lines[3] =
                        {
                            QLine(centerX - 3, downArrowRect.top(), centerX + 3, downArrowRect.top()),
                            QLine(centerX - 2, downArrowRect.top() + 1, centerX + 2, downArrowRect.top() + 1),
                            QLine(centerX - 1, downArrowRect.top() + 2, centerX + 1, downArrowRect.top() + 2)
                        };
                    painter->drawLines(lines, 3);
                    painter->drawPoint(centerX, downArrowRect.top() + 3);
                }
            }
            painter->restore();
        }
        break;
#endif // QT_NO_SPINBOX

#ifndef QT_NO_COMBOBOX
    case CC_ComboBox:
        if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option))
        {
            bool sunken = comboBox->state & State_On; // play dead if combobox has no items
            bool reverse = comboBox->direction == Qt::RightToLeft;
            int menuButtonWidth = 16;
            int xoffset = sunken ? (reverse ? -1 : 1) : 0;
            int yoffset = sunken ? 1 : 0;
            QRect rect = comboBox->rect;
            QPen oldPen = painter->pen();

            // Fill
            if (comboBox->editable)
            {
                // Button colors
                QBrush alphaCornerBrush = qBrushDark(option->palette.button(), 165);
                qBrushSetAlphaF(&alphaCornerBrush, 0.5);
                QBrush buttonGradientBrush;
                QBrush leftLineGradientBrush;
                QBrush rightLineGradientBrush;
                QBrush sunkenButtonGradientBrush;
                QBrush sunkenLeftLineGradientBrush;
                QBrush sunkenRightLineGradientBrush;
                QBrush button = option->palette.button();
                if (button.gradient() || !button.texture().isNull())
                {
                    buttonGradientBrush = button;
                    sunkenButtonGradientBrush = qBrushDark(button, 108);
                    leftLineGradientBrush = qBrushLight(button, 105);
                    rightLineGradientBrush = qBrushDark(button, 105);
                    sunkenLeftLineGradientBrush = qBrushDark(button, 110);
                    sunkenRightLineGradientBrush = qBrushDark(button, 106);
                }
                else
                {
                    // Generate gradients
                    QLinearGradient buttonGradient(option->rect.topLeft(), option->rect.bottomLeft());
                    buttonGradient.setColorAt(0.0, button.color().lighter(104));
                    buttonGradient.setColorAt(1.0, button.color().darker(110));
                    buttonGradientBrush = QBrush(buttonGradient);

                    QLinearGradient buttonGradient2(option->rect.topLeft(), option->rect.bottomLeft());
                    buttonGradient2.setColorAt(0.0, button.color().darker(113));
                    buttonGradient2.setColorAt(1.0, button.color().darker(103));
                    sunkenButtonGradientBrush = QBrush(buttonGradient2);

                    QLinearGradient buttonGradient3(option->rect.topLeft(), option->rect.bottomLeft());
                    buttonGradient3.setColorAt(0.0, button.color().lighter(105));
                    buttonGradient3.setColorAt(1.0, button.color());
                    leftLineGradientBrush = QBrush(buttonGradient3);

                    QLinearGradient buttonGradient4(option->rect.topLeft(), option->rect.bottomLeft());
                    buttonGradient4.setColorAt(0.0, button.color());
                    buttonGradient4.setColorAt(1.0, button.color().darker(110));
                    rightLineGradientBrush = QBrush(buttonGradient4);

                    QLinearGradient buttonGradient5(option->rect.topLeft(), option->rect.bottomLeft());
                    buttonGradient5.setColorAt(0.0, button.color().darker(113));
                    buttonGradient5.setColorAt(1.0, button.color().darker(107));
                    sunkenLeftLineGradientBrush = QBrush(buttonGradient5);

                    QLinearGradient buttonGradient6(option->rect.topLeft(), option->rect.bottomLeft());
                    buttonGradient6.setColorAt(0.0, button.color().darker(108));
                    buttonGradient6.setColorAt(1.0, button.color().darker(103));
                    sunkenRightLineGradientBrush = QBrush(buttonGradient6);
                }

                // ComboBox starts with a lineedit in place already.
                QRect buttonRect;
                if (!reverse)
                {
                    buttonRect.setRect(rect.right() - menuButtonWidth, rect.top(), menuButtonWidth + 1, rect.height());
                }
                else
                {
                    buttonRect.setRect(rect.left(), rect.top(), menuButtonWidth + 1, rect.height());
                }

                /* Q_D(const HvStylePlastique);
                 d->drawPartialFrame(painter,
                                 option,
                                 proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget),
                                 widget);*/

                QBrush border = qMapBrushToRect(option->palette.shadow(), buttonRect);
                qBrushSetAlphaF(&border, qreal(0.4));
                painter->setPen(QPen(border, 0));
                if (!reverse)
                    painter->drawLine(buttonRect.topLeft() + QPoint(0, 1), buttonRect.bottomLeft() + QPoint(0, -1));
                else
                    painter->drawLine(buttonRect.topRight() + QPoint(0, -1), buttonRect.bottomRight() + QPoint(0, 1));

                // Outline the button border
                if (!reverse)
                {
                    const QLine lines[3] =
                        {
                            QLine(buttonRect.left(), buttonRect.top(),
                                  buttonRect.right() - 2, buttonRect.top()),
                            QLine(buttonRect.right(), buttonRect.top() + 2,
                                  buttonRect.right(), buttonRect.bottom() - 2),
                            QLine(buttonRect.left(), buttonRect.bottom(),
                                  buttonRect.right() - 2, buttonRect.bottom())
                        };
                    painter->drawLines(lines, 3);
                    {
                        const QPoint points[2] =
                            {
                                QPoint(buttonRect.right() - 1, buttonRect.top() + 1),
                                QPoint(buttonRect.right() - 1, buttonRect.bottom() - 1)
                            };
                        painter->drawPoints(points, 2);
                    }

                    QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
                    qBrushSetAlphaF(&corner, qreal(0.16));
                    painter->setPen(QPen(corner, 0));
                    {
                        const QPoint points[4] =
                            {
                                QPoint(buttonRect.right() - 1, buttonRect.top()),
                                QPoint(buttonRect.right() - 1, buttonRect.bottom()),
                                QPoint(buttonRect.right(), buttonRect.top() + 1),
                                QPoint(buttonRect.right(), buttonRect.bottom() - 1)
                            };
                        painter->drawPoints(points, 4);
                    }
                }
                else
                {
                    const QLine lines[3] =
                        {
                            QLine(buttonRect.right(), buttonRect.top(),
                                  buttonRect.left() + 2, buttonRect.top()),
                            QLine(buttonRect.left(), buttonRect.top() + 2,
                                  buttonRect.left(), buttonRect.bottom() - 2),
                            QLine(buttonRect.right(), buttonRect.bottom(),
                                  buttonRect.left() + 2, buttonRect.bottom())
                        };
                    painter->drawLines(lines, 3);
                    {
                        const QPoint points[2] =
                            {
                                QPoint(buttonRect.left() + 1, buttonRect.top() + 1),
                                QPoint(buttonRect.left() + 1, buttonRect.bottom() - 1)
                            };
                        painter->drawPoints(points, 2);
                    }

                    QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
                    qBrushSetAlphaF(&corner, qreal(0.16));
                    painter->setPen(QPen(corner, 0));
                    {
                        const QPoint points[4] =
                            {
                                QPoint(buttonRect.left() + 1, buttonRect.top()),
                                QPoint(buttonRect.left() + 1, buttonRect.bottom()),
                                QPoint(buttonRect.left(), buttonRect.top() + 1),
                                QPoint(buttonRect.left(), buttonRect.bottom() - 1)
                            };
                        painter->drawPoints(points, 4);
                    }
                }

                QRect fillRect = buttonRect.adjusted(2, 2, -2, -2);
                // Main fill
                painter->fillRect(fillRect,
                                  qMapBrushToRect(sunken ? sunkenButtonGradientBrush
                                                  : buttonGradientBrush, option->rect));

                // Top line
                painter->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
                                                 : buttonGradientBrush, option->rect), 105), 0));
                if (!reverse)
                {
                    painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 1),
                                      QPointF(buttonRect.right() - 2, buttonRect.top() + 1));
                }
                else
                {
                    painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 1),
                                      QPointF(buttonRect.left() + 2, buttonRect.top() + 1));
                }

                // Bottom line
                painter->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
                                                : buttonGradientBrush, option->rect), 105), 0));
                if (!reverse)
                {
                    painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.bottom() - 1),
                                      QPointF(buttonRect.right() - 2, buttonRect.bottom() - 1));
                }
                else
                {
                    painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.bottom() - 1),
                                      QPointF(buttonRect.left() + 2, buttonRect.bottom() - 1));
                }

                // Left line
                painter->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush
                                                     : leftLineGradientBrush, option->rect), 1));
                if (!reverse)
                {
                    painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 2),
                                      QPointF(buttonRect.left() + 1, buttonRect.bottom() - 2));
                }
                else
                {
                    painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 2),
                                      QPointF(buttonRect.left() + 1, buttonRect.bottom() - 2));
                }

                // Right line
                painter->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush
                                                     : rightLineGradientBrush, option->rect), 1));
                if (!reverse)
                {
                    painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 2),
                                      QPointF(buttonRect.right() - 1, buttonRect.bottom() - 2));
                }
                else
                {
                    painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 2),
                                      QPointF(buttonRect.right() - 1, buttonRect.bottom() - 2));
                }
            }
            else
            {
                // Start with a standard panel button fill
                QStyleOptionButton buttonOption;
                buttonOption.QStyleOption::operator=(*comboBox);
                if (!sunken)
                {
                    buttonOption.state &= ~State_Sunken;
                }
                proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);

                // Draw the menu button separator line
                QBrush border = qMapBrushToRect(option->palette.shadow(), rect);
                qBrushSetAlphaF(&border, qreal(0.35));
                painter->setPen(QPen(border, 0));
                if (!reverse)
                {
                    painter->drawLine(rect.right() - menuButtonWidth + xoffset, rect.top() + 1,
                                      rect.right() - menuButtonWidth + xoffset, rect.bottom() - 1);
                }
                else
                {
                    painter->drawLine(rect.left() + menuButtonWidth + xoffset, rect.top() + 1,
                                      rect.left() + menuButtonWidth + xoffset, rect.bottom() - 1);
                }
            }

            // Draw the little arrow
            if (comboBox->subControls & SC_ComboBoxArrow)
            {
                int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
                int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
                QRect arrowRect((left + right) / 2 - 3 + xoffset,
                                rect.center().y() - 1 + yoffset, 7, 4);
                painter->setPen(QPen(qMapBrushToRect(option->palette.buttonText(), rect), 0));
                const QLine lines[3] =
                    {
                        QLine(arrowRect.topLeft(), arrowRect.topRight()),
                        QLine(arrowRect.left() + 1, arrowRect.top() + 1,
                              arrowRect.right() - 1, arrowRect.top() + 1),
                        QLine(arrowRect.left() + 2, arrowRect.top() + 2,
                              arrowRect.right() - 2, arrowRect.top() + 2)
                    };
                painter->drawLines(lines, 3);
                painter->drawPoint(arrowRect.center().x(), arrowRect.bottom());
            }

            // Draw the focus rect
            if ((option->state & State_HasFocus) && !comboBox->editable
                    && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget)))
            {
                QStyleOptionFocusRect focus;
                focus.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget)
                             .adjusted(-2, 0, 2, 0);
                proxy()->drawPrimitive(PE_FrameFocusRect, &focus, painter, widget);
            }

            painter->setPen(oldPen);
        }
        break;
#endif // QT_NO_COMBOBOX
    case CC_TitleBar:
        if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option))
        {
            painter->save();
            bool active = (titleBar->titleBarState & State_Active);
            QRect fullRect = titleBar->rect;

            // ### use palette colors instead
            QColor titleBarGradientStart(active ? 0x3b508a : 0x6e6e6e);
            QColor titleBarGradientStop(active ? 0x5d6e9e : 0x818181);
            QColor titleBarFrameBorder(0x393939);
            QColor titleBarAlphaCorner(active ? 0x4b5e7f : 0x6a6a6a);
            QColor titleBarInnerTopLine(active ? 0x8e98ba : 0xa4a4a4);
            QColor titleBarInnerInnerTopLine(active ? 0x57699b : 0x808080);
            QColor leftCorner(active ? 0x6f7ea8 : 0x8e8e8e);
            QColor rightCorner(active ? 0x44537d : 0x676767);
            QColor textColor(active ? 0x282e40 : 0x282e40);
            QColor textAlphaColor(active ? 0x3f4862 : 0x3f4862);

#ifdef  QT3_SUPPORT
            if (widget && widget->inherits("Q3DockWindowTitleBar"))
            {
                QStyleOptionDockWidgetV2 dockwidget;
                dockwidget.QStyleOption::operator=(*option);
                dockwidget.title = titleBar->text;
                proxy()->drawControl(CE_DockWidgetTitle, &dockwidget, painter, widget);
            }
            else
#endif // QT3_SUPPORT

            {
                // Fill title bar gradient
                qt_plastique_draw_gradient(painter, option->rect.adjusted(1, 1, -1, 0),
                                           titleBarGradientStart,
                                           titleBarGradientStop);

                // Frame and rounded corners
                painter->setPen(titleBarFrameBorder);

                // top border line
                {
                    const QLine lines[3] =
                        {
                            QLine(fullRect.left() + 2, fullRect.top(), fullRect.right() - 2, fullRect.top()),
                            QLine(fullRect.left(), fullRect.top() + 2, fullRect.left(), fullRect.bottom()),
                            QLine(fullRect.right(), fullRect.top() + 2, fullRect.right(), fullRect.bottom())
                        };
                    painter->drawLines(lines, 3);
                    const QPoint points[2] =
                        {
                            QPoint(fullRect.left() + 1, fullRect.top() + 1),
                            QPoint(fullRect.right() - 1, fullRect.top() + 1)
                        };
                    painter->drawPoints(points, 2);
                }

                // alpha corners
                painter->setPen(titleBarAlphaCorner);
                {
                    const QPoint points[4] =
                        {
                            QPoint(fullRect.left() + 2, fullRect.top() + 1),
                            QPoint(fullRect.left() + 1, fullRect.top() + 2),
                            QPoint(fullRect.right() - 2, fullRect.top() + 1),
                            QPoint(fullRect.right() - 1, fullRect.top() + 2)
                        };
                    painter->drawPoints(points, 4);
                }

                // inner top line
                painter->setPen(titleBarInnerTopLine);
                painter->drawLine(fullRect.left() + 3, fullRect.top() + 1, fullRect.right() - 3, fullRect.top() + 1);

                // inner inner top line
                painter->setPen(titleBarInnerInnerTopLine);
                painter->drawLine(fullRect.left() + 2, fullRect.top() + 2, fullRect.right() - 2, fullRect.top() + 2);

                // left and right inner
                painter->setPen(leftCorner);
                painter->drawLine(fullRect.left() + 1, fullRect.top() + 3, fullRect.left() + 1, fullRect.bottom());
                painter->setPen(rightCorner);
                painter->drawLine(fullRect.right() - 1, fullRect.top() + 3, fullRect.right() - 1, fullRect.bottom());

                if (titleBar->titleBarState & Qt::WindowMinimized)
                {
                    painter->setPen(titleBarFrameBorder);
                    painter->drawLine(fullRect.left() + 2, fullRect.bottom(), fullRect.right() - 2, fullRect.bottom());
                    {
                        const QPoint points[2] =
                            {
                                QPoint(fullRect.left() + 1, fullRect.bottom() - 1),
                                QPoint(fullRect.right() - 1, fullRect.bottom() - 1)
                            };
                        painter->drawPoints(points, 2);
                    }
                    painter->setPen(rightCorner);
                    painter->drawLine(fullRect.left() + 2, fullRect.bottom() - 1, fullRect.right() - 2, fullRect.bottom() - 1);
                    painter->setPen(titleBarAlphaCorner);
                    {
                        const QPoint points[4] =
                            {
                                QPoint(fullRect.left() + 1, fullRect.bottom() - 2),
                                QPoint(fullRect.left() + 2, fullRect.bottom() - 1),
                                QPoint(fullRect.right() - 1, fullRect.bottom() - 2),
                                QPoint(fullRect.right() - 2, fullRect.bottom() - 1)
                            };
                        painter->drawPoints(points, 4);
                    }
                }
                // draw title
                QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);

                QFont font = painter->font();
                font.setBold(true);
                painter->setFont(font);
                painter->setPen(titleBar->palette.text().color());

                // Attempt to align left if there is not enough room for the title
                // text. Otherwise, align center. QWorkspace does elliding for us,
                // and it doesn't know about the bold title, so we need to work
                // around some of the width mismatches.
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
                bool tooWide = (QFontMetrics(font).horizontalAdvance(titleBar->text) > textRect.width());//2.56
#else
                bool tooWide = (QFontMetrics(font).width(titleBar->text) > textRect.width());//2.56
#endif
                QTextOption option((tooWide ? Qt::AlignLeft : Qt::AlignHCenter) | Qt::AlignVCenter);
                option.setWrapMode(QTextOption::NoWrap);

                painter->drawText(textRect.adjusted(1, 1, 1, 1), titleBar->text, option);
                painter->setPen(titleBar->palette.highlightedText().color());
                painter->drawText(textRect, titleBar->text, option);
            }

            // min button
            if ((titleBar->subControls & SC_TitleBarMinButton)
                    && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint)
                    && !(titleBar->titleBarState & Qt::WindowMinimized))
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);

                QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
                qt_plastique_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);

                int xoffset = minButtonRect.width() / 3;
                int yoffset = minButtonRect.height() / 3;

                QRect minButtonIconRect(minButtonRect.left() + xoffset, minButtonRect.top() + yoffset,
                                        minButtonRect.width() - xoffset * 2, minButtonRect.height() - yoffset * 2);

                painter->setPen(textColor);
                {
                    const QLine lines[2] =
                        {
                            QLine(minButtonIconRect.center().x() - 2,
                                  minButtonIconRect.center().y() + 3,
                                  minButtonIconRect.center().x() + 3,
                                  minButtonIconRect.center().y() + 3),
                            QLine(minButtonIconRect.center().x() - 2,
                                  minButtonIconRect.center().y() + 4,
                                  minButtonIconRect.center().x() + 3,
                                  minButtonIconRect.center().y() + 4)
                        };
                    painter->drawLines(lines, 2);
                }
                painter->setPen(textAlphaColor);
                {
                    const QLine lines[2] =
                        {
                            QLine(minButtonIconRect.center().x() - 3,
                                  minButtonIconRect.center().y() + 3,
                                  minButtonIconRect.center().x() - 3,
                                  minButtonIconRect.center().y() + 4),
                            QLine(minButtonIconRect.center().x() + 4,
                                  minButtonIconRect.center().y() + 3,
                                  minButtonIconRect.center().x() + 4,
                                  minButtonIconRect.center().y() + 4)
                        };
                    painter->drawLines(lines, 2);
                }
            }

            // max button
            if ((titleBar->subControls & SC_TitleBarMaxButton)
                    && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint)
                    && !(titleBar->titleBarState & Qt::WindowMaximized))
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);

                QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
                qt_plastique_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);

                int xoffset = maxButtonRect.width() / 3;
                int yoffset = maxButtonRect.height() / 3;

                QRect maxButtonIconRect(maxButtonRect.left() + xoffset, maxButtonRect.top() + yoffset,
                                        maxButtonRect.width() - xoffset * 2, maxButtonRect.height() - yoffset * 2);

                painter->setPen(textColor);
                painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
                painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
                                  maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
                painter->setPen(textAlphaColor);
                const QPoint points[4] =
                    {
                        maxButtonIconRect.topLeft(), maxButtonIconRect.topRight(),
                        maxButtonIconRect.bottomLeft(), maxButtonIconRect.bottomRight()
                    };
                painter->drawPoints(points, 4);
            }

            // close button
            if (titleBar->subControls & SC_TitleBarCloseButton && titleBar->titleBarFlags & Qt::WindowSystemMenuHint)
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);

                QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
                qt_plastique_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);

                int xoffset = closeButtonRect.width() / 3;
                int yoffset = closeButtonRect.height() / 3;

                QRect closeIconRect(closeButtonRect.left() + xoffset, closeButtonRect.top() + yoffset,
                                    closeButtonRect.width() - xoffset * 2, closeButtonRect.height() - yoffset * 2);

                painter->setPen(textAlphaColor);
                {
                    const QLine lines[4] =
                        {
                            QLine(closeIconRect.left() + 1, closeIconRect.top(),
                                  closeIconRect.right(), closeIconRect.bottom() - 1),
                            QLine(closeIconRect.left(), closeIconRect.top() + 1,
                                  closeIconRect.right() - 1, closeIconRect.bottom()),
                            QLine(closeIconRect.right() - 1, closeIconRect.top(),
                                  closeIconRect.left(), closeIconRect.bottom() - 1),
                            QLine(closeIconRect.right(), closeIconRect.top() + 1,
                                  closeIconRect.left() + 1, closeIconRect.bottom())
                        };
                    painter->drawLines(lines, 4);
                    const QPoint points[4] =
                        {
                            closeIconRect.topLeft(), closeIconRect.topRight(),
                            closeIconRect.bottomLeft(), closeIconRect.bottomRight()
                        };
                    painter->drawPoints(points, 4);
                }
                painter->setPen(textColor);
                {
                    const QLine lines[2] =
                        {
                            QLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
                                  closeIconRect.right() - 1, closeIconRect.bottom() - 1),
                            QLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
                                  closeIconRect.right() - 1, closeIconRect.top() + 1)
                        };
                    painter->drawLines(lines, 2);
                }
            }

            // normalize button
            if ((titleBar->subControls & SC_TitleBarNormalButton) &&
                    (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
                      (titleBar->titleBarState & Qt::WindowMinimized)) ||
                     ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
                      (titleBar->titleBarState & Qt::WindowMaximized))))
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);

                QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
                qt_plastique_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
                int xoffset = int(normalButtonRect.width() / 3.5);
                int yoffset = int(normalButtonRect.height() / 3.5);

                QRect normalButtonIconRect(normalButtonRect.left() + xoffset, normalButtonRect.top() + yoffset,
                                           normalButtonRect.width() - xoffset * 2, normalButtonRect.height() - yoffset * 2);

                QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
                painter->setPen(textColor);
                painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
                painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
                                  frontWindowRect.right() - 1, frontWindowRect.top() + 1);
                painter->setPen(textAlphaColor);
                {
                    const QPoint points[4] =
                        {
                            frontWindowRect.topLeft(), frontWindowRect.topRight(),
                            frontWindowRect.bottomLeft(), frontWindowRect.bottomRight()
                        };
                    painter->drawPoints(points, 4);
                }

                QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
                QRegion clipRegion = backWindowRect;
                clipRegion -= frontWindowRect;
                painter->save();
                painter->setClipRegion(clipRegion);
                painter->setPen(textColor);
                painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
                painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
                                  backWindowRect.right() - 1, backWindowRect.top() + 1);
                painter->setPen(textAlphaColor);
                {
                    const QPoint points[4] =
                        {
                            backWindowRect.topLeft(), backWindowRect.topRight(),
                            backWindowRect.bottomLeft(), backWindowRect.bottomRight()
                        };
                    painter->drawPoints(points, 4);
                }
                painter->restore();
            }

            // context help button
            if (titleBar->subControls & SC_TitleBarContextHelpButton
                    && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint))
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);

                QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);

                qt_plastique_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);

                QColor blend;
                // ### Use palette colors
                if (active)
                {
                    blend = mergedColors(QColor(hover ? 0x7d8bb1 : 0x55689a),
                                         QColor(hover ? 0x939ebe : 0x7381ab));
                }
                else
                {
                    blend = mergedColors(QColor(hover ? 0x9e9e9e : 0x818181),
                                         QColor(hover ? 0xababab : 0x929292));
                }
                QImage image(qt_titlebar_context_help);
                image.setColor(4, textColor.rgba());
                image.setColor(3, mergedColors(blend, textColor, 30).rgba());
                image.setColor(2, mergedColors(blend, textColor, 70).rgba());
                image.setColor(1, mergedColors(blend, textColor, 90).rgba());

                painter->drawImage(contextHelpButtonRect, image);
            }

            // shade button
            if (titleBar->subControls & SC_TitleBarShadeButton)
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);

                QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
                qt_plastique_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);

                int xoffset = shadeButtonRect.width() / 3;
                int yoffset = shadeButtonRect.height() / 3;

                QRect shadeButtonIconRect(shadeButtonRect.left() + xoffset, shadeButtonRect.top() + yoffset,
                                          shadeButtonRect.width() - xoffset * 2, shadeButtonRect.height() - yoffset * 2);

                QPainterPath path(shadeButtonIconRect.bottomLeft());
                path.lineTo(shadeButtonIconRect.center().x(), shadeButtonIconRect.bottom() - shadeButtonIconRect.height() / 2);
                path.lineTo(shadeButtonIconRect.bottomRight());
                path.lineTo(shadeButtonIconRect.bottomLeft());

                painter->setPen(textAlphaColor);
                painter->setBrush(textColor);
                painter->drawPath(path);
            }

            // unshade button
            if (titleBar->subControls & SC_TitleBarUnshadeButton)
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);

                QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
                qt_plastique_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);

                int xoffset = unshadeButtonRect.width() / 3;
                int yoffset = unshadeButtonRect.height() / 3;

                QRect unshadeButtonIconRect(unshadeButtonRect.left() + xoffset, unshadeButtonRect.top() + yoffset,
                                            unshadeButtonRect.width() - xoffset * 2, unshadeButtonRect.height() - yoffset * 2);

                int midY = unshadeButtonIconRect.bottom() - unshadeButtonIconRect.height() / 2;
                QPainterPath path(QPoint(unshadeButtonIconRect.left(), midY));
                path.lineTo(unshadeButtonIconRect.right(), midY);
                path.lineTo(unshadeButtonIconRect.center().x(), unshadeButtonIconRect.bottom());
                path.lineTo(unshadeButtonIconRect.left(), midY);

                painter->setPen(textAlphaColor);
                painter->setBrush(textColor);
                painter->drawPath(path);
            }

            // from qwindowsstyle.cpp
            if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint))
            {
                bool hover = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_MouseOver);
                bool sunken = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_Sunken);

                QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
                if (hover)
                    qt_plastique_draw_mdibutton(painter, titleBar, iconRect, hover, sunken);

                if (!titleBar->icon.isNull())
                {
                    titleBar->icon.paint(painter, iconRect);
                }
                else
                {
                    QStyleOption tool(0);
                    tool.palette = titleBar->palette;
                    QPixmap pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
                    tool.rect = iconRect;
                    painter->save();
                    proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
                    painter->restore();
                }
            }
            painter->restore();
        }
        break;
#ifndef QT_NO_DIAL
    case CC_Dial:
        if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
            QStyleHelper1::drawDial(dial, painter);
        break;
#endif // QT_NO_DIAL
    default:
        HvPublicStyle::drawComplexControl(control, option, painter, widget);
        break;
    }
}

void HvStylePlastique::polish(QWidget *widget)
{
    if (qobject_cast<QPushButton *>(widget)
#ifndef QT_NO_COMBOBOX
            || qobject_cast<QComboBox *>(widget)
#endif
#ifndef QT_NO_SPINBOX
            || qobject_cast<QAbstractSpinBox *>(widget)
#endif
            || qobject_cast<QCheckBox *>(widget)
#ifndef QT_NO_GROUPBOX
            || qobject_cast<QGroupBox *>(widget)
#endif
            || qobject_cast<QRadioButton *>(widget)
#ifndef QT_NO_SPLITTER
            || qobject_cast<QSplitterHandle *>(widget)
#endif
#ifndef QT_NO_TABBAR
            || qobject_cast<QTabBar *>(widget)
#endif
       )
    {
        widget->setAttribute(Qt::WA_Hover);
    }

    if (widget->inherits("QWorkspaceTitleBar")
            || widget->inherits("QDockSeparator")
            || widget->inherits("QDockWidgetSeparator")
            || widget->inherits("Q3DockWindowResizeHandle"))
    {
        widget->setAttribute(Qt::WA_Hover);
    }

    if (false // to simplify the #ifdefs
#ifndef QT_NO_MENUBAR
            || qobject_cast<QMenuBar *>(widget)
#endif
#ifdef QT3_SUPPORT
            || widget->inherits("Q3ToolBar")
#endif
#ifndef QT_NO_TOOLBAR
            || qobject_cast<QToolBar *>(widget)
            || (widget && qobject_cast<QToolBar *>(widget->parent()))
#endif
       )
    {
        widget->setBackgroundRole(QPalette::Window);
    }

#ifndef QT_NO_PROGRESSBAR
    if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget))
        widget->installEventFilter(this);
#endif

#if defined QPlastique_MaskButtons
    if (qobject_cast<QPushButton *>(widget) || qobject_cast<QToolButton *>(widget))
        widget->installEventFilter(this);
#endif
}

/*!
  \reimp
*/
void HvStylePlastique::unpolish(QWidget *widget)
{
    if (qobject_cast<QPushButton *>(widget)
#ifndef QT_NO_COMBOBOX
            || qobject_cast<QComboBox *>(widget)
#endif
#ifndef QT_NO_SPINBOX
            || qobject_cast<QAbstractSpinBox *>(widget)
#endif
            || qobject_cast<QCheckBox *>(widget)
#ifndef QT_NO_GROUPBOX
            || qobject_cast<QGroupBox *>(widget)
#endif
#ifndef QT_NO_SPLITTER
            || qobject_cast<QSplitterHandle *>(widget)
#endif
#ifndef QT_NO_TABBAR
            || qobject_cast<QTabBar *>(widget)
#endif
            || qobject_cast<QRadioButton *>(widget))
    {
        widget->setAttribute(Qt::WA_Hover, false);
    }

    if (widget->inherits("QWorkspaceTitleBar")
            || widget->inherits("QDockSeparator")
            || widget->inherits("QDockWidgetSeparator")
            || widget->inherits("Q3DockWindowResizeHandle"))
    {
        widget->setAttribute(Qt::WA_Hover, false);
    }

    if (false // to simplify the #ifdefs
#ifndef QT_NO_MENUBAR
            || qobject_cast<QMenuBar *>(widget)
#endif
#ifndef QT_NO_TOOLBOX
            || qobject_cast<QToolBox *>(widget)
#endif
#ifdef QT3_SUPPORT
            || widget->inherits("Q3ToolBar")
#endif
#ifndef QT_NO_TOOLBAR
            || qobject_cast<QToolBar *>(widget)
            || (widget && qobject_cast<QToolBar *>(widget->parent()))
#endif
       )
    {
        widget->setBackgroundRole(QPalette::Button);
    }
    /*
    #ifndef QT_NO_PROGRESSBAR
        if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget)) {
            Q_D(QPlastiqueStyle);
            widget->removeEventFilter(this);
            d->bars.removeAll(static_cast<QProgressBar*>(widget));
        }
    #endif
    */
#if defined QPlastique_MaskButtons
    if (qobject_cast<QPushButton *>(widget) || qobject_cast<QToolButton *>(widget))
        widget->removeEventFilter(this);
#endif
}

/*!
  \reimp
*/
void HvStylePlastique::polish(QApplication *app)
{
    HvPublicStyle::polish(app);
}

/*!
  \reimp
*/
/*
QPainterPath HvStylePlastique::roundRectPath(const QRect &rect)
{
    int radius = qMin(rect.width(), rect.height()) / 2;
    int diam = 2 * radius;

    int x1, y1, x2, y2;
    rect.getCoords(&x1, &y1, &x2, &y2);

    QPainterPath path;
    path.moveTo(x2, y1 + radius);
    path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0);
    path.lineTo(x1 + radius, y1);
    path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0);
    path.lineTo(x1, y2 - radius);
    path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0);
    path.lineTo(x1 + radius, y2);
    path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0);
    path.closeSubpath();
    return path;
}
*/

/*
void HvStylePlastique::polish(QPalette & palette)
{
	QColor brown(212, 212, 212);//(212, 140, 95);
    QColor beige(250, 250, 250);//(236, 182, 120);
    QColor backg(240, 240, 240);
    QColor slightlyOpaqueBlack(0, 0, 0, 63);

    //QPixmap backgroundImage(":/images/woodbackground.png");
    //QPixmap backgroundImage(":font/woodbutton.png");
    QPixmap buttonImage(":font/woodbutton.png");
    QPixmap midImage = buttonImage;

    QPainter painter;
    painter.begin(&midImage);
    painter.setPen(Qt::NoPen);
    painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
    painter.end();

    palette = QPalette(brown);

    palette.setBrush(QPalette::BrightText, Qt::white);
    palette.setBrush(QPalette::Base, beige);
    palette.setBrush(QPalette::Highlight, Qt::blue);
    palette.setBrush(QPalette::Window, backg);
    setTexture(palette, QPalette::Button, buttonImage);
    setTexture(palette, QPalette::Mid, midImage);
    //setTexture(palette, QPalette::Window, backgroundImage);

    QBrush brush = palette.window();
    brush.setColor(brush.color().dark());

    palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
    palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);

	//QProxyStyle::polish(palette);
}

void HvStylePlastique::setTexture(QPalette &palette, QPalette::ColorRole role,
                                    const QPixmap &pixmap)
{
    for (int i = 0; i < QPalette::NColorGroups; ++i) {
        QColor color = palette.brush(QPalette::ColorGroup(i), role).color();
        palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap));
    }
}

void HvStylePlastique::polish(QWidget *widget)
{
    if (qobject_cast<QPushButton *>(widget)
            || qobject_cast<QComboBox *>(widget))
        widget->setAttribute(Qt::WA_Hover, true);
}

void HvStylePlastique::unpolish(QWidget *widget)
{
    if (qobject_cast<QPushButton *>(widget)
            || qobject_cast<QComboBox *>(widget))
        widget->setAttribute(Qt::WA_Hover, false);
}
*/
/*void HvStylePlastique::SetStyleHV(bool f)
{
    f_dark_style = f;
}*/
void HvStylePlastique::polish(QPalette & pal)
{
    if (f_dark_style)
    {
        pal.setColor(QPalette::Button, QColor(70,70,70)); // header color
        pal.setColor(QPalette::ButtonText, QColor(255,255,255));
        //pal.setColor(QPalette::BrightText, QColor(50,100,160)); // kontura na lista butonite
        pal.setColor(QPalette::Window, QColor(90,90,90)); // kantovete na prozoreca
        pal.setColor(QPalette::Foreground, QColor(255,255,255)); // strelkite na scrola width
        pal.setColor(QPalette::BrightText, QColor(0,150,0)); // ne znam ama e zeleno
        pal.setColor(QPalette::Base, QColor(25,25,25));// backgrownd
        pal.setColor(QPalette::Text, QColor(255,255,255));// bukwi
        pal.setColor(QPalette::HighlightedText, QColor(255,255,255));//selected Text color
        pal.setColor(QPalette::Highlight, QColor(80,80,80)); // selected row
        pal.setColor(QPalette::Light, QColor(110,110,110));// zaradi sort indicatora
        pal.setColor(QPalette::Midlight, QColor(65,65,65));// zaradi sort indicatora
        pal.setColor(QPalette::Dark, QColor(30,30,30));// zaradi sort indicatora
        pal.setColor(QPalette::Mid, QColor(20,20,20));// zaradi sort indicatora
        pal.setColor(QPalette::Shadow, QColor(0,0,0));// zaradi bordera okantovaneto na lista
        //pal.setColor(QPalette::ToolTipBase, QColor(255,255,255));// bukwi

        QBrush brush = pal.window();
        //brush.setColor(brush.color().dark());
        brush.setColor(brush.color().darker());//2.56
        pal.setBrush(QPalette::Disabled, QPalette::WindowText, QColor(150,150,150));
        pal.setBrush(QPalette::Disabled, QPalette::Text, QColor(125,125,125));
        pal.setBrush(QPalette::Disabled, QPalette::ButtonText, QColor(100,100,100));
        pal.setBrush(QPalette::Disabled, QPalette::Base, brush);
        pal.setBrush(QPalette::Disabled, QPalette::Button, QColor(50,50,50));
        pal.setBrush(QPalette::Disabled, QPalette::Mid, brush);
        pal.setBrush(QPalette::Disabled, QPalette::Shadow, brush);
    }

    HvPublicStyle::polish(pal);
#ifdef Q_WS_MAC
    pal.setBrush(QPalette::Shadow, Qt::black);
#endif
}

/*void HvStylePlastique::polish(QPalette &pal)
{
    HvPublicStyle::polish(pal);
#ifdef Q_WS_MAC
    pal.setBrush(QPalette::Shadow, Qt::black);
#endif
}
*/
/*!
  \reimp
*/
void HvStylePlastique::unpolish(QApplication *app)
{
    HvPublicStyle::unpolish(app);
}
/*
QIcon HvStylePlastique::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option,
                                                  const QWidget *widget) const
{
    return HvPublicStyle::standardIconImplementation(standardIcon, option, widget);
}
*/
QPixmap HvStylePlastique::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
        const QWidget *widget) const
{
    return HvPublicStyle::standardPixmap(standardPixmap, opt, widget);
}

/*!
  \reimp hv
*/
// this works as long as we have at most 16 different control types
#define CT1(c) CT2(c, c)
#define CT2(c1, c2) (((uint)c1 << 16) | (uint)c2)
//old qt4 protected slot
//int HvStylePlastique::layoutSpacingImplementation(QSizePolicy::ControlType control1,
//QSizePolicy::ControlType control2,
//Qt::Orientation orientation,
//const QStyleOption * /* option */,
//const QWidget * /* widget */) const
//new qt5  old is qt4 layoutSpacingImplementation
int HvStylePlastique::layoutSpacing(QSizePolicy::ControlType control1,
                                    QSizePolicy::ControlType control2,
                                    Qt::Orientation orientation,
                                    const QStyleOption * /* option */,
                                    const QWidget * /* widget */) const
{
    //qDebug()<<"Test---------------->";
    const int ButtonMask = QSizePolicy::ButtonBox | QSizePolicy::PushButton;

    if (control2 == QSizePolicy::ButtonBox)
        return 11;

    if ((control1 | control2) & ButtonMask)
        return (orientation == Qt::Horizontal) ? 10 : 9;

    switch (CT2(control1, control2))
    {
    case CT1(QSizePolicy::Label):
                case CT2(QSizePolicy::Label, QSizePolicy::DefaultType):
                    case CT2(QSizePolicy::Label, QSizePolicy::CheckBox):
                        case CT2(QSizePolicy::Label, QSizePolicy::ComboBox):
                            case CT2(QSizePolicy::Label, QSizePolicy::LineEdit):
                                case CT2(QSizePolicy::Label, QSizePolicy::RadioButton):
                                    case CT2(QSizePolicy::Label, QSizePolicy::Slider):
                                        case CT2(QSizePolicy::Label, QSizePolicy::SpinBox):
                                            case CT2(QSizePolicy::Label, QSizePolicy::ToolButton):
                                                    return 5;
    case CT2(QSizePolicy::CheckBox, QSizePolicy::RadioButton):
                case CT2(QSizePolicy::RadioButton, QSizePolicy::CheckBox):
                    case CT1(QSizePolicy::CheckBox):
                            if (orientation == Qt::Vertical)
                                return 2;
        break;
    case CT1(QSizePolicy::RadioButton):
                    if (orientation == Qt::Vertical)
                        return 1;
    }

    if (orientation == Qt::Horizontal
            && (control2 & (QSizePolicy::CheckBox | QSizePolicy::RadioButton)))
        return 8;

    if ((control1 | control2) & (QSizePolicy::Frame
                                 | QSizePolicy::GroupBox
                                 | QSizePolicy::TabWidget))
{
        return 11;
    }

    if ((control1 | control2) & (QSizePolicy::Line | QSizePolicy::Slider
                                 | QSizePolicy::LineEdit | QSizePolicy::ComboBox
                                 | QSizePolicy::SpinBox))
        return 7;

    return 6;
}
/*
QPalette HvStylePlastique::standardPalette() const
{
    QPalette palette;

    palette.setBrush(QPalette::Disabled, QPalette::WindowText, QColor(QRgb(0xff808080)));
    palette.setBrush(QPalette::Disabled, QPalette::Button, QColor(QRgb(0xffdddfe4)));
    palette.setBrush(QPalette::Disabled, QPalette::Light, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Disabled, QPalette::Midlight, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Disabled, QPalette::Dark, QColor(QRgb(0xff555555)));
    palette.setBrush(QPalette::Disabled, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
    palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(QRgb(0xffc7c7c7)));
    palette.setBrush(QPalette::Disabled, QPalette::BrightText, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Disabled, QPalette::ButtonText, QColor(QRgb(0xff808080)));
    palette.setBrush(QPalette::Disabled, QPalette::Base, QColor(QRgb(0xffefefef)));
    palette.setBrush(QPalette::Disabled, QPalette::AlternateBase, palette.color(QPalette::Disabled, QPalette::Base).darker(110));
    palette.setBrush(QPalette::Disabled, QPalette::Window, QColor(QRgb(0xffefefef)));
    palette.setBrush(QPalette::Disabled, QPalette::Shadow, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(QRgb(0xff567594)));
    palette.setBrush(QPalette::Disabled, QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Disabled, QPalette::Link, QColor(QRgb(0xff0000ee)));
    palette.setBrush(QPalette::Disabled, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
    palette.setBrush(QPalette::Active, QPalette::WindowText, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Active, QPalette::Button, QColor(QRgb(0xffdddfe4)));
    palette.setBrush(QPalette::Active, QPalette::Light, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Active, QPalette::Dark, QColor(QRgb(0xff555555)));
    palette.setBrush(QPalette::Active, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
    palette.setBrush(QPalette::Active, QPalette::Text, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Active, QPalette::BrightText, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Active, QPalette::ButtonText, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Active, QPalette::Base, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Active, QPalette::AlternateBase, palette.color(QPalette::Active, QPalette::Base).darker(110));
    palette.setBrush(QPalette::Active, QPalette::Window, QColor(QRgb(0xffefefef)));
    palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(QRgb(0xff678db2)));
    palette.setBrush(QPalette::Active, QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Active, QPalette::Link, QColor(QRgb(0xff0000ee)));
    palette.setBrush(QPalette::Active, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
    palette.setBrush(QPalette::Inactive, QPalette::WindowText, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Inactive, QPalette::Button, QColor(QRgb(0xffdddfe4)));
    palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Inactive, QPalette::Dark, QColor(QRgb(0xff555555)));
    palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
    palette.setBrush(QPalette::Inactive, QPalette::Text, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Inactive, QPalette::BrightText, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Inactive, QPalette::ButtonText, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Inactive, QPalette::Base, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Inactive, QPalette::AlternateBase, palette.color(QPalette::Inactive, QPalette::Base).darker(110));
    palette.setBrush(QPalette::Inactive, QPalette::Window, QColor(QRgb(0xffefefef)));
    palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(QRgb(0xff000000)));
    palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(QRgb(0xff678db2)));
    palette.setBrush(QPalette::Inactive, QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
    palette.setBrush(QPalette::Inactive, QPalette::Link, QColor(QRgb(0xff0000ee)));
    palette.setBrush(QPalette::Inactive, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
    return palette;
}
*/

int HvStylePlastique::styleHint(StyleHint hint, const QStyleOption * opt, const QWidget * widget, QStyleHintReturn * returnData) const
{
    /*int ret = 0;
    switch (hint) {
    case SH_WindowFrame_Mask:
        ret = 1;
        if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData)) {
            mask->region = option->rect;
            mask->region -= QRect(option->rect.left(), option->rect.top(), 2, 1);
            mask->region -= QRect(option->rect.right() - 1, option->rect.top(), 2, 1);
            mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 1, 1);
            mask->region -= QRect(option->rect.right(), option->rect.top() + 1, 1, 1);

            const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option);
            if (titleBar && (titleBar->titleBarState & Qt::WindowMinimized)) {
                mask->region -= QRect(option->rect.left(), option->rect.bottom(), 2, 1);
                mask->region -= QRect(option->rect.right() - 1, option->rect.bottom(), 2, 1);
                mask->region -= QRect(option->rect.left(), option->rect.bottom() - 1, 1, 1);
                mask->region -= QRect(option->rect.right(), option->rect.bottom() - 1, 1, 1);
            } else {
                mask->region -= QRect(option->rect.bottomLeft(), QSize(1, 1));
                mask->region -= QRect(option->rect.bottomRight(), QSize(1, 1));
            }
        }
        break;
    case SH_TitleBar_NoBorder:
        ret = 1;
        break;
    case SH_TitleBar_AutoRaise:
        ret = 1;
        break;
    case SH_ItemView_ShowDecorationSelected:
        ret = true;
        break;
    case SH_ToolBox_SelectedPageTitleBold:
    case SH_ScrollBar_MiddleClickAbsolutePosition:
        ret = true;
        break;
    case SH_MainWindow_SpaceBelowMenuBar:
        ret = 0;
        break;
    case SH_FormLayoutWrapPolicy:
        ret = QFormLayout::DontWrapRows;
        break;
    case SH_FormLayoutFieldGrowthPolicy:
        ret = QFormLayout::ExpandingFieldsGrow;
        break;
    case SH_FormLayoutFormAlignment:
        ret = Qt::AlignLeft | Qt::AlignTop;
        break;
    case SH_FormLayoutLabelAlignment:
        ret = Qt::AlignRight;
        break;
    case SH_MessageBox_TextInteractionFlags:
        ret = Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
        break;
    case SH_LineEdit_PasswordCharacter:
        ret = QCommonStyle::styleHint(hint, option, widget, returnData);
        break;
    case SH_ItemView_ArrowKeysNavigateIntoChildren:
        ret = true;
        break;
    case SH_Menu_SubMenuPopupDelay:
        ret = 96; // from Plastik
        break;
    #ifdef Q_WS_X11
    case SH_DialogButtonBox_ButtonsHaveIcons:
        ret = true;
        break;
    #endif
    #ifndef Q_OS_WIN
    case SH_Menu_AllowActiveAndDisabled:
        ret = false;
        break;
    #endif
    default:
        ret = HvPublicStyle::styleHint(hint, option, widget, returnData);
        break;
    }
    return ret;*/
    int ret = 0;

    switch (hint)
    {
    case SH_EtchDisabledText:
    case SH_Slider_SnapToValue:
    case SH_PrintDialog_RightAlignButtons:
    case SH_FontDialog_SelectAssociatedText:
    case SH_Menu_AllowActiveAndDisabled:
    case SH_MenuBar_AltKeyNavigation:
    case SH_MenuBar_MouseTracking:
    case SH_Menu_MouseTracking:
    case SH_ComboBox_ListMouseTracking:
    case SH_ScrollBar_StopMouseOverSlider:
    case SH_MainWindow_SpaceBelowMenuBar:
        ret = 1;

        break;
    case SH_ItemView_ShowDecorationSelected:
#ifndef QT_NO_LISTVIEW
        if (qobject_cast<const QListView*>(widget))
            ret = 1;
#endif
        break;
    case SH_ItemView_ChangeHighlightOnFocus:
        ret = 1;
        break;
    case SH_ToolBox_SelectedPageTitleBold:
        ret = 0;
        break;

#if defined(Q_WS_WIN)
    case SH_UnderlineShortcut:
    {
        ret = 1;
        BOOL cues = false;
        SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
        ret = int(cues);
        // Do nothing if we always paint underlines
        /* Q_D(const QWindowsStyle);
         if (!ret && widget && d) {
        #ifndef QT_NO_MENUBAR
             const QMenuBar *menuBar = qobject_cast<const QMenuBar *>(widget);
             if (!menuBar && qobject_cast<const QMenu *>(widget)) {
                 QWidget *w = QApplication::activeWindow();
                 if (w && w != widget)
                     menuBar = w->findChild<QMenuBar *>();
             }
             // If we paint a menu bar draw underlines if is in the keyboardState
             if (menuBar) {
                 if (menuBar->d_func()->keyboardState || d->altDown())
                     ret = 1;
                 // Otherwise draw underlines if the toplevel widget has seen an alt-press
             } else
        #endif // QT_NO_MENUBAR
             if (d->hasSeenAlt(widget)) {
                 ret = 1;
             }
         }*/
        break;
    }
#endif
#ifndef QT_NO_RUBBERBAND
    case SH_RubberBand_Mask:
        if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt))
        {
            ret = 0;
            if (rbOpt->shape == QRubberBand::Rectangle)
            {
                ret = true;
                if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData))
                {
                    mask->region = opt->rect;
                    int size = 1;
                    if (widget && widget->isWindow())
                        size = 4;
                    mask->region -= opt->rect.adjusted(size, size, -size, -size);
                }
            }
        }
        break;
#endif // QT_NO_RUBBERBAND
    case SH_LineEdit_PasswordCharacter:
    {
#ifdef Q_WS_WIN
        if (widget && (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)))
        {
            const QFontMetrics &fm = widget->fontMetrics();
            if (fm.inFont(QChar(0x25CF)))
                ret = 0x25CF;
            else if (fm.inFont(QChar(0x2022)))
                ret = 0x2022;
        }
#endif
        if (!ret)
            ret = '*';
    }
    break;
#ifndef QT_NO_WIZARD
    case SH_WizardStyle:
        ret = QWizard::ModernStyle;
        break;
#endif
    case SH_ItemView_ArrowKeysNavigateIntoChildren:
        ret = true;
        break;
    case SH_DialogButtonBox_ButtonsHaveIcons:
        ret = 0;
        break;
    default:
        ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
        break;
    }
    return ret;
}

QStyle::SubControl HvStylePlastique::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
        const QPoint &pos, const QWidget *widget) const
{
    SubControl ret = SC_None;
    switch (control)
    {
#ifndef QT_NO_SCROLLBAR
    case CC_ScrollBar:
        if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option))
        {
            QRect slider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
            if (slider.contains(pos))
            {
                ret = SC_ScrollBarSlider;
                break;
            }

            QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
            if (scrollBarAddLine.contains(pos))
            {
                ret = SC_ScrollBarAddLine;
                break;
            }

            QRect scrollBarSubPage = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubPage, widget);
            if (scrollBarSubPage.contains(pos))
            {
                ret = SC_ScrollBarSubPage;
                break;
            }

            QRect scrollBarAddPage = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddPage, widget);
            if (scrollBarAddPage.contains(pos))
            {
                ret = SC_ScrollBarAddPage;
                break;
            }

            QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
            if (scrollBarSubLine.contains(pos))
            {
                ret = SC_ScrollBarSubLine;
                break;
            }
        }
        break;
#endif // QT_NO_SCROLLBAR
    default:
        break;
    }

    return ret != SC_None ? ret : HvPublicStyle::hitTestComplexControl(control, option, pos, widget);
}

/*
bool HvStylePlastique::eventFilter(QObject *watched, QEvent *event)
{

#ifndef QT_NO_PROGRESSBAR
    Q_D(QPlastiqueStyle);

    switch (event->type()) {
    case QEvent::Show:
        if (QProgressBar *bar = qobject_cast<QProgressBar *>(watched)) {
            d->bars.append(bar);
            if (d->bars.size() == 1) {
                Q_ASSERT(ProgressBarFps > 0);
                d->timer.start();
                d->progressBarAnimateTimer = startTimer(1000 / ProgressBarFps);
            }
        }
        break;
    case QEvent::Destroy:
    case QEvent::Hide:
        if(!d->bars.isEmpty()) {
            d->bars.removeAll(reinterpret_cast<QProgressBar*>(watched));
            if (d->bars.isEmpty()) {
                killTimer(d->progressBarAnimateTimer);
                d->progressBarAnimateTimer = 0;
            }
        }
        break;
#if defined QPlastique_MaskButtons
    case QEvent::Resize:
        if (qobject_cast<QPushButton *>(watched) || qobject_cast<QToolButton *>(watched)) {
            QWidget *widget = qobject_cast<QWidget *>(watched);
            QRect rect = widget->rect();
            QRegion region(rect);
            region -= QRect(rect.left(), rect.top(), 2, 1);
            region -= QRect(rect.left(), rect.top() + 1, 1, 1);
            region -= QRect(rect.left(), rect.bottom(), 2, 1);
            region -= QRect(rect.left(), rect.bottom() - 1, 1, 1);
            region -= QRect(rect.right() - 1, rect.top(), 2, 1);
            region -= QRect(rect.right(), rect.top() + 1, 1, 1);
            region -= QRect(rect.right() - 1, rect.bottom(), 2, 1);
            region -= QRect(rect.right(), rect.bottom() - 1, 1, 1);
            widget->setMask(region);
        }
        break;
#endif
    default:
        break;
    }
#endif // QT_NO_PROGRESSBAR

    return HvPublicStyle::eventFilter(watched, event);
}

void HvStylePlastique::timerEvent(QTimerEvent *event)
{
#ifndef QT_NO_PROGRESSBAR
    Q_D(QPlastiqueStyle);

    if (event->timerId() == d->progressBarAnimateTimer) {
        Q_ASSERT(ProgressBarFps > 0);
        d->animateStep = d->timer.elapsed() / (1000 / ProgressBarFps);
        foreach (QProgressBar *bar, d->bars) {
            if (AnimateProgressBar || (bar->minimum() == 0 && bar->maximum() == 0))
                bar->update();
        }
    }
#endif // QT_NO_PROGRESSBAR
    event->ignore();
}
*/



