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>
|
2008-08-06 22:41:10 +02:00
|
|
|
#include <QtGui/QVBoxLayout>
|
2007-12-06 00:09:28 +01:00
|
|
|
#include <QtGui/QGraphicsSceneEvent>
|
2008-08-06 22:41:10 +02:00
|
|
|
#include <QtGui/QGraphicsView>
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
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-07-01 20:56:43 +02:00
|
|
|
class DialogPrivate
|
2008-02-06 22:07:16 +01:00
|
|
|
{
|
|
|
|
public:
|
2008-08-06 22:41:10 +02:00
|
|
|
DialogPrivate(Dialog *dialog)
|
|
|
|
: q(dialog),
|
|
|
|
background(0),
|
|
|
|
view(0),
|
|
|
|
widget(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~DialogPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void themeUpdated();
|
|
|
|
void adjustView();
|
|
|
|
|
|
|
|
|
|
|
|
Plasma::Dialog *q;
|
2008-02-06 22:07:16 +01:00
|
|
|
/**
|
|
|
|
* 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-08-06 22:41:10 +02:00
|
|
|
QGraphicsView *view;
|
|
|
|
QGraphicsWidget *widget;
|
2008-02-06 22:07:16 +01:00
|
|
|
};
|
2007-12-05 23:32:45 +01:00
|
|
|
|
2008-08-06 22:41:10 +02:00
|
|
|
void DialogPrivate::themeUpdated()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogPrivate::adjustView()
|
|
|
|
{
|
|
|
|
if (view && widget) {
|
|
|
|
view->setSceneRect(widget->mapToScene(widget->boundingRect()).boundingRect());
|
|
|
|
view->resize(widget->size().toSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 23:32:45 +01:00
|
|
|
Dialog::Dialog( QWidget * parent, Qt::WindowFlags f )
|
|
|
|
: QWidget(parent, f),
|
2008-08-06 22:41:10 +02:00
|
|
|
d(new DialogPrivate(this))
|
2007-12-05 23:32:45 +01:00
|
|
|
{
|
2008-04-23 15:07:41 +02:00
|
|
|
d->background = new PanelSvg(this);
|
|
|
|
d->background->setImagePath("dialogs/background");
|
2008-04-16 22:17:36 +02:00
|
|
|
d->background->setEnabledBorders(PanelSvg::AllBorders);
|
2008-04-23 22:42:10 +02:00
|
|
|
d->background->resizePanel(size());
|
2008-02-06 22:07:16 +01:00
|
|
|
|
|
|
|
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
2008-02-08 21:50:55 +01:00
|
|
|
|
2008-04-23 20:35:03 +02:00
|
|
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeUpdated()));
|
2008-04-17 15:12:25 +02:00
|
|
|
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-07-27 19:20:27 +02:00
|
|
|
d->background->paintPanel(&p);
|
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-04-23 22:42:10 +02:00
|
|
|
d->background->resizePanel(e->size());
|
2008-03-05 22:03:27 +01:00
|
|
|
|
|
|
|
setMask(d->background->mask());
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
2008-08-06 22:41:10 +02:00
|
|
|
void Dialog::setGraphicsWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
d->widget = widget;
|
|
|
|
|
|
|
|
if (widget) {
|
|
|
|
if (!layout()) {
|
|
|
|
QVBoxLayout *lay = new QVBoxLayout(this);
|
|
|
|
lay->setMargin(0);
|
|
|
|
lay->setSpacing(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->view) {
|
|
|
|
d->view = new QGraphicsView(this);
|
|
|
|
d->view->setFrameShape(QFrame::NoFrame);
|
|
|
|
d->view->viewport()->setAutoFillBackground(false);
|
|
|
|
layout()->addWidget(d->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->view->setScene(widget->scene());
|
|
|
|
d->adjustView();
|
|
|
|
|
|
|
|
adjustSize();
|
|
|
|
|
|
|
|
connect(widget, SIGNAL(geometryChanged()), this, SLOT(adjustView()));
|
|
|
|
} else {
|
|
|
|
delete d->view;
|
|
|
|
d->view = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *Dialog::graphicsWidget()
|
|
|
|
{
|
|
|
|
return d->widget;
|
|
|
|
}
|
|
|
|
|
2007-12-05 23:32:45 +01:00
|
|
|
}
|
|
|
|
#include "dialog.moc"
|