FlipLayout committed

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=747176
This commit is contained in:
Ivan Čukić 2007-12-11 09:06:21 +00:00
parent 8f2b055fb7
commit 12a2f50922
4 changed files with 127 additions and 0 deletions

View File

@ -37,6 +37,7 @@ set(plasma_LIB_SRCS
layouts/freelayout.cpp
layouts/nodelayout.cpp
layouts/flowlayout.cpp
layouts/fliplayout.cpp
layouts/layout.cpp
layouts/layoutanimator.cpp
layouts/layoutitem.cpp
@ -158,6 +159,7 @@ install(FILES
layouts/freelayout.h
layouts/nodelayout.h
layouts/flowlayout.h
layouts/fliplayout.h
layouts/layout.h
layouts/layoutanimator.h
layouts/layoutitem.h

25
layouts/fliplayout.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser/Library General Public License version 2,
* or (at your option) any later version, as published by the Free
* Software Foundation
*
* This program 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/Library General Public License for more details
*
* You should have received a copy of the GNU Lesser/Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "fliplayout.h"
namespace Plasma
{
}

90
layouts/fliplayout.h Normal file
View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2,
* or (at your option) any later version, as published by the Free
* Software Foundation
*
* This program 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 program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_FLIPLAYOUT_H_
#define PLASMA_FLIPLAYOUT_H_
#include <plasma/plasma.h>
#include <plasma/layouts/layout.h>
#include <plasma/widgets/widget.h>
#include <cmath>
#include <QMap>
namespace Plasma
{
template <typename SuperLayout>
class FlipLayout : public SuperLayout { //Plasma::Layout
public:
void setFlip(Flip flip)
{
m_flip = flip;
}
Flip flip()
{
return m_flip;
}
private:
Flip m_flip;
protected:
void relayout()
{
SuperLayout::relayout();
QRectF rect = SuperLayout::geometry();
int count = SuperLayout::count();
if (m_flip == NoFlip) {
return;
}
QRectF childGeometry;
for (int i = 0; i < count; i++) {
Plasma::LayoutItem * item = SuperLayout::itemAt(i);
if (!item) continue;
childGeometry = item->geometry();
if (m_flip & HorizontalFlip) {
// 2 * rect.left() - twice because we already have one
// value of rect.left() inside the childGeometry.left()
childGeometry.moveLeft(
2 * rect.left() + rect.width()
- childGeometry.left() - childGeometry.width()
);
}
if (m_flip & VerticalFlip) {
// 2 * rect.top() - same reason as aforemontioned
childGeometry.moveTop(
2 * rect.top() + rect.height()
- childGeometry.top() - childGeometry.height()
);
}
item->setGeometry(childGeometry);
}
}
};
}
#endif /*FlipLayout_H_*/

View File

@ -105,6 +105,15 @@ enum Position { LeftPositioned /**< Positioned left */,
CenterPositioned /**< Positioned in the center */
};
/**
* Flip enumeration
*/
enum FlipDirection { NoFlip = 0 /**< Do not flip */,
HorizontalFlip = 1 /**< Flip horizontally */,
VerticalFlip = 2 /**< Flip vertically */
};
Q_DECLARE_FLAGS(Flip, FlipDirection)
/**
* Zoom levels that Plasma is aware of...
**/
@ -147,5 +156,6 @@ PLASMA_EXPORT QPainterPath roundedRectangle(const QRectF& rect, qreal radius);
} // Plasma namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Constraints)
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Flip)
#endif // multiple inclusion guard