presetdocker_dock.cpp 2.98 KB
Newer Older
1 2 3
/*
 *  Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
 *
4
 *  This library is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU Lesser General Public License as published by
6 7
 *  the Free Software Foundation; version 2 of the License, or
 *  (at your option) any later version.
8
 *
9
 *  This library is distributed in the hope that it will be useful,
10 11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU Lesser General Public License for more details.
13 14 15 16 17 18 19 20 21 22 23
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "presetdocker_dock.h"

#include <QHBoxLayout>
#include <QPushButton>

24
#include <klocalizedstring.h>
25

26
#include <KoCanvasResourceProvider.h>
27 28 29
#include <KoCanvasBase.h>

#include "kis_canvas2.h"
30
#include "KisViewManager.h"
31 32
#include "kis_paintop_box.h"
#include "kis_paintop_presets_chooser_popup.h"
33
#include "kis_canvas_resource_provider.h"
Boudewijn Rempt's avatar
Boudewijn Rempt committed
34
#include <brushengine/kis_paintop_preset.h>
35 36


37
PresetDockerDock::PresetDockerDock( )
38
    : QDockWidget(i18n("Brush Presets"))
39
    , m_canvas(0)
40 41 42
{
    m_presetChooser = new KisPaintOpPresetsChooserPopup(this);
    m_presetChooser->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
43
    m_presetChooser->showButtons(false);
44 45 46
    setWidget(m_presetChooser);
}

47
void PresetDockerDock::setCanvas(KoCanvasBase *canvas)
48
{
49 50
    setEnabled(canvas != 0);

51 52
    if (m_canvas) {
        m_canvas->disconnectCanvasObserver(this);
53
        m_presetChooser->disconnect(m_canvas->viewManager()->paintOpBox());
54
    }
55

56
    m_canvas = dynamic_cast<KisCanvas2*>(canvas);
57 58

    if (!m_canvas || !m_canvas->viewManager() || !m_canvas->resourceManager()) return;
59 60

    connect(m_presetChooser, SIGNAL(resourceSelected(KoResource*)),
61
            m_canvas->viewManager()->paintOpBox(), SLOT(resourceSelected(KoResource*)));
62 63
    connect(m_presetChooser, SIGNAL(resourceClicked(KoResource*)),
            m_canvas->viewManager()->paintOpBox(), SLOT(resourceSelected(KoResource*)));
64 65
    connect(canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)),
            this, SLOT(canvasResourceChanged(int,QVariant)));
66 67 68 69


    connect(m_canvas->viewManager()->mainWindow(), SIGNAL(themeChanged()), m_presetChooser, SLOT(slotThemeChanged()));

70
    canvasResourceChanged();
71 72 73 74
}

void PresetDockerDock::canvasResourceChanged(int /*key*/, const QVariant& /*v*/)
{
75
    if (m_canvas && m_canvas->resourceManager()) {
76
        if (sender()) sender()->blockSignals(true);
77 78
        KisPaintOpPresetSP preset = m_canvas->resourceManager()->resource(KisCanvasResourceProvider::CurrentPaintOpPreset).value<KisPaintOpPresetSP>();
        if(preset)
79
            m_presetChooser->canvasResourceChanged(preset);
80
        if (sender()) sender()->blockSignals(false);
81
        m_presetChooser->updateViewSettings();
82
    }
83 84
}

85 86