-/*
-//
-// Qt Example Application: drawdemo
-//
-// Demonstrates the painter and the printer.
-//
-
-//#include <qwindow.h>
-*/
+
#include <QtGui/QPainter>
#include <QtGui/QPrinter>
#include <QtGui/QPushButton>
#include <QtGui/QButtonGroup>
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
+#include <QtGui/QFrame>
#include <math.h>
#include <QtGui/QPixmap>
#include <QtGui/QScrollBar>
#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, "loggraph: inited with sockname = %s\n", sockname);
+
QPixmap mp;
struct sockaddr_un svr;
int len, i, optval, on;
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);
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()),
void VGR::closeEvent(QCloseEvent *ev)
{
- if (Closed)
- QFrame::closeEvent(ev);
+// @TODO: Check this
+// if (Closed)
+// QFrame::closeEvent(ev);
}
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:
mouse_wait = FALSE;
}
- QFrame::mousePressEvent(ev);
+
+// @TODO: check
+// QFrame::mousePressEvent(ev);
}
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 */
+}
/****************************************/
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());
m->map->width(), m->map->height());
break;
}
- m = maps.next();
}
}
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))
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]);
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],
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;
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;
}
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);
}//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();
}