summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/coildialog.cpp244
-rw-r--r--ldmicro/includes/ldmicro.h2
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h3
-rw-r--r--ldmicro/miscutil.cpp47
4 files changed, 103 insertions, 193 deletions
diff --git a/ldmicro/coildialog.cpp b/ldmicro/coildialog.cpp
index f4888b9..e917bb4 100644
--- a/ldmicro/coildialog.cpp
+++ b/ldmicro/coildialog.cpp
@@ -27,7 +27,7 @@
#include "ldmicro.h"
-static HWID CoilDialog;
+static QDialog* CoilDialog;
static QRadioButton* SourceInternalRelayRadio;
static QRadioButton* SourceMcuPinRadio;
@@ -36,32 +36,13 @@ static QRadioButton* NormalRadio;
static QRadioButton* SetOnlyRadio;
static QRadioButton* ResetOnlyRadio;
static QLineEdit* NameTextbox;
-static HWID OkButton;
-static HWID CancelButton;
+static QPushButton* OkButton;
+static QPushButton* CancelButton;
static LONG_PTR PrevNameProc;
static QGridLayout* CoilGrid;
-static HWID CoilPackingBox;
-static bool* tmpnegated;
-static bool* tmpsetOnly ;
-static bool* tmpresetOnly;
-//-----------------------------------------------------------------------------
-// Don't allow any characters other than A-Za-z0-9_ in the name.
-//-----------------------------------------------------------------------------
-
-/*void CoilDialogMyNameProc (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;
- }
- }
-}
-*/
static void MakeControls(void)
{
QGroupBox* grouper = new QGroupBox(_("Type"));
@@ -69,185 +50,122 @@ static void MakeControls(void)
QGridLayout *TypeGrid = new QGridLayout();
QGridLayout *SourceGrid = new QGridLayout();
QGridLayout *NameGrid = new QGridLayout();
+ QDialogButtonBox *ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel, Qt::Vertical,
+ CoilDialog);
NormalRadio = new QRadioButton(_("( ) Normal"), CoilDialog);
NegatedRadio = new QRadioButton(_("(/) Negated"), CoilDialog);
SetOnlyRadio = new QRadioButton(_("(S) Set-Only"), CoilDialog);
ResetOnlyRadio = new QRadioButton(_("(R) Reset-Only"), CoilDialog);
- /*NormalRadio->setAutoExclusive(FALSE);
- NegatedRadio->setAutoExclusive(FALSE);*/
+ NiceFont(CoilDialog);
TypeGrid->addWidget(NormalRadio,0,0);
TypeGrid->addWidget(NegatedRadio,1,0);
TypeGrid->addWidget(SetOnlyRadio,2,0);
TypeGrid->addWidget(ResetOnlyRadio,3,0);
+
+ CoilGrid->setSpacing(3);
+ TypeGrid->setSpacing(3);
+ SourceGrid->setSpacing(3);
+
SourceInternalRelayRadio = new QRadioButton(_("Internal Relay"), CoilDialog);
SourceMcuPinRadio = new QRadioButton(_("Pin on MCU"), CoilDialog);
SourceGrid->addWidget(SourceInternalRelayRadio,0,0);
SourceGrid->addWidget(SourceMcuPinRadio,1,0);
+ SourceGrid->addItem(
+ new QSpacerItem(SetOnlyRadio->width(),
+ SetOnlyRadio->height()), 2, 0);
QLabel* textLabel = new QLabel(_("Name:"));
NameTextbox = new QLineEdit();
+ FixedFont(NameTextbox);
NameTextbox->setFixedWidth(155);
NameGrid->addWidget(textLabel,0,0);
NameGrid->addWidget(NameTextbox,0,1);
- SourceGrid->addLayout(NameGrid,2,0);
+ SourceGrid->addLayout(NameGrid,3,0);
+
grouper->setLayout(TypeGrid);
grouper2->setLayout(SourceGrid);
CoilGrid->addWidget(grouper,0,0);
CoilGrid->addWidget(grouper2,0,1);
- // CoilGrid->addWidget(NormalRadio,0,0);
- // CoilGrid->addWidget(NegatedRadio,1,0);
- // CoilGrid->addWidget(SetOnlyRadio,2,0);
- // CoilGrid->addWidget(ResetOnlyRadio,3,0);
- /*
-
- SourceInternalRelayRadio = gtk_radio_button_new_with_label (NULL, "Internal Relay");
- SourceMcuPinRadio = gtk_radio_button_new_with_label_from_widget
- (GTK_RADIO_BUTTON (SourceInternalRelayRadio), "Pin on MCU");
- HWID textLabel = gtk_label_new ("Name:");
-
- NameTextbox = gtk_entry_new();
- gtk_entry_set_max_length (GTK_ENTRY (NameTextbox), 0);
-
- OkButton = gtk_button_new_with_label ("OK");
- CancelButton = gtk_button_new_with_label ("Cancel");
-
- gtk_grid_attach (GTK_GRID (CoilGrid), NormalRadio, 0, 1, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), NegatedRadio, 0, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), SetOnlyRadio, 0, 3, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), ResetOnlyRadio, 0, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), SourceInternalRelayRadio, 1, 1, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), SourceMcuPinRadio, 1, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), textLabel, 1, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), NameTextbox, 2, 4, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), OkButton, 4, 2, 1, 1);
- gtk_grid_attach (GTK_GRID (CoilGrid), CancelButton, 4, 3, 1, 1);
-
- gtk_grid_set_column_spacing (GTK_GRID (CoilGrid), 1);
- gtk_box_pack_start(GTK_BOX(CoilPackingBox), CoilGrid, TRUE, TRUE, 0);
-
- g_signal_connect (G_OBJECT (NameTextbox), "insert-text",
- G_CALLBACK (CoilDialogMyNameProc), NULL);*/
+ CoilGrid->addWidget(ButtonBox,0,2);
+ QObject::connect(ButtonBox, SIGNAL(accepted()), CoilDialog, SLOT(accept()));
+ QObject::connect(ButtonBox, SIGNAL(rejected()), CoilDialog, SLOT(reject()));
}
-/*
-void CoilDialogGetData (char* name){
- bool* negated = tmpnegated;
- bool* resetOnly = tmpresetOnly;
- bool* setOnly = tmpsetOnly;
+inline void DestroyWindow()
+{
+ delete SourceInternalRelayRadio;
+ delete SourceMcuPinRadio;
+ delete NormalRadio;
+ delete NegatedRadio;
+ delete SetOnlyRadio;
+ delete ResetOnlyRadio;
+ delete NameTextbox;
+ delete OkButton;
+ delete CancelButton;
+ delete CoilGrid;
+}
- if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
- (SourceInternalRelayRadio))) {
- name[0] = 'R';
- }
- else {
- name[0] = 'Y';
- }
- strcpy (name+1, gtk_entry_get_text (GTK_ENTRY (NameTextbox)));
+void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name)
+{
+ CoilDialog = CreateWindowClient(_("Coil"),
+ 100, 100, 359, 115, MainWindow);
+ CoilGrid = new QGridLayout(CoilDialog);
+ CoilDialog->setWindowTitle("Coil");
+ // CoilDialog->setFixedSize(359,115);
+ MakeControls();
+ NameTextbox->setValidator(
+ new QRegExpValidator(QRegExp("[a-zA-Z0-9_]+")));
- if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
- (NormalRadio))) {
+ if(name[0] == 'R') {
+ SourceInternalRelayRadio->setChecked(TRUE);
+ } else {
+ SourceMcuPinRadio->setChecked(TRUE);
+ }
+ NameTextbox->setText(name + 1);
+ if(*negated) {
+ NegatedRadio->setChecked(TRUE);
+ } else if(*setOnly) {
+ SetOnlyRadio->setChecked(TRUE);
+ } else if(*resetOnly) {
+ ResetOnlyRadio->setChecked(TRUE);
+ } else {
+ NormalRadio->setChecked(TRUE);
+ }
+ int ret = CoilDialog->exec();
+ switch(ret)
+ {
+ case QDialog::Accepted:
+ {
+ if(SourceInternalRelayRadio->isChecked())
+ {
+ name[0] = 'R';
+ } else {
+ name[0] = 'Y';
+ }
+ strncpy(name +1, NameTextbox->text().toStdString().c_str(),16);
+ if(NormalRadio->isChecked()) {
*negated = FALSE;
*setOnly = FALSE;
*resetOnly = FALSE;
- }
- else if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
- (NegatedRadio))) {
+ } else if(NegatedRadio->isChecked()) {
*negated = TRUE;
*setOnly = FALSE;
*resetOnly = FALSE;
- }
- else if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
- (SetOnlyRadio))) {
+ } else if(SetOnlyRadio->isChecked()) {
*negated = FALSE;
*setOnly = TRUE;
*resetOnly = FALSE;
- }
- else if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
- (ResetOnlyRadio))){
+ } else if(ResetOnlyRadio->isChecked())
+ {
*negated = FALSE;
*setOnly = FALSE;
*resetOnly = TRUE;
}
-
- gtk_widget_set_sensitive (MainWindow, TRUE);
- DestroyWindow (CoilDialog);
- ProgramChanged();
-}
-
-// Mouse click callback
-void CoilDialogMouseClick (HWID widget, gpointer data){
- CoilDialogGetData((char*)data);
-}
-
-// Checks for the required key press
-gboolean CoilDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){
- if (event -> keyval == GDK_KEY_Return){
- CoilDialogGetData((char*)data);
- }
- else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (CoilDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
- }
- return FALSE;
-}
-
-// Calls DestroyWindow
-void CoilCallDestroyWindow (HWID widget, gpointer data){
- DestroyWindow (CoilDialog);
- ProgramChanged();
- gtk_widget_set_sensitive (MainWindow, TRUE);
-}*/
-
-void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name)
-{
- // CoilPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- CoilDialog = CreateWindowClient(_("Coil"),
- 100, 100, 359, 115, MainWindow);
- CoilGrid = new QGridLayout(CoilDialog);
- CoilDialog->setWindowTitle("Coil");
- // CoilDialog->resize(100, 50);
- // CoilDialog->setFixedSize(359,115);
- CoilDialog->show();
- // gtk_container_add(GTK_CONTAINER(CoilDialog), CoilPackingBox);
- // gtk_widget_add_events (CoilDialog, GDK_KEY_PRESS_MASK);
- // gtk_widget_add_events (CoilDialog, GDK_BUTTON_PRESS_MASK);
-
- MakeControls();
-
- /*if(name[0] == 'R') {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (SourceInternalRelayRadio), TRUE);
- }
- else {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (SourceMcuPinRadio), TRUE);
- }
- gtk_entry_set_text (GTK_ENTRY (NameTextbox), name+1);
- if(*negated) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (NegatedRadio), TRUE);
- }
- else if(*setOnly) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (SetOnlyRadio), TRUE);
- }
- else if(*resetOnly) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ResetOnlyRadio), TRUE);
- }
- else {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (NormalRadio), TRUE);
+ }
+ break;
+ case QDialog::Rejected:
+ break;
}
-
- gtk_widget_set_sensitive (MainWindow, FALSE);
- gtk_widget_show_all (CoilDialog);
- gtk_widget_grab_focus (NameTextbox);
-
- tmpnegated = negated;
- tmpresetOnly = resetOnly;
- tmpsetOnly = setOnly;
-
- g_signal_connect (G_OBJECT (CoilDialog), "key-press-event",
- G_CALLBACK(CoilDialogKeyPress), (gpointer)name);
- g_signal_connect (G_OBJECT (OkButton), "clicked",
- G_CALLBACK(CoilDialogMouseClick), (gpointer)name);
- g_signal_connect (G_OBJECT (CancelButton), "clicked",
- G_CALLBACK(CoilCallDestroyWindow), NULL);
-*/
+ DestroyWindow();
return;
}
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index 5f56788..38dd3d5 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -794,7 +794,7 @@ void WriteIhex(FILE *f, BYTE b);
void FinishIhex(FILE *f);
char *IoTypeToString(int ioType);
void PinNumberForIo(char *dest, PlcProgramSingleIo *io);
-HWID CreateWindowClient(char *windowName,
+QDialog* CreateWindowClient(char *windowName,
int x, int y, int width, int height, HWND parent);
void MakeComponentListClass(void);
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 0ba229b..507bd57 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -22,6 +22,9 @@
#include <QRadioButton>
#include <QButtonGroup>
#include <QLineEdit>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QRegExpValidator>
// #include <QtGui>
// #include <QSize>
// #include "freezeLD.h"
diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp
index 18e7f82..0a9379f 100644
--- a/ldmicro/miscutil.cpp
+++ b/ldmicro/miscutil.cpp
@@ -204,10 +204,10 @@ void FinishIhex(FILE *f)
//-----------------------------------------------------------------------------
// Create a window with a given client area.
//-----------------------------------------------------------------------------
-HWID CreateWindowClient(char *windowName,
+QDialog* CreateWindowClient(char *windowName,
int x, int y, int width, int height, HWND parent)
{
- HWID h = new QDialog(parent);
+ QDialog* h = new QDialog(parent);
h->resize(width,height);
h->setWindowTitle(windowName);
// HWND h = CreateWindowEx(exStyle, className, windowName, style, x, y,
@@ -263,20 +263,15 @@ HWID CreateWindowClient(char *windowName,
//-----------------------------------------------------------------------------
// Set the font of a control to a pretty proportional font (typ. Tahoma).
//-----------------------------------------------------------------------------
-/*void NiceFont(HWID h)
+void NiceFont(HWID h)
{
- GtkCssProvider *provider = gtk_css_provider_new ();
-
- char *cssdata = new char[strlen(MyNiceFont->lpszFace) + 26];
- int fontSize = 10;
- sprintf(cssdata, "textview { font: %ipx %s; }", fontSize, MyNiceFont->lpszFace);
-
- gtk_css_provider_load_from_data (provider, cssdata, -1, NULL);
-
- delete cssdata;
-
- gtk_style_context_add_provider (gtk_widget_get_style_context(h),
- GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
+ QFont qtfont = h->font();
+ qtfont.setFamily(MyNiceFont->lpszFace);
+ qtfont.setPixelSize(MyNiceFont->nHeight - 3);
+ qtfont.setFixedPitch(TRUE);
+ qtfont.setStyle(MyNiceFont->fdwItalic ? QFont::StyleItalic : QFont::StyleNormal);
+ qtfont.setWeight(MyNiceFont->fnWeight == FW_BOLD ? QFont::Bold : QFont::Normal);
+ h->setFont(qtfont);
// SendMessage(h, WM_SETFONT, (WPARAM)MyNiceFont, TRUE);
}
@@ -287,22 +282,16 @@ HWID CreateWindowClient(char *windowName,
//-----------------------------------------------------------------------------
void FixedFont(HWID h)
{
- GtkCssProvider *provider = gtk_css_provider_new ();
-
- char *cssdata = new char[strlen(MyFixedFont->lpszFace) + 26];
- int fontSize = 10;
- sprintf(cssdata, "textview { font: %ipx %s; }", fontSize, MyFixedFont->lpszFace);
-
- gtk_css_provider_load_from_data (provider, cssdata, -1, NULL);
-
- delete cssdata;
-
- gtk_style_context_add_provider (gtk_widget_get_style_context(h),
- GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
-
+ QFont qtfont = h->font();
+ qtfont.setFamily(MyFixedFont->lpszFace);
+ qtfont.setPixelSize(MyFixedFont->nHeight - 3);
+ qtfont.setFixedPitch(TRUE);
+ qtfont.setStyle(MyFixedFont->fdwItalic ? QFont::StyleItalic : QFont::StyleNormal);
+ qtfont.setWeight(MyFixedFont->fnWeight == FW_BOLD ? QFont::Bold : QFont::Normal);
+ h->setFont(qtfont);
// SendMessage(h, WM_SETFONT, (WPARAM)MyFixedFont, TRUE);
}
-*/
+
//-----------------------------------------------------------------------------
// Create our dialog box class, used for most of the popup dialogs.
//-----------------------------------------------------------------------------