diff --git a/hurricane/src/hviewer/ControllerWidget.cpp b/hurricane/src/hviewer/ControllerWidget.cpp index 8b40d104..701b4eb9 100644 --- a/hurricane/src/hviewer/ControllerWidget.cpp +++ b/hurricane/src/hviewer/ControllerWidget.cpp @@ -136,7 +136,10 @@ namespace Hurricane { : ControllerTab(parent) , _palette (new PaletteWidget()) { + //_palette->setOneColumn (); _palette->setObjectName ( "controller.tabPalette.palette" ); + _palette->build (); + //_palette->setSectionVisible ( "Viewer", false ); QVBoxLayout* wLayout = new QVBoxLayout (); wLayout->setContentsMargins ( 0, 0, 0, 0 ); diff --git a/hurricane/src/hviewer/PaletteExtensionGoItem.cpp b/hurricane/src/hviewer/PaletteExtensionGoItem.cpp index 61568e17..d172549c 100644 --- a/hurricane/src/hviewer/PaletteExtensionGoItem.cpp +++ b/hurricane/src/hviewer/PaletteExtensionGoItem.cpp @@ -63,7 +63,7 @@ namespace Hurricane { _selectable->setFixedWidth ( 23 ); _selectable->setChecked ( true ); _selectable->setStyleSheet ( "QCheckBox { background-color: red;" - " padding: 5px }" ); + " padding: 2px 3px 2px 3px }" ); layout->addWidget ( _selectable ); layout->addWidget ( _visible ); diff --git a/hurricane/src/hviewer/PaletteLayerItem.cpp b/hurricane/src/hviewer/PaletteLayerItem.cpp index 40d2a2b2..7d477192 100644 --- a/hurricane/src/hviewer/PaletteLayerItem.cpp +++ b/hurricane/src/hviewer/PaletteLayerItem.cpp @@ -23,18 +23,25 @@ // x-----------------------------------------------------------------x -# include -# include +#include +#include -# include "hurricane/BasicLayer.h" +#include +#include -# include "hurricane/viewer/Graphics.h" -# include "hurricane/viewer/PaletteLayerItem.h" +#include "hurricane/BasicLayer.h" + +#include "hurricane/viewer/Graphics.h" +#include "hurricane/viewer/PaletteLayerItem.h" namespace Hurricane { + using std::ostringstream; + using std::setw; + + PaletteLayerItem::PaletteLayerItem ( BasicLayer* basicLayer, bool visible ) : PaletteItem() , _basicLayer(basicLayer) @@ -47,14 +54,20 @@ namespace Hurricane { layout->addWidget ( _sample ); + ostringstream label; + label << setw(12) << left << getName(); _visible->setChecked ( visible ); - _visible->setText ( getString(getName()).c_str() ); + _visible->setText ( label.str().c_str() ); _visible->setFont ( Graphics::getFixedFont() ); _selectable->setFixedWidth ( 23 ); - _selectable->setChecked ( true ); + _selectable->setChecked ( true ); _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->addSpacing ( -15 ); diff --git a/hurricane/src/hviewer/PaletteWidget.cpp b/hurricane/src/hviewer/PaletteWidget.cpp index 97124f1d..574c97d1 100644 --- a/hurricane/src/hviewer/PaletteWidget.cpp +++ b/hurricane/src/hviewer/PaletteWidget.cpp @@ -23,6 +23,8 @@ // x-----------------------------------------------------------------x +#include + #include #include #include @@ -54,7 +56,7 @@ namespace { class GridBuffer { 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 getColumn () const; inline int getCurrentRow () const; @@ -65,21 +67,21 @@ namespace { inline bool columnOverload () const; protected: QGridLayout* _grid; - int _rowMax; - int _row; - int _column; + size_t _rowMax; + size_t _row; + size_t _column; vector _widgets; vector _aligns; }; - GridBuffer::GridBuffer ( QGridLayout* grid, int maxRow, int startRow, int startColumn ) - : _grid(grid) - , _rowMax(maxRow) - , _row(startRow) - , _column(startColumn) + GridBuffer::GridBuffer ( QGridLayout* grid, size_t maxRow, size_t startRow, size_t startColumn ) + : _grid (grid) + , _rowMax (maxRow) + , _row (startRow) + , _column (startColumn) , _widgets() - , _aligns() + , _aligns () { } @@ -167,15 +169,17 @@ namespace Hurricane { } - PaletteWidget::PaletteWidget ( QWidget* parent ) : QScrollArea(parent) - , _layerItems() - , _extensionGoItems() - , _showAll(new QPushButton(this)) - , _hideAll(new QPushButton(this)) - , _grid(new QGridLayout()) - , _extensionRow(0) - , _extensionColumn(0) - , _extensionGroup(NULL) + PaletteWidget::PaletteWidget ( QWidget* parent ) + : QScrollArea (parent) + , _layerItems () + , _extensionGoItems() + , _showAll (new QPushButton(this)) + , _hideAll (new QPushButton(this)) + , _grid (new QGridLayout()) + , _columnHeight (22) + , _extensionRow (0) + , _extensionColumn (0) + , _extensionGroup (NULL) { setWidgetResizable ( true ); QVBoxLayout* vLayout = new QVBoxLayout (); @@ -191,9 +195,9 @@ namespace Hurricane { connect ( _hideAll, SIGNAL(clicked()), this, SLOT(hideAll()) ); hLayout->addStretch (); - hLayout->addWidget ( _showAll ); + hLayout->addWidget ( _showAll ); hLayout->addStretch (); - hLayout->addWidget ( _hideAll ); + hLayout->addWidget ( _hideAll ); hLayout->addStretch (); QFrame* separator = new QFrame (); @@ -201,16 +205,30 @@ namespace Hurricane { separator->setFrameShadow ( QFrame::Sunken ); vLayout->setSpacing ( 0 ); - vLayout->addLayout ( hLayout ); - vLayout->addWidget ( separator ); + vLayout->addLayout ( hLayout ); + vLayout->addWidget ( separator ); vLayout->addSpacing ( 5 ); - vLayout->addLayout ( _grid ); + vLayout->addLayout ( _grid ); - GridBuffer gridBuffer ( _grid, 22 ); _grid->setHorizontalSpacing ( 10 ); _grid->setVerticalSpacing ( 0 ); //_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; const vector& groups = Graphics::getStyle()->getDrawingGroups(); const vector& styles = groups[gi]->getDrawingStyles(); @@ -228,7 +246,10 @@ namespace Hurricane { gridBuffer.addWidget ( item ); _layerItems [ item->getName() ] = item; } - gridBuffer.newColumn (); + if ( _columnHeight < numeric_limits::max() ) + gridBuffer.newColumn (); + else + gridBuffer.flushWidgets (); DataBase* database = DataBase::getDB(); if ( database ) { @@ -268,21 +289,16 @@ namespace Hurricane { } } - gridBuffer.newColumn (); + if ( _columnHeight < numeric_limits::max() ) + gridBuffer.newColumn (); + else + gridBuffer.flushWidgets (); + _extensionRow = gridBuffer.getRow(); _extensionColumn = gridBuffer.getColumn(); _extensionGroup = _createGroupItem ( "Extensions" ); gridBuffer.addSection ( _extensionGroup, Qt::AlignHCenter ); 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 (); - GridBuffer gridBuffer ( _grid, 22, _extensionRow, _extensionColumn ); + GridBuffer gridBuffer ( _grid, _columnHeight, _extensionRow, _extensionColumn ); _extensionGroup = _createGroupItem ( "Extensions" ); gridBuffer.addSection ( _extensionGroup, Qt::AlignHCenter ); @@ -315,6 +331,49 @@ namespace Hurricane { } + void PaletteWidget::_getSection ( const QString section, QLabel*& label, vector& 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(item->widget()); + if ( ilabel ) { + if ( found ) break; + if ( ilabel->text() != section ) continue; + found = true; + + label = ilabel; + } else if ( found ) { + PaletteItem* paletteItem = dynamic_cast(item->widget()); + if ( paletteItem ) items.push_back ( paletteItem ); + } + } + } + + + void PaletteWidget::setSectionVisible ( const QString section, bool visible ) + { + QLabel* label; + vector items; + + _getSection ( section, label, items ); + if ( !label ) return; + + if ( visible ) label->show (); + else label->hide (); + + for ( size_t i=0 ; ishow (); + else items[i]->hide (); + } + } + + bool PaletteWidget::isDrawable ( const Name& name ) const { PaletteItem* item = find ( name ); @@ -363,6 +422,32 @@ namespace Hurricane { } + void PaletteWidget::showSection ( const QString section ) + { + QLabel* label; + vector items; + + _getSection ( section, label, items ); + if ( !label ) return; + + for ( size_t i=0 ; isetItemVisible ( true ); + } + + + void PaletteWidget::hideSection ( const QString section ) + { + QLabel* label; + vector items; + + _getSection ( section, label, items ); + if ( !label ) return; + + for ( size_t i=0 ; isetItemVisible ( false ); + } + + PaletteItem* PaletteWidget::find ( const Name& name ) const { PaletteItems::const_iterator iitem = _layerItems.find(name); diff --git a/hurricane/src/hviewer/hurricane/viewer/PaletteWidget.h b/hurricane/src/hviewer/hurricane/viewer/PaletteWidget.h index f7d89787..9223fd39 100644 --- a/hurricane/src/hviewer/hurricane/viewer/PaletteWidget.h +++ b/hurricane/src/hviewer/hurricane/viewer/PaletteWidget.h @@ -27,15 +27,17 @@ #define __HURRICANE_PALETTE_WIDGET__ #include +#include #include #include "hurricane/Commons.h" #include "hurricane/Name.h" - class QCheckBox; - class QPushButton; - class QGridLayout; +class QLabel; +class QCheckBox; +class QPushButton; +class QGridLayout; namespace Hurricane { @@ -58,18 +60,24 @@ namespace Hurricane { public: typedef map PaletteItems; public: - PaletteWidget ( QWidget* parent=NULL ); - PaletteItem* find ( const Name& name ) const; - bool isDrawable ( const Name& name ) const; - bool isSelectable ( const Name& name ) const; - signals: - void paletteChanged (); + PaletteWidget ( QWidget* parent=NULL ); + PaletteItem* find ( const Name& name ) const; + bool isDrawable ( const Name& name ) const; + bool isSelectable ( const Name& name ) const; + inline void setOneColumn (); + inline void setColumnHeight ( size_t height=std::numeric_limits::max() ); + void build (); + signals: + void paletteChanged (); public slots: - void updateExtensions ( Cell* cell ); - void showAll (); - void hideAll (); - void changeStyle (); - void setItemVisible ( const Name& name, bool visible ); + void updateExtensions ( Cell* cell ); + void showAll (); + void hideAll (); + void hideSection ( const QString ); + void showSection ( const QString ); + void setSectionVisible ( const QString, bool visible ); + void changeStyle (); + void setItemVisible ( const Name& name, bool visible ); protected: PaletteItems _layerItems; @@ -77,21 +85,28 @@ namespace Hurricane { QPushButton* _showAll; QPushButton* _hideAll; QGridLayout* _grid; + size_t _columnHeight; int _extensionRow; int _extensionColumn; QWidget* _extensionGroup; - protected: + private: PaletteWidget ( const PaletteWidget& ); PaletteWidget& operator= ( const PaletteWidget& ); - protected: + private: QWidget* _createGroupItem ( const Name& ); PaletteNamedItem* _createNamedItem ( const Name&, bool checked=true ); PaletteLayerItem* _createLayerItem ( BasicLayer*, bool checked=true ); PaletteExtensionGoItem* _createExtensionGoItem ( const Name&, bool checked=true ); + void _getSection ( const QString, QLabel*&, vector& ) const; }; +// Inline Functions. + inline void PaletteWidget::setOneColumn () { setColumnHeight(std::numeric_limits::max()); } + inline void PaletteWidget::setColumnHeight ( size_t height ) { _columnHeight = height; } + + } // End of Hurricane namespace.