2023-08-24 15:50:37 +08:00
import QtQuick 2.15
import QtQuick . Window 2.15
import QtQuick . Controls 2.15
import QtQuick . Layouts 1.15
2024-03-18 17:07:44 +08:00
import QtQml 2.15
2023-08-24 15:50:37 +08:00
import Qt . labs . platform 1.1
import FluentUI 1.0
import example 1.0
2023-09-12 18:45:15 +08:00
import "../component"
import "../global"
2023-02-26 23:47:07 +08:00
2023-10-08 19:48:32 +08:00
FluWindow {
2023-04-22 18:08:11 +08:00
2023-04-16 02:28:58 +08:00
id:window
2023-04-22 18:08:11 +08:00
title: "FluentUI"
2024-03-09 22:26:21 +08:00
width: 1000
height: 680
2024-04-30 19:27:57 +08:00
minimumWidth: 800
2023-07-03 18:08:25 +08:00
minimumHeight: 200
2023-07-18 18:24:06 +08:00
launchMode: FluWindowType . SingleTask
2023-11-21 14:28:37 +08:00
fitsAppBarWindows: true
appBar: FluAppBar {
2024-03-19 12:50:16 +08:00
width: window . width
2023-11-21 14:28:37 +08:00
height: 30
showDark: true
darkClickListener: ( button ) = > handleDarkChanged ( button )
closeClickListener: ( ) = > { dialog_close . open ( ) }
z: 7
}
2023-02-27 18:46:39 +08:00
2024-04-17 15:11:14 +08:00
FluentInitializrWindow {
id:fluent_Initializr
}
2023-09-11 18:10:50 +08:00
FluEvent {
name: "checkUpdate"
onTriggered: {
checkUpdate ( false )
}
}
2024-03-28 19:18:56 +08:00
onLazyLoad: {
tour . open ( )
2023-11-27 16:45:37 +08:00
}
Component.onCompleted: {
2023-09-11 18:10:50 +08:00
checkUpdate ( true )
}
Component.onDestruction: {
2024-03-27 00:36:56 +08:00
FluRouter . exit ( )
2023-07-11 10:46:57 +08:00
}
2023-04-16 02:28:58 +08:00
SystemTrayIcon {
2023-04-20 19:15:38 +08:00
id:system_tray
2023-04-16 02:28:58 +08:00
visible: true
2023-04-27 09:38:57 +08:00
icon.source: "qrc:/example/res/image/favicon.ico"
2023-04-19 09:41:08 +08:00
tooltip: "FluentUI"
menu: Menu {
MenuItem {
text: "退出"
onTriggered: {
2024-03-27 00:36:56 +08:00
FluRouter . exit ( )
2023-04-19 09:41:08 +08:00
}
}
2023-04-16 02:28:58 +08:00
}
2023-04-19 09:41:08 +08:00
onActivated:
( reason ) = > {
if ( reason === SystemTrayIcon . Trigger ) {
window . show ( )
window . raise ( )
window . requestActivate ( )
}
}
2023-04-16 02:28:58 +08:00
}
2023-12-04 17:10:08 +08:00
Timer {
2024-03-09 15:35:48 +08:00
id: timer_window_hide_delay
2023-12-04 17:10:08 +08:00
interval: 150
onTriggered: {
window . hide ( )
}
}
2023-04-20 18:10:45 +08:00
FluContentDialog {
2024-03-09 15:35:48 +08:00
id: dialog_close
title: qsTr ( "Quit" )
message: qsTr ( "Are you sure you want to exit the program?" )
negativeText: qsTr ( "Minimize" )
2023-07-18 18:24:06 +08:00
buttonFlags: FluContentDialogType . NegativeButton | FluContentDialogType . NeutralButton | FluContentDialogType . PositiveButton
2023-12-04 17:10:08 +08:00
onNegativeClicked: {
2024-03-09 15:35:48 +08:00
system_tray . showMessage ( qsTr ( "Friendly Reminder" ) , qsTr ( "FluentUI is hidden from the tray, click on the tray to activate the window again" ) ) ;
2023-12-04 17:10:08 +08:00
timer_window_hide_delay . restart ( )
2023-04-20 18:10:45 +08:00
}
2024-03-09 15:35:48 +08:00
positiveText: qsTr ( "Quit" )
neutralText: qsTr ( "Cancel" )
2023-04-20 18:10:45 +08:00
onPositiveClicked: {
2024-03-27 00:36:56 +08:00
FluRouter . exit ( 0 )
2023-10-19 22:52:36 +08:00
}
}
Component {
2024-03-09 15:35:48 +08:00
id: nav_item_right_menu
2023-10-19 22:52:36 +08:00
FluMenu {
2024-03-09 23:42:01 +08:00
width: 186
2023-10-19 22:52:36 +08:00
FluMenuItem {
2024-03-09 15:35:48 +08:00
text: qsTr ( "Open in Separate Window" )
2024-04-04 01:10:14 +08:00
font: FluTextStyle . Caption
2023-10-19 22:52:36 +08:00
onClicked: {
2024-03-27 00:36:56 +08:00
FluRouter . navigate ( "/pageWindow" , { title: modelData . title , url: modelData . url } )
2023-10-19 22:52:36 +08:00
}
}
2023-04-20 18:10:45 +08:00
}
2023-05-17 18:15:15 +08:00
}
2023-04-20 18:10:45 +08:00
2023-06-09 18:15:09 +08:00
Flipable {
id:flipable
anchors.fill: parent
property bool flipped: false
2023-06-10 11:01:36 +08:00
property real flipAngle: 0
2023-06-09 18:15:09 +08:00
transform: Rotation {
id: rotation
origin.x: flipable . width / 2
origin.y: flipable . height / 2
axis { x: 0 ; y: 1 ; z: 0 }
2023-06-10 11:01:36 +08:00
angle: flipable . flipAngle
2023-04-20 18:10:45 +08:00
2023-06-09 18:15:09 +08:00
}
states: State {
2023-06-10 11:01:36 +08:00
PropertyChanges { target: flipable ; flipAngle: 180 }
2023-06-09 18:15:09 +08:00
when: flipable . flipped
}
transitions: Transition {
2023-07-03 18:08:25 +08:00
NumberAnimation { target: flipable ; property: "flipAngle" ; duration: 1000 ; easing.type: Easing . OutCubic }
2023-06-09 18:15:09 +08:00
}
back: Item {
anchors.fill: flipable
2023-06-10 11:01:36 +08:00
visible: flipable . flipAngle !== 0
2023-06-12 16:46:02 +08:00
Row {
2023-11-21 14:28:37 +08:00
id:layout_back_buttons
2023-06-09 18:15:09 +08:00
z: 8
2023-06-27 00:17:01 +08:00
anchors {
top: parent . top
left: parent . left
topMargin: FluTools . isMacos ( ) ? 20 : 5
leftMargin: 5
}
2023-06-12 16:46:02 +08:00
FluIconButton {
iconSource: FluentIcons . ChromeBack
width: 30
height: 30
iconSize: 13
onClicked: {
flipable . flipped = false
}
}
FluIconButton {
iconSource: FluentIcons . Sync
width: 30
height: 30
iconSize: 13
onClicked: {
loader . reload ( )
}
2023-03-30 17:16:57 +08:00
}
2024-02-26 15:50:42 +08:00
Component.onCompleted: {
2024-03-28 19:18:56 +08:00
window . setHitTestVisible ( layout_back_buttons )
2024-02-26 15:50:42 +08:00
}
2023-06-09 18:15:09 +08:00
}
2023-06-12 16:46:02 +08:00
FluRemoteLoader {
id:loader
2023-06-25 19:01:22 +08:00
lazy: true
2023-06-12 16:46:02 +08:00
anchors.fill: parent
2024-03-27 10:52:47 +08:00
source: "https://zhu-zichu.gitee.io/Qt_174_LieflatPage.qml"
2023-06-09 18:15:09 +08:00
}
2023-03-30 17:16:57 +08:00
}
2023-06-09 18:15:09 +08:00
front: Item {
2023-06-10 11:01:36 +08:00
id:page_front
visible: flipable . flipAngle !== 180
2023-06-09 18:15:09 +08:00
anchors.fill: flipable
FluNavigationView {
property int clickCount: 0
id:nav_view
width: parent . width
height: parent . height
z: 999
2023-07-06 18:17:52 +08:00
//Stack模式, 每次切换都会将页面压入栈中, 随着栈的页面增多, 消耗的内存也越多, 内存消耗多就会卡顿, 这时候就需要按返回将页面pop掉, 释放内存。该模式可以配合FluPage中的launchMode属性, 设置页面的启动模式
2023-09-08 22:33:23 +08:00
// pageMode: FluNavigationViewType.Stack
2024-03-27 00:36:56 +08:00
//NoStack模式, 每次切换都会销毁之前的页面然后创建一个新的页面, 只需消耗少量内存
2023-09-08 22:33:23 +08:00
pageMode: FluNavigationViewType . NoStack
2023-06-09 18:15:09 +08:00
items: ItemsOriginal
footerItems: ItemsFooter
2023-12-13 18:13:35 +08:00
topPadding: {
if ( window . useSystemAppBar ) {
return 0
}
return FluTools . isMacos ( ) ? 20 : 0
}
2024-03-27 00:36:56 +08:00
displayMode: GlobalModel . displayMode
2023-06-09 18:15:09 +08:00
logo: "qrc:/example/res/image/favicon.ico"
title: "FluentUI"
2023-07-01 07:54:43 +08:00
onLogoClicked: {
2023-06-09 18:15:09 +08:00
clickCount += 1
2024-03-09 15:35:48 +08:00
showSuccess ( "%1:%2" . arg ( qsTr ( "Click Time" ) ) . arg ( clickCount ) )
2023-08-07 21:46:54 +08:00
if ( clickCount === 5 ) {
2023-06-12 16:46:02 +08:00
loader . reload ( )
2023-06-09 18:15:09 +08:00
flipable . flipped = true
clickCount = 0
}
}
autoSuggestBox: FluAutoSuggestBox {
iconSource: FluentIcons . Search
items: ItemsOriginal . getSearchData ( )
2024-03-09 15:35:48 +08:00
placeholderText: qsTr ( "Search" )
2023-06-09 18:15:09 +08:00
onItemClicked:
( data ) = > {
ItemsOriginal . startPageByItem ( data )
}
}
Component.onCompleted: {
ItemsOriginal . navigationView = nav_view
2023-10-19 22:52:36 +08:00
ItemsOriginal . paneItemMenu = nav_item_right_menu
2023-06-09 18:15:09 +08:00
ItemsFooter . navigationView = nav_view
2023-10-19 22:52:36 +08:00
ItemsFooter . paneItemMenu = nav_item_right_menu
2024-03-28 19:18:56 +08:00
window . setHitTestVisible ( nav_view . buttonMenu )
window . setHitTestVisible ( nav_view . buttonBack )
window . setHitTestVisible ( nav_view . imageLogo )
2023-06-09 18:15:09 +08:00
setCurrentIndex ( 0 )
}
}
2023-02-26 23:47:07 +08:00
}
}
2023-06-10 11:01:36 +08:00
2023-07-25 21:24:45 +08:00
Component {
2024-03-11 18:55:33 +08:00
id: com_reveal
2023-07-25 21:24:45 +08:00
CircularReveal {
2024-03-11 18:55:33 +08:00
id: reveal
target: window . contentItem
2023-07-25 21:24:45 +08:00
anchors.fill: parent
onAnimationFinished: {
//动画结束后释放资源
loader_reveal . sourceComponent = undefined
}
onImageChanged: {
changeDark ( )
}
2023-06-10 11:01:36 +08:00
}
}
2023-11-02 23:02:08 +08:00
FluLoader {
2023-07-25 21:24:45 +08:00
id:loader_reveal
anchors.fill: parent
}
2023-06-10 11:01:36 +08:00
function distance ( x1 , y1 , x2 , y2 ) {
return Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )
}
function handleDarkChanged ( button ) {
2024-03-29 16:23:16 +08:00
if ( ! FluTheme . animationEnabled || window . fitsAppBarWindows === false ) {
2023-06-29 17:48:48 +08:00
changeDark ( )
} else {
2023-12-05 00:20:40 +08:00
if ( loader_reveal . sourceComponent ) {
return
}
2023-07-25 21:24:45 +08:00
loader_reveal . sourceComponent = com_reveal
2024-03-11 18:55:33 +08:00
var target = window . contentItem
2023-06-12 10:53:35 +08:00
var pos = button . mapToItem ( target , 0 , 0 )
2023-06-10 22:46:17 +08:00
var mouseX = pos . x
var mouseY = pos . y
2023-06-30 12:08:57 +08:00
var radius = Math . max ( distance ( mouseX , mouseY , 0 , 0 ) , distance ( mouseX , mouseY , target . width , 0 ) , distance ( mouseX , mouseY , 0 , target . height ) , distance ( mouseX , mouseY , target . width , target . height ) )
2023-07-25 21:24:45 +08:00
var reveal = loader_reveal . item
2023-06-30 12:08:57 +08:00
reveal . start ( reveal . width * Screen . devicePixelRatio , reveal . height * Screen . devicePixelRatio , Qt . point ( mouseX , mouseY ) , radius )
}
}
function changeDark ( ) {
if ( FluTheme . dark ) {
2023-07-18 18:24:06 +08:00
FluTheme . darkMode = FluThemeType . Light
2023-06-30 12:08:57 +08:00
} else {
2023-07-18 18:24:06 +08:00
FluTheme . darkMode = FluThemeType . Dark
2023-06-10 22:46:17 +08:00
}
2023-06-10 11:01:36 +08:00
}
2023-06-12 17:04:35 +08:00
Shortcut {
sequence: "F5"
context: Qt . WindowShortcut
onActivated: {
if ( flipable . flipped ) {
loader . reload ( )
}
}
}
2023-08-07 22:11:08 +08:00
Shortcut {
sequence: "F6"
context: Qt . WindowShortcut
onActivated: {
tour . open ( )
}
}
2023-08-07 21:46:54 +08:00
FluTour {
2024-03-09 15:35:48 +08:00
id: tour
finishText: qsTr ( "Finish" )
nextText: qsTr ( "Next" )
previousText: qsTr ( "Previous" )
2023-11-21 14:28:37 +08:00
steps: {
var data = [ ]
2023-12-13 17:31:08 +08:00
if ( ! window . useSystemAppBar ) {
2024-03-09 15:35:48 +08:00
data . push ( { title: qsTr ( "Dark Mode" ) , description: qsTr ( "Here you can switch to night mode." ) , target: ( ) = > appBar . buttonDark } )
2023-11-21 14:28:37 +08:00
}
2024-03-09 15:35:48 +08:00
data . push ( { title: qsTr ( "Hide Easter eggs" ) , description: qsTr ( "Try a few more clicks!!" ) , target: ( ) = > nav_view . imageLogo } )
2023-11-21 14:28:37 +08:00
return data
}
2023-08-07 21:46:54 +08:00
}
2023-08-28 17:14:21 +08:00
FpsItem {
id:fps_item
}
FluText {
2024-03-09 15:35:48 +08:00
text: "fps %1" . arg ( fps_item . fps )
2023-08-28 17:14:21 +08:00
opacity: 0.3
anchors {
bottom: parent . bottom
right: parent . right
bottomMargin: 5
rightMargin: 5
}
}
2023-08-27 09:11:44 +08:00
FluContentDialog {
property string newVerson
property string body
2024-03-09 15:35:48 +08:00
id: dialog_update
title: qsTr ( "Upgrade Tips" )
message: qsTr ( "FluentUI is currently up to date " ) + newVerson + qsTr ( " -- The current app version" ) + AppInfo . version + qsTr ( " \nNow go and download the new version? \n\nUpdated content: \n" ) + body
2023-08-27 09:11:44 +08:00
buttonFlags: FluContentDialogType . NegativeButton | FluContentDialogType . PositiveButton
2024-03-09 15:35:48 +08:00
negativeText: qsTr ( "Cancel" )
positiveText: qsTr ( "OK" )
2023-08-27 09:11:44 +08:00
onPositiveClicked: {
Qt . openUrlExternally ( "https://github.com/zhuzichu520/FluentUI/releases/latest" )
}
}
2024-03-27 09:45:56 +08:00
NetworkCallable {
2023-09-04 18:37:55 +08:00
id:callable
2023-09-11 18:10:50 +08:00
property bool silent: true
2023-09-04 18:37:55 +08:00
onStart: {
2024-03-31 21:52:06 +08:00
console . debug ( "start check update..." )
2023-08-27 09:11:44 +08:00
}
2023-09-04 18:37:55 +08:00
onFinish: {
2023-08-27 09:11:44 +08:00
console . debug ( "check update finish" )
2023-09-11 18:10:50 +08:00
FluEventBus . post ( "checkUpdateFinish" ) ;
2023-08-27 09:11:44 +08:00
}
2023-09-04 18:37:55 +08:00
onSuccess:
( result ) = > {
var data = JSON . parse ( result )
2023-09-17 20:36:33 +08:00
console . debug ( "current version " + AppInfo . version )
2023-09-04 18:37:55 +08:00
console . debug ( "new version " + data . tag_name )
2023-09-17 20:36:33 +08:00
if ( data . tag_name !== AppInfo . version ) {
2023-09-04 18:37:55 +08:00
dialog_update . newVerson = data . tag_name
dialog_update . body = data . body
dialog_update . open ( )
2023-09-11 18:10:50 +08:00
} else {
if ( ! silent ) {
2024-03-09 15:35:48 +08:00
showInfo ( qsTr ( "The current version is already the latest" ) )
2023-09-11 18:10:50 +08:00
}
2023-09-04 18:37:55 +08:00
}
2023-08-27 09:11:44 +08:00
}
2023-09-04 18:37:55 +08:00
onError:
( status , errorString ) = > {
2023-09-11 18:10:50 +08:00
if ( ! silent ) {
2024-03-09 15:35:48 +08:00
showError ( qsTr ( "The network is abnormal" ) )
2023-09-11 18:10:50 +08:00
}
2023-09-04 18:37:55 +08:00
console . debug ( status + ";" + errorString )
}
}
2023-09-11 18:10:50 +08:00
function checkUpdate ( silent ) {
callable . silent = silent
2024-03-27 09:45:56 +08:00
Network . get ( "https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest" )
2023-11-30 01:12:57 +08:00
. go ( callable )
2023-08-27 09:11:44 +08:00
}
2023-02-26 23:47:07 +08:00
}