1 /*
2 * Copyright (c) 2011 Sven Langkamp <sven.langkamp@gmail.com>
3 *
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 * the Free Software Foundation; version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "channeldocker_dock.h"
20
21 #include <QGridLayout>
22 #include <QTableView>
23 #include <QHeaderView>
24 #include <klocalizedstring.h>
25
26 #include <KoCanvasBase.h>
27 #include "channelmodel.h"
28 #include <KisViewManager.h>
29 #include <kis_canvas2.h>
30 #include <kis_layer.h>
31 #include <kis_node_manager.h>
32 #include <kis_image.h>
33 #include <kis_group_layer.h>
34 #include <kis_paint_device.h>
35 #include "kis_signal_compressor.h"
36 #include <KisView.h>
37 #include <kis_idle_watcher.h>
38
ChannelDockerDock()39 ChannelDockerDock::ChannelDockerDock( ) :
40 QDockWidget(i18n("Channels")),
41 m_imageIdleWatcher(new KisIdleWatcher(250, this)),
42 m_canvas(0)
43 {
44 m_channelTable = new QTableView(this);
45 m_model = new ChannelModel(this);
46 m_channelTable->setModel(m_model);
47 m_channelTable->setShowGrid(false);
48 m_channelTable->horizontalHeader()->setStretchLastSection(true);
49 m_channelTable->verticalHeader()->setVisible(false);
50 m_channelTable->horizontalHeader()->setVisible(false);
51 m_channelTable->setSelectionBehavior( QAbstractItemView::SelectRows );
52
53 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(m_channelTable);
54 if (scroller){
55 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
56 this, SLOT(slotScrollerStateChanged(QScroller::State)));
57 }
58
59 setWidget(m_channelTable);
60
61 connect(m_channelTable,&QTableView::activated, m_model, &ChannelModel::rowActivated);
62 }
63
setCanvas(KoCanvasBase * canvas)64 void ChannelDockerDock::setCanvas(KoCanvasBase * canvas)
65 {
66 if(m_canvas == canvas)
67 return;
68
69 setEnabled(canvas != 0);
70
71 if (m_canvas) {
72 m_canvas->disconnectCanvasObserver(this);
73 m_canvas->image()->disconnect(this);
74 }
75
76 if (!canvas) {
77 m_canvas = 0;
78 return;
79 }
80
81 m_canvas = dynamic_cast<KisCanvas2*>(canvas);
82 if ( m_canvas && m_canvas->image() ) {
83 m_model->slotSetCanvas(m_canvas);
84
85 KisPaintDeviceSP dev = m_canvas->image()->projection();
86
87 m_imageIdleWatcher->setTrackedImage(m_canvas->image());
88 connect(m_imageIdleWatcher, &KisIdleWatcher::startedIdleMode, this, &ChannelDockerDock::updateChannelTable);
89
90 connect(m_canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(startUpdateCanvasProjection()), Qt::UniqueConnection);
91
92 connect(dev, SIGNAL(colorSpaceChanged(const KoColorSpace*)), m_model, SLOT(slotColorSpaceChanged(const KoColorSpace*)));
93 connect(dev, SIGNAL(colorSpaceChanged(const KoColorSpace*)), m_canvas, SLOT(channelSelectionChanged()));
94 connect(m_model, SIGNAL(channelFlagsChanged()), m_canvas, SLOT(channelSelectionChanged()));
95 m_imageIdleWatcher->startCountdown();
96 }
97
98 }
99
unsetCanvas()100 void ChannelDockerDock::unsetCanvas()
101 {
102 setEnabled(false);
103 m_canvas = 0;
104 m_model->unsetCanvas();
105 }
106
showEvent(QShowEvent * event)107 void ChannelDockerDock::showEvent(QShowEvent *event)
108 {
109 Q_UNUSED(event);
110 m_imageIdleWatcher->startCountdown();
111 }
112
startUpdateCanvasProjection()113 void ChannelDockerDock::startUpdateCanvasProjection()
114 {
115 m_imageIdleWatcher->startCountdown();
116 }
117
updateChannelTable()118 void ChannelDockerDock::updateChannelTable()
119 {
120 if (isVisible() && m_canvas && m_canvas->image()){
121 m_model->updateData(m_canvas);
122 m_channelTable->resizeRowsToContents();
123 m_channelTable->resizeColumnsToContents();
124 }
125 }
126
127
128
129
130