GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit 1cd8bd90 authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Rework Design property management so that it works better.

[GB.GTK]
* NEW: Rework Design property management so that it works better.
* OPT: Cache font metrics to speed up some font properties.

[GB.GTK3]
* NEW: Rework Design property management so that it works better.
* OPT: Cache font metrics to speed up some font properties.

[GB.QT4]
* NEW: Rework Design property management so that it works better.

[GB.QT5]
* NEW: Rework Design property management so that it works better.
parent bc2b5946
Pipeline #215415004 passed with stage
in 23 minutes and 54 seconds
......@@ -376,8 +376,7 @@ BEGIN_METHOD(UserControl_new, GB_OBJECT parent)
InitControl(new gPanel(CONTAINER(VARG(parent))), (CWIDGET*)THIS);
PANEL->setArrange(ARRANGE_FILL);
PANEL->setUser(true);
PANEL->setUser();
THIS_UC->container = THIS;
END_METHOD
......
......@@ -502,7 +502,15 @@ BEGIN_PROPERTY(CWIDGET_design)
if (READ_PROPERTY)
GB.ReturnBoolean(CONTROL->isDesign());
else
CONTROL->setDesign(VPROP(GB_BOOLEAN));
{
bool v = VPROP(GB_BOOLEAN);
if (v == CONTROL->isDesign())
return;
if (v)
CONTROL->setDesign();
else
GB.Error("Design property cannot be reset");
}
END_PROPERTY
......
......@@ -568,6 +568,7 @@ __FOUND_WIDGET:
}
save_control = find_child(control, (int)event->button.x_root, (int)event->button.y_root, button_grab);
save_control = save_control->ignoreDesign();
//fprintf(stderr, "save_control = %p %s\n", save_control, save_control ? save_control->name() : "");
if (!save_control)
......@@ -582,8 +583,6 @@ __FOUND_WIDGET:
goto __HANDLE_EVENT;
}
while (save_control->isDesignIgnore())
save_control = save_control->parent();
control = save_control;
bool menu = false;
......@@ -599,8 +598,8 @@ __FOUND_WIDGET:
gApplication::setButtonGrab(control);
}
if (event->type == GDK_BUTTON_PRESS)
gMouse::handleClickCount(event);
if (event->type == GDK_BUTTON_PRESS)
gMouse::handleClickCount(event);
__BUTTON_TRY_PROXY:
......@@ -719,8 +718,9 @@ __FOUND_WIDGET:
if (!control)
goto __HANDLE_EVENT;
while (control->isDesignIgnore())
control = control->parent();
control = control->ignoreDesign();
/*while (control->isDesignIgnore())
control = control->parent();*/
//fprintf(stderr, "GDK_MOTION_NOTIFY: (%p %s) grab = %p\n", control, control->name(), button_grab);
gApplication::checkHoveredControl(control);
......@@ -780,8 +780,9 @@ __FOUND_WIDGET:
if (!control)
goto __HANDLE_EVENT;
while (control->isDesignIgnore())
control = control->parent();
control = control->ignoreDesign();
/*while (control->isDesignIgnore())
control = control->parent();*/
__SCROLL_TRY_PROXY:
......
......@@ -395,13 +395,14 @@ void gContainer::setAutoResize(bool vl)
}
}
void gContainer::setUser(bool vl)
void gContainer::setUser()
{
if (vl != arrangement.user)
{
arrangement.user = vl;
performArrange();
}
if (arrangement.user)
return;
arrangement.user = true;
performArrange();
updateDesignChildren();
}
void gContainer::setInvert(bool vl)
......@@ -613,6 +614,9 @@ void gContainer::insert(gControl *child, bool realize)
if (hasForeground() && !child->_fg_set) child->setForeground();
#endif
child->updateFont();
if ((isUser() && isDesign()) || isDesignIgnore())
child->setDesign(true);
}
void gContainer::remove(gControl *child)
......@@ -850,29 +854,38 @@ void gContainer::clear()
}
}
void gContainer::setDesignRecursive()
void gContainer::updateDesignChildren()
{
int i;
gControl *child;
gContainer *proxy = proxyContainer();
gContainer *cont;
for (i = 0;; i++)
{
child = proxy->child(i);
if (!child)
break;
child->setDesignIgnore();
if (child->isContainer())
((gContainer *)child)->setDesignRecursive();
}
if (!isDesign())
return;
if (!isUser() && !isDesignIgnore())
return;
cont = isDesignIgnore() ? this : proxyContainer();
for (i = 0; i < cont->childCount(); i++)
cont->child(i)->setDesign(true);
}
void gContainer::setDesign(bool vl)
void gContainer::setDesign(bool ignore)
{
if (!vl || !isUser())
if (isDesign())
return;
gControl::setDesign(true);
setDesignRecursive();
gControl::setDesign(ignore);
updateDesignChildren();
}
void gContainer::setProxyContainer(gContainer *proxy)
{
if (_proxyContainer != this)
_proxyContainer = proxy;
else
_proxyContainer = NULL;
updateDesignChildren();
}
......@@ -67,7 +67,7 @@ public:
virtual int containerHeight();
void setArrange(int vl);
void setUser(bool vl);
void setUser();
void setAutoResize(bool vl);
void setPadding(int vl);
void setSpacing(bool vl);
......@@ -110,16 +110,16 @@ public:
virtual void setVisible(bool vl);
gContainer *proxyContainer() { return _proxyContainer ? _proxyContainer : this; }
void setProxyContainer(gContainer *proxy) { if (_proxyContainer != this) _proxyContainer = proxy; else _proxyContainer = NULL; }
void setProxyContainer(gContainer *proxy);
gContainer *proxyContainerFor() { return _proxyContainerFor; }
void setProxyContainerFor(gContainer *proxy) { if (proxy != this) _proxyContainerFor = proxy; else _proxyContainerFor = NULL; }
virtual void setDesign(bool ignore = false);
void disableArrangement();
void enableArrangement();
bool isArrangementEnabled() const { return _no_arrangement == 0; }
virtual void setDesign(bool vl);
//"Signals"
void (*onArrange)(gContainer *sender);
void (*onBeforeArrange)(gContainer *sender);
......@@ -142,7 +142,7 @@ public:
private:
void initialize();
void setDesignRecursive();
void updateDesignChildren();
gContainerArrangement arrangement;
gContainer *_proxyContainer;
......
......@@ -1142,23 +1142,32 @@ void gControl::afterRefresh()
{
}
void gControl::setDesign(bool vl)
void gControl::setDesign(bool ignore)
{
if (vl && !_design)
{
fprintf(stderr, "setDesign: %s\n", name());
setCanFocus(false);
setMouse(GDK_LEFT_PTR);
setTooltip(NULL);
_design = vl;
}
if (_design)
return;
//fprintf(stderr, "setDesign: %s %d\n", name(), ignore);
setCanFocus(false);
setMouse(GDK_LEFT_PTR);
setTooltip(NULL);
_design = true;
_design_ignore = ignore;
}
void gControl::setDesignIgnore()
gControl *gControl::ignoreDesign()
{
setDesign(true);
fprintf(stderr, "setDesignIgnore: %s\n", name());
_design_ignore = true;
//fprintf(stderr, "ignoreDesign: %s", name());
if (!isDesignIgnore())
return this;
gControl *ctrl = this;
while (ctrl && ctrl->isDesignIgnore())
ctrl = ctrl->parent();
//fprintf(stderr, " --> %s\n", ctrl->name());
return ctrl;
}
bool gControl::canFocus() const
......@@ -2821,3 +2830,4 @@ gControl *gControl::previousFocus()
return ctrl;
}
......@@ -90,8 +90,10 @@ public:
void setCursor(gCursor *vl);
void setAcceptDrops(bool vl);
virtual void setDesign(bool vl);
void setDesignIgnore();
virtual void setDesign(bool ignore = false);
gControl *ignoreDesign();
virtual void setEnabled(bool vl);
void setExpand (bool vl);
void setIgnore (bool vl);
......@@ -277,7 +279,6 @@ public:
unsigned _no_auto_grab : 1; // do not automatically grab widget on button press event
unsigned _no_background : 1; // Don't draw the background automatically
unsigned _use_wheel : 1; // Do not propagate the mouse wheel event
unsigned _user_control : 1; // If the control is a UserControl
unsigned _is_container : 1; // I am a container
unsigned _is_window : 1; // I am a window
unsigned _is_button : 1; // I am a button
......
......@@ -236,12 +236,33 @@ void gFont::realize()
{
ct = NULL;
_height = 0;
_metrics = NULL;
reset();
_nfont++;
}
PangoFontMetrics *gFont::metrics()
{
if (!_metrics)
{
PangoFontDescription *desc = pango_context_get_font_description(ct);
_metrics = pango_context_get_metrics(ct, desc, NULL);
}
return _metrics;
}
void gFont::invalidateMetrics()
{
if (_metrics)
{
pango_font_metrics_unref(_metrics);
_metrics = NULL;
}
}
void gFont::initFlags()
{
gFont *comp = new gFont();
......@@ -368,28 +389,17 @@ gFont::~gFont()
int gFont::ascent()
{
PangoFontDescription *desc = pango_context_get_font_description(ct);
PangoFontMetrics *metric = pango_context_get_metrics(ct,desc,NULL);
//fprintf(stderr, "ascent: %d\n", pango_font_metrics_get_ascent(metric));
return gt_pango_to_pixel(pango_font_metrics_get_ascent(metric));
return gt_pango_to_pixel(pango_font_metrics_get_ascent(metrics()));
}
float gFont::ascentF()
{
PangoFontDescription *desc = pango_context_get_font_description(ct);
PangoFontMetrics *metric = pango_context_get_metrics(ct,desc,NULL);
return (float)pango_font_metrics_get_ascent(metric) / PANGO_SCALE;
return (float)pango_font_metrics_get_ascent(metrics()) / PANGO_SCALE;
}
int gFont::descent()
{
PangoFontDescription *desc = pango_context_get_font_description(ct);
PangoFontMetrics *metric = pango_context_get_metrics(ct,desc,NULL);
//fprintf(stderr, "descent: %d\n", pango_font_metrics_get_descent(metric));
return gt_pango_to_pixel(pango_font_metrics_get_descent(metric));
return gt_pango_to_pixel(pango_font_metrics_get_descent(metrics()));
}
bool gFont::bold()
......@@ -411,6 +421,7 @@ void gFont::setBold(bool vl)
pango_font_description_set_weight(desc,PANGO_WEIGHT_NORMAL);
_bold_set = true;
invalidateMetrics();
}
bool gFont::italic()
......@@ -430,6 +441,7 @@ void gFont::setItalic(bool vl)
pango_font_description_set_style(desc,PANGO_STYLE_NORMAL);
_italic_set = true;
invalidateMetrics();
}
char* gFont::name()
......@@ -447,6 +459,7 @@ void gFont::setName(char *nm)
_name_set = true;
_height = 0;
invalidateMetrics();
checkMustFixSpacing();
}
......@@ -475,6 +488,7 @@ void gFont::setSize(double sz)
_size_set = true;
_height = 0;
invalidateMetrics();
}
void gFont::setGrade(int grade)
......
......@@ -95,7 +95,7 @@ public:
unsigned _size_set : 1;
unsigned _strikeout_set : 1;
unsigned _underline_set : 1;
private:
bool uline;
......@@ -104,7 +104,10 @@ private:
void realize();
void initFlags();
void checkMustFixSpacing();
PangoFontMetrics *metrics();
void invalidateMetrics();
PangoFontMetrics *_metrics;
int _height;
unsigned _must_fix_spacing : 1;
};
......
......@@ -1079,7 +1079,6 @@ const char *gTextArea::getStyleSheetColorNode()
void gTextArea::customStyleSheet(GString *)
{
fprintf(stderr, "customStyleSheet: %d\n", font()->mustFixSpacing());
gtk_text_view_set_pixels_inside_wrap(GTK_TEXT_VIEW(widget), font()->mustFixSpacing());
gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(widget), font()->mustFixSpacing());
......
......@@ -584,8 +584,6 @@ void FUNCTION_NAME(void *_object) //(QFrame *cont)
case ARRANGE_FILL:
w = h = 0;
for(;;)
{
wid = GET_NEXT_CHILD_WIDGET();
......@@ -598,13 +596,16 @@ void FUNCTION_NAME(void *_object) //(QFrame *cont)
MOVE_RESIZE_WIDGET(ob, wid, xc, yc, wc, hc);
if (GET_WIDGET_H(wid) > h)
/*if (GET_WIDGET_H(wid) > h)
h = GET_WIDGET_H(wid);
if (GET_WIDGET_W(wid) > w)
w = GET_WIDGET_W(wid);
w = GET_WIDGET_W(wid);*/
}
w = wc;
h = hc;
break;
}
......@@ -662,10 +663,7 @@ void FUNCTION_NAME(void *_object) //(QFrame *cont)
break;
case ARRANGE_FILL:
// #ifndef QNAMESPACE_H
// if (strncmp(((gControl *)_object)->name(), "DataControl", 11) == 0)
// fprintf(stderr, "%s: RESIZE_CONTAINER(%p, %p, %d, %d)\n", ((gControl *)_object)->name(), GET_WIDGET(_object), cont, w, h);
// #endif
//fprintf(stderr, "%s: RESIZE_CONTAINER(%p, %p, %d, %d)\n", GET_OBJECT_NAME(_object), GET_WIDGET(_object), cont, w + padding * 2, h + padding * 2);
RESIZE_CONTAINER(_object, cont, w + padding * 2, h + padding * 2);
break;
}
......
......@@ -510,7 +510,7 @@ void MyPushButton::calcMinimumSize()
CBUTTON *_object = (CBUTTON *)CWidget::getReal(this);
QSize size;
if (!THIS || CWIDGET_test_flag(THIS, WF_DESIGN_LEADER))
if (!THIS || CWIDGET_is_design(THIS)) //CWIDGET_test_flag(THIS, WF_DESIGN_LEADER))
return;
if (text().length() > 0)
......@@ -572,7 +572,7 @@ void MyToolButton::calcMinimumSize()
CBUTTON *_object = (CBUTTON *)CWidget::get(this);
QSize size;
if (!THIS || CWIDGET_test_flag(THIS, WF_DESIGN))
if (!THIS || CWIDGET_is_design(THIS))
return;
if (text().length() > 0)
......
......@@ -51,7 +51,7 @@ void MyCheckBox::adjust(bool force)
bool a;
QSize hint;
if (!THIS || (!_autoResize && !force) || CWIDGET_test_flag(THIS, WF_DESIGN) || text().length() <= 0)
if (!THIS || (!_autoResize && !force) || CWIDGET_is_design(THIS) || text().length() <= 0)
return;
a = _autoResize;
......
......@@ -472,7 +472,10 @@ void CCONTAINER_insert_child(void *_object)
{
CWIDGET *parent = CWidget::get(WIDGET->parentWidget());
if (parent)
{
CCONTAINER_update_design(parent);
GB.Raise(parent, EVENT_Insert, 1, GB_T_OBJECT, THIS);
}
}
void CCONTAINER_decide(CWIDGET *control, bool *width, bool *height)
......@@ -495,6 +498,42 @@ void CCONTAINER_decide(CWIDGET *control, bool *width, bool *height)
*height = TRUE;
}
void CCONTAINER_update_design(void *_object)
{
QObjectList list;
CWIDGET *child;
int i;
if (!THIS->widget.flag.design)
return;
if (!THIS_ARRANGEMENT->user && !THIS->widget.flag.design_ignore)
return;
//fprintf(stderr, "CCONTAINER_update_design: %s %d\n", THIS->widget.name, THIS->widget.flag.design_ignore);
if (THIS->widget.flag.design_ignore)
{
list = THIS->widget.widget->children();
for (i = 0; i < list.count(); i++)
{
child = CWidget::getRealExisting(list.at(i));
if (child)
CWIDGET_set_design(child, true);
}
}
list = CONTAINER->children();
for (i = 0; i < list.count(); i++)
{
child = CWidget::getRealExisting(list.at(i));
if (child)
CWIDGET_set_design(child, true);
}
}
/***************************************************************************
......@@ -1121,6 +1160,7 @@ BEGIN_PROPERTY(UserControl_Container)
if (current)
CWIDGET_container_for(current, NULL);
THIS->container = WIDGET;
CCONTAINER_update_design(THIS);
CWIDGET_register_proxy(THIS, NULL);
return;
}
......@@ -1151,10 +1191,11 @@ BEGIN_PROPERTY(UserControl_Container)
THIS->container = w;
CWIDGET_update_design((CWIDGET *)THIS);
CCONTAINER_arrange(THIS);
CWIDGET_set_color((CWIDGET *)cont, bg, fg, true);
CCONTAINER_update_design(THIS);
CWIDGET_register_proxy(THIS, cont);
}
......
......@@ -126,6 +126,8 @@ void CCONTAINER_draw_border_without_widget(QPainter *p, char border, QStyleOptio
void CCONTAINER_set_border(char *border, char new_border, QWidget *wid);
int CCONTAINER_get_border_width(char border);
void CCONTAINER_update_design(void *_object);
class MyFrame : public QWidget
{
Q_OBJECT
......
......@@ -259,7 +259,7 @@ void MyLabel::calcMinimumHeight(bool adjust)
{
void *_object = CWidget::getReal(this);
if (!THIS || (!autoResize && !adjust) || CWIDGET_test_flag(THIS, WF_DESIGN) || text().length() <= 0)
if (!THIS || (!autoResize && !adjust) || CWIDGET_is_design(THIS) || text().length() <= 0)
return;
//qDebug("calcMinimumHeight: %p %s", ob, ((CWIDGET *)ob)->name);
......
......@@ -54,7 +54,7 @@ void MyRadioButton::adjust(bool force)
bool a;
QSize hint;
if (!THIS || (!_autoResize && !force) || CWIDGET_test_flag(THIS, WF_DESIGN) || text().length() <= 0)
if (!THIS || (!_autoResize && !force) || CWIDGET_is_design(THIS) || text().length() <= 0)
return;
a = _autoResize;
......
......@@ -457,7 +457,7 @@ static void combo_set_editable(void *_object, bool ed)
QObject::connect(COMBOBOX->lineEdit(), SIGNAL(returnPressed()), &CTextBox::manager, SLOT(onActivate()));
//QObject::connect(COMBOBOX->lineEdit(), SIGNAL(selectionChanged()), &CTextBox::manager, SLOT(onSelectionChanged()));
if (CWIDGET_test_flag(THIS, WF_DESIGN))
if (CWIDGET_is_design(THIS))
{
get(_object, &textbox);
//textbox->removeEventFilter(COMBOBOX);
......@@ -478,7 +478,7 @@ static void combo_set_editable(void *_object, bool ed)
if (hasFocus)
COMBOBOX->setFocus();
if (CWIDGET_test_flag(THIS, WF_DESIGN))
if (CWIDGET_is_design(THIS))
COMBOBOX->setFocusPolicy(Qt::NoFocus);
COMBOBOX->blockSignals(false);
......
......@@ -138,7 +138,7 @@ static void set_mouse(QWidget *w, int mouse, void *cursor)
}
}
static void set_design_object(CWIDGET *_object)
/*static void set_design_object(CWIDGET *_object)
{
if (CWIDGET_test_flag(THIS, WF_DESIGN))
return;
......@@ -170,33 +170,30 @@ static void set_design_recursive(QWidget *w, bool set = false)
if (child->isWidgetType())