summaryrefslogtreecommitdiff
path: root/ldmicro/confdialog.cpp
diff options
context:
space:
mode:
authorakshay-c2019-04-26 11:46:09 +0530
committerakshay-c2019-04-26 11:46:09 +0530
commitc42da945ba01864b55358c95ed0833e37af8fcdc (patch)
treeeb3a9bc57f6fd239ba7c839fedc546e4f98c6182 /ldmicro/confdialog.cpp
parent11b0fb9ef4dc1bb34cef5415855fce647a6b0c83 (diff)
downloadLDmicroQt-c42da945ba01864b55358c95ed0833e37af8fcdc.tar.gz
LDmicroQt-c42da945ba01864b55358c95ed0833e37af8fcdc.tar.bz2
LDmicroQt-c42da945ba01864b55358c95ed0833e37af8fcdc.zip
ConfDialog completed, issues with dialog close resolved
Diffstat (limited to 'ldmicro/confdialog.cpp')
-rw-r--r--ldmicro/confdialog.cpp172
1 files changed, 112 insertions, 60 deletions
diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp
index 099d35a..f63fae9 100644
--- a/ldmicro/confdialog.cpp
+++ b/ldmicro/confdialog.cpp
@@ -31,51 +31,65 @@
using namespace std;
-static HWID ConfDialog;
+static QDialog* ConfDialog;
-static HWID CrystalTextbox;
-static HWID CycleTextbox;
-static HWID BaudTextbox;
-static HWID OkButton;
-static HWID CancelButton;
+static QLineEdit* CrystalTextbox;
+static QLineEdit* CycleTextbox;
+static QLineEdit* BaudTextbox;
+static QDialogButtonBox* ButtonBox;
static LONG_PTR PrevCrystalProc;
static LONG_PTR PrevCycleProc;
static LONG_PTR PrevBaudProc;
-HWID ConfGrid;
-HWID ConfPackingBox;
+QGridLayout* ConfGrid;
+
+static inline void DestroyWindow()
+{
+ delete ConfDialog;
+ delete CrystalTextbox;
+ delete CycleTextbox;
+ delete BaudTextbox;
+ delete ButtonBox;
+ delete ConfGrid;
+}
static void MakeControls(void)
{
// Creating text labels
- HWID textLabel = gtk_label_new ("Cycle Time (ms):");
- HWID textLabel2 = gtk_label_new ("Crystal Frequency (MHz):");
- HWID textLabel3 = gtk_label_new ("UART Baud Rate (bps):");
-
- // Creating text boxes
- CycleTextbox = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (CycleTextbox), 0);
- // gtk_entry_set_input_purpose (GTK_ENTRY (CycleTextbox), GTK_INPUT_PURPOSE_DIGITS);
- CrystalTextbox = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (CrystalTextbox), 0);
- BaudTextbox = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (BaudTextbox), 0);
+
+ QLabel* textLabel = new QLabel(_("Cycle Time (ms):"));
+ QLabel* textLabel2 = new QLabel(_("Crystal Frequency (MHz):"));
+ QLabel* textLabel3 = new QLabel(_("UART Baud Rate (bps):"));
+
+ CycleTextbox = new QLineEdit();
+ CrystalTextbox = new QLineEdit();
+ BaudTextbox = new QLineEdit();
+ CycleTextbox->setValidator(
+ new QRegExpValidator(
+ QRegExp("[0-9]+")));
+ CrystalTextbox->setValidator(
+ new QRegExpValidator(
+ QRegExp("[0-9]+")));
+ BaudTextbox->setValidator(
+ new QRegExpValidator(
+ QRegExp("[0-9]+")));
if(!UartFunctionUsed()) {
- gtk_widget_set_sensitive (BaudTextbox, FALSE);
- gtk_widget_set_sensitive (textLabel3, FALSE);
+ BaudTextbox->setEnabled(FALSE);
+ textLabel3->setEnabled(FALSE);
}
if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC ||
Prog.mcu->whichIsa == ISA_INTERPRETED))
{
- gtk_widget_set_sensitive (CrystalTextbox, FALSE);
- gtk_widget_set_sensitive (textLabel2, FALSE);
+ CrystalTextbox->setEnabled(FALSE);
+ textLabel2->setEnabled(FALSE);
}
- OkButton = gtk_button_new_with_label ("OK");
- CancelButton = gtk_button_new_with_label ("Cancel");
+ ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel, Qt::Vertical,
+ ConfDialog);
char explanation[1024] = "";
@@ -91,43 +105,45 @@ static void MakeControls(void)
}
}
else {
- strcpy(explanation, _("\n No serial instructions (UART Send/UART Receive) \n"
- "are in use; add one to program before \n"
- "setting baud rate.\r\n\r\n") );
+ strcpy(explanation, _("No serial instructions (UART Send/UART Receive) "
+ "are in use; add one to program before setting baud rate.\r\n\r\n") );
}
strcat(explanation,
- _("The cycle time for the 'PLC' runtime generated by \n" "LDmicro is user-"
- "configurable. Very short cycle \n" "times may not be achievable due "
- "to processor \n" "speed constraints, and very long cycle times may \n"
- "not be achievable due to hardware overflows. Cycle \n" "times between 10 ms \n"
+ _("The cycle time for the 'PLC' runtime generated by LDmicro is user-"
+ "configurable. Very short cycle times may not be achievable due "
+ "to processor speed constraints, and very long cycle times may not "
+ "be achievable due to hardware overflows. Cycle times between 10 ms "
"and 100 ms will usually be practical.\r\n\r\n"
- "The compiler must know what speed crystal you \n" "are using with the "
- "micro to convert between timing \n" "in clock cycles and timing in"
- "seconds. A 4 MHz to \n" "20 MHz crystal is typical; check the speed "
- "grade of \n" "the part you are using to determine the maximum \n" "allowable"
- "clock speed before choosing a crystal.\n"));
+ "The compiler must know what speed crystal you are using with the "
+ "micro to convert between timing in clock cycles and timing in "
+ "seconds. A 4 MHz to 20 MHz crystal is typical; check the speed "
+ "grade of the part you are using to determine the maximum allowable "
+ "clock speed before choosing a crystal."));
- HWID textLabel4 = gtk_label_new (explanation);
+ QLabel* textLabel4 = new QLabel(explanation);
+ textLabel4->setAlignment(Qt::AlignJustify);
+ textLabel4->setMaximumWidth(310);
+ textLabel4->setWordWrap(TRUE);
// Creating required containers for packing
- ConfGrid = gtk_grid_new();
- ConfPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
-
- gtk_grid_attach (GTK_GRID (ConfGrid), textLabel, 1, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), CycleTextbox, 3, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), OkButton, 6, 2, 2, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), textLabel2, 1, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), CrystalTextbox, 3, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), CancelButton, 6, 4, 2, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), textLabel3, 1, 6, 1, 1);
- gtk_grid_attach (GTK_GRID (ConfGrid), BaudTextbox, 3, 6, 1, 1);
-
- gtk_grid_set_column_spacing (GTK_GRID (ConfGrid), 2);
-
- gtk_box_pack_start(GTK_BOX(ConfPackingBox), ConfGrid, TRUE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(ConfPackingBox), textLabel4, TRUE, TRUE, 0);
-
+ ConfGrid->addWidget(textLabel, 0,0);
+ ConfGrid->addWidget(CycleTextbox, 0,1);
+ ConfGrid->addWidget(ButtonBox, 0, 2, 0, 2);
+ ConfGrid->addWidget(textLabel2, 1, 0);
+ ConfGrid->addWidget(CrystalTextbox, 1, 1);
+ ConfGrid->addWidget(textLabel3, 2, 0);
+ ConfGrid->addWidget(BaudTextbox, 2, 1);
+ ConfGrid->addWidget(textLabel4, 3, 0, 2, 0,
+ Qt::AlignJustify);
+ NiceFont(ConfDialog);
+ CycleTextbox->setFocus();
+ // int height = textLabel4->pos().y();
+ // printf("Height:%d\n", height);
+ // ConfDialog->setSize(ConfGrid->sizeHint());
+ ConfDialog->adjustSize();
+ QObject::connect(ButtonBox, SIGNAL(accepted()), ConfDialog, SLOT(accept()));
+ QObject::connect(ButtonBox, SIGNAL(rejected()), ConfDialog, SLOT(reject()));
// PrevCycleProc = SetWindowLongPtr(CycleTextbox, GWLP_WNDPROC,
// (LONG_PTR)MyNumberProc);
@@ -137,7 +153,7 @@ static void MakeControls(void)
// PrevBaudProc = SetWindowLongPtr(BaudTextbox, GWLP_WNDPROC,
// (LONG_PTR)MyNumberProc);
}
-
+/*
//-----------------------------------------------------------------------------
// Don't allow any characters other than 0-9. in the text boxes.
//-----------------------------------------------------------------------------
@@ -208,12 +224,48 @@ void ConfDialogSignalCall () {
G_CALLBACK(ConfCallDestroyWindow), NULL);
g_signal_connect (ConfDialog, "delete_event", G_CALLBACK (ConfCallDestroyWindow), NULL);
}
-
+*/
void ShowConfDialog(void)
{
// The window's height will be resized later, to fit the explanation text.
+ ConfDialog = CreateWindowClient(_("PLC Configuration"),
+ 100, 100, 0, 0, MainWindow);
+ ConfGrid = new QGridLayout(ConfDialog);
MakeControls();
- GdkEventKey* event;
+ char buf[16];
+ sprintf(buf, "%.1f", (Prog.cycleTime / 1000.0));
+ CycleTextbox->setText(buf);
+
+ sprintf(buf, "%.6f", Prog.mcuClock / 1e6);
+ CrystalTextbox->setText(buf);
+
+ sprintf(buf, "%d", Prog.baudRate);
+ BaudTextbox->setText(buf);
+ int ret = ConfDialog->exec();
+ switch(ret)
+ {
+ case QDialog::Accepted:
+ {
+ char buf[16];
+ strncpy(buf, CycleTextbox->text().toStdString().c_str(),16);
+ Prog.cycleTime = (int)(1000*atof(buf) + 0.5);
+ if(Prog.cycleTime == 0) {
+ Error(_("Zero cycle time not valid; resetting to 10 ms."));
+ Prog.cycleTime = 10000;
+ }
+
+ strncpy(buf, CrystalTextbox->text().toStdString().c_str(),16);
+ Prog.mcuClock = (int)(1e6*atof(buf) + 0.5);
+
+ strncpy(buf, BaudTextbox->text().toStdString().c_str(),16);
+ Prog.baudRate = atoi(buf);
+ }
+ break;
+ case QDialog::Rejected:
+ break;
+ }
+ // DestroyWindow();
+/* GdkEventKey* event;
ConfDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(ConfDialog), "PLC Configuration");
@@ -241,5 +293,5 @@ void ShowConfDialog(void)
ConfDialogSignalCall();
- return;
+ return;*/
} \ No newline at end of file