summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-19 05:50:44 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-19 06:16:10 +0200
commit3f1a475c6cb6501a06efc7d5d62cecc104faee26 (patch)
treeab5b74c48a90f9fede05ad148204411c9db2f4c4 /src/gui
parent1ea14cd03b6172681a3dff0b31d4088af3b1b5eb (diff)
downloadmv-3f1a475c6cb6501a06efc7d5d62cecc104faee26.tar.gz
mv-3f1a475c6cb6501a06efc7d5d62cecc104faee26.tar.bz2
mv-3f1a475c6cb6501a06efc7d5d62cecc104faee26.tar.xz
mv-3f1a475c6cb6501a06efc7d5d62cecc104faee26.zip
Add flag to enable or disable scroll buttons in tabbed area.
Also add not working right margin to tabbed area.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp3
-rw-r--r--src/gui/shortcutwindow.cpp2
-rw-r--r--src/gui/widgets/tabbedarea.cpp77
-rw-r--r--src/gui/widgets/tabbedarea.h13
4 files changed, 78 insertions, 17 deletions
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<int>(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<gcn::Tab*, gcn::Widget*> > 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