summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakshay-c2019-02-19 12:16:06 +0530
committerakshay-c2019-02-19 12:16:06 +0530
commit0dbffa99fda94203c74b955f6f9fe534f30c6421 (patch)
tree9f0c9476e8c0d5e2de84308b1036b41ea1829d88
parenta962c0a7965f6c0d80c867ba9f3fbe797ac14de7 (diff)
downloadLDmicroQt-0dbffa99fda94203c74b955f6f9fe534f30c6421.tar.gz
LDmicroQt-0dbffa99fda94203c74b955f6f9fe534f30c6421.tar.bz2
LDmicroQt-0dbffa99fda94203c74b955f6f9fe534f30c6421.zip
Text Display in progress
-rw-r--r--ldmicro/CMakeLists.txt5
-rw-r--r--ldmicro/draw.cpp11
-rw-r--r--ldmicro/draw_outputdev.cpp78
-rw-r--r--ldmicro/includes/ldmicro.h6
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp8
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h25
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp49
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h17
-rw-r--r--ldmicro/maincontrols.cpp2
9 files changed, 108 insertions, 93 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt
index 42ec750..3f799c6 100644
--- a/ldmicro/CMakeLists.txt
+++ b/ldmicro/CMakeLists.txt
@@ -104,12 +104,16 @@ IF(UNIX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Core CONFIG REQUIRED)
+ find_package(Qt5Gui CONFIG REQUIRED)
get_target_property(Qt5Widgets_INCLUDES Qt5::Widgets INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(Qt5Core_INCLUDES Qt5::Core INTERFACE_INCLUDE_DIRECTORIES)
+ get_target_property(Qt5Gui_INCLUDES Qt5::Gui INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${Qt5Widgets_INCLUDES})
include_directories(${Qt5Core_INCLUDES})
+ include_directories(${Qt5Gui_INCLUDES})
add_definitions(${Qt5Widgets_DEFINITIONS})
add_definitions(${Qt5Core_DEFINITIONS})
+ include_directories(${Qt5Gui_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
#get_target_property(CMAKE_CXX_FLAGS Qt5::Core LINK_FLAGS)
MESSAGE ( STATUS " Qt INCLUDEs: " ${Qt5Core_INCLUDES} )
@@ -166,6 +170,7 @@ endif()
target_link_libraries (LDMicro FreezeLD)
target_link_libraries(LDMicro ${Qt5Widgets_LIBRARIES})
target_link_libraries(LDMicro ${Qt5Core_LIBRARIES})
+ target_link_libraries(LDMicro ${Qt5Gui_LIBRARIES})
## Add tests
MESSAGE( STATUS "Adding tests.." )
diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp
index dc5bf8d..ed5c6be 100644
--- a/ldmicro/draw.cpp
+++ b/ldmicro/draw.cpp
@@ -180,7 +180,7 @@ static int CountWidthOfElement(int which, void *elem, int soFar)
oops();
}
}
-/*
+
//-----------------------------------------------------------------------------
// Determine the height, in leaf element units, of a particular subcircuit.
// The height of a leaf is 1, the height of a parallel circuit is the sum of
@@ -225,7 +225,7 @@ int CountHeightOfElement(int which, void *elem)
oops();
}
}
-*/
+
//-----------------------------------------------------------------------------
// Determine the width, in leaf element units, of the widest row of the PLC
// program (i.e. loop over all the rungs and find the widest).
@@ -915,7 +915,7 @@ cmp:
return poweredAfter;
}
-
+*/
//-----------------------------------------------------------------------------
// Draw a particular subcircuit with its top left corner at *cx and *cy (in
// characters). If it is a leaf element then just print it and return; else
@@ -934,7 +934,7 @@ BOOL DrawElement(HCRDC Hcr, int which, void *elem, int *cx, int *cy, BOOL powere
ElemLeaf *leaf = (ElemLeaf *)elem;
SetBkColor(DrawWindow,Hcr, InSimulationMode ? HighlightColours.simBg :
HighlightColours.bg);
- NormText(Hcr);
+ /*NormText(Hcr);
if(elem == Selected && !InSimulationMode) {
EmphText(Hcr);
@@ -1044,7 +1044,7 @@ BOOL DrawElement(HCRDC Hcr, int which, void *elem, int *cx, int *cy, BOOL powere
}
- NormText(Hcr);
+ NormText(Hcr);*/
return poweredAfter;
}
@@ -1067,4 +1067,3 @@ void DrawEndRung(HCRDC Hcr, int cx, int cy)
DrawChars(Hcr, cx + i, cy + (POS_HEIGHT/2), "-");
}
}
-*/
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index 12dcb87..3068c23 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -134,14 +134,14 @@ BOOL BlinkCursor(BOOL kill = FALSE)
return !kill;
}
-
+*/
//-----------------------------------------------------------------------------
// Output a string to the screen at a particular location, in character-
// sized units.
//-----------------------------------------------------------------------------
static void DrawCharsToScreen(HCRDC Hcr, int cx, int cy, const char *str)
{
- cy -= ScrollYOffset*POS_HEIGHT;
+ /*cy -= ScrollYOffset*POS_HEIGHT;
if(cy < -2) return;
if(cy*FONT_HEIGHT + Y_PADDING > IoListTop) return;
@@ -211,9 +211,10 @@ static void DrawCharsToScreen(HCRDC Hcr, int cx, int cy, const char *str)
}
firstTime = FALSE;
- }
+ }*/
+ printf("DrawCharsToScreen\n");
}
-*/
+
//-----------------------------------------------------------------------------
// Total number of columns that we can display in the given amount of
// window area. Need to leave some slop on the right for the scrollbar, of
@@ -225,7 +226,7 @@ int ScreenColsAvailable(void)
return (rw - (X_PADDING + X_RIGHT_PADDING)) / (POS_WIDTH*FONT_WIDTH);
}
-/*
+
//-----------------------------------------------------------------------------
// Total number of columns that we can display in the given amount of
// window area. Need to leave some slop on the right for the scrollbar, of
@@ -242,29 +243,53 @@ int ScreenRowsAvailable(void)
}
return (IoListTop - Y_PADDING - adj) / (POS_HEIGHT*FONT_HEIGHT);
}
-*/
+
//-----------------------------------------------------------------------------
// Paint the ladder logic program to the screen. Also figure out where the
// cursor should go and fill in coordinates for BlinkCursor. Not allowed to
// draw deeper than IoListTop, as we would run in to the I/O listbox.
//-----------------------------------------------------------------------------
-void PaintWindow()
+void PaintWidget::paintEvent(QPaintEvent *event)
{
- ok();
- // DrawWindow->setStyleSheet("background-color:black;");
-
- static QPalette pal = QPalette(InSimulationMode ?
- SimBgBrush->rgb() : BgBrush->rgb());
- DrawWindow->setPalette(pal);
+ QPainter painter(this);
+ painter.setClipping(true);
+ QPalette pal = DrawWindow->palette();
+ HCRDC Hcr = &pal;
+ //a simple line
+/* painter.drawLine(1,1,100,100);
+
+ //create a black pen that has solid line
+ //and the width is 2.
+ QPen myPen(Qt::blue, 2, Qt::SolidLine);
+ painter.setPen(myPen);
+ painter.drawLine(100,100,100,1);
+
+ //draw a point
+ myPen.setColor(Qt::red);
+ painter.setPen(myPen);
+ painter.drawPoint(110,110);
+
+ //draw a polygon
+ QPolygon polygon;
+ polygon << QPoint(130, 140) << QPoint(180, 170)
+ << QPoint(180, 140) << QPoint(220, 110)
+ << QPoint(140, 100);
+ painter.drawPolygon(polygon);
+
+ //draw an ellipse
+ //The setRenderHint() call enables antialiasing, telling QPainter to use different
+ //color intensities on the edges to reduce the visual distortion that normally
+ //occurs when the edges of a shape are converted into pixels
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.setPen(QPen(Qt::blue, 3, Qt::DashDotLine, Qt::RoundCap));
+ painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
+ painter.drawEllipse(200, 80, 400, 240);
+*/
- /// now figure out how we should draw the ladder logic
- ColsAvailable = ProgCountWidestRow();
- if(ColsAvailable < ScreenColsAvailable()) {
- ColsAvailable = ScreenColsAvailable();
- }
+ ok();
- /*int bw = gtk_widget_get_allocated_width (DrawWindow);// = r.right;
- int bh = IoListTop;
+ int bw = this->width();// = r.right;
+ int bh = this->height();
/// now figure out how we should draw the ladder logic
ColsAvailable = ProgCountWidestRow();
@@ -280,6 +305,7 @@ void PaintWindow()
int i;
int cy = 0;
int rowsAvailable = ScreenRowsAvailable();
+
for(i = 0; i < Prog.numRungs; i++) {
int thisHeight = POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
Prog.rungs[i]);
@@ -295,7 +321,7 @@ void PaintWindow()
HighlightColours.bg);
SetTextColor(Hcr, InSimulationMode ? HighlightColours.simRungNum :
HighlightColours.rungNum);
- SelectObject(Hcr, FixedWidthFont);
+ SelectObject(painter, FixedWidthFont);
int rung = i + 1;
int y = Y_PADDING + FONT_HEIGHT*cy;
int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) -
@@ -311,13 +337,13 @@ void PaintWindow()
int cx = 0;
DrawElement(Hcr, ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
- Prog.rungPowered[i]);
+ Prog.rungPowered[i]);
}
cy += thisHeight;
cy += POS_HEIGHT;
}
- cy -= 2;
+ /*cy -= 2;
DrawEndRung(Hcr, 0, cy);
if(SelectedGxAfterNextPaint >= 0) {
@@ -360,8 +386,8 @@ void PaintWindow()
} else {
SetTimer(DrawWindow, TIMER_BLINK_CURSOR, 200, BlinkCursor);
}
-
- ok();*/
+*/
+ ok();
}
//-----------------------------------------------------------------------------
@@ -403,7 +429,7 @@ static void SetSyntaxHighlightingColours(void)
//-----------------------------------------------------------------------------
void InitForDrawing(void)
{
- DrawWindow = new QWidget;
+ DrawWindow = new PaintWidget();
SetSyntaxHighlightingColours();
FixedWidthFont = CreateFont(
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index c5db57f..fcbadb4 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -711,7 +711,7 @@ void AddFormattedString(void);
void DeleteSelectedFromProgram(void);
void DeleteSelectedRung(void);
void InsertRung(BOOL afterCursor);
-int RungContainingSelected(void);
+int RungContainingSelected(void);
BOOL ItemIsLastInCircuit(ElemLeaf *item);
BOOL UartFunctionUsed(void);
BOOL PwmFunctionUsed(void);
@@ -734,7 +734,7 @@ BOOL LoadProjectFromFile(char *filename);
BOOL SaveProjectToFile(char *filename);
// iolist.cpp
-int GenerateIoList(int prevSel);
+int GenerateIoList(int prevSel);
void SaveIoListToFile(FILE *f);
BOOL LoadIoListFromFile(FILE *f);
void ShowIoDialog(int item);
@@ -749,7 +749,7 @@ void ShowContactsDialog(BOOL *negated, char *name);
void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name);
//naminglist.cpp
-void MakeSmplDialogClass(void);
+void MakeSmplDialogClass(void);
// simpledialog.cpp
void ShowTimerDialog(int which, int *delay, char *name);
diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index a83d15e..d43fd0e 100644
--- a/ldmicro/lib/linuxUI/linuxLD.cpp
+++ b/ldmicro/lib/linuxUI/linuxLD.cpp
@@ -119,10 +119,10 @@ HICON LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired,
void RECT_to_GDRECT(const RECT *rc, GDRECT *gdrc)
{
- gdrc->x = rc->left;
- gdrc->y = rc->top;
- gdrc->width = rc->right - rc->left;
- gdrc->height = rc->bottom - rc->top;
+ // gdrc->x = rc->left;
+ // gdrc->y = rc->top;
+ // gdrc->width = rc->right - rc->left;
+ // gdrc->height = rc->bottom - rc->top;
}
void OutputDebugString(char* str)
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index f1abbaf..29e6ebc 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -70,18 +70,19 @@ typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
typedef HANDLE HGDIOBJ;
-typedef cairo_t *HCRDC;
-typedef QWidget* HWID;
-typedef QWidget* HWND;
-typedef QTreeWidget *HLIST;
-typedef GtkTreeIter ITLIST;
-typedef GtkApplication *HAPP;
-typedef GtkTreeViewColumn *HTVC;
-typedef GdkPixbuf *HICON;
-typedef GdkRectangle GDRECT;
-typedef GDRECT *PGDRECT;
-typedef QMenu* HMENU;
-typedef ITLIST *HITLIST;
+typedef GtkApplication* HAPP;
+typedef GtkTreeViewColumn* HTVC;
+typedef GdkRectangle* GDRECT;
+typedef QTreeWidget* HLIST;
+typedef GtkTreeIter ITLIST;
+typedef GDRECT* PGDRECT;
+typedef QMenu* HMENU;
+typedef ITLIST* HITLIST;
+typedef QPalette* HCRDC;
+typedef QWidget* HWID;
+typedef QWidget* HWND;
+typedef GdkPixbuf* HICON;
+
/// Check if system is x64 or x86
#if defined(__UNIX64)
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index e8a8ab5..727fea8 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -284,26 +284,15 @@ HANDLE GetStockObject(int fnObject)
}
}
-void SelectObject(HCRDC hcr, HFONT hfont)
+void SelectObject(QPainter* hcr, HFONT hfont)
{
if (hcr ==NULL)
return;
-
- cairo_select_font_face(hcr, hfont->lpszFace,
- hfont->fdwItalic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
- hfont->fnWeight == FW_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
-
- cairo_rotate(hcr, hfont->nOrientation);
- // cairo_text_extents_t extents;
- // cairo_text_extents (hcr, "Z", &extents);
- // cairo_matrix_t matrix;
- // cairo_matrix_init_scale (&matrix,
- // (double)hfont->nWidth,
- // (double)hfont->nHeight);
-
- // cairo_set_font_matrix (hcr, &matrix);
-
- cairo_set_font_size(hcr, 10);
+ QFont qtfont(hfont->lpszFace);
+ qtfont.setPointSize(hfont->nHeight);
+ qtfont.setStyle(hfont->fdwItalic ? QFont::StyleItalic : QFont::StyleNormal);
+ qtfont.setWeight(hfont->fnWeight == FW_BOLD ? QFont::Bold : QFont::Normal);
+ hcr->setFont();
}
HBRUSH CreateBrushIndirect(PLOGBRUSH plb)
@@ -334,28 +323,8 @@ HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight,
void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
{
-/* if (hcr == NULL)
- return;
-
- gtk_widget_override_background_color(GTK_WIDGET(widget),
- GTK_STATE_FLAG_NORMAL, &bkCol);
-
- gint width = gtk_widget_get_allocated_width (widget);
- gint height = gtk_widget_get_allocated_height (widget);
-
- // COLORREF col;
- // GtkStyleContext *context;
-
- // context = gtk_widget_get_style_context (widget);
-
- // gtk_style_context_get_color (context,
- // gtk_style_context_get_state (context),
- // &col);
- gdk_cairo_set_source_rgba (hcr, &bkCol);
- // cairo_rectangle(hcr, 0, 0, width, height);
- // cairo_stroke_preserve(hcr);
-
- cairo_fill (hcr);*/
+ hcr->setColor(QPalette::Background, bkCol);
+ widget->setPalette(*hcr);
}
void SetTextColor(HCRDC hcr, COLORREF color)
@@ -540,3 +509,5 @@ void DestroyWindow (HWID widget)
gtk_widget_destroy (widget);
}*/
}
+
+
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index e482051..88a89c4 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -9,6 +9,8 @@
#include <QMenuBar>
#include <QVBoxLayout>
#include <QLabel>
+#include <QPainter>
+// #include <QtGui>
// #include <QSize>
// #include "freezeLD.h"
// #include "linuxLD.h"
@@ -186,7 +188,7 @@ void CheckMenuItem(
HANDLE GetStockObject(int fnObject);
void SelectObject(
- HCRDC hcr,
+ QPainter* hcr,
HFONT hfont);
HBRUSH CreateBrushIndirect(PLOGBRUSH plb);
@@ -265,6 +267,17 @@ BOOL KillTimer(
void DestroyWindow (HWID widget);
-
+class PaintWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ // MyWidget();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+signals:
+
+public slots:
+};
#endif \ No newline at end of file
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index 976688b..5b4a924 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -1156,7 +1156,7 @@ void GenerateIoListDontLoseSelection(void)
//-----------------------------------------------------------------------------
void MainWindowResized(void)
{
- PaintWindow();
+ //PaintWindow();
/*RECT main;
//GetClientRect(DrawWindow, &main);