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
This commit is contained in:
parent
3e57946f66
commit
698b513868
117
dialog.cpp
117
dialog.cpp
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "dialog.h"
|
||||
#include "private/dialog_p.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QSvgRenderer>
|
||||
@ -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<QGraphicsWidget> graphicsWidgetPtr;
|
||||
Dialog::ResizeCorners resizeCorners;
|
||||
QMap<Dialog::ResizeCorner, QRect> 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<Extender*>(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<Plasma::Applet *>(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<Extender*>(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<Plasma::Corona *>(applet->scene());
|
||||
} else if (graphicsWidget) {
|
||||
c = qobject_cast<Plasma::Corona *>(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);
|
||||
|
3
dialog.h
3
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
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "popupapplet.h"
|
||||
#include "private/popupapplet_p.h"
|
||||
#include "private/dialog_p.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsProxyWidget>
|
||||
@ -381,6 +382,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
||||
}
|
||||
|
||||
Dialog *dialog = new Dialog();
|
||||
dialog->d->appletPtr = q;
|
||||
dialogPtr = dialog;
|
||||
|
||||
dialog->setAspectRatioMode(savedAspectRatio);
|
||||
|
86
private/dialog_p.h
Normal file
86
private/dialog_p.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2010 by Marco MArtin <mart@kde.org>
|
||||
* Copyright 2008 by Alessandro Diaferia <alediaferia@gmail.com>
|
||||
* Copyright 2007 by Alexis Ménard <darktears31@gmail.com>
|
||||
* Copyright 2007 Sebastian Kuegler <sebas@kde.org>
|
||||
* Copyright 2006 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* 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<QGraphicsWidget> graphicsWidgetPtr;
|
||||
QWeakPointer<Applet> appletPtr;
|
||||
Dialog::ResizeCorners resizeCorners;
|
||||
QMap<Dialog::ResizeCorner, QRect> resizeAreas;
|
||||
int resizeStartCorner;
|
||||
QTimer *moveTimer;
|
||||
QTimer *adjustViewTimer;
|
||||
QTimer *adjustSizeTimer;
|
||||
QSize oldGraphicsWidgetMinimumSize;
|
||||
QSize oldGraphicsWidgetMaximumSize;
|
||||
Plasma::AspectRatioMode aspectRatioMode;
|
||||
bool resizeChecksWithBorderCheck;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user