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);
72 IMenuGroup* XGUI_Workbench::addGroup()
74 if (!myLayout->isEmpty()) {
75 int aNb = myLayout->count();
76 QLayoutItem* aItem = myLayout->itemAt(aNb - 1);
77 myLayout->removeItem(aItem);
79 XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget);
80 myLayout->addWidget(aGroup);
82 myLayout->addStretch();
83 myGroups.append(aGroup);
87 void XGUI_Workbench::addSeparator()
89 QFrame* aLine = new QFrame(myChildWidget);
90 aLine->setFrameShape(QFrame::VLine);
91 aLine->setFrameShadow(QFrame::Sunken);
92 myLayout->addWidget(aLine);
95 void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
97 QWidget::resizeEvent(theEvent);
98 QSize aSize = theEvent->size();
99 myLeftButton->setMinimumHeight(aSize.height() - 2);
100 myRightButton->setMinimumHeight(aSize.height() - 2);
102 QSize aS = myChildWidget->sizeHint();
103 int aW = myChildWidget->width();
105 myChildWidget->resize(aS.width(), myChildWidget->height());
107 myLeftButton->setVisible(isExceedsLeft());
108 myRightButton->setVisible(isExceedsRight());
112 void XGUI_Workbench::onLeftScroll()
114 if (!isExceedsLeft())
116 myChildWidget->move( myChildWidget->pos().x() + SCROLL_STEP, 0 );
117 myLeftButton->setVisible(isExceedsLeft());
118 myRightButton->setVisible(isExceedsRight());
122 void XGUI_Workbench::onRightScroll()
124 if (!isExceedsRight())
126 myChildWidget->move( myChildWidget->pos().x() - SCROLL_STEP, 0 );
127 myLeftButton->setVisible(isExceedsLeft());
128 myRightButton->setVisible(isExceedsRight());
132 bool XGUI_Workbench::isExceedsLeft()
134 QPoint aPos = myChildWidget->pos();
135 return (aPos.x() < 0);
138 bool XGUI_Workbench::isExceedsRight()
140 QPoint aPos = myChildWidget->pos();
141 int aVPWidth = myCommandsArea->viewport()->rect().width();
142 int aWgtWidth = myChildWidget->childrenRect().width();
143 return ((aVPWidth - aPos.x()) < aWgtWidth);