Commit 8b8655ef authored by Boudewijn Rempt's avatar Boudewijn Rempt

Make it possible to move through favourite presets with the keyboard

Default shortcuts: left and right.

(Because the number shortcuts are taken by the blender-type canvas
manipulation, zoom, rotate etc.)

CCBUG:311352
parent c41f123b
......@@ -206,6 +206,16 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
action->setDefaultWidget(m_sliderChooser[1]);
connect(action, SIGNAL(triggered()), m_sliderChooser[1], SLOT(showPopupWidget()));
action = new KAction(i18n("Next Favourite Preset"), this);
view->actionCollection()->addAction("next_favorite_preset", action);
action->setShortcut(KShortcut(Qt::Key_Right));
connect(action, SIGNAL(triggered()), this, SLOT(slotNextFavoritePreset()));
action = new KAction(i18n("Previous Favourite Preset"), this);
view->actionCollection()->addAction("previous_favorite_preset", action);
action->setShortcut(KShortcut(Qt::Key_Left));
connect(action, SIGNAL(triggered()), this, SLOT(slotPreviousFavoritePreset()));
QWidget* mirrorActions = new QWidget(this);
QHBoxLayout* mirrorLayout = new QHBoxLayout(mirrorActions);
mirrorLayout->addWidget(hMirrorButton);
......@@ -729,3 +739,46 @@ void KisPaintopBox::slotOpacityChanged(qreal opacity)
}
m_blockUpdate = false;
}
void KisPaintopBox::slotPreviousFavoritePreset()
{
if (!m_view->canvasBase()->favoriteResourceManager()) {
m_view->canvasBase()->createFavoriteResourceManager(this);
}
KoFavoriteResourceManager *mgr = m_view->canvasBase()->favoriteResourceManager();
int i = 0;
foreach (const QString &preset, mgr->favoritePresetList()) {
if (m_activePreset->name() == preset) {
if (i > 0) {
mgr->slotChangeActivePaintop(i - 1);
}
else {
mgr->slotChangeActivePaintop(mgr->numFavoritePresets() - 1);
}
return;
}
i++;
}
}
void KisPaintopBox::slotNextFavoritePreset()
{
if (!m_view->canvasBase()->favoriteResourceManager()) {
m_view->canvasBase()->createFavoriteResourceManager(this);
}
KoFavoriteResourceManager *mgr = m_view->canvasBase()->favoriteResourceManager();
int i = 0;
foreach (const QString &preset, mgr->favoritePresetList()) {
if (m_activePreset->name() == preset) {
if (i < mgr->numFavoritePresets() - 1) {
mgr->slotChangeActivePaintop(i + 1);
}
else {
mgr->slotChangeActivePaintop(0);
}
return;
}
i++;
}
}
......@@ -126,6 +126,8 @@ private slots:
void slotSlider2Changed();
void slotToolChanged(KoCanvasController* canvas, int toolId);
void slotOpacityChanged(qreal);
void slotPreviousFavoritePreset();
void slotNextFavoritePreset();
private:
KisCanvasResourceProvider* m_resourceProvider;
......
......@@ -370,7 +370,7 @@ void KisPopupPalette::mouseMoveEvent (QMouseEvent* event)
if (pathBrush.contains(point))
{ //in favorite brushes area
int pos = calculatePresetIndex(point, m_resourceManager->favoritePresetsTotal());
int pos = calculatePresetIndex(point, m_resourceManager->numFavoritePresets());
if (pos >= 0)
{
......@@ -400,8 +400,8 @@ void KisPopupPalette::mousePressEvent(QMouseEvent* event)
if (pathBrush.contains(point))
{ //in favorite brushes area
int pos = calculateIndex(point, m_resourceManager->favoritePresetsTotal());
if (pos >= 0 && pos < m_resourceManager->favoritePresetsTotal()
int pos = calculateIndex(point, m_resourceManager->numFavoritePresets());
if (pos >= 0 && pos < m_resourceManager->numFavoritePresets()
&& isPointInPixmap(point, pos))
{
//setSelectedBrush(pos);
......
......@@ -114,8 +114,7 @@ void KoFavoriteResourceManager::slotChangeActivePaintop(int pos)
KoResource* resource = rServer->getResourceByName(m_favoritePresetsList.at(pos));
m_paintopBox->resourceSelected(resource);
if (m_popupPalette)
{
if (m_popupPalette) {
m_popupPalette->showPopupPalette(false); //automatically close the palette after a button is clicked.
}
}
......@@ -193,7 +192,7 @@ bool KoFavoriteResourceManager::isFavoritePresetsFull()
return m_favoritePresetsList.size() == KoFavoriteResourceManager::MAX_FAVORITE_PRESETS;
}
int KoFavoriteResourceManager::favoritePresetsTotal()
int KoFavoriteResourceManager::numFavoritePresets()
{
return m_favoritePresetsList.size();
}
......
......@@ -66,7 +66,7 @@ public:
void removeFavoritePreset(const QString& name);
//returns -1 if paintop is not in the list, returns the paintop position otherwise
int isFavoriteBrushSaved(const QString& name);
int favoritePresetsTotal();
int numFavoritePresets();
QStringList favoritePresetList();
......
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