| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2012 Martin Gräßlin <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
*/ |
| 6 |
import QtQuick |
| 7 |
import org.kde.kwin.decoration |
| 8 |
import org.kde.kwin.decorations.plastik |
| 9 |
|
| 10 |
Decoration { |
| 11 |
function readBorderSize() { |
| 12 |
switch (borderSize) { |
| 13 |
case DecorationOptions.BorderTiny: |
| 14 |
borders.setBorders(3); |
| 15 |
extendedBorders.setAllBorders(0); |
| 16 |
break; |
| 17 |
case DecorationOptions.BorderLarge: |
| 18 |
borders.setBorders(8); |
| 19 |
extendedBorders.setAllBorders(0); |
| 20 |
break; |
| 21 |
case DecorationOptions.BorderVeryLarge: |
| 22 |
borders.setBorders(12); |
| 23 |
extendedBorders.setAllBorders(0); |
| 24 |
break; |
| 25 |
case DecorationOptions.BorderHuge: |
| 26 |
borders.setBorders(18); |
| 27 |
extendedBorders.setAllBorders(0); |
| 28 |
break; |
| 29 |
case DecorationOptions.BorderVeryHuge: |
| 30 |
borders.setBorders(27); |
| 31 |
extendedBorders.setAllBorders(0); |
| 32 |
break; |
| 33 |
case DecorationOptions.BorderOversized: |
| 34 |
borders.setBorders(40); |
| 35 |
extendedBorders.setAllBorders(0); |
| 36 |
break; |
| 37 |
case DecorationOptions.BorderNoSides: |
| 38 |
borders.setBorders(4); |
| 39 |
borders.setSideBorders(1); |
| 40 |
extendedBorders.setSideBorders(3); |
| 41 |
break; |
| 42 |
case DecorationOptions.BorderNone: |
| 43 |
borders.setBorders(1); |
| 44 |
extendedBorders.setBorders(3); |
| 45 |
break; |
| 46 |
case DecorationOptions.BorderNormal: // fall through to default |
| 47 |
default: |
| 48 |
borders.setBorders(4); |
| 49 |
extendedBorders.setAllBorders(0); |
| 50 |
break; |
| 51 |
} |
| 52 |
} |
| 53 |
function readConfig() { |
| 54 |
var titleAlignLeft = decoration.readConfig("titleAlignLeft", true); |
| 55 |
var titleAlignCenter = decoration.readConfig("titleAlignCenter", false); |
| 56 |
var titleAlignRight = decoration.readConfig("titleAlignRight", false); |
| 57 |
if (titleAlignRight) { |
| 58 |
root.titleAlignment = Text.AlignRight; |
| 59 |
} else if (titleAlignCenter) { |
| 60 |
root.titleAlignment = Text.AlignHCenter; |
| 61 |
} else { |
| 62 |
if (!titleAlignLeft) { |
| 63 |
console.log("Error reading title alignment: all alignment options are false"); |
| 64 |
} |
| 65 |
root.titleAlignment = Text.AlignLeft; |
| 66 |
} |
| 67 |
root.animateButtons = decoration.readConfig("animateButtons", true); |
| 68 |
if (decoration.animationsSupported) { |
| 69 |
root.animationDuration = 150; |
| 70 |
root.animateButtons = false; |
| 71 |
} |
| 72 |
} |
| 73 |
ColorHelper { |
| 74 |
id: colorHelper |
| 75 |
} |
| 76 |
DecorationOptions { |
| 77 |
id: options |
| 78 |
deco: decoration |
| 79 |
} |
| 80 |
property int borderSize: decorationSettings.borderSize |
| 81 |
property alias buttonSize: titleRow.captionHeight |
| 82 |
property alias titleAlignment: caption.horizontalAlignment |
| 83 |
property color titleBarColor: options.titleBarColor |
| 84 |
// set by readConfig after Component completed, ensures that buttons do not flicker |
| 85 |
property int animationDuration: 0 |
| 86 |
property bool animateButtons: true |
| 87 |
Behavior on titleBarColor { |
| 88 |
ColorAnimation { |
| 89 |
duration: root.animationDuration |
| 90 |
} |
| 91 |
} |
| 92 |
id: root |
| 93 |
alpha: false |
| 94 |
Rectangle { |
| 95 |
color: root.titleBarColor |
| 96 |
anchors { |
| 97 |
fill: parent |
| 98 |
} |
| 99 |
border { |
| 100 |
width: decoration.client.maximized ? 0 : 2 |
| 101 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.DarkShade) |
| 102 |
} |
| 103 |
Rectangle { |
| 104 |
id: borderLeft |
| 105 |
anchors { |
| 106 |
left: parent.left |
| 107 |
top: parent.top |
| 108 |
bottom: parent.bottom |
| 109 |
leftMargin: 1 |
| 110 |
bottomMargin: 1 |
| 111 |
topMargin: 1 |
| 112 |
} |
| 113 |
visible: !decoration.client.maximized |
| 114 |
width: root.borders.left |
| 115 |
color: root.titleBarColor |
| 116 |
Rectangle { |
| 117 |
width: 1 |
| 118 |
anchors { |
| 119 |
left: parent.left |
| 120 |
top: parent.top |
| 121 |
bottom: parent.bottom |
| 122 |
} |
| 123 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.LightShade, colorHelper.contrast - (decoration.client.active ? 0.4 : 0.8)) |
| 124 |
} |
| 125 |
} |
| 126 |
Rectangle { |
| 127 |
id: borderRight |
| 128 |
anchors { |
| 129 |
right: parent.right |
| 130 |
top: parent.top |
| 131 |
bottom: parent.bottom |
| 132 |
rightMargin: 1 |
| 133 |
bottomMargin: 1 |
| 134 |
topMargin: 1 |
| 135 |
} |
| 136 |
visible: !decoration.client.maximized |
| 137 |
width: root.borders.right -1 |
| 138 |
color: root.titleBarColor |
| 139 |
Rectangle { |
| 140 |
width: 1 |
| 141 |
anchors { |
| 142 |
bottom: parent.bottom |
| 143 |
top: parent.top |
| 144 |
right: parent.right |
| 145 |
} |
| 146 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.DarkShade, colorHelper.contrast - (decoration.client.active ? 0.4 : 0.8)) |
| 147 |
} |
| 148 |
} |
| 149 |
Rectangle { |
| 150 |
id: borderBottom |
| 151 |
anchors { |
| 152 |
left: parent.right |
| 153 |
right: parent.left |
| 154 |
bottom: parent.bottom |
| 155 |
leftMargin: 1 |
| 156 |
rightMargin: 1 |
| 157 |
} |
| 158 |
height: root.borders.bottom |
| 159 |
visible: !decoration.client.maximized |
| 160 |
color: root.titleBarColor |
| 161 |
Rectangle { |
| 162 |
height: 1 |
| 163 |
anchors { |
| 164 |
left: parent.left |
| 165 |
right: parent.right |
| 166 |
bottom: parent.bottom |
| 167 |
} |
| 168 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.DarkShade, colorHelper.contrast - (decoration.client.active ? 0.4 : 0.8)) |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
Rectangle { |
| 173 |
id: top |
| 174 |
property int topMargin: 1 |
| 175 |
property real normalHeight: titleRow.normalHeight + topMargin + 1 |
| 176 |
property real maximizedHeight: titleRow.maximizedHeight + 1 |
| 177 |
height: decoration.client.maximized ? maximizedHeight : normalHeight |
| 178 |
anchors { |
| 179 |
left: parent.left |
| 180 |
right: parent.right |
| 181 |
top: parent.top |
| 182 |
topMargin: decoration.client.maximized ? 0 : top.topMargin |
| 183 |
leftMargin: decoration.client.maximized ? 0 : 2 |
| 184 |
rightMargin: decoration.client.maximized ? 0 : 2 |
| 185 |
} |
| 186 |
gradient: Gradient { |
| 187 |
id: topGradient |
| 188 |
GradientStop { |
| 189 |
position: 0.0 |
| 190 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidlightShade, colorHelper.contrast - 0.4) |
| 191 |
} |
| 192 |
GradientStop { |
| 193 |
id: middleGradientStop |
| 194 |
position: 4.0/(decoration.client.maximized ? top.maximizedHeight : top.normalHeight) |
| 195 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidShade, colorHelper.contrast - 0.4) |
| 196 |
} |
| 197 |
GradientStop { |
| 198 |
position: 1.0 |
| 199 |
color: root.titleBarColor |
| 200 |
} |
| 201 |
} |
| 202 |
Rectangle { |
| 203 |
height: 1 |
| 204 |
anchors { |
| 205 |
top: top.top |
| 206 |
left: top.left |
| 207 |
right: top.right |
| 208 |
} |
| 209 |
visible: !decoration.client.maximized |
| 210 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.LightShade, colorHelper.contrast - (decoration.client.active ? 0.4 : 0.8)) |
| 211 |
} |
| 212 |
|
| 213 |
Item { |
| 214 |
id: titleRow |
| 215 |
property real captionHeight: caption.implicitHeight + 4 |
| 216 |
property int topMargin: 3 |
| 217 |
property int bottomMargin: 1 |
| 218 |
property real normalHeight: captionHeight + bottomMargin + topMargin |
| 219 |
property real maximizedHeight: captionHeight + bottomMargin |
| 220 |
anchors { |
| 221 |
left: parent.left |
| 222 |
right: parent.right |
| 223 |
top: parent.top |
| 224 |
topMargin: decoration.client.maximized ? 0 : titleRow.topMargin |
| 225 |
leftMargin: decoration.client.maximized ? 0 : 3 |
| 226 |
rightMargin: decoration.client.maximized ? 0 : 3 |
| 227 |
bottomMargin: titleRow.bottomMargin |
| 228 |
} |
| 229 |
ButtonGroup { |
| 230 |
id: leftButtonGroup |
| 231 |
spacing: 1 |
| 232 |
explicitSpacer: root.buttonSize |
| 233 |
menuButton: menuButtonComponent |
| 234 |
appMenuButton: appMenuButtonComponent |
| 235 |
minimizeButton: minimizeButtonComponent |
| 236 |
maximizeButton: maximizeButtonComponent |
| 237 |
keepBelowButton: keepBelowButtonComponent |
| 238 |
keepAboveButton: keepAboveButtonComponent |
| 239 |
helpButton: helpButtonComponent |
| 240 |
shadeButton: shadeButtonComponent |
| 241 |
allDesktopsButton: stickyButtonComponent |
| 242 |
closeButton: closeButtonComponent |
| 243 |
buttons: options.titleButtonsLeft |
| 244 |
anchors { |
| 245 |
top: parent.top |
| 246 |
left: parent.left |
| 247 |
} |
| 248 |
} |
| 249 |
Text { |
| 250 |
id: caption |
| 251 |
textFormat: Text.PlainText |
| 252 |
anchors { |
| 253 |
top: parent.top |
| 254 |
left: leftButtonGroup.right |
| 255 |
right: rightButtonGroup.left |
| 256 |
rightMargin: 5 |
| 257 |
leftMargin: 5 |
| 258 |
topMargin: 3 |
| 259 |
} |
| 260 |
color: options.fontColor |
| 261 |
Behavior on color { |
| 262 |
ColorAnimation { duration: root.animationDuration } |
| 263 |
} |
| 264 |
text: decoration.client.caption |
| 265 |
font: options.titleFont |
| 266 |
elide: Text.ElideMiddle |
| 267 |
renderType: Text.NativeRendering |
| 268 |
} |
| 269 |
ButtonGroup { |
| 270 |
id: rightButtonGroup |
| 271 |
spacing: 1 |
| 272 |
explicitSpacer: root.buttonSize |
| 273 |
menuButton: menuButtonComponent |
| 274 |
appMenuButton: appMenuButtonComponent |
| 275 |
minimizeButton: minimizeButtonComponent |
| 276 |
maximizeButton: maximizeButtonComponent |
| 277 |
keepBelowButton: keepBelowButtonComponent |
| 278 |
keepAboveButton: keepAboveButtonComponent |
| 279 |
helpButton: helpButtonComponent |
| 280 |
shadeButton: shadeButtonComponent |
| 281 |
allDesktopsButton: stickyButtonComponent |
| 282 |
closeButton: closeButtonComponent |
| 283 |
buttons: options.titleButtonsRight |
| 284 |
anchors { |
| 285 |
top: parent.top |
| 286 |
right: parent.right |
| 287 |
} |
| 288 |
} |
| 289 |
Component.onCompleted: { |
| 290 |
decoration.installTitleItem(titleRow); |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
Item { |
| 296 |
id: innerBorder |
| 297 |
anchors.fill: parent |
| 298 |
|
| 299 |
Rectangle { |
| 300 |
anchors { |
| 301 |
left: parent.left |
| 302 |
right: parent.right |
| 303 |
} |
| 304 |
height: 1 |
| 305 |
y: top.height - 1 |
| 306 |
visible: decoration.client.maximized |
| 307 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidShade) |
| 308 |
} |
| 309 |
|
| 310 |
Rectangle { |
| 311 |
anchors { |
| 312 |
fill: parent |
| 313 |
leftMargin: root.borders.left - 1 |
| 314 |
rightMargin: root.borders.right |
| 315 |
topMargin: root.borders.top - 1 |
| 316 |
bottomMargin: root.borders.bottom |
| 317 |
} |
| 318 |
border { |
| 319 |
width: 1 |
| 320 |
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidShade) |
| 321 |
} |
| 322 |
visible: !decoration.client.maximized |
| 323 |
color: root.titleBarColor |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
Component { |
| 329 |
id: maximizeButtonComponent |
| 330 |
PlastikButton { |
| 331 |
objectName: "maximizeButton" |
| 332 |
buttonType: DecorationOptions.DecorationButtonMaximizeRestore |
| 333 |
size: root.buttonSize |
| 334 |
} |
| 335 |
} |
| 336 |
Component { |
| 337 |
id: keepBelowButtonComponent |
| 338 |
PlastikButton { |
| 339 |
buttonType: DecorationOptions.DecorationButtonKeepBelow |
| 340 |
size: root.buttonSize |
| 341 |
} |
| 342 |
} |
| 343 |
Component { |
| 344 |
id: keepAboveButtonComponent |
| 345 |
PlastikButton { |
| 346 |
buttonType: DecorationOptions.DecorationButtonKeepAbove |
| 347 |
size: root.buttonSize |
| 348 |
} |
| 349 |
} |
| 350 |
Component { |
| 351 |
id: helpButtonComponent |
| 352 |
PlastikButton { |
| 353 |
buttonType: DecorationOptions.DecorationButtonQuickHelp |
| 354 |
size: root.buttonSize |
| 355 |
} |
| 356 |
} |
| 357 |
Component { |
| 358 |
id: minimizeButtonComponent |
| 359 |
PlastikButton { |
| 360 |
buttonType: DecorationOptions.DecorationButtonMinimize |
| 361 |
size: root.buttonSize |
| 362 |
} |
| 363 |
} |
| 364 |
Component { |
| 365 |
id: shadeButtonComponent |
| 366 |
PlastikButton { |
| 367 |
buttonType: DecorationOptions.DecorationButtonShade |
| 368 |
size: root.buttonSize |
| 369 |
} |
| 370 |
} |
| 371 |
Component { |
| 372 |
id: stickyButtonComponent |
| 373 |
PlastikButton { |
| 374 |
buttonType: DecorationOptions.DecorationButtonOnAllDesktops |
| 375 |
size: root.buttonSize |
| 376 |
} |
| 377 |
} |
| 378 |
Component { |
| 379 |
id: closeButtonComponent |
| 380 |
PlastikButton { |
| 381 |
buttonType: DecorationOptions.DecorationButtonClose |
| 382 |
size: root.buttonSize |
| 383 |
} |
| 384 |
} |
| 385 |
Component { |
| 386 |
id: menuButtonComponent |
| 387 |
MenuButton { |
| 388 |
width: root.buttonSize |
| 389 |
height: root.buttonSize |
| 390 |
} |
| 391 |
} |
| 392 |
Component { |
| 393 |
id: appMenuButtonComponent |
| 394 |
PlastikButton { |
| 395 |
buttonType: DecorationOptions.DecorationButtonApplicationMenu |
| 396 |
size: root.buttonSize |
| 397 |
} |
| 398 |
} |
| 399 |
Component.onCompleted: { |
| 400 |
borders.setBorders(4); |
| 401 |
borders.setTitle(top.normalHeight); |
| 402 |
maximizedBorders.setTitle(top.maximizedHeight); |
| 403 |
readBorderSize(); |
| 404 |
readConfig(); |
| 405 |
} |
| 406 |
Connections { |
| 407 |
target: decoration |
| 408 |
function onConfigChanged() { |
| 409 |
root.readConfig() |
| 410 |
} |
| 411 |
} |
| 412 |
Connections { |
| 413 |
target: decorationSettings |
| 414 |
function onBorderSizeChanged() { |
| 415 |
root.readBorderSize(); |
| 416 |
} |
| 417 |
} |
| 418 |
} |