libplasma
fliplayout.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PLASMA_FLIPLAYOUT_H_
00021 #define PLASMA_FLIPLAYOUT_H_
00022
00023 #include <plasma/plasma.h>
00024 #include <plasma/layouts/layout.h>
00025 #include <plasma/widgets/widget.h>
00026
00027 namespace Plasma
00028 {
00029
00030 template <typename SuperLayout>
00031 class FlipLayout : public SuperLayout {
00032 public:
00033 void setFlip(Flip flip)
00034 {
00035 m_flip = flip;
00036 }
00037
00038 Flip flip()
00039 {
00040 return m_flip;
00041 }
00042
00043 private:
00044 Flip m_flip;
00045
00046 protected:
00047 void relayout()
00048 {
00049 SuperLayout::relayout();
00050 QRectF rect = SuperLayout::geometry();
00051
00052 int count = SuperLayout::count();
00053
00054 if (m_flip == NoFlip) {
00055 return;
00056 }
00057
00058 QRectF childGeometry;
00059 for (int i = 0; i < count; i++) {
00060 Plasma::LayoutItem * item = SuperLayout::itemAt(i);
00061
00062 if (!item) continue;
00063
00064 childGeometry = item->geometry();
00065 if (m_flip & HorizontalFlip) {
00066
00067
00068 childGeometry.moveLeft(
00069 2 * rect.left() + rect.width()
00070 - childGeometry.left() - childGeometry.width()
00071 );
00072 }
00073 if (m_flip & VerticalFlip) {
00074
00075 childGeometry.moveTop(
00076 2 * rect.top() + rect.height()
00077 - childGeometry.top() - childGeometry.height()
00078 );
00079 }
00080 item->setGeometry(childGeometry);
00081 }
00082 }
00083
00084 };
00085
00086 }
00087
00088 #endif