Skip to content

Commit

Permalink
Port to Qt5 - Part 2
Browse files Browse the repository at this point in the history
Restores most functionality to the Pic and View editors.

Closes #2.
  • Loading branch information
Deledrius committed Mar 15, 2018
1 parent 7a279ab commit f45fa3e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 29 deletions.
68 changes: 48 additions & 20 deletions src/picedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,31 @@ PicEdit::PicEdit(QWidget *parent, const char *name, int win_num, ResourcesWin *r

QVBoxLayout *shapebox = new QVBoxLayout();
QGroupBox *shape = new QGroupBox("Shape", this);
QButtonGroup *shapeGrp = new QButtonGroup(this);
QRadioButton *circle = new QRadioButton("Circle", shape);
QRadioButton *square = new QRadioButton("Square", shape);
circle->setChecked(true);
shapebox->addWidget(circle);
shapebox->addWidget(square);
b2->addWidget(shape);
shape->setLayout(shapebox);
connect(shape, SIGNAL(clicked(int)), SLOT(change_shape(int)));

shapeGrp->addButton(circle, 0);
shapeGrp->addButton(square, 1);
connect(shapeGrp, SIGNAL(buttonClicked(int)), SLOT(change_shape(int)));

QVBoxLayout *typebox = new QVBoxLayout();
QGroupBox *type = new QGroupBox("Type", this);
QButtonGroup *typeGrp = new QButtonGroup(this);
QRadioButton *spray = new QRadioButton("Spray", type);
QRadioButton *solid = new QRadioButton("Solid", type);
spray->setChecked(true);
typebox->addWidget(spray);
typebox->addWidget(solid);
b2->addWidget(type);
type->setLayout(typebox);
connect(type, SIGNAL(clicked(int)), SLOT(change_type(int)));
typeGrp->addButton(spray, 0);
typeGrp->addButton(solid, 1);
connect(typeGrp, SIGNAL(buttonClicked(int)), SLOT(change_type(int)));

QVBoxLayout *sizebox = new QVBoxLayout();
QGroupBox *lsize = new QGroupBox(tr("Size"), this); //vert
Expand Down Expand Up @@ -261,6 +266,7 @@ PicEdit::PicEdit(QWidget *parent, const char *name, int win_num, ResourcesWin *r

QVBoxLayout *drawbox = new QVBoxLayout();
QGroupBox *drawmode = new QGroupBox("Show", this);
QButtonGroup *dmgrp = new QButtonGroup(this);
pic = new QRadioButton("Visual", drawmode);
pri = new QRadioButton("Priority", drawmode);
bg = new QCheckBox("Background", drawmode);
Expand All @@ -274,7 +280,11 @@ PicEdit::PicEdit(QWidget *parent, const char *name, int win_num, ResourcesWin *r
picture->set_mode(0);
b4->addWidget(drawmode);
drawmode->setLayout(drawbox);
connect(drawmode, SIGNAL(clicked(int)), SLOT(change_drawmode(int)));
dmgrp->addButton(pic, 0);
dmgrp->addButton(pri, 1);
connect(dmgrp, SIGNAL(buttonClicked(int)), SLOT(change_drawmode(int)));
connect(bg, SIGNAL(clicked(bool)), SLOT(toggle_bgmode(bool)));
connect(prilines, SIGNAL(clicked(bool)), SLOT(toggle_prilinemode(bool)));

status = new QStatusBar(this);
QLabel *msg = new QLabel(status);
Expand All @@ -290,14 +300,13 @@ PicEdit::PicEdit(QWidget *parent, const char *name, int win_num, ResourcesWin *r
if (game->picstyle == P_TWO) {
canvas = new PCanvas(0, 0, this);
canvas->setMinimumSize(canvas->pixsize * MAX_W + canvas->x0 + 10, canvas->pixsize * MAX_HH + canvas->x0 + 10);
//canvas->resizeContents(canvas->pixsize*MAX_W+canvas->x0,canvas->pixsize*MAX_HH+canvas->x0);
canvas->resize(canvas->pixsize * MAX_W + canvas->x0, canvas->pixsize * MAX_HH + canvas->x0);

} else {
canvas = new PCanvas(this, 0, this);
canvas->setMinimumSize(canvas->pixsize * MAX_W + canvas->x0 + 10, canvas->pixsize * MAX_HH + canvas->x0 + 10);
//canvas->resizeContents(canvas->pixsize*MAX_W+canvas->x0,canvas->pixsize*MAX_HH+canvas->x0);
all->addWidget(canvas, 1);
canvas->resize(canvas->pixsize*MAX_W+canvas->x0,canvas->pixsize*MAX_HH+canvas->x0);
all->addWidget(canvas);
setFocusProxy(canvas);
}

Expand Down Expand Up @@ -607,21 +616,32 @@ void PicEdit::change_drawmode(int mode)
pic->setChecked(false);
pri->setChecked(true);
break;
case 2: //draw (also) background
canvas->bg_on = bg->isChecked();
if (canvas->bg_on && canvas->bg_loaded)
picture->bg_on = true;
else
picture->bg_on = false;
break;
case 3: //priority lines
canvas->pri_lines = prilines->isChecked();
break;
}
canvas->linedraw = false;
canvas->update();
}

//*********************************************
void PicEdit::toggle_bgmode(bool checked)
{
canvas->bg_on = checked;
if (canvas->bg_on && canvas->bg_loaded)
picture->bg_on = true;
else
picture->bg_on = false;

canvas->linedraw = false;
canvas->update();
}

//*********************************************
void PicEdit::toggle_prilinemode(bool checked)
{
canvas->pri_lines = checked;
canvas->linedraw = false;
canvas->update();
}

//*********************************************
void PicEdit::change_tool(int k)
{
Expand Down Expand Up @@ -837,11 +857,15 @@ PCanvas::PCanvas(QWidget *parent, const char *name, PicEdit *w)
cur_w = MAX_W * pixsize;
cur_h = MAX_HH * pixsize;
pixmap = QPixmap(cur_w, cur_h);
viewport()->setMouseTracking(true);
bg_loaded = false;
bg_on = false;
pri_lines = false;
bgpix = QImage();

imagecontainer = new QLabel;
this->setWidget(imagecontainer);
imagecontainer->resize(cur_w, cur_h);
imagecontainer->setPixmap(pixmap);
}

//*********************************************
Expand All @@ -863,11 +887,13 @@ void PCanvas::setPixsize(int s)
pixmap = pixmap.scaled(cur_w, cur_h);
QPainter p(&pixmap);
p.eraseRect(0, 0, cur_w, cur_h);
p.end();
update();
imagecontainer->resize(cur_w, cur_h);
}

//*********************************************
void PCanvas::viewportMousePressEvent(QMouseEvent *event)
void PCanvas::mousePressEvent(QMouseEvent *event)
{
int x = event->x(), y = event->y();
int xx = x, yy = y;
Expand Down Expand Up @@ -903,7 +929,7 @@ void PCanvas::viewportMousePressEvent(QMouseEvent *event)
}

//*********************************************
void PCanvas::viewportMouseMoveEvent(QMouseEvent *event)
void PCanvas::mouseMoveEvent(QMouseEvent *event)
{
int x = event->x(), y = event->y();
int xx = x, yy = y;
Expand Down Expand Up @@ -999,6 +1025,7 @@ void PCanvas::update()
}
}
repaint(x0, y0, x0 + MAX_W * pixsize, y0 + MAX_HH * pixsize);
imagecontainer->setPixmap(pixmap);
}

//*********************************************
Expand Down Expand Up @@ -1090,6 +1117,7 @@ void PCanvas::line(bool mode)
}
#endif
repaint(x0, y0, x0 + MAX_W * pixsize, y0 + MAX_HH * pixsize);
imagecontainer->setPixmap(pixmap);
}

//*********************************************
Expand Down
7 changes: 5 additions & 2 deletions src/picedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ class PCanvas : public QScrollArea
protected:
int CurColor;
Picture *picture;
QLabel *imagecontainer;
QPixmap pixmap;
QImage bgpix;
PicEdit *picedit;
void closeEvent(QCloseEvent *e);
void showEvent(QShowEvent *);
void hideEvent(QHideEvent *);
void keyPressEvent(QKeyEvent *);
void viewportMousePressEvent(QMouseEvent *e);
void viewportMouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph) ;
bool focusNextPrevChild(bool next) ;
};
Expand Down Expand Up @@ -151,6 +152,8 @@ public slots:
void zoom_plus();

void change_drawmode(int);
void toggle_bgmode(bool);
void toggle_prilinemode(bool);
void change_tool(int);
void change_size(int);
void change_shape(int);
Expand Down
27 changes: 22 additions & 5 deletions src/viewedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ ViewEdit::ViewEdit(QWidget *parent, const char *name, int win_num, ResourcesWin
bg->setExclusive(true);
bg->addButton(view_draw);
bg->addButton(view_fill, 1);
connect(bg, SIGNAL(clicked(int)), SLOT(change_mode(int)));
connect(bg, SIGNAL(buttonClicked(int)), SLOT(change_mode(int)));


QGridLayout *grid3 = new QGridLayout();
Expand Down Expand Up @@ -408,7 +408,6 @@ ViewEdit::ViewEdit(QWidget *parent, const char *name, int win_num, ResourcesWin
QBoxLayout *right = new QVBoxLayout(this);
frame3->setLayout(right);

// QScrollArea *canvas = new QScrollArea(frame3);
canvas = new Canvas(frame3, 0, this);
canvas->setMinimumSize(400, 200);
right->addWidget(canvas, 1);
Expand Down Expand Up @@ -1565,20 +1564,31 @@ Canvas::Canvas(QWidget *parent, const char *name, ViewEdit *v)
cur_mirror = false;
pixmap = QPixmap();
cur_w = cur_h = 0;

imagecontainer = new QLabel;
this->setWidget(imagecontainer);
imagecontainer->resize(cur_w, cur_h);
imagecontainer->setPixmap(pixmap);
}

//*********************************************
void Canvas::setSize(int w, int h)
{
if (cur_w != w || cur_h != h) {
pixmap = pixmap.scaled(w * pixsize * 2, h * pixsize);
if (!pixmap)
pixmap = QPixmap(w * pixsize * 2, h * pixsize);
else
pixmap = pixmap.scaled(w * pixsize * 2, h * pixsize);
cur_w = w;
cur_h = h;

imagecontainer->resize(w * pixsize * 2, h * pixsize);
imagecontainer->setPixmap(pixmap);
}
}

//*********************************************
void Canvas::viewportMousePressEvent(QMouseEvent *event)
void Canvas::mousePressEvent(QMouseEvent *event)
{
int x = event->x(), y = event->y();

Expand All @@ -1591,7 +1601,7 @@ void Canvas::viewportMousePressEvent(QMouseEvent *event)
}

//*********************************************
void Canvas::viewportMouseMoveEvent(QMouseEvent *event)
void Canvas::mouseMoveEvent(QMouseEvent *event)
{
int x = event->x(), y = event->y();
UpdateCel(x - x0, y - y0);
Expand Down Expand Up @@ -1635,6 +1645,9 @@ void Canvas::DrawCel(int w, int h, byte *celdata, bool mirror, int size)
}
}
repaint(x0, y0, MAX(ww, ww0), MAX(hh, hh0));

imagecontainer->resize(cur_w * pixsize * 2, cur_h * pixsize);
imagecontainer->setPixmap(pixmap);
}

//*********************************************
Expand Down Expand Up @@ -1678,6 +1691,9 @@ void Canvas::DrawCel(int w, int h, byte *celdata, bool mirror)
repaint(x0, y0, MAX(ww, ww0), MAX(hh, hh0));
else
repaint(x0, y0, ww, hh);

imagecontainer->resize(cur_w * pixsize * 2, cur_h * pixsize);
imagecontainer->setPixmap(pixmap);
}

//*********************************************
Expand Down Expand Up @@ -1710,6 +1726,7 @@ void Canvas::UpdateCel(int x, int y)
viewedit->fillCel(xn, yn, CurColor);
}
}
imagecontainer->setPixmap(pixmap);
}

//*********************************************
Expand Down
5 changes: 3 additions & 2 deletions src/viewedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ class Canvas : public QScrollArea
void UpdateCel(int x, int y);
protected:
int CurColor;
QLabel *imagecontainer;
QPixmap pixmap;
bool cur_mirror;
byte *data;
ViewEdit *viewedit;
void keyPressEvent(QKeyEvent *);
void viewportMousePressEvent(QMouseEvent *e);
void viewportMouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void drawContents(QPainter *p, int, int, int, int);
bool focusNextPrevChild(bool next) ;
};
Expand Down

0 comments on commit f45fa3e

Please sign in to comment.