* ./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)
, _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 );

View File

@ -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 );

View File

@ -23,18 +23,25 @@
// x-----------------------------------------------------------------x
# include <QCheckBox>
# include <QHBoxLayout>
#include <sstream>
#include <iomanip>
# include "hurricane/BasicLayer.h"
#include <QCheckBox>
#include <QHBoxLayout>
# 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 );

View File

@ -23,6 +23,8 @@
// x-----------------------------------------------------------------x
#include <limits>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
@ -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<QWidget*> _widgets;
vector<Qt::Alignment> _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<DrawingGroup*>& groups = Graphics::getStyle()->getDrawingGroups();
const vector<DrawingStyle*>& styles = groups[gi]->getDrawingStyles();
@ -228,7 +246,10 @@ namespace Hurricane {
gridBuffer.addWidget ( item );
_layerItems [ item->getName() ] = item;
}
gridBuffer.newColumn ();
if ( _columnHeight < numeric_limits<size_t>::max() )
gridBuffer.newColumn ();
else
gridBuffer.flushWidgets ();
DataBase* database = DataBase::getDB();
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();
_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<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
{
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
{
PaletteItems::const_iterator iitem = _layerItems.find(name);

View File

@ -27,15 +27,17 @@
#define __HURRICANE_PALETTE_WIDGET__
#include <map>
#include <limits>
#include <QScrollArea>
#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<const Name,PaletteItem*> 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<size_t>::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<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.