Code refactoring: pointers instead of names in Palettes

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 4a051f2ac4
commit 927c77ac25
  1. 13
      src/board/UBBoardPaletteManager.cpp
  2. 8
      src/gui/UBCachePropertiesWidget.cpp
  3. 48
      src/gui/UBDockPalette.cpp
  4. 7
      src/gui/UBDockPalette.h
  5. 4
      src/gui/UBDockPaletteWidget.h

@ -202,8 +202,11 @@ void UBBoardPaletteManager::setupDockPaletteWidgets()
// The cache widget will be visible only if a cache is put on the page // The cache widget will be visible only if a cache is put on the page
mRightPalette->registerWidget(mpCachePropWidget); mRightPalette->registerWidget(mpCachePropWidget);
// The teacher bar widget will always be there // The teacher bar widget will always be there
mRightPalette->registerWidget(mpTeacherBarWidget);
mRightPalette->addTab(mpTeacherBarWidget); // TeacherBarWidget moved to left side just for testing!!!!
mLeftPalette->registerWidget(mpTeacherBarWidget);
mLeftPalette->addTab(mpTeacherBarWidget);
// The download widget will be part of the right palette but // The download widget will be part of the right palette but
// will become visible only when the first download starts // will become visible only when the first download starts
mRightPalette->registerWidget(mpDownloadWidget); mRightPalette->registerWidget(mpDownloadWidget);
@ -211,8 +214,8 @@ void UBBoardPaletteManager::setupDockPaletteWidgets()
changeMode(eUBDockPaletteWidget_BOARD, true); changeMode(eUBDockPaletteWidget_BOARD, true);
// Hide the tabs that must be hidden // Hide the tabs that must be hidden
mRightPalette->removeTab(mpDownloadWidget->name()); mRightPalette->removeTab(mpDownloadWidget);
mRightPalette->removeTab(mpCachePropWidget->name()); mRightPalette->removeTab(mpCachePropWidget);
// mLeftPalette->showTabWidget(0); // mLeftPalette->showTabWidget(0);
// mRightPalette->showTabWidget(0); // mRightPalette->showTabWidget(0);
@ -998,7 +1001,7 @@ void UBBoardPaletteManager::stopDownloads()
{ {
mDownloadInProgress = false; mDownloadInProgress = false;
mpDownloadWidget->setVisibleState(false); mpDownloadWidget->setVisibleState(false);
mRightPalette->removeTab(mpDownloadWidget->name()); mRightPalette->removeTab(mpDownloadWidget);
} }
} }

@ -222,7 +222,7 @@ void UBCachePropertiesWidget::onCloseClicked()
emit cacheListEmpty(); emit cacheListEmpty();
} }
emit hideTab(name()); emit hideTab(this);
} }
} }
@ -300,7 +300,7 @@ void UBCachePropertiesWidget::updateCurrentCache()
if("Cache" == it->data(Qt::UserRole).toString()) if("Cache" == it->data(Qt::UserRole).toString())
{ {
setEnabled(true); setEnabled(true);
emit showTab(name()); emit showTab(this);
mpCurrentCache = dynamic_cast<UBGraphicsCache*>(it); mpCurrentCache = dynamic_cast<UBGraphicsCache*>(it);
if((NULL != mpCurrentCache) && (!mCaches.contains(mpCurrentCache))) if((NULL != mpCurrentCache) && (!mCaches.contains(mpCurrentCache)))
{ {
@ -331,7 +331,7 @@ void UBCachePropertiesWidget::updateCurrentCache()
// 1 - that this page has no cache // 1 - that this page has no cache
// 2 - we are not in Board mode // 2 - we are not in Board mode
// 3 - we are in Board mode, but show desktop (as really - Desktop mode) // 3 - we are in Board mode, but show desktop (as really - Desktop mode)
emit hideTab(name()); emit hideTab(this);
mpCurrentCache = NULL; mpCurrentCache = NULL;
setDisabled(true); setDisabled(true);
} }
@ -346,6 +346,6 @@ void UBCachePropertiesWidget::onSizeChanged(int newSize)
void UBCachePropertiesWidget::onCacheEnabled() void UBCachePropertiesWidget::onCacheEnabled()
{ {
emit showTab(name()); emit showTab(this);
} }

@ -567,19 +567,15 @@ void UBDockPalette::addTab(UBDockPaletteWidget *widget)
* \brief Remove the given tab * \brief Remove the given tab
* @param widgetName as the tab widget name * @param widgetName as the tab widget name
*/ */
void UBDockPalette::removeTab(const QString &widgetName) void UBDockPalette::removeTab(UBDockPaletteWidget* widget)
{ {
for(int i = 0; i < mTabWidgets.size(); i++) int nWidget = mTabWidgets.indexOf(widget);
if( nWidget >= 0 )
{ {
UBDockPaletteWidget* pCrntWidget = mTabWidgets.at(i); mpStackWidget->removeWidget(widget);
if(NULL != pCrntWidget && (pCrntWidget->name() == widgetName)) mTabWidgets.remove(nWidget);
{ widget->hide();
mpStackWidget->removeWidget(pCrntWidget);
mTabWidgets.remove(i);
pCrntWidget->hide();
update(); update();
break;
}
} }
resizeTabs(); resizeTabs();
mCurrentTab = qMax(mCurrentTab - 1, 0); mCurrentTab = qMax(mCurrentTab - 1, 0);
@ -607,17 +603,12 @@ int UBDockPalette::tabSpacing()
* \brief Show the given widget * \brief Show the given widget
* @param widgetName as the given widget name * @param widgetName as the given widget name
*/ */
void UBDockPalette::onShowTabWidget(const QString &widgetName) void UBDockPalette::onShowTabWidget(UBDockPaletteWidget* widget)
{ {
for(int i = 0; i < mRegisteredWidgets.size(); i++) if (mRegisteredWidgets.contains(widget))
{
UBDockPaletteWidget* pCrntWidget = mRegisteredWidgets.at(i);
if(NULL != pCrntWidget && (pCrntWidget->name() == widgetName))
{ {
pCrntWidget->setVisibleState(true); widget->setVisibleState(true);
addTab(pCrntWidget); addTab(widget);
break;
}
} }
} }
@ -625,16 +616,13 @@ void UBDockPalette::onShowTabWidget(const QString &widgetName)
* \brief Hide the given widget * \brief Hide the given widget
* @param widgetName as the given widget name * @param widgetName as the given widget name
*/ */
void UBDockPalette::onHideTabWidget(const QString &widgetName) void UBDockPalette::onHideTabWidget(UBDockPaletteWidget* widget)
{ {
for(int i = 0; i < mRegisteredWidgets.size(); i++){ if (mRegisteredWidgets.contains(widget))
UBDockPaletteWidget* pCrntWidget = mRegisteredWidgets.at(i); {
if(NULL != pCrntWidget && (pCrntWidget->name() == widgetName)){ widget->setVisibleState(false);
pCrntWidget->setVisibleState(false); removeTab(widget);
break;
}
} }
removeTab(widgetName);
} }
/** /**
@ -644,8 +632,8 @@ void UBDockPalette::connectSignals()
{ {
for(int i=0; i < mRegisteredWidgets.size(); i++) for(int i=0; i < mRegisteredWidgets.size(); i++)
{ {
connect(mRegisteredWidgets.at(i), SIGNAL(showTab(QString)), this, SLOT(onShowTabWidget(QString))); connect(mRegisteredWidgets.at(i), SIGNAL(showTab(UBDockPaletteWidget*)), this, SLOT(onShowTabWidget(UBDockPaletteWidget*)));
connect(mRegisteredWidgets.at(i), SIGNAL(hideTab(QString)), this, SLOT(onHideTabWidget(QString))); connect(mRegisteredWidgets.at(i), SIGNAL(hideTab(UBDockPaletteWidget*)), this, SLOT(onHideTabWidget(UBDockPaletteWidget*)));
} }
} }
@ -747,7 +735,7 @@ bool UBDockPalette::switchMode(eUBDockPaletteWidgetMode mode)
} }
else else
{ {
removeTab(pNextWidget->name()); removeTab(pNextWidget);
} }
} }
} }

@ -111,8 +111,9 @@ public:
void setBackgroundBrush(const QBrush& brush); void setBackgroundBrush(const QBrush& brush);
void registerWidget(UBDockPaletteWidget* widget); void registerWidget(UBDockPaletteWidget* widget);
void addTab(UBDockPaletteWidget* widget); void addTab(UBDockPaletteWidget* widget);
void removeTab(const QString& widgetName); void removeTab(UBDockPaletteWidget* widget);
void connectSignals(); void connectSignals();
@ -129,8 +130,8 @@ public:
eUBDockPaletteType paletteType(){return mPaletteType;} eUBDockPaletteType paletteType(){return mPaletteType;}
public slots: public slots:
void onShowTabWidget(const QString& widgetName); void onShowTabWidget(UBDockPaletteWidget* widget);
void onHideTabWidget(const QString& widgetName); void onHideTabWidget(UBDockPaletteWidget* widget);
void onAllDownloadsFinished(); void onAllDownloadsFinished();
protected: protected:

@ -31,8 +31,8 @@ public:
void setVisibleState(bool state){mVisibleState = state;} void setVisibleState(bool state){mVisibleState = state;}
signals: signals:
void hideTab(const QString& widgetName); void hideTab(UBDockPaletteWidget* widget);
void showTab(const QString& widgetName); void showTab(UBDockPaletteWidget* widget);
public slots: public slots:
void slot_changeMode(eUBDockPaletteWidgetMode newMode); void slot_changeMode(eUBDockPaletteWidgetMode newMode);

Loading…
Cancel
Save