UserLine.qml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright (C) 2019 by Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. import QtQuick 2.15
  15. import QtQuick.Window 2.15
  16. import QtQuick.Controls 2.15
  17. import QtQuick.Layouts 1.15
  18. // Custom qml modules are in /theme (and included by resources.qrc)
  19. import Style 1.0
  20. import com.nextcloud.desktopclient 1.0
  21. AbstractButton {
  22. id: userLine
  23. signal showUserStatusSelector(int id)
  24. property variant dialog;
  25. property variant comp;
  26. Accessible.role: Accessible.MenuItem
  27. Accessible.name: qsTr("Switch to account") + " " + model.name
  28. height: Style.trayWindowHeaderHeight
  29. background: Rectangle {
  30. anchors.fill: parent
  31. anchors.margins: 1
  32. color: (userLine.hovered || userLine.visualFocus) && !(userMoreButton.hovered || userMoreButton.visualFocus) ? Style.lightHover : Style.backgroundColor
  33. }
  34. contentItem: RowLayout {
  35. id: userLineLayout
  36. spacing: Style.userStatusSpacing
  37. Image {
  38. id: accountAvatar
  39. Layout.leftMargin: 7
  40. verticalAlignment: Qt.AlignCenter
  41. cache: false
  42. source: model.avatar !== "" ? model.avatar : Theme.darkMode ? "image://avatars/fallbackWhite" : "image://avatars/fallbackBlack"
  43. Layout.preferredHeight: Style.accountAvatarSize
  44. Layout.preferredWidth: Style.accountAvatarSize
  45. Rectangle {
  46. id: accountStatusIndicatorBackground
  47. visible: model.isConnected && model.serverHasUserStatus
  48. width: accountStatusIndicator.sourceSize.width + 2
  49. height: width
  50. anchors.bottom: accountAvatar.bottom
  51. anchors.right: accountAvatar.right
  52. color: userLine.hovered || userLine.visualFocus ? "#f6f6f6" : "white"
  53. radius: width*0.5
  54. }
  55. Image {
  56. id: accountStatusIndicator
  57. visible: model.isConnected && model.serverHasUserStatus
  58. source: model.statusIcon
  59. cache: false
  60. x: accountStatusIndicatorBackground.x + 1
  61. y: accountStatusIndicatorBackground.y + 1
  62. sourceSize.width: Style.accountAvatarStateIndicatorSize
  63. sourceSize.height: Style.accountAvatarStateIndicatorSize
  64. Accessible.role: Accessible.Indicator
  65. Accessible.name: model.desktopNotificationsAllowed ? qsTr("Current account status is online") : qsTr("Current account status is do not disturb")
  66. }
  67. }
  68. ColumnLayout {
  69. id: accountLabels
  70. Layout.leftMargin: Style.accountLabelsSpacing
  71. Layout.fillWidth: true
  72. Layout.fillHeight: true
  73. EnforcedPlainTextLabel {
  74. id: accountUser
  75. Layout.fillWidth: true
  76. Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
  77. verticalAlignment: Text.AlignBottom
  78. text: name
  79. elide: Text.ElideRight
  80. color: Style.ncTextColor
  81. font.pixelSize: Style.topLinePixelSize
  82. font.bold: true
  83. }
  84. RowLayout {
  85. id: statusLayout
  86. Layout.fillWidth: true
  87. height: visible ? implicitHeight : 0
  88. visible: model.isConnected &&
  89. model.serverHasUserStatus &&
  90. (model.statusEmoji !== "" || model.statusMessage !== "")
  91. EnforcedPlainTextLabel {
  92. id: emoji
  93. visible: model.statusEmoji !== ""
  94. text: statusEmoji
  95. topPadding: -Style.accountLabelsSpacing
  96. }
  97. EnforcedPlainTextLabel {
  98. id: message
  99. Layout.fillWidth: true
  100. visible: model.statusMessage !== ""
  101. text: statusMessage
  102. elide: Text.ElideRight
  103. color: Style.ncTextColor
  104. font.pixelSize: Style.subLinePixelSize
  105. leftPadding: Style.accountLabelsSpacing
  106. }
  107. }
  108. EnforcedPlainTextLabel {
  109. id: accountServer
  110. Layout.fillWidth: true
  111. Layout.alignment: Qt.AlignLeft | Qt.AlignTop
  112. verticalAlignment: Text.AlignTop
  113. text: server
  114. elide: Text.ElideRight
  115. color: Style.ncTextColor
  116. font.pixelSize: Style.subLinePixelSize
  117. }
  118. }
  119. Button {
  120. id: userMoreButton
  121. Layout.preferredWidth: Style.headerButtonIconSize
  122. Layout.fillHeight: true
  123. flat: true
  124. icon.source: "qrc:///client/theme/more.svg"
  125. icon.color: Style.ncTextColor
  126. Accessible.role: Accessible.ButtonMenu
  127. Accessible.name: qsTr("Account actions")
  128. Accessible.onPressAction: userMoreButtonMouseArea.clicked()
  129. onClicked: userMoreButtonMenu.visible ? userMoreButtonMenu.close() : userMoreButtonMenu.popup()
  130. background: Rectangle {
  131. anchors.fill: parent
  132. anchors.margins: 1
  133. color: userMoreButton.hovered || userMoreButton.visualFocus ? Style.lightHover : "transparent"
  134. }
  135. AutoSizingMenu {
  136. id: userMoreButtonMenu
  137. closePolicy: Menu.CloseOnPressOutsideParent | Menu.CloseOnEscape
  138. background: Rectangle {
  139. border.color: Style.menuBorder
  140. color: Style.backgroundColor
  141. radius: 2
  142. }
  143. MenuItem {
  144. visible: model.isConnected && model.serverHasUserStatus
  145. height: visible ? implicitHeight : 0
  146. text: qsTr("Set status")
  147. font.pixelSize: Style.topLinePixelSize
  148. palette.windowText: Style.ncTextColor
  149. hoverEnabled: true
  150. onClicked: showUserStatusSelector(index)
  151. background: Item {
  152. height: parent.height
  153. width: parent.menu.width
  154. Rectangle {
  155. anchors.fill: parent
  156. anchors.margins: 1
  157. color: parent.parent.hovered ? Style.lightHover : "transparent"
  158. }
  159. }
  160. }
  161. MenuItem {
  162. text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
  163. font.pixelSize: Style.topLinePixelSize
  164. palette.windowText: Style.ncTextColor
  165. hoverEnabled: true
  166. onClicked: {
  167. model.isConnected ? UserModel.logout(index) : UserModel.login(index)
  168. accountMenu.close()
  169. }
  170. background: Item {
  171. height: parent.height
  172. width: parent.menu.width
  173. Rectangle {
  174. anchors.fill: parent
  175. anchors.margins: 1
  176. color: parent.parent.hovered ? Style.lightHover : "transparent"
  177. }
  178. }
  179. Accessible.role: Accessible.Button
  180. Accessible.name: model.isConnected ? qsTr("Log out") : qsTr("Log in")
  181. onPressed: {
  182. if (model.isConnected) {
  183. UserModel.logout(index)
  184. } else {
  185. UserModel.login(index)
  186. }
  187. accountMenu.close()
  188. }
  189. }
  190. MenuItem {
  191. id: removeAccountButton
  192. text: qsTr("Remove account")
  193. font.pixelSize: Style.topLinePixelSize
  194. palette.windowText: Style.ncTextColor
  195. hoverEnabled: true
  196. onClicked: {
  197. UserModel.removeAccount(index)
  198. accountMenu.close()
  199. }
  200. background: Item {
  201. height: parent.height
  202. width: parent.menu.width
  203. Rectangle {
  204. anchors.fill: parent
  205. anchors.margins: 1
  206. color: parent.parent.hovered ? Style.lightHover : "transparent"
  207. }
  208. }
  209. Accessible.role: Accessible.Button
  210. Accessible.name: text
  211. Accessible.onPressAction: removeAccountButton.clicked()
  212. }
  213. }
  214. }
  215. }
  216. } // MenuItem userLine