• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • plasma
plasma.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2005 by Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include <plasma/plasma.h>
21
22#include <QAction>
23#include <QGraphicsScene>
24#include <QGraphicsView>
25#include <QMenu>
26
27#include <plasma/containment.h>
28#include <plasma/view.h>
29
30namespace Plasma
31{
32
33qreal scalingFactor(ZoomLevel level)
34{
35 switch (level) {
36 case DesktopZoom:
37 return 1;
38 break;
39 case GroupZoom:
40 return 0.5;
41 break;
42 case OverviewZoom:
43 return 0.2;
44 break;
45 }
46
47 // to make odd compilers not warn like silly beasts
48 return 1;
49}
50
51Direction locationToDirection(Location location)
52{
53 switch (location) {
54 case Floating:
55 case Desktop:
56 case TopEdge:
57 case FullScreen:
58 //TODO: should we be smarter for floating and planer?
59 // perhaps we should take a QRect and/or QPos as well?
60 return Down;
61 case BottomEdge:
62 return Up;
63 case LeftEdge:
64 return Right;
65 case RightEdge:
66 return Left;
67 }
68
69 return Down;
70}
71
72Direction locationToInverseDirection(Location location)
73{
74 switch (location) {
75 case Floating:
76 case Desktop:
77 case TopEdge:
78 case FullScreen:
79 //TODO: should we be smarter for floating and planer?
80 // perhaps we should take a QRect and/or QPos as well?
81 return Up;
82 case BottomEdge:
83 return Down;
84 case LeftEdge:
85 return Left;
86 case RightEdge:
87 return Right;
88 }
89
90 return Up;
91}
92
93QGraphicsView *viewFor(const QGraphicsItem *item)
94{
95 if (!item || !item->scene()) {
96 return 0;
97 }
98
99 QGraphicsView *found = 0;
100 foreach (QGraphicsView *view, item->scene()->views()) {
101 if (view->sceneRect().intersects(item->sceneBoundingRect()) ||
102 view->sceneRect().contains(item->scenePos())) {
103 if (!found || view->isActiveWindow()) {
104 found = view;
105 }
106 }
107 }
108
109 return found;
110}
111
112QList<QAction*> actionsFromMenu(QMenu *menu, const QString &prefix, QObject *parent)
113{
114 Q_ASSERT(menu);
115
116 QList<QAction*> ret;
117 foreach (QAction *action, menu->actions()) {
118 if (QMenu *submenu = action->menu()) {
119 //Flatten hierarchy and prefix submenu text to all actions in submenu
120 ret << actionsFromMenu(submenu, action->text(), parent);
121 } else if (!action->isSeparator() && action->isEnabled()) {
122 QString text = action->text();
123 if (action->isCheckable()) {
124 if (action->isChecked()) {
125 text = QString("(%1) %2").arg(QChar(0x2613)).arg(text);
126 } else {
127 text = QString("( ) %1").arg(text);
128 }
129 }
130
131 if (!prefix.isEmpty()) {
132 text = QString("%1: %2").arg(prefix).arg(text);
133 }
134 text = text.replace(QRegExp("&([\\S])"), "\\1");
135
136 QAction *a = new QAction(action->icon(), text, parent);
137
138 QObject::connect(a, SIGNAL(triggered(bool)), action, SIGNAL(triggered(bool)));
139 ret << a;
140 }
141 }
142 return ret;
143}
144
145} // Plasma namespace
QGraphicsView
QObject
containment.h
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
Plasma::viewFor
QGraphicsView * viewFor(const QGraphicsItem *item)
Returns the most appropriate QGraphicsView for the item.
Definition: plasma.cpp:93
Plasma::Location
Location
The Location enumeration describes where on screen an element, such as an Applet or its managing cont...
Definition: plasma.h:108
Plasma::FullScreen
@ FullScreen
Full screen.
Definition: plasma.h:113
Plasma::LeftEdge
@ LeftEdge
Along the left side of the screen.
Definition: plasma.h:116
Plasma::Desktop
@ Desktop
On the planar desktop layer, extending across the full screen from edge to edge.
Definition: plasma.h:111
Plasma::Floating
@ Floating
Free floating.
Definition: plasma.h:109
Plasma::TopEdge
@ TopEdge
Along the top of the screen.
Definition: plasma.h:114
Plasma::RightEdge
@ RightEdge
Along the right side of the screen.
Definition: plasma.h:117
Plasma::BottomEdge
@ BottomEdge
Along the bottom of the screen.
Definition: plasma.h:115
Plasma::locationToInverseDirection
Direction locationToInverseDirection(Location location)
Converts a location to the direction facing it.
Definition: plasma.cpp:72
Plasma::locationToDirection
Direction locationToDirection(Location location)
Converts a location to a direction.
Definition: plasma.cpp:51
Plasma::ZoomLevel
ZoomLevel
Zoom levels that Plasma is aware of...
Definition: plasma.h:170
Plasma::OverviewZoom
@ OverviewZoom
Groups become icons themselves.
Definition: plasma.h:175
Plasma::GroupZoom
@ GroupZoom
Plasmoids are shown as icons in visual groups; drag and drop and limited context menu interaction onl...
Definition: plasma.h:173
Plasma::DesktopZoom
@ DesktopZoom
Normal desktop usage, plasmoids are painted normally and have full interaction.
Definition: plasma.h:171
Plasma::scalingFactor
qreal scalingFactor(ZoomLevel level)
Definition: plasma.cpp:33
Plasma::Direction
Direction
The Direction enumeration describes in which direction, relative to the Applet (and its managing cont...
Definition: plasma.h:89
Plasma::Down
@ Down
Display downards.
Definition: plasma.h:90
Plasma::Up
@ Up
Display upwards.
Definition: plasma.h:91
Plasma::Right
@ Right
Display to the right.
Definition: plasma.h:93
Plasma::Left
@ Left
Display to the left.
Definition: plasma.h:92
Plasma::actionsFromMenu
QList< QAction * > actionsFromMenu(QMenu *menu, const QString &prefix, QObject *parent)
Returns a list of all actions in the given QMenu This method flattens the hierarchy of the menu by pr...
Definition: plasma.cpp:112
plasma.h
view.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal