Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
85abf746
Commit
85abf746
authored
Nov 22, 2018
by
Christoffer Ackelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backported unique_ptr from C++11.
parent
17c471c9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
271 additions
and
185 deletions
+271
-185
sev/exe/sev_xtt/src/xtt_tbl_command.cpp
sev/exe/sev_xtt/src/xtt_tbl_command.cpp
+6
-2
src/lib/co/src/co_smart_ptr.h
src/lib/co/src/co_smart_ptr.h
+167
-0
xtt/lib/flow/qt/flow_draw_qt.cqt
xtt/lib/flow/qt/flow_draw_qt.cqt
+36
-71
xtt/lib/flow/qt/flow_draw_qt.h
xtt/lib/flow/qt/flow_draw_qt.h
+3
-4
xtt/lib/glow/qt/glow_draw_qt.cqt
xtt/lib/glow/qt/glow_draw_qt.cqt
+54
-103
xtt/lib/glow/qt/glow_draw_qt.h
xtt/lib/glow/qt/glow_draw_qt.h
+5
-5
No files found.
sev/exe/sev_xtt/src/xtt_tbl_command.cpp
View file @
85abf746
...
...
@@ -465,7 +465,9 @@ int XttTbl::command(char* input_str)
/* Read command file */
sts
=
readcmdfile
(
&
command
[
1
]);
if
(
sts
==
DCLI__NOFILE
)
{
message
(
'E'
,
"Unable to open file"
);
char
tmp
[
200
];
snprintf
(
tmp
,
200
,
"Unable to open file
\"
%s
\"
"
,
&
command
[
1
]);
message
(
'E'
,
tmp
);
return
DCLI__SUCCESS
;
}
else
if
(
EVEN
(
sts
))
return
sts
;
...
...
@@ -486,7 +488,9 @@ int XttTbl::command(char* input_str)
/* Read command file */
sts
=
readcmdfile
(
&
symbol_value
[
1
]);
if
(
sts
==
DCLI__NOFILE
)
{
message
(
'E'
,
"Unable to open file"
);
char
tmp
[
200
];
snprintf
(
tmp
,
200
,
"Unable to open file
\"
%s
\"
"
,
&
symbol_value
[
1
]);
message
(
'E'
,
tmp
);
return
DCLI__SUCCESS
;
}
else
if
(
EVEN
(
sts
))
return
sts
;
...
...
src/lib/co/src/co_smart_ptr.h
0 → 100644
View file @
85abf746
#ifndef CO_UNIQUE_PTR
#define CO_UNIQUE_PTR
#include "co_debug.h"
// std::remove_reference
template
<
typename
T
>
struct
remove_reference
{
typedef
T
type
;
};
template
<
typename
T
>
struct
remove_reference
<
T
&>
{
typedef
T
type
;
};
template
<
typename
T
>
struct
remove_reference
<
T
&&>
{
typedef
T
type
;
};
// std::forward
template
<
typename
T
>
T
&&
forward
(
typename
remove_reference
<
T
>::
type
&
x
)
{
return
static_cast
<
T
&&>
(
x
);
}
template
<
typename
T
>
T
&&
forward
(
typename
remove_reference
<
T
>::
type
&&
x
)
{
return
static_cast
<
T
&&>
(
x
);
}
// std::move
template
<
typename
T
>
typename
remove_reference
<
T
>::
type
&&
move
(
T
&&
x
)
{
return
((
typename
remove_reference
<
T
>::
type
&&
)
x
);
}
template
<
typename
T
>
class
default_delete
{
public:
void
operator
()(
T
*
ptr
)
const
{
delete
ptr
;
}
};
template
<
typename
T
>
class
default_delete
<
T
[]
>
{
public:
void
operator
()(
T
*
ptr
)
const
{
delete
[]
ptr
;
}
};
// std::unique_ptr for single objects -> free memory with 'delete'
template
<
typename
T
,
typename
Deleter
=
default_delete
<
T
>
>
class
unique_ptr
{
public:
typedef
unique_ptr
<
T
,
Deleter
>
this_type
;
unique_ptr
(
T
*
p
)
:
value
(
p
)
{
}
unique_ptr
(
T
*
p
,
Deleter
d
)
:
value
(
p
),
del
(
d
)
{
}
unique_ptr
(
this_type
&&
x
)
:
value
(
x
.
release
()),
del
(
forward
<
Deleter
>
(
x
.
get_deleter
()))
{
}
this_type
&
operator
=
(
this_type
&&
x
)
{
reset
(
x
.
release
());
del
=
move
(
forward
<
Deleter
>
(
x
.
get_deleter
()));
return
*
this
;
}
~
unique_ptr
()
{
reset
();
}
void
reset
(
T
*
p
=
NULL
)
{
if
(
p
!=
value
)
{
get_deleter
()(
value
);
value
=
p
;
}
}
T
*
release
()
{
T
*
const
tmp
=
value
;
value
=
NULL
;
return
tmp
;
}
T
&
operator
*
()
const
{
return
*
value
;
}
T
*
operator
->
()
const
{
return
value
;
}
T
*
get
()
const
{
return
value
;
}
Deleter
&
get_deleter
()
{
return
del
;
}
const
Deleter
&
get_deleter
()
const
{
return
del
;
}
protected:
T
*
value
;
Deleter
del
;
unique_ptr
(
const
this_type
&
);
unique_ptr
&
operator
=
(
const
this_type
&
);
unique_ptr
&
operator
=
(
T
*
p
);
};
// std::unique_ptr for arrays -> free memory with 'delete[]'
template
<
typename
T
,
typename
Deleter
>
class
unique_ptr
<
T
[],
Deleter
>
{
public:
typedef
unique_ptr
<
T
[],
Deleter
>
this_type
;
unique_ptr
(
T
*
p
,
Deleter
d
=
default_delete
<
T
[]
>
())
:
value
(
p
),
del
(
d
)
{
}
unique_ptr
(
this_type
&&
x
)
:
value
(
x
.
release
()),
del
(
forward
<
Deleter
>
(
x
.
get_deleter
()))
{
}
this_type
&
operator
=
(
this_type
&&
x
)
{
reset
(
x
.
release
());
del
=
move
(
forward
<
Deleter
>
(
x
.
get_deleter
()));
return
*
this
;
}
~
unique_ptr
()
{
reset
();
}
void
reset
(
T
*
p
=
NULL
)
{
if
(
p
!=
value
)
{
get_deleter
()(
value
);
value
=
p
;
}
}
T
*
release
()
{
T
*
const
tmp
=
value
;
value
=
NULL
;
return
tmp
;
}
T
&
operator
[](
int
i
)
const
{
return
value
[
i
];
}
T
*
get
()
const
{
return
value
;
}
Deleter
&
get_deleter
()
{
return
del
;
}
const
Deleter
&
get_deleter
()
const
{
return
del
;
}
protected:
T
*
value
;
Deleter
del
;
unique_ptr
(
const
this_type
&
);
unique_ptr
&
operator
=
(
const
this_type
&
);
unique_ptr
&
operator
=
(
T
*
p
);
};
#endif
\ No newline at end of file
xtt/lib/flow/qt/flow_draw_qt.cqt
View file @
85abf746
...
...
@@ -108,10 +108,10 @@ static QFont get_font(int painter_type, double size, const char* fontstr = "Luci
return res;
}
static
QPainter*
get_painter(
static
unique_ptr<QPainter>
get_painter(
QPaintDevice* window, FlowDrawQt* draw_ctx, int painter_type, int size)
{
QPainter* painter = new QPainter(window
);
unique_ptr<QPainter> painter(new QPainter(window)
);
switch (painter_type) {
case flow_eDrawType_LineDashed:
case flow_eDrawType_LineDashedRed: {
...
...
@@ -836,7 +836,7 @@ void FlowDrawQt::enable_event(FlowCtx* ctx, flow_eEvent event,
ctx->enable_event(event, event_type, event_cb);
}
QPainter*
FlowDrawQt::get_painter(int painter_type, int size, bool nav)
unique_ptr<QPainter>
FlowDrawQt::get_painter(int painter_type, int size, bool nav)
{
if (nav) {
return ::get_painter(nav_window_canvas, this, painter_type, size);
...
...
@@ -856,7 +856,7 @@ int FlowDrawQt::rect_helper(FlowCtx* ctx, int painter_type, int size, int x,
return 1;
}
QPainter*
painter = get_painter(painter_type, size, nav);
unique_ptr<QPainter>
painter = get_painter(painter_type, size, nav);
if (fill) {
// debug_print("fillRect [%d, %d, %d, %d] painter_type=%d, with color %s\n", x, y, width, height, painter_type, qPrintable(painter->brush().color().name()));
...
...
@@ -867,8 +867,6 @@ int FlowDrawQt::rect_helper(FlowCtx* ctx, int painter_type, int size, int x,
painter->drawRect(x, y, width, height);
}
delete painter;
return 1;
}
...
...
@@ -921,7 +919,7 @@ int FlowDrawQt::triangle_helper(FlowCtx* ctx, int painter_type, int size, int x,
return 1;
}
QPainter*
painter = get_painter(painter_type, size, nav);
unique_ptr<QPainter>
painter = get_painter(painter_type, size, nav);
QPolygon poly(4);
poly[0] = QPoint(x, y + height);
...
...
@@ -942,8 +940,6 @@ int FlowDrawQt::triangle_helper(FlowCtx* ctx, int painter_type, int size, int x,
painter->drawPolygon(poly);
}
delete painter;
return 1;
}
...
...
@@ -1004,7 +1000,7 @@ int FlowDrawQt::arrow_helper(FlowCtx* ctx, int painter_type, int size, int x1,
return 1;
}
QPainter*
painter = get_painter(painter_type, size, nav);
unique_ptr<QPainter>
painter = get_painter(painter_type, size, nav);
QPolygon poly(4);
poly[0] = QPoint(x1, y1);
...
...
@@ -1017,8 +1013,6 @@ int FlowDrawQt::arrow_helper(FlowCtx* ctx, int painter_type, int size, int x1,
// debug_print("arrow (%d, %d) (%d, %d) (%d, %d)\n", x1, y1, x2, y2, x3, y3);
painter->fillPath(path, painter->brush());
delete painter;
return 1;
}
...
...
@@ -1069,11 +1063,10 @@ int FlowDrawQt::arc_helper(FlowCtx* ctx, int painter_type, int size, int x,
return 1;
}
QPainter*
painter = get_painter(painter_type, size, nav);
unique_ptr<QPainter>
painter = get_painter(painter_type, size, nav);
painter->setBrush(Qt::NoBrush);
// debug_print("arc [%d, %d, %d, %d], %d, %d\n", x, y, width, height, angle1, angle2);
painter->drawArc(x, y, width, height, angle1 * 16, angle2 * 16);
delete painter;
return 1;
}
...
...
@@ -1130,10 +1123,9 @@ int FlowDrawQt::line_helper(FlowCtx* ctx, int painter_type, int size, int x1,
return 1;
}
QPainter*
painter = get_painter(painter_type, size, nav);
unique_ptr<QPainter>
painter = get_painter(painter_type, size, nav);
// debug_print("line (%d, %d) (%d, %d)\n", x1, y1, x2, y2);
painter->drawLine(x1, y1, x2, y2);
delete painter;
return 1;
}
...
...
@@ -1182,7 +1174,7 @@ int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text,
return 1;
}
QPainter*
painter = get_painter(painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(painter_type, idx);
if (dimmed) {
painter->setBrush(QBrush(flow_allocate_color(this, "gray")));
painter->setPen(QPen(painter->brush(), size + 1));
...
...
@@ -1210,8 +1202,6 @@ int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text,
painter->drawText(x, ROUND(y - 0.8 * height), rect.width(), height, Qt::TextDontClip, str, &rect);
}
delete painter;
return 1;
}
...
...
@@ -1275,12 +1265,10 @@ int FlowDrawQt::nav_text_helper(FlowCtx* ctx, flow_eDrawType painter_type,
return 1;
}
QPainter*
painter = get_painter(painter_type, size, true);
unique_ptr<QPainter>
painter = get_painter(painter_type, size, true);
// debug_print("drawText %s at (%d, %d)\n", text, x, y);
painter->drawText(x, y, QString::fromLocal8Bit(text, len));
delete painter;
return 1;
}
...
...
@@ -1343,12 +1331,12 @@ int FlowDrawQt::pixmap(FlowCtx* ctx, int x, int y,
pms = (draw_sPixmap*)pixmaps;
QPainter* painter = get_painter(painter_type, idx);
painter->fillRect(x, y, pdata->width, pdata->height, painter->brush());
delete painter;
{
unique_ptr<QPainter> painter = get_painter(painter_type, idx);
painter->fillRect(x, y, pdata->width, pdata->height, painter->brush());
}
painter = get_painter(flow_eDrawType_LineErase, idx);
unique_ptr<QPainter>
painter = get_painter(flow_eDrawType_LineErase, idx);
QRegion clipRegion = QRegion(pms->pixmap[idx].createMaskFromColor(Qt::black));
painter->setClipRegion(clipRegion.translated(x, y));
...
...
@@ -1356,8 +1344,6 @@ int FlowDrawQt::pixmap(FlowCtx* ctx, int x, int y,
painter->fillRect(x, y, pdata->width, pdata->height, painter->brush());
delete painter;
return 1;
}
...
...
@@ -1374,14 +1360,15 @@ int FlowDrawQt::pixmap_inverse(FlowCtx* ctx, int x, int y,
pms = (draw_sPixmap*)pixmaps;
QPainter* painter = get_painter(flow_eDrawType_LineErase, idx);
// debug_print("pixmap_inverse fillRect [%d, %d, %d, %d] with color %s\n", x,
// y, pdata->width, pdata->height,
// painter->brush().color().name().toAscii().data());
painter->fillRect(x, y, pdata->width, pdata->height, painter->brush());
delete painter;
{
unique_ptr<QPainter> painter = get_painter(flow_eDrawType_LineErase, idx);
// debug_print("pixmap_inverse fillRect [%d, %d, %d, %d] with color %s\n", x,
// y, pdata->width, pdata->height,
// painter->brush().color().name().toAscii().data());
painter->fillRect(x, y, pdata->width, pdata->height, painter->brush());
}
painter = get_painter(painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(painter_type, idx);
QRegion clipRegion = QRegion(pms->pixmap[idx].createMaskFromColor(Qt::black));
painter->setClipRegion(clipRegion.translated(x, y));
...
...
@@ -1392,8 +1379,6 @@ int FlowDrawQt::pixmap_inverse(FlowCtx* ctx, int x, int y,
// painter->brush().color().name().toAscii().data());
painter->fillRect(x, y, pdata->width, pdata->height, painter->brush());
delete painter;
return 1;
}
...
...
@@ -1406,11 +1391,10 @@ int FlowDrawQt::pixmap_erase(FlowCtx* ctx, int x, int y,
return 1;
}
QPainter*
painter = get_painter(painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(painter_type, idx);
// debug_print("pixmap_erase [%d, %d, %d, %d]\n", x, y, pdata->width,
// pdata->height);
painter->eraseRect(x, y, pdata->width, pdata->height);
delete painter;
return 1;
}
...
...
@@ -1428,11 +1412,10 @@ int FlowDrawQt::nav_pixmap(FlowCtx* ctx, int x, int y,
pms = (draw_sPixmap*)pixmaps;
QPainter*
painter = get_painter(painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(painter_type, idx);
// debug_print("nav_pixmap [%d, %d, %d, %d]\n", x, y, pdata->width,
// pdata->height);
painter->drawPixmap(x, y, pdata->width, pdata->height, pms->pixmap[idx]);
delete painter;
return 1;
}
...
...
@@ -1446,11 +1429,10 @@ int FlowDrawQt::nav_pixmap_erase(FlowCtx* ctx, int x, int y,
return 1;
}
QPainter*
painter = get_painter(painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(painter_type, idx);
// debug_print("nav_pixmap_erase [%d, %d, %d, %d]\n", x, y, pdata->width,
// pdata->height);
painter->eraseRect(x, y, pdata->width, pdata->height);
delete painter;
return 1;
}
...
...
@@ -1478,17 +1460,18 @@ int FlowDrawQt::image(FlowCtx* ctx, int x, int y, int width, int height,
return 1;
}
QPainter*
painter = get_painter(flow_eDrawType_Line, 0);
unique_ptr<QPainter>
painter = get_painter(flow_eDrawType_Line, 0);
if (clip_mask) {
set_image_clip_mask(painter, clip_mask, x, y);
QRegion clipRegion
= QRegion(((QPixmap*)clip_mask)->createMaskFromColor(Qt::black));
painter->setClipRegion(clipRegion.translated(x, y));
painter->setClipping(true);
}
// debug_print("image [%d, %d, %d, %d]\n", x, y, width, height);
painter->drawImage(QRect(x, y, width, height), *((QImage*)image));
delete painter;
return 1;
}
...
...
@@ -1498,13 +1481,11 @@ void FlowDrawQt::clear(FlowCtx* ctx)
return;
}
QPainter*
painter = new QPainter(window_canvas);
unique_ptr<QPainter>
painter = new QPainter(window_canvas);
painter->setBackground(QBrush(background));
// debug_print("clear color=%s\n", painter->background().color().name().toAscii().data());
painter->eraseRect(window_canvas->rect());
delete painter;
}
void FlowDrawQt::nav_clear(FlowCtx* ctx)
...
...
@@ -1513,13 +1494,11 @@ void FlowDrawQt::nav_clear(FlowCtx* ctx)
return;
}
QPainter*
painter = new QPainter(nav_window_canvas);
unique_ptr<QPainter>
painter = new QPainter(nav_window_canvas);
painter->setBackground(QBrush(background));
// debug_print("nav_clear color=%s\n\n", painter->background().color().name().toAscii().data());
painter->eraseRect(nav_window_canvas->rect());
delete painter;
}
void FlowDrawQt::get_window_size(FlowCtx* ctx, int* width, int* height)
...
...
@@ -1652,7 +1631,7 @@ int FlowDrawQt::get_text_extent(FlowCtx* ctx, const char* text, int len,
int FlowDrawQt::get_text_extent_pango(FlowCtx* ctx, const char* text, int len,
flow_eDrawType painter_type, int idx, double size, int* width, int* height)
{
QPainter*
painter = get_painter(painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(painter_type, idx);
QString str;
if (ctx->text_coding != flow_eTextCoding_UTF_8) {
...
...
@@ -1668,8 +1647,6 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx* ctx, const char* text, int len,
*width = boundingRect.width();
*height = boundingRect.height();
delete painter;
return 1;
}
...
...
@@ -1682,7 +1659,7 @@ void FlowDrawQt::copy_area(FlowCtx* ctx, int x, int y)
// debug_print("copy_area: x=%d, y=%d\n", x, y);
QPixmap screenShot = QPixmap::grabWidget(window);
QPainter*
painter = get_painter(flow_eDrawType_Line, 3);
unique_ptr<QPainter>
painter = get_painter(flow_eDrawType_Line, 3);
if (x >= 0 && y >= 0) {
painter->drawPixmap(
x, y, screenShot, 0, 0, ctx->window_width - x, ctx->window_height - y);
...
...
@@ -1724,7 +1701,6 @@ void FlowDrawQt::copy_area(FlowCtx* ctx, int x, int y)
x, ctx->window_height + y, ctx->window_width, ctx->window_height);
}
}
delete painter;
}
void FlowDrawQt::clear_area(
...
...
@@ -1734,13 +1710,11 @@ void FlowDrawQt::clear_area(
return;
}
QPainter*
painter = new QPainter(window_canvas);
unique_ptr<QPainter>
painter = new QPainter(window_canvas);
painter->setBackground(QBrush(background));
// debug_print("clear_area [%d, %d, %d, %d], color=%s\n", ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, painter->background().color().name().toAscii().data());
painter->eraseRect(ll_x, ll_y, ur_x - ll_x, ur_y - ll_y);
delete painter;
}
void FlowDrawQt::set_inputfocus(FlowCtx* ctx)
...
...
@@ -1754,15 +1728,6 @@ void FlowDrawQt::set_click_sensitivity(FlowCtx* ctx, int value)
click_sensitivity = value;
}
void FlowDrawQt::set_image_clip_mask(
QPainter* painter, flow_tPixmap pixmap, int x, int y)
{
QRegion clipRegion
= QRegion(((QPixmap*)pixmap)->createMaskFromColor(Qt::black));
painter->setClipRegion(clipRegion.translated(x, y));
painter->setClipping(true);
}
void FlowDrawQt::set_white_background(FlowCtx* ctx)
{
background = flow_allocate_color(this, "white");
...
...
xtt/lib/flow/qt/flow_draw_qt.h
View file @
85abf746
...
...
@@ -37,6 +37,8 @@
#ifndef flow_draw_qt_h
#define flow_draw_qt_h
#include "co_smart_ptr.h"
#include "flow_draw.h"
#include <QColor>
...
...
@@ -205,9 +207,6 @@ public:
void
set_click_sensitivity
(
FlowCtx
*
ctx
,
int
value
);
void
set_image_clip_mask
(
QPainter
*
painter
,
flow_tPixmap
pixmap
,
int
x
,
int
y
);
void
set_white_background
(
FlowCtx
*
ctx
);
int
image_get_width
(
flow_tImImage
image
);
...
...
@@ -233,7 +232,7 @@ public:
void
*
flow_ctx
,
int
page_border
,
int
*
sts
);
private:
QPainter
*
get_painter
(
int
painter_type
,
int
size
,
bool
nav
=
false
);
unique_ptr
<
QPainter
>
get_painter
(
int
painter_type
,
int
size
,
bool
nav
=
false
);
int
rect_helper
(
FlowCtx
*
ctx
,
int
painter_type
,
int
size
,
int
x
,
int
y
,
int
width
,
int
height
,
bool
nav
=
false
,
bool
fill
=
false
);
...
...
xtt/lib/glow/qt/glow_draw_qt.cqt
View file @
85abf746
...
...
@@ -77,8 +77,8 @@ static QColor glow_allocate_color(
static QColor glow_allocate_custom_color(GlowDrawQt* draw_ctx,
glow_eDrawType drawtype, int rgb_red, int rgb_green, int rgb_blue);
static
int
glow_read_color_file(
const char* filename,
QColor** color_array, int* size
);
static
unique_ptr<QColor[]>
glow_read_color_file(
const char* filename,
int* size, int* sts
);
static QColor draw_type_to_color(
GlowDrawQt* draw_ctx, int painter_type, int size)
...
...
@@ -101,14 +101,13 @@ static QColor draw_type_to_color(
default: {
if (painter_type >= glow_eDrawType_Color4
&& painter_type <= glow_eDrawType_Color300) {
QColor* color_array
;
int sts
= glow_read_color_file(
"/home/claes/test/ge_colors.dat", &
color_array, &size
);
int sts = 0
;
unique_ptr<QColor[]> color_array
= glow_read_color_file(
"/home/claes/test/ge_colors.dat", &
size, &sts
);
if (ODD(sts)) {
QColor color_p = color_array[painter_type - glow_eDrawType_Color4];
QColor color = glow_allocate_color(
draw_ctx, color_p.red(), color_p.green(), color_p.blue());
delete color_array;
return color;
}
}
...
...
@@ -160,10 +159,10 @@ static QFont get_font(int font_idx, int painter_type, double size)
return res;
}
static
QPainter*
get_painter(
static
unique_ptr<QPainter>
get_painter(
QPaintDevice* window, GlowDrawQt* draw_ctx, int painter_type, int size)
{
QPainter*
painter = new QPainter(window);
unique_ptr<QPainter>
painter = new QPainter(window);
switch (painter_type) {
case glow_eDrawType_LineDashed:
case glow_eDrawType_LineDashedRed: {
...
...
@@ -898,7 +897,7 @@ int GlowDrawQt::rect_helper(GlowWind* wind, int painter_type, int size, int x,
}
DrawWindQt* w = (DrawWindQt*)wind->window;
QPainter*
painter = get_painter(w->buffer, this, painter_type, size);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, size);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -913,8 +912,6 @@ int GlowDrawQt::rect_helper(GlowWind* wind, int painter_type, int size, int x,
painter->drawRect(x, y, width, height);
}
delete painter;
return 1;
}
...
...
@@ -948,7 +945,7 @@ int GlowDrawQt::arrow_helper(GlowWind* wind, int painter_type, int size, int x1,
poly[2] = QPoint(x3, y3);
poly[3] = QPoint(x1, y1);
QPainter*
painter = get_painter(w->buffer, this, painter_type, size);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, size);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -958,7 +955,6 @@ int GlowDrawQt::arrow_helper(GlowWind* wind, int painter_type, int size, int x1,
path.addPolygon(poly);
// debug_print("arrow (%d, %d) (%d, %d) (%d, %d)\n", x1, y1, x2, y2, x3, y3);
painter->fillPath(path, painter->brush());
delete painter;
return 1;
}
...
...
@@ -1003,7 +999,7 @@ int GlowDrawQt::arc_helper(GlowWind* wind, int painter_type, int size, int x,
}
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, size);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, size);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1018,8 +1014,6 @@ int GlowDrawQt::arc_helper(GlowWind* wind, int painter_type, int size, int x,
painter->drawArc(x, y, width, height, angle1 * 16, angle2 * 16);
}
delete painter;
return 1;
}
...
...
@@ -1095,7 +1089,7 @@ int GlowDrawQt::line_helper(GlowWind* wind, int painter_type, int size, int x1,
return 1;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, size);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, size);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1149,8 +1143,6 @@ int GlowDrawQt::line_helper(GlowWind* wind, int painter_type, int size, int x1,
// debug_print("line (%d, %d) (%d, %d)\n", x1, y1, x2, y2);
painter->drawLine(x1, y1, x2, y2);
delete painter;
return 1;
}
...
...
@@ -1200,7 +1192,7 @@ int GlowDrawQt::polyline_helper(GlowWind* wind, int painter_type, int size,
}
DrawWindQt* w = (DrawWindQt*)wind->window;
QPainter*
painter = get_painter(w->buffer, this, painter_type, size);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, size);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1208,19 +1200,15 @@ int GlowDrawQt::polyline_helper(GlowWind* wind, int painter_type, int size,
if (fill) {
int cnt;
QPoint* qpoints = points_to_qt_points_curve(wind, points, point_cnt, &cnt);
painter->drawPolygon(qpoints, cnt);
delete[] qpoints;
unique_ptr<QPoint[]> qpoints = points_to_qt_points_curve(wind, points, point_cnt, &cnt);
painter->drawPolygon(qpoints.get(), cnt);
} else {
QPoint*
qpoints = points_to_qt_points(points, point_cnt);
unique_ptr<QPoint[]>
qpoints = points_to_qt_points(points, point_cnt);
painter->setBrush(Qt::NoBrush);
// debug_print("polyline painter_type=%d, fill=%d, point_cnt=%d\n", painter_type, fill, point_cnt);
painter->drawPolyline(qpoints, point_cnt);
delete[] qpoints;
painter->drawPolyline(qpoints.get(), point_cnt);
}
delete painter;
return 1;
}
...
...
@@ -1271,7 +1259,7 @@ int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
font_idx = glow_eFont_Helvetica;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, idx);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1292,8 +1280,6 @@ int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len));
delete painter;
return 1;
}
...
...
@@ -1316,7 +1302,7 @@ int GlowDrawQt::text_cursor(GlowWind* wind, int x, int y, char* text, int len,
width = 0;
}
QPainter*
painter = get_painter(w->buffer, this, color, 1);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, color, 1);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1325,8 +1311,6 @@ int GlowDrawQt::text_cursor(GlowWind* wind, int x, int y, char* text, int len,
// debug_print("cursor %d,%d to %d,%d\n", x + width, y + descent, x + width, y - height + descent);
painter->drawLine(x + width, y + descent, x + width, y - height + descent);
delete painter;
return 1;
}
...
...
@@ -1354,7 +1338,7 @@ int GlowDrawQt::text_erase(GlowWind* wind, int x, int y, char* text, int len,
painter_type = glow_eDrawType_TextHelveticaEraseBold;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, idx);
if (font_idx != glow_eFont_Helvetica) {
painter->setFont(get_font(font_idx, painter_type, idx));
...
...
@@ -1370,8 +1354,6 @@ int GlowDrawQt::text_erase(GlowWind* wind, int x, int y, char* text, int len,
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len));
delete painter;
return 1;
}
...
...
@@ -1418,7 +1400,7 @@ int GlowDrawQt::image_helper(GlowWind* wind, int x, int y, int width,
return 1;
}
QPainter*
painter = get_painter(w->buffer, this, glow_eDrawType_Line, 0);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, glow_eDrawType_Line, 0);
if (clip_mask) {
set_image_clip_mask(painter, clip_mask, x, y);
...
...
@@ -1433,8 +1415,6 @@ int GlowDrawQt::image_helper(GlowWind* wind, int x, int y, int width,
painter->drawImage(QRect(x, y, width, height), *((QImage*)image));
}
delete painter;
return 1;
}
...
...
@@ -1489,11 +1469,9 @@ void GlowDrawQt::copy_buffer(
+ w->clip_rectangle[w->clip_cnt - 1].height());
}
QPainter*
painter = get_painter(w->buffer, this, glow_eDrawType_Line, 0);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, glow_eDrawType_Line, 0);
painter->drawImage(x0, y0, *(w->buffer), x0, y0, x1 - x0, y1 - y0);
delete painter;
}
void GlowDrawQt::get_window_size(GlowWind* wind, int* width, int* height)
...
...
@@ -1659,7 +1637,7 @@ void GlowDrawQt::copy_area(GlowWind* wind, int x, int y)
// debug_print("copy_area [%d, %d, %d, %d]\n", x, y, window_width, window_height);
QPainter*
painterBuffer
unique_ptr<QPainter>
painterBuffer
= get_painter(w->buffer, this, glow_eDrawType_Line, 3);
if (x >= 0 && y >= 0) {
painterBuffer->drawImage(
...
...
@@ -1698,8 +1676,6 @@ void GlowDrawQt::copy_area(GlowWind* wind, int x, int y)
painterBuffer->eraseRect(x, window_height + y, window_width - x, -y);
}
}
delete painterBuffer;
}
void GlowDrawQt::clear_area(
...
...
@@ -1710,14 +1686,12 @@ void GlowDrawQt::clear_area(
}
DrawWindQt* w = (DrawWindQt*)wind->window;
QPainter*
painter = new QPainter(w->buffer);
unique_ptr<QPainter>
painter = new QPainter(w->buffer);
painter->setBackground(QBrush(background));
// debug_print("clear_area [%d, %d, %d, %d], color=%s\n", ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, qPrintable(painter->background().color().name()));
painter->eraseRect(ll_x, ll_y, ur_x - ll_x, ur_y - ll_y);
delete painter;
}
void GlowDrawQt::set_inputfocus(GlowWind* wind)
...
...
@@ -1726,30 +1700,31 @@ void GlowDrawQt::set_inputfocus(GlowWind* wind)
w->window->setFocus(Qt::OtherFocusReason);
}
static
int
glow_read_color_file(
const char* filename,
QColor** color_array, int* size
)
static
unique_ptr<QColor[]>
glow_read_color_file(
const char* filename,
int* size, int* sts
)
{
char line[80];
QColor* color_p;
std::ifstream fp;
int nr;
int line_cnt;
float f_red, f_green, f_blue;
unique_ptr<QColor[]> color_array(new QColor[300]);
if (!check_file(filename)) {
return 0;
*sts = 0;
return color_array;
} else {
printf("** Opening color file %s\n", filename);
fp.open(filename);
if (!fp) {
return GLOW__FILEOPEN;
*sts = GLOW__FILEOPEN;
return color_array;
}
*color_array = new QColor[300];
*size = 0;
line_cnt = 0;
color_p = *color_array;
while (*size < 300) {
fp.getline(line, sizeof(line));
if (line[0] == 0) {
...
...
@@ -1763,16 +1738,16 @@ static int glow_read_color_file(
if (nr != 3) {
printf("** Syntax error in file %s, line %d", filename, line_cnt);
} else {
color_
p->
setRgb(
color_
array[*size].
setRgb(
int(f_red * 255), int(f_green * 255), int(f_blue * 255));
color_p++;
(*size)++;
}
}
fp.close();
}
return 1;
*sts = 1;
return color_array;
}
void GlowDrawQt::set_background(GlowWind* wind, glow_eDrawType drawtype,
...
...
@@ -1827,7 +1802,7 @@ void GlowDrawQt::reset_background(GlowWind* wind)
m_wind->window->setPalette(pal);
}
void GlowDrawQt::set_clip(DrawWind* wind,
QPainter*
painter)
void GlowDrawQt::set_clip(DrawWind* wind,
unique_ptr<QPainter>&
painter)
{
DrawWindQt* w = (DrawWindQt*)wind;
painter->setClipRect(w->clip_rectangle[w->clip_cnt - 1]);
...
...
@@ -1835,7 +1810,7 @@ void GlowDrawQt::set_clip(DrawWind* wind, QPainter* painter)
}
void GlowDrawQt::set_image_clip_mask(
QPainter*
painter, glow_tPixmap pixmap, int x, int y)
unique_ptr<QPainter>&
painter, glow_tPixmap pixmap, int x, int y)
{
QRegion clipRegion
= QRegion(((QPixmap*)pixmap)->createMaskFromColor(Qt::black));
...
...
@@ -1912,7 +1887,7 @@ int GlowDrawQt::draw_point(
return 1;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, 0);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, 0);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1920,8 +1895,6 @@ int GlowDrawQt::draw_point(
painter->drawPoint(x1, y1);
delete painter;
return 1;
}
...
...
@@ -1933,8 +1906,8 @@ int GlowDrawQt::draw_points(GlowWind* wind, glow_sPointX* points, int point_num,
}
DrawWindQt* w = (DrawWindQt*)wind->window;
QPoint*
qpoints = points_to_qt_points(points, point_num);
QPainter*
painter = get_painter(w->buffer, this, painter_type, 0);
unique_ptr<QPoint[]>
qpoints = points_to_qt_points(points, point_num);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, 0);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -1946,12 +1919,9 @@ int GlowDrawQt::draw_points(GlowWind* wind, glow_sPointX* points, int point_num,
painter->brush());
}
} else {
painter->drawPoints(qpoints, point_num);
painter->drawPoints(qpoints
.get()
, point_num);
}
delete painter;
delete[] qpoints;
return 1;
}
...
...
@@ -2009,7 +1979,7 @@ void GlowDrawQt::buffer_background(DrawWind* wind, GlowCtx* cctx)
}
if (w->background_pixmap) {
QPainter*
painterBg
unique_ptr<QPainter>
painterBg
= get_painter(w->background_pixmap, this, glow_eDrawType_Line, 0);
if (w->clip_on) {
...
...
@@ -2029,8 +1999,6 @@ void GlowDrawQt::buffer_background(DrawWind* wind, GlowCtx* cctx)
}
}
}
delete painterBg;
} else {
glow_eDrawType bg;
if (cctx) {
...
...
@@ -2039,7 +2007,7 @@ void GlowDrawQt::buffer_background(DrawWind* wind, GlowCtx* cctx)
bg = ((GrowCtx*)ctx)->background_color;
}
QPainter*
painter = get_painter(w->buffer, this, bg, 0);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, bg, 0);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -2047,8 +2015,6 @@ void GlowDrawQt::buffer_background(DrawWind* wind, GlowCtx* cctx)
painter->fillRect(subwindow_x, subwindow_y, window_width, window_height,
painter->brush());
delete painter;
}
}
...
...
@@ -2218,9 +2184,9 @@ int GlowDrawQt::print(char* filename, double x0, double x1, int end)
return 1;
}
QPoint*
GlowDrawQt::points_to_qt_points(glow_sPointX* points, int point_cnt)
unique_ptr<QPoint[]>
GlowDrawQt::points_to_qt_points(glow_sPointX* points, int point_cnt)
{
QPoint* qpoints = new QPoint[point_cnt]
;
unique_ptr<QPoint[]> qpoints(new QPoint[point_cnt])
;
for (int i = 0; i < point_cnt; i++) {
qpoints[i].setX(points[i].x);
qpoints[i].setY(points[i].y);
...
...
@@ -2231,10 +2197,10 @@ QPoint* GlowDrawQt::points_to_qt_points(glow_sPointX* points, int point_cnt)
//
// Points outside window in x direction excluded
//
QPoint*
GlowDrawQt::points_to_qt_points_curve(
unique_ptr<QPoint[]>
GlowDrawQt::points_to_qt_points_curve(
GlowWind* w, glow_sPointX* points, int point_cnt, int* cnt)
{
QPoint* qpoints = new QPoint[point_cnt]
;
unique_ptr<QPoint[]> qpoints(new QPoint[point_cnt])
;
int idx = 0;
int last_idx = 0;
for (int i = 0; i < point_cnt; i++) {
...
...
@@ -2855,7 +2821,7 @@ int GlowDrawQt::gradient_fill_rect(GlowWind* wind, int x, int y, int w, int h,
return 1;
}
QPainter*
painter = new QPainter(ww->buffer);
unique_ptr<QPainter>
painter = new QPainter(ww->buffer);
if (ww->clip_on) {
set_clip(ww, painter);
...
...
@@ -2869,7 +2835,6 @@ int GlowDrawQt::gradient_fill_rect(GlowWind* wind, int x, int y, int w, int h,
painter->fillRect(QRect(x, y, w, h), *pat);
delete pat;
delete painter;
return 1;
}
...
...
@@ -2883,7 +2848,7 @@ int GlowDrawQt::gradient_fill_rectrounded(GlowWind* wind, int x, int y, int w,
return 1;
}
QPainter*
painter = new QPainter(ww->buffer);
unique_ptr<QPainter>
painter = new QPainter(ww->buffer);
if (ww->clip_on) {
set_clip(ww, painter);
...
...
@@ -2905,8 +2870,6 @@ int GlowDrawQt::gradient_fill_rectrounded(GlowWind* wind, int x, int y, int w,
delete pat;
delete painter;
return 1;
}
...
...
@@ -2925,7 +2888,7 @@ int GlowDrawQt::gradient_fill_arc(GlowWind* wind, int x, int y, int w, int h,
angle1 = angle1 + (-angle1 / 360 + 1) * 360;
}
QPainter*
painter = new QPainter(ww->buffer);
unique_ptr<QPainter>
painter = new QPainter(ww->buffer);
if (ww->clip_on) {
set_clip(ww, painter);
...
...
@@ -2954,8 +2917,6 @@ int GlowDrawQt::gradient_fill_arc(GlowWind* wind, int x, int y, int w, int h,
delete pat;
delete painter;
return 1;
}
...
...
@@ -2968,7 +2929,7 @@ int GlowDrawQt::gradient_fill_polyline(GlowWind* wind, glow_sPointX* points,
return 1;
}
QPainter*
painter = new QPainter(ww->buffer);
unique_ptr<QPainter>
painter = new QPainter(ww->buffer);
QPainterPath path;
double x0, y0, x1, y1;
...
...
@@ -3008,8 +2969,6 @@ int GlowDrawQt::gradient_fill_polyline(GlowWind* wind, glow_sPointX* points,
delete pat;
delete painter;
return 1;
}
...
...
@@ -3026,7 +2985,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
font_idx = glow_eFont_Helvetica;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, idx);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -3073,8 +3032,6 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
// debug_print("textQt %s on %d,%d with color %s, painter_type=%d, color=%d\n", text, px, py, qPrintable(painter->pen().color().name()), painter_type, color);
painter->drawText(px, py, rect.width(), rect.height(), Qt::TextDontClip, str);
delete painter;
return 1;
}
...
...
@@ -3101,7 +3058,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
int width, height;
{
QPainter*
painter = get_painter(w->buffer, this, painter_type, 0);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, 0);
QString str;
if (((GrowCtx*)ctx)->text_coding != glow_eTextCoding_UTF_8) {
...
...
@@ -3116,8 +3073,6 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
width = rect.width();
height = rect.height();
height = (int)(height * 0.9);
delete painter;
}
if (rot == 90) {
...
...
@@ -3137,7 +3092,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
ph = height;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, idx);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, idx);
if (w->clip_on) {
set_clip(w, painter);
...
...
@@ -3146,8 +3101,6 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
// debug_print("textEraseQt %s on %d,%d\n", text, px, py);
painter->fillRect(px, py, pw, ph, painter->brush());
delete painter;
return 1;
}
...
...
@@ -3167,7 +3120,7 @@ int GlowDrawQt::get_text_extent_qt(const char* text, int len,
painter_type = glow_eDrawType_TextHelveticaEraseBold;
}
QPainter*
painter = get_painter(w->buffer, this, painter_type, 0);
unique_ptr<QPainter>
painter = get_painter(w->buffer, this, painter_type, 0);
painter->setFont(get_font(font_idx, painter_type, size));
QString str;
...
...
@@ -3191,8 +3144,6 @@ int GlowDrawQt::get_text_extent_qt(const char* text, int len,
}
*descent = (int)(FONT_DESCENT * lheight);
delete painter;
return 1;
}
...
...
xtt/lib/glow/qt/glow_draw_qt.h
View file @
85abf746
...
...
@@ -37,7 +37,7 @@
#ifndef glow_draw_qt_h
#define glow_draw_qt_h
#include
<stack>
#include
"co_smart_ptr.h"
#include "glow_customcolors.h"
#include "glow_draw.h"
...
...
@@ -175,7 +175,7 @@ public:
int
pixmap_height
);
virtual
void
reset_background
(
GlowWind
*
w
);
virtual
void
set_image_clip_mask
(
QPainter
*
painter
,
glow_tPixmap
pixmap
,
int
x
,
int
y
);
unique_ptr
<
QPainter
>&
painter
,
glow_tPixmap
pixmap
,
int
x
,
int
y
);
virtual
int
set_clip_rectangle
(
GlowWind
*
w
,
int
ll_x
,
int
ll_y
,
int
ur_x
,
int
ur_y
);
...
...
@@ -192,13 +192,13 @@ public:
virtual
void
buffer_background
(
DrawWind
*
w
,
GlowCtx
*
cctx
);
virtual
int
print
(
char
*
filename
,
double
x0
,
double
x1
,
int
end
);
virtual
int
export_image
(
char
*
filename
);
void
set_clip
(
DrawWind
*
w
,
QPainter
*
painter
);
void
set_clip
(
DrawWind
*
w
,
unique_ptr
<
QPainter
>&
painter
);
virtual
void
set_timer
(
GlowCtx
*
ctx
,
int
time_ms
,
void
(
*
callback_func
)(
GlowCtx
*
ctx
),
void
**
id
);
virtual
void
remove_timer
(
void
*
id
);
int
init_nav
(
QWidget
*
nav_widget
);
QPoint
*
points_to_qt_points
(
glow_sPointX
*
points
,
int
point_cnt
);
QPoint
*
points_to_qt_points_curve
(
unique_ptr
<
QPoint
[]
>
points_to_qt_points
(
glow_sPointX
*
points
,
int
point_cnt
);
unique_ptr
<
QPoint
[]
>
points_to_qt_points_curve
(
GlowWind
*
w
,
glow_sPointX
*
points
,
int
point_cnt
,
int
*
cnt
);
int
image_get_width
(
glow_tImImage
image
);
int
image_get_height
(
glow_tImImage
image
);
...
...
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