2008-11-04 00:08:39 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2008 by Alessandro Diaferia <alediaferia@gmail.com>
|
|
|
|
|
* Copyright 2007 by Alexis Ménard <darktears31@gmail.com>
|
|
|
|
|
* Copyright 2007 Sebastian Kuegler <sebas@kde.org>
|
|
|
|
|
* Copyright 2006 Aaron Seigo <aseigo@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "dialog.h"
|
2010-12-17 23:37:09 +01:00
|
|
|
|
#include "private/dialog_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QSvgRenderer>
|
|
|
|
|
#include <QResizeEvent>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
|
#include <QX11Info>
|
|
|
|
|
#endif
|
|
|
|
|
#include <QBitmap>
|
2009-03-02 21:32:01 +01:00
|
|
|
|
#include <QTimer>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QGraphicsSceneEvent>
|
|
|
|
|
#include <QtGui/QGraphicsView>
|
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
2009-03-02 21:32:01 +01:00
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopWidget>
|
2009-07-23 21:08:06 +02:00
|
|
|
|
#include <QVarLengthArray>
|
2010-05-14 14:44:46 +02:00
|
|
|
|
#include <QGraphicsLayout>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
|
#include <kdebug.h>
|
2009-04-16 05:19:02 +02:00
|
|
|
|
#include <kwindowsystem.h>
|
2008-11-04 03:39:56 +01:00
|
|
|
|
#include <netwm.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
#include "plasma/applet.h"
|
2009-04-16 05:19:02 +02:00
|
|
|
|
#include "plasma/animator.h"
|
2010-02-01 13:02:20 +01:00
|
|
|
|
#include "plasma/containment.h"
|
2010-03-23 19:52:08 +01:00
|
|
|
|
#include "plasma/corona.h"
|
2009-09-03 23:53:56 +02:00
|
|
|
|
#include "plasma/extenders/extender.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
#include "plasma/private/extender_p.h"
|
2012-11-14 20:50:52 +01:00
|
|
|
|
#include "plasma/private/dialogshadows_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
#include "plasma/framesvg.h"
|
|
|
|
|
#include "plasma/theme.h"
|
2011-01-04 17:53:31 +01:00
|
|
|
|
#include "plasma/widgets/scrollwidget.h"
|
2009-07-26 20:58:27 +02:00
|
|
|
|
#include "plasma/windoweffects.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
|
{
|
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
void DialogPrivate::scheduleBorderCheck(bool triggeredByResize)
|
|
|
|
|
{
|
|
|
|
|
//kDebug();
|
|
|
|
|
if (triggeredByResize) {
|
|
|
|
|
resizeChecksWithBorderCheck = true;
|
|
|
|
|
|
|
|
|
|
// to keep the UI as fluid as possible, we call checkBorders
|
|
|
|
|
// immediately when there is a resize, and therefore stop any
|
|
|
|
|
// move-triggered scheduled calls to it. this keeps things
|
|
|
|
|
// looking reasonable during resize while avoiding as many
|
|
|
|
|
// calls to checkBorders as possible
|
|
|
|
|
if (moveTimer) {
|
|
|
|
|
moveTimer->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkBorders();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!moveTimer) {
|
|
|
|
|
moveTimer = new QTimer(q);
|
|
|
|
|
moveTimer->setSingleShot(true);
|
|
|
|
|
QObject::connect(moveTimer, SIGNAL(timeout()), q, SLOT(checkBorders()));
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-16 16:22:16 +02:00
|
|
|
|
moveTimer->start(0);
|
2010-03-16 21:40:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
|
void DialogPrivate::themeChanged()
|
2008-11-04 00:08:39 +01:00
|
|
|
|
{
|
2010-03-16 21:40:59 +01:00
|
|
|
|
checkBorders(false);
|
2010-01-12 09:11:27 +01:00
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
const bool translucency = Plasma::Theme::defaultTheme()->windowTranslucencyEnabled();
|
|
|
|
|
// WA_NoSystemBackground is going to fail combined with sliding popups, but is needed
|
|
|
|
|
// when we aren't compositing
|
|
|
|
|
q->setAttribute(Qt::WA_NoSystemBackground, !translucency);
|
2012-11-16 15:57:35 +01:00
|
|
|
|
WindowEffects::overrideShadow(q->winId(), !DialogShadows::self()->enabled());
|
2010-03-16 21:40:59 +01:00
|
|
|
|
updateMask();
|
2011-01-19 00:04:07 +01:00
|
|
|
|
q->update();
|
2010-03-16 21:40:59 +01:00
|
|
|
|
}
|
2009-03-15 17:51:05 +01:00
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
void DialogPrivate::updateMask()
|
|
|
|
|
{
|
|
|
|
|
const bool translucency = Plasma::Theme::defaultTheme()->windowTranslucencyEnabled();
|
|
|
|
|
WindowEffects::enableBlurBehind(q->winId(), translucency,
|
|
|
|
|
translucency ? background->mask() : QRegion());
|
|
|
|
|
if (translucency) {
|
2010-03-05 23:31:04 +01:00
|
|
|
|
q->clearMask();
|
2010-01-02 21:48:44 +01:00
|
|
|
|
} else {
|
2010-03-05 23:31:04 +01:00
|
|
|
|
q->setMask(background->mask());
|
2010-01-02 21:48:44 +01:00
|
|
|
|
}
|
2010-03-16 21:40:59 +01:00
|
|
|
|
}
|
2009-03-02 21:32:01 +01:00
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
void DialogPrivate::checkBorders()
|
|
|
|
|
{
|
|
|
|
|
checkBorders(true);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-11 09:20:46 +02:00
|
|
|
|
void DialogPrivate::delayedAdjustSize()
|
|
|
|
|
{
|
2010-05-21 18:47:23 +02:00
|
|
|
|
q->syncToGraphicsWidget();
|
2010-05-11 09:20:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-31 21:48:22 +02:00
|
|
|
|
void DialogPrivate::checkBorders(bool updateMaskIfNeeded)
|
|
|
|
|
{
|
|
|
|
|
if (resizeChecksWithBorderCheck) {
|
|
|
|
|
background->resizeFrame(q->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QGraphicsWidget *graphicsWidget = graphicsWidgetPtr.data();
|
|
|
|
|
const FrameSvg::EnabledBorders currentBorders = background->enabledBorders();
|
|
|
|
|
FrameSvg::EnabledBorders borders = FrameSvg::AllBorders;
|
|
|
|
|
|
|
|
|
|
Extender *extender = qobject_cast<Extender*>(graphicsWidget);
|
2010-12-17 23:37:09 +01:00
|
|
|
|
Plasma::Applet *applet = appletPtr.data();
|
2010-02-01 13:02:20 +01:00
|
|
|
|
|
|
|
|
|
//used to remove borders at the edge of the desktop
|
2010-12-17 23:37:09 +01:00
|
|
|
|
QRect avail;
|
|
|
|
|
QRect screenGeom;
|
2010-02-01 13:02:20 +01:00
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
2010-12-17 23:37:09 +01:00
|
|
|
|
Plasma::Corona *c = 0;
|
|
|
|
|
if (applet) {
|
|
|
|
|
c = qobject_cast<Plasma::Corona *>(applet->scene());
|
|
|
|
|
} else if (graphicsWidget) {
|
|
|
|
|
c = qobject_cast<Plasma::Corona *>(graphicsWidget->scene());
|
|
|
|
|
}
|
|
|
|
|
if (c) {
|
|
|
|
|
QRegion r = c->availableScreenRegion(desktop->screenNumber(q));
|
|
|
|
|
QRect maxRect;
|
|
|
|
|
foreach (QRect rect, r.rects()) {
|
|
|
|
|
if (rect.width() > maxRect.width() && rect.height() > maxRect.height()) {
|
|
|
|
|
maxRect = rect;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
avail = maxRect;
|
|
|
|
|
screenGeom = c->screenGeometry(desktop->screenNumber(q));
|
|
|
|
|
} else {
|
|
|
|
|
avail = desktop->availableGeometry(desktop->screenNumber(q));
|
|
|
|
|
screenGeom = desktop->screenGeometry(desktop->screenNumber(q));
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-01 13:02:20 +01:00
|
|
|
|
QRect dialogGeom = q->geometry();
|
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
qreal topHeight(0);
|
|
|
|
|
qreal leftWidth(0);
|
|
|
|
|
qreal rightWidth(0);
|
|
|
|
|
qreal bottomHeight(0);
|
|
|
|
|
|
2010-02-01 13:02:20 +01:00
|
|
|
|
//decide about disabling the border attached to the panel
|
2012-07-12 11:58:58 +02:00
|
|
|
|
//don't cut borders on tooltips
|
2012-07-12 13:32:43 +02:00
|
|
|
|
if (applet && !q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip)) {
|
2009-06-09 01:33:10 +02:00
|
|
|
|
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
|
|
|
|
|
2009-10-07 15:04:09 +02:00
|
|
|
|
switch (applet->location()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
case BottomEdge:
|
2010-02-01 13:02:20 +01:00
|
|
|
|
if (applet->containment() &&
|
|
|
|
|
dialogGeom.bottom() + 2 >= screenGeom.bottom() - applet->containment()->size().height() &&
|
|
|
|
|
dialogGeom.width() <= applet->containment()->size().width()) {
|
|
|
|
|
borders &= ~FrameSvg::BottomBorder;
|
|
|
|
|
leftWidth = 0;
|
|
|
|
|
rightWidth = 0;
|
|
|
|
|
bottomHeight = 0;
|
|
|
|
|
}
|
2009-04-16 05:19:02 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
case TopEdge:
|
2010-02-01 13:02:20 +01:00
|
|
|
|
if (applet->containment() &&
|
|
|
|
|
dialogGeom.top() <= screenGeom.top() + applet->containment()->size().height() &&
|
|
|
|
|
dialogGeom.width() <= applet->containment()->size().width()) {
|
|
|
|
|
borders &= ~FrameSvg::TopBorder;
|
|
|
|
|
topHeight = 0;
|
|
|
|
|
leftWidth = 0;
|
|
|
|
|
rightWidth = 0;
|
|
|
|
|
}
|
2009-04-16 05:19:02 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
case LeftEdge:
|
2010-02-01 13:02:20 +01:00
|
|
|
|
if (applet->containment() &&
|
|
|
|
|
dialogGeom.left() <= screenGeom.left() + applet->containment()->size().width() &&
|
|
|
|
|
dialogGeom.height() <= applet->containment()->size().height()) {
|
|
|
|
|
borders &= ~FrameSvg::LeftBorder;
|
|
|
|
|
leftWidth = 0;
|
|
|
|
|
rightWidth = 0;
|
|
|
|
|
}
|
2009-04-16 05:19:02 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
case RightEdge:
|
2010-02-01 13:02:20 +01:00
|
|
|
|
if (applet->containment() &&
|
|
|
|
|
dialogGeom.right() + 2 >= screenGeom.right() - applet->containment()->size().width() &&
|
|
|
|
|
dialogGeom.height() <= applet->containment()->size().height()) {
|
|
|
|
|
borders &= ~FrameSvg::RightBorder;
|
|
|
|
|
leftWidth = 0;
|
|
|
|
|
rightWidth = 0;
|
|
|
|
|
}
|
2009-04-16 05:19:02 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
default:
|
2009-04-16 05:19:02 +02:00
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
2009-10-07 15:04:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-01 13:02:20 +01:00
|
|
|
|
//decide if to disable the other borders
|
2012-07-12 13:32:43 +02:00
|
|
|
|
if (q->isVisible() && !q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip)) {
|
2010-12-17 23:37:09 +01:00
|
|
|
|
if (dialogGeom.left() <= avail.left()) {
|
2009-10-07 15:04:09 +02:00
|
|
|
|
borders &= ~FrameSvg::LeftBorder;
|
2009-03-02 21:32:01 +01:00
|
|
|
|
}
|
2010-12-17 23:37:09 +01:00
|
|
|
|
if (dialogGeom.top() <= avail.top()) {
|
2009-10-07 15:04:09 +02:00
|
|
|
|
borders &= ~FrameSvg::TopBorder;
|
2009-03-02 21:32:01 +01:00
|
|
|
|
}
|
|
|
|
|
//FIXME: that 2 pixels offset has probably something to do with kwin
|
2010-12-17 23:37:09 +01:00
|
|
|
|
if (dialogGeom.right() + 2 > avail.right()) {
|
2009-10-07 15:04:09 +02:00
|
|
|
|
borders &= ~FrameSvg::RightBorder;
|
2009-03-02 21:32:01 +01:00
|
|
|
|
}
|
2010-12-17 23:37:09 +01:00
|
|
|
|
if (dialogGeom.bottom() + 2 > avail.bottom()) {
|
2009-10-07 15:04:09 +02:00
|
|
|
|
borders &= ~FrameSvg::BottomBorder;
|
2009-03-02 21:32:01 +01:00
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
2009-01-23 08:33:30 +01:00
|
|
|
|
|
2009-03-02 21:32:01 +01:00
|
|
|
|
background->setEnabledBorders(borders);
|
2012-11-14 20:50:52 +01:00
|
|
|
|
DialogShadows::self()->addWindow(q, borders);
|
2009-03-02 21:32:01 +01:00
|
|
|
|
|
2011-01-04 17:53:31 +01:00
|
|
|
|
if (extender) {
|
2010-12-13 17:15:49 +01:00
|
|
|
|
FrameSvg::EnabledBorders disabledBorders = FrameSvg::NoBorder;
|
|
|
|
|
if (!(borders & FrameSvg::LeftBorder)) {
|
|
|
|
|
disabledBorders |= FrameSvg::LeftBorder;
|
|
|
|
|
}
|
|
|
|
|
if (!(borders & FrameSvg::RightBorder)) {
|
|
|
|
|
disabledBorders |= FrameSvg::RightBorder;
|
|
|
|
|
}
|
|
|
|
|
extender->d->setDisabledBordersHint(disabledBorders);
|
2011-01-04 17:53:31 +01:00
|
|
|
|
|
|
|
|
|
//if there is a scrollbar, reserve a margin to not draw it over the shadow
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
|
background->getMargins(left, top, right, bottom);
|
|
|
|
|
if (extender->d->scrollWidget->viewportGeometry().height() < extender->d->scrollWidget->contentsSize().height()) {
|
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
|
leftWidth = left;
|
|
|
|
|
} else {
|
|
|
|
|
rightWidth = right;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
2009-03-15 18:31:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
//kDebug() << leftWidth << topHeight << rightWidth << bottomHeight;
|
2009-03-02 21:32:01 +01:00
|
|
|
|
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
2010-03-16 21:40:59 +01:00
|
|
|
|
|
|
|
|
|
if (resizeChecksWithBorderCheck) {
|
|
|
|
|
updateResizeCorners();
|
|
|
|
|
updateMask();
|
|
|
|
|
q->update();
|
|
|
|
|
} else if (currentBorders != borders) {
|
|
|
|
|
if (updateMaskIfNeeded) {
|
|
|
|
|
updateMask();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
q->update();
|
2010-12-13 17:15:49 +01:00
|
|
|
|
}
|
2010-03-16 21:40:59 +01:00
|
|
|
|
|
|
|
|
|
resizeChecksWithBorderCheck = false;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 23:52:08 +01:00
|
|
|
|
void Dialog::syncToGraphicsWidget()
|
2008-11-04 00:08:39 +01:00
|
|
|
|
{
|
2010-01-11 23:52:08 +01:00
|
|
|
|
d->adjustViewTimer->stop();
|
2010-01-12 09:11:27 +01:00
|
|
|
|
QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
|
2010-05-14 14:44:46 +02:00
|
|
|
|
if (d->view && graphicsWidget && d->resizeStartCorner != -1) {
|
2010-01-11 23:52:08 +01:00
|
|
|
|
const int prevStartCorner = d->resizeStartCorner;
|
|
|
|
|
d->resizeStartCorner = -1;
|
|
|
|
|
QSize prevSize = size();
|
2009-04-27 18:33:15 +02:00
|
|
|
|
/*
|
2009-04-09 06:51:51 +02:00
|
|
|
|
kDebug() << "Widget size:" << graphicsWidget->size()
|
|
|
|
|
<< "| Widget size hint:" << graphicsWidget->effectiveSizeHint(Qt::PreferredSize)
|
|
|
|
|
<< "| Widget minsize hint:" << graphicsWidget->minimumSize()
|
|
|
|
|
<< "| Widget maxsize hint:" << graphicsWidget->maximumSize()
|
|
|
|
|
<< "| Widget bounding rect:" << graphicsWidget->sceneBoundingRect();
|
2009-04-27 18:33:15 +02:00
|
|
|
|
*/
|
2008-11-04 00:08:39 +01:00
|
|
|
|
//set the sizehints correctly:
|
|
|
|
|
int left, top, right, bottom;
|
2010-01-11 23:52:08 +01:00
|
|
|
|
getContentsMargins(&left, &top, &right, &bottom);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2009-12-29 19:58:10 +01:00
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
2010-01-11 23:52:08 +01:00
|
|
|
|
QSize maxSize = desktop->availableGeometry(desktop->screenNumber(this)).size();
|
2009-12-29 19:58:10 +01:00
|
|
|
|
|
2010-08-22 11:06:37 +02:00
|
|
|
|
setMinimumSize(0, 0);
|
2010-05-14 14:44:46 +02:00
|
|
|
|
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
2010-05-21 18:47:23 +02:00
|
|
|
|
|
|
|
|
|
QSize newSize(qMin(int(graphicsWidget->size().width()) + left + right, maxSize.width()),
|
2010-05-14 14:44:46 +02:00
|
|
|
|
qMin(int(graphicsWidget->size().height()) + top + bottom, maxSize.height()));
|
|
|
|
|
|
2011-01-04 20:10:38 +01:00
|
|
|
|
const QSizeF minimum = graphicsWidget->effectiveSizeHint(Qt::MinimumSize);
|
|
|
|
|
QSize newMinimumSize(qMin(int(minimum.width()) + left + right, maxSize.width()),
|
|
|
|
|
qMin(int(minimum.height()) + top + bottom, maxSize.height()));
|
2010-05-14 14:44:46 +02:00
|
|
|
|
|
|
|
|
|
|
2010-05-21 18:47:23 +02:00
|
|
|
|
QSize newMaximumSize(qMin(int(graphicsWidget->maximumSize().width()) + left + right, maxSize.width()),
|
2010-01-12 09:11:27 +01:00
|
|
|
|
qMin(int(graphicsWidget->maximumSize().height()) + top + bottom, maxSize.height()));
|
2010-05-14 14:44:46 +02:00
|
|
|
|
|
2010-05-21 18:47:23 +02:00
|
|
|
|
|
2010-12-17 23:37:09 +01:00
|
|
|
|
Plasma::Applet *applet = d->appletPtr.data();
|
2010-05-21 18:47:23 +02:00
|
|
|
|
if (applet) {
|
|
|
|
|
QRect currentGeometry(geometry());
|
|
|
|
|
currentGeometry.setSize(newSize);
|
|
|
|
|
if (applet->location() == Plasma::TopEdge ||
|
|
|
|
|
applet->location() == Plasma::LeftEdge) {
|
|
|
|
|
currentGeometry.setSize(newSize);
|
|
|
|
|
} else if (applet->location() == Plasma::RightEdge) {
|
|
|
|
|
currentGeometry.moveTopRight(geometry().topRight());
|
|
|
|
|
//BottomEdge and floating
|
|
|
|
|
} else {
|
|
|
|
|
currentGeometry.moveBottomLeft(geometry().bottomLeft());
|
|
|
|
|
}
|
|
|
|
|
setGeometry(currentGeometry);
|
|
|
|
|
} else {
|
|
|
|
|
resize(newSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMinimumSize(newMinimumSize);
|
|
|
|
|
setMaximumSize(newMaximumSize);
|
|
|
|
|
|
|
|
|
|
|
2010-01-11 23:52:08 +01:00
|
|
|
|
updateGeometry();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
//reposition and resize the view.
|
2008-11-23 18:55:01 +01:00
|
|
|
|
//force a valid rect, otherwise it will take up the whole scene
|
2010-01-12 09:11:27 +01:00
|
|
|
|
QRectF sceneRect(graphicsWidget->sceneBoundingRect());
|
2008-11-23 18:55:01 +01:00
|
|
|
|
|
|
|
|
|
sceneRect.setWidth(qMax(qreal(1), sceneRect.width()));
|
|
|
|
|
sceneRect.setHeight(qMax(qreal(1), sceneRect.height()));
|
2010-01-11 23:52:08 +01:00
|
|
|
|
d->view->setSceneRect(sceneRect);
|
2008-11-23 18:55:01 +01:00
|
|
|
|
|
2010-05-21 18:47:23 +02:00
|
|
|
|
//d->view->resize(graphicsWidget->size().toSize());
|
2010-01-12 09:11:27 +01:00
|
|
|
|
d->view->centerOn(graphicsWidget);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2010-01-11 23:52:08 +01:00
|
|
|
|
if (size() != prevSize) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
//the size of the dialog has changed, emit the signal:
|
2010-01-11 23:52:08 +01:00
|
|
|
|
emit dialogResized();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
2010-01-11 23:52:08 +01:00
|
|
|
|
|
|
|
|
|
d->resizeStartCorner = prevStartCorner;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-18 21:11:03 +01:00
|
|
|
|
int DialogPrivate::calculateWidthForHeightAndRatio(int height, qreal ratio)
|
|
|
|
|
{
|
|
|
|
|
switch (aspectRatioMode) {
|
|
|
|
|
case KeepAspectRatio:
|
|
|
|
|
return qRound(height * ratio);
|
|
|
|
|
break;
|
|
|
|
|
case Square:
|
|
|
|
|
return height;
|
|
|
|
|
break;
|
|
|
|
|
case ConstrainedSquare:
|
|
|
|
|
return height;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
Dialog::Dialog(QWidget *parent, Qt::WindowFlags f)
|
2010-05-12 18:17:51 +02:00
|
|
|
|
: QWidget(parent, f | Qt::FramelessWindowHint),
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d(new DialogPrivate(this))
|
|
|
|
|
{
|
2011-01-19 00:04:07 +01:00
|
|
|
|
setMouseTracking(true);
|
2009-02-16 20:24:05 +01:00
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->background = new FrameSvg(this);
|
|
|
|
|
d->background->setImagePath("dialogs/background");
|
|
|
|
|
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
|
d->background->resizeFrame(size());
|
2011-01-19 00:04:07 +01:00
|
|
|
|
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(themeChanged()));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2008-12-04 18:03:00 +01:00
|
|
|
|
QPalette pal = palette();
|
|
|
|
|
pal.setColor(backgroundRole(), Qt::transparent);
|
|
|
|
|
setPalette(pal);
|
2012-11-16 15:57:35 +01:00
|
|
|
|
WindowEffects::overrideShadow(winId(), !DialogShadows::self()->enabled());
|
2008-12-04 18:03:00 +01:00
|
|
|
|
|
2009-12-16 15:19:10 +01:00
|
|
|
|
d->adjustViewTimer = new QTimer(this);
|
|
|
|
|
d->adjustViewTimer->setSingleShot(true);
|
2010-01-11 23:52:08 +01:00
|
|
|
|
connect(d->adjustViewTimer, SIGNAL(timeout()), this, SLOT(syncToGraphicsWidget()));
|
2009-12-16 15:19:10 +01:00
|
|
|
|
|
2010-05-04 23:30:52 +02:00
|
|
|
|
d->adjustSizeTimer = new QTimer(this);
|
|
|
|
|
d->adjustSizeTimer->setSingleShot(true);
|
2010-05-11 09:20:46 +02:00
|
|
|
|
connect(d->adjustSizeTimer, SIGNAL(timeout()), this, SLOT(delayedAdjustSize()));
|
2010-05-04 23:30:52 +02:00
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
|
d->themeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dialog::~Dialog()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::paintEvent(QPaintEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
2009-09-12 02:18:26 +02:00
|
|
|
|
d->background->paintFrame(&p, e->rect(), e->rect());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
|
{
|
2010-03-03 19:12:33 +01:00
|
|
|
|
if (event->modifiers() == Qt::AltModifier) {
|
|
|
|
|
unsetCursor();
|
|
|
|
|
} else if (d->resizeAreas[Dialog::NorthEast].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
setCursor(Qt::SizeBDiagCursor);
|
2009-11-11 20:43:43 +01:00
|
|
|
|
} else if (d->resizeAreas[Dialog::NorthWest].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
setCursor(Qt::SizeFDiagCursor);
|
2009-11-11 20:43:43 +01:00
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthEast].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
setCursor(Qt::SizeFDiagCursor);
|
2009-11-11 20:43:43 +01:00
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthWest].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
setCursor(Qt::SizeBDiagCursor);
|
2008-12-07 21:47:58 +01:00
|
|
|
|
} else if (!(event->buttons() & Qt::LeftButton)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
unsetCursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// here we take care of resize..
|
|
|
|
|
if (d->resizeStartCorner != Dialog::NoCorner) {
|
|
|
|
|
int newWidth;
|
|
|
|
|
int newHeight;
|
|
|
|
|
QPoint position;
|
|
|
|
|
|
2009-11-18 21:11:03 +01:00
|
|
|
|
qreal aspectRatio = (qreal)width() / (qreal)height();
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
switch(d->resizeStartCorner) {
|
|
|
|
|
case Dialog::NorthEast:
|
2008-11-14 13:31:49 +01:00
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), height() - event->y()));
|
2009-11-18 21:11:03 +01:00
|
|
|
|
newWidth = d->calculateWidthForHeightAndRatio(newHeight, aspectRatio);
|
|
|
|
|
if (newWidth == -1) {
|
|
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), event->x()));
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
position = QPoint(x(), y() + height() - newHeight);
|
|
|
|
|
break;
|
|
|
|
|
case Dialog::NorthWest:
|
2008-11-14 13:31:49 +01:00
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), height() - event->y()));
|
2009-11-18 21:11:03 +01:00
|
|
|
|
newWidth = d->calculateWidthForHeightAndRatio(newHeight, aspectRatio);
|
|
|
|
|
if (newWidth == -1) {
|
|
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), width() - event->x()));
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
position = QPoint(x() + width() - newWidth, y() + height() - newHeight);
|
|
|
|
|
break;
|
|
|
|
|
case Dialog::SouthWest:
|
2008-11-14 13:31:49 +01:00
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), event->y()));
|
2009-11-18 21:11:03 +01:00
|
|
|
|
newWidth = d->calculateWidthForHeightAndRatio(newHeight, aspectRatio);
|
|
|
|
|
if (newWidth == -1) {
|
|
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), width() - event->x()));
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
position = QPoint(x() + width() - newWidth, y());
|
|
|
|
|
break;
|
|
|
|
|
case Dialog::SouthEast:
|
2008-11-14 13:31:49 +01:00
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), event->y()));
|
2009-11-18 21:11:03 +01:00
|
|
|
|
newWidth = d->calculateWidthForHeightAndRatio(newHeight, aspectRatio);
|
|
|
|
|
if (newWidth == -1) {
|
|
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), event->x()));
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
position = QPoint(x(), y());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2008-11-14 13:31:49 +01:00
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), height()));
|
2009-11-18 21:11:03 +01:00
|
|
|
|
newWidth = d->calculateWidthForHeightAndRatio(newHeight, aspectRatio);
|
|
|
|
|
if (newWidth == -1) {
|
|
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), width()));
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
position = QPoint(x(), y());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 14:57:20 +01:00
|
|
|
|
QRect newGeom(position, QSize(newWidth, newHeight));
|
|
|
|
|
|
|
|
|
|
// now sanity check the resize results again min constraints, if any
|
|
|
|
|
if (d->leftResizeMin > -1 && newGeom.left() > d->leftResizeMin) {
|
|
|
|
|
newGeom.setLeft(d->leftResizeMin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->topResizeMin > -1 && newGeom.top() > d->topResizeMin) {
|
|
|
|
|
newGeom.setTop(d->topResizeMin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->rightResizeMin > -1 && newGeom.right() < d->rightResizeMin) {
|
|
|
|
|
newGeom.setRight(d->rightResizeMin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->bottomResizeMin > -1 && newGeom.bottom() < d->bottomResizeMin) {
|
|
|
|
|
newGeom.setBottom(d->bottomResizeMin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((newGeom.width() >= minimumSize().width()) && (newGeom.height() >= minimumSize().height())) {
|
|
|
|
|
setGeometry(newGeom);
|
2009-11-18 21:11:03 +01:00
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget::mouseMoveEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
{
|
2009-11-11 20:43:43 +01:00
|
|
|
|
if (d->resizeAreas[Dialog::NorthEast].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->resizeStartCorner = Dialog::NorthEast;
|
2009-11-11 20:43:43 +01:00
|
|
|
|
} else if (d->resizeAreas[Dialog::NorthWest].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->resizeStartCorner = Dialog::NorthWest;
|
2009-11-11 20:43:43 +01:00
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthEast].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->resizeStartCorner = Dialog::SouthEast;
|
2009-11-11 20:43:43 +01:00
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthWest].contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->resizeStartCorner = Dialog::SouthWest;
|
|
|
|
|
} else {
|
|
|
|
|
d->resizeStartCorner = Dialog::NoCorner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (d->resizeStartCorner != Dialog::NoCorner) {
|
2011-12-16 14:57:20 +01:00
|
|
|
|
emit dialogResized();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->resizeStartCorner = Dialog::NoCorner;
|
2008-12-07 21:47:58 +01:00
|
|
|
|
unsetCursor();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget::mouseReleaseEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-04 08:59:55 +01:00
|
|
|
|
void Dialog::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->key() == Qt::Key_Escape) {
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-10 19:52:26 +01:00
|
|
|
|
bool Dialog::event(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
void Dialog::resizeEvent(QResizeEvent *event)
|
2008-11-04 00:08:39 +01:00
|
|
|
|
{
|
2010-03-16 21:40:59 +01:00
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
//kDebug();
|
|
|
|
|
d->scheduleBorderCheck(true);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2010-01-12 09:11:27 +01:00
|
|
|
|
if (d->resizeStartCorner != -1 && d->view && d->graphicsWidgetPtr) {
|
|
|
|
|
QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
|
|
|
|
|
graphicsWidget->resize(d->view->size());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2010-01-12 09:11:27 +01:00
|
|
|
|
QRectF sceneRect(graphicsWidget->sceneBoundingRect());
|
2009-04-09 05:18:24 +02:00
|
|
|
|
sceneRect.setWidth(qMax(qreal(1), sceneRect.width()));
|
|
|
|
|
sceneRect.setHeight(qMax(qreal(1), sceneRect.height()));
|
|
|
|
|
d->view->setSceneRect(sceneRect);
|
2010-01-12 09:11:27 +01:00
|
|
|
|
d->view->centerOn(graphicsWidget);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
2009-01-23 08:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DialogPrivate::updateResizeCorners()
|
|
|
|
|
{
|
|
|
|
|
const int resizeAreaMargin = 20;
|
|
|
|
|
const QRect r = q->rect();
|
2009-11-11 20:43:43 +01:00
|
|
|
|
const FrameSvg::EnabledBorders borders = background->enabledBorders();
|
|
|
|
|
|
|
|
|
|
// IMPLEMENTATION NOTE: we set resize corners for the corners set, but also
|
|
|
|
|
// for the complimentary corners if we've cut out an edge of our SVG background
|
|
|
|
|
// which implies we are up against an immovable edge (e.g. a screen edge)
|
2009-01-23 08:33:30 +01:00
|
|
|
|
|
|
|
|
|
resizeAreas.clear();
|
2009-11-11 20:43:43 +01:00
|
|
|
|
if (resizeCorners & Dialog::NorthEast ||
|
|
|
|
|
(resizeCorners & Dialog::NorthWest && !(borders & FrameSvg::LeftBorder)) ||
|
|
|
|
|
(resizeCorners & Dialog::SouthEast && !(borders & FrameSvg::BottomBorder))) {
|
2009-01-23 08:33:30 +01:00
|
|
|
|
resizeAreas[Dialog::NorthEast] = QRect(r.right() - resizeAreaMargin, 0,
|
|
|
|
|
resizeAreaMargin, resizeAreaMargin);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 20:43:43 +01:00
|
|
|
|
if (resizeCorners & Dialog::NorthWest ||
|
|
|
|
|
(resizeCorners & Dialog::NorthEast && !(borders & FrameSvg::RightBorder)) ||
|
|
|
|
|
(resizeCorners & Dialog::SouthWest && !(borders & FrameSvg::BottomBorder))) {
|
2009-01-23 08:33:30 +01:00
|
|
|
|
resizeAreas[Dialog::NorthWest] = QRect(0, 0, resizeAreaMargin, resizeAreaMargin);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 20:43:43 +01:00
|
|
|
|
if (resizeCorners & Dialog::SouthEast ||
|
|
|
|
|
(resizeCorners & Dialog::SouthWest && !(borders & FrameSvg::LeftBorder)) ||
|
|
|
|
|
(resizeCorners & Dialog::NorthEast && !(borders & FrameSvg::TopBorder))) {
|
2009-01-23 08:33:30 +01:00
|
|
|
|
resizeAreas[Dialog::SouthEast] = QRect(r.right() - resizeAreaMargin,
|
|
|
|
|
r.bottom() - resizeAreaMargin,
|
|
|
|
|
resizeAreaMargin, resizeAreaMargin);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 20:43:43 +01:00
|
|
|
|
if (resizeCorners & Dialog::SouthWest ||
|
|
|
|
|
(resizeCorners & Dialog::SouthEast && !(borders & FrameSvg::RightBorder)) ||
|
|
|
|
|
(resizeCorners & Dialog::NorthWest && !(borders & FrameSvg::TopBorder))) {
|
2009-01-23 08:33:30 +01:00
|
|
|
|
resizeAreas[Dialog::SouthWest] = QRect(0, r.bottom() - resizeAreaMargin,
|
|
|
|
|
resizeAreaMargin, resizeAreaMargin);
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::setGraphicsWidget(QGraphicsWidget *widget)
|
|
|
|
|
{
|
2010-01-12 09:11:27 +01:00
|
|
|
|
if (d->graphicsWidgetPtr) {
|
|
|
|
|
d->graphicsWidgetPtr.data()->removeEventFilter(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-12 09:11:27 +01:00
|
|
|
|
d->graphicsWidgetPtr = widget;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
if (widget) {
|
2010-08-02 21:29:45 +02:00
|
|
|
|
Plasma::Corona *c = qobject_cast<Plasma::Corona *>(widget->scene());
|
|
|
|
|
if (c) {
|
|
|
|
|
c->addOffscreenWidget(widget);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
if (!layout()) {
|
|
|
|
|
QVBoxLayout *lay = new QVBoxLayout(this);
|
|
|
|
|
lay->setMargin(0);
|
|
|
|
|
lay->setSpacing(0);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 21:40:59 +01:00
|
|
|
|
d->checkBorders();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
if (!d->view) {
|
|
|
|
|
d->view = new QGraphicsView(this);
|
2008-11-23 20:24:49 +01:00
|
|
|
|
d->view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
d->view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
d->view->setFrameShape(QFrame::NoFrame);
|
|
|
|
|
d->view->viewport()->setAutoFillBackground(false);
|
|
|
|
|
layout()->addWidget(d->view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->view->setScene(widget->scene());
|
2010-05-14 14:44:46 +02:00
|
|
|
|
|
|
|
|
|
//try to have the proper size -before- showing the dialog
|
|
|
|
|
d->view->centerOn(widget);
|
|
|
|
|
if (widget->layout()) {
|
|
|
|
|
widget->layout()->activate();
|
|
|
|
|
}
|
|
|
|
|
static_cast<QGraphicsLayoutItem *>(widget)->updateGeometry();
|
|
|
|
|
widget->resize(widget->size().expandedTo(widget->effectiveSizeHint(Qt::MinimumSize)));
|
|
|
|
|
|
2010-01-11 23:52:08 +01:00
|
|
|
|
syncToGraphicsWidget();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
2010-05-14 14:44:46 +02:00
|
|
|
|
//d->adjustSizeTimer->start(150);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
|
|
widget->installEventFilter(this);
|
2010-04-15 11:49:44 +02:00
|
|
|
|
d->view->installEventFilter(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
} else {
|
|
|
|
|
delete d->view;
|
|
|
|
|
d->view = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-08 22:46:56 +02:00
|
|
|
|
//KDE5 FIXME: should be const
|
2008-11-04 00:08:39 +01:00
|
|
|
|
QGraphicsWidget *Dialog::graphicsWidget()
|
|
|
|
|
{
|
2010-01-12 09:11:27 +01:00
|
|
|
|
return d->graphicsWidgetPtr.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Dialog::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
|
{
|
2010-01-12 09:11:27 +01:00
|
|
|
|
if (d->resizeStartCorner == Dialog::NoCorner && watched == d->graphicsWidgetPtr.data() &&
|
2008-11-04 00:08:39 +01:00
|
|
|
|
(event->type() == QEvent::GraphicsSceneResize || event->type() == QEvent::GraphicsSceneMove)) {
|
2009-12-16 15:19:10 +01:00
|
|
|
|
d->adjustViewTimer->start(150);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-15 11:49:44 +02:00
|
|
|
|
// when moving the cursor with a 45<34> angle from the outside
|
|
|
|
|
// to the inside passing over a resize angle the cursor changes its
|
|
|
|
|
// shape to a resize cursor. As a side effect this is the only case
|
|
|
|
|
// when the cursor immediately enters the view without giving
|
|
|
|
|
// the dialog the chance to restore the original cursor shape.
|
|
|
|
|
if (event->type() == QEvent::Enter && watched == d->view) {
|
|
|
|
|
unsetCursor();
|
|
|
|
|
}
|
2010-05-08 22:46:56 +02:00
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::hideEvent(QHideEvent * event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
emit dialogVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::showEvent(QShowEvent * event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
2008-12-28 13:54:48 +01:00
|
|
|
|
|
|
|
|
|
//check if the widget size is still synced with the view
|
2010-03-16 21:40:59 +01:00
|
|
|
|
d->checkBorders();
|
2009-11-11 20:43:43 +01:00
|
|
|
|
d->updateResizeCorners();
|
2009-04-09 05:18:24 +02:00
|
|
|
|
|
2010-01-12 09:11:27 +01:00
|
|
|
|
QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
|
2010-04-08 22:31:29 +02:00
|
|
|
|
if (graphicsWidget &&
|
|
|
|
|
((d->view && graphicsWidget->size().toSize() != d->view->size()) ||
|
|
|
|
|
d->oldGraphicsWidgetMinimumSize != graphicsWidget->minimumSize() ||
|
|
|
|
|
d->oldGraphicsWidgetMaximumSize != graphicsWidget->maximumSize())) {
|
2010-05-14 14:44:46 +02:00
|
|
|
|
//here have to be done immediately, ideally should have to be done -before- shwing, but is not possible to catch show() so early
|
2010-01-11 23:52:08 +01:00
|
|
|
|
syncToGraphicsWidget();
|
2010-04-08 22:31:29 +02:00
|
|
|
|
d->oldGraphicsWidgetMinimumSize = graphicsWidget->minimumSize().toSize();
|
|
|
|
|
d->oldGraphicsWidgetMaximumSize = graphicsWidget->maximumSize().toSize();
|
2008-12-28 13:54:48 +01:00
|
|
|
|
}
|
2009-01-23 08:33:30 +01:00
|
|
|
|
|
2009-02-23 21:15:11 +01:00
|
|
|
|
if (d->view) {
|
|
|
|
|
d->view->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-12 09:11:27 +01:00
|
|
|
|
if (graphicsWidget) {
|
|
|
|
|
graphicsWidget->setFocus();
|
2009-02-23 21:15:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
emit dialogVisible(true);
|
2012-11-16 15:57:35 +01:00
|
|
|
|
WindowEffects::overrideShadow(winId(), !DialogShadows::self()->enabled());
|
2012-11-14 20:50:52 +01:00
|
|
|
|
DialogShadows::self()->addWindow(this, d->background->enabledBorders());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-26 20:58:27 +02:00
|
|
|
|
void Dialog::focusInEvent(QFocusEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
|
|
|
|
|
if (d->view) {
|
|
|
|
|
d->view->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-12 09:11:27 +01:00
|
|
|
|
QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
|
|
|
|
|
if (graphicsWidget) {
|
|
|
|
|
graphicsWidget->setFocus();
|
2009-07-26 20:58:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-02 21:32:01 +01:00
|
|
|
|
void Dialog::moveEvent(QMoveEvent *event)
|
|
|
|
|
{
|
2009-04-09 05:18:24 +02:00
|
|
|
|
Q_UNUSED(event)
|
2010-03-16 21:40:59 +01:00
|
|
|
|
//kDebug();
|
|
|
|
|
d->scheduleBorderCheck();
|
2009-03-02 21:32:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
void Dialog::setResizeHandleCorners(ResizeCorners corners)
|
|
|
|
|
{
|
2009-11-18 21:11:03 +01:00
|
|
|
|
if ((d->resizeCorners != corners) && (aspectRatioMode() != FixedSize)) {
|
2009-01-23 08:33:30 +01:00
|
|
|
|
d->resizeCorners = corners;
|
|
|
|
|
d->updateResizeCorners();
|
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dialog::ResizeCorners Dialog::resizeCorners() const
|
|
|
|
|
{
|
|
|
|
|
return d->resizeCorners;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 14:57:20 +01:00
|
|
|
|
bool Dialog::isUserResizing() const
|
|
|
|
|
{
|
|
|
|
|
return d->resizeStartCorner > NoCorner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::setMinimumResizeLimits(int left, int top, int right, int bottom)
|
|
|
|
|
{
|
|
|
|
|
d->leftResizeMin = left;
|
|
|
|
|
d->topResizeMin = top;
|
|
|
|
|
d->rightResizeMin = right;
|
|
|
|
|
d->bottomResizeMin = bottom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::getMinimumResizeLimits(int *left, int *top, int *right, int *bottom)
|
|
|
|
|
{
|
|
|
|
|
if (left) {
|
|
|
|
|
*left = d->leftResizeMin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (top) {
|
|
|
|
|
*top = d->topResizeMin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (right) {
|
|
|
|
|
*right = d->rightResizeMin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bottom) {
|
|
|
|
|
*bottom = d->bottomResizeMin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-16 05:19:02 +02:00
|
|
|
|
void Dialog::animatedHide(Plasma::Direction direction)
|
|
|
|
|
{
|
2011-08-03 16:42:51 +02:00
|
|
|
|
if (!isVisible()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-08 12:53:25 +01:00
|
|
|
|
if (!Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
|
2009-07-23 21:08:06 +02:00
|
|
|
|
hide();
|
2009-04-16 05:19:02 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-26 20:58:27 +02:00
|
|
|
|
Location location = Desktop;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
switch (direction) {
|
2009-07-26 20:58:27 +02:00
|
|
|
|
case Down:
|
|
|
|
|
location = BottomEdge;
|
|
|
|
|
break;
|
|
|
|
|
case Right:
|
|
|
|
|
location = RightEdge;
|
|
|
|
|
break;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
case Left:
|
2009-07-26 20:58:27 +02:00
|
|
|
|
location = LeftEdge;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
break;
|
|
|
|
|
case Up:
|
2009-07-26 20:58:27 +02:00
|
|
|
|
location = TopEdge;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2009-07-26 20:58:27 +02:00
|
|
|
|
break;
|
2009-04-16 05:19:02 +02:00
|
|
|
|
}
|
2009-07-23 21:08:06 +02:00
|
|
|
|
|
2009-07-28 15:50:48 +02:00
|
|
|
|
Plasma::WindowEffects::slideWindow(this, location);
|
2009-07-23 21:08:06 +02:00
|
|
|
|
hide();
|
2009-04-16 05:19:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-16 06:19:03 +02:00
|
|
|
|
void Dialog::animatedShow(Plasma::Direction direction)
|
|
|
|
|
{
|
2011-12-08 12:53:25 +01:00
|
|
|
|
if (!Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
|
2009-07-23 21:08:06 +02:00
|
|
|
|
show();
|
2009-04-16 06:19:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-26 20:58:27 +02:00
|
|
|
|
//copied to not add new api
|
|
|
|
|
Location location = Desktop;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
switch (direction) {
|
2009-07-26 20:58:27 +02:00
|
|
|
|
case Up:
|
|
|
|
|
location = BottomEdge;
|
|
|
|
|
break;
|
|
|
|
|
case Left:
|
|
|
|
|
location = RightEdge;
|
|
|
|
|
break;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
case Right:
|
2009-07-26 20:58:27 +02:00
|
|
|
|
location = LeftEdge;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
break;
|
|
|
|
|
case Down:
|
2009-07-26 20:58:27 +02:00
|
|
|
|
location = TopEdge;
|
2009-07-23 21:08:06 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2009-07-26 20:58:27 +02:00
|
|
|
|
break;
|
2009-04-16 06:19:03 +02:00
|
|
|
|
}
|
2009-07-23 21:08:06 +02:00
|
|
|
|
|
2011-12-08 12:53:25 +01:00
|
|
|
|
if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
|
2009-09-12 02:18:26 +02:00
|
|
|
|
Plasma::WindowEffects::slideWindow(this, location);
|
2009-04-16 06:19:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-12 02:18:26 +02:00
|
|
|
|
show();
|
2009-04-16 05:19:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
bool Dialog::inControlArea(const QPoint &point)
|
|
|
|
|
{
|
|
|
|
|
foreach (const QRect &r, d->resizeAreas) {
|
|
|
|
|
if (r.contains(point)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-18 21:11:03 +01:00
|
|
|
|
Plasma::AspectRatioMode Dialog::aspectRatioMode() const
|
|
|
|
|
{
|
|
|
|
|
return d->aspectRatioMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog::setAspectRatioMode(Plasma::AspectRatioMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == FixedSize) {
|
|
|
|
|
setResizeHandleCorners(NoCorner);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->aspectRatioMode = mode;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
}
|
|
|
|
|
#include "dialog.moc"
|