Skip to content

Commit

Permalink
Merge pull request FreeCAD#16265 from kadet1090/sketcher-taskpanel-fixes
Browse files Browse the repository at this point in the history
 Gui: Fix issues with icons in sketcher elements panel
  • Loading branch information
chennes authored Sep 4, 2024
2 parents d6347a4 + b46ba09 commit 01d9e0c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherConstraints.ui
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="modelColumn">
<number>0</number>
</property>
Expand Down
31 changes: 27 additions & 4 deletions src/Mod/Sketcher/Gui/TaskSketcherElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ class ElementItem: public QListWidgetItem
// limitation of not knowing about padding, border and margin boxes of stylesheets
// thus being unable to provide proper sizeHint for stylesheets to render correctly
if (role == Qt::DecorationRole) {
int size = listWidget()->style()->pixelMetric(QStyle::PM_ListViewIconSize);
auto size = listWidget()->iconSize();

return QIcon(QPixmap(QSize(size, size)));
return QIcon(QPixmap(size));
}

return QListWidgetItem::data(role);
Expand All @@ -246,6 +246,22 @@ class ElementItem: public QListWidgetItem
}
}

bool isGeometryPreselected(Sketcher::PointPos pos) const
{
switch (pos) {
case Sketcher::PointPos::none:
return hovered == SubElementType::edge;
case Sketcher::PointPos::start:
return hovered == SubElementType::start;
case Sketcher::PointPos::end:
return hovered == SubElementType::end;
case Sketcher::PointPos::mid:
return hovered == SubElementType::mid;
default:
return false;
}
}

Sketcher::SketchObject* getSketchObject() const
{
return sketchView->getSketchObject();
Expand Down Expand Up @@ -943,9 +959,16 @@ void ElementItemDelegate::drawSubControl(SubControl element,

auto drawSelectIcon = [&](Sketcher::PointPos pos) {
auto icon = ElementWidgetIcons::getIcon(item->GeometryType, pos, item->State);
auto opacity = 0.4f;

if (isHovered) {
auto isOptionSelected = option.state & QStyle::State_Selected;
auto isOptionHovered = option.state & QStyle::State_MouseOver;

// items that user is not interacting with should be fully opaque
// only if item is partially selected (so only one part of geometry)
// the rest should be dimmed out
auto opacity = isOptionHovered || isOptionSelected ? 0.4 : 1.0;

if (item->isGeometryPreselected(pos)) {
opacity = 0.8f;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherElements.ui
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="modelColumn">
<number>0</number>
</property>
Expand Down

0 comments on commit 01d9e0c

Please sign in to comment.