From 8841fd5b0627d878a50c04dd11bdbc4835930dca Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 3 Feb 2013 21:19:34 +0300 Subject: Add ability to scroll menu popups. --- src/gui/popupmenu.cpp | 20 ++++++++++++++++++-- src/gui/popupmenu.h | 4 +++- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 2c25cceaf..6bd384132 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -56,6 +56,7 @@ #include "gui/widgets/browserbox.h" #include "gui/widgets/chattab.h" #include "gui/widgets/progressbar.h" +#include "gui/widgets/scrollarea.h" #include "gui/widgets/textfield.h" #include "gui/widgets/whispertab.h" @@ -110,8 +111,10 @@ PopupMenu::PopupMenu(): mPlayerListener.setNick(""); mPlayerListener.setDialog(nullptr); mPlayerListener.setType(static_cast(Being::UNKNOWN)); + mScrollArea = new ScrollArea(mBrowserBox, false); + mScrollArea->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); - add(mBrowserBox); + add(mScrollArea); } void PopupMenu::showPopup(const int x, const int y, const Being *const being) @@ -2140,14 +2143,27 @@ void PopupMenu::showPopup(int x, int y) const int pad2 = 2 * getPadding(); const int bPad2 = 2 * mBrowserBox->getPadding(); mBrowserBox->setPosition(mPadding, mPadding); + mScrollArea->setPosition(mPadding, mPadding); // add padding to initial size before draw browserbox mBrowserBox->setWidth(mBrowserBox->getWidth() + bPad2); + int height = mBrowserBox->getHeight(); + if (height + pad2 >= mainGraphics->getHeight()) + { + height = mainGraphics->getHeight() - pad2; + mBrowserBox->setWidth(mBrowserBox->getWidth() + bPad2 + 10); + } + else + { + mBrowserBox->setWidth(mBrowserBox->getWidth() + bPad2); + } setContentSize(mBrowserBox->getWidth() + pad2, - mBrowserBox->getHeight() + pad2); + height + pad2); if (mainGraphics->mWidth < (x + getWidth() + 5)) x = mainGraphics->mWidth - getWidth(); if (mainGraphics->mHeight < (y + getHeight() + 5)) y = mainGraphics->mHeight - getHeight(); + mScrollArea->setWidth(mBrowserBox->getWidth() + pad2); + mScrollArea->setHeight(height + pad2); setPosition(x, y); setVisible(true); requestMoveToTop(); diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 7266b4d29..d3682f68e 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -41,6 +41,7 @@ class FloorItem; class Item; class ItemShortcut; class MapItem; +class ScrollArea; class TextCommand; class TextDialog; class TextField; @@ -198,7 +199,8 @@ class PopupMenu final : public Popup, public LinkHandler void addPickupFilter(const std::string &name); - BrowserBox* mBrowserBox; + BrowserBox *mBrowserBox; + ScrollArea *mScrollArea; int mBeingId; int mFloorItemId; -- cgit v1.2.3-70-g09d2