Plasma
plasma.cpp
Go to the documentation of this file.00001 /* 00002 * Copyright 2005 by Aaron Seigo <aseigo@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include <plasma/plasma.h> 00021 00022 #include <QGraphicsScene> 00023 #include <QGraphicsView> 00024 00025 #include <plasma/containment.h> 00026 #include <plasma/view.h> 00027 00028 namespace Plasma 00029 { 00030 00031 qreal scalingFactor(ZoomLevel level) 00032 { 00033 switch (level) { 00034 case DesktopZoom: 00035 return 1; 00036 break; 00037 case GroupZoom: 00038 return 0.5; 00039 break; 00040 case OverviewZoom: 00041 return 0.2; 00042 break; 00043 } 00044 00045 // to make odd compilers not warn like silly beasts 00046 return 1; 00047 } 00048 00049 Direction locationToDirection(Location location) 00050 { 00051 switch (location) { 00052 case Floating: 00053 case Desktop: 00054 case TopEdge: 00055 case FullScreen: 00056 //TODO: should we be smarter for floating and planer? 00057 // perhaps we should take a QRect and/or QPos as well? 00058 return Down; 00059 case BottomEdge: 00060 return Up; 00061 case LeftEdge: 00062 return Right; 00063 case RightEdge: 00064 return Left; 00065 } 00066 00067 return Down; 00068 } 00069 00070 Direction locationToInverseDirection(Location location) 00071 { 00072 switch (location) { 00073 case Floating: 00074 case Desktop: 00075 case TopEdge: 00076 case FullScreen: 00077 //TODO: should we be smarter for floating and planer? 00078 // perhaps we should take a QRect and/or QPos as well? 00079 return Up; 00080 case BottomEdge: 00081 return Down; 00082 case LeftEdge: 00083 return Left; 00084 case RightEdge: 00085 return Right; 00086 } 00087 00088 return Up; 00089 } 00090 00091 QGraphicsView *viewFor(const QGraphicsItem *item) 00092 { 00093 if (!item || !item->scene()) { 00094 return 0; 00095 } 00096 00097 QGraphicsView *found = 0; 00098 foreach (QGraphicsView *view, item->scene()->views()) { 00099 if (view->sceneRect().intersects(item->sceneBoundingRect()) || 00100 view->sceneRect().contains(item->scenePos())) { 00101 if (!found || view->isActiveWindow()) { 00102 found = view; 00103 } 00104 } 00105 } 00106 00107 return found; 00108 } 00109 00110 } // Plasma namespace