Change icon on button in scout eclipse - image

I would like to implement some think like toggle button in scout eclipse.
What I need is to change image of button for state.
I see function
setIconId(String)
but I dont know how to find parameter for this function. How to find image that scout use for different state of button?
Marko

setIconId(..) and Icons
It is a good practice in your Scout Application to pass as Argument from setIconId(..) a constant defined in the Icons Class. See Icons page on the wiki.
An example for your use case:
setIconId(Icons.WeatherSun)
In the Demo Widget Application there is an Icons class:
org.eclipsescout.demo.widgets.shared.Icons
Here some constants defined in this class:
public static final String WeatherRain = "weather_rain";
public static final String WeatherSnow = "weather_snow";
public static final String WeatherSun = "weather_sun";
The values defined in the constants represent an identifier for the image.
The Image lookup is realized by the ImageLocator. (Depending on the UI technology, the appropriate IconLocator will be used. For example, in case of Swing the SwingIconLocator implementation).
In case of weather_sun the default implementation of the ImageLocator will look for a File called weather_sun.<ext> (where <ext> can be gif, png and so on) in the \resources\icons\ folder of each plugins. In this case it will find the File: \org.eclipsescout.demo.widgets.client\resources\icons\weather_sun.png
If the image is not found, you will see a log entry like this:
!MESSAGE org.eclipse.scout.rt.ui.swing.SwingIconLocator.warnImageNotFound(SwingIconLocator.java:141) could not find image 'weather_sun'
In the Scout SDK, there is an Icons Editor. This Editor represents all the constants defined in the Icons class and the corresponding Icon. Is a file not found a red square is displayed instead of the image.
Toggle Button
There is no specific field for Toggle Button, use an AbstractButton an set the display style to DISPLAY_STYLE_TOGGLE.
See also:
10.8 - Buttons and Links in the Scout Boook.
ToggleButton wiki page.
Changing the icon in a Toogle Button
I think this code snippet does what you are looking for:
#Order(10)
public class ToggleButton1 extends AbstractButton {
#Override
protected boolean getConfiguredProcessButton() {
return false;
}
#Override
protected void execClickAction() throws ProcessingException {
if (isSelected()) {
setIconId(Icons.WeatherSun);
}
else {
setIconId(Icons.WeatherRain);
}
}
}
It would also be possible (and even better) to use execToggleAction instead of execClickAction.
Screenshot:

Related

VisualStudio customize paste operation for my component at design-time

I created WinForm component and I want to replace some properties of my component when developer copy and then paste(not when copy but when paste) component from clipboard at design time.
VisualStudio creates new copy of component and assign properties so it became copy of the source component.
I need to replace some properties on paste operation depending on the selected component.
It is very similar to standard Copy/Paste operation with Control component. When designer change Parent of component if developer select other container (like Panel) before Paste Control.
I think that code to perform it should be somewhere in my ComponentDesigner class.
I explored ComponentDesigner methods but can't find any methods that controls clipboard operations.
You can override the OnParentChanged method of your component, which is executed when the component is pasted onto the form. Then test the DesignMode property to make sure you are in design mode:
public class MyComponent : Label
{
protected override void OnParentChanged(EventArgs e)
{
if (DesignMode) {
// Change properties as desired.
Text = "Design";
}
base.OnParentChanged(e);
}
}
When the component is dropped from the Toolbox, this code is not executed. (I can't explain why, but it happens to be exactly what we need.)
If you derived your component from System.ComponentModel.Component, you can override the property Site; however, this will require some more logic to check whether the component has been pasted.
public override ISite Site
{
get {
return base.Site;
}
set {
base.Site = value;
if (value?.Container is IDesignerHost dh &&
dh.TransactionDescription == "Paste components") {
MessageBox.Show("Pasted");
}
}
}
But probably the transaction description is localized, because it is the text that you see in the drop-down of the Undo button on the toolbar of Visual Studio after having pasted the component.

How to programmatically associate a style to a button in Xamarin?

In my Xamarin app, I create a button (Xamarin.Forms.Button) programmatically. I need this button to show a different background image under normal vs hovered state. I have created a style resource similar to what is described at How to indicate currently selected control in Xamarin?. However, I cannot figure out how to apply this style to the button.
The Button class exposes a property called Image that is of FileImageSource type. The closest API I found to load my style resource is ImageSource.FromResource static method. However, this method seems to return StreamImageSource instance which is not what we need.
Class Button does not seem to provide any Style property.
Can you please suggest how I can programmatically associate a style to the button? Regards.
To achieve this request you need custom renderers.
To be able to apply your style f.e.: "myButtonStyle.xml" you have to create a custom renderer for your target platform:
Android:
[assembly: ExportRenderer (typeof (YourExtendedButtonClass), typeof (MyCustomButtonRenderer))]
namespace YourApp.Droid
{
public class MyCustomButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
var myButton = this.Control as Android.Widget.Button;
myButton?.SetBackgroundResource(Resource.Drawable.myButtonStyle);
}
}
}

Telerik UI For WinForms RadMessageBox font size

Is there a way to increase the default font size of the RadMessageBox for the whole application without having to create a custom theme?
If not, how to just increase the font on the default theme in Visual Style Builder? I tried just increasing the label and button font sizes, but the style builder reset the whole form that hosts the message box to look very plain and cutting the text of the label (see attached screenshot).
Thank you.
It is possible to customize the font for all RadMessageBoxes within an application.
Implement a method ('SetTelerikControlStyles') which is called before any form and/or RadMessageBox is created. You only need to call this method once!
Add the following lines of code in the created method of step 1:
RadMessageBox.Instance.FormElement.TitleBar.Font = new Font("Calibri", 25f);
RadMessageBox.Instance.Controls["radLabel1"].Font = new Font("Calibri", 50f, FontStyle.Regular);
The FormElement.TitleBar.Font, as the name already reveals, is the title bar of the RadMessageBox.
Telerik is using dynamic named controls, so in this case radLabel1 represents the RadMessageBox text area.
Complete Program.cs sample:
using System;
using System.Drawing;
using System.Windows.Forms;
using Telerik.WinControls;
namespace WindowsFormsApplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SetTelerikControlStyles();
Application.Run(new Form1());
}
private static void SetTelerikControlStyles()
{
RadMessageBox.Instance.FormElement.TitleBar.Font = new Font("Calibri", 25f);
// I added this additional check for safety, if Telerik modifies the name of the control.
if (RadMessageBox.Instance.Controls.ContainsKey("radLabel1"))
{
RadMessageBox.Instance.Controls["radLabel1"].Font = new Font("Calibri", 50f, FontStyle.Regular);
}
}
}
}

Xamarin forms background image for all Pages

It´s possible to set an image to be the background of all Pages on my application (for all platforms IOS, Android and WP) ?
Page has a BackgroundImage property, so I can create a base page, set the background and make all my pages extends from it.
I want to know if there is a more appropriate solution, to handle this.
You could use Styles in your App.cs :
public App ()
{
Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(Page)){
Setters = {
new Xamarin.Forms.Setter { Property = Page.BackgroundImageProperty, Value = "back.png"},
}
});
}
much less preferred or advised but for the sake of showing another option you could attach an event handler to your NavigationPages and set the background from there:
yourRootNavigationPage.Pushed+= (sender, e) => e.Page.BackgroundImage = "back.png";

Qt TableView - How to show image, when mouse hover?

I've got table view that is reading from SQL Database in one of my Qt project. It contains names column, and column that store the path of some image. How i can show the image like a ToolTip, when i do hover with the mouse on some of the image paths? I 've activated the mouse tracking, but i really don't know how to use it. If you can please provide some example. Than you a lot in advance.
The view's model should respond to Qt::TooltipRole and return the tooltip's content. It can contain HTML tags, including img tag that displays an image:
class Model : public QAbstractTableModel {
public:
//...
QVariant data(const QModelIndex &index, int role) const {
if (role == Qt::ToolTipRole) {
// find path for specified index
return QString("<img src='%1'>").arg(path);
}
//...
}
If you're using a built-in model class such as QSqlRelationalTableModel, you can create a subclass of that class and reimplement data function.

Resources