You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
335 lines
10 KiB
QML
335 lines
10 KiB
QML
7 years ago
|
/*
|
||
|
* Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com>
|
||
|
*
|
||
|
* This file is part of Latte-Dock
|
||
|
*
|
||
|
* Latte-Dock is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License as
|
||
|
* published by the Free Software Foundation; either version 2 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* Latte-Dock is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
import QtQuick 2.7
|
||
|
|
||
|
import QtQuick.Layouts 1.0
|
||
|
|
||
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
||
|
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||
|
|
||
5 years ago
|
import org.kde.latte.core 0.2 as LatteCore
|
||
7 years ago
|
|
||
7 years ago
|
Item{
|
||
7 years ago
|
id: rulerItem
|
||
|
|
||
6 years ago
|
width: root.isHorizontal ? userMaxLength : thickness
|
||
|
height: root.isVertical ? userMaxLength : thickness
|
||
7 years ago
|
|
||
5 years ago
|
property int rulerAnimationTime: root.animationSpeed
|
||
6 years ago
|
property int thicknessMargin: 0
|
||
7 years ago
|
|
||
7 years ago
|
readonly property bool containsMouse: rulerMouseArea.containsMouse
|
||
6 years ago
|
readonly property int thickness: theme.defaultFont.pixelSize
|
||
7 years ago
|
|
||
7 years ago
|
readonly property string tooltip: i18nc("maximum length tooltip, %0% is maximum length percentage","You can use mouse wheel to change maximum length of %0%").arg(plasmoid.configuration.maxLength)
|
||
7 years ago
|
|
||
6 years ago
|
readonly property int userMaxLength: {
|
||
|
if (root.isHorizontal) {
|
||
|
return root.width * (plasmoid.configuration.maxLength/100);
|
||
|
} else {
|
||
|
return root.height * (plasmoid.configuration.maxLength/100);
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
x: {
|
||
|
if (root.isHorizontal) {
|
||
|
return xL;
|
||
|
} else {
|
||
|
if (plasmoid.location === PlasmaCore.Types.LeftEdge){
|
||
6 years ago
|
return settingsRoot.width - thickness - thicknessMargin;
|
||
7 years ago
|
} else if (plasmoid.location === PlasmaCore.Types.RightEdge){
|
||
6 years ago
|
return thicknessMargin;
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
y: {
|
||
|
if (root.isVertical) {
|
||
|
return yL;
|
||
|
} else {
|
||
|
if (plasmoid.location === PlasmaCore.Types.BottomEdge){
|
||
6 years ago
|
return thicknessMargin;
|
||
7 years ago
|
} else if (plasmoid.location === PlasmaCore.Types.TopEdge){
|
||
6 years ago
|
return settingsRoot.height - thickness - thicknessMargin;
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
6 years ago
|
property int length: userMaxLength
|
||
7 years ago
|
|
||
6 years ago
|
property int thickMargin: 3
|
||
7 years ago
|
property int xL: 0
|
||
|
property int yL: 0
|
||
|
|
||
|
Binding{
|
||
|
target: ruler
|
||
|
property: "xL"
|
||
|
value: {
|
||
|
if (root.isHorizontal) {
|
||
5 years ago
|
if (plasmoid.configuration.alignment === LatteCore.Types.Justify) {
|
||
7 years ago
|
return root.width/2 - rulerItem.length/2 + root.offset;
|
||
5 years ago
|
} else if (root.panelAlignment === LatteCore.Types.Left) {
|
||
7 years ago
|
return root.offset;
|
||
5 years ago
|
} else if (root.panelAlignment === LatteCore.Types.Center) {
|
||
7 years ago
|
return root.width/2 - rulerItem.length/2 + root.offset;
|
||
5 years ago
|
} else if (root.panelAlignment === LatteCore.Types.Right) {
|
||
7 years ago
|
return root.width - rulerItem.length - root.offset;
|
||
|
}
|
||
|
} else {
|
||
|
return ;
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Binding{
|
||
|
target: ruler
|
||
|
property: "yL"
|
||
|
value: {
|
||
|
if (root.isVertical) {
|
||
5 years ago
|
if (plasmoid.configuration.alignment === LatteCore.Types.Justify) {
|
||
7 years ago
|
return root.height/2 - rulerItem.length/2 + root.offset;
|
||
5 years ago
|
} else if (root.panelAlignment === LatteCore.Types.Top) {
|
||
7 years ago
|
return root.offset;
|
||
5 years ago
|
} else if (root.panelAlignment === LatteCore.Types.Center) {
|
||
7 years ago
|
return root.height/2 - rulerItem.length/2 + root.offset;
|
||
5 years ago
|
} else if (root.panelAlignment === LatteCore.Types.Bottom) {
|
||
7 years ago
|
return root.height - rulerItem.length - root.offset;
|
||
|
}
|
||
|
} else {
|
||
|
return;
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Behavior on width {
|
||
|
NumberAnimation {
|
||
7 years ago
|
id: horizontalAnimation
|
||
|
duration: rulerAnimationTime
|
||
7 years ago
|
easing.type: Easing.OutCubic
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Behavior on height {
|
||
|
NumberAnimation {
|
||
7 years ago
|
id: verticalAnimation
|
||
|
duration: rulerAnimationTime
|
||
7 years ago
|
easing.type: Easing.OutCubic
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Behavior on x {
|
||
7 years ago
|
enabled: root.isHorizontal && !offsetAnimation.running
|
||
7 years ago
|
NumberAnimation {
|
||
7 years ago
|
duration: rulerAnimationTime
|
||
7 years ago
|
easing.type: Easing.OutCubic
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Behavior on y {
|
||
7 years ago
|
enabled: root.isVertical && !offsetAnimation.running
|
||
7 years ago
|
NumberAnimation {
|
||
7 years ago
|
duration: rulerAnimationTime
|
||
7 years ago
|
easing.type: Easing.OutCubic
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Grid{
|
||
|
id: rulerGrid
|
||
7 years ago
|
width: root.isHorizontal ? parent.length : undefined
|
||
|
height: root.isVertical ? parent.length : undefined
|
||
7 years ago
|
|
||
|
rows: root.isHorizontal ? 1 : 0
|
||
|
columns: root.isVertical ? 1 : 0
|
||
7 years ago
|
spacing: 2
|
||
7 years ago
|
|
||
|
flow: root.isHorizontal ? GridLayout.TopToBottom : GridLayout.LeftToRight
|
||
7 years ago
|
|
||
7 years ago
|
x: {
|
||
|
if (plasmoid.location === PlasmaCore.Types.LeftEdge) {
|
||
6 years ago
|
return -thickMargin;
|
||
7 years ago
|
} else if (plasmoid.location === PlasmaCore.Types.RightEdge) {
|
||
6 years ago
|
return thickMargin;
|
||
7 years ago
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
y: {
|
||
|
if (plasmoid.location === PlasmaCore.Types.BottomEdge) {
|
||
6 years ago
|
return thickMargin;
|
||
7 years ago
|
} else if (plasmoid.location === PlasmaCore.Types.TopEdge) {
|
||
6 years ago
|
return -thickMargin;
|
||
7 years ago
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Behavior on width {
|
||
|
NumberAnimation {
|
||
|
duration: rulerAnimationTime
|
||
|
easing.type: Easing.OutCubic
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Behavior on height {
|
||
|
NumberAnimation {
|
||
|
duration: rulerAnimationTime
|
||
|
easing.type: Easing.OutCubic
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
property int freeSpace: {
|
||
|
if (root.isHorizontal) {
|
||
7 years ago
|
return rulerItem.width - rulerGrid.spacing - 1 //((rulerGrid.children.length-2) * rulerGrid.spacing)
|
||
|
- (startLine.width + startArrow.width + labelItem.width + endArrow.width + endArrow.width);
|
||
7 years ago
|
} else {
|
||
7 years ago
|
return rulerItem.height - rulerGrid.spacing - 1 //((rulerGrid.children.length-2) * rulerGrid.spacing)
|
||
|
- (startLine.height + startArrow.height + labelItem.height + endArrow.height + endArrow.height);
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Rectangle{
|
||
7 years ago
|
id: startLine
|
||
7 years ago
|
width: root.isHorizontal ? 2 : theme.defaultFont.pixelSize
|
||
|
height: root.isVertical ? 2 : theme.defaultFont.pixelSize
|
||
7 years ago
|
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
}
|
||
|
|
||
|
Item{
|
||
7 years ago
|
id: startArrow
|
||
7 years ago
|
width: root.isHorizontal ? 0.6 * theme.defaultFont.pixelSize : theme.defaultFont.pixelSize
|
||
|
height: root.isVertical ? 0.6 * theme.defaultFont.pixelSize : theme.defaultFont.pixelSize
|
||
|
|
||
7 years ago
|
clip:true
|
||
|
|
||
|
Rectangle{
|
||
7 years ago
|
anchors.verticalCenter: root.isHorizontal ? parent.verticalCenter : parent.bottom
|
||
|
anchors.horizontalCenter: root.isHorizontal ? parent.right : parent.horizontalCenter
|
||
7 years ago
|
width: 0.75*theme.defaultFont.pixelSize
|
||
|
height: width
|
||
|
rotation: 45
|
||
|
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Item{
|
||
7 years ago
|
id: startSpacer
|
||
|
width: root.isHorizontal ? rulerGrid.freeSpace / 2 : theme.defaultFont.pixelSize
|
||
|
height: root.isVertical ? rulerGrid.freeSpace / 2 : theme.defaultFont.pixelSize
|
||
7 years ago
|
|
||
|
Rectangle{
|
||
|
height: root.isHorizontal ? 2 : parent.height
|
||
|
width: root.isVertical ? 2 : parent.width
|
||
|
|
||
|
anchors.centerIn: parent
|
||
|
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
Item {
|
||
7 years ago
|
id: labelItem
|
||
7 years ago
|
width: root.isHorizontal ? labelMetricsRec.width : labelMetricsRec.height / 2
|
||
|
height: root.isVertical ? labelMetricsRec.width : labelMetricsRec.height / 2
|
||
|
|
||
|
PlasmaComponents.Label{
|
||
|
id: maxLengthLbl
|
||
|
|
||
|
anchors.centerIn: parent
|
||
|
|
||
|
text: i18n("Maximum Length")
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
|
||
|
transformOrigin: Item.Center
|
||
|
|
||
|
rotation: {
|
||
|
if (root.isHorizontal) {
|
||
|
return 0;
|
||
|
} else if (plasmoid.location === PlasmaCore.Types.LeftEdge){
|
||
|
return 90;
|
||
|
} else if (plasmoid.location === PlasmaCore.Types.RightEdge){
|
||
|
return -90;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Rectangle {
|
||
|
id: labelMetricsRec
|
||
|
anchors.fill: parent
|
||
|
visible: false
|
||
|
}
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
Item{
|
||
7 years ago
|
id: endSpacer
|
||
|
width: startSpacer.width
|
||
|
height: startSpacer.height
|
||
7 years ago
|
|
||
|
Rectangle{
|
||
|
height: root.isHorizontal ? 2 : parent.height
|
||
|
width: root.isVertical ? 2 : parent.width
|
||
|
|
||
|
anchors.centerIn: parent
|
||
|
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
Item{
|
||
7 years ago
|
id: endArrow
|
||
7 years ago
|
width: root.isHorizontal ? 0.6 * theme.defaultFont.pixelSize : theme.defaultFont.pixelSize
|
||
|
height: root.isVertical ? 0.6 * theme.defaultFont.pixelSize : theme.defaultFont.pixelSize
|
||
7 years ago
|
clip:true
|
||
|
|
||
|
Rectangle{
|
||
7 years ago
|
anchors.verticalCenter: root.isHorizontal ? parent.verticalCenter : parent.top
|
||
|
anchors.horizontalCenter: root.isHorizontal ? parent.left : parent.horizontalCenter
|
||
7 years ago
|
width: 0.75*theme.defaultFont.pixelSize
|
||
|
height: width
|
||
|
rotation: 45
|
||
|
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
Rectangle{
|
||
7 years ago
|
id: endLine
|
||
7 years ago
|
width: root.isHorizontal ? 2 : theme.defaultFont.pixelSize
|
||
|
height: root.isVertical ? 2 : theme.defaultFont.pixelSize
|
||
7 years ago
|
|
||
6 years ago
|
color: settingsRoot.textColor
|
||
7 years ago
|
}
|
||
7 years ago
|
} // end of grid
|
||
6 years ago
|
|
||
|
RulerMouseArea {
|
||
|
id: rulerMouseArea
|
||
|
anchors.fill: parent
|
||
|
}
|
||
6 years ago
|
|
||
|
PlasmaComponents.Button {
|
||
|
anchors.fill: parent
|
||
|
opacity: 0
|
||
|
tooltip: rulerItem.tooltip
|
||
|
}
|
||
7 years ago
|
}
|