2007-12-05 23:32:45 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com> *
|
|
|
|
* Copyright (C) 2007 Sebastian Kuegler <sebas@kde.org> *
|
|
|
|
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dialog.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSvgRenderer>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QMouseEvent>
|
2008-01-25 17:24:40 +01:00
|
|
|
#ifdef Q_WS_X11
|
2007-12-05 23:32:45 +01:00
|
|
|
#include <QX11Info>
|
2008-01-25 17:24:40 +01:00
|
|
|
#endif
|
2008-03-05 22:03:27 +01:00
|
|
|
#include <QBitmap>
|
2007-12-05 23:32:45 +01:00
|
|
|
#include <QGraphicsView>
|
2007-12-06 00:09:28 +01:00
|
|
|
#include <QtGui/QGraphicsSceneEvent>
|
2007-12-05 23:32:45 +01:00
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
#include <NETRootInfo>
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
#include <plasma/panelsvg.h>
|
2008-02-08 21:50:55 +01:00
|
|
|
#include <plasma/theme.h>
|
2007-12-05 23:32:45 +01:00
|
|
|
|
2008-01-25 17:24:40 +01:00
|
|
|
#ifdef Q_WS_X11
|
2007-12-05 23:32:45 +01:00
|
|
|
#include <X11/Xlib.h>
|
2008-01-25 17:24:40 +01:00
|
|
|
#endif
|
2007-12-05 23:32:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-02-06 22:07:16 +01:00
|
|
|
class Dialog::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Holds the background SVG, to be re-rendered when the cache is invalidated,
|
|
|
|
* for example by resizing the dialogue.
|
|
|
|
*/
|
2008-04-16 19:23:58 +02:00
|
|
|
Plasma::PanelSvg *background;
|
2008-04-17 15:12:25 +02:00
|
|
|
Plasma::Dialog *q;
|
2008-04-17 14:45:46 +02:00
|
|
|
|
2008-04-17 15:12:25 +02:00
|
|
|
void themeUpdated()
|
2008-04-17 14:45:46 +02:00
|
|
|
{
|
|
|
|
const int topHeight = background->marginSize(Plasma::TopMargin);
|
|
|
|
const int leftWidth = background->marginSize(Plasma::LeftMargin);
|
|
|
|
const int rightWidth = background->marginSize(Plasma::RightMargin);
|
|
|
|
const int bottomHeight = background->marginSize(Plasma::BottomMargin);
|
2008-04-17 15:12:25 +02:00
|
|
|
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
2008-04-17 14:45:46 +02:00
|
|
|
};
|
2008-02-06 22:07:16 +01:00
|
|
|
};
|
2007-12-05 23:32:45 +01:00
|
|
|
|
|
|
|
Dialog::Dialog( QWidget * parent, Qt::WindowFlags f )
|
|
|
|
: QWidget(parent, f),
|
2008-02-06 22:07:16 +01:00
|
|
|
d(new Private)
|
2007-12-05 23:32:45 +01:00
|
|
|
{
|
2008-04-17 15:12:25 +02:00
|
|
|
d->q = this;
|
2008-04-16 19:23:58 +02:00
|
|
|
d->background = new PanelSvg("dialogs/background", this);
|
2008-04-16 22:17:36 +02:00
|
|
|
d->background->setEnabledBorders(PanelSvg::AllBorders);
|
2008-02-06 22:07:16 +01:00
|
|
|
d->background->resize(size());
|
|
|
|
|
|
|
|
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
2008-02-08 21:50:55 +01:00
|
|
|
|
2008-04-17 15:12:25 +02:00
|
|
|
connect(Plasma::Theme::self(), SIGNAL(changed()), this, SLOT(themeUpdated()));
|
|
|
|
d->themeUpdated();
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Dialog::~Dialog()
|
|
|
|
{
|
2008-03-20 08:44:02 +01:00
|
|
|
delete d;
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog::paintEvent(QPaintEvent *e)
|
|
|
|
{
|
|
|
|
QPainter p(this);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source );
|
|
|
|
p.fillRect(rect(), Qt::transparent);
|
2008-02-06 22:07:16 +01:00
|
|
|
d->background->paint(&p, e->rect());
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 22:07:16 +01:00
|
|
|
void Dialog::resizeEvent(QResizeEvent *e)
|
2007-12-05 23:32:45 +01:00
|
|
|
{
|
2008-02-06 22:07:16 +01:00
|
|
|
d->background->resize(e->size());
|
2008-03-05 22:03:27 +01:00
|
|
|
|
|
|
|
setMask(d->background->mask());
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
2007-12-06 00:09:28 +01:00
|
|
|
void Dialog::position(QGraphicsSceneEvent *event, const QRectF boundingRect, QPointF scenePos)
|
2007-12-05 23:32:45 +01:00
|
|
|
{
|
|
|
|
QWidget *viewWidget = event->widget() ? event->widget()->parentWidget() : 0;
|
|
|
|
//QPointF scenePos = mapToScene(boundingRect.topLeft());
|
|
|
|
QGraphicsView *view = qobject_cast<QGraphicsView*>(viewWidget);
|
2007-12-29 22:38:00 +01:00
|
|
|
position(view,boundingRect,scenePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog::position(QGraphicsView * view,const QRectF boundingRect,QPointF scenePos)
|
|
|
|
{
|
2007-12-05 23:32:45 +01:00
|
|
|
if (view) {
|
2007-12-29 22:38:00 +01:00
|
|
|
QPoint viewPos = view->mapFromScene(scenePos);
|
|
|
|
QPoint globalPos = view->mapToGlobal(viewPos);
|
|
|
|
if ((globalPos.ry()-height())< 0) {
|
|
|
|
scenePos = QPointF(scenePos.x() + boundingRect.width(), scenePos.y() + boundingRect.height());
|
|
|
|
viewPos = view->mapFromScene(scenePos);
|
|
|
|
globalPos = view->mapToGlobal(viewPos)+QPoint(0,10);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
globalPos.ry() -= (height()+10);
|
|
|
|
}
|
|
|
|
if ((globalPos.rx() + width()) > view->width()) {
|
|
|
|
globalPos.rx()-=((globalPos.rx() + width())-view->width());
|
|
|
|
}
|
|
|
|
move(globalPos);
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << globalPos;
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#include "dialog.moc"
|