Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added support for headset button in the settings dialog to qml
  • Loading branch information
xerxes2 committed Jul 20, 2011
1 parent ba22bd0 commit e18081a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 33 deletions.
2 changes: 0 additions & 2 deletions data/panucci.conf
Expand Up @@ -18,5 +18,3 @@ main_height = 285
button_border_width = 6
button_radius = 10
font_size = 14
# headset_button should be short, long or switch
headset_button = switch
101 changes: 77 additions & 24 deletions data/ui/qml/Settings.qml
Expand Up @@ -20,14 +20,14 @@ Item {
width: root.width - config.button_width - config.button_border_width
height: root.height
contentWidth: root.width - config.button_width - config.button_border_width
contentHeight: (config.font_size * 52.5)
clip: true

MouseArea {
anchors.fill: parent
onClicked: settingsArea.close()
}
Text {
id: main_window_text
y: config.font_size
anchors.horizontalCenter: parent.horizontalCenter
text: main_window_str
Expand All @@ -37,7 +37,7 @@ Item {
SettingsButton {
id: action_scrolling_labels_button
checked: action_scrolling_labels.checked
y: config.font_size * 3.5
y: main_window_text.y + (config.font_size * 2.5)
text: action_scrolling_labels.text
onClicked: { if (action_scrolling_labels_button.checked) {
action_scrolling_labels_button.checked = false
Expand All @@ -50,7 +50,7 @@ Item {
SettingsButton {
id: action_lock_progress_button
checked: action_lock_progress.checked
y: config.font_size * 8.5
y: action_scrolling_labels_button.y + (config.font_size * 5)
text: action_lock_progress.text
onClicked: { if (action_lock_progress_button.checked) {
action_lock_progress_button.checked = false
Expand All @@ -63,7 +63,7 @@ Item {
SettingsButton {
id: action_dual_action_button
checked: action_dual_action.checked
y: config.font_size * 13.5
y: action_lock_progress_button.y + (config.font_size * 5)
text: action_dual_action.text
onClicked: { if (action_dual_action_button.checked) {
action_dual_action_button.checked = false
Expand All @@ -74,7 +74,8 @@ Item {
}
}
Text {
y: config.font_size * 19
id: playback_text
y: action_dual_action_button.y + (config.font_size * 5.5)
anchors.horizontalCenter: parent.horizontalCenter
text: playback_str
font.pixelSize: config.font_size * 1.5
Expand All @@ -83,7 +84,7 @@ Item {
SettingsButton {
id: action_stay_at_end_button
checked: action_stay_at_end.checked
y: config.font_size * 21.5
y: playback_text.y + (config.font_size * 2.5)
text: action_stay_at_end.text
onClicked: { if (action_stay_at_end_button.checked) {
action_stay_at_end_button.checked = false
Expand All @@ -96,7 +97,7 @@ Item {
SettingsButton {
id: action_seek_back_button
checked: action_seek_back.checked
y: config.font_size * 26.5
y: action_stay_at_end_button.y + (config.font_size * 5.5)
text: action_seek_back.text
onClicked: { if (action_seek_back_button.checked) {
action_seek_back_button.checked = false
Expand All @@ -109,7 +110,7 @@ Item {
SettingsButton {
id: action_resume_all_button
checked: action_resume_all.checked
y: config.font_size * 31.5
y: action_seek_back_button.y + (config.font_size * 5.5)
text: action_resume_all.text
onClicked: { if (action_resume_all_button.checked) {
action_resume_all_button.checked = false
Expand All @@ -119,8 +120,22 @@ Item {
}
}
}
SettingsButton {
id: action_play_on_headset_button
checked: action_play_on_headset.checked
y: action_resume_all_button.y + (config.font_size * 5.5)
text: action_play_on_headset.text
onClicked: { if (action_play_on_headset_button.checked) {
action_play_on_headset_button.checked = false
}
else {
action_play_on_headset_button.checked = true
}
}
}
Text {
y: config.font_size * 37
id: play_mode_text
y: action_play_on_headset_button.y + (config.font_size * 5.5)
anchors.horizontalCenter: parent.horizontalCenter
text: play_mode_str
font.pixelSize: config.font_size * 1.5
Expand All @@ -129,8 +144,8 @@ Item {
SettingsButtonSmall {
id: action_play_mode_all_button
checked: action_play_mode_all.checked
y: config.font_size * 39.5
x: parent.width / 25
y: play_mode_text.y + (config.font_size * 2.5)
text: action_play_mode_all.text
onClicked: { action_play_mode_all_button.checked = true
action_play_mode_single_button.checked = false
Expand All @@ -141,10 +156,8 @@ Item {
SettingsButtonSmall {
id: action_play_mode_single_button
checked: action_play_mode_single.checked
width: parent.width / 5
height: config.font_size * 4
y: config.font_size * 39.5
x: (parent.width / 25 * 2) + width
y: action_play_mode_all_button.y
text: action_play_mode_single.text
onClicked: { action_play_mode_all_button.checked = false
action_play_mode_single_button.checked = true
Expand All @@ -155,10 +168,8 @@ Item {
SettingsButtonSmall {
id: action_play_mode_random_button
checked: action_play_mode_random.checked
width: parent.width / 5
height: config.font_size * 4
y: config.font_size * 39.5
x: (parent.width / 25 * 3) + (width * 2)
y: action_play_mode_all_button.y
text: action_play_mode_random.text
onClicked: { action_play_mode_all_button.checked = false
action_play_mode_single_button.checked = false
Expand All @@ -169,10 +180,8 @@ Item {
SettingsButtonSmall {
id: action_play_mode_repeat_button
checked: action_play_mode_repeat.checked
width: parent.width / 5
height: config.font_size * 4
y: config.font_size * 39.5
x: (parent.width / 25 * 4) + (width * 3)
y: action_play_mode_all_button.y
text: action_play_mode_repeat.text
onClicked: { action_play_mode_all_button.checked = false
action_play_mode_single_button.checked = false
Expand All @@ -181,7 +190,49 @@ Item {
}
}
Text {
y: config.font_size * 45
id: headset_button_text
y: action_play_mode_all_button.y + (config.font_size * 5.5)
anchors.horizontalCenter: parent.horizontalCenter
text: headset_button_str
font.pixelSize: config.font_size * 1.5
color: themeController.foreground
}
SettingsButtonSmall {
id: action_headset_button_short_button
checked: action_headset_button_short.checked
x: ((parent.width / 5 * 2) - (parent.width / 25 * 2)) / 2
y: headset_button_text.y + (config.font_size * 2.5)
text: action_headset_button_short.text
onClicked: { action_headset_button_short_button.checked = true
action_headset_button_long_button.checked = false
action_headset_button_switch_button.checked = false
}
}
SettingsButtonSmall {
id: action_headset_button_long_button
checked: action_headset_button_long.checked
x: action_headset_button_short_button.x + width + (parent.width / 25)
y: action_headset_button_short_button.y
text: action_headset_button_long.text
onClicked: { action_headset_button_short_button.checked = false
action_headset_button_long_button.checked = true
action_headset_button_switch_button.checked = false
}
}
SettingsButtonSmall {
id: action_headset_button_switch_button
checked: action_headset_button_switch.checked
x: action_headset_button_long_button.x + width + (parent.width / 25)
y: action_headset_button_short_button.y
text: action_headset_button_switch.text
onClicked: { action_headset_button_short_button.checked = false
action_headset_button_long_button.checked = false
action_headset_button_switch_button.checked = true
}
}
Text {
id: theme_text
y: action_headset_button_short_button.y + (config.font_size * 5.5)
anchors.horizontalCenter: parent.horizontalCenter
text: theme_str
font.pixelSize: config.font_size * 1.5
Expand Down Expand Up @@ -211,14 +262,16 @@ Item {
}
property variant actions: [action_scrolling_labels, action_lock_progress,
action_dual_action, action_stay_at_end, action_seek_back,
action_resume_all,
action_resume_all, action_play_on_headset,
action_play_mode_all, action_play_mode_single,
action_play_mode_random, action_play_mode_repeat]
action_play_mode_random, action_play_mode_repeat,
action_headset_button_short, action_headset_button_long, action_headset_button_switch]
property variant buttons: [action_scrolling_labels_button, action_lock_progress_button,
action_dual_action_button, action_stay_at_end_button, action_seek_back_button,
action_resume_all_button,
action_resume_all_button, action_play_on_headset_button,
action_play_mode_all_button, action_play_mode_single_button,
action_play_mode_random_button, action_play_mode_repeat_button]
action_play_mode_random_button, action_play_mode_repeat_button,
action_headset_button_short_button, action_headset_button_long_button, action_headset_button_switch_button]
onClose: { var i=0
for (i=0;i<settingsArea.actions.length;i++) {
settingsArea.buttons[i].checked = settingsArea.actions[i].checked
Expand Down
2 changes: 1 addition & 1 deletion data/ui/qml/themeGenerator.js
Expand Up @@ -5,7 +5,7 @@ function createThemeButtons() {
var component
component = Qt.createComponent("SettingsButtonSmall.qml")
var button
var ypos = config.font_size * 47.5
var ypos = theme_text.y + (config.font_size * 2.5)
var count = 0
var i
for (i=0;i<themes.length;i++) {
Expand Down
54 changes: 48 additions & 6 deletions src/panucci/qmlui/qmlmain.py
Expand Up @@ -172,6 +172,11 @@ def create_actions(self):
self.action_resume_all.setCheckable(True)
self.action_resume_all.setChecked(self.config.getboolean("options", "resume_all"))
self.context.setContextProperty('action_resume_all', self.action_resume_all)
self.action_play_on_headset = QtGui.QAction(_("Play on Headset").decode("utf-8"), self.view, shortcut="Ctrl+B",
statusTip="Start playback automatically when connecting headset", triggered=self.play_on_headset_callback)
self.action_play_on_headset.setCheckable(True)
self.action_play_on_headset.setChecked(self.config.getboolean("options", "play_on_headset"))
self.context.setContextProperty('action_play_on_headset', self.action_play_on_headset)
self.play_mode_str = _("Play Mode").decode("utf-8")
self.context.setContextProperty('play_mode_str', self.play_mode_str)
self.action_play_mode_all = QtGui.QAction(_("All").decode("utf-8"), self.view, statusTip="Set play mode",
Expand All @@ -190,12 +195,12 @@ def create_actions(self):
triggered=self.play_mode_repeat_callback)
self.action_play_mode_repeat.setCheckable(True)
self.context.setContextProperty('action_play_mode_repeat', self.action_play_mode_repeat)
actiongroup = QtGui.QActionGroup(self.view)
actiongroup.setExclusive(True)
self.action_play_mode_all.setActionGroup(actiongroup)
self.action_play_mode_single.setActionGroup(actiongroup)
self.action_play_mode_random.setActionGroup(actiongroup)
self.action_play_mode_repeat.setActionGroup(actiongroup)
actiongroup_play_mode = QtGui.QActionGroup(self.view)
actiongroup_play_mode.setExclusive(True)
self.action_play_mode_all.setActionGroup(actiongroup_play_mode)
self.action_play_mode_single.setActionGroup(actiongroup_play_mode)
self.action_play_mode_random.setActionGroup(actiongroup_play_mode)
self.action_play_mode_repeat.setActionGroup(actiongroup_play_mode)
if self.config.get("options", "play_mode") == "single":
self.action_play_mode_single.setChecked(True)
elif self.config.get("options", "play_mode") == "random":
Expand All @@ -204,6 +209,31 @@ def create_actions(self):
self.action_play_mode_repeat.setChecked(True)
else:
self.action_play_mode_all.setChecked(True)
self.headset_button_str = _("Headset Button").decode("utf-8")
self.context.setContextProperty('headset_button_str', self.headset_button_str)
self.action_headset_button_short = QtGui.QAction(_("Short").decode("utf-8"), self.view,
triggered=self.headset_button_short_callback)
self.action_headset_button_short.setCheckable(True)
self.context.setContextProperty('action_headset_button_short', self.action_headset_button_short)
self.action_headset_button_long = QtGui.QAction(_("Long").decode("utf-8"), self.view,
triggered=self.headset_button_long_callback)
self.action_headset_button_long.setCheckable(True)
self.context.setContextProperty('action_headset_button_long', self.action_headset_button_long)
self.action_headset_button_switch = QtGui.QAction(_("Switch").decode("utf-8"), self.view,
triggered=self.headset_button_switch_callback)
self.action_headset_button_switch.setCheckable(True)
self.context.setContextProperty('action_headset_button_switch', self.action_headset_button_switch)
actiongroup_headset_button = QtGui.QActionGroup(self.view)
actiongroup_headset_button.setExclusive(True)
self.action_headset_button_short.setActionGroup(actiongroup_headset_button)
self.action_headset_button_long.setActionGroup(actiongroup_headset_button)
self.action_headset_button_switch.setActionGroup(actiongroup_headset_button)
if self.config.get("options", "headset_button") == "short":
self.action_headset_button_short.setChecked(True)
elif self.config.get("options", "headset_button") == "long":
self.action_headset_button_long.setChecked(True)
else:
self.action_headset_button_switch.setChecked(True)
self.theme_str = _('Theme').decode("utf-8")
self.context.setContextProperty('theme_str', self.theme_str)
# help menu
Expand Down Expand Up @@ -424,6 +454,9 @@ def resume_all_callback(self):
if not self.action_resume_all.isChecked():
self.playlist.reset_all_seek_to()

def play_on_headset_callback(self):
self.set_config_option("play_on_headset", str(self.action_play_on_headset.isChecked()).lower())

def play_mode_all_callback(self):
self.set_config_option("play_mode", "all")

Expand All @@ -436,6 +469,15 @@ def play_mode_random_callback(self):
def play_mode_repeat_callback(self):
self.set_config_option("play_mode", "repeat")

def headset_button_short_callback(self):
self.set_config_option("headset_button", "short")

def headset_button_long_callback(self):
self.set_config_option("headset_button", "long")

def headset_button_switch_callback(self):
self.set_config_option("headset_button", "switch")

def about_callback(self):
from panucci import about
self.view.rootObject().openAboutDialog([about.about_name+" "+panucci.__version__, about.about_text,
Expand Down

0 comments on commit e18081a

Please sign in to comment.