Skip to content

Commit

Permalink
[render] possibility to add custom icon in DrawableObjectFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Feb 28, 2025
1 parent 85a566e commit 8d16838
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
2 changes: 2 additions & 0 deletions vclib/render/include/vclib/qt/gui/drawable_object_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class DrawableObjectFrame : public QFrame
QWidget* parent = nullptr);
~DrawableObjectFrame();

void setIcon(const QIcon& icon, const QString& tooltip = "");

signals:
void visibilityChanged();

Expand Down
10 changes: 10 additions & 0 deletions vclib/render/include/vclib/qt/gui/drawable_object_vector_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,29 @@ class DrawableObjectVectorFrame;

class DrawableObjectVectorFrame : public QFrame
{
public:
using IconFunction =
std::function<std::pair<QIcon, std::string>(const DrawableObject&)>;

private:
Q_OBJECT

// this frame does not normally own this drawList
std::shared_ptr<DrawableObjectVector> mDrawList;
Ui::DrawableObjectVectorFrame* mUI;

// icon function
IconFunction mIconFunction = nullptr;

public:
explicit DrawableObjectVectorFrame(QWidget* parent = nullptr);
explicit DrawableObjectVectorFrame(
const std::shared_ptr<DrawableObjectVector>& v,
QWidget* parent = nullptr);
~DrawableObjectVectorFrame();

void setIconFunction(const IconFunction& f);

void setDrawableObjectVector(
const std::shared_ptr<vcl::DrawableObjectVector>& v);

Expand Down
6 changes: 6 additions & 0 deletions vclib/render/src/vclib/qt/gui/drawable_object_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ DrawableObjectFrame::~DrawableObjectFrame()
delete mUI;
}

void DrawableObjectFrame::setIcon(const QIcon& icon, const QString& tooltip)
{
mUI->iconLabel->setPixmap(icon.pixmap(16, 16));
mUI->iconLabel->setToolTip(tooltip);
}

void DrawableObjectFrame::visibilityCheckBoxStateChanged(Qt::CheckState arg1)
{
mObj->setVisibility(arg1 == Qt::CheckState::Checked);
Expand Down
57 changes: 32 additions & 25 deletions vclib/render/src/vclib/qt/gui/drawable_object_frame.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@
<string>Frame</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QCheckBox" name="visibilityCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="objNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>DrawableObjectName</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="showInfoToolButton">
<property name="toolTip">
Expand All @@ -58,26 +38,39 @@
<bool>true</bool>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
<enum>QToolButton::ToolButtonPopupMode::DelayedPopup</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonIconOnly</enum>
<enum>Qt::ToolButtonStyle::ToolButtonIconOnly</enum>
</property>
<property name="autoRaise">
<bool>false</bool>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
<enum>Qt::ArrowType::RightArrow</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="objNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>DrawableObjectName</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QFrame" name="infoFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::Shadow::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
Expand All @@ -102,6 +95,20 @@
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="visibilityCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="iconLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
12 changes: 12 additions & 0 deletions vclib/render/src/vclib/qt/gui/drawable_object_vector_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ DrawableObjectVectorFrame::~DrawableObjectVectorFrame()
delete mUI;
}

void DrawableObjectVectorFrame::setIconFunction(const IconFunction& f)
{
mIconFunction = f;
updateDrawableVectorWidget();
}

void DrawableObjectVectorFrame::setDrawableObjectVector(
const std::shared_ptr<DrawableObjectVector>& v)
{
Expand Down Expand Up @@ -99,6 +105,12 @@ void DrawableObjectVectorFrame::updateDrawableVectorWidget()
DrawableObjectFrame* frame =
new DrawableObjectFrame(d, mUI->listWidget);

if (mIconFunction) {
std::pair<QIcon, std::string> p = mIconFunction(*d);

frame->setIcon(p.first, QString::fromStdString(p.second));
}

mUI->listWidget->addItem(item);
mUI->listWidget->setItemWidget(item, frame);
item->setSizeHint(frame->sizeHint());
Expand Down

0 comments on commit 8d16838

Please sign in to comment.