2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
4 // (C) 2009 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 12/23/2009 Created this file
20 // Uncomment this for debugging...
22 //#define DEBUGFOO // Various tool debugging...
23 //#define DEBUGTP // Toolpalette debugging...
30 //#include "editwindow.h"
31 //#include "charwindow.h"
34 MainWin::MainWin(): running(true)
36 // The way BSNES controls things is by setting a timer with a zero
37 // timeout, sleeping if not emulating anything. Seems there has to be a
40 // It has a novel approach to plugging-in/using different video/audio/input
41 // methods, can we do something similar or should we just use the built-in
44 // We're going to try to use the built-in OpenGL support and see how it goes.
45 // We'll make the VJ core modular so that it doesn't matter what GUI is in
46 // use, we can drop it in anywhere and use it as-is.
48 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
49 videoWidget = new GLWidget(this);
50 setCentralWidget(videoWidget);
51 setWindowIcon(QIcon(":/res/vj.xpm"));
52 setWindowTitle("Virtual Jaguar v2.0.0");
54 QMenu * menu = menuBar()->addMenu(tr("&File"));
55 QToolBar * toolbar = addToolBar(tr("x1"));
56 /*QAction */ action = new QAction(tr("Toggle"), this);
57 action->setStatusTip(tr("Toggle running state"));
58 action->setCheckable(true);
59 toolbar->addAction(action);
60 connect(action, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
63 newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
64 newAct->setShortcuts(QKeySequence::New);
65 newAct->setStatusTip(tr("Create a new file"));
66 connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
68 openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
69 openAct->setShortcuts(QKeySequence::Open);
70 openAct->setStatusTip(tr("Open an existing file"));
71 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
73 aboutQtAct = new QAction(tr("About &Qt"), this);
74 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
75 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
78 fileMenu = menuBar()->addMenu(tr("&File"));
79 fileMenu->addAction(newAct);
80 fileMenu->addAction(openAct);
81 fileMenu->addAction(saveAct);
82 fileMenu->addAction(saveAsAct);
83 fileMenu->addSeparator();
84 fileMenu->addAction(exitAct);
86 editMenu = menuBar()->addMenu(tr("&Edit"));
87 editMenu->addAction(cutAct);
88 editMenu->addAction(copyAct);
89 editMenu->addAction(pasteAct);
91 menuBar()->addSeparator();
93 helpMenu = menuBar()->addMenu(tr("&Help"));
94 helpMenu->addAction(aboutAct);
95 helpMenu->addAction(aboutQtAct);
98 fileToolBar = addToolBar(tr("File"));
99 fileToolBar->addAction(newAct);
100 fileToolBar->addAction(openAct);
101 fileToolBar->addAction(saveAct);
103 editToolBar = addToolBar(tr("Edit"));
104 editToolBar->addAction(cutAct);
105 editToolBar->addAction(copyAct);
106 editToolBar->addAction(pasteAct);
110 statusBar()->showMessage(tr("Ready"));
114 // connect(textEdit->document(), SIGNAL(contentsChanged()),
115 // this, SLOT(documentWasModified()));
117 // setCurrentFile("");
118 setUnifiedTitleAndToolBarOnMac(true);
120 // Set up timer based loop for animation...
121 timer = new QTimer(this);
122 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
126 void MainWin::closeEvent(QCloseEvent * event)
129 event->accept(); // ignore() if can't close for some reason
132 void MainWin::Open(void)
136 void MainWin::Timer(void)
141 // Random hash & trash
142 // We try to simulate an untuned tank circuit here... :-)
143 for(int x=0; x<videoWidget->rasterWidth; x++)
145 for(int y=0; y<videoWidget->rasterHeight; y++)
147 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
148 // buffer[(y * textureWidth) + x] = x*y;
152 videoWidget->updateGL();
155 void MainWin::ToggleRunState(void)
160 void MainWin::ReadSettings(void)
162 QSettings settings("Underground Software", "Virtual Jaguar");
163 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
164 QSize size = settings.value("size", QSize(400, 400)).toSize();
167 //videoWidget->updateGL();
168 // pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
169 // size = settings.value("charWndSize", QSize(200, 200)).toSize();
170 // ((TTEdit *)qApp)->charWnd->resize(size);
171 // ((TTEdit *)qApp)->charWnd->move(pos);
174 void MainWin::WriteSettings(void)
176 QSettings settings("Underground Software", "Virtual Jaguar");
177 settings.setValue("pos", pos());
178 settings.setValue("size", size());
179 // settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
180 // settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());