Commit cc6df8cb authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added functionality to show icons inside a multi selection. Added some sample icons.

parent 00734d51
......@@ -42,11 +42,12 @@ WItemSelection::~WItemSelection()
// cleanup
}
void WItemSelection::addItem( std::string name, std::string description )
void WItemSelection::addItem( std::string name, std::string description, const char** icon )
{
if ( m_modifyable )
{
m_items.push_back( Item( name, description ) );
Item i = { name, description, icon }; // NOLINT <-- initialize the struct this way is far more comfortable
m_items.push_back( i );
}
else
{
......
......@@ -29,6 +29,7 @@
#include <string>
#include <utility>
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
......@@ -45,9 +46,26 @@ class WItemSelection: public boost::enable_shared_from_this< WItemSelection >
{
public:
/**
* For shortening, it is the type of an item
* For shortening, it is the type of an item.
*/
typedef std::pair< std::string, std::string > Item;
typedef struct
{
/**
* Name
*/
std::string name;
/**
* Description, can be empty.
*/
std::string description;
/**
* Icon shown in the item selection box. Can be NULL.
*/
const char** icon;
}
Item;
/**
* Default constructor.
......@@ -64,8 +82,9 @@ public:
*
* \param name the name
* \param description the description
* \param icon an icon to show together with this item. Useful to illustrate the selection options.
*/
virtual void addItem( std::string name, std::string description );
virtual void addItem( std::string name, std::string description, const char** icon = NULL );
/**
* Creates an default selection (all items selected). After the first call of this function, no more items can be added using \ref addItem.
......
......@@ -51,13 +51,14 @@ WPropertySelectionWidget::WPropertySelectionWidget( WPropSelection property, QGr
// Lists are used if the selection of multiple elements is allowed
if ( m_selectionProperty->countConstraint( PC_SELECTONLYONE ) != 0 )
{
// TODO(all): how to show the icon inside a combobox?
m_combo = new QComboBox( &m_parameterWidgets );
// add all items from the selection set:
WItemSelector s = m_selectionProperty->get();
for ( size_t i = 0; i < s.sizeAll(); ++i )
{
m_combo->addItem( QString::fromStdString( s.atAll( i ).first ) );
m_combo->addItem( QString::fromStdString( s.atAll( i ).name ) );
}
// layout
......@@ -79,9 +80,23 @@ WPropertySelectionWidget::WPropertySelectionWidget( WPropSelection property, QGr
QWidget* widget = new QWidget( m_list );
QGridLayout* layoutWidget = new QGridLayout();
int column = 0;
// if there is an icon -> show it
if ( s.atAll( i ).icon )
{
QLabel* icon = new QLabel();
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ); // <-- scale it down
icon->setSizePolicy( sizePolicy );
icon->setPixmap( QPixmap( s.atAll( i ).icon ) );
layoutWidget->addWidget( icon, 0, 0, 2, 1 );
++column;
}
// Add Name and Description
layoutWidget->addWidget( new QLabel( "<b>" + QString::fromStdString( s.atAll( i ).first )+ "</b>" ), 0, 0 );
layoutWidget->addWidget( new QLabel( QString::fromStdString( s.atAll( i ).second ) ), 1, 0 );
layoutWidget->addWidget( new QLabel( "<b>" + QString::fromStdString( s.atAll( i ).name )+ "</b>" ), 0, column );
layoutWidget->addWidget( new QLabel( QString::fromStdString( s.atAll( i ).description ) ), 1, column );
layoutWidget->setSizeConstraint( QLayout::SetMaximumSize );
widget->setLayout( layoutWidget );
......
......@@ -64,6 +64,9 @@
#include "../../graphicsEngine/WGEUtils.h"
#include "template.xpm"
#include "icons/bier.xpm"
#include "icons/wurst.xpm"
#include "icons/steak.xpm"
#include "WMTemplate.h"
WMTemplate::WMTemplate():
......@@ -222,9 +225,9 @@ void WMTemplate::properties()
// algorithms to run on some data and you want the user to select which one should do the work. This might be done with integer properties but it
// is simply ugly. Therefore, properties of type WPropSelection are available. First you need to define a list of alternatives:
m_possibleSelections = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_possibleSelections->addItem( "Beer", "Cold and fresh." );
m_possibleSelections->addItem( "Steaks", "Medium please" );
m_possibleSelections->addItem( "Sausages", "With Sauerkraut" );
m_possibleSelections->addItem( "Beer", "Cold and fresh.", template_bier_xpm ); // NOTE: you can add XPM images here.
m_possibleSelections->addItem( "Steaks", "Medium please", template_steak_xpm );
m_possibleSelections->addItem( "Sausages", "With Sauerkraut", template_wurst_xpm );
// This list of alternatives is NOT the actual property value. It is the list on which so called "WItemSelector" instances work. These
// selectors are the actual property. After you created the first selector instance from the list, it can't be modified anymore. This ensures
......@@ -586,13 +589,13 @@ void WMTemplate::moduleMain()
// The single selector allows only one selected item and requires one item to be selected all the time. So accessing it by index
// is trivial:
WItemSelector s = m_aSingleSelection->get( true );
infoLog() << "The user likes " << s.at( 0 ).first << " the most.";
infoLog() << "The user likes " << s.at( 0 ).name << " the most.";
// The multi property allows the selection of several items. So, iteration needs to be done here:
s = m_aMultiSelection->get( true );
for ( size_t i = 0; i < s.size(); ++i )
{
infoLog() << "The user likes " << s.at( i ).first;
infoLog() << "The user likes " << s.at( i ).name;
}
}
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment