channeldocker_dock.cpp 3.55 KB
Newer Older
Sven Langkamp's avatar
Sven Langkamp committed
1 2 3
/*
 *  Copyright (c) 2011 Sven Langkamp <sven.langkamp@gmail.com>
 *
4
 *  This library is free software; you can redistribute it and/or modify
Sven Langkamp's avatar
Sven Langkamp committed
5
 *  it under the terms of the GNU Lesser General Public License as published by
6
 *  the Free Software Foundation; version 2.1 of the License.
Sven Langkamp's avatar
Sven Langkamp committed
7
 *
8
 *  This library is distributed in the hope that it will be useful,
Sven Langkamp's avatar
Sven Langkamp committed
9 10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU Lesser General Public License for more details.
Sven Langkamp's avatar
Sven Langkamp committed
12 13 14 15 16 17 18 19 20
 *
 *  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 "channeldocker_dock.h"

#include <QGridLayout>
21 22
#include <QTableView>
#include <QHeaderView>
23
#include <klocalizedstring.h>
Sven Langkamp's avatar
Sven Langkamp committed
24 25 26

#include <KoCanvasBase.h>
#include "channelmodel.h"
27
#include <KisViewManager.h>
Sven Langkamp's avatar
Sven Langkamp committed
28 29
#include <kis_canvas2.h>
#include <kis_layer.h>
30
#include <kis_node_manager.h>
31 32 33
#include <kis_image.h>
#include <kis_group_layer.h>
#include <kis_layer.h>
34
#include <kis_paint_device.h>
35
#include "kis_signal_compressor.h"
36
#include <KisView.h>
37
#include <kis_idle_watcher.h>
Sven Langkamp's avatar
Sven Langkamp committed
38

39 40 41 42
ChannelDockerDock::ChannelDockerDock( ) :
    QDockWidget(i18n("Channels")),
    m_imageIdleWatcher(new KisIdleWatcher(250, this)),
    m_canvas(0)
Sven Langkamp's avatar
Sven Langkamp committed
43
{
44
    m_channelTable = new QTableView(this);
Sven Langkamp's avatar
Sven Langkamp committed
45
    m_model = new ChannelModel(this);
46 47
    m_channelTable->setModel(m_model);
    m_channelTable->setShowGrid(false);
48
    m_channelTable->horizontalHeader()->setStretchLastSection(true);
49
    m_channelTable->verticalHeader()->setVisible(false);
50 51 52
    m_channelTable->horizontalHeader()->setVisible(false);
    m_channelTable->setSelectionBehavior( QAbstractItemView::SelectRows );

53
    setWidget(m_channelTable);
54 55

    connect(m_channelTable,&QTableView::activated, m_model, &ChannelModel::rowActivated);
Sven Langkamp's avatar
Sven Langkamp committed
56 57 58 59
}

void ChannelDockerDock::setCanvas(KoCanvasBase * canvas)
{
60 61 62
    if(m_canvas == canvas)
        return;

63 64
    setEnabled(canvas != 0);

65 66 67 68 69
    if (m_canvas) {
        m_canvas->disconnectCanvasObserver(this);
        m_canvas->image()->disconnect(this);
    }

70 71 72
    if (!canvas) {
        m_canvas = 0;
        return;
73
    }
74

75
    m_canvas = dynamic_cast<KisCanvas2*>(canvas);
76 77 78 79 80 81 82 83
    if ( m_canvas && m_canvas->image() ) {
        m_model->slotSetCanvas(m_canvas);

        KisPaintDeviceSP dev = m_canvas->image()->projection();

        m_imageIdleWatcher->setTrackedImage(m_canvas->image());
        connect(m_imageIdleWatcher, &KisIdleWatcher::startedIdleMode, this, &ChannelDockerDock::updateChannelTable);

84
        connect(dev, SIGNAL(colorSpaceChanged(const KoColorSpace*)), m_model, SLOT(slotColorSpaceChanged(const KoColorSpace*)));
85
        connect(dev, SIGNAL(colorSpaceChanged(const KoColorSpace*)), m_canvas, SLOT(channelSelectionChanged()));
86 87
        connect(m_model, SIGNAL(channelFlagsChanged()), m_canvas, SLOT(channelSelectionChanged()));
        m_imageIdleWatcher->startCountdown();
88
    }
89

Sven Langkamp's avatar
Sven Langkamp committed
90 91
}

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
void ChannelDockerDock::unsetCanvas()
{
    setEnabled(false);
    m_canvas = 0;
    m_model->unsetCanvas();
}

void ChannelDockerDock::showEvent(QShowEvent *event)
{
    Q_UNUSED(event);
    m_imageIdleWatcher->startCountdown();
}

void ChannelDockerDock::startUpdateCanvasProjection()
{
    m_imageIdleWatcher->startCountdown();
}

void ChannelDockerDock::updateChannelTable()
{
    if (isVisible() && m_canvas && m_canvas->image()){
        m_model->updateData(m_canvas);
        m_channelTable->resizeRowsToContents();
        m_channelTable->resizeColumnsToContents();
    }
}


Sven Langkamp's avatar
Sven Langkamp committed
120

121