ToolBoxManager.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QApplication>
00027 # include <QStyle>
00028 # include <QToolBar>
00029 # include <QToolButton>
00030 #endif
00031
00032 #include "ToolBoxManager.h"
00033 #include "ToolBarManager.h"
00034 #include "Application.h"
00035 #include "Command.h"
00036 #include "ToolBox.h"
00037
00038 using namespace Gui;
00039 using DockWnd::ToolBox;
00040
00041 ToolBoxManager* ToolBoxManager::_instance=0;
00042
00043 ToolBoxManager* ToolBoxManager::getInstance()
00044 {
00045 if ( !_instance )
00046 _instance = new ToolBoxManager;
00047 return _instance;
00048 }
00049
00050 void ToolBoxManager::destruct()
00051 {
00052 delete _instance;
00053 _instance = 0;
00054 }
00055
00056 ToolBoxManager::ToolBoxManager() : _toolBox(0L)
00057 {
00058 }
00059
00060 ToolBoxManager::~ToolBoxManager()
00061 {
00062 }
00063
00064 void ToolBoxManager::setToolBox( DockWnd::ToolBox* tb )
00065 {
00066 _toolBox = tb;
00067 }
00068
00069 void ToolBoxManager::setup( ToolBarItem* toolBar ) const
00070 {
00071 if ( !toolBar || !_toolBox )
00072 return;
00073
00074 int ct = _toolBox->count();
00075 for ( int i=0; i<ct; i++ )
00076 {
00077
00078 QWidget* w = _toolBox->widget(0);
00079 _toolBox->removeItem(0);
00080 delete w;
00081 }
00082
00083 CommandManager& mgr = Application::Instance->commandManager();
00084 QList<ToolBarItem*> items = toolBar->getItems();
00085
00086 for ( QList<ToolBarItem*>::ConstIterator item = items.begin(); item != items.end(); ++item )
00087 {
00088 QToolBar* bar = new QToolBar();
00089 bar->setOrientation(Qt::Vertical);
00090 bar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
00091 std::string toolbarName = (*item)->command();
00092 bar->setObjectName(QString::fromAscii((*item)->command().c_str()));
00093 bar->setWindowTitle(QObject::trUtf8(toolbarName.c_str()));
00094 _toolBox->addItem( bar, bar->windowTitle() );
00095
00096 QList<ToolBarItem*> subitems = (*item)->getItems();
00097 for ( QList<ToolBarItem*>::ConstIterator subitem = subitems.begin(); subitem != subitems.end(); ++subitem )
00098 {
00099 if ( (*subitem)->command() == "Separator" ) {
00100
00101 } else {
00102 mgr.addTo((*subitem)->command().c_str(), bar);
00103 }
00104 }
00105
00106
00107 QList<QToolButton*> tool = bar->findChildren<QToolButton*>();
00108 for (QList<QToolButton*>::Iterator it = tool.begin(); it != tool.end(); ++it) {
00109 (*it)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
00110
00111
00112 QIcon icon = (*it)->icon();
00113 if (icon.isNull())
00114 {
00115
00116 int size = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
00117 QPixmap p(size, size);
00118 p.fill(Qt::transparent);
00119 (*it)->setIcon(p);
00120 }
00121 }
00122 }
00123 }
00124
00125 void ToolBoxManager::retranslate() const
00126 {
00127 int ct = _toolBox->count();
00128 for (int i=0; i<ct; i++) {
00129
00130 QWidget* w = _toolBox->widget(i);
00131 QByteArray toolbarName = w->objectName().toUtf8();
00132 w->setWindowTitle(QObject::trUtf8(toolbarName.constData()));
00133 _toolBox->setItemText(i, w->windowTitle());
00134 }
00135 }