* ./hurricane/src/hviewer :

- New: In PaletteWidget: allow to select the number of rows of the grid
        widget (up to "infinite", meaning one column). Allow to hide entire
        groups in the widget.
This commit is contained in:
Jean-Paul Chaput 2009-04-21 11:41:10 +00:00
parent 4b8f79bc29
commit 609772dcc3
5 changed files with 178 additions and 62 deletions

View File

@ -136,7 +136,10 @@ namespace Hurricane {
: ControllerTab(parent) : ControllerTab(parent)
, _palette (new PaletteWidget()) , _palette (new PaletteWidget())
{ {
//_palette->setOneColumn ();
_palette->setObjectName ( "controller.tabPalette.palette" ); _palette->setObjectName ( "controller.tabPalette.palette" );
_palette->build ();
//_palette->setSectionVisible ( "Viewer", false );
QVBoxLayout* wLayout = new QVBoxLayout (); QVBoxLayout* wLayout = new QVBoxLayout ();
wLayout->setContentsMargins ( 0, 0, 0, 0 ); wLayout->setContentsMargins ( 0, 0, 0, 0 );

View File

@ -63,7 +63,7 @@ namespace Hurricane {
_selectable->setFixedWidth ( 23 ); _selectable->setFixedWidth ( 23 );
_selectable->setChecked ( true ); _selectable->setChecked ( true );
_selectable->setStyleSheet ( "QCheckBox { background-color: red;" _selectable->setStyleSheet ( "QCheckBox { background-color: red;"
" padding: 5px }" ); " padding: 2px 3px 2px 3px }" );
layout->addWidget ( _selectable ); layout->addWidget ( _selectable );
layout->addWidget ( _visible ); layout->addWidget ( _visible );

View File

@ -23,18 +23,25 @@
// x-----------------------------------------------------------------x // x-----------------------------------------------------------------x
# include <QCheckBox> #include <sstream>
# include <QHBoxLayout> #include <iomanip>
# include "hurricane/BasicLayer.h" #include <QCheckBox>
#include <QHBoxLayout>
# include "hurricane/viewer/Graphics.h" #include "hurricane/BasicLayer.h"
# include "hurricane/viewer/PaletteLayerItem.h"
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/PaletteLayerItem.h"
namespace Hurricane { namespace Hurricane {
using std::ostringstream;
using std::setw;
PaletteLayerItem::PaletteLayerItem ( BasicLayer* basicLayer, bool visible ) PaletteLayerItem::PaletteLayerItem ( BasicLayer* basicLayer, bool visible )
: PaletteItem() : PaletteItem()
, _basicLayer(basicLayer) , _basicLayer(basicLayer)
@ -47,14 +54,20 @@ namespace Hurricane {
layout->addWidget ( _sample ); layout->addWidget ( _sample );
ostringstream label;
label << setw(12) << left << getName();
_visible->setChecked ( visible ); _visible->setChecked ( visible );
_visible->setText ( getString(getName()).c_str() ); _visible->setText ( label.str().c_str() );
_visible->setFont ( Graphics::getFixedFont() ); _visible->setFont ( Graphics::getFixedFont() );
_selectable->setFixedWidth ( 23 ); _selectable->setFixedWidth ( 23 );
_selectable->setChecked ( true ); _selectable->setChecked ( true );
_selectable->setStyleSheet ( "QCheckBox { background-color: red;" _selectable->setStyleSheet ( "QCheckBox { background-color: red;"
" padding: 5px }" ); " padding: 2px 3px 2px 3px; }" );
//_selectable->setStyleSheet ( "QCheckBox::indicator {"
// " border: 2px solid red;"
// "}"
// );
layout->addWidget ( _selectable ); layout->addWidget ( _selectable );
//layout->addSpacing ( -15 ); //layout->addSpacing ( -15 );

View File

@ -23,6 +23,8 @@
// x-----------------------------------------------------------------x // x-----------------------------------------------------------------x
#include <limits>
#include <QLabel> #include <QLabel>
#include <QCheckBox> #include <QCheckBox>
#include <QPushButton> #include <QPushButton>
@ -54,7 +56,7 @@ namespace {
class GridBuffer { class GridBuffer {
public: public:
GridBuffer ( QGridLayout*, int rowMax, int startRow=0, int startColumn=0 ); GridBuffer ( QGridLayout*, size_t rowMax, size_t startRow=0, size_t startColumn=0 );
inline int getRow () const; inline int getRow () const;
inline int getColumn () const; inline int getColumn () const;
inline int getCurrentRow () const; inline int getCurrentRow () const;
@ -65,21 +67,21 @@ namespace {
inline bool columnOverload () const; inline bool columnOverload () const;
protected: protected:
QGridLayout* _grid; QGridLayout* _grid;
int _rowMax; size_t _rowMax;
int _row; size_t _row;
int _column; size_t _column;
vector<QWidget*> _widgets; vector<QWidget*> _widgets;
vector<Qt::Alignment> _aligns; vector<Qt::Alignment> _aligns;
}; };
GridBuffer::GridBuffer ( QGridLayout* grid, int maxRow, int startRow, int startColumn ) GridBuffer::GridBuffer ( QGridLayout* grid, size_t maxRow, size_t startRow, size_t startColumn )
: _grid(grid) : _grid (grid)
, _rowMax(maxRow) , _rowMax (maxRow)
, _row(startRow) , _row (startRow)
, _column(startColumn) , _column (startColumn)
, _widgets() , _widgets()
, _aligns() , _aligns ()
{ } { }
@ -167,15 +169,17 @@ namespace Hurricane {
} }
PaletteWidget::PaletteWidget ( QWidget* parent ) : QScrollArea(parent) PaletteWidget::PaletteWidget ( QWidget* parent )
, _layerItems() : QScrollArea (parent)
, _extensionGoItems() , _layerItems ()
, _showAll(new QPushButton(this)) , _extensionGoItems()
, _hideAll(new QPushButton(this)) , _showAll (new QPushButton(this))
, _grid(new QGridLayout()) , _hideAll (new QPushButton(this))
, _extensionRow(0) , _grid (new QGridLayout())
, _extensionColumn(0) , _columnHeight (22)
, _extensionGroup(NULL) , _extensionRow (0)
, _extensionColumn (0)
, _extensionGroup (NULL)
{ {
setWidgetResizable ( true ); setWidgetResizable ( true );
QVBoxLayout* vLayout = new QVBoxLayout (); QVBoxLayout* vLayout = new QVBoxLayout ();
@ -191,9 +195,9 @@ namespace Hurricane {
connect ( _hideAll, SIGNAL(clicked()), this, SLOT(hideAll()) ); connect ( _hideAll, SIGNAL(clicked()), this, SLOT(hideAll()) );
hLayout->addStretch (); hLayout->addStretch ();
hLayout->addWidget ( _showAll ); hLayout->addWidget ( _showAll );
hLayout->addStretch (); hLayout->addStretch ();
hLayout->addWidget ( _hideAll ); hLayout->addWidget ( _hideAll );
hLayout->addStretch (); hLayout->addStretch ();
QFrame* separator = new QFrame (); QFrame* separator = new QFrame ();
@ -201,16 +205,30 @@ namespace Hurricane {
separator->setFrameShadow ( QFrame::Sunken ); separator->setFrameShadow ( QFrame::Sunken );
vLayout->setSpacing ( 0 ); vLayout->setSpacing ( 0 );
vLayout->addLayout ( hLayout ); vLayout->addLayout ( hLayout );
vLayout->addWidget ( separator ); vLayout->addWidget ( separator );
vLayout->addSpacing ( 5 ); vLayout->addSpacing ( 5 );
vLayout->addLayout ( _grid ); vLayout->addLayout ( _grid );
GridBuffer gridBuffer ( _grid, 22 );
_grid->setHorizontalSpacing ( 10 ); _grid->setHorizontalSpacing ( 10 );
_grid->setVerticalSpacing ( 0 ); _grid->setVerticalSpacing ( 0 );
//_grid->setSizeConstraint ( QLayout::SetFixedSize ); //_grid->setSizeConstraint ( QLayout::SetFixedSize );
vLayout->addStretch ();
QWidget* adaptator = new QWidget ();
adaptator->setLayout ( vLayout );
setWidget ( adaptator );
setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
setVerticalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
setFrameStyle ( QFrame::Plain );
}
void PaletteWidget::build ()
{
GridBuffer gridBuffer ( _grid, _columnHeight );
size_t gi = 0; size_t gi = 0;
const vector<DrawingGroup*>& groups = Graphics::getStyle()->getDrawingGroups(); const vector<DrawingGroup*>& groups = Graphics::getStyle()->getDrawingGroups();
const vector<DrawingStyle*>& styles = groups[gi]->getDrawingStyles(); const vector<DrawingStyle*>& styles = groups[gi]->getDrawingStyles();
@ -228,7 +246,10 @@ namespace Hurricane {
gridBuffer.addWidget ( item ); gridBuffer.addWidget ( item );
_layerItems [ item->getName() ] = item; _layerItems [ item->getName() ] = item;
} }
gridBuffer.newColumn (); if ( _columnHeight < numeric_limits<size_t>::max() )
gridBuffer.newColumn ();
else
gridBuffer.flushWidgets ();
DataBase* database = DataBase::getDB(); DataBase* database = DataBase::getDB();
if ( database ) { if ( database ) {
@ -268,21 +289,16 @@ namespace Hurricane {
} }
} }
gridBuffer.newColumn (); if ( _columnHeight < numeric_limits<size_t>::max() )
gridBuffer.newColumn ();
else
gridBuffer.flushWidgets ();
_extensionRow = gridBuffer.getRow(); _extensionRow = gridBuffer.getRow();
_extensionColumn = gridBuffer.getColumn(); _extensionColumn = gridBuffer.getColumn();
_extensionGroup = _createGroupItem ( "Extensions" ); _extensionGroup = _createGroupItem ( "Extensions" );
gridBuffer.addSection ( _extensionGroup, Qt::AlignHCenter ); gridBuffer.addSection ( _extensionGroup, Qt::AlignHCenter );
gridBuffer.flushWidgets (); gridBuffer.flushWidgets ();
vLayout->addStretch ();
QWidget* adaptator = new QWidget ();
adaptator->setLayout ( vLayout );
setWidget ( adaptator );
setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
setVerticalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
setFrameStyle ( QFrame::Plain );
} }
@ -300,7 +316,7 @@ namespace Hurricane {
_extensionGoItems.clear (); _extensionGoItems.clear ();
GridBuffer gridBuffer ( _grid, 22, _extensionRow, _extensionColumn ); GridBuffer gridBuffer ( _grid, _columnHeight, _extensionRow, _extensionColumn );
_extensionGroup = _createGroupItem ( "Extensions" ); _extensionGroup = _createGroupItem ( "Extensions" );
gridBuffer.addSection ( _extensionGroup, Qt::AlignHCenter ); gridBuffer.addSection ( _extensionGroup, Qt::AlignHCenter );
@ -315,6 +331,49 @@ namespace Hurricane {
} }
void PaletteWidget::_getSection ( const QString section, QLabel*& label, vector<PaletteItem*>& items ) const
{
label = NULL;
items.clear ();
bool found = false;
for ( int index=0 ; index < _grid->count() ; index++ ) {
QLayoutItem* item = _grid->itemAt ( index );
if ( !item ) continue;
QLabel* ilabel = dynamic_cast<QLabel*>(item->widget());
if ( ilabel ) {
if ( found ) break;
if ( ilabel->text() != section ) continue;
found = true;
label = ilabel;
} else if ( found ) {
PaletteItem* paletteItem = dynamic_cast<PaletteItem*>(item->widget());
if ( paletteItem ) items.push_back ( paletteItem );
}
}
}
void PaletteWidget::setSectionVisible ( const QString section, bool visible )
{
QLabel* label;
vector<PaletteItem*> items;
_getSection ( section, label, items );
if ( !label ) return;
if ( visible ) label->show ();
else label->hide ();
for ( size_t i=0 ; i<items.size() ; ++i ) {
if ( visible ) items[i]->show ();
else items[i]->hide ();
}
}
bool PaletteWidget::isDrawable ( const Name& name ) const bool PaletteWidget::isDrawable ( const Name& name ) const
{ {
PaletteItem* item = find ( name ); PaletteItem* item = find ( name );
@ -363,6 +422,32 @@ namespace Hurricane {
} }
void PaletteWidget::showSection ( const QString section )
{
QLabel* label;
vector<PaletteItem*> items;
_getSection ( section, label, items );
if ( !label ) return;
for ( size_t i=0 ; i<items.size() ; ++i )
items[i]->setItemVisible ( true );
}
void PaletteWidget::hideSection ( const QString section )
{
QLabel* label;
vector<PaletteItem*> items;
_getSection ( section, label, items );
if ( !label ) return;
for ( size_t i=0 ; i<items.size() ; ++i )
items[i]->setItemVisible ( false );
}
PaletteItem* PaletteWidget::find ( const Name& name ) const PaletteItem* PaletteWidget::find ( const Name& name ) const
{ {
PaletteItems::const_iterator iitem = _layerItems.find(name); PaletteItems::const_iterator iitem = _layerItems.find(name);

View File

@ -27,15 +27,17 @@
#define __HURRICANE_PALETTE_WIDGET__ #define __HURRICANE_PALETTE_WIDGET__
#include <map> #include <map>
#include <limits>
#include <QScrollArea> #include <QScrollArea>
#include "hurricane/Commons.h" #include "hurricane/Commons.h"
#include "hurricane/Name.h" #include "hurricane/Name.h"
class QCheckBox; class QLabel;
class QPushButton; class QCheckBox;
class QGridLayout; class QPushButton;
class QGridLayout;
namespace Hurricane { namespace Hurricane {
@ -58,18 +60,24 @@ namespace Hurricane {
public: public:
typedef map<const Name,PaletteItem*> PaletteItems; typedef map<const Name,PaletteItem*> PaletteItems;
public: public:
PaletteWidget ( QWidget* parent=NULL ); PaletteWidget ( QWidget* parent=NULL );
PaletteItem* find ( const Name& name ) const; PaletteItem* find ( const Name& name ) const;
bool isDrawable ( const Name& name ) const; bool isDrawable ( const Name& name ) const;
bool isSelectable ( const Name& name ) const; bool isSelectable ( const Name& name ) const;
inline void setOneColumn ();
inline void setColumnHeight ( size_t height=std::numeric_limits<size_t>::max() );
void build ();
signals: signals:
void paletteChanged (); void paletteChanged ();
public slots: public slots:
void updateExtensions ( Cell* cell ); void updateExtensions ( Cell* cell );
void showAll (); void showAll ();
void hideAll (); void hideAll ();
void changeStyle (); void hideSection ( const QString );
void setItemVisible ( const Name& name, bool visible ); void showSection ( const QString );
void setSectionVisible ( const QString, bool visible );
void changeStyle ();
void setItemVisible ( const Name& name, bool visible );
protected: protected:
PaletteItems _layerItems; PaletteItems _layerItems;
@ -77,21 +85,28 @@ namespace Hurricane {
QPushButton* _showAll; QPushButton* _showAll;
QPushButton* _hideAll; QPushButton* _hideAll;
QGridLayout* _grid; QGridLayout* _grid;
size_t _columnHeight;
int _extensionRow; int _extensionRow;
int _extensionColumn; int _extensionColumn;
QWidget* _extensionGroup; QWidget* _extensionGroup;
protected: private:
PaletteWidget ( const PaletteWidget& ); PaletteWidget ( const PaletteWidget& );
PaletteWidget& operator= ( const PaletteWidget& ); PaletteWidget& operator= ( const PaletteWidget& );
protected: private:
QWidget* _createGroupItem ( const Name& ); QWidget* _createGroupItem ( const Name& );
PaletteNamedItem* _createNamedItem ( const Name&, bool checked=true ); PaletteNamedItem* _createNamedItem ( const Name&, bool checked=true );
PaletteLayerItem* _createLayerItem ( BasicLayer*, bool checked=true ); PaletteLayerItem* _createLayerItem ( BasicLayer*, bool checked=true );
PaletteExtensionGoItem* _createExtensionGoItem ( const Name&, bool checked=true ); PaletteExtensionGoItem* _createExtensionGoItem ( const Name&, bool checked=true );
void _getSection ( const QString, QLabel*&, vector<PaletteItem*>& ) const;
}; };
// Inline Functions.
inline void PaletteWidget::setOneColumn () { setColumnHeight(std::numeric_limits<size_t>::max()); }
inline void PaletteWidget::setColumnHeight ( size_t height ) { _columnHeight = height; }
} // End of Hurricane namespace. } // End of Hurricane namespace.