forked from Shinonome/dots-hyprland
region selector: remove auto fullscreen ocr, make close btn fab
ocr-ing the whole screen slow and messy. it's better to just go with the regular flow of selecting a region
This commit is contained in:
@@ -12,9 +12,9 @@ RippleButton {
|
|||||||
property bool expanded: false
|
property bool expanded: false
|
||||||
property real baseSize: 56
|
property real baseSize: 56
|
||||||
property real elementSpacing: 5
|
property real elementSpacing: 5
|
||||||
implicitWidth: Math.max(contentRowLayout.implicitWidth + 10 * 2, baseSize)
|
implicitWidth: expanded ? (Math.max(contentRowLayout.implicitWidth + 10 * 2, baseSize)) : baseSize
|
||||||
implicitHeight: baseSize
|
implicitHeight: baseSize
|
||||||
buttonRadius: Appearance.rounding.small
|
buttonRadius: baseSize / 14 * 4
|
||||||
colBackground: Appearance.colors.colPrimaryContainer
|
colBackground: Appearance.colors.colPrimaryContainer
|
||||||
colBackgroundHover: Appearance.colors.colPrimaryContainerHover
|
colBackgroundHover: Appearance.colors.colPrimaryContainerHover
|
||||||
colRipple: Appearance.colors.colPrimaryContainerActive
|
colRipple: Appearance.colors.colPrimaryContainerActive
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ RippleButton {
|
|||||||
property string mainText: "Button text"
|
property string mainText: "Button text"
|
||||||
property Component mainContentComponent: Component {
|
property Component mainContentComponent: Component {
|
||||||
StyledText {
|
StyledText {
|
||||||
|
visible: text !== ""
|
||||||
text: buttonWithIconRoot.mainText
|
text: buttonWithIconRoot.mainText
|
||||||
font.pixelSize: Appearance.font.pixelSize.small
|
font.pixelSize: Appearance.font.pixelSize.small
|
||||||
color: Appearance.colors.colOnSecondaryContainer
|
color: Appearance.colors.colOnSecondaryContainer
|
||||||
|
|||||||
@@ -64,9 +64,4 @@ Toolbar {
|
|||||||
onClicked: root.selectionMode = RegionSelection.SelectionMode.Circle
|
onClicked: root.selectionMode = RegionSelection.SelectionMode.Circle
|
||||||
}
|
}
|
||||||
|
|
||||||
IconToolbarButton {
|
|
||||||
text: "close"
|
|
||||||
colBackground: Appearance.colors.colLayer3
|
|
||||||
onClicked: root.dismiss();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ PanelWindow {
|
|||||||
});
|
});
|
||||||
return offsetAdjustedLayers;
|
return offsetAdjustedLayers;
|
||||||
}
|
}
|
||||||
property list<var> textRegions: []
|
|
||||||
|
|
||||||
property bool isCircleSelection: (root.selectionMode === RegionSelection.SelectionMode.Circle)
|
property bool isCircleSelection: (root.selectionMode === RegionSelection.SelectionMode.Circle)
|
||||||
property bool enableWindowRegions: Config.options.regionSelector.targetRegions.windows && !isCircleSelection
|
property bool enableWindowRegions: Config.options.regionSelector.targetRegions.windows && !isCircleSelection
|
||||||
@@ -182,7 +181,6 @@ PanelWindow {
|
|||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
root.visible = true;
|
root.visible = true;
|
||||||
if (root.enableContentRegions) imageDetectionProcess.running = true;
|
if (root.enableContentRegions) imageDetectionProcess.running = true;
|
||||||
// if (root.action === RegionSelection.SnipAction.CharRecognition) ocrProc.running = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,41 +202,6 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
|
||||||
id: ocrProc
|
|
||||||
command: ["bash", "-c", `tesseract '${StringUtils.shellSingleQuoteEscape(root.screenshotPath)}' stdout tsv 2>/dev/null`]
|
|
||||||
stdout: StdioCollector {
|
|
||||||
id: outputCollector
|
|
||||||
onStreamFinished: {
|
|
||||||
// level page_num block_num par_num line_num word_num left top width height conf text
|
|
||||||
const output = outputCollector.text
|
|
||||||
const lines = output.split("\n").slice(1) // Skip header
|
|
||||||
const filteredLines = lines.filter(line => (!line.trim().endsWith("-1")))
|
|
||||||
let regions = filteredLines.map(line => {
|
|
||||||
const parts = line.split("\t")
|
|
||||||
return ({
|
|
||||||
"block_num": parseInt(parts[2]),
|
|
||||||
"line_num": parseInt(parts[4]),
|
|
||||||
"word_num": parseInt(parts[5]),
|
|
||||||
"left": parseInt(parts[6]),
|
|
||||||
"top": parseInt(parts[7]),
|
|
||||||
"width": parseInt(parts[8]),
|
|
||||||
"height": parseInt(parts[9]),
|
|
||||||
"conf": parseInt(parts[10]),
|
|
||||||
"text": parts.slice(11).join("\t")
|
|
||||||
})
|
|
||||||
}).filter(region => {
|
|
||||||
if (region === null) return false;
|
|
||||||
// if (region.text.length <= 3 && region.text.replace(/[^a-zA-Z0-9]/g, "").length < region.text.length / 2) return false;
|
|
||||||
// if (region.text.length < 2) return false;
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
// print(`[Region Selector] OCR Regions: ${JSON.stringify(regions, null, 2)}`)
|
|
||||||
root.textRegions = regions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function snip() {
|
function snip() {
|
||||||
// Validity check
|
// Validity check
|
||||||
if (root.regionWidth <= 0 || root.regionHeight <= 0) {
|
if (root.regionWidth <= 0 || root.regionHeight <= 0) {
|
||||||
@@ -450,35 +413,9 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OCR text regions
|
// Controls
|
||||||
// Repeater {
|
Row {
|
||||||
// model: ScriptModel {
|
id: regionSelectionControls
|
||||||
// values: root.textRegions
|
|
||||||
// }
|
|
||||||
// delegate: Rectangle {
|
|
||||||
// id: textRegionItem
|
|
||||||
// z: 5
|
|
||||||
// required property var modelData
|
|
||||||
// property real padding: 4
|
|
||||||
// color: ColorUtils.transparentize(Appearance.colors.colTooltip, 0.3)
|
|
||||||
// radius: 6
|
|
||||||
// x: modelData.left - padding
|
|
||||||
// y: modelData.top - padding
|
|
||||||
// width: modelData.width + padding
|
|
||||||
// height: modelData.height + padding
|
|
||||||
|
|
||||||
// StyledText {
|
|
||||||
// font.pixelSize: Appearance.font.pixelSize.smallie
|
|
||||||
// anchors.centerIn: parent
|
|
||||||
// text: textRegionItem.modelData.text
|
|
||||||
// color: ColorUtils.transparentize(Appearance.colors.colOnTooltip, 0.2)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Options toolbar
|
|
||||||
OptionsToolbar {
|
|
||||||
id: toolbar
|
|
||||||
z: 9999
|
z: 9999
|
||||||
anchors {
|
anchors {
|
||||||
horizontalCenter: parent.horizontalCenter
|
horizontalCenter: parent.horizontalCenter
|
||||||
@@ -490,8 +427,8 @@ PanelWindow {
|
|||||||
target: root
|
target: root
|
||||||
function onVisibleChanged() {
|
function onVisibleChanged() {
|
||||||
if (!visible) return;
|
if (!visible) return;
|
||||||
toolbar.anchors.bottomMargin = 8;
|
regionSelectionControls.anchors.bottomMargin = 8;
|
||||||
toolbar.opacity = 1;
|
regionSelectionControls.opacity = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Behavior on opacity {
|
Behavior on opacity {
|
||||||
@@ -500,16 +437,42 @@ PanelWindow {
|
|||||||
Behavior on anchors.bottomMargin {
|
Behavior on anchors.bottomMargin {
|
||||||
animation: Appearance.animation.elementMove.numberAnimation.createObject(this)
|
animation: Appearance.animation.elementMove.numberAnimation.createObject(this)
|
||||||
}
|
}
|
||||||
|
spacing: 6
|
||||||
|
|
||||||
Synchronizer on action {
|
OptionsToolbar {
|
||||||
property alias source: root.action
|
Synchronizer on action {
|
||||||
|
property alias source: root.action
|
||||||
|
}
|
||||||
|
Synchronizer on selectionMode {
|
||||||
|
property alias source: root.selectionMode
|
||||||
|
}
|
||||||
|
onDismiss: root.dismiss();
|
||||||
}
|
}
|
||||||
Synchronizer on selectionMode {
|
Item {
|
||||||
property alias source: root.selectionMode
|
anchors {
|
||||||
|
verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
implicitWidth: closeFab.implicitWidth
|
||||||
|
implicitHeight: closeFab.implicitHeight
|
||||||
|
StyledRectangularShadow {
|
||||||
|
target: closeFab
|
||||||
|
radius: closeFab.buttonRadius
|
||||||
|
}
|
||||||
|
FloatingActionButton {
|
||||||
|
id: closeFab
|
||||||
|
baseSize: 48
|
||||||
|
iconText: "close"
|
||||||
|
onClicked: root.dismiss();
|
||||||
|
StyledToolTip {
|
||||||
|
text: Translation.tr("Close")
|
||||||
|
}
|
||||||
|
colBackground: Appearance.colors.colTertiaryContainer
|
||||||
|
colBackgroundHover: Appearance.colors.colTertiaryContainerHover
|
||||||
|
colRipple: Appearance.colors.colTertiaryContainerActive
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDismiss: root.dismiss();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user