24#include <tqcheckbox.h>
25#include <tqradiobutton.h>
28#include <tqpushbutton.h>
31#include <tqapplication.h>
33#include <tqgroupbox.h>
38#include <kiconloader.h>
39#include <kpushbutton.h>
41#include <kis_cursor.h>
42#include <kis_colorspace.h>
43#include <kis_colorspace_factory_registry.h>
44#include <kis_config.h>
45#include <kis_filter_strategy.h>
46#include <kis_global.h>
49#include <kis_paint_layer.h>
50#include <kis_group_layer.h>
51#include <kis_meta_registry.h>
52#include <kis_painter.h>
53#include <kis_profile.h>
55#include <kis_undo_adapter.h>
56#include <kis_label_progress.h>
57#include <kis_selection.h>
58#include <kis_transform_worker.h>
60#include "kis_previewwidgetbase.h"
61#include "kis_previewwidget.h"
62#include "imageviewer.h"
64static const int ZOOM_PAUSE = 100;
65static const int FILTER_PAUSE = 500;
66static const double ZOOM_FACTOR = 1.1;
69 : PreviewWidgetBase( parent, name )
71 , m_previewIsDisplayed(true)
73 , m_dirtyOriginal(true)
76 , m_dirtyPreview(true)
83 , m_zoomTimer(new TQTimer(this))
84 , m_filterTimer(new TQTimer(this))
88 btnZoomIn->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet(
"zoom-in", TDEIcon::MainToolbar, 16 ));
89 connect(btnZoomIn, TQ_SIGNAL(clicked()),
this, TQ_SLOT(zoomIn()));
90 btnZoomOut->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet(
"zoom-out", TDEIcon::MainToolbar, 16 ));
91 connect(btnZoomOut, TQ_SIGNAL(clicked()),
this, TQ_SLOT(zoomOut()));
92 btnUpdate->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet(
"reload", TDEIcon::MainToolbar, 16 ));
93 connect(btnUpdate, TQ_SIGNAL(clicked()),
this, TQ_SLOT(forceUpdate()));
95 connect(radioBtnPreview, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(
setPreviewDisplayed(
bool)));
97 connect(checkBoxAutoUpdate, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(
slotSetAutoUpdate(
bool)));
98 btnZoomOneToOne->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet(
"zoom-original", TDEIcon::MainToolbar, 16 ));
99 connect(btnZoomOneToOne, TQ_SIGNAL(clicked()),
this, TQ_SLOT(zoomOneToOne()));
101 m_progress =
new KisLabelProgress(frmProgress);
102 m_progress->setMaximumHeight(fontMetrics().height() );
103 TQVBoxLayout *vbox =
new TQVBoxLayout( frmProgress );
104 vbox->addWidget(m_progress);
107 connect(m_zoomTimer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(updateZoom()));
108 connect(m_filterTimer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(runFilterHelper()));
124KisPreviewWidget::~KisPreviewWidget() { }
126void KisPreviewWidget::forceUpdate()
128 if(m_previewIsDisplayed)
130 m_groupBox->setTitle(m_origDevice->name());
142 m_previewDevice = dev;
146 TQString monitorProfileName = cfg.monitorProfile();
147 m_profile = KisMetaRegistry::instance()->csRegistry()->
getProfileByName(monitorProfileName);
149 TQRect r = dev->exactBounds();
151 m_groupBox->setTitle(i18n(
"Preview: ") + dev->name());
152 m_previewIsDisplayed =
true;
155 zoomChanged(
double(m_preview->width()) /
double(r.width()) );
158void KisPreviewWidget::updateZoom()
160 TQApplication::setOverrideCursor(KisCursor::waitCursor());
162 if(m_previewIsDisplayed)
166 TQSize r = m_previewDevice->extent().size();
167 int w = r.width(), h = r.height();
168 int sw = int(ceil(m_zoom * w / m_filterZoom));
169 int sh = int(ceil(m_zoom * h / m_filterZoom));
170 m_dirtyPreview =
false;
171 m_scaledPreview = m_previewDevice->convertToTQImage(m_profile, 0, 0, w, h);
172 m_scaledPreview = m_scaledPreview.scale(sw,sh, TQImage::ScaleMax);
174 m_preview->setImage(m_scaledPreview);
179 TQSize r = m_origDevice->extent().size();
180 int w = r.width(), h = r.height();
181 int sw = int(ceil(m_zoom * w));
182 int sh = int(ceil(m_zoom * h));
183 m_dirtyOriginal =
false;
184 m_scaledOriginal = m_origDevice->convertToTQImage(m_profile, 0, 0, w, h);
185 m_scaledOriginal = m_scaledOriginal.scale(sw,sh, TQImage::ScaleMax);
187 m_preview->setImage(m_scaledOriginal);
190 TQApplication::restoreOverrideCursor();
197void KisPreviewWidget::wheelEvent(TQWheelEvent * e)
199 if (e->delta() > 0) {
209 if(v != m_previewIsDisplayed)
211 m_previewIsDisplayed = v;
212 if(m_previewIsDisplayed) {
213 m_groupBox->setTitle(i18n(
"Preview: ") + m_origDevice->name());
215 m_groupBox->setTitle(i18n(
"Original: ") + m_origDevice->name());
224 if(m_previewIsDisplayed)
225 m_groupBox->setTitle(i18n(
"Preview (needs update)"));
232void KisPreviewWidget::zoomChanged(
const double zoom)
236 if(zoom <= 1./8.) { tZoom = 1./8.; }
237 if(zoom > 8.) { tZoom = 8.; }
242 m_dirtyOriginal =
true;
243 m_dirtyPreview =
true;
249 m_zoomTimer->start(ZOOM_PAUSE,
true);
254void KisPreviewWidget::zoomIn() {
255 zoomChanged(m_zoom * ZOOM_FACTOR);
258void KisPreviewWidget::zoomOut() {
259 zoomChanged(m_zoom / ZOOM_FACTOR);
262void KisPreviewWidget::zoomOneToOne() {
266static inline void cropDevice(
KisPaintDevice * device,
const double & zoom) {
268 r.setX(
int(zoom * r.x()) );
269 r.setY(
int(zoom * r.y()) );
270 r.setWidth(
int(zoom * r.width()) );
271 r.setHeight(
int(zoom * r.height()) );
275class MyCropVisitor :
public KisLayerVisitor {
279 MyCropVisitor(
const double & z) : m_zoom(z) { }
280 virtual ~MyCropVisitor() { }
283 KisPaintDeviceSP device = layer->paintDevice();
284 ::cropDevice(device.data(), m_zoom);
286 if(device->hasSelection()) {
287 ::cropDevice(device->selection().data(), m_zoom);
293 for(KisLayerSP l = layer->
firstChild(); l; l = l->nextSibling()) {
310 m_firstFilter =
false;
313 m_filterTimer->start(FILTER_PAUSE,
true);
321void KisPreviewWidget::runFilterHelper() {
323 m_filterZoom = m_zoom;
325 if(m_filterZoom > 1.0) {
329 KisPaintDeviceSP scaledDevice;
330 KisHermiteFilterStrategy strategy;
333 if (m_origDevice->image())
335 m_scaledImage =
new KisImage(*m_origDevice->image());
336 if(!m_origDevice->parentLayer())
return;
337 TQString layerName = m_origDevice->parentLayer()->name();
338 KisPaintLayerSP pl = ::tqt_cast<KisPaintLayer*>(m_scaledImage->findLayer(layerName));
340 scaledDevice = pl->paintDevice();
342 KisSelectionSP select;
343 if(scaledDevice->hasSelection())
346 scaledDevice->deselect();
349 m_scaledImage->setUndoAdapter(NULL);
350 m_scaledImage->scale(m_filterZoom, m_filterZoom, NULL, &strategy);
354 KisPaintDeviceSP t = select.data();
355 KisTransformWorker tw(t, m_filterZoom, m_filterZoom,
356 0.0, 0.0, 0.0, 0, 0, NULL, &strategy);
358 scaledDevice->setSelection(select);
359 select->setParentLayer(scaledDevice->parentLayer());
363 MyCropVisitor v(m_filterZoom);
364 m_scaledImage->rootLayer()->accept(v);
368 KisSelectionSP select;
369 if(scaledDevice->hasSelection())
372 scaledDevice->deselect();
374 KisTransformWorker tw(scaledDevice, m_filterZoom, m_filterZoom,
375 0.0, 0.0, 0.0, 0, 0, NULL, &strategy);
380 KisPaintDeviceSP t = select.data();
381 KisTransformWorker tw(t, m_filterZoom, m_filterZoom,
382 0.0, 0.0, 0.0, 0, 0, NULL, &strategy);
384 scaledDevice->setSelection(select);
385 ::cropDevice(select.data(), m_filterZoom);
387 ::cropDevice(scaledDevice.data(), m_filterZoom);
393 m_filter->enableProgress();
394 m_progress->setSubject(m_filter,
true,
true);
395 m_filter->setProgressDisplay(m_progress);
396 m_filter->process(scaledDevice, m_previewDevice, m_config, scaledDevice->exactBounds());
397 m_filter->disableProgress();
399 m_dirtyPreview =
true;
405 m_zoomTimer->start(ZOOM_PAUSE,
true);
409#include "kis_previewwidget.moc"
Class that contains a KisFilter and optionally a KisSelection.
KisProfile * getProfileByName(const TQString &name)
Return the profile associated with the given product name, or 0.
A KisFilterConfiguration is the serializable representation of the filter parameters.
Basic interface of a Chalk filter.
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
A paint device contains the actual pixel data and offers methods to read and write pixels.
void crop(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
Cut the paint device down to the specified rect.
virtual void exactBounds(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
Get the exact bounds of this paint device.
This layer is of a type that can be painted on.
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.
KisSelection contains a byte-map representation of a layer, where the value of a byte signifies wheth...