[kwin/tabbox] Adjust Grid to API change

icc-effect-5.14.5
Martin Gräßlin 2013-12-11 15:06:01 +01:00
parent 1c953821c1
commit f6eb594c2d
1 changed files with 144 additions and 147 deletions

View File

@ -20,166 +20,163 @@ 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
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
KWin.Switcher {
id: tabBox
currentIndex: thumbnailListView.currentIndex
function setModel(model) {
thumbnailListView.model = model;
}
ShadowedSvgItem {
id: background
anchors.fill: parent
}
// just to get the margin sizes
PlasmaCore.FrameSvgItem {
id: hoverItem
imagePath: "widgets/viewitem"
prefix: "hover"
visible: false
}
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"
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
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;
}
}
delegate: Item {
width: thumbnailListView.cellWidth
height: thumbnailListView.cellHeight
KWin.ThumbnailItem {
id: thumbnailItem
wId: windowId
mainItem: Item {
id: dialogMainItem
property int optimalWidth: 0.9*tabBox.screenGeometry.width
property int optimalHeight: 0.9*tabBox.screenGeometry.height
property int standardMargin: 2
width: optimalWidth
height: optimalHeight
focus: true
// just to get the margin sizes
PlasmaCore.FrameSvgItem {
id: hoverItem
imagePath: "widgets/viewitem"
prefix: "hover"
visible: false
}
GridView {
property int rows: Math.round(Math.sqrt(count))
property int columns: (rows*rows < count) ? rows + 1 : rows
id: thumbnailListView
model: tabBox.model
cellWidth: Math.floor(width / columns)
cellHeight: Math.floor(height / rows)
clip: true
clipTo: thumbnailListView
anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: captionItem.top
leftMargin: hoverItem.margins.left
rightMargin: hoverItem.margins.right
topMargin: hoverItem.margins.top
bottomMargin: standardMargin
fill: parent
}
}
Item {
id: captionItem
height: childrenRect.height
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: hoverItem.margins.left + standardMargin
bottomMargin: hoverItem.margins.bottom
rightMargin: hoverItem.margins.right
}
QIconItem {
id: iconItem
icon: model.icon
width: 32
height: 32
anchors {
bottom: parent.bottom
right: textItem.left
delegate: Item {
width: thumbnailListView.cellWidth
height: thumbnailListView.cellHeight
KWin.ThumbnailItem {
id: thumbnailItem
wId: windowId
clip: true
clipTo: thumbnailListView
anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: captionItem.top
leftMargin: hoverItem.margins.left
rightMargin: hoverItem.margins.right
topMargin: hoverItem.margins.top
bottomMargin: dialogMainItem.standardMargin
}
}
}
Item {
id: textItem
property int maxWidth: parent.width - iconItem.width - parent.anchors.leftMargin - parent.anchors.rightMargin - anchors.leftMargin - standardMargin * 2
width: (textElementSelected.implicitWidth >= maxWidth) ? maxWidth : textElementSelected.implicitWidth
anchors {
top: parent.top
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
leftMargin: standardMargin
Item {
id: captionItem
height: childrenRect.height
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: hoverItem.margins.left + dialogMainItem.standardMargin
bottomMargin: hoverItem.margins.bottom
rightMargin: hoverItem.margins.right
}
QIconItem {
id: iconItem
icon: model.icon
width: 32
height: 32
anchors {
bottom: parent.bottom
right: textItem.left
}
}
Item {
id: textItem
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: dialogMainItem.standardMargin
}
Text {
id: textElementSelected
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: caption
font.italic: minimized
font.bold: true
visible: index == thumbnailListView.currentIndex
color: theme.textColor
elide: Text.ElideMiddle
anchors.fill: parent
}
Text {
id: textElementNormal
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: caption
font.italic: minimized
visible: index != thumbnailListView.currentIndex
color: theme.textColor
elide: Text.ElideMiddle
anchors.fill: parent
}
}
}
Text {
id: textElementSelected
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: caption
font.italic: minimized
font.bold: true
visible: index == thumbnailListView.currentIndex
color: theme.textColor
elide: Text.ElideMiddle
anchors.fill: parent
}
Text {
id: textElementNormal
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: caption
font.italic: minimized
visible: index != thumbnailListView.currentIndex
color: theme.textColor
elide: Text.ElideMiddle
MouseArea {
anchors.fill: parent
onClicked: {
thumbnailListView.currentIndex = index;
}
}
}
}
MouseArea {
anchors.fill: parent
onClicked: {
thumbnailListView.currentIndex = index;
thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex);
highlight: PlasmaCore.FrameSvgItem {
id: highlightItem
imagePath: "widgets/viewitem"
prefix: "hover"
width: thumbnailListView.cellWidth
height: thumbnailListView.cellHeight
}
boundsBehavior: Flickable.StopAtBounds
Connections {
target: tabBox
onCurrentIndexChanged: {thumbnailListView.currentIndex = tabBox.currentIndex;}
}
}
/*
* Key navigation on outer item for two reasons:
* @li we have to emit the change signal
* @li on multiple invocation it does not work on the list view. Focus seems to be lost.
**/
Keys.onPressed: {
if (event.key == Qt.Key_Left) {
thumbnailListView.moveCurrentIndexLeft();
} else if (event.key == Qt.Key_Right) {
thumbnailListView.moveCurrentIndexRight();
} else if (event.key == Qt.Key_Up) {
thumbnailListView.moveCurrentIndexUp();
} else if (event.key == Qt.Key_Down) {
thumbnailListView.moveCurrentIndexDown();
}
}
}
highlight: PlasmaCore.FrameSvgItem {
id: highlightItem
imagePath: "widgets/viewitem"
prefix: "hover"
width: thumbnailListView.cellWidth
height: thumbnailListView.cellHeight
}
boundsBehavior: Flickable.StopAtBounds
}
/*
* Key navigation on outer item for two reasons:
* @li we have to emit the change signal
* @li on multiple invocation it does not work on the list view. Focus seems to be lost.
**/
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);
}
}
}