From 3f1a475c6cb6501a06efc7d5d62cecc104faee26 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 19 Mar 2011 05:50:44 +0200 Subject: Add flag to enable or disable scroll buttons in tabbed area. Also add not working right margin to tabbed area. --- src/gui/chat.cpp | 3 ++ src/gui/shortcutwindow.cpp | 2 ++ src/gui/widgets/tabbedarea.cpp | 77 ++++++++++++++++++++++++++++++++---------- src/gui/widgets/tabbedarea.h | 13 +++++++ 4 files changed, 78 insertions(+), 17 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 6815796ff..8923b40f4 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -159,6 +159,7 @@ ChatWindow::ChatWindow(): mChatInput->addActionListener(this); mChatTabs = new TabbedArea; + mChatTabs->enableScrollButtons(true); mChatColor = config.getIntValue("chatColor"); mColorListModel = new ColorListModel; @@ -300,6 +301,8 @@ void ChatWindow::adjustTabSize() mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth() - 2*getPadding() - 8 - 16, getPadding()); +// if (mColorPicker->isVisible()) +// mChatTabs->setRightMargin(mColorPicker->getWidth() - 8); } void ChatWindow::widgetResized(const gcn::Event &event) diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index dce04d150..0ca93fb91 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -107,6 +107,8 @@ ShortcutWindow::ShortcutWindow(const std::string &title, int width, int height) setupWindow->registerWindowForReset(this); mTabs = new TabbedArea; + mTabs->enableScrollButtons(true); + mTabs->setRightMargin(40); mItems = 0; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 7da6f9398..f4b4a78f8 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -31,7 +31,9 @@ TabbedArea::TabbedArea() : gcn::TabbedArea(), mTabsWidth(0), mVisibleTabsWidth(0), - mTabScrollIndex(0) + mTabScrollIndex(0), + mEnableScrollButtons(false), + mRightMargin(0) { mWidgetContainer->setOpaque(false); addWidgetListener(this); @@ -39,12 +41,38 @@ TabbedArea::TabbedArea() : gcn::TabbedArea(), mArrowButton[0] = new Button("<", "shift_left", this); mArrowButton[1] = new Button(">", "shift_right", this); - add(mArrowButton[0]); - add(mArrowButton[1]); - widgetResized(NULL); } +TabbedArea::~TabbedArea() +{ + if (!mEnableScrollButtons) + { + delete mArrowButton[0]; + mArrowButton[0] = 0; + delete mArrowButton[1]; + mArrowButton[1] = 0; + } +} + +void TabbedArea::enableScrollButtons(bool enable) +{ + if (mEnableScrollButtons && !enable) + { + if (mArrowButton[0]) + add(mArrowButton[0]); + if (mArrowButton[1]) + add(mArrowButton[1]); + } + else if (!mEnableScrollButtons && enable) + { + if (mArrowButton[0]) + add(mArrowButton[0]); + if (mArrowButton[1]) + add(mArrowButton[1]); + } +} + int TabbedArea::getNumberOfTabs() const { return static_cast(mTabs.size()); @@ -223,19 +251,31 @@ void TabbedArea::widgetResized(const gcn::Event &event _UNUSED_) if (w) w->setSize(width, height); - // Check whether there is room to show more tabs now. - int innerWidth = getWidth() - 4 - mArrowButton[0]->getWidth() - - mArrowButton[1]->getWidth(); - int newWidth = mVisibleTabsWidth; - while (mTabScrollIndex && newWidth < innerWidth) + if (mArrowButton[1]) { - newWidth += mTabs[mTabScrollIndex - 1].first->getWidth(); - if (newWidth < innerWidth) - --mTabScrollIndex; - } + // Check whether there is room to show more tabs now. + int innerWidth = getWidth() - 4 - mArrowButton[0]->getWidth() + - mArrowButton[1]->getWidth() - mRightMargin; + if (innerWidth < 0) + innerWidth = 0; + + int newWidth = mVisibleTabsWidth; + while (mTabScrollIndex && newWidth < innerWidth) + { + newWidth += mTabs[mTabScrollIndex - 1].first->getWidth(); + if (newWidth < innerWidth) + --mTabScrollIndex; + } - // Move the right arrow to fit the windows content. - mArrowButton[1]->setPosition(width - mArrowButton[1]->getWidth(), 0); + if (mArrowButton[1]) + { + // Move the right arrow to fit the windows content. + newWidth = width - mArrowButton[1]->getWidth() - mRightMargin; + if (newWidth < 0) + newWidth = 0; + mArrowButton[1]->setPosition(newWidth, 0); + } + } updateArrowEnableState(); adjustTabPositions(); @@ -328,9 +368,12 @@ void TabbedArea::action(const gcn::ActionEvent& actionEvent) void TabbedArea::updateArrowEnableState() { updateTabsWidth(); + if (!mArrowButton[0] || !mArrowButton[1]) + return; + if (mTabsWidth > getWidth() - 4 - mArrowButton[0]->getWidth() - - mArrowButton[1]->getWidth()) + - mArrowButton[1]->getWidth() - mRightMargin) { mArrowButton[0]->setVisible(true); mArrowButton[1]->setVisible(true); @@ -351,7 +394,7 @@ void TabbedArea::updateArrowEnableState() // Right arrow consistency check if (mVisibleTabsWidth < getWidth() - 4 - mArrowButton[0]->getWidth() - - mArrowButton[1]->getWidth()) + - mArrowButton[1]->getWidth() - mRightMargin) { mArrowButton[1]->setEnabled(false); } diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index e5a00e277..0c2903777 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -51,6 +51,8 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener */ TabbedArea(); + ~TabbedArea(); + /** * Draw the tabbed area. */ @@ -129,6 +131,14 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener void mousePressed(gcn::MouseEvent &mouseEvent); + void enableScrollButtons(bool enable); + + void setRightMargin(int n) + { mRightMargin = n; } + + int getRightMargin() + { return mRightMargin; } + private: typedef std::vector< std::pair > TabContainer; @@ -168,6 +178,9 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener * @note the index must start at 0. */ unsigned mTabScrollIndex; + + bool mEnableScrollButtons; + int mRightMargin; }; #endif -- cgit v1.2.3-60-g2f50