Fixes #179 tabs can't be repositioned

This commit is contained in:
fourtf 2018-01-22 21:31:45 +01:00
parent 305191d4b3
commit 06be94b9a6
3 changed files with 11 additions and 7 deletions

View file

@ -291,14 +291,14 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event)
}
}
if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) {
QPoint relPoint = this->mapToParent(event->pos());
QPoint relPoint = this->mapToParent(event->pos());
if (this->mouseDown && !this->getDesiredRect().contains(relPoint)) {
int index;
SplitContainer *clickedPage = notebook->tabAt(relPoint, index);
SplitContainer *clickedPage = notebook->tabAt(relPoint, index, this->width());
if (clickedPage != nullptr && clickedPage != this->page) {
this->notebook->rearrangePage(clickedPage, index);
this->notebook->rearrangePage(this->page, index);
}
}
}

View file

@ -151,12 +151,15 @@ int Notebook::tabCount()
return this->pages.size();
}
SplitContainer *Notebook::tabAt(QPoint point, int &index)
SplitContainer *Notebook::tabAt(QPoint point, int &index, int maxWidth)
{
int i = 0;
for (auto *page : this->pages) {
if (page->getTab()->getDesiredRect().contains(point)) {
QRect rect = page->getTab()->getDesiredRect();
rect.setWidth(std::min(maxWidth, rect.width()));
if (rect.contains(point)) {
index = i;
return page;
}
@ -250,6 +253,7 @@ void Notebook::performLayout(bool animated)
if (this->selectedPage != nullptr) {
this->selectedPage->move(0, y + tabHeight);
this->selectedPage->resize(width(), height() - y - tabHeight);
this->selectedPage->raise();
}
}

View file

@ -41,7 +41,7 @@ public:
void performLayout(bool animate = true);
int tabCount();
SplitContainer *tabAt(QPoint point, int &index);
SplitContainer *tabAt(QPoint point, int &index, int maxWidth = 2000000000);
void rearrangePage(SplitContainer *page, int index);
void nextTab();