Commit 95683c61 authored by Laurent Montel's avatar Laurent Montel 😁

Change parameter order. Use Splitter as parent. Fix varialble name from private class etc.

parent 06470f46
......@@ -65,7 +65,7 @@ EditorPage::EditorPage(GrantleeThemeEditor::EditorPage::PageType type, const QSt
connect(mContactTemplate, SIGNAL(insertTemplate(QString)), mEditor->editor(), SLOT(insertPlainText(QString)));
mMainSplitter->addWidget(mContactTemplate);
mMainSplitter->setCollapsible(0, false);
new PimCommon::SplitterCollapser(mMainSplitter, mContactTemplate, this);
new PimCommon::SplitterCollapser(mContactTemplate, mMainSplitter);
connect(mEditor->editor(), SIGNAL(textChanged()), this, SIGNAL(changed()));
......
......@@ -64,7 +64,7 @@ EditorPage::EditorPage(GrantleeThemeEditor::EditorPage::PageType type, const QSt
connect(mThemeTemplate, SIGNAL(insertTemplate(QString)), mEditor->editor(), SLOT(insertPlainText(QString)));
mMainSplitter->addWidget(mThemeTemplate);
mMainSplitter->setCollapsible(0, false);
new PimCommon::SplitterCollapser(mMainSplitter, mThemeTemplate, this);
new PimCommon::SplitterCollapser(mThemeTemplate, mMainSplitter);
connect(mEditor->editor(), SIGNAL(textChanged()), this, SIGNAL(changed()));
......
......@@ -391,7 +391,7 @@ KMComposeWin::KMComposeWin( const KMime::Message::Ptr &aMsg, bool lastSignState,
mSnippetWidget->setVisible( GlobalSettings::self()->showSnippetManager() );
mSnippetSplitter->addWidget( mSnippetWidget );
mSnippetSplitter->setCollapsible( 0, false );
mSnippetSplitterCollapser = new PimCommon::SplitterCollapser(mSnippetSplitter, mSnippetWidget, this);
mSnippetSplitterCollapser = new PimCommon::SplitterCollapser(mSnippetWidget, mSnippetSplitter);
mSnippetSplitterCollapser->setVisible( GlobalSettings::self()->showSnippetManager() );
mSplitter->setOpaqueResize( true );
......
......@@ -112,7 +112,7 @@ SieveEditorTextModeWidget::SieveEditorTextModeWidget(QWidget *parent)
mTemplateSplitter->addWidget(textEditWidget);
mTemplateSplitter->addWidget(mExtraSplitter);
mTemplateSplitter->setCollapsible(0, false);
new PimCommon::SplitterCollapser(mTemplateSplitter, mExtraSplitter, this);
new PimCommon::SplitterCollapser(mExtraSplitter, mTemplateSplitter);
connect(sieveTemplateWidget, SIGNAL(insertTemplate(QString)), mTextEdit, SLOT(insertPlainText(QString)));
......
......@@ -63,11 +63,11 @@ public:
Private(SplitterCollapser *qq);
SplitterCollapser *q;
QSplitter *mSplitter;
QWidget *mWidget;
Direction mDirection;
QTimeLine *mOpacityTimeLine;
QList<int> mSizeAtCollapse;
QSplitter *splitter;
QWidget *childWidget;
Direction direction;
QTimeLine *opacityTimeLine;
QList<int> sizeAtCollapse;
bool isVertical() const;
......@@ -86,21 +86,21 @@ public:
SplitterCollapser::Private::Private(PimCommon::SplitterCollapser *qq)
: q(qq),
mSplitter(0),
mWidget(0),
mOpacityTimeLine(0)
splitter(0),
childWidget(0),
opacityTimeLine(0)
{
}
bool SplitterCollapser::Private::isVertical() const
{
return (mSplitter->orientation() == Qt::Vertical);
return (splitter->orientation() == Qt::Vertical);
}
bool SplitterCollapser::Private::isVisible() const
{
const QRect widgetRect = mWidget->geometry();
const QRect widgetRect = childWidget->geometry();
const QPoint br = widgetRect.bottomRight();
if ((br.x() <= 0) || (br.y() <= 0)) {
return false;
......@@ -113,15 +113,15 @@ void SplitterCollapser::Private::updatePosition()
{
int x = 0;
int y = 0;
const QRect widgetRect = mWidget->geometry();
const int handleWidth = mSplitter->handleWidth();
const QRect widgetRect = childWidget->geometry();
const int handleWidth = splitter->handleWidth();
if (!isVertical()) {
const int splitterWidth = mSplitter->width();
const int splitterWidth = splitter->width();
const int width = q->width();
// FIXME: Make this configurable
y = 30;
if (mDirection == LeftToRight) {
if (direction == LeftToRight) {
if (isVisible()) {
x = widgetRect.right() + handleWidth;
} else {
......@@ -137,8 +137,8 @@ void SplitterCollapser::Private::updatePosition()
} else {
x = 30;
const int height = q->height();
const int splitterHeight = mSplitter->height();
if (mDirection == TopToBottom) {
const int splitterHeight = splitter->height();
if (direction == TopToBottom) {
if (isVisible()) {
y = widgetRect.bottom() + handleWidth;
} else {
......@@ -157,7 +157,7 @@ void SplitterCollapser::Private::updatePosition()
void SplitterCollapser::Private::updateArrow()
{
q->setArrowType(isVisible() ? s_arrowDirection[mDirection].arrowVisible : s_arrowDirection[mDirection].notArrowVisible);
q->setArrowType(isVisible() ? s_arrowDirection[direction].arrowVisible : s_arrowDirection[direction].notArrowVisible);
}
void SplitterCollapser::Private::widgetEventFilter(QEvent *event)
......@@ -186,26 +186,26 @@ void SplitterCollapser::Private::updateOpacity()
const QPoint pos = q->parentWidget()->mapFromGlobal(QCursor::pos());
const QRect opaqueRect = q->geometry();
const bool opaqueCollapser = opaqueRect.contains(pos);
const int frame = mOpacityTimeLine->currentFrame();
if (opaqueCollapser && frame == mOpacityTimeLine->startFrame()) {
mOpacityTimeLine->setDirection(QTimeLine::Forward);
const int frame = opacityTimeLine->currentFrame();
if (opaqueCollapser && frame == opacityTimeLine->startFrame()) {
opacityTimeLine->setDirection(QTimeLine::Forward);
startTimeLine();
} else if (!opaqueCollapser && frame == mOpacityTimeLine->endFrame()) {
mOpacityTimeLine->setDirection(QTimeLine::Backward);
} else if (!opaqueCollapser && frame == opacityTimeLine->endFrame()) {
opacityTimeLine->setDirection(QTimeLine::Backward);
startTimeLine();
}
}
void SplitterCollapser::Private::startTimeLine()
{
if (mOpacityTimeLine->state() != QTimeLine::Running) {
mOpacityTimeLine->start();
if (opacityTimeLine->state() != QTimeLine::Running) {
opacityTimeLine->start();
}
}
SplitterCollapser::SplitterCollapser(QSplitter *splitter, QWidget *widget, QWidget *parent)
: QToolButton(parent),
SplitterCollapser::SplitterCollapser(QWidget *childWidget, QSplitter *splitter)
: QToolButton(),
d(new Private(this))
{
setObjectName(QLatin1String("splittercollapser"));
......@@ -213,32 +213,32 @@ SplitterCollapser::SplitterCollapser(QSplitter *splitter, QWidget *widget, QWidg
// splitter!
setAttribute(Qt::WA_NoChildEventsForParent);
d->mOpacityTimeLine = new QTimeLine(TIMELINE_DURATION, this);
d->mOpacityTimeLine->setFrameRange(int(MINIMUM_OPACITY * 1000), 1000);
connect(d->mOpacityTimeLine, SIGNAL(valueChanged(qreal)), SLOT(update()));
d->opacityTimeLine = new QTimeLine(TIMELINE_DURATION, this);
d->opacityTimeLine->setFrameRange(int(MINIMUM_OPACITY * 1000), 1000);
connect(d->opacityTimeLine, SIGNAL(valueChanged(qreal)), SLOT(update()));
d->mWidget = widget;
d->mWidget->installEventFilter(this);
d->childWidget = childWidget;
d->childWidget->installEventFilter(this);
qApp->installEventFilter(this);
d->mSplitter = splitter;
setParent(d->mSplitter);
d->splitter = splitter;
setParent(d->splitter);
switch(splitter->orientation()) {
case Qt::Horizontal: {
if (splitter->indexOf(widget) < splitter->count() / 2) {
d->mDirection = LeftToRight;
if (splitter->indexOf(childWidget) < splitter->count() / 2) {
d->direction = LeftToRight;
} else {
d->mDirection = RightToLeft;
d->direction = RightToLeft;
}
break;
}
case Qt::Vertical:
if (splitter->indexOf(widget) < splitter->count() / 2) {
d->mDirection = TopToBottom;
if (splitter->indexOf(childWidget) < splitter->count() / 2) {
d->direction = TopToBottom;
} else {
d->mDirection = BottomToTop;
d->direction = BottomToTop;
}
break;
}
......@@ -260,7 +260,7 @@ bool SplitterCollapser::isCollapsed() const
bool SplitterCollapser::eventFilter(QObject *object, QEvent *event)
{
if (object == d->mWidget) {
if (object == d->childWidget) {
d->widgetEventFilter(event);
} else { /* app */
if (event->type() == QEvent::MouseMove) {
......@@ -282,23 +282,23 @@ QSize SplitterCollapser::sizeHint() const
void SplitterCollapser::slotClicked()
{
QList<int> sizes = d->mSplitter->sizes();
const int index = d->mSplitter->indexOf(d->mWidget);
QList<int> sizes = d->splitter->sizes();
const int index = d->splitter->indexOf(d->childWidget);
if (d->isVisible()) {
d->mSizeAtCollapse = sizes;
d->sizeAtCollapse = sizes;
sizes[index] = 0;
} else {
if (!d->mSizeAtCollapse.isEmpty()) {
sizes = d->mSizeAtCollapse;
if (!d->sizeAtCollapse.isEmpty()) {
sizes = d->sizeAtCollapse;
} else {
if (d->isVertical()) {
sizes[index] = d->mWidget->sizeHint().height();
sizes[index] = d->childWidget->sizeHint().height();
} else {
sizes[index] = d->mWidget->sizeHint().width();
sizes[index] = d->childWidget->sizeHint().width();
}
}
}
d->mSplitter->setSizes(sizes);
d->splitter->setSizes(sizes);
}
void SplitterCollapser::collapse()
......@@ -328,20 +328,20 @@ void SplitterCollapser::setCollapsed(bool collapse)
void SplitterCollapser::paintEvent(QPaintEvent *)
{
QStylePainter painter(this);
const qreal opacity = d->mOpacityTimeLine->currentFrame() / 1000.;
const qreal opacity = d->opacityTimeLine->currentFrame() / 1000.;
painter.setOpacity(opacity);
QStyleOptionToolButton opt;
initStyleOption(&opt);
if (d->isVertical()) {
if (d->mDirection == TopToBottom) {
if (d->direction == TopToBottom) {
opt.rect.setTop(-height());
} else {
opt.rect.setHeight(height()*2);
}
} else {
if (d->mDirection == LeftToRight) {
if (d->direction == LeftToRight) {
opt.rect.setLeft(-width());
} else {
opt.rect.setWidth(width() * 2);
......
......@@ -41,11 +41,10 @@ class PIMCOMMON_EXPORT SplitterCollapser : public QToolButton
public:
/**
* @brief SplitterCollapser create a splitter collapser
* @param the splitted which this collapser should be associated with.
* @param widget the widget which be associate with splitter collapser.
* @param parent the parent widget.
* @param childWidget the widget, child of the splitter, whose size is controlled by this collapser
* @param the splitter which this collapser should be associated with.
*/
explicit SplitterCollapser(QSplitter *splitter, QWidget *widget, QWidget *parent = 0);
explicit SplitterCollapser(QWidget *childWidget, QSplitter *splitter);
~SplitterCollapser();
......
......@@ -36,9 +36,9 @@ SplitterCollapserGui_test::SplitterCollapserGui_test(int indexOfWidgetAssociateT
QTextEdit *leftTextEdit = new QTextEdit;
splitter->addWidget(leftTextEdit);
if (indexOfWidgetAssociateToSplitterCollapser == 0) {
new PimCommon::SplitterCollapser(splitter, rightTextEdit, this);
new PimCommon::SplitterCollapser(rightTextEdit, splitter);
} else {
new PimCommon::SplitterCollapser(splitter, leftTextEdit, this);
new PimCommon::SplitterCollapser(leftTextEdit, splitter);
}
}
......
......@@ -23,7 +23,8 @@
#include <qtest_kde.h>
#include <qtestmouse.h>
TestSplitter::TestSplitter(QObject *parent)
TestSplitter::TestSplitter(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *lay = new QHBoxLayout;
setLayout(lay);
......@@ -54,12 +55,13 @@ void SplitterCollapserTest::shouldHasDefaultValue()
{
TestSplitter testSplitter;
new PimCommon::SplitterCollapser(testSplitter.splitter, testSplitter.edit2);
new PimCommon::SplitterCollapser(testSplitter.edit2, testSplitter.splitter);
testSplitter.show();
QTest::qWaitForWindowShown(&testSplitter);
QVERIFY(testSplitter.isVisible());
PimCommon::SplitterCollapser *collapser = qFindChild<PimCommon::SplitterCollapser *>(&testSplitter, QLatin1String("splittercollapser"));
QVERIFY(collapser);
QVERIFY(!collapser->isCollapsed());
......@@ -76,8 +78,7 @@ void SplitterCollapserTest::shouldHasDefaultValue()
void SplitterCollapserTest::shouldCollapsedWhenClickOnButton()
{
TestSplitter testSplitter;
new PimCommon::SplitterCollapser(testSplitter.splitter, testSplitter.edit2);
new PimCommon::SplitterCollapser(testSplitter.edit2, testSplitter.splitter);
testSplitter.show();
QTest::qWaitForWindowShown(&testSplitter);
......@@ -95,7 +96,7 @@ void SplitterCollapserTest::shouldRestoreCorrectPosition()
{
TestSplitter testSplitter;
new PimCommon::SplitterCollapser(testSplitter.splitter, testSplitter.edit2);
new PimCommon::SplitterCollapser(testSplitter.edit2, testSplitter.splitter);
testSplitter.show();
QTest::qWaitForWindowShown(&testSplitter);
......@@ -122,7 +123,7 @@ void SplitterCollapserTest::shouldRestoreCorrectPositionForFirstWidget()
{
TestSplitter testSplitter;
new PimCommon::SplitterCollapser(testSplitter.splitter, testSplitter.edit1);
new PimCommon::SplitterCollapser(testSplitter.edit1, testSplitter.splitter);
testSplitter.show();
QTest::qWaitForWindowShown(&testSplitter);
......@@ -148,7 +149,7 @@ void SplitterCollapserTest::shouldTestVerticalSplitterFirstWidget()
{
TestSplitter testSplitter;
testSplitter.splitter->setOrientation(Qt::Vertical);
new PimCommon::SplitterCollapser(testSplitter.splitter, testSplitter.edit1);
new PimCommon::SplitterCollapser(testSplitter.edit1, testSplitter.splitter);
testSplitter.show();
QTest::qWaitForWindowShown(&testSplitter);
......@@ -175,7 +176,7 @@ void SplitterCollapserTest::shouldTestVerticalSplitterSecondWidget()
{
TestSplitter testSplitter;
testSplitter.splitter->setOrientation(Qt::Vertical);
new PimCommon::SplitterCollapser(testSplitter.splitter, testSplitter.edit2);
new PimCommon::SplitterCollapser(testSplitter.edit2, testSplitter.splitter);
testSplitter.show();
QTest::qWaitForWindowShown(&testSplitter);
......
......@@ -26,7 +26,7 @@ class TestSplitter : public QWidget
{
Q_OBJECT
public:
explicit TestSplitter(QObject *parent = 0);
explicit TestSplitter(QWidget *parent = 0);
QSplitter *splitter;
QTextEdit *edit1;
QTextEdit *edit2;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment