Restore compilation of loggraph, extract code layout of kernel's message dialog into...
[vlp.git] / src / graph / loggraph.cpp
index 4a12ad40c270c6cb79b14e64806b37dc3310a3cc..f44ec66bf089988846c95206a6acb9a61f36a602 100644 (file)
@@ -6,6 +6,7 @@
 #include <QtGui/QButtonGroup>
 #include <QtGui/QApplication>
 #include <QtGui/QMainWindow>
+#include <QtGui/QFrame>
 #include <math.h>
 #include <QtGui/QPixmap>
 #include <QtGui/QScrollBar>
@@ -27,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;
@@ -206,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);
@@ -261,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()),
@@ -311,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)
@@ -325,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:
@@ -342,7 +212,9 @@ void VGR::mousePressEvent(QMouseEvent *ev)
 
                mouse_wait = FALSE;
        }
-       QFrame::mousePressEvent(ev);
+
+// @TODO: check
+//     QFrame::mousePressEvent(ev);
 }
 
 
@@ -571,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 */
+}
 
 /****************************************/
 
@@ -950,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());
@@ -959,7 +852,6 @@ void VGR::Putmap(int map)
                                        m->map->width(), m->map->height());
                        break;
                }
-               m = maps.next();
        }
 }
 
@@ -1291,16 +1183,18 @@ 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;
@@ -1331,12 +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]);
+       VGR gs(argc, argv);
        gs.show();
        return app.exec();
 }