Commit 9f0278a2 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Simplified printing, removed flow_printdraw.

parent 44eea749
......@@ -118,10 +118,7 @@ WbBckWQt::WbBckWQt(void* bckw_parent_ctx, QWidget* bckw_parent_wid,
void WbBckWQt::print()
{
pwr_tStatus sts;
CoWowQt::CreateBrowPrintDialogQt(name, bckwnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(name, bckwnav->brow->ctx, nav_widget);
}
void WbBckWQtWidget::focusInEvent(QFocusEvent* event)
......
......@@ -130,10 +130,7 @@ WbExpWQt::~WbExpWQt()
void WbExpWQt::print()
{
pwr_tStatus sts;
CoWowQt::CreateBrowPrintDialogQt(name, expwnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(name, expwnav->brow->ctx, nav_widget);
}
void WbExpWQtWidget::focusInEvent(QFocusEvent* event)
......
......@@ -118,9 +118,8 @@ void WFoeQtWidget::activate_print()
void WFoeQtWidget::activate_printdialog()
{
pwr_tStatus sts;
CoWowQt::CreateFlowPrintDialogQt("PlcEditor", foe->gre->flow_ctx,
flow_eOrientation_Landscape, 1.0, this, &sts);
((WGreQt*)foe->gre)->flow_widget);
}
void WFoeQtWidget::activate_printoverv()
......
......@@ -200,10 +200,7 @@ void WAttQtWidget::hide_cmd_entry()
void WAttQt::print(const char* title)
{
pwr_tStatus sts;
CoWowQt::CreateBrowPrintDialogQt(title, wattnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, wattnav->brow->ctx, ((WAttNavQt*)wattnav)->brow_widget);
}
void WAttQt::change_value_close()
......
......@@ -75,10 +75,7 @@ void WdaQt::set_prompt(const char* prompt)
void WdaQt::print(const char* title)
{
pwr_tStatus sts;
wow->CreateBrowPrintDialog(title, wdanav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, wdanav->brow->ctx, brow_widget);
}
void WdaQt::change_value(int set_focus)
......
......@@ -170,10 +170,7 @@ void WNavQtTraceObject::trace_scan()
void WNavQt::print(const char* title)
{
pwr_tStatus sts;
wow->CreateBrowPrintDialog(
title, brow->ctx, flow_eOrientation_Portrait, 1.0, NULL, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, brow->ctx, brow_widget);
}
int WNavQt::get_selection(char* str, int len)
......
......@@ -81,20 +81,18 @@ void WCrrQt::pop()
void WCrrQt::print()
{
pwr_tStatus sts;
char* namep;
int size;
pwr_tAName title;
sts = ldh_AttrRefToName(ldhses, &objar, cdh_mNName, &namep, &size);
pwr_tStatus sts = ldh_AttrRefToName(ldhses, &objar, cdh_mNName, &namep, &size);
if (EVEN(sts)) {
return;
}
strncpy(title, namep, sizeof(title));
CoWowQt::CreateBrowPrintDialogQt(title, xcrrnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, xcrrnav->brow->ctx, brow_widget);
}
void WCrrQtWidget::closeEvent(QCloseEvent* event)
......
......@@ -235,8 +235,7 @@ void XttQt::print()
strcat(title, nodename);
}
wow->CreateBrowPrintDialog(title, xnav->brow->ctx, flow_eOrientation_Portrait,
1.0, (void*)this, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, xnav->brow->ctx, brow_widget);
if (sts == WOW__PRINTDIALOGDISABLED) {
pwr_tFileName filename;
pwr_tCmd cmd;
......
......@@ -89,10 +89,7 @@ CoLogWQt::CoLogWQt(void* logw_parent_ctx, QWidget* logw_parent_wid,
void CoLogWQt::print()
{
pwr_tStatus sts;
CoWowQt::CreateBrowPrintDialogQt(name, logwnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(name, logwnav->brow->ctx, nav_widget);
}
void CoLogWQtWidget::focusInEvent(QFocusEvent* event)
......
......@@ -132,13 +132,10 @@ void MsgWindowQt::unmap()
void MsgWindowQt::print()
{
pwr_tStatus sts;
char title[80];
strncpy(title, qPrintable(translate_utf8(name)), sizeof(title));
CoWowQt::CreateBrowPrintDialogQt(title, msgnav->brow->ctx,
flow_eOrientation_Landscape, 1.4, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, msgnav->brow->ctx, nav_widget);
}
void MsgWindowQtWidget::focusInEvent(QFocusEvent* event)
......
......@@ -953,94 +953,6 @@ void CoWowQt::Wait(float time)
initOneShotTimer(m_wait_timerid, SLOT(wait_cb()), int(time * 1000));
}
void CoWowQt::CreateBrowPrintDialogQt(const char* title, void* brow_ctx,
int orientation, double scale, void* parent_widget, pwr_tStatus* sts)
{
if (m_printdialog_disable && streq(m_default_printer, "")) {
*sts = WOW__PRINTDIALOGDISABLED;
return;
}
wow_sPrintData* print_data = new wow_sPrintData();
print_data->flow_ctx = (flow_tCtx)brow_ctx;
print_data->orientation = (flow_eOrientation)orientation;
print_data->scale = scale;
strncpy(print_data->title, title, sizeof(print_data->title));
QPrinter printer;
QPrintDialog printDialog(&printer, (QWidget*)parent_widget);
if (printDialog.exec() == QDialog::Accepted) {
print_data->painter = new QPainter();
print_data->painter->begin(&printer);
int pages;
brow_PrintGetPages((brow_tCtx)print_data->flow_ctx, print_data->orientation,
print_data->scale, &pages);
for (int page = 0; page < pages; page++) {
if (print_data->orientation == flow_eOrientation_Landscape) {
printer.setOrientation(QPrinter::Landscape);
} else {
printer.setOrientation(QPrinter::Portrait);
}
brow_PrintDrawPage((brow_tCtx)print_data->flow_ctx, print_data->painter,
print_data->title, page, print_data->orientation, print_data->scale);
if (page < pages - 1) {
printer.newPage();
}
}
print_data->painter->end();
*sts = WOW__SUCCESS;
}
delete print_data;
}
void CoWowQt::CreateFlowPrintDialogQt(const char* title, void* flow_ctx,
int orientation, double scale, void* parent_widget, pwr_tStatus* sts)
{
if (m_printdialog_disable && streq(m_default_printer, "")) {
*sts = WOW__PRINTDIALOGDISABLED;
return;
}
wow_sPrintData* print_data = new wow_sPrintData();
print_data->flow_ctx = (flow_tCtx)flow_ctx;
print_data->orientation = (flow_eOrientation)orientation;
print_data->scale = scale;
strncpy(print_data->title, title, sizeof(print_data->title));
QPrinter printer;
QPrintDialog printDialog(&printer, (QWidget*)parent_widget);
if (printDialog.exec() == QDialog::Accepted) {
print_data->painter = new QPainter();
print_data->painter->begin(&printer);
int pages;
flow_PrintGetPages(print_data->flow_ctx, print_data->orientation,
print_data->scale, &pages);
for (int page = 0; page < pages; page++) {
flow_eOrientation orientation;
flow_PrintDrawGetOrientation(print_data->flow_ctx, page, &orientation);
if (orientation == flow_eOrientation_Landscape) {
printer.setOrientation(QPrinter::Landscape);
} else {
printer.setOrientation(QPrinter::Portrait);
}
flow_PrintDrawPage(print_data->flow_ctx, print_data->painter,
print_data->title, page, print_data->orientation, print_data->scale);
if (page < pages - 1) {
printer.newPage();
}
}
print_data->painter->end();
*sts = WOW__SUCCESS;
}
delete print_data;
}
void CoWowQt::update_title(QWidget* w, int editmode)
{
QString title = w->windowTitle();
......@@ -1070,4 +982,220 @@ CoWowQt::~CoWowQt()
void CoWowQt::SetParent(QWidget* parent)
{
object->setParent(parent);
}
static bool PrintDialog(QPrinter* printer, QImage *image, QWidget *parent)
{
if (image->width() > image->height()) {
printer->setOrientation(QPrinter::Landscape);
} else {
printer->setOrientation(QPrinter::Portrait);
}
QPrintDialog printDialog(printer, parent);
return (printDialog.exec() == QDialog::Accepted);
}
typedef struct {
double zoom_factor;
int window_width;
int window_height;
int offset_x;
int offset_y;
} ctx_settings;
static ctx_settings BeginPrint(QPrinter* printer, QPainter *painter, flow_tCtx ctx, QImage *image)
{
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setRenderHint(QPainter::TextAntialiasing, true);
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
ctx_settings settings = {ctx->zoom_factor, ctx->window_width, ctx->window_height, ctx->offset_x, ctx->offset_y};
ctx->window_width = image->width();
ctx->window_height = image->height();
return settings;
}
static void EndPrint(flow_tCtx ctx, ctx_settings* settings)
{
// Restore ctx zoom settings
ctx->zoom_factor = settings->zoom_factor;
ctx->window_width = settings->window_width;
ctx->window_height = settings->window_height;
ctx->offset_x = settings->offset_x;
ctx->offset_y = settings->offset_y;
ctx->a.zoom();
ctx->clear();
ctx->draw(0, 0, ctx->window_width, ctx->window_height);
ctx->nav_zoom();
ctx->change_scrollbar();
}
static int GetPrintHeaderMargin(QPainter* painter)
{
QFont tmpFont = painter->font();
QFont font("Lucida Sans", 9);
painter->setFont(font);
QFontMetrics fm(painter->font());
int height = fm.lineSpacing();
painter->setFont(tmpFont); // Restore font
return height;
}
static void PrintPage(QPainter* painter, const char* title, flow_tCtx ctx, QImage* image, double ll_x, double ll_y, double ur_x, double ur_y, int page) {
debug_print("ll_x=%f, ll_y=%f, ur_x=%f, ur_y=%f\n", ll_x, ll_y, ur_x, ur_y);
double zoom = qMin(
ctx->window_width / (ur_x - ll_x + 2 / ctx->zoom_factor),
ctx->window_height / (ur_y - ll_y + 2 / ctx->zoom_factor)
);
ctx->zoom_factor = zoom;
ctx->offset_x = ll_x * zoom;
ctx->offset_y = ll_y * zoom;
ctx->a.zoom();
ctx->clear();
double document_width = (ur_x - ll_x) * zoom + 2;
double document_height = (ur_y - ll_y) * zoom + 2;
ctx->draw(0, 0, document_width, document_height);
double margin_y = GetPrintHeaderMargin(painter);
QPen tmpPen = painter->pen();
QPen pen = QPen(QColor::fromRgbF(0, 0, 0));
pen.setWidthF(0.5);
painter->setPen(pen);
painter->drawLine(0, margin_y, document_width, margin_y);
painter->setPen(tmpPen); // Restore pen
QFont tmpFont = painter->font();
QFont font("Lucida Sans", 9);
painter->setFont(font);
QFontMetrics fm(painter->font());
if (page > 0) {
char page_str[40];
sprintf(page_str, "Page %d", page);
painter->drawText(document_width - fm.width(fl(page_str)), margin_y, fl(page_str));
}
painter->drawText(document_width / 2.0 - fm.width(fl(title)) / 2.0, margin_y, fl(title));
painter->setFont(tmpFont); // Restore font
painter->translate(0, margin_y);
painter->setClipRect(0, 0, document_width, document_height);
painter->setClipping(true);
painter->drawImage(0, 0, *image);
painter->setClipping(false);
}
#include <assert.h>
#include "flow_node.h"
#include "flow_scroll_widget_qt.h"
pwr_tStatus CoWowQt::CreateBrowPrintDialogQt(const char* title, void* brow_ctx, QWidget* w)
{
if (m_printdialog_disable && streq(m_default_printer, "")) {
return WOW__PRINTDIALOGDISABLED;
}
assert(dynamic_cast<QtScrollWidgetFlow*>(w) != NULL);
QtScrollWidgetFlow* widget = dynamic_cast<QtScrollWidgetFlow*>(w);
QImage imageTmp(widget->image);
// TODO: Change FlowDraw so that pixmaps can be scaled up in size.
// Then, change this to QPrinter::HighResolution.
QPrinter printer;
if (PrintDialog(&printer, &imageTmp, widget)) {
brow_tCtx ctx = (brow_tCtx)brow_ctx;
QPainter painter(&printer);
widget->image = QImage(printer.pageRect().width(), printer.pageRect().height() - GetPrintHeaderMargin(&painter), QImage::Format_RGB32);
// For some reason, the brow context cannot measure its width correctly
// So we estimate it to be 42 rows (portrait) or 60 rows (landscape).
// 60 * 42 is chosen because it is 2x the A4 size 29.7 * 21 cm
double ll_x, ll_y, ur_x, ur_y;
((FlowNode*)ctx->a[0])->measure(&ll_x, &ll_y, &ur_x, &ur_y);
double height = 60 * (ur_y - ll_y);
double width = (210.0 / 297.0) * height;
if (printer.orientation() == QPrinter::Landscape) {
height = 42 * (ur_y - ll_y);
width = height / (210.0 / 297.0);
}
ctx_settings settings = BeginPrint(&printer, &painter, ctx, &(widget->image));
for (int i = 0;; i++) {
ll_y = i * height;
ur_y = ll_y + height;
if (ll_y > ctx->y_high)
break;
PrintPage(&painter, title, ctx, &(widget->image), 0, ll_y, width, ur_y, i+1);
if (ur_y < ctx->y_high) {
printer.newPage();
}
}
widget->image = imageTmp;
EndPrint(ctx, &settings);
}
return WOW__SUCCESS;
}
pwr_tStatus CoWowQt::CreateFlowPrintDialogQt(const char* title, void* flow_ctx, QWidget* w)
{
if (m_printdialog_disable && streq(m_default_printer, "")) {
return WOW__PRINTDIALOGDISABLED;
}
assert(dynamic_cast<QtScrollWidgetFlow*>(w) != NULL);
QtScrollWidgetFlow* widget = dynamic_cast<QtScrollWidgetFlow*>(w);
QImage imageTmp(widget->image);
QPrinter printer(QPrinter::HighResolution);
if (PrintDialog(&printer, &imageTmp, widget)) {
flow_tCtx ctx = (flow_tCtx)flow_ctx;
QPainter painter(&printer);
widget->image = QImage(printer.pageRect().width(), printer.pageRect().height() - GetPrintHeaderMargin(&painter), QImage::Format_RGB32);
ctx_settings settings = BeginPrint(&printer, &painter, ctx, &(widget->image));
int num_pages = 0;
for (int i = 0; i < ctx->a.size(); i++) {
if (ctx->a[i]->type() == flow_eObjectType_Node && ((FlowNode*)ctx->a[i])->nc->group == flow_eNodeGroup_Document) {
num_pages++;
}
}
int j = 1;
for (int i = 0; i < ctx->a.size(); i++) {
if (ctx->a[i]->type() == flow_eObjectType_Node) {
FlowNode* elem = ((FlowNode*)ctx->a[i]);
if (elem->nc->group == flow_eNodeGroup_Document) {
PrintPage(&painter, title, ctx, &(widget->image), elem->x_left, elem->y_low, elem->x_right, elem->y_high, j);
if (j < num_pages) {
printer.newPage();
j++;
}
}
}
}
widget->image = imageTmp;
EndPrint(ctx, &settings);
}
return WOW__SUCCESS;
}
\ No newline at end of file
......@@ -216,25 +216,9 @@ public:
const char* name, void* menu, int pixmap, int append, void* w);
pwr_tStatus DeleteMenuItem(const char* name, void* menu);
void CreateBrowPrintDialog(const char* title, void* brow_ctx, int orientation,
double scale, void* parent_widget, pwr_tStatus* sts)
{
CreateBrowPrintDialogQt(
title, brow_ctx, orientation, scale, parent_widget, sts);
}
static void CreateBrowPrintDialogQt(const char* title, void* brow_ctx,
int orientation, double scale, void* parent_widget, pwr_tStatus* sts);
void CreateFlowPrintDialog(const char* title, void* flow_ctx, int orientation,
double scale, void* parent_widget, pwr_tStatus* sts)
{
CreateFlowPrintDialogQt(
title, flow_ctx, orientation, scale, parent_widget, sts);
}
static pwr_tStatus CreateBrowPrintDialogQt(const char* title, void* flow_ctx, QWidget* brow_widget);
static pwr_tStatus CreateFlowPrintDialogQt(const char* title, void* flow_ctx, QWidget* flow_widget);
static void CreateFlowPrintDialogQt(const char* title, void* flow_ctx,
int orientation, double scale, void* parent_widget, pwr_tStatus* sts);
CoWowTimer* timer_new();
void SetParent(QWidget* parent);
......
......@@ -147,13 +147,10 @@ void CoXHelpQt::set_dimension(int width, int height)
void CoXHelpQt::print()
{
pwr_tStatus sts;
char title[80];
strcpy(title, qPrintable(translate_utf8("Help")));
CoWowQt::CreateBrowPrintDialogQt(title, xhelpnav->brow->ctx,
flow_eOrientation_Portrait, 0.7, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, xhelpnav->brow->ctx, brow_widget);
}
void CoXHelpQtWidget::closeEvent(QCloseEvent* event)
......
......@@ -45,7 +45,6 @@
#include "flow_browwidget_qt.h"
#include "flow_draw_qt.h"
#include "flow_msg.h"
#include "flow_printdraw_qt.h"
#include "flow_scroll_widget_qt.h"
#include "flow_widget_qt.h"
......@@ -1812,10 +1811,9 @@ int FlowDrawQt::image_load(const char* imagefile, float scale, float nav_scale,
return 1;
}
FlowPrintDraw* FlowDrawQt::print_draw_new(void* context, const char* title,
int page, void* flow_ctx, int page_border, int* sts)
{
FlowPrintDrawQt* pd
= new FlowPrintDrawQt(context, title, page, flow_ctx, page_border, sts);
return (FlowPrintDraw*)pd;
FlowPrintDraw* FlowDrawQt::print_draw_new(void* context, const char* title, int page,
void* flow_ctx, int page_border, int* sts) {
fprintf(stderr, "ERROR!\nFlowDrawQt::print_draw_new called.\nThis should never happend!\n");
assert(false);
return NULL;
}
\ No newline at end of file
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#include <math.h>
#include "cow_qt_helpers.h"
#include "flow_printdraw_qt.h"
FlowPrintDrawQt::FlowPrintDrawQt(void* context, const char* t, int p,
void* flow_ctx, int page_border, int* sts)
: painter((QPainter*)context), border(page_border), ctx((FlowCtx*)flow_ctx),
show_red(1), page(p)
{
strncpy(title, t, sizeof(title));
if (ctx->type() == flow_eCtxType_Flow) {
print_margin_x = 10;
print_margin_y = 10;
}
print_margin_x = print_margin_y = 0;
*sts = 1;
}
FlowPrintDrawQt::~FlowPrintDrawQt()
{
debug_print("FlowPrintDrawQt::~FlowPrintDrawQt\n");
}
int FlowPrintDrawQt::print_page(
double ll_x, double ll_y, double ur_x, double ur_y)
{
if (ctx->type() == flow_eCtxType_Flow) {
if (ur_x - ll_x > ur_y - ll_y) {
print_margin_x = 10;
print_margin_y = 60;
} else {
print_margin_x = 60;
print_margin_y = 10;
}
}
print_margin_x = print_margin_y = 0;
if (ur_x - ll_x > ur_y - ll_y) {
ctx->print_zoom_factor = 730 / (ur_x - ll_x);
} else {
ctx->print_zoom_factor = 730 / (ur_y - ll_y);
}
ctx->print_zoom();
page_x = ll_x * ctx->print_zoom_factor;
page_y = ll_y * ctx->print_zoom_factor;
double width = painter->window().width();
double height = painter->window().height();
if (ctx->type() == flow_eCtxType_Brow) {
QPen pen = QPen(QColor::fromRgbF(0, 0, 0));
pen.setWidthF(0.5);
painter->setPen(pen);
painter->drawLine(
print_margin_x, print_margin_y, print_margin_x + width, print_margin_y);
painter->setFont(QFont("Lucida Sans", 9));
char page_str[40];
sprintf(page_str, "Page %d", page + 1);
painter->drawText(
print_margin_x + width - 90, print_margin_y - height, fl(page_str));
painter->drawText(print_margin_x, print_margin_y - height, fl(title));
}
painter->setClipRect(print_margin_x, print_margin_y,
(ur_x - ll_x) * ctx->print_zoom_factor,
(ur_y - ll_y) * ctx->print_zoom_factor);
painter->setClipping(true);
((FlowCtx*)ctx)->current_print = this;
((FlowCtx*)ctx)->print(ll_x, ll_y, ur_x, ur_y);
painter->setClipping(false);
return 1;
}
int FlowPrintDrawQt::rect(double x, double y, double width, double height,
flow_eDrawType type, double idx, int highlight)
{
QPen pen;
if (highlight || type == flow_eDrawType_LineRed) {
pen = QPen(QColor::fromRgbF(1, 0, 0));
} else {
pen = QPen(QColor::fromRgbF(0, 0, 0));
}
pen.setWidth(0.5 * idx);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawRect(
print_margin_x + x - page_x, print_margin_y + y - page_y, width, height);
return 1;
}
int FlowPrintDrawQt::filled_rect(double x, double y, double width,
double height, flow_eDrawType type, double idx)
{
switch (type) {
case flow_eDrawType_LineRed:
painter->setBrush(QBrush(QColor::fromRgbF(1, 0, 0)));
break;
case flow_eDrawType_Green:
painter->setBrush(QBrush(QColor::fromRgbF(0, 1, 0)));
break;
case flow_eDrawType_Yellow:
painter->setBrush(QBrush(QColor::fromRgbF(1, 1, 0)));
break;
case flow_eDrawType_DarkGray:
painter->setBrush(QBrush(QColor::fromRgbF(0.3, 0.3, 0.3)));
break;
default:
painter->setBrush(QBrush(QColor::fromRgbF(0, 0, 0)));
}
QPen pen = QPen(QColor::fromRgbF(0, 0, 0));
pen.setWidth(0.5 * idx);
painter->setPen(pen);
painter->drawRect(
print_margin_x + x - page_x, print_margin_y + y - page_y, width, height);
return 1;
}
int FlowPrintDrawQt::arc(double x, double y, double width, double height,
int angle1, int angle2, flow_eDrawType type, double idx, int highlight)
{
QPen pen;
if (highlight || type == flow_eDrawType_LineRed
|| type == flow_eDrawType_LineDashedRed) {
pen = QPen(QColor::fromRgbF(1, 0, 0));
} else {
pen = QPen(QColor::fromRgbF(0, 0, 0));
}
if (type == flow_eDrawType_LineDashed
|| type == flow_eDrawType_LineDashedRed) {
QVector<double> dashes;
dashes << 4 << 2;
pen.setDashPattern(dashes);
}
pen.setWidth(0.5 * idx);
painter->setPen(pen);
painter->drawArc(print_margin_x + x + width / 2 - page_x,
print_margin_y + y + height / 2 - page_y, width, width,
-M_PI * (angle1 + angle2) / 180, -M_PI * angle1 / 180);
if (type == flow_eDrawType_LineDashed
|| type == flow_eDrawType_LineDashedRed) {
QPen pen = painter->pen();
pen.setStyle(Qt::SolidLine);
painter->setPen(pen);
}
return 1;
}
int FlowPrintDrawQt::line(double x1, double y1, double x2, double y2,
flow_eDrawType type, double idx, int highlight)
{
QPen pen;
switch (type) {
case flow_eDrawType_LineGray:
pen = QPen(QColor::fromRgbF(0.7, 0.7, 0.7));
break;
case flow_eDrawType_LineRed:
case flow_eDrawType_LineDashedRed:
pen = QPen(QColor::fromRgbF(1, 0, 0));
break;
default:
pen = QPen(QColor::fromRgbF(0, 0, 0));
break;
}
if (type == flow_eDrawType_LineDashed
|| type == flow_eDrawType_LineDashedRed) {
QVector<double> dashes;
dashes << 4 << 2;
pen.setDashPattern(dashes);
}
pen.setWidth(0.5 * idx);
painter->setPen(pen);
painter->drawLine(print_margin_x + x1 - page_x, print_margin_y + y1 - page_y,
print_margin_x + x2 - page_x, print_margin_y + y2 - page_y);
if (type == flow_eDrawType_LineDashed
|| type == flow_eDrawType_LineDashedRed) {
QPen pen = painter->pen();
pen.setStyle(Qt::SolidLine);
painter->setPen(pen);
}
return 1;
}
int FlowPrintDrawQt::text(double x, double y, char* text, int len,
flow_eDrawType type, double size, int line)
{
QFont font;
switch (type) {
case flow_eDrawType_TextHelvetica:
font = QFont(fl("Lucida Sans"), -1);
break;
case flow_eDrawType_TextHelveticaBold:
font = QFont(fl("Lucida Sans"), -1, QFont::Bold);
break;
default:;
}
font.setPointSizeF(size);
char* s;
for (s = text; *s; s++) {
if (*s == 10) {
break;
}
}
if (s - text > 0) {
QString textutf8 = QString::fromLatin1(text, s - text);
painter->setFont(font);
painter->setBrush(QBrush(QColor::fromRgbF(0, 0, 0)));
painter->drawText(
print_margin_x + x - page_x, print_margin_y + y - page_y, textutf8);
}
return 1;
}
int FlowPrintDrawQt::pixmap(
double x, double y, flow_sPixmapDataElem* data, flow_eDrawType type)
{
float scale = 0.7;
painter->scale(scale, scale);
painter->drawPixmap((print_margin_x + x - page_x) / scale,
(print_margin_y + y - page_y) / scale, *((QPixmap*)data));
painter->scale(1.0 / scale, 1.0 / scale);
return 1;
}
int FlowPrintDrawQt::image(double x, double y, double width, double height,
flow_tImImage image, flow_eDrawType type)
{
float scale = width / ((QImage*)image)->width();
painter->scale(scale, scale);
painter->drawImage((print_margin_x + x - page_x) / scale,
(print_margin_y + y - page_y) / scale, *((QImage*)image));
painter->scale(1.0 / scale, 1.0 / scale);
return 1;
}
int FlowPrintDrawQt::arrow(double x1, double y1, double x2, double y2,
double x3, double y3, flow_eDrawType type, double idx)
{
switch (type) {
case flow_eDrawType_LineRed:
painter->setPen(QColor::fromRgbF(1, 0, 0));
painter->setBrush(QBrush(QColor::fromRgbF(1, 0, 0)));
break;
case flow_eDrawType_LineGray:
painter->setPen(QColor::fromRgbF(0.7, 0.7, 0.7));
painter->setBrush(QBrush(QColor::fromRgbF(0.7, 0.7, 0.7)));
break;
default:
painter->setPen(QColor::fromRgbF(0, 0, 0));
painter->setBrush(QBrush(QColor::fromRgbF(0, 0, 0)));
break;
}
QPainterPath path;
path.moveTo(print_margin_x + x1 - page_x, print_margin_y + y1 - page_y);
path.lineTo(print_margin_x + x2 - page_x, print_margin_y + y2 - page_y);
path.lineTo(print_margin_x + x3 - page_x, print_margin_y + y3 - page_y);
path.lineTo(print_margin_x + x1 - page_x, print_margin_y + y1 - page_y);
painter->fillPath(path, painter->brush());
return 1;
}
\ No newline at end of file
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef flow_printdraw_qt_h
#define flow_printdraw_qt_h
#include "flow_printdraw.h"
#include <QPainter>
class FlowPrintDrawQt : public FlowPrintDraw {
public:
FlowPrintDrawQt(void* context, const char* title, int page, void* flow_ctx,
int page_border, int* sts);
~FlowPrintDrawQt();
int print_page(double ll_x, double ll_y, double ur_x, double ur_y);
int rect(double x, double y, double width, double height, flow_eDrawType type,
double idx, int highlight);
int filled_rect(double x, double y, double width, double height,
flow_eDrawType type, double idx);
int arc(double x, double y, double width, double height, int angle1,
int angle2, flow_eDrawType type, double idx, int highlight);
int line(double x1, double y1, double x2, double y2, flow_eDrawType type,
double idx, int highlight);
int text(double x, double y, char* text, int len, flow_eDrawType type,
double size, int line);
int pixmap(
double x, double y, flow_sPixmapDataElem* data, flow_eDrawType type);
int image(double x, double y, double width, double height,
flow_tImImage image, flow_eDrawType type);
int arrow(double x1, double y1, double x2, double y2, double x3, double y3,
flow_eDrawType type, double idx);
void set_showred(int show)
{
show_red = show;
}
QPainter* painter;
int border;
FlowCtx* ctx;
int show_red;
double page_x;
double page_y;
char title[80];
int page;
};
#endif
\ No newline at end of file
......@@ -353,8 +353,7 @@ void CLogQt::print()
strcat(title, nodename);
}
wow->CreateBrowPrintDialog(title, clognav->brow->ctx,
flow_eOrientation_Landscape, 1.0, toplevel, &sts);
sts = CoWowQt::CreateBrowPrintDialogQt(title, clognav->brow->ctx, clognav_widget);
if (sts == WOW__PRINTDIALOGDISABLED) {
wow->DisplayError("Disabled", "Print Dialog is disabled");
}
......
......@@ -103,8 +103,7 @@ void EvListQt::print(const char* title)
strcat(print_title, nodename);
}
CoWowQt::CreateBrowPrintDialogQt(print_title, brow->ctx,
flow_eOrientation_Landscape, 1.0, form_widget, &sts);
sts = CoWowQt::CreateBrowPrintDialogQt(print_title, brow->ctx, brow_widget);
if (sts == WOW__PRINTDIALOGDISABLED) {
pwr_tFileName filename;
pwr_tCmd cmd;
......
......@@ -63,10 +63,7 @@
void RtTraceQtWidget::activate_print()
{
pwr_tStatus sts;
CoWowQt::CreateFlowPrintDialogQt(
"Trace", rt->flow_ctx, flow_eOrientation_Landscape, 1.0, this, &sts);
CoWowQt::CreateFlowPrintDialogQt("Trace", rt->flow_ctx, rt->flow_widget);
}
void RtTraceQtWidget::activate_printselect()
......
......@@ -323,14 +323,12 @@ void XAttQt::pop()
void XAttQt::print()
{
pwr_tAName title;
pwr_tStatus sts = gdh_AttrrefToName(&objar, title, sizeof(title), cdh_mNName);
if (EVEN(sts)) {
return;
}
CoWowQt::CreateBrowPrintDialogQt(title, xattnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, xattnav->brow->ctx, brow_widget);
}
void XAttQtWidget::closeEvent(QCloseEvent* event)
......
......@@ -403,10 +403,7 @@ void XColWindQt::get_window_size(int* w, int* h)
void XColWindQt::print()
{
pwr_tStatus sts;
wow->CreateBrowPrintDialog(title, xattnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, xattnav->brow->ctx, brow_widget);
}
void XColWindQtWidget::closeEvent(QCloseEvent* event)
......
......@@ -86,16 +86,13 @@ void XCrrQt::pop()
void XCrrQt::print()
{
pwr_tStatus sts;
pwr_tAName title;
sts = gdh_AttrrefToName(&objar, title, sizeof(title), cdh_mNName);
pwr_tStatus sts = gdh_AttrrefToName(&objar, title, sizeof(title), cdh_mNName);
if (EVEN(sts)) {
return;
}
CoWowQt::CreateBrowPrintDialogQt(title, xcrrnav->brow->ctx,
flow_eOrientation_Portrait, 1.0, toplevel, &sts);
CoWowQt::CreateBrowPrintDialogQt(title, xcrrnav->brow->ctx, brow_widget);
}
void XCrrQtWidget::closeEvent(QCloseEvent* event)
......
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