now Plasma::Dialog has setGraphicsWidget(QGraphicsWidget*)
it will be used by all applets that needs to display a graphics widget in a popup window at the moment used by popupapplet and clockapplet svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=843265
This commit is contained in:
parent
dc878d9033
commit
24398315e7
88
dialog.cpp
88
dialog.cpp
@ -29,8 +29,10 @@
|
||||
#include <QX11Info>
|
||||
#endif
|
||||
#include <QBitmap>
|
||||
#include <QGraphicsView>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QGraphicsSceneEvent>
|
||||
#include <QtGui/QGraphicsView>
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
|
||||
#include <KDebug>
|
||||
#include <NETRootInfo>
|
||||
@ -49,28 +51,53 @@ namespace Plasma
|
||||
class DialogPrivate
|
||||
{
|
||||
public:
|
||||
DialogPrivate(Dialog *dialog)
|
||||
: q(dialog),
|
||||
background(0),
|
||||
view(0),
|
||||
widget(0)
|
||||
{
|
||||
}
|
||||
|
||||
~DialogPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void themeUpdated();
|
||||
void adjustView();
|
||||
|
||||
|
||||
Plasma::Dialog *q;
|
||||
/**
|
||||
* Holds the background SVG, to be re-rendered when the cache is invalidated,
|
||||
* for example by resizing the dialogue.
|
||||
*/
|
||||
Plasma::PanelSvg *background;
|
||||
Plasma::Dialog *q;
|
||||
|
||||
void 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);
|
||||
};
|
||||
QGraphicsView *view;
|
||||
QGraphicsWidget *widget;
|
||||
};
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
Dialog::Dialog( QWidget * parent, Qt::WindowFlags f )
|
||||
: QWidget(parent, f),
|
||||
d(new DialogPrivate)
|
||||
d(new DialogPrivate(this))
|
||||
{
|
||||
d->q = this;
|
||||
d->background = new PanelSvg(this);
|
||||
d->background->setImagePath("dialogs/background");
|
||||
d->background->setEnabledBorders(PanelSvg::AllBorders);
|
||||
@ -104,5 +131,40 @@ void Dialog::resizeEvent(QResizeEvent *e)
|
||||
setMask(d->background->mask());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
#include "dialog.moc"
|
||||
|
4
dialog.h
4
dialog.h
@ -56,6 +56,9 @@ class PLASMA_EXPORT Dialog : public QWidget
|
||||
explicit Dialog(QWidget * parent = 0, Qt::WindowFlags f = Qt::Window);
|
||||
virtual ~Dialog();
|
||||
|
||||
void setGraphicsWidget(QGraphicsWidget *widget);
|
||||
QGraphicsWidget *graphicsWidget();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Reimplemented from QWidget
|
||||
@ -69,6 +72,7 @@ class PLASMA_EXPORT Dialog : public QWidget
|
||||
* React to theme changes
|
||||
*/
|
||||
Q_PRIVATE_SLOT(d, void themeUpdated())
|
||||
Q_PRIVATE_SLOT(d, void adjustView())
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <KIconLoader>
|
||||
|
||||
#include <plasma/dialog.h>
|
||||
#include <plasma/corona.h>
|
||||
#include <plasma/widgets/icon.h>
|
||||
|
||||
namespace Plasma
|
||||
@ -191,18 +192,19 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||
d->dialog = new Plasma::Dialog();
|
||||
d->dialog->setWindowFlags(Qt::Popup);
|
||||
|
||||
QVBoxLayout *l_layout = new QVBoxLayout(d->dialog);
|
||||
l_layout->setSpacing(0);
|
||||
l_layout->setMargin(0);
|
||||
|
||||
if (graphicsWidget()) {
|
||||
QGraphicsScene *scene = new QGraphicsScene(d->dialog);
|
||||
QGraphicsView *view = new QGraphicsView(scene, d->dialog);
|
||||
Corona *corona = qobject_cast<Corona *>(graphicsWidget()->scene());
|
||||
|
||||
scene->addItem(graphicsWidget());
|
||||
l_layout->addWidget(view);
|
||||
view->show();
|
||||
//could that cast ever fail??
|
||||
if (corona) {
|
||||
corona->addOffscreenWidget(graphicsWidget());
|
||||
graphicsWidget()->resize(graphicsWidget()->preferredSize());
|
||||
d->dialog->setGraphicsWidget(graphicsWidget());
|
||||
}
|
||||
} else {
|
||||
QVBoxLayout *l_layout = new QVBoxLayout(d->dialog);
|
||||
l_layout->setSpacing(0);
|
||||
l_layout->setMargin(0);
|
||||
l_layout->addWidget(widget());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user