mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 13:32:50 -05:00
better fuzzy search, sweeping clean and qmlfmt of Widgets
This commit is contained in:
@@ -1,678 +0,0 @@
|
||||
.pragma library
|
||||
|
||||
var single = (search, target) => {
|
||||
if(!search || !target) return NULL
|
||||
|
||||
var preparedSearch = getPreparedSearch(search)
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
|
||||
var searchBitflags = preparedSearch.bitflags
|
||||
if((searchBitflags & target._bitflags) !== searchBitflags) return NULL
|
||||
|
||||
return algorithm(preparedSearch, target)
|
||||
}
|
||||
|
||||
var go = (search, targets, options) => {
|
||||
if(!search) return options?.all ? all(targets, options) : noResults
|
||||
|
||||
var preparedSearch = getPreparedSearch(search)
|
||||
var searchBitflags = preparedSearch.bitflags
|
||||
var containsSpace = preparedSearch.containsSpace
|
||||
|
||||
var threshold = denormalizeScore( options?.threshold || 0 )
|
||||
var limit = options?.limit || INFINITY
|
||||
|
||||
var resultsLen = 0; var limitedCount = 0
|
||||
var targetsLen = targets.length
|
||||
|
||||
function push_result(result) {
|
||||
if(resultsLen < limit) { q.add(result); ++resultsLen }
|
||||
else {
|
||||
++limitedCount
|
||||
if(result._score > q.peek()._score) q.replaceTop(result)
|
||||
}
|
||||
}
|
||||
|
||||
// This code is copy/pasted 3 times for performance reasons [options.key, options.keys, no keys]
|
||||
|
||||
// options.key
|
||||
if(options?.key) {
|
||||
var key = options.key
|
||||
for(var i = 0; i < targetsLen; ++i) { var obj = targets[i]
|
||||
var target = getValue(obj, key)
|
||||
if(!target) continue
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
|
||||
if((searchBitflags & target._bitflags) !== searchBitflags) continue
|
||||
var result = algorithm(preparedSearch, target)
|
||||
if(result === NULL) continue
|
||||
if(result._score < threshold) continue
|
||||
|
||||
result.obj = obj
|
||||
push_result(result)
|
||||
}
|
||||
|
||||
// options.keys
|
||||
} else if(options?.keys) {
|
||||
var keys = options.keys
|
||||
var keysLen = keys.length
|
||||
|
||||
outer: for(var i = 0; i < targetsLen; ++i) { var obj = targets[i]
|
||||
|
||||
{ // early out based on bitflags
|
||||
var keysBitflags = 0
|
||||
for (var keyI = 0; keyI < keysLen; ++keyI) {
|
||||
var key = keys[keyI]
|
||||
var target = getValue(obj, key)
|
||||
if(!target) { tmpTargets[keyI] = noTarget; continue }
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
tmpTargets[keyI] = target
|
||||
|
||||
keysBitflags |= target._bitflags
|
||||
}
|
||||
|
||||
if((searchBitflags & keysBitflags) !== searchBitflags) continue
|
||||
}
|
||||
|
||||
if(containsSpace) for(let i=0; i<preparedSearch.spaceSearches.length; i++) keysSpacesBestScores[i] = NEGATIVE_INFINITY
|
||||
|
||||
for (var keyI = 0; keyI < keysLen; ++keyI) {
|
||||
target = tmpTargets[keyI]
|
||||
if(target === noTarget) { tmpResults[keyI] = noTarget; continue }
|
||||
|
||||
tmpResults[keyI] = algorithm(preparedSearch, target, /*allowSpaces=*/false, /*allowPartialMatch=*/containsSpace)
|
||||
if(tmpResults[keyI] === NULL) { tmpResults[keyI] = noTarget; continue }
|
||||
|
||||
// todo: this seems weird and wrong. like what if our first match wasn't good. this should just replace it instead of averaging with it
|
||||
// if our second match isn't good we ignore it instead of averaging with it
|
||||
if(containsSpace) for(let i=0; i<preparedSearch.spaceSearches.length; i++) {
|
||||
if(allowPartialMatchScores[i] > -1000) {
|
||||
if(keysSpacesBestScores[i] > NEGATIVE_INFINITY) {
|
||||
var tmp = (keysSpacesBestScores[i] + allowPartialMatchScores[i]) / 4/*bonus score for having multiple matches*/
|
||||
if(tmp > keysSpacesBestScores[i]) keysSpacesBestScores[i] = tmp
|
||||
}
|
||||
}
|
||||
if(allowPartialMatchScores[i] > keysSpacesBestScores[i]) keysSpacesBestScores[i] = allowPartialMatchScores[i]
|
||||
}
|
||||
}
|
||||
|
||||
if(containsSpace) {
|
||||
for(let i=0; i<preparedSearch.spaceSearches.length; i++) { if(keysSpacesBestScores[i] === NEGATIVE_INFINITY) continue outer }
|
||||
} else {
|
||||
var hasAtLeast1Match = false
|
||||
for(let i=0; i < keysLen; i++) { if(tmpResults[i]._score !== NEGATIVE_INFINITY) { hasAtLeast1Match = true; break } }
|
||||
if(!hasAtLeast1Match) continue
|
||||
}
|
||||
|
||||
var objResults = new KeysResult(keysLen)
|
||||
for(let i=0; i < keysLen; i++) { objResults[i] = tmpResults[i] }
|
||||
|
||||
if(containsSpace) {
|
||||
var score = 0
|
||||
for(let i=0; i<preparedSearch.spaceSearches.length; i++) score += keysSpacesBestScores[i]
|
||||
} else {
|
||||
// todo could rewrite this scoring to be more similar to when there's spaces
|
||||
// if we match multiple keys give us bonus points
|
||||
var score = NEGATIVE_INFINITY
|
||||
for(let i=0; i<keysLen; i++) {
|
||||
var result = objResults[i]
|
||||
if(result._score > -1000) {
|
||||
if(score > NEGATIVE_INFINITY) {
|
||||
var tmp = (score + result._score) / 4/*bonus score for having multiple matches*/
|
||||
if(tmp > score) score = tmp
|
||||
}
|
||||
}
|
||||
if(result._score > score) score = result._score
|
||||
}
|
||||
}
|
||||
|
||||
objResults.obj = obj
|
||||
objResults._score = score
|
||||
if(options?.scoreFn) {
|
||||
score = options.scoreFn(objResults)
|
||||
if(!score) continue
|
||||
score = denormalizeScore(score)
|
||||
objResults._score = score
|
||||
}
|
||||
|
||||
if(score < threshold) continue
|
||||
push_result(objResults)
|
||||
}
|
||||
|
||||
// no keys
|
||||
} else {
|
||||
for(var i = 0; i < targetsLen; ++i) { var target = targets[i]
|
||||
if(!target) continue
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
|
||||
if((searchBitflags & target._bitflags) !== searchBitflags) continue
|
||||
var result = algorithm(preparedSearch, target)
|
||||
if(result === NULL) continue
|
||||
if(result._score < threshold) continue
|
||||
|
||||
push_result(result)
|
||||
}
|
||||
}
|
||||
|
||||
if(resultsLen === 0) return noResults
|
||||
var results = new Array(resultsLen)
|
||||
for(var i = resultsLen - 1; i >= 0; --i) results[i] = q.poll()
|
||||
results.total = resultsLen + limitedCount
|
||||
return results
|
||||
}
|
||||
|
||||
|
||||
// this is written as 1 function instead of 2 for minification. perf seems fine ...
|
||||
// except when minified. the perf is very slow
|
||||
var highlight = (result, open='<b>', close='</b>') => {
|
||||
var callback = typeof open === 'function' ? open : undefined
|
||||
|
||||
var target = result.target
|
||||
var targetLen = target.length
|
||||
var indexes = result.indexes
|
||||
var highlighted = ''
|
||||
var matchI = 0
|
||||
var indexesI = 0
|
||||
var opened = false
|
||||
var parts = []
|
||||
|
||||
for(var i = 0; i < targetLen; ++i) { var char = target[i]
|
||||
if(indexes[indexesI] === i) {
|
||||
++indexesI
|
||||
if(!opened) { opened = true
|
||||
if(callback) {
|
||||
parts.push(highlighted); highlighted = ''
|
||||
} else {
|
||||
highlighted += open
|
||||
}
|
||||
}
|
||||
|
||||
if(indexesI === indexes.length) {
|
||||
if(callback) {
|
||||
highlighted += char
|
||||
parts.push(callback(highlighted, matchI++)); highlighted = ''
|
||||
parts.push(target.substr(i+1))
|
||||
} else {
|
||||
highlighted += char + close + target.substr(i+1)
|
||||
}
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if(opened) { opened = false
|
||||
if(callback) {
|
||||
parts.push(callback(highlighted, matchI++)); highlighted = ''
|
||||
} else {
|
||||
highlighted += close
|
||||
}
|
||||
}
|
||||
}
|
||||
highlighted += char
|
||||
}
|
||||
|
||||
return callback ? parts : highlighted
|
||||
}
|
||||
|
||||
|
||||
var prepare = (target) => {
|
||||
if(typeof target === 'number') target = ''+target
|
||||
else if(typeof target !== 'string') target = ''
|
||||
var info = prepareLowerInfo(target)
|
||||
return new_result(target, {_targetLower:info._lower, _targetLowerCodes:info.lowerCodes, _bitflags:info.bitflags})
|
||||
}
|
||||
|
||||
var cleanup = () => { preparedCache.clear(); preparedSearchCache.clear() }
|
||||
|
||||
|
||||
// Below this point is only internal code
|
||||
// Below this point is only internal code
|
||||
// Below this point is only internal code
|
||||
// Below this point is only internal code
|
||||
|
||||
|
||||
class Result {
|
||||
get ['indexes']() { return this._indexes.slice(0, this._indexes.len).sort((a,b)=>a-b) }
|
||||
set ['indexes'](indexes) { return this._indexes = indexes }
|
||||
['highlight'](open, close) { return highlight(this, open, close) }
|
||||
get ['score']() { return normalizeScore(this._score) }
|
||||
set ['score'](score) { this._score = denormalizeScore(score) }
|
||||
}
|
||||
|
||||
class KeysResult extends Array {
|
||||
get ['score']() { return normalizeScore(this._score) }
|
||||
set ['score'](score) { this._score = denormalizeScore(score) }
|
||||
}
|
||||
|
||||
var new_result = (target, options) => {
|
||||
const result = new Result()
|
||||
result['target'] = target
|
||||
result['obj'] = options.obj ?? NULL
|
||||
result._score = options._score ?? NEGATIVE_INFINITY
|
||||
result._indexes = options._indexes ?? []
|
||||
result._targetLower = options._targetLower ?? ''
|
||||
result._targetLowerCodes = options._targetLowerCodes ?? NULL
|
||||
result._nextBeginningIndexes = options._nextBeginningIndexes ?? NULL
|
||||
result._bitflags = options._bitflags ?? 0
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
var normalizeScore = score => {
|
||||
if(score === NEGATIVE_INFINITY) return 0
|
||||
if(score > 1) return score
|
||||
return Math.E ** ( ((-score + 1)**.04307 - 1) * -2)
|
||||
}
|
||||
var denormalizeScore = normalizedScore => {
|
||||
if(normalizedScore === 0) return NEGATIVE_INFINITY
|
||||
if(normalizedScore > 1) return normalizedScore
|
||||
return 1 - Math.pow((Math.log(normalizedScore) / -2 + 1), 1 / 0.04307)
|
||||
}
|
||||
|
||||
|
||||
var prepareSearch = (search) => {
|
||||
if(typeof search === 'number') search = ''+search
|
||||
else if(typeof search !== 'string') search = ''
|
||||
search = search.trim()
|
||||
var info = prepareLowerInfo(search)
|
||||
|
||||
var spaceSearches = []
|
||||
if(info.containsSpace) {
|
||||
var searches = search.split(/\s+/)
|
||||
searches = [...new Set(searches)] // distinct
|
||||
for(var i=0; i<searches.length; i++) {
|
||||
if(searches[i] === '') continue
|
||||
var _info = prepareLowerInfo(searches[i])
|
||||
spaceSearches.push({lowerCodes:_info.lowerCodes, _lower:searches[i].toLowerCase(), containsSpace:false})
|
||||
}
|
||||
}
|
||||
|
||||
return {lowerCodes: info.lowerCodes, _lower: info._lower, containsSpace: info.containsSpace, bitflags: info.bitflags, spaceSearches: spaceSearches}
|
||||
}
|
||||
|
||||
|
||||
|
||||
var getPrepared = (target) => {
|
||||
if(target.length > 999) return prepare(target) // don't cache huge targets
|
||||
var targetPrepared = preparedCache.get(target)
|
||||
if(targetPrepared !== undefined) return targetPrepared
|
||||
targetPrepared = prepare(target)
|
||||
preparedCache.set(target, targetPrepared)
|
||||
return targetPrepared
|
||||
}
|
||||
var getPreparedSearch = (search) => {
|
||||
if(search.length > 999) return prepareSearch(search) // don't cache huge searches
|
||||
var searchPrepared = preparedSearchCache.get(search)
|
||||
if(searchPrepared !== undefined) return searchPrepared
|
||||
searchPrepared = prepareSearch(search)
|
||||
preparedSearchCache.set(search, searchPrepared)
|
||||
return searchPrepared
|
||||
}
|
||||
|
||||
|
||||
var all = (targets, options) => {
|
||||
var results = []; results.total = targets.length // this total can be wrong if some targets are skipped
|
||||
|
||||
var limit = options?.limit || INFINITY
|
||||
|
||||
if(options?.key) {
|
||||
for(var i=0;i<targets.length;i++) { var obj = targets[i]
|
||||
var target = getValue(obj, options.key)
|
||||
if(target == NULL) continue
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
var result = new_result(target.target, {_score: target._score, obj: obj})
|
||||
results.push(result); if(results.length >= limit) return results
|
||||
}
|
||||
} else if(options?.keys) {
|
||||
for(var i=0;i<targets.length;i++) { var obj = targets[i]
|
||||
var objResults = new KeysResult(options.keys.length)
|
||||
for (var keyI = options.keys.length - 1; keyI >= 0; --keyI) {
|
||||
var target = getValue(obj, options.keys[keyI])
|
||||
if(!target) { objResults[keyI] = noTarget; continue }
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
target._score = NEGATIVE_INFINITY
|
||||
target._indexes.len = 0
|
||||
objResults[keyI] = target
|
||||
}
|
||||
objResults.obj = obj
|
||||
objResults._score = NEGATIVE_INFINITY
|
||||
results.push(objResults); if(results.length >= limit) return results
|
||||
}
|
||||
} else {
|
||||
for(var i=0;i<targets.length;i++) { var target = targets[i]
|
||||
if(target == NULL) continue
|
||||
if(!isPrepared(target)) target = getPrepared(target)
|
||||
target._score = NEGATIVE_INFINITY
|
||||
target._indexes.len = 0
|
||||
results.push(target); if(results.length >= limit) return results
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
|
||||
var algorithm = (preparedSearch, prepared, allowSpaces=false, allowPartialMatch=false) => {
|
||||
if(allowSpaces===false && preparedSearch.containsSpace) return algorithmSpaces(preparedSearch, prepared, allowPartialMatch)
|
||||
|
||||
var searchLower = preparedSearch._lower
|
||||
var searchLowerCodes = preparedSearch.lowerCodes
|
||||
var searchLowerCode = searchLowerCodes[0]
|
||||
var targetLowerCodes = prepared._targetLowerCodes
|
||||
var searchLen = searchLowerCodes.length
|
||||
var targetLen = targetLowerCodes.length
|
||||
var searchI = 0 // where we at
|
||||
var targetI = 0 // where you at
|
||||
var matchesSimpleLen = 0
|
||||
|
||||
// very basic fuzzy match; to remove non-matching targets ASAP!
|
||||
// walk through target. find sequential matches.
|
||||
// if all chars aren't found then exit
|
||||
for(;;) {
|
||||
var isMatch = searchLowerCode === targetLowerCodes[targetI]
|
||||
if(isMatch) {
|
||||
matchesSimple[matchesSimpleLen++] = targetI
|
||||
++searchI; if(searchI === searchLen) break
|
||||
searchLowerCode = searchLowerCodes[searchI]
|
||||
}
|
||||
++targetI; if(targetI >= targetLen) return NULL // Failed to find searchI
|
||||
}
|
||||
|
||||
var searchI = 0
|
||||
var successStrict = false
|
||||
var matchesStrictLen = 0
|
||||
|
||||
var nextBeginningIndexes = prepared._nextBeginningIndexes
|
||||
if(nextBeginningIndexes === NULL) nextBeginningIndexes = prepared._nextBeginningIndexes = prepareNextBeginningIndexes(prepared.target)
|
||||
targetI = matchesSimple[0]===0 ? 0 : nextBeginningIndexes[matchesSimple[0]-1]
|
||||
|
||||
// Our target string successfully matched all characters in sequence!
|
||||
// Let's try a more advanced and strict test to improve the score
|
||||
// only count it as a match if it's consecutive or a beginning character!
|
||||
var backtrackCount = 0
|
||||
if(targetI !== targetLen) for(;;) {
|
||||
if(targetI >= targetLen) {
|
||||
// We failed to find a good spot for this search char, go back to the previous search char and force it forward
|
||||
if(searchI <= 0) break // We failed to push chars forward for a better match
|
||||
|
||||
++backtrackCount; if(backtrackCount > 200) break // exponential backtracking is taking too long, just give up and return a bad match
|
||||
|
||||
--searchI
|
||||
var lastMatch = matchesStrict[--matchesStrictLen]
|
||||
targetI = nextBeginningIndexes[lastMatch]
|
||||
|
||||
} else {
|
||||
var isMatch = searchLowerCodes[searchI] === targetLowerCodes[targetI]
|
||||
if(isMatch) {
|
||||
matchesStrict[matchesStrictLen++] = targetI
|
||||
++searchI; if(searchI === searchLen) { successStrict = true; break }
|
||||
++targetI
|
||||
} else {
|
||||
targetI = nextBeginningIndexes[targetI]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if it's a substring match
|
||||
var substringIndex = searchLen <= 1 ? -1 : prepared._targetLower.indexOf(searchLower, matchesSimple[0]) // perf: this is slow
|
||||
var isSubstring = !!~substringIndex
|
||||
var isSubstringBeginning = !isSubstring ? false : substringIndex===0 || prepared._nextBeginningIndexes[substringIndex-1] === substringIndex
|
||||
|
||||
// if it's a substring match but not at a beginning index, let's try to find a substring starting at a beginning index for a better score
|
||||
if(isSubstring && !isSubstringBeginning) {
|
||||
for(var i=0; i<nextBeginningIndexes.length; i=nextBeginningIndexes[i]) {
|
||||
if(i <= substringIndex) continue
|
||||
|
||||
for(var s=0; s<searchLen; s++) if(searchLowerCodes[s] !== prepared._targetLowerCodes[i+s]) break
|
||||
if(s === searchLen) { substringIndex = i; isSubstringBeginning = true; break }
|
||||
}
|
||||
}
|
||||
|
||||
// tally up the score & keep track of matches for highlighting later
|
||||
// if it's a simple match, we'll switch to a substring match if a substring exists
|
||||
// if it's a strict match, we'll switch to a substring match only if that's a better score
|
||||
|
||||
var calculateScore = matches => {
|
||||
var score = 0
|
||||
|
||||
var extraMatchGroupCount = 0
|
||||
for(var i = 1; i < searchLen; ++i) {
|
||||
if(matches[i] - matches[i-1] !== 1) {score -= matches[i]; ++extraMatchGroupCount}
|
||||
}
|
||||
var unmatchedDistance = matches[searchLen-1] - matches[0] - (searchLen-1)
|
||||
|
||||
score -= (12+unmatchedDistance) * extraMatchGroupCount // penality for more groups
|
||||
|
||||
if(matches[0] !== 0) score -= matches[0]*matches[0]*.2 // penality for not starting near the beginning
|
||||
|
||||
if(!successStrict) {
|
||||
score *= 1000
|
||||
} else {
|
||||
// successStrict on a target with too many beginning indexes loses points for being a bad target
|
||||
var uniqueBeginningIndexes = 1
|
||||
for(var i = nextBeginningIndexes[0]; i < targetLen; i=nextBeginningIndexes[i]) ++uniqueBeginningIndexes
|
||||
|
||||
if(uniqueBeginningIndexes > 24) score *= (uniqueBeginningIndexes-24)*10 // quite arbitrary numbers here ...
|
||||
}
|
||||
|
||||
score -= (targetLen - searchLen)/2 // penality for longer targets
|
||||
|
||||
if(isSubstring) score /= 1+searchLen*searchLen*1 // bonus for being a full substring
|
||||
if(isSubstringBeginning) score /= 1+searchLen*searchLen*1 // bonus for substring starting on a beginningIndex
|
||||
|
||||
score -= (targetLen - searchLen)/2 // penality for longer targets
|
||||
|
||||
return score
|
||||
}
|
||||
|
||||
if(!successStrict) {
|
||||
if(isSubstring) for(var i=0; i<searchLen; ++i) matchesSimple[i] = substringIndex+i // at this point it's safe to overwrite matchehsSimple with substr matches
|
||||
var matchesBest = matchesSimple
|
||||
var score = calculateScore(matchesBest)
|
||||
} else {
|
||||
if(isSubstringBeginning) {
|
||||
for(var i=0; i<searchLen; ++i) matchesSimple[i] = substringIndex+i // at this point it's safe to overwrite matchehsSimple with substr matches
|
||||
var matchesBest = matchesSimple
|
||||
var score = calculateScore(matchesSimple)
|
||||
} else {
|
||||
var matchesBest = matchesStrict
|
||||
var score = calculateScore(matchesStrict)
|
||||
}
|
||||
}
|
||||
|
||||
prepared._score = score
|
||||
|
||||
for(var i = 0; i < searchLen; ++i) prepared._indexes[i] = matchesBest[i]
|
||||
prepared._indexes.len = searchLen
|
||||
|
||||
const result = new Result()
|
||||
result.target = prepared.target
|
||||
result._score = prepared._score
|
||||
result._indexes = prepared._indexes
|
||||
return result
|
||||
}
|
||||
var algorithmSpaces = (preparedSearch, target, allowPartialMatch) => {
|
||||
var seen_indexes = new Set()
|
||||
var score = 0
|
||||
var result = NULL
|
||||
|
||||
var first_seen_index_last_search = 0
|
||||
var searches = preparedSearch.spaceSearches
|
||||
var searchesLen = searches.length
|
||||
var changeslen = 0
|
||||
|
||||
// Return _nextBeginningIndexes back to its normal state
|
||||
var resetNextBeginningIndexes = () => {
|
||||
for(let i=changeslen-1; i>=0; i--) target._nextBeginningIndexes[nextBeginningIndexesChanges[i*2 + 0]] = nextBeginningIndexesChanges[i*2 + 1]
|
||||
}
|
||||
|
||||
var hasAtLeast1Match = false
|
||||
for(var i=0; i<searchesLen; ++i) {
|
||||
allowPartialMatchScores[i] = NEGATIVE_INFINITY
|
||||
var search = searches[i]
|
||||
|
||||
result = algorithm(search, target)
|
||||
if(allowPartialMatch) {
|
||||
if(result === NULL) continue
|
||||
hasAtLeast1Match = true
|
||||
} else {
|
||||
if(result === NULL) {resetNextBeginningIndexes(); return NULL}
|
||||
}
|
||||
|
||||
// if not the last search, we need to mutate _nextBeginningIndexes for the next search
|
||||
var isTheLastSearch = i === searchesLen - 1
|
||||
if(!isTheLastSearch) {
|
||||
var indexes = result._indexes
|
||||
|
||||
var indexesIsConsecutiveSubstring = true
|
||||
for(let i=0; i<indexes.len-1; i++) {
|
||||
if(indexes[i+1] - indexes[i] !== 1) {
|
||||
indexesIsConsecutiveSubstring = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
if(indexesIsConsecutiveSubstring) {
|
||||
var newBeginningIndex = indexes[indexes.len-1] + 1
|
||||
var toReplace = target._nextBeginningIndexes[newBeginningIndex-1]
|
||||
for(let i=newBeginningIndex-1; i>=0; i--) {
|
||||
if(toReplace !== target._nextBeginningIndexes[i]) break
|
||||
target._nextBeginningIndexes[i] = newBeginningIndex
|
||||
nextBeginningIndexesChanges[changeslen*2 + 0] = i
|
||||
nextBeginningIndexesChanges[changeslen*2 + 1] = toReplace
|
||||
changeslen++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
score += result._score / searchesLen
|
||||
allowPartialMatchScores[i] = result._score / searchesLen
|
||||
|
||||
// dock points based on order otherwise "c man" returns Manifest.cpp instead of CheatManager.h
|
||||
if(result._indexes[0] < first_seen_index_last_search) {
|
||||
score -= (first_seen_index_last_search - result._indexes[0]) * 2
|
||||
}
|
||||
first_seen_index_last_search = result._indexes[0]
|
||||
|
||||
for(var j=0; j<result._indexes.len; ++j) seen_indexes.add(result._indexes[j])
|
||||
}
|
||||
|
||||
if(allowPartialMatch && !hasAtLeast1Match) return NULL
|
||||
|
||||
resetNextBeginningIndexes()
|
||||
|
||||
// allows a search with spaces that's an exact substring to score well
|
||||
var allowSpacesResult = algorithm(preparedSearch, target, /*allowSpaces=*/true)
|
||||
if(allowSpacesResult !== NULL && allowSpacesResult._score > score) {
|
||||
if(allowPartialMatch) {
|
||||
for(var i=0; i<searchesLen; ++i) {
|
||||
allowPartialMatchScores[i] = allowSpacesResult._score / searchesLen
|
||||
}
|
||||
}
|
||||
return allowSpacesResult
|
||||
}
|
||||
|
||||
if(allowPartialMatch) result = target
|
||||
result._score = score
|
||||
|
||||
var i = 0
|
||||
for (let index of seen_indexes) result._indexes[i++] = index
|
||||
result._indexes.len = i
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// we use this instead of just .normalize('NFD').replace(/[\u0300-\u036f]/g, '') because that screws with japanese characters
|
||||
var remove_accents = (str) => str.replace(/\p{Script=Latin}+/gu, match => match.normalize('NFD')).replace(/[\u0300-\u036f]/g, '')
|
||||
|
||||
var prepareLowerInfo = (str) => {
|
||||
str = remove_accents(str)
|
||||
var strLen = str.length
|
||||
var lower = str.toLowerCase()
|
||||
var lowerCodes = [] // new Array(strLen) sparse array is too slow
|
||||
var bitflags = 0
|
||||
var containsSpace = false // space isn't stored in bitflags because of how searching with a space works
|
||||
|
||||
for(var i = 0; i < strLen; ++i) {
|
||||
var lowerCode = lowerCodes[i] = lower.charCodeAt(i)
|
||||
|
||||
if(lowerCode === 32) {
|
||||
containsSpace = true
|
||||
continue // it's important that we don't set any bitflags for space
|
||||
}
|
||||
|
||||
var bit = lowerCode>=97&&lowerCode<=122 ? lowerCode-97 // alphabet
|
||||
: lowerCode>=48&&lowerCode<=57 ? 26 // numbers
|
||||
// 3 bits available
|
||||
: lowerCode<=127 ? 30 // other ascii
|
||||
: 31 // other utf8
|
||||
bitflags |= 1<<bit
|
||||
}
|
||||
|
||||
return {lowerCodes:lowerCodes, bitflags:bitflags, containsSpace:containsSpace, _lower:lower}
|
||||
}
|
||||
var prepareBeginningIndexes = (target) => {
|
||||
var targetLen = target.length
|
||||
var beginningIndexes = []; var beginningIndexesLen = 0
|
||||
var wasUpper = false
|
||||
var wasAlphanum = false
|
||||
for(var i = 0; i < targetLen; ++i) {
|
||||
var targetCode = target.charCodeAt(i)
|
||||
var isUpper = targetCode>=65&&targetCode<=90
|
||||
var isAlphanum = isUpper || targetCode>=97&&targetCode<=122 || targetCode>=48&&targetCode<=57
|
||||
var isBeginning = isUpper && !wasUpper || !wasAlphanum || !isAlphanum
|
||||
wasUpper = isUpper
|
||||
wasAlphanum = isAlphanum
|
||||
if(isBeginning) beginningIndexes[beginningIndexesLen++] = i
|
||||
}
|
||||
return beginningIndexes
|
||||
}
|
||||
var prepareNextBeginningIndexes = (target) => {
|
||||
target = remove_accents(target)
|
||||
var targetLen = target.length
|
||||
var beginningIndexes = prepareBeginningIndexes(target)
|
||||
var nextBeginningIndexes = [] // new Array(targetLen) sparse array is too slow
|
||||
var lastIsBeginning = beginningIndexes[0]
|
||||
var lastIsBeginningI = 0
|
||||
for(var i = 0; i < targetLen; ++i) {
|
||||
if(lastIsBeginning > i) {
|
||||
nextBeginningIndexes[i] = lastIsBeginning
|
||||
} else {
|
||||
lastIsBeginning = beginningIndexes[++lastIsBeginningI]
|
||||
nextBeginningIndexes[i] = lastIsBeginning===undefined ? targetLen : lastIsBeginning
|
||||
}
|
||||
}
|
||||
return nextBeginningIndexes
|
||||
}
|
||||
|
||||
var preparedCache = new Map()
|
||||
var preparedSearchCache = new Map()
|
||||
|
||||
// the theory behind these being globals is to reduce garbage collection by not making new arrays
|
||||
var matchesSimple = []; var matchesStrict = []
|
||||
var nextBeginningIndexesChanges = [] // allows straw berry to match strawberry well, by modifying the end of a substring to be considered a beginning index for the rest of the search
|
||||
var keysSpacesBestScores = []; var allowPartialMatchScores = []
|
||||
var tmpTargets = []; var tmpResults = []
|
||||
|
||||
// prop = 'key' 2.5ms optimized for this case, seems to be about as fast as direct obj[prop]
|
||||
// prop = 'key1.key2' 10ms
|
||||
// prop = ['key1', 'key2'] 27ms
|
||||
// prop = obj => obj.tags.join() ??ms
|
||||
var getValue = (obj, prop) => {
|
||||
var tmp = obj[prop]; if(tmp !== undefined) return tmp
|
||||
if(typeof prop === 'function') return prop(obj) // this should run first. but that makes string props slower
|
||||
var segs = prop
|
||||
if(!Array.isArray(prop)) segs = prop.split('.')
|
||||
var len = segs.length
|
||||
var i = -1
|
||||
while (obj && (++i < len)) obj = obj[segs[i]]
|
||||
return obj
|
||||
}
|
||||
|
||||
var isPrepared = (x) => { return typeof x === 'object' && typeof x._bitflags === 'number' }
|
||||
var INFINITY = Infinity; var NEGATIVE_INFINITY = -INFINITY
|
||||
var noResults = []; noResults.total = 0
|
||||
var NULL = null
|
||||
|
||||
var noTarget = prepare('')
|
||||
|
||||
// Hacked version of https://github.com/lemire/FastPriorityQueue.js
|
||||
var fastpriorityqueue=r=>{var e=[],o=0,a={},v=r=>{for(var a=0,v=e[a],c=1;c<o;){var s=c+1;a=c,s<o&&e[s]._score<e[c]._score&&(a=s),e[a-1>>1]=e[a],c=1+(a<<1)}for(var f=a-1>>1;a>0&&v._score<e[f]._score;f=(a=f)-1>>1)e[a]=e[f];e[a]=v};return a.add=(r=>{var a=o;e[o++]=r;for(var v=a-1>>1;a>0&&r._score<e[v]._score;v=(a=v)-1>>1)e[a]=e[v];e[a]=r}),a.poll=(r=>{if(0!==o){var a=e[0];return e[0]=e[--o],v(),a}}),a.peek=(r=>{if(0!==o)return e[0]}),a.replaceTop=(r=>{e[0]=r,v()}),a}
|
||||
var q = fastpriorityqueue() // reuse this
|
||||
1307
Common/fzf.js
Normal file
1307
Common/fzf.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,4 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
@@ -127,14 +126,6 @@ Item {
|
||||
visible: filteredModel.count === 0
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: ClipboardEntry {
|
||||
required property int index
|
||||
required property var model
|
||||
|
||||
@@ -122,7 +122,6 @@ Rectangle {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 6
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.surfaceHover
|
||||
onClicked: deleteRequested()
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ Item {
|
||||
iconName: "info"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: showKeyboardHints ? Theme.primary : Theme.surfaceText
|
||||
hoverColor: Theme.primaryHover
|
||||
onClicked: keyboardHintsToggled()
|
||||
}
|
||||
|
||||
@@ -53,7 +52,6 @@ Item {
|
||||
iconName: "delete_sweep"
|
||||
iconSize: Theme.iconSize
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.surfaceHover
|
||||
onClicked: clearAllClicked()
|
||||
}
|
||||
|
||||
@@ -61,7 +59,6 @@ Item {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.surfaceHover
|
||||
onClicked: closeClicked()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +349,6 @@ DankModal {
|
||||
iconName: "help"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.surfacePressed
|
||||
onClicked: fileBrowserModal.showKeyboardHints = !fileBrowserModal.showKeyboardHints
|
||||
}
|
||||
|
||||
@@ -358,7 +357,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.errorHover
|
||||
onClicked: fileBrowserModal.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.errorHover
|
||||
onClicked: root.hideDialog()
|
||||
}
|
||||
|
||||
@@ -93,23 +92,20 @@ DankModal {
|
||||
border.width: 1
|
||||
clip: true
|
||||
|
||||
ScrollView {
|
||||
DankFlickable {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingM
|
||||
contentHeight: detailsText.contentHeight
|
||||
|
||||
TextArea {
|
||||
StyledText {
|
||||
id: detailsText
|
||||
|
||||
width: parent.width
|
||||
text: NetworkService.networkInfoDetails && NetworkService.networkInfoDetails.replace(/\\n/g, '\n') || "No information available"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceText
|
||||
wrapMode: Text.WordWrap
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
background: null
|
||||
padding: 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -181,7 +181,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.errorHover
|
||||
onClicked: root.hide()
|
||||
}
|
||||
|
||||
@@ -293,7 +292,6 @@ DankModal {
|
||||
iconName: "save"
|
||||
iconSize: Theme.iconSize - 2
|
||||
iconColor: Theme.primary
|
||||
hoverColor: Theme.primaryHover
|
||||
enabled: root.hasUnsavedChanges || SessionData.notepadContent.length > 0
|
||||
onClicked: contentItem.saveToCurrentFile()
|
||||
}
|
||||
@@ -313,7 +311,6 @@ DankModal {
|
||||
iconName: "folder_open"
|
||||
iconSize: Theme.iconSize - 2
|
||||
iconColor: Theme.secondary
|
||||
hoverColor: Theme.secondaryHover
|
||||
onClicked: contentItem.openLoadDialog()
|
||||
}
|
||||
|
||||
@@ -332,7 +329,6 @@ DankModal {
|
||||
iconName: "note_add"
|
||||
iconSize: Theme.iconSize - 2
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.primaryHover
|
||||
onClicked: contentItem.newDocument()
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.12)
|
||||
onClicked: () => {
|
||||
return close();
|
||||
}
|
||||
|
||||
@@ -170,7 +170,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.errorHover
|
||||
onClicked: () => {
|
||||
return processListModal.hide();
|
||||
}
|
||||
|
||||
@@ -159,7 +159,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.errorHover
|
||||
onClicked: () => {
|
||||
return settingsModal.hide();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import Quickshell
|
||||
import Quickshell.Widgets
|
||||
import qs.Common
|
||||
@@ -72,14 +71,6 @@ Rectangle {
|
||||
appLauncher.keyboardNavigationActive = false
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOn
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: ListView.view.width
|
||||
height: resultsList.itemHeight
|
||||
@@ -242,14 +233,6 @@ Rectangle {
|
||||
appLauncher.keyboardNavigationActive = false
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: resultsGrid.cellWidth - resultsGrid.cellPadding
|
||||
height: resultsGrid.cellHeight - resultsGrid.cellPadding
|
||||
|
||||
@@ -97,7 +97,6 @@ DankModal {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Theme.errorHover
|
||||
onClicked: () => {
|
||||
close()
|
||||
wifiPasswordInput = ""
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Effects
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
@@ -271,16 +270,6 @@ DankPopout {
|
||||
iconSize: 20
|
||||
iconColor: appLauncher.viewMode
|
||||
=== "list" ? Theme.primary : Theme.surfaceText
|
||||
hoverColor: appLauncher.viewMode
|
||||
=== "list" ? Qt.rgba(
|
||||
Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b,
|
||||
0.12) : Qt.rgba(
|
||||
Theme.surfaceVariant.r,
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.08)
|
||||
backgroundColor: appLauncher.viewMode
|
||||
=== "list" ? Qt.rgba(
|
||||
Theme.primary.r,
|
||||
@@ -299,16 +288,6 @@ DankPopout {
|
||||
iconSize: 20
|
||||
iconColor: appLauncher.viewMode
|
||||
=== "grid" ? Theme.primary : Theme.surfaceText
|
||||
hoverColor: appLauncher.viewMode
|
||||
=== "grid" ? Qt.rgba(
|
||||
Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b,
|
||||
0.12) : Qt.rgba(
|
||||
Theme.surfaceVariant.r,
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.08)
|
||||
backgroundColor: appLauncher.viewMode
|
||||
=== "grid" ? Qt.rgba(
|
||||
Theme.primary.r,
|
||||
@@ -391,14 +370,6 @@ DankPopout {
|
||||
appLauncher.keyboardNavigationActive = false
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOn
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: ListView.view.width
|
||||
height: appList.itemHeight
|
||||
@@ -576,14 +547,6 @@ DankPopout {
|
||||
appLauncher.keyboardNavigationActive = false
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: appGrid.cellWidth - appGrid.cellPadding
|
||||
height: appGrid.cellHeight - appGrid.cellPadding
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Effects
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
@@ -156,11 +155,6 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: eventsList.contentHeight
|
||||
> eventsList.height ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Theme.mediumDuration
|
||||
|
||||
@@ -246,9 +246,6 @@ DankPopout {
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.5)
|
||||
hoverColor: Qt.rgba(Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b, 0.12)
|
||||
onClicked: {
|
||||
root.close()
|
||||
root.lockRequested()
|
||||
@@ -265,9 +262,6 @@ DankPopout {
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.5)
|
||||
hoverColor: Qt.rgba(Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b, 0.12)
|
||||
onClicked: {
|
||||
root.powerOptionsExpanded = !root.powerOptionsExpanded
|
||||
}
|
||||
@@ -284,9 +278,6 @@ DankPopout {
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.5)
|
||||
hoverColor: Qt.rgba(Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b, 0.12)
|
||||
onClicked: {
|
||||
root.close()
|
||||
settingsModal.show()
|
||||
|
||||
@@ -81,8 +81,6 @@ PanelWindow {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
hoverColor: Qt.rgba(Theme.error.r, Theme.error.g,
|
||||
Theme.error.b, 0.12)
|
||||
onClicked: {
|
||||
powerMenuVisible = false
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ DankActionButton {
|
||||
height: 40
|
||||
property bool isShift: false
|
||||
color: Theme.surface
|
||||
hoverColor: Theme.surfacePressed
|
||||
|
||||
StyledText {
|
||||
id: contentItem
|
||||
|
||||
@@ -41,10 +41,7 @@ Item {
|
||||
active: !SessionData.wallpaperPath
|
||||
asynchronous: true
|
||||
|
||||
sourceComponent: DankBackdrop {
|
||||
screenWidth: parent.width
|
||||
screenHeight: parent.height
|
||||
}
|
||||
sourceComponent: DankBackdrop {}
|
||||
}
|
||||
|
||||
Image {
|
||||
|
||||
@@ -92,14 +92,14 @@ Column {
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
DankFlickable {
|
||||
clip: true
|
||||
width: parent.width
|
||||
height: parent.height - 40
|
||||
clip: true
|
||||
ScrollBar.vertical.policy: ScrollBar.AsNeeded
|
||||
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
||||
contentHeight: coreUsageColumn.implicitHeight
|
||||
|
||||
Column {
|
||||
id: coreUsageColumn
|
||||
width: parent.width
|
||||
spacing: 6
|
||||
|
||||
|
||||
@@ -4,11 +4,9 @@ import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
ScrollView {
|
||||
DankFlickable {
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
ScrollBar.vertical.policy: ScrollBar.AsNeeded
|
||||
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
||||
contentHeight: systemColumn.implicitHeight
|
||||
Component.onCompleted: {
|
||||
DgopService.addRef(["system", "hardware", "diskmounts"])
|
||||
}
|
||||
@@ -17,6 +15,7 @@ ScrollView {
|
||||
}
|
||||
|
||||
Column {
|
||||
id: systemColumn
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
|
||||
|
||||
@@ -286,7 +286,6 @@ Item {
|
||||
enabled: SessionData.wallpaperPath
|
||||
opacity: SessionData.wallpaperPath ? 1 : 0.5
|
||||
backgroundColor: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.5)
|
||||
hoverColor: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
|
||||
iconColor: Theme.surfaceText
|
||||
onClicked: {
|
||||
WallpaperCyclingService.cyclePrevManually();
|
||||
@@ -300,7 +299,6 @@ Item {
|
||||
enabled: SessionData.wallpaperPath
|
||||
opacity: SessionData.wallpaperPath ? 1 : 0.5
|
||||
backgroundColor: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.5)
|
||||
hoverColor: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
|
||||
iconColor: Theme.surfaceText
|
||||
onClicked: {
|
||||
WallpaperCyclingService.cycleNextManually();
|
||||
@@ -395,9 +393,11 @@ Item {
|
||||
width: 200
|
||||
height: 32
|
||||
model: [{
|
||||
"text": "Interval"
|
||||
"text": "Interval",
|
||||
"icon": "schedule"
|
||||
}, {
|
||||
"text": "Time"
|
||||
"text": "Time",
|
||||
"icon": "access_time"
|
||||
}]
|
||||
currentIndex: SessionData.wallpaperCyclingMode === "time" ? 1 : 0
|
||||
onTabClicked: (index) => {
|
||||
@@ -702,9 +702,11 @@ Item {
|
||||
width: 200
|
||||
height: 32
|
||||
model: [{
|
||||
"text": "Time"
|
||||
"text": "Time",
|
||||
"icon": "access_time"
|
||||
}, {
|
||||
"text": "Location"
|
||||
"text": "Location",
|
||||
"icon": "place"
|
||||
}]
|
||||
|
||||
Component.onCompleted: {
|
||||
|
||||
@@ -93,8 +93,6 @@ Item {
|
||||
iconName: "delete_sweep"
|
||||
iconSize: Theme.iconSize - 2
|
||||
iconColor: Theme.error
|
||||
hoverColor: Qt.rgba(Theme.error.r, Theme.error.g,
|
||||
Theme.error.b, 0.12)
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
onClicked: {
|
||||
AppUsageHistoryData.appUsageRanking = {}
|
||||
@@ -218,9 +216,6 @@ Item {
|
||||
iconName: "close"
|
||||
iconSize: 16
|
||||
iconColor: Theme.error
|
||||
hoverColor: Qt.rgba(Theme.error.r,
|
||||
Theme.error.g,
|
||||
Theme.error.b, 0.12)
|
||||
onClicked: {
|
||||
var currentRanking = Object.assign(
|
||||
{},
|
||||
|
||||
@@ -1152,7 +1152,7 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
DankWidgetSelectionPopup {
|
||||
WidgetSelectionPopup {
|
||||
id: widgetSelectionPopup
|
||||
|
||||
anchors.centerIn: parent
|
||||
|
||||
183
Modules/Settings/WidgetSelectionPopup.qml
Normal file
183
Modules/Settings/WidgetSelectionPopup.qml
Normal file
@@ -0,0 +1,183 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
import qs.Widgets
|
||||
|
||||
Popup {
|
||||
id: root
|
||||
|
||||
property var allWidgets: []
|
||||
property string targetSection: ""
|
||||
property bool isOpening: false
|
||||
|
||||
signal widgetSelected(string widgetId, string targetSection)
|
||||
|
||||
function safeOpen() {
|
||||
if (!isOpening && !visible) {
|
||||
isOpening = true
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
width: 400
|
||||
height: 450
|
||||
modal: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
onOpened: {
|
||||
isOpening = false
|
||||
}
|
||||
onClosed: {
|
||||
isOpening = false
|
||||
allWidgets = []
|
||||
targetSection = ""
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g,
|
||||
Theme.surfaceContainer.b, 1)
|
||||
border.color: Theme.primarySelected
|
||||
border.width: 1
|
||||
radius: Theme.cornerRadius
|
||||
}
|
||||
|
||||
contentItem: Item {
|
||||
anchors.fill: parent
|
||||
|
||||
DankActionButton {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 2
|
||||
iconColor: Theme.outline
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
onClicked: root.close()
|
||||
}
|
||||
|
||||
Column {
|
||||
id: contentColumn
|
||||
|
||||
spacing: Theme.spacingM
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingL
|
||||
anchors.topMargin: Theme.spacingL + 30 // Space for close button
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
|
||||
DankIcon {
|
||||
name: "add_circle"
|
||||
size: Theme.iconSize
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: "Add Widget to " + root.targetSection + " Section"
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: "Select a widget to add to the " + root.targetSection.toLowerCase(
|
||||
) + " section of the top bar. You can add multiple instances of the same widget if needed."
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.outline
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
DankListView {
|
||||
id: widgetList
|
||||
|
||||
width: parent.width
|
||||
height: parent.height - y
|
||||
spacing: Theme.spacingS
|
||||
model: root.allWidgets
|
||||
clip: true
|
||||
|
||||
delegate: Rectangle {
|
||||
width: widgetList.width
|
||||
height: 60
|
||||
radius: Theme.cornerRadius
|
||||
color: widgetArea.containsMouse ? Theme.primaryHover : Qt.rgba(
|
||||
Theme.surfaceVariant.r,
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.3)
|
||||
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g,
|
||||
Theme.outline.b, 0.2)
|
||||
border.width: 1
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingM
|
||||
spacing: Theme.spacingM
|
||||
|
||||
DankIcon {
|
||||
name: modelData.icon
|
||||
size: Theme.iconSize
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 2
|
||||
width: parent.width - Theme.iconSize - Theme.spacingM * 3
|
||||
|
||||
StyledText {
|
||||
text: modelData.text
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
elide: Text.ElideRight
|
||||
width: parent.width
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: modelData.description
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.outline
|
||||
elide: Text.ElideRight
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
name: "add"
|
||||
size: Theme.iconSize - 4
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: widgetArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.widgetSelected(modelData.id,
|
||||
root.targetSection)
|
||||
root.close()
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,12 @@ Item {
|
||||
id: launcherContent
|
||||
anchors.fill: parent
|
||||
radius: SettingsData.topBarNoBackground ? 0 : Theme.cornerRadius
|
||||
color: SettingsData.topBarNoBackground ? "transparent" : Qt.rgba(Theme.surfaceTextHover.r, Theme.surfaceTextHover.g,
|
||||
Theme.surfaceTextHover.b,
|
||||
Theme.surfaceTextHover.a * Theme.widgetTransparency)
|
||||
color: {
|
||||
if (SettingsData.topBarNoBackground) return "transparent"
|
||||
const baseColor = launcherArea.containsMouse ? Theme.primaryPressed : (SessionService.idleInhibited ? Theme.primaryHover : Theme.secondaryHover)
|
||||
return Qt.rgba(baseColor.r, baseColor.g, baseColor.b,
|
||||
baseColor.a * Theme.widgetTransparency)
|
||||
}
|
||||
|
||||
SystemLogo {
|
||||
visible: SettingsData.useOSLogo
|
||||
@@ -65,5 +68,12 @@ Item {
|
||||
size: Theme.iconSize - 6
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +49,7 @@ LazyLoader {
|
||||
active: !root.source
|
||||
asynchronous: true
|
||||
|
||||
sourceComponent: DankBackdrop {
|
||||
screenWidth: wallpaperWindow.modelData.width
|
||||
screenHeight: wallpaperWindow.modelData.height
|
||||
}
|
||||
sourceComponent: DankBackdrop {}
|
||||
}
|
||||
|
||||
Img {
|
||||
|
||||
@@ -4,59 +4,103 @@ pragma ComponentBehavior
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import "../Common/fuzzysort.js" as Fuzzy
|
||||
import "../Common/fzf.js" as Fzf
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property var applications: DesktopEntries.applications.values.filter(app => !app.noDisplay && !app.runInTerminal)
|
||||
|
||||
property var preppedApps: applications.map(app => ({
|
||||
"name": Fuzzy.prepare(app.name || ""),
|
||||
"comment": Fuzzy.prepare(app.comment || ""),
|
||||
"entry": app
|
||||
}))
|
||||
|
||||
function searchApplications(query) {
|
||||
if (!query || query.length === 0)
|
||||
return applications
|
||||
if (preppedApps.length === 0)
|
||||
if (applications.length === 0)
|
||||
return []
|
||||
|
||||
var results = Fuzzy.go(query, preppedApps, {
|
||||
"all": false,
|
||||
"keys": ["name", "comment"],
|
||||
"scoreFn": r => {
|
||||
const nameScore = r[0]?.score || 0
|
||||
const commentScore = r[1]?.score || 0
|
||||
const appName = r.obj.entry.name || ""
|
||||
|
||||
if (nameScore === 0) {
|
||||
return commentScore * 0.1
|
||||
}
|
||||
|
||||
const queryLower = query.toLowerCase()
|
||||
const nameLower = appName.toLowerCase()
|
||||
|
||||
if (nameLower === queryLower) {
|
||||
return nameScore * 100
|
||||
}
|
||||
if (nameLower.startsWith(queryLower)) {
|
||||
return nameScore * 50
|
||||
}
|
||||
if (nameLower.includes(" " + queryLower) || nameLower.includes(queryLower + " ") || nameLower.endsWith(" " + queryLower)) {
|
||||
return nameScore * 25
|
||||
}
|
||||
if (nameLower.includes(queryLower)) {
|
||||
return nameScore * 10
|
||||
}
|
||||
|
||||
return nameScore * 2 + commentScore * 0.1
|
||||
},
|
||||
"limit": 50
|
||||
})
|
||||
|
||||
return results.map(r => r.obj.entry)
|
||||
const queryLower = query.toLowerCase()
|
||||
const scoredApps = []
|
||||
|
||||
for (const app of applications) {
|
||||
const name = (app.name || "").toLowerCase()
|
||||
const genericName = (app.genericName || "").toLowerCase()
|
||||
const comment = (app.comment || "").toLowerCase()
|
||||
const keywords = app.keywords ? app.keywords.map(k => k.toLowerCase()) : []
|
||||
|
||||
let score = 0
|
||||
let matched = false
|
||||
|
||||
// Exact name match - highest priority
|
||||
if (name === queryLower) {
|
||||
score = 1000
|
||||
matched = true
|
||||
}
|
||||
// Name starts with query
|
||||
else if (name.startsWith(queryLower)) {
|
||||
score = 900 - name.length
|
||||
matched = true
|
||||
}
|
||||
// Name contains query as a word
|
||||
else if (name.includes(" " + queryLower) || name.includes(queryLower + " ")) {
|
||||
score = 800 - name.length
|
||||
matched = true
|
||||
}
|
||||
// Name contains query substring
|
||||
else if (name.includes(queryLower)) {
|
||||
score = 700 - name.length
|
||||
matched = true
|
||||
}
|
||||
// Check individual keywords
|
||||
else if (keywords.length > 0) {
|
||||
for (const keyword of keywords) {
|
||||
if (keyword === queryLower) {
|
||||
score = 650 // Exact keyword match
|
||||
matched = true
|
||||
break
|
||||
} else if (keyword.startsWith(queryLower)) {
|
||||
score = 620 // Keyword starts with query
|
||||
matched = true
|
||||
break
|
||||
} else if (keyword.includes(queryLower)) {
|
||||
score = 600 // Keyword contains query
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// Generic name matches
|
||||
if (!matched && genericName.includes(queryLower)) {
|
||||
score = 500
|
||||
matched = true
|
||||
}
|
||||
// Comment contains query
|
||||
else if (!matched && comment.includes(queryLower)) {
|
||||
score = 400
|
||||
matched = true
|
||||
}
|
||||
// Fuzzy match on name only (not on all fields)
|
||||
else {
|
||||
const nameFinder = new Fzf.Finder([app], {
|
||||
"selector": a => a.name || "",
|
||||
"casing": "case-insensitive",
|
||||
"fuzzy": "v2"
|
||||
})
|
||||
const fuzzyResults = nameFinder.find(query)
|
||||
if (fuzzyResults.length > 0 && fuzzyResults[0].score > 0) {
|
||||
score = fuzzyResults[0].score
|
||||
matched = true
|
||||
}
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
scoredApps.push({ app, score })
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by score descending
|
||||
scoredApps.sort((a, b) => b.score - a.score)
|
||||
|
||||
// Return top results
|
||||
return scoredApps.slice(0, 50).map(item => item.app)
|
||||
}
|
||||
|
||||
function getCategoriesForApp(app) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Common
|
||||
|
||||
@@ -9,8 +8,7 @@ Image {
|
||||
property string imagePath: ""
|
||||
property string imageHash: ""
|
||||
property int maxCacheSize: 512
|
||||
readonly property string cachePath: imageHash ? `${Paths.stringify(
|
||||
Paths.imagecache)}/${imageHash}@${maxCacheSize}x${maxCacheSize}.png` : ""
|
||||
readonly property string cachePath: imageHash ? `${Paths.stringify(Paths.imagecache)}/${imageHash}@${maxCacheSize}x${maxCacheSize}.png` : ""
|
||||
|
||||
asynchronous: true
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
@@ -18,32 +16,34 @@ Image {
|
||||
sourceSize.height: maxCacheSize
|
||||
smooth: true
|
||||
onImagePathChanged: {
|
||||
if (imagePath) {
|
||||
hashProcess.command = ["sha256sum", Paths.strip(imagePath)]
|
||||
hashProcess.running = true
|
||||
} else {
|
||||
if (!imagePath) {
|
||||
source = ""
|
||||
imageHash = ""
|
||||
return
|
||||
}
|
||||
hashProcess.command = ["sha256sum", Paths.strip(imagePath)]
|
||||
hashProcess.running = true
|
||||
}
|
||||
onCachePathChanged: {
|
||||
if (imageHash && cachePath) {
|
||||
Paths.mkdir(Paths.imagecache)
|
||||
source = cachePath
|
||||
if (!imageHash || !cachePath) {
|
||||
return
|
||||
}
|
||||
Paths.mkdir(Paths.imagecache)
|
||||
source = cachePath
|
||||
}
|
||||
onStatusChanged: {
|
||||
if (source == cachePath && status === Image.Error) {
|
||||
source = imagePath
|
||||
} else if (source == imagePath && status === Image.Ready && imageHash
|
||||
&& cachePath) {
|
||||
Paths.mkdir(Paths.imagecache)
|
||||
const grabPath = cachePath
|
||||
if (visible && width > 0 && height > 0 && Window.window
|
||||
&& Window.window.visible)
|
||||
grabToImage(res => {
|
||||
return res.saveToFile(grabPath)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (source != imagePath || status !== Image.Ready || !imageHash || !cachePath) {
|
||||
return
|
||||
}
|
||||
|
||||
Paths.mkdir(Paths.imagecache)
|
||||
const grabPath = cachePath
|
||||
if (visible && width > 0 && height > 0 && Window.window && Window.window.visible) {
|
||||
grabToImage(res => res.saveToFile(grabPath))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,7 @@ Image {
|
||||
id: hashProcess
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
root.imageHash = text.split(" ")[0]
|
||||
}
|
||||
onStreamFinished: root.imageHash = text.split(" ")[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ StyledRect {
|
||||
property string iconName: ""
|
||||
property int iconSize: Theme.iconSize - 4
|
||||
property color iconColor: Theme.surfaceText
|
||||
property color hoverColor: Theme.primaryHover
|
||||
property color backgroundColor: "transparent"
|
||||
property bool circular: true
|
||||
property int buttonSize: 32
|
||||
@@ -30,8 +29,6 @@ StyledRect {
|
||||
StateLayer {
|
||||
stateColor: Theme.primary
|
||||
cornerRadius: root.radius
|
||||
onClicked: {
|
||||
root.clicked()
|
||||
}
|
||||
onClicked: root.clicked()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
import qs.Common
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property int screenWidth: parent.width
|
||||
property int screenHeight: parent.height
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
Rectangle {
|
||||
@@ -33,28 +29,25 @@ Item {
|
||||
rotation: 35
|
||||
}
|
||||
|
||||
|
||||
Item {
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.leftMargin: Theme.spacingXL * 2
|
||||
anchors.bottomMargin: Theme.spacingXL * 2
|
||||
|
||||
opacity: 0.25
|
||||
|
||||
|
||||
StyledText {
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
text: `
|
||||
██████╗ █████╗ ███╗ ██╗██╗ ██╗
|
||||
██╔══██╗██╔══██╗████╗ ██║██║ ██╔╝
|
||||
██║ ██║███████║██╔██╗ ██║█████╔╝
|
||||
██║ ██║██╔══██║██║╚██╗██║██╔═██╗
|
||||
██████╔╝██║ ██║██║ ╚████║██║ ██╗
|
||||
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝`
|
||||
text: `██████╗ █████╗ ███╗ ██╗██╗ ██╗
|
||||
██╔══██╗██╔══██╗████╗ ██║██║ ██╔╝
|
||||
██║ ██║███████║██╔██╗ ██║█████╔╝
|
||||
██║ ██║██╔══██║██║╚██╗██║██╔═██╗
|
||||
██████╔╝██║ ██║██║ ╚████║██║ ██╗
|
||||
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝`
|
||||
isMonospace: true
|
||||
font.pixelSize: Theme.fontSizeLarge * 1.2
|
||||
color: Theme.primary
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import "../Common/fuzzysort.js" as FuzzySort
|
||||
import "../Common/fzf.js" as Fzf
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
@@ -11,10 +11,10 @@ Rectangle {
|
||||
property string description: ""
|
||||
property string currentValue: ""
|
||||
property var options: []
|
||||
property var optionIcons: [] // Array of icon names corresponding to options
|
||||
property var optionIcons: []
|
||||
property bool forceRecreate: false
|
||||
property bool enableFuzzySearch: false
|
||||
property int popupWidthOffset: 0 // How much wider the popup should be than the button
|
||||
property int popupWidthOffset: 0
|
||||
property int maxPopupHeight: 400
|
||||
|
||||
signal valueChanged(string value)
|
||||
@@ -23,20 +23,20 @@ Rectangle {
|
||||
height: 60
|
||||
radius: Theme.cornerRadius
|
||||
color: "transparent"
|
||||
Component.onCompleted: {
|
||||
forceRecreateTimer.start()
|
||||
}
|
||||
Component.onCompleted: forceRecreateTimer.start()
|
||||
Component.onDestruction: {
|
||||
var popup = popupLoader.item
|
||||
if (popup && popup.visible)
|
||||
const popup = popupLoader.item
|
||||
if (popup && popup.visible) {
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
onVisibleChanged: {
|
||||
var popup = popupLoader.item
|
||||
if (!visible && popup && popup.visible)
|
||||
const popup = popupLoader.item
|
||||
if (!visible && popup && popup.visible) {
|
||||
popup.close()
|
||||
else if (visible)
|
||||
} else if (visible) {
|
||||
forceRecreateTimer.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
@@ -44,12 +44,9 @@ Rectangle {
|
||||
|
||||
interval: 50
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
root.forceRecreate = !root.forceRecreate
|
||||
}
|
||||
onTriggered: root.forceRecreate = !root.forceRecreate
|
||||
}
|
||||
|
||||
|
||||
Column {
|
||||
anchors.left: parent.left
|
||||
anchors.right: dropdown.left
|
||||
@@ -95,16 +92,20 @@ Rectangle {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
var popup = popupLoader.item
|
||||
if (popup && popup.visible) {
|
||||
popup.close()
|
||||
} else if (popup) {
|
||||
var pos = dropdown.mapToItem(Overlay.overlay, 0,
|
||||
dropdown.height + 4)
|
||||
popup.x = pos.x - (root.popupWidthOffset / 2)
|
||||
popup.y = pos.y
|
||||
popup.open()
|
||||
const popup = popupLoader.item
|
||||
if (!popup) {
|
||||
return
|
||||
}
|
||||
|
||||
if (popup.visible) {
|
||||
popup.close()
|
||||
return
|
||||
}
|
||||
|
||||
const pos = dropdown.mapToItem(Overlay.overlay, 0, dropdown.height + 4)
|
||||
popup.x = pos.x - (root.popupWidthOffset / 2)
|
||||
popup.y = pos.y
|
||||
popup.open()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,9 +119,8 @@ Rectangle {
|
||||
|
||||
DankIcon {
|
||||
name: {
|
||||
var currentIndex = root.options.indexOf(root.currentValue)
|
||||
return root.optionIcons.length > currentIndex
|
||||
&& currentIndex >= 0 ? root.optionIcons[currentIndex] : ""
|
||||
const currentIndex = root.options.indexOf(root.currentValue)
|
||||
return currentIndex >= 0 && root.optionIcons.length > currentIndex ? root.optionIcons[currentIndex] : ""
|
||||
}
|
||||
size: 18
|
||||
color: Theme.surfaceVariantText
|
||||
@@ -131,9 +131,7 @@ Rectangle {
|
||||
text: root.currentValue
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceText
|
||||
width: root.width <= 60 ?
|
||||
(dropdown.width - expandIcon.width - Theme.spacingS * 2) :
|
||||
(dropdown.width - contentRow.x - expandIcon.width - Theme.spacingM - Theme.spacingS)
|
||||
width: root.width <= 60 ? dropdown.width - expandIcon.width - Theme.spacingS * 2 : dropdown.width - contentRow.x - expandIcon.width - Theme.spacingM - Theme.spacingS
|
||||
elide: root.width <= 60 ? Text.ElideNone : Text.ElideRight
|
||||
horizontalAlignment: root.width <= 60 ? Text.AlignHCenter : Text.AlignLeft
|
||||
}
|
||||
@@ -169,61 +167,61 @@ Rectangle {
|
||||
property string searchQuery: ""
|
||||
property var filteredOptions: []
|
||||
property int selectedIndex: -1
|
||||
property var fzfFinder: new Fzf.Finder(root.options, {
|
||||
"selector": option => option,
|
||||
"limit": 50,
|
||||
"casing": "case-insensitive"
|
||||
})
|
||||
|
||||
function updateFilteredOptions() {
|
||||
if (!root.enableFuzzySearch || searchQuery.length === 0) {
|
||||
filteredOptions = root.options
|
||||
} else {
|
||||
var results = FuzzySort.go(searchQuery, root.options, {
|
||||
"limit": 50,
|
||||
"threshold": -10000
|
||||
})
|
||||
filteredOptions = results.map(function (result) {
|
||||
return result.target
|
||||
})
|
||||
selectedIndex = -1
|
||||
return
|
||||
}
|
||||
|
||||
const results = fzfFinder.find(searchQuery)
|
||||
filteredOptions = results.map(result => result.item)
|
||||
selectedIndex = -1
|
||||
}
|
||||
|
||||
function selectNext() {
|
||||
if (filteredOptions.length > 0) {
|
||||
selectedIndex = (selectedIndex + 1) % filteredOptions.length
|
||||
listView.positionViewAtIndex(selectedIndex,
|
||||
ListView.Contain)
|
||||
if (filteredOptions.length === 0) {
|
||||
return
|
||||
}
|
||||
selectedIndex = (selectedIndex + 1) % filteredOptions.length
|
||||
listView.positionViewAtIndex(selectedIndex, ListView.Contain)
|
||||
}
|
||||
|
||||
function selectPrevious() {
|
||||
if (filteredOptions.length > 0) {
|
||||
selectedIndex = selectedIndex
|
||||
<= 0 ? filteredOptions.length - 1 : selectedIndex - 1
|
||||
listView.positionViewAtIndex(selectedIndex,
|
||||
ListView.Contain)
|
||||
if (filteredOptions.length === 0) {
|
||||
return
|
||||
}
|
||||
selectedIndex = selectedIndex <= 0 ? filteredOptions.length - 1 : selectedIndex - 1
|
||||
listView.positionViewAtIndex(selectedIndex, ListView.Contain)
|
||||
}
|
||||
|
||||
function selectCurrent() {
|
||||
if (selectedIndex >= 0
|
||||
&& selectedIndex < filteredOptions.length) {
|
||||
root.currentValue = filteredOptions[selectedIndex]
|
||||
root.valueChanged(filteredOptions[selectedIndex])
|
||||
close()
|
||||
if (selectedIndex < 0 || selectedIndex >= filteredOptions.length) {
|
||||
return
|
||||
}
|
||||
root.currentValue = filteredOptions[selectedIndex]
|
||||
root.valueChanged(filteredOptions[selectedIndex])
|
||||
close()
|
||||
}
|
||||
|
||||
parent: Overlay.overlay
|
||||
width: dropdown.width + root.popupWidthOffset
|
||||
height: Math.min(root.maxPopupHeight,
|
||||
(root.enableFuzzySearch ? 54 : 0) + Math.min(
|
||||
filteredOptions.length, 10) * 36 + 16)
|
||||
height: Math.min(root.maxPopupHeight, (root.enableFuzzySearch ? 54 : 0) + Math.min(filteredOptions.length, 10) * 36 + 16)
|
||||
padding: 0
|
||||
modal: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
onOpened: {
|
||||
searchQuery = ""
|
||||
updateFilteredOptions()
|
||||
if (root.enableFuzzySearch && searchField.visible)
|
||||
if (root.enableFuzzySearch && searchField.visible) {
|
||||
searchField.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
@@ -231,9 +229,7 @@ Rectangle {
|
||||
}
|
||||
|
||||
contentItem: Rectangle {
|
||||
color: Qt.rgba(Theme.surfaceContainer.r,
|
||||
Theme.surfaceContainer.g,
|
||||
Theme.surfaceContainer.b, 1)
|
||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 1)
|
||||
border.color: Theme.primarySelected
|
||||
border.width: 1
|
||||
radius: Theme.cornerRadius
|
||||
@@ -288,28 +284,18 @@ Rectangle {
|
||||
model: filteredOptions
|
||||
spacing: 2
|
||||
|
||||
// Qt 6.9+ scrolling: flickDeceleration/maximumFlickVelocity only affect touch now
|
||||
interactive: true
|
||||
flickDeceleration: 1500 // Touch only in Qt 6.9+ // Lower = more momentum, longer scrolling
|
||||
maximumFlickVelocity: 2000 // Touch only in Qt 6.9+ // Higher = faster maximum scroll speed
|
||||
flickDeceleration: 1500
|
||||
maximumFlickVelocity: 2000
|
||||
boundsBehavior: Flickable.DragAndOvershootBounds
|
||||
boundsMovement: Flickable.FollowBoundsBehavior
|
||||
pressDelay: 0
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
property bool isSelected: selectedIndex === index
|
||||
property bool isCurrentValue: root.currentValue === modelData
|
||||
property int optionIndex: root.options.indexOf(
|
||||
modelData)
|
||||
property int optionIndex: root.options.indexOf(modelData)
|
||||
|
||||
width: ListView.view.width
|
||||
height: 32
|
||||
@@ -323,9 +309,7 @@ Rectangle {
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: optionIndex >= 0
|
||||
&& root.optionIcons.length
|
||||
> optionIndex ? root.optionIcons[optionIndex] : ""
|
||||
name: optionIndex >= 0 && root.optionIcons.length > optionIndex ? root.optionIcons[optionIndex] : ""
|
||||
size: 18
|
||||
color: isCurrentValue ? Theme.primary : Theme.surfaceVariantText
|
||||
visible: name !== ""
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
import qs.Widgets
|
||||
|
||||
Flickable {
|
||||
id: flickable
|
||||
@@ -11,7 +12,6 @@ Flickable {
|
||||
property real friction: 0.95
|
||||
property real minMomentumVelocity: 50
|
||||
property real maxMomentumVelocity: 2500
|
||||
// Internal: controls transient scrollbar visibility
|
||||
property bool _scrollBarActive: false
|
||||
|
||||
flickDeceleration: 1500
|
||||
@@ -38,16 +38,15 @@ Flickable {
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
|
||||
|
||||
onWheel: event => {
|
||||
// Activate scrollbar on any wheel interaction
|
||||
flickable._scrollBarActive = true
|
||||
hideScrollBarTimer.restart()
|
||||
let currentTime = Date.now()
|
||||
let timeDelta = currentTime - lastWheelTime
|
||||
vbar._scrollBarActive = true
|
||||
vbar.hideTimer.restart()
|
||||
|
||||
const currentTime = Date.now()
|
||||
const timeDelta = currentTime - lastWheelTime
|
||||
lastWheelTime = currentTime
|
||||
|
||||
const deltaY = event.angleDelta.y
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120
|
||||
&& (Math.abs(deltaY) % 120) === 0
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0
|
||||
|
||||
if (isMouseWheel) {
|
||||
momentumTimer.stop()
|
||||
@@ -56,16 +55,13 @@ Flickable {
|
||||
momentum = 0
|
||||
|
||||
const lines = Math.floor(Math.abs(deltaY) / 120)
|
||||
const scrollAmount = (deltaY > 0 ? -lines : lines)
|
||||
* flickable.mouseWheelSpeed
|
||||
const scrollAmount = (deltaY > 0 ? -lines : lines) * flickable.mouseWheelSpeed
|
||||
let newY = flickable.contentY + scrollAmount
|
||||
newY = Math.max(
|
||||
0, Math.min(
|
||||
flickable.contentHeight - flickable.height,
|
||||
newY))
|
||||
newY = Math.max(0, Math.min(flickable.contentHeight - flickable.height, newY))
|
||||
|
||||
if (flickable.flicking)
|
||||
flickable.cancelFlick()
|
||||
if (flickable.flicking) {
|
||||
flickable.cancelFlick()
|
||||
}
|
||||
|
||||
flickable.contentY = newY
|
||||
} else {
|
||||
@@ -83,22 +79,14 @@ Flickable {
|
||||
"delta": delta,
|
||||
"time": currentTime
|
||||
})
|
||||
velocitySamples = velocitySamples.filter(s => {
|
||||
return currentTime
|
||||
- s.time < 100
|
||||
})
|
||||
velocitySamples = velocitySamples.filter(s => currentTime - s.time < 100)
|
||||
|
||||
if (velocitySamples.length > 1) {
|
||||
let totalDelta = velocitySamples.reduce(
|
||||
(sum, s) => {
|
||||
return sum + s.delta
|
||||
}, 0)
|
||||
let timeSpan = currentTime - velocitySamples[0].time
|
||||
if (timeSpan > 0)
|
||||
flickable.momentumVelocity = Math.max(
|
||||
-flickable.maxMomentumVelocity,
|
||||
Math.min(flickable.maxMomentumVelocity,
|
||||
totalDelta / timeSpan * 1000))
|
||||
const totalDelta = velocitySamples.reduce((sum, s) => sum + s.delta, 0)
|
||||
const timeSpan = currentTime - velocitySamples[0].time
|
||||
if (timeSpan > 0) {
|
||||
flickable.momentumVelocity = Math.max(-flickable.maxMomentumVelocity, Math.min(flickable.maxMomentumVelocity, totalDelta / timeSpan * 1000))
|
||||
}
|
||||
}
|
||||
|
||||
if (event.pixelDelta.y !== 0 && timeDelta < 50) {
|
||||
@@ -109,13 +97,11 @@ Flickable {
|
||||
}
|
||||
|
||||
let newY = flickable.contentY - delta
|
||||
newY = Math.max(
|
||||
0, Math.min(
|
||||
flickable.contentHeight - flickable.height,
|
||||
newY))
|
||||
newY = Math.max(0, Math.min(flickable.contentHeight - flickable.height, newY))
|
||||
|
||||
if (flickable.flicking)
|
||||
flickable.cancelFlick()
|
||||
if (flickable.flicking) {
|
||||
flickable.cancelFlick()
|
||||
}
|
||||
|
||||
flickable.contentY = newY
|
||||
}
|
||||
@@ -135,12 +121,11 @@ Flickable {
|
||||
}
|
||||
}
|
||||
|
||||
// Show scrollbar while flicking / momentum
|
||||
onMovementStarted: {
|
||||
_scrollBarActive = true
|
||||
hideScrollBarTimer.stop()
|
||||
vbar._scrollBarActive = true
|
||||
vbar.hideTimer.stop()
|
||||
}
|
||||
onMovementEnded: hideScrollBarTimer.restart()
|
||||
onMovementEnded: vbar.hideTimer.restart()
|
||||
|
||||
Timer {
|
||||
id: momentumTimer
|
||||
@@ -148,17 +133,11 @@ Flickable {
|
||||
repeat: true
|
||||
|
||||
onTriggered: {
|
||||
let newY = flickable.contentY - flickable.momentumVelocity * 0.016
|
||||
let maxY = Math.max(0, flickable.contentHeight - flickable.height)
|
||||
const newY = flickable.contentY - flickable.momentumVelocity * 0.016
|
||||
const maxY = Math.max(0, flickable.contentHeight - flickable.height)
|
||||
|
||||
if (newY < 0) {
|
||||
flickable.contentY = 0
|
||||
stop()
|
||||
flickable.isMomentumActive = false
|
||||
flickable.momentumVelocity = 0
|
||||
return
|
||||
} else if (newY > maxY) {
|
||||
flickable.contentY = maxY
|
||||
if (newY < 0 || newY > maxY) {
|
||||
flickable.contentY = newY < 0 ? 0 : maxY
|
||||
stop()
|
||||
flickable.isMomentumActive = false
|
||||
flickable.momentumVelocity = 0
|
||||
@@ -166,7 +145,6 @@ Flickable {
|
||||
}
|
||||
|
||||
flickable.contentY = newY
|
||||
|
||||
flickable.momentumVelocity *= flickable.friction
|
||||
|
||||
if (Math.abs(flickable.momentumVelocity) < 5) {
|
||||
@@ -185,50 +163,7 @@ Flickable {
|
||||
easing.type: Easing.OutQuad
|
||||
}
|
||||
|
||||
// Styled vertical scrollbar (auto-hide, no track)
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
ScrollBar.vertical: DankScrollbar {
|
||||
id: vbar
|
||||
policy: flickable.contentHeight
|
||||
> flickable.height ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
|
||||
minimumSize: 0.08
|
||||
implicitWidth: 10
|
||||
interactive: true
|
||||
hoverEnabled: true
|
||||
z: 1000
|
||||
opacity: (policy !== ScrollBar.AlwaysOff)
|
||||
&& (vbar.pressed || vbar.hovered || vbar.active
|
||||
|| flickable.moving || flickable.flicking
|
||||
|| flickable.isMomentumActive
|
||||
|| flickable._scrollBarActive) ? 1 : 0
|
||||
visible: policy !== ScrollBar.AlwaysOff
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: 160
|
||||
easing.type: Easing.OutQuad
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Rectangle {
|
||||
implicitWidth: 6
|
||||
radius: width / 2
|
||||
color: vbar.pressed ? Theme.primary : (vbar.hovered || vbar.active
|
||||
|| flickable.moving
|
||||
|| flickable.flicking
|
||||
|| flickable.isMomentumActive
|
||||
|| flickable._scrollBarActive ? Theme.outline : Theme.outlineMedium)
|
||||
opacity: vbar.pressed ? 1 : (vbar.hovered || vbar.active
|
||||
|| flickable.moving
|
||||
|| flickable.flicking
|
||||
|| flickable.isMomentumActive
|
||||
|| flickable._scrollBarActive ? 1 : 0.6)
|
||||
}
|
||||
|
||||
background: Item {}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: hideScrollBarTimer
|
||||
interval: 1200
|
||||
onTriggered: flickable._scrollBarActive = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Widgets
|
||||
|
||||
GridView {
|
||||
id: gridView
|
||||
|
||||
// Kinetic scrolling momentum properties
|
||||
property real momentumVelocity: 0
|
||||
property bool isMomentumActive: false
|
||||
property real friction: 0.95
|
||||
@@ -18,14 +18,17 @@ GridView {
|
||||
pressDelay: 0
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
|
||||
onMovementStarted: {
|
||||
vbar._scrollBarActive = true
|
||||
vbar.hideTimer.stop()
|
||||
}
|
||||
onMovementEnded: vbar.hideTimer.restart()
|
||||
|
||||
WheelHandler {
|
||||
id: wheelHandler
|
||||
|
||||
// Tunable parameters for responsive scrolling
|
||||
property real mouseWheelSpeed: 60
|
||||
// Higher = faster mouse wheel
|
||||
property real touchpadSpeed: 1.8
|
||||
// Touchpad sensitivity
|
||||
property real momentumRetention: 0.92
|
||||
property real lastWheelTime: 0
|
||||
property real momentum: 0
|
||||
@@ -38,17 +41,17 @@ GridView {
|
||||
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
|
||||
onWheel: event => {
|
||||
let currentTime = Date.now()
|
||||
let timeDelta = currentTime - lastWheelTime
|
||||
vbar._scrollBarActive = true
|
||||
vbar.hideTimer.restart()
|
||||
|
||||
const currentTime = Date.now()
|
||||
const timeDelta = currentTime - lastWheelTime
|
||||
lastWheelTime = currentTime
|
||||
|
||||
// Detect mouse wheel vs touchpad
|
||||
const deltaY = event.angleDelta.y
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120
|
||||
&& (Math.abs(deltaY) % 120) === 0
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0
|
||||
|
||||
if (isMouseWheel) {
|
||||
// Fixed scrolling for mouse wheel - 2 cells per click
|
||||
momentumTimer.stop()
|
||||
isMomentumActive = false
|
||||
velocitySamples = []
|
||||
@@ -56,55 +59,34 @@ GridView {
|
||||
|
||||
const lines = Math.floor(Math.abs(deltaY) / 120)
|
||||
const scrollAmount = (deltaY > 0 ? -lines : lines) * cellHeight * 0.35
|
||||
// 0.15 cells per wheel click
|
||||
let newY = contentY + scrollAmount
|
||||
newY = Math.max(0,
|
||||
Math.min(contentHeight - height, newY))
|
||||
newY = Math.max(0, Math.min(contentHeight - height, newY))
|
||||
|
||||
if (flicking)
|
||||
cancelFlick()
|
||||
if (flicking) {
|
||||
cancelFlick()
|
||||
}
|
||||
|
||||
contentY = newY
|
||||
} else {
|
||||
// Touchpad - existing smooth kinetic scrolling
|
||||
// Stop any existing momentum
|
||||
momentumTimer.stop()
|
||||
isMomentumActive = false
|
||||
|
||||
// Calculate scroll delta based on input type
|
||||
let delta = 0
|
||||
if (event.pixelDelta.y !== 0)
|
||||
// Touchpad with pixel precision
|
||||
delta = event.pixelDelta.y * touchpadSpeed
|
||||
else
|
||||
// Fallback for touchpad without pixel delta
|
||||
delta = event.angleDelta.y / 120 * cellHeight * 1.2
|
||||
let delta = event.pixelDelta.y !== 0 ? event.pixelDelta.y * touchpadSpeed : event.angleDelta.y / 120 * cellHeight * 1.2
|
||||
|
||||
// Track velocity for momentum
|
||||
velocitySamples.push({
|
||||
"delta": delta,
|
||||
"time": currentTime
|
||||
})
|
||||
velocitySamples = velocitySamples.filter(s => {
|
||||
return currentTime
|
||||
- s.time < 100
|
||||
})
|
||||
velocitySamples = velocitySamples.filter(s => currentTime - s.time < 100)
|
||||
|
||||
// Calculate momentum velocity from samples
|
||||
if (velocitySamples.length > 1) {
|
||||
let totalDelta = velocitySamples.reduce(
|
||||
(sum, s) => {
|
||||
return sum + s.delta
|
||||
}, 0)
|
||||
let timeSpan = currentTime - velocitySamples[0].time
|
||||
if (timeSpan > 0)
|
||||
momentumVelocity = Math.max(
|
||||
-maxMomentumVelocity,
|
||||
Math.min(maxMomentumVelocity,
|
||||
totalDelta / timeSpan * 1000))
|
||||
const totalDelta = velocitySamples.reduce((sum, s) => sum + s.delta, 0)
|
||||
const timeSpan = currentTime - velocitySamples[0].time
|
||||
if (timeSpan > 0) {
|
||||
momentumVelocity = Math.max(-maxMomentumVelocity, Math.min(maxMomentumVelocity, totalDelta / timeSpan * 1000))
|
||||
}
|
||||
}
|
||||
|
||||
// Apply momentum for touchpad (smooth continuous scrolling)
|
||||
if (event.pixelDelta.y !== 0 && timeDelta < 50) {
|
||||
momentum = momentum * momentumRetention + delta * 0.15
|
||||
delta += momentum
|
||||
@@ -112,14 +94,12 @@ GridView {
|
||||
momentum = 0
|
||||
}
|
||||
|
||||
// Apply scrolling with proper bounds checking
|
||||
let newY = contentY - delta
|
||||
newY = Math.max(0,
|
||||
Math.min(contentHeight - height, newY))
|
||||
newY = Math.max(0, Math.min(contentHeight - height, newY))
|
||||
|
||||
// Cancel any conflicting flicks and apply new position
|
||||
if (flicking)
|
||||
cancelFlick()
|
||||
if (flicking) {
|
||||
cancelFlick()
|
||||
}
|
||||
|
||||
contentY = newY
|
||||
}
|
||||
@@ -127,35 +107,27 @@ GridView {
|
||||
event.accepted = true
|
||||
}
|
||||
onActiveChanged: {
|
||||
if (!active && Math.abs(momentumVelocity) >= minMomentumVelocity) {
|
||||
startMomentum()
|
||||
} else if (!active) {
|
||||
velocitySamples = []
|
||||
momentumVelocity = 0
|
||||
if (!active) {
|
||||
if (Math.abs(momentumVelocity) >= minMomentumVelocity) {
|
||||
startMomentum()
|
||||
} else {
|
||||
velocitySamples = []
|
||||
momentumVelocity = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Physics-based momentum timer for kinetic scrolling
|
||||
Timer {
|
||||
id: momentumTimer
|
||||
|
||||
interval: 16 // ~60 FPS
|
||||
interval: 16
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
// Apply velocity to position
|
||||
let newY = contentY - momentumVelocity * 0.016
|
||||
let maxY = Math.max(0, contentHeight - height)
|
||||
const newY = contentY - momentumVelocity * 0.016
|
||||
const maxY = Math.max(0, contentHeight - height)
|
||||
|
||||
// Stop momentum at boundaries instead of bouncing
|
||||
if (newY < 0) {
|
||||
contentY = 0
|
||||
stop()
|
||||
isMomentumActive = false
|
||||
momentumVelocity = 0
|
||||
return
|
||||
} else if (newY > maxY) {
|
||||
contentY = maxY
|
||||
if (newY < 0 || newY > maxY) {
|
||||
contentY = newY < 0 ? 0 : maxY
|
||||
stop()
|
||||
isMomentumActive = false
|
||||
momentumVelocity = 0
|
||||
@@ -163,11 +135,8 @@ GridView {
|
||||
}
|
||||
|
||||
contentY = newY
|
||||
|
||||
// Apply friction
|
||||
momentumVelocity *= friction
|
||||
|
||||
// Stop if velocity too low
|
||||
if (Math.abs(momentumVelocity) < 5) {
|
||||
stop()
|
||||
isMomentumActive = false
|
||||
@@ -176,13 +145,15 @@ GridView {
|
||||
}
|
||||
}
|
||||
|
||||
// Smooth return to bounds animation
|
||||
NumberAnimation {
|
||||
id: returnToBoundsAnimation
|
||||
|
||||
target: gridView
|
||||
property: "contentY"
|
||||
duration: 300
|
||||
easing.type: Easing.OutQuad
|
||||
}
|
||||
|
||||
ScrollBar.vertical: DankScrollbar {
|
||||
id: vbar
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ StyledText {
|
||||
property alias size: icon.font.pixelSize
|
||||
property alias color: icon.color
|
||||
property bool filled: false
|
||||
property real fill: filled ? 1 : 0
|
||||
property real fill: filled ? 1.0 : 0.0
|
||||
property int grade: Theme.isLightMode ? 0 : -25
|
||||
property int weight: filled ? 500 : 400
|
||||
|
||||
@@ -18,12 +18,12 @@ StyledText {
|
||||
color: Theme.surfaceText
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font.variableAxes: ({
|
||||
"FILL": fill.toFixed(1),
|
||||
"GRAD": grade,
|
||||
"opsz": 24,
|
||||
"wght": weight
|
||||
})
|
||||
font.variableAxes: {
|
||||
"FILL": fill.toFixed(1),
|
||||
"GRAD": grade,
|
||||
"opsz": 24,
|
||||
"wght": weight
|
||||
}
|
||||
|
||||
Behavior on fill {
|
||||
NumberAnimation {
|
||||
|
||||
@@ -10,7 +10,6 @@ Rectangle {
|
||||
id: root
|
||||
|
||||
property string currentIcon: ""
|
||||
property string currentText: ""
|
||||
property string iconType: "icon" // "icon" or "text"
|
||||
|
||||
signal iconSelected(string iconName, string iconType)
|
||||
@@ -19,12 +18,15 @@ Rectangle {
|
||||
height: 32
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.surfaceContainer
|
||||
border.color: dropdownLoader.active ? Theme.primary : (mouseArea.containsMouse ? Theme.outline : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.5))
|
||||
border.color: dropdownLoader.active ? Theme.primary : Theme.outline
|
||||
border.width: 1
|
||||
|
||||
property var iconCategories: [{
|
||||
"name": "Numbers",
|
||||
"icons": ["looks_one", "looks_two", "looks_3", "looks_4", "looks_5", "looks_6", "filter_1", "filter_2", "filter_3", "filter_4", "filter_5", "filter_6", "filter_7", "filter_8", "filter_9", "filter_9_plus", "plus_one", "exposure_plus_1", "exposure_plus_2"]
|
||||
}, {
|
||||
"name": "Workspace",
|
||||
"icons": ["work", "laptop", "desktop_windows", "code", "terminal", "build", "settings", "folder", "view_module", "dashboard", "apps", "grid_view"]
|
||||
"icons": ["work", "laptop", "desktop_windows", "folder", "view_module", "dashboard", "apps", "grid_view"]
|
||||
}, {
|
||||
"name": "Development",
|
||||
"icons": ["code", "terminal", "bug_report", "build", "engineering", "integration_instructions", "data_object", "schema", "api", "webhook"]
|
||||
@@ -36,7 +38,7 @@ Rectangle {
|
||||
"icons": ["music_note", "headphones", "mic", "videocam", "photo", "movie", "library_music", "album", "radio", "volume_up"]
|
||||
}, {
|
||||
"name": "System",
|
||||
"icons": ["memory", "storage", "developer_board", "monitor", "keyboard", "mouse", "battery_std", "wifi", "bluetooth", "security"]
|
||||
"icons": ["memory", "storage", "developer_board", "monitor", "keyboard", "mouse", "battery_std", "wifi", "bluetooth", "security", "settings"]
|
||||
}, {
|
||||
"name": "Navigation",
|
||||
"icons": ["home", "arrow_forward", "arrow_back", "expand_more", "expand_less", "menu", "close", "search", "filter_list", "sort"]
|
||||
@@ -45,21 +47,12 @@ Rectangle {
|
||||
"icons": ["add", "remove", "edit", "delete", "save", "download", "upload", "share", "content_copy", "content_paste", "content_cut", "undo", "redo"]
|
||||
}, {
|
||||
"name": "Status",
|
||||
"icons": ["check", "close", "error", "warning", "info", "done", "pending", "schedule", "update", "sync", "offline_bolt"]
|
||||
"icons": ["check", "error", "warning", "info", "done", "pending", "schedule", "update", "sync", "offline_bolt"]
|
||||
}, {
|
||||
"name": "Fun",
|
||||
"icons": ["celebration", "cake", "star", "favorite", "pets", "sports_esports", "local_fire_department", "bolt", "auto_awesome", "diamond"]
|
||||
}]
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onClicked: {
|
||||
dropdownLoader.active = !dropdownLoader.active
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
@@ -67,29 +60,26 @@ Rectangle {
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: root.iconType === "icon"
|
||||
&& root.currentIcon ? root.currentIcon : (root.iconType
|
||||
=== "text" ? "text_fields" : "add")
|
||||
name: (root.iconType === "icon" && root.currentIcon) ? root.currentIcon : (root.iconType === "text" ? "text_fields" : "add")
|
||||
size: 16
|
||||
color: root.currentIcon
|
||||
|| root.currentText ? Theme.surfaceText : Theme.outline
|
||||
color: root.currentIcon ? Theme.surfaceText : Theme.outline
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: {
|
||||
if (root.iconType === "text" && root.currentText)
|
||||
return root.currentText
|
||||
if (root.iconType === "icon" && root.currentIcon)
|
||||
return root.currentIcon
|
||||
return "Choose icon or text"
|
||||
}
|
||||
text: root.currentIcon ? root.currentIcon : "Choose icon"
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: root.currentIcon
|
||||
|| root.currentText ? Theme.surfaceText : Theme.outline
|
||||
color: root.currentIcon ? Theme.surfaceText : Theme.outline
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 160
|
||||
elide: Text.ElideRight
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
dropdownLoader.active = !dropdownLoader.active
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +106,6 @@ Rectangle {
|
||||
color: "transparent"
|
||||
WlrLayershell.layer: WlrLayershell.Overlay
|
||||
WlrLayershell.exclusiveZone: -1
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand
|
||||
|
||||
anchors {
|
||||
top: true
|
||||
@@ -125,37 +114,58 @@ Rectangle {
|
||||
bottom: true
|
||||
}
|
||||
|
||||
// Click outside to close
|
||||
// Top area - above popup
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: dropdownLoader.active = false
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
height: popupContainer.y
|
||||
onClicked: {
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
|
||||
// Bottom area - below popup
|
||||
MouseArea {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: popupContainer.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
onClicked: {
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
|
||||
// Left area - left of popup
|
||||
MouseArea {
|
||||
anchors.left: parent.left
|
||||
anchors.top: popupContainer.top
|
||||
anchors.bottom: popupContainer.bottom
|
||||
width: popupContainer.x
|
||||
onClicked: {
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
|
||||
// Right area - right of popup
|
||||
MouseArea {
|
||||
anchors.right: parent.right
|
||||
anchors.top: popupContainer.top
|
||||
anchors.bottom: popupContainer.bottom
|
||||
anchors.left: popupContainer.right
|
||||
onClicked: {
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: popupContainer
|
||||
width: 320
|
||||
height: Math.min(500, dropdownContent.implicitHeight + 32)
|
||||
x: {
|
||||
// Get the root picker's position relative to the screen
|
||||
var pickerPos = root.mapToItem(null, 0, 0)
|
||||
return Math.max(16, Math.min(pickerPos.x,
|
||||
parent.width - width - 16))
|
||||
}
|
||||
y: {
|
||||
// Position below the picker button
|
||||
var pickerPos = root.mapToItem(null, 0, root.height + 4)
|
||||
return Math.max(16, Math.min(pickerPos.y,
|
||||
parent.height - height - 16))
|
||||
}
|
||||
x: Math.max(16, Math.min(root.mapToItem(null, 0, 0).x, parent.width - width - 16))
|
||||
y: Math.max(16, Math.min(root.mapToItem(null, 0, root.height + 4).y, parent.height - height - 16))
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.surface
|
||||
border.color: Theme.outline
|
||||
border.width: 1
|
||||
|
||||
// Prevent this from closing the dropdown when clicked
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
// Don't propagate clicks to parent
|
||||
}
|
||||
|
||||
layer.enabled: true
|
||||
layer.effect: MultiEffect {
|
||||
@@ -166,95 +176,48 @@ Rectangle {
|
||||
shadowVerticalOffset: 4
|
||||
}
|
||||
|
||||
// Close button
|
||||
Rectangle {
|
||||
width: 24
|
||||
height: 24
|
||||
radius: 12
|
||||
color: closeMouseArea.containsMouse ? Theme.errorHover : "transparent"
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.topMargin: Theme.spacingS
|
||||
anchors.rightMargin: Theme.spacingS
|
||||
z: 1
|
||||
|
||||
DankIcon {
|
||||
name: "close"
|
||||
size: 16
|
||||
color: closeMouseArea.containsMouse ? Theme.error : Theme.outline
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: closeMouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DankFlickable {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingS
|
||||
contentHeight: dropdownContent.height
|
||||
clip: true
|
||||
pressDelay: 0
|
||||
|
||||
Column {
|
||||
id: dropdownContent
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
|
||||
// Custom text section
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: customTextSection.implicitHeight + Theme.spacingS * 2
|
||||
radius: Theme.cornerRadius
|
||||
color: Qt.rgba(Theme.surfaceVariant.r,
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b, 0.3)
|
||||
|
||||
Column {
|
||||
id: customTextSection
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingS
|
||||
spacing: Theme.spacingS
|
||||
|
||||
StyledText {
|
||||
text: "Custom Text"
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 28
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.surfaceContainer
|
||||
border.color: customTextInput.activeFocus ? Theme.primary : Theme.outline
|
||||
border.width: 1
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.leftMargin: Theme.spacingS
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: "text_fields"
|
||||
size: 14
|
||||
color: Theme.outline
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
TextInput {
|
||||
id: customTextInput
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 200
|
||||
text: root.iconType === "text" ? root.currentText : ""
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceText
|
||||
selectByMouse: true
|
||||
|
||||
onEditingFinished: {
|
||||
var trimmedText = text.trim()
|
||||
if (trimmedText) {
|
||||
root.iconSelected(
|
||||
trimmedText,
|
||||
"text")
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Theme.spacingS + 14 + Theme.spacingS
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "1-2 characters"
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.outline
|
||||
opacity: 0.6
|
||||
visible: customTextInput.text === ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Icon categories
|
||||
Repeater {
|
||||
model: root.iconCategories
|
||||
@@ -298,9 +261,7 @@ Rectangle {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.iconSelected(
|
||||
modelData,
|
||||
"icon")
|
||||
root.iconSelected(modelData, "icon")
|
||||
dropdownLoader.active = false
|
||||
}
|
||||
}
|
||||
@@ -323,14 +284,8 @@ Rectangle {
|
||||
}
|
||||
|
||||
function setIcon(iconName, type) {
|
||||
if (type === "text") {
|
||||
root.currentText = iconName
|
||||
root.currentIcon = ""
|
||||
root.iconType = "text"
|
||||
} else {
|
||||
root.currentIcon = iconName
|
||||
root.currentText = ""
|
||||
root.iconType = "icon"
|
||||
}
|
||||
root.iconType = type
|
||||
root.iconType = "icon"
|
||||
root.currentIcon = iconName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Widgets
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
|
||||
property real mouseWheelSpeed: 60
|
||||
|
||||
// Simple position preservation
|
||||
property real savedY: 0
|
||||
property bool justChanged: false
|
||||
property bool isUserScrolling: false
|
||||
|
||||
// Kinetic scrolling momentum properties
|
||||
property real momentumVelocity: 0
|
||||
property bool isMomentumActive: false
|
||||
property real friction: 0.95
|
||||
@@ -25,8 +22,15 @@ ListView {
|
||||
pressDelay: 0
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
|
||||
onMovementStarted: isUserScrolling = true
|
||||
onMovementEnded: isUserScrolling = false
|
||||
onMovementStarted: {
|
||||
isUserScrolling = true
|
||||
vbar._scrollBarActive = true
|
||||
vbar.hideTimer.stop()
|
||||
}
|
||||
onMovementEnded: {
|
||||
isUserScrolling = false
|
||||
vbar.hideTimer.restart()
|
||||
}
|
||||
|
||||
onContentYChanged: {
|
||||
if (!justChanged && isUserScrolling) {
|
||||
@@ -35,7 +39,6 @@ ListView {
|
||||
justChanged = false
|
||||
}
|
||||
|
||||
// Restore position when model changes
|
||||
onModelChanged: {
|
||||
justChanged = true
|
||||
contentY = savedY
|
||||
@@ -43,10 +46,7 @@ ListView {
|
||||
|
||||
WheelHandler {
|
||||
id: wheelHandler
|
||||
|
||||
// Tunable parameters for responsive scrolling
|
||||
property real touchpadSpeed: 1.8 // Touchpad sensitivity
|
||||
property real momentumRetention: 0.92
|
||||
property real touchpadSpeed: 1.8
|
||||
property real lastWheelTime: 0
|
||||
property real momentum: 0
|
||||
property var velocitySamples: []
|
||||
@@ -59,16 +59,16 @@ ListView {
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
|
||||
|
||||
onWheel: event => {
|
||||
isUserScrolling = true // Mark as user interaction
|
||||
isUserScrolling = true
|
||||
vbar._scrollBarActive = true
|
||||
vbar.hideTimer.restart()
|
||||
|
||||
let currentTime = Date.now()
|
||||
let timeDelta = currentTime - lastWheelTime
|
||||
const currentTime = Date.now()
|
||||
const timeDelta = currentTime - lastWheelTime
|
||||
lastWheelTime = currentTime
|
||||
|
||||
// Detect mouse wheel vs touchpad, seems like assuming based on the increments is the only way in QT
|
||||
const deltaY = event.angleDelta.y
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120
|
||||
&& (Math.abs(deltaY) % 120) === 0
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0
|
||||
|
||||
if (isMouseWheel) {
|
||||
momentumTimer.stop()
|
||||
@@ -79,13 +79,11 @@ ListView {
|
||||
const lines = Math.floor(Math.abs(deltaY) / 120)
|
||||
const scrollAmount = (deltaY > 0 ? -lines : lines) * mouseWheelSpeed
|
||||
let newY = listView.contentY + scrollAmount
|
||||
newY = Math.max(
|
||||
0,
|
||||
Math.min(listView.contentHeight - listView.height,
|
||||
newY))
|
||||
newY = Math.max(0, Math.min(listView.contentHeight - listView.height, newY))
|
||||
|
||||
if (listView.flicking)
|
||||
listView.cancelFlick()
|
||||
if (listView.flicking) {
|
||||
listView.cancelFlick()
|
||||
}
|
||||
|
||||
listView.contentY = newY
|
||||
savedY = newY
|
||||
@@ -93,61 +91,43 @@ ListView {
|
||||
momentumTimer.stop()
|
||||
isMomentumActive = false
|
||||
|
||||
// Calculate scroll delta based on input type
|
||||
let delta = 0
|
||||
if (event.pixelDelta.y !== 0) {
|
||||
// Touchpad with pixel precision
|
||||
delta = event.pixelDelta.y * touchpadSpeed
|
||||
} else {
|
||||
// Fallback for touchpad without pixel delta
|
||||
delta = event.angleDelta.y / 8 * touchpadSpeed
|
||||
}
|
||||
|
||||
// Track velocity for momentum
|
||||
velocitySamples.push({
|
||||
"delta": delta,
|
||||
"time": currentTime
|
||||
})
|
||||
velocitySamples = velocitySamples.filter(s => {
|
||||
return currentTime
|
||||
- s.time < 100
|
||||
})
|
||||
velocitySamples = velocitySamples.filter(s => currentTime - s.time < 100)
|
||||
|
||||
// Calculate momentum velocity from samples
|
||||
if (velocitySamples.length > 1) {
|
||||
let totalDelta = velocitySamples.reduce(
|
||||
(sum, s) => {
|
||||
return sum + s.delta
|
||||
}, 0)
|
||||
let timeSpan = currentTime - velocitySamples[0].time
|
||||
if (timeSpan > 0)
|
||||
momentumVelocity = Math.max(
|
||||
-maxMomentumVelocity,
|
||||
Math.min(maxMomentumVelocity,
|
||||
totalDelta / timeSpan * 1000))
|
||||
const totalDelta = velocitySamples.reduce((sum, s) => sum + s.delta, 0)
|
||||
const timeSpan = currentTime - velocitySamples[0].time
|
||||
if (timeSpan > 0) {
|
||||
momentumVelocity = Math.max(-maxMomentumVelocity, Math.min(maxMomentumVelocity, totalDelta / timeSpan * 1000))
|
||||
}
|
||||
}
|
||||
|
||||
// Apply momentum for touchpad (smooth continuous scrolling)
|
||||
if (event.pixelDelta.y !== 0 && timeDelta < 50) {
|
||||
momentum = momentum * momentumRetention + delta * 0.15
|
||||
momentum = momentum * 0.92 + delta * 0.15
|
||||
delta += momentum
|
||||
} else {
|
||||
momentum = 0
|
||||
}
|
||||
|
||||
// Apply scrolling with proper bounds checking
|
||||
let newY = listView.contentY - delta
|
||||
newY = Math.max(
|
||||
0,
|
||||
Math.min(listView.contentHeight - listView.height,
|
||||
newY))
|
||||
newY = Math.max(0, Math.min(listView.contentHeight - listView.height, newY))
|
||||
|
||||
// Cancel any conflicting flicks and apply new position
|
||||
if (listView.flicking)
|
||||
listView.cancelFlick()
|
||||
if (listView.flicking) {
|
||||
listView.cancelFlick()
|
||||
}
|
||||
|
||||
listView.contentY = newY
|
||||
savedY = newY // Update saved position
|
||||
savedY = newY
|
||||
}
|
||||
|
||||
event.accepted = true
|
||||
@@ -156,8 +136,6 @@ ListView {
|
||||
onActiveChanged: {
|
||||
if (!active) {
|
||||
isUserScrolling = false
|
||||
|
||||
// Start momentum if applicable (touchpad only)
|
||||
if (Math.abs(momentumVelocity) >= minMomentumVelocity) {
|
||||
startMomentum()
|
||||
} else {
|
||||
@@ -168,28 +146,18 @@ ListView {
|
||||
}
|
||||
}
|
||||
|
||||
// Physics-based momentum timer for kinetic scrolling (touchpad only)
|
||||
Timer {
|
||||
id: momentumTimer
|
||||
interval: 16 // ~60 FPS
|
||||
interval: 16
|
||||
repeat: true
|
||||
|
||||
onTriggered: {
|
||||
// Apply velocity to position
|
||||
let newY = contentY - momentumVelocity * 0.016
|
||||
let maxY = Math.max(0, contentHeight - height)
|
||||
const newY = contentY - momentumVelocity * 0.016
|
||||
const maxY = Math.max(0, contentHeight - height)
|
||||
|
||||
// Stop momentum at boundaries instead of bouncing
|
||||
if (newY < 0) {
|
||||
contentY = 0
|
||||
savedY = 0
|
||||
stop()
|
||||
isMomentumActive = false
|
||||
momentumVelocity = 0
|
||||
return
|
||||
} else if (newY > maxY) {
|
||||
contentY = maxY
|
||||
savedY = maxY
|
||||
if (newY < 0 || newY > maxY) {
|
||||
contentY = newY < 0 ? 0 : maxY
|
||||
savedY = contentY
|
||||
stop()
|
||||
isMomentumActive = false
|
||||
momentumVelocity = 0
|
||||
@@ -197,12 +165,9 @@ ListView {
|
||||
}
|
||||
|
||||
contentY = newY
|
||||
savedY = newY // Keep updating saved position during momentum
|
||||
|
||||
// Apply friction
|
||||
savedY = newY
|
||||
momentumVelocity *= friction
|
||||
|
||||
// Stop if velocity too low
|
||||
if (Math.abs(momentumVelocity) < 5) {
|
||||
stop()
|
||||
isMomentumActive = false
|
||||
@@ -211,12 +176,7 @@ ListView {
|
||||
}
|
||||
}
|
||||
|
||||
// Smooth return to bounds animation
|
||||
NumberAnimation {
|
||||
id: returnToBoundsAnimation
|
||||
target: listView
|
||||
property: "contentY"
|
||||
duration: 300
|
||||
easing.type: Easing.OutQuad
|
||||
ScrollBar.vertical: DankScrollbar {
|
||||
id: vbar
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ Item {
|
||||
property string placeholderText: "Search for a location..."
|
||||
property bool _internalChange: false
|
||||
property bool isLoading: false
|
||||
property string helperTextState: "default" // "default", "prompt", "searching", "found", "not_found"
|
||||
property string currentSearchText: ""
|
||||
|
||||
signal locationSelected(string displayName, string coordinates)
|
||||
@@ -21,10 +20,8 @@ Item {
|
||||
dropdownHideTimer.stop()
|
||||
if (locationSearcher.running)
|
||||
locationSearcher.running = false
|
||||
|
||||
isLoading = false
|
||||
searchResultsModel.clear()
|
||||
helperTextState = "default"
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
@@ -47,7 +44,6 @@ Item {
|
||||
|
||||
searchResultsModel.clear()
|
||||
root.isLoading = true
|
||||
root.helperTextState = "searching"
|
||||
const searchLocation = locationInput.text
|
||||
root.currentSearchText = searchLocation
|
||||
const encodedLocation = encodeURIComponent(searchLocation)
|
||||
@@ -79,7 +75,6 @@ Item {
|
||||
root.isLoading = false
|
||||
if (exitCode !== 0) {
|
||||
searchResultsModel.clear()
|
||||
root.helperTextState = "not_found"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,19 +87,16 @@ Item {
|
||||
root.isLoading = false
|
||||
searchResultsModel.clear()
|
||||
if (!raw || raw[0] !== "[") {
|
||||
root.helperTextState = "not_found"
|
||||
return
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(raw)
|
||||
if (data.length === 0) {
|
||||
root.helperTextState = "not_found"
|
||||
return
|
||||
}
|
||||
for (var i = 0; i < Math.min(data.length, 5); i++) {
|
||||
const location = data[i]
|
||||
if (location.display_name && location.lat
|
||||
&& location.lon) {
|
||||
if (location.display_name && location.lat && location.lon) {
|
||||
const parts = location.display_name.split(', ')
|
||||
let cleanName = parts[0]
|
||||
if (parts.length > 1) {
|
||||
@@ -119,9 +111,8 @@ Item {
|
||||
})
|
||||
}
|
||||
}
|
||||
root.helperTextState = "found"
|
||||
} catch (e) {
|
||||
root.helperTextState = "not_found"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,23 +138,18 @@ Item {
|
||||
onTextEdited: {
|
||||
if (root._internalChange)
|
||||
return
|
||||
|
||||
if (getActiveFocus()) {
|
||||
if (text.length > 2) {
|
||||
root.isLoading = true
|
||||
root.helperTextState = "searching"
|
||||
locationSearchTimer.restart()
|
||||
} else {
|
||||
root.resetSearchState()
|
||||
root.helperTextState = "prompt"
|
||||
}
|
||||
}
|
||||
}
|
||||
onFocusStateChanged: hasFocus => {
|
||||
if (hasFocus) {
|
||||
dropdownHideTimer.stop()
|
||||
if (text.length <= 2)
|
||||
root.helperTextState = "prompt"
|
||||
} else {
|
||||
dropdownHideTimer.start()
|
||||
}
|
||||
@@ -171,38 +157,13 @@ Item {
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
name: {
|
||||
if (root.isLoading)
|
||||
return "hourglass_empty"
|
||||
|
||||
if (searchResultsModel.count > 0)
|
||||
return "check_circle"
|
||||
|
||||
if (locationInput.getActiveFocus()
|
||||
&& locationInput.text.length > 2 && !root.isLoading)
|
||||
return "error"
|
||||
|
||||
return ""
|
||||
}
|
||||
name: root.isLoading ? "hourglass_empty" : (searchResultsModel.count > 0 ? "check_circle" : "error")
|
||||
size: Theme.iconSize - 4
|
||||
color: {
|
||||
if (root.isLoading)
|
||||
return Theme.surfaceVariantText
|
||||
|
||||
if (searchResultsModel.count > 0)
|
||||
return Theme.success || Theme.primary
|
||||
|
||||
if (locationInput.getActiveFocus()
|
||||
&& locationInput.text.length > 2)
|
||||
return Theme.error
|
||||
|
||||
return "transparent"
|
||||
}
|
||||
color: root.isLoading ? Theme.surfaceVariantText : (searchResultsModel.count > 0 ? Theme.primary : Theme.error)
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
opacity: (locationInput.getActiveFocus()
|
||||
&& locationInput.text.length > 2) ? 1 : 0
|
||||
opacity: (locationInput.getActiveFocus() && locationInput.text.length > 2) ? 1 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
@@ -219,17 +180,13 @@ Item {
|
||||
property bool hovered: false
|
||||
|
||||
width: parent.width
|
||||
height: Math.min(
|
||||
Math.max(
|
||||
searchResultsModel.count * 38 + Theme.spacingS * 2,
|
||||
50), 200)
|
||||
height: Math.min(Math.max(searchResultsModel.count * 38 + Theme.spacingS * 2, 50), 200)
|
||||
y: searchInputField.height
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.popupBackground()
|
||||
border.color: Theme.primarySelected
|
||||
border.width: 1
|
||||
visible: locationInput.getActiveFocus() && locationInput.text.length > 2
|
||||
&& (searchResultsModel.count > 0 || root.isLoading)
|
||||
visible: locationInput.getActiveFocus() && locationInput.text.length > 2 && (searchResultsModel.count > 0 || root.isLoading)
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
@@ -258,40 +215,6 @@ Item {
|
||||
model: searchResultsModel
|
||||
spacing: 2
|
||||
|
||||
// Qt 6.9+ scrolling: flickDeceleration/maximumFlickVelocity only affect touch now
|
||||
interactive: true
|
||||
flickDeceleration: 1500
|
||||
maximumFlickVelocity: 2000
|
||||
boundsBehavior: Flickable.DragAndOvershootBounds
|
||||
boundsMovement: Flickable.FollowBoundsBehavior
|
||||
pressDelay: 0
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
|
||||
// Custom wheel handler for Qt 6.9+ responsive mouse wheel scrolling
|
||||
WheelHandler {
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
|
||||
property real momentum: 0
|
||||
onWheel: event => {
|
||||
if (event.pixelDelta.y !== 0) {
|
||||
// Touchpad with pixel delta
|
||||
momentum = event.pixelDelta.y * 1.8
|
||||
} else {
|
||||
// Mouse wheel with angle delta
|
||||
momentum = (event.angleDelta.y / 120)
|
||||
* ((36 + parent.spacing) * 2.5) // ~2.5 items per wheel step
|
||||
}
|
||||
|
||||
let newY = parent.contentY - momentum
|
||||
newY = Math.max(
|
||||
0, Math.min(
|
||||
parent.contentHeight - parent.height,
|
||||
newY))
|
||||
parent.contentY = newY
|
||||
momentum *= 0.92 // Decay for smooth momentum
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
delegate: StyledRect {
|
||||
width: searchResultsList.width
|
||||
height: 36
|
||||
@@ -345,8 +268,7 @@ Item {
|
||||
text: root.isLoading ? "Searching..." : "No locations found"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceVariantText
|
||||
visible: searchResultsList.count === 0
|
||||
&& locationInput.text.length > 2
|
||||
visible: searchResultsList.count === 0 && locationInput.text.length > 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,28 +34,13 @@ PanelWindow {
|
||||
closeTimer.restart()
|
||||
}
|
||||
|
||||
function resetHideTimer() {
|
||||
if (shouldBeVisible && enableMouseInteraction) {
|
||||
// Only restart timer if we're not currently hovering
|
||||
let isHovered = (enableMouseInteraction && mouseArea.containsMouse) || osdContainer.childHovered
|
||||
if (!isHovered) {
|
||||
hideTimer.restart()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function stopHideTimer() {
|
||||
if (enableMouseInteraction)
|
||||
hideTimer.stop()
|
||||
}
|
||||
|
||||
function updateHoverState() {
|
||||
let isHovered = (enableMouseInteraction && mouseArea.containsMouse) || osdContainer.childHovered
|
||||
if (enableMouseInteraction) {
|
||||
if (isHovered) {
|
||||
stopHideTimer()
|
||||
hideTimer.stop()
|
||||
} else if (shouldBeVisible) {
|
||||
resetHideTimer()
|
||||
hideTimer.restart()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +70,7 @@ PanelWindow {
|
||||
interval: autoHideInterval
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
if (!enableMouseInteraction || !osdContainer.containsMouse) {
|
||||
if (!enableMouseInteraction || !mouseArea.containsMouse) {
|
||||
hide()
|
||||
} else {
|
||||
hideTimer.restart()
|
||||
@@ -107,7 +92,6 @@ PanelWindow {
|
||||
Rectangle {
|
||||
id: osdContainer
|
||||
|
||||
property bool containsMouse: enableMouseInteraction && mouseArea.containsMouse
|
||||
property bool childHovered: false
|
||||
|
||||
width: osdWidth
|
||||
@@ -130,15 +114,10 @@ PanelWindow {
|
||||
acceptedButtons: Qt.NoButton
|
||||
propagateComposedEvents: true
|
||||
z: -1
|
||||
|
||||
onContainsMouseChanged: {
|
||||
updateHoverState()
|
||||
}
|
||||
onContainsMouseChanged: updateHoverState()
|
||||
}
|
||||
|
||||
onChildHoveredChanged: {
|
||||
root.updateHoverState()
|
||||
}
|
||||
onChildHoveredChanged: updateHoverState()
|
||||
|
||||
Loader {
|
||||
id: contentLoader
|
||||
@@ -153,7 +132,6 @@ PanelWindow {
|
||||
shadowVerticalOffset: 4
|
||||
shadowBlur: 0.8
|
||||
shadowColor: Qt.rgba(0, 0, 0, 0.3)
|
||||
shadowOpacity: 0.3
|
||||
}
|
||||
|
||||
Behavior on opacity {
|
||||
@@ -174,4 +152,4 @@ PanelWindow {
|
||||
mask: Region {
|
||||
item: osdContainer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,11 +69,8 @@ PanelWindow {
|
||||
anchors.fill: parent
|
||||
enabled: shouldBeVisible
|
||||
onClicked: mouse => {
|
||||
var localPos = mapToItem(contentContainer,
|
||||
mouse.x, mouse.y)
|
||||
if (localPos.x < 0 || localPos.x > contentContainer.width
|
||||
|| localPos.y < 0
|
||||
|| localPos.y > contentContainer.height) {
|
||||
var localPos = mapToItem(contentContainer, mouse.x, mouse.y)
|
||||
if (localPos.x < 0 || localPos.x > contentContainer.width || localPos.y < 0 || localPos.y > contentContainer.height) {
|
||||
backgroundClicked()
|
||||
close()
|
||||
}
|
||||
@@ -88,23 +85,11 @@ PanelWindow {
|
||||
readonly property real calculatedX: {
|
||||
if (positioning === "center") {
|
||||
var centerX = triggerX + (triggerWidth / 2) - (popupWidth / 2)
|
||||
|
||||
if (centerX >= Theme.spacingM
|
||||
&& centerX + popupWidth <= screenWidth - Theme.spacingM)
|
||||
return centerX
|
||||
|
||||
if (centerX < Theme.spacingM)
|
||||
return Theme.spacingM
|
||||
|
||||
if (centerX + popupWidth > screenWidth - Theme.spacingM)
|
||||
return screenWidth - popupWidth - Theme.spacingM
|
||||
|
||||
return centerX
|
||||
return Math.max(Theme.spacingM, Math.min(screenWidth - popupWidth - Theme.spacingM, centerX))
|
||||
} else if (positioning === "left") {
|
||||
return Math.max(Theme.spacingM, triggerX)
|
||||
} else if (positioning === "right") {
|
||||
return Math.min(screenWidth - popupWidth - Theme.spacingM,
|
||||
triggerX + triggerWidth - popupWidth)
|
||||
return Math.min(screenWidth - popupWidth - Theme.spacingM, triggerX + triggerWidth - popupWidth)
|
||||
}
|
||||
return triggerX
|
||||
}
|
||||
@@ -141,25 +126,15 @@ PanelWindow {
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Escape) {
|
||||
close()
|
||||
event.accepted = true
|
||||
} else {
|
||||
event.accepted = false
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
forceActiveFocus()
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
forceActiveFocus()
|
||||
}
|
||||
}
|
||||
if (event.key === Qt.Key_Escape) {
|
||||
close()
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
Component.onCompleted: forceActiveFocus()
|
||||
onVisibleChanged: if (visible)
|
||||
forceActiveFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
Widgets/DankScrollbar.qml
Normal file
43
Widgets/DankScrollbar.qml
Normal file
@@ -0,0 +1,43 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
|
||||
ScrollBar {
|
||||
id: scrollbar
|
||||
|
||||
property bool _scrollBarActive: false
|
||||
property alias hideTimer: hideScrollBarTimer
|
||||
property bool _isParentMoving: parent && (parent.moving || parent.flicking || parent.isMomentumActive)
|
||||
property bool _shouldShow: pressed || hovered || active || _isParentMoving || _scrollBarActive
|
||||
|
||||
policy: (parent && parent.contentHeight > parent.height) ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
|
||||
minimumSize: 0.08
|
||||
implicitWidth: 10
|
||||
interactive: true
|
||||
hoverEnabled: true
|
||||
z: 1000
|
||||
opacity: (policy !== ScrollBar.AlwaysOff && _shouldShow) ? 1.0 : 0.0
|
||||
visible: policy !== ScrollBar.AlwaysOff
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: 160
|
||||
easing.type: Easing.OutQuad
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Rectangle {
|
||||
implicitWidth: 6
|
||||
radius: width / 2
|
||||
color: scrollbar.pressed ? Theme.primary : scrollbar._shouldShow ? Theme.outline : Theme.outlineMedium
|
||||
opacity: scrollbar.pressed ? 1.0 : scrollbar._shouldShow ? 1.0 : 0.6
|
||||
}
|
||||
|
||||
background: Item {}
|
||||
|
||||
Timer {
|
||||
id: hideScrollBarTimer
|
||||
interval: 1200
|
||||
onTriggered: scrollbar._scrollBarActive = false
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,15 @@ Item {
|
||||
|
||||
height: 40
|
||||
|
||||
function updateValueFromPosition(x) {
|
||||
let ratio = Math.max(0, Math.min(1, (x - sliderHandle.width / 2) / (sliderTrack.width - sliderHandle.width)))
|
||||
let newValue = Math.round(minimum + ratio * (maximum - minimum))
|
||||
if (newValue !== value) {
|
||||
value = newValue
|
||||
sliderValueChanged(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.centerIn: parent
|
||||
width: parent.width
|
||||
@@ -41,9 +50,7 @@ Item {
|
||||
property int leftIconWidth: slider.leftIcon.length > 0 ? Theme.iconSize : 0
|
||||
property int rightIconWidth: slider.rightIcon.length > 0 ? Theme.iconSize : 0
|
||||
|
||||
width: parent.width - (leftIconWidth + rightIconWidth
|
||||
+ (slider.leftIcon.length > 0 ? Theme.spacingM : 0)
|
||||
+ (slider.rightIcon.length > 0 ? Theme.spacingM : 0))
|
||||
width: parent.width - (leftIconWidth + rightIconWidth + (slider.leftIcon.length > 0 ? Theme.spacingM : 0) + (slider.rightIcon.length > 0 ? Theme.spacingM : 0))
|
||||
height: 6
|
||||
radius: 3
|
||||
color: slider.enabled ? Theme.surfaceVariantAlpha : Theme.surfaceLight
|
||||
@@ -52,9 +59,7 @@ Item {
|
||||
StyledRect {
|
||||
id: sliderFill
|
||||
|
||||
width: (parent.width - sliderHandle.width) * (
|
||||
(slider.value - slider.minimum) / (slider.maximum - slider.minimum)
|
||||
) + sliderHandle.width
|
||||
width: (parent.width - sliderHandle.width) * ((slider.value - slider.minimum) / (slider.maximum - slider.minimum)) + sliderHandle.width
|
||||
height: parent.height
|
||||
radius: parent.radius
|
||||
color: slider.enabled ? Theme.primary : Theme.surfaceVariantText
|
||||
@@ -74,15 +79,11 @@ Item {
|
||||
height: 18
|
||||
radius: 9
|
||||
color: slider.enabled ? Theme.primary : Theme.surfaceVariantText
|
||||
border.color: slider.enabled ? Qt.lighter(Theme.primary,
|
||||
1.3) : Qt.lighter(
|
||||
Theme.surfaceVariantText,
|
||||
1.3)
|
||||
border.color: slider.enabled ? Qt.lighter(Theme.primary, 1.3) : Qt.lighter(Theme.surfaceVariantText, 1.3)
|
||||
border.width: 2
|
||||
x: sliderFill.width - width
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
scale: sliderMouseArea.containsMouse
|
||||
|| sliderMouseArea.pressed ? 1.2 : 1
|
||||
scale: sliderMouseArea.containsMouse || sliderMouseArea.pressed ? 1.2 : 1
|
||||
|
||||
StyledRect {
|
||||
anchors.centerIn: parent
|
||||
@@ -107,8 +108,7 @@ Item {
|
||||
anchors.bottom: parent.top
|
||||
anchors.bottomMargin: Theme.spacingS
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: (sliderMouseArea.containsMouse && slider.showValue)
|
||||
|| (slider.isDragging && slider.showValue)
|
||||
visible: (sliderMouseArea.containsMouse && slider.showValue) || (slider.isDragging && slider.showValue)
|
||||
opacity: visible ? 1 : 0
|
||||
|
||||
StyledText {
|
||||
@@ -147,76 +147,32 @@ Item {
|
||||
id: sliderMouseArea
|
||||
|
||||
property bool isDragging: false
|
||||
property real scrollAccumulator: 0
|
||||
property real touchpadThreshold: 20
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: -10
|
||||
anchors.bottomMargin: -10
|
||||
hoverEnabled: true
|
||||
cursorShape: slider.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
enabled: slider.enabled
|
||||
preventStealing: true
|
||||
acceptedButtons: Qt.LeftButton
|
||||
onWheel: (wheelEvent) => {
|
||||
if (!slider.enabled || !slider.wheelEnabled) {
|
||||
wheelEvent.accepted = false
|
||||
return
|
||||
}
|
||||
|
||||
const deltaY = wheelEvent.angleDelta.y
|
||||
const isMouseWheel = Math.abs(deltaY) >= 120
|
||||
&& (Math.abs(deltaY) % 120) === 0
|
||||
|
||||
let currentValue = slider.value
|
||||
|
||||
if (isMouseWheel) {
|
||||
// Direct mouse wheel action - 5% steps
|
||||
let step = Math.max(1, (slider.maximum - slider.minimum) / 20)
|
||||
let newValue
|
||||
if (deltaY > 0)
|
||||
newValue = Math.min(slider.maximum, currentValue + step)
|
||||
else
|
||||
newValue = Math.max(slider.minimum, currentValue - step)
|
||||
newValue = Math.round(newValue)
|
||||
if (newValue !== slider.value) {
|
||||
slider.value = newValue
|
||||
slider.sliderValueChanged(newValue)
|
||||
}
|
||||
} else {
|
||||
// Touchpad - accumulate then apply 1% steps
|
||||
scrollAccumulator += deltaY
|
||||
|
||||
if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
|
||||
let step = Math.max(0.5, (slider.maximum - slider.minimum) / 100)
|
||||
let newValue
|
||||
if (scrollAccumulator > 0)
|
||||
newValue = Math.min(slider.maximum, currentValue + step)
|
||||
else
|
||||
newValue = Math.max(slider.minimum, currentValue - step)
|
||||
newValue = Math.round(newValue)
|
||||
if (newValue !== slider.value) {
|
||||
slider.value = newValue
|
||||
slider.sliderValueChanged(newValue)
|
||||
}
|
||||
scrollAccumulator = 0
|
||||
}
|
||||
}
|
||||
wheelEvent.accepted = true
|
||||
}
|
||||
onWheel: wheelEvent => {
|
||||
if (!slider.wheelEnabled)
|
||||
return
|
||||
let step = Math.max(1, (maximum - minimum) / 20)
|
||||
let newValue = wheelEvent.angleDelta.y > 0 ? Math.min(maximum, value + step) : Math.max(minimum, value - step)
|
||||
newValue = Math.round(newValue)
|
||||
if (newValue !== value) {
|
||||
value = newValue
|
||||
sliderValueChanged(newValue)
|
||||
}
|
||||
wheelEvent.accepted = true
|
||||
}
|
||||
onPressed: mouse => {
|
||||
if (slider.enabled) {
|
||||
slider.isDragging = true
|
||||
sliderMouseArea.isDragging = true
|
||||
let ratio = Math.max(
|
||||
0, Math.min(1, (
|
||||
mouse.x - sliderHandle.width / 2) / (
|
||||
width - sliderHandle.width)))
|
||||
let newValue = Math.round(
|
||||
slider.minimum + ratio
|
||||
* (slider.maximum - slider.minimum))
|
||||
slider.value = newValue
|
||||
slider.sliderValueChanged(newValue)
|
||||
updateValueFromPosition(mouse.x)
|
||||
}
|
||||
}
|
||||
onReleased: {
|
||||
@@ -227,68 +183,16 @@ Item {
|
||||
}
|
||||
}
|
||||
onPositionChanged: mouse => {
|
||||
if (pressed && slider.isDragging
|
||||
&& slider.enabled) {
|
||||
let ratio = Math.max(
|
||||
0, Math.min(1, (
|
||||
mouse.x - sliderHandle.width / 2) / (
|
||||
width - sliderHandle.width)))
|
||||
let newValue = Math.round(
|
||||
slider.minimum + ratio
|
||||
* (slider.maximum - slider.minimum))
|
||||
slider.value = newValue
|
||||
slider.sliderValueChanged(
|
||||
newValue)
|
||||
if (pressed && slider.isDragging && slider.enabled) {
|
||||
updateValueFromPosition(mouse.x)
|
||||
}
|
||||
}
|
||||
onClicked: mouse => {
|
||||
if (slider.enabled && !slider.isDragging) {
|
||||
let ratio = Math.max(
|
||||
0, Math.min(1, (
|
||||
mouse.x - sliderHandle.width / 2) / (
|
||||
width - sliderHandle.width)))
|
||||
let newValue = Math.round(
|
||||
slider.minimum + ratio
|
||||
* (slider.maximum - slider.minimum))
|
||||
slider.value = newValue
|
||||
slider.sliderValueChanged(newValue)
|
||||
updateValueFromPosition(mouse.x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: sliderGlobalMouseArea
|
||||
|
||||
anchors.fill: sliderContainer
|
||||
enabled: slider.isDragging
|
||||
visible: false
|
||||
preventStealing: true
|
||||
onPositionChanged: mouse => {
|
||||
if (slider.isDragging
|
||||
&& slider.enabled) {
|
||||
let globalPos = mapToItem(
|
||||
sliderTrack,
|
||||
mouse.x, mouse.y)
|
||||
let ratio = Math.max(
|
||||
0, Math.min(
|
||||
1,
|
||||
globalPos.x / sliderTrack.width))
|
||||
let newValue = Math.round(
|
||||
slider.minimum + ratio
|
||||
* (slider.maximum - slider.minimum))
|
||||
slider.value = newValue
|
||||
slider.sliderValueChanged(
|
||||
newValue)
|
||||
}
|
||||
}
|
||||
onReleased: {
|
||||
if (slider.isDragging && slider.enabled) {
|
||||
slider.isDragging = false
|
||||
sliderMouseArea.isDragging = false
|
||||
slider.sliderDragFinished(slider.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,19 +26,11 @@ Item {
|
||||
id: tabRepeater
|
||||
|
||||
Rectangle {
|
||||
property int tabCount: tabRepeater.count
|
||||
property bool isActive: tabBar.currentIndex === index
|
||||
property bool hasIcon: tabBar.showIcons && modelData
|
||||
&& ("icon" in modelData)
|
||||
&& modelData.icon
|
||||
&& modelData.icon.length > 0
|
||||
property bool hasText: modelData && ("text" in modelData)
|
||||
&& modelData.text
|
||||
&& modelData.text.length > 0
|
||||
property bool hasIcon: tabBar.showIcons && modelData && modelData.icon && modelData.icon.length > 0
|
||||
property bool hasText: modelData && modelData.text && modelData.text.length > 0
|
||||
|
||||
width: tabBar.equalWidthTabs ? (tabBar.width - tabBar.spacing * (tabCount - 1))
|
||||
/ tabCount : contentRow.implicitWidth
|
||||
+ Theme.spacingM * 2
|
||||
width: tabBar.equalWidthTabs ? (tabBar.width - tabBar.spacing * (tabRepeater.count - 1)) / tabRepeater.count : contentRow.implicitWidth + Theme.spacingM * 2
|
||||
height: tabBar.tabHeight
|
||||
radius: Theme.cornerRadius
|
||||
color: isActive ? Theme.primaryPressed : tabArea.containsMouse ? Theme.primaryHoverLight : "transparent"
|
||||
@@ -52,19 +44,19 @@ Item {
|
||||
DankIcon {
|
||||
name: modelData.icon || ""
|
||||
size: Theme.iconSize - 4
|
||||
color: parent.parent.isActive ? Theme.primary : Theme.surfaceText
|
||||
color: isActive ? Theme.primary : Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: parent.parent.hasIcon
|
||||
visible: hasIcon
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: modelData.text || ""
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: parent.parent.isActive ? Theme.primary : Theme.surfaceText
|
||||
font.weight: parent.parent.isActive ? Font.Medium : Font.Normal
|
||||
color: isActive ? Theme.primary : Theme.surfaceText
|
||||
font.weight: isActive ? Font.Medium : Font.Normal
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.verticalCenterOffset: 1
|
||||
visible: parent.parent.hasText
|
||||
visible: hasText
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,34 +10,24 @@ StyledRect {
|
||||
property string placeholderText: ""
|
||||
property alias font: textInput.font
|
||||
property alias textColor: textInput.color
|
||||
property alias selectByMouse: textInput.selectByMouse
|
||||
property alias enabled: textInput.enabled
|
||||
property alias echoMode: textInput.echoMode
|
||||
property alias verticalAlignment: textInput.verticalAlignment
|
||||
property alias cursorVisible: textInput.cursorVisible
|
||||
property alias readOnly: textInput.readOnly
|
||||
property alias validator: textInput.validator
|
||||
property alias inputMethodHints: textInput.inputMethodHints
|
||||
property alias maximumLength: textInput.maximumLength
|
||||
property string leftIconName: ""
|
||||
property int leftIconSize: Theme.iconSize
|
||||
property color leftIconColor: Theme.surfaceVariantText
|
||||
property color leftIconFocusedColor: Theme.primary
|
||||
property bool showClearButton: false
|
||||
property color backgroundColor: Qt.rgba(Theme.surfaceContainer.r,
|
||||
Theme.surfaceContainer.g,
|
||||
Theme.surfaceContainer.b, 0.9)
|
||||
property color backgroundColor: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 0.9)
|
||||
property color focusedBorderColor: Theme.primary
|
||||
property color normalBorderColor: Theme.outlineStrong
|
||||
property color placeholderColor: Theme.outlineButton
|
||||
property int borderWidth: 1
|
||||
property int focusedBorderWidth: 2
|
||||
property real cornerRadius: Theme.cornerRadius
|
||||
readonly property real leftPadding: Theme.spacingM
|
||||
+ (leftIconName ? leftIconSize + Theme.spacingM : 0)
|
||||
readonly property real rightPadding: Theme.spacingM + (showClearButton
|
||||
&& text.length
|
||||
> 0 ? 24 + Theme.spacingM : 0)
|
||||
readonly property real leftPadding: Theme.spacingM + (leftIconName ? leftIconSize + Theme.spacingM : 0)
|
||||
readonly property real rightPadding: Theme.spacingM + (showClearButton && text.length > 0 ? 24 + Theme.spacingM : 0)
|
||||
property real topPadding: Theme.spacingM
|
||||
property real bottomPadding: Theme.spacingM
|
||||
property bool ignoreLeftRightKeys: false
|
||||
@@ -51,47 +41,22 @@ StyledRect {
|
||||
function getActiveFocus() {
|
||||
return textInput.activeFocus
|
||||
}
|
||||
|
||||
function getFocus() {
|
||||
return textInput.focus
|
||||
}
|
||||
|
||||
function setFocus(value) {
|
||||
textInput.focus = value
|
||||
}
|
||||
|
||||
function forceActiveFocus() {
|
||||
textInput.forceActiveFocus()
|
||||
}
|
||||
|
||||
function selectAll() {
|
||||
textInput.selectAll()
|
||||
}
|
||||
|
||||
function clear() {
|
||||
textInput.clear()
|
||||
}
|
||||
|
||||
function paste() {
|
||||
textInput.paste()
|
||||
}
|
||||
|
||||
function copy() {
|
||||
textInput.copy()
|
||||
}
|
||||
|
||||
function cut() {
|
||||
textInput.cut()
|
||||
}
|
||||
|
||||
function insertText(str) {
|
||||
textInput.insert(textInput.cursorPosition, str)
|
||||
}
|
||||
|
||||
function clearFocus() {
|
||||
textInput.focus = false
|
||||
}
|
||||
|
||||
width: 200
|
||||
height: 48
|
||||
radius: cornerRadius
|
||||
@@ -129,14 +94,14 @@ StyledRect {
|
||||
onAccepted: root.accepted()
|
||||
onActiveFocusChanged: root.focusStateChanged(activeFocus)
|
||||
Keys.forwardTo: root.ignoreLeftRightKeys ? root.keyForwardTargets : []
|
||||
Keys.onLeftPressed: function (event) {
|
||||
if (root.ignoreLeftRightKeys)
|
||||
event.accepted = true
|
||||
}
|
||||
Keys.onRightPressed: function (event) {
|
||||
if (root.ignoreLeftRightKeys)
|
||||
event.accepted = true
|
||||
}
|
||||
Keys.onLeftPressed: event => {
|
||||
if (root.ignoreLeftRightKeys)
|
||||
event.accepted = true
|
||||
}
|
||||
Keys.onRightPressed: event => {
|
||||
if (root.ignoreLeftRightKeys)
|
||||
event.accepted = true
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
|
||||
@@ -15,43 +15,45 @@ Item {
|
||||
signal clicked
|
||||
signal toggled(bool checked)
|
||||
|
||||
width: (text && !hideText) ? parent.width : 48
|
||||
height: (text && !hideText) ? 60 : 24
|
||||
readonly property bool showText: text && !hideText
|
||||
|
||||
width: showText ? parent.width : 48
|
||||
height: showText ? 60 : 24
|
||||
|
||||
function handleClick() {
|
||||
if (!enabled) {
|
||||
return
|
||||
}
|
||||
checked = !checked
|
||||
clicked()
|
||||
toggled(checked)
|
||||
}
|
||||
|
||||
StyledRect {
|
||||
id: background
|
||||
|
||||
anchors.fill: parent
|
||||
radius: (toggle.text && !toggle.hideText) ? Theme.cornerRadius : 0
|
||||
color: (toggle.text
|
||||
&& !toggle.hideText) ? Theme.surfaceHover : "transparent"
|
||||
visible: (toggle.text && !toggle.hideText)
|
||||
radius: showText ? Theme.cornerRadius : 0
|
||||
color: showText ? Theme.surfaceHover : "transparent"
|
||||
visible: showText
|
||||
|
||||
StateLayer {
|
||||
visible: (toggle.text && !toggle.hideText)
|
||||
visible: showText
|
||||
disabled: !toggle.enabled
|
||||
stateColor: Theme.primary
|
||||
cornerRadius: parent.radius
|
||||
onClicked: {
|
||||
if (toggle.enabled) {
|
||||
toggle.checked = !toggle.checked
|
||||
toggle.clicked()
|
||||
toggle.toggled(toggle.checked)
|
||||
}
|
||||
}
|
||||
onClicked: toggle.handleClick()
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: textRow
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: toggleTrack.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.leftMargin: Theme.spacingM
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
spacing: Theme.spacingXS
|
||||
visible: (toggle.text && !toggle.hideText)
|
||||
visible: showText
|
||||
|
||||
Column {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
@@ -78,15 +80,14 @@ Item {
|
||||
StyledRect {
|
||||
id: toggleTrack
|
||||
|
||||
width: toggle.text ? 48 : parent.width
|
||||
height: toggle.text ? 24 : parent.height
|
||||
width: text ? 48 : parent.width
|
||||
height: text ? 24 : parent.height
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: toggle.text ? Theme.spacingM : 0
|
||||
anchors.rightMargin: text ? Theme.spacingM : 0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
radius: height / 2
|
||||
color: (toggle.checked
|
||||
&& toggle.enabled) ? Theme.primary : Theme.surfaceVariantAlpha
|
||||
opacity: toggle.toggling ? 0.6 : (toggle.enabled ? 1 : 0.4)
|
||||
color: (checked && enabled) ? Theme.primary : Theme.surfaceVariantAlpha
|
||||
opacity: toggling ? 0.6 : (enabled ? 1 : 0.4)
|
||||
|
||||
StyledRect {
|
||||
id: toggleHandle
|
||||
@@ -96,18 +97,9 @@ Item {
|
||||
radius: 10
|
||||
color: Theme.surface
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
x: (toggle.checked && toggle.enabled) ? parent.width - width - 2 : 2
|
||||
|
||||
StyledRect {
|
||||
anchors.centerIn: parent
|
||||
width: parent.width + 2
|
||||
height: parent.height + 2
|
||||
radius: (parent.width + 2) / 2
|
||||
color: "transparent"
|
||||
border.color: Qt.rgba(0, 0, 0, 0.1)
|
||||
border.width: 1
|
||||
z: -1
|
||||
}
|
||||
x: (checked && enabled) ? parent.width - width - 2 : 2
|
||||
border.color: Qt.rgba(0, 0, 0, 0.1)
|
||||
border.width: 1
|
||||
|
||||
Behavior on x {
|
||||
NumberAnimation {
|
||||
@@ -122,13 +114,7 @@ Item {
|
||||
disabled: !toggle.enabled
|
||||
stateColor: Theme.primary
|
||||
cornerRadius: parent.radius
|
||||
onClicked: {
|
||||
if (toggle.enabled) {
|
||||
toggle.checked = !toggle.checked
|
||||
toggle.clicked()
|
||||
toggle.toggled(toggle.checked)
|
||||
}
|
||||
}
|
||||
onClicked: toggle.handleClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,222 +0,0 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
import qs.Widgets
|
||||
|
||||
Popup {
|
||||
id: root
|
||||
|
||||
property var allWidgets: []
|
||||
property string targetSection: ""
|
||||
property bool isOpening: false
|
||||
|
||||
signal widgetSelected(string widgetId, string targetSection)
|
||||
|
||||
function safeOpen() {
|
||||
if (!isOpening && !visible) {
|
||||
isOpening = true
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
width: 400
|
||||
height: 450
|
||||
modal: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
onOpened: {
|
||||
isOpening = false
|
||||
}
|
||||
onClosed: {
|
||||
isOpening = false
|
||||
allWidgets = []
|
||||
targetSection = ""
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g,
|
||||
Theme.surfaceContainer.b, 1)
|
||||
border.color: Theme.primarySelected
|
||||
border.width: 1
|
||||
radius: Theme.cornerRadius
|
||||
}
|
||||
|
||||
contentItem: Item {
|
||||
anchors.fill: parent
|
||||
|
||||
DankActionButton {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 2
|
||||
iconColor: Theme.outline
|
||||
hoverColor: Theme.primaryContainer
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
onClicked: root.close()
|
||||
}
|
||||
|
||||
Column {
|
||||
id: contentColumn
|
||||
|
||||
spacing: Theme.spacingM
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingL
|
||||
anchors.topMargin: Theme.spacingL + 30 // Space for close button
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
|
||||
DankIcon {
|
||||
name: "add_circle"
|
||||
size: Theme.iconSize
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: "Add Widget to " + root.targetSection + " Section"
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: "Select a widget to add to the " + root.targetSection.toLowerCase(
|
||||
) + " section of the top bar. You can add multiple instances of the same widget if needed."
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.outline
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
width: parent.width
|
||||
height: parent.height - 120 // Leave space for header and description
|
||||
clip: true
|
||||
|
||||
DankListView {
|
||||
id: widgetList
|
||||
|
||||
spacing: Theme.spacingS
|
||||
model: root.allWidgets
|
||||
|
||||
// Qt 6.9+ scrolling: flickDeceleration/maximumFlickVelocity only affect touch now
|
||||
interactive: true
|
||||
flickDeceleration: 1500
|
||||
maximumFlickVelocity: 2000
|
||||
boundsBehavior: Flickable.DragAndOvershootBounds
|
||||
boundsMovement: Flickable.FollowBoundsBehavior
|
||||
pressDelay: 0
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
|
||||
// Custom wheel handler for Qt 6.9+ responsive mouse wheel scrolling
|
||||
WheelHandler {
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
|
||||
property real momentum: 0
|
||||
onWheel: event => {
|
||||
if (event.pixelDelta.y !== 0) {
|
||||
// Touchpad with pixel delta
|
||||
momentum = event.pixelDelta.y * 1.8
|
||||
} else {
|
||||
// Mouse wheel with angle delta
|
||||
momentum = (event.angleDelta.y / 120)
|
||||
* ((60 + parent.spacing)
|
||||
* 2.5) // ~2.5 items per wheel step
|
||||
}
|
||||
|
||||
let newY = parent.contentY - momentum
|
||||
newY = Math.max(
|
||||
0, Math.min(
|
||||
parent.contentHeight - parent.height,
|
||||
newY))
|
||||
parent.contentY = newY
|
||||
momentum *= 0.92 // Decay for smooth momentum
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: widgetList.width
|
||||
height: 60
|
||||
radius: Theme.cornerRadius
|
||||
color: widgetArea.containsMouse ? Theme.primaryHover : Qt.rgba(
|
||||
Theme.surfaceVariant.r,
|
||||
Theme.surfaceVariant.g,
|
||||
Theme.surfaceVariant.b,
|
||||
0.3)
|
||||
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g,
|
||||
Theme.outline.b, 0.2)
|
||||
border.width: 1
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingM
|
||||
spacing: Theme.spacingM
|
||||
|
||||
DankIcon {
|
||||
name: modelData.icon
|
||||
size: Theme.iconSize
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 2
|
||||
width: parent.width - Theme.iconSize - Theme.spacingM * 3
|
||||
|
||||
StyledText {
|
||||
text: modelData.text
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
elide: Text.ElideRight
|
||||
width: parent.width
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: modelData.description
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.outline
|
||||
elide: Text.ElideRight
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
name: "add"
|
||||
size: Theme.iconSize - 4
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: widgetArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.widgetSelected(modelData.id,
|
||||
root.targetSection)
|
||||
root.close()
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,22 @@
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
import qs.Widgets
|
||||
|
||||
MouseArea {
|
||||
id: root
|
||||
|
||||
property bool disabled: false
|
||||
property color stateColor: Theme.surfaceText
|
||||
property real cornerRadius: parent?.radius ?? Theme.cornerRadius
|
||||
property real cornerRadius: parent && parent.radius !== undefined ? parent.radius : Theme.cornerRadius
|
||||
|
||||
readonly property real stateOpacity: disabled ? 0 : pressed ? 0.12 : containsMouse ? 0.08 : 0
|
||||
|
||||
anchors.fill: parent
|
||||
cursorShape: disabled ? undefined : Qt.PointingHandCursor
|
||||
hoverEnabled: true
|
||||
|
||||
Rectangle {
|
||||
id: hoverLayer
|
||||
anchors.fill: parent
|
||||
radius: root.cornerRadius
|
||||
color: Qt.rgba(
|
||||
root.stateColor.r, root.stateColor.g, root.stateColor.b,
|
||||
root.disabled ? 0 : root.pressed ? 0.12 : root.containsMouse ? 0.08 : 0)
|
||||
color: Qt.rgba(stateColor.r, stateColor.g, stateColor.b, stateOpacity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,32 +2,36 @@ import QtQuick
|
||||
import qs.Common
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
color: "transparent"
|
||||
radius: Appearance.rounding.normal
|
||||
|
||||
readonly property var standardAnimation: {
|
||||
"duration": Appearance.anim.durations.normal,
|
||||
"easing.type": Easing.BezierSpline,
|
||||
"easing.bezierCurve": Appearance.anim.curves.standard
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Appearance.anim.durations.normal
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Appearance.anim.curves.standard
|
||||
duration: standardAnimation.duration
|
||||
easing.type: standardAnimation["easing.type"]
|
||||
easing.bezierCurve: standardAnimation["easing.bezierCurve"]
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on radius {
|
||||
NumberAnimation {
|
||||
duration: Appearance.anim.durations.normal
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Appearance.anim.curves.standard
|
||||
duration: standardAnimation.duration
|
||||
easing.type: standardAnimation["easing.type"]
|
||||
easing.bezierCurve: standardAnimation["easing.bezierCurve"]
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Appearance.anim.durations.normal
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Appearance.anim.curves.standard
|
||||
duration: standardAnimation.duration
|
||||
easing.type: standardAnimation["easing.type"]
|
||||
easing.bezierCurve: standardAnimation["easing.bezierCurve"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,22 +3,30 @@ import qs.Common
|
||||
import qs.Services
|
||||
|
||||
Text {
|
||||
id: root
|
||||
|
||||
property bool isMonospace: false
|
||||
|
||||
color: Theme.surfaceText
|
||||
font.pixelSize: Appearance.fontSize.normal
|
||||
font.family: {
|
||||
var requestedFont = isMonospace ? SettingsData.monoFontFamily : SettingsData.fontFamily
|
||||
var defaultFont = isMonospace ? SettingsData.defaultMonoFontFamily : SettingsData.defaultFontFamily
|
||||
readonly property string resolvedFontFamily: {
|
||||
const requestedFont = isMonospace ? SettingsData.monoFontFamily : SettingsData.fontFamily
|
||||
const defaultFont = isMonospace ? SettingsData.defaultMonoFontFamily : SettingsData.defaultFontFamily
|
||||
|
||||
if (requestedFont === defaultFont) {
|
||||
var availableFonts = Qt.fontFamilies()
|
||||
if (!availableFonts.includes(requestedFont))
|
||||
const availableFonts = Qt.fontFamilies()
|
||||
if (!availableFonts.includes(requestedFont)) {
|
||||
return isMonospace ? "Monospace" : "DejaVu Sans"
|
||||
}
|
||||
}
|
||||
return requestedFont
|
||||
}
|
||||
|
||||
readonly property var standardAnimation: {
|
||||
"duration": Appearance.anim.durations.normal,
|
||||
"easing.type": Easing.BezierSpline,
|
||||
"easing.bezierCurve": Appearance.anim.curves.standard
|
||||
}
|
||||
|
||||
color: Theme.surfaceText
|
||||
font.pixelSize: Appearance.fontSize.normal
|
||||
font.family: resolvedFontFamily
|
||||
font.weight: SettingsData.fontWeight
|
||||
wrapMode: Text.WordWrap
|
||||
elide: Text.ElideRight
|
||||
@@ -27,17 +35,17 @@ Text {
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Appearance.anim.durations.normal
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Appearance.anim.curves.standard
|
||||
duration: standardAnimation.duration
|
||||
easing.type: standardAnimation["easing.type"]
|
||||
easing.bezierCurve: standardAnimation["easing.bezierCurve"]
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Appearance.anim.durations.normal
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Appearance.anim.curves.standard
|
||||
duration: standardAnimation.duration
|
||||
easing.type: standardAnimation["easing.type"]
|
||||
easing.bezierCurve: standardAnimation["easing.bezierCurve"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ import Quickshell.Widgets
|
||||
import qs.Common
|
||||
|
||||
IconImage {
|
||||
id: root
|
||||
|
||||
property string colorOverride: ""
|
||||
property real brightnessOverride: 0.5
|
||||
property real contrastOverride: 1
|
||||
|
||||
readonly property bool hasColorOverride: colorOverride !== ""
|
||||
|
||||
smooth: true
|
||||
asynchronous: true
|
||||
layer.enabled: colorOverride !== ""
|
||||
layer.enabled: hasColorOverride
|
||||
|
||||
Process {
|
||||
running: true
|
||||
@@ -22,8 +22,7 @@ IconImage {
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: () => {
|
||||
root.source = Quickshell.iconPath(
|
||||
this.text.trim(), true)
|
||||
source = Quickshell.iconPath(text.trim(), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user