dtkSplitter.cpp 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Version: $Id$
//
//

// Commentary:
//
//

// Change Log:
//
//

// Code:
Julien Wintz's avatar
Julien Wintz committed
14

15
#include "dtkSplitter.h"
Julien Wintz's avatar
Julien Wintz committed
16 17

// /////////////////////////////////////////////////////////////////
18
// dtkSplitterHandle
Julien Wintz's avatar
Julien Wintz committed
19 20
// /////////////////////////////////////////////////////////////////

21
class dtkSplitterHandle : public QSplitterHandle
Julien Wintz's avatar
Julien Wintz committed
22 23
{
public:
24 25 26
    dtkSplitterHandle(Qt::Orientation orientation, bool slim, QSplitter *parent);

public:
Julien Wintz's avatar
Julien Wintz committed
27 28
    QSize sizeHint(void) const;

29
protected:
30
    void paintEvent(QPaintEvent *event);
31

Julien Wintz's avatar
Julien Wintz committed
32 33 34 35
private:
    bool m_slim;
};

36
dtkSplitterHandle::dtkSplitterHandle(Qt::Orientation orientation, bool slim, QSplitter *parent) : QSplitterHandle(orientation, parent)
Julien Wintz's avatar
Julien Wintz committed
37 38 39 40
{
    this->m_slim = slim;
}

41
void dtkSplitterHandle::paintEvent(QPaintEvent *event)
Julien Wintz's avatar
Julien Wintz committed
42 43 44 45
{
    Q_UNUSED(event);

    QPainter painter(this);
46

Julien Wintz's avatar
Julien Wintz committed
47 48 49 50
    QColor topColor(145, 145, 145);
    QColor bottomColor(142, 142, 142);
    QColor gradientStart(252, 252, 252);
    QColor gradientStop(223, 223, 223);
51

Julien Wintz's avatar
Julien Wintz committed
52
    if (orientation() == Qt::Vertical) {
53 54 55
        painter.setPen(topColor);
        painter.drawLine(0, 0, width(), 0);

56
        if (m_slim)
57 58 59
            return;

        painter.setPen(bottomColor);
60
        painter.drawLine(0, height() - 1, width(), height() - 1);
61

62
        QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height() - 3));
63 64
        linearGrad.setColorAt(0, gradientStart);
        linearGrad.setColorAt(1, gradientStop);
65
        painter.fillRect(QRect(QPoint(0, 1), size() - QSize(0, 2)), QBrush(linearGrad));
66

Julien Wintz's avatar
Julien Wintz committed
67
    } else {
68 69 70

        painter.setPen(topColor);
        painter.drawLine(0, 0, 0, height());
Julien Wintz's avatar
Julien Wintz committed
71 72 73
    }
}

74
QSize dtkSplitterHandle::sizeHint(void) const
Julien Wintz's avatar
Julien Wintz committed
75 76
{
    QSize parent = QSplitterHandle::sizeHint();
77

Julien Wintz's avatar
Julien Wintz committed
78
    if (orientation() == Qt::Vertical) {
79
        return m_slim ? QSize(parent.width(), 1) : parent + QSize(0, 3);
Julien Wintz's avatar
Julien Wintz committed
80
    } else {
81
        return QSize(1, parent.height());
Julien Wintz's avatar
Julien Wintz committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    }
}

// /////////////////////////////////////////////////////////////////
// dtkSplitterPrivate
// /////////////////////////////////////////////////////////////////

class dtkSplitterPrivate
{
public:
    bool slim;
};

// /////////////////////////////////////////////////////////////////
// dtkSplitter
// /////////////////////////////////////////////////////////////////

99
dtkSplitter::dtkSplitter(QWidget *parent, bool slim) : QSplitter(parent), d(new dtkSplitterPrivate)
Julien Wintz's avatar
Julien Wintz committed
100 101 102 103 104 105 106 107 108 109 110 111 112
{
    d->slim = slim;
}

dtkSplitter::~dtkSplitter(void)
{
    delete d;

    d = NULL;
}

QSplitterHandle *dtkSplitter::createHandle(void)
{
113
    return new dtkSplitterHandle(orientation(), d->slim, this);
Julien Wintz's avatar
Julien Wintz committed
114
}
115 116 117

//
// dtkSplitter.cpp ends here