@@ -107,9 +107,19 @@ Control {
107107 */
108108 property bool allowTooltips: true
109109
110- implicitWidth: style === BasemapGallery .ViewStyle .List ? view .cellWidth
111- : view .cellWidth * 3
112- implicitHeight: view .cellHeight * 2
110+ implicitWidth: style === BasemapGallery .ViewStyle .List ? internal .defaultCellWidthList
111+ : internal .defaultCellWidthGrid * 3
112+
113+ implicitHeight: style === BasemapGallery .ViewStyle .List ? internal .defaultCellHeightList * 2
114+ : internal .defaultCellHeightGrid * 2
115+
116+ width: {
117+ if (style === BasemapGallery .ViewStyle .Automatic && internal .calculatedStyle === BasemapGallery .ViewStyle .List ) {
118+ return internal .defaultCellWidthList ;
119+ } else {
120+ return implicitWidth;
121+ }
122+ }
113123
114124 background: Rectangle {
115125 color: basemapGallery .palette .base
@@ -152,8 +162,10 @@ Control {
152162 contentItem: GridView {
153163 id: view
154164 model: controller .gallery
155- cellWidth: 208 // Thumbnail width + 8 padding
156- cellHeight: 141 // Thumbnail height + 8 padding
165+ cellWidth: basemapGallery .internal .calculatedStyle === BasemapGallery .ViewStyle .Grid ? basemapGallery .internal .defaultCellWidthGrid
166+ : basemapGallery .internal .defaultCellWidthList
167+ cellHeight: basemapGallery .internal .calculatedStyle === BasemapGallery .ViewStyle .Grid ? basemapGallery .internal .defaultCellHeightGrid
168+ : basemapGallery .internal .defaultCellHeightList
157169 clip: true
158170 snapMode: GridView .SnapToRow
159171 currentIndex: controller .basemapIndex (controller .currentBasemap )
@@ -162,35 +174,49 @@ Control {
162174 width: view .cellWidth
163175 height: view .cellHeight
164176 enabled: controller .basemapMatchesCurrentSpatialReference (modelData .basemap )
165- Image {
166- anchors .centerIn : parent
167- id: thumbnailItem
168- width: 200
169- height: 133
170- source: modelData .thumbnailUrl
171- cache: false
177+ ToolTip .visible : allowTooltips && mouseArea .containsMouse && modelData .tooltip !== " "
178+ ToolTip .delay : Qt .styleHints .mousePressAndHoldInterval
179+ ToolTip .text : modelData .tooltip
180+ GridLayout {
181+ anchors .fill : parent
182+ anchors .margins : 8
183+ flow: {
184+ if (basemapGallery .internal .calculatedStyle === BasemapGallery .ViewStyle .List ) {
185+ return GridLayout .LeftToRight ;
186+ } else if (basemapGallery .internal .calculatedStyle === BasemapGallery .ViewStyle .Grid ) {
187+ return GridLayout .TopToBottom ;
188+ }
189+ }
190+ Image {
191+ id: thumbnailItem
192+ source: modelData .thumbnailUrl
193+ cache: false
194+ fillMode: Image .PreserveAspectCrop
195+ clip: true
196+ Layout .maximumWidth : basemapGallery .internal .defaultCellSize
197+ Layout .maximumHeight : Layout .maximumWidth
198+ Layout .alignment : Qt .AlignHCenter | Qt .AlignTop
199+ }
172200 Text {
173201 id: itemText
174- anchors .fill : parent
175- style: Text .Outline
176- styleColor: " black"
177- color: " white"
202+ color: GridView .isCurrentItem ? palette .highlightedText : palette .text
178203 text: modelData .name === " " ? " Unnamed basemap" : modelData .name
179204 horizontalAlignment: Text .AlignHCenter
180- verticalAlignment: Text .AlignVCenter
205+ verticalAlignment: (basemapGallery .internal .calculatedStyle === BasemapGallery .ViewStyle .Grid ) ? Qt .AlignTop
206+ : Qt .AlignVCenter
181207 minimumPointSize: 16
182208 wrapMode: Text .WordWrap
183209 font: basemapGallery .font
210+ elide: Text .ElideRight
211+ Layout .fillWidth : true
212+ Layout .fillHeight : true
184213 }
185- MouseArea {
186- id: mouseArea
187- anchors .fill : parent
188- hoverEnabled: true
189- onClicked: controller .setCurrentBasemap (modelData .basemap )
190- }
191- ToolTip .visible : allowTooltips && mouseArea .containsMouse && modelData .tooltip !== " "
192- ToolTip .delay : Qt .styleHints .mousePressAndHoldInterval
193- ToolTip .text : modelData .tooltip
214+ }
215+ MouseArea {
216+ id: mouseArea
217+ anchors .fill : parent
218+ hoverEnabled: true
219+ onClicked: controller .setCurrentBasemap (modelData .basemap )
194220 }
195221 }
196222 highlightFollowsCurrentItem: false
@@ -205,16 +231,28 @@ Control {
205231 }
206232 }
207233
208- // If we have automatic styling, resize the the view between grid/list based
209- // on available space in the parent.
210- Connections {
211- target: parent
212- enabled: style === BasemapGallery .ViewStyle .Automatic
213- function onWidthChanged () {
214- if (parent .width < implicitWidth) {
215- width = view .cellWidth ;
216- } else {
217- width = implicitWidth;
234+ property QtObject internal: QtObject {
235+ property int defaultCellSize: 100 ;
236+
237+ property int defaultCellHeightGrid: defaultCellSize + 86 ;
238+ property int defaultCellWidthGrid: defaultCellSize + 16 ;
239+
240+ property int defaultCellHeightList: defaultCellSize + 16 ;
241+ property int defaultCellWidthList: defaultCellSize + 116 ;
242+
243+ property int calculatedStyle: {
244+ switch (basemapGallery .style ) {
245+ case BasemapGallery .ViewStyle .List :
246+ return BasemapGallery .ViewStyle .List ;
247+ case BasemapGallery .ViewStyle .Grid :
248+ return BasemapGallery .ViewStyle .Grid ;
249+ case BasemapGallery .ViewStyle .Automatic :
250+ if (basemapGallery .parent .width < basemapGallery .implicitWidth ) {
251+ return BasemapGallery .ViewStyle .List ;
252+ } else {
253+ return BasemapGallery .ViewStyle .Grid ;
254+ }
255+
218256 }
219257 }
220258 }
0 commit comments