Commit 6bb2572e authored by Casper Boemann's avatar Casper Boemann

Add Image Resolution (aka physical size) to krita

The new image dialog now allows entering pysical size.
The zoom displays it correctly

For that the KoUnit have been changed into a prober class
which meant a lot of code changes all over KOffice


svn path=/trunk/koffice/; revision=610261
parent 716d0480
......@@ -77,7 +77,7 @@
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1025" isRoot="false" isAbstract="false" name="const KisProfileSP&amp;" elementReference="438" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1028" isRoot="false" isAbstract="false" name="KoCommandHistory*" elementReference="957" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1034" isRoot="false" isAbstract="false" name="const KUrl&amp;" elementReference="1032" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1040" isRoot="false" isAbstract="false" name="const KoUnit::Unit&amp;" elementReference="1038" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1040" isRoot="false" isAbstract="false" name="const KoUnit&amp;" elementReference="1038" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1052" isRoot="false" isAbstract="false" name="const vKisLayerSP&amp;" elementReference="395" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1056" isRoot="false" isAbstract="false" name="const KisLayerSP" elementReference="394" />
<UML:DataType stereotype="3" isSpecification="false" isLeaf="false" visibility="public" xmi.id="1062" isRoot="false" isAbstract="false" name="const KisLayerSP&amp;" elementReference="394" />
......@@ -28291,7 +28291,7 @@ XXX: for post 1.4: make sure we can drag &amp; drop widgets." isSpecification="f
</header>
<classfields/>
</classifiercodedocument>
<classifiercodedocument writeOutCode="true" package="" id="1040" parent_class="1040" fileExt=".java" fileName="const KoUnit::Unit&amp;" >
<classifiercodedocument writeOutCode="true" package="" id="1040" parent_class="1040" fileExt=".java" fileName="const KoUnit&amp;" >
<textblocks>
<codeblockwithcomments tag="packages" writeOutText="false" >
<header>
......@@ -28305,7 +28305,7 @@ XXX: for post 1.4: make sure we can drag &amp; drop widgets." isSpecification="f
</codeblockwithcomments>
<javaclassdeclarationblock parent_id="1040" tag="ClassDeclBlock" canDelete="false" >
<header>
<javacodedocumentation tag="" text="Class Const KoUnit::Unit&amp;&amp;#010;" />
<javacodedocumentation tag="" text="Class Const KoUnit&amp;&amp;#010;" />
</header>
<textblocks>
<hierarchicalcodeblock tag="fieldsDecl" canDelete="false" indentLevel="1" >
......@@ -28324,7 +28324,7 @@ XXX: for post 1.4: make sure we can drag &amp; drop widgets." isSpecification="f
<codecomment tag="" indentLevel="1" text="Constructors" />
</header>
<textblocks>
<codeblockwithcomments tag="emptyconstructor" writeOutText="false" indentLevel="1" text="public Const KoUnit::Unit&amp; ( ) { }" >
<codeblockwithcomments tag="emptyconstructor" writeOutText="false" indentLevel="1" text="public Const KoUnit&amp; ( ) { }" >
<header>
<codecomment tag="" indentLevel="1" text="Empty Constructor" />
</header>
......@@ -519,7 +519,7 @@ public:
double xres;
double yres;
KoUnit::Unit unit;
KoUnit unit;
KoColorSpace * colorSpace;
......@@ -661,7 +661,7 @@ void KisImage::init(KisUndoAdapter *adapter, qint32 width, qint32 height, KoCol
m_d->xres = 1.0;
m_d->yres = 1.0;
m_d->unit = KoUnit::U_PT;
m_d->unit = KoUnit::Point;
m_d->dirty = false;
m_d->width = width;
m_d->height = height;
......
......@@ -239,7 +239,7 @@ public:
double yRes();
/**
* Set the resolution in pixels per inch.
* Set the resolution in pixels per pt.
*/
void setResolution(double xres, double yres);
......
......@@ -139,9 +139,9 @@ QWidget* KisCanvas2::canvasWidget()
}
KoUnit::Unit KisCanvas2::unit()
KoUnit KisCanvas2::unit()
{
return KoUnit::U_PIXEL;
return KoUnit(KoUnit::Pixel);
}
KoToolProxy * KisCanvas2::toolProxy() {
......
......@@ -83,7 +83,7 @@ public: // KoCanvasBase implementation
virtual QWidget* canvasWidget();
virtual KoUnit::Unit unit();
virtual KoUnit unit();
virtual KoToolProxy* toolProxy();
......
......@@ -20,6 +20,7 @@
#include <QPushButton>
#include <QSlider>
#include <QComboBox>
#include <kcolorcombo.h>
#include <kdebug.h>
......@@ -45,18 +46,34 @@ KisCustomImageWidget::KisCustomImageWidget(QWidget *parent, KisDoc2 *doc, qint32
txtName->setText(imageName);
m_widthUnit = KoUnit(KoUnit::Pixel, resolution);
doubleWidth->setValue(defWidth);
doubleWidth->setDecimals(0);
m_width = KoUnit::fromUserValue(defWidth, m_widthUnit);
cmbWidthUnit->addItems( KoUnit::listOfUnitName(false) );
cmbWidthUnit->setCurrentIndex(KoUnit::Pixel);
m_heightUnit = KoUnit(KoUnit::Pixel, resolution);
doubleHeight->setValue(defHeight);
doubleResolution->setValue(resolution);
doubleHeight->setDecimals(0);
m_height = KoUnit::fromUserValue(defHeight, m_heightUnit);
cmbHeightUnit->addItems( KoUnit::listOfUnitName(false) );
cmbHeightUnit->setCurrentIndex(KoUnit::Pixel);
cmbWidthUnit->addItem( i18n("Pixels") );
cmbWidthUnit->addItems( KoUnit::listOfUnitName() );
cmbHeightUnit->addItem( i18n("Pixels") );
cmbHeightUnit->addItems( KoUnit::listOfUnitName() );
doubleResolution->setValue(72.0 * resolution);
doubleResolution->setDecimals(0);
cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys());
cmbColorSpaces->setCurrent(defColorSpaceName);
connect(cmbWidthUnit, SIGNAL(activated(int)),
this, SLOT(widthUnitChanged(int)));
connect(doubleWidth, SIGNAL(valueChanged(double)),
this, SLOT(widthChanged(double)));
connect(cmbHeightUnit, SIGNAL(activated(int)),
this, SLOT(heightUnitChanged(int)));
connect(doubleHeight, SIGNAL(valueChanged(double)),
this, SLOT(heightChanged(double)));
connect(cmbColorSpaces, SIGNAL(activated(const KoID &)),
this, SLOT(fillCmbProfiles(const KoID &)));
connect (m_createButton, SIGNAL( clicked() ), this, SLOT (buttonClicked()) );
......@@ -66,6 +83,48 @@ KisCustomImageWidget::KisCustomImageWidget(QWidget *parent, KisDoc2 *doc, qint32
}
void KisCustomImageWidget::widthUnitChanged(int index) {
doubleWidth->blockSignals(true);
if(index == KoUnit::Pixel) {
doubleWidth->setDecimals(0);
m_widthUnit = KoUnit(KoUnit::Pixel, doubleResolution->value() / 72.0);
}
else {
doubleWidth->setDecimals(2);
m_widthUnit = KoUnit((KoUnit::Unit)cmbWidthUnit->currentIndex());
}
doubleWidth->setValue(KoUnit::ptToUnit(m_width, m_widthUnit));
doubleWidth->blockSignals(false);
}
void KisCustomImageWidget::widthChanged(double value) {
m_width = KoUnit::fromUserValue(value, m_widthUnit);
}
void KisCustomImageWidget::heightUnitChanged(int index) {
doubleHeight->blockSignals(true);
if(index == KoUnit::Pixel) {
doubleHeight->setDecimals(0);
m_heightUnit = KoUnit(KoUnit::Pixel, doubleResolution->value()/72.0);
}
else {
doubleHeight->setDecimals(2);
m_heightUnit = KoUnit((KoUnit::Unit)cmbHeightUnit->currentIndex());
}
doubleHeight->setValue(KoUnit::ptToUnit(m_height, m_heightUnit));
doubleHeight->blockSignals(false);
}
void KisCustomImageWidget::heightChanged(double value) {
m_height = KoUnit::fromUserValue(value, m_heightUnit);
}
void KisCustomImageWidget::buttonClicked() {
KoColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->colorSpace(cmbColorSpaces->currentItem(), cmbProfile->currentText());
......@@ -73,24 +132,11 @@ void KisCustomImageWidget::buttonClicked() {
qint32 width, height;
double resolution;
resolution = doubleResolution->value() / 72.0; // internal resolution is in pixels per pt
switch(cmbWidthUnit->currentIndex())
{
case 0:
width = int(doubleWidth->value());
break;
case 1:
width = int(doubleWidth->value());
break;
case 2:
width = int(doubleWidth->value());
break;
case 3:
width = int(doubleWidth->value());
break;
}
resolution = doubleResolution->value() / 72.0; // internal resolution is in pixels per pt
width = 0.5 + KoUnit::ptToUnit(m_width, KoUnit(KoUnit::Pixel, resolution));
height = 0.5 + KoUnit::ptToUnit(m_height, KoUnit(KoUnit::Pixel, resolution));
m_doc->newImage(txtName->text(), width, height, cs, KoColor(qc, cs), txtDescription->toPlainText(), resolution);
KisImageSP img = m_doc->currentImage();
......
......@@ -21,6 +21,7 @@
#include "kis_global.h"
#include "kis_dlg_image_properties.h"
#include "KoUnit.h"
class KisDoc2;
class KoID;
......@@ -43,6 +44,10 @@ public:
private slots:
void buttonClicked();
void fillCmbProfiles(const KoID & s);
void widthUnitChanged(int index);
void widthChanged(double value);
void heightUnitChanged(int index);
void heightChanged(double value);
signals:
/// this signal is emitted (as defined by KoDocument) the moment the document is 'ready'
......@@ -52,6 +57,8 @@ private:
quint8 backgroundOpacity() const;
KisDoc2 *m_doc;
double m_width, m_height;
KoUnit m_widthUnit, m_heightUnit;
};
#endif
......@@ -64,7 +64,7 @@ KisDlgImageProperties::KisDlgImageProperties(KisImageSP image, QWidget *parent,
m_page->doubleWidth->setValue(image->width());
m_page->doubleHeight->setValue(image->height());
m_page->doubleResolution->setValue(image->xRes()); // XXX: separate values for x & y?
m_page->doubleResolution->setValue(image->xRes()*72); // XXX: separate values for x & y?
m_page->txtDescription->setText( m_image->description() );
......@@ -128,7 +128,7 @@ QString KisDlgImageProperties::imageName()
double KisDlgImageProperties::resolution()
{
return m_page->doubleResolution->value();
return m_page->doubleResolution->value() / 72;
}
QString KisDlgImageProperties::description()
......
......@@ -105,18 +105,23 @@ void KisQPainterCanvas::paintEvent( QPaintEvent * ev )
++it;
}
double zx,zy;
m_viewConverter->zoom(&zx, &zy);
double sx,sy;
m_viewConverter->zoom(&sx, &sy);
double pppx,pppy;
pppx = img->xRes();
pppy = img->yRes();
if(zx < 1.0 +EPSILON && zy < 1.0 +EPSILON) {
if(sx < 1.0 +EPSILON && sy < 1.0 +EPSILON) {
// We are scaling pixels down (birds eye) so adjust for display profile AFTER scaling the pixels
it = checkRects.begin();
while (it != end) {
// Image
QRectF imagerect = m_viewConverter->viewToDocument(*it);
imagerect.adjust(-5,-5,5,5);
imagerect.setCoords(imagerect.left()*pppx,imagerect.top()*pppy,
imagerect.right()*pppx,imagerect.bottom()*pppy);
QImage image = img->convertToQImage(imagerect.toRect(), 1/zx, 1/zy,
QImage image = img->convertToQImage(imagerect.toRect(), pppx/sx, pppy/sy,
m_canvas->monitorProfile());
gc.drawImage(imagerect.topLeft(), image, image.rect());
......@@ -127,14 +132,16 @@ void KisQPainterCanvas::paintEvent( QPaintEvent * ev )
{
// We are scaling pixels up (magnified look) so adjust for display profile before scaling the pixels
gc.setWorldMatrixEnabled(true);
gc.scale(zx, zy);
gc.scale(sx/pppx, sy/pppy);
it = checkRects.begin();
while (it != end) {
// Image
QRectF imagerect = m_viewConverter->viewToDocument(*it);
imagerect.adjust(-5,-5,5,5);
img->renderToPainter(imagerect.x(),
// Image
QRectF imagerect = m_viewConverter->viewToDocument(*it);
imagerect.adjust(-5,-5,5,5);
imagerect.setCoords(imagerect.left()*pppx,imagerect.top()*pppy,
imagerect.right()*pppx,imagerect.bottom()*pppy);
img->renderToPainter(imagerect.x(),
imagerect.y(),
imagerect.x(), imagerect.y(),
imagerect.width(), imagerect.height(), gc,
......
......@@ -88,8 +88,8 @@ void KisZoomManager::slotZoomChanged(KoZoomMode::Mode mode, int zoom)
zoomHandler->setZoomMode(mode);
KisImageSP img = m_view->image();
m_view->canvasBase()->setCanvasSize(
int(zoomHandler->documentToViewX(img->xRes() * img->width())),
int(zoomHandler->documentToViewY(img->yRes() * img->height())));
int(zoomHandler->documentToViewX(img->width() / img->xRes())),
int(zoomHandler->documentToViewY(img->height() / img->yRes())));
m_view->canvas()->update();
}
......@@ -107,8 +107,8 @@ void KisZoomManager::slotZoomIn()
zoomHandler->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
KisImageSP img = m_view->image();
m_view->canvasBase()->setCanvasSize(
int(zoomHandler->documentToViewX(img->xRes() * img->width())),
int(zoomHandler->documentToViewY(img->yRes() * img->height())));
int(zoomHandler->documentToViewX(img->width() / img->xRes())),
int(zoomHandler->documentToViewY(img->height() / img->yRes())));
m_view->canvas()->update();
}
......@@ -126,8 +126,8 @@ void KisZoomManager::slotZoomOut()
zoomHandler->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
KisImageSP img = m_view->image();
m_view->canvasBase()->setCanvasSize(
int(zoomHandler->documentToViewX(img->xRes() * img->width())),
int(zoomHandler->documentToViewY(img->yRes() * img->height())));
int(zoomHandler->documentToViewX(img->width() / img->xRes())),
int(zoomHandler->documentToViewY(img->height() / img->yRes())));
m_view->canvas()->update();
}
......
......@@ -52,7 +52,7 @@ KisRuler::KisRuler(Qt::Orientation o, QWidget *parent, const char *name)
setLineWidth(1);
setMidLineWidth(0);
m_orientation = o;
m_unit = KoUnit::U_PT;
m_unit = KoUnit::Point;
m_zoom = 1.0;
m_firstVisible = 0;
m_pixmapBuffer = 0;
......@@ -109,12 +109,12 @@ void KisRuler::recalculateSize()
updatePointer(m_currentPosition, m_currentPosition);
}
KoUnit::Unit KisRuler::unit() const
KoUnit KisRuler::unit() const
{
return m_unit;
}
void KisRuler::setUnit(KoUnit::Unit u)
void KisRuler::setUnit(KoUnit u)
{
m_unit = u;
//drawRuler();
......@@ -199,19 +199,19 @@ void KisRuler::drawRuler()
p.eraseRect(0, 0, m_pixmapBuffer->width(), m_pixmapBuffer->height());
switch (m_unit) {
case KoUnit::U_PT:
case KoUnit::U_MM:
case KoUnit::U_DD:
case KoUnit::U_CC:
case KoUnit::Point:
case KoUnit::Millimeter:
case KoUnit::Didot:
case KoUnit::Cicero:
st1 = 1;
st2 = 5;
st3 = 10;
st4 = 25;
stt = 100;
break;
case KoUnit::U_CM:
case KoUnit::U_PI:
case KoUnit::U_INCH:
case KoUnit::Centimeter:
case KoUnit::Pica:
case KoUnit::Inch:
st1 = 1;
st2 = 2;
st3 = 5;
......
......@@ -44,13 +44,13 @@ public:
virtual ~KisRuler();
public:
KoUnit::Unit unit() const;
KoUnit unit() const;
public slots:
void setZoom(double zoom);
void updatePointer(qint32 x, qint32 y);
void updateVisibleArea(qint32 xpos, qint32 ypos);
void setUnit(KoUnit::Unit u);
void setUnit(KoUnit u);
void hide();
void show();
......@@ -66,7 +66,7 @@ protected:
void drawNums(QPainter *gc, qint32 x, qint32 y, QString& num, bool orientationHoriz);
private:
KoUnit::Unit m_unit;
KoUnit m_unit;
Qt::Orientation m_orientation;
qint32 m_firstVisible;
qint32 m_currentPosition;
......
......@@ -59,7 +59,7 @@
<item>
<widget class="QLabel" name="lblWidth" >
<property name="text" >
<string>&amp;Width:</string>
<string>Width:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
......@@ -69,7 +69,7 @@
<item>
<widget class="QLabel" name="lblHeight" >
<property name="text" >
<string>Hei&amp;ght:</string>
<string>Height:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
......@@ -90,10 +90,33 @@
<number>6</number>
</property>
<item>
<widget class="QDoubleSpinBox" name="doubleWidth" />
<widget class="QDoubleSpinBox" name="doubleWidth" >
<property name="minimumSize" >
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="decimals" >
<number>2</number>
</property>
<property name="maximum" >
<double>100000000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleHeight" />
<widget class="QDoubleSpinBox" name="doubleHeight" >
<property name="minimumSize" >
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximum" >
<double>100000000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
......@@ -118,13 +141,23 @@
<property name="text" >
<string>&amp;Resolution:</string>
</property>
<property name="buddy" >
<cstring>doubleResolution</cstring>
</property>
</widget>
</item>
<item>
<widget class="KDoubleSpinBox" name="doubleResolution" />
<widget class="QDoubleSpinBox" name="doubleResolution" >
<property name="minimumSize" >
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="decimals" >
<number>0</number>
</property>
<property name="maximum" >
<double>99999.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer>
......@@ -334,22 +367,16 @@
</widget>
<layoutdefault spacing="6" margin="11" />
<customwidgets>
<customwidget>
<class>SqueezedComboBox</class>
<extends>QComboBox</extends>
<header>squeezedcombobox.h</header>
</customwidget>
<customwidget>
<class>KDoubleSpinBox</class>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisCmbIDList</class>
<extends>QWidget</extends>
<header>kis_cmb_idlist.h</header>
</customwidget>
<customwidget>
<class>SqueezedComboBox</class>
<extends>QComboBox</extends>
<header>squeezedcombobox.h</header>
</customwidget>
<customwidget>
<class>KColorCombo</class>
<extends>QWidget</extends>
......@@ -359,7 +386,6 @@
</customwidgets>
<tabstops>
<tabstop>txtName</tabstop>
<tabstop>doubleResolution</tabstop>
<tabstop>cmbColorSpaces</tabstop>
<tabstop>cmbProfile</tabstop>
<tabstop>cmbColor</tabstop>
......
......@@ -118,7 +118,7 @@ public:
* by the flake framework.
* @see KoDocument::unit()
*/
virtual KoUnit::Unit unit() = 0;
virtual KoUnit unit() = 0;
/**
* Return the position of the document origin inside the canvas widget.
......
......@@ -73,7 +73,7 @@ public:
* Called by the tool that created the shape using KoCavasBase::unit()
* @param unit the new unit to show data in.
*/
virtual void setUnit(KoUnit::Unit unit) { Q_UNUSED(unit); }
virtual void setUnit(KoUnit unit) { Q_UNUSED(unit); }
};
......
......@@ -40,5 +40,5 @@ public:
KoToolProxy * toolProxy() { return 0; }
KoViewConverter *viewConverter() { return 0; }
QWidget* canvasWidget() { return 0; }
KoUnit::Unit unit() { return KoUnit::U_MM; }
KoUnit unit() { return KoUnit::Millimeter; }
};
......@@ -132,9 +132,9 @@ public:
m_confirmNonNativeSave[0] = true;
m_confirmNonNativeSave[1] = true;
if ( KGlobal::locale()->measureSystem() == KLocale::Imperial ) {
m_unit = KoUnit::U_INCH;
m_unit = KoUnit::Inch;
} else {
m_unit = KoUnit::U_CM;
m_unit = KoUnit::Centimeter;
}
}
......@@ -147,7 +147,7 @@ public:
// KoDocumentIface * m_dcopObject;
KoDocumentInfo *m_docInfo;
KoUnit::Unit m_unit;
KoUnit m_unit;
KoFilterManager * filterManager; // The filter-manager to use when loading/saving [for the options]
......@@ -2661,12 +2661,12 @@ KoPageLayout KoDocument::pageLayout(int /*pageNumber*/) const
return m_pageLayout;
}
KoUnit::Unit KoDocument::unit() const
KoUnit KoDocument::unit() const
{
return d->m_unit;
}
void KoDocument::setUnit( KoUnit::Unit unit )
void KoDocument::setUnit( KoUnit unit )
{
if ( d->m_unit != unit )
{
......
......@@ -879,13 +879,13 @@ public:
* Returns the unit used to display all measures/distances.
* @since 1.5
*/
KoUnit::Unit unit() const;
KoUnit unit() const;
/**
* Sets the unit used to display all measures/distances.
* @since 1.5
*/
void setUnit( KoUnit::Unit u );
void setUnit( KoUnit u );
/**
* Returns the name of the unit used to display all measures/distances.
......@@ -941,7 +941,7 @@ signals:
* It is common to connect views to it, in order to change the displayed units
* (e.g. in the rulers)
*/
void unitChanged(KoUnit::Unit);
void unitChanged(KoUnit);
/**
* This signal is emitted when a direct or indirect child document changes
......
......@@ -28,118 +28,135 @@
#include <QRegExp>
QStringList KoUnit::listOfUnitName()
QStringList KoUnit::listOfUnitName(bool hidePixel)
{
QStringList lst;
for ( uint i = 0 ; i <= KoUnit::U_LASTUNIT ; ++i )
for ( uint i = 0 ; i <= KoUnit::LastUnit ; ++i )