Qt5 custom widget - Curved slider - c++

I'm starting my next electronics project which is to create my own version of Google's Nest Thermostat. I like the whole circular dial for temperature selection and I've been having a think about how to create this myself. GUI programming is not my area of expertise (CLI all the way!).
So far I'm think along one of two lines, both involving custom widgets:
Create a widget that inherits from the pushbutton class. This subclass will contain lots of buttons, one for each step in the temperature scale, arranged in a 3/4 circle.
Create a widget that inherits from the slider class, defining an object that is curved around 3/4 of a circle. Each step is a temperature.
Now... I have no idea if these are practical solutions to this problem or if there is a much easier way of doing this. I've had a look at the style sheets and I don't THINK that is going to do it. I've had a root around Google for anything similar and not found anything yet; that said, AnalogWidgets from 3electrons at least creates dials, but these are for output rather than input.

I tried this out yesterday and it works rather nicely if you want to simulate the nest thermostat in an app this includes the js and SVG image:
https://www.svidget.io/examples/nestthermostat
HTML snippet:
<object id="nestThermostatWidget" role="svidget" data="nestThermostatWidget.svg" type="image/svg+xml" width="400" height="400">
<param name="targetTemp" value="77" />
<param name="ambientTemp" value="80" />
<param name="unit" value="F" />
<param name="state" value="cooling" />
<param name="showLeaf" value="1" />
<param name="awayMode" value="0" />
</object>

Related

How can I get an element from within a ListViewItem's ItemTemplate?

I have a ListView that uses a custom ItemTemplate (doesn't everyone?):
<ListView>
<!-- ... -->
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<MyGreatControl Thing="{x:Bind}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MyGreatControl today has extensive keyboard handling code built-in, but due to some refactoring, I need to move the actual handlers to the ListView itself. However, I don't want to move all of the code in MyGreatControl to the ListView (for many reasons).
If I have an arbitrary ListViewItem (which, for example, I can get from an event handler), how can I access the MyGreatControl instance in its DataTemplate?
MyGreatControl^ GetMyGreatControlFromListViewItem(ListViewItem^ listViewItem) {
// ???
}
Disclaimer: I work for Microsoft.
You want to use ContentTemplateRoot!
MyGreatControl^ GetMyGreatControlFromListViewItem(ListViewItem^ listViewItem) {
return safe_cast<MyGreatControl^>(listViewItem->ContentTemplateRoot);
}
This also works for any arbitrary element—if you have a StackPanel, for example, ContentTemplateRoot will return the StackPanel instance you want:
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<StackPanel><!-- This is what you get! -->
<TextBlock Text="{x:Bind}" />
<Button Content="Foo" IsTabStop="False" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
You can then use normal visual tree navigation to find Children, etc.

Add extended Scroller to extended spark List in Flex

I'm trying to add a custom Scroller.as (extended from spark.components.Scroller) to a InfiniteScrollList.as (extended from spark.components.list)
I wrote the following MXML code:
<list:InfiniteScrollList width="100%" height="100%" id="EventsList" useVirtualLayout="true">
<list:scroller>
<list:Scroller/> <!-- The Scroller.as Class -->
</list:scroller>
</list:InfiniteScrollList>
The List behavior works well but the extended Scroller component does not function at all.
What is the correct way to add this scroller functionality (in MXML or ActionScript) to the list?
The s:Scroller is used by wrapping it around the content or DataGroup. But the List class wraps all that functionality inside of it's skin, so I believe that in order to create a custom Scroller for a List, you actually need to do within the SkinClass.
<list:InfiniteScrollList width="100%" height="100%" id="EventsList"
useVirtualLayout="true" skinClass="MyListSkin" />
MyListSkin.mxml:
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minWidth="112">
<fx:Metadata>
[HostComponent("spark.components.Scroller")]
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
</s:states>
<!-- The Scroller.as Class -->
<list:Scroller left="0" top="0" right="0" bottom="0" id="scroller" hasFocusableChildren="false">
<!--- #copy spark.components.SkinnableDataContainer#dataGroup -->
<s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
<s:layout>
<!--- The default layout is vertical and measures at least for 5 rows.
When switching to a different layout, HorizontalLayout for example,
make sure to adjust the minWidth, minHeight sizes of the skin -->
<s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedMinRowCount="5" />
</s:layout>
</s:DataGroup>
</list:Scroller/>
</s:SparkSkin>

regex find word in string, replace word in new string (using Notepad++)

I posted a simplified version of this question before, but I think I might have simplified it too much, so here is the actual problem.
I want to use regex (in Notepad++ or similar) to find "a_dog" in the following (sorry about the wall):
<object classid="clsid:D27CDB6E-AE6D-11cf" id="FlashID">
<param name="movie" value="../flash/words/a_dog.swf">
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="6.0.65.0">
<!--[if !IE]>-->
<object data="../flash/words/a_dog.swf" type="application/x-shockwave-flash">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="6.0.65.0">
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
Then I want to use a back-reference to replace all instances of øø with a_dog in the following:
<input type="button" class="ButtonNormal" onClick="audio_func_øø()">
<script>
function audio_func_øø() {
var playAudio = document.getElementById("element_øø");
playAudio.play();
}
</script>
<audio id="element_øø">
<source src="../audio/words/øø.mp3" type='audio/mpeg'>
<source src="../audio/words/øø.wav" type='audio/wav'>
</audio>
So that only the second code is left (with a_dog instead of øø), and no trace of the first code remains.
I don't know how to do this in Notepad++, but you can do this in SublimeText using regex, snippets, and multiple selection:
First make a new snippet (guide) with the following in it:
<snippet>
<content><![CDATA[
<input type="button" class="ButtonNormal" onClick="audio_func_$1()">
<script>
function audio_func_$2() {
var playAudio = document.getElementById("element_$3");
playAudio.play();
}
</script>
<audio id="element_$4">
<source src="../audio/words/$5.mp3" type='audio/mpeg'>
<source src="../audio/words/$6.wav" type='audio/wav'>
</audio>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>audioSnippet</tabTrigger>
</snippet>
Save it as whatever you like in your User package. Follow the linked article if you have any questions on how/where to save it to get it working. I will discuss how this works later on.
Next use the following regex in Sublime Text by searching (with regex enabled) using the following pattern:
(?<=value="../flash/words/).+(?=\.swf)
And hit "Find All" - this will select all the names (e.g. 'a_dog', 'a_cat', 'a_plane') using multiple selection.
Copy the selected words (Ctrl+C or equivalent on your system)
In the menu, Selection->Expand to Paragraph (This will select where the <object> begins, to where </object> ends)
Hit Delete/Backspace to remove the <object>'s
Type in your snippet shortcut (above I've defined it to be "audioSnippet") and hit Tab
Paste in your copied text (Ctrl+V or equivalent on your system)
You will notice that you have only replaced the text in the snippet where the $1 appears. you will need to hit Tab to jump to $2, paste the text again (Ctrl+V), and repeat until you get to tab stop $6.
I've made a screen capture that you can look at here: http://youtu.be/oo2MQV3X244 (unlisted video on YouTube)

How do I change CFCHART title font?

I am using the WebCharts3D interface to create and modify charts, and then using the generated XML style as an in-line style in my Coldfusion code.
So this shows up correctly in the WebCharts3D:
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Double" style="Solid">
<title font="Arial-18-bold">
<decoration style="None"/>This is a title
</title>
</pieChart>
This simply shows the example title with no box around it, and set to the desired font size and weight. You can take this code, copy it into the WebCharts "XML Style" window, apply it, and see that it works.
I use this in my Coldfusion code like this:
<cfsavecontent variable="piecontent">
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Double" style="Solid">
<title font="Arial-18-bold">
<decoration style="None"/>This is a title
</title>
</pieChart>
</cfsavecontent>
<cfchart name="mychart" format="png"
style="#piecontent#">
<cfchartseries type= "pie">
<cfchartdata item="sample1" value="10">
<cfchartdata item="sample2" value="20">
</cfchartseries>
</cfchart>
The title correctly has "decoration" set to "none", because there is no box around it, but the title font size and weight is totally ignored. Is this a bug? Is there a workaround?
EDIT: It appears that this problem of ignored font size and weight is ALSO true for the overall font, like if you put this: <pieChart depth="Double" style="Solid" font="Arial-16-Bold">.
It seems like those particular settings are ignored in favor of the cfchart tag's font attributes. Try using those instead:
<cfchart format="png" font="Arial" fontBold="true" fontSize="18">
EDIT: While the above works with pie charts (only), it seems like another bug... What does work is interfacing with webcharts directly. It is more involved, but offers complete control over chart settings.
My experience, though I can't find any proof online other than my own testing, is that ColdFusion's implementation of Webcharts does not support styling the title.

cfchart tooltip popup format?

Would anyone know if it is possible to format the tooltip that displays when hovering over a ColdFusion chart (when the attribute tipStyle = "MouseOver" is set)?
I would like it to be formatted as a number style to include two decimal places, even if the value is 0 (ex: 0.00 instead of just 0). I believe this value ties into the axis data format as well, so if it would be at all possible to format the axis numbers, then it might carry over to the tooltip.
I had been thinking to try and override the javascript function call for the onmouseover event that is built into the cfchart tag, but I am not sure the name of this functionor how to go about doing that either. Any thoughts/suggestions would be great. Thanks.
You could customize the annotation (ie tooltip). Just specify a custom format ie ${value;##.00} to display two decimal places.
For a list of the supported variables see the webcharts3D utility help: Designer => Design => Elements =>Parameters.
<cfsavecontent variable="style"><?xml version="1.0" encoding="UTF-8"?>
<frameChart>
<frame xDepth="12" yDepth="11"/>
<yAxis scaleMin="0" />
<elements drawShadow="true">
<morph morph="Grow"/>
<![CDATA[
X Label = $(colLabel)
X Value = ${value;##.00}
]]>
</elements>
<decoration style="FrameTopBottom" foreColor="white"/>
<paint palette="Pastel" isVertical="true" min="47" max="83"/>
<insets right="5"/>
</frameChart></cfsavecontent>
<cfchart format="png" style="#style#">
<cfchartseries type="bar">
<cfchartdata item="Apple" value="50">
<cfchartdata item="Orange" value="76.8">
<cfchartdata item="Pear" value="100.634">
</cfchartseries>
</cfchart>
Just as a note I don't think you could intercept cfchart's onmouseover event in Javascript easily because cfchart uses Flash or static images, so you'd have to do some sort of funky ActionScript <-> Javascript wizardry to intercept the event.