Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 65df2a9a authored by Agata Cacko's avatar Agata Cacko Committed by Dmitry Kazakov

Make the color labels combobox nicer in Tool Options

Before this commit, color labels combobox would look exactly like
in the filter label for layers, but stretched horizontally.
It means the view-filter icon when no filtering is used,
and a small circle with colors when there are colors selected.
This commit changes the icon to "tag", which seems more appropriate,
and the visuals of the combobox to be in simple rectangles instead of
a circle, so it fills the combobox better.
parent 53b48009
......@@ -182,12 +182,29 @@ public:
struct KisColorFilterCombo::Private
{
LabelFilteringModel *filteringModel;
/**
* if the combobox is in the filter mode
* (when no colors are selected)
* it will show the filter icon ("view-filter")
* otherwise it will show tag icon ("tag")
*/
bool filterMode {true};
/**
* If the combobox is in the circle mode,
* it will show the selected colors as circle
* otherwise it will show it in a rectangle
*/
bool circleMode {true};
};
KisColorFilterCombo::KisColorFilterCombo(QWidget *parent)
KisColorFilterCombo::KisColorFilterCombo(QWidget *parent, bool filterMode, bool circleMode)
: QComboBox(parent),
m_d(new Private)
{
m_d->filterMode = filterMode;
m_d->circleMode = circleMode;
QStandardItemModel *newModel = new QStandardItemModel(this);
setModel(newModel);
......@@ -269,6 +286,12 @@ void KisColorFilterCombo::updateAvailableLabels(const QSet<int> &labels)
m_d->filteringModel->setAcceptedLabels(labels);
}
void KisColorFilterCombo::setModes(bool filterMode, bool circleMode)
{
m_d->filterMode = filterMode;
m_d->circleMode = circleMode;
}
QList<int> KisColorFilterCombo::selectedColors() const
{
QList<int> colors;
......@@ -305,7 +328,7 @@ void KisColorFilterCombo::paintEvent(QPaintEvent *event)
const QList<int> selectedColors = this->selectedColors();
if (selectedColors.size() == 0 || selectedColors.size() == model()->rowCount() - 1) {
QIcon icon = KisIconUtils::loadIcon("view-filter");
QIcon icon = KisIconUtils::loadIcon(m_d->filterMode ? "view-filter" : "tag");
QPixmap pixmap = icon.pixmap(QSize(size, size), !isEnabled() ? QIcon::Disabled : QIcon::Normal);
painter.drawPixmap(editRect.right() - size, editRect.top(), pixmap);
......@@ -328,26 +351,53 @@ void KisColorFilterCombo::paintEvent(QPaintEvent *event)
painter.drawLine(crossRect.bottomLeft(), crossRect.topRight());
}
} else {
const int border = 0;
QRect pieRect(0, 0, size - 2 * border, size - 2 * border);
pieRect.moveCenter(editRect.center());
const int numColors = selectedColors.size();
const int step = 16 * 360 / numColors;
if (m_d->circleMode) {
// show all colors in a circle
const int border = 0;
QRect pieRect(0, 0, size - 2 * border, size - 2 * border);
pieRect.moveCenter(editRect.center());
const int step = 16 * 360 / numColors;
int currentAngle = 0;
//painter.save(); // optimize out!
painter.setRenderHint(QPainter::Antialiasing);
for (int i = 0; i < numColors; i++) {
QColor color = scm.colorLabel(selectedColors[i]);
QBrush brush = color.alpha() > 0 ? QBrush(color) : QBrush(Qt::black, Qt::Dense4Pattern);
painter.setPen(color);
painter.setBrush(brush);
painter.drawPie(pieRect, currentAngle, step);
currentAngle += step;
}
} else {
// show all colors in a rectangle
int oneColorWidth = editRect.width()/numColors;
int currentWidth = 0;
for (int i = 0; i < numColors; i++) {
QColor color = scm.colorLabel(selectedColors[i]);
QBrush brush = color.alpha() > 0 ? QBrush(color) : QBrush(Qt::black, Qt::Dense4Pattern);
painter.setPen(color);
painter.setBrush(brush);
if (i == numColors - 1) {
// last color; let's fill up
painter.fillRect(currentWidth, editRect.top(), editRect.width() - currentWidth, editRect.height(), brush);
} else {
painter.fillRect(currentWidth, editRect.top(), oneColorWidth, editRect.height(), brush);
}
currentWidth += oneColorWidth;
}
int currentAngle = 0;
//painter.save(); // optimize out!
painter.setRenderHint(QPainter::Antialiasing);
for (int i = 0; i < numColors; i++) {
QColor color = scm.colorLabel(selectedColors[i]);
QBrush brush = color.alpha() > 0 ? QBrush(color) : QBrush(Qt::black, Qt::Dense4Pattern);
painter.setPen(color);
painter.setBrush(brush);
painter.drawPie(pieRect, currentAngle, step);
currentAngle += step;
}
//painter.restore(); // optimize out!
}
......
......@@ -30,11 +30,12 @@ class KRITAUI_EXPORT KisColorFilterCombo : public QComboBox
{
Q_OBJECT
public:
KisColorFilterCombo(QWidget *parent);
KisColorFilterCombo(QWidget *parent, bool filterMode = true, bool circleMode = true);
~KisColorFilterCombo() override;
void updateAvailableLabels(KisNodeSP rootNode);
void updateAvailableLabels(const QSet<int> &labels);
void setModes(bool filterMode, bool circleMode);
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
......
......@@ -85,6 +85,7 @@ KisSelectionOptions::KisSelectionOptions(KisCanvas2 * /*canvas*/)
m_page->cmbSampleLayersMode->addItem(sampleLayerModeToUserString(SAMPLE_LAYERS_MODE_COLOR_LABELED), SAMPLE_LAYERS_MODE_COLOR_LABELED);
m_page->cmbSampleLayersMode->setEditable(false);
m_page->cmbColorLabels->setModes(false, false);
connect(m_mode, SIGNAL(buttonClicked(int)), this, SIGNAL(modeChanged(int)));
connect(m_action, SIGNAL(buttonClicked(int)), this, SIGNAL(actionChanged(int)));
......
......@@ -268,7 +268,7 @@ QWidget* KisToolFill::createOptionWidget()
QLabel *lbl_cmbLabel = new QLabel(i18nc("This is a string in tool options for Fill Tool to describe a combobox about "
"a choice of color labels that a layer can be marked with. Those color labels "
"will be used for calculating the area to fill.", "Labels used:"), widget);
m_cmbSelectedLabels = new KisColorFilterCombo(widget);
m_cmbSelectedLabels = new KisColorFilterCombo(widget, false, false);
m_cmbSelectedLabels->updateAvailableLabels(currentImage().isNull() ? KisNodeSP() : currentImage()->root());
QLabel *lbl_fillSelection = new QLabel(i18n("Fill entire selection:"), widget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment