Commit 72f2ec41 authored by Sven Langkamp's avatar Sven Langkamp

replace custom gradient button with add and edit functionality

parent 3be5d402
......@@ -34,13 +34,12 @@
/****************************** KisAutogradient ******************************/
KisAutogradient::KisAutogradient(QWidget *parent, const char* name, const QString& caption) : QWidget(parent)
KisAutogradient::KisAutogradient(KisAutogradientResource* gradient, QWidget *parent, const char* name, const QString& caption)
: QWidget(parent), m_autogradientResource(gradient)
{
setObjectName(name);
setupUi(this);
setWindowTitle(caption);
m_autogradientResource = new KisAutogradientResource();
m_autogradientResource->createSegment(INTERP_LINEAR, COLOR_INTERP_RGB, 0.0, 1.0, 0.5, Qt::black, Qt::white);
gradientSlider->setGradientResource(m_autogradientResource);
connect(gradientSlider, SIGNAL(sigSelectedSegment(KoGradientSegment*)), SLOT(slotSelectedSegment(KoGradientSegment*)));
......
......@@ -31,7 +31,7 @@ class KisAutogradient : public QWidget, public Ui::KisWdgAutogradient
Q_OBJECT
public:
KisAutogradient(QWidget *parent, const char* name, const QString& caption);
KisAutogradient(KisAutogradientResource* gradient, QWidget *parent, const char* name, const QString& caption);
void activate();
signals:
void activatedResource(KoResource *r);
......
......@@ -28,16 +28,19 @@
#include <kfiledialog.h>
#include <KoAbstractGradient.h>
#include <KoResource.h>
#include <KoSegmentGradient.h>
#include <KoResourceItemChooser.h>
#include <KoResourceServerProvider.h>
#include <KoResourceServerAdapter.h>
#include <KoIcon.h>
#include "kis_view2.h"
#include "kis_global.h"
#include "kis_autogradient.h"
#include "kis_canvas_resource_provider.h"
#include <kis_autogradient_resource.h>
KisCustomGradientDialog::KisCustomGradientDialog(KisView2 * view, QWidget * parent, const char *name)
KisCustomGradientDialog::KisCustomGradientDialog(KisAutogradientResource* gradient, QWidget * parent, const char *name)
: KDialog(parent)
{
setCaption(i18n("Custom Gradient"));
......@@ -45,9 +48,8 @@ KisCustomGradientDialog::KisCustomGradientDialog(KisView2 * view, QWidget * pare
setDefaultButton(Close);
setObjectName(name);
setModal(false);
m_page = new KisAutogradient(this, "autogradient", i18n("Custom Gradient"));
m_page = new KisAutogradient(gradient, this, "autogradient", i18n("Custom Gradient"));
setMainWidget(m_page);
connect(m_page, SIGNAL(activatedResource(KoResource *)), view->resourceProvider(), SLOT(slotGradientActivated(KoResource*)));
}
KisGradientChooser::KisGradientChooser(KisView2 * view, QWidget *parent, const char *name)
......@@ -72,17 +74,23 @@ KisGradientChooser::KisGradientChooser(KisView2 * view, QWidget *parent, const c
connect(m_itemChooser, SIGNAL(resourceSelected(KoResource *)),
this, SIGNAL(resourceSelected(KoResource *)));
m_customGradient = new QPushButton(i18n("Custom Gradient..."));
m_customGradient->setObjectName("custom gradient button");
KisCustomGradientDialog * autogradient = new KisCustomGradientDialog(view, 0, "autogradient");
connect(m_customGradient, SIGNAL(clicked()), autogradient, SLOT(show()));
QWidget* buttonWidget = new QWidget(this);
QHBoxLayout* buttonLayout = new QHBoxLayout(buttonWidget);
QPushButton* addGradient = new QPushButton(koIcon("list-add"), i18n("Add..."), this);
connect(addGradient, SIGNAL(clicked()), this, SLOT(addGradient()));
buttonLayout->addWidget(addGradient);
QPushButton* editGradient = new QPushButton(koIcon("configure"), i18n("Edit..."));
connect(editGradient, SIGNAL(clicked()), this, SLOT(editGradient()));
buttonLayout->addWidget(editGradient);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName("main layout");
mainLayout->setMargin(2);
mainLayout->addWidget(m_lbName);
mainLayout->addWidget(m_itemChooser, 10);
mainLayout->addWidget(m_customGradient, 10);
mainLayout->addWidget(buttonWidget);
setLayout(mainLayout);
}
......@@ -109,5 +117,34 @@ void KisGradientChooser::update(KoResource * resource)
m_lbName->setText(i18n(gradient->name().toUtf8().data()));
}
void KisGradientChooser::addGradient()
{
KoResourceServer<KoAbstractGradient> * rserver = KoResourceServerProvider::instance()->gradientServer();
QString saveLocation = rserver->saveLocation();
KisAutogradientResource* gradient = new KisAutogradientResource();
gradient->createSegment(INTERP_LINEAR, COLOR_INTERP_RGB, 0.0, 1.0, 0.5, Qt::black, Qt::white);
gradient->setName(i18n("unnamed"));
KisCustomGradientDialog dialog(gradient, this, "autogradient");
dialog.exec();
gradient->setFilename(saveLocation + gradient->name() + gradient->defaultFileExtension());
gradient->setValid(true);
rserver->addResource(gradient);
m_itemChooser->setCurrentResource(gradient);
}
void KisGradientChooser::editGradient()
{
KisAutogradientResource* gradient = dynamic_cast<KisAutogradientResource*>(currentResource());
if (gradient) {
KisCustomGradientDialog dialog(gradient, this, "autogradient");
dialog.exec();
}
}
#include "kis_gradient_chooser.moc"
......@@ -22,6 +22,8 @@
#include <QFrame>
class KisAutogradientResource;
class KisView2;
class QLabel;
class QPushButton;
class KisView2;
......@@ -36,7 +38,7 @@ class KisCustomGradientDialog : public KDialog
public:
KisCustomGradientDialog(KisView2 * view, QWidget * parent, const char *name);
KisCustomGradientDialog(KisAutogradientResource* gradient, QWidget * parent, const char *name);
private:
......@@ -66,11 +68,12 @@ signals:
private slots:
virtual void update(KoResource * resource);
void addGradient();
void editGradient();
private:
QLabel *m_lbName;
KoResourceItemChooser * m_itemChooser;
QPushButton * m_customGradient;
};
#endif // KIS_GRADIENT_CHOOSER_H_
......
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