165 lines
3.4 KiB
C++
165 lines
3.4 KiB
C++
/**
|
|
* @file PaiToolBarView.cpp
|
|
* @date 2011-9-16
|
|
*/
|
|
#include <QVBoxLayout>
|
|
#include <QToolBar>
|
|
|
|
#include "PaiToolBarView.h"
|
|
#include "PaiToolBar.h"
|
|
|
|
using namespace pai;
|
|
|
|
PaiToolBarView::PaiToolBarView(QWidget *pParent, EToolBarType type) :
|
|
QWidget(pParent)
|
|
{
|
|
m_pToolBarArea = new QWidget(this);
|
|
m_pViewport = new QWidget(this);
|
|
|
|
m_pMainVLayout = new QVBoxLayout(this);
|
|
m_pMainVLayout->setSpacing(0);
|
|
m_pMainVLayout->setContentsMargins(0, 0, 0, 0);
|
|
m_pMainVLayout->addWidget(m_pToolBarArea);
|
|
m_pMainVLayout->addWidget(m_pViewport);
|
|
|
|
m_pToolBarLayout = new QVBoxLayout(m_pToolBarArea);
|
|
m_pToolBarLayout->setSpacing(0);
|
|
m_pToolBarLayout->setContentsMargins(0, 0, 0, 0);
|
|
m_pToolBarArea->setLayout(m_pToolBarLayout);
|
|
|
|
AddToolBar(new pai::gui::PaiToolBar(m_pToolBarArea), type);
|
|
m_pToolBarArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
setLayout(m_pMainVLayout);
|
|
}
|
|
|
|
PaiToolBarView::~PaiToolBarView()
|
|
{
|
|
}
|
|
|
|
QWidget* PaiToolBarView::GetViewport()
|
|
{
|
|
return m_pViewport;
|
|
}
|
|
|
|
void PaiToolBarView::SetViewport(QWidget *pWidget)
|
|
{
|
|
if(m_pViewport)
|
|
{
|
|
m_pMainVLayout->removeWidget(m_pViewport);
|
|
delete m_pViewport;
|
|
}
|
|
m_pViewport = pWidget;
|
|
|
|
if(pWidget)
|
|
{
|
|
m_pMainVLayout->addWidget(m_pViewport);
|
|
}
|
|
}
|
|
|
|
void PaiToolBarView::AddToolBar(QToolBar *pToolBar, EToolBarType type)
|
|
{
|
|
if(pToolBar)
|
|
{
|
|
pToolBar->setParent(m_pToolBarArea);
|
|
pToolBar->setMinimumHeight(type);
|
|
pToolBar->setMaximumHeight(type);
|
|
|
|
pai::gui::PaiToolBar *pSToolBar = dynamic_cast< pai::gui::PaiToolBar* > (pToolBar);
|
|
if(pSToolBar)
|
|
{
|
|
pSToolBar->ShowBorder(1, 0, 1, 1);
|
|
}
|
|
|
|
m_pToolBarLayout->addWidget(pToolBar);
|
|
|
|
m_ToolBars.append(pToolBar);
|
|
}
|
|
}
|
|
|
|
void PaiToolBarView::RemoveToolBar(QToolBar *pToolBar)
|
|
{
|
|
int count = m_ToolBars.count();
|
|
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
if(m_ToolBars.at(i) == pToolBar)
|
|
{
|
|
m_pToolBarLayout->removeWidget(pToolBar);
|
|
pToolBar->setParent(NULL);
|
|
delete pToolBar;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
QList< QToolBar* > PaiToolBarView::GetToolBars()
|
|
{
|
|
return m_ToolBars;
|
|
}
|
|
|
|
void PaiToolBarView::AddAction(QAction *pAct, QToolBar *pToolBar)
|
|
{
|
|
if(NULL == pToolBar)
|
|
{
|
|
if(m_ToolBars.count() > 0)
|
|
{
|
|
pToolBar = m_ToolBars.at(0);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
pToolBar->addAction(pAct);
|
|
}
|
|
|
|
void PaiToolBarView::AddWidget(QWidget *pWidget, QToolBar *pToolBar)
|
|
{
|
|
if(NULL == pToolBar)
|
|
{
|
|
if(m_ToolBars.count() > 0)
|
|
{
|
|
pToolBar = m_ToolBars.at(0);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
pToolBar->addWidget(pWidget);
|
|
}
|
|
|
|
void PaiToolBarView::AddToolButton(QWidget *pToolBt, QToolBar *pToolBar)
|
|
{
|
|
if(NULL == pToolBar)
|
|
{
|
|
if(m_ToolBars.count() > 0)
|
|
{
|
|
pToolBar = m_ToolBars.at(0);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
if(pToolBar != NULL)
|
|
{
|
|
if(pToolBar->height() == NORMAL_TOOLBAR)
|
|
{
|
|
pToolBt->setMinimumHeight(NORMAL_TOOLBAR - 8);
|
|
}
|
|
else if(pToolBar->height() == SMALL_TOOLBAR)
|
|
{
|
|
pToolBt->setMaximumHeight(SMALL_TOOLBAR - 5);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
pToolBar->addWidget(pToolBt);
|
|
}
|