void QwtDynGridLayout::setGeometry(const QRect &rect)
{
    QLayout::setGeometry(rect);

    if ( isEmpty() )
        return;

    d_data->numCols = columnsForWidth(rect.width());
    d_data->numRows = itemCount() / d_data->numCols;
    if ( itemCount() % d_data->numCols )
        d_data->numRows++;

#if QT_VERSION < 0x040000
    QValueList<QRect> itemGeometries = layoutItems(rect, d_data->numCols);
#else
    QList<QRect> itemGeometries = layoutItems(rect, d_data->numCols);
#endif

    int index = 0;
    for (PrivateData::LayoutItemList::iterator it = d_data->itemList.begin();
        it != d_data->itemList.end(); ++it)
    {
        QWidget *w = (*it)->widget();
        if ( w )
        {
            w->setGeometry(itemGeometries[index]);
            index++;
        }
    }
}
QSize QwtDynGridLayout::sizeHint() const
{
    if ( isEmpty() )
        return QSize();

    const uint numCols = (d_data->maxCols > 0 ) ? d_data->maxCols : itemCount();
    uint numRows = itemCount() / numCols;
    if ( itemCount() % numCols )
        numRows++;

    QwtArray<int> rowHeight(numRows);
    QwtArray<int> colWidth(numCols);

    layoutGrid(numCols, rowHeight, colWidth);

    int h = 2 * margin() + (numRows - 1) * spacing();
    for ( int row = 0; row < (int)numRows; row++ )
        h += rowHeight[row];

    int w = 2 * margin() + (numCols - 1) * spacing(); 
    for ( int col = 0; col < (int)numCols; col++ )
        w += colWidth[col];

    return QSize(w, h);
}
Exemplo n.º 3
0
QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
    uint numCols ) const
{
    QList<QRect> itemGeometries;
    if ( numCols == 0 || isEmpty() )
        return itemGeometries;

    uint numRows = itemCount() / numCols;
    if ( numRows % itemCount() )
        numRows++;

    QVector<int> rowHeight( numRows );
    QVector<int> colWidth( numCols );

    layoutGrid( numCols, rowHeight, colWidth );

    bool expandH, expandV;
    expandH = expandingDirections() & Qt::Horizontal;
    expandV = expandingDirections() & Qt::Vertical;

    if ( expandH || expandV )
        stretchGrid( rect, numCols, rowHeight, colWidth );

    const int maxCols = d_data->maxCols;
    d_data->maxCols = numCols;
    const QRect alignedRect = alignmentRect( rect );
    d_data->maxCols = maxCols;

    const int xOffset = expandH ? 0 : alignedRect.x();
    const int yOffset = expandV ? 0 : alignedRect.y();

    QVector<int> colX( numCols );
    QVector<int> rowY( numRows );

    const int xySpace = spacing();

    rowY[0] = yOffset + margin();
    for ( int r = 1; r < ( int )numRows; r++ )
        rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace;

    colX[0] = xOffset + margin();
    for ( int c = 1; c < ( int )numCols; c++ )
        colX[c] = colX[c-1] + colWidth[c-1] + xySpace;

    const int itemCount = d_data->itemList.size();
    for ( int i = 0; i < itemCount; i++ )
    {
        const int row = i / numCols;
        const int col = i % numCols;

        QRect itemGeometry( colX[col], rowY[row],
            colWidth[col], rowHeight[row] );
        itemGeometries.append( itemGeometry );
    }

    return itemGeometries;
}
void QwtDynGridLayout::stretchGrid(const QRect &rect, 
    uint numCols, QwtArray<int>& rowHeight, QwtArray<int>& colWidth) const
{
    if ( numCols == 0 || isEmpty() )
        return;

    bool expandH, expandV;
#if QT_VERSION >= 0x040000
    expandH = expandingDirections() & Qt::Horizontal;
    expandV = expandingDirections() & Qt::Vertical;
#else
    expandH = expanding() & QSizePolicy::Horizontally;
    expandV = expanding() & QSizePolicy::Vertically;
#endif

    if ( expandH )
    {
        int xDelta = rect.width() - 2 * margin() - (numCols - 1) * spacing();
        for ( int col = 0; col < (int)numCols; col++ )
            xDelta -= colWidth[col];

        if ( xDelta > 0 )
        {
            for ( int col = 0; col < (int)numCols; col++ )
            {
                const int space = xDelta / (numCols - col);
                colWidth[col] += space;
                xDelta -= space;
            }
        }
    }

    if ( expandV )
    {
        uint numRows = itemCount() / numCols;
        if ( itemCount() % numCols )
            numRows++;

        int yDelta = rect.height() - 2 * margin() - (numRows - 1) * spacing();
        for ( int row = 0; row < (int)numRows; row++ )
            yDelta -= rowHeight[row];

        if ( yDelta > 0 )
        {
            for ( int row = 0; row < (int)numRows; row++ )
            {
                const int space = yDelta / (numRows - row);
                rowHeight[row] += space;
                yDelta -= space;
            }
        }
    }
}
Exemplo n.º 5
0
/*!
 * Adds the item \a item to the end of the array.
 *
 * Returns the index of the added item.
 */
int QScatterDataProxy::addItem(const QScatterDataItem &item)
{
    int addIndex = dptr()->addItem(item);
    emit itemsAdded(addIndex, 1);
    emit itemCountChanged(itemCount());
    return addIndex;
}
Exemplo n.º 6
0
void QtFallbackWebPopup::populate()
{
    m_combo->clear();

    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_combo->model());
    Q_ASSERT(model);

#if !defined(Q_WS_S60)
    m_combo->setFont(font());
#endif
    for (int i = 0; i < itemCount(); ++i) {
        switch (itemType(i)) {
        case Separator:
            m_combo->insertSeparator(i);
            break;
        case Group:
            m_combo->insertItem(i, itemText(i));
            model->item(i)->setEnabled(false);
            break;
        case Option:
            m_combo->insertItem(i, itemText(i));
            model->item(i)->setEnabled(itemIsEnabled(i));
            break;
        }
    }
}
Exemplo n.º 7
0
/*!
 * Adds the items specified by \a items to the end of the array.
 *
 * Returns the index of the first added item.
 */
int QScatterDataProxy::addItems(const QScatterDataArray &items)
{
    int addIndex = dptr()->addItems(items);
    emit itemsAdded(addIndex, items.size());
    emit itemCountChanged(itemCount());
    return addIndex;
}
Exemplo n.º 8
0
void MSOptionPopupMenu::update(const MSIndexVector& index_)
{
  if (MSView::model()!=0)
   {
     if (index_.length()==0)
      {
	if (optionsModel().length()==itemCount())
	 {
	   MSMenuItem *mi;
           int i,n=itemCount();
           for(i=0;i<n;i++)
	    {
	      mi=(MSMenuItem *)itemVector()(i);
	      mi->label(optionsModel()(i));
	    }
	   computeSize();
	   optionMenu()->setSelectedItem(0);
	   optionMenu()->computeSize();
	 }
	else rebuildMenu();
      }
     else 
      {
	MSIndexVector iv(index_);
	iv.sortUp();
	if (iv(0)==itemCount())
	 {
	   for (unsigned i=0,j=itemCount();i<iv.length();i++,j++)
	    {
	      MSMenuItem *pMenuItem=new MSMenuItem(this,optionsModel()(j),0,j);
	      setItem(pMenuItem,j);
	    }
	 }
	else
	 {
	   for (unsigned i=0;i<iv.length();i++)
	    {
	      unsigned index=iv(i);
	      MSMenuItem *mi=menuItem(index);
	      if (mi!=0) mi->label(optionsModel()(index));
	    }
	 }
      }
     computeSize();
     optionMenu()->computeSize();
   }
}
bool AbstractWheelWidget::event(QEvent *e)
{
    switch (e->type()) {
// ![1]
    case QEvent::ScrollPrepare:
    {
        // We set the snap positions as late as possible so that we are sure
        // we get the correct itemHeight
        QScroller *scroller = QScroller::scroller(this);
        scroller->setSnapPositionsY( WHEEL_SCROLL_OFFSET, itemHeight() );

        QScrollPrepareEvent *se = static_cast<QScrollPrepareEvent *>(e);
        se->setViewportSize(QSizeF(size()));
        // we claim a huge scrolling area and a huge content position and
        // hope that the user doesn't notice that the scroll area is restricted
        se->setContentPosRange(QRectF(0.0, 0.0, 0.0, WHEEL_SCROLL_OFFSET * 2));
        se->setContentPos(QPointF(0.0, WHEEL_SCROLL_OFFSET + m_currentItem * itemHeight() + m_itemOffset));
        se->accept();
        return true;
    }
// ![1]
// ![2]
    case QEvent::Scroll:
    {
        QScrollEvent *se = static_cast<QScrollEvent *>(e);

        qreal y = se->contentPos().y();
        int iy = y - WHEEL_SCROLL_OFFSET;
        int ih = itemHeight();

// ![2]
// ![3]
        // -- calculate the current item position and offset and redraw the widget
        int ic = itemCount();
        if (ic>0) {
            m_currentItem = iy / ih % ic;
            m_itemOffset = iy % ih;

            // take care when scrolling backwards. Modulo returns negative numbers
            if (m_itemOffset < 0) {
                m_itemOffset += ih;
                m_currentItem--;
            }

            if (m_currentItem < 0)
                m_currentItem += ic;
        }
        // -- repaint
        update();

        se->accept();
        return true;
// ![3]
    }
    default:
        return QWidget::event(e);
    }
    return true;
}
Exemplo n.º 10
0
LayerItem* LayerWidget::itemAt(int index)
{
    if(itemCount()){
        return qobject_cast<LayerItem*>(layout_->itemAt(index)->widget());
    }else{
        return 0;
    }
}
void AbstractWheelWidget::setCurrentIndex(int index)
{
    if (index >= 0 && index < itemCount()) {
        m_currentItem = index;
        m_itemOffset = 0;
        update();
    }
}
Exemplo n.º 12
0
/*!
 * Takes ownership of the array \a newArray. Clears the existing array if the
 * new array differs from it. If the arrays are the same, this function
 * just triggers the arrayReset() signal.
 *
 * Passing a null array deletes the old array and creates a new empty array.
 */
void QScatterDataProxy::resetArray(QScatterDataArray *newArray)
{
    if (dptr()->m_dataArray != newArray)
        dptr()->resetArray(newArray);

    emit arrayReset();
    emit itemCountChanged(itemCount());
}
Exemplo n.º 13
0
void CNcdQuery::InternalizeL( RReadStream& aReadStream )
    {
    delete iId;
    iId = NULL;
    iId = HBufC::NewL( aReadStream, KMaxTInt );
    iIsOptional = aReadStream.ReadInt32L();
    iSemantics = static_cast<MNcdQuery::TSemantics>(
        aReadStream.ReadInt32L());
    delete iTitle;
    iTitle = NULL;
    iTitle = CNcdString::NewL( aReadStream );
    delete iBody;
    iBody = NULL;
    iBody = CNcdString::NewL( aReadStream );
    iResponse = static_cast<TResponse>( aReadStream.ReadInt32L() );
    iIsSecureConnection = aReadStream.ReadInt32L();
    TInt itemCount( aReadStream.ReadInt32L() );
    iItems.ResetAndRelease();
    for ( TInt i = 0 ; i < itemCount ; i++ )
        {
        TNcdInterfaceId interfaceId = static_cast<TNcdInterfaceId>(aReadStream.ReadInt32L());
        CNcdQueryItem* item = NULL;
        switch ( interfaceId )
            {
            case ENcdQueryTextItemUid:
                {
                item = CNcdQueryTextItem::NewL( aReadStream, *this );
                break;
                }
            case ENcdQueryNumericItemUid:
                {
                item = CNcdQueryNumericItem::NewL( aReadStream, *this );
                break;
                }
            case ENcdQueryPinCodeItemUid:
                {
                item = CNcdQueryPinCodeItem::NewL( aReadStream, *this );
                break;
                }
            case ENcdQuerySelectionItemUid:
                {
                item = CNcdQuerySelectionItem::NewL( aReadStream, *this );
                break;
                }
            default:
                {
                User::Leave( KErrCorrupt );
                break;
                }
            }

        // Object's refcount must be at least 1 for Release() to work correctly
        item->AddRef();
        CleanupReleasePushL( *item );
        iItems.AppendL( item );        
        CleanupStack::Pop( item );
        }
    }
Exemplo n.º 14
0
/*!
 * Removes the number of items specified by \a removeCount starting at the
 * position \a index. Attempting to remove items past the end of
 * the array does nothing.
 */
void QScatterDataProxy::removeItems(int index, int removeCount)
{
    if (index >= dptr()->m_dataArray->size())
        return;

    dptr()->removeItems(index, removeCount);
    emit itemsRemoved(index, removeCount);
    emit itemCountChanged(itemCount());
}
Exemplo n.º 15
0
bool DropDownList::selectItem(size_t item) {
    if ((int)item >= 0 && item < itemCount()) {
        selected_item = item;
        ensureSelectedItemVisible();
        Refresh(false);
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 16
0
int DropDownList::itemPosition(size_t item) const {
    int y = marginH - visible_start;
    size_t count = itemCount();
    for (size_t i = 0 ; i < count ; ++i) {
        if (i == item) return y;
        y += (int)item_size.height + lineBelow(i);
    }
    // not found
    assert(false);
    return 0;
}
int QwtDynGridLayout::heightForWidth(int width) const
{
    if ( isEmpty() )
        return 0;

    const uint numCols = columnsForWidth(width);
    uint numRows = itemCount() / numCols;
    if ( itemCount() % numCols )
        numRows++;

    QwtArray<int> rowHeight(numRows);
    QwtArray<int> colWidth(numCols);

    layoutGrid(numCols, rowHeight, colWidth);

    int h = 2 * margin() + (numRows - 1) * spacing();
    for ( int row = 0; row < (int)numRows; row++ )
        h += rowHeight[row];

    return h;
}
void CPresenceDataCache::RemoveMeFromArray( RPointerArray< Type >& aItemArray, Type* aChild )
{
    TInt itemCount( aItemArray.Count() );
    for ( TInt i( 0 ); i < itemCount; i++ )
    {
        if ( aChild == aItemArray[ i ] )
        {
            aItemArray.Remove( i );
            break;
        }
    }
}
Wom_PortQueue::t_item Wom_PortQueue::getItem(unsigned int i)
//*************************************************************************************************************
{
	unsigned int idx;
	WOM_ASSERT(i < (itemCount()));
	m_Mutex.Lock() ; // No race here, m_Mutex is for memory barriers
	idx = m_front + i;
	if (idx >= m_Size) 
		idx -= m_Size;
	m_Mutex.Unlock();
	return m_circ_array[idx];
}
Exemplo n.º 20
0
int CDoodMemberManager::indexOfSection(QString sectnion)
{
    int index = groupAdminListMap.size()+groupLeaderListMap.size();
    for(;index < itemCount();++index){
        CDoodMemberItem *tmpItem = (CDoodMemberItem *)itemOfIndex(index);
        if(tmpItem->sectionKey() == sectnion||tmpItem->sectionKey()=="#"){
            return index;
        }
        else if(tmpItem->sectionKey()[0]>sectnion[0]&&sectnion!="#"){
            return index;
        }
    }
    return index;
}
void QwtDynGridLayout::updateLayoutCache()
{
    d_data->itemSizeHints.resize(itemCount());

    int index = 0;

    for (PrivateData::LayoutItemList::iterator it = d_data->itemList.begin();
        it != d_data->itemList.end(); ++it, index++)
    {
        d_data->itemSizeHints[int(index)] = (*it)->sizeHint();
    }

    d_data->isDirty = false;
}
Exemplo n.º 22
0
int InlineListWidget::handleCommand(menucommand_e cmd)
{
    switch(cmd)
    {
    case MCMD_SELECT: // Treat as @c MCMD_NAV_RIGHT
    case MCMD_NAV_LEFT:
    case MCMD_NAV_RIGHT: {
        int oldSelection = selection();

        if(MCMD_NAV_LEFT == cmd)
        {
            if(selection() > 0)
                selectItem(selection() - 1);
            else
                selectItem(itemCount() - 1);
        }
        else
        {
            if(selection() < itemCount() - 1)
                selectItem(selection() + 1);
            else
                selectItem(0);
        }

        updateVisibleSelection();

        if(oldSelection != selection())
        {
            S_LocalSound(SFX_MENU_SLIDER_MOVE, NULL);
            execAction(Modified);
        }
        return true;
      }
    default:
        return false; // Not eaten.
    }
}
Exemplo n.º 23
0
void DropDownList::draw(DC& dc) {
    // Size
    wxSize cs = dc.GetSize();
    // Draw background & frame
    dc.SetPen  (*wxTRANSPARENT_PEN);
    dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
    dc.DrawRectangle(0, 0, cs.x, cs.y);
    dc.SetFont(*wxNORMAL_FONT);
    // Draw items
    int y = marginH - visible_start;
    size_t count = itemCount();
    for (size_t i = 0 ; i < count ; ++i) {
        drawItem(dc, y, i);
        y += (int)item_size.height + lineBelow(i);
    }
}
uint QwtDynGridLayout::columnsForWidth(int width) const
{
    if ( isEmpty() )
        return 0;

    const int maxCols = (d_data->maxCols > 0) ? d_data->maxCols : itemCount();
    if ( maxRowWidth(maxCols) <= width )
        return maxCols;

    for (int numCols = 2; numCols <= maxCols; numCols++ )
    {
        const int rowWidth = maxRowWidth(numCols);
        if ( rowWidth > width )
            return numCols - 1;
    }

    return 1; // At least 1 column
}
Exemplo n.º 25
0
void QtFallbackWebPopup::showS60BrowserDialog()
{
    static MBrCtlDialogsProvider* dialogs = CBrowserDialogsProvider::NewL(0);
    if (!dialogs)
        return;

    int size = itemCount();
    CArrayFix<TBrCtlSelectOptionData>* options = new CArrayFixFlat<TBrCtlSelectOptionData>(qMax(1, size));
    RPointerArray<HBufC> items(qMax(1, size));
    CleanupStack::PushL(TCleanupItem(&ResetAndDestroy, &items));

    for (int i = 0; i < size; i++) {
        if (itemType(i) == Separator) {
            TBrCtlSelectOptionData data(_L("----------"), false, false, false);
            options->AppendL(data);
        } else {
            HBufC16* itemStr = HBufC16::NewL(itemText(i).length());
            itemStr->Des().Copy((const TUint16*)itemText(i).utf16(), itemText(i).length());
            CleanupStack::PushL(itemStr);
            TBrCtlSelectOptionData data(*itemStr, i == currentIndex(), false, itemIsEnabled(i));
            options->AppendL(data);
            items.AppendL(itemStr);
            CleanupStack::Pop();
        }
    }

    dialogs->DialogSelectOptionL(KNullDesC(), (TBrCtlSelectOptionType)(ESelectTypeSingle | ESelectTypeWithFindPane), *options);

    CleanupStack::PopAndDestroy(&items);

    int newIndex;
    for (newIndex = 0; newIndex < options->Count() && !options->At(newIndex).IsSelected(); newIndex++) {}
    if (newIndex == options->Count())
        newIndex = currentIndex();
    
    m_popupVisible = false;
    popupDidHide();

    if (currentIndex() != newIndex && newIndex >= 0)
        valueChanged(newIndex);

    delete options;
}
Wom_PortQueue::t_item Wom_PortQueue::pop_front()
//*************************************************************************************************************
{
	t_item item;

	WOM_ASSERT(itemCount() != 0);

	m_Mutex.Lock();
	item = m_circ_array[m_front];
	m_front++;
	if (m_front == m_Size)
	{
		m_front = 0;
	}

	m_count--;
	m_Mutex.Unlock();

	return item;
}
Exemplo n.º 27
0
void insertIt(Item **base, char *name, char *desc, int price, char *shelf, int amount) {
  
  Item **item = &(*base);
  int size = itemCount(base);
  int c = 0;
  Item **items[size];
  
  while((*item) != NULL) {
    items[c] = item;
    if (strcmp(name, (*item)->name) < 0) {
      item = &(*item)->left;
    } else if (strcmp(name, (*item)->name) > 0) {
      item = &(*item)->right;
    } else if (strcmp(name, (*item)->name) == 0) {
      addToShelves((*item)->shelves, shelf, amount);
      break;
    }
    
    ++c;
    
  }
  
  if ((*item) == NULL) {
    (*item) =  createItem(name, desc, price, shelf, amount);
  }
  
  for (int i = c; i >= 0; i--) {

    (*item)->height = max(getHeight((*item)->left), getHeight((*item)->right)) +1;

    int balanceFactor = getBalance(*item);
  
    if (balanceFactor < -1 || balanceFactor > 1) {
      balance(item, name, balanceFactor);
    }

  }


}
Exemplo n.º 28
0
void DropDownList::drawItem(DC& dc, int y, size_t item) {
    if (y + item_size.height <= 0 || y >= dc.GetSize().y) return; // not visible
    // draw background
    dc.SetPen(*wxTRANSPARENT_PEN);
    if (item == selected_item) {
        if (itemEnabled(item)) {
            dc.SetBrush         (wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
            dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
        } else {
            dc.SetBrush         (wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
            dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
        }
        dc.DrawRectangle(marginW, y, (int)item_size.width, (int)item_size.height);
    } else if (!itemEnabled(item)) {
        // mix between foreground and background
        dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
    } else if (highlightItem(item)) {
        // mix a color between selection and window
        dc.SetBrush         (lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT),
                                  wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), 0.75));
        dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
        dc.DrawRectangle(marginW, y, (int)item_size.width, (int)item_size.height);
    } else {
        dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
    }
    // draw text and icon
    drawIcon(dc, marginW, y, item, item == selected_item);
    dc.DrawText(capitalize(itemText(item)), marginW + (int)icon_size.width + 1, y + text_offset);
    // draw popup icon
    if (submenu(item)) {
        draw_menu_arrow(this, dc, RealRect(marginW, y, item_size.width, item_size.height), item == selected_item);
    }
    // draw line below
    if (lineBelow(item) && item != itemCount()) {
        dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
        dc.DrawLine(marginW, y + (int)item_size.height, marginW + (int)item_size.width, y + (int)item_size.height);
    }
}
Exemplo n.º 29
0
void DropDownList::onMotion(wxMouseEvent& ev) {
    // size
    wxSize cs = GetClientSize();
    // inside?
    if (ev.GetX() < marginW || ev.GetX() + marginW >= cs.GetWidth() || ev.GetY() < marginH || ev.GetY() + marginH >= cs.GetHeight()) {
        ev.Skip();
        return;
    }
    // find selected item
    int startY = marginH - visible_start;
    size_t count = itemCount();
    for (size_t i = 0 ; i < count ; ++i) {
        int endY = startY + (int)item_size.height;
        if (ev.GetY() >= startY && ev.GetY() < endY) {
            if (itemEnabled(i)) {
                showSubMenu(i, startY);
            }
            selectItem(i);
            return;
        }
        startY = endY + lineBelow(i);
    }
    hideSubMenu();
}
void AbstractWheelWidget::paintEvent(QPaintEvent* event)
{
    Q_UNUSED( event );

    // -- first calculate size and position.
    int w = width();
    int h = height();

    QPainter painter(this);
    QPalette palette = QApplication::palette();
    QPalette::ColorGroup colorGroup = isEnabled() ? QPalette::Active : QPalette::Disabled;

    // linear gradient brush
    QLinearGradient grad(0.5, 0, 0.5, 1.0);
    grad.setColorAt(0, palette.color(colorGroup, QPalette::ButtonText));
    grad.setColorAt(0.2, palette.color(colorGroup, QPalette::Button));
    grad.setColorAt(0.8, palette.color(colorGroup, QPalette::Button));
    grad.setColorAt(1.0, palette.color(colorGroup, QPalette::ButtonText));
    grad.setCoordinateMode( QGradient::ObjectBoundingMode );
    QBrush gBrush( grad );

    // paint a border and background
    painter.setPen(palette.color(colorGroup, QPalette::ButtonText));
    painter.setBrush(gBrush);
    // painter.setBrushOrigin( QPointF( 0.0, 0.0 ) );
    painter.drawRect( 0, 0, w-1, h-1 );

    // paint inner border
    painter.setPen(palette.color(colorGroup, QPalette::Button));
    painter.setBrush(Qt::NoBrush);
    painter.drawRect( 1, 1, w-3, h-3 );

    // paint the items
    painter.setClipRect( QRect( 3, 3, w-6, h-6 ) );
    painter.setPen(palette.color(colorGroup, QPalette::ButtonText));

    int iH = itemHeight();
    int iC = itemCount();
    if (iC > 0) {

        m_itemOffset = m_itemOffset % iH;

        for (int i=-h/2/iH; i<=h/2/iH+1; i++) {

            int itemNum = m_currentItem + i;
            while (itemNum < 0)
                itemNum += iC;
            while (itemNum >= iC)
                itemNum -= iC;

            paintItem(&painter, itemNum, QRect(6, h/2 +i*iH - m_itemOffset - iH/2, w-6, iH ));
        }
    }

    // draw a transparent bar over the center
    QColor highlight = palette.color(colorGroup, QPalette::Highlight);
    highlight.setAlpha(150);

    QLinearGradient grad2(0.5, 0, 0.5, 1.0);
    grad2.setColorAt(0, highlight);
    grad2.setColorAt(1.0, highlight.lighter());
    grad2.setCoordinateMode( QGradient::ObjectBoundingMode );
    QBrush gBrush2( grad2 );

    QLinearGradient grad3(0.5, 0, 0.5, 1.0);
    grad3.setColorAt(0, highlight);
    grad3.setColorAt(1.0, highlight.darker());
    grad3.setCoordinateMode( QGradient::ObjectBoundingMode );
    QBrush gBrush3( grad3 );

    painter.fillRect( QRect( 0, h/2 - iH/2, w, iH/2 ), gBrush2 );
    painter.fillRect( QRect( 0, h/2,        w, iH/2 ), gBrush3 );
}