| 935 | } |
| 936 | |
| 937 | void LollipopPlotPrivate::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget*) { |
| 938 | if (!isVisible()) |
| 939 | return; |
| 940 | |
| 941 | painter->setPen(Qt::NoPen); |
| 942 | painter->setBrush(Qt::NoBrush); |
| 943 | painter->setRenderHint(QPainter::SmoothPixmapTransform); |
| 944 | |
| 945 | if (!q->isPrinting() && Settings::group(QStringLiteral("Settings_Worksheet")).readEntry<bool>("DoubleBuffering", true)) |
| 946 | painter->drawPixmap(m_boundingRectangle.topLeft(), m_pixmap); // draw the cached pixmap (fast) |
| 947 | else |
| 948 | draw(painter); // draw directly again (slow) |
| 949 | |
| 950 | // no need to handle the selection/hover effect if the cached pixmap is empty |
| 951 | if (m_pixmap.isNull()) |
| 952 | return; |
| 953 | |
| 954 | if (m_hovered && !isSelected() && !q->isPrinting()) { |
| 955 | if (m_hoverEffectImageIsDirty) { |
| 956 | QPixmap pix = m_pixmap; |
| 957 | QPainter p(&pix); |
| 958 | p.setCompositionMode(QPainter::CompositionMode_SourceIn); // source (shadow) pixels merged with the alpha channel of the destination (m_pixmap) |
| 959 | p.fillRect(pix.rect(), QApplication::palette().color(QPalette::Shadow)); |
| 960 | p.end(); |
| 961 | |
| 962 | m_hoverEffectImage = ImageTools::blurred(pix.toImage(), m_pixmap.rect(), 5); |
| 963 | m_hoverEffectImageIsDirty = false; |
| 964 | } |
| 965 | |
| 966 | painter->drawImage(m_boundingRectangle.topLeft(), m_hoverEffectImage, m_pixmap.rect()); |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | if (isSelected() && !q->isPrinting()) { |
| 971 | if (m_selectionEffectImageIsDirty) { |
| 972 | QPixmap pix = m_pixmap; |
| 973 | QPainter p(&pix); |
| 974 | p.setCompositionMode(QPainter::CompositionMode_SourceIn); |
| 975 | p.fillRect(pix.rect(), QApplication::palette().color(QPalette::Highlight)); |
| 976 | p.end(); |
| 977 | |
| 978 | m_selectionEffectImage = ImageTools::blurred(pix.toImage(), m_pixmap.rect(), 5); |
| 979 | m_selectionEffectImageIsDirty = false; |
| 980 | } |
| 981 | |
| 982 | painter->drawImage(m_boundingRectangle.topLeft(), m_selectionEffectImage, m_pixmap.rect()); |
| 983 | return; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // ############################################################################## |
| 988 | // ################## Serialization/Deserialization ########################### |