Commit 82f89857 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Fixed bug 90447

* Added method to the selection manager so plugins can define selection actions
that are enabled/disabled when there is a selection (or not).

svn path=/trunk/koffice/; revision=350190
parent bcab93ed
......@@ -24,7 +24,40 @@
#include "kis_pixel_representation.h"
/**
* XXX: document
There are two functions to create an iterator : iteratorPixelBegin and
iteratorPixelSelectionBegin, use the first if you don't care about
whether pixels are selected, the second if you need to take selections
into account.
KisIteratorLinePixel lineIt = device->iteratorPixelBegin( command, 0, width(), y);
KisIteratorPixel pixelIt = *linetIt;
KisIteratorPixel endIt = linetIt.end();
while( pixelIt <= endIt )
{
// your computing
++pixelIt;
}
If y goes from 0 to height(), you may do the following:
KisIteratorLinePixel lineIt = device->iteratorPixelBegin( command, 0, width(),
0);
KisIteratorLinePixel endLineIt = device->iteratorPixelEnd( command, 0,
width(), height);
while( lineIt <) endLineIt )
{
KisIteratorPixel pixelIt = *linetIt;
KisIteratorPixel endIt = linetIt.end();
while( pixelIt <= endIt )
{
// your computing
++pixelIt;
}
++lineIt;
}
*/
class KisIteratorPixel : public KisIteratorUnit
{
......
......@@ -65,10 +65,12 @@ KisSelectionManager::KisSelectionManager(KisView * parent, KisDoc * doc)
m_save(0)
{
m_pluginActions.setAutoDelete(true);
}
KisSelectionManager::~KisSelectionManager()
{
m_pluginActions.clear();
}
......@@ -211,6 +213,11 @@ void KisSelectionManager::setup(KActionCollection * collection)
}
void KisSelectionManager::addSelectionAction(KAction * action)
{
m_pluginActions.append(action);
}
void KisSelectionManager::clipboardDataChanged()
{
m_clipboardHasImage = !QApplication::clipboard() -> image().isNull();
......@@ -245,6 +252,10 @@ void KisSelectionManager::updateGUI()
m_save -> setEnabled(enable);
m_parent -> updateStatusBarSelectionLabel();
KAction a;
for (Q_UINT32 i = 0; i < m_pluginActions.count(); ++i) {
}
}
void KisSelectionManager::imgSelectionChanged(KisImageSP img)
......
......@@ -19,6 +19,7 @@
#define KIS_SELECTION_MANAGER_
#include "qobject.h"
#include "qptrlist.h"
#include "kis_image.h"
#include "kis_selection.h"
......@@ -43,6 +44,8 @@ public:
void setup(KActionCollection * collection);
void addSelectionAction(KAction * action);
public slots:
void clipboardDataChanged();
......@@ -98,6 +101,9 @@ private:
KAction *m_transform;
KAction *m_load;
KAction *m_save;
QPtrList<KAction> m_pluginActions;
};
#endif // KIS_SELECTION_MANAGER_
......@@ -2250,9 +2250,9 @@ void KisView::layerAdd()
if (img) {
KisConfig cfg;
NewLayerDialog dlg(cfg.maxLayerWidth(),
cfg.defLayerWidth(),
img -> width(),
cfg.maxLayerHeight(),
cfg.defLayerHeight(),
img -> height(),
img -> colorStrategy() -> name(),
img -> nextLayerName(),
this);
......
......@@ -143,6 +143,8 @@ public: // Plugin access API. XXX: This needs redesign.
KisDoc * getDocument() { return m_doc; }
KisSelectionManager * selectionManager() { return m_selectionManager; }
signals:
void bgColorChanged(const KoColor& c);
void fgColorChanged(const KoColor& c);
......
......@@ -28,7 +28,8 @@
<Action name="view_color_docker"/>
<Action name="view_control_docker"/>
<Action name="view_layer_docker"/>
<Action name="view_resource_docker"/>
<Action name="view_shapes_docker"/>
<Action name="view_fills_docker"/>
<Separator/>
<Action name="view_ruler"/>
<Separator/>
......
SUBDIRS = example colorsfilters variations colorrange imagesize screenshot histogram convolutionfilters rotateimage #performancetest
SUBDIRS = example colorsfilters variations colorrange imagesize screenshot histogram convolutionfilters rotateimage performancetest
......@@ -47,6 +47,7 @@
#include <kistilemgr.h>
#include <kis_iterators_quantum.h>
#include <kis_selection.h>
#include <kis_selection_manager.h>
#include "colorrange.h"
#include "dlg_colorrange.h"
......@@ -65,13 +66,14 @@ ColorRange::ColorRange(QObject *parent, const char *name, const QStringList &)
<< parent -> className()
<< "\n";
(void) new KAction(i18n("&Color Range..."), 0, 0, this, SLOT(slotActivated()), actionCollection(), "colorrange");
KAction * a = new KAction(i18n("&Color Range..."), 0, 0, this, SLOT(slotActivated()), actionCollection(), "colorrange");
if ( !parent->inherits("KisView") )
{
m_view = 0;
} else {
m_view = (KisView*) parent;
m_view -> selectionManager() -> addSelectionAction(a);
}
}
......
......@@ -65,6 +65,11 @@ DlgImageSize::~DlgImageSize()
delete m_page;
}
void DlgImageSize::hideScaleBox()
{
// m_page -> grpResizeScale -> hide();
}
void DlgImageSize::setWidth(Q_UINT32 w)
{
blockAll();
......
......@@ -41,6 +41,8 @@ public:
const char* name = 0);
~DlgImageSize();
void hideScaleBox();
void setWidth(Q_UINT32 w);
void setWidthPercent(Q_UINT32 w);
void setMaximumWidth(Q_UINT32 w);
......
......@@ -47,6 +47,7 @@
#include <kistilemgr.h>
#include <kis_iterators_quantum.h>
#include <kis_selection.h>
#include <kis_selection_manager.h>
#include <kis_scale_visitor.h>
#include "imagesize.h"
......@@ -69,12 +70,15 @@ ImageSize::ImageSize(QObject *parent, const char *name, const QStringList &)
(void) new KAction(i18n("&Image Size..."), 0, 0, this, SLOT(slotImageSize()), actionCollection(), "imagesize");
(void) new KAction(i18n("&Layer Size..."), 0, 0, this, SLOT(slotLayerSize()), actionCollection(), "layersize");
if ( !parent->inherits("KisView") )
{
m_view = 0;
} else {
m_view = (KisView*) parent;
// Selection manager takes ownership?
KAction * a = new KAction(i18n("&Layer Size..."), 0, 0, this, SLOT(slotLayerSize()), actionCollection(), "selectionScale");
m_view -> selectionManager() -> addSelectionAction(a);
}
}
......@@ -128,7 +132,7 @@ void ImageSize::slotLayerSize()
if (!image) return;
DlgImageSize * dlgImageSize = new DlgImageSize(m_view, "LayerSize");
dlgImageSize -> setCaption("Layer Size");
dlgImageSize -> setCaption(i18n("Layer Size"));
KisConfig cfg;
......@@ -154,4 +158,46 @@ void ImageSize::slotLayerSize()
delete dlgImageSize;
}
void ImageSize::slotSelectionScale()
{
// XXX: figure out a way to add selection actions to the selection
// manager to enable/disable
KisImageSP image = m_view -> currentImg();
if (!image) return;
KisLayerSP layer = image -> activeLayer();
if (!layer) return;
if (!layer -> hasSelection()) return;
DlgImageSize * dlgImageSize = new DlgImageSize(m_view, "SelectionScale");
dlgImageSize -> setCaption(i18n("Scale Selection"));
KisConfig cfg;
dlgImageSize -> setWidth(image -> width());
dlgImageSize -> setHeight(image -> height());
dlgImageSize -> setMaximumWidth(cfg.maxImgWidth());
dlgImageSize -> setMaximumHeight(cfg.maxImgHeight());
dlgImageSize -> hideScaleBox();
if (dlgImageSize -> exec() == QDialog::Accepted) {
Q_INT32 w = dlgImageSize -> width();
Q_INT32 h = dlgImageSize -> height();
Q_INT32 f = dlgImageSize -> filterType();
m_view -> scaleLayer((double)w / ((double)(image -> width())),
(double)h / ((double)(image -> height())),
(enumFilterType)f);
}
delete dlgImageSize;
}
#include "imagesize.moc"
......@@ -37,6 +37,7 @@ private slots:
void slotImageSize();
void slotLayerSize();
void slotSelectionScale();
private:
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui library="kritaimagesize" version="6">
<MenuBar>
......@@ -9,5 +10,9 @@
<Separator/>
<Action name="layersize"/>
</Menu>
<Menu name="Adjust"><text>&amp;Adjust</text>
<Separator/>
<Action name="selectionscale"/>
</Menu>
</MenuBar>
</kpartgui>
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>392</width>
<height>352</height>
<width>397</width>
<height>332</height>
</rect>
</property>
<property name="caption">
......@@ -178,7 +178,7 @@
</widget>
<widget class="QButtonGroup" row="0" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>buttonGroup3</cstring>
<cstring>grpResizeScale</cstring>
</property>
<property name="title">
<string></string>
......@@ -251,6 +251,14 @@
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" row="1" column="0">
<property name="name">
<cstring>radioResize</cstring>
</property>
<property name="text">
<string>&amp;Resize</string>
</property>
</widget>
<widget class="QRadioButton" row="1" column="2">
<property name="name">
<cstring>radioScale</cstring>
......@@ -262,14 +270,6 @@
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" row="1" column="0">
<property name="name">
<cstring>radioResize</cstring>
</property>
<property name="text">
<string>&amp;Resize</string>
</property>
</widget>
</grid>
</widget>
<widget class="QLabel" row="2" column="0">
......
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