[kwin/tabbox] Adjust Grid to API change

This commit is contained in:
Martin Gräßlin 2013-12-11 15:06:01 +01:00
parent 1c953821c1
commit f6eb594c2d

View file

@ -20,32 +20,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 2.0
import org.kde.kwin 0.1 as KWin
import org.kde.kwin 2.0 as KWin
Item {
id: presentWindowsTabBox
property int screenWidth : 1
property int screenHeight : 1
property int optimalWidth: 0.9*screenWidth
property int optimalHeight: 0.9*screenHeight
KWin.Switcher {
id: tabBox
currentIndex: thumbnailListView.currentIndex
PlasmaCore.Dialog {
id: dialog
location: PlasmaCore.Types.Floating
visible: tabBox.visible
windowFlags: Qt.X11BypassWindowManagerHint
onVisibleChanged: {
if (visible) {
dialog.x = tabBox.screenGeometry.x + tabBox.screenGeometry.width * 0.5 - dialogMainItem.width * 0.5;
dialog.y = tabBox.screenGeometry.y + tabBox.screenGeometry.height * 0.5 - dialogMainItem.height * 0.5;
}
}
mainItem: Item {
id: dialogMainItem
property int optimalWidth: 0.9*tabBox.screenGeometry.width
property int optimalHeight: 0.9*tabBox.screenGeometry.height
property int standardMargin: 2
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin
property int maskLeftMargin: background.centerLeftMargin
width: optimalWidth
height: optimalHeight
focus: true
function setModel(model) {
thumbnailListView.model = model;
}
ShadowedSvgItem {
id: background
anchors.fill: parent
}
// just to get the margin sizes
PlasmaCore.FrameSvgItem {
id: hoverItem
@ -55,20 +56,15 @@ Item {
}
GridView {
signal currentIndexChanged(int index)
property int rows: Math.round(Math.sqrt(count))
property int columns: (rows*rows < count) ? rows + 1 : rows
id: thumbnailListView
objectName: "listView"
model: tabBox.model
cellWidth: Math.floor(width / columns)
cellHeight: Math.floor(height / rows)
clip: true
anchors {
fill: parent
leftMargin: background.leftMargin
rightMargin: background.rightMargin
topMargin: background.topMargin
bottomMargin: background.bottomMargin
}
delegate: Item {
width: thumbnailListView.cellWidth
@ -86,7 +82,7 @@ Item {
leftMargin: hoverItem.margins.left
rightMargin: hoverItem.margins.right
topMargin: hoverItem.margins.top
bottomMargin: standardMargin
bottomMargin: dialogMainItem.standardMargin
}
}
Item {
@ -96,7 +92,7 @@ Item {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: hoverItem.margins.left + standardMargin
leftMargin: hoverItem.margins.left + dialogMainItem.standardMargin
bottomMargin: hoverItem.margins.bottom
rightMargin: hoverItem.margins.right
}
@ -112,13 +108,13 @@ Item {
}
Item {
id: textItem
property int maxWidth: parent.width - iconItem.width - parent.anchors.leftMargin - parent.anchors.rightMargin - anchors.leftMargin - standardMargin * 2
property int maxWidth: parent.width - iconItem.width - parent.anchors.leftMargin - parent.anchors.rightMargin - anchors.leftMargin - dialogMainItem.standardMargin * 2
width: (textElementSelected.implicitWidth >= maxWidth) ? maxWidth : textElementSelected.implicitWidth
anchors {
top: parent.top
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
leftMargin: standardMargin
leftMargin: dialogMainItem.standardMargin
}
Text {
id: textElementSelected
@ -149,7 +145,6 @@ Item {
anchors.fill: parent
onClicked: {
thumbnailListView.currentIndex = index;
thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex);
}
}
}
@ -161,6 +156,10 @@ Item {
height: thumbnailListView.cellHeight
}
boundsBehavior: Flickable.StopAtBounds
Connections {
target: tabBox
onCurrentIndexChanged: {thumbnailListView.currentIndex = tabBox.currentIndex;}
}
}
/*
* Key navigation on outer item for two reasons:
@ -170,16 +169,14 @@ Item {
Keys.onPressed: {
if (event.key == Qt.Key_Left) {
thumbnailListView.moveCurrentIndexLeft();
thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex);
} else if (event.key == Qt.Key_Right) {
thumbnailListView.moveCurrentIndexRight();
thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex);
} else if (event.key == Qt.Key_Up) {
thumbnailListView.moveCurrentIndexUp();
thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex);
} else if (event.key == Qt.Key_Down) {
thumbnailListView.moveCurrentIndexDown();
thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex);
}
}
}
}
}