OSDN Git Service

[denncoCreator] implemented the feature to launch dennco engine from creator.
authortkawata <tkawata@users.sourceforge.jp>
Tue, 23 Oct 2012 13:08:10 +0000 (22:08 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Tue, 23 Oct 2012 13:08:10 +0000 (22:08 +0900)
Source/dccreator.cpp
Source/denncoCreator.pro
Source/denncoCreator.qrc
Source/images/playbutton.png [new file with mode: 0644]
Source/mainwindow.cpp
Source/mainwindow.h

index 25f47f0..e1db5df 100644 (file)
@@ -68,6 +68,9 @@ DCCreator::~DCCreator()
 
 bool DCCreator::event(QEvent *event)
 {
+    if (!d_scene)
+        return false;
+
     if(event->type() == DCCommandEvent::EVENT_TYPEID)
     {
         DCCommandEvent *commandEvent = dynamic_cast<DCCommandEvent*>(event);
@@ -142,6 +145,7 @@ bool DCCreator::loadContent(const QString &contentRoot)
     else
     {
         d_scene = NULL;
+        emit contentRootPathChanged(this, d_contentRootPath);
         emit sceneChanged(this, NULL);
 
         if (!dnGlobal()->isErrorStatusNormal())
index 7f735f6..361b4ed 100644 (file)
@@ -1,5 +1,5 @@
 
-QT       += core gui xml opengl sql webkit
+QT       += core gui xml opengl sql webkit network
 
 INCLUDEPATH += engine/layer1 engine/layer2 visualizer visualizer/component visualizer/toolwindow visualizer/component/shape treeview codeeditor receptoreditor axoneditor axonterminaleditor
 
index 7cf04d9..6c5c194 100644 (file)
@@ -10,5 +10,6 @@
         <file alias="deleteItemIcon.png">images/minusIcon.png</file>
         <file alias="pageIcon.png">images/page.png</file>
         <file alias="folderIcon.png">images/folder.png</file>
+        <file>images/playbutton.png</file>
     </qresource>
 </RCC>
diff --git a/Source/images/playbutton.png b/Source/images/playbutton.png
new file mode 100644 (file)
index 0000000..1dbcea8
Binary files /dev/null and b/Source/images/playbutton.png differ
index c296042..3ca1749 100644 (file)
@@ -22,6 +22,7 @@
 #include "ui_mainwindow.h"
 
 #include "dccreator.h"
+#include "dccontent.h"
 #include "dcglvisualizerwidget.h"
 #include "dctreeviewwidget.h"
 #include "TKConsole.h"
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QSettings>
+#include <QLocalSocket>
+
+#ifdef Q_WS_WIN
+    const QString DENNCO_ENGINE = "QtDennco.exe";
+#elif Q_WS_MACX
+
+#elif Q_OS_UNIX
+
+#endif
+
+class SleeperThread : public QThread
+{
+public:
+    static void msleep(unsigned long msecs)
+    {
+        QThread::msleep(msecs);
+    }
+};
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
@@ -50,12 +69,17 @@ MainWindow::MainWindow(QWidget *parent) :
 
     TKLog::setDestination(new TKConsole);
 
-    mCreator = new DCCreator(this);
-    mVisualizerWidget = new DCGLVisualizerWidget(mCreator, this) ;
-    setCentralWidget(mVisualizerWidget);
+    d_IPCServerName = "denncoCreator_";
+    QTextStream s(&d_IPCServerName);
+    s.setIntegerBase(16);
+    s << qrand();
 
-    mTreeViewWidget = new DCTreeViewWidget(this, mCreator);
-    ui->treeViewDock->layout()->addWidget(mTreeViewWidget);
+    d_creator = new DCCreator(this);
+    d_visualizerWidget = new DCGLVisualizerWidget(d_creator, this) ;
+    setCentralWidget(d_visualizerWidget);
+
+    d_treeViewWidget = new DCTreeViewWidget(this, d_creator);
+    ui->treeViewDock->layout()->addWidget(d_treeViewWidget);
 
     setCurrentContent("");
     setUnifiedTitleAndToolBarOnMac(true);
@@ -64,8 +88,8 @@ MainWindow::MainWindow(QWidget *parent) :
 MainWindow::~MainWindow()
 {
     delete ui;
-    if (mCreator)
-        delete mCreator;
+    if (d_creator)
+        delete d_creator;
 }
 
 
@@ -178,15 +202,21 @@ void MainWindow::createActions()
     pasteAct->setShortcuts(QKeySequence::Paste);
     pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
                               "selection"));
-//    connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+    //    connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+    playAct = new QAction(QIcon(":/images/playbutton.png"), tr("Play"), this);
+    playAct->setStatusTip(tr("Play the editing content"));
+
+    connect(playAct, SIGNAL(triggered()), this, SLOT(playContent()));
 
     aboutAct = new QAction(tr("&About"), this);
     aboutAct->setStatusTip(tr("Show the application's About box"));
     connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
 
     cutAct->setEnabled(false);
-//! [23] //! [24]
     copyAct->setEnabled(false);
+    playAct->setEnabled(false);
 //    connect(textEdit, SIGNAL(copyAvailable(bool)),
 //            cutAct, SLOT(setEnabled(bool)));
 //    connect(textEdit, SIGNAL(copyAvailable(bool)),
@@ -216,29 +246,31 @@ void MainWindow::createMenus()
 
     menuBar()->addSeparator();
 
+    editMenu = menuBar()->addMenu(tr("&Play"));
+    editMenu->addAction(playAct);
+
+    menuBar()->addSeparator();
+
     helpMenu = menuBar()->addMenu(tr("&Help"));
     helpMenu->addAction(aboutAct);
 }
-//! [27]
 
-//! [29] //! [30]
 void MainWindow::createToolBars()
 {
     fileToolBar = addToolBar(tr("File"));
     fileToolBar->addAction(newAct);
-//! [29] //! [31]
     fileToolBar->addAction(openAct);
-//! [31]
     fileToolBar->addAction(saveAct);
 
     editToolBar = addToolBar(tr("Edit"));
     editToolBar->addAction(cutAct);
     editToolBar->addAction(copyAct);
     editToolBar->addAction(pasteAct);
+
+    playToolBar = addToolBar(tr("Play"));
+    playToolBar->addAction(playAct);
 }
-//! [30]
 
-//! [32]
 void MainWindow::createStatusBar()
 //! [32] //! [33]
 {
@@ -290,22 +322,29 @@ bool MainWindow::maybeSave()
 //! [42]
 void MainWindow::loadContent(const QString &contentDirectory)
 {
-    if (!mCreator)
+    if (!d_creator)
         return;
 
-    mCreator->loadContent(contentDirectory);
+    if (d_creator->loadContent(contentDirectory))
+    {
+        playAct->setEnabled(true);
+    }
+    else
+    {
+        playAct->setEnabled(false);
+    }
 
     setCurrentContent(contentDirectory);
 }
 
 bool MainWindow::saveContent()
 {
-    if (!mCreator)
+    if (!d_creator)
         return false;
 
-    if (mCreator->getCurrentContainer())
+    if (d_creator->getCurrentContainer())
     {
-        mCreator->saveAll(true);
+        d_creator->saveAll(true);
     }
 
     return true;
@@ -322,12 +361,67 @@ void MainWindow::setCurrentContent(const QString &contentDirectory)
         shownName = "untitled.txt";
     setWindowFilePath(shownName);
 }
-//! [47]
 
-//! [48]
 QString MainWindow::strippedName(const QString &fullFileName)
-//! [48] //! [49]
 {
     return QFileInfo(fullFileName).fileName();
 }
-//! [49]
+
+void MainWindow::playContent()
+{
+    if (!d_creator || !d_creator->getCurrentContent())
+        return;
+
+    if (d_player.state() != QProcess::NotRunning)
+    {
+        QLocalSocket *socket = new QLocalSocket(this);
+        connect(socket, SIGNAL(disconnected()), socket,SLOT(deleteLater()));
+
+        for (int retry = 0; retry < 10; retry++)
+        {
+            socket->connectToServer(d_IPCServerName);
+            if (socket->waitForConnected())
+            {
+                break;
+            }
+            SleeperThread::msleep(500);
+        }
+        QString requestData = "close,";
+        socket->write(requestData.toLocal8Bit());
+        socket->flush();
+        socket->close();
+    }
+
+    if (!d_player.waitForFinished(5000))
+        d_player.kill();
+
+    if (d_player.state() == QProcess::NotRunning)
+    {
+        QStringList args;
+        args << "-creatorControlled";
+        args << d_IPCServerName;
+
+        d_player.start(DENNCO_ENGINE, args);
+        d_player.waitForStarted(5000);
+    }
+
+    if (d_player.state() == QProcess::Running)
+    {
+        QLocalSocket *socket = new QLocalSocket(this);
+        connect(socket, SIGNAL(disconnected()), socket,SLOT(deleteLater()));
+        for (int retry = 0; retry < 10; retry++)
+        {
+            socket->connectToServer(d_IPCServerName);
+            if (socket->waitForConnected())
+            {
+                break;
+            }
+            SleeperThread::msleep(500);
+        }
+        QString requestData = "load,";
+        requestData.append(d_creator->getCurrentContent()->getContentRootPath());
+        socket->write(requestData.toLocal8Bit());
+        socket->flush();
+        socket->close();
+    }
+}
index 659c2f2..43d910d 100644 (file)
@@ -20,6 +20,8 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
+#include <QProcess>
+#include <QSharedMemory>
 
 namespace Ui {
 class MainWindow;
@@ -28,8 +30,6 @@ class MainWindow;
 class DCCreator;
 class DCGLVisualizerWidget;
 class DCTreeViewWidget;
-class DCCellInfoViewWidget;
-class DCCellCodeInfoViewWidget;
 
 class MainWindow : public QMainWindow
 {
@@ -50,6 +50,7 @@ private slots:
     bool saveAs();
     void about();
     void documentWasModified();
+    void playContent();
 
 private:
     void createActions();
@@ -71,6 +72,7 @@ private:
     QMenu *helpMenu;
     QToolBar *fileToolBar;
     QToolBar *editToolBar;
+    QToolBar *playToolBar;
     QAction *newAct;
     QAction *openAct;
     QAction *saveAct;
@@ -78,18 +80,17 @@ private:
     QAction *exitAct;
     QAction *cutAct;
     QAction *copyAct;
+    QAction *playAct;
     QAction *pasteAct;
     QAction *aboutAct;
 
-//! [0]
-private:
     Ui::MainWindow *ui;
 
-    DCCreator                   *mCreator;
-    DCGLVisualizerWidget        *mVisualizerWidget;
-    DCTreeViewWidget            *mTreeViewWidget;
-    DCCellInfoViewWidget        *mCellInfoViewWidget;
-    DCCellCodeInfoViewWidget    *mCellCodeInfoViewWidget;
+    DCCreator                   *d_creator;
+    DCGLVisualizerWidget        *d_visualizerWidget;
+    DCTreeViewWidget            *d_treeViewWidget;
+    QProcess                    d_player;
+    QString                     d_IPCServerName;
 };
 
 #endif // MAINWINDOW_H