Skip to content

Commit

Permalink
Possibility to add custom actions and content in the bar
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
Pixep committed Apr 11, 2017
1 parent b88d8c0 commit 162dd27
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
57 changes: 53 additions & 4 deletions ResponsiveHelper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Item {
// List of presets to display
property ListModel presets: ListModel {}

// List of custom actions
property ListModel actions: ListModel {}

// List of custom actions
property alias extraContent: extraContentColumn.children

//**********************
// Public properties
//
Expand All @@ -35,6 +41,14 @@ Item {
readonly property int initialHeight: d.initialHeight
readonly property int initialPixelDensity: d.initialPixelDensity

// Bar width
readonly property int barWidth: 125

//**********************
// Signals
//
signal actionClicked(int actionIndex)

//**********************
// Public functions
//
Expand Down Expand Up @@ -88,6 +102,10 @@ Item {
sourceComponent: responsiveHelperComponent
}

Column {
id: extraContentColumn
visible: false
}

//**********************
// GUI
Expand All @@ -104,9 +122,9 @@ Item {
else
return targetWindow.x + targetWindow.width + root.distanceFromEdge
}
width: column.width
height: column.height
y: targetWindow.y
width: barColumn.width
height: barColumn.height
color: "#202020"
flags: Qt.FramelessWindowHint

Expand All @@ -130,9 +148,14 @@ Item {
}

Column {
id: column
id: barColumn
spacing: 1
width: 125
width: root.barWidth

Component.onCompleted: {
extraContentColumn.parent = barColumn
extraContentColumn.visible = true
}

Button {
text: "Hide"
Expand Down Expand Up @@ -371,6 +394,32 @@ Item {
}
}
}

//**********************
// Actions & Buttons
//
Text {
text: "Actions"
width: parent.width
height: d.textHeight
color: "white"
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
visible: root.actions.count > 0 || root.buttons.length > 0
}

Repeater {
model: root.actions

Button {
width: parent.width
text: model.text
onClicked: {
root.actionClicked(index);
}
}
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions example/main.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick 2.2
import QtQuick.Window 2.0
import QtQuick.Controls 1.0

Window {
id: window
Expand All @@ -23,6 +24,28 @@ Window {
ListElement { width: 480; height: 800 }
}

// Your custom action buttons
actions: ListModel {
ListElement { text: "MyAction1" }
ListElement { text: "MyAction2" }
}

// Handle clicks on your actions
onActionClicked: {
console.log(actionIndex)
}

// Your buttons or content
extraContent: [
Button {
text: "My Close Button"
width: helperBar.barWidth
onClicked: {
window.close()
}
}
]

// Handle dpi or pixelDensity changes as you wish, instead of "Screen.pixelDensity"
onDpiChanged: {
console.log("Dpi set to " + dpi)
Expand Down

0 comments on commit 162dd27

Please sign in to comment.