Mercurial > projects > qtd
diff examples/layouts/borderlayout/borderlayout.d @ 204:6aeaf24018d7
more D2 examples fixes
author | eldar |
---|---|
date | Mon, 13 Jul 2009 23:16:08 +0000 |
parents | c28c0340fdf3 |
children | 7c2cf27391c4 |
line wrap: on
line diff
--- a/examples/layouts/borderlayout/borderlayout.d Mon Jul 13 17:27:34 2009 +0000 +++ b/examples/layouts/borderlayout/borderlayout.d Mon Jul 13 23:16:08 2009 +0000 @@ -52,193 +52,193 @@ { public: - enum Position { West, North, South, East, Center }; + enum Position { West, North, South, East, Center }; - this(QWidget parent, int margin = 0, int spacing = -1) - { - super(parent); - setMargin(margin); - setWidgetSpacing(spacing); - } + this(QWidget parent, int margin = 0, int spacing = -1) + { + super(parent); + setMargin(margin); + setWidgetSpacing(spacing); + } - this(int spacing = -1) - { - setWidgetSpacing(spacing); - } + this(int spacing = -1) + { + setWidgetSpacing(spacing); + } - ~this() - { - QLayoutItem l = takeAt(0); - while (l) { - delete l; - l = takeAt(0); - } - } + ~this() + { + QLayoutItem l = takeAt(0); + while (l) { + delete l; + l = takeAt(0); + } + } - void addItem(IQLayoutItem item) - { - add(item, Position.West); - } + void addItem(IQLayoutItem item) + { + add(item, Position.West); + } - void addWidget(QWidget widget, Position position) - { - add(cast(IQLayoutItem) new QWidgetItem(widget), position); - } + void addWidget(QWidget widget, Position position) + { + add(cast(IQLayoutItem) new QWidgetItem(widget), position); + } - int expandingDirections() - { - return Qt.Horizontal | Qt.Vertical; - } + int expandingDirections() + { + return Qt.Horizontal | Qt.Vertical; + } - bool hasHeightForWidth() - { - return false; - } + bool hasHeightForWidth() + { + return false; + } - int count() - { - return list.length; - } + int count() + { + return list.length; + } - QLayoutItem itemAt(int index) - { - if(index >= 0 && index < list.length) - return list[index].item; - else - return null; - } + QLayoutItem itemAt(int index) + { + if(index >= 0 && index < list.length) + return list[index].item; + else + return null; + } - QSize minimumSize() - { - return calculateSize(SizeType.MinimumSize); - } + QSize minimumSize() + { + return calculateSize(SizeType.MinimumSize); + } - void setGeometry(QRect rect) - { - ItemWrapper center = null; - int eastWidth = 0; - int westWidth = 0; - int northHeight = 0; - int southHeight = 0; - int centerHeight = 0; - int i; + void setGeometry(const QRect rect) + { + ItemWrapper center = null; + int eastWidth = 0; + int westWidth = 0; + int northHeight = 0; + int southHeight = 0; + int centerHeight = 0; + int i; - super.setGeometry(rect); + super.setGeometry(rect); - for (i = 0; i < list.length; ++i) { - ItemWrapper wrapper = list[i]; - IQLayoutItem item = wrapper.item; - Position position = wrapper.position; + for (i = 0; i < list.length; ++i) { + ItemWrapper wrapper = list[i]; + IQLayoutItem item = wrapper.item; + Position position = wrapper.position; - if (position == Position.North) { - item.setGeometry(QRect(rect.x(), northHeight, rect.width(), - item.sizeHint().height())); + if (position == Position.North) { + item.setGeometry(QRect(rect.x(), northHeight, rect.width(), + item.sizeHint().height())); - northHeight += item.geometry().height() + widgetSpacing(); - } else if (position == Position.South) { - item.setGeometry(QRect(item.geometry().x(), - item.geometry().y(), rect.width(), - item.sizeHint().height())); + northHeight += item.geometry().height() + widgetSpacing(); + } else if (position == Position.South) { + item.setGeometry(QRect(item.geometry().x(), + item.geometry().y(), rect.width(), + item.sizeHint().height())); - southHeight += item.geometry().height() + widgetSpacing(); + southHeight += item.geometry().height() + widgetSpacing(); - item.setGeometry(QRect(rect.x(), - rect.y() + rect.height() - southHeight + widgetSpacing(), - item.geometry().width(), - item.geometry().height())); - } else if (position == Position.Center) { - center = wrapper; - } - } + item.setGeometry(QRect(rect.x(), + rect.y() + rect.height() - southHeight + widgetSpacing(), + item.geometry().width(), + item.geometry().height())); + } else if (position == Position.Center) { + center = wrapper; + } + } - centerHeight = rect.height() - northHeight - southHeight; + centerHeight = rect.height() - northHeight - southHeight; - for (i = 0; i < list.length; ++i) { - ItemWrapper wrapper = list[i]; - IQLayoutItem item = wrapper.item; - Position position = wrapper.position; + for (i = 0; i < list.length; ++i) { + ItemWrapper wrapper = list[i]; + IQLayoutItem item = wrapper.item; + Position position = wrapper.position; - if (position == Position.West) { - item.setGeometry(QRect(rect.x() + westWidth, northHeight, - item.sizeHint().width(), centerHeight)); + if (position == Position.West) { + item.setGeometry(QRect(rect.x() + westWidth, northHeight, + item.sizeHint().width(), centerHeight)); - westWidth += item.geometry().width() + widgetSpacing(); - } else if (position == Position.East) { - item.setGeometry(QRect(item.geometry().x(), item.geometry().y(), - item.sizeHint().width(), centerHeight)); + westWidth += item.geometry().width() + widgetSpacing(); + } else if (position == Position.East) { + item.setGeometry(QRect(item.geometry().x(), item.geometry().y(), + item.sizeHint().width(), centerHeight)); - eastWidth += item.geometry().width() + widgetSpacing(); + eastWidth += item.geometry().width() + widgetSpacing(); - item.setGeometry(QRect( - rect.x() + rect.width() - eastWidth + widgetSpacing(), - northHeight, item.geometry().width(), - item.geometry().height())); - } - } + item.setGeometry(QRect( + rect.x() + rect.width() - eastWidth + widgetSpacing(), + northHeight, item.geometry().width(), + item.geometry().height())); + } + } - if (center) - center.item.setGeometry(QRect(westWidth, northHeight, - rect.width() - eastWidth - westWidth, - centerHeight)); - } + if (center) + center.item.setGeometry(QRect(westWidth, northHeight, + rect.width() - eastWidth - westWidth, + centerHeight)); + } - QSize sizeHint() - { - return calculateSize(SizeType.SizeHint); - } + QSize sizeHint() + { + return calculateSize(SizeType.SizeHint); + } - QLayoutItem takeAt(int index) - { - if (index >= 0 && index < list.length) { - ItemWrapper layoutStruct = list[index]; - return layoutStruct.item; - } - return null; - } + QLayoutItem takeAt(int index) + { + if (index >= 0 && index < list.length) { + ItemWrapper layoutStruct = list[index]; + return layoutStruct.item; + } + return null; + } - void add(IQLayoutItem item, Position position) - { - list ~= new ItemWrapper(item, position); - } + void add(IQLayoutItem item, Position position) + { + list ~= new ItemWrapper(item, position); + } private: - class ItemWrapper - { - this(IQLayoutItem i, Position p) - { - item = i; - position = p; - } + class ItemWrapper + { + this(IQLayoutItem i, Position p) + { + item = i; + position = p; + } - IQLayoutItem item; - Position position; - }; + IQLayoutItem item; + Position position; + }; - enum SizeType { MinimumSize, SizeHint }; + enum SizeType { MinimumSize, SizeHint }; - QSize calculateSize(SizeType sizeType) - { - QSize totalSize; + QSize calculateSize(SizeType sizeType) + { + QSize totalSize; - for (int i = 0; i < list.length; ++i) { - ItemWrapper wrapper = list[i]; - Position position = wrapper.position; - QSize itemSize; + for (int i = 0; i < list.length; ++i) { + ItemWrapper wrapper = list[i]; + Position position = wrapper.position; + QSize itemSize; - if (sizeType == SizeType.MinimumSize) - itemSize = wrapper.item.minimumSize(); - else // (sizeType == SizeHint) - itemSize = wrapper.item.sizeHint(); + if (sizeType == SizeType.MinimumSize) + itemSize = wrapper.item.minimumSize(); + else // (sizeType == SizeHint) + itemSize = wrapper.item.sizeHint(); - if (position == Position.North || position == Position.South || position == Position.Center) - totalSize.setHeight(totalSize.height + itemSize.height); - - if (position == Position.West || position == Position.East || position == Position.Center) - totalSize.setWidth(totalSize.width + itemSize.width); - } - return totalSize; - } + if (position == Position.North || position == Position.South || position == Position.Center) + totalSize.setHeight(totalSize.height + itemSize.height); + + if (position == Position.West || position == Position.East || position == Position.Center) + totalSize.setWidth(totalSize.width + itemSize.width); + } + return totalSize; + } - ItemWrapper[] list; + ItemWrapper[] list; }