TextArea: Setting background and foreground colors now should work correctly in all cases.

[GB.QT4]
* BUG: TextArea: Setting background and foreground colors now should work correctly in all cases.

[GB.QT5]
* BUG: TextArea: Setting background and foreground colors now should work correctly in all cases.
This commit is contained in:
gambas 2021-02-26 11:31:33 +01:00 committed by Christof Thalhofer
parent fcb0799e34
commit aa7c7733cc
4 changed files with 45 additions and 18 deletions

View file

@ -23,9 +23,8 @@
#define __CTEXTAREA_CPP
#include <qapplication.h>
#include <qpalette.h>
#include <QPlainTextEdit>
#include <QPalette>
#include <QTextEdit>
#include <QTextBlock>
#include <QTextDocumentFragment>
@ -59,6 +58,12 @@ static int get_length(void *_object)
return THIS->length;
}
static bool is_empty(void *_object)
{
QTextBlock block = WIDGET->document()->begin();
return !block.isValid();
}
static void to_pos(QTextEdit *wid, int par, int car, int *pos)
{
QTextCursor cursor;
@ -147,16 +152,27 @@ void CTEXTAREA_set_foreground(void *_object)
{
THIS->no_change = TRUE;
QTextCursor oldCursor = WIDGET->textCursor();
WIDGET->selectAll();
WIDGET->setTextColor(Qt::black);
set_text_color(THIS);
WIDGET->setTextCursor(oldCursor);
set_text_color(THIS);
if (is_empty(THIS))
{
WIDGET->setPlainText(" ");
WIDGET->selectAll();
WIDGET->setTextColor(Qt::black);
set_text_color(THIS);
WIDGET->textCursor().insertText("");
}
else
{
QTextCursor oldCursor = WIDGET->textCursor();
WIDGET->selectAll();
WIDGET->setTextColor(Qt::black);
set_text_color(THIS);
WIDGET->setTextCursor(oldCursor);
set_text_color(THIS);
}
THIS->no_change = FALSE;
}

View file

@ -1308,7 +1308,7 @@ void CWIDGET_reset_color(CWIDGET *_object)
bg = THIS_EXT->bg;
fg = THIS_EXT->fg;
if (qobject_cast<QComboBox *>(w))
if (GB.Is(THIS, CLASS_ComboBox))
{
//QComboBox *cb = (QComboBox *)w;
palette = QPalette();
@ -1333,18 +1333,28 @@ void CWIDGET_reset_color(CWIDGET *_object)
w->setPalette(palette);
}
/*else if (qobject_cast<QSpinBox *>(w))
else if (GB.Is(THIS, CLASS_TextArea))
{
palette = QPalette();
if (bg != COLOR_DEFAULT)
{
palette.setColor(QPalette::Base, TO_QCOLOR(bg));
palette.setColor(QPalette::Window, TO_QCOLOR(bg));
palette.setColor(QPalette::Button, TO_QCOLOR(bg));
}
if (fg != COLOR_DEFAULT)
{
palette.setColor(QPalette::Text, TO_QCOLOR(fg));
palette.setColor(QPalette::WindowText, TO_QCOLOR(fg));
palette.setColor(QPalette::ButtonText, TO_QCOLOR(fg));
}
w->setPalette(palette);
}*/
CTEXTAREA_set_foreground(THIS);
}
else
{
palette = QPalette();
@ -1383,8 +1393,6 @@ void CWIDGET_reset_color(CWIDGET *_object)
//w->setAutoFillBackground(THIS->bg != COLOR_DEFAULT);
if (GB.Is(THIS, CLASS_TextArea))
CTEXTAREA_set_foreground(THIS);
if (_after_set_color)
(*_after_set_color)(THIS);

View file

@ -144,6 +144,7 @@ GB_CLASS CLASS_Printer;
GB_CLASS CLASS_Image;
GB_CLASS CLASS_SvgImage;
GB_CLASS CLASS_TextArea;
GB_CLASS CLASS_ComboBox;
static bool in_event_loop = false;
static int _no_destroy = 0;
@ -1459,6 +1460,7 @@ int EXPORT GB_INIT(void)
CLASS_Image = GB.FindClass("Image");
CLASS_SvgImage = GB.FindClass("SvgImage");
CLASS_TextArea = GB.FindClass("TextArea");
CLASS_ComboBox = GB.FindClass("ComboBox");
QT_InitEventLoop();

View file

@ -76,6 +76,7 @@ extern GB_CLASS CLASS_Printer;
extern GB_CLASS CLASS_Image;
extern GB_CLASS CLASS_SvgImage;
extern GB_CLASS CLASS_TextArea;
extern GB_CLASS CLASS_ComboBox;
#endif