Commit 48e3a402 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: fixed error when loading certain image files.

parent d259aa92
......@@ -63,7 +63,6 @@ Wtt* WbQt::wtt_new(const char* name, const char* iconname,
ldh_tWBContext ldhwbctx, pwr_tVolumeId volid, ldh_tVolume volctx,
wnav_sStartMenu* root_menu, pwr_tStatus* status)
{
debug_print("Creating a WttQt\n");
return new WttQt(
0, toplevel, name, iconname, ldhwbctx, volid, volctx, root_menu, status);
}
......@@ -273,14 +272,15 @@ WbQt::WbQt(int argc, char* argv[]) : mainwindow(0)
}
if (sw_projectvolume && !login_display) {
Wtt* wtt;
char projectname[80];
pwr_tVolumeId volume = ldh_cDirectoryVolume;
utl_get_projectname(projectname);
strcpy(title, CoLogin::username());
strcat(title, " on ");
strcat(title, projectname);
wtt = wtt_new(title, "Navigator", wbctx, volume, 0, 0, &sts);
debug_print("Opening project volume %s\n", projectname);
Wtt* wtt = wtt_new(title, "Navigator", wbctx, volume, 0, 0, &sts);
debug_print("Opening project volume sts=%d\n", sts);
if (ODD(sts)) {
appl_count++;
wtt->close_cb = Wb::wtt_close;
......@@ -291,11 +291,14 @@ WbQt::WbQt(int argc, char* argv[]) : mainwindow(0)
psts(sts, NULL);
}
} else if (sw_classeditor) {
debug_print("Opening class editor\n");
wtt_open_volume(
0, wb_eType_ClassEditor, filename, wow_eFileSelType_WblClass);
} else if (sw_projectlist) {
debug_print("Opening project list\n");
wtt_open_volume(0, wb_eType_ExternVolume, "ProjectList", wow_eFileSelType_);
} else if (nav_display && !login_display) {
debug_print("Opening navigator\n");
if (CoLogin::privilege() & pwr_mPrv_DevRead) {
strcpy(title, "PwR Navigator: ");
strcat(title, CoLogin::username());
......@@ -308,7 +311,7 @@ WbQt::WbQt(int argc, char* argv[]) : mainwindow(0)
exit(LOGIN__NOPRIV);
}
} else if (login_display) {
debug_print("Creating a CoLoginQt\n");
debug_print("Opening a CoLoginQt\n");
new CoLoginQt(NULL, mainwindow, "PwR Login", systemgroup,
&Wb::login_success, &Wb::login_cancel, 0, &sts);
}
......
......@@ -40,6 +40,7 @@
#include "wb_wge_qt.h"
#include <QApplication>
#include <QMenuBar>
#include <QMessageBox>
#include <QVBoxLayout>
......@@ -170,6 +171,8 @@ void WGeQt::set_size(int width, int height)
void WGeQt::set_subwindow_release()
{
subwindow_release = 1;
debug_print("Shutting down...\n");
QApplication::exit();
}
void WGeQt::pop()
......@@ -182,6 +185,8 @@ void WGeQtWidget::closeEvent(QCloseEvent* event)
debug_print("WGeQtWidget::closeEvent\n");
if (ge->modal) {
ge->terminated = 1;
debug_print("Shutting down...\n");
QApplication::exit();
} else {
delete ge;
}
......@@ -235,7 +240,6 @@ WGeQt::WGeQt(QWidget* wge_parent_wid, void* wge_parent_ctx, char* wge_name,
QObject::connect(((GraphQt*)graph)->grow_widget,
SIGNAL(resize_signal(QResizeEvent*)), toplevel,
SLOT(action_resize(QResizeEvent*)));
// TODO: grow_widget must emit a resize_signal signal in resizeEvent()
if (wge_menu) {
QMenuBar* menu_bar = new QMenuBar();
......@@ -267,6 +271,8 @@ WGeQt::WGeQt(QWidget* wge_parent_wid, void* wge_parent_ctx, char* wge_name,
toplevel->setLayout(graph_form);
toplevel->show();
debug_print("Should be visible now...\n");
if (navigator) {
// Create navigator popup
nav_shell = new QWidget();
......
......@@ -59,6 +59,7 @@
#include "wb_wrev_qt.h"
#include "wb_xcrr_qt.h"
#include <QApplication>
#include <QColor>
#include <QInputDialog>
#include <QLayout>
......@@ -447,10 +448,14 @@ WAttText* WNavQt::watttext_new(
void WNavQt::wge_subwindow_loop(WGe* wge)
{
debug_print(" before wge_subwindow_loop\n");
QApplication::exec();
debug_print(" after wge_subwindow_loop\n");
}
void WNavQt::wge_modal_loop(WGe* wge)
{
QApplication::exec();
}
void WNavQt::message_dialog(char* title, char* text)
......
......@@ -48,10 +48,6 @@ MsgListQt::MsgListQt(void* ev_parent_ctx, QWidget* ev_parent_wid, QWidget** w)
form_widget
= scrolledbrowwidgetqt_new(MsgList::init_brow_cb, this, &brow_widget);
// The widget is not realized until it has processed a show event. By calling
// widget->show(), Qt processes the show event at some arbitrary time in the
// future. But in order to use the widget, we need to realize it NOW!
// This way, we force Qt to process the show() event immediately.
showNow(brow_widget);
// Create the root item
......
......@@ -93,7 +93,7 @@ static char font_names[draw_eFont__][DRAW_FONT_SIZE][80]
"-*-Helvetica-Medium-R-Normal--18-*-*-*-P-*-ISO8859-1",
"-*-Helvetica-Medium-R-Normal--24-*-*-*-P-*-ISO8859-1" } };
static QMouseEvent *last_event;
static QMouseEvent* last_event;
static QColor flow_allocate_color(
FlowDrawQt* draw_ctx, const char* named_color);
......@@ -253,7 +253,8 @@ void FlowDrawQt::delete_secondary_ctx(FlowCtx* ctx)
FlowDrawQt::FlowDrawQt(QWidget* x_toplevel, void** flow_ctx,
int (*init_proc)(QWidget* w, FlowCtx* ctx, void* client_data),
void* client_data, flow_eCtxType type)
: toplevel(x_toplevel), nav_toplevel(0), window(0), nav_window(0), closing_down(0)
: toplevel(x_toplevel), nav_toplevel(0), window(0), nav_window(0),
closing_down(0)
{
timer_id = new QTimer(this);
......@@ -331,8 +332,8 @@ int FlowDrawQt::event_handler(QEvent* event)
switch (event->type()) {
case QEvent::KeyPress: {
QKeyEvent* keyEvent = ((QKeyEvent*)event);
debug_print("event_handler: KeyPress key=%s\n",
QKeySequence(keyEvent->key()).toString().toAscii().data());
// debug_print("event_handler: KeyPress key=%s\n",
// QKeySequence(keyEvent->key()).toString().toAscii().data());
switch (keyEvent->key()) {
case Qt::Key_Return:
......@@ -396,10 +397,9 @@ int FlowDrawQt::event_handler(QEvent* event)
}
case QEvent::MouseButtonPress: {
QMouseEvent* mouseEvent = ((QMouseEvent*)event);
debug_print("event_handler: MouseButtonPress button=%d, x=%d, y=%d, "
"globalX=%d, globalY=%d\n",
mouseEvent->button(), mouseEvent->x(), mouseEvent->y(),
mouseEvent->globalX(), mouseEvent->globalY());
// debug_print("event_handler: MouseButtonPress button=%d, x=%d, y=%d,
// globalX=%d, globalY=%d\n", mouseEvent->button(), mouseEvent->x(),
// mouseEvent->y(), mouseEvent->globalX(), mouseEvent->globalY());
switch (mouseEvent->button()) {
case Qt::LeftButton:
basectx->event_handler(
......@@ -474,7 +474,7 @@ int FlowDrawQt::event_handler(QEvent* event)
event_timer(mouseEvent);
return 1;
} else {
debug_print("event_handler: MouseButtonPress from timer\n");
// debug_print("event_handler: MouseButtonPress from timer\n");
/* Press event, callback from timer */
button_pressed = 0;
button_clicked_and_pressed = 0;
......@@ -533,8 +533,8 @@ int FlowDrawQt::event_handler(QEvent* event)
}
case QEvent::MouseButtonRelease: {
QMouseEvent* mouseEvent = ((QMouseEvent*)event);
debug_print("event_handler: MouseButtonRelease button=%d\n",
mouseEvent->button());
// debug_print("event_handler: MouseButtonRelease button=%d\n",
// mouseEvent->button());
button1_pressed = 0;
button2_pressed = 0;
button3_pressed = 0;
......@@ -777,7 +777,7 @@ int FlowDrawQt::event_handler(QEvent* event)
case QEvent::FocusOut:
break;
case QEvent::Wheel: {
debug_print("event_handler: Wheel\n");
// debug_print("event_handler: Wheel\n");
QWheelEvent* wheelEvent = ((QWheelEvent*)event);
if (wheelEvent->delta() > 0) {
sts = basectx->event_handler(flow_eEvent_ScrollUp, 0, 0, 0, 0);
......@@ -793,8 +793,8 @@ int FlowDrawQt::event_handler(QEvent* event)
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent* mouseEvent = ((QMouseEvent*)event);
debug_print(
"event_handler: MouseButtonPress button=%d\n", mouseEvent->button());
// debug_print("event_handler: MouseButtonPress button=%d\n",
// mouseEvent->button());
switch (mouseEvent->button()) {
case Qt::LeftButton: // Button1
button1_pressed = 1;
......@@ -816,8 +816,8 @@ int FlowDrawQt::event_handler(QEvent* event)
}
case QEvent::MouseButtonRelease: {
QMouseEvent* mouseEvent = ((QMouseEvent*)event);
debug_print("event_handler: MouseButtonRelease button=%d\n",
mouseEvent->button());
// debug_print("event_handler: MouseButtonRelease button=%d\n",
// mouseEvent->button());
switch (mouseEvent->button()) {
case Qt::LeftButton: // Button1
button1_pressed = 0;
......@@ -847,7 +847,7 @@ int FlowDrawQt::event_handler(QEvent* event)
break;
}
case QEvent::MouseMove: {
debug_print("event_handler: MouseMove\n");
// debug_print("event_handler: MouseMove\n");
QPoint pos = QCursor::pos();
if (button1_pressed || button2_pressed || button3_pressed) {
sts = basectx->event_handler_nav(
......@@ -1223,7 +1223,8 @@ static QFont font(flow_eDrawType painter_type, double size)
{
QFont res(FONTSTR);
res.setPointSizeF(FONT_SCALE * size);
if (painter_type == flow_eDrawType_TextHelveticaBold || painter_type == flow_eDrawType_TextHelveticaEraseBold) {
if (painter_type == flow_eDrawType_TextHelveticaBold
|| painter_type == flow_eDrawType_TextHelveticaEraseBold) {
res.setWeight(QFont::Bold);
}
return res;
......@@ -1598,8 +1599,8 @@ void FlowDrawQt::get_window_size(FlowCtx* ctx, int* width, int* height)
void FlowDrawQt::get_nav_window_size(FlowCtx* ctx, int* width, int* height)
{
debug_print(
"get_nav_window_size, nav_window == NULL ? %d\n", (nav_window == NULL));
// debug_print("get_nav_window_size, nav_window == NULL ? %d\n", (nav_window
// == NULL));
*width = nav_window->width();
*height = nav_window->height();
}
......@@ -1634,12 +1635,13 @@ void FlowDrawQt::cancel_event_timer()
}
}
void FlowDrawQt::event_timer(QMouseEvent *event)
void FlowDrawQt::event_timer(QMouseEvent* event)
{
if (last_event) {
delete last_event;
}
last_event = new QMouseEvent(event->type(), event->pos(), event->globalPos(), event->button(), event->buttons(), event->modifiers());
last_event = new QMouseEvent(event->type(), event->pos(), event->globalPos(),
event->button(), event->buttons(), event->modifiers());
initOneShotTimer(timer_id, SLOT(event_timer_cb()), 200);
}
......@@ -1743,7 +1745,7 @@ void FlowDrawQt::copy_area(FlowCtx* ctx, int x, int y)
return;
}
debug_print("copy_area: x=%d, y=%d\n", x, 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);
......@@ -1810,7 +1812,7 @@ void FlowDrawQt::clear_area(
void FlowDrawQt::set_inputfocus(FlowCtx* ctx)
{
debug_print("set_inputfocus\n");
// debug_print("set_inputfocus\n");
window->setFocus(Qt::OtherFocusReason);
}
......@@ -1869,6 +1871,7 @@ void FlowDrawQt::image_scale(float scale, flow_tImImage orig_im,
if (*im) {
delete ((QImage*)*im);
}
// debug_print("image_scale\n");
*im = new QImage(((QImage*)orig_im)->scaled(width, height));
}
......@@ -1882,7 +1885,7 @@ int FlowDrawQt::image_load(const char* imagefile, float scale, float nav_scale,
strcpy(filename, imagefile);
debug_print("image_load %s\n", imagefile);
// debug_print("image_load %s\n", imagefile);
// Look for file in $pwrp_exe, $pwr_doc/en_us/orm and $pwr_exe
for (int i = 0; i < 3; i++) {
......
......@@ -49,6 +49,9 @@
void QtScrollWidgetFlow::createBuffer(QSize size)
{
if (size.isEmpty()) {
return;
}
this->image = QImage(size, QImage::Format_RGB32);
QPainter imPainter(&image);
imPainter.fillRect(image.rect(), palette().color(QPalette::Background));
......@@ -253,8 +256,7 @@ bool QtScrollWidgetFlow::event(QEvent* event)
if (event->type() == QEvent::Resize) {
createBuffer(((QResizeEvent*)event)->size());
}
if (!is_realized
&& (event->type() == QEvent::Show || event->type() == QEvent::Resize)) {
if (!is_realized && event->type() == QEvent::Show) {
realize();
is_realized = true;
}
......
......@@ -141,7 +141,7 @@ static char font_names[glow_eFont__][glow_eDrawFont__][DRAW_FONT_SIZE][80] = {
"-*-courier-Medium-R-Normal--24-*-*-*-m-*-ISO8859-1" } }
};
static QMouseEvent *last_event;
static QMouseEvent* last_event;
static QColor glow_allocate_named_color(
GlowDrawQt* draw_ctx, const char* named_color);
......@@ -179,14 +179,13 @@ static QColor draw_type_to_color(
QColor* color_array;
int sts = glow_read_color_file(
"/home/claes/test/ge_colors.dat", &color_array, &size);
if (sts) {
QColor* color_p = color_array + (painter_type - glow_eDrawType_Color4);
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());
draw_ctx, color_p.red(), color_p.green(), color_p.blue());
delete color_array;
return color;
}
return glow_allocate_named_color(draw_ctx, "black");
}
double r, g, b;
......@@ -970,8 +969,12 @@ int GlowDrawQt::rect_helper(GlowWind* wind, int painter_type, int size, int x,
}
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()));
painter->fillRect(x, y, width, height, painter->brush());
} else {
// debug_print("drawRect [%d, %d, %d, %d]\n", x, y, width, height);
painter->setBrush(Qt::NoBrush);
painter->drawRect(x, y, width, height);
}
......@@ -1019,6 +1022,7 @@ int GlowDrawQt::arrow_helper(GlowWind* wind, int painter_type, int size, int x1,
QPainterPath path;
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;
......@@ -1072,8 +1076,12 @@ int GlowDrawQt::arc_helper(GlowWind* wind, int painter_type, int size, int x,
}
if (fill) {
// debug_print("pie [%d, %d, %d, %d], %d, %d\n", x, y, width, height, angle1
// * 64, angle2 * 64);
painter->drawPie(x, y, width, height, angle1 * 64, angle2 * 64);
} else {
// debug_print("arc [%d, %d, %d, %d], %d, %d\n", x, y, width, height, angle1
// * 64, angle2 * 64);
painter->setBrush(Qt::NoBrush);
painter->drawArc(x, y, width, height, angle1 * 64, angle2 * 64);
}
......@@ -1206,6 +1214,7 @@ int GlowDrawQt::line_helper(GlowWind* wind, int painter_type, int size, int x1,
painter->setPen(pen);
}
// debug_print("line (%d, %d) (%d, %d)\n", x1, y1, x2, y2);
painter->drawLine(x1, y1, x2, y2);
delete painter;
......@@ -1271,6 +1280,8 @@ int GlowDrawQt::polyline_helper(GlowWind* wind, int painter_type, int size,
if (!fill) {
painter->setBrush(Qt::NoBrush);
}
// debug_print("polyline painter_type=%d, fill=%d, point_cnt=%d\n",
// painter_type, fill, point_cnt);
painter->drawPolygon(qpoints, point_cnt);
delete qpoints;
......@@ -1484,6 +1495,7 @@ int GlowDrawQt::image_helper(GlowWind* wind, int x, int y, int width,
set_clip(w, painter);
}
// debug_print("image [%d, %d, %d, %d]\n", x, y, width, height);
if (d) {
painter->drawImage(QPoint(x, y), *((QImage*)image));
} else {
......@@ -1599,12 +1611,13 @@ void GlowDrawQt::cancel_event_timer()
timer_id->stop();
}
void GlowDrawQt::event_timer(QMouseEvent *event)
void GlowDrawQt::event_timer(QMouseEvent* event)
{
if (last_event) {
delete last_event;
}
last_event = new QMouseEvent(event->type(), event->pos(), event->globalPos(), event->button(), event->buttons(), event->modifiers());
last_event = new QMouseEvent(event->type(), event->pos(), event->globalPos(),
event->button(), event->buttons(), event->modifiers());
initOneShotTimer(timer_id, SLOT(event_timer_cb()), 200);
}
......@@ -1686,7 +1699,8 @@ int GlowDrawQt::get_text_extent(const char* text, int len,
int font_type = get_font_type(painter_type);
QFontMetrics fontMetrics = QFontMetrics(QFont(font_names[font_idx][font_type][idx]));
QFontMetrics fontMetrics
= QFontMetrics(QFont(font_names[font_idx][font_type][idx]));
QRect rect = fontMetrics.boundingRect(QString::fromLocal8Bit(text, len));
*width = rect.width();
int text_ascent = fontMetrics.ascent();
......@@ -1850,6 +1864,8 @@ void GlowDrawQt::set_background(GlowWind* wind, glow_eDrawType drawtype,
delete w->background_pixmap;
}
// debug_print("set_background\n");
*(w->background_pixmap) = QPixmap::fromImage(*((QImage*)image));
w->background_pixmap_width = pixmap_width;
w->background_pixmap_height = pixmap_height;
......@@ -2392,7 +2408,9 @@ void GlowDrawQt::image_copy(glow_tImImage orig_image, glow_tImImage* image)
delete ((QImage*)*image);
}
*(*((QImage**)image)) = ((QImage*)orig_image)->copy();
// debug_print("image_copy\n");
*image = new QImage(((QImage*)orig_image)->copy());
}
void GlowDrawQt::image_rotate(
......@@ -2402,6 +2420,9 @@ void GlowDrawQt::image_rotate(
drot = int((float(drot) / 360 - floor(float(drot) / 360)) * 360);
QTransform trans;
trans.rotate(drot);
// debug_print("image_rotate\n");
QImage* im = new QImage(((QImage*)*image)->transformed(trans));
delete ((QImage*)*image);
*image = (glow_tImImage)im;
......@@ -2409,6 +2430,8 @@ void GlowDrawQt::image_rotate(
void GlowDrawQt::image_flip_vertical(glow_tImImage* image)
{
// debug_print("image_flip_vertical\n");
QImage* im = new QImage(((QImage*)*image)->mirrored());
delete ((QImage*)*image);
*image = (glow_tImImage)im;
......@@ -2416,6 +2439,8 @@ void GlowDrawQt::image_flip_vertical(glow_tImImage* image)
void GlowDrawQt::image_flip_horizontal(glow_tImImage* image)
{
// debug_print("image_flip_horizontal\n");
QImage* im = new QImage(((QImage*)*image)->mirrored(true, false));
delete ((QImage*)*image);
*image = (glow_tImImage)im;
......@@ -2425,6 +2450,8 @@ int GlowDrawQt::image_scale(int width, int height, glow_tImImage orig_im,
glow_tImImage* im, glow_tImData* im_data, glow_tPixmap* im_pixmap,
glow_tPixmap* im_mask)
{
// debug_print("image_scale\n");
if (width == ((QImage*)*im)->width() && height == ((QImage*)*im)->height()) {
return 0;
}
......@@ -2485,7 +2512,7 @@ int GlowDrawQt::image_load(char* imagefile, glow_tImImage* orig_im,
} else
#endif
{
*orig_im = ((glow_tImImage*)new QImage(imagefile));
*orig_im = new QImage(imagefile);
if (!*orig_im) {
if (im) {
*im = 0;
......@@ -2494,7 +2521,7 @@ int GlowDrawQt::image_load(char* imagefile, glow_tImImage* orig_im,
}
}
if (im) {
*((QImage*)*im) = ((QImage*)*orig_im)->copy();
*im = new QImage(((QImage*)*orig_im)->copy());
}
return 1;
}
......@@ -2523,6 +2550,8 @@ void GlowDrawQt::image_pixel_iter(glow_tImImage orig_image,
int rgb_width;
int rowstride;
// debug_print("image_pixel_iter\n");
if (orig_image) {
if (image && *image != orig_image) {
delete ((QImage*)*image);
......@@ -3368,7 +3397,7 @@ void GlowDrawQt::event_exec(void* event, unsigned int size)
return;
}
memcpy((void *)&e, (void *)event, size);
memcpy((void*)&e, (void*)event, size);
// e.any.window = m_wind->window;
switch (e.type()) {
......
......@@ -50,6 +50,9 @@
void QtScrollWidgetGlow::createBuffer(QSize size)
{
if (size.isEmpty()) {
return;
}
this->image = QImage(size, QImage::Format_RGB32);
QPainter imPainter(&image);
imPainter.fillRect(image.rect(), palette().color(QPalette::Background));
......@@ -259,8 +262,7 @@ bool QtScrollWidgetGlow::event(QEvent* event)
emit resize_signal((QResizeEvent*)event);
createBuffer(((QResizeEvent*)event)->size());
}
if (!is_realized
&& (event->type() == QEvent::Show || event->type() == QEvent::Resize)) {
if (!is_realized && event->type() == QEvent::Show) {
realize();
is_realized = true;
}
......
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