[Gambas-user] TextEdit on Qt5
Ian Haywood
ihaywood3 at ...626...
Sat Jan 23 09:48:07 CET 2016
This was a lot simpler than I thought.
I enclose a working patch. Two outstanding issues:
- the TextEdit has a grey background (the system default) and ignores
setting .Background = Color.White
- the documentation doesn't appear in the IDE (because it's looking
for qt4.TextEdit, whereas the docs wil lbe under
qt5.ext.TextEdit)
I suspect I'm missing something (i.e. if it's so easy presumably
Benoit had a good reason for not doing it at the start)
Anyway I hope this will kick the work along... as I said several of us
*really need* TextEdit!
Ian
-------------- next part --------------
diff --git a/gb.qt4/src/main.cpp b/gb.qt4/src/main.cpp
index 543dc7c..b3bfec6 100644
--- a/gb.qt4/src/main.cpp
+++ b/gb.qt4/src/main.cpp
@@ -99,6 +99,8 @@
#include <QX11Info>
#ifndef QT5
#include "CEmbedder.h"
+#else
+#include "CTextEdit.h"
#endif
#include "desktop.h"
@@ -147,6 +149,9 @@ GB_CLASS CLASS_ScrollView;
GB_CLASS CLASS_Image;
GB_CLASS CLASS_SvgImage;
GB_CLASS CLASS_TextArea;
+#ifdef QT5
+GB_CLASS CLASS_TextEdit;
+#endif
static bool in_event_loop = false;
static int _no_destroy = 0;
@@ -1298,6 +1303,9 @@ GB_DESC *GB_CLASSES[] EXPORT =
CWatcherDesc,
PrinterDesc,
SvgImageDesc,
+#ifdef QT5
+ CTextEditSelectionDesc, CTextEditFormatDesc, CTextEditDesc,
+#endif
NULL
};
@@ -1406,7 +1414,9 @@ int EXPORT GB_INIT(void)
CLASS_Image = GB.FindClass("Image");
CLASS_SvgImage = GB.FindClass("SvgImage");
CLASS_TextArea = GB.FindClass("TextArea");
-
+#ifdef QT5
+ CLASS_TextEdit = GB.FindClass("TextEdit");
+#endif
QT_InitEventLoop();
#ifdef OS_CYGWIN
diff --git a/gb.qt5/src/CTextEdit.cpp b/gb.qt5/src/CTextEdit.cpp
new file mode 100644
index 0000000..bb0bc20
--- /dev/null
+++ b/gb.qt5/src/CTextEdit.cpp
@@ -0,0 +1,728 @@
+/***************************************************************************
+
+ CTextEdit.cpp
+
+ (c) 2000-2013 Benoît Minisini <gambas at users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+
+***************************************************************************/
+
+#define __CTEXTEDIT_CPP
+
+#include <QApplication>
+#include <QPalette>
+#include <QPlainTextEdit>
+#include <QTextDocumentFragment>
+#include <QTextBlock>
+#include <QScrollBar>
+#include <QAbstractTextDocumentLayout>
+
+#include "gambas.h"
+#include "main.h"
+#include "CFont.h"
+#include "CConst.h"
+#include "CTextEdit.h"
+
+
+DECLARE_EVENT(EVENT_Change);
+DECLARE_EVENT(EVENT_Cursor);
+
+#if 0
+static void to_pos(Q3TextEdit *wid, int par, int car, int *pos)
+{
+ int i, l;
+ int p = 0;
+
+ for (i = 0; i < par; i++)
+ {
+ l = wid->paragraphLength(i);
+ if (l < 0)
+ break;
+ p += l + 1;
+ }
+
+ *pos = p + car;
+}
+
+
+static void from_pos(Q3TextEdit *wid, int pos, int *par, int *car)
+{
+ int i;
+ int l;
+
+ for (i = 0; i <= wid->paragraphs(); i++)
+ {
+ l = wid->paragraphLength(i);
+ if (l < 0)
+ {
+ pos = wid->length();
+ i--;
+ break;
+ }
+ if (pos <= l)
+ break;
+ pos -= l + 1;
+ }
+
+ *par = i;
+ *car = pos;
+}
+
+
+static void look_pos(Q3TextEdit *wid, int *line, int *col)
+{
+ if (*line == -1)
+ *line = wid->paragraphs();
+
+ if (*col == -1)
+ *col = wid->paragraphLength(*line);
+}
+
+
+static void get_selection(Q3TextEdit *wid, int *start, int *length)
+{
+ int pStart, iStart, pEnd, iEnd;
+ int posEnd;
+
+ wid->getSelection(&pStart, &iStart, &pEnd, &iEnd);
+
+ if (pStart < 0)
+ {
+ wid->getCursorPosition(&pStart, &iStart);
+ to_pos(wid, pStart, iStart, start);
+ *length = 0;
+ return;
+ }
+
+ to_pos(wid, pStart, iStart, start);
+ to_pos(wid, pEnd, iEnd, &posEnd);
+
+ *length = posEnd - *start;
+}
+#endif
+
+static int get_length(void *_object)
+{
+ if (THIS->length < 0)
+ {
+ QTextBlock block = WIDGET->document()->begin();
+ int len = 0;
+
+ while (block.isValid())
+ {
+ len += block.length();
+ block = block.next();
+ }
+
+ THIS->length = len - 1;
+ }
+
+ return THIS->length;
+}
+
+static int get_column(void *_object)
+{
+ QTextCursor cursor = WIDGET->textCursor();
+ return cursor.position() - cursor.block().position();
+}
+
+static void to_pos(QTextEdit *wid, int par, int car, int *pos)
+{
+ QTextCursor cursor = wid->textCursor();
+ QTextBlock block = cursor.block();
+ int p = 0;
+
+ while (par)
+ {
+ if (!block.isValid())
+ break;
+ p += block.length() + 1;
+ block = block.next();
+ par--;
+ }
+
+ *pos = p + car;
+}
+
+
+static void from_pos(void *_object, int pos, int *par, int *car)
+{
+ QTextCursor cursor = WIDGET->textCursor();
+
+ if (pos >= get_length(THIS))
+ cursor.movePosition(QTextCursor::End);
+ else
+ cursor.setPosition(pos);
+
+ *par = cursor.blockNumber();
+ *car = cursor.position() - cursor.block().position();
+}
+
+
+static void get_selection(QTextEdit *wid, int *start, int *length)
+{
+ QTextCursor cursor = wid->textCursor();
+
+ *start = cursor.selectionStart();
+ *length = cursor.selectionEnd() - *start;
+}
+
+
+/** MyTextEdit *************************************************************/
+
+MyTextEdit::MyTextEdit(QWidget *parent) : QTextEdit(parent)
+{
+ setTabChangesFocus(true);
+ //viewport()->setMouseTracking(true);
+}
+
+MyTextEdit::~MyTextEdit()
+{
+}
+
+void MyTextEdit::emitLinkClicked(const QString &s)
+{
+ //d->textOrSourceChanged = FALSE;
+ emit linkClicked( s );
+ //if ( !d->textOrSourceChanged )
+ // setSource( s );
+}
+
+/** TEXTEDIT ***************************************************************/
+
+BEGIN_PROPERTY(CTEXTEDIT_text)
+
+ if (READ_PROPERTY)
+ RETURN_NEW_STRING(WIDGET->document()->toPlainText());
+ else
+ {
+ WIDGET->document()->setPlainText(QSTRING_PROP());
+ //THIS->length = -1;
+ }
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_rich_text)
+
+ if (READ_PROPERTY)
+ RETURN_NEW_STRING(WIDGET->document()->toHtml("utf-8"));
+ else
+ WIDGET->document()->setHtml(QSTRING_PROP());
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_length)
+
+ GB.ReturnInteger(get_length(THIS));
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_read_only)
+
+ if (READ_PROPERTY)
+ GB.ReturnBoolean(WIDGET->isReadOnly());
+ else
+ WIDGET->setReadOnly(VPROP(GB_BOOLEAN));
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_wrap)
+
+ if (READ_PROPERTY)
+ GB.ReturnBoolean(WIDGET->lineWrapMode() != QTextEdit::NoWrap);
+ else
+ WIDGET->setLineWrapMode(VPROP(GB_BOOLEAN) ? QTextEdit::WidgetWidth : QTextEdit::NoWrap);
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_column)
+
+ QTextCursor cursor = WIDGET->textCursor();
+
+ if (READ_PROPERTY)
+ //GB.ReturnInteger(WIDGET->textCursor().columnNumber());
+ GB.ReturnInteger(get_column(THIS));
+ else
+ {
+ int col = VPROP(GB_INTEGER);
+
+ if (col <= 0)
+ cursor.movePosition(QTextCursor::QTextCursor::StartOfBlock);
+ else if (col >= cursor.block().length())
+ cursor.movePosition(QTextCursor::QTextCursor::EndOfBlock);
+ else
+ cursor.setPosition(cursor.block().position() + col);
+
+ WIDGET->setTextCursor(cursor);
+ }
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_line)
+
+ QTextCursor cursor = WIDGET->textCursor();
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(cursor.blockNumber());
+ else
+ {
+ int col = get_column(THIS);
+ int line = VPROP(GB_INTEGER);
+
+ if (line < 0)
+ cursor.movePosition(QTextCursor::Start);
+ else if (line >= WIDGET->document()->blockCount())
+ cursor.movePosition(QTextCursor::End);
+ else
+ {
+ cursor.setPosition(WIDGET->document()->findBlockByNumber(line).position());
+ if (col > 0)
+ {
+ if (col >= cursor.block().length())
+ cursor.movePosition(QTextCursor::QTextCursor::EndOfBlock);
+ else
+ cursor.setPosition(cursor.block().position() + col);
+ }
+ }
+
+ WIDGET->setTextCursor(cursor);
+ }
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_pos)
+
+ if (READ_PROPERTY)
+ {
+ GB.ReturnInteger(WIDGET->textCursor().position());
+ }
+ else
+ {
+ int pos = VPROP(GB_INTEGER);
+ QTextCursor cursor = WIDGET->textCursor();
+
+ if (pos >= get_length(THIS))
+ cursor.movePosition(QTextCursor::End);
+ else
+ cursor.setPosition(pos);
+
+ WIDGET->setTextCursor(cursor);
+ }
+
+END_PROPERTY
+
+BEGIN_METHOD_VOID(CTEXTEDIT_clear)
+
+ WIDGET->clear();
+
+END_METHOD
+
+BEGIN_METHOD(CTEXTEDIT_insert, GB_STRING text)
+
+ WIDGET->textCursor().insertText(QSTRING_ARG(text));
+
+END_METHOD
+
+
+/** .TextEdit.Selection ****************************************************/
+
+BEGIN_PROPERTY(CTEXTEDIT_sel_text)
+
+ if (READ_PROPERTY)
+ RETURN_NEW_STRING(WIDGET->textCursor().selection().toPlainText());
+ else
+ WIDGET->textCursor().insertText(QSTRING_PROP());
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_sel_rich_text)
+
+ if (READ_PROPERTY)
+ RETURN_NEW_STRING(WIDGET->textCursor().selection().toHtml());
+ else
+ WIDGET->textCursor().insertFragment(QTextDocumentFragment::fromHtml(QSTRING_PROP()));
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_sel_length)
+
+ int start, length;
+
+ get_selection(WIDGET, &start, &length);
+ GB.ReturnInteger(length);
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_sel_start)
+
+ int start, length;
+
+ get_selection(WIDGET, &start, &length);
+ GB.ReturnInteger(start);
+
+END_PROPERTY
+
+BEGIN_METHOD_VOID(CTEXTEDIT_sel_clear)
+
+ QTextCursor cursor = WIDGET->textCursor();
+ cursor.clearSelection();
+ WIDGET->setTextCursor(cursor);
+
+END_METHOD
+
+BEGIN_PROPERTY(CTEXTEDIT_selected)
+
+ GB.ReturnBoolean(WIDGET->textCursor().hasSelection());
+
+END_PROPERTY
+
+BEGIN_METHOD(CTEXTEDIT_sel_select, GB_INTEGER start; GB_INTEGER length)
+
+ if (MISSING(start) && MISSING(length))
+ WIDGET->textCursor().select(QTextCursor::Document);
+ else if (!MISSING(start) && !MISSING(length))
+ {
+ QTextCursor cursor = WIDGET->textCursor();
+
+ cursor.setPosition(VARG(start));
+ cursor.setPosition(VARG(start) + VARG(length), QTextCursor::KeepAnchor);
+
+ WIDGET->setTextCursor(cursor);
+ }
+
+END_METHOD
+
+BEGIN_METHOD_VOID(CTEXTEDIT_sel_all)
+
+ QTextCursor cursor = WIDGET->textCursor();
+ cursor.select(QTextCursor::Document);
+ WIDGET->setTextCursor(cursor);
+
+END_METHOD
+
+/***************************************************************************/
+
+BEGIN_METHOD(CTEXTEDIT_to_pos, GB_INTEGER line; GB_INTEGER col)
+
+ int pos;
+
+ to_pos(WIDGET, VARG(line), VARG(col), &pos);
+
+ GB.ReturnInteger(pos);
+
+END_METHOD
+
+BEGIN_METHOD(CTEXTEDIT_to_line, GB_INTEGER pos)
+
+ int line, col;
+
+ from_pos(THIS, VARG(pos), &line, &col);
+
+ GB.ReturnInteger(line);
+
+END_METHOD
+
+BEGIN_METHOD(CTEXTEDIT_to_col, GB_INTEGER pos)
+
+ int line, col;
+
+ from_pos(THIS, VARG(pos), &line, &col);
+
+ GB.ReturnInteger(col);
+
+END_METHOD
+
+BEGIN_METHOD_VOID(CTEXTEDIT_copy)
+
+ WIDGET->copy();
+
+END_METHOD
+
+
+BEGIN_METHOD_VOID(CTEXTEDIT_cut)
+
+ WIDGET->cut();
+
+END_METHOD
+
+
+BEGIN_METHOD_VOID(CTEXTEDIT_paste)
+
+ WIDGET->paste();
+
+END_METHOD
+
+
+BEGIN_METHOD_VOID(CTEXTEDIT_undo)
+
+ WIDGET->undo();
+
+END_METHOD
+
+
+BEGIN_METHOD_VOID(CTEXTEDIT_redo)
+
+ WIDGET->redo();
+
+END_METHOD
+
+BEGIN_METHOD_VOID(CTEXTEDIT_ensure_visible)
+
+ WIDGET->ensureCursorVisible();
+
+END_METHOD
+
+
+BEGIN_PROPERTY(CTEXTEDIT_border)
+
+ CWIDGET_border_simple(_object, _param);
+
+END_PROPERTY
+
+
+
+/** TextEdit ***************************************************************/
+
+BEGIN_METHOD(CTEXTEDIT_new, GB_OBJECT parent)
+
+ QTextEdit *wid = new QTextEdit(QCONTAINER(VARG(parent)));
+
+ QObject::connect(wid, SIGNAL(textChanged()), &CTextEdit::manager, SLOT(changed()));
+ QObject::connect(wid, SIGNAL(cursorPositionChanged()), &CTextEdit::manager, SLOT(cursor()));
+
+ wid->setLineWrapMode(QTextEdit::NoWrap);
+
+ CWIDGET_new(wid, (void *)_object);
+
+ THIS->length = -1;
+
+END_METHOD
+
+BEGIN_PROPERTY(CTEXTEDIT_scroll_x)
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(WIDGET->horizontalScrollBar()->value());
+ else
+ WIDGET->horizontalScrollBar()->setValue(VPROP(GB_INTEGER));
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_scroll_y)
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(WIDGET->verticalScrollBar()->value());
+ else
+ WIDGET->verticalScrollBar()->setValue(VPROP(GB_INTEGER));
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_text_width)
+
+ if (WIDGET->document()->isEmpty())
+ GB.ReturnInteger(0);
+ else
+ GB.ReturnInteger(WIDGET->document()->documentLayout()->documentSize().toSize().width());
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_text_height)
+
+ if (WIDGET->document()->isEmpty())
+ GB.ReturnInteger(0);
+ else
+ GB.ReturnInteger(WIDGET->document()->documentLayout()->documentSize().toSize().height());
+
+END_PROPERTY
+
+/***************************************************************************/
+
+BEGIN_PROPERTY(CTEXTEDIT_format_alignment)
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(CCONST_alignment(WIDGET->alignment() + Qt::AlignVCenter, ALIGN_NORMAL, false));
+ else
+ WIDGET->setAlignment((Qt::Alignment)(CCONST_alignment(VPROP(GB_INTEGER), ALIGN_NORMAL, true) & Qt::AlignHorizontal_Mask));
+
+END_PROPERTY
+
+
+/*BEGIN_PROPERTY(CTEXTEDIT_format_position)
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(WIDGET->verticalAlignment());
+ else
+ WIDGET->setVerticalAlignment((QTextEdit::VerticalAlignment)VPROP(GB_INTEGER));
+
+END_PROPERTY*/
+
+static void set_font(QFont &font, void *_object = 0)
+{
+ WIDGET->setCurrentFont(font);
+}
+
+BEGIN_PROPERTY(CTEXTEDIT_format_font)
+
+ if (READ_PROPERTY)
+ GB.ReturnObject(CFONT_create(WIDGET->currentFont(), set_font, _object));
+ else
+ CFONT_set(set_font, VPROP(GB_OBJECT), THIS);
+
+END_PROPERTY
+
+
+BEGIN_PROPERTY(CTEXTEDIT_format_color)
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(WIDGET->textColor().rgb() & 0xFFFFFF);
+ else
+ WIDGET->setTextColor(QColor((QRgb)VPROP(GB_INTEGER)));
+
+END_PROPERTY
+
+BEGIN_PROPERTY(CTEXTEDIT_format_background)
+
+ if (READ_PROPERTY)
+ GB.ReturnInteger(WIDGET->textBackgroundColor().rgb() & 0xFFFFFF);
+ else
+ WIDGET->setTextBackgroundColor(QColor((QRgb)VPROP(GB_INTEGER)));
+
+END_PROPERTY
+
+/***************************************************************************/
+
+GB_DESC CTextEditFormatDesc[] =
+{
+ GB_DECLARE(".TextEdit.Format", 0), GB_VIRTUAL_CLASS(),
+
+ GB_PROPERTY("Alignment", "i", CTEXTEDIT_format_alignment),
+ //GB_PROPERTY("Position", "i", CTEXTEDIT_format_position),
+ GB_PROPERTY("Font", "Font", CTEXTEDIT_format_font),
+ GB_PROPERTY("Color", "i", CTEXTEDIT_format_color),
+ GB_PROPERTY("Background", "i", CTEXTEDIT_format_background),
+
+ GB_END_DECLARE
+};
+
+GB_DESC CTextEditSelectionDesc[] =
+{
+ GB_DECLARE(".TextEdit.Selection", 0), GB_VIRTUAL_CLASS(),
+
+ GB_PROPERTY("Text", "s", CTEXTEDIT_sel_text),
+ GB_PROPERTY("RichText", "s", CTEXTEDIT_sel_rich_text),
+ GB_PROPERTY_READ("Length", "i", CTEXTEDIT_sel_length),
+ GB_PROPERTY_READ("Start", "i", CTEXTEDIT_sel_start),
+ GB_METHOD("Hide", NULL, CTEXTEDIT_sel_clear, NULL),
+
+ GB_END_DECLARE
+};
+
+GB_DESC CTextEditDesc[] =
+{
+ GB_DECLARE("TextEdit", sizeof(CTEXTEDIT)), GB_INHERITS("Control"),
+
+ GB_METHOD("_new", NULL, CTEXTEDIT_new, "(Parent)Container;"),
+
+ //GB_CONSTANT("Normal", "i", QTextEdit::AlignNormal),
+ //GB_CONSTANT("SubScript", "i", QTextEdit::AlignSubScript),
+ //GB_CONSTANT("SuperScript", "i", QTextEdit::AlignSuperScript),
+
+ GB_PROPERTY("ReadOnly", "b", CTEXTEDIT_read_only),
+
+ GB_METHOD("Clear", NULL, CTEXTEDIT_clear, NULL),
+
+ GB_PROPERTY("Text", "s", CTEXTEDIT_text),
+ GB_PROPERTY("RichText", "s", CTEXTEDIT_rich_text),
+ GB_METHOD("Insert", NULL, CTEXTEDIT_insert, "(Text)s"),
+
+ GB_PROPERTY("Paragraph", "i", CTEXTEDIT_line),
+ GB_PROPERTY("Index", "i", CTEXTEDIT_column),
+ GB_PROPERTY("Pos", "i", CTEXTEDIT_pos),
+ //GB_PROPERTY_READ("Line", "i", CTEXTEDIT_line),
+
+ GB_METHOD("ToPos", "i", CTEXTEDIT_to_pos, "(Paragraph)i(Index)i"),
+ GB_METHOD("ToParagraph", "i", CTEXTEDIT_to_line, "(Pos)i"),
+ GB_METHOD("ToIndex", "i", CTEXTEDIT_to_col, "(Pos)i"),
+
+ GB_METHOD("EnsureVisible", NULL, CTEXTEDIT_ensure_visible, NULL),
+
+ GB_PROPERTY_SELF("Selection", ".TextEdit.Selection"),
+ GB_METHOD("Select", NULL, CTEXTEDIT_sel_select, "[(Start)i(Length)i]"),
+ GB_METHOD("SelectAll", NULL, CTEXTEDIT_sel_all, NULL),
+ GB_METHOD("Unselect", NULL, CTEXTEDIT_sel_clear, NULL),
+ GB_PROPERTY_READ("Selected", "b", CTEXTEDIT_selected),
+
+ GB_METHOD("Copy", NULL, CTEXTEDIT_copy, NULL),
+ GB_METHOD("Cut", NULL, CTEXTEDIT_cut, NULL),
+ GB_METHOD("Paste", NULL, CTEXTEDIT_paste, NULL),
+ GB_METHOD("Undo", NULL, CTEXTEDIT_undo, NULL),
+ GB_METHOD("Redo", NULL, CTEXTEDIT_redo, NULL),
+
+ GB_PROPERTY("Border", "b", CTEXTEDIT_border),
+ GB_PROPERTY("ScrollBar", "i", CWIDGET_scrollbar),
+ GB_PROPERTY("Wrap", "b", CTEXTEDIT_wrap),
+
+ GB_PROPERTY("ScrollX", "i", CTEXTEDIT_scroll_x),
+ GB_PROPERTY("ScrollY", "i", CTEXTEDIT_scroll_y),
+
+ GB_PROPERTY_READ("TextWidth", "i", CTEXTEDIT_text_width),
+ GB_PROPERTY_READ("TextHeight", "i", CTEXTEDIT_text_height),
+
+ GB_PROPERTY_SELF("Format", ".TextEdit.Format"),
+
+ GB_EVENT("Change", NULL, NULL, &EVENT_Change),
+ GB_EVENT("Cursor", NULL, NULL, &EVENT_Cursor),
+ //GB_EVENT("Link", NULL, "(Path)s", &EVENT_Link),
+
+ TEXTEDIT_DESCRIPTION,
+
+ GB_END_DECLARE
+};
+
+
+/** CTextEdit **************************************************************/
+
+CTextEdit CTextEdit::manager;
+
+void CTextEdit::changed(void)
+{
+ GET_SENDER();
+ GB.Raise(THIS, EVENT_Change, 0);
+}
+
+void CTextEdit::cursor(void)
+{
+ GET_SENDER();
+ GB.Raise(THIS, EVENT_Cursor, 0);
+}
+
+#if 0
+void CTEXTEDIT::link(const QString &path)
+{
+ void *_object = QT.GetObject((QWidget *)sender());
+
+ //THIS_EDIT->change = false;
+
+ GB.Raise(_object, EVENT_Link, 1,
+ GB_T_STRING, TO_UTF8(path), 0);
+
+ /*if (!THIS_EDIT->change)
+ {
+ // This cancels the click on the link (see qt source code)
+ WIDGET->setSource(WIDGET->source());
+ }*/
+}
+#endif
diff --git a/gb.qt5/src/CTextEdit.h b/gb.qt5/src/CTextEdit.h
new file mode 100644
index 0000000..a5ffd44
--- /dev/null
+++ b/gb.qt5/src/CTextEdit.h
@@ -0,0 +1,85 @@
+/***************************************************************************
+
+ CTextEdit.h
+
+ (c) 2000-2013 Benoît Minisini <gambas at users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+
+***************************************************************************/
+
+#ifndef __CTEXTEDIT_H
+#define __CTEXTEDIT_H
+
+#include "gambas.h"
+#include "CWidget.h"
+#include <QTextEdit>
+
+#ifndef __CTEXTEDIT_CPP
+extern GB_DESC CTextEditSelectionDesc[];
+extern GB_DESC CTextEditFormatDesc[];
+extern GB_DESC CTextEditDesc[];
+#else
+
+#define WIDGET ((QTextEdit *)((CWIDGET *)_object)->widget)
+#define MYTEXTEDIT ((MyTextEdit *)((CWIDGET *)_object)->widget)
+#define THIS ((CTEXTEDIT *)_object)
+
+#endif
+
+typedef
+ struct {
+ CWIDGET widget;
+ int length;
+ bool change;
+ }
+ CTEXTEDIT;
+
+class MyTextEdit: public QTextEdit
+{
+ Q_OBJECT
+
+public:
+ MyTextEdit(QWidget *parent = 0);
+ ~MyTextEdit();
+
+signals:
+ //void highlighted(const QString&);
+ void linkClicked(const QString&);
+
+private:
+ //void popupDetail( const QString& contents, const QPoint& pos );
+ bool linksEnabled() const { return true; }
+ //void emitHighlighted( const QString &s );
+ void emitLinkClicked( const QString &s );
+};
+
+class CTextEdit : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ static CTextEdit manager;
+
+public slots:
+
+ void changed(void);
+ void cursor(void);
+ //void link(const QString &);
+};
+
+#endif
More information about the User
mailing list