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 QScrollArea::resizeEvent(theEvent);
24 QRect aRect = widget()->childrenRect();
25 QSize aNewSize = theEvent->size();
26 if (aRect.width() > aNewSize.width())
27 aNewSize.setWidth(aRect.width() * 2);
28 widget()->resize(aNewSize);
32 //**************************************************
33 XGUI_Workbench::XGUI_Workbench(QWidget *theParent) :
37 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
38 aMainLayout->setSpacing(0);
39 aMainLayout->setMargin(0);
40 aMainLayout->setContentsMargins(0,0,0,0);
42 myLeftButton = new QPushButton("<", this);
43 myLeftButton->setMaximumWidth(14);
44 //myLeftButton->setEnabled(false);
45 myLeftButton->setVisible(false);
46 connect(myLeftButton,SIGNAL(clicked()), this, SLOT(onLeftScroll()));
47 aMainLayout->addWidget(myLeftButton);
49 myCommandsArea = new CommandsArea(this);
50 aMainLayout->addWidget(myCommandsArea);
52 myChildWidget = new QWidget(myCommandsArea);
53 myCommandsArea->setWidget(myChildWidget);
54 myCommandsArea->setAlignment(Qt::AlignLeft | Qt::AlignTop);
55 myCommandsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
56 myCommandsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 myLayout = new QHBoxLayout(myChildWidget);
59 myLayout->setSpacing(0);
60 myLayout->setMargin(0);
61 myLayout->setContentsMargins(0,0,0,0);
63 myRightButton = new QPushButton(">", this);
64 myRightButton->setMaximumWidth(14);
65 //myRightButton->setEnabled(false);
66 myRightButton->setVisible(false);
67 connect(myRightButton,SIGNAL(clicked()), this, SLOT(onRightScroll()));
68 aMainLayout->addWidget(myRightButton);
72 int 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);
84 return myGroups.size() - 1;
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::addCommand(int theGroupId, XGUI_Command* theCommand)
97 XGUI_MenuGroupPanel* aGroup = myGroups.at(theGroupId);
98 aGroup->addCommand(theCommand);
102 void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
104 QWidget::resizeEvent(theEvent);
105 QSize aSize = theEvent->size();
106 myLeftButton->setMinimumHeight(aSize.height() - 2);
107 myRightButton->setMinimumHeight(aSize.height() - 2);
109 QSize aS = myChildWidget->sizeHint();
110 int aW = myChildWidget->width();
112 myChildWidget->resize(aS.width(), myChildWidget->height());
114 //myLeftButton->setEnabled(isExceedsLeft());
115 //myRightButton->setEnabled(isExceedsRight());
116 myLeftButton->setVisible(isExceedsLeft());
117 myRightButton->setVisible(isExceedsRight());
121 void XGUI_Workbench::onLeftScroll()
123 if (!isExceedsLeft())
125 myChildWidget->move( myChildWidget->pos().x() + SCROLL_STEP, 0 );
126 myLeftButton->setVisible(isExceedsLeft());
127 myRightButton->setVisible(isExceedsRight());
128 //myLeftButton->setEnabled(isExceedsLeft());
129 //myRightButton->setEnabled(isExceedsRight());
133 void XGUI_Workbench::onRightScroll()
135 if (!isExceedsRight())
137 myChildWidget->move( myChildWidget->pos().x() - SCROLL_STEP, 0 );
138 //myLeftButton->setEnabled(isExceedsLeft());
139 //myRightButton->setEnabled(isExceedsRight());
140 myLeftButton->setVisible(isExceedsLeft());
141 myRightButton->setVisible(isExceedsRight());
145 bool XGUI_Workbench::isExceedsLeft()
147 QPoint aPos = myChildWidget->pos();
148 return (aPos.x() < 0);
151 bool XGUI_Workbench::isExceedsRight()
153 QPoint aPos = myChildWidget->pos();
154 int aVPWidth = myCommandsArea->viewport()->rect().width();
155 int aWgtWidth = myChildWidget->childrenRect().width();
156 return ((aVPWidth - aPos.x()) < aWgtWidth);