Commit 1e7ba3d1 authored by Mathias Wein's avatar Mathias Wein

Make preset history sorting configurable

- Add a most recently used sorting variant
- Load/save the setting from "presethistorySorting" in kritarc
parent 77afe223
......@@ -43,9 +43,6 @@
PresetHistoryDock::PresetHistoryDock( )
: QDockWidget(i18n("Brush Preset History"))
, m_canvas(0)
, m_block(false)
, m_initialized(false)
{
m_presetHistory = new QListWidget(this);
m_presetHistory->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
......@@ -86,6 +83,8 @@ void PresetHistoryDock::setCanvas(KoCanvasBase * canvas)
KisPaintOpPresetSP preset = rserver->resourceByName(p);
addPreset(preset);
}
int ordering = qBound(int(Static), cfg.readEntry("presethistorySorting", 0), int(Bubbling));
m_sorting = static_cast<DisplayOrder>(ordering);
m_initialized = true;
}
}
......@@ -103,21 +102,19 @@ void PresetHistoryDock::unsetCanvas()
}
KisConfig cfg(false);
cfg.writeEntry("presethistory", presetHistory.join(","));
cfg.writeEntry("presethistorySorting", int(m_sorting));
}
void PresetHistoryDock::presetSelected(QListWidgetItem *item)
{
if (item) {
int oldPosition = m_presetHistory->currentRow();
int newPosition = bubblePreset(oldPosition);
sortPresets(oldPosition);
QVariant v = item->data(Qt::UserRole);
KisPaintOpPresetSP preset = v.value<KisPaintOpPresetSP>();
m_block = true;
m_canvas->viewManager()->paintOpBox()->resourceSelected(preset.data());
m_block = false;
if (oldPosition != newPosition) {
m_presetHistory->setCurrentRow(newPosition);
}
}
}
......@@ -130,8 +127,7 @@ void PresetHistoryDock::canvasResourceChanged(int key, const QVariant& v)
if (preset) {
for (int i = 0; i < m_presetHistory->count(); ++i) {
if (preset->name() == m_presetHistory->item(i)->text()) {
int newPosition = bubblePreset(i);
m_presetHistory->setCurrentRow(newPosition);
sortPresets(i);
return;
}
}
......@@ -140,6 +136,21 @@ void PresetHistoryDock::canvasResourceChanged(int key, const QVariant& v)
}
}
void PresetHistoryDock::sortPresets(int position)
{
switch (m_sorting) {
case Static:
break;
case MostRecent:
m_presetHistory->insertItem(0, m_presetHistory->takeItem(position));
m_presetHistory->setCurrentRow(0);
break;
case Bubbling:
position = bubblePreset(position);
m_presetHistory->setCurrentRow(position);
};
}
int PresetHistoryDock::bubblePreset(int position)
{
QListWidgetItem *item = m_presetHistory->item(position);
......
......@@ -35,6 +35,11 @@ class PresetHistoryDock : public QDockWidget, public KoCanvasObserverBase {
Q_OBJECT
public:
PresetHistoryDock();
enum DisplayOrder {
Static = 0,
MostRecent = 1,
Bubbling = 2
};
QString observerName() override { return "PresetHistoryDock"; }
void setCanvas(KoCanvasBase *canvas) override;
void unsetCanvas() override;
......@@ -44,13 +49,15 @@ private Q_SLOTS:
void presetSelected(QListWidgetItem* item);
void canvasResourceChanged(int key, const QVariant& v);
private:
void sortPresets(int position);
int bubblePreset(int position);
void addPreset(KisPaintOpPresetSP preset);
private:
QPointer<KisCanvas2> m_canvas;
QListWidget *m_presetHistory;
bool m_block;
bool m_initialized;
DisplayOrder m_sorting {Static};
bool m_block {false};
bool m_initialized {false};
};
......
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