9#include "splittercollapser.h"
11#include <QApplication>
15#include <QStyleOptionToolButton>
16#include <QStylePainter>
27 BTT = Vertical + (1 << 1)
30const int TIMELINE_DURATION = 500;
32const qreal MINIMUM_OPACITY = 0.3;
39 : visible(t1), notVisible(t2) {}
46 return isVisible ? visible : notVisible;
50struct SplitterCollapserPrivate {
58 bool isVertical()
const
63 bool isVisible()
const
69 if ((br.
x() <= 0) || (br.
y() <= 0)) {
80 int splitterWidth = mSplitter->
width();
82 int width = q->width();
87 if (mDirection == LTR) {
89 x = widgetRect.
right() + handleWidth;
95 x = widgetRect.
left() - handleWidth - width;
97 x = splitterWidth - handleWidth - width;
111 if (arrowForDirection.
isEmpty()) {
117 q->setArrowType(arrowForDirection[mDirection].
get(isVisible()));
120 void widgetEventFilter(
QEvent *event)
122 switch (
event->type()) {
144 QRect opaqueRect = q->geometry();
145 bool opaqueCollapser = opaqueRect.
contains(pos);
147 if (opaqueCollapser && frame == mOpacityTimeLine->
startFrame()) {
150 }
else if (!opaqueCollapser && frame == mOpacityTimeLine->
endFrame()) {
159 mOpacityTimeLine->
start();
166 d(new SplitterCollapserPrivate)
174 d->mOpacityTimeLine =
new QTimeLine(TIMELINE_DURATION,
this);
175 d->mOpacityTimeLine->setFrameRange(
int(MINIMUM_OPACITY * 1000), 1000);
176 connect(d->mOpacityTimeLine, SIGNAL(valueChanged(qreal)), SLOT(
update()));
181 qApp->installEventFilter(
this);
183 d->mSplitter = splitter;
184 setParent(d->mSplitter);
186 if (splitter->
indexOf(widget) < splitter->
count() / 2) {
193 d->mDirection =
static_cast<Direction
>(int(d->mDirection) + int(TTB));
196 connect(
this, SIGNAL(clicked()), SLOT(slotClicked()));
201SplitterCollapser::~SplitterCollapser()
206bool SplitterCollapser::eventFilter(
QObject *
object,
QEvent *event)
208 if (
object == d->mWidget) {
209 d->widgetEventFilter(event);
218QSize SplitterCollapser::sizeHint()
const
221 QSize sh(extent * 3 / 4, extent * 240 / 100);
222 if (d->isVertical()) {
228void SplitterCollapser::slotClicked()
231 int index = d->mSplitter->
indexOf(d->mWidget);
232 if (d->isVisible()) {
233 d->mSizeAtCollaps = sizes[index];
236 if (d->mSizeAtCollaps != 0) {
237 sizes[index] = d->mSizeAtCollaps;
239 if (d->isVertical()) {
240 sizes[index] = d->mWidget->sizeHint().height();
242 sizes[index] = d->mWidget->sizeHint().width();
246 d->mSplitter->setSizes(sizes);
249void SplitterCollapser::slotCollapse()
251 if (d->isVisible()) {
257void SplitterCollapser::slotRestore()
259 if (!d->isVisible()) {
265void SplitterCollapser::slotSetCollapsed(
bool collapse)
267 if (collapse == d->isVisible()) {
276 qreal opacity = d->mOpacityTimeLine->currentFrame() / 1000.;
277 painter.setOpacity(opacity);
280 initStyleOption(&opt);
281 if (d->mDirection == LTR) {
282 opt.rect.setLeft(-width());
284 opt.rect.setWidth(width() * 2);
289 initStyleOption(&opt2);
295#include "moc_splittercollapser.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
void update(Part *part, const QByteArray &data, qint64 dataSize)
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
qsizetype indexOf(const AT &value, qsizetype from) const const
bool isEmpty() const const
void installEventFilter(QObject *filterObj)
QPoint bottomRight() const const
bool contains(const QPoint &point, bool proper) const const
int indexOf(QWidget *widget) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
int currentFrame() const const
void setDirection(Direction direction)
int endFrame() const const
int startFrame() const const
State state() const const