2 * Copyright 2008 Marco Martin <notmart@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "positioningruler.h"
24 #include <QMouseEvent>
25 #include <QToolButton>
26 #include <QApplication>
27 #include <QDesktopWidget>
31 #include <KColorUtils>
32 #include <KWindowSystem>
34 #include <Plasma/Theme>
35 #include <Plasma/FrameSvg>
36 #include <Plasma/Containment>
39 class PositioningRuler::Private
43 : location(Plasma::BottomEdge
),
44 alignment(Qt::AlignLeft
),
51 leftMaxSliderRect(QRect(0,0,0,0)),
52 rightMaxSliderRect(QRect(0,0,0,0)),
53 leftMinSliderRect(QRect(0,0,0,0)),
54 rightMinSliderRect(QRect(0,0,0,0)),
55 offsetSliderRect(QRect(0,0,0,0)),
57 elementPrefix(QString()),
66 bool moveSlider(QRect
&sliderRect
, QRect
&symmetricSliderRect
, const QPoint
&newPos
)
68 if (location
== Plasma::LeftEdge
|| location
== Plasma::RightEdge
) {
69 if (newPos
.y() < 0 || newPos
.y() > availableLength
) {
73 if (alignment
== Qt::AlignCenter
) {
74 int newTop
= offsetSliderRect
.center().y() + (offsetSliderRect
.center().y() - newPos
.y());
75 newTop
= qBound(0, newTop
, availableLength
);
77 symmetricSliderRect
.moveCenter(QPoint(symmetricSliderRect
.center().x(), newTop
));
79 sliderRect
.moveCenter(QPoint(sliderRect
.center().x(), newPos
.y()));
81 if (newPos
.x() < 0 || newPos
.x() > availableLength
) {
85 if (alignment
== Qt::AlignCenter
) {
86 int newLeft
= offsetSliderRect
.center().x() + (offsetSliderRect
.center().x() - newPos
.x());
87 newLeft
= qBound(0, newLeft
, availableLength
);
89 symmetricSliderRect
.moveCenter(QPoint(newLeft
, symmetricSliderRect
.center().y()));
91 sliderRect
.moveCenter(QPoint(newPos
.x(), sliderRect
.center().y()));
97 int sliderRectToLength(const QRect
&sliderRect
)
102 if (location
== Plasma::LeftEdge
|| location
== Plasma::RightEdge
) {
103 sliderPos
= sliderRect
.center().y();
104 offsetPos
= offsetSliderRect
.center().y();
106 sliderPos
= sliderRect
.center().x();
107 offsetPos
= offsetSliderRect
.center().x();
110 if (alignment
== Qt::AlignCenter
) {
111 return 2 * qAbs(sliderPos
- offsetPos
);
113 return qAbs(sliderPos
- offsetPos
);
117 void loadSlidersGraphics()
119 QString elementPrefix
;
122 case Plasma::LeftEdge
:
123 elementPrefix
= "west-";
125 case Plasma::RightEdge
:
126 elementPrefix
= "east-";
128 case Plasma::TopEdge
:
129 elementPrefix
= "north-";
131 case Plasma::BottomEdge
:
133 elementPrefix
= "south-";
137 leftMaxSliderRect
.setSize(sliderGraphics
->elementSize(elementPrefix
+ "maxslider"));
138 leftMinSliderRect
.setSize(sliderGraphics
->elementSize(elementPrefix
+ "minslider"));
139 rightMaxSliderRect
.setSize(leftMinSliderRect
.size());
140 rightMinSliderRect
.setSize(leftMaxSliderRect
.size());
141 offsetSliderRect
.setSize(sliderGraphics
->elementSize(elementPrefix
+ "offsetslider"));
144 void setupSliders(const QSize
&totalSize
)
146 //FIXME: the following is waay too clumsy...
155 if (location
== Plasma::LeftEdge
|| location
== Plasma::RightEdge
) {
156 totalLength
= totalSize
.height();
158 totalLength
= totalSize
.width();
163 // Here subtracting one to everything because QRect.moveCenter(pos) moves the rect with
164 // the width/2 th pixel at pos.x (and so for y) resulting in the painted image moved
165 // one pixel to the right
166 rightMaxPos
= offset
+ maxLength
;
168 rightMinPos
= offset
+ minLength
;
173 leftMaxPos
= totalLength
- offset
- maxLength
;
175 leftMinPos
= totalLength
- offset
- minLength
;
177 offsetPos
= totalLength
- offset
;
179 case Qt::AlignCenter
:
181 leftMaxPos
= totalLength
/2 + offset
- maxLength
/2;
182 rightMaxPos
= totalLength
/2 + offset
+ maxLength
/2;
184 leftMinPos
= totalLength
/2 + offset
- minLength
/2;
185 rightMinPos
= totalLength
/2 + offset
+ minLength
/2;
187 offsetPos
= totalLength
/2 + offset
;
192 case Plasma::LeftEdge
:
193 leftMaxSliderRect
.moveCenter(QPoint(3*(totalSize
.width()/4), leftMaxPos
));
194 rightMaxSliderRect
.moveCenter(QPoint(3*(totalSize
.width()/4), rightMaxPos
));
196 leftMinSliderRect
.moveCenter(QPoint(totalSize
.width()/4, leftMinPos
));
197 rightMinSliderRect
.moveCenter(QPoint(totalSize
.width()/4, rightMinPos
));
199 offsetSliderRect
.moveCenter(QPoint(3*(totalSize
.width()/4), offsetPos
));
201 case Plasma::RightEdge
:
202 leftMaxSliderRect
.moveCenter(QPoint(totalSize
.width()/4, leftMaxPos
));
203 rightMaxSliderRect
.moveCenter(QPoint(totalSize
.width()/4, rightMaxPos
));
205 leftMinSliderRect
.moveCenter(QPoint(3*(totalSize
.width()/4), leftMinPos
));
206 rightMinSliderRect
.moveCenter(QPoint(3*(totalSize
.width()/4), rightMinPos
));
208 offsetSliderRect
.moveCenter(QPoint(totalSize
.width()/4, offsetPos
));
210 case Plasma::TopEdge
:
211 leftMaxSliderRect
.moveCenter(QPoint(leftMaxPos
, 3*(totalSize
.height()/4)));
212 rightMaxSliderRect
.moveCenter(QPoint(rightMaxPos
, 3*(totalSize
.height()/4)));
214 leftMinSliderRect
.moveCenter(QPoint(leftMinPos
, totalSize
.height()/4));
215 rightMinSliderRect
.moveCenter(QPoint(rightMinPos
, totalSize
.height()/4));
217 offsetSliderRect
.moveCenter(QPoint(offsetPos
, 3*(totalSize
.height()/4)));
219 case Plasma::BottomEdge
:
221 leftMaxSliderRect
.moveCenter(QPoint(leftMaxPos
, totalSize
.height()/4));
222 rightMaxSliderRect
.moveCenter(QPoint(rightMaxPos
, totalSize
.height()/4));
224 leftMinSliderRect
.moveCenter(QPoint(leftMinPos
, 3*(totalSize
.height()/4)));
225 rightMinSliderRect
.moveCenter(QPoint(rightMinPos
, 3*(totalSize
.height()/4)));
227 offsetSliderRect
.moveCenter(QPoint(offsetPos
, totalSize
.height()/4));
233 enum SubElement
{ NoElement
= 0,
241 Plasma::Location location
;
242 Qt::Alignment alignment
;
249 QRect leftMaxSliderRect
;
250 QRect rightMaxSliderRect
;
251 QRect leftMinSliderRect
;
252 QRect rightMinSliderRect
;
253 QRect offsetSliderRect
;
254 Plasma::FrameSvg
*sliderGraphics
;
255 QString elementPrefix
;
260 PositioningRuler::PositioningRuler(QWidget
* parent
)
264 d
->sliderGraphics
= new Plasma::FrameSvg(this);
265 d
->sliderGraphics
->setImagePath("widgets/containment-controls");
267 d
->loadSlidersGraphics();
270 PositioningRuler::~PositioningRuler()
275 QSize
PositioningRuler::sizeHint() const
277 //FIXME:why must add 6 pixels????
279 switch (d
->location
) {
280 case Plasma::LeftEdge
:
281 case Plasma::RightEdge
:
282 return QSize(d
->leftMaxSliderRect
.width() + d
->leftMinSliderRect
.width() + 6, d
->availableLength
);
284 case Plasma::TopEdge
:
285 case Plasma::BottomEdge
:
287 return QSize(d
->availableLength
, d
->leftMaxSliderRect
.height() + d
->leftMinSliderRect
.height() + 6);
293 void PositioningRuler::setLocation(const Plasma::Location
&loc
)
295 if (d
->location
== loc
) {
301 d
->setupSliders(size());
302 d
->loadSlidersGraphics();
307 Plasma::Location
PositioningRuler::location() const
312 void PositioningRuler::setAlignment(const Qt::Alignment
&align
)
314 if (d
->alignment
== align
) {
318 d
->alignment
= align
;
320 d
->setupSliders(size());
325 Qt::Alignment
PositioningRuler::alignment() const
330 void PositioningRuler::setOffset(int newOffset
)
332 d
->offset
= newOffset
;
334 d
->setupSliders(size());
338 int PositioningRuler::offset() const
343 void PositioningRuler::setMaxLength(int newMax
)
348 switch (d
->location
) {
349 case Plasma::LeftEdge
:
350 case Plasma::RightEdge
:
352 deltaY
= newMax
- d
->maxLength
;
354 case Plasma::TopEdge
:
355 case Plasma::BottomEdge
:
357 deltaX
= newMax
- d
->maxLength
;
362 if (d
->alignment
== Qt::AlignLeft
) {
363 d
->rightMaxSliderRect
.moveCenter(QPoint(d
->rightMaxSliderRect
.center().x() + deltaX
,
364 d
->rightMaxSliderRect
.center().y() + deltaY
));
365 } else if (d
->alignment
== Qt::AlignRight
) {
366 d
->leftMaxSliderRect
.moveCenter(QPoint(d
->leftMaxSliderRect
.center().x() - deltaX
,
367 d
->leftMaxSliderRect
.center().y() - deltaY
));
370 d
->rightMaxSliderRect
.moveCenter(QPoint(d
->rightMaxSliderRect
.center().x() + deltaX
/2,
371 d
->rightMaxSliderRect
.center().y() + deltaY
/2));
372 d
->leftMaxSliderRect
.moveCenter(QPoint(d
->leftMaxSliderRect
.center().x() - deltaX
/2,
373 d
->leftMaxSliderRect
.center().y() - deltaY
/2));
376 d
->maxLength
= newMax
;
377 if (d
->minLength
> d
->maxLength
) {
378 setMinLength(newMax
);
383 int PositioningRuler::maxLength() const
388 void PositioningRuler::setMinLength(int newMin
)
393 int min
= qMax(d
->minimumBound
, newMin
);
395 switch (d
->location
) {
396 case Plasma::LeftEdge
:
397 case Plasma::RightEdge
:
399 deltaY
= min
- d
->minLength
;
401 case Plasma::TopEdge
:
402 case Plasma::BottomEdge
:
404 deltaX
= min
- d
->minLength
;
410 if (d
->alignment
== Qt::AlignLeft
) {
411 d
->rightMinSliderRect
.moveCenter(QPoint(d
->rightMinSliderRect
.center().x() + deltaX
,
412 d
->rightMinSliderRect
.center().y() + deltaY
));
413 } else if (d
->alignment
== Qt::AlignRight
) {
414 d
->leftMinSliderRect
.moveCenter(QPoint(d
->leftMinSliderRect
.center().x() - deltaX
,
415 d
->leftMinSliderRect
.center().y() - deltaY
));
418 d
->rightMinSliderRect
.moveCenter(QPoint(d
->rightMinSliderRect
.center().x() + deltaX
/2,
419 d
->rightMinSliderRect
.center().y() + deltaY
/2));
420 d
->leftMinSliderRect
.moveCenter(QPoint(d
->leftMinSliderRect
.center().x() - deltaX
/2,
421 d
->leftMinSliderRect
.center().y() - deltaY
/2));
425 if (d
->minLength
> d
->maxLength
) {
431 int PositioningRuler::minLength() const
436 void PositioningRuler::setAvailableLength(int newAvail
)
438 d
->availableLength
= newAvail
;
440 if (d
->maxLength
> newAvail
) {
441 setMaxLength(newAvail
);
444 if (d
->minLength
> newAvail
) {
445 setMinLength(newAvail
);
449 int PositioningRuler::availableLength() const
451 return d
->availableLength
;
454 bool PositioningRuler::event(QEvent
*ev
)
456 //Show a different tooltip on each slider
457 if (ev
->type() == QEvent::ToolTip
) {
458 QHelpEvent
*helpEvent
= static_cast<QHelpEvent
*>(ev
);
459 if (d
->offsetSliderRect
.contains(helpEvent
->pos())) {
460 QToolTip::showText(helpEvent
->globalPos(), i18n("Move this slider to set the panel position"), this);
461 } else if ((d
->alignment
!= Qt::AlignLeft
&& d
->leftMaxSliderRect
.contains(helpEvent
->pos())) ||
462 (d
->alignment
!= Qt::AlignRight
&& d
->rightMaxSliderRect
.contains(helpEvent
->pos()))) {
463 QToolTip::showText(helpEvent
->globalPos(), i18n("Move this slider to set the maximum panel size"), this);
464 } else if ((d
->alignment
!= Qt::AlignLeft
&& d
->leftMinSliderRect
.contains(helpEvent
->pos())) ||
465 (d
->alignment
!= Qt::AlignRight
&& d
->rightMinSliderRect
.contains(helpEvent
->pos()))) {
466 QToolTip::showText(helpEvent
->globalPos(), i18n("Move this slider to set the minimum panel size"), this);
471 return QWidget::event(ev
);
475 void PositioningRuler::paintEvent(QPaintEvent
*event
)
478 d
->sliderGraphics
->setElementPrefix(d
->location
);
480 QPainter
painter(this);
482 d
->sliderGraphics
->resizeFrame(event
->rect().size());
483 d
->sliderGraphics
->paintFrame(&painter
);
485 //Draw center indicators
486 if (d
->alignment
== Qt::AlignCenter
&& (d
->location
== Plasma::LeftEdge
|| d
->location
== Plasma::RightEdge
)) {
487 QSize indicatorSize
= d
->sliderGraphics
->elementSize("vertical-centerindicator");
488 d
->sliderGraphics
->paint(&painter
, QRect(QPoint(event
->rect().left(), event
->rect().center().y()), indicatorSize
), "vertical-centerindicator");
489 //this because rect.moveCenter will cause a rect moved one pixel off respect where we need it
490 painter
.translate(0, -1);
491 } else if (d
->alignment
== Qt::AlignCenter
) {
492 QSize indicatorSize
= d
->sliderGraphics
->elementSize("horizontal-centerindicator");
493 d
->sliderGraphics
->paint(&painter
, QRect(QPoint(event
->rect().center().x(), event
->rect().top()), indicatorSize
), "horizontal-centerindicator");
494 painter
.translate(-1, 0);
498 QString elementPrefix
;
500 switch (d
->location
) {
501 case Plasma::LeftEdge
:
502 elementPrefix
= "west-";
504 case Plasma::RightEdge
:
505 elementPrefix
= "east-";
507 case Plasma::TopEdge
:
508 elementPrefix
= "north-";
510 case Plasma::BottomEdge
:
512 elementPrefix
= "south-";
516 if (d
->alignment
!= Qt::AlignLeft
) {
518 QTransform transform
;
520 switch (d
->location
) {
521 case Plasma::LeftEdge
:
522 case Plasma::RightEdge
:
523 transform
.scale(1, -1);
525 case Plasma::TopEdge
:
526 case Plasma::BottomEdge
:
528 transform
.scale(-1, 1);
532 painter
.setTransform(transform
);
533 d
->sliderGraphics
->paint(&painter
, transform
.mapRect(d
->leftMaxSliderRect
), elementPrefix
+ "maxslider");
534 d
->sliderGraphics
->paint(&painter
, transform
.mapRect(d
->leftMinSliderRect
), elementPrefix
+ "minslider");
538 if (d
->alignment
!= Qt::AlignRight
) {
539 d
->sliderGraphics
->paint(&painter
, d
->rightMaxSliderRect
, elementPrefix
+ "maxslider");
540 d
->sliderGraphics
->paint(&painter
, d
->rightMinSliderRect
, elementPrefix
+ "minslider");
543 d
->sliderGraphics
->paint(&painter
, d
->offsetSliderRect
, elementPrefix
+ "offsetslider");
546 void PositioningRuler::wheelEvent(QWheelEvent
*event
)
552 if (d
->location
== Plasma::LeftEdge
|| d
->location
== Plasma::RightEdge
) {
554 if (event
->delta() < 0) {
555 movement
= QPoint(0, 20);
557 movement
= QPoint(0, -20);
561 if (event
->delta() < 0) {
562 movement
= QPoint(20, 0);
564 movement
= QPoint(-20, 0);
568 if (d
->alignment
!= Qt::AlignLeft
&& d
->leftMaxSliderRect
.adjusted(-hMargins
, -vMargins
, hMargins
, vMargins
).contains(event
->pos())) {
569 d
->dragging
= Private::LeftMaxSlider
;
570 movement
+= d
->leftMaxSliderRect
.center();
571 } else if (d
->alignment
!= Qt::AlignRight
&& d
->rightMaxSliderRect
.adjusted(-hMargins
, -vMargins
, hMargins
, vMargins
).contains(event
->pos())) {
572 d
->dragging
= Private::RightMaxSlider
;
573 movement
+= d
->rightMaxSliderRect
.center();
574 } else if (d
->alignment
!= Qt::AlignLeft
&& d
->leftMinSliderRect
.adjusted(-hMargins
, -vMargins
, hMargins
, vMargins
).contains(event
->pos())) {
575 d
->dragging
= Private::LeftMinSlider
;
576 movement
+= d
->leftMinSliderRect
.center();
577 } else if (d
->alignment
!= Qt::AlignRight
&& d
->rightMinSliderRect
.adjusted(-hMargins
, -vMargins
, hMargins
, vMargins
).contains(event
->pos())) {
578 d
->dragging
= Private::RightMinSlider
;
579 movement
+= d
->rightMinSliderRect
.center();
580 } else if (d
->offsetSliderRect
.adjusted(-hMargins
, -vMargins
, hMargins
, vMargins
).contains(event
->pos())) {
581 d
->dragging
= Private::OffsetSlider
;
582 movement
+= d
->offsetSliderRect
.center();
584 d
->dragging
= Private::NoElement
;
587 //do a fake mouse move event that drags the slider around
588 if (d
->dragging
!= Private::NoElement
) {
589 d
->startDragPos
= QPoint(0,0);
590 QMouseEvent
mouseEvent(QEvent::MouseMove
, movement
, Qt::LeftButton
, Qt::LeftButton
, Qt::NoModifier
);
591 mouseMoveEvent(&mouseEvent
);
592 d
->dragging
= Private::NoElement
;
596 void PositioningRuler::mousePressEvent(QMouseEvent
*event
)
598 if (d
->alignment
!= Qt::AlignLeft
&& d
->leftMaxSliderRect
.contains(event
->pos())) {
599 d
->dragging
= Private::LeftMaxSlider
;
600 d
->startDragPos
= QPoint(event
->pos().x() - d
->leftMaxSliderRect
.center().x(), event
->pos().y() - d
->leftMaxSliderRect
.center().y());
601 } else if (d
->alignment
!= Qt::AlignRight
&& d
->rightMaxSliderRect
.contains(event
->pos())) {
602 d
->dragging
= Private::RightMaxSlider
;
603 d
->startDragPos
= QPoint(event
->pos().x() - d
->rightMaxSliderRect
.center().x(), event
->pos().y() - d
->rightMaxSliderRect
.center().y());
604 } else if (d
->alignment
!= Qt::AlignLeft
&& d
->leftMinSliderRect
.contains(event
->pos())) {
605 d
->dragging
= Private::LeftMinSlider
;
606 d
->startDragPos
= QPoint(event
->pos().x() - d
->leftMinSliderRect
.center().x(), event
->pos().y() - d
->leftMinSliderRect
.center().y());
607 } else if (d
->alignment
!= Qt::AlignRight
&& d
->rightMinSliderRect
.contains(event
->pos())) {
608 d
->dragging
= Private::RightMinSlider
;
609 d
->startDragPos
= QPoint(event
->pos().x() - d
->rightMinSliderRect
.center().x(), event
->pos().y() - d
->rightMinSliderRect
.center().y());
610 } else if (d
->offsetSliderRect
.contains(event
->pos())) {
611 d
->dragging
= Private::OffsetSlider
;
612 d
->startDragPos
= QPoint(event
->pos().x() - d
->offsetSliderRect
.center().x(), event
->pos().y() - d
->offsetSliderRect
.center().y());
614 d
->dragging
= Private::NoElement
;
617 QWidget::mousePressEvent(event
);
620 void PositioningRuler::mouseReleaseEvent(QMouseEvent
*event
)
624 d
->startDragPos
= QPoint(0, 0);
625 d
->dragging
= Private::NoElement
;
628 void PositioningRuler::mouseMoveEvent(QMouseEvent
*event
)
630 if (d
->dragging
== Private::NoElement
) {
634 //bound to width, height
635 QPoint newPos
= QPoint(qMin(event
->pos().x() - d
->startDragPos
.x(), width()),
636 qMin(event
->pos().y() - d
->startDragPos
.y(), height()));
638 newPos
= QPoint(qMax(newPos
.x(), 0), qMax(newPos
.y(), 0));
641 const bool horizontal
= (d
->location
== Plasma::TopEdge
|| d
->location
== Plasma::BottomEdge
);
642 const int widthBound
= d
->minimumBound
;
643 const int snapSize
= 5;
647 if (newPos
.x() <= snapSize
) {
649 } else if (qAbs(newPos
.x() - d
->availableLength
/2) <= snapSize
) {
650 newPos
.setX(d
->availableLength
/2);
651 } else if (d
->availableLength
- newPos
.x() <= snapSize
) {
652 newPos
.setX(d
->availableLength
);
655 if (newPos
.y() <= snapSize
) {
657 } else if (qAbs(newPos
.y() - d
->availableLength
/2) <= snapSize
) {
658 newPos
.setY(d
->availableLength
/2);
659 } else if (d
->availableLength
- newPos
.y() <= snapSize
) {
660 newPos
.setY(d
->availableLength
);
664 switch (d
->dragging
) {
665 case Private::LeftMaxSlider
:
666 //don't let the slider "cross" with the offset slider
667 if (horizontal
&& newPos
.x() > d
->offsetSliderRect
.left() - widthBound
) {
669 } else if (!horizontal
&& newPos
.y() > d
->offsetSliderRect
.top() - widthBound
) {
673 if (!d
->moveSlider(d
->leftMaxSliderRect
, d
->rightMaxSliderRect
, newPos
)) {
677 d
->maxLength
= d
->sliderRectToLength(d
->leftMaxSliderRect
);
679 if (d
->minLength
> d
->maxLength
) {
680 d
->moveSlider(d
->leftMinSliderRect
, d
->rightMinSliderRect
, newPos
);
681 d
->minLength
= d
->maxLength
;
684 case Private::RightMaxSlider
:
685 if (horizontal
&& newPos
.x() < d
->offsetSliderRect
.left() + widthBound
) {
687 } else if (!horizontal
&& newPos
.y() < d
->offsetSliderRect
.top() + widthBound
) {
691 if (!d
->moveSlider(d
->rightMaxSliderRect
, d
->leftMaxSliderRect
, newPos
)) {
695 d
->maxLength
= d
->sliderRectToLength(d
->rightMaxSliderRect
);
697 if (d
->minLength
> d
->maxLength
) {
698 d
->moveSlider(d
->rightMinSliderRect
, d
->leftMinSliderRect
, newPos
);
699 d
->minLength
= d
->maxLength
;
702 case Private::LeftMinSlider
:
703 if (horizontal
&& newPos
.x() > d
->offsetSliderRect
.left() - widthBound
) {
705 } else if (!horizontal
&& newPos
.y() > d
->offsetSliderRect
.top() - widthBound
) {
709 if (!d
->moveSlider(d
->leftMinSliderRect
, d
->rightMinSliderRect
, newPos
)) {
713 d
->minLength
= d
->sliderRectToLength(d
->leftMinSliderRect
);
715 if (d
->minLength
> d
->maxLength
) {
716 d
->moveSlider(d
->leftMaxSliderRect
, d
->rightMaxSliderRect
, newPos
);
717 d
->maxLength
= d
->minLength
;
720 case Private::RightMinSlider
:
721 if (horizontal
&& newPos
.x() < d
->offsetSliderRect
.left() + widthBound
) {
723 } else if (!horizontal
&& newPos
.y() < d
->offsetSliderRect
.top() + widthBound
) {
727 if (!d
->moveSlider(d
->rightMinSliderRect
, d
->leftMinSliderRect
, newPos
)) {
731 d
->minLength
= d
->sliderRectToLength(d
->rightMinSliderRect
);
733 if (d
->minLength
> d
->maxLength
) {
734 d
->moveSlider(d
->rightMaxSliderRect
, d
->leftMaxSliderRect
, newPos
);
735 d
->maxLength
= d
->minLength
;
738 case Private::OffsetSlider
:
740 if (d
->location
== Plasma::LeftEdge
|| d
->location
== Plasma::RightEdge
) {
741 d
->offsetSliderRect
.moveCenter(QPoint(d
->offsetSliderRect
.center().x(), newPos
.y()));
742 d
->offset
= d
->offsetSliderRect
.center().y();
744 d
->offsetSliderRect
.moveCenter(QPoint(newPos
.x(), d
->offsetSliderRect
.center().y()));
745 d
->offset
= d
->offsetSliderRect
.center().x();
748 if (d
->alignment
== Qt::AlignCenter
) {
749 d
->offset
-= d
->availableLength
/2;
750 } else if (d
->alignment
== Qt::AlignRight
) {
751 d
->offset
= d
->availableLength
- d
->offset
;
754 int centerFactor
= 1;
755 if (d
->alignment
== Qt::AlignCenter
) {
759 d
->maxLength
= centerFactor
*qMin(d
->maxLength
/centerFactor
, d
->availableLength
/centerFactor
- qAbs(d
->offset
));
760 d
->minLength
= centerFactor
*qMin(d
->minLength
/centerFactor
, d
->availableLength
/centerFactor
- qAbs(d
->offset
));
762 if (d
->location
== Plasma::LeftEdge
|| d
->location
== Plasma::RightEdge
) {
763 d
->leftMaxSliderRect
.moveTop(d
->offsetSliderRect
.top() - d
->maxLength
/centerFactor
);
764 d
->leftMinSliderRect
.moveTop(d
->offsetSliderRect
.top() - d
->minLength
/centerFactor
);
765 d
->rightMaxSliderRect
.moveTop(d
->offsetSliderRect
.top() + d
->maxLength
/centerFactor
);
766 d
->rightMinSliderRect
.moveTop(d
->offsetSliderRect
.top() + d
->minLength
/centerFactor
);
768 d
->leftMaxSliderRect
.moveLeft(d
->offsetSliderRect
.left() - d
->maxLength
/centerFactor
);
769 d
->leftMinSliderRect
.moveLeft(d
->offsetSliderRect
.left() - d
->minLength
/centerFactor
);
770 d
->rightMaxSliderRect
.moveLeft(d
->offsetSliderRect
.left() + d
->maxLength
/centerFactor
);
771 d
->rightMinSliderRect
.moveLeft(d
->offsetSliderRect
.left() + d
->minLength
/centerFactor
);
780 emit
rulersMoved(d
->offset
, d
->minLength
, d
->maxLength
);
784 void PositioningRuler::resizeEvent(QResizeEvent
*event
)
786 switch (d
->location
) {
787 case Plasma::LeftEdge
:
788 case Plasma::RightEdge
:
789 setAvailableLength(event
->size().height());
792 setAvailableLength(event
->size().width());
796 d
->setupSliders(event
->size());
801 #include "positioningruler.moc"