QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer* vl, QWidget* parent, bool embedded )
    : QDialog( parent ), mAdvancedMenu( NULL ), mVectorLayer( vl )
{
  mStyle = style;
  mSymbol = symbol;

  setupUi( this );

  btnAdvanced->hide(); // advanced button is hidden by default

  // can be embedded in renderer properties dialog
  if ( embedded )
  {
    buttonBox->hide();
    layout()->setContentsMargins( 0, 0, 0, 0 );
  }

  connect( btnSymbolProperties, SIGNAL( clicked() ), this, SLOT( changeSymbolProperties() ) );
  connect( btnStyleManager, SIGNAL( clicked() ), SLOT( openStyleManager() ) );

  QStandardItemModel* model = new QStandardItemModel( viewSymbols );
  viewSymbols->setModel( model );
  connect( viewSymbols, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( setSymbolFromStyle( const QModelIndex & ) ) );
  lblSymbolName->setText( "" );
  populateSymbolView();
  updateSymbolPreview();
  updateSymbolInfo();

  if ( mSymbol )
  {
    // output unit
    mSymbolUnitComboBox->blockSignals( true );
    mSymbolUnitComboBox->setCurrentIndex( mSymbol->outputUnit() );
    mSymbolUnitComboBox->blockSignals( false );

    mTransparencySlider->blockSignals( true );
    double transparency = 1 - symbol->alpha();
    mTransparencySlider->setValue( transparency * 255 );
    displayTransparency( symbol->alpha() );
    mTransparencySlider->blockSignals( false );
  }

  // select correct page in stacked widget
  // there's a correspondence between symbol type number and page numbering => exploit it!
  stackedWidget->setCurrentIndex( symbol->type() );

  connect( btnColor, SIGNAL( clicked() ), this, SLOT( setSymbolColor() ) );
  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setMarkerAngle( double ) ) );
  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setMarkerSize( double ) ) );
  connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( setLineWidth( double ) ) );

  connect( btnAddToStyle, SIGNAL( clicked() ), this, SLOT( addSymbolToStyle() ) );
  btnSymbolProperties->setIcon( QIcon( QgsApplication::defaultThemePath() + "mActionOptions.png" ) );
  btnAddToStyle->setIcon( QIcon( QgsApplication::defaultThemePath() + "symbologyAdd.png" ) );
}
  {
    groupsCombo->addItem( group, QVariant( "smart" ) );
  }

  QStandardItemModel* model = new QStandardItemModel( viewSymbols );
  viewSymbols->setModel( model );
  connect( viewSymbols->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), this, SLOT( setSymbolFromStyle( const QModelIndex & ) ) );

  // Set the Style Menu under btnStyle
  QMenu *styleMenu = new QMenu( btnStyle );
  QAction *styleMgrAction = new QAction( "Style Manager", styleMenu );
  styleMenu->addAction( styleMgrAction );
  QAction *saveStyle = new QAction( "Save as style", styleMenu );
  styleMenu->addAction( saveStyle );
  connect( styleMgrAction, SIGNAL( triggered() ), this, SLOT( openStyleManager() ) );
  connect( saveStyle, SIGNAL( triggered() ), this, SLOT( addSymbolToStyle() ) );
  btnStyle->setMenu( styleMenu );

  lblSymbolName->setText( "" );
  populateSymbolView();

  if ( mSymbol )
  {
    // output unit
    mSymbolUnitComboBox->blockSignals( true );
    mSymbolUnitComboBox->setCurrentIndex( mSymbol->outputUnit() );
    mSymbolUnitComboBox->blockSignals( false );

    mTransparencySlider->blockSignals( true );
    double transparency = 1 - symbol->alpha();
    mTransparencySlider->setValue( transparency * 255 );