summaryrefslogtreecommitdiff
path: root/ldmicro/lutdialog.cpp
diff options
context:
space:
mode:
authorakshay-c2019-04-25 16:36:07 +0530
committerakshay-c2019-04-25 16:36:07 +0530
commitf6bbbce25c376efcc3cb645a4f87816c3b5aadb6 (patch)
treee546528894dfdbcc0e4d039446a20c31a0ff723a /ldmicro/lutdialog.cpp
parentc3a5877f22d47142c204c291227c5a70e33940d3 (diff)
downloadLDmicroQt-f6bbbce25c376efcc3cb645a4f87816c3b5aadb6.tar.gz
LDmicroQt-f6bbbce25c376efcc3cb645a4f87816c3b5aadb6.tar.bz2
LDmicroQt-f6bbbce25c376efcc3cb645a4f87816c3b5aadb6.zip
Created dialog boxes for compare,move,readadc,pwm,uart,math,shift register,formattedstring,Persist, LookupTable,PiecewiseLinear
Diffstat (limited to 'ldmicro/lutdialog.cpp')
-rw-r--r--ldmicro/lutdialog.cpp706
1 files changed, 241 insertions, 465 deletions
diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp
index 04e7684..a4e5987 100644
--- a/ldmicro/lutdialog.cpp
+++ b/ldmicro/lutdialog.cpp
@@ -33,86 +33,65 @@
using namespace std;
-static HWID LutDialog;
+static QDialog* LutDialog;
-static HWID AsStringCheckbox;
-static HWID CountTextbox;
-static HWID DestTextbox;
-static HWID IndexTextbox;
-static HWID Labels[3];
+static QCheckBox* AsStringCheckbox;
+static QLineEdit* CountTextbox;
+static QLineEdit* DestTextbox;
+static QLineEdit* IndexTextbox;
+static QLabel* Labels[3];
-static HWID StringTextbox;
+static QLineEdit* StringTextbox;
static bool checkString;
static BOOL WasAsString;
+static BOOL asString;
+static int ControlCount;
static int WasCount;
-static HWID ValuesTextbox[MAX_LOOK_UP_TABLE_LEN];
+static QLineEdit* ValuesTextbox[MAX_LOOK_UP_TABLE_LEN];
static LONG_PTR PrevValuesProc[MAX_LOOK_UP_TABLE_LEN];
-static HWID ValuesLabel[MAX_LOOK_UP_TABLE_LEN];
+static QLabel* ValuesLabel[MAX_LOOK_UP_TABLE_LEN];
static SWORD ValuesCache[MAX_LOOK_UP_TABLE_LEN];
static LONG_PTR PrevDestProc;
static LONG_PTR PrevIndexProc;
static LONG_PTR PrevCountProc;
-static HWID OkButton;
-static HWID CancelButton;
+static QDialogButtonBox* ButtonBox;
static UINT LUT_DIALOG_REFRESH_TIMER_ID_1 = 0;
static UINT LUT_DIALOG_REFRESH_TIMER_ID_2 = 0;
-HWID LutGrid;
-HWID LutPackingBox;
+static QGridLayout* LutGrid;
+static QGridLayout* LutPackingBox;
+static QGridLayout* FixedControlGrid;
+static QGridLayout* LutControlGrid;
+char PrevTableAsString[1024];
-struct LookUpTableDialogBuffer{
+/*struct LookUpTableDialogBuffer{
int tmpcount;
bool tmpasString;
char PrevTableAsString[1024] = "";
-} temp;
+} temp;*/
static int piecewiseTmpCount;
-
-//-----------------------------------------------------------------------------
-// Don't allow any characters other than 0-9 and minus in the values.
-//-----------------------------------------------------------------------------
-
-void LutDialogMyNumberProc (GtkEditable *editable, gchar *NewText, gint length,
- gint *position, gpointer data){
- for (int i = 0; i < length; i++){
- if (!(isdigit (NewText[i]) || NewText[i] == '\b' || NewText[i] == '-')){
- g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
- return;
- }
- }
-}
-
-//-----------------------------------------------------------------------------
-// Don't allow any characters other than 0-9 in the count.
-//-----------------------------------------------------------------------------
-
-void LutDialogMyDigitsProc (GtkEditable *editable, gchar *NewText, gint length,
- gint *position, gpointer data){
- for (int i = 0; i < length; i++){
- if (!(isdigit (NewText[i]) || NewText[i] == '\b' )){
- g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
- return;
- }
- }
-}
-
-//-----------------------------------------------------------------------------
-// Don't allow any characters other than A-Za-z0-9_ in the name.
-//-----------------------------------------------------------------------------
-
-void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length,
- gint *position, gpointer data){
- for (int i = 0; i < length; i++){
- if (!(isalpha (NewText[i]) || NewText[i] == '_' || isdigit (NewText[i])
- || NewText[i] == '\b' )){
- g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
- return;
- }
- }
+void CheckBoxFunction(int state);
+void CountFunction(QString text);
+void StringFunction(QString text);
+
+
+inline void DestroyWindow (){
+ delete Labels[0];
+ delete Labels[1];
+ delete Labels[2];
+ delete DestTextbox;
+ delete IndexTextbox;
+ delete CountTextbox;
+ delete AsStringCheckbox;
+ delete FixedControlGrid;
+ delete LutGrid;
+ delete ButtonBox;
+ ProgramChanged();
}
//-----------------------------------------------------------------------------
@@ -124,44 +103,51 @@ void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length,
static void MakeFixedControls(BOOL forPwl)
{
bool madeCheckbox = FALSE;
- Labels[0] = gtk_label_new ("Destination");
- Labels[1] = gtk_label_new ("Index:");
- Labels[2] = forPwl ? gtk_label_new ("Points:") : gtk_label_new ("Count:");
-
- DestTextbox = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (DestTextbox), 0);
- IndexTextbox = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (IndexTextbox), 0);
- CountTextbox = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (CountTextbox), 0);
+ FixedControlGrid = new QGridLayout();
+ Labels[0] = new QLabel(_("Destination"));
+ Labels[1] = new QLabel(_("Index:"));
+ Labels[2] = new QLabel(forPwl ? _("Points:") : _("Count:"));
+
+ DestTextbox = new QLineEdit();
+ // gtk_entry_set_max_length (GTK_ENTRY (DestTextbox), 0);
+ IndexTextbox = new QLineEdit();
+ // gtk_entry_set_max_length (GTK_ENTRY (IndexTextbox), 0);
+ CountTextbox = new QLineEdit();
+ // gtk_entry_set_max_length (GTK_ENTRY (CountTextbox), 0);
+ DestTextbox->setValidator(
+ new QRegExpValidator(
+ QRegExp("[a-zA-Z0-9_]+")));
+ IndexTextbox->setValidator(
+ new QRegExpValidator(
+ QRegExp("[a-zA-Z0-9_]+")));
+ CountTextbox->setValidator(
+ new QRegExpValidator(
+ QRegExp("[0-9]+")));
if(!forPwl) {
- AsStringCheckbox = gtk_check_button_new_with_label
- ("Edit table of ASCII values like a string");
- madeCheckbox = TRUE;
+ AsStringCheckbox = new QCheckBox(
+ _("Edit table of ASCII values like a string"), LutDialog);
}
-
- OkButton = gtk_button_new_with_label ("OK");
- CancelButton = gtk_button_new_with_label ("Cancel");
-
- gtk_grid_attach (GTK_GRID (LutGrid), Labels[0], 0, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), DestTextbox, 1, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), OkButton, 3, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), Labels[1], 0, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), IndexTextbox, 1, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), CancelButton, 3, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), Labels[2], 0, 6, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), CountTextbox, 1, 6, 1, 1);
- if (madeCheckbox){
- gtk_grid_attach (GTK_GRID (LutGrid), AsStringCheckbox, 0, 8, 1, 1);
+ FixedControlGrid->addWidget(Labels[0],0,0);
+ FixedControlGrid->addWidget(DestTextbox,0,1);
+ FixedControlGrid->addWidget(Labels[1],1,0);
+ FixedControlGrid->addWidget(IndexTextbox,1,1);
+ FixedControlGrid->addWidget(Labels[2],2,0);
+ FixedControlGrid->addWidget(CountTextbox,2,1);
+ if (!forPwl){
+ FixedControlGrid->addWidget(AsStringCheckbox, 3, 0, 1, 0,
+ Qt::AlignTop);
}
-
- g_signal_connect (G_OBJECT(DestTextbox), "insert-text",
- G_CALLBACK(LutDialogMyNameProc), NULL);
- g_signal_connect (G_OBJECT(IndexTextbox), "insert-text",
- G_CALLBACK(LutDialogMyNameProc), NULL);
- g_signal_connect (G_OBJECT(CountTextbox), "insert-text",
- G_CALLBACK(LutDialogMyDigitsProc), NULL);
+ LutGrid->addLayout(FixedControlGrid, 0, 0,
+ Qt::AlignLeft | Qt::AlignTop);
+ ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel, Qt::Vertical,
+ LutDialog);
+ LutGrid->addWidget(ButtonBox,0,1);
+ QObject::connect(ButtonBox, SIGNAL(accepted()), LutDialog, SLOT(accept()));
+ QObject::connect(ButtonBox, SIGNAL(rejected()), LutDialog, SLOT(reject()));
+ QObject::connect(AsStringCheckbox, &QCheckBox::stateChanged,CheckBoxFunction);
+ QObject::connect(CountTextbox, &QLineEdit::textChanged,CountFunction);
}
//-----------------------------------------------------------------------------
@@ -175,77 +161,47 @@ static void DestroyLutControls(BOOL destroyFlag = TRUE)
// Nothing to do; we constantly update the cache from the user-
// specified string, because we might as well do that when we
// calculate the length.
+ delete StringTextbox;
}
else {
int i;
for(i = 0; i < WasCount; i++) {
- char buf[20];
- char *tmpB = (char*)gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i]));
- strcpy (buf, tmpB);
+ const char* buf;
+ buf = ValuesTextbox[i]->text().toStdString().c_str();
ValuesCache[i] = atoi(buf);
+ delete ValuesTextbox[i];
+ delete ValuesLabel[i];
}
+ delete LutControlGrid;
}
-
- if (destroyFlag){
- for(int i = 0; i < temp.tmpcount; i++)
- {
- if (GTK_IS_ENTRY(ValuesTextbox[i]))
- {
- DestroyWindow(ValuesTextbox[i]);
- DestroyWindow(ValuesLabel[i]);
- }
- }
- ProgramChanged();
- }
-}
-static void DestroyLutControlsPiecewise(BOOL destroyFlag = TRUE)
-{
- if(WasAsString) {
- // Nothing to do; we constantly update the cache from the user-
- // specified string, because we might as well do that when we
- // calculate the length.
- }
- else {
- int i;
- for(i = 0; i < WasCount; i++) {
- char buf[20];
- char *tmpB = (char*)gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i]));
- strcpy (buf, tmpB);
- ValuesCache[i] = atoi(buf);
- }
- }
-
- if (destroyFlag)
- {
- int i;
- for(i = 0; i < WasCount; i++) {
- DestroyWindow(ValuesTextbox[i]);
- DestroyWindow(ValuesLabel[i]);
- }
- ProgramChanged();
- }
+ // int i;
+ /*for(i = 0; i < MAX_LOOK_UP_TABLE_LEN; i++) {
+ delete ValuesTextbox[i];
+ delete ValuesLabel[i];
+ }*/
}
+
//-----------------------------------------------------------------------------
// Make the controls that hold the LUT. The exact configuration of the dialog
// will depend on (a) whether the user chose table-type or string-type entry,
// and for table-type entry, on (b) the number of entries, and on (c)
// whether we are editing a PWL table (list of points) or a straight LUT.
//-----------------------------------------------------------------------------
-static void MakeLutControls(BOOL asString, int count, BOOL forPwl)
+static void MakeLutControls(BOOL asString, int counts, BOOL forPwl)
{
// Remember these, so that we know from where to cache stuff if we have
// to destroy these textboxes and make something new later.
WasAsString = asString;
- WasCount = count;
+ WasCount = counts;
if(forPwl && asString) oops();
if(asString) {
char str[3*MAX_LOOK_UP_TABLE_LEN+1];
int i, j;
j = 0;
- for(i = 0; i < count; i++) {
+ for(i = 0; i < counts; i++) {
int c = ValuesCache[i];
if(c >= 32 && c <= 127 && c != '\\') {
str[j++] = c;
@@ -269,13 +225,17 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl)
}
}
str[j++] = '\0';
- StringTextbox = gtk_entry_new ();
- gtk_grid_attach (GTK_GRID (LutGrid), StringTextbox, 0, 9, 1, 1);
- checkString = TRUE;
- gtk_widget_show_all (LutGrid);
- gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), FALSE);
+ StringTextbox = new QLineEdit();
+ FixedFont(StringTextbox);
+ FixedControlGrid->addWidget(StringTextbox, 4, 0, 1, 0,
+ Qt::AlignTop);
+ StringTextbox->setText(str);
+ QObject::connect(StringTextbox, &QLineEdit::textChanged,StringFunction);
+ /*checkString = TRUE;*/
+ CountTextbox->setReadOnly(TRUE);
}
else {
+ LutControlGrid = new QGridLayout();
int i;
int base;
if(forPwl) {
@@ -284,23 +244,28 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl)
else {
base = 140;
}
- for(i = 0; i < count; i++) {
+ for(i = 0; i < counts; i++) {
int x, y;
if(i < 16) {
- x = 10;
- y = base+30*i;
+ x = i;
+ y = 0;
}
else {
- x = 160;
- y = base+30*(i-16);
+ x = i % 16;
+ y = 2;
}
char buf[20];
sprintf(buf, "%d", ValuesCache[i]);
- ValuesTextbox[i] = gtk_entry_new ();
- gtk_entry_set_max_length (GTK_ENTRY (ValuesTextbox[i]), 0);
- gtk_entry_set_text (GTK_ENTRY (ValuesTextbox[i]), buf);
+ ValuesTextbox[i] = new QLineEdit();
+ ValuesTextbox[i]->setMaximumWidth(80);
+ ValuesTextbox[i]->setValidator(
+ new QRegExpValidator(
+ QRegExp("-?[0-9]+")));
+ NiceFont(ValuesTextbox[i]);
+ ValuesTextbox[i]->setText(buf);
+ LutControlGrid->addWidget(ValuesTextbox[i], x, y + 1);
if(forPwl) {
sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2);
@@ -309,28 +274,21 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl)
sprintf(buf, "%2d:", i);
}
- ValuesLabel[i] = gtk_label_new (buf);
- if (i<10){
- gtk_grid_attach (GTK_GRID (LutGrid), ValuesLabel[i], 0, i+12, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), ValuesTextbox[i], 1, i+12, 1, 1);
- }
- else if ((i>=10) && (i<20)){
- gtk_grid_attach (GTK_GRID (LutGrid), ValuesLabel[i], 2, i+2, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), ValuesTextbox[i], 3, i+2, 1, 1);
- }
- else if ((i>=20) && (i<30)){
- gtk_grid_attach (GTK_GRID (LutGrid), ValuesLabel[i], 4, i-8, 1, 1);
- gtk_grid_attach (GTK_GRID (LutGrid), ValuesTextbox[i], 5, i-8, 1, 1);
- }
- gtk_widget_show_all (LutDialog);
- g_signal_connect (G_OBJECT(ValuesTextbox[i]), "insert-text",
- G_CALLBACK(LutDialogMyNumberProc), NULL);
+ ValuesLabel[i] = new QLabel(buf);
+ FixedFont(ValuesLabel[i]);
+ LutControlGrid->addWidget(ValuesLabel[i], x , y);
}
- if(count > 16) count = 16;
- gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE);
+ // if(counts > 16)
+ FixedControlGrid->addLayout(LutControlGrid, 4, 0, 1, 0,
+ Qt::AlignTop);
+ // else
+ // FixedControlGrid->addLayout(LutControlGrid, 4, 0, 1, 0,
+ // Qt::AlignTop);
+ CountTextbox->setReadOnly(FALSE);
}
}
+
//-----------------------------------------------------------------------------
// Decode a string into a look-up table; store the values in ValuesCache[],
// and update the count checkbox (which in string mode is read-only) to
@@ -363,148 +321,11 @@ BOOL StringToValuesCache(char *str, int *c)
char buf[10];
sprintf(buf, "%d", count);
- gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf);
+ CountTextbox->setText(buf);
*c = count;
return TRUE;
}
-void LookUpTableGetData (gpointer data){
- ElemLeaf *l = (ElemLeaf *) data;
- ElemLookUpTable *t = &(l->d.lookUpTable);
- strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox)));
- strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox)));
- DestroyLutControls(FALSE);
-
- // The call to DestroyLutControls updated ValuesCache, so just read
- // them out of there (whichever mode we were in before).
- int i;
- for(i = 0; i < temp.tmpcount; i++) {
- t->vals[i] = ValuesCache[i];
- }
- t->count = temp.tmpcount;
- t->editAsString = temp.tmpasString;
- gtk_widget_set_sensitive (MainWindow, TRUE);
-}
-
-void LookUpTableCheckMode (void){
- int count = temp.tmpcount;
- bool asString = temp.tmpasString;
-
- // Are we in table mode? In that case watch the (user-editable) count
- // field, and use that to determine how many textboxes to show.
- char buf[20];
- // buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY (CountTextbox)));
- strcpy (buf, gtk_entry_get_text (GTK_ENTRY (CountTextbox)));
- if(atoi(buf) != count && !asString) {
- count = atoi(buf);
- if(count < 0 || count > 32) {
- count = 0;
- gtk_entry_set_text (GTK_ENTRY (CountTextbox), "");
- }
- DestroyLutControls();
- MakeLutControls(asString, count, FALSE);
- }
-
- // Are we in string mode? In that case watch the string textbox,
- // and use that to update the (read-only) count field.
- if(asString) {
- char scratch[1024];
- strcpy (scratch, gtk_entry_get_text (GTK_ENTRY (StringTextbox)));
- if(strcmp(scratch, temp.PrevTableAsString)!=0) {
- if(StringToValuesCache(scratch, &count)) {
- strcpy(temp.PrevTableAsString, scratch);
- }
- else {
- // Too long; put back the old one
- gtk_entry_set_text (GTK_ENTRY (StringTextbox),
- temp.PrevTableAsString);
- }
- }
- }
- // Did we just change modes?
- BOOL x = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (AsStringCheckbox));
- checkString = x;
- if((x && !asString) || (!x && asString)) {
- asString = x;
- if (x == 1){
- MakeLutControls(asString, count, FALSE);
-
- for(int i = 0; i < temp.tmpcount; i++) {
- if (GTK_IS_ENTRY(ValuesTextbox[i]))
- {
- DestroyWindow(ValuesTextbox[i]);
- DestroyWindow(ValuesLabel[i]);
- }
- }
- ProgramChanged();
- }
- else {
- DestroyLutControls();
- if (!x && GTK_IS_ENTRY(StringTextbox))
- {
- DestroyWindow(StringTextbox);
- ProgramChanged();
- gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE);
- }
- }
- }
-
- temp.tmpcount = count;
- temp.tmpasString = asString;
-}
-
-// Checks for the required key press
-gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){
-
- if (event -> keyval == GDK_KEY_Return){
- LookUpTableCheckMode ();
- LookUpTableGetData((gpointer) data);
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1);
- LUT_DIALOG_REFRESH_TIMER_ID_1 = 0;
- }
- else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1);
- LUT_DIALOG_REFRESH_TIMER_ID_1 = 0;
- }
- return FALSE;
-}
-
-/// Dialog refresh function
-BOOL LutDialogRefresh(gpointer data)
-{
- LookUpTableCheckMode ();
- LookUpTableGetData((gpointer) data);
- return TRUE;
-}
-// Ok button call
-void LutDialogOk (HWID widget, gpointer data)
-{
- LookUpTableCheckMode ();
- LookUpTableGetData((gpointer) data);
-
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1);
- LUT_DIALOG_REFRESH_TIMER_ID_1 = 0;
-}
-
-// Cancel button call
-void LutCallCancel (HWID widget, gpointer data)
-{
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1);
- LUT_DIALOG_REFRESH_TIMER_ID_1 = 0;
-}
-
//-----------------------------------------------------------------------------
// Show the look-up table dialog. This one is nasty, mostly because there are
// two ways to enter a look-up table: as a table, or as a string. Presumably
@@ -520,151 +341,109 @@ void ShowLookUpTableDialog(ElemLeaf *l)
// bad to update those in the leaf before the user clicks okay (as he
// might cancel).
- int count = t->count;
- BOOL asString = t->editAsString;
+ ControlCount = t->count;
+ asString = t->editAsString;
memset(ValuesCache, 0, sizeof(ValuesCache));
int i;
- for(i = 0; i < count; i++) {
+ for(i = 0; i < ControlCount; i++) {
ValuesCache[i] = t->vals[i];
}
// Now create the dialog's fixed controls, plus the changing (depending
// on show style/entry count) controls for the initial configuration.
- LutGrid = gtk_grid_new();
- LutPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
-
- LutDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(LutDialog), "Look-Up Table");
- gtk_window_set_default_size(GTK_WINDOW(LutDialog), 100, 200);
- gtk_window_set_resizable (GTK_WINDOW (LutDialog), FALSE);
- gtk_box_pack_start(GTK_BOX(LutPackingBox), LutGrid, TRUE, TRUE, 0);
- gtk_container_add(GTK_CONTAINER(LutDialog), LutPackingBox);
- gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK);
- gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK);
+ LutDialog = CreateWindowClient(_("Look-Up Table"),
+ 100, 100, 320, 375, MainWindow);
+ LutPackingBox = new QGridLayout();
+ LutGrid = new QGridLayout(LutDialog);
+ LutDialog->setWindowTitle(_("Look-Up Table"));
MakeFixedControls(FALSE);
- MakeLutControls(asString, count, FALSE);
-
- // Set up the controls to reflect the initial configuration.
- gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest);
- gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index);
-
+ MakeLutControls(asString, ControlCount, FALSE);
+ DestTextbox->setText(t->dest);
+ IndexTextbox->setText(t->index);
char buf[30];
sprintf(buf, "%d", t->count);
- gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf);
- if(asString) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (AsStringCheckbox), TRUE);
- }
-
- // And show the window
- gtk_widget_set_sensitive (MainWindow, FALSE);
- gtk_widget_show_all (LutDialog);
- gtk_widget_grab_focus(DestTextbox);
- gtk_widget_grab_focus(OkButton);
-
- temp.tmpcount = count;
- temp.tmpasString = asString;
-
- g_signal_connect (G_OBJECT (LutDialog), "key-press-event",
- G_CALLBACK(LookUpTableKeyPress), (gpointer)l);
- g_signal_connect (G_OBJECT (OkButton), "clicked",
- G_CALLBACK(LutDialogOk), (gpointer)l);
- g_signal_connect (G_OBJECT (CancelButton), "clicked",
- G_CALLBACK(LutCallCancel), NULL);
-
- if (LUT_DIALOG_REFRESH_TIMER_ID_1 == 0)
- LUT_DIALOG_REFRESH_TIMER_ID_1 = g_timeout_add(100, (GSourceFunc)LutDialogRefresh, (gpointer)l);
-}
-
-// Piecewise Dialog
-
-void PiecewiseDialogGetData(gpointer data){
-
- ElemLeaf *l = (ElemLeaf *) data;
- ElemPiecewiseLinear *t = &(l->d.piecewiseLinear);
- int count = piecewiseTmpCount;
- strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox)));
- strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox)));
- DestroyLutControlsPiecewise(FALSE);
- // MakeLutControls(FALSE, count*2, TRUE);
-
- // The call to DestroyLutControlsPiecewise updated ValuesCache, so just read
- // them out of there.
- int i;
- for(i = 0; i < count*2; i++) {
- t->vals[i] = ValuesCache[i];
- }
- t->count = count;
-}
-
-void PiecewiseDialogPointTextbox (int count){
- char* buf;
- char *tmpBuf = (char*)gtk_entry_get_text (GTK_ENTRY (CountTextbox));
- buf = (char*)malloc(strlen(tmpBuf));
- strcpy (buf, tmpBuf);
- if(atoi(buf) != count) {
- count = atoi(buf);
- if(count < 0 || count > 10) {
- count = 0;
- gtk_entry_set_text (GTK_ENTRY (CountTextbox), "");
+ CountTextbox->setText(buf);
+ AsStringCheckbox->setChecked(asString);
+ PrevTableAsString[0] = NULL;
+ int ret = LutDialog->exec();
+ switch(ret)
+ {
+ case QDialog::Accepted:
+ {
+ strncpy(t->dest,
+ DestTextbox->text().toStdString().c_str(),16);
+ strncpy(t->index,
+ IndexTextbox->text().toStdString().c_str(),16);
+ int count = ControlCount;
+ DestroyLutControls();
+ // The call to DestroyLutControls updated ValuesCache, so just read
+ // them out of there (whichever mode we were in before).
+ int i;
+ for(i = 0; i < count; i++) {
+ t->vals[i] = ValuesCache[i];
+ printf("Value:%d\n", ValuesCache[i]);
}
- DestroyLutControlsPiecewise();
- MakeLutControls(FALSE, count*2, TRUE);
+ t->count = count;
+ t->editAsString = asString;
+ printf("Count:%d\n", count);
}
- piecewiseTmpCount = count;
+ break;
+ case QDialog::Rejected:
+ break;
+ }
+ DestroyWindow();
}
-/// Dialog refresh function
-BOOL PiecewiseDialogRefresh(gpointer data)
-{
- PiecewiseDialogPointTextbox (piecewiseTmpCount);
- PiecewiseDialogGetData((gpointer) data);
- return TRUE;
-}
+// The function to handle checkbox event separated from
+// ShowLookUpTableDialog function to improve performance in Qt
-// Ok button call
-void PiecewiseDialogOk (HWID widget, gpointer data)
+void CheckBoxFunction(int state)
{
- PiecewiseDialogPointTextbox (piecewiseTmpCount);
- PiecewiseDialogGetData((gpointer) data);
-
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2);
- LUT_DIALOG_REFRESH_TIMER_ID_2 = 0;
+ printf("CheckBoxFunctionCalled\n");
+ asString = state;
+ DestroyLutControls();
+ const char* buf;
+ buf = CountTextbox->text().toStdString().c_str();
+ MakeLutControls(asString, atoi(buf), FALSE);
}
-// Checks for the required key press
-gboolean PiecewiseDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){
-
- if (event -> keyval == GDK_KEY_Return){
- PiecewiseDialogPointTextbox (piecewiseTmpCount);
- PiecewiseDialogGetData((gpointer) data);
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2);
- LUT_DIALOG_REFRESH_TIMER_ID_2 = 0;
- }
- else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2);
- LUT_DIALOG_REFRESH_TIMER_ID_2 = 0;
- }
- return FALSE;
+// The function to handle change in CountTextbox separated from
+// ShowLookUpTableDialog function to improve performance in Qt
+void CountFunction(QString text)
+{
+ printf("TextFunction called:%s\n",text.toStdString().c_str());
+ const char* buf;
+ buf = text.toStdString().c_str();
+ if(atoi(buf) != ControlCount && !asString) {
+ ControlCount = atoi(buf);
+ if(ControlCount < 0 || ControlCount > 32) {
+ ControlCount = 0;
+ CountTextbox->setText("");
+ }
+ DestroyLutControls();
+ MakeLutControls(asString, ControlCount, FALSE);
+ }
}
-// Cancel button call
-void PiecewiseCallCancel (HWID widget, gpointer data)
+// The function to handle change in StringTextbox separated from
+// ShowLookUpTableDialog function to improve performance in Qt
+void StringFunction(QString text)
{
- DestroyWindow (LutDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2);
- LUT_DIALOG_REFRESH_TIMER_ID_2 = 0;
+ printf("StringFunction called \n");
+ char* scratch = (char*)text.toStdString().c_str();
+ // SendMessage(StringTextbox, WM_GETTEXT, (WPARAM)sizeof(scratch),
+ // (LPARAM)scratch);
+ if(strcmp(scratch, PrevTableAsString)!=0) {
+ if(StringToValuesCache(scratch, &ControlCount)) {
+ strcpy(PrevTableAsString, scratch);
+ } else {
+ // Too long; put back the old one
+ // SendMessage(StringTextbox, WM_SETTEXT, 0,
+ // (LPARAM)PrevTableAsString);
+ StringTextbox->setText(PrevTableAsString);
+ }
+ }
}
//-----------------------------------------------------------------------------
@@ -688,43 +467,40 @@ void ShowPiecewiseLinearDialog(ElemLeaf *l)
// Now create the dialog's fixed controls, plus the changing (depending
// on show style/entry count) controls for the initial configuration.
-
- LutGrid = gtk_grid_new();
- LutPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
-
- LutDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(LutDialog), "Piecewise Linear Table");
- gtk_window_set_default_size(GTK_WINDOW(LutDialog), 100, 200);
- gtk_window_set_resizable (GTK_WINDOW (LutDialog), FALSE);
- gtk_box_pack_start(GTK_BOX(LutPackingBox), LutGrid, TRUE, TRUE, 0);
- gtk_container_add(GTK_CONTAINER(LutDialog), LutPackingBox);
- gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK);
- gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK);
-
+ LutDialog = CreateWindowClient(_("Piecewise Linear Table"),
+ 100, 100, 320, 375, MainWindow);
+ LutPackingBox = new QGridLayout();
+ LutGrid = new QGridLayout(LutDialog);
+ LutDialog->setWindowTitle(_("Piecewise Linear Table"));
MakeFixedControls(TRUE);
- MakeLutControls(FALSE, count*2, TRUE);
-
- // Set up the controls to reflect the initial configuration.
- gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest);
- gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index);
+ MakeLutControls(FALSE, ControlCount, TRUE);
+ DestTextbox->setText(t->dest);
+ IndexTextbox->setText(t->index);
char buf[30];
sprintf(buf, "%d", t->count);
- gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf);
-
- // And show the window
- gtk_widget_set_sensitive (MainWindow, FALSE);
- gtk_widget_show_all (LutDialog);
- // gtk_widget_grab_focus (DestTextbox);
-
- piecewiseTmpCount = count;
-
- g_signal_connect (G_OBJECT (LutDialog), "key-press-event",
- G_CALLBACK(PiecewiseDialogKeyPress), (gpointer)l);
- g_signal_connect (G_OBJECT (OkButton), "clicked",
- G_CALLBACK(PiecewiseDialogOk), (gpointer)l);
- g_signal_connect (G_OBJECT (CancelButton), "clicked",
- G_CALLBACK(PiecewiseCallCancel), NULL);
-
- if (LUT_DIALOG_REFRESH_TIMER_ID_2 == 0)
- LUT_DIALOG_REFRESH_TIMER_ID_2 = g_timeout_add(100, (GSourceFunc)PiecewiseDialogRefresh, (gpointer)l);
-}
+ CountTextbox->setText(buf);
+ int ret = LutDialog->exec();
+ switch(ret)
+ {
+ case QDialog::Accepted:
+ {
+ strncpy(t->dest,
+ DestTextbox->text().toStdString().c_str(),16);
+ strncpy(t->index,
+ IndexTextbox->text().toStdString().c_str(),16);
+ int count = ControlCount;
+ DestroyLutControls();
+ // The call to DestroyLutControls updated ValuesCache, so just read
+ // them out of there (whichever mode we were in before).
+ int i;
+ for(i = 0; i < count; i++) {
+ t->vals[i] = ValuesCache[i];
+ }
+ t->count = count;
+ }
+ break;
+ case QDialog::Rejected:
+ break;
+ }
+ DestroyWindow();
+} \ No newline at end of file