• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libplasma

dialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com>           *
00003  *   Copyright (C) 2007 Sebastian Kuegler <sebas@kde.org>                  *
00004  *   Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>                       *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00020  ***************************************************************************/
00021 
00022 #include "dialog.h"
00023 
00024 #include <QPainter>
00025 #include <QSvgRenderer>
00026 #include <QResizeEvent>
00027 #include <QMouseEvent>
00028 #ifdef Q_WS_X11
00029 #include <QX11Info>
00030 #endif
00031 #include <QBitmap>
00032 #include <QGraphicsView>
00033 #include <QtGui/QGraphicsSceneEvent>
00034 
00035 #include <KDebug>
00036 #include <NETRootInfo>
00037 
00038 #include <plasma/panelsvg.h>
00039 #include <plasma/theme.h>
00040 
00041 #ifdef Q_WS_X11
00042 #include <X11/Xlib.h>
00043 #endif
00044 
00045 
00046 namespace Plasma
00047 {
00048 
00049 class DialogPrivate
00050 {
00051 public:
00056     Plasma::PanelSvg *background;
00057     Plasma::Dialog *q;
00058 
00059     void themeUpdated()
00060     {
00061         const int topHeight = background->marginSize(Plasma::TopMargin);
00062         const int leftWidth = background->marginSize(Plasma::LeftMargin);
00063         const int rightWidth = background->marginSize(Plasma::RightMargin);
00064         const int bottomHeight = background->marginSize(Plasma::BottomMargin);
00065         q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
00066     }; 
00067 };
00068 
00069 Dialog::Dialog( QWidget * parent, Qt::WindowFlags f )
00070     : QWidget(parent, f),
00071       d(new DialogPrivate)
00072 {
00073     d->q = this;
00074     d->background = new PanelSvg(this);
00075     d->background->setImagePath("dialogs/background");
00076     d->background->setEnabledBorders(PanelSvg::AllBorders);
00077     d->background->resizePanel(size());
00078 
00079     connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(update()));
00080 
00081     connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeUpdated()));
00082     d->themeUpdated();
00083 }
00084 
00085 Dialog::~Dialog()
00086 {
00087     delete d;
00088 }
00089 
00090 void Dialog::paintEvent(QPaintEvent *e)
00091 {
00092     QPainter p(this);
00093     p.setRenderHint(QPainter::Antialiasing);
00094     p.setClipRect(e->rect());
00095     p.setCompositionMode(QPainter::CompositionMode_Source );
00096     p.fillRect(rect(), Qt::transparent);
00097     d->background->paintPanel(&p, e->rect());
00098 }
00099 
00100 void Dialog::resizeEvent(QResizeEvent *e)
00101 {
00102     d->background->resizePanel(e->size());
00103 
00104     setMask(d->background->mask());
00105 }
00106 
00107 void Dialog::position(QGraphicsSceneEvent *event, const QRectF boundingRect, QPointF scenePos)
00108 {
00109     QWidget *viewWidget = event->widget() ? event->widget()->parentWidget() : 0;
00110     //QPointF scenePos = mapToScene(boundingRect.topLeft());
00111     QGraphicsView *view = qobject_cast<QGraphicsView*>(viewWidget);
00112     position(view,boundingRect,scenePos);
00113 }
00114 
00115 void Dialog::position(QGraphicsView * view,const QRectF boundingRect,QPointF scenePos)
00116 {
00117     if (view) {
00118         QPoint viewPos = view->mapFromScene(scenePos);
00119         QPoint globalPos = view->mapToGlobal(viewPos);
00120 
00121         if ((globalPos.ry()-height())< 0) {
00122             scenePos = QPointF(scenePos.x() + boundingRect.width(), scenePos.y() + boundingRect.height());
00123             viewPos = view->mapFromScene(scenePos);
00124             globalPos = view->mapToGlobal(viewPos)+QPoint(0,10);
00125         } else {
00126             globalPos.ry() -= (height()+10);
00127         }
00128 
00129         if ((globalPos.rx() + width()) > view->width()) {
00130             globalPos.rx()-=((globalPos.rx() + width())-view->width());
00131         }
00132 
00133         move(globalPos);
00134         kDebug() << globalPos;
00135     }
00136 }
00137 
00138 }
00139 #include "dialog.moc"

libplasma

Skip menu "libplasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal