diff --git a/components/Button.qml b/components/Button.qml index d046b58a467c097b775a2ddef7fac25984aab6f4..4a5ea6f7c0b67e26536ec884270cea33b2dde1ce 100644 --- a/components/Button.qml +++ b/components/Button.qml @@ -4,11 +4,10 @@ import "custom" as Components Components.Button { id: button - implicitWidth: Math.max(72, sizehint.width) - implicitHeight: Math.max(22, sizehint.height) + implicitWidth: Math.max(72, backgroundItem.implicitWidth) + implicitHeight: Math.max(22, backgroundItem.implicitHeight) property alias containsMouse: tooltip.containsMouse - property variant sizehint: backgroundItem.sizeFromContents(80, 6) property bool defaultbutton: false property string styleHint diff --git a/components/ComboBox.qml b/components/ComboBox.qml index 12290957a18660102813e15b9794490a8cd274da..c551711209c7c42c359d35be910bfeebe874e6ad 100644 --- a/components/ComboBox.qml +++ b/components/ComboBox.qml @@ -73,20 +73,19 @@ Custom.BasicButton { enabled: comboBox.enabled text: comboBox.selectedText hasFocus: comboBox.focus + contentHeight: 18 } -// ToDo: adjust margins so that selected popup label -// centers directly above button label when -// popup.centerOnSelectedText === true -// property int leftMargin: 0 -// property int topMargin: 0 -// property int rightMargin: 0 -// property int bottomMargin: 0 +// ToDo: adjust margins so that selected popup label +// centers directly above button label when +// popup.centerOnSelectedText === true + width: implicitWidth - implicitWidth: Math.max(80, backgroundItem.sizeFromContents(100, 18).height) + height: implicitHeight + implicitWidth: Math.max(80, backgroundItem.implicitWidth) + implicitHeight: backgroundItem.implicitHeight onWidthChanged: popup.setMinimumWidth(width) - height: backgroundItem.sizeFromContents(100, 18).height checkable: false onPressedChanged: if (pressed) popup.visible = true diff --git a/components/GroupBox.qml b/components/GroupBox.qml index edab89f2c49755926c63153f3d7ba199485a698f..83764c081b843c23665d0dee59a3df66f82ad2ce 100644 --- a/components/GroupBox.qml +++ b/components/GroupBox.qml @@ -3,11 +3,9 @@ import "custom" as Components Components.GroupBox { id: groupbox - implicitWidth: Math.max(200, contentWidth + sizeHint.width) - implicitHeight: contentHeight + sizeHint.height + 4 - property variant sizeHint: - backgroundItem.sizeFromContents(0, (title.length > 0 || checkable) ? 24 : 4) - property bool flat: focus + implicitWidth: Math.max(200, contentWidth + backgroundItem.implicitWidth) + implicitHeight: contentHeight + backgroundItem.implicitHeight + 4 + property bool flat: false background : StyleItem { id: styleitem elementType: "groupbox" @@ -18,5 +16,6 @@ Components.GroupBox { hasFocus: checkbox.activeFocus activeControl: checkable ? "checkbox" : "" sunken: !flat + contentHeight: (title.length > 0 || checkable) ? 24 : 4 } } diff --git a/components/ProgressBar.qml b/components/ProgressBar.qml index 3255d9dd5268a5e809c18e96320df8ef2c4394ab..b4ce5f1e304222f4c3e5d07487c9c36e0b2dbd64 100644 --- a/components/ProgressBar.qml +++ b/components/ProgressBar.qml @@ -4,12 +4,11 @@ import "custom" as Components Components.ProgressBar { id:progressbar - property variant sizehint: backgroundItem.sizeFromContents(23, 23) property int orientation: Qt.Horizontal property string styleHint - implicitWidth: orientation === Qt.Horizontal ? 200 : sizehint.height - implicitHeight: orientation === Qt.Horizontal ? sizehint.height : 200 + implicitWidth: orientation === Qt.Horizontal ? 200 : backgroundItem.implicitHeight + implicitHeight: orientation === Qt.Horizontal ? backgroundItem.implicitHeight : 200 SystemPalette {id: syspal} @@ -26,6 +25,8 @@ Components.ProgressBar { enabled: progressbar.enabled horizontal: progressbar.orientation == Qt.Horizontal hint: progressbar.styleHint + contentWidth: 23 + contentHeight: 23 } } diff --git a/components/Slider.qml b/components/Slider.qml index deec4bb2efa0d3b87c8625f1f249cf9c465be9a3..d2429b3673adc2edc3ffdd8585affddf311d7e91 100644 --- a/components/Slider.qml +++ b/components/Slider.qml @@ -9,13 +9,17 @@ Components.Slider{ property bool tickmarksEnabled: true property string tickPosition: "Below" // "Above", "Below", "BothSides" - StyleItem { id:buttonitem; elementType: "slider" } + StyleItem { + id:buttonitem + elementType: "slider" + contentWidth:23 + contentHeight:23 + } - property variant sizehint: buttonitem.sizeFromContents(23, 23) property int orientation: Qt.Horizontal - implicitWidth: orientation === Qt.Horizontal ? 200 : sizehint.height - implicitHeight: orientation === Qt.Horizontal ? sizehint.height : 200 + implicitWidth: orientation === Qt.Horizontal ? 200 : buttonitem.implicitHeight + implicitHeight: orientation === Qt.Horizontal ? buttonitem.implicitHeight : 200 property string styleHint; diff --git a/components/SpinBox.qml b/components/SpinBox.qml index b139f9a87c076b0999bade9880164e1217551c2c..cafe41454ab9f27469701449200ea4239f71f14d 100644 --- a/components/SpinBox.qml +++ b/components/SpinBox.qml @@ -16,10 +16,16 @@ Components.SpinBox { leftMargin:6 rightMargin:6 - StyleItem { id:edititem ; elementType:"edit" ; visible:false } + StyleItem { + id:edititem + elementType: "edit" + visible: false + contentWidth: 70 + contentHeight: 20 + } - implicitWidth: edititem.sizeFromContents(70, 20).width - implicitHeight: edititem.sizeFromContents(70, 20).height + implicitWidth: edititem.implicitWidth + implicitHeight: edititem.implicitHeight clip:false diff --git a/components/TabBar.qml b/components/TabBar.qml index 081a82dd44b9ca9e05f457c2d39e58d4ba6a691c..600752022676475dada6e03f00cce769bfab78e7 100644 --- a/components/TabBar.qml +++ b/components/TabBar.qml @@ -70,11 +70,9 @@ Item { z: selected ? 1 : -1 width: Math.min(implicitWidth, tabbar.width/tabs.length) function updateRect() { - var rect = style.sizeFromContents(textitem.width + tabHSpace + 2, Math.max(style.fontHeight + tabVSpace + 6, 0)) - implicitWidth = rect.width - height = rect.height + implicitWidth = style.implicitWidth + height = style.implicitHeight } - // Component.onCompleted: print("taboverlap" + tabOverlap + " tabbaseoverlap " + tabBaseOverlap + " overlap " +__overlap + " hspace " + tabHSpace) StyleItem { id: style elementType: "tab" @@ -85,10 +83,12 @@ Item { hasFocus: tabbar.focus && selected property bool first: index === 0 paintMargins: tabrow.paintMargins - activeControl: tabFrame.count == 1 ? "only" : index === 0 ? "beginning" : - index == tabFrame.count-1 ? "end" : "middle" + activeControl: tabFrame.count === 1 ? "only" : index === 0 ? "beginning" : + index === tabFrame.count-1 ? "end" : "middle" anchors.fill: parent anchors.margins: -paintMargins + contentWidth: textitem.width + tabHSpace + 2 + contentHeight: Math.max(style.fontHeight + tabVSpace + 6, 0) Text { id: textitem // Used for size hint diff --git a/components/TableView.qml b/components/TableView.qml index 5b84222264025529889c12f77f95bfa1ab95fa0b..4a7282999e7df9cd666eb35f7053d4aa817d79a1 100644 --- a/components/TableView.qml +++ b/components/TableView.qml @@ -359,7 +359,7 @@ FocusScope{ property variant modelData: itemModelData width: header[index].width - height: item ? item.height : Math.max(16, styleitem.sizeFromContents(16, 16).height) + height: item ? item.height : Math.max(16, styleitem.implicitHeight) function getValue() { if (header[index].role.length && hasOwnProperty(header[index].role)) @@ -397,7 +397,7 @@ FocusScope{ clip: true visible: headerVisible - height: headerVisible ? styleitem.sizeFromContents(text.font.pixelSize, styleitem.fontHeight).height : frameWidth + height: headerVisible ? styleitem.implicitHeight : frameWidth Behavior on height { NumberAnimation{ duration: 80 } } @@ -578,6 +578,8 @@ FocusScope{ id: styleitem elementType: "header" visible:false + contentWidth: 16 + contentHeight: fontHeight } StyleItem { diff --git a/components/TextField.qml b/components/TextField.qml index d3b8fb7bf6be0e868f25eb377e6146bf181460de..628036bfb42f8b12034bc7d27a4ea519a5443fda 100644 --- a/components/TextField.qml +++ b/components/TextField.qml @@ -11,8 +11,8 @@ Components.TextField { leftMargin: 6 rightMargin: 6 - implicitWidth: 200 - implicitHeight: backgroundItem.sizeFromContents(200, 25).height + implicitWidth: backgroundItem.implicitWidth + implicitHeight: backgroundItem.implicitHeight clip: false @@ -25,6 +25,8 @@ Components.TextField { hasFocus: textfield.activeFocus hover: containsMouse hint: textfield.styleHint + contentWidth: 200 + contentHeight: 25 } Item{ diff --git a/components/ToolBar.qml b/components/ToolBar.qml index 855895bbf6a0890ec6b3ed8a17f5b9b025d8321f..1b48a134c3e95f72610383237dc675c6fcf0772b 100644 --- a/components/ToolBar.qml +++ b/components/ToolBar.qml @@ -5,6 +5,6 @@ import "custom" as Components StyleItem { id: toolbar width: parent ? parent.width : 200 - height: 40 + height: implicitHeight elementType: "toolbar" } diff --git a/components/ToolButton.qml b/components/ToolButton.qml index 4a5f4eb583e3cb27686788158c8c787f94bea372..4bf9827a4436aa822d19fce830213bc8d392319a 100644 --- a/components/ToolButton.qml +++ b/components/ToolButton.qml @@ -8,17 +8,15 @@ Components.Button { property string iconName property string styleHint - implicitWidth: styleitem.sizeFromContents(32, 32).width - implicitHeight: styleitem.sizeFromContents(32, 32).height + implicitWidth: backgroundItem.implicitWidth + implicitHeight: backgroundItem.implicitHeight onIconNameChanged: { - if (styleitem.hasThemeIcon(iconName)) { + if (backgroundItem && backgroundItem.hasThemeIcon(iconName)) { themeIcon.source = "image://desktoptheme/" + button.iconName; } } - StyleItem {elementType: "toolbutton"; id:styleitem} - TooltipArea { // Note this will eat hover events id: tooltip @@ -36,7 +34,10 @@ Components.Button { hover: containsMouse info: __position hint: button.styleHint + contentWidth: Math.max(textitem.paintedWidth, 32) + contentHeight: 32 Text { + id: textitem text: button.text anchors.centerIn: parent visible: button.iconSource == "" diff --git a/components/custom/BasicButton.qml b/components/custom/BasicButton.qml index 3f6f8f320948122080d704be1bc881713f4d3e41..e3049ca7b76e253351b88e20cbe43222003d49bc 100644 --- a/components/custom/BasicButton.qml +++ b/components/custom/BasicButton.qml @@ -22,8 +22,8 @@ Item { // implementation property string __position: "only" - width: backgroundLoader.item.width - height: backgroundLoader.item.height + implicitWidth: backgroundLoader.item.width + implicitHeight: backgroundLoader.item.height function animateClick() { behavior.pressed = true diff --git a/components/custom/GroupBox.qml b/components/custom/GroupBox.qml index 62aebb7fd64bc7295c3122470ef80b13eb7482d2..51dab6489b4d8446d89c17c33ec1b4955a161480 100644 --- a/components/custom/GroupBox.qml +++ b/components/custom/GroupBox.qml @@ -3,8 +3,8 @@ import QtQuick 1.1 Item { id: groupbox - width: adjustToContentSize ? Math.max(200, contentWidth + loader.leftMargin + loader.rightMargin) : 100 - height: adjustToContentSize ? contentHeight + loader.topMargin + loader.bottomMargin : 100 + implicitWidth: adjustToContentSize ? Math.max(200, contentWidth + loader.leftMargin + loader.rightMargin) : 100 + implicitHeight: adjustToContentSize ? contentHeight + loader.topMargin + loader.bottomMargin : 100 default property alias data: content.data diff --git a/components/custom/private/ChoiceListPopup.qml b/components/custom/private/ChoiceListPopup.qml deleted file mode 100644 index 9c7cb38837ec2e84e2b32217b82d90a1286bd97e..0000000000000000000000000000000000000000 --- a/components/custom/private/ChoiceListPopup.qml +++ /dev/null @@ -1,322 +0,0 @@ -import QtQuick 1.1 - -MouseArea { - id: popup - - // There is no global z-ordering that can stack this popup in front, so we - // need to reparent it to the root item to fake it upon showing the popup. - // In that case, the popup will also fill the whole window to allow the user to - // close the popup by clicking anywhere in the window. Letting the popup act as the mouse - // area for the button that 'owns' it is also nessesary to support drag'n'release behavior. - - // The 'popupframe' delegate will be told to show or hide by assigning - // opacity to 1 or 0, respectively. - - anchors.fill: parent - hoverEnabled: true - - // Set 'popupOpen' to show/hide the popup. The 'state' property is more - // internal, and contains additional states used to protect the popup from - // e.g. receiving mouse clicks while its about to hide etc. - property bool popupOpen: false - - property bool desktopBehavior: true - property int previousCurrentIndex: -1 - property alias model: listView.model - property alias currentIndex: listView.currentIndex - property string currentText: model && currentIndex >= 0 ? model.get(currentIndex).text : "" - - // buttonPressed will be true when the mouse press starts - // while the popup is closed. At that point, this component can be - // seen as a button, and not yet a popup menu: - property bool buttonPressed: false - - property Component listItem - property Component listHighlight - property Component popupFrame - - property Item originalParent: parent - - onPopupOpenChanged: { - if (popupFrameLoader.item === null) - return; - if (popupOpen) { - var oldMouseX = mouseX - - // Reparent to root, so the popup stacks in front: - originalParent = parent; - var p = parent; - while (p.parent != undefined) - p = p.parent - parent = p; - - previousCurrentIndex = currentIndex; - positionPopup(); - popupFrameLoader.item.opacity = 1; - if (oldMouseX === mouseX){ - // Work around bug: mouseX and mouseY does not immidiatly - // update after reparenting and resizing the mouse area: - var pos = originalParent.mapToItem(parent, mouseX, mouseY) - highlightItemAt(pos.x, pos.y); - } else { - highlightItemAt(mouseX, mouseY); - } - listView.forceActiveFocus(); - state = "popupOpen" - } else { - popupFrameLoader.item.opacity = 0; - popup.hideHighlight(); - if (popupFrameLoader.item.opacity !== 0) - state = "popupClosed" - } - } - - Component.onCompleted: { - // In case 'popupOpen' was set to 'true' before - // 'popupFrameLoader' was finished, we open the popup now instead: - if (popup.popupOpen){ - popup.popupOpen = false - popup.popupOpen = true - } - } - - function highlightItemAt(posX, posY) - { - var mappedPos = mapToItem(listView.contentItem, posX, posY); - var indexAt = listView.indexAt(mappedPos.x, mappedPos.y); - if (indexAt == listView.highlightedIndex) - return; - if (indexAt >= 0) { - listView.highlightedIndex = indexAt; - } else { - if(posY > listView.y+listView.height && listView.highlightedIndex+1 < listView.count ) { - listView.highlightedIndex++; - } else if(posY < listView.y && listView.highlightedIndex > 0) { - listView.highlightedIndex--; - } else if(posX < popupFrameLoader.x || posX > popupFrameLoader.x+popupFrameLoader.width) { - popup.hideHighlight(); - } - } - } - - function hideHighlight() { - listView.highlightedIndex = -1; - listView.highlightedItem = null; // will trigger positionHighlight() what will hide the highlight - } - - function positionPopup() { - // Set initial values to top left corner of original parent: - var globalPos = mapFromItem(originalParent, 0, 0); - var newX = globalPos.x; - var newY = globalPos.y - var newW = originalParent.width; - var newH = listView.contentHeight - - switch (popupFrameLoader.item.popupLocation) { - case "center": - // Show centered over original parent with respect to selected item: - var itemHeight = Math.max(listView.contentHeight/listView.count, 0); - var currentItemY = Math.max(currentIndex*itemHeight, 0); - currentItemY += Math.floor(itemHeight/2 - choiceList.height/2); // correct for choiceLists that are higher than items in the list - newY -= currentItemY; - break; - case "below": - case "": - // Show below original parent: - newX -= popupFrameLoader.anchors.leftMargin; - newY += originalParent.height - popupFrameLoader.anchors.topMargin; - break; - } - - // Ensure the popup is inside the window: - if (newX < popupFrameLoader.anchors.leftMargin) - newX = popupFrameLoader.anchors.leftMargin; - else if (newX + newW > popup.width - popupFrameLoader.anchors.rightMargin) - newX = popup.width - popupFrameLoader.anchors.rightMargin - newW; - - if (newY < popupFrameLoader.anchors.topMargin) - newY = popupFrameLoader.anchors.topMargin; - else if (newY + newH > popup.height - popupFrameLoader.anchors.bottomMargin) - newY = popup.height - popupFrameLoader.anchors.bottomMargin - newH; - - // Todo: handle case when the list itself is larger than the window... - - listView.x = newX - listView.y = newY - listView.width = newW - listView.height = newH - } - - Loader { - id: popupFrameLoader - property alias styledItem: popup.originalParent - anchors.fill: listView - anchors.leftMargin: -item.anchors.leftMargin - anchors.rightMargin: -item.anchors.rightMargin - anchors.topMargin: -item.anchors.topMargin - anchors.bottomMargin: -item.anchors.bottomMargin - sourceComponent: popupFrame - onItemChanged: item.opacity = 0 - } - - ListView { - id: listView - focus: true - opacity: popupFrameLoader.item.opacity - boundsBehavior: desktopBehavior ? ListView.StopAtBounds : ListView.DragOverBounds - keyNavigationWraps: !desktopBehavior - highlightFollowsCurrentItem: false // explicitly handled below - - interactive: !desktopBehavior // disable flicking. also disables key handling - onCurrentItemChanged: { - if(desktopBehavior) { - positionViewAtIndex(currentIndex, ListView.Contain); - } - } - - property int highlightedIndex: -1 - onHighlightedIndexChanged: positionViewAtIndex(highlightedIndex, ListView.Contain) - - property variant highlightedItem: null - onHighlightedItemChanged: { - if(desktopBehavior) { - positionHighlight(); - } - } - - function positionHighlight() { - if(!Qt.isQtObject(highlightItem)) - return; - - if(!Qt.isQtObject(highlightedItem)) { - highlightItem.opacity = 0; // hide when no item is highlighted - } else { - highlightItem.x = highlightedItem.x; - highlightItem.y = highlightedItem.y; - highlightItem.width = highlightedItem.width; - highlightItem.height = highlightedItem.height; - highlightItem.opacity = 1; // show once positioned - } - } - - delegate: Item { - id: itemDelegate - width: delegateLoader.item.width - height: delegateLoader.item.height - property int theIndex: index // for some reason the loader can't bind directly to 'index' - - Loader { - id: delegateLoader - property variant model: listView.model - property alias index: itemDelegate.theIndex - property Item styledItem: choiceList - property bool highlighted: theIndex == listView.highlightedIndex - property string itemText: popup.model.get(theIndex).text - sourceComponent: listItem - } - - states: State { - name: "highlighted" - when: index == listView.highlightedIndex - StateChangeScript { - script: { - if(Qt.isQtObject(listView.highlightedItem)) { - listView.highlightedItem.yChanged.disconnect(listView.positionHighlight); - } - listView.highlightedItem = itemDelegate; - listView.highlightedItem.yChanged.connect(listView.positionHighlight); - } - } - - } - } - - function firstVisibleItem() { return indexAt(contentX+10,contentY+10); } - function lastVisibleItem() { return indexAt(contentX+width-10,contentY+height-10); } - function itemsPerPage() { return lastVisibleItem() - firstVisibleItem(); } - - Keys.onPressed: { - // with the ListView !interactive (non-flicking) we have to handle arrow keys - if (event.key == Qt.Key_Up) { - if(!highlightedItem) highlightedIndex = lastVisibleItem(); - else if(highlightedIndex > 0) highlightedIndex--; - } else if (event.key == Qt.Key_Down) { - if(!highlightedItem) highlightedIndex = firstVisibleItem(); - else if(highlightedIndex+1 < model.count) highlightedIndex++; - } else if (event.key == Qt.Key_PageUp) { - if(!highlightedItem) highlightedIndex = lastVisibleItem(); - else highlightedIndex = Math.max(highlightedIndex-itemsPerPage(), 0); - } else if (event.key == Qt.Key_PageDown) { - if(!highlightedItem) highlightedIndex = firstVisibleItem(); - else highlightedIndex = Math.min(highlightedIndex+itemsPerPage(), model.count-1); - } else if (event.key == Qt.Key_Home) { - highlightedIndex = 0; - } else if (event.key == Qt.Key_End) { - highlightedIndex = model.count-1; - } else if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { - if(highlightedIndex != -1) { - listView.currentIndex = highlightedIndex; - } else { - listView.currentIndex = popup.previousCurrentIndex; - } - - popup.popupOpen = false; - } else if (event.key == Qt.Key_Escape) { - listView.currentIndex = popup.previousCurrentIndex; - popup.popupOpen = false; - } - event.accepted = true; // consume all keys while popout has focus - } - - highlight: popup.listHighlight - } - - Timer { - // This is the time-out value for when we consider the - // user doing a press'n'release, and not just a click to - // open the popup: - id: pressedTimer - interval: 400 // Todo: fetch value from style object - } - - onPressed: { - if (state == "popupClosed") { - // Show the popup: - pressedTimer.running = true - popup.popupOpen = true - popup.buttonPressed = true - } - } - - onReleased: { - if (state == "popupOpen" && pressedTimer.running === false) { - // Either we have a 'new' click on the popup, or the user has - // done a drag'n'release. In either case, the user has done a selection: - var mappedPos = mapToItem(listView.contentItem, mouseX, mouseY); - var indexAt = listView.indexAt(mappedPos.x, mappedPos.y); - if(indexAt != -1) - listView.currentIndex = indexAt; - popup.popupOpen = false - } - popup.buttonPressed = false - } - - onPositionChanged: { - if (state == "popupOpen") - popup.highlightItemAt(mouseX, mouseY) - } - - states: [ - State { - name: "popupClosed" - when: popupFrameLoader.item.opacity === 0; - StateChangeScript { - script: parent = originalParent - } - } - ] -} - - - - diff --git a/examples/TableViewGallery.qml b/examples/TableViewGallery.qml index e64a4429c68ec2886f3628704570605af544c527..820b767e35a099ab08c5154a967bf0e2eb3eb5f8 100644 --- a/examples/TableViewGallery.qml +++ b/examples/TableViewGallery.qml @@ -9,7 +9,7 @@ Rectangle { ToolBar { id: toolbar width: parent.width - height: 40 + //height: 40 MouseArea { anchors.fill: parent diff --git a/src/qstyleitem.cpp b/src/qstyleitem.cpp index 0ab7843d1651787e17a55675c0c7c01158a68b39..253334e48437c31957701f00e9e6025be885043c 100644 --- a/src/qstyleitem.cpp +++ b/src/qstyleitem.cpp @@ -78,7 +78,11 @@ QStyleItem::QStyleItem(QDeclarativeItem *parent) m_minimum(0), m_maximum(100), m_value(0), - m_paintMargins(0) + m_paintMargins(0), + m_implicitWidth(0), + m_implicitHeight(0), + m_contentWidth(0), + m_contentHeight(0) { setFlag(QGraphicsItem::ItemHasNoContents, false); setCacheMode(QGraphicsItem::DeviceCoordinateCache); @@ -101,6 +105,10 @@ QStyleItem::QStyleItem(QDeclarativeItem *parent) connect(this, SIGNAL(hasFocusChanged()), this, SLOT(updateItem())); connect(this, SIGNAL(activeControlChanged()), this, SLOT(updateItem())); connect(this, SIGNAL(elementTypeChanged()), this, SLOT(updateItem())); + + connect(this, SIGNAL(textChanged()), this, SLOT(updateSizeHint())); + connect(this, SIGNAL(contentWidthChanged(int)), this, SLOT(updateSizeHint())); + connect(this, SIGNAL(contentHeightChanged(int)), this, SLOT(updateSizeHint())); } QStyleItem::~QStyleItem() @@ -369,10 +377,12 @@ void QStyleItem::initStyleOption() opt->text = text(); opt->lineWidth = 1; opt->subControls = QStyle::SC_GroupBoxLabel; - if (sunken()) // Qt draws an ugly line here so I ignore it + opt->features = 0; + if (sunken()) { // Qt draws an ugly line here so I ignore it opt->subControls |= QStyle::SC_GroupBoxFrame; - else + } else { opt->features |= QStyleOptionFrameV2::Flat; + } if (activeControl() == "checkbox") opt->subControls |= QStyle::SC_GroupBoxCheckBox; @@ -551,6 +561,9 @@ QSize QStyleItem::sizeFromContents(int width, int height) case CheckBox: size = qApp->style()->sizeFromContents(QStyle::CT_CheckBox, m_styleoption, QSize(width,height), widget()); break; + case ToolBar: + size = QSize(200, 40); + break; case ToolButton: size = qApp->style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(width,height), widget()); break; @@ -608,6 +621,12 @@ QSize QStyleItem::sizeFromContents(int width, int height) return size; } +void QStyleItem::updateSizeHint() +{ + QSize implicitSize = sizeFromContents(m_contentWidth, m_contentHeight); + m_implicitWidth = implicitSize.width(); + m_implicitHeight = implicitSize.height(); +} int QStyleItem::pixelMetric(const QString &metric) { @@ -844,6 +863,7 @@ void QStyleItem::setElementType(const QString &str) m_dummywidget->setAttribute(Qt::WA_DontShowOnScreen); m_dummywidget->setVisible(visible); } + updateSizeHint(); } bool QStyleItem::eventFilter(QObject *o, QEvent *e) { @@ -1174,6 +1194,16 @@ double QStyleItem::fontPointSize() return qApp->font().pointSizeF(); } +int QStyleItem::implicitHeight() +{ + return m_implicitHeight; +} + +int QStyleItem::implicitWidth() +{ + return m_implicitWidth; +} + bool QStyleItem::hasThemeIcon(const QString &icon) const { return QIcon::hasThemeIcon(icon); diff --git a/src/qstyleitem.h b/src/qstyleitem.h index 1c736f7de07feff808fc9091a7ee79e697767436..fdcbc82d8a1191e1a422b6408032582391abc76f 100644 --- a/src/qstyleitem.h +++ b/src/qstyleitem.h @@ -72,6 +72,11 @@ class QStyleItem: public QDeclarativeItem Q_PROPERTY( int step READ step WRITE setStep NOTIFY stepChanged) Q_PROPERTY( int paintMargins READ paintMargins WRITE setPaintMargins NOTIFY paintMarginsChanged) + Q_PROPERTY( int implicitWidth READ implicitWidth() NOTIFY implicitWidthChanged) + Q_PROPERTY( int implicitHeight READ implicitHeight() NOTIFY implicitHeightChanged) + Q_PROPERTY( int contentWidth READ contentWidth() WRITE setContentWidth NOTIFY contentWidthChanged) + Q_PROPERTY( int contentHeight READ contentHeight() WRITE setContentHeight NOTIFY contentHeightChanged) + Q_PROPERTY( QString fontFamily READ fontFamily NOTIFY fontHeightChanged) Q_PROPERTY( double fontPointSize READ fontPointSize NOTIFY fontHeightChanged) Q_PROPERTY( int fontHeight READ fontHeight NOTIFY fontHeightChanged) @@ -168,10 +173,21 @@ public: QString fontFamily(); double fontPointSize(); + int implicitHeight(); + int implicitWidth(); + + int contentWidth() const { + return m_contentWidth; + } + + int contentHeight() const { + return m_contentHeight; + } + public Q_SLOTS: int pixelMetric(const QString&); QVariant styleHint(const QString&); - QSize sizeFromContents(int width, int height); + void updateSizeHint(); void updateItem(){update();} QString hitTest(int x, int y); QRect subControlRect(const QString &subcontrolString); @@ -179,6 +195,22 @@ public Q_SLOTS: int textWidth(const QString &); bool hasThemeIcon(const QString &) const; + void setContentWidth(int arg) + { + if (m_contentWidth != arg) { + m_contentWidth = arg; + emit contentWidthChanged(arg); + } + } + + void setContentHeight(int arg) + { + if (m_contentHeight != arg) { + m_contentHeight = arg; + emit contentHeightChanged(arg); + } + } + Q_SIGNALS: void elementTypeChanged(); void textChanged(); @@ -201,6 +233,15 @@ Q_SIGNALS: void hintChanged(); void fontHeightChanged(); + void implicitHeightChanged(int arg); + void implicitWidthChanged(int arg); + + void contentWidthChanged(int arg); + void contentHeightChanged(int arg); + +private: + QSize sizeFromContents(int width, int height); + protected: QWidget *m_dummywidget; QStyleOption *m_styleoption; @@ -227,6 +268,12 @@ protected: int m_value; int m_step; int m_paintMargins; + + int m_implicitWidth; + int m_implicitHeight; + int m_contentWidth; + int m_contentHeight; + }; #endif //STYLEWRAPPER_H