1 /***************************************************************************
2 * Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com> *
3 * Copyright (C) 2007 Sebastian Kuegler <sebas@kde.org> *
4 * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20 ***************************************************************************/
25 #include <QSvgRenderer>
26 #include <QResizeEvent>
27 #include <QMouseEvent>
31 #include <QGraphicsView>
32 #include <QtGui/QGraphicsSceneEvent>
35 #include <NETRootInfo>
37 #include <plasma/svgpanel.h>
38 #include <plasma/theme.h>
52 * Holds the background SVG, to be re-rendered when the cache is invalidated,
53 * for example by resizing the dialogue.
55 Plasma::SvgPanel
*background
;
58 Dialog::Dialog( QWidget
* parent
, Qt::WindowFlags f
)
62 d
->background
= new SvgPanel("dialogs/background", this);
63 d
->background
->setBorderFlags(SvgPanel::DrawAllBorders
);
64 d
->background
->resize(size());
66 connect(d
->background
, SIGNAL(repaintNeeded()), this, SLOT(update()));
68 connect(Plasma::Theme::self(), SIGNAL(changed()), this, SLOT(themeUpdated()));
76 void Dialog::themeUpdated()
78 const int topHeight
= d
->background
->marginSize(Plasma::TopMargin
);
79 const int leftWidth
= d
->background
->marginSize(Plasma::LeftMargin
);
80 const int rightWidth
= d
->background
->marginSize(Plasma::RightMargin
);
81 const int bottomHeight
= d
->background
->marginSize(Plasma::BottomMargin
);
82 setContentsMargins(leftWidth
, topHeight
, rightWidth
, bottomHeight
);
85 void Dialog::paintEvent(QPaintEvent
*e
)
88 p
.setRenderHint(QPainter::Antialiasing
);
89 p
.setClipRect(e
->rect());
90 p
.setCompositionMode(QPainter::CompositionMode_Source
);
91 p
.fillRect(rect(), Qt::transparent
);
92 d
->background
->paint(&p
, e
->rect());
95 void Dialog::resizeEvent(QResizeEvent
*e
)
97 d
->background
->resize(e
->size());
100 void Dialog::position(QGraphicsSceneEvent
*event
, const QRectF boundingRect
, QPointF scenePos
)
102 QWidget
*viewWidget
= event
->widget() ? event
->widget()->parentWidget() : 0;
103 //QPointF scenePos = mapToScene(boundingRect.topLeft());
104 QGraphicsView
*view
= qobject_cast
<QGraphicsView
*>(viewWidget
);
105 position(view
,boundingRect
,scenePos
);
108 void Dialog::position(QGraphicsView
* view
,const QRectF boundingRect
,QPointF scenePos
)
111 QPoint viewPos
= view
->mapFromScene(scenePos
);
112 QPoint globalPos
= view
->mapToGlobal(viewPos
);
113 if ((globalPos
.ry()-height())< 0) {
114 scenePos
= QPointF(scenePos
.x() + boundingRect
.width(), scenePos
.y() + boundingRect
.height());
115 viewPos
= view
->mapFromScene(scenePos
);
116 globalPos
= view
->mapToGlobal(viewPos
)+QPoint(0,10);
119 globalPos
.ry() -= (height()+10);
121 if ((globalPos
.rx() + width()) > view
->width()) {
122 globalPos
.rx()-=((globalPos
.rx() + width())-view
->width());
125 kDebug() << globalPos
;
130 #include "dialog.moc"