Skip to content

Commit

Permalink
Fixed text selection
Browse files Browse the repository at this point in the history
+ Minor cleanups
+ Added "show background" option
  • Loading branch information
koldbyte committed Apr 26, 2020
1 parent e4723f8 commit ab333ea
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 94 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.plasmoid
*.qmlc
*.jsc
*.mo
/dist
*/.kdev4/*
68 changes: 0 additions & 68 deletions .kdev4/termoid.kdev4

This file was deleted.

5 changes: 4 additions & 1 deletion package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<default>640</default>
<min>10</min>
</entry>

<entry name="showBackground" type="Bool">
<label>Show Background</label>
<default>true</default>
</entry>
</group>
</kcfg>
19 changes: 17 additions & 2 deletions package/contents/ui/config/ConfigGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import QtQuick.Dialogs 1.2
import org.kde.plasma.components 2.0 as PlasmaComponents

import ".."
// import "../../code/utils.js" as Utils

ConfigPage {
id: page
Expand All @@ -16,6 +15,7 @@ ConfigPage {
property alias cfg_colorschemeInt: colorscheme.currentIndex
property string cfg_colorschemetextString: cbItems.get(colorscheme.currentIndex).text
property alias cfg_opacityInt: opacity_spin.value
property alias cfg_showBackgroundBool: show_background_switch.checked
width: 500
height: 250

Expand All @@ -25,6 +25,7 @@ ConfigPage {
cfg_colorschemeInt = plasmoid.configuration.colorscheme;
colorscheme.currentIndex = cfg_colorschemeInt;
cfg_opacityInt = plasmoid.configuration.opacity;
cfg_showBackgroundBool = plasmoid.configuration.showBackground

console.log("ConfigPage loaded");
}
Expand Down Expand Up @@ -54,6 +55,11 @@ ConfigPage {
plasmoid.configuration.opacity = opacity_spin.value;
console.log("Opacity Widget Updated " + opacity_spin.value);
}

onCfg_showBackgroundBoolChanged: {
plasmoid.configuration.showBackground = show_background_switch.checked;
console.log("Show Background Updated " + show_background_switch.checked);
}

GroupBox {
Layout.fillWidth: true
Expand Down Expand Up @@ -126,6 +132,15 @@ ConfigPage {
maximumValue: 100
stepSize: 1
}

PlasmaComponents.Label {
text: i18n("Show Background")
}

CheckBox {
id: show_background_switch
checked: plasmoid.configuration.showBackground
}
}
}
}
Expand All @@ -143,7 +158,7 @@ ConfigPage {
Layout.fillWidth: true
}

PlasmaComponents.TextField {
TextField {
id: command
placeholderText: cfg_commandString
Layout.fillWidth: true
Expand Down
95 changes: 86 additions & 9 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import QtQuick.Controls 1.2

import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponentss
import org.kde.plasma.components 2.0 as PlasmaComponents

import QMLTermWidget 1.0

Expand All @@ -38,9 +38,10 @@ Item{

Layout.minimumWidth: units.gridUnit * 10
Layout.minimumHeight: units.gridUnit * 10

Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation

Plasmoid.backgroundHints: plasmoid.configuration.showBackground ? PlasmaCore.Types.DefaultBackground : PlasmaCore.Types.NoBackground

PlasmaCore.DataSource {
id: executeSource
engine: "executable"
Expand Down Expand Up @@ -68,30 +69,73 @@ Item{
QMLTermWidget {
id: terminal
anchors.fill: parent

font.family: plasmoid.configuration.fontfamily === "" ? "Monospace" : plasmoid.configuration.fontfamily || theme.defaultFont.family
font.pointSize: plasmoid.configuration.fontsize === "" ? "12" : plasmoid.configuration.fontsize
colorScheme: plasmoid.configuration.colorschemetext === null ? "Linux" : plasmoid.configuration.colorschemetext
antialiasText:true

colorScheme: plasmoid.configuration.colorschemetext === null ? "Linux" : plasmoid.configuration.colorschemetext
opacity: plasmoid.configuration.opacity / 100
fullCursorHeight: true

session: QMLTermSession{
id: mainsession
initialWorkingDirectory: "$HOME"
//shellProgram: plasmoid.configuration.command === "" ? "$SHELL" : Utils.prog(plasmoid.configuration.command)
//shellProgramArgs: Utils.arg(plasmoid.configuration.command) || []
}

Component.onCompleted: {
mainsession.setShellProgram(plasmoid.configuration.command === "" ? "$SHELL" : Utils.prog(plasmoid.configuration.command));
mainsession.setArgs(Utils.arg(plasmoid.configuration.command) || []);

console.log("Running with session shellProgram: " + JSON.stringify(mainsession))
mainsession.startShellProgram();
forceActiveFocus();
}


// Switch focus properly to terminal to allow text selection
onFocusChanged:
{
mouse_area.enabled = !terminal.focus
}

// Enable keyboard input on mouse click over the plasmoid window
MouseArea {
id: mouse_area
anchors.fill: parent

onClicked: {
forceActiveFocus(Qt.MouseFocusReason);
propagateComposedEvents: false
cursorShape: terminal.terminalUsesMouse ? Qt.ArrowCursor : Qt.IBeamCursor
acceptedButtons: Qt.RightButton | Qt.LeftButton

// Pass on the events to terminal object to enable text selection
onDoubleClicked:
{
var coord = correctDistortion(mouse.x, mouse.y);
terminal.simulateMouseDoubleClick(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers);
}

onPressed:
{
var coord = correctDistortion(mouse.x, mouse.y);
terminal.simulateMousePress(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers)
}

onReleased:
{
var coord = correctDistortion(mouse.x, mouse.y);
terminal.simulateMouseRelease(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers);
}

onPositionChanged:
{
var coord = correctDistortion(mouse.x, mouse.y);
terminal.simulateMouseMove(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers);
}

onClicked:
{
if(mouse.button === Qt.LeftButton)
terminal.forceActiveFocus()
}
}

Expand All @@ -105,5 +149,38 @@ Item{
anchors.fill: parent
}
}

// Manage copy and paste
Connections{
target: copyAction
onTriggered: terminal.copyClipboard();
}
Connections{
target: pasteAction
onTriggered: terminal.pasteClipboard()
}
}

Action{
id: copyAction
text: qsTr("Copy")
shortcut: "Ctrl+Shift+C"
}
Action{
id: pasteAction
text: qsTr("Paste")
shortcut: "Ctrl+Shift+V"
}

function correctDistortion(x, y)
{
x = x / width;
y = y / height;

var cc = Qt.size(0.5 - x, 0.5 - y);
var distortion = 0;

return Qt.point((x - cc.width * (1+distortion) * distortion) * terminal.width,
(y - cc.height * (1+distortion) * distortion) * terminal.height)
}
}
12 changes: 6 additions & 6 deletions package/metadata.desktop
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[Desktop Entry]
Encoding=UTF-8
Name=Termoid
Comment=Terminal in a plasmoid

Type=Service
Icon=utilities-terminal
X-KDE-ServiceTypes=Plasma/Applet

X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml

X-KDE-PluginInfo-Author=Bhaskar Divya
X-KDE-PluginInfo-Email=
X-KDE-PluginInfo-Name=com.koldbyte.kde.termoid
X-KDE-PluginInfo-Version=0.3
X-KDE-PluginInfo-Version=0.4
X-KDE-PluginInfo-Website=https://github.com/koldbyte/termoid
X-KDE-PluginInfo-Category=Utilities
X-KDE-PluginInfo-Depends=qtermwidget
X-KDE-PluginInfo-License=GPL v2+
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml
X-KDE-PluginInfo-KdeStoreId=1169451
Binary file removed termoid-v0.3.plasmoid
Binary file not shown.
4 changes: 0 additions & 4 deletions termoid.kdev4

This file was deleted.

4 changes: 0 additions & 4 deletions upgrade

This file was deleted.

0 comments on commit ab333ea

Please sign in to comment.