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 <QAction> 00023 #include <QGraphicsScene> 00024 #include <QGraphicsView> 00025 #include <QMenu> 00026 00027 #include <plasma/containment.h> 00028 #include <plasma/view.h> 00029 00030 namespace Plasma 00031 { 00032 00033 qreal scalingFactor(ZoomLevel level) 00034 { 00035 switch (level) { 00036 case DesktopZoom: 00037 return 1; 00038 break; 00039 case GroupZoom: 00040 return 0.5; 00041 break; 00042 case OverviewZoom: 00043 return 0.2; 00044 break; 00045 } 00046 00047 // to make odd compilers not warn like silly beasts 00048 return 1; 00049 } 00050 00051 Direction locationToDirection(Location location) 00052 { 00053 switch (location) { 00054 case Floating: 00055 case Desktop: 00056 case TopEdge: 00057 case FullScreen: 00058 //TODO: should we be smarter for floating and planer? 00059 // perhaps we should take a QRect and/or QPos as well? 00060 return Down; 00061 case BottomEdge: 00062 return Up; 00063 case LeftEdge: 00064 return Right; 00065 case RightEdge: 00066 return Left; 00067 } 00068 00069 return Down; 00070 } 00071 00072 Direction locationToInverseDirection(Location location) 00073 { 00074 switch (location) { 00075 case Floating: 00076 case Desktop: 00077 case TopEdge: 00078 case FullScreen: 00079 //TODO: should we be smarter for floating and planer? 00080 // perhaps we should take a QRect and/or QPos as well? 00081 return Up; 00082 case BottomEdge: 00083 return Down; 00084 case LeftEdge: 00085 return Left; 00086 case RightEdge: 00087 return Right; 00088 } 00089 00090 return Up; 00091 } 00092 00093 QGraphicsView *viewFor(const QGraphicsItem *item) 00094 { 00095 if (!item || !item->scene()) { 00096 return 0; 00097 } 00098 00099 QGraphicsView *found = 0; 00100 foreach (QGraphicsView *view, item->scene()->views()) { 00101 if (view->sceneRect().intersects(item->sceneBoundingRect()) || 00102 view->sceneRect().contains(item->scenePos())) { 00103 if (!found || view->isActiveWindow()) { 00104 found = view; 00105 } 00106 } 00107 } 00108 00109 return found; 00110 } 00111 00112 QList<QAction*> actionsFromMenu(QMenu *menu, const QString &prefix, QObject *parent) 00113 { 00114 Q_ASSERT(menu); 00115 00116 QList<QAction*> ret; 00117 foreach (QAction *action, menu->actions()) { 00118 if (QMenu *submenu = action->menu()) { 00119 //Flatten hierarchy and prefix submenu text to all actions in submenu 00120 ret << actionsFromMenu(submenu, action->text(), parent); 00121 } else if (!action->isSeparator() && action->isEnabled()) { 00122 QString text = action->text(); 00123 if (action->isCheckable()) { 00124 if (action->isChecked()) { 00125 text = QString("(%1) %2").arg(QChar(0x2613)).arg(text); 00126 } else { 00127 text = QString("( ) %1").arg(text); 00128 } 00129 } 00130 00131 if (!prefix.isEmpty()) { 00132 text = QString("%1: %2").arg(prefix).arg(text); 00133 } 00134 text = text.replace(QRegExp("&([\\S])"), "\\1"); 00135 00136 QAction *a = new QAction(action->icon(), text, parent); 00137 00138 QObject::connect(a, SIGNAL(triggered(bool)), action, SIGNAL(triggered(bool))); 00139 ret << a; 00140 } 00141 } 00142 return ret; 00143 } 00144 00145 } // Plasma namespace
KDE 4.6 API Reference