X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workbench.cpp;h=f92380374eb88c32b2494d572f29bd49b276da50;hb=8da742ab694198bf02ffd7c4b876128774fd2c92;hp=61da43fa236f0fcb7f2ee8c7d3ed3bdf535fd31b;hpb=e607e2c793a83dc30d483e1819f44c3497a08555;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workbench.cpp b/src/XGUI/XGUI_Workbench.cpp index 61da43fa2..f92380374 100644 --- a/src/XGUI/XGUI_Workbench.cpp +++ b/src/XGUI/XGUI_Workbench.cpp @@ -5,67 +5,69 @@ #include #include - #define SCROLL_STEP 20 //************************************************** -class CommandsArea : public QScrollArea +class CommandsArea: public QScrollArea { public: - CommandsArea(QWidget* theParent) : QScrollArea(theParent) {} + CommandsArea(QWidget* theParent) + : QScrollArea(theParent) + { + } protected: - virtual void resizeEvent(QResizeEvent * theEvent); + virtual void resizeEvent(QResizeEvent * theEvent); }; void CommandsArea::resizeEvent(QResizeEvent* theEvent) { - int x = widget()->x(); - QScrollArea::resizeEvent(theEvent); - QRect aRect = widget()->childrenRect(); - QSize aNewSize = theEvent->size(); - if (aRect.width() > aNewSize.width()) - aNewSize.setWidth(aRect.width() * 2); - widget()->resize(aNewSize); - widget()->move(x, 0); + int x = widget()->x(); + QScrollArea::resizeEvent(theEvent); + QRect aRect = widget()->childrenRect(); + QSize aNewSize = theEvent->size(); + if (aRect.width() > aNewSize.width()) + aNewSize.setWidth(aRect.width() * 2); + widget()->resize(aNewSize); + widget()->move(x, 0); } - //************************************************** -XGUI_Workbench::XGUI_Workbench(QWidget *theParent) : - QWidget(theParent) +XGUI_Workbench::XGUI_Workbench(QWidget *theParent) + : QWidget(theParent) { - setMinimumHeight(30); - QHBoxLayout* aMainLayout = new QHBoxLayout(this); - aMainLayout->setSpacing(0); - aMainLayout->setMargin(0); - aMainLayout->setContentsMargins(0,0,0,0); - - myLeftButton = new QPushButton("<", this); - myLeftButton->setMaximumWidth(14); - myLeftButton->setVisible(false); - connect(myLeftButton,SIGNAL(clicked()), this, SLOT(onLeftScroll())); - aMainLayout->addWidget(myLeftButton); - - myCommandsArea = new CommandsArea(this); - aMainLayout->addWidget(myCommandsArea); - - myChildWidget = new QWidget(myCommandsArea); - myCommandsArea->setWidget(myChildWidget); - myCommandsArea->setAlignment(Qt::AlignLeft | Qt::AlignTop); - myCommandsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - myCommandsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - myLayout = new QHBoxLayout(myChildWidget); - myLayout->setSpacing(0); - myLayout->setMargin(0); - myLayout->setContentsMargins(0,0,0,0); - - myRightButton = new QPushButton(">", this); - myRightButton->setMaximumWidth(14); - myRightButton->setVisible(false); - connect(myRightButton,SIGNAL(clicked()), this, SLOT(onRightScroll())); - aMainLayout->addWidget(myRightButton); + setMinimumHeight(30); + QHBoxLayout* aMainLayout = new QHBoxLayout(this); + aMainLayout->setSpacing(0); + aMainLayout->setMargin(0); + aMainLayout->setContentsMargins(0, 0, 0, 0); + + myLeftButton = new QPushButton("<", this); + myLeftButton->setMaximumWidth(14); + myLeftButton->setVisible(false); + connect(myLeftButton, SIGNAL(clicked()), this, SLOT(onLeftScroll())); + aMainLayout->addWidget(myLeftButton); + + myCommandsArea = new CommandsArea(this); + aMainLayout->addWidget(myCommandsArea); + myCommandsArea->viewport()->installEventFilter(this); + + myChildWidget = new QWidget(myCommandsArea); + myCommandsArea->setWidget(myChildWidget); + myCommandsArea->setAlignment(Qt::AlignLeft | Qt::AlignTop); + myCommandsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + myCommandsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + myLayout = new QHBoxLayout(myChildWidget); + myLayout->setSpacing(0); + myLayout->setMargin(0); + myLayout->setContentsMargins(0, 0, 0, 0); + + myRightButton = new QPushButton(">", this); + myRightButton->setMaximumWidth(14); + myRightButton->setVisible(false); + connect(myRightButton, SIGNAL(clicked()), this, SLOT(onRightScroll())); + aMainLayout->addWidget(myRightButton); } @@ -74,18 +76,20 @@ XGUI_Workbench::XGUI_Workbench(QWidget *theParent) : */ XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theId) { - if (!myLayout->isEmpty()) { - int aNb = myLayout->count(); - QLayoutItem* aItem = myLayout->itemAt(aNb - 1); - myLayout->removeItem(aItem); - } - XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget); - aGroup->setObjectName(theId); - myLayout->addWidget(aGroup); + if (!myLayout->isEmpty()) { + int aNb = myLayout->count(); + QLayoutItem* aItem = myLayout->itemAt(aNb - 1); + myLayout->removeItem(aItem); + } + XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget); + aGroup->setObjectName(theId); + myLayout->addWidget(aGroup); + if(theId != "Default") { addSeparator(); - myLayout->addStretch(); - myGroups.append(aGroup); - return aGroup; + } + myLayout->addStretch(); + myGroups.append(aGroup); + return aGroup; } /* @@ -94,71 +98,98 @@ XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theId) XGUI_MenuGroupPanel* XGUI_Workbench::findGroup(const QString& theId) { XGUI_MenuGroupPanel* aPanel; - foreach(aPanel, myGroups) { - if(aPanel->objectName() == theId) { + foreach(aPanel, myGroups) + { + if (aPanel->objectName() == theId) { return aPanel; } } return NULL; } - void XGUI_Workbench::addSeparator() { - QFrame* aLine = new QFrame(myChildWidget); - aLine->setFrameShape(QFrame::VLine); - aLine->setFrameShadow(QFrame::Sunken); - myLayout->addWidget(aLine); + QFrame* aLine = new QFrame(myChildWidget); + aLine->setFrameShape(QFrame::VLine); + aLine->setFrameShadow(QFrame::Sunken); + myLayout->addWidget(aLine); } - void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent) { - QWidget::resizeEvent(theEvent); - QSize aSize = theEvent->size(); - myLeftButton->setMinimumHeight(aSize.height() - 2); - myRightButton->setMinimumHeight(aSize.height() - 2); - - QSize aS = myChildWidget->sizeHint(); - int aW = myChildWidget->width(); - if (aW < aS.width()) - myChildWidget->resize(aS.width(), myChildWidget->height()); - - myLeftButton->setVisible(isExceedsLeft()); - myRightButton->setVisible(isExceedsRight()); + QWidget::resizeEvent(theEvent); + QSize aSize = theEvent->size(); + myLeftButton->setMinimumHeight(aSize.height() - 2); + myRightButton->setMinimumHeight(aSize.height() - 2); + + QSize aS = myChildWidget->sizeHint(); + int aW = myChildWidget->width(); + if (aW < aS.width()) + myChildWidget->resize(aS.width(), myChildWidget->height()); + + myLeftButton->setVisible(isExceedsLeft()); + myRightButton->setVisible(isExceedsRight()); } - void XGUI_Workbench::onLeftScroll() { - if (!isExceedsLeft()) - return; - myChildWidget->move( myChildWidget->pos().x() + SCROLL_STEP, 0 ); - myLeftButton->setVisible(isExceedsLeft()); - myRightButton->setVisible(isExceedsRight()); + if (!isExceedsLeft()) + return; + myChildWidget->move(myChildWidget->pos().x() + SCROLL_STEP, 0); + myLeftButton->setVisible(isExceedsLeft()); + myRightButton->setVisible(isExceedsRight()); } - void XGUI_Workbench::onRightScroll() { - if (!isExceedsRight()) - return; - myChildWidget->move( myChildWidget->pos().x() - SCROLL_STEP, 0 ); - myLeftButton->setVisible(isExceedsLeft()); - myRightButton->setVisible(isExceedsRight()); + if (!isExceedsRight()) + return; + myChildWidget->move(myChildWidget->pos().x() - SCROLL_STEP, 0); + myLeftButton->setVisible(isExceedsLeft()); + myRightButton->setVisible(isExceedsRight()); } - bool XGUI_Workbench::isExceedsLeft() { - QPoint aPos = myChildWidget->pos(); - return (aPos.x() < 0); + QPoint aPos = myChildWidget->pos(); + return (aPos.x() < 0); } bool XGUI_Workbench::isExceedsRight() { - QPoint aPos = myChildWidget->pos(); - int aVPWidth = myCommandsArea->viewport()->rect().width(); - int aWgtWidth = myChildWidget->childrenRect().width(); - return ((aVPWidth - aPos.x()) < aWgtWidth); + QPoint aPos = myChildWidget->pos(); + int aVPWidth = myCommandsArea->viewport()->rect().width(); + int aWgtWidth = myChildWidget->childrenRect().width(); + return ((aVPWidth - aPos.x()) < aWgtWidth); +} + +bool XGUI_Workbench::eventFilter(QObject *theObj, QEvent *theEvent) +{ + if (theObj == myCommandsArea->viewport()) { + if (theEvent->type() == QEvent::Resize) { + myLeftButton->setVisible(isExceedsLeft()); + myRightButton->setVisible(isExceedsRight()); + } + } + return QWidget::eventFilter(theObj, theEvent); +} + +XGUI_Command* XGUI_Workbench::feature(const QString& theId) const +{ + QList::const_iterator aIt; + for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) { + XGUI_Command* aCmd = (*aIt)->feature(theId); + if (aCmd) + return aCmd; + } + return 0; +} + +QList XGUI_Workbench::features() const +{ + QList aList; + QList::const_iterator aIt; + for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) + aList.append((*aIt)->features()); + return aList; }