void ShadowEffect::draw(QPainter *painter) { if (m_blurRadius < 0 && qFuzzyIsNull(m_xOffset) && qFuzzyIsNull(m_yOffset)) { drawSource(painter); return; } PixmapPadMode mode = PadToEffectiveBoundingRect; if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) { mode = NoPad; } // Draw pixmap in device coordinates to avoid pixmap scaling. QPoint offset; const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); if (pixmap.isNull()) { return; } QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); if (m_shadow.isNull()) { m_shadow = generateShadow(pixmap); } // Draw shadow (draw it twice to darken it) painter->drawImage(offset, m_shadow); painter->drawImage(offset, m_shadow); // Draw the actual pixmap painter->drawPixmap(offset, pixmap); painter->setWorldTransform(restoreTransform); }
KNMusicAlbumView::KNMusicAlbumView(QWidget *parent) : QAbstractItemView(parent), m_shadowSource(QPixmap("://public/shadow.png")), m_albumArtShadow(QPixmap()), m_albumBase(QPixmap(":/plugin/music/public/base.png")), m_scaledAlbumBase(QPixmap()), m_noAlbumArt(knMusicGlobal->noAlbumArt()), m_scaledNoAlbumArt(QPixmap()), m_nullIndex(QModelIndex()), m_selectedIndex(m_nullIndex), m_mouseDownIndex(m_nullIndex), m_scrollAnime(new QTimeLine(200, this)), m_proxyModel(nullptr), m_model(nullptr), m_albumDetail(nullptr), m_itemWidth(135), m_itemMinimalSpacing(30), m_minimalWidth(m_itemMinimalSpacing+m_itemWidth), m_lineCount(0), m_textSpacing(5), m_itemHeight(154), m_spacing(30), m_itemSpacingHeight(m_spacing+m_itemHeight), m_itemSpacingWidth(m_spacing+m_itemWidth), m_maxColumnCount(0) { setObjectName("MusicAlbumView"); //Set properties. setFocusPolicy(Qt::WheelFocus); //Set default scrollbar properties. verticalScrollBar()->setRange(0, 0); //Set the palette. knTheme->registerWidget(this); //Configure the timeline. m_scrollAnime->setUpdateInterval(10); m_scrollAnime->setEasingCurve(QEasingCurve::OutCubic); connect(m_scrollAnime, &QTimeLine::frameChanged, verticalScrollBar(), &QScrollBar::setValue); //Link the scrolling event. connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &KNMusicAlbumView::onActionScrolling); //The icon size should be the item width. //Update the painting parameters. updateUIElements(); //Generate the album art shadow pixmap. int shadowSize=m_itemWidth+(m_shadowIncrease<<1); //Update album art shadow. m_albumArtShadow=generateShadow(shadowSize, shadowSize); //Update the album base. m_scaledAlbumBase=m_albumBase.scaled(m_itemWidth, m_itemWidth, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); //Update the no album art. m_scaledNoAlbumArt=m_noAlbumArt.scaled(m_itemWidth, m_itemWidth, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); //The height of the item should be a item icon size and two text lines. m_itemHeight=m_itemWidth+(fontMetrics().height()<<1); //Link the search. connect(knMusicGlobal->search(), &KNMusicSearchBase::requireSearch, this, &KNMusicAlbumView::onActionSearch); //Set the search shortcut. QAction *searchAction=new QAction(this); searchAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_F)); searchAction->setShortcutContext(Qt::WidgetWithChildrenShortcut); connect(searchAction, &QAction::triggered, [=] { //Check whether the search plugin is loaded. if(knMusicGlobal->search()) { knMusicGlobal->search()->onActionSearchShortcut(this); } }); addAction(searchAction); //Link the locale manager. knI18n->link(this, &KNMusicAlbumView::retranslate); retranslate(); }