Blue on Black

A forum for research and development of the user interface of FreeCAD

Moderator: agryson

vocx
Posts: 2693
Joined: Thu Oct 18, 2018 9:18 pm

Re: Blue on Black

Post by vocx » Thu Nov 14, 2019 5:21 pm

pablogil wrote:
Thu Nov 14, 2019 12:21 pm
It has to be hard coded because Qt doesn't have a hyperlink element so, we are stuck in the same point. We would need a programmer to locate the code of this "link" and tell us how to make it styleable...
This isn't so hard to locate, as we can just search for the entire string in the source code.

This is the result, src/Mod/Sketcher/Gui/ViewProviderSketch.cpp, lines 5837 to 5894.

It seems the colors are hard coded in the strings for "Over-constrained sketch", "Sketch contains conflicting constraints ", "Sketch contains redundant constraints", "Fully constrained sketch", "Under-constrained sketch with %1 degrees of freedom", "Solved in %1 sec", and "Unsolved in %1 sec".

Code: Select all

void ViewProviderSketch::UpdateSolverInformation()
{
    // Updates Solver Information with the Last solver execution at SketchObject level
    int dofs = getSketchObject()->getLastDoF();
    bool hasConflicts = getSketchObject()->getLastHasConflicts();
    bool hasRedundancies = getSketchObject()->getLastHasRedundancies();

    if (getSketchObject()->Geometry.getSize() == 0) {
        signalSetUp(tr("Empty sketch"));
        signalSolved(QString());
    }
    else if (dofs < 0) { // over-constrained sketch
        std::string msg;
        SketchObject::appendConflictMsg(getSketchObject()->getLastConflicting(), msg);
        signalSetUp(QString::fromLatin1("<font color='red'>%1<a href=\"#conflicting\"><span style=\" text-decoration: underline; color:#0000ff;\">%2</span></a><br/>%3</font><br/>")
                    .arg(tr("Over-constrained sketch "))
                    .arg(tr("(click to select)"))
                    .arg(QString::fromStdString(msg)));
        signalSolved(QString());
    }
    else if (hasConflicts) { // conflicting constraints
        signalSetUp(QString::fromLatin1("<font color='red'>%1<a href=\"#conflicting\"><span style=\" text-decoration: underline; color:#0000ff;\">%2</span></a><br/>%3</font><br/>")
                    .arg(tr("Sketch contains conflicting constraints "))
                    .arg(tr("(click to select)"))
                    .arg(appendConflictMsg(getSketchObject()->getLastConflicting())));
        signalSolved(QString());
    }
    else {
        if (hasRedundancies) { // redundant constraints
            signalSetUp(QString::fromLatin1("<font color='orangered'>%1<a href=\"#redundant\"><span style=\" text-decoration: underline; color:#0000ff;\">%2</span></a><br/>%3</font><br/>")
                        .arg(tr("Sketch contains redundant constraints "))
                        .arg(tr("(click to select)"))
                        .arg(appendRedundantMsg(getSketchObject()->getLastRedundant())));
        }
        if (getSketchObject()->getLastSolverStatus() == 0) {
            if (dofs == 0) {
                // color the sketch as fully constrained if it has geometry (other than the axes)
                if(getSketchObject()->getSolvedSketch().getGeometrySize()>2)
                    edit->FullyConstrained = true;

                if (!hasRedundancies) {
                    signalSetUp(QString::fromLatin1("<font color='green'>%1</font>").arg(tr("Fully constrained sketch")));
                }
            }
            else if (!hasRedundancies) {
                if (dofs == 1)
                    signalSetUp(tr("Under-constrained sketch with <a href=\"#dofs\"><span style=\" text-decoration: underline; color:#0000ff;\">1 degree</span></a> of freedom"));
                else
                    signalSetUp(tr("Under-constrained sketch with <a href=\"#dofs\"><span style=\" text-decoration: underline; color:#0000ff;\">%1 degrees</span></a> of freedom").arg(dofs));
            }

            signalSolved(QString::fromLatin1("<font color='green'>%1</font>").arg(tr("Solved in %1 sec").arg(getSketchObject()->getLastSolveTime())));
        }
        else {
            signalSolved(QString::fromLatin1("<font color='red'>%1</font>").arg(tr("Unsolved (%1 sec)").arg(getSketchObject()->getLastSolveTime())));
        }
    }
}
As you can see, the strings use fixed font properties, like

Code: Select all

<font color='red'>%1</font>
and

Code: Select all

<span style=\" text-decoration: underline; color:#0000ff;\">%1 degrees</span>
I'm not sure how the Qt styles are applied, but maybe you could prepare some styles for each of the cases above, "Under constrained", "Over constrained", "Conflicting constrains", etc. Those styles should blend well with your other style sheets.

Then maybe we can test the code with

Code: Select all

<font color=overconstrained_color>%1</font>

<span style=\" underconstrained_style;\">%1 degrees</span>
Something like that.
To support the documentation effort, and code development, your donation is appreciated: paypal.

pablogil
Posts: 799
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Blue on Black

Post by pablogil » Fri Nov 15, 2019 7:59 am

Thanks vocx, this is a step forward.

As I see, it's a QString which is not "stylesheet styleable" so it would be needed to:
  • turn them into QLabels
  • identify each "case" ("Under constrained", "Over constrained", "Conflicting constrains", etc) with an ID or name applied to the QLabel itself so that I can create a code like following in each stylesheet (besides the color selected for each "case" will be stylesheet independent):

Code: Select all

QLabel#overConstrained {
   color: red;
}
QLabel#onflictingConstrains {
   color: blue;
}
...
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here

vocx
Posts: 2693
Joined: Thu Oct 18, 2018 9:18 pm

Re: Blue on Black

Post by vocx » Sat Nov 16, 2019 10:18 pm

pablogil wrote:
Fri Nov 15, 2019 7:59 am
...
As I see, it's a QString which is not "stylesheet styleable" so it would be needed to:
...
Where did you read this? I don't say I'll commit to solving this problem, but it's good to have the information.
To support the documentation effort, and code development, your donation is appreciated: paypal.

User avatar
yorik
Site Admin
Posts: 11642
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Blue on Black

Post by yorik » Sun Nov 17, 2019 4:12 pm

About the link text, on KDE-based systems it's handled correctly by Qt from the desktop theme. The problem is on GTK-based systems, where Qt does a very dirty job of trying to emulate GTK theme colors (but as you can see "misses" some)

This works for me in a QSS file:

Code: Select all

/* links color */
a, a:link, QLabel:link, QTextBrowser:link { 
    color: #00A6FF; 
}

User avatar
yorik
Site Admin
Posts: 11642
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Blue on Black

Post by yorik » Sun Nov 17, 2019 4:13 pm

BTW this is my full QSS file currently, can be useful...

Code: Select all

/* Pressable toolbar buttons (snap buttons etc) */
QToolButton:checked, QPushButton:checked, QAction:checked {
    background-color: #888888;
    border: 1px solid #bbbbbb;
    border-radius: 2px;
}

/* Group header inside Property Editor */
Gui--PropertyEditor--PropertyEditor {
    qproperty-groupTextColor: #ffffff;
    qproperty-groupBackground: #404040;
}

/* links color */
a, a:link, QLabel:link, QTextBrowser:link { 
    color: #00A6FF; 
}

vocx
Posts: 2693
Joined: Thu Oct 18, 2018 9:18 pm

Re: Blue on Black

Post by vocx » Sun Nov 17, 2019 4:39 pm

yorik wrote:
Sun Nov 17, 2019 4:12 pm
About the link text, on KDE-based systems it's handled correctly by Qt from the desktop theme. The problem is on GTK-based systems, ...
Thank you, Yorik. But how would you style the other cases? It seems they are hard coded. For example, the following has a "green" font. Ideally, all these cases should be style-aware, not only the "a href".

Code: Select all

signalSolved(QString::fromLatin1("<font color='green'>%1</font>").arg(tr("Solved in %1 sec").arg(getSketchObject()->getLastSolveTime())));
To support the documentation effort, and code development, your donation is appreciated: paypal.

pablogil
Posts: 799
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Blue on Black

Post by pablogil » Sun Nov 17, 2019 10:13 pm

yorik wrote:
Sun Nov 17, 2019 4:12 pm
About the link text, on KDE-based systems it's handled correctly by Qt from the desktop theme. The problem is on GTK-based systems, where Qt does a very dirty job of trying to emulate GTK theme colors (but as you can see "misses" some)

This works for me in a QSS file:

Code: Select all

/* links color */
a, a:link, QLabel:link, QTextBrowser:link { 
    color: #00A6FF; 
}
Nice tip for styling links but, it doesn't work for the specific requested place: link of the remaining degrees of freedom under a sketch.

Maybe it is because I'm under macOS but I would guess that it's because it was used an HTML-CSS style with the QString and it's not styleable with stylesheets, you can only "hard code-style it". It would be nice to swap it into a QText, QLabel or similar so that you can add as suggested in the Qt style examples:
If we want the property to apply only to one specific QLineEdit, we can give it a name using QObject::setObjectName() and use an ID Selector to refer to it:
And use the following code in the .qss file (stylesheet):

Code: Select all

QLineEdit#nameEdit {
     background-color: yellow
}
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here

grooveman
Posts: 27
Joined: Fri Jul 05, 2019 3:29 pm

Re: Blue on Black

Post by grooveman » Wed Dec 04, 2019 11:27 am

yorik wrote:
Sun Nov 17, 2019 4:12 pm
About the link text, on KDE-based systems it's handled correctly by Qt from the desktop theme. The problem is on GTK-based systems, where Qt does a very dirty job of trying to emulate GTK theme colors (but as you can see "misses" some)

This works for me in a QSS file:

Code: Select all

/* links color */
a, a:link, QLabel:link, QTextBrowser:link { 
    color: #00A6FF; 
}
Unfortunately, I do use KDE, and this does not seem to affect that specific link at all. It is always blue. But, this thread is encouraging. It would be nice to include it amongst the options someday... or at least provide a class with which we can apply a style to it.

User avatar
yorik
Site Admin
Posts: 11642
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Blue on Black

Post by yorik » Thu Dec 05, 2019 9:55 pm

Links inside a widget are links. They should take the links color, and not need a separate setting for them.
Not sure what needs to be done to give a class to the sketcher degrees of freedom text?

pablogil
Posts: 799
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Blue on Black

Post by pablogil » Sat Dec 07, 2019 2:49 pm

yorik wrote:
Thu Dec 05, 2019 9:55 pm
Links inside a widget are links. They should take the links color, and not need a separate setting for them.
Not sure what needs to be done to give a class to the sketcher degrees of freedom text?
In macOS links don't work when styling them with the stylesheets...

As for the "class" to the sketcher DOF text I guess you should use QObject::setObjectName() to the QLabel so that you can access later with the following stylesheet code:

Code: Select all

QLabel#ObjectName {
     color: yellow;
}
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here

Post Reply