From 698b51386848169ff013999354e449570e4f3f41 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 17 Dec 2010 22:37:09 +0000 Subject: [PATCH] the dialog private is in its seprarate file ecause it gets accessed by popupapplet to set an applet pointer in this way we can use the corona to actually find out the real desktop geometry, that doesn't fail for extended monitors like QDesktopWidget does. BUG:257955 svn path=/trunk/KDE/kdelibs/; revision=1207416 --- dialog.cpp | 117 ++++++++++++--------------------------------- dialog.h | 3 +- popupapplet.cpp | 2 + private/dialog_p.h | 86 +++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 88 deletions(-) create mode 100644 private/dialog_p.h diff --git a/dialog.cpp b/dialog.cpp index 36a525886..49f3df507 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -21,6 +21,7 @@ */ #include "dialog.h" +#include "private/dialog_p.h" #include #include @@ -61,56 +62,6 @@ namespace Plasma { -class DialogPrivate -{ -public: - DialogPrivate(Dialog *dialog) - : q(dialog), - background(0), - view(0), - resizeCorners(Dialog::NoCorner), - resizeStartCorner(Dialog::NoCorner), - moveTimer(0), - aspectRatioMode(Plasma::IgnoreAspectRatio), - resizeChecksWithBorderCheck(false) - { - } - - ~DialogPrivate() - { - } - - void scheduleBorderCheck(bool triggeredByResize = false); - void themeChanged(); - void updateMask(); - void checkBorders(); - void checkBorders(bool updateMaskIfNeeded); - void updateResizeCorners(); - int calculateWidthForHeightAndRatio(int height, qreal ratio); - Plasma::Applet *applet(); - void delayedAdjustSize(); - - Plasma::Dialog *q; - - /** - * Holds the background SVG, to be re-rendered when the cache is invalidated, - * for example by resizing the dialogue. - */ - Plasma::FrameSvg *background; - QGraphicsView *view; - QWeakPointer graphicsWidgetPtr; - Dialog::ResizeCorners resizeCorners; - QMap resizeAreas; - int resizeStartCorner; - QTimer *moveTimer; - QTimer *adjustViewTimer; - QTimer *adjustSizeTimer; - QSize oldGraphicsWidgetMinimumSize; - QSize oldGraphicsWidgetMaximumSize; - Plasma::AspectRatioMode aspectRatioMode; - bool resizeChecksWithBorderCheck; -}; - void DialogPrivate::scheduleBorderCheck(bool triggeredByResize) { //kDebug(); @@ -167,28 +118,6 @@ void DialogPrivate::checkBorders() checkBorders(true); } -Plasma::Applet *DialogPrivate::applet() -{ - Extender *extender = qobject_cast(graphicsWidgetPtr.data()); - Plasma::Applet *applet = 0; - if (extender) { - if (!extender->d->applet) { - return 0; - } - applet = extender->d->applet.data(); - } else if (graphicsWidgetPtr) { - QObject *pw = graphicsWidgetPtr.data(); - - while ((pw = pw->parent())) { - applet = dynamic_cast(pw); - if (applet) { - break; - } - } - } - return applet; -} - void DialogPrivate::delayedAdjustSize() { q->syncToGraphicsWidget(); @@ -205,12 +134,33 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded) FrameSvg::EnabledBorders borders = FrameSvg::AllBorders; Extender *extender = qobject_cast(graphicsWidget); - Plasma::Applet *applet = this->applet(); + Plasma::Applet *applet = appletPtr.data(); //used to remove borders at the edge of the desktop + QRect avail; + QRect screenGeom; QDesktopWidget *desktop = QApplication::desktop(); - QRect avail = desktop->availableGeometry(desktop->screenNumber(q)); - QRect screenGeom = desktop->screenGeometry(desktop->screenNumber(q)); + Plasma::Corona *c = 0; + if (applet) { + c = qobject_cast(applet->scene()); + } else if (graphicsWidget) { + c = qobject_cast(graphicsWidget->scene()); + } + if (c) { + QRegion r = c->availableScreenRegion(desktop->screenNumber(q)); + QRect maxRect; + foreach (QRect rect, r.rects()) { + if (rect.width() > maxRect.width() && rect.height() > maxRect.height()) { + maxRect = rect; + } + } + avail = maxRect; + screenGeom = c->screenGeometry(desktop->screenNumber(q)); + } else { + avail = desktop->availableGeometry(desktop->screenNumber(q)); + screenGeom = desktop->screenGeometry(desktop->screenNumber(q)); + } + QRect dialogGeom = q->geometry(); qreal topHeight(0); @@ -272,24 +222,17 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded) //decide if to disable the other borders if (q->isVisible()) { - QRect geom; - if (applet) { - geom = screenGeom; - } else { - geom = avail; - } - - if (dialogGeom.left() <= geom.left()) { + if (dialogGeom.left() <= avail.left()) { borders &= ~FrameSvg::LeftBorder; } - if (dialogGeom.top() <= geom.top()) { + if (dialogGeom.top() <= avail.top()) { borders &= ~FrameSvg::TopBorder; } //FIXME: that 2 pixels offset has probably something to do with kwin - if (dialogGeom.right() + 2 > geom.right()) { + if (dialogGeom.right() + 2 > avail.right()) { borders &= ~FrameSvg::RightBorder; } - if (dialogGeom.bottom() + 2 > geom.bottom()) { + if (dialogGeom.bottom() + 2 > avail.bottom()) { borders &= ~FrameSvg::BottomBorder; } } @@ -365,7 +308,7 @@ void Dialog::syncToGraphicsWidget() qMin(int(graphicsWidget->maximumSize().height()) + top + bottom, maxSize.height())); - Plasma::Applet *applet = d->applet(); + Plasma::Applet *applet = d->appletPtr.data(); if (applet) { QRect currentGeometry(geometry()); currentGeometry.setSize(newSize); diff --git a/dialog.h b/dialog.h index a24f360d1..4c4ef12a2 100644 --- a/dialog.h +++ b/dialog.h @@ -51,7 +51,6 @@ class DialogPrivate; class PLASMA_EXPORT Dialog : public QWidget { Q_OBJECT - public: /** * Use these flags to choose the active resize corners. @@ -180,6 +179,8 @@ class PLASMA_EXPORT Dialog : public QWidget Q_PRIVATE_SLOT(d, void themeChanged()) Q_PRIVATE_SLOT(d, void checkBorders()) Q_PRIVATE_SLOT(d, void delayedAdjustSize()) + + friend class PopupAppletPrivate; }; } // Plasma namespace diff --git a/popupapplet.cpp b/popupapplet.cpp index 27301b9d1..329d5d7d7 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -20,6 +20,7 @@ #include "popupapplet.h" #include "private/popupapplet_p.h" +#include "private/dialog_p.h" #include #include @@ -381,6 +382,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) } Dialog *dialog = new Dialog(); + dialog->d->appletPtr = q; dialogPtr = dialog; dialog->setAspectRatioMode(savedAspectRatio); diff --git a/private/dialog_p.h b/private/dialog_p.h new file mode 100644 index 000000000..2a3bbda44 --- /dev/null +++ b/private/dialog_p.h @@ -0,0 +1,86 @@ +/* + * Copyright 2010 by Marco MArtin + * Copyright 2008 by Alessandro Diaferia + * Copyright 2007 by Alexis Ménard + * Copyright 2007 Sebastian Kuegler + * Copyright 2006 Aaron Seigo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef LIBS_PLASMA_DIALOG_P_H +#define LIBS_PLASMA_DIALOG_P_H + +#include "plasma/dialog.h" + +namespace Plasma { + +class Applet; +class FrameSvg; + +class DialogPrivate +{ +public: + DialogPrivate(Dialog *dialog) + : q(dialog), + background(0), + view(0), + resizeCorners(Dialog::NoCorner), + resizeStartCorner(Dialog::NoCorner), + moveTimer(0), + aspectRatioMode(Plasma::IgnoreAspectRatio), + resizeChecksWithBorderCheck(false) + { + } + + ~DialogPrivate() + { + } + + void scheduleBorderCheck(bool triggeredByResize = false); + void themeChanged(); + void updateMask(); + void checkBorders(); + void checkBorders(bool updateMaskIfNeeded); + void updateResizeCorners(); + int calculateWidthForHeightAndRatio(int height, qreal ratio); + void delayedAdjustSize(); + + Plasma::Dialog *q; + + /** + * Holds the background SVG, to be re-rendered when the cache is invalidated, + * for example by resizing the dialogue. + */ + Plasma::FrameSvg *background; + QGraphicsView *view; + QWeakPointer graphicsWidgetPtr; + QWeakPointer appletPtr; + Dialog::ResizeCorners resizeCorners; + QMap resizeAreas; + int resizeStartCorner; + QTimer *moveTimer; + QTimer *adjustViewTimer; + QTimer *adjustSizeTimer; + QSize oldGraphicsWidgetMinimumSize; + QSize oldGraphicsWidgetMaximumSize; + Plasma::AspectRatioMode aspectRatioMode; + bool resizeChecksWithBorderCheck; +}; + +} + +#endif