Git commit c2706b36038383da9415bb366207d20acada094d by Sven Langkamp. Committed on 31/01/2016 at 11:40. Pushed by langkamp into branch 'master'. Better pop-up palette thumbnails Maniphest Tasks: T1428 M +62 -78 libs/ui/kis_popup_palette.cpp http://commits.kde.org/krita/c2706b36038383da9415bb366207d20acada094d diff --git a/libs/ui/kis_popup_palette.cpp b/libs/ui/kis_popup_palette.cpp index 651fd35..1d27b58e0 100644 --- a/libs/ui/kis_popup_palette.cpp +++ b/libs/ui/kis_popup_palette.cpp @@ -38,11 +38,11 @@ #include "kis_signal_compressor.h" #include = -#define brushInnerRadius 94.0 -#define brushOuterRadius 145.0 + #define colorInnerRadius 72.0 #define colorOuterRadius 92.0 -#define brushRadius (brushInnerRadius+brushOuterRadius)/2 +#define maxbrushRadius 42.0 +#define widgetSize (colorOuterRadius*2+maxbrushRadius*4) = class PopupColorTriangle : public KoTriangleColorSelector { @@ -95,12 +95,14 @@ KisPopupPalette::KisPopupPalette(KisFavoriteResourceMan= ager* manager, const KoCo , m_displayRenderer(displayRenderer) , m_colorChangeCompressor(new KisSignalCompressor(50, KisSignalCompres= sor::POSTPONE)) { + = + const int borderWidth =3D 3; m_triangleColorSelector =3D new PopupColorTriangle(displayRenderer, t= his); - m_triangleColorSelector->move(77, 77); - m_triangleColorSelector->resize(136, 136); + m_triangleColorSelector->move(widgetSize/2-colorInnerRadius+borderWidt= h, widgetSize/2-colorInnerRadius+borderWidth); + m_triangleColorSelector->resize(colorInnerRadius*2-borderWidth*2, colo= rInnerRadius*2-borderWidth*2); m_triangleColorSelector->setVisible(true); = - QRegion maskedRegion(0, 0, 136, 136, QRegion::Ellipse ); + QRegion maskedRegion(0, 0, m_triangleColorSelector->width(), m_triangl= eColorSelector->height(), QRegion::Ellipse ); m_triangleColorSelector->setMask(maskedRegion); = setAttribute(Qt::WA_ContentsPropagated, true); @@ -241,7 +243,7 @@ void KisPopupPalette::setVisible(bool b) = QSize KisPopupPalette::sizeHint() const { - return QSize(290, 290); + return QSize(widgetSize, widgetSize); } = void KisPopupPalette::resizeEvent(QResizeEvent*) @@ -274,12 +276,8 @@ void KisPopupPalette::paintEvent(QPaintEvent* e) // create an ellipse for the background that is slightly // smaller than the clipping mask. This will prevent aliasing QPainterPath backgroundContainer; - - qreal backgroundWidth =3D (qreal)(e->rect().width() ); - qreal backgroundHeight =3D (qreal)(e->rect().height() ); - - backgroundContainer.addEllipse( (-backgroundWidth/2 +1), (-backgroundH= eight/2 +1), - backgroundWidth - 3 , background= Height - 3 ); + backgroundContainer.addEllipse( -colorOuterRadius, -colorOuterRadius, + colorOuterRadius*2, colorOuterRadius*2= ); painter.fillPath(backgroundContainer,palette().brush(QPalette::Window)= ); painter.drawPath(backgroundContainer); = @@ -300,6 +298,8 @@ void KisPopupPalette::paintEvent(QPaintEvent* e) = QRect bounds =3D path.boundingRect().toAlignedRect(); painter.drawImage(bounds.topLeft() , images.at(pos).scaled(bounds.= size() , Qt::KeepAspectRatioByExpanding)); + painter.drawPath(path); + = painter.restore(); } if (hoveredPreset() > -1) { @@ -409,22 +409,21 @@ void KisPopupPalette::mouseMoveEvent(QMouseEvent* eve= nt) QPointF point =3D event->posF(); event->accept(); = - QPainterPath pathBrush(drawDonutPathFull(width() / 2, height() / 2, br= ushInnerRadius, brushOuterRadius)); QPainterPath pathColor(drawDonutPathFull(width() / 2, height() / 2, co= lorInnerRadius, colorOuterRadius)); = setToolTip(""); setHoveredPreset(-1); setHoveredColor(-1); = - if (pathBrush.contains(point)) { - //in favorite brushes area + { int pos =3D calculatePresetIndex(point, m_resourceManager->numFavo= ritePresets()); = if (pos >=3D 0 && pos < m_resourceManager->numFavoritePresets()) { setToolTip(m_resourceManager->favoritePresetList().at(pos).dat= a()->name()); setHoveredPreset(pos); } - } else if (pathColor.contains(point)) { + } + if (pathColor.contains(point)) { int pos =3D calculateIndex(point, m_resourceManager->recentColorsT= otal()); = if (pos >=3D 0 && pos < m_resourceManager->recentColorsTotal()) { @@ -440,38 +439,35 @@ void KisPopupPalette::mousePressEvent(QMouseEvent* ev= ent) event->accept(); = if (event->button() =3D=3D Qt::LeftButton) { - QPainterPath pathBrush(drawDonutPathFull(width() / 2, height() / 2= , brushInnerRadius, brushOuterRadius)); - - if (pathBrush.contains(point)) { - //in favorite brushes area - int pos =3D calculateIndex(point, m_resourceManager->numFavori= tePresets()); - if (pos >=3D 0 && pos < m_resourceManager->numFavoritePresets() - && isPointInPixmap(point, pos)) { - //setSelectedBrush(pos); - update(); - } - } else { - int side =3D qMin(width(), height()); - QPainterPath settingCircle; - settingCircle.addEllipse(width() / 2 + side / 2 - 40, height()= / 2 + side / 2 - 40, 40, 40); - if (settingCircle.contains(point)) { = - KisPaintOpPresetResourceServer* rServer =3D KisResourceSer= verProvider::instance()->paintOpPresetServer(); - QStringList tags =3D rServer->tagNamesList(); - qSort(tags); - - if (!tags.isEmpty()) { - QMenu menu; - Q_FOREACH (const QString& tag, tags) { - menu.addAction(tag); - } - QAction* action =3D menu.exec(event->globalPos()); - if (action) { - m_resourceManager->setCurrentTag(action->text()); - } - } else { - QWhatsThis::showText(event->globalPos(), = - i18n("There are no tags available= to show in this popup. To add presets, you need to tag them and then selec= t the tag here.")); + + //in favorite brushes area + int pos =3D calculateIndex(point, m_resourceManager->numFavoritePr= esets()); + if (pos >=3D 0 && pos < m_resourceManager->numFavoritePresets() + && isPointInPixmap(point, pos)) { + //setSelectedBrush(pos); + update(); + } + + int side =3D qMin(width(), height()); + QPainterPath settingCircle; + settingCircle.addEllipse(width() / 2 + side / 2 - 40, height() / 2= + side / 2 - 40, 40, 40); + if (settingCircle.contains(point)) { = + KisPaintOpPresetResourceServer* rServer =3D KisResourceServerP= rovider::instance()->paintOpPresetServer(); + QStringList tags =3D rServer->tagNamesList(); + qSort(tags); + + if (!tags.isEmpty()) { + QMenu menu; + Q_FOREACH (const QString& tag, tags) { + menu.addAction(tag); + } + QAction* action =3D menu.exec(event->globalPos()); + if (action) { + m_resourceManager->setCurrentTag(action->text()); } + } else { + QWhatsThis::showText(event->globalPos(), = + i18n("There are no tags available = to show in this popup. To add presets, you need to tag them and then select= the tag here.")); } } } @@ -489,16 +485,14 @@ void KisPopupPalette::mouseReleaseEvent(QMouseEvent *= event) event->accept(); = if (event->button() =3D=3D Qt::LeftButton || event->button() =3D=3D Qt= ::RightButton) { - QPainterPath pathBrush(drawDonutPathFull(width() / 2, height() / 2= , brushInnerRadius, brushOuterRadius)); QPainterPath pathColor(drawDonutPathFull(width() / 2, height() / 2= , colorInnerRadius, colorOuterRadius)); = - if (pathBrush.contains(point)) { - //in favorite brushes area - if (hoveredPreset() > -1) { - //setSelectedBrush(hoveredBrush()); - emit sigChangeActivePaintop(hoveredPreset()); - } - } else if (pathColor.contains(point)) { + //in favorite brushes area + if (hoveredPreset() > -1) { + //setSelectedBrush(hoveredBrush()); + emit sigChangeActivePaintop(hoveredPreset()); + } + if (pathColor.contains(point)) { int pos =3D calculateIndex(point, m_resourceManager->recentCol= orsTotal()); = if (pos >=3D 0 && pos < m_resourceManager->recentColorsTotal()= ) { @@ -542,38 +536,28 @@ KisPopupPalette::~KisPopupPalette() = QPainterPath KisPopupPalette::pathFromPresetIndex(int index) { - QRect outerRect(-width() / 2, -height() / 2, width(), height()); - outerRect.adjust(3, 3, -3, -3); - int ringSize =3D brushOuterRadius - colorOuterRadius - 6; - QRect innerRect =3D outerRect.adjusted(ringSize, ringSize, -ringSize, = -ringSize); - - qreal angleLength =3D 360.0 / numSlots(); + qreal angleLength =3D 360.0 / numSlots() / 180 * M_PI; qreal angle =3D index * angleLength; = + qreal r =3D colorOuterRadius * sin(angleLength/2) / ( 1 - sin(angleLen= gth/2)); + = QPainterPath path; - path.moveTo(brushOuterRadius * cos(angle / 180 * M_PI), -brushOuterRad= ius * sin(angle / 180 * M_PI)); - path.arcTo(outerRect, angle, angleLength); - path.arcTo(innerRect, angle + angleLength, -angleLength); + path.addEllipse((colorOuterRadius+r) * cos(angle)-r, -(colorOuterRadiu= s+r) * sin(angle)-r, 2*r, 2*r); path.closeSubpath(); return path; } = int KisPopupPalette::calculatePresetIndex(QPointF point, int /*n*/) { - int x =3D point.x() - width() / 2; - int y =3D point.y() - height() / 2; - - qreal radius =3D sqrt((qreal) x * x + y * y); - - qreal angle; - // y coordinate is the reverse of the cartesian one - if (y < 0) { - angle =3D acos(x / radius); - } else { - angle =3D 2 * M_PI - acos(x / radius); + for(int i =3D 0; i < numSlots(); i++) + { + QPointF adujustedPoint =3D point - QPointF(width()/2, height()/2); + if(pathFromPresetIndex(i).contains(adujustedPoint)) + { + return i; + } } - int pos =3D floor(angle / (2 * M_PI / numSlots())); - return pos; + return -1; } = int KisPopupPalette::numSlots()