summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
authorakshay-c2019-04-11 16:57:56 +0530
committerakshay-c2019-04-11 16:57:56 +0530
commitb0c1405589824fc9f9f464683286cdac7ad139d0 (patch)
treee28f1efce0fce74e20a95f42e965f02a372b29ee /ldmicro
parentb874e82bc5a6856c4b2fa4c19f98ab2269daebc6 (diff)
downloadLDmicroQt-b0c1405589824fc9f9f464683286cdac7ad139d0.tar.gz
LDmicroQt-b0c1405589824fc9f9f464683286cdac7ad139d0.tar.bz2
LDmicroQt-b0c1405589824fc9f9f464683286cdac7ad139d0.zip
Improved cursor performance, simulation timer, drawwindow,scrollbar,closeevent, open-save dialogs, submenu-disabling
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/draw.cpp3
-rw-r--r--ldmicro/draw_outputdev.cpp27
-rw-r--r--ldmicro/helpdialog.cpp3
-rw-r--r--ldmicro/includes/ldmicro.h1
-rw-r--r--ldmicro/ldmicro.cpp36
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp149
-rw-r--r--ldmicro/maincontrols.cpp20
-rw-r--r--ldmicro/simulate.cpp8
8 files changed, 156 insertions, 91 deletions
diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp
index d2feca2..b3bec06 100644
--- a/ldmicro/draw.cpp
+++ b/ldmicro/draw.cpp
@@ -396,7 +396,8 @@ static BOOL DrawEndOfLine(HCRDC Hcr, int which, ElemLeaf *leaf, int *cx, int *cy
int gx = *cx/POS_WIDTH;
int gy = *cy/POS_HEIGHT;
- if(CheckBoundsUndoIfFails(gx, gy)) return FALSE;
+ if(CheckBoundsUndoIfFails(gx, gy))
+ return FALSE;
if(gx >= DISPLAY_MATRIX_X_SIZE) oops();
DM_BOUNDS(gx, gy);
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index d7ca7bd..7dd1723 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -86,7 +86,11 @@ BOOL BlinkCursor(BOOL kill = FALSE)
{
// if(GetFocus(MainWindow) != !CursorDrawn) return TRUE;
- if(Cursor.left() == 0) return TRUE;
+ if(Cursor.left() == 0)
+ {
+ CursorObject->setVisible(FALSE);
+ return TRUE;
+ }
QRect c;
memcpy(&c, &Cursor, sizeof(c));
@@ -252,8 +256,16 @@ int ScreenRowsAvailable(void)
void PaintWidget::timerEvent(QTimerEvent *event)
{
- if (event->timerId() == CursorTimer)
+
+ if(event->timerId() == CursorTimer)
+ {
BlinkCursor();
+ // printf("CursorTimer\n");
+ }
+ if(event->timerId() == SimulateTimer)
+ {
+ PlcCycleTimer(FALSE);
+ }
}
//-----------------------------------------------------------------------------
@@ -325,6 +337,15 @@ void PaintWidget::paintEvent(QPaintEvent *event)
cy += thisHeight;
cy += POS_HEIGHT;
}
+ // printf("Endrung:%d\n", cy);
+ QSize DWSize = this->size();
+ int newHeight = ((cy + (POS_HEIGHT/2)) * FONT_HEIGHT + Y_PADDING + 50);
+ if(DWSize.height() < newHeight)
+ {
+ DWSize.setHeight(newHeight);
+ }
+ DrawWindow->resize(DWSize);
+
cy -= 2;
DrawEndRung(Hcr, 0, cy);
@@ -352,7 +373,7 @@ void PaintWidget::paintEvent(QPaintEvent *event)
r.setLeft(X_PADDING - FONT_WIDTH);
r.setTop(0);
r.setRight(r.left() + 4);
- r.setBottom(IoListTop);
+ r.setBottom(this->height());
FillRect(Hcr, &r, InSimulationMode ? BusLeftBrush : BusBrush);
r.setLeft(POS_WIDTH*FONT_WIDTH*ColsAvailable + 32);
r.setRight(POS_WIDTH*FONT_WIDTH*ColsAvailable + 32);
diff --git a/ldmicro/helpdialog.cpp b/ldmicro/helpdialog.cpp
index ea4d23e..9bd28e1 100644
--- a/ldmicro/helpdialog.cpp
+++ b/ldmicro/helpdialog.cpp
@@ -329,11 +329,12 @@ void ShowHelpDialog(BOOL about)
HelpDialog[a]->setLayout(PackBoxHelp);
HelpDialog[a]->show();
+ RichEdit[a]->verticalScrollBar()->setValue(
+ RichEdit[a]->verticalScrollBar()->minimum());
/*if(HelpWindowOpen[a]) {
gtk_widget_grab_focus (HelpDialog[a]);
return;
}*/
HelpWindowOpen[a] = TRUE;
- RichEdit[a]->verticalScrollBar()->setValue(RichEdit[a]->verticalScrollBar()->minimum());
}
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index fa9ae53..f9710a0 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -610,6 +610,7 @@ class MyWidget : public QWidget
void keyPressEvent(QKeyEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
+ void closeEvent(QCloseEvent* event);
};
// maincontrols.cpp
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index 7fa64ee..3e19fb8 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -81,7 +81,7 @@ gboolean LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data
// Get a filename with a common dialog box and then save the program to that
// file and then set our default filename to that.
//-----------------------------------------------------------------------------
-/*static BOOL SaveAsDialog(void)
+static BOOL SaveAsDialog(void)
{
OPENFILENAME ofn;
@@ -105,7 +105,7 @@ gboolean LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data
return TRUE;
}
}
-
+/*
//-----------------------------------------------------------------------------
// Get a filename with a common dialog box and then export the program as
// an ASCII art drawing.
@@ -131,7 +131,7 @@ static void ExportDialog(void)
return;
ExportDrawingAsText(exportFile);
-}
+}*/
//-----------------------------------------------------------------------------
// If we already have a filename, save the program to that. Otherwise same
@@ -150,7 +150,7 @@ static BOOL SaveProgram(void)
} else {
return SaveAsDialog();
}
-}*/
+}
//-----------------------------------------------------------------------------
// Compile the program to a hex file for the target micro. Get the output
@@ -234,10 +234,10 @@ BOOL CheckSaveUserCancels(void)
MB_YESNOCANCEL , MB_ICONWARNING);
switch(r) {
case IDYES:
- // if(SaveProgram())
+ if(SaveProgram())
return FALSE;
- // else
- // return TRUE;
+ else
+ return TRUE;
case IDNO:
return FALSE;
@@ -359,7 +359,7 @@ static void ProcessMenu(int code)
}
switch(code) {
- /*case MNU_NEW:
+ case MNU_NEW:
if(CheckSaveUserCancels()) break;
NewProgram();
strcpy(CurrentSaveFile, "");
@@ -367,14 +367,14 @@ static void ProcessMenu(int code)
GenerateIoListDontLoseSelection();
RefreshScrollbars();
UpdateMainWindowTitleBar();
- break;*/
+ break;
case MNU_OPEN:
if(CheckSaveUserCancels()) break;
OpenDialog();
break;
- /*case MNU_SAVE:
+ case MNU_SAVE:
SaveProgram();
UpdateMainWindowTitleBar();
break;
@@ -383,7 +383,7 @@ static void ProcessMenu(int code)
SaveAsDialog();
UpdateMainWindowTitleBar();
break;
-
+/*
case MNU_EXPORT:
ExportDialog();
break;
@@ -708,6 +708,20 @@ void MyWidget::keyPressEvent(QKeyEvent* event)
return;
}
+
+void MyWidget::closeEvent(QCloseEvent* event)
+{
+ if(CheckSaveUserCancels())
+ event->ignore();
+ else
+ event->accept();
+
+ /*GdkRectangle allocation;
+ gtk_widget_get_allocation(GTK_WIDGET(view), &allocation);
+ IoListHeight = allocation.height;
+ FreezeWindowPos(MainWindow);
+ FreezeDWORD(IoListHeight);*/
+}
// gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
// {
// /* Handles:
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index b17edf7..a8c4eb3 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -58,73 +58,45 @@ int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags, UINT iFlag
BOOL GetSaveFileName(OPENFILENAME *ofn)
{
- /*GtkWidget *dialog;
- GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
-
- dialog = gtk_file_chooser_dialog_new (ofn->lpstrTitle,
- GTK_WINDOW(ofn->parentWindow),
- action,
- "_Cancel",
- GTK_RESPONSE_CANCEL,
- "_Save",
- GTK_RESPONSE_ACCEPT,
- NULL);
+ std::string strFilter;
+ DWORD strFilterLen = 0;
+ BOOL filterResetFlag = FALSE;
char filename[15] = "Untitled";
if (ofn->lpstrDefExt != NULL)
sprintf(filename, "Untitled.%s", ofn->lpstrDefExt);
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), filename);
-
- if (ofn->Flags & OFN_OVERWRITEPROMPT)
- gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
-
- GtkFileFilter *filter = gtk_file_filter_new ();
- char* strFilter = new char[strlen(ofn->lpstrFilter)];
- DWORD strFilterLen = 0;
- BOOL filterResetFlag = FALSE;
-
- for (int i = 0; !(ofn->lpstrFilter[i] == '\0' && ofn->lpstrFilter[i-1] == '\0'); ++i)
+ while(!((ofn->lpstrFilter[strFilterLen] == '\0') &&
+ (ofn->lpstrFilter[strFilterLen + 1] == '\0')))
{
- memcpy (strFilter + strFilterLen, &ofn->lpstrFilter[i], 1 );
- ++strFilterLen;
- if (ofn->lpstrFilter[i] == '\0')
- if (filterResetFlag)
- {
- gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter);
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter);
- filter = gtk_file_filter_new ();
- strFilterLen = 0;
- filterResetFlag = FALSE;
- }
- else
- {
- gtk_file_filter_set_name (GTK_FILE_FILTER(filter), strFilter);
- strFilterLen = 0;
- filterResetFlag = TRUE;
- }
+ if(filterResetFlag)
+ {
+ strFilter = strFilter + "(";
+ strFilter.append(&ofn->lpstrFilter[strFilterLen]);
+ strFilter = strFilter + ");;";
+ filterResetFlag = FALSE;
+ }
+ else
+ {
+ strFilter.append(&ofn->lpstrFilter[strFilterLen]);
+ filterResetFlag = TRUE;
+ }
+ strFilterLen = strFilterLen + strlen(&ofn->lpstrFilter[strFilterLen]) +1;
}
- sprintf(strFilter, "*.%s", ofn->lpstrDefExt);
- gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter);
- gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(dialog), filter);
-
- delete strFilter;
+ QString file = QFileDialog::getSaveFileName(ofn->parentWindow, ofn->lpstrTitle,
+ QStandardPaths::locate(QStandardPaths::HomeLocation,"",
+ QStandardPaths::LocateDirectory)+ filename,
+ strFilter.c_str());
+ BOOL exitStatus;
+ file.isEmpty() ? exitStatus = FALSE : exitStatus = TRUE;
- BOOL exitStatus = gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
if (exitStatus)
{
- char* str;
- str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
-
- strcpy(ofn->lpstrFile, str);
- g_free(str);
+ strcpy(ofn->lpstrFile, file.toStdString().c_str());
}
-
- gtk_widget_destroy (dialog);
- return exitStatus;*/
- return TRUE;
+ return exitStatus;
}
BOOL GetOpenFileName(OPENFILENAME *ofn)
@@ -171,21 +143,49 @@ void EnableMenuItem(HMENU MenuName, QAction* MenuItem, UINT CheckEnabledItem)
switch (CheckEnabledItem){
case MF_ENABLED :
MenuItem->setEnabled(true);
+ // MenuItem->blockSignals(false);
break;
case MF_GRAYED :
MenuItem->setEnabled(false);
+ // MenuItem->blockSignals(true);
break;
}
}
void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem)
{
+ /*Blocks only the top menu signals. Does not block submenu signals.
+ Signals still executed through keyboard shortcuts
+ Reqd:
+ QList<QAction *> actions()
+ action->blockSignals(bool)*/
+ QList<QAction *> MenuList = MenuItem->actions();
+ QList<QAction *>::iterator item = MenuList.begin();
+ // printf("MenuListCount%d\n", MenuList.count());
switch (CheckEnabledItem){
case MF_ENABLED :
+ while((item != MenuList.end()))/* || !(MenuList->isEmpty))*/
+ {
+ (*item)->setEnabled(true);
+ (*item)->blockSignals(false);
+ item++;
+ // printf("Indexof%d\n", MenuList.indexOf(*item, 0));
+ }
MenuItem->setEnabled(true);
+ MenuItem->blockSignals(false);
break;
case MF_GRAYED :
+ while((item != MenuList.end()))/* || !(MenuList->isEmpty))*/
+ {
+ (*item)->setEnabled(false);
+ (*item)->blockSignals(true);
+ /*if(*item == InsertContactsMenu)
+ printf("InsertContactsMenu\n");*/
+ item++;
+ // printf("Indexof%d\n", MenuList.indexOf(*item, 0));
+ }
MenuItem->setEnabled(false);
+ MenuItem->blockSignals(true);
break;
}
}
@@ -459,16 +459,25 @@ UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, UINT TimerID)
{
if(TimerID != NULL)
return nIDEvent;
- if(nIDEvent == TIMER_BLINK_CURSOR)
+ switch(nIDEvent)
{
- TimerID = hWid->startTimer(uElapse);
- CursorObject = new QGroupBox(hWid);
-
- QPalette pal = CursorObject->palette();
- pal.setColor(QPalette::Background, Qt::white);
- CursorObject->setAutoFillBackground(true);
- CursorObject->setPalette(pal);
- CursorObject->setGeometry(0,0,2,20);
+ case TIMER_BLINK_CURSOR:
+ {
+ TimerID = hWid->startTimer(uElapse);
+ CursorObject = new QGroupBox(hWid);
+ QPalette pal = CursorObject->palette();
+ pal.setColor(QPalette::Background, Qt::white);
+ CursorObject->setAutoFillBackground(true);
+ CursorObject->setPalette(pal);
+ CursorObject->setGeometry(0,0,2,20);
+ }
+ break;
+
+ case TIMER_SIMULATE:
+ {
+ TimerID = hWid->startTimer(uElapse);
+ }
+ break;
}
// if(hWid!=NULL)
// CursorObject->setVisible(TRUE);
@@ -498,9 +507,19 @@ BOOL KillTimer(HWID hWid, UINT uIDEvent)
record_it->pfun(TRUE);
g_source_remove (record_it->utID);
timerRecords.erase(record_it);*/
- if(uIDEvent == TIMER_BLINK_CURSOR)
+ // printf("KillTimer\n");
+ switch(uIDEvent)
{
- hWid->killTimer(CursorTimer);
+ case TIMER_BLINK_CURSOR:
+ hWid->killTimer(CursorTimer);
+ CursorTimer = NULL;
+ CursorObject->setVisible(FALSE);
+ break;
+
+ case TIMER_SIMULATE:
+ hWid->killTimer(SimulateTimer);
+ SimulateTimer = NULL;
+ break;
}
return TRUE;
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index be15552..51d7b54 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -549,14 +549,20 @@ void MakeMainWindowControls(void)
IoList->insertTopLevelItems(0, items);*/
DrawWindow->setAutoFillBackground(true);
QSize DWSize;
-
+ WM_SCROLL scrollbar = new QScrollArea();
+ scrollbar->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ scrollbar->setFocusPolicy(Qt::NoFocus);
DWSize.setHeight(MainWindow->height() - IoListHeight);
DWSize.setWidth(MainWindow->width());
DrawWindow->setMinimumHeight(100);
- DrawWindow->resize(DWSize);
- WM_SCROLL scrollbar = new QScrollArea();
+ // scrollbar->setWidgetResizable(TRUE);
+ scrollbar->resize(DWSize);
+ // DrawWindow->resize(scrollbar->viewportSizeHint());
scrollbar->setWidget(DrawWindow);
splitter->addWidget(scrollbar);
+ DWSize.setWidth(MainWindow->width() -
+ (scrollbar->sizeHint().width()+ MainWindow->sizeHint().width()));
+ DrawWindow->resize(DWSize);
/*QPalette pal = QPalette();
pal.setColor(QPalette::Background, Qt::black);
DrawWindow->setAutoFillBackground(true);
@@ -958,6 +964,7 @@ void ToggleSimulationMode(void)
{
InSimulationMode = !InSimulationMode;
if(InSimulationMode) {
+ KillTimer(DrawWindow, TIMER_BLINK_CURSOR);
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED);
EnableMenuItem(SimulateMenu, SingleCycleMenu, MF_ENABLED);
@@ -983,8 +990,8 @@ void ToggleSimulationMode(void)
}
else {
RealTimeSimulationRunning = FALSE;
- // KillTimer(MainWindow, TIMER_SIMULATE);
-
+ KillTimer(DrawWindow, TIMER_SIMULATE);
+ CursorTimer = SetTimer(DrawWindow, TIMER_BLINK_CURSOR, 500, CursorTimer);
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, SingleCycleMenu, MF_GRAYED);
@@ -1028,6 +1035,7 @@ void RefreshControlsToSettings(void)
items.append(new QTreeWidgetItem(QStringList(QString("Item2"))));
items.append(new QTreeWidgetItem(QStringList(QString("Item3"))));
IoList->insertTopLevelItems(0, items);*/
+ DrawWindow->repaint();
QTreeWidgetItem iter;
QTreeWidgetItem* selection;
if(!IoListOutOfSync) {
@@ -1167,7 +1175,7 @@ void StopSimulation(void)
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
- // KillTimer(MainWindow, TIMER_SIMULATE);
+ KillTimer(DrawWindow, TIMER_SIMULATE);
// UpdateMainWindowTitleBar();
} \ No newline at end of file
diff --git a/ldmicro/simulate.cpp b/ldmicro/simulate.cpp
index 3cd9212..4a3475a 100644
--- a/ldmicro/simulate.cpp
+++ b/ldmicro/simulate.cpp
@@ -731,14 +731,14 @@ void SimulateOneCycle(BOOL forceRefresh)
//-----------------------------------------------------------------------------
void StartSimulationTimer(void)
{
- /* int p = Prog.cycleTime/1000;
+ int p = Prog.cycleTime/1000;
if(p < 5) {
- SetTimer(MainWindow, TIMER_SIMULATE, 10, PlcCycleTimer);
+ SimulateTimer = SetTimer(DrawWindow, TIMER_SIMULATE, 10, SimulateTimer);
CyclesPerTimerTick = 10000 / Prog.cycleTime;
} else {
- SetTimer(MainWindow, TIMER_SIMULATE, p, PlcCycleTimer);
+ SimulateTimer = SetTimer(DrawWindow, TIMER_SIMULATE, p, SimulateTimer);
CyclesPerTimerTick = 1;
- }*/
+ }
}
//-----------------------------------------------------------------------------