Move layout code into separate ui file. Compile layout using uic
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Thu, 21 Jan 2016 15:40:43 +0000 (16:40 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Thu, 21 Jan 2016 15:40:43 +0000 (16:40 +0100)
Makefile.am
src/kernel/kernel.cpp
src/kernel/kernel.h
src/kernel/kernelwindow.ui [new file with mode: 0644]

index 2a77e838f65263902457d670531b98b6d2bcaf06..5a902a5ed06d9b02dac9f2bb2557feb1ee4ed317 100644 (file)
@@ -22,7 +22,6 @@ EXTRA_DIST = \
 #  bin/loghelp
 
 bin_PROGRAMS = \
-  bin/loggraph   \
   bin/lognet \
   bin/logker \
   bin/logint \
@@ -70,12 +69,17 @@ bin_logker_LDADD = $(bin_logker_LIBS)
 bin_logkerdir = src/kernel
 bin_logker_HEADERS = \
        src/kernel/kernel.h
-src/kernel/kernel.moc.cpp: src/kernel/kernel.h
+src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/kernelwindow.h
        moc-qt4 src/kernel/kernel.h -o src/kernel/kernel.moc.cpp
 #      $(MOC) -i src/kernel/kernel.cpp -o src/kernel/kernel.moc
-       
+
+src/kernel/kernelwindow.h:
+       uic src/kernel/kernelwindow.ui -o src/kernel/kernelwindow.h
+
+
 clean-logker-extra:
        rm -f src/kernel/*.moc
+       rm -f src/kernel/kernelwindow.h
        rm -f bin/logker
        
 bin_logint_SOURCES = \
index b63a148ae4fba69ca2edd47b7fffaba7d49be9f8..49c9314e6e1482bc6dcea88f2a0eed92a1573beb 100644 (file)
@@ -64,6 +64,7 @@
 #include <libconfig.h>
 
 #include "kernel.h"
+#include "kernelwindow.h"
 
 /* File resides in top directory (where are Makefiles)*/
 #include "../../config.h"
@@ -83,7 +84,7 @@ void QKernel::closeEvent(QCloseEvent * e)
        e->ignore();
 
        if (!LOCKED) {
-               QuitProc();
+               on_actionQuit_triggered();
        }
 }
 
@@ -91,19 +92,21 @@ void QKernel::setLocked(bool locked)
 {
        LOCKED = locked;
 
-       quitAction->setDisabled(locked);
-       programExecuteAction->setDisabled(locked);
-       programKillAction->setDisabled(locked);
-       machineMessageAction->setDisabled(locked);
-       machineConnectAction->setDisabled(locked);
-       machineDisconnectAction->setDisabled(locked);
-       machineInfoAction->setDisabled(locked);
+       actionQuit->setDisabled(locked);
+
+       actionExecute->setDisabled(locked);
+       actionKill->setDisabled(locked);
+       actionMessage->setDisabled(locked);
+       actionConnect->setDisabled(locked);
+       actionDisconnect->setDisabled(locked);
+       actionInfo->setDisabled(locked);
+
 
        /* Enable only menu entry for unlocking */
-       toolsEditorAction->setDisabled(locked);
-       toolsOptionsAction->setDisabled(locked);
-       toolsLockAction->setDisabled(locked);
-       toolsUnlockAction->setEnabled(locked);
+       actionEditor->setDisabled(locked);
+       actionOptions->setDisabled(locked);
+       actionLock_console->setDisabled(locked);
+       actionUnlock_console->setDisabled(!locked);
 }
 
 /**
@@ -112,6 +115,8 @@ void QKernel::setLocked(bool locked)
  */
 QKernel::QKernel()
 {
+       setupUi(this);
+
        QDir q(REMOTE_PATH);
        char ss[255];
 
@@ -125,35 +130,8 @@ QKernel::QKernel()
 
        setWindowTitle(PACKAGE_NAME);
 
-       QMenu * programMenu = NULL;
-       programMenu = menuBar()->addMenu("&Program");
-       programExecuteAction = programMenu->addAction("Execute", this, SLOT(Run_Prog()));
-       programKillAction = programMenu->addAction("Kill", this, SLOT(KillInterpreter()));
-
-       machineMenu = menuBar()->addMenu("&Machine");
-       machineMessageAction = machineMenu->addAction("Message", this, SLOT(MessageToNode()));
-       machineMenu->addSeparator();
-       machineConnectAction = machineMenu->addAction("Connect", this, SLOT(Connect()));
-       machineDisconnectAction = machineMenu->addAction("Disconnect", this, SLOT(Disconnect()));
-       machineInfoAction = machineMenu->addAction("Info", this, SLOT(Info()));
-
-       toolsMenu = menuBar()->addMenu("&Tools");
-       toolsEditorAction = toolsMenu->addAction("Editor", this, SLOT(Edit()));
-       toolsMenu->addAction("Help", this, SLOT(Help()));
-       toolsMenu->addSeparator(); 
-       toolsOptionsAction = toolsMenu->addAction("Options", this, SLOT(SetOptions()));
-       toolsInfoAction = toolsMenu->addAction("Info messages", this, SLOT(SetMessages()));
-       toolsInfoAction->setCheckable(TRUE);
-       toolsInfoAction->setChecked(TRUE);
-       toolsMenu->addSeparator();
-       toolsLockAction = toolsMenu->addAction("Lock console", this, SLOT(LockConsole()));
-       toolsUnlockAction = toolsMenu->addAction("Unlock console", this, 
-                                                       SLOT(UnlockConsole()));
-       toolsUnlockAction->setDisabled(TRUE);
        LOCKED = FALSE;
 
-       quitAction = menuBar()->addAction("&Quit", this, SLOT(QuitProc()));
-
        desktop = new QTextEdit(this);
        desktop->setReadOnly(TRUE);
        QVBoxLayout * layout = new QVBoxLayout();
@@ -303,7 +281,7 @@ void QKernel::LoadConfig(char * fname)
  * Executes program.
  * Additional window id displayed to set which code to execute.
  */
-void QKernel::Run_Prog()
+void QKernel::on_actionExecute_triggered()
 {
        int i;
        QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
@@ -321,7 +299,7 @@ void QKernel::Run_Prog()
 /**
  * Invokes editor program
  */
-void QKernel::Edit()
+void QKernel::on_actionEditor_triggered()
 {
        char cmd[255];
        sprintf(cmd, "%s/modules/logedit %s %s %s %s %s %s &", HomeDir, HomeDir, 
@@ -332,7 +310,7 @@ void QKernel::Edit()
 /**
  * Invokes help program
  */
-void QKernel::Help()
+void QKernel::on_actionHelp_triggered()
 {
        char cmd[255];
        sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir,
@@ -390,14 +368,14 @@ void QKernel::RunNetModule()
                        WriteMessage("Cannot connect NETWORK resources");
                        WriteMessage("Exiting...");
                        sleep(2);
-                       QuitProc(); 
+                       on_actionQuit_triggered();
                }
        /* system OK */
        } else {
                WriteMessage("Cannot connect NETWORK resources");
                WriteMessage("Exiting...");
                sleep(2);
-               QuitProc(); 
+               on_actionQuit_triggered();
        }
 }
 
@@ -405,7 +383,7 @@ void QKernel::RunNetModule()
  * Connects to the specified address
  * Additional window is displayed to connect to the specified address
  */
-void QKernel::Connect()
+void QKernel::on_actionConnect_triggered()
 {
        QDialog d(this, Qt::Dialog);
        QLabel lab("IP Address:", &d);
@@ -437,7 +415,7 @@ void QKernel::Connect()
 /**
  * Disconnects from virtual machine
  */
-void QKernel::Disconnect()
+void QKernel::on_actionDisconnect_triggered()
 {
        MESSAGE msg;
 
@@ -452,7 +430,7 @@ void QKernel::Disconnect()
 /**
  * Quits process. Closes VLP. Shows additional window to confirm exit. 
  */
-void QKernel::QuitProc()
+void QKernel::on_actionQuit_triggered()
 {
        MESSAGE msg;
 
@@ -526,7 +504,7 @@ void QKernel::DelAddress()
  * Additional window is displayed to set Node Number of node where send message,
  * and textfield to enter message.
  */
-void QKernel::MessageToNode()
+void QKernel::on_actionMessage_triggered()
 {
        QDialog *dlg;
        QLineEdit *nodenr;
@@ -579,7 +557,7 @@ void QKernel::MessageToNode()
  * Additional window is displayed to get ID of interpreter which should be
  * killed.
  */
-void QKernel::KillInterpreter()
+void QKernel::on_actionKill_triggered()
 {
        QDialog *dlg;
        QLineEdit *nodenr;
@@ -840,13 +818,13 @@ void QKernel::WriteMessage(char *msg)
  * Adds checkbox to menu item. If it is checked additional info messages are
  * shown.
  */
-void QKernel::SetMessages()
+void QKernel::on_actionInfo_messages_triggered()
 {
        if (toolsMenu != NULL) {
-               toolsInfoAction->setChecked(!toolsInfoAction->isChecked());
-//             toolsInfoAction->toggle();
-               info_messages = toolsInfoAction->isChecked();
-               fprintf(stderr, "Info is checked? %s\n", toolsInfoAction->isChecked() ? "yes" : "no");
+               actionInfo_messages->setChecked(!actionInfo_messages->isChecked());
+//             actionInfo_messages->toggle();
+               info_messages = actionInfo_messages->isChecked();
+               fprintf(stderr, "Info is checked? %s\n", actionInfo_messages->isChecked() ? "yes" : "no");
        }
 //     menuBar()->repaint();
 }
@@ -856,7 +834,7 @@ void QKernel::SetMessages()
  * Additional window is displayed to set kernel options which are saved in 
  * vlp.cfg file in kernel executable directory.
  */
-void QKernel::SetOptions()
+void QKernel::on_actionOptions_triggered()
 {
        QDialog dlg(this, Qt::Dialog);
        dlg.setWindowTitle("Options");
@@ -995,7 +973,7 @@ void QKernel::SetOptions()
  * Additional window is displayed to enter password and retype it. If both are
  * same kernel window is locked.
  */
-void QKernel::LockConsole()
+void QKernel::on_actionLock_console_triggered()
 {
        QDialog d(this, Qt::Dialog);
        d.setWindowTitle("Lock console");
@@ -1054,7 +1032,7 @@ void QKernel::LockConsole()
  * Additional window is displayed to enter password. If it is correct, kernel 
  * window is unlocked
  */
-void QKernel::UnlockConsole()
+void QKernel::on_actionUnlock_console_triggered()
 {
        QDialog d(this, Qt::Dialog);
        d.setWindowTitle("Enter password");
@@ -1346,7 +1324,7 @@ void QKernel::CloseInstances(InterpEntry *e)
 /**
  * Displays information about virtual machine
  */
-void QKernel::Info()
+void QKernel::on_actionInfo_triggered()
 {
        MESSAGE m;
 
index 168777c1631efb92c7b7132affc23f2c8151936b..e0843cb09fed52fbc9a7c2965c3847353f76c9cc 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "comm.h"
 
+#include "kernelwindow.h"
+
 #define GPATH "loggr"
 #define IPATH "logi"
 #define NPATH "logn"
@@ -90,7 +92,7 @@ public:
 /**
  * Kernel class
  */
-class QKernel : public QMainWindow {
+class QKernel : public QMainWindow, private Ui::KernelWindow {
        Q_OBJECT
 public:
        QTextEdit *desktop;
@@ -111,23 +113,10 @@ public:
 
 public slots:
        void n_impl();
-       void Run_Prog();
-       void Edit();
-       void Help();
-       void SetOptions();
        void AddAddress();
        void DelAddress();
-       void LockConsole();
-       void UnlockConsole();
-       void MessageToNode();
-       void QuitProc();
        void NetMessage();
        void IntMessage(int);
-       void KillInterpreter();
-       void Disconnect();
-       void SetMessages();
-       void Connect();
-       void Info();
 
 protected:
        virtual void closeEvent (QCloseEvent * e);
@@ -154,17 +143,6 @@ private:
        bool synchro;
        bool wait_for_info;
        char LockPasswd[25];
-       QAction * toolsEditorAction;
-       QAction * toolsOptionsAction;
-       QAction * toolsInfoAction;
-       QAction * programExecuteAction;
-       QAction * programKillAction;
-       QAction * machineMessageAction;
-       QAction * machineConnectAction;
-       QAction * machineDisconnectAction;
-       QAction * machineInfoAction;
-       QAction * toolsLockAction;
-       QAction * toolsUnlockAction;
        QAction * quitAction;
        
        int net_sock;
@@ -187,6 +165,23 @@ private:
         * @param locked status which will be set on the menu entries.
         */
        void setLocked(bool locked);
+
+private slots:
+       void on_actionExecute_triggered();
+       void on_actionKill_triggered();
+       void on_actionQuit_triggered();
+       
+       void on_actionMessage_triggered();
+       void on_actionConnect_triggered();
+       void on_actionDisconnect_triggered();
+       void on_actionInfo_triggered();
+
+       void on_actionEditor_triggered();
+       void on_actionHelp_triggered();
+       void on_actionOptions_triggered();
+       void on_actionInfo_messages_triggered();
+       void on_actionLock_console_triggered();
+       void on_actionUnlock_console_triggered();
 };
 
 #endif /* VLP_KERNEL_H */
diff --git a/src/kernel/kernelwindow.ui b/src/kernel/kernelwindow.ui
new file mode 100644 (file)
index 0000000..0b4170c
--- /dev/null
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>KernelWindow</class>
+ <widget class="QMainWindow" name="KernelWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget"/>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>19</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuProgram">
+    <property name="title">
+     <string>Program</string>
+    </property>
+    <addaction name="actionExecute"/>
+    <addaction name="actionKill"/>
+    <addaction name="separator"/>
+    <addaction name="actionQuit"/>
+   </widget>
+   <widget class="QMenu" name="menuMachine">
+    <property name="title">
+     <string>Machine</string>
+    </property>
+    <addaction name="actionMessage"/>
+    <addaction name="separator"/>
+    <addaction name="actionConnect"/>
+    <addaction name="actionDisconnect"/>
+    <addaction name="actionInfo"/>
+   </widget>
+   <widget class="QMenu" name="menuTools">
+    <property name="title">
+     <string>Tools</string>
+    </property>
+    <addaction name="actionEditor"/>
+    <addaction name="actionHelp"/>
+    <addaction name="separator"/>
+    <addaction name="actionOptions"/>
+    <addaction name="actionInfo_messages"/>
+    <addaction name="separator"/>
+    <addaction name="actionLock_console"/>
+    <addaction name="actionUnlock_console"/>
+   </widget>
+   <addaction name="menuProgram"/>
+   <addaction name="menuMachine"/>
+   <addaction name="menuTools"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <action name="actionExecute">
+   <property name="text">
+    <string>Execute</string>
+   </property>
+  </action>
+  <action name="actionKill">
+   <property name="text">
+    <string>Kill</string>
+   </property>
+  </action>
+  <action name="actionMessage">
+   <property name="text">
+    <string>Message</string>
+   </property>
+  </action>
+  <action name="actionConnect">
+   <property name="text">
+    <string>Connect</string>
+   </property>
+  </action>
+  <action name="actionDisconnect">
+   <property name="text">
+    <string>Disconnect</string>
+   </property>
+  </action>
+  <action name="actionInfo">
+   <property name="text">
+    <string>Info</string>
+   </property>
+  </action>
+  <action name="actionEditor">
+   <property name="enabled">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Editor</string>
+   </property>
+  </action>
+  <action name="actionHelp">
+   <property name="text">
+    <string>Help</string>
+   </property>
+  </action>
+  <action name="actionOptions">
+   <property name="text">
+    <string>Options</string>
+   </property>
+  </action>
+  <action name="actionInfo_messages">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="checked">
+    <bool>true</bool>
+   </property>
+   <property name="enabled">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Info messages</string>
+   </property>
+  </action>
+  <action name="actionLock_console">
+   <property name="text">
+    <string>Lock console</string>
+   </property>
+  </action>
+  <action name="actionUnlock_console">
+   <property name="enabled">
+    <bool>false</bool>
+   </property>
+   <property name="text">
+    <string>Unlock console</string>
+   </property>
+  </action>
+  <action name="actionQuit">
+   <property name="text">
+    <string>Quit</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>