Skip to content

Commit

Permalink
fix(DTabBar): setTabMaxiumnSize is invalid
Browse files Browse the repository at this point in the history
Change-Id: I4e262c7bcb5d8a2226d1f6c34cbea9c692961d12
  • Loading branch information
zccrs committed May 17, 2018
1 parent 9fa5422 commit ff5b948
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 69 deletions.
3 changes: 0 additions & 3 deletions debian/libdtkwidget2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -1373,12 +1373,10 @@ libdtkwidget.so.2 libdtkwidget2 #MINVER#
_ZN3Dtk6Widget14DTabBarPrivate11makeVisibleEi@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate11qt_metacallEN11QMetaObject4CallEiPPv@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate11qt_metacastEPKc@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate11resizeEventEP12QResizeEvent@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate11tabInsertedEi@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate13dragMoveEventEP14QDragMoveEvent@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate13layoutWidgetsEi@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate13startTabFlashEv@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate13updateTabSizeEv@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate14autoScrollTabsERK6QPoint@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate14dragEnterEventEP15QDragEnterEvent@Base 2.0.7.2
_ZN3Dtk6Widget14DTabBarPrivate14dragLeaveEventEP15QDragLeaveEvent@Base 2.0.7.2
Expand Down Expand Up @@ -3721,7 +3719,6 @@ libdtkwidget.so.2 libdtkwidget2 #MINVER#
_ZNK3Dtk6Widget14DTabBarPrivate11tabSizeHintEi@Base 2.0.7.2
_ZNK3Dtk6Widget14DTabBarPrivate15initStyleOptionEP15QStyleOptionTabi@Base 2.0.7.2
_ZNK3Dtk6Widget14DTabBarPrivate15minimumSizeHintEv@Base 2.0.7.2
_ZNK3Dtk6Widget14DTabBarPrivate18maximumTabSizeHintEi@Base 2.0.7.2
_ZNK3Dtk6Widget14DTabBarPrivate18minimumTabSizeHintEi@Base 2.0.7.2
_ZNK3Dtk6Widget14DWaterProgress10metaObjectEv@Base 2.0.7.2
_ZNK3Dtk6Widget14DWaterProgress5valueEv@Base 2.0.7.2
Expand Down
179 changes: 113 additions & 66 deletions src/widgets/dtabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "dthememanager.h"

#include <QPainter>
#include <QApplication>
#include <QMouseEvent>
#include <QStyleOption>
#include <QStylePainter>
Expand All @@ -44,6 +43,8 @@
#undef private
#undef protected

#include "dapplication.h"

DWIDGET_BEGIN_NAMESPACE

inline static bool verticalTabs(QTabBar::Shape shape)
Expand Down Expand Up @@ -230,11 +231,9 @@ class DTabBarPrivate : public QTabBar, public DObjectPrivate
void dragMoveEvent(QDragMoveEvent *e) override;
void dropEvent(QDropEvent *e) override;
void showEvent(QShowEvent *e) override;
void resizeEvent(QResizeEvent *e) override;

QSize tabSizeHint(int index) const override;
QSize minimumTabSizeHint(int index) const override;
virtual QSize maximumTabSizeHint(int index) const;

void tabInserted(int index) override;
void tabRemoved(int index) override;
Expand All @@ -258,7 +257,6 @@ class DTabBarPrivate : public QTabBar, public DObjectPrivate
void stopAutoScrollTabs();
void ensureScrollTabsAnimation();

void updateTabSize();
void startTabFlash();

void setDragingFromOther(bool v);
Expand Down Expand Up @@ -737,28 +735,6 @@ void DTabBarPrivate::ensureScrollTabsAnimation()
});
}

void DTabBarPrivate::updateTabSize()
{
QTabBarPrivate *d = reinterpret_cast<QTabBarPrivate *>(qGetPtrHelper(d_ptr));

bool is_vertical = verticalTabs(d->shape);

for (int i = 0; i < d->tabList.count(); ++i) {
QTabBarPrivate::Tab &tab = d->tabList[i];
const QSize &size_hint = tabSizeHint(i);
const QSize old_size = tab.rect.size();

if (is_vertical) {
tab.rect.setWidth(qMax(size_hint.width(), width()));
} else {
tab.rect.setHeight(qMax(size_hint.height(), height()));
}

if (tab.rect.size() != old_size)
layoutTab(i);
}
}

void DTabBarPrivate::startTabFlash()
{
QVariantAnimation *animation = new QVariantAnimation(this);
Expand Down Expand Up @@ -1202,27 +1178,27 @@ void DTabBarPrivate::showEvent(QShowEvent *e)
QTabBar::showEvent(e);
}

void DTabBarPrivate::resizeEvent(QResizeEvent *e)
QSize DTabBarPrivate::tabSizeHint(int index) const
{
updateTabSize();
D_QC(DTabBar);

if (qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1))
return q->tabSizeHint(index);

QTabBar::resizeEvent(e);
return q->DTabBar::tabSizeHint(index);
}

QSize DTabBarPrivate::tabSizeHint(int index) const
QSize DTabBarPrivate::minimumTabSizeHint(int index) const
{
D_QC(DTabBar);

QSize size = QTabBar::tabSizeHint(index);

if (index >= tabMaximumSize.count())
return size;
const QSize &min = qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1) ? q->minimumTabSizeHint(index) : q->DTabBar::minimumTabSizeHint(index);

const QSize &min = tabMinimumSize.at(index);
const QSize &max = tabMaximumSize.at(index);
if (min.isValid())
return min;

size.setWidth(qMax(size.width(), min.width()));
size.setHeight(qMax(size.height(), min.height()));
QSize size = QTabBar::tabSizeHint(index);
const QSize &max = qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1) ? q->maximumTabSizeHint(index) : q->DTabBar::maximumTabSizeHint(index);

if (max.isValid()) {
size.setWidth(qMin(size.width(), max.width()));
Expand All @@ -1232,47 +1208,34 @@ QSize DTabBarPrivate::tabSizeHint(int index) const
return size;
}

QSize DTabBarPrivate::minimumTabSizeHint(int index) const
{
const QSize &min = tabMinimumSize.value(index);

if (min.isValid())
return min;

return QTabBar::minimumTabSizeHint(index);
}

QSize DTabBarPrivate::maximumTabSizeHint(int index) const
{
const QSize &max = tabMaximumSize.value(index);

if (max.isValid())
return max;

return QTabBar::tabSizeHint(index);
}

void DTabBarPrivate::tabInserted(int index)
{
tabMaximumSize.insert(index, QSize());
tabMinimumSize.insert(index, QSize());
D_Q(DTabBar);

QTabBar::tabInserted(index);
if (qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1))
q->tabInserted(index);
else
q->DTabBar::tabInserted(index);
}

void DTabBarPrivate::tabRemoved(int index)
{
tabMaximumSize.removeAt(index);
tabMinimumSize.removeAt(index);
D_Q(DTabBar);

QTabBar::tabInserted(index);
if (qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1))
q->tabRemoved(index);
else
q->DTabBar::tabRemoved(index);
}

void DTabBarPrivate::tabLayoutChange()
{
updateTabSize();
D_Q(DTabBar);

QTabBar::tabLayoutChange();
if (qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1))
q->tabLayoutChange();
else
q->DTabBar::tabLayoutChange();
}

void DTabBarPrivate::initStyleOption(QStyleOptionTab *option, int tabIndex) const
Expand All @@ -1296,14 +1259,28 @@ void DTabBar::setTabMinimumSize(int index, const QSize &size)
{
D_D(DTabBar);

if (d->tabMinimumSize.at(index) == size)
return;

d->tabMinimumSize[index] = size;

QTabBarPrivate *dd = reinterpret_cast<QTabBarPrivate *>(qGetPtrHelper(d->d_ptr));

dd->layoutDirty = true;
}

void DTabBar::setTabMaximumSize(int index, const QSize &size)
{
D_D(DTabBar);

if (d->tabMaximumSize.at(index) == size)
return;

d->tabMaximumSize[index] = size;

QTabBarPrivate *dd = reinterpret_cast<QTabBarPrivate *>(qGetPtrHelper(d->d_ptr));

dd->layoutDirty = true;
}

bool DTabBar::visibleAddButton() const
Expand Down Expand Up @@ -1865,6 +1842,76 @@ void DTabBar::insertFromMimeDataOnDragEnter(int index, const QMimeData *source)
startTabFlash(insertTab(index, source->text()));
}

void DTabBar::tabInserted(int index)
{
D_D(DTabBar);

d->tabMaximumSize.insert(index, QSize());
d->tabMinimumSize.insert(index, QSize());

d->QTabBar::tabInserted(index);
}

void DTabBar::tabLayoutChange()
{
D_D(DTabBar);

d->QTabBar::tabLayoutChange();
}

void DTabBar::tabRemoved(int index)
{
D_D(DTabBar);

d->tabMaximumSize.removeAt(index);
d->tabMinimumSize.removeAt(index);

d->QTabBar::tabRemoved(index);
}

QSize DTabBar::tabSizeHint(int index) const
{
D_DC(DTabBar);

QSize size = d->QTabBar::tabSizeHint(index);

QTabBarPrivate *dd = reinterpret_cast<QTabBarPrivate *>(qGetPtrHelper(d->d_ptr));
bool is_vertical = verticalTabs(dd->shape);

if (is_vertical) {
size.setWidth(qMax(size.width(), d->width()));
} else {
size.setHeight(qMax(size.height(), d->height()));
}

const QSize &min = qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1) ? minimumTabSizeHint(index) : DTabBar::minimumTabSizeHint(index);
const QSize &max = qApp->buildDtkVersion() > DTK_VERSION_CHECK(2, 0, 8, 1) ? maximumTabSizeHint(index) : DTabBar::maximumTabSizeHint(index);

size.setWidth(qMax(size.width(), min.width()));
size.setHeight(qMax(size.height(), min.height()));

if (max.isValid()) {
size.setWidth(qMin(size.width(), max.width()));
size.setHeight(qMin(size.height(), max.height()));
}

return size;
}

QSize DTabBar::minimumTabSizeHint(int index) const
{
D_DC(DTabBar);

return d->tabMinimumSize.value(index);
}

QSize DTabBar::maximumTabSizeHint(int index) const
{
D_DC(DTabBar);

return d->tabMaximumSize.value(index);
}

DTabBarPrivate *DTabBar::d_func()
{
return dynamic_cast<DTabBarPrivate*>(d_d_ptr.data());
Expand Down
8 changes: 8 additions & 0 deletions src/widgets/dtabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ public Q_SLOTS:
virtual void insertFromMimeData(int index, const QMimeData *source);
virtual void insertFromMimeDataOnDragEnter(int index, const QMimeData *source);

virtual void tabInserted(int index);
virtual void tabLayoutChange();
virtual void tabRemoved(int index);

virtual QSize tabSizeHint(int index) const;
virtual QSize minimumTabSizeHint(int index) const;
virtual QSize maximumTabSizeHint(int index) const;

private:
DTabBarPrivate* d_func();
const DTabBarPrivate* d_func() const;
Expand Down

0 comments on commit ff5b948

Please sign in to comment.