summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-12-16 01:47:39 +0300
committerAndrei Karas <akaras@inbox.ru>2016-12-16 01:47:39 +0300
commitabee7cd42ffa9c4fe6e789f6ceb98d7b695f8c72 (patch)
tree6e6841d6b8d0d25fbfad1de753f0a01cb96fce30
parentddfa72d8d01dacdcd38c159ea8dc024fe9d5562a (diff)
downloadmv-abee7cd42ffa9c4fe6e789f6ceb98d7b695f8c72.tar.gz
mv-abee7cd42ffa9c4fe6e789f6ceb98d7b695f8c72.tar.bz2
mv-abee7cd42ffa9c4fe6e789f6ceb98d7b695f8c72.tar.xz
mv-abee7cd42ffa9c4fe6e789f6ceb98d7b695f8c72.zip
Fix hiding tabs in skill dialog.
-rw-r--r--src/gui/widgets/tabbedarea.cpp50
-rw-r--r--src/gui/widgets/tabbedarea.h2
-rw-r--r--src/gui/windows/skilldialog.cpp11
3 files changed, 51 insertions, 12 deletions
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index fa874133b..9c45226ed 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -238,7 +238,7 @@ void TabbedArea::addTab(Tab *const tab,
mTabContainer->add(tab);
mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
- if (!mSelectedTab)
+ if (!mSelectedTab && tab->mVisible == Visible_true)
setSelectedTab(tab);
adjustTabPositions();
@@ -248,6 +248,7 @@ void TabbedArea::addTab(Tab *const tab,
widget->setSize(getWidth() - frameSize,
getHeight() - frameSize - mTabContainer->getHeight());
+ widgetResized(Event(nullptr));
updateTabsWidth();
updateArrowEnableState();
}
@@ -419,6 +420,23 @@ void TabbedArea::setSelectedTab(Tab *const tab)
widgetResized(Event(nullptr));
}
+void TabbedArea::setSelectedTabDefault()
+{
+ if (mSelectedTab == nullptr ||
+ mSelectedTab->mVisible == Visible_false)
+ {
+ for (size_t i = 0; i < mTabs.size(); i++)
+ {
+ Tab *const tab = mTabs[i].first;
+ if (tab && tab->mVisible == Visible_true)
+ {
+ setSelectedTab(tab);
+ return;
+ }
+ }
+ }
+}
+
int TabbedArea::getSelectedTabIndex() const
{
for (unsigned int i = 0, fsz = CAST_U32(mTabs.size());
@@ -492,9 +510,13 @@ void TabbedArea::widgetResized(const Event &event A_UNUSED)
int newWidth = mVisibleTabsWidth;
while (mTabScrollIndex && newWidth < innerWidth)
{
- newWidth += mTabs[mTabScrollIndex - 1].first->getWidth();
- if (newWidth < innerWidth)
- --mTabScrollIndex;
+ Tab *const tab = mTabs[mTabScrollIndex - 1].first;
+ if (tab && tab->mVisible == Visible_true)
+ {
+ newWidth += tab->getWidth();
+ if (newWidth < innerWidth)
+ --mTabScrollIndex;
+ }
}
if (mArrowButton[1])
@@ -516,8 +538,9 @@ void TabbedArea::updateTabsWidth()
mTabsWidth = 0;
FOR_EACH (TabContainer::const_iterator, itr, mTabs)
{
- if ((*itr).first)
- mTabsWidth += (*itr).first->getWidth();
+ Tab *const tab = (*itr).first;
+ if (tab && tab->mVisible == Visible_true)
+ mTabsWidth += tab->getWidth();
}
updateVisibleTabsWidth();
}
@@ -527,8 +550,9 @@ void TabbedArea::updateVisibleTabsWidth()
mVisibleTabsWidth = 0;
for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
{
- if (mTabs[i].first)
- mVisibleTabsWidth += CAST_S32(mTabs[i].first->getWidth());
+ Tab *const tab = mTabs[i].first;
+ if (tab && tab->mVisible == Visible_true)
+ mVisibleTabsWidth += CAST_S32(tab->getWidth());
}
}
@@ -576,8 +600,12 @@ void TabbedArea::adjustTabPositions()
for (size_t i = 0; i < sz; ++i)
{
const Tab *const tab = mTabs[i].first;
- if (tab && tab->getHeight() > maxTabHeight)
+ if (tab &&
+ tab->mVisible == Visible_true &&
+ tab->getHeight() > maxTabHeight)
+ {
maxTabHeight = tab->getHeight();
+ }
}
int x = (mEnableScrollButtons && mArrowButton[0]->mVisible == Visible_true)
@@ -585,7 +613,7 @@ void TabbedArea::adjustTabPositions()
for (size_t i = mTabScrollIndex; i < sz; ++i)
{
Tab *const tab = mTabs[i].first;
- if (!tab)
+ if (!tab || tab->mVisible == Visible_false)
continue;
tab->setPosition(x, maxTabHeight - tab->getHeight());
x += tab->getWidth();
@@ -598,7 +626,7 @@ void TabbedArea::adjustTabPositions()
for (unsigned i = 0; i < mTabScrollIndex; ++i)
{
Tab *const tab = mTabs[i].first;
- if (tab)
+ if (tab && tab->mVisible == Visible_true)
{
x -= tab->getWidth();
tab->setPosition(x, maxTabHeight - tab->getHeight());
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index 6d8bc84d2..e2d88eacf 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -167,6 +167,8 @@ class TabbedArea final : public ActionListener,
void setSelectedTab(Tab *const tab);
+ void setSelectedTabDefault();
+
void setSelectedTabByIndex(const size_t index);
int getSelectedTabIndex() const A_WARN_UNUSED;
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index a18ab3b3e..d273d8453 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -145,7 +145,10 @@ void SkillDialog::addDefaultTab()
// TRANSLATORS: unknown skills tab name
mDefaultTab = new SkillTab(this, _("Unknown"), listbox);
mDeleteTabs.push_back(mDefaultTab);
+ mDefaultTab->setVisible(Visible_false);
mTabs->addTab(mDefaultTab, scroll);
+ mTabs->adjustTabPositions();
+ mTabs->setSelectedTabDefault();
}
void SkillDialog::action(const ActionEvent &event)
@@ -403,11 +406,11 @@ void SkillDialog::loadXmlFile(const std::string &fileName,
mDefaultTab = tab;
}
+ mDeleteTabs.push_back(tab);
if (alwaysVisible == true)
tab->setVisible(Visible_true);
else
tab->setVisible(Visible_false);
- mDeleteTabs.push_back(tab);
mTabs->addTab(tab, scroll);
for_each_xml_child_node(node, set)
@@ -602,7 +605,11 @@ bool SkillDialog::updateSkill(const int id,
info->sp = sp;
info->update();
if (info->tab)
+ {
info->tab->setVisible(Visible_true);
+ mTabs->adjustTabPositions();
+ mTabs->setSelectedTabDefault();
+ }
}
return true;
}
@@ -655,6 +662,8 @@ void SkillDialog::addSkill(const SkillOwner::Type owner,
skill->tab = mDefaultTab;
mDefaultModel->addSkill(skill);
mDefaultTab->setVisible(Visible_true);
+ mTabs->adjustTabPositions();
+ mTabs->setSelectedTabDefault();
mSkills[id] = skill;
mDefaultModel->updateVisibilities();