Index: trunk/src/styles/qwarp4style.cpp
===================================================================
--- trunk/src/styles/qwarp4style.cpp	(revision 180)
+++ trunk/src/styles/qwarp4style.cpp	(revision 181)
@@ -747,5 +747,5 @@
     p.drawLine(pt2, pt += QPoint(5, 1));
     pt2 = pt + QPoint(sz - 7, sz - 7);
-    p.drawLine(pt2 + QPoint(0, 1), pt2 + QPoint(0, 4));
+    p.drawLine(pt2 + QPoint(0, 1), pt2 + QPoint(0, 5));
 
     // corner
@@ -792,5 +792,5 @@
     p.drawLine(pt2, pt += QPoint(5, -1));
     pt2 = pt + QPoint(sz - 7, -sz + 7);
-    p.drawLine(pt2 + QPoint(0, -1), pt2 + QPoint(0, -4));
+    p.drawLine(pt2 + QPoint(0, -1), pt2 + QPoint(0, -5));
 
     // corner
@@ -835,4 +835,5 @@
     p.drawLine(pt2, pt += QPoint(-5, 1));
     pt2 = pt + QPoint(7 - sz, sz - 7);
+    p.drawLine(pt2 + QPoint(0, 1), pt2 + QPoint(0, 5));
 
     // corner
@@ -886,4 +887,5 @@
     p.drawLine(pt2, pt += QPoint(-5, -1));
     pt2 = pt + QPoint(7 - sz, 7 - sz);
+    p.drawLine(pt2 + QPoint(0, -1), pt2 + QPoint(0, -5));
 
     // corner
@@ -1239,96 +1241,88 @@
     Q_OBJECT
 
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+
 public:
-    QWarpTabPanelHeader(QTabWidget* tw);
+
+    QWarpTabPanelHeader (QTabWidget* tw);
 
 protected:
-    virtual bool eventFilter(QObject* watched, QEvent* ev);
-    virtual void paintEvent(QPaintEvent* pev);
-    virtual void mouseReleaseEvent(QMouseEvent* e);
+
+    virtual bool eventFilter (QObject* watched, QEvent* ev);
+    virtual void paintEvent (QPaintEvent* pev);
+    virtual void mouseReleaseEvent (QMouseEvent* e);
 
 private:
+
     bool _bottom;
 
-    QTabWidget* getTabWidget();
-    QWidgetStack* getPanel();
-    QTabBar* getTabBar();
-    QWidget* getTabBarBase();
-
-    void setupLayout(QSize sz);
-
-    void drawBentCornerTR(QPoint pt, int h, QPainter& p);
-    void drawBentCornerTL(QPoint pt, int h, QPainter& p);
-    void drawBentCornerBR(QPoint pt, int h, QPainter& p);
-    void drawBentCornerBL(QPoint pt, int h, QPainter& p);
-    void drawPlusButton(QPoint pt, QPainter& p);
-    void drawMinusButton(QPoint pt, QPainter& p);
+    QTabWidget *_tabWidget;
+    QWidgetStack *_widgetStack;
+    QTabBar *_tabBar;
+    QWidget *_tabBarBase;
+
+    void setupLayout (QRect rect);
+
+    static void drawBentCornerTR (QPoint pt, int h, QPainter& p);
+    static void drawBentCornerTL (QPoint pt, int h, QPainter& p);
+    static void drawBentCornerBR (QPoint pt, int h, QPainter& p);
+    static void drawBentCornerBL (QPoint pt, int h, QPainter& p);
+    static void drawPlusButton (QPoint pt, QPainter& p);
+    static void drawMinusButton (QPoint pt, QPainter& p);
 
     int currentInx();
 
-public:
-    static void addIfNotPresent(QTabBar const* tb);
+#endif // QT_PM_NO_TABWIDGET_HEADERS
 };
 
-QWarpTabPanelHeader::QWarpTabPanelHeader(QTabWidget* tw)
-:   QWidget(tw, "qt_warp_tabpanel_header")
-{
-    if(0 == tw)
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+
+QWarpTabPanelHeader::QWarpTabPanelHeader (QTabWidget *tw)
+    : QWidget (tw, "qt_warp_tabpanel_header")
+    , _bottom (false), _tabWidget (0), _widgetStack (0)
+    , _tabBar (0), _tabBarBase (0)
+{
+    Q_ASSERT (tw);
+    if (tw == 0)
         return;
 
-    // adapt the panel area size ("QWidgetStack")
-    // note: the same effect could also be achieved by increasing the frame line
-    // width for tab widgets, but this would also affect the tabbar layout in a
-    // "very strange" (buggy??) way (it only works correctly for frame line widths
-    // between 0 and 2)
-    // also note that this reduction must be compensated when drawing the frame
-    // (see PE_PanelTabWidget)
-
     _bottom = tw->tabPosition() == QTabWidget::Bottom;
-    QWidgetStack* tp = getPanel();
-    if(0 != tp)
-    {
-        QRect r = tp->frameRect();
-        if(_bottom)
-            r.addCoords(11, 11, -14, 0);
-        else
-            r.addCoords(11, 0, -14, -11);
-        tp->setFrameRect(r);
-    }
-
-    // now we are "abusing" the otherwise unused "midLineWidth" of the tab panel
-    // stack for signalling whether the tab bar is on top or at the bottom.
-    // note that we can retrieve this information later in PE_PanelTabWidget from
-    // the "opt" parameter (we don't have access to any widget from where we could
-    // get that information "legally"!
-
-    tp->setMidLineWidth((int)_bottom); // now 1 is "bottom", 0 is "top"
-
-    // we also need to catch resize events from the tab widget, in order to adapt
+
+    _tabWidget = tw;
+
+    _widgetStack = (QWidgetStack *) tw->child ("tab pages", "QWidgetStack", false);
+    Q_ASSERT (_widgetStack != 0);
+    if (_widgetStack == 0)
+        return;
+
+    _tabBar = (QTabBar *) tw->child (NULL, "QTabBar", false);
+    Q_ASSERT (_tabBar != 0);
+    if (_tabBar == 0)
+        return;
+
+    _tabBarBase = (QWidget *) tw->child ("tab base", "QWidget", false);
+    Q_ASSERT (_tabBarBase != 0);
+    if (_tabBarBase == 0)
+        return;
+
+    setupLayout (_tabBarBase->geometry());
+
+    // catch resize/move events from the tab bar base widget in order to adapt
     // the size of this panel header widget accordingly
 
-    tw->installEventFilter(this);
-
-    // note that size 0/0 means that the size is taken from that widget
-
-    setupLayout(QSize(0, 0));
-
-    // make this panel header widget visible: it displays the tab title
-
-#ifndef QT_PM_NO_TABWIDGET_HEADERS
+    _tabBarBase->installEventFilter (this);
+
+    // make this visible: it displays the tab title
     show();
-#else
-    hide();
-#endif
-}
-
-bool QWarpTabPanelHeader::eventFilter(QObject* watched, QEvent* ev)
-{
-    if(!watched->inherits("QTabWidget") ||
-       (QEvent::Resize != ev->type()))
+}
+
+bool QWarpTabPanelHeader::eventFilter (QObject *watched, QEvent *ev)
+{
+    if ((ev->type() != QEvent::Resize && ev->type() != QEvent::Move))
         return false;
 
-    // resize the panel header widget if the main tab widget is being resized
-
-    setupLayout(((QResizeEvent*)ev)->size());
+    // adapt the panel header widget position if the tab bar base widget is
+    // being resized/moved
+    setupLayout (((QWidget *) watched)->geometry());
 
     return false;
@@ -1337,18 +1331,17 @@
 void QWarpTabPanelHeader::paintEvent(QPaintEvent* pev)
 {
-#ifndef QT_PM_NO_TABWIDGET_HEADERS
+    if (_tabWidget == 0)
+        return; // should never happen
 
     // draw the caption of the page in the tab bar base area
 
-    QRect r(geometry());
+    QRect r (rect());
     QPainter p(this);
     bool reverse = QApplication::reverseLayout();
 
-    r.addCoords(-r.left(), -r.top(), -r.left(), -r.top());
-    p.setClipRect(r);
-    QFont f = QApplication::font();
-    f.setBold(true);
-    p.setFont(f);
-    QRect fr = QFontMetrics(f).boundingRect(caption());
+    QFont f = _tabWidget->font();
+    f.setBold (true);
+    p.setFont (f);
+    QRect fr = QFontMetrics(f).boundingRect (caption());
 
     int x = (reverse ?
@@ -1359,96 +1352,89 @@
     QString cap = caption();
     cap.remove (cap.find ('&'), 1);
-    p.drawText(x, y, cap);
+    p.drawText (x, y, cap);
 
     QPoint pt1l, pt1r, pt2l, pt2r;
-    int hh = r.height() + 1;
-    if(_bottom)
-    {
-        pt1l = QPoint(1, r.bottom());
-        pt1r = QPoint(r.width() - hh, r.bottom());
-        pt2l = QPoint(5, r.top());
-        pt2r = QPoint(r.width() - hh, r.top());
+    int hh = r.height();
+    if (_bottom)
+    {
+        pt1l = QPoint (1, r.bottom());
+        pt1r = QPoint (r.width() - hh, r.bottom());
+        pt2l = QPoint (5, r.top() + 1);
+        pt2r = QPoint (r.width() - hh, r.top() + 1);
     }
     else
     {
-        pt1l = QPoint(1, r.top());
-        pt1r = QPoint(r.width() - hh, r.top());
-        pt2l = QPoint(5, r.bottom() - 1);
-        pt2r = QPoint(r.width() - hh, r.bottom() - 1);
-    }
-    if(reverse)
-    {
-        pt1l.setX(r.right() - pt1l.x());
-        pt1r.setX(r.right() - pt1r.x());
-        pt2l.setX(r.right() - pt2l.x());
-        pt2r.setX(r.right() - pt2r.x());
+        pt1l = QPoint (1, r.top());
+        pt1r = QPoint (r.width() - hh, r.top());
+        pt2l = QPoint (5, hh - 3);
+        pt2r = QPoint (r.width() - hh, hh - 3);
+    }
+    if (reverse)
+    {
+        pt1l.setX (r.right() - pt1l.x());
+        pt1r.setX (r.right() - pt1r.x());
+        pt2l.setX (r.right() - pt2l.x());
+        pt2r.setX (r.right() - pt2r.x());
+    }
+
+    const QColorGroup &cg = colorGroup();
+    p.setPen (cg.dark());
+    p.drawLine (pt1l, pt1r);
+    p.drawLine (pt2l, pt2r);
+    p.setPen (cg.light());
+    ++ pt2l.ry();
+    ++ pt2r.ry();
+    p.drawLine (pt2l, pt2r);
+
+    if (_tabBar == 0)
+        return; // should never happen
+
+    int inx = currentInx();
+    bool noPlus = inx >= _tabBar->count() - 1,
+         noMinus = inx <= 0;
+
+    QPoint cpt (pt1r);
+    if (_bottom)
+    {
+        if (reverse)
+        {
+            cpt += QPoint (-hh, -hh + 1);
+            drawBentCornerBL (cpt, hh, p);
+            if (!noPlus)
+                drawPlusButton (cpt + QPoint (5, hh - 12), p);
+            if (!noMinus)
+                drawMinusButton (cpt + QPoint (hh - 15, 7), p);
+        }
+        else
+        {
+            cpt += QPoint (1, -hh + 1);
+            drawBentCornerBR (cpt, hh, p);
+            if (!noPlus)
+                drawPlusButton (cpt + QPoint (hh - 12, hh - 12), p);
+            if (!noMinus)
+                drawMinusButton (cpt + QPoint (8, 7), p);
+        }
     }
     else
     {
-        pt1l.setX(r.left() + pt1l.x());
-        pt1r.setX(r.left() + pt1r.x());
-        pt2l.setX(r.left() + pt2l.x());
-        pt2r.setX(r.left() + pt2r.x());
-    }
-    QColorGroup cg = colorGroup();
-    p.setPen(cg.dark());
-    p.drawLine(pt1l, pt1r);
-    p.drawLine(pt2l, pt2r);
-    p.setPen(cg.light());
-    pt2l += QPoint(0, 1);
-    pt2r += QPoint(0, 1);
-    p.drawLine(pt2l, pt2r);
-
-    int inx = currentInx();
-    QTabBar* tb = getTabBar();
-    if(0 == tb)
-        return; // should never happen
-    bool noPlus = (tb->count() - 1) <= inx,
-        noMinus = 0 >= inx;
-
-    QPoint cpt(pt1r);
-    if(_bottom)
-    {
         if(reverse)
         {
-            cpt += QPoint(-hh, -hh + 1);
-            drawBentCornerBL(cpt, hh, p);
-            if(!noPlus)
-                drawPlusButton(cpt + QPoint(5, hh - 12), p);
-            if(!noMinus)
-                drawMinusButton(cpt + QPoint(hh - 15, 7), p);
+            cpt += QPoint (-hh, 0);
+            drawBentCornerTL (cpt, hh, p);
+            if (!noPlus)
+                drawPlusButton (cpt + QPoint (5, 5), p);
+            if (!noMinus)
+                drawMinusButton (cpt + QPoint (hh - 15, hh - 14), p);
         }
         else
         {
-            cpt += QPoint(1, -hh + 1);
-            drawBentCornerBR(cpt, hh, p);
-            if(!noPlus)
-                drawPlusButton(cpt + QPoint(hh - 12, hh - 12), p);
-            if(!noMinus)
-                drawMinusButton(cpt + QPoint(8, 7), p);
-        }
-    }
-    else
-    {
-        if(reverse)
-        {
-            cpt += QPoint(-hh, 0);
-            drawBentCornerTL(cpt, hh, p);
-            if(!noPlus)
-                drawPlusButton(cpt + QPoint(5, 5), p);
-            if(!noMinus)
-                drawMinusButton(cpt + QPoint(hh - 15, hh - 14), p);
-        }
-        else
-        {
-            cpt += QPoint(1, 0);
-            drawBentCornerTR(cpt, hh, p);
-            if(!noPlus)
-                drawPlusButton(cpt + QPoint(hh - 12, 5), p);
-            if(!noMinus)
-                drawMinusButton(cpt + QPoint(8, hh - 14), p);
-        }
-    }
-#endif
+            cpt += QPoint (1, 0);
+            drawBentCornerTR (cpt, hh, p);
+            if (!noPlus)
+                drawPlusButton (cpt + QPoint (hh - 12, 5), p);
+            if (!noMinus)
+                drawMinusButton (cpt + QPoint (8, hh - 14), p);
+        }
+    }
 }
 
@@ -1491,145 +1477,79 @@
         --inx;
 
-    QTabBar* tb = getTabBar();
-    if(0 == tb)
+    if(_tabBar == 0)
         return; // should never happen
-    if((0 <= inx) && (tb->count() > inx))
-        tb->setCurrentTab(tb->tabAt(inx)->identifier());
+
+    if (inx >= 0 && _tabBar->count() > inx)
+        _tabBar->setCurrentTab (_tabBar->tabAt (inx)->identifier());
 }
 
 void QWarpTabPanelHeader::drawBentCornerTR(QPoint pt, int h, QPainter& p)
 {
-    p.drawPixmap(pt, *qWarpSystemPixmaps.getPixmap(QWarpPixmap::tabheadertr,
-                                                  QWarpPixmap::internal, h));
+    p.drawPixmap (pt, *qWarpSystemPixmaps.getPixmap (QWarpPixmap::tabheadertr,
+                                                     QWarpPixmap::internal, h));
 }
 
 void QWarpTabPanelHeader::drawBentCornerTL(QPoint pt, int h, QPainter& p)
 {
-    p.drawPixmap(pt, *qWarpSystemPixmaps.getPixmap(QWarpPixmap::tabheadertl,
-                                                  QWarpPixmap::internal, h));
+    p.drawPixmap (pt, *qWarpSystemPixmaps.getPixmap (QWarpPixmap::tabheadertl,
+                                                     QWarpPixmap::internal, h));
 }
 
 void QWarpTabPanelHeader::drawBentCornerBR(QPoint pt, int h, QPainter& p)
 {
-    p.drawPixmap(pt, *qWarpSystemPixmaps.getPixmap(QWarpPixmap::tabheaderbr,
-                                                  QWarpPixmap::internal, h));
+    p.drawPixmap (pt, *qWarpSystemPixmaps.getPixmap (QWarpPixmap::tabheaderbr,
+                                                     QWarpPixmap::internal, h));
 }
 
 void QWarpTabPanelHeader::drawBentCornerBL(QPoint pt, int h, QPainter& p)
 {
-    p.drawPixmap(pt, *qWarpSystemPixmaps.getPixmap(QWarpPixmap::tabheaderbl,
-                                                  QWarpPixmap::internal, h));
+    p.drawPixmap (pt, *qWarpSystemPixmaps.getPixmap (QWarpPixmap::tabheaderbl,
+                                                     QWarpPixmap::internal, h));
 }
 
 void QWarpTabPanelHeader::drawPlusButton(QPoint pt, QPainter& p)
 {
-    p.drawPixmap(pt, *qWarpSystemPixmaps.getPixmap(QWarpPixmap::tabhdrplus,
-                                                  QWarpPixmap::internal));
+    p.drawPixmap (pt, *qWarpSystemPixmaps.getPixmap (QWarpPixmap::tabhdrplus,
+                                                     QWarpPixmap::internal));
 }
 
 void QWarpTabPanelHeader::drawMinusButton(QPoint pt, QPainter& p)
 {
-    p.drawPixmap(pt, *qWarpSystemPixmaps.getPixmap(QWarpPixmap::tabhdrminus,
-                                                  QWarpPixmap::internal));
-}
-
-QTabWidget* QWarpTabPanelHeader::getTabWidget()
-{
-    QWidget* ww = parentWidget();
-    if((0 == ww) || !ww->inherits("QTabWidget"))
-        return 0;
-
-    return (QTabWidget*)ww;
-}
-
-QWidgetStack* QWarpTabPanelHeader::getPanel()
-{
-    QTabWidget* tw = getTabWidget();
-    if(0 == tw)
-        return 0;
-
-    return (QWidgetStack*)tw->child("tab pages", "QWidgetStack", false);
-}
-
-QTabBar* QWarpTabPanelHeader::getTabBar()
-{
-    QTabWidget* tw = getTabWidget();
-    if(0 == tw)
-        return 0;
-
-    QObjectList* childList = tw->queryList("QTabBar", 0, false, false);
-    if(childList->isEmpty())
-        return 0;
-
-    return (QTabBar*)childList->at(0);
-}
-
-QWidget* QWarpTabPanelHeader::getTabBarBase()
-{
-    QTabWidget* tw = getTabWidget();
-    if(0 == tw)
-        return 0;
-
-    return (QWidget*)tw->child("tab base", "QWidget", false);
+    p.drawPixmap (pt, *qWarpSystemPixmaps.getPixmap (QWarpPixmap::tabhdrminus,
+                                                     QWarpPixmap::internal));
 }
 
 int QWarpTabPanelHeader::currentInx()
 {
-    QTabBar* tb = getTabBar();
-    if(0 == tb)
+    if (_tabBar == 0)
         return 0; // should never happen
-    int id = tb->currentTab();
-
-    return (id == 0) ? 0 : tb->indexOf(id);
-}
-
-void QWarpTabPanelHeader::setupLayout(QSize sz)
-{
-    QTabWidget* tw = getTabWidget();
-    if(0 == tw)
-        return;
-
-    if(QSize(0, 0) == sz)
-        sz = tw->size();
-
-    QTabBar* tb = getTabBar();
-    if(0 == tb)
-        return;
-
-    int th = tb->size().height();
-    int fh = QFontMetrics(QApplication::font()).boundingRect("X").height();
-
-    QRect r(17, 0, sz.width() - 37, 0);
-    if(_bottom)
-    {
-        r.setBottom(sz.height() - th - 17);
-        r.setTop(r.bottom() - fh);
-        r.addCoords(-5, -7, 6, 6);
+    int id = _tabBar->currentTab();
+
+    return (id == 0) ? 0 : _tabBar->indexOf (id);
+}
+
+void QWarpTabPanelHeader::setupLayout (QRect rect)
+{
+    QRect r (rect);
+    bool reverse = QApplication::reverseLayout();
+    if (_bottom)
+    {
+        if (reverse)
+            r.addCoords (14, 0, -12, -13);
+        else
+            r.addCoords (12, 0, -14, -13);
     }
     else
     {
-        r.setTop(th + 14);
-        r.setBottom(r.top() + fh);
-        r.addCoords(-5, -6, 6, 7);
-    }
-
-    setGeometry(r);
-}
-
-void QWarpTabPanelHeader::addIfNotPresent(QTabBar const* tb)
-{
-    QWidget* ww = tb->parentWidget();
-    if((0 == ww) || !ww->inherits("QTabWidget"))
-        return;
-    QTabWidget* tw = (QTabWidget*)ww;
-
-    if(0 != tw->child("qt_warp_tabpanel_header", "QWarpTabPanelHeader", false))
-        return; // header already there
-
-    // create if not yet present, with the tab widget as parent
-    // note: deletion occurs when the tab widget is destroyed
-
-    new QWarpTabPanelHeader(tw);
-}
+        if (reverse)
+            r.addCoords (14, 13, -12, 0);
+        else
+            r.addCoords (12, 13, -14, 0);
+    }
+
+    setGeometry (r);
+}
+
+#endif // QT_PM_NO_TABWIDGET_HEADERS
 
 /*----------------------------------------------------------------------*\
@@ -1830,5 +1750,5 @@
 
 /*! \reimp */
-void QWarp4Style::polish(QApplication* app)
+void QWarp4Style::polish (QApplication *app)
 {
 #ifndef QT_NO_ICONSET
@@ -1845,5 +1765,5 @@
 
 /*! \reimp */
-void QWarp4Style::unPolish(QApplication*)
+void QWarp4Style::unPolish (QApplication *)
 {
 #ifndef QT_NO_ICONSET
@@ -1868,19 +1788,86 @@
 
 /*! \reimp */
-void QWarp4Style::polish(QWidget* widget)
-{
-    QCommonStyle::polish(widget);
+void QWarp4Style::polish (QWidget *widget)
+{
+    if (widget != 0 && widget->inherits ("QTabWidget"))
+    {
+        QTabWidget *tw = (QTabWidget *) widget;
+
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+        // create the tab panel header widget
+        new QWarpTabPanelHeader (tw);
+#endif
+
+        // reduce the widget stack's frame rect to get space for drawing
+        // PE_PanelTabWidget. Hackish, but there seems to be no any official way
+        // in the QStyle framework to change the tab the width of the frame
+        // drawn by PE_PanelTabWidget (QFrame::TabWidgetPanel style).
+        QWidgetStack *ws = (QWidgetStack *) tw->child ("tab pages",
+                                                       "QWidgetStack", false);
+        Q_ASSERT (ws);
+        if (ws)
+        {
+            QRect r = ws->rect();
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+            bool reverse = QApplication::reverseLayout();
+            if (reverse)
+            {
+                if (tw->tabPosition() == QTabWidget::Bottom)
+                    r.addCoords (15, 12, -12, 0);
+                else
+                    r.addCoords (15, 0, -12, -12);
+            }
+            else
+            {
+                if (tw->tabPosition() == QTabWidget::Bottom)
+                    r.addCoords (12, 12, -15, 0);
+                else
+                    r.addCoords (12, 0, -15, -12);
+            }
+#else
+            if (tw->tabPosition() == QTabWidget::Bottom)
+                r.addCoords (12, 12, -12, 0);
+            else
+                r.addCoords (12, 0, -12, -12);
+#endif
+            ws->setFrameRect (r);
+        }
+    }
+
+    QCommonStyle::polish (widget);
 }
 
 /*! \reimp */
-void QWarp4Style::unPolish(QWidget* widget)
-{
-    QCommonStyle::polish(widget);
+void QWarp4Style::unPolish (QWidget *widget)
+{
+    if (widget != 0 && widget->inherits ("QTabWidget"))
+    {
+        QTabWidget *tw = (QTabWidget *) widget;
+
+        // restore the widget stack's frame rect
+        QWidgetStack *ws = (QWidgetStack *) tw->child ("tab pages",
+                                                       "QWidgetStack", false);
+        Q_ASSERT (ws);
+        if (ws)
+            ws->setFrameRect (QRect());
+
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+        // delete the tab panel header widget
+        QWarpTabPanelHeader* tph =
+            (QWarpTabPanelHeader *) tw->child ("qt_warp_tabpanel_header",
+                                               "QWarpTabPanelHeader", false);
+        Q_ASSERT (tph);
+        if (tph != 0)
+            delete tph;
+#endif
+    }
+
+    QCommonStyle::unPolish (widget);
 }
 
 /*! \reimp */
-void QWarp4Style::polish(QPalette& pal)
-{
-    QCommonStyle::polish(pal);
+void QWarp4Style::polish (QPalette &pal)
+{
+    QCommonStyle::polish (pal);
 }
 
@@ -2188,126 +2175,101 @@
         case PE_PanelTabWidget:
         {
-            // compensate for artificially reduced frame size
-            // note that we get the information about "bottom" or "top" tabs
-            // from the "mid line width" in the "opt" parameter
-            // (see also QWarpTabPanelHeader::QWarpTabPanelHeader)
-            bool bottom = (bool)opt.midLineWidth();
-            QRect rr1(rr), rr2(rr);
-            if(bottom)
-            {
-                rr1.addCoords(-11, -11, 14, 0);
-                rr2.addCoords(0, 0, 3, 0);
+            bool reverse = QApplication::reverseLayout();
+
+            QRect rr2 (rr);
+
+            // compensate for reduced frame rect in polish(). Note that due to
+            // this frame rect hack, it's not possible to draw a
+            // QFrame::TabWidgetPanel styled frame outside the QTabWidget
+            // context.
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+            if (reverse)
+            {
+                rr.addCoords (-15, -12, 12, 12);
+                rr2.addCoords (-4, -1, 1, 1);
             }
             else
             {
-                rr1.addCoords(-11, 0, 14, 11);
-                rr2.addCoords(0, 0, 3, 0);
-            }
-            p->setClipRect(rr1);
-
-            p->setPen(cg.light());
-            if(bottom)
-            {
-                p->drawLine(rr1.left(), rr1.top(), rr1.left(), rr1.bottom());
-                p->drawLine(rr1.left(), rr1.top(), rr1.right(), rr1.top());
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
-            }
+                rr.addCoords (-12, -12, 15, 12);
+                rr2.addCoords (-1, -1, 4, 1);
+            }
+#else
+            rr.addCoords (-12, -12, 12, 12);
+            rr2.addCoords (-1, -1, 1, 1);
+#endif
+
+            p->setClipRect (rr);
+
+            for (int i = 0; i < 2; ++ i)
+            {
+                p->setPen (i == 0 ? cg.light() : cg.dark());
+                if (i > 0)
+                {
+                    QRect rt = rr2;
+                    rr2 = rr;
+                    rr = rt;
+                }
+
+                p->drawLine (rr.left(), rr.top(), rr.left(), rr.bottom() - 1);
+                p->drawLine (rr.left(), rr.top(), rr.right(), rr.top());
+                p->drawLine (rr2.left(), rr2.bottom(), rr2.right(), rr2.bottom());
+                p->drawLine (rr2.right(), rr2.top() + 1, rr2.right(), rr2.bottom());
+            }
+
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+            if (reverse)
+                p->drawLine (rr.left() + 3, rr.bottom() - 2,
+                             rr.left() + 3, rr.top() + 2);
             else
-            {
-                p->drawLine(rr1.left(), rr1.top(), rr1.left(), rr1.bottom() - 1);
-                p->drawLine(rr2.left(), rr2.bottom(), rr2.right(), rr2.bottom());
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
-            }
-
-            p->setPen(cg.dark());
-            if(bottom)
-            {
-                p->drawLine(rr1.right(), rr1.top(), rr1.right(), rr1.bottom());
-                p->drawLine(rr2.left(), rr2.top(), rr2.right(), rr2.top());
-                p->drawLine(rr2.left(), rr2.top(), rr2.left(), rr2.bottom());
-                rr2.addCoords(0, 2, -3, 0);
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
-            }
+                p->drawLine (rr.right() - 3, rr.bottom() - 2,
+                             rr.right() - 3, rr.top() + 2);
+#endif
+            break;
+        }
+
+        case PE_PanelMenuBar:
+        {
+            // It looks like this code is never being called!
+            break;
+        }
+
+        case PE_PanelGroupBox:
+        {
+            qDrawWarpPanel(p, rr, cg, 0);
+            break;
+        }
+
+        case PE_TabBarBase:
+        {
+            bool bottom = flags & Style_Bottom;
+
+            QRect rr2 (rr);
+            if (bottom)
+                rr2.addCoords (11, 0, -11, -11);
             else
-            {
-                p->drawLine(rr1.left(), rr1.bottom(), rr1.right(), rr1.bottom());
-                p->drawLine(rr1.right(), rr1.top(), rr1.right(), rr1.bottom());
-                p->drawLine(rr2.left(), rr2.top(), rr2.left(), rr2.bottom() - 1);
-                rr2.addCoords(0, 0, -3, -2);
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
-            }
-
-            break;
-        }
-
-        case PE_PanelMenuBar:
-        {
-            // It looks like this code is never being called!
-            break;
-        }
-
-        case PE_PanelGroupBox:
-        {
-            qDrawWarpPanel(p, rr, cg, 0);
-            break;
-        }
-
-        case PE_TabBarBase:
-        {
-            bool bottom = flags & Style_Bottom;
-            if(bottom)
-                rr.addCoords(0, 0, 0, -1);
-            else
-                rr.addCoords(0, 1, 0, 0);
-            QRect rr2(rr);
-            if(bottom)
-                rr2.addCoords(11, 0, -11, -11);
-            else
-                rr2.addCoords(11, 11, -11, 0);
-
-            p->setPen(cg.light());
-            if(bottom)
-            {
-                p->drawLine(rr.left(), rr.top(), rr.left(), rr.bottom());
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
-                p->drawLine(rr2.left(), rr2.bottom(), rr2.right(), rr2.bottom());
-#ifndef QT_PM_NO_TABWIDGET_HEADERS
-                p->drawLine(rr2.left() + 6, rr2.top() + 2, rr2.right() - 9, rr2.top() + 2);
-#endif
-            }
-            else
-            {
-                p->drawLine(rr.left(), rr.top(), rr.right(), rr.top());
-                p->drawLine(rr.left(), rr.top(), rr.left(), rr.bottom());
-                p->drawLine(rr2.right(), rr2.top() + 1, rr2.right(), rr2.bottom());
-#ifndef QT_PM_NO_TABWIDGET_HEADERS
-                p->drawLine(rr2.left() + 6, rr2.bottom() - 1, rr2.right() - 9, rr2.bottom() - 1);
-#endif
-            }
-
-            p->setPen(cg.dark());
-            if(bottom)
-            {
-                p->drawLine(rr.left(), rr.bottom(), rr.right(), rr.bottom());
-                p->drawLine(rr.right(), rr.top(), rr.right(), rr.bottom());
-                p->drawLine(rr2.left(), rr2.top(), rr2.left(), rr2.bottom() - 1);
-#ifndef QT_PM_NO_TABWIDGET_HEADERS
-                p->drawLine(rr2.left() + 6, rr2.top() + 1, rr2.right() - 9, rr2.top() + 1);
-#endif
-                rr2.addCoords(2, 0, -3, -2);
-                p->drawLine(rr2.left(), rr2.bottom(), rr2.right(), rr2.bottom());
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
-            }
-            else
-            {
-                p->drawLine(rr.right(), rr.top(), rr.right(), rr.bottom());
-                p->drawLine(rr2.left(), rr2.top(), rr2.right(), rr2.top());
-                p->drawLine(rr2.left(), rr2.top(), rr2.left(), rr2.bottom());
-#ifndef QT_PM_NO_TABWIDGET_HEADERS
-                p->drawLine(rr2.left() + 6, rr2.bottom() - 2, rr2.right() - 9, rr2.bottom() - 2);
-#endif
-                rr2.addCoords(2, 2, -3, 0);
-                p->drawLine(rr2.left(), rr2.top(), rr2.right(), rr2.top());
-                p->drawLine(rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
+                rr2.addCoords (11, 11, -11, 0);
+
+            for (int i = 0; i < 2; ++ i)
+            {
+                p->setPen (i == 0 ? cg.light() : cg.dark());
+                if (i > 0)
+                {
+                    QRect rt = rr2;
+                    rr2 = rr;
+                    rr = rt;
+                }
+
+                if(bottom)
+                {
+                    p->drawLine (rr.left(), rr.top(), rr.left(), rr.bottom() - 1);
+                    p->drawLine (rr2.right(), rr2.top(), rr2.right(), rr2.bottom());
+                    p->drawLine (rr2.left(), rr2.bottom(), rr2.right(), rr2.bottom());
+                }
+                else
+                {
+                    p->drawLine (rr.left(), rr.top(), rr.right(), rr.top());
+                    p->drawLine (rr.left(), rr.top(), rr.left(), rr.bottom());
+                    p->drawLine (rr2.right(), rr2.top() + 1, rr2.right(), rr2.bottom());
+                }
             }
 
@@ -2629,10 +2591,4 @@
                               (QTabBar::TriangularBelow == tb->shape());
                 int id = tb->indexOf(t->identifier());
-
-                // check if the panel header widget is already present and
-                // create them here
-                // note that this is the only place to do it from within the
-                // style class!
-                QWarpTabPanelHeader::addIfNotPresent(tb);
 
                 static const QColor tabCols[10] =
@@ -2698,18 +2654,20 @@
                     tr.addCoords(-hdiff / 2, 0, hdiff / 2, 0);
 
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
                     QWidget* pw = widget->parentWidget();
-                    if((0 != pw) && (pw->inherits("QTabWidget")))
+                    if (pw != 0 && pw->inherits ("QTabWidget"))
                     {
-                        QTabWidget* tw = (QTabWidget*)pw;
-                        QWarpTabPanelHeader* twh =
-                            (QWarpTabPanelHeader*)tw->child("qt_warp_tabpanel_header",
-                                                           "QWarpTabPanelHeader", false);
-                        if(0 != twh)
+                        QTabWidget *tw = (QTabWidget *) pw;
+                        QWarpTabPanelHeader *tph =
+                            (QWarpTabPanelHeader *) tw->child ("qt_warp_tabpanel_header",
+                                                               "QWarpTabPanelHeader", false);
+                        if (tph != 0)
                         {
-                            twh->setCaption(t->text());
-                            QRect r(twh->visibleRect());
-                            twh->repaint();
+                            tph->setCaption (t->text());
+                            QRect r (tph->visibleRect());
+                            tph->repaint();
                         }
                     }
+#endif // QT_PM_NO_TABWIDGET_HEADERS
                 }
 
@@ -3160,5 +3118,5 @@
   \reimp
 */
-int QWarp4Style::pixelMetric(PixelMetric metric, QWidget const* widget) const
+int QWarp4Style::pixelMetric (PixelMetric metric, const QWidget *widget) const
 {
     int ret;
@@ -3177,6 +3135,6 @@
         case PM_ExclusiveIndicatorWidth:
         {
-            QPixmap const* ip = qWarpSystemPixmaps.getPixmap(QWarpPixmap::chkboxnormal,
-                                                             QWarpPixmap::internal);
+            QPixmap const* ip = qWarpSystemPixmaps.getPixmap (QWarpPixmap::chkboxnormal,
+                                                              QWarpPixmap::internal);
             ret = ip->width();
             break;
@@ -3186,112 +3144,132 @@
         case PM_ExclusiveIndicatorHeight:
         {
-            QPixmap const* ip = qWarpSystemPixmaps.getPixmap(QWarpPixmap::chkboxnormal,
-                                                             QWarpPixmap::internal);
+            QPixmap const* ip = qWarpSystemPixmaps.getPixmap (QWarpPixmap::chkboxnormal,
+                                                              QWarpPixmap::internal);
             ret = ip->height();
             break;
         }
 
-        #ifndef QT_NO_SCROLLBAR
-            case PM_ScrollBarExtent:
-            {
-                if(!widget)
-                {
-                    ret = 16;
-                }
-                else
-                {
-                    QScrollBar const* bar = (QScrollBar const*)widget;
-                    int s = (bar->orientation() == Qt::Horizontal) ?
-                            QApplication::globalStrut().height() :
-                            QApplication::globalStrut().width();
-                    ret = QMAX(16, s);
-                }
-
+#ifndef QT_NO_SCROLLBAR
+        case PM_ScrollBarExtent:
+        {
+            if (!widget)
+            {
+                ret = 16;
+            }
+            else
+            {
+                const QScrollBar * bar = (const QScrollBar *) widget;
+                int s = (bar->orientation() == Qt::Horizontal) ?
+                        QApplication::globalStrut().height() :
+                        QApplication::globalStrut().width();
+                ret = QMAX(16, s);
+            }
+
+            break;
+        }
+
+        case PM_ScrollBarSliderMin:
+        {
+            ret = 20;
+            break;
+        }
+#endif
+
+        case PM_MaximumDragDistance:
+        {
+            ret = -1;
+            break;
+        }
+
+#ifndef QT_NO_SLIDER
+        case PM_SliderThickness:
+        {
+            ret = 20;
+            break;
+        }
+
+        case PM_SliderLength:
+        {
+            // we increase the "length" by 2 x 2, but then draw the slider 2 pixels
+            // smaller than indicated, so we get the effect of a slider that does
+            // not fully touch the extreme ends of the "groove"
+            ret = 12 + 4;
+            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:
+        {
+            QSlider const* sl = (QSlider const*) widget;
+            int space = (sl->orientation() == Horizontal) ? sl->height() : sl->width();
+            int ticks = sl->tickmarks();
+            int n = 0;
+            if (ticks & QSlider::Above)
+                n++;
+            if (ticks & QSlider::Below)
+                n++;
+            if (!n)
+            {
+                ret = space;
                 break;
             }
 
-            case PM_ScrollBarSliderMin:
-            {
-                ret = 20;
+            int thick = 6;      // Magic constant to get 5 + 16 + 5
+            if (ticks != QSlider::Both && ticks != QSlider::NoMarks)
+                thick += pixelMetric (PM_SliderLength, sl) / 4;
+
+            space -= thick;
+            //### the two sides may be unequal in size
+            if(space > 0)
+                thick += (space * 2) / (n + 2);
+            ret = thick;
+
+            break;
+        }
+#endif // QT_NO_SLIDER
+
+        case PM_MenuBarFrameWidth:
+        {
+            ret = 0;
+            break;
+        }
+
+        case PM_MenuBarItemSpacing:
+        {
+            ret = 8;
+            break;
+        }
+
+        case PM_PopupMenuFrameHorizontalExtra:
+        {
+            ret = 0;
+            break;
+        }
+
+        case PM_PopupMenuFrameVerticalExtra:
+        {
+            ret = 1;
+            break;
+        }
+
+        case PM_DefaultFrameWidth:
+        {
+            if (widget && widget->inherits ("QWidgetStack") &&
+                !qstrcmp (widget->name(), "tab pages"))
+            {
+#ifndef QT_PM_NO_TABWIDGET_HEADERS
+                // cause 1px overlap with the tab header base widget to get the
+                // left vertical line joined with the bended corner (see the
+                // PE_PanelTabWidget primitive and QTabWidget::setUpLayout())
+                ret = 1;
+#else
+                // no frame is drawn within the the widget stack frame rect
+                ret = 0;
+#endif
                 break;
             }
-        #endif
-
-        case PM_MaximumDragDistance:
-        {
-            ret = -1;
-            break;
-        }
-
-        #ifndef QT_NO_SLIDER
-            case PM_SliderThickness:
-            {
-                ret = 20;
-                break;
-            }
-
-            case PM_SliderLength:
-            {
-                // we increase the "length" by 2 x 2, but then draw the slider 2 pixels
-                // smaller than indicated, so we get the effect of a slider that does
-                // not fully touch the extreme ends of the "groove"
-                ret = 12 + 4;
-                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:
-            {
-                QSlider const* sl = (QSlider const*) widget;
-                int space = (sl->orientation() == Horizontal) ? sl->height() : sl->width();
-                int ticks = sl->tickmarks();
-                int n = 0;
-                if(ticks & QSlider::Above)
-                    n++;
-                if(ticks & QSlider::Below)
-                    n++;
-                if(!n)
-                {
-                    ret = space;
-                    break;
-                }
-
-                int thick = 6;      // Magic constant to get 5 + 16 + 5
-                if(ticks != QSlider::Both && ticks != QSlider::NoMarks)
-                    thick += pixelMetric(PM_SliderLength, sl) / 4;
-
-                space -= thick;
-                //### the two sides may be unequal in size
-                if(space > 0)
-                    thick += (space * 2) / (n + 2);
-                ret = thick;
-
-                break;
-            }
-        #endif // QT_NO_SLIDER
-
-        case PM_MenuBarFrameWidth:
-        {
-            ret = 0;
-            break;
-        }
-
-        case PM_MenuBarItemSpacing:
-        {
-            ret = 8;
-            break;
-        }
-
-        case PM_PopupMenuFrameHorizontalExtra:
-        {
-            ret = 0;
-            break;
-        }
-
-        case PM_PopupMenuFrameVerticalExtra:
-        {
-            ret = 1;
+            ret = QCommonStyle::pixelMetric (metric, widget);
             break;
         }
@@ -3306,7 +3284,7 @@
         {
 #ifndef QT_PM_NO_TABWIDGET_HEADERS
-            ret = QFontMetrics(QApplication::font()).boundingRect("X").height() + 29;
+            ret = QFontMetrics (widget->font()).boundingRect ("X").height() + 28;
 #else
-            ret = 16;
+            ret = 12;
 #endif
             break;
@@ -3315,5 +3293,5 @@
         case PM_TabBarBaseOverlap:
         {
-            ret = 6;
+            ret = 5;
             break;
         }
@@ -3375,18 +3353,18 @@
         {
 #ifndef QT_NO_PUSHBUTTON
-                const QPushButton* button = (const QPushButton*)widget;
-                sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt);
-                int w = sz.width(),
-                    h = sz.height();
-
-                int defwidth = 0;
-                if(button->isDefault() || button->autoDefault())
-                    defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, widget);
-                if(w < 80 + defwidth && !button->pixmap())
-                    w = 80 + defwidth;
-                if(h < 23 + defwidth)
-                    h = 23 + defwidth;
-
-                sz = QSize(w, h);
+            const QPushButton* button = (const QPushButton*)widget;
+            sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt);
+            int w = sz.width(),
+                h = sz.height();
+
+            int defwidth = 0;
+            if(button->isDefault() || button->autoDefault())
+                defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, widget);
+            if(w < 80 + defwidth && !button->pixmap())
+                w = 80 + defwidth;
+            if(h < 23 + defwidth)
+                h = 23 + defwidth;
+
+            sz = QSize(w, h);
 #endif // QT_NO_PUSHBUTTON
 
@@ -3405,57 +3383,57 @@
         {
 #ifndef QT_NO_POPUPMENU
-                if(! widget || opt.isDefault())
-                    break;
-
-                QPopupMenu const* popup = (QPopupMenu const*)widget;
-                QMenuItem* mi = opt.menuItem();
-                int iconw = QMAX(11, opt.maxIconWidth());
-                QString s = mi->text();
-                int w = sz.width(),
-                    h = sz.height();
-
-                if(mi->custom())
-                {
-                    w = mi->custom()->sizeHint().width();
-                    h = mi->custom()->sizeHint().height();
-                    if(!mi->custom()->fullSpan())
-                        w += iconw;
-                }
-                else if(mi->widget())
-                {
-                }
-                else if(mi->isSeparator())
-                {
-                    w = 10; // arbitrary
-                    h = 8;
-                }
-                else
-                {
-                    if(mi->pixmap())
-                        h = QMAX(h, mi->pixmap()->height() + 3);
-                    else if(!s.isNull())
-                        h = QMAX(h, popup->fontMetrics().height() + 1);
-
-                    if(mi->iconSet())
-                    {
-                        h = QMAX(h, mi->iconSet()->
-                                    pixmap(QIconSet::Small, QIconSet::Normal).height() + 3);
-                        w = QMAX(w, iconw);
-                    }
-                }
-
-                if(!s.isNull())
-                {
-                    w += 19;
-                }
-
-                if(qPopupMenuHasSub(popup))
-                {
-                    w += 19;
-                }
-
-                w += 9;
-
-                sz = QSize(w, h);
+            if(! widget || opt.isDefault())
+                break;
+
+            QPopupMenu const* popup = (QPopupMenu const*)widget;
+            QMenuItem* mi = opt.menuItem();
+            int iconw = QMAX(11, opt.maxIconWidth());
+            QString s = mi->text();
+            int w = sz.width(),
+                h = sz.height();
+
+            if(mi->custom())
+            {
+                w = mi->custom()->sizeHint().width();
+                h = mi->custom()->sizeHint().height();
+                if(!mi->custom()->fullSpan())
+                    w += iconw;
+            }
+            else if(mi->widget())
+            {
+            }
+            else if(mi->isSeparator())
+            {
+                w = 10; // arbitrary
+                h = 8;
+            }
+            else
+            {
+                if(mi->pixmap())
+                    h = QMAX(h, mi->pixmap()->height() + 3);
+                else if(!s.isNull())
+                    h = QMAX(h, popup->fontMetrics().height() + 1);
+
+                if(mi->iconSet())
+                {
+                    h = QMAX(h, mi->iconSet()->
+                                pixmap(QIconSet::Small, QIconSet::Normal).height() + 3);
+                    w = QMAX(w, iconw);
+                }
+            }
+
+            if(!s.isNull())
+            {
+                w += 19;
+            }
+
+            if(qPopupMenuHasSub(popup))
+            {
+                w += 19;
+            }
+
+            w += 9;
+
+            sz = QSize(w, h);
 #endif // QT_NO_POPUPMENU
 
@@ -3515,66 +3493,66 @@
                                  QStyleOption const& opt) const
 {
-    #ifndef QT_NO_IMAGEIO_XPM
-        switch (stylepixmap)
-        {
-            // SP_TitleBarShadeButton - shade button on titlebars.
-            case SP_TitleBarShadeButton:
-                return *qWarpSystemPixmaps.getPixmap(54, // any SBMP_ value??
-                                                     QWarpPixmap::bmp);
-
-            // SP_TitleBarUnshadeButton - unshade button on titlebars.
-            case SP_TitleBarUnshadeButton:
-                return *qWarpSystemPixmaps.getPixmap(56, // any SBMP_ value??
-                                                     QWarpPixmap::bmp);
-
-            // SP_TitleBarNormalButton - normal (restore) button on titlebars.
-            case SP_TitleBarNormalButton:
-                return *qWarpSystemPixmaps.getPixmap(SBMP_RESTOREBUTTON,
-                                                     QWarpPixmap::bmp);
-
-            // SP_TitleBarMinButton - minimize button on titlebars. For example, in a QWorkspace.
-            case SP_TitleBarMinButton:
-                return *qWarpSystemPixmaps.getPixmap(SBMP_MINBUTTON,
-                                                     QWarpPixmap::bmp);
-
-            // SP_TitleBarMaxButton - maximize button on titlebars.
-            case SP_TitleBarMaxButton:
-                return *qWarpSystemPixmaps.getPixmap(SBMP_MAXBUTTON,
-                                                     QWarpPixmap::bmp);
-
-            // SP_TitleBarCloseButton - close button on titlebars.
-            case SP_TitleBarCloseButton:
-                return *qWarpSystemPixmaps.getPixmap(52, // any SBMP_ value??
-                                                     QWarpPixmap::bmp);
-
-            // SP_DockWindowCloseButton - close button on dock windows; see also QDockWindow.
-            case SP_DockWindowCloseButton:
-                return *qWarpSystemPixmaps.getPixmap(52, // should be a bit smaller!
-                                                     QWarpPixmap::bmp);
-
-            // SP_MessageBoxInformation - the 'information' icon.
-            case SP_MessageBoxInformation:
-                return *qWarpSystemPixmaps.getPixmap(SPTR_ICONINFORMATION,
-                                                     QWarpPixmap::ico);
-
-            // SP_MessageBoxWarning - the 'warning' icon.
-            case SP_MessageBoxWarning:
-                return *qWarpSystemPixmaps.getPixmap(SPTR_ICONWARNING,
-                                                     QWarpPixmap::ico);
-
-            // SP_MessageBoxCritical - the 'critical' icon.
-            case SP_MessageBoxCritical:
-                return *qWarpSystemPixmaps.getPixmap(SPTR_ICONERROR,
-                                                     QWarpPixmap::ico);
-
-            // SP_MessageBoxQuestion - the 'question' icon.
-            case SP_MessageBoxQuestion:
-                return *qWarpSystemPixmaps.getPixmap(SPTR_ICONQUESTION,
-                                                     QWarpPixmap::ico);
-
-            default:
-                break;
-        }
-    #endif //QT_NO_IMAGEIO_XPM
+#ifndef QT_NO_IMAGEIO_XPM
+    switch (stylepixmap)
+    {
+        // SP_TitleBarShadeButton - shade button on titlebars.
+        case SP_TitleBarShadeButton:
+            return *qWarpSystemPixmaps.getPixmap(54, // any SBMP_ value??
+                                                 QWarpPixmap::bmp);
+
+        // SP_TitleBarUnshadeButton - unshade button on titlebars.
+        case SP_TitleBarUnshadeButton:
+            return *qWarpSystemPixmaps.getPixmap(56, // any SBMP_ value??
+                                                 QWarpPixmap::bmp);
+
+        // SP_TitleBarNormalButton - normal (restore) button on titlebars.
+        case SP_TitleBarNormalButton:
+            return *qWarpSystemPixmaps.getPixmap(SBMP_RESTOREBUTTON,
+                                                 QWarpPixmap::bmp);
+
+        // SP_TitleBarMinButton - minimize button on titlebars. For example, in a QWorkspace.
+        case SP_TitleBarMinButton:
+            return *qWarpSystemPixmaps.getPixmap(SBMP_MINBUTTON,
+                                                 QWarpPixmap::bmp);
+
+        // SP_TitleBarMaxButton - maximize button on titlebars.
+        case SP_TitleBarMaxButton:
+            return *qWarpSystemPixmaps.getPixmap(SBMP_MAXBUTTON,
+                                                 QWarpPixmap::bmp);
+
+        // SP_TitleBarCloseButton - close button on titlebars.
+        case SP_TitleBarCloseButton:
+            return *qWarpSystemPixmaps.getPixmap(52, // any SBMP_ value??
+                                                 QWarpPixmap::bmp);
+
+        // SP_DockWindowCloseButton - close button on dock windows; see also QDockWindow.
+        case SP_DockWindowCloseButton:
+            return *qWarpSystemPixmaps.getPixmap(52, // should be a bit smaller!
+                                                 QWarpPixmap::bmp);
+
+        // SP_MessageBoxInformation - the 'information' icon.
+        case SP_MessageBoxInformation:
+            return *qWarpSystemPixmaps.getPixmap(SPTR_ICONINFORMATION,
+                                                 QWarpPixmap::ico);
+
+        // SP_MessageBoxWarning - the 'warning' icon.
+        case SP_MessageBoxWarning:
+            return *qWarpSystemPixmaps.getPixmap(SPTR_ICONWARNING,
+                                                 QWarpPixmap::ico);
+
+        // SP_MessageBoxCritical - the 'critical' icon.
+        case SP_MessageBoxCritical:
+            return *qWarpSystemPixmaps.getPixmap(SPTR_ICONERROR,
+                                                 QWarpPixmap::ico);
+
+        // SP_MessageBoxQuestion - the 'question' icon.
+        case SP_MessageBoxQuestion:
+            return *qWarpSystemPixmaps.getPixmap(SPTR_ICONQUESTION,
+                                                 QWarpPixmap::ico);
+
+        default:
+            break;
+    }
+#endif //QT_NO_IMAGEIO_XPM
 
     return QCommonStyle::stylePixmap(stylepixmap, widget, opt);
@@ -3594,585 +3572,585 @@
     switch (ctrl)
     {
-        #ifndef QT_NO_SCROLLBAR
-            case CC_ScrollBar:
-            {
-                QScrollBar const* scrollbar = (QScrollBar const*)widget;
-                bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
-
-                QRect subline = querySubControlMetrics(ctrl, widget, SC_ScrollBarSubLine, opt),
-                      addline = querySubControlMetrics(ctrl, widget, SC_ScrollBarAddLine, opt),
-                      subpage = querySubControlMetrics(ctrl, widget, SC_ScrollBarSubPage, opt),
-                      addpage = querySubControlMetrics(ctrl, widget, SC_ScrollBarAddPage, opt),
-                      slider  = querySubControlMetrics(ctrl, widget, SC_ScrollBarSlider,  opt);
-                if(!scrollbar->isEnabled())
-                {
-                    subpage.unite(addpage).unite(slider); // fill the whole, empty bar
-                    addpage = slider = QRect(); // invalid rectangle
-                    maxedOut = true; // to avoid setting the Style_Enabled flag
-                }
-                bool isMin = scrollbar->value() <= scrollbar->minValue(),
-                     isMax = scrollbar->value() >= scrollbar->maxValue();
-
-                if((sub & SC_ScrollBarSubLine) && subline.isValid())
-                    drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
-                                  ((maxedOut || isMin) ? Style_Default : Style_Enabled) |
-                                  ((!isMin && (subActive == SC_ScrollBarSubLine)) ? Style_Down : Style_Default) |
-                                  ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
-                if((sub & SC_ScrollBarAddLine) && addline.isValid())
-                    drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
-                                  ((maxedOut || isMax) ? Style_Default : Style_Enabled) |
-                                  ((!isMax && (subActive == SC_ScrollBarAddLine)) ? Style_Down : Style_Default) |
-                                  ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
-                if((sub & SC_ScrollBarSubPage) && subpage.isValid())
-                    drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
-                                  ((maxedOut) ? Style_Default : Style_Enabled) |
-                                  ((subActive == SC_ScrollBarSubPage) ? Style_Down : Style_Default) |
-                                  ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
-                if((sub & SC_ScrollBarAddPage) && addpage.isValid())
-                    drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
-                                  ((maxedOut) ? Style_Default : Style_Enabled) |
-                                  ((subActive == SC_ScrollBarAddPage) ? Style_Down : Style_Default) |
-                                  ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
-                if((sub & SC_ScrollBarSlider) && slider.isValid())
-                    drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
-                                  ((maxedOut) ? Style_Default : Style_Enabled) |
-                                  ((subActive == SC_ScrollBarSlider) ? Style_Down : Style_Default) |
-                                  ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
-
-                break;
-            }
-        #endif // QT_NO_SCROLLBAR
+#ifndef QT_NO_SCROLLBAR
+        case CC_ScrollBar:
+        {
+            QScrollBar const* scrollbar = (QScrollBar const*)widget;
+            bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
+
+            QRect subline = querySubControlMetrics(ctrl, widget, SC_ScrollBarSubLine, opt),
+                  addline = querySubControlMetrics(ctrl, widget, SC_ScrollBarAddLine, opt),
+                  subpage = querySubControlMetrics(ctrl, widget, SC_ScrollBarSubPage, opt),
+                  addpage = querySubControlMetrics(ctrl, widget, SC_ScrollBarAddPage, opt),
+                  slider  = querySubControlMetrics(ctrl, widget, SC_ScrollBarSlider,  opt);
+            if(!scrollbar->isEnabled())
+            {
+                subpage.unite(addpage).unite(slider); // fill the whole, empty bar
+                addpage = slider = QRect(); // invalid rectangle
+                maxedOut = true; // to avoid setting the Style_Enabled flag
+            }
+            bool isMin = scrollbar->value() <= scrollbar->minValue(),
+                 isMax = scrollbar->value() >= scrollbar->maxValue();
+
+            if((sub & SC_ScrollBarSubLine) && subline.isValid())
+                drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
+                              ((maxedOut || isMin) ? Style_Default : Style_Enabled) |
+                              ((!isMin && (subActive == SC_ScrollBarSubLine)) ? Style_Down : Style_Default) |
+                              ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
+            if((sub & SC_ScrollBarAddLine) && addline.isValid())
+                drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
+                              ((maxedOut || isMax) ? Style_Default : Style_Enabled) |
+                              ((!isMax && (subActive == SC_ScrollBarAddLine)) ? Style_Down : Style_Default) |
+                              ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
+            if((sub & SC_ScrollBarSubPage) && subpage.isValid())
+                drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
+                              ((maxedOut) ? Style_Default : Style_Enabled) |
+                              ((subActive == SC_ScrollBarSubPage) ? Style_Down : Style_Default) |
+                              ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
+            if((sub & SC_ScrollBarAddPage) && addpage.isValid())
+                drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
+                              ((maxedOut) ? Style_Default : Style_Enabled) |
+                              ((subActive == SC_ScrollBarAddPage) ? Style_Down : Style_Default) |
+                              ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
+            if((sub & SC_ScrollBarSlider) && slider.isValid())
+                drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
+                              ((maxedOut) ? Style_Default : Style_Enabled) |
+                              ((subActive == SC_ScrollBarSlider) ? Style_Down : Style_Default) |
+                              ((scrollbar->orientation() == Qt::Horizontal) ? Style_Horizontal : 0));
+
+            break;
+        }
+#endif // QT_NO_SCROLLBAR
 
         case CC_SpinWidget:
         {
-            #ifndef QT_NO_SPINWIDGET
-                QSpinWidget const* sw = (QSpinWidget const*)widget;
-                SFlags flags;
-                PrimitiveElement pe;
-
-                if(sub & SC_SpinWidgetFrame)
-                {
-                    qDrawWarpPanel(p, r, cg, -1);
-                }
-
-                if((sub & SC_SpinWidgetUp) ||
-                   (sub & SC_SpinWidgetDown))
-                {
-                    flags = Style_Enabled;
-                    if((subActive == SC_SpinWidgetUp) ||
-                       (subActive == SC_SpinWidgetDown))
-                        flags |= Style_Sunken;
+#ifndef QT_NO_SPINWIDGET
+            QSpinWidget const* sw = (QSpinWidget const*)widget;
+            SFlags flags;
+            PrimitiveElement pe;
+
+            if(sub & SC_SpinWidgetFrame)
+            {
+                qDrawWarpPanel(p, r, cg, -1);
+            }
+
+            if((sub & SC_SpinWidgetUp) ||
+               (sub & SC_SpinWidgetDown))
+            {
+                flags = Style_Enabled;
+                if((subActive == SC_SpinWidgetUp) ||
+                   (subActive == SC_SpinWidgetDown))
+                    flags |= Style_Sunken;
+                else
+                    flags |= Style_Raised;
+
+                // we "misuse" the On flag to indicate whether the
+                // "up" part or the "down" part of the button is sunken
+                if(subActive == SC_SpinWidgetUp)
+                    flags |= Style_On;
+
+                if(sub & SC_SpinWidgetUp)
+                {
+                    if(sw->buttonSymbols() == QSpinWidget::PlusMinus)
+                        pe = PE_SpinWidgetPlus;
                     else
-                        flags |= Style_Raised;
-
-                    // we "misuse" the On flag to indicate whether the
-                    // "up" part or the "down" part of the button is sunken
-                    if(subActive == SC_SpinWidgetUp)
-                        flags |= Style_On;
-
-                    if(sub & SC_SpinWidgetUp)
+                        pe = PE_SpinWidgetUp;
+                }
+                else
+                {
+                    if(sw->buttonSymbols() == QSpinWidget::PlusMinus)
+                        pe = PE_SpinWidgetMinus;
+                    else
+                        pe = PE_SpinWidgetDown;
+                }
+
+                QRect re = sw->upRect();
+                re.setWidth(re.width() - 2);
+                bool reverse = QApplication::reverseLayout();
+                if(!reverse)
+                    re.moveLeft(re.left() + 2);
+                drawPrimitive(pe, p, re, cg, flags);
+
+                // doesn't work yet...
+                int x = re.left() - 1;
+                if(reverse)
+                {
+                    x = re.right() + 2;
+                    p->setPen(cg.light());
+                }
+                else
+                {
+                    p->setPen(cg.dark());
+                }
+                p->drawLine(x, re.top(), x, re.bottom());
+                p->setPen(cg.button());
+                x--;
+                p->drawLine(x, re.top(), x, re.bottom());
+            }
+
+            //if(sub & SC_SpinWidgetDown)
+            //{
+                // do nothing!
+                // note: for the Warp style we put all the up/down button
+                // functionality into the "up" button with the diagonal
+                // separator
+            //}
+#endif
+
+            break;
+        }
+
+#ifndef QT_NO_TOOLBUTTON
+        case CC_ToolButton:
+        {
+            bool right;
+            if((right = (QString("qt_right_btn") == widget->name())) ||
+               (QString("qt_left_btn") == widget->name()))
+            {
+                QToolButton* tb = (QToolButton*)widget;
+                QTabBar* ptb = (QTabBar*)tb->parentWidget();
+                if((0 == ptb) || !ptb->inherits("QTabBar"))
+                    return;
+                bool bottom = (QTabBar::RoundedBelow == ptb->shape()) ||
+                              (QTabBar::TriangularBelow == ptb->shape());
+
+                QRect r(visualRect(querySubControlMetrics(ctrl, widget, SC_ToolButton, opt), widget));
+                if(right)
+                    r.addCoords(-3, 0, 0, 0);
+                else
+                    r.addCoords(0, 0, 3, 0);
+                p->setClipRect(r);
+
+                p->setPen(cg.dark());
+                if(right)
+                {
+                    if(bottom)
+                        p->drawLine(r.right(), r.top(), r.right(), r.top() + 3);
+                    else
+                        p->drawLine(r.right(), r.bottom(), r.right(), r.bottom() - 3);
+                }
+
+                QRect tr1(r), tr2(r);
+                if(right)
+                {
+                    tr1.addCoords(-1, 0, 1, 0);
+                    tr2.addCoords(-21, 0, -21, 0);
+                }
+                else
+                {
+                    tr1.addCoords(21, 0, 21, 0);
+                    tr2.addCoords(-1, 0, 1, 0);
+                }
+
+                QColorGroup const& cg(tb->colorGroup());
+                qDrawTabBar(p, tr1, cg, cg.background(), false, bottom);
+                qDrawTabBar(p, tr2, cg, cg.background(), false, bottom);
+
+                if(bottom)
+                    r.addCoords(0, 2, 0, 2);
+                QPointArray triang;
+                if(right)
+                {
+                    triang.putPoints(0, 3,
+                                     r.left() + 8,  r.top() + 6,
+                                     r.left() + 19, r.top() + 12,
+                                     r.left() + 8,  r.top() + 18);
+                }
+                else
+                {
+                    triang.putPoints(0, 3,
+                                     r.right() - 10,  r.top() + 6,
+                                     r.right() - 21, r.top() + 12,
+                                     r.right() - 10,  r.top() + 18);
+                }
+                p->setBrush(QColor(0, 0, 255));
+                p->setPen(QPen::NoPen);
+                p->drawPolygon(triang);
+            }
+
+            else
+            {
+                QCommonStyle::drawComplexControl(ctrl, p, widget, r, cg, flags, sub,
+                                                 subActive, opt);
+            }
+
+            break;
+        }
+#endif // QT_NO_TOOLBUTTON
+
+#ifndef QT_NO_LISTVIEW
+        case CC_ListView:
+        {
+            if(sub & SC_ListView)
+            {
+                QCommonStyle::drawComplexControl(ctrl, p, widget, r, cg, flags, sub, subActive, opt);
+            }
+
+            if(sub & (SC_ListViewBranch | SC_ListViewExpand))
+            {
+                QListViewItem *item = opt.listViewItem(),
+                              *child = item->firstChild();
+                QListView* v = item->listView();
+                int y = r.y();
+                int bx = r.width() / 2;
+                int // linetop = 0,
+                    linebot = 0;
+
+                // skip the stuff above the exposed rectangle
+                while(child && ((y + child->height()) <= 0))
+                {
+                    y += child->totalHeight();
+                    child = child->nextSibling();
+                }
+
+                // notes about drawing lines for Warp:
+                // 1. Warp type lines follow a different logic than the "normal" lines
+                //    for "tree views" in Qt (which follows more or less Windows)
+                // 2. In order to ensure partial repaints, it looks like we have to
+                //    draw some lines twice: once with the parent and once with the
+                //    child (and hopefully to the same place...)
+
+                while(child && (y < r.height()))
+                {
+                    if(child->isVisible())
                     {
-                        if(sw->buttonSymbols() == QSpinWidget::PlusMinus)
-                            pe = PE_SpinWidgetPlus;
+                        int lh;
+                        if(!item->multiLinesEnabled())
+                            lh = child->height();
                         else
-                            pe = PE_SpinWidgetUp;
-                    }
-                    else
-                    {
-                        if(sw->buttonSymbols() == QSpinWidget::PlusMinus)
-                            pe = PE_SpinWidgetMinus;
-                        else
-                            pe = PE_SpinWidgetDown;
-                    }
-
-                    QRect re = sw->upRect();
-                    re.setWidth(re.width() - 2);
-                    bool reverse = QApplication::reverseLayout();
-                    if(!reverse)
-                        re.moveLeft(re.left() + 2);
-                    drawPrimitive(pe, p, re, cg, flags);
-
-                    // doesn't work yet...
-                    int x = re.left() - 1;
-                    if(reverse)
-                    {
-                        x = re.right() + 2;
-                        p->setPen(cg.light());
-                    }
-                    else
-                    {
-                        p->setPen(cg.dark());
-                    }
-                    p->drawLine(x, re.top(), x, re.bottom());
-                    p->setPen(cg.button());
-                    x--;
-                    p->drawLine(x, re.top(), x, re.bottom());
-                }
-
-                //if(sub & SC_SpinWidgetDown)
-                //{
-                    // do nothing!
-                    // note: for the Warp style we put all the up/down button
-                    // functionality into the "up" button with the diagonal
-                    // separator
-                //}
-            #endif
-
-            break;
-        }
-
-        #ifndef QT_NO_TOOLBUTTON
-            case CC_ToolButton:
-            {
-                bool right;
-                if((right = (QString("qt_right_btn") == widget->name())) ||
-                   (QString("qt_left_btn") == widget->name()))
-                {
-                    QToolButton* tb = (QToolButton*)widget;
-                    QTabBar* ptb = (QTabBar*)tb->parentWidget();
-                    if((0 == ptb) || !ptb->inherits("QTabBar"))
-                        return;
-                    bool bottom = (QTabBar::RoundedBelow == ptb->shape()) ||
-                                  (QTabBar::TriangularBelow == ptb->shape());
-
-                    QRect r(visualRect(querySubControlMetrics(ctrl, widget, SC_ToolButton, opt), widget));
-                    if(right)
-                        r.addCoords(-3, 0, 0, 0);
-                    else
-                        r.addCoords(0, 0, 3, 0);
-                    p->setClipRect(r);
-
-                    p->setPen(cg.dark());
-                    if(right)
-                    {
-                        if(bottom)
-                            p->drawLine(r.right(), r.top(), r.right(), r.top() + 3);
-                        else
-                            p->drawLine(r.right(), r.bottom(), r.right(), r.bottom() - 3);
-                    }
-
-                    QRect tr1(r), tr2(r);
-                    if(right)
-                    {
-                        tr1.addCoords(-1, 0, 1, 0);
-                        tr2.addCoords(-21, 0, -21, 0);
-                    }
-                    else
-                    {
-                        tr1.addCoords(21, 0, 21, 0);
-                        tr2.addCoords(-1, 0, 1, 0);
-                    }
-
-                    QColorGroup const& cg(tb->colorGroup());
-                    qDrawTabBar(p, tr1, cg, cg.background(), false, bottom);
-                    qDrawTabBar(p, tr2, cg, cg.background(), false, bottom);
-
-                    if(bottom)
-                        r.addCoords(0, 2, 0, 2);
-                    QPointArray triang;
-                    if(right)
-                    {
-                        triang.putPoints(0, 3,
-                                         r.left() + 8,  r.top() + 6,
-                                         r.left() + 19, r.top() + 12,
-                                         r.left() + 8,  r.top() + 18);
-                    }
-                    else
-                    {
-                        triang.putPoints(0, 3,
-                                         r.right() - 10,  r.top() + 6,
-                                         r.right() - 21, r.top() + 12,
-                                         r.right() - 10,  r.top() + 18);
-                    }
-                    p->setBrush(QColor(0, 0, 255));
-                    p->setPen(QPen::NoPen);
-                    p->drawPolygon(triang);
-                }
-
-                else
-                {
-                    QCommonStyle::drawComplexControl(ctrl, p, widget, r, cg, flags, sub,
-                                                     subActive, opt);
-                }
-
-                break;
-            }
-        #endif // QT_NO_TOOLBUTTON
-
-        #ifndef QT_NO_LISTVIEW
-            case CC_ListView:
-            {
-                if(sub & SC_ListView)
-                {
-                    QCommonStyle::drawComplexControl(ctrl, p, widget, r, cg, flags, sub, subActive, opt);
-                }
-
-                if(sub & (SC_ListViewBranch | SC_ListViewExpand))
-                {
-                    QListViewItem *item = opt.listViewItem(),
-                                  *child = item->firstChild();
-                    QListView* v = item->listView();
-                    int y = r.y();
-                    int bx = r.width() / 2;
-                    int // linetop = 0,
-                        linebot = 0;
-
-                    // skip the stuff above the exposed rectangle
-                    while(child && ((y + child->height()) <= 0))
-                    {
-                        y += child->totalHeight();
-                        child = child->nextSibling();
-                    }
-
-                    // notes about drawing lines for Warp:
-                    // 1. Warp type lines follow a different logic than the "normal" lines
-                    //    for "tree views" in Qt (which follows more or less Windows)
-                    // 2. In order to ensure partial repaints, it looks like we have to
-                    //    draw some lines twice: once with the parent and once with the
-                    //    child (and hopefully to the same place...)
-
-                    while(child && (y < r.height()))
-                    {
-                        if(child->isVisible())
+                            lh = p->fontMetrics().height() + 2 * v->itemMargin();
+                        lh = QMAX(lh, QApplication::globalStrut().height());
+                        if((lh % 2) > 0)
+                            lh++;
+                        linebot = y + lh / 2;
+                        p->setPen(cg.shadow());
+
+                        // parents and grandparents
+                        int vlx = bx - v->treeStepSize() + 2,
+                            vlyt = linebot - child->height() + 8,
+                            vlyb = linebot - child->height() + 9 + child->totalHeight();
+                        if(0 <= item->depth())
                         {
-                            int lh;
-                            if(!item->multiLinesEnabled())
-                                lh = child->height();
-                            else
-                                lh = p->fontMetrics().height() + 2 * v->itemMargin();
-                            lh = QMAX(lh, QApplication::globalStrut().height());
-                            if((lh % 2) > 0)
-                                lh++;
-                            linebot = y + lh / 2;
+                            // vertical line for parent
+                            if(item->isOpen())
+                            {
+                                if(0 == child->nextSibling())
+                                    p->drawLine(vlx, vlyt, vlx, linebot - 2);
+                                else
+                                    p->drawLine(vlx, vlyt, vlx, vlyb);
+                            }
+
+                            // vertical lines for grandparents and "older"
+                            QListViewItem* gp = item;
+                            while(0 < gp->depth())
+                            {
+                                gp = gp->parent();
+                                vlx -= v->treeStepSize();
+                                if(0 != gp->nextSibling())
+                                    p->drawLine(vlx, vlyt, vlx, vlyb);
+                            }
+                        }
+
+                        // draw child itself
+                        if((child->isExpandable() || child->childCount()) &&
+                           (child->height() > 0))
+                        {
+                            // horizontal line up to button
+                            if((0 <= item->depth()) && item->isOpen())
+                            {
+                                p->drawLine(bx - v->treeStepSize() + 3, linebot - 2,
+                                            bx - 6, linebot - 2);
+                            }
+
+                            // button
+                            QRect rr(bx - 6, linebot - 9, 16, 16);
+                            drawPrimitive(PE_ButtonCommand, p, rr, cg,
+                                          Style_Raised | Style_ButtonDefault);
+
+                            // plus or minus
+                            p->setPen(cg.light());
+                            p->drawLine(bx, linebot - 1, bx + 6, linebot - 1);
+                            if(!child->isOpen())
+                                p->drawLine(bx + 3, linebot + 2, bx + 3, linebot - 4);
                             p->setPen(cg.shadow());
-
-                            // parents and grandparents
-                            int vlx = bx - v->treeStepSize() + 2,
-                                vlyt = linebot - child->height() + 8,
-                                vlyb = linebot - child->height() + 9 + child->totalHeight();
-                            if(0 <= item->depth())
+                            p->drawLine(bx - 1, linebot - 2, bx + 5, linebot - 2);
+                            if(!child->isOpen())
+                                p->drawLine(bx + 2, linebot + 1, bx + 2, linebot - 5);
+
+                            // lines below expanded child
+                            if(child->isOpen())
                             {
-                                // vertical line for parent
-                                if(item->isOpen())
+                                // vertical line
+                                p->drawLine(bx + 2,
+                                            linebot + child->height() - 15,
+                                            bx + 2,
+                                            linebot + child->totalHeight() - child->height() - 2);
+
+                                // horizontal lines at child's children
+                                QListViewItem* child2 = child->firstChild();
+                                int y2 = linebot + child->height() - 2;
+                                while(child2 && (y2 < r.height()))
                                 {
-                                    if(0 == child->nextSibling())
-                                        p->drawLine(vlx, vlyt, vlx, linebot - 2);
-                                    else
-                                        p->drawLine(vlx, vlyt, vlx, vlyb);
-                                }
-
-                                // vertical lines for grandparents and "older"
-                                QListViewItem* gp = item;
-                                while(0 < gp->depth())
-                                {
-                                    gp = gp->parent();
-                                    vlx -= v->treeStepSize();
-                                    if(0 != gp->nextSibling())
-                                        p->drawLine(vlx, vlyt, vlx, vlyb);
+                                    if(child2->isVisible())
+                                    {
+                                        p->drawLine(bx + 2, y2,
+                                                    bx + v->treeStepSize() - 12, y2);
+                                        y2 += child2->totalHeight();
+                                    }
+                                    child2 = child2->nextSibling();
                                 }
                             }
-
-                            // draw child itself
-                            if((child->isExpandable() || child->childCount()) &&
-                               (child->height() > 0))
-                            {
-                                // horizontal line up to button
-                                if((0 <= item->depth()) && item->isOpen())
-                                {
-                                    p->drawLine(bx - v->treeStepSize() + 3, linebot - 2,
-                                                bx - 6, linebot - 2);
-                                }
-
-                                // button
-                                QRect rr(bx - 6, linebot - 9, 16, 16);
-                                drawPrimitive(PE_ButtonCommand, p, rr, cg,
-                                              Style_Raised | Style_ButtonDefault);
-
-                                // plus or minus
-                                p->setPen(cg.light());
-                                p->drawLine(bx, linebot - 1, bx + 6, linebot - 1);
-                                if(!child->isOpen())
-                                    p->drawLine(bx + 3, linebot + 2, bx + 3, linebot - 4);
-                                p->setPen(cg.shadow());
-                                p->drawLine(bx - 1, linebot - 2, bx + 5, linebot - 2);
-                                if(!child->isOpen())
-                                    p->drawLine(bx + 2, linebot + 1, bx + 2, linebot - 5);
-
-                                // lines below expanded child
-                                if(child->isOpen())
-                                {
-                                    // vertical line
-                                    p->drawLine(bx + 2,
-                                                linebot + child->height() - 15,
-                                                bx + 2,
-                                                linebot + child->totalHeight() - child->height() - 2);
-
-                                    // horizontal lines at child's children
-                                    QListViewItem* child2 = child->firstChild();
-                                    int y2 = linebot + child->height() - 2;
-                                    while(child2 && (y2 < r.height()))
-                                    {
-                                        if(child2->isVisible())
-                                        {
-                                            p->drawLine(bx + 2, y2,
-                                                        bx + v->treeStepSize() - 12, y2);
-                                            y2 += child2->totalHeight();
-                                        }
-                                        child2 = child2->nextSibling();
-                                    }
-                                }
-                            }
-                            else if((0 <= item->depth()) && item->isOpen())
-                            {
-                                // horizontal line without button
-                                p->setPen(cg.shadow());
-                                p->drawLine(bx - v->treeStepSize() + 3, linebot - 2,
-                                            bx + 8, linebot - 2);
-                            }
-
-                            y += child->totalHeight();
                         }
-                        child = child->nextSibling();
+                        else if((0 <= item->depth()) && item->isOpen())
+                        {
+                            // horizontal line without button
+                            p->setPen(cg.shadow());
+                            p->drawLine(bx - v->treeStepSize() + 3, linebot - 2,
+                                        bx + 8, linebot - 2);
+                        }
+
+                        y += child->totalHeight();
                     }
-                }
-
-                break;
-            }
-            #endif //QT_NO_LISTVIEW
-
-            #ifndef QT_NO_COMBOBOX
-                case CC_ComboBox:
-                {
-                    if(sub & SC_ComboBoxFrame)
+                    child = child->nextSibling();
+                }
+            }
+
+            break;
+        }
+#endif //QT_NO_LISTVIEW
+
+#ifndef QT_NO_COMBOBOX
+        case CC_ComboBox:
+        {
+            if(sub & SC_ComboBoxFrame)
+            {
+                qDrawWarpPanel(p, r, cg, -1);
+                p->setPen(cg.dark());
+                int x = r.right() - 2 - 16;
+                p->drawLine(x, r.top() + 2, x, r.bottom() - 2);
+            }
+
+            if(sub & SC_ComboBoxArrow)
+            {
+                QRect ar = visualRect(querySubControlMetrics(CC_ComboBox, widget,
+                                                             SC_ComboBoxArrow),
+                                      widget);
+                QBrush fill = cg.brush(QColorGroup::Button);
+                bool sunken = subActive == SC_ComboBoxArrow;
+                qDrawWarpFilledRect(p, ar, cg.dark(), cg.light(), &fill, 2, sunken);
+                p->setPen(cg.button());
+                p->drawLine(ar.bottomLeft(), ar.topRight());
+                QPixmap const* pm = qWarpSystemPixmaps.getPixmap(SBMP_COMBODOWN,
+                                                                 QWarpPixmap::bmp);
+                QPoint ppt = ar.topLeft() +
+                             QPoint((ar.width() - pm->width()) / 2,
+                                    (ar.height() - pm->height()) / 2);
+                p->drawPixmap(ppt, *pm);
+            }
+
+            if(sub & SC_ComboBoxEditField)
+            {
+                QComboBox const* cb = (QComboBox const*)widget;
+                QRect re = QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
+                                                                     SC_ComboBoxEditField),
+                                              widget);
+                p->fillRect(re, cg.brush(QColorGroup::Base));
+
+                if(cb->hasFocus())
+                {
+                    p->setPen(cg.highlightedText());
+                    p->setBackgroundColor(cg.highlight());
+                }
+                else
+                {
+                    p->setPen(cg.text());
+                    p->setBackgroundColor(cg.background());
+                }
+
+                if(cb->hasFocus() && !cb->editable())
+                {
+                    re = QStyle::visualRect(subRect(SR_ComboBoxFocusRect, cb), widget);
+                    p->fillRect(re, cg.brush(QColorGroup::Highlight));
+                }
+            }
+
+            break;
+        }
+#endif  // QT_NO_COMBOBOX
+
+#ifndef QT_NO_SLIDER
+        case CC_Slider:
+        {
+            QSlider const* sl = (QSlider const*)widget;
+            QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, opt),
+                  handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, opt);
+
+            // reducing the handle length by 2 on each side
+            if(sl->orientation() == Horizontal)
+            {
+                handle.setLeft(handle.left() + 2);
+                handle.setRight(handle.right() - 2);
+            }
+            else
+            {
+                handle.setTop(handle.top() + 2);
+                handle.setBottom(handle.bottom() - 2);
+            }
+
+            if((sub & SC_SliderGroove) && groove.isValid())
+            {
+                if(sl->orientation() == Horizontal)
+                {
+                    groove.setTop(groove.top() + 4);
+                    groove.setBottom(groove.bottom() - 4);
+                }
+                else
+                {
+                    groove.setLeft(groove.left() + 4);
+                    groove.setRight(groove.right() - 4);
+                }
+
+                qDrawWarpFilledRect(p, groove, cg.dark(), cg.light(),
+                                    &cg.brush(QColorGroup::Button), 2, true);
+
+                groove.setTop(groove.top() + 2);
+                groove.setLeft(groove.left() + 2);
+                if(sl->orientation() == Horizontal)
+                {
+                    groove.setRight(groove.right() - 2);
+                    groove.setBottom(groove.bottom() - 1);
+                }
+                else
+                {
+                    groove.setRight(groove.right() - 1);
+                    groove.setBottom(groove.bottom() - 2);
+                }
+
+                if(flags & Style_HasFocus)
+                    p->setPen(cg.shadow());
+                else
+                    p->setPen(cg.dark());
+
+                p->drawRect(groove);
+            }
+
+            if(sub & SC_SliderTickmarks)
+            {
+                int tickOffset = pixelMetric(PM_SliderTickmarkOffset, sl);
+                int thickness = pixelMetric(PM_SliderControlThickness, sl);
+                int len = pixelMetric(PM_SliderLength, sl);
+                int ticks = sl->tickmarks();
+                int available = pixelMetric(PM_SliderSpaceAvailable, sl);
+                int interval = sl->tickInterval();
+
+                if(interval <= 0 )
+                {
+                    interval = sl->lineStep();
+                    if((qPositionFromValue(sl, interval, available) -
+                        qPositionFromValue(sl, 0, available)) < 3)
+                        interval = sl->pageStep();
+                }
+
+                int fudge = len / 2;
+                int pos;
+
+                if(ticks & QSlider::Above)
+                {
+                    if(sl->orientation() == Horizontal)
+                        p->fillRect(0, 0, sl->width(), tickOffset,
+                                    cg.brush(QColorGroup::Background));
+                    else
+                        p->fillRect(0, 0, tickOffset, sl->width(),
+                                    cg.brush(QColorGroup::Background));
+                    int v = sl->minValue();
+                    if (!interval)
+                        interval = 1;
+                    while(v <= sl->maxValue() + 1)
                     {
-                        qDrawWarpPanel(p, r, cg, -1);
-                        p->setPen(cg.dark());
-                        int x = r.right() - 2 - 16;
-                        p->drawLine(x, r.top() + 2, x, r.bottom() - 2);
-                    }
-
-                    if(sub & SC_ComboBoxArrow)
-                    {
-                        QRect ar = visualRect(querySubControlMetrics(CC_ComboBox, widget,
-                                                                     SC_ComboBoxArrow),
-                                              widget);
-                        QBrush fill = cg.brush(QColorGroup::Button);
-                        bool sunken = subActive == SC_ComboBoxArrow;
-                        qDrawWarpFilledRect(p, ar, cg.dark(), cg.light(), &fill, 2, sunken);
-                        p->setPen(cg.button());
-                        p->drawLine(ar.bottomLeft(), ar.topRight());
-                        QPixmap const* pm = qWarpSystemPixmaps.getPixmap(SBMP_COMBODOWN,
-                                                                         QWarpPixmap::bmp);
-                        QPoint ppt = ar.topLeft() +
-                                     QPoint((ar.width() - pm->width()) / 2,
-                                            (ar.height() - pm->height()) / 2);
-                        p->drawPixmap(ppt, *pm);
-                    }
-
-                    if(sub & SC_ComboBoxEditField)
-                    {
-                        QComboBox const* cb = (QComboBox const*)widget;
-                        QRect re = QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
-                                                                             SC_ComboBoxEditField),
-                                                      widget);
-                        p->fillRect(re, cg.brush(QColorGroup::Base));
-
-                        if(cb->hasFocus())
+                        pos = qPositionFromValue(sl, v, available) + fudge;
+                        if(sl->orientation() == Horizontal)
                         {
-                            p->setPen(cg.highlightedText());
-                            p->setBackgroundColor(cg.highlight());
+                            p->setPen(cg.dark());
+                            p->drawLine(pos - 1, 0, pos - 1, tickOffset - 1);
+                            p->setPen(cg.light());
+                            p->drawLine(pos, 0, pos, tickOffset - 1);
                         }
                         else
                         {
-                            p->setPen(cg.text());
-                            p->setBackgroundColor(cg.background());
+                            p->setPen(cg.dark());
+                            p->drawLine(0, pos - 1, tickOffset - 1, pos - 1);
+                            p->setPen(cg.light());
+                            p->drawLine(0, pos, tickOffset - 1, pos);
                         }
-
-                        if(cb->hasFocus() && !cb->editable())
+                        v += interval;
+                    }
+                }
+
+                if(ticks & QSlider::Below)
+                {
+                    if(sl->orientation() == Horizontal)
+                        p->fillRect(0, tickOffset + thickness, sl->width(), tickOffset,
+                                    cg.brush(QColorGroup::Background));
+                    else
+                        p->fillRect(tickOffset + thickness, 0, tickOffset, sl->height(),
+                                    cg.brush(QColorGroup::Background));
+                    int v = sl->minValue();
+                    if(!interval)
+                        interval = 1;
+                    while(v <= sl->maxValue() + 1)
+                    {
+                        pos = qPositionFromValue(sl, v, available) + fudge;
+                        if(sl->orientation() == Horizontal)
                         {
-                            re = QStyle::visualRect(subRect(SR_ComboBoxFocusRect, cb), widget);
-                            p->fillRect(re, cg.brush(QColorGroup::Highlight));
+                            p->setPen(cg.dark());
+                            p->drawLine(pos - 1, tickOffset + thickness + 1,
+                                        pos - 1, tickOffset + thickness + 1 + available - 1);
+                            p->setPen(cg.light());
+                            p->drawLine(pos, tickOffset + thickness + 1,
+                                        pos, tickOffset + thickness + 1 + available - 1);
                         }
+                        else
+                        {
+                            p->setPen(cg.dark());
+                            p->drawLine(tickOffset + thickness + 1, pos - 1,
+                                        tickOffset + thickness + 1 + available - 1, pos - 1);
+                            p->setPen(cg.light());
+                            p->drawLine(tickOffset + thickness + 1, pos,
+                                        tickOffset + thickness + 1 + available - 1, pos);
+                        }
+                        v += interval;
                     }
-
-                    break;
-                }
-            #endif  // QT_NO_COMBOBOX
-
-            #ifndef QT_NO_SLIDER
-            case CC_Slider:
-            {
-                QSlider const* sl = (QSlider const*)widget;
-                QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, opt),
-                      handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, opt);
-
-                // reducing the handle length by 2 on each side
+                }
+            }
+
+            if(sub & SC_SliderHandle)
+            {
+                qDrawWarpFilledRect(p, handle, cg.dark(), cg.light(),
+                                    &cg.brush(QColorGroup::Button), 2, false);
+
+                if(flags & Style_HasFocus)
+                    p->setPen(cg.shadow());
+                else
+                    p->setPen(cg.dark());
+
                 if(sl->orientation() == Horizontal)
-                {
-                    handle.setLeft(handle.left() + 2);
-                    handle.setRight(handle.right() - 2);
-                }
+                    p->drawLine(handle.topLeft() + QPoint(5, 2),
+                                handle.bottomLeft() + QPoint(5, -2));
                 else
-                {
-                    handle.setTop(handle.top() + 2);
-                    handle.setBottom(handle.bottom() - 2);
-                }
-
-                if((sub & SC_SliderGroove) && groove.isValid())
-                {
-                    if(sl->orientation() == Horizontal)
-                    {
-                        groove.setTop(groove.top() + 4);
-                        groove.setBottom(groove.bottom() - 4);
-                    }
-                    else
-                    {
-                        groove.setLeft(groove.left() + 4);
-                        groove.setRight(groove.right() - 4);
-                    }
-
-                    qDrawWarpFilledRect(p, groove, cg.dark(), cg.light(),
-                                        &cg.brush(QColorGroup::Button), 2, true);
-
-                    groove.setTop(groove.top() + 2);
-                    groove.setLeft(groove.left() + 2);
-                    if(sl->orientation() == Horizontal)
-                    {
-                        groove.setRight(groove.right() - 2);
-                        groove.setBottom(groove.bottom() - 1);
-                    }
-                    else
-                    {
-                        groove.setRight(groove.right() - 1);
-                        groove.setBottom(groove.bottom() - 2);
-                    }
-
-                    if(flags & Style_HasFocus)
-                        p->setPen(cg.shadow());
-                    else
-                        p->setPen(cg.dark());
-
-                    p->drawRect(groove);
-                }
-
-                if(sub & SC_SliderTickmarks)
-                {
-                    int tickOffset = pixelMetric(PM_SliderTickmarkOffset, sl);
-                    int thickness = pixelMetric(PM_SliderControlThickness, sl);
-                    int len = pixelMetric(PM_SliderLength, sl);
-                    int ticks = sl->tickmarks();
-                    int available = pixelMetric(PM_SliderSpaceAvailable, sl);
-                    int interval = sl->tickInterval();
-
-                    if(interval <= 0 )
-                    {
-                        interval = sl->lineStep();
-                        if((qPositionFromValue(sl, interval, available) -
-                            qPositionFromValue(sl, 0, available)) < 3)
-                            interval = sl->pageStep();
-                    }
-
-                    int fudge = len / 2;
-                    int pos;
-
-                    if(ticks & QSlider::Above)
-                    {
-                        if(sl->orientation() == Horizontal)
-                            p->fillRect(0, 0, sl->width(), tickOffset,
-                                        cg.brush(QColorGroup::Background));
-                        else
-                            p->fillRect(0, 0, tickOffset, sl->width(),
-                                        cg.brush(QColorGroup::Background));
-                        int v = sl->minValue();
-                        if (!interval)
-                            interval = 1;
-                        while(v <= sl->maxValue() + 1)
-                        {
-                            pos = qPositionFromValue(sl, v, available) + fudge;
-                            if(sl->orientation() == Horizontal)
-                            {
-                                p->setPen(cg.dark());
-                                p->drawLine(pos - 1, 0, pos - 1, tickOffset - 1);
-                                p->setPen(cg.light());
-                                p->drawLine(pos, 0, pos, tickOffset - 1);
-                            }
-                            else
-                            {
-                                p->setPen(cg.dark());
-                                p->drawLine(0, pos - 1, tickOffset - 1, pos - 1);
-                                p->setPen(cg.light());
-                                p->drawLine(0, pos, tickOffset - 1, pos);
-                            }
-                            v += interval;
-                        }
-                    }
-
-                    if(ticks & QSlider::Below)
-                    {
-                        if(sl->orientation() == Horizontal)
-                            p->fillRect(0, tickOffset + thickness, sl->width(), tickOffset,
-                                        cg.brush(QColorGroup::Background));
-                        else
-                            p->fillRect(tickOffset + thickness, 0, tickOffset, sl->height(),
-                                        cg.brush(QColorGroup::Background));
-                        int v = sl->minValue();
-                        if(!interval)
-                            interval = 1;
-                        while(v <= sl->maxValue() + 1)
-                        {
-                            pos = qPositionFromValue(sl, v, available) + fudge;
-                            if(sl->orientation() == Horizontal)
-                            {
-                                p->setPen(cg.dark());
-                                p->drawLine(pos - 1, tickOffset + thickness + 1,
-                                            pos - 1, tickOffset + thickness + 1 + available - 1);
-                                p->setPen(cg.light());
-                                p->drawLine(pos, tickOffset + thickness + 1,
-                                            pos, tickOffset + thickness + 1 + available - 1);
-                            }
-                            else
-                            {
-                                p->setPen(cg.dark());
-                                p->drawLine(tickOffset + thickness + 1, pos - 1,
-                                            tickOffset + thickness + 1 + available - 1, pos - 1);
-                                p->setPen(cg.light());
-                                p->drawLine(tickOffset + thickness + 1, pos,
-                                            tickOffset + thickness + 1 + available - 1, pos);
-                            }
-                            v += interval;
-                        }
-                    }
-                }
-
-                if(sub & SC_SliderHandle)
-                {
-                    qDrawWarpFilledRect(p, handle, cg.dark(), cg.light(),
-                                        &cg.brush(QColorGroup::Button), 2, false);
-
-                    if(flags & Style_HasFocus)
-                        p->setPen(cg.shadow());
-                    else
-                        p->setPen(cg.dark());
-
-                    if(sl->orientation() == Horizontal)
-                        p->drawLine(handle.topLeft() + QPoint(5, 2),
-                                    handle.bottomLeft() + QPoint(5, -2));
-                    else
-                        p->drawLine(handle.topLeft() + QPoint(2, 5),
-                                    handle.topRight() + QPoint(-2, 5));
-
-                    p->setPen(cg.light());
-
-                    if(sl->orientation() == Horizontal)
-                        p->drawLine(handle.topLeft() + QPoint(6, 2),
-                                    handle.bottomLeft() + QPoint(6, -2));
-                    else
-                        p->drawLine(handle.topLeft() + QPoint(2, 6),
-                                    handle.topRight() + QPoint(-2, 6));
-                }
-
-                break;
-            }
-        #endif // QT_NO_SLIDER
+                    p->drawLine(handle.topLeft() + QPoint(2, 5),
+                                handle.topRight() + QPoint(-2, 5));
+
+                p->setPen(cg.light());
+
+                if(sl->orientation() == Horizontal)
+                    p->drawLine(handle.topLeft() + QPoint(6, 2),
+                                handle.bottomLeft() + QPoint(6, -2));
+                else
+                    p->drawLine(handle.topLeft() + QPoint(2, 6),
+                                handle.topRight() + QPoint(-2, 6));
+            }
+
+            break;
+        }
+#endif // QT_NO_SLIDER
 
         default:
@@ -4193,102 +4171,102 @@
     switch(control)
     {
-        #ifndef QT_NO_SCROLLBAR
-            case CC_ScrollBar:
-            {
-                QScrollBar const* scrollbar = (QScrollBar const*)widget;
-                int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
-                int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
-                              scrollbar->width() : scrollbar->height()) -
-                              (2 * 21); // 2 buttons incl. lines
-                int sliderstart = scrollbar->sliderStart();
-
-                // calculate slider length
-                int sliderlen;
-                if(scrollbar->maxValue() != scrollbar->minValue())
-                {
-                    uint range = scrollbar->maxValue() - scrollbar->minValue();
-                    sliderlen = (scrollbar->pageStep() * maxlen) /
-                                (range + scrollbar->pageStep());
-                    int slidermin = pixelMetric(PM_ScrollBarSliderMin, widget);
-                    if((sliderlen < slidermin) || (range > INT_MAX / 2))
-                        sliderlen = slidermin;
-                    if(sliderlen > maxlen)
-                        sliderlen = maxlen;
-                }
-                else
-                {
+#ifndef QT_NO_SCROLLBAR
+        case CC_ScrollBar:
+        {
+            QScrollBar const* scrollbar = (QScrollBar const*)widget;
+            int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
+            int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
+                          scrollbar->width() : scrollbar->height()) -
+                          (2 * 21); // 2 buttons incl. lines
+            int sliderstart = scrollbar->sliderStart();
+
+            // calculate slider length
+            int sliderlen;
+            if(scrollbar->maxValue() != scrollbar->minValue())
+            {
+                uint range = scrollbar->maxValue() - scrollbar->minValue();
+                sliderlen = (scrollbar->pageStep() * maxlen) /
+                            (range + scrollbar->pageStep());
+                int slidermin = pixelMetric(PM_ScrollBarSliderMin, widget);
+                if((sliderlen < slidermin) || (range > INT_MAX / 2))
+                    sliderlen = slidermin;
+                if(sliderlen > maxlen)
                     sliderlen = maxlen;
-                }
-
-                // calculate button width (for vertical scroll bars this is the height)
-                // note: the "button" includes the lines at the extreme ends of the sb
-                int buttonWidth;
-                if(scrollbar->orientation() == Qt::Horizontal)
-                    buttonWidth = QMIN(scrollbar->width() / 2, 21);
-                else
-                    buttonWidth = QMIN(scrollbar->height() / 2, 21);
-
-                switch(sc)
-                {
-                    case SC_ScrollBarSubLine:           // top/left button
-                    {
-                        if(scrollbar->orientation() == Qt::Horizontal)
-                            return QRect(0, 0, buttonWidth, sbextent);
-                        else
-                            return QRect(0, 0, sbextent, buttonWidth);
-                    }
-
-                    case SC_ScrollBarAddLine:           // bottom/right button
-                    {
-                        if(scrollbar->orientation() == Qt::Horizontal)
-                            return QRect(scrollbar->width() - buttonWidth, 0,
-                                         buttonWidth, sbextent);
-                        else
-                            return QRect(0, scrollbar->height() - buttonWidth,
-                                         sbextent, buttonWidth);
-                    }
-
-                    case SC_ScrollBarSubPage:           // between top/left button and slider
-                    {
-                        if(scrollbar->orientation() == Qt::Horizontal)
-                            return QRect(buttonWidth, 0,
-                                         sliderstart - buttonWidth, sbextent);
-                        else
-                            return QRect(0, buttonWidth,
-                                         sbextent, sliderstart - buttonWidth);
-                    }
-
-                    case SC_ScrollBarAddPage:           // between bottom/right button and slider
-                    {
-                        if(scrollbar->orientation() == Qt::Horizontal)
-                            return QRect(sliderstart + sliderlen, 0,
-                                         maxlen + buttonWidth - sliderstart - sliderlen, sbextent);
-                        else
-                            return QRect(0, sliderstart + sliderlen,
-                                         sbextent, maxlen + buttonWidth - sliderstart - sliderlen);
-                    }
-
-                    case SC_ScrollBarGroove:
-                    {
-                        if(scrollbar->orientation() == Qt::Horizontal)
-                            return QRect(buttonWidth, 0,
-                                         scrollbar->width() - buttonWidth * 2, sbextent);
-                        else
-                            return QRect(0, buttonWidth,
-                                         sbextent, scrollbar->height() - buttonWidth * 2);
-                    }
-
-                    case SC_ScrollBarSlider:
-                    {
-                        if(scrollbar->orientation() == Qt::Horizontal)
-                            return QRect(sliderstart, 0, sliderlen, sbextent);
-                        else
-                            return QRect(0, sliderstart, sbextent, sliderlen);
-                    }
-                }
-
-                break;
-            }
-        #endif // QT_NO_SCROLLBAR
+            }
+            else
+            {
+                sliderlen = maxlen;
+            }
+
+            // calculate button width (for vertical scroll bars this is the height)
+            // note: the "button" includes the lines at the extreme ends of the sb
+            int buttonWidth;
+            if(scrollbar->orientation() == Qt::Horizontal)
+                buttonWidth = QMIN(scrollbar->width() / 2, 21);
+            else
+                buttonWidth = QMIN(scrollbar->height() / 2, 21);
+
+            switch(sc)
+            {
+                case SC_ScrollBarSubLine:           // top/left button
+                {
+                    if(scrollbar->orientation() == Qt::Horizontal)
+                        return QRect(0, 0, buttonWidth, sbextent);
+                    else
+                        return QRect(0, 0, sbextent, buttonWidth);
+                }
+
+                case SC_ScrollBarAddLine:           // bottom/right button
+                {
+                    if(scrollbar->orientation() == Qt::Horizontal)
+                        return QRect(scrollbar->width() - buttonWidth, 0,
+                                     buttonWidth, sbextent);
+                    else
+                        return QRect(0, scrollbar->height() - buttonWidth,
+                                     sbextent, buttonWidth);
+                }
+
+                case SC_ScrollBarSubPage:           // between top/left button and slider
+                {
+                    if(scrollbar->orientation() == Qt::Horizontal)
+                        return QRect(buttonWidth, 0,
+                                     sliderstart - buttonWidth, sbextent);
+                    else
+                        return QRect(0, buttonWidth,
+                                     sbextent, sliderstart - buttonWidth);
+                }
+
+                case SC_ScrollBarAddPage:           // between bottom/right button and slider
+                {
+                    if(scrollbar->orientation() == Qt::Horizontal)
+                        return QRect(sliderstart + sliderlen, 0,
+                                     maxlen + buttonWidth - sliderstart - sliderlen, sbextent);
+                    else
+                        return QRect(0, sliderstart + sliderlen,
+                                     sbextent, maxlen + buttonWidth - sliderstart - sliderlen);
+                }
+
+                case SC_ScrollBarGroove:
+                {
+                    if(scrollbar->orientation() == Qt::Horizontal)
+                        return QRect(buttonWidth, 0,
+                                     scrollbar->width() - buttonWidth * 2, sbextent);
+                    else
+                        return QRect(0, buttonWidth,
+                                     sbextent, scrollbar->height() - buttonWidth * 2);
+                }
+
+                case SC_ScrollBarSlider:
+                {
+                    if(scrollbar->orientation() == Qt::Horizontal)
+                        return QRect(sliderstart, 0, sliderlen, sbextent);
+                    else
+                        return QRect(0, sliderstart, sbextent, sliderlen);
+                }
+            }
+
+            break;
+        }
+#endif // QT_NO_SCROLLBAR
 
         case CC_SpinWidget:
@@ -4475,56 +4453,56 @@
         }
 
-        #ifndef QT_NO_SLIDER
-            case SR_SliderFocusRect:
-            {
-                rect = widget->rect();
-                break;
-            }
-        #endif // QT_NO_SLIDER
-
-        #ifndef QT_NO_PROGRESSBAR
-            case SR_ProgressBarGroove:
-            case SR_ProgressBarContents:
-            {
-                QFontMetrics fm((widget ? widget->fontMetrics() :
-                                          QApplication::fontMetrics()));
-                QProgressBar const* progressbar = (QProgressBar const*)widget;
-                int textw = 0;
-                if(progressbar->percentageVisible())
-                    textw = fm.width("100%") + 6;
-
-                // only change for Warp4 compared to "common": the style default
-                // is "centered"
-                QRect wrect(widget->rect());
-                if(!progressbar->indicatorFollowsStyle() &&
-                   !progressbar->centerIndicator())
-                    rect.setCoords(wrect.left(), wrect.top(),
-                                   wrect.right() - textw, wrect.bottom());
-                else
-                    rect = wrect;
-                break;
-            }
-
-            case SR_ProgressBarLabel:
-            {
-                QFontMetrics fm((widget ? widget->fontMetrics() :
-                                          QApplication::fontMetrics()));
-                QProgressBar const* progressbar = (QProgressBar const*)widget;
-                int textw = 0;
-                if(progressbar->percentageVisible())
-                    textw = fm.width("100%") + 6;
-
-                // only change for Warp4 compared to "common": the style default
-                // is "centered"
-                QRect wrect(widget->rect());
-                if(!progressbar->indicatorFollowsStyle() &&
-                   !progressbar->centerIndicator())
-                    rect.setCoords(wrect.right() - textw, wrect.top(),
-                                   wrect.right(), wrect.bottom());
-                else
-                    rect = wrect;
-                break;
-            }
-        #endif
+#ifndef QT_NO_SLIDER
+        case SR_SliderFocusRect:
+        {
+            rect = widget->rect();
+            break;
+        }
+#endif // QT_NO_SLIDER
+
+#ifndef QT_NO_PROGRESSBAR
+        case SR_ProgressBarGroove:
+        case SR_ProgressBarContents:
+        {
+            QFontMetrics fm((widget ? widget->fontMetrics() :
+                                      QApplication::fontMetrics()));
+            QProgressBar const* progressbar = (QProgressBar const*)widget;
+            int textw = 0;
+            if(progressbar->percentageVisible())
+                textw = fm.width("100%") + 6;
+
+            // only change for Warp4 compared to "common": the style default
+            // is "centered"
+            QRect wrect(widget->rect());
+            if(!progressbar->indicatorFollowsStyle() &&
+               !progressbar->centerIndicator())
+                rect.setCoords(wrect.left(), wrect.top(),
+                               wrect.right() - textw, wrect.bottom());
+            else
+                rect = wrect;
+            break;
+        }
+
+        case SR_ProgressBarLabel:
+        {
+            QFontMetrics fm((widget ? widget->fontMetrics() :
+                                      QApplication::fontMetrics()));
+            QProgressBar const* progressbar = (QProgressBar const*)widget;
+            int textw = 0;
+            if(progressbar->percentageVisible())
+                textw = fm.width("100%") + 6;
+
+            // only change for Warp4 compared to "common": the style default
+            // is "centered"
+            QRect wrect(widget->rect());
+            if(!progressbar->indicatorFollowsStyle() &&
+               !progressbar->centerIndicator())
+                rect.setCoords(wrect.right() - textw, wrect.top(),
+                               wrect.right(), wrect.bottom());
+            else
+                rect = wrect;
+            break;
+        }
+#endif // QT_NO_PROGRESSBAR
 
         case SR_ToolBoxTabContents:
