I am currently adding support of QWebEngineWidgets to my older applications but I don't want to loose QWebKitWidgets. because in some embeded platforms the qt version is still 5.3. I wonder if the following solution I made by myself is correct and better solutions is also welcome.
equals(QT_MAJOR_VERSION, 5) {
lessThan(QT_MINOR_VERSION, 5) {
QT += webkitwidgets
}
greaterThan(QT_MINOR_VERSION, 4) {
QT += webenginewidgets
}
}
You can also use "else" for the alternative branch, e.g.
lessThan(QT_MINOR_VERSION, 5) {
} else {
}
or even check for a module's availability specifically
qtHaveModule(webengine) {
}
Related
Is there a way to enable/disable parts of a qss stylesheet per OS (platform). So that I can enable one font for MacOS, another for Windows.
I could set dynamic properties for a particular widget
this->setProperty("qsysKernelType", QSysInfo::kernelType());
this->setProperty("qsysCurrentCpuArchitecture", QSysInfo::currentCpuArchitecture());
this->setProperty("qsysBuildCpuArchitecture", QSysInfo::buildCpuArchitecture());
this->setProperty("qsysProductType", QSysInfo::productType());
but that only works with one widget, not the whole hierarchy.
I don't believe there is a standard simple way for this.
But you always can hold your CSS resources for different platforms in different files, and use ifdefs, to load it, like:
this->setStyleSheet(QFile(
#ifdef Q_OS_WIN
":/style/win.css"
#else // add more, if you need
":/style/mac.css"
#endif
).readAll());
Or simply use two hardcoded strings with ifdefs.
Actually we are now using a combintion of Youw's answer and the approach mentioned in the question.
For conditional qss checks we set the properties for a particular widget or widget tree.
void CStyleSheetUtility::setQSysInfoProperties(QWidget *widget, bool withChildWidgets)
{
Q_ASSERT_X(widget, Q_FUNC_INFO, "Missing widget");
if (!widget->property("qsysKernelType").isValid())
{
widget->setProperty("qsysKernelType", QSysInfo::kernelType());
widget->setProperty("qsysCurrentCpuArchitecture", QSysInfo::currentCpuArchitecture());
widget->setProperty("qsysBuildCpuArchitecture", QSysInfo::buildCpuArchitecture());
widget->setProperty("qsysProductType", QSysInfo::productType());
}
if (withChildWidgets)
{
for (QWidget *w : widget->findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly))
{
CStyleSheetUtility::setQSysInfoProperties(w, true);
}
}
}
I develop an application in JavaFX. Now i've got the Problem that i would like to generate an error at compile time if a css class, e.g. for a button, which if've set in the code doesn't exist in the corresponding css file.
Example:
main.java
String sCSS = this.getClass().getResource("/main.css").toExternalForm();
scene.getStylesheets().add(sCSS);
Button btn = new Button("Hello JFXWorld...");
btn.getStyleClass().add("button"); // should show compile time error
main.css
.buttonWithWrongName {
-fx-background-color: red; }
My solution would be the following, but I'm looking for advice how I can realize it.
I include an preprocessor or create an new project or something like that which parses the css code and dynamically generates an enum (into a .jar). And this jar i could include into my Project. In the best case ant would trigger the build of the enum automatically if no preprocessor is used.
again an Example:
Css file is the same as above.
{
Do preprocessor stuff for the css file here (parse and create enum) and build it to a jar file.
}
main.java
String sCSS = this.getClass().getResource("/main.css").toExternalForm();
scene.getStylesheets().add(sCSS);
Button btn = new Button("Hello JFXWorld...");
// will throw an compile time error becaus the eMainCSS enum only contains the class ".buttonWithWrongName"
btn.getStyleClass().add(eMainCSS.button.toString());
// works fine
btn.getStyleClass().add(eMainCSS.buttonWithWrongName.toString());
I'm using Eclipse (Neon) and JDK 1.8.0.
I hope there's a solution.
Thank you for the answers.
Best Regards,
Max S.
-- Edit --
Solution:
I've used an Ant WatchTask to watch at all my less files in the project.
If I change something in the less file, ant will run a self written jar file with the file name as parameter. The jar converts the less file to a css file (with less4j) and the css file to a java file (my own parser) which contains the enum.
Note: Youre not allowed to change anything in the enum. Even if you do, after the next changes in the less file, itll be gone.
The result looks like this:
Stylesheet.less:
.button { -fx-stroke-width: (1 + 1); }
#anotherButton { -fx-stroke-width: (1 + 2); }
to Stylesheet.css:
.button { -fx-stroke-width: 2; }
#anotherButton { -fx-stroke-width: 3; }
to Stylesheet.java:
// Auto-generated java file
public enum Stylesheet {
C_BUTTON("button"),
ID_ANOTHERBUTTON("anotherButton");
private final String sValue;
Stylesheet(String sValue) {
this.sValue = sValue;
}
#Override
public String toString() {
return this.sValue;
}
}
Now the compiler will throw an error at the compile time if the class or id which i'm using in javafx doesn`t exist.
Best Regards,
Max S.
I want to specify compiler switches for a certain directory only in premake.
Now AFAIR, I think I should have to use buildoption for the switches.
So I would await:
configuration { "vs2010" }
files { "mysubdir/**" }
buildoption { "/wd4244" }
Sadly this does not seem to work. Is this even possible with premake?
If you are using the latest development version of Premake, you can do it like this:
filter { "files:mysubdir/**" }
buildoptions { "/wd4244" }
I don't recall if per-file build options were supported in Premake 4.x, but if so it would work like this:
configuration { "mysubdir/**" }
buildoptions { "/wd4244" }
H I, Working with Less and here is what I am hoping :
.createClass() {
#varone:one;
#vartwo:two;
#classname: #{varone}_#{vartwo};
.testClass_#{classname} {
padding:.5em;
}
}
.createClass();
Things I have tried from a few searches :
#classname: '#{varone}_#{vartwo}';
But this renders as:
.testClass_'one_two' {
padding:.5em;
}
And I read about the tilder ~ ( but might be just for the phpless I found off a search ? )
#classname: ~'#{varone}_#{vartwo}';
didn't run.
I am running on node , compiling via the grunt less contrib
How do I render a 'unquoted string' in this way / is it possible ?
Many Thanks,
#classname: ~'#{varone}_#{vartwo}'; (or same with double quotes) is the correct syntax and works in all conformant Less compilers. I.e.:
.createClass() {
#varone: one;
#vartwo: two;
#classname: ~'#{varone}_#{vartwo}';
.testClass_#{classname} {
padding: .5em;
}
}
.createClass();
Ahh I found it.
http://lesscss.org/functions/#string-functions
Can use:
#classname: e(#{varone}_#{vartwo});
The e(str) filter does it
Bit more RTFM was needed from me !
Related to How do I add a .properties file into my WAR using gradle? but not quite:
I've got one project, call it 'webclient' that produces:
build/out/WEB-INF/deploy/foo
build/out/client/bar.js
build/out/clientDebug/baz.js
and then I've got a war project, call it 'server' that I'm trying to include the above into the a few different directories by doing:
war {
from files(project(':webclient').file('build/out/WEB-INF')) {
into('xxx')
}
from files(project(':webclient').file('build/out/client')) {
into('yyy')
}
from files(project(':webclient').file('build/out/clientDebug')) {
into('zzz')
}
}
...but that doesn't work. I end up with all the contents under zzz/ ! Am I doing something wrong? bug in gradle (1.0-m6, btw)?
I didn't digged deeper in the details, but the files() method seems to cause the problems here. The following workaround should do the trick for you:
war{
from (project(':shared').file('build/out/WEB-INF')) {
into('xxx')
}
from (project(':shared').file('build/out/client')) {
into('yyy')
}
from (project(':shared').file('build/out/clientDebug')) {
into('zzz')
}
}