diff options
-rw-r--r-- | examples/layouts/anchorlayout/anchorlayout.pro | 15 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/anchorlayout.ui | 451 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/layoutitem.cpp | 93 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/layoutitem.h | 62 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/main.cpp | 10 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/scene.cpp | 57 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/scene.h | 64 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/widgetchooserdelegate.cpp | 134 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/widgetchooserdelegate.h | 75 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/window.cpp | 555 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/window.h | 61 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/xml/center.xml | 57 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/xml/linear.xml | 46 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/xml/snake.xml | 79 |
14 files changed, 0 insertions, 1759 deletions
diff --git a/examples/layouts/anchorlayout/anchorlayout.pro b/examples/layouts/anchorlayout/anchorlayout.pro deleted file mode 100644 index 8c19404..0000000 --- a/examples/layouts/anchorlayout/anchorlayout.pro +++ /dev/null @@ -1,15 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) fr 15. mai 08:51:37 2009 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -HEADERS += layoutitem.h widgetchooserdelegate.h window.h scene.h -FORMS += anchorlayout.ui -SOURCES += layoutitem.cpp main.cpp widgetchooserdelegate.cpp window.cpp scene.cpp - -DEFINES += PRO_FILE_PWD=$$_PRO_FILE_PWD_
\ No newline at end of file diff --git a/examples/layouts/anchorlayout/anchorlayout.ui b/examples/layouts/anchorlayout/anchorlayout.ui deleted file mode 100644 index 5f3718b..0000000 --- a/examples/layouts/anchorlayout/anchorlayout.ui +++ /dev/null @@ -1,451 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>MainWindow</class> - <widget class="QMainWindow" name="MainWindow"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>795</width> - <height>765</height> - </rect> - </property> - <property name="windowTitle"> - <string>Anchor layout example</string> - </property> - <widget class="QWidget" name="centralwidget"> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QGraphicsView" name="graphicsView"> - <property name="backgroundBrush"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>0</red> - <green>128</green> - <blue>0</blue> - </color> - </brush> - </property> - <property name="foregroundBrush"> - <brush brushstyle="NoBrush"> - <color alpha="255"> - <red>0</red> - <green>0</green> - <blue>0</blue> - </color> - </brush> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QMenuBar" name="menubar"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>795</width> - <height>21</height> - </rect> - </property> - <widget class="QMenu" name="menu_File"> - <property name="title"> - <string>&File</string> - </property> - <addaction name="actionSave_layout"/> - <addaction name="actionE_xit"/> - </widget> - <widget class="QMenu" name="menu_View"> - <property name="title"> - <string>&View</string> - </property> - <addaction name="action_Anchors"/> - <addaction name="actionLayout_presets"/> - <addaction name="action_Item_properties"/> - </widget> - <addaction name="menu_File"/> - <addaction name="menu_View"/> - </widget> - <widget class="QStatusBar" name="statusbar"/> - <widget class="QToolBar" name="toolBar"> - <property name="windowTitle"> - <string>toolBar</string> - </property> - <attribute name="toolBarArea"> - <enum>TopToolBarArea</enum> - </attribute> - <attribute name="toolBarBreak"> - <bool>false</bool> - </attribute> - <addaction name="actionAdd_item"/> - </widget> - <widget class="QDockWidget" name="dwAnchors"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="allowedAreas"> - <set>Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> - </property> - <property name="windowTitle"> - <string>Anchors</string> - </property> - <attribute name="dockWidgetArea"> - <number>1</number> - </attribute> - <widget class="QWidget" name="dockWidgetContents_3"> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QTableWidget" name="anchors"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>330</width> - <height>0</height> - </size> - </property> - <attribute name="horizontalHeaderDefaultSectionSize"> - <number>50</number> - </attribute> - <column> - <property name="text"> - <string>Begin</string> - </property> - </column> - <column> - <property name="text"> - <string>Edge</string> - </property> - </column> - <column> - <property name="text"> - <string>End</string> - </property> - </column> - <column> - <property name="text"> - <string>Edge</string> - </property> - </column> - <column> - <property name="text"> - <string>Min</string> - </property> - </column> - <column> - <property name="text"> - <string>Max</string> - </property> - </column> - </widget> - </item> - <item> - <widget class="QPushButton" name="pbAddAnchor"> - <property name="text"> - <string>Add anchor ^^</string> - </property> - <property name="shortcut"> - <string>Ctrl+A</string> - </property> - <property name="flat"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </widget> - </widget> - <widget class="QDockWidget" name="dwProperties"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>Item properties</string> - </property> - <attribute name="dockWidgetArea"> - <number>1</number> - </attribute> - <widget class="QWidget" name="dockWidgetContents"> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="title"> - <string>Item properties</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="0" column="1" colspan="2"> - <widget class="QLineEdit" name="itemName"/> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="itemMinW"/> - </item> - <item row="2" column="2"> - <widget class="QDoubleSpinBox" name="itemMinH"/> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QDoubleSpinBox" name="itemPrefW"/> - </item> - <item row="3" column="2"> - <widget class="QDoubleSpinBox" name="itemPrefH"/> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QDoubleSpinBox" name="itemMaxW"/> - </item> - <item row="4" column="2"> - <widget class="QDoubleSpinBox" name="itemMaxH"/> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - </widget> - <widget class="QDockWidget" name="dwPresets"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>Layout presets</string> - </property> - <attribute name="dockWidgetArea"> - <number>1</number> - </attribute> - <widget class="QWidget" name="dockWidgetContents_2"> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QListWidget" name="layouts"/> - </item> - </layout> - </widget> - </widget> - <action name="actionAdd_item"> - <property name="text"> - <string>Add item</string> - </property> - <property name="shortcut"> - <string>Ctrl+N</string> - </property> - </action> - <action name="action_Anchors"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>&Anchors</string> - </property> - </action> - <action name="actionLayout_presets"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>Layout &presets</string> - </property> - </action> - <action name="action_Item_properties"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>&Item properties</string> - </property> - </action> - <action name="actionSave_layout"> - <property name="text"> - <string>Save layout</string> - </property> - <property name="shortcut"> - <string>Ctrl+S</string> - </property> - </action> - <action name="actionE_xit"> - <property name="text"> - <string>&Quit</string> - </property> - <property name="shortcut"> - <string>Ctrl+Q</string> - </property> - </action> - </widget> - <resources/> - <connections> - <connection> - <sender>actionLayout_presets</sender> - <signal>triggered(bool)</signal> - <receiver>dwPresets</receiver> - <slot>setVisible(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> - </hint> - <hint type="destinationlabel"> - <x>173</x> - <y>345</y> - </hint> - </hints> - </connection> - <connection> - <sender>action_Anchors</sender> - <signal>triggered(bool)</signal> - <receiver>dwAnchors</receiver> - <slot>setVisible(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> - </hint> - <hint type="destinationlabel"> - <x>173</x> - <y>169</y> - </hint> - </hints> - </connection> - <connection> - <sender>action_Item_properties</sender> - <signal>triggered(bool)</signal> - <receiver>dwProperties</receiver> - <slot>setVisible(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>173</x> - <y>483</y> - </hint> - <hint type="destinationlabel"> - <x>173</x> - <y>483</y> - </hint> - </hints> - </connection> - <connection> - <sender>dwAnchors</sender> - <signal>visibilityChanged(bool)</signal> - <receiver>action_Anchors</receiver> - <slot>setChecked(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>173</x> - <y>169</y> - </hint> - <hint type="destinationlabel"> - <x>-1</x> - <y>-1</y> - </hint> - </hints> - </connection> - <connection> - <sender>dwPresets</sender> - <signal>visibilityChanged(bool)</signal> - <receiver>actionLayout_presets</receiver> - <slot>setChecked(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>173</x> - <y>345</y> - </hint> - <hint type="destinationlabel"> - <x>-1</x> - <y>-1</y> - </hint> - </hints> - </connection> - <connection> - <sender>dwProperties</sender> - <signal>visibilityChanged(bool)</signal> - <receiver>action_Item_properties</receiver> - <slot>setChecked(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>173</x> - <y>483</y> - </hint> - <hint type="destinationlabel"> - <x>-1</x> - <y>-1</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/examples/layouts/anchorlayout/layoutitem.cpp b/examples/layouts/anchorlayout/layoutitem.cpp deleted file mode 100644 index b85a589..0000000 --- a/examples/layouts/anchorlayout/layoutitem.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "layoutitem.h" -#include "scene.h" - -LayoutItem::LayoutItem(const QString &name, QGraphicsItem *parent/* = 0*/) - : QGraphicsWidget(parent) -{ - setData(0, name); - setGraphicsItem(this); - setFocusPolicy(Qt::ClickFocus); -} - -LayoutItem::~LayoutItem() -{ -} - -void LayoutItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/) -{ - Q_UNUSED(widget); - Q_UNUSED(option); - - // text - QString name = graphicsItem()->data(0).toString(); - painter->drawText(rect(), Qt::AlignCenter, name); - - // rect - if (Scene *scn = static_cast<Scene*>(scene())) { - if (scn->lastFocusItem() == this) { - QPen pen(Qt::blue, 2.0); - painter->setPen(pen); - } - } - painter->drawRoundedRect(rect(), 5, 5); -} - -void LayoutItem::focusInEvent(QFocusEvent *event) -{ - if (Scene *scn = static_cast<Scene*>(scene())) { - scn->emitFocusItemChanged(this); - } - QGraphicsWidget::focusInEvent(event); -} - -void LayoutItem::focusOutEvent(QFocusEvent *event) -{ - if (Scene *scn = static_cast<Scene*>(scene())) { - scn->emitFocusItemChanged(0); - } - QGraphicsWidget::focusOutEvent(event); -} - - diff --git a/examples/layouts/anchorlayout/layoutitem.h b/examples/layouts/anchorlayout/layoutitem.h deleted file mode 100644 index 86c0b06..0000000 --- a/examples/layouts/anchorlayout/layoutitem.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef LAYOUTITEM_H -#define LAYOUTITEM_H - -#include <QtGui> - -class LayoutItem : public QGraphicsWidget -{ - Q_OBJECT -public: - LayoutItem(const QString &name, QGraphicsItem *parent = 0); - ~LayoutItem(); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = 0); - void focusInEvent(QFocusEvent *event); - void focusOutEvent(QFocusEvent *event); - -}; - - -#endif diff --git a/examples/layouts/anchorlayout/main.cpp b/examples/layouts/anchorlayout/main.cpp deleted file mode 100644 index 716a563..0000000 --- a/examples/layouts/anchorlayout/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "window.h" -#include <QtGui/qapplication.h> - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - Window *w = new Window(app.arguments()); - w->show(); - return app.exec(); -} diff --git a/examples/layouts/anchorlayout/scene.cpp b/examples/layouts/anchorlayout/scene.cpp deleted file mode 100644 index 68b4002..0000000 --- a/examples/layouts/anchorlayout/scene.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "scene.h" - -Scene::Scene() : QGraphicsScene() -{ - -} - -void Scene::emitFocusItemChanged(QGraphicsItem *item) -{ - if (hasFocus()) { // when leaving the view, we want to remember the last focused item - emit focusItemChanged(item); - m_lastFocusItem = item; - } -} - - diff --git a/examples/layouts/anchorlayout/scene.h b/examples/layouts/anchorlayout/scene.h deleted file mode 100644 index ba7f5d8..0000000 --- a/examples/layouts/anchorlayout/scene.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SCENE_H -#define SCENE_H - -#include <QtGui/qgraphicsscene.h> - -class Scene : public QGraphicsScene -{ - Q_OBJECT -public: - Scene(); - - void emitFocusItemChanged(QGraphicsItem *item); - QGraphicsItem *lastFocusItem() { return m_lastFocusItem; } - -Q_SIGNALS: - void focusItemChanged(QGraphicsItem *item); - -private: - QGraphicsItem *m_lastFocusItem; - -}; - -#endif // SCENE_H diff --git a/examples/layouts/anchorlayout/widgetchooserdelegate.cpp b/examples/layouts/anchorlayout/widgetchooserdelegate.cpp deleted file mode 100644 index 0f988c1..0000000 --- a/examples/layouts/anchorlayout/widgetchooserdelegate.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui> - -#include "widgetchooserdelegate.h" - - -WidgetChooserDelegate::WidgetChooserDelegate(QVector<QGraphicsLayoutItem*> *layoutItems, - QGraphicsLayout *layout, - QWidget *parent /*= 0*/) -: QStyledItemDelegate(parent), m_layoutItems(layoutItems), m_layout(layout) -{ -} - -static const char *edges[] = { - "Left", - "HCenter", - "Right", - "Top", - "VCenter", - "Bottom" - }; - -QWidget *WidgetChooserDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &option, - const QModelIndex &index) const - -{ - int column = index.column(); - if (column == 0 || column == 2) { - // first and second anchor items - QComboBox *chooser = new QComboBox(parent); - chooser->addItem(QLatin1String("layout"), - qVariantFromValue(reinterpret_cast<void*>(m_layout))); - for (int i = 0; i < m_layoutItems->count(); ++i) { - QGraphicsLayoutItem *item = m_layoutItems->at(i); - chooser->addItem(item->graphicsItem()->data(0).toString(), - qVariantFromValue(reinterpret_cast<void*>(item))); - } - connect(chooser, SIGNAL(currentIndexChanged(int)), - this, SLOT(commitAndCloseEditor())); - return chooser; - } else if (column == 1 || column == 3) { - // first and second anchor edges - QComboBox *chooser = new QComboBox(parent); - for (int i = 0; i < sizeof(edges)/sizeof(char*); ++i) { - chooser->addItem(QLatin1String(edges[i]), i); - } - connect(chooser, SIGNAL(currentIndexChanged(int)), - this, SLOT(commitAndCloseEditor())); - return chooser; - } else { - return QStyledItemDelegate::createEditor(parent, option, index); - } -} - -void WidgetChooserDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const -{ - if (QComboBox *chooser = qobject_cast<QComboBox*>(editor)) { - int column = index.column(); - if (column >= 0 && column <= 3) { - QVariant data = index.data(Qt::UserRole); - int index = chooser->findData(data); - if (index >= 0) { - chooser->setCurrentIndex(index); - } - } - } else { - QStyledItemDelegate::setEditorData(editor, index); - } -} - -void WidgetChooserDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const -{ - if (QComboBox *chooser = qobject_cast<QComboBox*>(editor)) { - int column = index.column(); - if (column >= 0 && column <= 3) { - int currentIndex = chooser->currentIndex(); - model->setData(index, chooser->itemText(currentIndex)); - model->setData(index, chooser->itemData(currentIndex), Qt::UserRole); - } - } else { - QStyledItemDelegate::setModelData(editor, model, index); - } -} - -void WidgetChooserDelegate::commitAndCloseEditor() -{ - QComboBox *editor = qobject_cast<QComboBox *>(sender()); - emit commitData(editor); - emit closeEditor(editor); -} - diff --git a/examples/layouts/anchorlayout/widgetchooserdelegate.h b/examples/layouts/anchorlayout/widgetchooserdelegate.h deleted file mode 100644 index 50b9e48..0000000 --- a/examples/layouts/anchorlayout/widgetchooserdelegate.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef STARDELEGATE_H -#define STARDELEGATE_H - -#include <QStyledItemDelegate> - -#include <QtCore/qvector.h> - -class QGraphicsLayoutItem; -class QGraphicsLayout; - -class WidgetChooserDelegate : public QStyledItemDelegate -{ - Q_OBJECT - -public: - WidgetChooserDelegate(QVector<QGraphicsLayoutItem*> *layoutItems, - QGraphicsLayout *layout, - QWidget *parent = 0); - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; - -private slots: - void commitAndCloseEditor(); - -private: - QVector<QGraphicsLayoutItem*> *m_layoutItems; - QGraphicsLayout *m_layout; -}; - -#endif diff --git a/examples/layouts/anchorlayout/window.cpp b/examples/layouts/anchorlayout/window.cpp deleted file mode 100644 index cab1b60..0000000 --- a/examples/layouts/anchorlayout/window.cpp +++ /dev/null @@ -1,555 +0,0 @@ -#include "window.h" -#include "layoutitem.h" -#include "scene.h" -#include "widgetchooserdelegate.h" - -#include <QtGui/qgraphicswidget.h> -#include <QtGui/qgraphicsanchorlayout.h> - -static QGraphicsLayoutItem *layoutItem(const QVariant &data) -{ - return reinterpret_cast<QGraphicsLayoutItem *>(qVariantValue<void *>(data)); -} - -static QString nodeName(QGraphicsLayoutItem *item) -{ - QString str = item->isLayout() ? QLatin1String("layout") : item->graphicsItem()->data(0).toString(); - str.replace(QLatin1Char(' '), QLatin1Char('_')); - return str; -} - -#define _QUOTEMACRO(x) #x -#define QUOTEMACRO(x) _QUOTEMACRO(x) - -Window::Window(const QStringList &arguments, QWidget *parent) - : QMainWindow(parent), m_inAddAnchor(false) -{ - m_ui.setupUi(this); - m_scene = new Scene; - - m_ui.graphicsView->setScene(m_scene); - connect(m_scene, SIGNAL(focusItemChanged(QGraphicsItem*)), this, SLOT(scene_focusItemChanged(QGraphicsItem*))); - - m_window = new QGraphicsWidget(0, Qt::Window); - m_scene->addItem(m_window); - m_layout = new QGraphicsAnchorLayout(m_window); - m_window->setLayout(m_layout); - m_window->resize(400, 300); - - findLayoutFiles(); - - WidgetChooserDelegate *delegate = new WidgetChooserDelegate(&m_layoutItems, m_layout, m_ui.anchors); - m_ui.anchors->setItemDelegate(delegate); - - if (arguments.count() >= 2) { - QString fileName = QString::fromAscii("%1/xml/%2.xml").arg(QUOTEMACRO(PRO_FILE_PWD), arguments.at(1)); - if (!loadLayout(fileName, m_layout)) { - QMessageBox::warning(this, tr("Not found"), tr("Could not find %1").arg(fileName)); - } - } -} - -void Window::findLayoutFiles() -{ - m_ignoreCurrentLayoutChange = true; - QLatin1String s(QUOTEMACRO(PRO_FILE_PWD)"/xml"); - QDirIterator it(s); - while (it.hasNext()) { - it.next(); - QFileInfo fi = it.fileInfo(); - QString baseName = fi.baseName(); - if (!baseName.isEmpty()) { // avoid "." and ".." - m_ui.layouts->addItem(baseName); - } - } - m_ignoreCurrentLayoutChange = false; -} - -void Window::on_layouts_currentRowChanged(int row) -{ - if (m_ignoreCurrentLayoutChange) - return; - - QListWidgetItem *item = m_ui.layouts->item(row); - if (item) { - QString fileName = QString::fromAscii("%1/xml/%2.xml").arg(QUOTEMACRO(PRO_FILE_PWD), item->text()); - if (!loadLayout(fileName, m_layout)) { - qWarning("could not find %s", qPrintable(fileName)); - } - } -} - -void Window::on_anchors_cellChanged(int row, int column) -{ - Q_UNUSED(row); - Q_UNUSED(column); - if (!m_inAddAnchor) - rebuildLayout(); -} - - -void Window::on_pbAddAnchor_clicked(bool) -{ - addAnchorRow(); -} - -void Window::on_actionAdd_item_triggered(bool ) -{ - addItem(); -} - -void Window::on_actionSave_layout_triggered(bool ) -{ - QString fileName = QFileDialog::getSaveFileName(this, tr("Save layout"), QLatin1String(QUOTEMACRO(PRO_FILE_PWD)"/xml"), QLatin1String("*.xml")); - if (!fileName.isEmpty()) - saveLayout(fileName); -} - -void Window::on_itemName_textEdited(const QString & ) -{ - updateItem(); -} - -void Window::on_itemMinW_valueChanged(double ) -{ - updateItem(); -} - -void Window::on_itemMinH_valueChanged(double ) -{ - updateItem(); -} - -void Window::on_itemPrefW_valueChanged(double ) -{ - updateItem(); -} - -void Window::on_itemPrefH_valueChanged(double ) -{ - updateItem(); -} - -void Window::on_itemMaxW_valueChanged(double ) -{ - updateItem(); -} - -void Window::on_itemMaxH_valueChanged(double ) -{ - updateItem(); -} - -void Window::scene_focusItemChanged(QGraphicsItem *item) -{ - bool isItemValid = item && item->isWidget(); - m_ui.groupBox->setEnabled(isItemValid); - QGraphicsLayoutItem *newCurrentItem = m_currentItem; - m_currentItem = 0; - if (isItemValid) { - QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item); - setItemData(item->data(0).toString(), w->minimumSize(), w->preferredSize(), w->maximumSize()); - newCurrentItem = w; - } else { - setItemData(QString(), QSizeF(), QSizeF(), QSizeF()); - } - m_currentItem = newCurrentItem; -} - -void Window::updateItem() -{ - if (!m_currentItem) - return; - if (QGraphicsItem *gi = m_currentItem->graphicsItem()) { - gi->setData(0, m_ui.itemName->text()); - gi->update(); - } - QSizeF min(m_ui.itemMinW->value(), m_ui.itemMinH->value()); - QSizeF pref(m_ui.itemPrefW->value(), m_ui.itemPrefH->value()); - QSizeF max(m_ui.itemMaxW->value(), m_ui.itemMaxH->value()); - - if (min.isValid()) - m_currentItem->setMinimumSize(min); - if (pref.isValid()) - m_currentItem->setPreferredSize(pref); - if (max.isValid()) - m_currentItem->setMaximumSize(max); -} - -void Window::rebuildLayout() -{ - int i; - for (i = m_layout->count(); i > 0; --i) { - m_layout->removeAt(0); - } - - int rc = m_ui.anchors->rowCount(); - for (i = 0; i < rc; ++i) { - bool ok; - - QGraphicsLayoutItem *startItem = layoutItemAt(m_ui.anchors->model(), i, 0); - if (!startItem) - continue; - Qt::AnchorPoint startEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); - if (!ok) - continue; - QGraphicsLayoutItem *endItem = layoutItemAt(m_ui.anchors->model(), i, 2); - if (!endItem) - continue; - Qt::AnchorPoint endEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); - if (!ok) - continue; - - m_layout->addAnchor(startItem, startEdge, endItem, endEdge); - } -} - -void Window::setItemData(const QString &name, const QSizeF &min, const QSizeF &pref, const QSizeF &max) -{ - m_ui.itemName->setText(name); - m_ui.itemMinW->setValue(min.width()); - m_ui.itemMinH->setValue(min.height()); - m_ui.itemPrefW->setValue(pref.width()); - m_ui.itemPrefH->setValue(pref.height()); - m_ui.itemMaxW->setValue(max.width()); - m_ui.itemMaxH->setValue(max.height()); -} - -QGraphicsLayoutItem *Window::addItem(const QString &name) -{ - int rc = m_layoutItems.count(); - QString effectiveName = name.isEmpty() ? QString::fromAscii("item %1").arg(rc + 1) : name; - QGraphicsLayoutItem *layoutItem = new LayoutItem(effectiveName, m_window); - m_layoutItems.append(layoutItem); - m_scene->setFocusItem(layoutItem->graphicsItem()); - return layoutItem; -} - -static const char *strEdges[] = {"Left", - "HCenter", - "Right", - "Top", - "VCenter", - "Bottom"}; - -void Window::setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, Qt::AnchorPoint startEdge, - QGraphicsLayoutItem *endItem, const QString &endName, Qt::AnchorPoint endEdge, int row /*= -1*/) -{ - if (row == -1) { - row = m_ui.anchors->rowCount(); - m_ui.anchors->insertRow(row); - } - m_inAddAnchor = true; - - QTableWidgetItem *item = new QTableWidgetItem; - item->setData(Qt::UserRole, qVariantFromValue<void*>(reinterpret_cast<void*>(startItem))); - item->setData(Qt::DisplayRole, startName); - m_ui.anchors->setItem(row, 0, item); - - item = new QTableWidgetItem; - item->setData(Qt::UserRole, int(startEdge)); - item->setData(Qt::DisplayRole, QLatin1String(strEdges[startEdge])); - m_ui.anchors->setItem(row, 1, item); - - item = new QTableWidgetItem; - item->setData(Qt::UserRole, qVariantFromValue<void*>(reinterpret_cast<void*>(endItem))); - item->setData(Qt::DisplayRole, endName); - m_ui.anchors->setItem(row, 2, item); - - item = new QTableWidgetItem; - item->setData(Qt::UserRole, int(endEdge)); - item->setData(Qt::DisplayRole, QLatin1String(strEdges[endEdge])); - m_ui.anchors->setItem(row, 3, item); - - item = new QTableWidgetItem; - item->setData(Qt::DisplayRole, 6); - m_ui.anchors->setItem(row, 4, item); - - item = new QTableWidgetItem; - item->setData(Qt::DisplayRole, 6); - m_ui.anchors->setItem(row, 5, item); - m_inAddAnchor = false; - -} - -void Window::addAnchorRow() -{ - int rc = m_ui.anchors->rowCount(); - QGraphicsLayoutItem *defaultLayoutItem = m_layout; - if (m_layoutItems.count() > 0) { - defaultLayoutItem = m_layoutItems.at(0); - } - - m_ui.anchors->insertRow(rc); - - if (defaultLayoutItem) { - QString defaultName = defaultLayoutItem->isLayout() ? - QLatin1String("layout") : - defaultLayoutItem->graphicsItem()->data(0).toString(); - setAnchorData(defaultLayoutItem, defaultName, Qt::AnchorRight, defaultLayoutItem, defaultName, Qt::AnchorLeft, rc); - rebuildLayout(); - } -} - -QGraphicsLayoutItem *Window::layoutItemAt(QAbstractItemModel *model, int row, int column /*= 0*/) -{ - int rc = model->rowCount(); - QGraphicsLayoutItem *item = 0; - if (row < rc) { - QVariant data = model->data(model->index(row, column), Qt::UserRole); - if (data.isValid()) { - item = layoutItem(data); - } - } - return item; -} - -bool Window::saveLayout(const QString& fileName) -{ - bool ok; - QFile out(fileName); - ok = out.open(QIODevice::WriteOnly); - if (ok) { - QXmlStreamWriter xml(&out); - xml.setAutoFormatting(true); - xml.writeStartDocument(); - xml.writeStartElement(QLatin1String("anchorlayout")); - int i; - for (i = 0; i < m_layoutItems.count(); ++i) { - QGraphicsLayoutItem *item = m_layoutItems.at(i); - xml.writeStartElement(QLatin1String("item")); - QString name = nodeName(item); - if (name == QLatin1String("layout")) - name = QLatin1String("this"); - xml.writeAttribute(QLatin1String("id"), name); - for (int p = 0; p < 3; ++p) { - const char *propertyNames[] = {"minimumSize", "preferredSize", "maximumSize"}; - typedef QSizeF (QGraphicsLayoutItem::*QGLISizeGetter)(void) const; - QGLISizeGetter sizeGetters[] = { &QGraphicsLayoutItem::minimumSize, - &QGraphicsLayoutItem::preferredSize, - &QGraphicsLayoutItem::maximumSize}; - QSizeF size = ((*item).*(sizeGetters[p])) (); - xml.writeStartElement(QLatin1String("property")); - xml.writeAttribute(QLatin1String("name"), QLatin1String(propertyNames[p])); - xml.writeStartElement(QLatin1String("size")); - xml.writeAttribute(QLatin1String("width"), QString::number(size.width())); - xml.writeAttribute(QLatin1String("height"), QString::number(size.height())); - xml.writeEndElement(); - xml.writeEndElement(); - } - xml.writeEndElement(); - } - - QHash<int, QString> edgeString; - for (i = 0; i < sizeof(strEdges)/sizeof(char*); ++i) { - edgeString.insert(i, QLatin1String(strEdges[i])); - } - int rc = m_ui.anchors->rowCount(); - for (i = 0; i < rc; ++i) { - xml.writeStartElement(QLatin1String("anchor")); - bool ok; - - QGraphicsLayoutItem *startItem = layoutItemAt(m_ui.anchors->model(), i, 0); - if (!startItem) - continue; - Qt::AnchorPoint startEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); - if (!ok) - continue; - QGraphicsLayoutItem *endItem = layoutItemAt(m_ui.anchors->model(), i, 2); - if (!endItem) - continue; - Qt::AnchorPoint endEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); - if (!ok) - continue; - - QString strStart = nodeName(startItem); - if (strStart == QLatin1String("layout")) - strStart = QLatin1String("this"); - xml.writeAttribute(QLatin1String("first"), QString::fromAscii("%1.%2").arg(strStart, edgeString.value(startEdge))); - - QString strEnd = nodeName(endItem); - if (strEnd == QLatin1String("layout")) - strEnd = QLatin1String("this"); - xml.writeAttribute(QLatin1String("second"), QString::fromAscii("%1.%2").arg(strEnd, edgeString.value(endEdge))); - - xml.writeEndElement(); - } - - xml.writeEndElement(); - xml.writeEndDocument(); - out.close(); - } - return ok; -} - -static bool parseProperty(QXmlStreamReader *xml, QString *name, QSizeF *size) -{ - QString propName = xml->attributes().value("name").toString(); - QSizeF sz; - while (!xml->atEnd()) { - xml->readNext(); - if (xml->isStartElement() && xml->name() == QLatin1String("size")) { - QXmlStreamAttributes attrs = xml->attributes(); - QString sw = attrs.value("width").toString(); - QString sh = attrs.value("height").toString(); - bool ok; - float w = sw.toFloat(&ok); - if (ok) { - sz.setWidth(w); - } - - float h = sw.toFloat(&ok); - if (ok) { - sz.setHeight(h); - } - - } - if (xml->isEndElement() && xml->name() == QLatin1String("property")) { - if (name && size && sz.isValid()) { - *name = propName; - *size = sz; - return true; - } - } - } - return false; -} - -static bool parseEdge(const QString &itemEdge, QByteArray *id, Qt::AnchorPoint *edge) -{ - QStringList item_edge = itemEdge.split(QLatin1Char('.')); - bool ok = item_edge.count() == 2; - if (ok) { - QByteArray strEdge = item_edge.at(1).toAscii().toLower(); - if (strEdge == "left") { - *edge = Qt::AnchorLeft; - } else if (strEdge == "hcenter") { - *edge = Qt::AnchorHorizontalCenter; - } else if (strEdge == "right") { - *edge = Qt::AnchorRight; - } else if (strEdge == "top") { - *edge = Qt::AnchorTop; - } else if (strEdge == "vcenter") { - *edge = Qt::AnchorVerticalCenter; - } else if (strEdge == "bottom") { - *edge = Qt::AnchorBottom; - } else { - ok = false; - } - if (ok) - *id = item_edge.at(0).toAscii(); - } - return ok; -} - -bool Window::loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout) -{ - QFile input(fileName); - bool ok = input.open(QIODevice::ReadOnly | QIODevice::Text); - if (ok) { - int i; - for (i = 0; i < m_layoutItems.count(); ++i) { - QGraphicsLayoutItem *item = m_layoutItems.at(i); - delete item; - } - - m_layoutItems.clear(); - m_ui.anchors->setRowCount(0); - - QLatin1String str_anchorlayout("anchorlayout"); - QLatin1String str_item("item"); - QLatin1String str_property("property"); - QXmlStreamReader xml(&input); - - int level = 0; - QHash<QByteArray, QGraphicsLayoutItem*> hash; - QString item_id; - QSizeF min, pref, max; - - while (!xml.atEnd()) { - QXmlStreamReader::TokenType token = xml.readNext(); - switch (token) { - case QXmlStreamReader::StartDocument: - break; - case QXmlStreamReader::StartElement: - if (level == 0 && xml.name() == str_anchorlayout) { - - } else if (level == 1 && xml.name() == str_item) { - item_id = xml.attributes().value("id").toString(); - } else if (level == 1 && xml.name() == QLatin1String("anchor")) { - QXmlStreamAttributes attrs = xml.attributes(); - QString first = attrs.value("first").toString(); - QString second = attrs.value("second").toString(); - QByteArray startID; - Qt::AnchorPoint startEdge; - QGraphicsLayoutItem *startItem = 0; - if (parseEdge(first, &startID, &startEdge)) { - if (startID == "this") { - startID = "layout"; - startItem = layout; - } else { - startItem = hash.value(startID); - } - } else { - qWarning("%s is not a valid edge description", qPrintable(first)); - break; - } - - QByteArray endID; - Qt::AnchorPoint endEdge; - QGraphicsLayoutItem *endItem = 0; - if (parseEdge(second, &endID, &endEdge)) { - if (endID == "this") { - endID = "layout"; - endItem = layout; - } else { - endItem = hash.value(endID); - } - } else { - qWarning("%s is not a valid edge description", qPrintable(second)); - break; - } - setAnchorData( startItem, startID, startEdge, - endItem, endID, endEdge, -1); - } else if (level == 2 && xml.name() == str_property) { - QString name; - QSizeF size; - if (parseProperty(&xml, &name, &size)) { - if (name == QLatin1String("minimumSize")) { - min = size; - } else if (name == QLatin1String("preferredSize")) { - pref = size; - } else if (name == QLatin1String("maximumSize")) { - max = size; - } - break; - } - } else { - --level; - } - ++level; - break; - case QXmlStreamReader::EndElement: - if (xml.name() == str_anchorlayout) { - } - if (xml.name() == str_item) { - QGraphicsLayoutItem *item = addItem(item_id); - item->setMinimumSize(min); - item->setPreferredSize(pref); - item->setMaximumSize(max); - hash.insert(item_id.toAscii(), item); - } - --level; - break; - } - } - if (xml.hasError()) { - // do error handling - qWarning("%s", qPrintable(xml.errorString())); - } - input.close(); - } - if (ok) - rebuildLayout(); - return ok; -} diff --git a/examples/layouts/anchorlayout/window.h b/examples/layouts/anchorlayout/window.h deleted file mode 100644 index f87b2c9..0000000 --- a/examples/layouts/anchorlayout/window.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef WINDOW_H -#define WINDOW_H - -#include "ui_anchorlayout.h" -#include <QtGui/qgraphicsanchorlayout.h> - -class QGraphicsWidget; -class Scene; - -class Window : public QMainWindow -{ - Q_OBJECT -public: - Window(const QStringList &arguments, QWidget *parent = 0); - -private slots: - void on_anchors_cellChanged(int row, int column); - void on_pbAddAnchor_clicked(bool); - void on_actionAdd_item_triggered(bool checked); - void on_actionSave_layout_triggered(bool checked); - void on_layouts_currentRowChanged(int row); - void on_itemName_textEdited(const QString &text); - void on_itemMinW_valueChanged(double d); - void on_itemMinH_valueChanged(double d); - void on_itemPrefW_valueChanged(double d); - void on_itemPrefH_valueChanged(double d); - void on_itemMaxW_valueChanged(double d); - void on_itemMaxH_valueChanged(double d); - - - - // not in ui file - void scene_focusItemChanged(QGraphicsItem *item); -private: - void updateItem(); - void setItemData(const QString &name, const QSizeF &min, const QSizeF &pref, const QSizeF &max); - QGraphicsLayoutItem *addItem(const QString &name = QString()); - void addAnchorRow(); - void setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, Qt::AnchorPoint startEdge, - QGraphicsLayoutItem *endItem, const QString &endName, Qt::AnchorPoint endEdge, int row = -1); - - bool saveLayout(const QString& fileName); - bool loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout); - void findLayoutFiles(); - - void rebuildLayout(); - QGraphicsLayoutItem *layoutItemAt(QAbstractItemModel *mode, int row, int column = 0); - - Ui::MainWindow m_ui; - Scene *m_scene; - bool m_changingCell; - QGraphicsWidget *m_window; - QGraphicsAnchorLayout *m_layout; - QVector<QGraphicsLayoutItem*> m_layoutItems; - QGraphicsLayoutItem *m_currentItem; - bool m_inAddAnchor; - bool m_ignoreCurrentLayoutChange; -}; - -#endif // WINDOW_H - diff --git a/examples/layouts/anchorlayout/xml/center.xml b/examples/layouts/anchorlayout/xml/center.xml deleted file mode 100644 index cf857fc..0000000 --- a/examples/layouts/anchorlayout/xml/center.xml +++ /dev/null @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<anchorlayout> - <item id="item_1"> - <property name="minimumSize"> - <size width="0" height="0"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="1.67772e+07" height="1.67772e+07"/> - </property> - </item> - <item id="item_2"> - <property name="minimumSize"> - <size width="0" height="0"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="1.67772e+07" height="1.67772e+07"/> - </property> - </item> - <item id="item_3"> - <property name="minimumSize"> - <size width="0" height="0"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="1.67772e+07" height="1.67772e+07"/> - </property> - </item> - <item id="item_4"> - <property name="minimumSize"> - <size width="0" height="0"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="1.67772e+07" height="1.67772e+07"/> - </property> - </item> - <anchor first="this.Left" second="item_1.Left"/> - <anchor first="item_1.Right" second="item_2.Left"/> - <anchor first="item_2.Right" second="item_3.Left"/> - <anchor first="item_3.Right" second="this.Right"/> - <anchor first="item_2.HCenter" second="item_4.Left"/> - <anchor first="item_4.Right" second="this.Right"/> - <anchor first="this.Top" second="item_1.Top"/> - <anchor first="this.Top" second="item_2.Top"/> - <anchor first="this.Top" second="item_3.Top"/> - <anchor first="item_1.Bottom" second="item_4.Top"/> -</anchorlayout> diff --git a/examples/layouts/anchorlayout/xml/linear.xml b/examples/layouts/anchorlayout/xml/linear.xml deleted file mode 100644 index 723b72b..0000000 --- a/examples/layouts/anchorlayout/xml/linear.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0"?> -<anchorlayout> - <item id="item1"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <item id="item2"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <item id="item3"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - - <anchor first="this.Left" second="item1.Left"/> - <anchor first="item1.Right" second="item2.Left"/> - <anchor first="item2.Right" second="item3.Left"/> - <anchor first="item3.Right" second="this.Right"/> - - <anchor first="this.Top" second="item1.Top"/> - <anchor first="this.Top" second="item2.Top"/> - <anchor first="this.Top" second="item3.Top"/> - -</anchorlayout>
\ No newline at end of file diff --git a/examples/layouts/anchorlayout/xml/snake.xml b/examples/layouts/anchorlayout/xml/snake.xml deleted file mode 100644 index 22b1a6d..0000000 --- a/examples/layouts/anchorlayout/xml/snake.xml +++ /dev/null @@ -1,79 +0,0 @@ -<?xml version="1.0"?> -<anchorlayout> - <item id="item1"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <item id="item2"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <item id="item3"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <item id="item4"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <item id="item5"> - <property name="minimumSize"> - <size width="10" height="10"/> - </property> - <property name="preferredSize"> - <size width="50" height="50"/> - </property> - <property name="maximumSize"> - <size width="100" height="100"/> - </property> - </item> - <!-- - --> - - <!-- Horizontal anchors --> - <anchor first="this.Left" second="item1.Left"/> - <anchor first="item1.Right" second="item2.Right"/> - <anchor first="item1.Right" second="item4.Right"/> - <anchor first="item3.Right" second="item4.Left"/> - <anchor first="item2.Left" second="item5.Left"/> - <anchor first="item3.Left" second="item5.Left"/> - <anchor first="item5.Right" second="this.Right"/> - - <!-- Vertical anchors --> - <anchor first="this.Top" second="item1.Top"/> - <anchor first="item1.Bottom" second="item2.Top"/> - <anchor first="item2.Bottom" second="item3.Top"/> - <anchor first="item2.Bottom" second="item4.Top"/> - <anchor first="item4.Bottom" second="item5.Top"/> - <anchor first="item3.Bottom" second="item5.Top"/> - <anchor first="item5.Bottom" second="this.Bottom"/> - -</anchorlayout>
\ No newline at end of file |