backport QML code changes from awesome-widgets to deskop-panel

This commit is contained in:
Evgenii Alekseev 2016-04-22 15:39:36 +03:00
parent 82dda14260
commit 22586811de
5 changed files with 59 additions and 42 deletions

View File

@ -84,7 +84,7 @@ Item {
// ui
Text {
id: text
anchors.fill: Layout
anchors.fill: Plasmoid.Layout
renderType: Text.NativeRendering
textFormat: Text.RichText
wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap

View File

@ -71,7 +71,9 @@ Item {
title: i18n("Select a color")
onAccepted: {
var text = textPattern.text
textPattern.text = "<body bgcolor=\"" + backgroundDialog.color + "\">" + text + "</body>"
textPattern.text = "<body bgcolor=\"" +
backgroundDialog.color + "\">" +
text + "</body>"
}
}
}
@ -292,10 +294,9 @@ Item {
onClicked: {
if (!tags.currentText) return
if (debug) console.debug("Add tag button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "$" + tags.currentText)
textPattern.insert(textPattern.cursorPosition, selected + "$" + tags.currentText)
}
}
QtControls.Button {

View File

@ -57,7 +57,7 @@ Item {
// ui
GridLayout {
anchors.fill: parent
anchors.fill: Plasmoid.Layout
columns: plasmoid.configuration.verticalLayout ? 1 : dpAdds.numberOfDesktops()
rows: plasmoid.configuration.verticalLayout ? dpAdds.numberOfDesktops() : 1

View File

@ -17,6 +17,7 @@
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Dialogs 1.2 as QtDialogs
import org.kde.plasma.private.desktoppanel 1.0
@ -54,7 +55,24 @@ Item {
height: implicitHeight
width: parent.width
QtControls.Button {
width: parent.width * 3 / 12
width: parent.width * 3 / 15
text: i18n("Bgcolor")
onClicked: backgroundDialog.visible = true
QtDialogs.ColorDialog {
id: backgroundDialog
title: i18n("Select a color")
onAccepted: {
var text = textPattern.text
textPattern.text = "<body bgcolor=\"" +
backgroundDialog.color + "\">" +
text + "</body>"
}
}
}
QtControls.Button {
width: parent.width * 3 / 15
text: i18n("Font")
iconName: "font"
@ -66,123 +84,119 @@ Item {
"size": plasmoid.configuration.fontSize
}
var font = dpAdds.getFont(defaultFont)
var pos = textPattern.cursorPosition
if (font.applied != 1) {
if (debug) console.debug("No font selected")
return
}
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<span style=\"color:" + font.color +
textPattern.insert(textPattern.cursorPosition,
"<span style=\"color:" + font.color +
"; font-family:'" + font.family +
"'; font-size:" + font.size + "pt;\">" +
selected + "</span>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-indent-more"
onClicked: {
if (debug) console.debug("Indent button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "<br>\n")
textPattern.insert(textPattern.cursorPosition, selected + "<br>\n")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-bold"
onClicked: {
if (debug) console.debug("Bold button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<b>" + selected + "</b>")
textPattern.insert(textPattern.cursorPosition, "<b>" + selected + "</b>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-italic"
onClicked: {
if (debug) console.debug("Italic button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<i>" + selected + "</i>")
textPattern.insert(textPattern.cursorPosition, "<i>" + selected + "</i>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-underline"
onClicked: {
if (debug) console.debug("Underline button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<u>" + selected + "</u>")
textPattern.insert(textPattern.cursorPosition, "<u>" + selected + "</u>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-strikethrough"
onClicked: {
if (debug) console.debug("Strike button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<s>" + selected + "</s>")
textPattern.insert(textPattern.cursorPosition, "<s>" + selected + "</s>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-left"
onClicked: {
if (debug) console.debug("Left button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"left\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"left\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-center"
onClicked: {
if (debug) console.debug("Center button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"center\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"center\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-right"
onClicked: {
if (debug) console.debug("Right button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"right\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"right\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-fill"
onClicked: {
if (debug) console.debug("Justify button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"justify\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"justify\">" + selected + "</p>")
}
}
}
@ -201,10 +215,9 @@ Item {
onClicked: {
if (debug) console.debug("Add tag button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "$" + tags.currentText)
textPattern.insert(textPattern.cursorPosition, selected + "$" + tags.currentText)
}
}
QtControls.Button {

View File

@ -318,11 +318,14 @@ QVariantMap DPAdds::getFont(const QVariantMap defaultFont) const
qCDebug(LOG_DP) << "Default font is" << defaultFont;
QVariantMap fontMap;
int ret = 0;
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
defaultFont[QString("size")].toInt(), 400, false,
defaultFont[QString("color")].toString());
CFont font
= CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false);
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false,
false, &ret);
fontMap[QString("applied")] = ret;
fontMap[QString("color")] = font.color().name();
fontMap[QString("family")] = font.family();
fontMap[QString("size")] = font.pointSize();