{
Q_OBJECT
public:
explicit Widget
(QWidget * parent
= 0) , mHPushButtons()
, mVPushButtons()
, mActivePage(0)
, mActiveWidget()
{
// Create Horizontal QPushButton 8 Qty
for(int i = 0; i < HButtons; i++)
{
mActiveWidget[i] = 0;
}
// Create Vertical QPushButton 6 * 2 = 12 Qty
for(int i = 0; i < LButtons + RButtons; i++)
connect(pageSignalMapper, SIGNAL(mapped(int)), SLOT(hButtonClicked(int)));
connect(widgetSignalMapper, SIGNAL(mapped(int)), SLOT(vButtonClicked(int)));
// Create Page Widgets - 8 * 12 = 96 Qty
for(int i = 0; i < HButtons; i++)
{
connect(mHPushButtons[i], SIGNAL(clicked()), pageSignalMapper, SLOT(map()));
pageSignalMapper->setMapping(mHPushButtons[i], i);
for(int j = 0; j < LButtons + RButtons; j++)
{
mStackedWidget->addWidget(label);
}
}
for(int j = 0; j < LButtons + RButtons; j++)
{
connect(mVPushButtons[j], SIGNAL(clicked()), widgetSignalMapper, SLOT(map()));
widgetSignalMapper->setMapping(mVPushButtons[j], j);
}
// Add Horozontal QPushButtons to QGridLayout
for(int i = 0; i < HButtons; i++)
mGridLayout->addWidget(mHPushButtons[i], 0, i, 1, 1);
// Add Left Vertical QPushButtons to QGridLayout
for(int i = 0; i < LButtons; i++)
mGridLayout->addWidget(mVPushButtons[i], 1 + i, 0, 1, 1);
// Add Vertical QPushButtons to QGridLayout
for(int i = LButtons; i < LButtons + RButtons; i++)
mGridLayout->addWidget(mVPushButtons[i], 1 + i - LButtons, HButtons - 1, 1, 1);
// Add QStackedWidget to QGridLayout
mGridLayout->addWidget(mStackedWidget, 1, 1, LButtons, HButtons - 2);
}
private slots:
void hButtonClicked(int page)
{
mActivePage = page;
activateWidget();
}
void vButtonClicked(int widget)
{
mActiveWidget[mActivePage] = widget;
activateWidget();
}
private:
static const int HButtons = 8;
static const int LButtons = 6;
static const int RButtons = 6;
int mActivePage;
int mActiveWidget[HButtons];
void activateWidget(void)
{
int index = mActivePage * (LButtons + RButtons) + mActiveWidget[mActivePage];
mStackedWidget->setCurrentIndex(index);
}
};
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget * parent = 0)
: QWidget(parent)
, mStackedWidget(new QStackedWidget)
, mHPushButtons()
, mVPushButtons()
, mGridLayout(new QGridLayout(this))
, mActivePage(0)
, mActiveWidget()
{
// Create Horizontal QPushButton 8 Qty
for(int i = 0; i < HButtons; i++)
{
mHPushButtons[i] = new QPushButton(QString("Page %1").arg(i + 1));
mActiveWidget[i] = 0;
}
// Create Vertical QPushButton 6 * 2 = 12 Qty
for(int i = 0; i < LButtons + RButtons; i++)
mVPushButtons[i] = new QPushButton(QString("Widget %1").arg(i + 1));
QSignalMapper * pageSignalMapper = new QSignalMapper(this);
connect(pageSignalMapper, SIGNAL(mapped(int)), SLOT(hButtonClicked(int)));
QSignalMapper * widgetSignalMapper = new QSignalMapper(this);
connect(widgetSignalMapper, SIGNAL(mapped(int)), SLOT(vButtonClicked(int)));
// Create Page Widgets - 8 * 12 = 96 Qty
for(int i = 0; i < HButtons; i++)
{
connect(mHPushButtons[i], SIGNAL(clicked()), pageSignalMapper, SLOT(map()));
pageSignalMapper->setMapping(mHPushButtons[i], i);
for(int j = 0; j < LButtons + RButtons; j++)
{
QLabel * label = new QLabel(QString("QWidget : Page %1, Widget %2").arg(i + 1).arg(j + 1));
mStackedWidget->addWidget(label);
}
}
for(int j = 0; j < LButtons + RButtons; j++)
{
connect(mVPushButtons[j], SIGNAL(clicked()), widgetSignalMapper, SLOT(map()));
widgetSignalMapper->setMapping(mVPushButtons[j], j);
}
// Add Horozontal QPushButtons to QGridLayout
for(int i = 0; i < HButtons; i++)
mGridLayout->addWidget(mHPushButtons[i], 0, i, 1, 1);
// Add Left Vertical QPushButtons to QGridLayout
for(int i = 0; i < LButtons; i++)
mGridLayout->addWidget(mVPushButtons[i], 1 + i, 0, 1, 1);
// Add Vertical QPushButtons to QGridLayout
for(int i = LButtons; i < LButtons + RButtons; i++)
mGridLayout->addWidget(mVPushButtons[i], 1 + i - LButtons, HButtons - 1, 1, 1);
// Add QStackedWidget to QGridLayout
mGridLayout->addWidget(mStackedWidget, 1, 1, LButtons, HButtons - 2);
}
private slots:
void hButtonClicked(int page)
{
mActivePage = page;
activateWidget();
}
void vButtonClicked(int widget)
{
mActiveWidget[mActivePage] = widget;
activateWidget();
}
private:
static const int HButtons = 8;
static const int LButtons = 6;
static const int RButtons = 6;
QStackedWidget * mStackedWidget;
QPushButton * mHPushButtons[HButtons];
QPushButton * mVPushButtons[LButtons + RButtons];
QGridLayout * mGridLayout;
int mActivePage;
int mActiveWidget[HButtons];
void activateWidget(void)
{
int index = mActivePage * (LButtons + RButtons) + mActiveWidget[mActivePage];
mStackedWidget->setCurrentIndex(index);
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks