Skip to content

Commit

Permalink
menu bar demo
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioastarita committed Mar 21, 2019
1 parent 97d1abc commit 458c53c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 20 deletions.
44 changes: 44 additions & 0 deletions cmd/qml/LyricfierMenuBar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import QtQuick 2.2
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import QtQuick.Controls.Styles 1.3
import QtQuick.Layouts 1.12

MenuBar {
Menu {
title: "Settings"
MenuItem {
text: "+ Font size"
onClicked: root.incFontFactor()
}
MenuItem {
text: "- Font Size"
onClicked: root.decFontFactor()
}

font {
pixelSize: 11
}
}
background: Rectangle {
color: "#0F1624"
}
delegate: MenuBarItem {
id: menuBarItem
contentItem: Text {
text: menuBarItem.text
font: menuBarItem.font
opacity: enabled ? 1.0 : 0.3
color: menuBarItem.highlighted ? "#ffffff" : "#f45b69"
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 40
implicitHeight: 40
opacity: enabled ? 1 : 0.3
color: menuBarItem.highlighted ? "#f45b69" : "transparent"
}
}
}
28 changes: 23 additions & 5 deletions cmd/qml/application.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@ import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12

Item {

ApplicationWindow {
id: root
width: 274
height: 507
visible: true

property real fontFactor: 1.0

function incFontFactor() {
root.fontFactor += 0.1
}
function decFontFactor() {
root.fontFactor = root.fontFactor - 0.1
if (root.fontFactor < 0.7) {
root.fontFactor = 0.7
}
}

menuBar: LyricfierMenuBar{}

Rectangle {
color : "#0F1624"
implicitWidth: parent.width
Expand All @@ -23,7 +41,7 @@ Item {
Text {
Layout.margins: 5
id: runningStatus
font { pixelSize: 18 }
font { pixelSize: 18 * fontFactor }
text: "Is spotify running?"
visible: song.running == false
color: "#f45b69"
Expand All @@ -32,14 +50,14 @@ Item {
Text {
Layout.margins: 5
id: title
font { pixelSize: 18 }
font { pixelSize: 18 * fontFactor }
text: song.title
color: "#f45b69"
}
Text {
Layout.leftMargin: 5
id: artist
font { pixelSize: 15 }
font { pixelSize: 15 * fontFactor }
text: song.artist
color: "#028090"
}
Expand All @@ -51,7 +69,7 @@ Item {
readOnly: true
wrapMode: Text.WordWrap
selectByMouse: true
font { pixelSize: 13 }
font { pixelSize: 13 * fontFactor }
}
}
}
Expand Down
32 changes: 17 additions & 15 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package gui

import (
"fmt"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/widgets"
"github.com/therecipe/qt/gui"
. "github.com/therecipe/qt/qml"
"os"
)

Expand All @@ -21,7 +20,6 @@ func SetTitle(text string) {
}

func SetRunning(running bool) {
fmt.Printf("Setting running to %v\n", running)
guiSong.SetRunning(running)
}

Expand All @@ -35,22 +33,26 @@ type CtxObject struct {
}

func (ctx *CtxObject) init() {
ctx.ConnectRunningChanged(func(boolProp bool) {
fmt.Println(" go: changed bool ->", boolProp)
})
ctx.SetRunning(false)
}

var guiSong = NewCtxObject(nil)

func Main() {
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
app := widgets.NewQApplication(len(os.Args), os.Args)
view := quick.NewQQuickView(nil)
view.SetTitle("Lyricfier 2")
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.RootContext().SetContextProperty("song", guiSong)
view.SetSource(core.NewQUrl3("qrc:/qml/application.qml", 0))
view.Show()
app.Exec()

gui.NewQGuiApplication(len(os.Args), os.Args)
engine := NewQQmlApplicationEngine(nil)
context := engine.RootContext()
context.SetContextProperty("song", guiSong)

engine.Load(core.NewQUrl3("qrc:/qml/application.qml", 0))

//view := quick.NewQQuickView(nil)
//view.SetTitle("Lyricfier 2")
//view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
//view.SetSource(core.NewQUrl3("qrc:/qml/application.qml", 0))
//view.Show()
gui.QGuiApplication_Exec()

}

0 comments on commit 458c53c

Please sign in to comment.