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"
|
|
|
|
|
|
|
|
#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>
|
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"
|
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"
|
|
|
|
#include "plasma/framesvg.h"
|
|
|
|
#include "plasma/theme.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
|
|
|
|
{
|
|
|
|
|
|
|
|
class DialogPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DialogPrivate(Dialog *dialog)
|
|
|
|
: q(dialog),
|
|
|
|
background(0),
|
|
|
|
view(0),
|
2009-04-09 06:51:51 +02:00
|
|
|
graphicsWidget(0),
|
2008-11-04 00:08:39 +01:00
|
|
|
resizeCorners(Dialog::NoCorner),
|
2009-03-02 21:32:01 +01:00
|
|
|
resizeStartCorner(Dialog::NoCorner),
|
2009-09-12 02:18:26 +02:00
|
|
|
moveTimer(0)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~DialogPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
void themeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
void adjustView();
|
2009-01-23 08:33:30 +01:00
|
|
|
void updateResizeCorners();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Plasma::Dialog *q;
|
2009-01-23 08:33:30 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Holds the background SVG, to be re-rendered when the cache is invalidated,
|
|
|
|
* for example by resizing the dialogue.
|
|
|
|
*/
|
|
|
|
Plasma::FrameSvg *background;
|
|
|
|
QGraphicsView *view;
|
2009-04-09 06:51:51 +02:00
|
|
|
QGraphicsWidget *graphicsWidget;
|
2008-11-04 00:08:39 +01:00
|
|
|
Dialog::ResizeCorners resizeCorners;
|
|
|
|
QMap<Dialog::ResizeCorner, QRect> resizeAreas;
|
|
|
|
Dialog::ResizeCorner resizeStartCorner;
|
2009-03-02 21:32:01 +01:00
|
|
|
QTimer *moveTimer;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
void DialogPrivate::themeChanged()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-03-15 17:51:05 +01:00
|
|
|
qreal topHeight;
|
|
|
|
qreal leftWidth;
|
|
|
|
qreal rightWidth;
|
|
|
|
qreal bottomHeight;
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
//kDebug() << leftWidth << topHeight << rightWidth << bottomHeight;
|
2009-03-02 21:32:01 +01:00
|
|
|
|
|
|
|
FrameSvg::EnabledBorders borders = FrameSvg::AllBorders;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
Extender *extender = qobject_cast<Extender*>(graphicsWidget);
|
2008-11-04 00:08:39 +01:00
|
|
|
if (extender) {
|
2009-06-09 01:33:10 +02:00
|
|
|
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
switch (extender->d->applet->location()) {
|
|
|
|
case BottomEdge:
|
2009-03-02 21:32:01 +01:00
|
|
|
borders ^= FrameSvg::BottomBorder;
|
2009-03-15 18:31:19 +01:00
|
|
|
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:
|
2009-03-02 21:32:01 +01:00
|
|
|
borders ^= FrameSvg::TopBorder;
|
2009-03-15 18:31:19 +01:00
|
|
|
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:
|
2009-03-02 21:32:01 +01:00
|
|
|
borders ^= FrameSvg::LeftBorder;
|
2009-03-15 18:31:19 +01:00
|
|
|
leftWidth = 0;
|
|
|
|
rightWidth = 0;
|
2009-04-16 05:19:02 +02:00
|
|
|
break;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
case RightEdge:
|
2009-03-02 21:32:01 +01:00
|
|
|
borders ^= FrameSvg::RightBorder;
|
2009-04-16 05:19:02 +02:00
|
|
|
leftWidth = 0;
|
|
|
|
rightWidth = 0;
|
|
|
|
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-05-11 14:08:29 +02:00
|
|
|
} else if (q->isVisible()) {
|
2009-03-06 11:55:33 +01:00
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
QRect avail = desktop->availableGeometry(desktop->screenNumber(q));
|
2009-03-02 21:32:01 +01:00
|
|
|
QRect dialogGeom = q->geometry();
|
|
|
|
|
|
|
|
if (dialogGeom.left() <= avail.left()) {
|
|
|
|
borders ^= FrameSvg::LeftBorder;
|
|
|
|
}
|
|
|
|
if (dialogGeom.top() <= avail.top()) {
|
|
|
|
borders ^= FrameSvg::TopBorder;
|
|
|
|
}
|
|
|
|
//FIXME: that 2 pixels offset has probably something to do with kwin
|
|
|
|
if (dialogGeom.right() + 2 > avail.right()) {
|
|
|
|
borders ^= FrameSvg::RightBorder;
|
|
|
|
}
|
|
|
|
if (dialogGeom.bottom() + 2 > avail.bottom()) {
|
|
|
|
borders ^= FrameSvg::BottomBorder;
|
|
|
|
}
|
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);
|
|
|
|
|
2009-03-15 18:31:19 +01:00
|
|
|
if (!extender) {
|
|
|
|
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
|
|
|
}
|
|
|
|
|
2009-03-02 21:32:01 +01:00
|
|
|
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
2008-11-04 00:08:39 +01:00
|
|
|
q->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogPrivate::adjustView()
|
|
|
|
{
|
2009-04-09 06:51:51 +02:00
|
|
|
if (view && graphicsWidget) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QSize prevSize = q->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;
|
|
|
|
q->getContentsMargins(&left, &top, &right, &bottom);
|
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
q->setMinimumSize(qMin(int(graphicsWidget->minimumSize().width()) + left + right, QWIDGETSIZE_MAX),
|
|
|
|
qMin(int(graphicsWidget->minimumSize().height()) + top + bottom, QWIDGETSIZE_MAX));
|
|
|
|
q->setMaximumSize(qMin(int(graphicsWidget->maximumSize().width()) + left + right, QWIDGETSIZE_MAX),
|
|
|
|
qMin(int(graphicsWidget->maximumSize().height()) + top + bottom, QWIDGETSIZE_MAX));
|
|
|
|
q->resize(qMin(int(graphicsWidget->size().width()) + left + right, QWIDGETSIZE_MAX),
|
|
|
|
qMin(int(graphicsWidget->size().height()) + top + bottom, QWIDGETSIZE_MAX));
|
2008-11-04 00:08:39 +01:00
|
|
|
q->updateGeometry();
|
|
|
|
|
|
|
|
//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
|
2009-04-09 06:51:51 +02: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()));
|
|
|
|
view->setSceneRect(sceneRect);
|
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
view->resize(graphicsWidget->size().toSize());
|
|
|
|
view->centerOn(graphicsWidget);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-05-18 14:36:19 +02:00
|
|
|
//if the view resized and a border is disabled move the dialog to make sure it will still look attached to panel/screen edge
|
|
|
|
qreal topHeight;
|
|
|
|
qreal leftWidth;
|
|
|
|
qreal rightWidth;
|
|
|
|
qreal bottomHeight;
|
|
|
|
|
|
|
|
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
|
|
|
|
|
|
|
if (rightWidth == 0) {
|
|
|
|
q->move(q->pos().x() + (prevSize.width() - q->size().width()), q->pos().y());
|
|
|
|
}
|
|
|
|
if (bottomHeight == 0) {
|
|
|
|
q->move(q->pos().x(), q->pos().y() + (prevSize.height() - q->size().height()));
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (q->size() != prevSize) {
|
|
|
|
//the size of the dialog has changed, emit the signal:
|
|
|
|
emit q->dialogResized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dialog::Dialog(QWidget *parent, Qt::WindowFlags f)
|
|
|
|
: QWidget(parent, f),
|
|
|
|
d(new DialogPrivate(this))
|
|
|
|
{
|
2009-02-16 20:24:05 +01:00
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
2008-11-04 00:08:39 +01:00
|
|
|
setWindowFlags(Qt::FramelessWindowHint);
|
|
|
|
d->background = new FrameSvg(this);
|
|
|
|
d->background->setImagePath("dialogs/background");
|
|
|
|
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
d->background->resizeFrame(size());
|
|
|
|
|
2008-12-04 18:03:00 +01:00
|
|
|
QPalette pal = palette();
|
|
|
|
pal.setColor(backgroundRole(), Qt::transparent);
|
|
|
|
setPalette(pal);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeChanged()));
|
|
|
|
d->themeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (d->resizeAreas[Dialog::NorthEast].contains(event->pos()) && d->resizeCorners & Dialog::NorthEast) {
|
|
|
|
setCursor(Qt::SizeBDiagCursor);
|
|
|
|
} else if (d->resizeAreas[Dialog::NorthWest].contains(event->pos()) && d->resizeCorners & Dialog::NorthWest) {
|
|
|
|
setCursor(Qt::SizeFDiagCursor);
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthEast].contains(event->pos()) && d->resizeCorners & Dialog::SouthEast) {
|
|
|
|
setCursor(Qt::SizeFDiagCursor);
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthWest].contains(event->pos()) && d->resizeCorners & Dialog::SouthWest) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch(d->resizeStartCorner) {
|
|
|
|
case Dialog::NorthEast:
|
2008-11-14 13:31:49 +01:00
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), event->x()));
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), height() - event->y()));
|
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
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), width() - event->x()));
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), height() - event->y()));
|
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
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), width() - event->x()));
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), event->y()));
|
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
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), event->x()));
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), event->y()));
|
2008-11-04 00:08:39 +01:00
|
|
|
position = QPoint(x(), y());
|
|
|
|
break;
|
|
|
|
default:
|
2008-11-14 13:31:49 +01:00
|
|
|
newWidth = qMin(maximumWidth(), qMax(minimumWidth(), width()));
|
|
|
|
newHeight = qMin(maximumHeight(), qMax(minimumHeight(), height()));
|
2008-11-04 00:08:39 +01:00
|
|
|
position = QPoint(x(), y());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setGeometry(QRect(position, QSize(newWidth, newHeight)));
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->resizeAreas[Dialog::NorthEast].contains(event->pos()) && d->resizeCorners & Dialog::NorthEast) {
|
|
|
|
d->resizeStartCorner = Dialog::NorthEast;
|
|
|
|
|
|
|
|
} else if (d->resizeAreas[Dialog::NorthWest].contains(event->pos()) && d->resizeCorners & Dialog::NorthWest) {
|
|
|
|
d->resizeStartCorner = Dialog::NorthWest;
|
|
|
|
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthEast].contains(event->pos()) && d->resizeCorners & Dialog::SouthEast) {
|
|
|
|
d->resizeStartCorner = Dialog::SouthEast;
|
|
|
|
|
|
|
|
} else if (d->resizeAreas[Dialog::SouthWest].contains(event->pos()) && d->resizeCorners & Dialog::SouthWest) {
|
|
|
|
d->resizeStartCorner = Dialog::SouthWest;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
d->resizeStartCorner = Dialog::NoCorner;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->resizeStartCorner != Dialog::NoCorner) {
|
|
|
|
d->resizeStartCorner = Dialog::NoCorner;
|
2008-12-07 21:47:58 +01:00
|
|
|
unsetCursor();
|
2008-11-04 00:08:39 +01:00
|
|
|
emit dialogResized();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Paint) {
|
|
|
|
QPainter p(this);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.fillRect(rect(), Qt::transparent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Dialog::resizeEvent(QResizeEvent *e)
|
|
|
|
{
|
|
|
|
d->background->resizeFrame(e->size());
|
|
|
|
|
|
|
|
setMask(d->background->mask());
|
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
if (d->resizeStartCorner != Dialog::NoCorner && d->view && d->graphicsWidget) {
|
|
|
|
d->graphicsWidget->resize(d->view->size());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
QRectF sceneRect(d->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);
|
2009-04-09 06:51:51 +02:00
|
|
|
d->view->centerOn(d->graphicsWidget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-01-23 08:33:30 +01:00
|
|
|
|
|
|
|
d->updateResizeCorners();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogPrivate::updateResizeCorners()
|
|
|
|
{
|
|
|
|
const int resizeAreaMargin = 20;
|
|
|
|
const QRect r = q->rect();
|
|
|
|
|
|
|
|
resizeAreas.clear();
|
|
|
|
if (resizeCorners & Dialog::NorthEast) {
|
|
|
|
resizeAreas[Dialog::NorthEast] = QRect(r.right() - resizeAreaMargin, 0,
|
|
|
|
resizeAreaMargin, resizeAreaMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resizeCorners & Dialog::NorthWest) {
|
|
|
|
resizeAreas[Dialog::NorthWest] = QRect(0, 0, resizeAreaMargin, resizeAreaMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resizeCorners & Dialog::SouthEast) {
|
|
|
|
resizeAreas[Dialog::SouthEast] = QRect(r.right() - resizeAreaMargin,
|
|
|
|
r.bottom() - resizeAreaMargin,
|
|
|
|
resizeAreaMargin, resizeAreaMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resizeCorners & Dialog::SouthWest) {
|
|
|
|
resizeAreas[Dialog::SouthWest] = QRect(0, r.bottom() - resizeAreaMargin,
|
|
|
|
resizeAreaMargin, resizeAreaMargin);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog::setGraphicsWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
2009-04-09 06:51:51 +02:00
|
|
|
if (d->graphicsWidget) {
|
|
|
|
d->graphicsWidget->removeEventFilter(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
d->graphicsWidget = widget;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (widget) {
|
|
|
|
if (!layout()) {
|
|
|
|
QVBoxLayout *lay = new QVBoxLayout(this);
|
|
|
|
lay->setMargin(0);
|
|
|
|
lay->setSpacing(0);
|
|
|
|
}
|
|
|
|
|
2009-06-02 07:49:31 +02:00
|
|
|
d->themeChanged();
|
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());
|
|
|
|
d->adjustView();
|
|
|
|
|
|
|
|
adjustSize();
|
|
|
|
|
|
|
|
widget->installEventFilter(this);
|
|
|
|
} else {
|
|
|
|
delete d->view;
|
|
|
|
d->view = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *Dialog::graphicsWidget()
|
|
|
|
{
|
2009-04-09 06:51:51 +02:00
|
|
|
return d->graphicsWidget;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Dialog::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
2009-04-09 06:51:51 +02:00
|
|
|
if (d->resizeStartCorner == Dialog::NoCorner && watched == d->graphicsWidget &&
|
2008-11-04 00:08:39 +01:00
|
|
|
(event->type() == QEvent::GraphicsSceneResize || event->type() == QEvent::GraphicsSceneMove)) {
|
|
|
|
d->adjustView();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2009-06-02 07:49:31 +02:00
|
|
|
d->themeChanged();
|
2009-04-09 05:18:24 +02:00
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
if (d->graphicsWidget && d->view && d->graphicsWidget->size().toSize() != d->view->size()) {
|
2009-03-04 16:47:59 +01:00
|
|
|
d->adjustView();
|
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();
|
|
|
|
}
|
|
|
|
|
2009-04-09 06:51:51 +02:00
|
|
|
if (d->graphicsWidget) {
|
|
|
|
d->graphicsWidget->setFocus();
|
2009-02-23 21:15:11 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
emit dialogVisible(true);
|
|
|
|
}
|
|
|
|
|
2009-07-26 20:58:27 +02:00
|
|
|
void Dialog::focusInEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
|
|
|
if (d->view) {
|
|
|
|
d->view->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->graphicsWidget) {
|
|
|
|
d->graphicsWidget->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-02 21:32:01 +01:00
|
|
|
void Dialog::moveEvent(QMoveEvent *event)
|
|
|
|
{
|
2009-04-09 05:18:24 +02:00
|
|
|
Q_UNUSED(event)
|
|
|
|
|
2009-03-02 21:32:01 +01:00
|
|
|
if (!d->moveTimer) {
|
|
|
|
d->moveTimer = new QTimer(this);
|
|
|
|
d->moveTimer->setSingleShot(true);
|
2009-06-02 07:49:31 +02:00
|
|
|
connect(d->moveTimer, SIGNAL(timeout()), this, SLOT(themeChanged()));
|
2009-03-02 21:32:01 +01:00
|
|
|
}
|
2009-06-02 07:49:31 +02:00
|
|
|
|
2009-03-02 21:32:01 +01:00
|
|
|
d->moveTimer->start(200);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Dialog::setResizeHandleCorners(ResizeCorners corners)
|
|
|
|
{
|
2009-01-23 08:33:30 +01:00
|
|
|
if (d->resizeCorners != corners) {
|
|
|
|
d->resizeCorners = corners;
|
|
|
|
d->updateResizeCorners();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Dialog::ResizeCorners Dialog::resizeCorners() const
|
|
|
|
{
|
|
|
|
return d->resizeCorners;
|
|
|
|
}
|
|
|
|
|
2009-04-16 05:19:02 +02:00
|
|
|
void Dialog::animatedHide(Plasma::Direction direction)
|
|
|
|
{
|
2009-07-23 21:08:06 +02:00
|
|
|
if (!KWindowSystem::compositingActive()) {
|
|
|
|
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)
|
|
|
|
{
|
2009-07-23 21:08:06 +02:00
|
|
|
if (!KWindowSystem::compositingActive()) {
|
|
|
|
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
|
|
|
|
2009-09-12 02:18:26 +02:00
|
|
|
if (KWindowSystem::compositingActive()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#include "dialog.moc"
|