Skip to content

Commit

Permalink
fix: Lock icon now updates in the context menu and the dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jim555-lab committed Apr 9, 2024
1 parent 8ef9b54 commit 34cbd4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/libs/tools/image_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ImageDialog::ImageDialog(DraftImage image)
this, &ImageDialog::rotationChanged);
connect(ui->aspectLocked_ToolButton, &QToolButton::clicked, this, &ImageDialog::lockAspectChanged);
connect(ui->units_ToolButton, &QToolButton::clicked, this, &ImageDialog::unitsChanged);
connect(ui->lockImage_CheckBox, &QCheckBox::toggled, this, &ImageDialog::lockChanged);
connect(ui->lockImage_ToolButton, &QCheckBox::toggled, this, &ImageDialog::lockChanged);
connect(ui->visibility_CheckBox, &QCheckBox::toggled, this, &ImageDialog::visibilityChanged);
connect(ui->opacity_DoubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &ImageDialog::opacityChanged);
Expand Down Expand Up @@ -146,7 +146,7 @@ void ImageDialog::updateImage()
blockSignals(true);
ui->idText_Label->setNum(static_cast<double>(m_image.id));
ui->name_LineEdit->setText(m_image.name);
ui->lockImage_CheckBox->setChecked(m_image.locked);
ui->lockImage_ToolButton->setChecked(m_image.locked);
setXPos(m_image.xPos);
setYPos(m_image.yPos);
setWidth(m_image.width);
Expand Down Expand Up @@ -185,7 +185,7 @@ void ImageDialog::updateImage()
void ImageDialog::enableWidgets()
{
ui->name_LineEdit->setEnabled(!m_image.locked);
ui->lockImage_CheckBox->setEnabled(true);
ui->lockImage_ToolButton->setEnabled(true);
ui->xPosition_DoubleSpinBox->setEnabled(!m_image.locked);
ui->yPosition_DoubleSpinBox->setEnabled(!m_image.locked);
ui->width_DoubleSpinBox->setEnabled(!m_image.locked);
Expand Down Expand Up @@ -364,10 +364,10 @@ bool ImageDialog::isLocked() const
//---------------------------------------------------------------------------------------------------------------------
void ImageDialog::setLocked(const bool &checked)
{
ui->lockImage_CheckBox->blockSignals(true);
ui->lockImage_ToolButton->blockSignals(true);
m_image.locked = checked;
ui->lockImage_CheckBox->setChecked(checked);
ui->lockImage_CheckBox->blockSignals(false);
ui->lockImage_ToolButton->setChecked(checked);
ui->lockImage_ToolButton->blockSignals(false);
}

//---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -588,7 +588,7 @@ void ImageDialog::lockChanged(bool checked)
{
blockSignals(true);
m_image.locked = checked;
ui->lockImage_CheckBox->setChecked(m_image.locked);
ui->lockImage_ToolButton->setChecked(m_image.locked);
enableWidgets();
blockSignals(false);
emit lockClicked(m_image.locked);
Expand Down
26 changes: 18 additions & 8 deletions src/libs/tools/image_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<x>12</x>
<y>25</y>
<width>187</width>
<height>49</height>
<height>55</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -912,21 +912,31 @@ border: none
</widget>
</item>
<item>
<widget class="QCheckBox" name="lockImage_CheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QToolButton" name="lockImage_ToolButton">
<property name="font">
<font>
<bold>false</bold>
</font>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="styleSheet">
<string notr="true">QToolButton:checked {
background-color: #f0f0f0;
}</string>
</property>
<property name="text">
<string/>
<string notr="true">...</string>
</property>
<property name="icon">
<iconset resource="../vmisc/share/resources/icon.qrc">
<normaloff>:/icon/32x32/lock_off.png</normaloff>
<normalon>:/icon/32x32/lock_on.png</normalon>:/icon/32x32/lock_off.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand Down
8 changes: 7 additions & 1 deletion src/libs/tools/image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ void ImageItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QMenu menu;
QAction *actionProperties = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Properties"));

QAction *actionLock = menu.addAction(QIcon("://icon/32x32/lock_on.png"), tr("Lock"));
QAction *actionLock = menu.addAction(tr("Lock"));
if (m_image.locked){
actionLock->setIcon(QIcon("://icon/32x32/lock_on.png"));
}
else{
actionLock->setIcon(QIcon("://icon/32x32/lock_off.png"));
}
actionLock->setCheckable(true);
actionLock->setChecked(m_image.locked);

Expand Down

0 comments on commit 34cbd4f

Please sign in to comment.