X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fgraph%2Floggraph.cpp;h=688e8e4062c309d90f6ab01547ba09214239b83f;hb=refs%2Ftags%2F3.4-b1;hp=461669fe881fe64a388048a75a1662efb451d9c4;hpb=b479a8704403e7cb775bff79f270cf0d1af5083d;p=vlp.git diff --git a/src/graph/loggraph.cpp b/src/graph/loggraph.cpp index 461669f..688e8e4 100644 --- a/src/graph/loggraph.cpp +++ b/src/graph/loggraph.cpp @@ -1,26 +1,20 @@ -/* -// -// Qt Example Application: drawdemo -// -// Demonstrates the painter and the printer. -// - -//#include -*/ -#include -#include -#include -#include -#include -#include + +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -28,14 +22,15 @@ #include "comm.h" #include "socu.h" #include -#include -#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +// #include +#include #define MAXWIDTH 640 #define MAXHEIGHT 480 @@ -44,151 +39,18 @@ #define REQUEST_NAME "gr.req" #define PERM 0666 -class VGRMap { -public: - QPixmap *map; - int number; - - VGRMap(int n, QPixmap *m) { - number = n; - map = m; - }; -}; - -class VGR : public QFrame { - Q_OBJECT -public: - VGR(char*); - ~VGR(); - - int resp_sock; - int fcol; - int bcol; - int gfcol; - int gbcol; - int curx; - int cury; - int tx; - int ty; - QQueue CharBuffer; - - bool string_wait; - bool char_wait; - bool line_wait; - bool mouse_wait; - bool inkey_wait; - bool was_line; - QColor *lcolors[256]; - QFont *prv_font; - QFont *italic_font; - QFont *bold_font; - QFont *normal_font; - - void MakeColors(); - - void SetForeground(int); - void SetBackground(int); - void ClearAll(); - void ClearArea(int, int, int, int); - - void Line(int, int, int, int); - void Ellipse(int x, int y, int a, int b, int alfa, int beta, int fill); - void Rect(int x1, int y1, int x2, int y2, int col, int fill); - void Point(int x, int y); - void TextXY(int x, int y, char *s); - void CharXY(int x, int y, char a); - void IntXY(int x, int y, int val); - - void WriteText(char *s); - void WriteChar(char a); - void WriteLine(); - - /* Write Char w/o changing position */ - void PutChar(char a); - void DelChar(); - - void Outstring(int x, int y, char *s, int b, int f); - void writeintxy(int x, int y, int val, int c); - void CurPos(); - - int Getmap(int w, int h); - void Putmap(int map); - - void MagicGraph(G_MESSAGE*); - bool GetInput(int); - -public slots: - void vscrolled(int); - void hscrolled(int); - void CloseMe(); - void RequestMessage(); - -protected: - virtual void resizeEvent(QResizeEvent *); - virtual void closeEvent(QCloseEvent *); - virtual void keyPressEvent(QKeyEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void paintEvent(QPaintEvent *); - virtual void focusInEvent(QFocusEvent *); - -private: - QPixmap *canvas; - QScrollBar *hscroll; - QScrollBar *vscroll; - QPushButton *close_btn; - int ox,oy,lstep,pstep,gx,gy; - QList maps; - int firstfreemap; - bool Closed; - bool MustRepaint; - bool GraphRead; - QSocketNotifier *request; - char internal_buffer[256]; - int strcnt; -}; - -void VGR::MakeColors() -{ - /* black */ - lcolors[0] = new QColor(0, 0, 0); - /* blue dark */ - lcolors[1] = new QColor(0, 0, 139); - /* green dark */ - lcolors[2] = new QColor(0, 100, 0); - /* turquoise dark */ - lcolors[3] = new QColor(0, 197, 205); - /* red dark */ - lcolors[4] = new QColor(205, 0, 0); - /* violet */ - lcolors[5] = new QColor(238, 130, 238); - /* brown */ - lcolors[6] = new QColor(139,35, 35); - /* grey light */ - lcolors[7] = new QColor(190, 190, 190); - /* grey dark */ - lcolors[8] = new QColor(97, 97, 97); - /* blue */ - lcolors[9] = new QColor(0, 0, 255); - /* green */ - lcolors[10] = new QColor(0, 255, 0); - /* turquoise */ - lcolors[11] = new QColor(0, 229, 238); - /* red light */ - lcolors[12] = new QColor(255, 0, 0); - /* rose */ - lcolors[13] = new QColor(255, 110, 180); - /* yellow */ - lcolors[14] = new QColor(255, 255, 0); - /* white */ - lcolors[15] = new QColor(255, 255, 255); -} +#include "loggraph.h" /* * Construct the DrawView with buttons. */ -VGR::VGR(char *sockname) - :QFrame() +VGR::VGR(int argc, char **argv) + :QMainWindow() { + char *sockname = argv[1]; + + fprintf(stderr, "loggraph: inited with sockname = %s\n", sockname); + QPixmap mp; struct sockaddr_un svr; int len, i, optval, on; @@ -204,7 +66,7 @@ VGR::VGR(char *sockname) MakeColors(); setCaption("graphic resource"); - setBackgroundColor(white); +// setBackgroundColor(white); canvas = new QPixmap(640, 480); canvas->fill(backgroundColor()); @@ -213,14 +75,14 @@ VGR::VGR(char *sockname) tx = ty = 0; gx = gy = 0; - maps.setAutoDelete(TRUE); +// maps.setAutoDelete(TRUE); firstfreemap = 1; Closed = FALSE; GraphRead = FALSE; lstep = 10; pstep = 250; - hscroll = new QScrollBar(0, MAXWIDTH, lstep, pstep, 0, QScrollBar::Horizontal, this); - vscroll = new QScrollBar(0, MAXHEIGHT, lstep, pstep, 0, QScrollBar::Vertical, this); + hscroll = new QScrollBar(0, MAXWIDTH, lstep, pstep, 0, Qt::Orientation::Horizontal, this); + vscroll = new QScrollBar(0, MAXHEIGHT, lstep, pstep, 0, Qt::Orientation::Vertical, this); hscroll->setTracking(TRUE); vscroll->setTracking(TRUE); resize(640, 300); @@ -268,9 +130,9 @@ VGR::VGR(char *sockname) char_wait = line_wait = mouse_wait = FALSE; was_line = FALSE; CharBuffer.clear(); - CharBuffer.setAutoDelete(TRUE); +// CharBuffer.setAutoDelete(TRUE); - setFocusPolicy(QWidget::StrongFocus); + setFocusPolicy(Qt::StrongFocus); hscroll->setRange(0, MAXWIDTH - width() + 20); vscroll->setRange(0, MAXHEIGHT - height() + 20); hscroll->setSteps((int)(hscroll->width() / hscroll->maxValue()), @@ -280,7 +142,7 @@ VGR::VGR(char *sockname) setMaximumSize(MAXWIDTH + 16, MAXHEIGHT + 16); setUpdatesEnabled(FALSE); -}; +} VGR::~VGR() { @@ -318,8 +180,9 @@ void VGR::resizeEvent( QResizeEvent *ev ) void VGR::closeEvent(QCloseEvent *ev) { - if (Closed) - QFrame::closeEvent(ev); +// @TODO: Check this +// if (Closed) +// QFrame::closeEvent(ev); } void VGR::mousePressEvent(QMouseEvent *ev) @@ -332,13 +195,13 @@ void VGR::mousePressEvent(QMouseEvent *ev) msg.param.pword[2] = ev->pos().x() - ox; msg.param.pword[3] = ev->pos().y() - oy; switch(ev->button()) { - case LeftButton: + case Qt::LeftButton: msg.param.pword[7] = 1; break; - case RightButton: + case Qt::RightButton: msg.param.pword[7] = 3; break; - case MidButton: + case Qt::MidButton: msg.param.pword[7] = 2; break; default: @@ -349,7 +212,9 @@ void VGR::mousePressEvent(QMouseEvent *ev) mouse_wait = FALSE; } - QFrame::mousePressEvent(ev); + +// @TODO: check +// QFrame::mousePressEvent(ev); } @@ -426,61 +291,61 @@ void VGR::keyPressEvent(QKeyEvent *ev) *pom=ev->ascii(); if (*pom==0) { switch(ev->key()) { - case Key_F1: + case Qt::Key_F1: *pom = -10; break; - case Key_F2: + case Qt::Key_F2: *pom = -11; break; - case Key_F3: + case Qt::Key_F3: *pom = -12; break; - case Key_F4: + case Qt::Key_F4: *pom = -13; break; - case Key_F5: + case Qt::Key_F5: *pom = -14; break; - case Key_F6: + case Qt::Key_F6: *pom = -15; break; - case Key_F7: + case Qt::Key_F7: *pom = -16; break; - case Key_F8: + case Qt::Key_F8: *pom = -17; break; - case Key_F9: + case Qt::Key_F9: *pom = -18; break; - case Key_F10: + case Qt::Key_F10: *pom = -19; break; - case Key_Insert: + case Qt::Key_Insert: *pom = -20; break; - case Key_Home: + case Qt::Key_Home: *pom = -21; break; - case Key_End: + case Qt::Key_End: *pom = -22; break; - case Key_PageUp: + case Qt::Key_PageUp: *pom = -23; break; - case Key_PageDown: + case Qt::Key_PageDown: *pom = -24; break; - case Key_Left: + case Qt::Key_Left: *pom = -25; break; - case Key_Right: + case Qt::Key_Right: *pom = -26; break; - case Key_Up: + case Qt::Key_Up: *pom = -27; break; - case Key_Down: + case Qt::Key_Down: *pom = -28; break; }/* switch */ @@ -578,6 +443,25 @@ void VGR::vscrolled(int val) setUpdatesEnabled(FALSE); } +void VGR::MakeColors() +{ + lcolors[0] = new QColor(0, 0, 0 ); /* black */ + lcolors[1] = new QColor(0, 0, 139); /* blue dark */ + lcolors[2] = new QColor(0, 100, 0 ); /* green dark */ + lcolors[3] = new QColor(0, 197, 205 ); /* turquoise dark */ + lcolors[4] = new QColor(205,0 , 0 ); /* red dark */ + lcolors[5] = new QColor(238, 130,238); /* violet */ + lcolors[6] = new QColor(139,35,35 ); /* brown */ + lcolors[7] = new QColor(190,190,190 ); /* grey light */ + lcolors[8] = new QColor(97, 97, 97 ); /* grey dark */ + lcolors[9] = new QColor(0, 0, 255 ); /* blue */ + lcolors[10] = new QColor(0, 255, 0 ); /* green */ + lcolors[11] = new QColor(0, 229,238 ); /* turquoise */ + lcolors[12] = new QColor(255, 0, 0 ); /* red light */ + lcolors[13] = new QColor(255, 110,180 ); /* rose */ + lcolors[14] = new QColor(255,255, 0 ); /* yellow */ + lcolors[15] = new QColor(255, 255, 255 ); /* white */ +} /****************************************/ @@ -660,7 +544,7 @@ void VGR::TextXY(int x, int y, char *s) p.begin(canvas); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x, y + fm.height(), s, strlen(s)); p.end(); @@ -669,7 +553,7 @@ void VGR::TextXY(int x, int y, char *s) p.begin(this); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x - ox, y - oy + fm.height(), s, strlen(s)); p.end(); @@ -687,7 +571,7 @@ void VGR::CharXY(int x, int y, char a) p.begin(canvas); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x , y + fm.height(), s, strlen(s)); p.end(); @@ -695,7 +579,7 @@ void VGR::CharXY(int x, int y, char a) p.begin(this); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x - ox, y - oy + fm.height(), s, strlen(s)); p.end(); @@ -712,7 +596,7 @@ void VGR::IntXY(int x, int y, int val) p.begin(canvas); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x, y + fm.height(), s, strlen(s)); p.end(); @@ -720,7 +604,7 @@ void VGR::IntXY(int x, int y, int val) p.begin(this); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x - ox, y - oy + fm.height(), s, strlen(s)); p.end(); @@ -734,7 +618,7 @@ void VGR::WriteText(char *s) p.begin(canvas); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(tx * fm.maxWidth(), (ty + 1) * fm.height(), s, strlen(s)); p.end(); @@ -742,7 +626,7 @@ void VGR::WriteText(char *s) p.begin(this); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(tx * fm.maxWidth() - ox, (ty + 1) * fm.height() - oy, s, strlen(s)); @@ -771,7 +655,7 @@ void VGR::WriteChar(char a) p.begin(canvas); p.setPen(*lcolors[gfcol]); p.setBackgroundColor(*lcolors[gbcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(gx, gy + fm.height(), s, strlen(s)); p.end(); @@ -779,7 +663,7 @@ void VGR::WriteChar(char a) p.begin(this); p.setPen(*lcolors[gfcol]); p.setBackgroundColor(*lcolors[gbcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(gx - ox, gy - oy + fm.height(), s, strlen(s)); p.end(); @@ -796,7 +680,7 @@ void VGR::WriteChar(char a) p.begin(canvas); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(tx * fm.maxWidth(), (ty + 1) * fm.height(), s, strlen(s)); @@ -805,7 +689,7 @@ void VGR::WriteChar(char a) p.begin(this); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(tx * fm.maxWidth() - ox, (ty + 1) * fm.height() - oy, s, strlen(s)); @@ -876,7 +760,7 @@ void VGR::PutChar(char a) p.begin(canvas); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(tx * fm.maxWidth(), (ty + 1) * fm.height(), s, strlen(s)); p.end(); @@ -884,7 +768,7 @@ void VGR::PutChar(char a) p.begin(this); p.setPen(*lcolors[fcol]); p.setBackgroundColor(*lcolors[bcol]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(tx * fm.maxWidth() - ox, (ty + 1) * fm.height() - oy, s, strlen(s)); @@ -957,8 +841,10 @@ int VGR::Getmap(int w, int h) void VGR::Putmap(int map) { VGRMap *m; - m = maps.first(); - while (m != NULL) { + QListIterator mapsIterator(maps); + + while (mapsIterator.hasNext()) { + m = mapsIterator.next(); if (m->number == map) { bitBlt(canvas, curx, cury, m->map, 0, 0, m->map->width(), m->map->height()); @@ -966,7 +852,6 @@ void VGR::Putmap(int map) m->map->width(), m->map->height()); break; } - m = maps.next(); } } @@ -978,7 +863,7 @@ void VGR::Outstring(int x, int y, char *s, int b, int f) p.begin(canvas); p.setPen(*lcolors[f]); p.setBackgroundColor(*lcolors[b]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.setFont(*prv_font); p.drawText(x, y + fm.height(), s, strlen(s)); p.end(); @@ -987,7 +872,7 @@ void VGR::Outstring(int x, int y, char *s, int b, int f) p.setPen(*lcolors[f]); p.setFont(*prv_font); p.setBackgroundColor(*lcolors[b]); - p.setBackgroundMode(OpaqueMode); + p.setBackgroundMode(Qt::OpaqueMode); p.drawText(x - ox, y - oy + fm.height(), s, strlen(s)); p.end(); @@ -1051,8 +936,11 @@ void VGR::RequestMessage() break; case GRAPH_WRITEXY: - TextXY(m.param.pword[3], m.param.pword[4], - m.param.pstr); + TextXY( + m.param.pword[3], + m.param.pword[4], + m.param.pstr + ); break; case GRAPH_READCHAR: if (!GetInput(0)) @@ -1078,19 +966,32 @@ void VGR::RequestMessage() WriteChar(m.param.pchar); break; case GRAPH_LINETO: - Line(curx,cury, m.param.pword[3], - m.param.pword[4]); + Line( + curx,cury, + m.param.pword[3], + m.param.pword[4] + ); break; case GRAPH_ELLIPSE: - Ellipse(m.param.pword[3], m.param.pword[4], - m.param.pword[5], m.param.pword[6], - m.param.pword[7], m.param.pword[8], - m.param.pword[9]); + Ellipse( + m.param.pword[3], + m.param.pword[4], + m.param.pword[5], + m.param.pword[6], + m.param.pword[7], + m.param.pword[8], + m.param.pword[9] + ); break; case GRAPH_RECT: - Rect(m.param.pword[3], m.param.pword[4], - m.param.pword[5], m.param.pword[6], - m.param.pword[7], m.param.pword[8]); + Rect( + m.param.pword[3], + m.param.pword[4], + m.param.pword[5], + m.param.pword[6], + m.param.pword[7], + m.param.pword[8] + ); break; case GRAPH_FOREGROUND: SetForeground(m.param.pword[3]); @@ -1113,9 +1014,13 @@ void VGR::RequestMessage() CurPos(); break; case GRAPH_OUTSTRING: - Outstring(m.param.pword[2], m.param.pword[3], - m.param.pstr, m.param.pword[4], - m.param.pword[5]); + Outstring( + m.param.pword[2], + m.param.pword[3], + m.param.pstr, + m.param.pword[4], + m.param.pword[5] + ); break; case GRAPH_WRITEINTXY: writeintxy(m.param.pword[2], m.param.pword[3], @@ -1196,7 +1101,11 @@ void VGR::MagicGraph(G_MESSAGE *msg) b = bcol; fcol = msg->param.pword[4]; bcol = msg->param.pword[5]; - TextXY(msg->param.pword[2], msg->param.pword[3], msg->param.pstr); + TextXY( + msg->param.pword[2], + msg->param.pword[3], + msg->param.pstr + ); fcol = f; bcol = b; break; @@ -1206,7 +1115,11 @@ void VGR::MagicGraph(G_MESSAGE *msg) b = bcol; fcol = msg->param.pword[5]; bcol = msg->param.pword[6]; - IntXY(msg->param.pword[2], msg->param.pword[3], msg->param.pword[4]); + IntXY( + msg->param.pword[2], + msg->param.pword[3], + msg->param.pword[4] + ); fcol = f; bcol = b; break; @@ -1270,29 +1183,36 @@ void VGR::MagicGraph(G_MESSAGE *msg) } break; /* Kill map */ - case 309: - pmap = maps.first(); - while (pmap != NULL) { + case 309: { + QListIterator mapsIterator(maps); + + while (mapsIterator.hasNext()) { + pmap = mapsIterator.next(); if (msg->param.pword[2] == pmap->number) { maps.remove(pmap); break; } - pmap = maps.next(); } break; + } /* Line (x1,y1,x2,y2,col) */ case 310: f = fcol; fcol = msg->param.pword[6]; - Line(msg->param.pword[2], msg->param.pword[3], - msg->param.pword[4], msg->param.pword[5]); + Line( + msg->param.pword[2], msg->param.pword[3], + msg->param.pword[4], msg->param.pword[5] + ); fcol = f; break; /* Rectangle(x1,y1,x2,y2,fcol,icol) */ case 311: - Rect(msg->param.pword[2], msg->param.pword[3], - msg->param.pword[4], msg->param.pword[5], - msg->param.pword[7], 1); + Rect( + msg->param.pword[2], msg->param.pword[3], + msg->param.pword[4], msg->param.pword[5], + msg->param.pword[7], + 1 + ); Rect(msg->param.pword[2], msg->param.pword[3], msg->param.pword[4],msg->param.pword[5], msg->param.pword[6], 0); @@ -1305,13 +1225,10 @@ void VGR::MagicGraph(G_MESSAGE *msg) }//switch } -#include "loggraph.moc" - int main(int argc, char **argv) { QApplication app(argc, argv); - VGR gs(argv[1]); - app.setMainWidget(&gs); + VGR gs(argc, argv); gs.show(); return app.exec(); }