Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Make the options widget for Knife Tool more clear

Agata Cackob7f1433d810a
diff --git a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp
index 34436f5f4d..56753b8b0f 100644
--- a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp
+++ b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp
@@ -19,6 +19,9 @@
#include <KoGroupButton.h>
#include <KoUnit.h>
+#include <kis_node.h>
+#include <kis_shape_layer.h>
+
Q_DECLARE_METATYPE(KisToolKnifeOptionsWidget::GapWidthType)
@@ -268,7 +271,7 @@ struct KisToolKnifeOptionsWidget::Private {
};
-KisToolKnifeOptionsWidget::KisToolKnifeOptionsWidget(KisCanvasResourceProvider */*provider*/, QWidget *parent, QString toolId, qreal resolution)
+KisToolKnifeOptionsWidget::KisToolKnifeOptionsWidget(KisCanvasResourceProvider *provider, QWidget *parent, QString toolId, qreal resolution)
: QWidget(parent),
m_d(new Private)
{
@@ -320,6 +323,16 @@ KisToolKnifeOptionsWidget::KisToolKnifeOptionsWidget(KisCanvasResourceProvider *
m_d->readFromConfig(toolId);
connect(m_d->ui->unitsCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(unitForWidthChanged(int)));
+ connect(provider, SIGNAL(sigNodeChanged(const KisNodeSP)), this, SLOT(currentNodeChanged(const KisNodeSP)));
+ connect(m_d->buttonModeAddGutter, SIGNAL(clicked()), this, SLOT(modeChanged()));
+ connect(m_d->buttonModeRemoveGutter, SIGNAL(clicked()), this, SLOT(modeChanged()));
+
+ connect(m_d->ui->automaticGapWidthRadioButton, SIGNAL(toggled(bool)), this, SLOT(currentWidthSystemChanged()));
+
+ modeChanged();
+ currentNodeChanged(provider->currentNode());
+ currentWidthSystemChanged();
+
}
@@ -347,3 +360,64 @@ void KisToolKnifeOptionsWidget::unitForWidthChanged(int index)
m_d->setUnit(selected);
}
+void KisToolKnifeOptionsWidget::currentNodeChanged(const KisNodeSP node)
+{
+ ENTER_FUNCTION();
+ const KisShapeLayer *shapeLayer = qobject_cast<const KisShapeLayer*>(node.data());
+ if (!shapeLayer) {
+ m_d->ui->gapOptionsWidget->setVisible(false);
+ m_d->ui->warningLabel->setVisible(true);
+
+ } else {
+ m_d->ui->gapOptionsWidget->setVisible(true);
+ m_d->ui->warningLabel->setVisible(false);
+ }
+}
+
+void KisToolKnifeOptionsWidget::modeChanged()
+{
+ KisToolKnifeOptionsWidget::ToolMode mode = getToolMode();
+ switch(mode) {
+ case AddGutter:
+ m_d->ui->gapOptionsWidget->setEnabled(true);
+ break;
+ case RemoveGutter:
+ m_d->ui->gapOptionsWidget->setEnabled(false);
+ break;
+
+ }
+}
+
+void KisToolKnifeOptionsWidget::currentWidthSystemChanged()
+{
+
+ ENTER_FUNCTION();
+
+ GapWidthType gapConfig = m_d->getCurrentWidthType();
+ switch(gapConfig) {
+ case Thin:
+ case Thick:
+ case Special:
+ m_d->ui->automaticDiagonalCombobox->setEnabled(false);
+ m_d->ui->automaticVerticalCombobox->setEnabled(false);
+ m_d->ui->automaticHorizontalCombobox->setEnabled(false);
+ m_d->ui->gutterWidthAngleSpinBox->setEnabled(false);
+ m_d->ui->angleLabel->setEnabled(false);
+ m_d->ui->horizontalLabel->setEnabled(false);
+ m_d->ui->verticalLabel->setEnabled(false);
+ m_d->ui->diagonalLabel->setEnabled(false);
+
+ break;
+ case Automatic:
+ m_d->ui->automaticDiagonalCombobox->setEnabled(true);
+ m_d->ui->automaticVerticalCombobox->setEnabled(true);
+ m_d->ui->automaticHorizontalCombobox->setEnabled(true);
+ m_d->ui->gutterWidthAngleSpinBox->setEnabled(true);
+ m_d->ui->horizontalLabel->setEnabled(true);
+ m_d->ui->verticalLabel->setEnabled(true);
+ m_d->ui->diagonalLabel->setEnabled(true);
+ m_d->ui->angleLabel->setEnabled(true);
+ break;
+ }
+}
+
diff --git a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.h b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.h
index ebc3f33fe7..a003d54945 100644
--- a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.h
+++ b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.h
@@ -13,6 +13,7 @@
#include "kis_types.h"
#include "GutterWidthsConfig.h"
+#include <kis_node.h>
class KisCanvasResourceProvider;
class KoColor;
@@ -45,6 +46,9 @@ public:
public Q_SLOTS:
void unitForWidthChanged(int index);
+ void currentNodeChanged(const KisNodeSP node);
+ void modeChanged();
+ void currentWidthSystemChanged();
private:
diff --git a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.ui b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.ui
index 74841ae630..f2f9d73dc7 100644
--- a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.ui
+++ b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.ui
@@ -19,194 +19,206 @@
<widget class="KisOptionButtonStrip" name="optionButtonStripToolMode" native="true"/>
</item>
<item>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>Unit of width:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QComboBox" name="unitsCombobox"/>
- </item>
- <item row="1" column="0">
- <widget class="QRadioButton" name="thickGapWidthRadioButton">
- <property name="text">
- <string>Thick gap:</string>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="KisDoubleSliderSpinBox" name="thickGapWidth">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="suffix">
- <string> px</string>
- </property>
- <property name="minimum">
- <double>0.000000000000000</double>
- </property>
- <property name="maximum">
- <double>500.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>5.000000000000000</double>
- </property>
- <property name="value">
- <double>40.000000000000000</double>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QRadioButton" name="thinGapWidthRadioButton">
- <property name="text">
- <string>Thin gap:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="KisDoubleSliderSpinBox" name="thinGapWidth">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="suffix">
- <string> px</string>
- </property>
- <property name="minimum">
- <double>0.000000000000000</double>
- </property>
- <property name="maximum">
- <double>500.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>5.000000000000000</double>
- </property>
- <property name="value">
- <double>15.000000000000000</double>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QRadioButton" name="specialGapWidthRadioButton">
- <property name="text">
- <string>Special gap:</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="KisDoubleSliderSpinBox" name="customGapWidth">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- <property name="suffix">
- <string> px</string>
- </property>
- <property name="minimum">
- <double>0.000000000000000</double>
- </property>
- <property name="maximum">
- <double>500.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>5.000000000000000</double>
- </property>
- <property name="value">
- <double>70.000000000000000</double>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QRadioButton" name="automaticGapWidthRadioButton">
- <property name="text">
- <string>Automatic</string>
- </property>
- </widget>
- </item>
- <item row="5" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Horizontal:</string>
- </property>
- </widget>
- </item>
- <item row="5" column="1">
- <widget class="QComboBox" name="automaticHorizontalCombobox">
- <property name="currentText">
- <string/>
- </property>
- </widget>
- </item>
- <item row="6" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Vertical:</string>
- </property>
- </widget>
- </item>
- <item row="6" column="1">
- <widget class="QComboBox" name="automaticVerticalCombobox">
- <property name="currentText">
- <string/>
- </property>
- </widget>
- </item>
- <item row="7" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Diagonal:</string>
- </property>
- </widget>
- </item>
- <item row="7" column="1">
- <widget class="QComboBox" name="automaticDiagonalCombobox"/>
- </item>
- <item row="8" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Angle:</string>
- </property>
- </widget>
- </item>
- <item row="8" column="1">
- <widget class="KisDoubleSliderSpinBox" name="gutterWidthAngleSpinBox">
- <property name="prefix">
- <string/>
- </property>
- <property name="suffix">
- <string>°</string>
- </property>
- <property name="maximum">
- <double>45.000000000000000</double>
- </property>
- <property name="value">
- <double>2.000000000000000</double>
- </property>
- </widget>
- </item>
- </layout>
+ <widget class="QLabel" name="warningLabel">
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This tool only works on a vector layer.&lt;br/&gt;Create the first panel using any shape tool on a vector layer.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="gapOptionsWidget" native="true">
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Unit of width:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="unitsCombobox"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QRadioButton" name="thickGapWidthRadioButton">
+ <property name="text">
+ <string>Thick gap:</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="KisDoubleSliderSpinBox" name="thickGapWidth">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> px</string>
+ </property>
+ <property name="minimum">
+ <double>0.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>500.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>5.000000000000000</double>
+ </property>
+ <property name="value">
+ <double>40.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QRadioButton" name="thinGapWidthRadioButton">
+ <property name="text">
+ <string>Thin gap:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="KisDoubleSliderSpinBox" name="thinGapWidth">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> px</string>
+ </property>
+ <property name="minimum">
+ <double>0.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>500.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>5.000000000000000</double>
+ </property>
+ <property name="value">
+ <double>15.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QRadioButton" name="specialGapWidthRadioButton">
+ <property name="text">
+ <string>Special gap:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="KisDoubleSliderSpinBox" name="customGapWidth">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> px</string>
+ </property>
+ <property name="minimum">
+ <double>0.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>500.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>5.000000000000000</double>
+ </property>
+ <property name="value">
+ <double>70.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QRadioButton" name="automaticGapWidthRadioButton">
+ <property name="text">
+ <string>Automatic</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="horizontalLabel">
+ <property name="text">
+ <string>Horizontal:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QComboBox" name="automaticHorizontalCombobox">
+ <property name="currentText">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="verticalLabel">
+ <property name="text">
+ <string>Vertical:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QComboBox" name="automaticVerticalCombobox">
+ <property name="currentText">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0">
+ <widget class="QLabel" name="diagonalLabel">
+ <property name="text">
+ <string>Diagonal:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1">
+ <widget class="QComboBox" name="automaticDiagonalCombobox"/>
+ </item>
+ <item row="8" column="0">
+ <widget class="QLabel" name="angleLabel">
+ <property name="text">
+ <string>Angle:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="KisDoubleSliderSpinBox" name="gutterWidthAngleSpinBox">
+ <property name="prefix">
+ <string/>
+ </property>
+ <property name="suffix">
+ <string>°</string>
+ </property>
+ <property name="maximum">
+ <double>45.000000000000000</double>
+ </property>
+ <property name="value">
+ <double>2.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
</item>
<item>
<spacer name="verticalSpacer">