• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • workspace API Reference
  • KDE Home
  • Contact Us
 

liblancelot

  • sources
  • kde-4.14
  • workspace
  • kdeplasma-addons
  • libs
  • lancelot
  • layouts
FlipLayout.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser/Library General Public License version 2,
6  * or (at your option) any later version, as published by the Free
7  * Software Foundation
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 Lesser/Library General Public License for more details
13  *
14  * You should have received a copy of the GNU Lesser/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 "FlipLayout.h"
21 
22 #include <QGraphicsWidget>
23 #include <QMap>
24 #include <QSet>
25 
26 namespace Lancelot
27 {
28 
29 FlipLayoutManager * FlipLayoutManager::m_instance = NULL;
30 
31 class FlipLayoutManager::Private {
32 public:
33  Plasma::Flip globalFlip;
34  QSet < QGraphicsLayout * > globalFlipLayouts;
35  QMap < QGraphicsLayout *, Plasma::Flip > flips;
36 };
37 
38 FlipLayoutManager::FlipLayoutManager()
39  : d(new Private())
40 {
41 
42 }
43 
44 FlipLayoutManager::~FlipLayoutManager()
45 {
46  delete d;
47 }
48 
49 FlipLayoutManager * FlipLayoutManager::self()
50 {
51  if (m_instance == NULL) {
52  m_instance = new FlipLayoutManager();
53  }
54  return m_instance;
55 }
56 
57 void FlipLayoutManager::setGlobalFlip(Plasma::Flip flip)
58 {
59  d->globalFlip = flip;
60 }
61 
62 Plasma::Flip FlipLayoutManager::globalFlip() const
63 {
64  return d->globalFlip;
65 }
66 
67 void FlipLayoutManager::setFlip(const QGraphicsLayout * layout, Plasma::Flip flip)
68 {
69  QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
70  d->globalFlipLayouts.remove(l);
71 
72  if (d->flips[l] != flip) {
73  d->flips[l] = flip;
74  l->setGeometry(l->geometry());
75  }
76 }
77 
78 void FlipLayoutManager::setUseGlobalFlip(const QGraphicsLayout * layout)
79 {
80  QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
81  d->flips.remove(l);
82  d->globalFlipLayouts.insert(l);
83 }
84 
85 Plasma::Flip FlipLayoutManager::flip(const QGraphicsLayout * layout) const
86 {
87  QGraphicsLayout * l = const_cast<QGraphicsLayout *>(layout);
88  if (d->globalFlipLayouts.contains(l)) {
89  return d->globalFlip;
90  } else if (d->flips.contains(l)) {
91  return d->flips[l];
92  }
93  return 0;
94 }
95 
96 void FlipLayoutManager::setGeometry(QGraphicsLayout * layout) const
97 {
98  int count = layout->count();
99  QRectF rect = layout->geometry();
100 
101  if (flip(layout) == Plasma::NoFlip) {
102  return;
103  }
104 
105  QRectF childGeometry;
106  for (int i = 0; i < count; i++) {
107  QGraphicsLayoutItem * item = layout->itemAt(i);
108 
109  if (!item) continue;
110 
111  childGeometry = item->geometry();
112  if (flip(layout) & Plasma::HorizontalFlip) {
113  childGeometry.moveLeft(rect.left() + rect.right() - childGeometry.right());
114  }
115  if (flip(layout) & Plasma::VerticalFlip) {
116  childGeometry.moveTop(rect.top() + rect.bottom() - childGeometry.bottom());
117  }
118  item->setGeometry(childGeometry);
119  }
120 }
121 
122 }
123 
Lancelot::FlipLayoutManager::self
static FlipLayoutManager * self()
Definition: FlipLayout.cpp:49
QGraphicsLayout::itemAt
virtual QGraphicsLayoutItem * itemAt(int i) const =0
QGraphicsLayoutItem::geometry
QRectF geometry() const
QMap< QGraphicsLayout *, Plasma::Flip >
QRectF::top
qreal top() const
FlipLayout.h
QRectF::left
qreal left() const
QRectF::bottom
qreal bottom() const
QGraphicsLayout::count
virtual int count() const =0
Lancelot::FlipLayoutManager::flip
Plasma::Flip flip(const QGraphicsLayout *layout) const
Definition: FlipLayout.cpp:85
Lancelot::FlipLayoutManager::globalFlip
Plasma::Flip globalFlip() const
Definition: FlipLayout.cpp:62
QRectF::moveLeft
void moveLeft(qreal x)
QSet< QGraphicsLayout * >
Lancelot::FlipLayoutManager::setUseGlobalFlip
void setUseGlobalFlip(const QGraphicsLayout *layout)
Makes the specified layout to use the global flip.
Definition: FlipLayout.cpp:78
QRectF::right
qreal right() const
Lancelot::FlipLayoutManager::setFlip
void setFlip(const QGraphicsLayout *layout, Plasma::Flip flip)
Sets the flip for a specified layout.
Definition: FlipLayout.cpp:67
QRectF
QGraphicsLayout
QRectF::moveTop
void moveTop(qreal y)
Lancelot::FlipLayoutManager::setGeometry
void setGeometry(QGraphicsLayout *layout) const
Implementation of the actual flipping.
Definition: FlipLayout.cpp:96
Lancelot::FlipLayoutManager::setGlobalFlip
void setGlobalFlip(Plasma::Flip flip)
Sets the global flip.
Definition: FlipLayout.cpp:57
Lancelot::FlipLayoutManager
Definition: FlipLayout.h:33
QGraphicsLayoutItem
QGraphicsLayoutItem::setGeometry
virtual void setGeometry(const QRectF &rect)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:43:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

liblancelot

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

workspace API Reference

Skip menu "workspace API Reference"
  • kdeplasma-addons
  •       GroupingDesktop
  •     liblancelot

Search



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