1 #include "XGUI_Workbench.h"
2 #include "XGUI_MenuGroupPanel.h"
5 #include <QResizeEvent>
10 //**************************************************
11 class CommandsArea: public QScrollArea
14 CommandsArea(QWidget* theParent)
15 : QScrollArea(theParent)
20 virtual void resizeEvent(QResizeEvent * theEvent);
23 void CommandsArea::resizeEvent(QResizeEvent* theEvent)
25 int x = widget()->x();
26 QScrollArea::resizeEvent(theEvent);
27 QRect aRect = widget()->childrenRect();
28 QSize aNewSize = theEvent->size();
29 if (aRect.width() > aNewSize.width())
30 aNewSize.setWidth(aRect.width() * 2);
31 widget()->resize(aNewSize);
35 //**************************************************
36 XGUI_Workbench::XGUI_Workbench(QWidget *theParent)
40 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
41 aMainLayout->setSpacing(0);
42 aMainLayout->setMargin(0);
43 aMainLayout->setContentsMargins(0, 0, 0, 0);
45 myLeftButton = new QPushButton("<", this);
46 myLeftButton->setMaximumWidth(14);
47 myLeftButton->setVisible(false);
48 connect(myLeftButton, SIGNAL(clicked()), this, SLOT(onLeftScroll()));
49 aMainLayout->addWidget(myLeftButton);
51 myCommandsArea = new CommandsArea(this);
52 aMainLayout->addWidget(myCommandsArea);
54 myChildWidget = new QWidget(myCommandsArea);
55 myCommandsArea->setWidget(myChildWidget);
56 myCommandsArea->setAlignment(Qt::AlignLeft | Qt::AlignTop);
57 myCommandsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 myCommandsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
60 myLayout = new QHBoxLayout(myChildWidget);
61 myLayout->setSpacing(0);
62 myLayout->setMargin(0);
63 myLayout->setContentsMargins(0, 0, 0, 0);
65 myRightButton = new QPushButton(">", this);
66 myRightButton->setMaximumWidth(14);
67 myRightButton->setVisible(false);
68 connect(myRightButton, SIGNAL(clicked()), this, SLOT(onRightScroll()));
69 aMainLayout->addWidget(myRightButton);
74 * Creates a new group in the workbench with given object name.
76 XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theId)
78 if (!myLayout->isEmpty()) {
79 int aNb = myLayout->count();
80 QLayoutItem* aItem = myLayout->itemAt(aNb - 1);
81 myLayout->removeItem(aItem);
83 XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget);
84 aGroup->setObjectName(theId);
85 myLayout->addWidget(aGroup);
87 myLayout->addStretch();
88 myGroups.append(aGroup);
93 * Searches for already created group with given name.
95 XGUI_MenuGroupPanel* XGUI_Workbench::findGroup(const QString& theId)
97 XGUI_MenuGroupPanel* aPanel;
98 foreach(aPanel, myGroups)
100 if (aPanel->objectName() == theId) {
107 void XGUI_Workbench::addSeparator()
109 QFrame* aLine = new QFrame(myChildWidget);
110 aLine->setFrameShape(QFrame::VLine);
111 aLine->setFrameShadow(QFrame::Sunken);
112 myLayout->addWidget(aLine);
115 void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
117 QWidget::resizeEvent(theEvent);
118 QSize aSize = theEvent->size();
119 myLeftButton->setMinimumHeight(aSize.height() - 2);
120 myRightButton->setMinimumHeight(aSize.height() - 2);
122 QSize aS = myChildWidget->sizeHint();
123 int aW = myChildWidget->width();
125 myChildWidget->resize(aS.width(), myChildWidget->height());
127 myLeftButton->setVisible(isExceedsLeft());
128 myRightButton->setVisible(isExceedsRight());
131 void XGUI_Workbench::onLeftScroll()
133 if (!isExceedsLeft())
135 myChildWidget->move(myChildWidget->pos().x() + SCROLL_STEP, 0);
136 myLeftButton->setVisible(isExceedsLeft());
137 myRightButton->setVisible(isExceedsRight());
140 void XGUI_Workbench::onRightScroll()
142 if (!isExceedsRight())
144 myChildWidget->move(myChildWidget->pos().x() - SCROLL_STEP, 0);
145 myLeftButton->setVisible(isExceedsLeft());
146 myRightButton->setVisible(isExceedsRight());
149 bool XGUI_Workbench::isExceedsLeft()
151 QPoint aPos = myChildWidget->pos();
152 return (aPos.x() < 0);
155 bool XGUI_Workbench::isExceedsRight()
157 QPoint aPos = myChildWidget->pos();
158 int aVPWidth = myCommandsArea->viewport()->rect().width();
159 int aWgtWidth = myChildWidget->childrenRect().width();
160 return ((aVPWidth - aPos.x()) < aWgtWidth);