2014-08-11 16:00:08 +08:00
|
|
|
/*
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "adjustingscrollarea.h"
|
|
|
|
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QLayout>
|
2014-08-11 23:06:57 +08:00
|
|
|
#include <QScrollBar>
|
2014-08-11 19:56:52 +08:00
|
|
|
#include <QDebug>
|
2014-08-11 16:00:08 +08:00
|
|
|
|
2014-09-28 23:30:00 +08:00
|
|
|
AdjustingScrollArea::AdjustingScrollArea(QWidget *parent)
|
|
|
|
: QScrollArea(parent)
|
2014-08-11 16:00:08 +08:00
|
|
|
{
|
2014-08-11 19:56:52 +08:00
|
|
|
|
2014-08-11 16:00:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdjustingScrollArea::resizeEvent(QResizeEvent *ev)
|
2014-08-11 19:56:52 +08:00
|
|
|
{
|
2014-09-28 23:30:00 +08:00
|
|
|
int scrollBarWidth = verticalScrollBar()->isVisible() ? verticalScrollBar()->sizeHint().width() : 0;
|
|
|
|
|
|
|
|
if (layoutDirection() == Qt::RightToLeft)
|
|
|
|
setViewportMargins(-scrollBarWidth, 0, 0, 0);
|
|
|
|
|
2014-08-11 19:56:52 +08:00
|
|
|
updateGeometry();
|
|
|
|
QScrollArea::resizeEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize AdjustingScrollArea::sizeHint() const
|
2014-08-11 16:00:08 +08:00
|
|
|
{
|
|
|
|
if (widget())
|
2014-08-11 23:06:57 +08:00
|
|
|
{
|
|
|
|
int scrollbarWidth = verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0;
|
|
|
|
return widget()->sizeHint() + QSize(scrollbarWidth, 0);
|
|
|
|
}
|
2014-08-11 16:00:08 +08:00
|
|
|
|
2014-08-11 19:56:52 +08:00
|
|
|
return QScrollArea::sizeHint();
|
2014-08-11 16:00:08 +08:00
|
|
|
}
|