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->setEnabled(false);
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);
73 int XGUI_Workbench::addGroup()
75 if (!myLayout->isEmpty()) {
76 int aNb = myLayout->count();
77 QLayoutItem* aItem = myLayout->itemAt(aNb - 1);
78 myLayout->removeItem(aItem);
80 XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget);
81 myLayout->addWidget(aGroup);
83 myLayout->addStretch();
84 myGroups.append(aGroup);
85 return myGroups.size() - 1;
88 void XGUI_Workbench::addSeparator()
90 QFrame* aLine = new QFrame(myChildWidget);
91 aLine->setFrameShape(QFrame::VLine);
92 aLine->setFrameShadow(QFrame::Sunken);
93 myLayout->addWidget(aLine);
96 void XGUI_Workbench::addCommand(int theGroupId, XGUI_Command* theCommand)
98 XGUI_MenuGroupPanel* aGroup = myGroups.at(theGroupId);
99 aGroup->addCommand(theCommand);
103 void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
105 QWidget::resizeEvent(theEvent);
106 QSize aSize = theEvent->size();
107 myLeftButton->setMinimumHeight(aSize.height() - 2);
108 myRightButton->setMinimumHeight(aSize.height() - 2);
110 QSize aS = myChildWidget->sizeHint();
111 int aW = myChildWidget->width();
113 myChildWidget->resize(aS.width(), myChildWidget->height());
115 myLeftButton->setVisible(isExceedsLeft());
116 myRightButton->setVisible(isExceedsRight());
120 void XGUI_Workbench::onLeftScroll()
122 if (!isExceedsLeft())
124 myChildWidget->move( myChildWidget->pos().x() + SCROLL_STEP, 0 );
125 myLeftButton->setVisible(isExceedsLeft());
126 myRightButton->setVisible(isExceedsRight());
130 void XGUI_Workbench::onRightScroll()
132 if (!isExceedsRight())
134 myChildWidget->move( myChildWidget->pos().x() - SCROLL_STEP, 0 );
135 myLeftButton->setVisible(isExceedsLeft());
136 myRightButton->setVisible(isExceedsRight());
140 bool XGUI_Workbench::isExceedsLeft()
142 QPoint aPos = myChildWidget->pos();
143 return (aPos.x() < 0);
146 bool XGUI_Workbench::isExceedsRight()
148 QPoint aPos = myChildWidget->pos();
149 int aVPWidth = myCommandsArea->viewport()->rect().width();
150 int aWgtWidth = myChildWidget->childrenRect().width();
151 return ((aVPWidth - aPos.x()) < aWgtWidth);