Restore compilation of loggraph, extract code layout of kernel's message dialog into...
[vlp.git] / src / graph / loggraph.cpp
index 752828490a8dd60600c9d321e0058e8a35b40bdb..f44ec66bf089988846c95206a6acb9a61f36a602 100644 (file)
@@ -1,12 +1,4 @@
-/*
-//
-// Qt Example Application: drawdemo
-//
-// Demonstrates the painter and the printer.
-//
-
-//#include <qwindow.h>
-*/
+
 #include <QtGui/QPainter>
 #include <QtGui/QPrinter>
 #include <QtGui/QPushButton>
@@ -14,6 +6,7 @@
 #include <QtGui/QButtonGroup>
 #include <QtGui/QApplication>
 #include <QtGui/QMainWindow>
+#include <QtGui/QFrame>
 #include <math.h>
 #include <QtGui/QPixmap>
 #include <QtGui/QScrollBar>
@@ -35,6 +28,7 @@
 #include <QtCore/QQueue>
 #include <QtGui/QMessageBox>
 #include <QtGui/QMenuBar>
+#include <QtGui/QMouseEvent>
 // #include <qpopmenu.h>
 #include <QtCore/qnamespace.h>
 
 #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 QMainWindow {
-       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<int> 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<VGRMap> 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)
+VGR::VGR(int argc, char **argv)
        :QMainWindow()
 {
+       char *sockname = argv[1];
+
+       fprintf(stderr, "GRAPH: sockname inited with: %s (%s)\n", sockname, argv[1]);
+
        QPixmap mp;
        struct sockaddr_un svr;
        int len, i, optval, on;
@@ -214,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);
@@ -269,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()),
@@ -319,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)
@@ -333,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:
@@ -350,7 +212,9 @@ void VGR::mousePressEvent(QMouseEvent *ev)
 
                mouse_wait = FALSE;
        }
-       QFrame::mousePressEvent(ev);
+
+// @TODO: check
+//     QFrame::mousePressEvent(ev);
 }
 
 
@@ -579,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 */
+}
 
 /****************************************/
 
@@ -958,8 +841,10 @@ int VGR::Getmap(int w, int h)
 void VGR::Putmap(int map)
 {
        VGRMap *m;
-       m = maps.first();
-       while (m != NULL) {
+       QListIterator<VGRMap *> 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());
@@ -967,7 +852,6 @@ void VGR::Putmap(int map)
                                        m->map->width(), m->map->height());
                        break;
                }
-               m = maps.next();
        }
 }
 
@@ -1052,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))
@@ -1079,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]);
@@ -1114,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],
@@ -1197,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;
@@ -1207,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;
@@ -1271,29 +1183,36 @@ void VGR::MagicGraph(G_MESSAGE *msg)
                }
                break;
        /* Kill map */
-       case 309:
-               pmap = maps.first();
-               while (pmap != NULL) {
+       case 309: {
+               QListIterator<VGRMap *> 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);
@@ -1306,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();
 }