src/gui/styles/qs60style.cpp
changeset 22 79de32ba3296
parent 19 fcece45ef507
child 23 89e065397ea6
equal deleted inserted replaced
19:fcece45ef507 22:79de32ba3296
   120 // theme palette
   120 // theme palette
   121 QPalette *QS60StylePrivate::m_themePalette = 0;
   121 QPalette *QS60StylePrivate::m_themePalette = 0;
   122 
   122 
   123 qint64 QS60StylePrivate::m_webPaletteKey = 0;
   123 qint64 QS60StylePrivate::m_webPaletteKey = 0;
   124 
   124 
       
   125 QPointer<QWidget> QS60StylePrivate::m_pressedWidget = 0;
       
   126 
   125 const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = {
   127 const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = {
   126     {SE_ButtonNormal,           QS60StyleEnums::SP_QsnFrButtonTbCenter},
   128     {SE_ButtonNormal,           QS60StyleEnums::SP_QsnFrButtonTbCenter},
   127     {SE_ButtonPressed,          QS60StyleEnums::SP_QsnFrButtonTbCenterPressed},
   129     {SE_ButtonPressed,          QS60StyleEnums::SP_QsnFrButtonTbCenterPressed},
   128     {SE_FrameLineEdit,          QS60StyleEnums::SP_QsnFrInputCenter},
   130     {SE_FrameLineEdit,          QS60StyleEnums::SP_QsnFrInputCenter},
   129     {SE_ListHighlight,          QS60StyleEnums::SP_QsnFrListCenter},
   131     {SE_ListHighlight,          QS60StyleEnums::SP_QsnFrListCenter},
   136     {SE_ToolBarButton,          QS60StyleEnums::SP_QsnFrSctrlButtonCenter},
   138     {SE_ToolBarButton,          QS60StyleEnums::SP_QsnFrSctrlButtonCenter},
   137     {SE_ToolBarButtonPressed,   QS60StyleEnums::SP_QsnFrSctrlButtonCenterPressed},
   139     {SE_ToolBarButtonPressed,   QS60StyleEnums::SP_QsnFrSctrlButtonCenterPressed},
   138     {SE_PanelBackground,        QS60StyleEnums::SP_QsnFrSetOptCenter},
   140     {SE_PanelBackground,        QS60StyleEnums::SP_QsnFrSetOptCenter},
   139     {SE_ButtonInactive,         QS60StyleEnums::SP_QsnFrButtonCenterInactive},
   141     {SE_ButtonInactive,         QS60StyleEnums::SP_QsnFrButtonCenterInactive},
   140     {SE_Editor,                 QS60StyleEnums::SP_QsnFrInputCenter},
   142     {SE_Editor,                 QS60StyleEnums::SP_QsnFrInputCenter},
       
   143     {SE_TableItemPressed,       QS60StyleEnums::SP_QsnFrGridCenterPressed},
       
   144     {SE_ListItemPressed,        QS60StyleEnums::SP_QsnFrListPressed},
   141 };
   145 };
   142 
   146 
   143 static const int frameElementsCount =
   147 static const int frameElementsCount =
   144     int(sizeof(QS60StylePrivate::m_frameElementsData)/sizeof(QS60StylePrivate::m_frameElementsData[0]));
   148     int(sizeof(QS60StylePrivate::m_frameElementsData)/sizeof(QS60StylePrivate::m_frameElementsData[0]));
   145 
   149 
   291     case SE_Editor:
   295     case SE_Editor:
   292         drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth);
   296         drawFrame(SF_FrameLineEdit, painter, rect, flags | SF_PointNorth);
   293         break;
   297         break;
   294     case SE_DropArea:
   298     case SE_DropArea:
   295         drawPart(QS60StyleEnums::SP_QgnGrafOrgBgGrid, painter, rect, flags | SF_PointNorth);
   299         drawPart(QS60StyleEnums::SP_QgnGrafOrgBgGrid, painter, rect, flags | SF_PointNorth);
       
   300         break;
       
   301     case SE_TableItemPressed:
       
   302         drawFrame(SF_TableItemPressed, painter, rect, flags | SF_PointNorth);
       
   303         break;
       
   304     case SE_ListItemPressed:
       
   305         drawFrame(SF_ListItemPressed, painter, rect, flags | SF_PointNorth);
   296         break;
   306         break;
   297     default:
   307     default:
   298         break;
   308         break;
   299     }
   309     }
   300 }
   310 }
   540     QRect startRect = QRect(rect.topLeft(), startEndSize);
   550     QRect startRect = QRect(rect.topLeft(), startEndSize);
   541     QRect middleRect = rect;
   551     QRect middleRect = rect;
   542     QRect endRect;
   552     QRect endRect;
   543 
   553 
   544     if (orientation == Qt::Horizontal) {
   554     if (orientation == Qt::Horizontal) {
       
   555         startRect.setHeight(rect.height());
   545         startRect.setWidth(qMin((rect.width() >> 1) - 1, startRect.width()));
   556         startRect.setWidth(qMin((rect.width() >> 1) - 1, startRect.width()));
   546         endRect = startRect.translated(rect.width() - startRect.width(), 0);
   557         endRect = startRect.translated(rect.width() - startRect.width(), 0);
   547         middleRect.adjust(startRect.width(), 0, -startRect.width(), 0);
   558         middleRect.adjust(startRect.width(), 0, -startRect.width(), 0);
   548         if (startRect.bottomRight().x() > endRect.topLeft().x()) {
   559         if (startRect.bottomRight().x() > endRect.topLeft().x()) {
   549             const int overlap = (startRect.bottomRight().x() -  endRect.topLeft().x()) >> 1;
   560             const int overlap = (startRect.bottomRight().x() -  endRect.topLeft().x()) >> 1;
   550             startRect.setWidth(startRect.width() - overlap);
   561             startRect.setWidth(startRect.width() - overlap);
   551             endRect.adjust(overlap, 0, 0, 0);
   562             endRect.adjust(overlap, 0, 0, 0);
   552         }
   563         }
   553     } else {
   564     } else {
       
   565         startRect.setWidth(rect.width());
   554         startRect.setHeight(qMin((rect.height() >> 1) - 1, startRect.height()));
   566         startRect.setHeight(qMin((rect.height() >> 1) - 1, startRect.height()));
   555         endRect = startRect.translated(0, rect.height() - startRect.height());
   567         endRect = startRect.translated(0, rect.height() - startRect.height());
   556         middleRect.adjust(0, startRect.height(), 0, -startRect.height());
   568         middleRect.adjust(0, startRect.height(), 0, -startRect.height());
   557         if (startRect.topRight().y() > endRect.bottomLeft().y()) {
   569         if (startRect.topRight().y() > endRect.bottomLeft().y()) {
   558             const int overlap = (startRect.topRight().y() - endRect.bottomLeft().y()) >> 1;
   570             const int overlap = (startRect.topRight().y() - endRect.bottomLeft().y()) >> 1;
   937     //If brush is not changed from style's default values, draw theme graphics.
   949     //If brush is not changed from style's default values, draw theme graphics.
   938     return (backgroundBrush.color() == Qt::transparent ||
   950     return (backgroundBrush.color() == Qt::transparent ||
   939             backgroundBrush.style() == Qt::NoBrush) ? true : false;
   951             backgroundBrush.style() == Qt::NoBrush) ? true : false;
   940 }
   952 }
   941 
   953 
       
   954 bool QS60StylePrivate::isWidgetPressed(const QWidget *widget)
       
   955 {
       
   956     return (widget && widget == m_pressedWidget);
       
   957 }
       
   958 
   942 /*!
   959 /*!
   943   \class QS60Style
   960   \class QS60Style
   944   \brief The QS60Style class provides a look and feel suitable for applications on S60.
   961   \brief The QS60Style class provides a look and feel suitable for applications on S60.
   945   \since 4.6
   962   \since 4.6
   946   \ingroup appearance
   963   \ingroup appearance
  1355             optionComboBox.palette.setColor(QPalette::Active, QPalette::WindowText,
  1372             optionComboBox.palette.setColor(QPalette::Active, QPalette::WindowText,
  1356                 optionComboBox.palette.text().color() );
  1373                 optionComboBox.palette.text().color() );
  1357             optionComboBox.palette.setColor(QPalette::Inactive, QPalette::WindowText,
  1374             optionComboBox.palette.setColor(QPalette::Inactive, QPalette::WindowText,
  1358                 optionComboBox.palette.text().color() );
  1375                 optionComboBox.palette.text().color() );
  1359             QRect editRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
  1376             QRect editRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
  1360             painter->save();
  1377             const int frameW = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
  1361             painter->setClipRect(editRect);
       
  1362 
  1378 
  1363             if (!comboBox->currentIcon.isNull()) {
  1379             if (!comboBox->currentIcon.isNull()) {
  1364                 QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
  1380                 const QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
  1365                 QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
  1381                 const QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
  1366                 QRect iconRect(editRect);
  1382                 QRect iconRect(editRect);
  1367                 iconRect.setWidth(comboBox->iconSize.width() + 4);
  1383                 iconRect.setWidth(comboBox->iconSize.width() + frameW);
  1368                 iconRect = alignedRect(comboBox->direction,
  1384                 iconRect = alignedRect(comboBox->direction,
  1369                                        Qt::AlignLeft | Qt::AlignVCenter,
  1385                                        Qt::AlignLeft | Qt::AlignVCenter,
  1370                                        iconRect.size(), editRect);
  1386                                        iconRect.size(), editRect);
  1371                 if (comboBox->editable)
  1387                 if (comboBox->editable)
  1372                     painter->fillRect(iconRect, optionComboBox.palette.brush(QPalette::Base));
  1388                     painter->fillRect(iconRect, optionComboBox.palette.brush(QPalette::Base));
  1373                 drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
  1389                 drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
  1374 
  1390 
  1375                 if (comboBox->direction == Qt::RightToLeft)
  1391                 if (comboBox->direction == Qt::RightToLeft)
  1376                     editRect.translate(-4 - comboBox->iconSize.width(), 0);
  1392                     editRect.setRight(editRect.right() - frameW - comboBox->iconSize.width());
  1377                 else
  1393                 else
  1378                     editRect.translate(comboBox->iconSize.width() + 4, 0);
  1394                     editRect.setLeft(comboBox->iconSize.width() + frameW);
  1379             }
  1395             }
  1380             if (!comboBox->currentText.isEmpty() && !comboBox->editable) {
  1396             if (!comboBox->currentText.isEmpty() && !comboBox->editable) {
       
  1397                 const Qt::TextElideMode elideMode = (comboBox->direction == Qt::LeftToRight) ? Qt::ElideRight : Qt::ElideLeft;
       
  1398                 const QString text = comboBox->fontMetrics.elidedText(comboBox->currentText, elideMode, editRect.width());
       
  1399 
  1381                 QCommonStyle::drawItemText(painter,
  1400                 QCommonStyle::drawItemText(painter,
  1382                             editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0),
  1401                             editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0),
  1383                             visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter),
  1402                             visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter),
  1384                             comboBox->palette, comboBox->state & State_Enabled, comboBox->currentText);
  1403                             comboBox->palette, comboBox->state & State_Enabled, text);
  1385             }
  1404             }
  1386             painter->restore();
       
  1387         }
  1405         }
  1388         break;
  1406         break;
  1389 #endif //QT_NO_COMBOBOX
  1407 #endif //QT_NO_COMBOBOX
  1390 #ifndef QT_NO_ITEMVIEWS
  1408 #ifndef QT_NO_ITEMVIEWS
  1391     case CE_ItemViewItem:
  1409     case CE_ItemViewItem:
  1422             const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget);
  1440             const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget);
  1423 
  1441 
  1424             // draw themed background for table unless background brush has been defined.
  1442             // draw themed background for table unless background brush has been defined.
  1425             if (vopt->backgroundBrush == Qt::NoBrush) {
  1443             if (vopt->backgroundBrush == Qt::NoBrush) {
  1426                 if (itemView) {
  1444                 if (itemView) {
  1427                     const QModelIndex index = vopt->index;
       
  1428                     //todo: Draw cell background only once - for the first cell.
       
  1429                     QStyleOptionViewItemV4 voptAdj2 = voptAdj;
       
  1430                     const QModelIndex indexFirst = itemView->model()->index(0, 0);
       
  1431                     const QModelIndex indexLast = itemView->model()->index(
       
  1432                             itemView->model()->rowCount() - 1, itemView->model()->columnCount() -1);
       
  1433                     if (itemView->viewport())
       
  1434                         voptAdj2.rect = QRect( itemView->visualRect(indexFirst).topLeft(),
       
  1435                                 itemView->visualRect(indexLast).bottomRight()).intersect(itemView->viewport()->rect());
       
  1436                     drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);
  1445                     drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);
  1437                 }
  1446                 }
  1438             } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);}
  1447             } else { QCommonStyle::drawPrimitive(PE_PanelItemViewItem, &voptAdj, painter, widget);}
  1439 
  1448 
  1440             // draw the focus rect
       
  1441             if (isSelected || hasFocus ) {
       
  1442                 QRect highlightRect = option->rect.adjusted(1,1,-1,-1);
       
  1443                 QAbstractItemView::SelectionBehavior selectionBehavior =
       
  1444                     itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems;
       
  1445                 if (selectionBehavior != QAbstractItemView::SelectItems) {
       
  1446                     // set highlight rect so that it is continuous from cell to cell, yet sligthly
       
  1447                     // smaller than cell rect
       
  1448                     int xBeginning = 0, yBeginning = 0, xEnd = 0, yEnd = 0;
       
  1449                     if (selectionBehavior == QAbstractItemView::SelectRows) {
       
  1450                         yBeginning = 1; yEnd = -1;
       
  1451                         if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning)
       
  1452                             xBeginning = 1;
       
  1453                         else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End)
       
  1454                             xEnd = -1;
       
  1455                     } else if (selectionBehavior == QAbstractItemView::SelectColumns) {
       
  1456                         xBeginning = 1; xEnd = -1;
       
  1457                         if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning)
       
  1458                             yBeginning = 1;
       
  1459                         else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End)
       
  1460                             yEnd = -1;
       
  1461                     }
       
  1462                     highlightRect = option->rect.adjusted(xBeginning, yBeginning, xEnd, yEnd);
       
  1463                 }
       
  1464                 if (vopt->showDecorationSelected &&
       
  1465                     (vopt->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()))
       
  1466                     QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, highlightRect, flags);
       
  1467                 else
       
  1468                     painter->fillRect(highlightRect, vopt->palette.highlight());
       
  1469             }
       
  1470 
       
  1471              // draw the icon
  1449              // draw the icon
  1472              const QIcon::Mode mode = (voptAdj.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled;
  1450              const QIcon::Mode mode = (voptAdj.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled;
  1473              const QIcon::State state = voptAdj.state & State_Open ? QIcon::On : QIcon::Off;
  1451              const QIcon::State state = (voptAdj.state & State_Open) ? QIcon::On : QIcon::Off;
  1474              voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state);
  1452              voptAdj.icon.paint(painter, iconRect, voptAdj.decorationAlignment, mode, state);
  1475 
  1453 
  1476              // Draw selection check mark. Show check mark only in multi selection modes.
  1454              // Draw selection check mark. Show check mark only in multi selection modes.
  1477              if (itemView) {
  1455              if (itemView) {
  1478                  const bool singleSelection =
  1456                  const bool singleSelection =
  1479                      (itemView->selectionMode() == QAbstractItemView::SingleSelection ||
  1457                      (itemView->selectionMode() == QAbstractItemView::SingleSelection ||
  1480                       itemView->selectionMode() == QAbstractItemView::NoSelection);
  1458                       itemView->selectionMode() == QAbstractItemView::NoSelection)||
       
  1459                      (itemView->selectionModel()->selectedIndexes().count() < 2 );
       
  1460 
       
  1461                  const bool selectItemsOnly = (itemView->selectionBehavior() == QAbstractItemView::SelectItems);
       
  1462 
  1481                  const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget);
  1463                  const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, &voptAdj, widget);
  1482 
  1464 
  1483                  QStyleOptionViewItemV4 checkMarkOption(voptAdj);
  1465                  QStyleOptionViewItemV4 checkMarkOption(voptAdj);
       
  1466                  if (selectionRect.isValid())
       
  1467                      checkMarkOption.rect = selectionRect;
  1484                  // Draw selection mark.
  1468                  // Draw selection mark.
  1485                  if (voptAdj.state & State_Selected && !singleSelection) {
  1469                  if (isSelected && !singleSelection && selectItemsOnly) {
  1486                      checkMarkOption.rect = selectionRect;
  1470                      proxy()->drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1487                      drawPrimitive(PE_IndicatorViewItemCheck, &checkMarkOption, painter, widget);
  1471                      // @todo: this should happen in the rect retrievel i.e. subElementRect()
  1488                      if ( textRect.right() > selectionRect.left() )
  1472                      if (textRect.right() > selectionRect.left())
  1489                          textRect.setRight(selectionRect.left());
  1473                          textRect.setRight(selectionRect.left());
  1490                  } else if (singleSelection &&
  1474                  } else if (singleSelection &&
  1491                      voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator &&
  1475                      voptAdj.features & QStyleOptionViewItemV2::HasCheckIndicator) {
  1492                      selectionRect.isValid()) {
       
  1493                      checkMarkOption.rect = selectionRect;
       
  1494                      checkMarkOption.state = checkMarkOption.state & ~State_HasFocus;
  1476                      checkMarkOption.state = checkMarkOption.state & ~State_HasFocus;
  1495 
  1477 
  1496                      switch (vopt->checkState) {
  1478                      switch (vopt->checkState) {
  1497                      case Qt::Unchecked:
  1479                      case Qt::Unchecked:
  1498                          checkMarkOption.state |= State_Off;
  1480                          checkMarkOption.state |= State_Off;
  1560                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1542                     skinElement==QS60StylePrivate::SE_TabBarTabWestActive) {
  1561                 const int borderThickness =
  1543                 const int borderThickness =
  1562                     QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1544                     QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  1563                 const int tabOverlap =
  1545                 const int tabOverlap =
  1564                     QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1546                     QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap) - borderThickness;
  1565                 //todo: draw navi wipe behind tabbar - must be drawn with first draw
       
  1566 
  1547 
  1567                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1548                 if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive||
  1568                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1549                         skinElement==QS60StylePrivate::SE_TabBarTabEastActive||
  1569                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1550                         skinElement==QS60StylePrivate::SE_TabBarTabWestInactive||
  1570                         skinElement==QS60StylePrivate::SE_TabBarTabWestActive){
  1551                         skinElement==QS60StylePrivate::SE_TabBarTabWestActive){
  1664                                         tabIcon);
  1645                                         tabIcon);
  1665                 else
  1646                 else
  1666                     painter->drawPixmap(tr.left() + tabOverlap,
  1647                     painter->drawPixmap(tr.left() + tabOverlap,
  1667                                         tr.center().y() - (tabIcon.height() >> 1),
  1648                                         tr.center().y() - (tabIcon.height() >> 1),
  1668                                         tabIcon);
  1649                                         tabIcon);
  1669                 tr.setLeft(tr.left() + iconSize.width() + 4);
  1650                 tr.setLeft(tr.left() + iconSize.width() + 4); //todo: magic four
  1670             }
  1651             }
  1671 
  1652 
  1672             QCommonStyle::drawItemText(painter, tr, alignment, optionTab.palette, tab->state & State_Enabled, tab->text, QPalette::WindowText);
  1653             QCommonStyle::drawItemText(painter, tr, alignment, optionTab.palette, tab->state & State_Enabled, tab->text, QPalette::WindowText);
  1673             if (verticalTabs)
  1654             if (verticalTabs)
  1674                 painter->restore();
  1655                 painter->restore();
  1983             const qreal opacity = 0.85;
  1964             const qreal opacity = 0.85;
  1984 #endif
  1965 #endif
  1985             // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin
  1966             // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin
  1986             // Otherwise, we would overlay adjacent widgets.
  1967             // Otherwise, we would overlay adjacent widgets.
  1987             const int frameHeightReduction =
  1968             const int frameHeightReduction =
  1988                     qMin(0, pixelMetric(QStyle::PM_LayoutVerticalSpacing)
  1969                     qMin(0, pixelMetric(PM_LayoutVerticalSpacing)
  1989                             - pixelMetric(QStyle::PM_FocusFrameVMargin));
  1970                             - pixelMetric(PM_FocusFrameVMargin));
  1990             const int frameWidthReduction =
  1971             const int frameWidthReduction =
  1991                     qMin(0, pixelMetric(QStyle::PM_LayoutHorizontalSpacing)
  1972                     qMin(0, pixelMetric(PM_LayoutHorizontalSpacing)
  1992                             - pixelMetric(QStyle::PM_FocusFrameHMargin));
  1973                             - pixelMetric(PM_FocusFrameHMargin));
  1993             const int rounding =
  1974             const int rounding =
  1994                     qMin(pixelMetric(QStyle::PM_FocusFrameVMargin),
  1975                     qMin(pixelMetric(PM_FocusFrameVMargin),
  1995                             pixelMetric(QStyle::PM_LayoutVerticalSpacing));
  1976                             pixelMetric(PM_LayoutVerticalSpacing));
  1996             const QRect frameRect =
  1977             const QRect frameRect =
  1997                     option->rect.adjusted(-frameWidthReduction, -frameHeightReduction,
  1978                     option->rect.adjusted(-frameWidthReduction, -frameHeightReduction,
  1998                             frameWidthReduction, frameHeightReduction);
  1979                             frameWidthReduction, frameHeightReduction);
  1999             QPainterPath framePath;
  1980             QPainterPath framePath;
  2000             framePath.addRoundedRect(frameRect, rounding, rounding);
  1981             framePath.addRoundedRect(frameRect, rounding, rounding);
  2035             //Draw themed highlight to radiobuttons and checkboxes.
  2016             //Draw themed highlight to radiobuttons and checkboxes.
  2036             //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle.
  2017             //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle.
  2037             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color())
  2018             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color())
  2038                 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) &&
  2019                 if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) &&
  2039                     (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget))))
  2020                     (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget))))
  2040                         QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
  2021                         QS60StylePrivate::drawSkinElement(
       
  2022                             QS60StylePrivate::isWidgetPressed(widget) ? 
       
  2023                                 QS60StylePrivate::SE_ListItemPressed : 
       
  2024                                 QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags);
  2041             else
  2025             else
  2042                 commonStyleDraws = true;
  2026                 commonStyleDraws = true;
  2043             }
  2027             }
  2044         break;
  2028         break;
  2045 #ifndef QT_NO_LINEEDIT
  2029 #ifndef QT_NO_LINEEDIT
  2255         break;
  2239         break;
  2256     case PE_Frame:
  2240     case PE_Frame:
  2257         break;
  2241         break;
  2258 #ifndef QT_NO_ITEMVIEWS
  2242 #ifndef QT_NO_ITEMVIEWS
  2259     case PE_PanelItemViewItem:
  2243     case PE_PanelItemViewItem:
       
  2244         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
       
  2245             const bool isSelected = (vopt->state & State_Selected);
       
  2246             const bool hasFocus = (vopt->state & State_HasFocus);
       
  2247             const bool isPressed = QS60StylePrivate::isWidgetPressed(widget);
       
  2248 
       
  2249             if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) {
       
  2250                 QRect highlightRect = vopt->rect.adjusted(1,1,-1,-1);
       
  2251                 const QAbstractItemView *itemView = qobject_cast<const QAbstractItemView *>(widget);
       
  2252                 QAbstractItemView::SelectionBehavior selectionBehavior =
       
  2253                     itemView ? itemView->selectionBehavior() : QAbstractItemView::SelectItems;
       
  2254                 // Set the draw area for highlights (focus, select rect or pressed rect)
       
  2255                 if (hasFocus || isSelected || isPressed) {
       
  2256                     if (selectionBehavior != QAbstractItemView::SelectItems) {
       
  2257                         // set highlight rect so that it is continuous from cell to cell, yet sligthly
       
  2258                         // smaller than cell rect
       
  2259                         int xBeginning = 0, yBeginning = 0, xEnd = 0, yEnd = 0;
       
  2260                         if (selectionBehavior == QAbstractItemView::SelectRows) {
       
  2261                             yBeginning = 1; yEnd = -1;
       
  2262                             if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning)
       
  2263                                 xBeginning = 1;
       
  2264                             else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End)
       
  2265                                 xEnd = -1;
       
  2266                         } else if (selectionBehavior == QAbstractItemView::SelectColumns) {
       
  2267                             xBeginning = 1; xEnd = -1;
       
  2268                             if (vopt->viewItemPosition == QStyleOptionViewItemV4::Beginning)
       
  2269                                 yBeginning = 1;
       
  2270                             else if (vopt->viewItemPosition == QStyleOptionViewItemV4::End)
       
  2271                                 yEnd = -1;
       
  2272                         }
       
  2273                         highlightRect = option->rect.adjusted(xBeginning, yBeginning, xEnd, yEnd);
       
  2274                     }
       
  2275                 }
       
  2276                 bool tableView = false;
       
  2277                 if (itemView && qobject_cast<const QTableView *>(widget))
       
  2278                     tableView = true;
       
  2279 
       
  2280                 QS60StylePrivate::SkinElements element;
       
  2281                 QRect elementRect = option->rect;
       
  2282 
       
  2283                 //draw item is drawn as pressed, if it already has focus.
       
  2284                 if (isPressed && (hasFocus || isSelected)) {
       
  2285                     element = tableView ? QS60StylePrivate::SE_TableItemPressed : QS60StylePrivate::SE_ListItemPressed;
       
  2286                 } else if (hasFocus || (isSelected && selectionBehavior != QAbstractItemView::SelectItems)) {
       
  2287                     element = QS60StylePrivate::SE_ListHighlight;
       
  2288                     elementRect = highlightRect;
       
  2289                 }
       
  2290                 QS60StylePrivate::drawSkinElement(element, painter, elementRect, flags);
       
  2291             } else {
       
  2292                 QCommonStyle::drawPrimitive(element, option, painter, widget);
       
  2293             }
       
  2294         }
  2260         break;
  2295         break;
  2261 #endif //QT_NO_ITEMVIEWS
  2296 #endif //QT_NO_ITEMVIEWS
  2262 
  2297 
  2263     case PE_IndicatorMenuCheckMark:
  2298     case PE_IndicatorMenuCheckMark:
  2264         if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){
  2299         if (const QStyleOptionMenuItem *checkBox = qstyleoption_cast<const QStyleOptionMenuItem *>(option)){
  2431                 const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0;
  2466                 const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0;
  2432 
  2467 
  2433                 const int contentHeight =
  2468                 const int contentHeight =
  2434                         qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin),
  2469                         qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin),
  2435                              textHeight + 2*pixelMetric(PM_ButtonMargin));
  2470                              textHeight + 2*pixelMetric(PM_ButtonMargin));
  2436                 sz.setHeight(contentHeight);
  2471                 sz.setHeight(qMax(sz.height(), contentHeight));
  2437                 sz += QSize(2 * pixelMetric(PM_ButtonMargin), 0);
  2472                 sz += QSize(2 * pixelMetric(PM_ButtonMargin), 0);
  2438             }
  2473             }
  2439             break;
  2474             break;
  2440         case CT_LineEdit:
  2475         case CT_LineEdit:
  2441             if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt))
  2476             if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt))
  2812 
  2847 
  2813                 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2848                 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  2814                     const int tabOverlapNoBorder =
  2849                     const int tabOverlapNoBorder =
  2815                         QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap);
  2850                         QS60StylePrivate::pixelMetric(PM_TabBarTabOverlap);
  2816                     const int tabOverlap =
  2851                     const int tabOverlap =
  2817                         tabOverlapNoBorder-QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  2852                         tabOverlapNoBorder - QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth);
  2818                     const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget);
  2853                     const QTabWidget *tab = qobject_cast<const QTabWidget *>(widget);
  2819                     int gain = (tab) ? tabOverlap * tab->count() : 0;
  2854                     int gain = (tab) ? tabOverlap * tab->count() : 0;
  2820                     switch (twf->shape) {
  2855                     switch (twf->shape) {
  2821                         case QTabBar::RoundedNorth:
  2856                         case QTabBar::RoundedNorth:
  2822                         case QTabBar::TriangularNorth:
  2857                         case QTabBar::TriangularNorth:
  2878                 if (element == SE_ItemViewItemDecoration) {
  2913                 if (element == SE_ItemViewItemDecoration) {
  2879                     if (menuItem->icon.isNull()) {
  2914                     if (menuItem->icon.isNull()) {
  2880                         ret = QRect();
  2915                         ret = QRect();
  2881                     } else {
  2916                     } else {
  2882                         if (menuItem->direction == Qt::RightToLeft)
  2917                         if (menuItem->direction == Qt::RightToLeft)
  2883                             ret.translate(ret.width()-indicatorWidth, 0);
  2918                             ret.translate(ret.width() - indicatorWidth, 0);
  2884                         ret.setWidth(indicatorWidth);
  2919                         ret.setWidth(indicatorWidth);
  2885                     }
  2920                     }
  2886                 } else {
  2921                 } else {
  2887                     ret = menuItem->rect;
  2922                     ret = menuItem->rect;
  2888                     if (!menuItem->icon.isNull())
  2923                     if (!menuItem->icon.isNull())
  3065   \reimp
  3100   \reimp
  3066  */
  3101  */
  3067 void QS60Style::polish(QApplication *application)
  3102 void QS60Style::polish(QApplication *application)
  3068 {
  3103 {
  3069     Q_D(QS60Style);
  3104     Q_D(QS60Style);
       
  3105     QCommonStyle::polish(qApp);
  3070     d->m_originalPalette = application->palette();
  3106     d->m_originalPalette = application->palette();
  3071     d->setThemePalette(application);
  3107     d->setThemePalette(application);
       
  3108     if (QS60StylePrivate::isTouchSupported())
       
  3109         qApp->installEventFilter(this);
  3072 }
  3110 }
  3073 
  3111 
  3074 /*!
  3112 /*!
  3075   \reimp
  3113   \reimp
  3076  */
  3114  */
  3077 void QS60Style::unpolish(QApplication *application)
  3115 void QS60Style::unpolish(QApplication *application)
  3078 {
  3116 {
  3079     Q_UNUSED(application)
  3117     Q_UNUSED(application)
       
  3118 
  3080     Q_D(QS60Style);
  3119     Q_D(QS60Style);
       
  3120     QCommonStyle::unpolish(qApp);
  3081     const QPalette newPalette = QApplication::style()->standardPalette();
  3121     const QPalette newPalette = QApplication::style()->standardPalette();
  3082     QApplication::setPalette(newPalette);
  3122     QApplication::setPalette(newPalette);
  3083     QApplicationPrivate::setSystemPalette(d->m_originalPalette);
  3123     QApplicationPrivate::setSystemPalette(d->m_originalPalette);
       
  3124     if (QS60StylePrivate::isTouchSupported())
       
  3125         qApp->removeEventFilter(this);
  3084 }
  3126 }
  3085 
  3127 
  3086 /*!
  3128 /*!
  3087   \reimp
  3129   \reimp
  3088  */
  3130  */
  3225     \internal
  3267     \internal
  3226     Animate indeterminate progress bars only when visible
  3268     Animate indeterminate progress bars only when visible
  3227 */
  3269 */
  3228 bool QS60Style::eventFilter(QObject *object, QEvent *event)
  3270 bool QS60Style::eventFilter(QObject *object, QEvent *event)
  3229 {
  3271 {
       
  3272     Q_D(QS60Style);
       
  3273     switch(event->type()) {
       
  3274         case QEvent::MouseButtonPress: {
       
  3275             QWidget *w = QApplication::widgetAt(QCursor::pos());
       
  3276             if (w) {
       
  3277                 QWidget *focusW = w->focusProxy();
       
  3278                 if (qobject_cast<QAbstractItemView *>(focusW) ||
       
  3279                     qobject_cast<QRadioButton *>(focusW) ||
       
  3280                     qobject_cast<QCheckBox *>(focusW))
       
  3281                     d->m_pressedWidget = focusW;
       
  3282                 else if (qobject_cast<QAbstractItemView *>(w)||
       
  3283                         qobject_cast<QRadioButton *>(w) ||
       
  3284                         qobject_cast<QCheckBox *>(w))
       
  3285                     d->m_pressedWidget = w;
       
  3286 
       
  3287                 if ( d->m_pressedWidget)
       
  3288                     d->m_pressedWidget->update();
       
  3289             }
       
  3290             break;
       
  3291         }
       
  3292         case QEvent::MouseButtonRelease: {
       
  3293             const QWidget *w = QApplication::widgetAt(QCursor::pos());
       
  3294             if (w && d->m_pressedWidget) {
       
  3295                 d->m_pressedWidget->update();
       
  3296                 d->m_pressedWidget = 0;
       
  3297             }
       
  3298             break;
       
  3299         }
       
  3300         default:
       
  3301             break;
       
  3302     }
       
  3303 
  3230 #ifdef Q_WS_S60
  3304 #ifdef Q_WS_S60
  3231 #ifndef QT_NO_PROGRESSBAR
  3305 #ifndef QT_NO_PROGRESSBAR
  3232     Q_D(QS60Style);
       
  3233     switch(event->type()) {
  3306     switch(event->type()) {
  3234     case QEvent::StyleChange:
  3307     case QEvent::StyleChange:
  3235     case QEvent::Show:
  3308     case QEvent::Show:
  3236         if (QProgressBar *bar = qobject_cast<QProgressBar *>(object)) {
  3309         if (QProgressBar *bar = qobject_cast<QProgressBar *>(object)) {
  3237             if (!d->m_bars.contains(bar))
  3310             if (!d->m_bars.contains(bar))
  3240                 d->startAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
  3313                 d->startAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
  3241         }
  3314         }
  3242         break;
  3315         break;
  3243     case QEvent::Destroy:
  3316     case QEvent::Destroy:
  3244     case QEvent::Hide:
  3317     case QEvent::Hide:
  3245         d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
  3318         if (QProgressBar *bar = reinterpret_cast<QProgressBar *>(object)) {
  3246         d->m_bars.removeAll(reinterpret_cast<QProgressBar *>(object));
  3319             d->stopAnimation(QS60StyleEnums::SP_QgnGrafBarWaitAnim);
       
  3320             d->m_bars.removeAll(bar);
       
  3321         }
  3247         break;
  3322         break;
  3248     default:
  3323     default:
  3249         break;
  3324         break;
  3250     }
  3325     }
  3251 #endif // QT_NO_PROGRESSBAR
  3326 #endif // QT_NO_PROGRESSBAR
  3252 #endif // Q_WS_S60
  3327 #endif // Q_WS_S60
  3253     return QStyle::eventFilter(object, event);
  3328     return QCommonStyle::eventFilter(object, event);
  3254 }
  3329 }
  3255 
  3330 
  3256 /*!
  3331 /*!
  3257     \internal
  3332     \internal
  3258     Handle the timer \a event.
  3333     Handle the timer \a event.