Commit cc337eec authored by Vera Lukman's avatar Vera Lukman

switching between favourite brushes on the palette now works

svn path=/trunk/koffice/; revision=1048301
parent 3fd6db55
......@@ -18,6 +18,7 @@
#include "kis_favorite_brush_data.h"
#include "kis_popup_palette.h"
#include "ko_favorite_resource_manager.h"
#include <kis_paintop_preset.h>
#include <kis_types.h>
#include <KoID.h>
......@@ -25,9 +26,10 @@
#include <QIcon>
#include <QToolButton>
KisFavoriteBrushData::KisFavoriteBrushData(KisPaintOpPresetSP newdata, QIcon* icon)
: m_button (0)
, m_data (newdata) // put this here instead of in the constructor is better style and more efficient.
KisFavoriteBrushData::KisFavoriteBrushData(KoFavoriteResourceManager* resourceManager, KisPaintOpPresetSP newdata, QIcon* icon)
: m_favoriteResourceManager (resourceManager)
, m_button (0)
, m_data (newdata)
{
// without a button, this class doesn't make sense, so always initialize it
m_button = new QToolButton();
......@@ -40,6 +42,7 @@ KisFavoriteBrushData::KisFavoriteBrushData(KisPaintOpPresetSP newdata, QIcon* i
void KisFavoriteBrushData::slotBrushButtonClicked()
{
qDebug() << "Brush name:" << m_data->paintOp();
m_favoriteResourceManager->changeCurrentPaintOp(m_data);
}
KisPaintOpPresetSP KisFavoriteBrushData::paintopPreset()
......@@ -59,6 +62,7 @@ QToolButton* KisFavoriteBrushData::paintopButton()
KisFavoriteBrushData::~KisFavoriteBrushData()
{
m_favoriteResourceManager = 0;
qDebug() << "Brush name:" << m_data->paintOp() << "deleting";
// don't delete m_data, it's a shared pointer
// only delete the button if it hasn't got a parent object, otherwise
......
......@@ -24,19 +24,21 @@
class QToolButton;
class QIcon;
class KoFavoriteResourceManager;
class KisFavoriteBrushData : public QObject
{
Q_OBJECT
public:
KisFavoriteBrushData(KisPaintOpPresetSP, QIcon * = 0);
KisFavoriteBrushData(KoFavoriteResourceManager*, KisPaintOpPresetSP, QIcon * = 0);
~KisFavoriteBrushData();
KisPaintOpPresetSP paintopPreset(); //CHANGE TO KisPresetPaintOpSP
void setIcon (QIcon*);
QToolButton* paintopButton();
private:
KoFavoriteResourceManager* m_favoriteResourceManager;
QToolButton* m_button;
KisPaintOpPresetSP m_data; //CHANGE TO KisPresetPaintOpSP
......
......@@ -128,11 +128,6 @@ KisPaintOpPresetSP KisPaintopBox::paintOpPresetSP(KoID* paintop)
return activePreset(*paintop, KoToolManager::instance()->currentInputDevice());
}
const KoID& KisPaintopBox::currentPaintopKoID()
{
return currentPaintop();
}
void KisPaintopBox::slotItemSelected(int index)
{
if (index < m_displayedOps.count()) {
......@@ -242,36 +237,45 @@ const KoID& KisPaintopBox::currentPaintop()
void KisPaintopBox::setCurrentPaintop(const KoID & paintop)
{
if (m_activePreset && m_optionWidget) {
m_optionWidget->writeConfiguration(const_cast<KisPaintOpSettings*>(m_activePreset->settings().data()));
m_optionWidget->disconnect(m_presetWidget);
m_optionWidget->disconnect(m_presetsPopup->presetPreview());
m_presetsPopup->setPaintOpSettingsWidget(0);
m_optionWidget->hide();
const_cast<KisPaintOpSettings*>(m_activePreset->settings().data())->setOptionsWidget(0);
m_optionWidget->writeConfiguration(const_cast<KisPaintOpSettings*>(m_activePreset->settings().data()));
m_optionWidget->disconnect(m_presetWidget);
m_optionWidget->disconnect(m_presetsPopup->presetPreview());
m_presetsPopup->setPaintOpSettingsWidget(0);
m_optionWidget->hide();
const_cast<KisPaintOpSettings*>(m_activePreset->settings().data())->setOptionsWidget(0);
}
m_currentID[KoToolManager::instance()->currentInputDevice()] = paintop;
KisPaintOpPresetSP preset =
activePreset(currentPaintop(), KoToolManager::instance()->currentInputDevice());
activePreset(currentPaintop(), KoToolManager::instance()->currentInputDevice());
setCurrentPaintop(preset);
}
void KisPaintopBox::setCurrentPaintop (KisPaintOpPresetSP preset)
{
KoID paintop = preset->paintOp();
if (preset != 0 && preset->settings()) {
if (!m_paintopOptionWidgets.contains(paintop)) {
m_paintopOptionWidgets[paintop] = KisPaintOpRegistry::instance()->get(paintop.id())->createSettingsWidget(this);
}
m_optionWidget = m_paintopOptionWidgets[paintop];
// XXX: Hack!
const_cast<KisPaintOpSettings*>(preset->settings().data())->setOptionsWidget(m_optionWidget);
m_optionWidget->setImage(m_view->image());
if (!m_paintopOptionWidgets.contains(paintop)) {
m_paintopOptionWidgets[paintop] = KisPaintOpRegistry::instance()->get(paintop.id())->createSettingsWidget(this);
}
m_optionWidget = m_paintopOptionWidgets[paintop];
// XXX: Hack!
const_cast<KisPaintOpSettings*>(preset->settings().data())->setOptionsWidget(m_optionWidget);
m_optionWidget->setImage(m_view->image());
if (!preset->settings()->getProperties().isEmpty()) {
m_optionWidget->setConfiguration(preset->settings());
}
m_presetsPopup->setPaintOpSettingsWidget(m_optionWidget);
Q_ASSERT(m_optionWidget);
Q_ASSERT(m_presetWidget);
connect(m_optionWidget, SIGNAL(sigConfigurationUpdated()), this, SLOT(slotUpdatePreset()));
if (!preset->settings()->getProperties().isEmpty()) {
m_optionWidget->setConfiguration(preset->settings());
}
m_presetsPopup->setPaintOpSettingsWidget(m_optionWidget);
Q_ASSERT(m_optionWidget);
Q_ASSERT(m_presetWidget);
connect(m_optionWidget, SIGNAL(sigConfigurationUpdated()), this, SLOT(slotUpdatePreset()));
} else {
m_presetsPopup->setPaintOpSettingsWidget(0);
m_presetsPopup->setPaintOpSettingsWidget(0);
}
preset->settings()->setNode(m_resourceProvider->currentNode());
......@@ -280,9 +284,9 @@ void KisPaintopBox::setCurrentPaintop(const KoID & paintop)
int index = m_displayedOps.indexOf(paintop);
if (index == -1) {
// Must change the paintop as the current one is not supported
// by the new colorspace.
index = 0;
// Must change the paintop as the current one is not supported
// by the new colorspace.
index = 0;
}
m_cmbPaintops->setCurrentIndex(index);
......@@ -292,7 +296,7 @@ void KisPaintopBox::setCurrentPaintop(const KoID & paintop)
//TODO: FIX THIS! use signal and slot instead!
if (m_view->favoriteResourceManager() != 0)
m_view->favoriteResourceManager()->changeCurrentBrush();
m_view->favoriteResourceManager()->changeCurrentBrushLabel();
}
KoID KisPaintopBox::defaultPaintop(const KoInputDevice & inputDevice)
......
......@@ -64,7 +64,9 @@ class KisPaintopBox : public QWidget
public:
KisPaintopBox(KisView2 * view, QWidget * parent, const char * name);
KisPaintOpPresetSP paintOpPresetSP(KoID * = 0);
const KoID& currentPaintopKoID();
const KoID & currentPaintop();
void setCurrentPaintop(const KoID & paintop);
void setCurrentPaintop(KisPaintOpPresetSP);
QPixmap paintopPixmap(const KoID & paintop);
~KisPaintopBox();
......@@ -79,8 +81,6 @@ public slots:
private:
const KoID & currentPaintop();
void setCurrentPaintop(const KoID & paintop);
KoID defaultPaintop(const KoInputDevice & inputDevice);
KisPaintOpPresetSP activePreset(const KoID & paintop, const KoInputDevice & inputDevice);
......
......@@ -114,7 +114,7 @@ KisPaletteManager::KisPaletteManager(KoFavoriteResourceManager *manager, KisPain
void KisPaletteManager::changeCurrentBrushLabel()
{
m_currentBrushLabel->setText(m_paintOpBox->currentPaintopKoID().id());
m_currentBrushLabel->setText(m_paintOpBox->currentPaintop().id());
//m_paintOpBox->currentPaintopKoID().name() doesnt work properly.
}
......@@ -146,7 +146,7 @@ void KisPaletteManager::slotAddBrush()
}
else
{
m_nameList.append(m_paintOpBox->currentPaintopKoID().id());
m_nameList.append(m_paintOpBox->currentPaintop().id());
m_model->setStringList(m_nameList);
index = m_model->index(m_resourceManager->favoriteBrushesTotal()-1);
}
......
......@@ -51,12 +51,12 @@ KoFavoriteResourceManager::KoFavoriteResourceManager(KisPaintopBox *paintopBox)
for (int pos = 0; pos < favoriteList.size(); pos++)
{
KisPaintOpPresetSP newBrush = m_paintopBox->paintOpPresetSP(new KoID(favoriteList[pos], favoriteList[pos]));
KisFavoriteBrushData* newBrushData = new KisFavoriteBrushData(newBrush, new QIcon (m_paintopBox->paintopPixmap(newBrush->paintOp())));
KisFavoriteBrushData* newBrushData = new KisFavoriteBrushData(this, newBrush, new QIcon (m_paintopBox->paintopPixmap(newBrush->paintOp())));
m_favoriteBrushesList.append(newBrushData);
}
}
void KoFavoriteResourceManager::changeCurrentBrush()
void KoFavoriteResourceManager::changeCurrentBrushLabel()
{
if (m_favoriteBrushManager!=0)
m_favoriteBrushManager->changeCurrentBrushLabel();
......@@ -98,7 +98,7 @@ int KoFavoriteResourceManager::addFavoriteBrush (KisPaintOpPresetSP newBrush)
return pos;
}
KisFavoriteBrushData* newBrushData = new KisFavoriteBrushData(newBrush, new QIcon (m_paintopBox->paintopPixmap(newBrush->paintOp())));
KisFavoriteBrushData* newBrushData = new KisFavoriteBrushData(this, newBrush, new QIcon (m_paintopBox->paintopPixmap(newBrush->paintOp())));
m_favoriteBrushesList.append(newBrushData);
if (m_popupPalette != 0)
......@@ -146,13 +146,13 @@ KisFavoriteBrushData* KoFavoriteResourceManager::favoriteBrush(int pos)
return m_favoriteBrushesList.at(pos);
}
QString KoFavoriteResourceManager::KoIDNameID(const KoID &newKoID)
void KoFavoriteResourceManager::changeCurrentPaintOp(KisPaintOpPresetSP brush)
{
QString str = newKoID.name();
return str.append(newKoID.id());
qDebug() << "[KoFavoriteResourceManager] Calling brush: " << brush->paintOp().id();
m_paintopBox->setCurrentPaintop(brush);
return;
}
//Recent Colors
int KoFavoriteResourceManager::isInRecentColor(QColor &newColor)
{
......
......@@ -46,11 +46,12 @@ public:
static const int MAX_FAVORITE_BRUSHES = 10;
static const int MAX_RECENT_COLORS = 10;
void changeCurrentBrush();
void changeCurrentBrushLabel();
/************************************Popup Palette************************************/
void showPopupPalette();
void showPaletteManager();
void changeCurrentPaintOp(KisPaintOpPresetSP);
/**********************************Favorite Brushes***********************************/
......@@ -62,7 +63,6 @@ public:
bool isFavoriteBrushesFull();
int favoriteBrushesTotal();
KisFavoriteBrushData* favoriteBrush(int);
QString KoIDNameID(const KoID &);
void saveFavoriteBrushes();
......@@ -74,6 +74,7 @@ public:
int isInRecentColor(QColor&);
void addRecentColor(KisRecentColorData*);
QQueue<KisRecentColorData*>* recentColorsList();
private:
KisPaletteManager *m_favoriteBrushManager;
......
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