From 879b59817c6e29922e46e66dc901a250c0245e91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Thu, 21 Jan 2016 16:40:43 +0100 Subject: [PATCH] Move layout code into separate ui file. Compile layout using uic --- Makefile.am | 10 ++- src/kernel/kernel.cpp | 94 +++++++++--------------- src/kernel/kernel.h | 45 +++++------- src/kernel/kernelwindow.ui | 146 +++++++++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+), 86 deletions(-) create mode 100644 src/kernel/kernelwindow.ui diff --git a/Makefile.am b/Makefile.am index 2a77e83..5a902a5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 = \ diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index b63a148..49c9314 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -64,6 +64,7 @@ #include #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; diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 168777c..e0843cb 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -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 index 0000000..0b4170c --- /dev/null +++ b/src/kernel/kernelwindow.ui @@ -0,0 +1,146 @@ + + + KernelWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 0 + 0 + 800 + 19 + + + + + Program + + + + + + + + + Machine + + + + + + + + + + Tools + + + + + + + + + + + + + + + + + + Execute + + + + + Kill + + + + + Message + + + + + Connect + + + + + Disconnect + + + + + Info + + + + + true + + + Editor + + + + + Help + + + + + Options + + + + + true + + + true + + + true + + + Info messages + + + + + Lock console + + + + + false + + + Unlock console + + + + + Quit + + + + + + -- 2.30.2