1 #include "XGUI_Workbench.h"
2 #include "XGUI_MenuGroupPanel.h"
5 #include <QResizeEvent>
11 //**************************************************
12 class CommandsArea : public QScrollArea
15 CommandsArea(QWidget* theParent) : QScrollArea(theParent) {}
18 virtual void resizeEvent(QResizeEvent * theEvent);
21 void CommandsArea::resizeEvent(QResizeEvent* theEvent)
23 int x = widget()->x();
24 QScrollArea::resizeEvent(theEvent);
25 QRect aRect = widget()->childrenRect();
26 QSize aNewSize = theEvent->size();
27 if (aRect.width() > aNewSize.width())
28 aNewSize.setWidth(aRect.width() * 2);
29 widget()->resize(aNewSize);
34 //**************************************************
35 XGUI_Workbench::XGUI_Workbench(QWidget *theParent) :
39 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
40 aMainLayout->setSpacing(0);
41 aMainLayout->setMargin(0);
42 aMainLayout->setContentsMargins(0,0,0,0);
44 myLeftButton = new QPushButton("<", this);
45 myLeftButton->setMaximumWidth(14);
46 myLeftButton->setVisible(false);
47 connect(myLeftButton,SIGNAL(clicked()), this, SLOT(onLeftScroll()));
48 aMainLayout->addWidget(myLeftButton);
50 myCommandsArea = new CommandsArea(this);
51 aMainLayout->addWidget(myCommandsArea);
53 myChildWidget = new QWidget(myCommandsArea);
54 myCommandsArea->setWidget(myChildWidget);
55 myCommandsArea->setAlignment(Qt::AlignLeft | Qt::AlignTop);
56 myCommandsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57 myCommandsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
59 myLayout = new QHBoxLayout(myChildWidget);
60 myLayout->setSpacing(0);
61 myLayout->setMargin(0);
62 myLayout->setContentsMargins(0,0,0,0);
64 myRightButton = new QPushButton(">", this);
65 myRightButton->setMaximumWidth(14);
66 myRightButton->setVisible(false);
67 connect(myRightButton,SIGNAL(clicked()), this, SLOT(onRightScroll()));
68 aMainLayout->addWidget(myRightButton);
73 * Creates a new group in the workbench with given name.
74 * If no name provided it would be defined as {workbench_name}_Group_N.
76 IMenuGroup* XGUI_Workbench::addGroup(const QString& theName)
78 QString aGroupName = theName;
79 //Generate a group name.
80 if(theName.isEmpty()){
81 QString aGroupName = objectName();
82 aGroupName = aGroupName.replace("_Workbench", "_Group_%1");
83 aGroupName = aGroupName.arg(myGroups.count());
85 if (!myLayout->isEmpty()) {
86 int aNb = myLayout->count();
87 QLayoutItem* aItem = myLayout->itemAt(aNb - 1);
88 myLayout->removeItem(aItem);
90 XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget);
91 aGroup->setObjectName(aGroupName);
92 myLayout->addWidget(aGroup);
94 myLayout->addStretch();
95 myGroups.append(aGroup);
100 * Searches for already created group with given name.
102 IMenuGroup* XGUI_Workbench::findGroup(const QString& theName)
104 QString aGroupName = theName;
105 XGUI_MenuGroupPanel* aPanel;
106 foreach(aPanel, myGroups) {
107 if(aPanel->objectName() == theName) {
115 void XGUI_Workbench::addSeparator()
117 QFrame* aLine = new QFrame(myChildWidget);
118 aLine->setFrameShape(QFrame::VLine);
119 aLine->setFrameShadow(QFrame::Sunken);
120 myLayout->addWidget(aLine);
124 void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
126 QWidget::resizeEvent(theEvent);
127 QSize aSize = theEvent->size();
128 myLeftButton->setMinimumHeight(aSize.height() - 2);
129 myRightButton->setMinimumHeight(aSize.height() - 2);
131 QSize aS = myChildWidget->sizeHint();
132 int aW = myChildWidget->width();
134 myChildWidget->resize(aS.width(), myChildWidget->height());
136 myLeftButton->setVisible(isExceedsLeft());
137 myRightButton->setVisible(isExceedsRight());
141 void XGUI_Workbench::onLeftScroll()
143 if (!isExceedsLeft())
145 myChildWidget->move( myChildWidget->pos().x() + SCROLL_STEP, 0 );
146 myLeftButton->setVisible(isExceedsLeft());
147 myRightButton->setVisible(isExceedsRight());
151 void XGUI_Workbench::onRightScroll()
153 if (!isExceedsRight())
155 myChildWidget->move( myChildWidget->pos().x() - SCROLL_STEP, 0 );
156 myLeftButton->setVisible(isExceedsLeft());
157 myRightButton->setVisible(isExceedsRight());
161 bool XGUI_Workbench::isExceedsLeft()
163 QPoint aPos = myChildWidget->pos();
164 return (aPos.x() < 0);
167 bool XGUI_Workbench::isExceedsRight()
169 QPoint aPos = myChildWidget->pos();
170 int aVPWidth = myCommandsArea->viewport()->rect().width();
171 int aWgtWidth = myChildWidget->childrenRect().width();
172 return ((aVPWidth - aPos.x()) < aWgtWidth);