Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Mathias Wein
Krita
Commits
6fa8ffaa
Commit
6fa8ffaa
authored
Apr 01, 2007
by
Sven Langkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added measure tool
svn path=/trunk/koffice/; revision=648944
parent
20e1fde0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
285 additions
and
1 deletion
+285
-1
krita/plugins/tools/defaulttools/CMakeLists.txt
krita/plugins/tools/defaulttools/CMakeLists.txt
+1
-0
krita/plugins/tools/defaulttools/default_tools.cc
krita/plugins/tools/defaulttools/default_tools.cc
+3
-1
krita/plugins/tools/defaulttools/kis_tool_measure.cc
krita/plugins/tools/defaulttools/kis_tool_measure.cc
+184
-0
krita/plugins/tools/defaulttools/kis_tool_measure.h
krita/plugins/tools/defaulttools/kis_tool_measure.h
+97
-0
No files found.
krita/plugins/tools/defaulttools/CMakeLists.txt
View file @
6fa8ffaa
...
...
@@ -9,6 +9,7 @@ set(kritadefaulttools_PART_SRCS
kis_tool_rectangle.cc
kis_tool_ellipse.cc
kis_tool_gradient.cc
kis_tool_measure.cc
)
kde4_automoc
(
${
kritadefaulttools_PART_SRCS
}
)
...
...
krita/plugins/tools/defaulttools/default_tools.cc
View file @
6fa8ffaa
...
...
@@ -36,6 +36,7 @@
#include "kis_tool_duplicate.h"
#include "kis_tool_move.h"
#include "kis_tool_ellipse.h"
#include "kis_tool_measure.h"
typedef
KGenericFactory
<
DefaultTools
>
DefaultToolsFactory
;
...
...
@@ -52,10 +53,11 @@ DefaultTools::DefaultTools(QObject *parent, const QStringList &)
r
->
add
(
new
KisToolBrushFactory
(
r
,
QStringList
()));
r
->
add
(
new
KisToolColorPickerFactory
(
r
,
QStringList
()));
r
->
add
(
new
KisToolLineFactory
(
r
,
QStringList
()));
r
->
add
(
(
new
KisToolDuplicateFactory
(
r
,
QStringList
()))
)
;
r
->
add
(
new
KisToolDuplicateFactory
(
r
,
QStringList
()));
r
->
add
(
new
KisToolMoveFactory
(
r
,
QStringList
()));
r
->
add
(
new
KisToolEllipseFactory
(
r
,
QStringList
()));
r
->
add
(
new
KisToolRectangleFactory
(
r
,
QStringList
()));
r
->
add
(
new
KisToolMeasureFactory
(
r
,
QStringList
()));
}
DefaultTools
::~
DefaultTools
()
...
...
krita/plugins/tools/defaulttools/kis_tool_measure.cc
0 → 100644
View file @
6fa8ffaa
/*
*
* Copyright (c) 2007 Sven Langkamp <sven.langkamp@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU 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 <math.h>
#include <QPainter>
#include <QLayout>
#include <QWidget>
#include <QLabel>
#include <kdebug.h>
#include <klocale.h>
#include "kis_tool_measure.h"
#include "kis_image.h"
#include "KoPointerEvent.h"
#include "KoCanvasBase.h"
#define INNER_RADIUS 50
KisToolMeasure
::
KisToolMeasure
(
KoCanvasBase
*
canvas
)
:
KisTool
(
canvas
,
QCursor
(
Qt
::
CrossCursor
)),
m_dragging
(
false
)
{
m_currentImage
=
0
;
m_startPos
=
QPointF
(
0
,
0
);
m_endPos
=
QPointF
(
0
,
0
);
}
KisToolMeasure
::~
KisToolMeasure
()
{
}
void
KisToolMeasure
::
paint
(
QPainter
&
gc
,
KoViewConverter
&
converter
)
{
double
sx
,
sy
;
converter
.
zoom
(
&
sx
,
&
sy
);
gc
.
scale
(
sx
/
m_currentImage
->
xRes
(),
sy
/
m_currentImage
->
yRes
()
);
QPen
old
=
gc
.
pen
();
QPen
pen
(
Qt
::
SolidLine
);
QPointF
start
;
QPointF
end
;
start
=
m_startPos
;
end
=
m_endPos
;
gc
.
setPen
(
pen
);
start
=
QPoint
(
static_cast
<
int
>
(
start
.
x
()),
static_cast
<
int
>
(
start
.
y
()));
end
=
QPoint
(
static_cast
<
int
>
(
end
.
x
()),
static_cast
<
int
>
(
end
.
y
()));
gc
.
drawLine
(
start
,
end
);
if
(
deltaX
()
>=
0
)
gc
.
drawLine
(
start
.
x
(),
start
.
y
(),
start
.
x
()
+
INNER_RADIUS
,
start
.
y
());
else
gc
.
drawLine
(
start
.
x
(),
start
.
y
(),
start
.
x
()
-
INNER_RADIUS
,
start
.
y
());
if
(
distance
()
>=
INNER_RADIUS
){
QRectF
rectangle
(
start
.
x
()
-
INNER_RADIUS
,
start
.
y
()
-
INNER_RADIUS
,
2
*
INNER_RADIUS
,
2
*
INNER_RADIUS
);
int
startAngle
=
(
deltaX
()
>=
0
)
?
0
:
180
*
16
;
int
spanAngle
;
if
((
deltaY
()
>=
0
&&
deltaX
()
>=
0
)
||
(
deltaY
()
<
0
&&
deltaX
()
<
0
))
spanAngle
=
angle
()
*
16
;
else
spanAngle
=
-
angle
()
*
16
;
gc
.
drawArc
(
rectangle
,
startAngle
,
spanAngle
);
}
gc
.
setPen
(
old
);
}
void
KisToolMeasure
::
mousePressEvent
(
KoPointerEvent
*
e
)
{
if
(
!
m_currentImage
)
return
;
// Erase old temporary lines
m_canvas
->
updateCanvas
(
convertToPt
(
boundingRect
()));
QPointF
pos
=
convertToPixelCoord
(
e
);
if
(
e
->
button
()
==
Qt
::
LeftButton
)
{
m_dragging
=
true
;
m_startPos
=
pos
;
m_endPos
=
pos
;
}
emit
sigDistanceChanged
(
0
);
emit
sigAngleChanged
(
0
);
}
void
KisToolMeasure
::
mouseMoveEvent
(
KoPointerEvent
*
e
)
{
if
(
m_dragging
)
{
// Erase old temporary lines
m_canvas
->
updateCanvas
(
convertToPt
(
boundingRect
()));
QPointF
pos
=
convertToPixelCoord
(
e
);
if
(
e
->
modifiers
()
&
Qt
::
AltModifier
)
{
QPointF
trans
=
pos
-
m_endPos
;
m_startPos
+=
trans
;
m_endPos
+=
trans
;
}
else
m_endPos
=
pos
;
m_canvas
->
updateCanvas
(
convertToPt
(
boundingRect
()));
}
emit
sigDistanceChanged
(
distance
());
emit
sigAngleChanged
(
angle
());
}
void
KisToolMeasure
::
mouseReleaseEvent
(
KoPointerEvent
*
e
)
{
if
(
m_dragging
&&
e
->
button
()
==
Qt
::
LeftButton
)
{
m_dragging
=
false
;
}
}
QWidget
*
KisToolMeasure
::
createOptionWidget
()
{
m_optWidget
=
new
QWidget
();
Q_CHECK_PTR
(
m_optWidget
);
QLabel
*
distanceLabel
=
new
QLabel
(
i18n
(
"Distance: "
),
m_optWidget
);
QLabel
*
angleLabel
=
new
QLabel
(
i18n
(
"Angle: "
),
m_optWidget
);
QLabel
*
distance
=
new
QLabel
(
i18n
(
"1234 "
),
m_optWidget
);
QLabel
*
angle
=
new
QLabel
(
i18n
(
"5678"
),
m_optWidget
);
connect
(
this
,
SIGNAL
(
sigDistanceChanged
(
double
)),
distance
,
SLOT
(
setNum
(
double
)));
connect
(
this
,
SIGNAL
(
sigAngleChanged
(
double
)),
angle
,
SLOT
(
setNum
(
double
)));
QGridLayout
*
optionLayout
=
new
QGridLayout
(
m_optWidget
);
Q_CHECK_PTR
(
optionLayout
);
optionLayout
->
setMargin
(
0
);
optionLayout
->
setSpacing
(
6
);
optionLayout
->
addWidget
(
distanceLabel
,
0
,
0
);
optionLayout
->
addWidget
(
angleLabel
,
1
,
0
);
optionLayout
->
addWidget
(
distance
,
0
,
1
);
optionLayout
->
addWidget
(
angle
,
1
,
1
);
return
m_optWidget
;
}
double
KisToolMeasure
::
angle
()
{
return
atan
(
qAbs
(
deltaY
())
/
qAbs
(
deltaX
()))
/
(
2
*
M_PI
)
*
360
;
}
double
KisToolMeasure
::
distance
()
{
return
sqrt
(
deltaX
()
*
deltaX
()
+
deltaY
()
*
deltaY
());
}
QRectF
KisToolMeasure
::
boundingRect
()
{
QRectF
bound
;
bound
.
setTopLeft
(
m_startPos
);
bound
.
setBottomRight
(
m_endPos
);
bound
=
bound
.
united
(
QRectF
(
m_startPos
.
x
()
-
INNER_RADIUS
,
m_startPos
.
y
()
-
INNER_RADIUS
,
2
*
INNER_RADIUS
,
2
*
INNER_RADIUS
));
return
bound
.
normalized
();
}
#include "kis_tool_measure.moc"
krita/plugins/tools/defaulttools/kis_tool_measure.h
0 → 100644
View file @
6fa8ffaa
/*
*
* Copyright (c) 2007 Sven Langkamp <sven.langkamp@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU 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.
*/
#ifndef KIS_TOOL_MEASURE_H_
#define KIS_TOOL_MEASURE_H_
#include "kis_tool.h"
#include "kis_global.h"
#include "kis_types.h"
#include "KoToolFactory.h"
#include "kis_layer_shape.h"
class
QPointF
;
class
QWidget
;
class
KoCanvasBase
;
class
KisToolMeasure
:
public
KisTool
{
Q_OBJECT
typedef
KisTool
super
;
public:
KisToolMeasure
(
KoCanvasBase
*
canvas
);
virtual
~
KisToolMeasure
();
virtual
void
mousePressEvent
(
KoPointerEvent
*
event
);
virtual
void
mouseMoveEvent
(
KoPointerEvent
*
event
);
virtual
void
mouseReleaseEvent
(
KoPointerEvent
*
event
);
virtual
void
paint
(
QPainter
&
gc
,
KoViewConverter
&
converter
);
QWidget
*
createOptionWidget
();
signals:
void
sigDistanceChanged
(
double
distance
);
void
sigAngleChanged
(
double
angle
);
private:
QRectF
boundingRect
();
double
angle
();
double
distance
();
double
deltaX
()
{
return
m_endPos
.
x
()
-
m_startPos
.
x
();
}
double
deltaY
()
{
return
m_startPos
.
y
()
-
m_endPos
.
y
();
}
private:
bool
m_dragging
;
QWidget
*
m_optWidget
;
QPointF
m_startPos
;
QPointF
m_endPos
;
};
class
KisToolMeasureFactory
:
public
KoToolFactory
{
public:
KisToolMeasureFactory
(
QObject
*
parent
,
const
QStringList
&
)
:
KoToolFactory
(
parent
,
"KritaShape/KisToolMeasure"
,
i18n
(
"Measure"
))
{
setToolType
(
dynamicToolType
()
);
setActivationShapeId
(
KIS_LAYER_SHAPE_ID
);
setPriority
(
0
);
}
virtual
~
KisToolMeasureFactory
(){}
virtual
KoTool
*
createTool
(
KoCanvasBase
*
canvas
)
{
return
new
KisToolMeasure
(
canvas
);
}
};
#endif //KIS_TOOL_MEASURE_H_
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment