diff -Nru ukui-panel-3.14.0.1/.git/FETCH_HEAD ukui-panel-4.0.0.0/.git/FETCH_HEAD --- ukui-panel-3.14.0.1/.git/FETCH_HEAD 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/FETCH_HEAD 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1 @@ +c15cf3214ee2a4d81495316577d13a3167338536 branch 'dev-openkylin' of http://172.29.221.223:3000/openkylin/ukui-panel-openkylin diff -Nru ukui-panel-3.14.0.1/.git/HEAD ukui-panel-4.0.0.0/.git/HEAD --- ukui-panel-3.14.0.1/.git/HEAD 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/HEAD 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1 @@ +ref: refs/heads/dev-openkylin diff -Nru ukui-panel-3.14.0.1/.git/ORIG_HEAD ukui-panel-4.0.0.0/.git/ORIG_HEAD --- ukui-panel-3.14.0.1/.git/ORIG_HEAD 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/ORIG_HEAD 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1 @@ +c9a5d00b6ce951db667c242a0debb465e6044ccb diff -Nru ukui-panel-3.14.0.1/.git/config ukui-panel-4.0.0.0/.git/config --- ukui-panel-3.14.0.1/.git/config 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/config 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1,14 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true +[remote "origin"] + url = http://172.29.221.223:3000/openkylin/ukui-panel-openkylin.git + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "main"] + remote = origin + merge = refs/heads/main +[branch "dev-openkylin"] + remote = origin + merge = refs/heads/dev-openkylin diff -Nru ukui-panel-3.14.0.1/.git/description ukui-panel-4.0.0.0/.git/description --- ukui-panel-3.14.0.1/.git/description 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/description 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff -Nru ukui-panel-3.14.0.1/.git/hooks/applypatch-msg.sample ukui-panel-4.0.0.0/.git/hooks/applypatch-msg.sample --- ukui-panel-3.14.0.1/.git/hooks/applypatch-msg.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/applypatch-msg.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff -Nru ukui-panel-3.14.0.1/.git/hooks/commit-msg.sample ukui-panel-4.0.0.0/.git/hooks/commit-msg.sample --- ukui-panel-3.14.0.1/.git/hooks/commit-msg.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/commit-msg.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff -Nru ukui-panel-3.14.0.1/.git/hooks/fsmonitor-watchman.sample ukui-panel-4.0.0.0/.git/hooks/fsmonitor-watchman.sample --- ukui-panel-3.14.0.1/.git/hooks/fsmonitor-watchman.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/fsmonitor-watchman.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,109 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 1) and a time in nanoseconds +# formatted as a string and outputs to stdout all files that have been +# modified since the given time. Paths must be relative to the root of +# the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $time) = @ARGV; + +# Check the hook interface version + +if ($version == 1) { + # convert nanoseconds to seconds + # subtract one second to make sure watchman will return all changes + $time = int ($time / 1000000000) - 1; +} else { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree; +if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $git_work_tree = Win32::GetCwd(); + $git_work_tree =~ tr/\\/\//; +} else { + require Cwd; + $git_work_tree = Cwd::cwd(); +} + +my $retry = 1; + +launch_watchman(); + +sub launch_watchman { + + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $time but were not transient (ie created after + # $time but no longer exist). + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. + + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $time, + "fields": ["name"] + }] + END + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; <CHLD_OUT>}; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + my $json_pkg; + eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; + } or do { + require JSON::PP; + $json_pkg = "JSON::PP"; + }; + + my $o = $json_pkg->new->utf8->decode($response); + + if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { + print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; + $retry--; + qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + print "/\0"; + eval { launch_watchman() }; + exit 0; + } + + die "Watchman: $o->{error}.\n" . + "Falling back to scanning...\n" if $o->{error}; + + binmode STDOUT, ":utf8"; + local $, = "\0"; + print @{$o->{files}}; +} diff -Nru ukui-panel-3.14.0.1/.git/hooks/post-update.sample ukui-panel-4.0.0.0/.git/hooks/post-update.sample --- ukui-panel-3.14.0.1/.git/hooks/post-update.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/post-update.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff -Nru ukui-panel-3.14.0.1/.git/hooks/pre-applypatch.sample ukui-panel-4.0.0.0/.git/hooks/pre-applypatch.sample --- ukui-panel-3.14.0.1/.git/hooks/pre-applypatch.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/pre-applypatch.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff -Nru ukui-panel-3.14.0.1/.git/hooks/pre-commit.sample ukui-panel-4.0.0.0/.git/hooks/pre-commit.sample --- ukui-panel-3.14.0.1/.git/hooks/pre-commit.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/pre-commit.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff -Nru ukui-panel-3.14.0.1/.git/hooks/pre-merge-commit.sample ukui-panel-4.0.0.0/.git/hooks/pre-merge-commit.sample --- ukui-panel-3.14.0.1/.git/hooks/pre-merge-commit.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/pre-merge-commit.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,13 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git merge" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message to +# stderr if it wants to stop the merge commit. +# +# To enable this hook, rename this file to "pre-merge-commit". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: diff -Nru ukui-panel-3.14.0.1/.git/hooks/pre-push.sample ukui-panel-4.0.0.0/.git/hooks/pre-push.sample --- ukui-panel-3.14.0.1/.git/hooks/pre-push.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/pre-push.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# <local ref> <local sha1> <remote ref> <remote sha1> +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff -Nru ukui-panel-3.14.0.1/.git/hooks/pre-rebase.sample ukui-panel-4.0.0.0/.git/hooks/pre-rebase.sample --- ukui-panel-3.14.0.1/.git/hooks/pre-rebase.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/pre-rebase.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff -Nru ukui-panel-3.14.0.1/.git/hooks/pre-receive.sample ukui-panel-4.0.0.0/.git/hooks/pre-receive.sample --- ukui-panel-3.14.0.1/.git/hooks/pre-receive.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/pre-receive.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff -Nru ukui-panel-3.14.0.1/.git/hooks/prepare-commit-msg.sample ukui-panel-4.0.0.0/.git/hooks/prepare-commit-msg.sample --- ukui-panel-3.14.0.1/.git/hooks/prepare-commit-msg.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/prepare-commit-msg.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff -Nru ukui-panel-3.14.0.1/.git/hooks/update.sample ukui-panel-4.0.0.0/.git/hooks/update.sample --- ukui-panel-3.14.0.1/.git/hooks/update.sample 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/hooks/update.sample 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 <ref> <oldrev> <newrev>)" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 <ref> <oldrev> <newrev>" >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +denycreatebranch=$(git config --bool hooks.denycreatebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero="0000000000000000000000000000000000000000" +if [ "$newrev" = "$zero" ]; then + newrev_type=delete +else + newrev_type=$(git cat-file -t $newrev) +fi + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annotated tag + short_refname=${refname##refs/tags/} + if [ "$allowunannotated" != "true" ]; then + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/index and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/index differ diff -Nru ukui-panel-3.14.0.1/.git/info/exclude ukui-panel-4.0.0.0/.git/info/exclude --- ukui-panel-3.14.0.1/.git/info/exclude 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/info/exclude 2023-05-22 14:06:05.000000000 +0800 @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff -Nru ukui-panel-3.14.0.1/.git/logs/HEAD ukui-panel-4.0.0.0/.git/logs/HEAD --- ukui-panel-3.14.0.1/.git/logs/HEAD 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/logs/HEAD 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1,3 @@ +0000000000000000000000000000000000000000 7ae06bd129bf89ea8290b21c9adb3f19d44b3e85 duhongfei <duhongfei@kylinos.cn> 1684735570 +0800 clone: from http://172.29.221.223:3000/openkylin/ukui-panel-openkylin.git +7ae06bd129bf89ea8290b21c9adb3f19d44b3e85 c9a5d00b6ce951db667c242a0debb465e6044ccb root <root@kylinos.(none)> 1684845398 +0800 checkout: moving from main to dev-openkylin +c9a5d00b6ce951db667c242a0debb465e6044ccb c15cf3214ee2a4d81495316577d13a3167338536 kylin <kylin@kylin-vmware71.(none)> 1685948826 +0800 pull origin dev-openkylin: Fast-forward diff -Nru ukui-panel-3.14.0.1/.git/logs/refs/heads/dev-openkylin ukui-panel-4.0.0.0/.git/logs/refs/heads/dev-openkylin --- ukui-panel-3.14.0.1/.git/logs/refs/heads/dev-openkylin 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/logs/refs/heads/dev-openkylin 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 c9a5d00b6ce951db667c242a0debb465e6044ccb root <root@kylinos.(none)> 1684845398 +0800 branch: Created from origin/dev-openkylin +c9a5d00b6ce951db667c242a0debb465e6044ccb c15cf3214ee2a4d81495316577d13a3167338536 kylin <kylin@kylin-vmware71.(none)> 1685948826 +0800 pull origin dev-openkylin: Fast-forward diff -Nru ukui-panel-3.14.0.1/.git/logs/refs/heads/main ukui-panel-4.0.0.0/.git/logs/refs/heads/main --- ukui-panel-3.14.0.1/.git/logs/refs/heads/main 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/logs/refs/heads/main 2023-05-22 14:06:10.000000000 +0800 @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 7ae06bd129bf89ea8290b21c9adb3f19d44b3e85 duhongfei <duhongfei@kylinos.cn> 1684735570 +0800 clone: from http://172.29.221.223:3000/openkylin/ukui-panel-openkylin.git diff -Nru ukui-panel-3.14.0.1/.git/logs/refs/remotes/origin/HEAD ukui-panel-4.0.0.0/.git/logs/refs/remotes/origin/HEAD --- ukui-panel-3.14.0.1/.git/logs/refs/remotes/origin/HEAD 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/logs/refs/remotes/origin/HEAD 2023-05-22 14:06:10.000000000 +0800 @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 7ae06bd129bf89ea8290b21c9adb3f19d44b3e85 duhongfei <duhongfei@kylinos.cn> 1684735570 +0800 clone: from http://172.29.221.223:3000/openkylin/ukui-panel-openkylin.git diff -Nru ukui-panel-3.14.0.1/.git/logs/refs/remotes/origin/dev-openkylin ukui-panel-4.0.0.0/.git/logs/refs/remotes/origin/dev-openkylin --- ukui-panel-3.14.0.1/.git/logs/refs/remotes/origin/dev-openkylin 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/logs/refs/remotes/origin/dev-openkylin 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 c9a5d00b6ce951db667c242a0debb465e6044ccb root <root@kylinos.(none)> 1684845328 +0800 pull origin: storing head +c9a5d00b6ce951db667c242a0debb465e6044ccb c15cf3214ee2a4d81495316577d13a3167338536 kylin <kylin@kylin-vmware71.(none)> 1685948826 +0800 pull origin dev-openkylin: fast-forward Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/02/0ac70d8fb9acb5424d80d98205a9a32144771d and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/02/0ac70d8fb9acb5424d80d98205a9a32144771d differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/19/435c59230288c9ddaecbb2c54c183b2e4e88bd and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/19/435c59230288c9ddaecbb2c54c183b2e4e88bd differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/74/42a129feea09da267c52cd4a3616cacb9b7b67 and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/74/42a129feea09da267c52cd4a3616cacb9b7b67 differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/74/b5f31e9192d7fd72600f072bca6b820f9a268e and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/74/b5f31e9192d7fd72600f072bca6b820f9a268e differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/7b/7b503e679d103f229476b4ad2079b45d7e847c and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/7b/7b503e679d103f229476b4ad2079b45d7e847c differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/93/17a8c570e71a7e36d2c17f9ae8f9c610b8bd70 and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/93/17a8c570e71a7e36d2c17f9ae8f9c610b8bd70 differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/9e/bfedc0cc5731d2f5602526c2d19506ee8cded6 and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/9e/bfedc0cc5731d2f5602526c2d19506ee8cded6 differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/c1/5cf3214ee2a4d81495316577d13a3167338536 and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/c1/5cf3214ee2a4d81495316577d13a3167338536 differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/pack/pack-0affc60ff4aa856194ce09fee0ee0442d0495ddc.idx and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/pack/pack-0affc60ff4aa856194ce09fee0ee0442d0495ddc.idx differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/pack/pack-0affc60ff4aa856194ce09fee0ee0442d0495ddc.pack and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/pack/pack-0affc60ff4aa856194ce09fee0ee0442d0495ddc.pack differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/pack/pack-6e663a91086d6e33514d80480593161a5e1f30e4.idx and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/pack/pack-6e663a91086d6e33514d80480593161a5e1f30e4.idx differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/.git/objects/pack/pack-6e663a91086d6e33514d80480593161a5e1f30e4.pack and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/.git/objects/pack/pack-6e663a91086d6e33514d80480593161a5e1f30e4.pack differ diff -Nru ukui-panel-3.14.0.1/.git/packed-refs ukui-panel-4.0.0.0/.git/packed-refs --- ukui-panel-3.14.0.1/.git/packed-refs 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/packed-refs 2023-05-22 14:06:10.000000000 +0800 @@ -0,0 +1,2 @@ +# pack-refs with: peeled fully-peeled sorted +7ae06bd129bf89ea8290b21c9adb3f19d44b3e85 refs/remotes/origin/main diff -Nru ukui-panel-3.14.0.1/.git/refs/heads/dev-openkylin ukui-panel-4.0.0.0/.git/refs/heads/dev-openkylin --- ukui-panel-3.14.0.1/.git/refs/heads/dev-openkylin 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/refs/heads/dev-openkylin 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1 @@ +c15cf3214ee2a4d81495316577d13a3167338536 diff -Nru ukui-panel-3.14.0.1/.git/refs/heads/main ukui-panel-4.0.0.0/.git/refs/heads/main --- ukui-panel-3.14.0.1/.git/refs/heads/main 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/refs/heads/main 2023-05-22 14:06:10.000000000 +0800 @@ -0,0 +1 @@ +7ae06bd129bf89ea8290b21c9adb3f19d44b3e85 diff -Nru ukui-panel-3.14.0.1/.git/refs/remotes/origin/HEAD ukui-panel-4.0.0.0/.git/refs/remotes/origin/HEAD --- ukui-panel-3.14.0.1/.git/refs/remotes/origin/HEAD 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/refs/remotes/origin/HEAD 2023-05-22 14:06:10.000000000 +0800 @@ -0,0 +1 @@ +ref: refs/remotes/origin/main diff -Nru ukui-panel-3.14.0.1/.git/refs/remotes/origin/dev-openkylin ukui-panel-4.0.0.0/.git/refs/remotes/origin/dev-openkylin --- ukui-panel-3.14.0.1/.git/refs/remotes/origin/dev-openkylin 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/.git/refs/remotes/origin/dev-openkylin 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1 @@ +c15cf3214ee2a4d81495316577d13a3167338536 diff -Nru ukui-panel-3.14.0.1/CMakeLists.txt ukui-panel-4.0.0.0/CMakeLists.txt --- ukui-panel-3.14.0.1/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/CMakeLists.txt 2023-05-23 15:58:00.000000000 +0800 @@ -35,16 +35,11 @@ set(UKUI_MINIMUM_VERSION "0.14.1") set(QTXDG_MINIMUM_VERSION "3.3.1") -find_package(Qt5DBus ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5LinguistTools ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5Widgets ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5X11Extras ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5Xml ${REQUIRED_QT_VERSION} REQUIRED) find_package(KF5WindowSystem ${KF5_MINIMUM_VERSION} REQUIRED) -find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets DBus X11Extras LinguistTools) +find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets Core QuickWidgets DBus X11Extras LinguistTools Xml) find_package(Qt5Xdg ${QTXDG_MINIMUM_VERSION} REQUIRED) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Quick REQUIRED) find_package(X11 REQUIRED) -find_package(Qt5LinguistTools) find_package(PkgConfig) pkg_check_modules(Gsetting REQUIRED gsettings-qt) @@ -128,8 +123,6 @@ add_subdirectory(plugin-taskbar) endif() -add_subdirectory(ukui-flash-disk) -#add_subdirectory(ukui-calendar) add_subdirectory(panel-daemon) add_subdirectory(sni-daemon) add_subdirectory(sni-xembed-proxy) @@ -156,12 +149,6 @@ add_subdirectory(plugin-calendar) endif(CALENDAR_PLUGIN) -setByDefault(NIGHTMODE_PLUGIN Yes) -if(NIGHTMODE_PLUGIN) - list(APPEND ENABLED_PLUGINS "nightmode") - add_subdirectory(plugin-nightmode) -endif(NIGHTMODE_PLUGIN) - setByDefault(STARTBAR_PLUGIN Yes) if(STARTBAR_PLUGIN) list(APPEND ENABLED_PLUGINS "startbar") diff -Nru ukui-panel-3.14.0.1/README.md ukui-panel-4.0.0.0/README.md --- ukui-panel-3.14.0.1/README.md 2022-05-09 17:44:07.000000000 +0800 +++ ukui-panel-4.0.0.0/README.md 2023-05-22 14:06:10.000000000 +0800 @@ -15,7 +15,6 @@ * taskbar * statusnotifier * calendar - * nightmode * showdesktop ... ## Getting Started diff -Nru ukui-panel-3.14.0.1/debian/changelog ukui-panel-4.0.0.0/debian/changelog --- ukui-panel-3.14.0.1/debian/changelog 2023-01-06 11:34:29.000000000 +0800 +++ ukui-panel-4.0.0.0/debian/changelog 2023-05-23 15:58:00.000000000 +0800 @@ -1,3 +1,56 @@ +ukui-panel (4.0.0.0-ok0.5e01) yangtze; urgency=medium + + * 1.修改任务栏点击开始菜单的启动,任务栏阅览界面的以列表式,并修复会遮挡的bug + * 2.默认关闭显示任务视图按钮 + * 3.去除panel部分插件-showdesktop + + -- duhongfei <duhongfei@kylinos.cn> Tue, 23 May 2023 15:58:00 +0800 + +ukui-panel (4.0.0.0-ok0.5) yangtze; urgency=medium + + * BUG: I69TB2 修改分辨率任务栏位置显示的不对 + * 需求:无 + * 其他改动:无 + + -- buxiaoqing <buxiaoqing@kylinos.cn> Fri, 05 May 2023 18:35:39 +0800 + +ukui-panel (4.0.0.0-ok0.3) yangtze; urgency=medium + + * BUG:无 + * 需求:无 + * 其他改动:修复悬浮预览窗偶先崩溃问题 + + -- buxiaoqing <buxiaoqing@kylinos.cn> Mon, 17 Apr 2023 17:25:18 +0800 + +ukui-panel (4.0.0.0-ok0.2) yangtze; urgency=medium + + * BUG:无 + * 需求:无 + * 其他改动:修复升级任务栏版本后配置文件没有被安装问题 + + -- buxiaoqing <buxiaoqing@kylinos.cn> Sat, 15 Apr 2023 14:19:24 +0800 + +ukui-panel (4.0.0.0-ok0.1) yangtze; urgency=medium + + * 解决编译依赖问题 + + -- buxiaoqing <buxiaoqing@kylinos.cn> Thu, 13 Apr 2023 17:47:18 +0800 + +ukui-panel (4.0.0.0-ok0.0build1) yangtze; urgency=medium + + * 版本号升级到4.0.0.0 + + -- buxiaoqing <buxiaoqing@kylinos.cn> Thu, 13 Apr 2023 16:28:49 +0800 + +ukui-panel (3.14.0.1-ok3.4) yangtze; urgency=medium + + * BUG:#130885 触摸长安容易同时出现日历和右键菜单 + 需求:无 + 其他改动: + 其他改动说明: + + -- zhangyinjie <zhangyinjie@kylinos.cn> Mon, 16 Jan 2023 16:53:40 +0800 + ukui-panel (3.14.0.1-ok3.3) yangtze; urgency=medium * fix position error bug diff -Nru ukui-panel-3.14.0.1/debian/control ukui-panel-4.0.0.0/debian/control --- ukui-panel-3.14.0.1/debian/control 2023-01-06 11:34:29.000000000 +0800 +++ ukui-panel-4.0.0.0/debian/control 2023-05-23 15:58:00.000000000 +0800 @@ -39,6 +39,7 @@ libkysdk-waylandhelper-dev, libukui-common-dev, libkysdk-qtwidgets-dev, + qtdeclarative5-dev, libkf5screen-dev Standards-Version: 4.5.0 Rules-Requires-Root: no diff -Nru ukui-panel-3.14.0.1/debian/patches/0035-43-Fix-130885.patch ukui-panel-4.0.0.0/debian/patches/0035-43-Fix-130885.patch --- ukui-panel-3.14.0.1/debian/patches/0035-43-Fix-130885.patch 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/debian/patches/0035-43-Fix-130885.patch 2023-05-23 15:58:00.000000000 +0800 @@ -0,0 +1,37 @@ +From: =?utf-8?b?5L2V5py05bCn?= <18373370753@163.com> +Date: Wed, 8 Feb 2023 01:37:39 +0000 +Subject: =?utf-8?b?ITQzICpGaXg6IzEzMDg4NSDop6bmkbjplb/lronlrrnmmJPlkIzml7Y=?= + =?utf-8?b?5Ye6546w5pel5Y6G5ZKM5Y+z6ZSu6I+c5Y2VIE1lcmdlIHB1bGwgcmVxdWVzdCAh?= + =?utf-8?b?NDMgZnJvbSB6aGFuZ3lpbmppZS9vcGVua3lsaW4veWFuZ3R6ZQ==?= + +--- + plugin-calendar/ukuicalendar.cpp | 2 +- + plugin-calendar/ukuicalendar.h | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/plugin-calendar/ukuicalendar.cpp b/plugin-calendar/ukuicalendar.cpp +index baa8915..0b30a49 100644 +--- a/plugin-calendar/ukuicalendar.cpp ++++ b/plugin-calendar/ukuicalendar.cpp +@@ -636,7 +636,7 @@ CalendarActiveLabel::CalendarActiveLabel(IUKUIPanelPlugin *plugin, QWidget *pare + QTimer::singleShot(1000,[this] {setToolTip(tr("Time and Date")); }); + } + +-void CalendarActiveLabel::mousePressEvent(QMouseEvent *event) ++void CalendarActiveLabel::mouseReleaseEvent(QMouseEvent *event) + { + if (Qt::LeftButton == event->button()){ + if(calendar_version == "old"){ +diff --git a/plugin-calendar/ukuicalendar.h b/plugin-calendar/ukuicalendar.h +index 88d7148..299d707 100644 +--- a/plugin-calendar/ukuicalendar.h ++++ b/plugin-calendar/ukuicalendar.h +@@ -136,7 +136,7 @@ protected: + * @param event + */ + virtual void contextMenuEvent(QContextMenuEvent *event); +- void mousePressEvent(QMouseEvent *event); ++ void mouseReleaseEvent(QMouseEvent *event); + private: + frmLunarCalendarWidget *w; + QDBusInterface *mInterface; diff -Nru ukui-panel-3.14.0.1/debian/patches/series ukui-panel-4.0.0.0/debian/patches/series --- ukui-panel-3.14.0.1/debian/patches/series 2023-01-06 11:34:29.000000000 +0800 +++ ukui-panel-4.0.0.0/debian/patches/series 1970-01-01 08:00:00.000000000 +0800 @@ -1,34 +0,0 @@ -0001-1-wayland.patch -0002-2-quicklaunch.patch -0003-3.patch -0004-SDK.patch -0005-6-BUG-125493.patch -0006-7-wayland.patch -0007-8.patch -0008-10-Merge-pull-request-10-from-openkylin-yangtze.patch -0009-AppManager.patch -0010-4-wayland-desktop.patch -0011-9-wayland.patch -0012-Fix-125312.patch -0013-Fix-upstream.patch -0014-15-upstream-widget-upstream-widget-AppManager.patch -0015-.patch -0016-changelog-BUG.patch -0017-build-debian-changelog.patch -0018-18-fixbug-wayland-U.patch -0019-SDK-workaround-BUG-125354.patch -0020-22-taskbar.patch -0021-23.patch -0022-24.patch -0023-26.patch -0024-27.patch -0025-29-x86-bug-130312-SDK.patch -0026-30.patch -0027-31.patch -0028-32.patch -0029-ukui-flash-disk.patch -0030-.patch -0031-38.patch -0032-build-debian-Changelog.patch -0033-.patch -0034-42-DBus.patch diff -Nru ukui-panel-3.14.0.1/debian/source/format ukui-panel-4.0.0.0/debian/source/format --- ukui-panel-3.14.0.1/debian/source/format 2023-01-06 11:34:29.000000000 +0800 +++ ukui-panel-4.0.0.0/debian/source/format 2023-05-22 14:06:10.000000000 +0800 @@ -1 +1 @@ -3.0 (quilt) +3.0 (native) diff -Nru ukui-panel-3.14.0.1/doc/changlog.txt ukui-panel-4.0.0.0/doc/changlog.txt --- ukui-panel-3.14.0.1/doc/changlog.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/doc/changlog.txt 1970-01-01 08:00:00.000000000 +0800 @@ -1,24 +0,0 @@ -+ukui-panel (3.0.1-42) v101; urgency=medium -+ -+ * 更新任务栏高分屏适配代码 Link#28059 -+ 提供给输入法显示toolTips的相关接口 Link #20236 -+ 点击快速启动栏打开应用改为gio的方式加载 Link #24172 -+ 解决任务栏注释出现的段错误问题 Link #29586 -+ -+ -- hepuyao <hepuyao@kylinos.cn> Thu, 24 Dec 2020 15:10:02 +0800 -+ -+ukui-panel (3.0.1-40~1224) v101; urgency=medium -+ -+ * 解决u盘图标不消失的问题 -+ -+ -- hepuyao <hepuyao@kylinos.cn> Fri, 11 Dec 2020 13:49:52 +0800 -+ -+ukui-panel (3.0.1-39) v101; urgency=medium -+ -+ * 任务栏判断配置文件异常 -+ 解决翻译文件“睡眠”和“休眠”统一 #27572 -+ 任务栏托盘图标高亮逻辑优化 #22328 -+ 修改判断右键是否需要添加系统监视器的接口 -+ -+ -- hepuyao <hepuyao@kylinos.cn> Thu, 10 Dec 2020 20:25:05 +0800 - diff -Nru ukui-panel-3.14.0.1/doc/studyLink ukui-panel-4.0.0.0/doc/studyLink --- ukui-panel-3.14.0.1/doc/studyLink 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/doc/studyLink 1970-01-01 08:00:00.000000000 +0800 @@ -1,6 +0,0 @@ -Qt拖放(1):拖放基本原理(QDrag类) - https://blog.csdn.net/hyongilfmmm/article/details/83238239 -QT---之Q_D和d指针概念2 - https://blog.csdn.net/weixin_39609623/article/details/83152662 -Qt中使用Q指针和D指针 - https://blog.csdn.net/u013399898/article/details/83930426 Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/doc/ukui-panel-Requirements-Document.doc and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/doc/ukui-panel-Requirements-Document.doc differ diff -Nru ukui-panel-3.14.0.1/panel/CMakeLists.txt ukui-panel-4.0.0.0/panel/CMakeLists.txt --- ukui-panel-3.14.0.1/panel/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/CMakeLists.txt 2023-05-23 15:58:00.000000000 +0800 @@ -1,11 +1,9 @@ -set(PROJECT ukui-panel) +project(ukui-panel LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) add_subdirectory(common) -#add_subdirectory(xdg) -#add_subdirectory(common_fun) set(PRIV_HEADERS panelpluginsmodel.h @@ -15,7 +13,7 @@ ukuipanellayout.h plugin.h pluginsettings_p.h - highlight-effect.h + contextmenu.h ) # using UKUi namespace in the public headers. @@ -24,12 +22,10 @@ pluginsettings.h iukuipanelplugin.h iukuipanel.h - common/ukuisettings.h common/ukuiplugininfo.h common/ukuitranslator.h common/common.h - common/ukuigridlayout.h common/ukuiglobals.h common_fun/listengsettings.h @@ -48,26 +44,29 @@ ukuipanellayout.cpp plugin.cpp pluginsettings.cpp - + contextmenu.cpp common/ukuiplugininfo.cpp common/ukuisettings.cpp common/ukuitranslator.cpp - common/ukuigridlayout.cpp common_fun/listengsettings.cpp common_fun/ukuipanel_infomation.cpp common_fun/dbus-adaptor.cpp common_fun/panel_commission.cpp customstyle.cpp - highlight-effect.cpp ) -file(GLOB CONFIG_FILES resources/*.conf resources/*.qss) -############################################ +set(PLUGIN_DESKTOPS_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/ukui/${PROJECT_NAME}") +set(QTX_LIBRARIES Qt5::Widgets Qt5::Xml Qt5::DBus) +set(UKUI_PANEL_MAN ../man/ukui-panel.1) +set(DESKTOP_FILE resources/ukui-panel.desktop) +set(IMAGE_DIR ./img/) +set(GSETTINGS_FILE resources/org.ukui.panel.settings.gschema.xml) +set(PANEL_GLOBAL_CONFIG_FILES resources/panel-commission.sh resources/panel-commission.ini + resources/ukui-panel-reset.sh resources/ukui-panel-config.sh) +file(GLOB UKUI_PANEL_CONFIG_FILES resources/*.conf) add_definitions(-DCOMPILE_UKUI_PANEL) - -set(PLUGIN_DESKTOPS_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/ukui/${PROJECT}") add_definitions(-DPLUGIN_DESKTOPS_DIR=\"${PLUGIN_DESKTOPS_DIR}\") if (WITH_SCREENSAVER_FALLBACK) @@ -75,38 +74,18 @@ add_definitions(-DWITH_SCREENSAVER_FALLBACK "-DUKUI_LOCK_DESKTOP=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications/ukui-lockscreen.desktop\"") endif () -project(${PROJECT}) - -set(QTX_LIBRARIES Qt5::Widgets Qt5::Xml Qt5::DBus) - - #Translations -#ukui_translate_ts(QM_FILES SOURCES -# UPDATE_TRANSLATIONS -# ${UPDATE_TRANSLATIONS} -# SOURCES -# ${PUB_HEADERS} -# ${PRIV_HEADERS} -# ${SOURCES} -# ${UI} -# INSTALL_DIR -# "${UKUI_TRANSLATIONS_DIR}/${PROJECT_NAME}" -#) - ukui_app_translation_loader(SOURCES ${PROJECT_NAME}) set_property(SOURCE ${DBUS_INTERFACE_SRCS} ${DBUS_ADAPTOR_SRCS} PROPERTY SKIP_AUTOGEN ON) list(APPEND SOURCES "${DBUS_INTERFACE_SRCS}" "${DBUS_ADAPTOR_SRCS}") - - - -add_executable(${PROJECT} +add_executable(${PROJECT_NAME} ${PUB_HEADERS} ${PRIV_HEADERS} ${QM_FILES} ${SOURCES} - ${UI} ) + find_package(PkgConfig) pkg_check_modules(GLIB2 REQUIRED glib-2.0) pkg_check_modules(GIO2 REQUIRED gio-2.0) @@ -114,8 +93,14 @@ include_directories(${GLIB2_INCLUDE_DIRS}) include_directories(${GIO2_INCLUDE_DIRS}) include_directories(${Gsetting_INCLUDE_DIRS}) + +find_package(PkgConfig REQUIRED) +find_package(KF5WindowSystem) +find_package(KF5Screen) +pkg_check_modules(KYSDKWAYLANDHELPER_PKG kysdk-waylandhelper) + #ADD_DEFINITIONS(-DQT_NO_KEYWORDS) -target_link_libraries(${PROJECT} +target_link_libraries(${PROJECT_NAME} ${LIBRARIES} ${QTX_LIBRARIES} KF5::WindowSystem @@ -124,69 +109,37 @@ ${GLIB2_LIBRARIES} ${GIO2_LIBRARIES} ${Gsetting_LIBRARIES} + Qt${QT_VERSION_MAJOR}::Quick + KF5::Screen ) +target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDKWAYLANDHELPER_PKG_INCLUDE_DIRS}) +target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDKWAYLANDHELPER_PKG_LIBRARY_DIRS} KF5::WindowSystem) +target_link_libraries(${PROJECT_NAME} ${KYSDKWAYLANDHELPER_PKG_LIBRARIES}) -target_compile_definitions(${PROJECT} +target_compile_definitions(${PROJECT_NAME} PRIVATE "UKUI_RELATIVE_SHARE_DIR=\"${UKUI_RELATIVE_SHARE_DIR}\"" - #"UKUI_SHARE_DIR=\"${UKUI_SHARE_DIR}\"" "UKUI_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${UKUI_RELATIVE_TRANSLATIONS_DIR}\"" "UKUI_SHARE_TRANSLATIONS_DIR=\"${UKUI_TRANSLATIONS_DIR}\"" "UKUI_GRAPHICS_DIR=\"${UKUI_GRAPHICS_DIR}\"" - #"UKUI_ETC_XDG_DIR=\"${UKUI_ETC_XDG_DIR}\"" "UKUI_DATA_DIR=\"${UKUI_DATA_DIR}\"" "UKUI_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"" - #"UKUI_VERSION=\"${UKUI_VERSION}\"" - #"COMPILE_LIBUKUI" - #"QT_USE_QSTRINGBUILDER" - #"QT_NO_CAST_FROM_ASCII" - #"QT_NO_CAST_TO_ASCII" - #"QT_NO_URL_CAST_FROM_STRING" - #"QT_NO_CAST_FROM_BYTEARRAY" - #"$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>" - #"$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>" ) - -install(TARGETS ${PROJECT} RUNTIME DESTINATION bin) -install(FILES ${CONFIG_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/ukui) +#安装ukui-panel +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) +#DESKTOP FILE +install(FILES ${DESKTOP_FILE} DESTINATION "/etc/xdg/autostart/" COMPONENT Runtime) +install(FILES ${UKUI_PANEL_CONFIG_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/ukui) install(FILES ${PUB_HEADERS} DESTINATION include/ukui) -install(FILES - ../man/ukui-panel.1 - DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" - COMPONENT Runtime -) -install(FILES - resources/ukui-panel.desktop - DESTINATION "/etc/xdg/autostart/" - COMPONENT Runtime -) - -install(DIRECTORY - ./img/ - DESTINATION "${PACKAGE_DATA_DIR}/panel/img" -) - -install(FILES - resources/ukui-panel_zh_CN.qm resources/ukui-panel_zh_CN.ts resources/ukui-panel_tr.ts - DESTINATION "${PACKAGE_DATA_DIR}/panel/resources" - COMPONENT Runtime -) - -install(FILES - resources/org.ukui.panel.settings.gschema.xml - DESTINATION "/usr/share/glib-2.0/schemas" - COMPONENT Runtime -) - -install(FILES - resources/panel-commission.sh resources/panel-commission.ini resources/ukui-panel-reset.sh resources/ukui-panel-config.sh - DESTINATION "/usr/share/ukui/ukui-panel" - COMPONENT Runtime +install(FILES ${UKUI_PANEL_MAN} DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" COMPONENT Runtime) +install(FILES ${GSETTINGS_FILE} DESTINATION "/usr/share/glib-2.0/schemas" COMPONENT Runtime) +install(FILES ${PANEL_GLOBAL_CONFIG_FILES} DESTINATION "/usr/share/ukui/ukui-panel" COMPONENT Runtime PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE WORLD_EXECUTE GROUP_EXECUTE GROUP_READ ) +install(DIRECTORY ${IMAGE_DIR} DESTINATION "${PACKAGE_DATA_DIR}/panel/img") set(PLUGIN panel) include(../cmake/UkuiPluginTranslationTs.cmake) diff -Nru ukui-panel-3.14.0.1/panel/common/common.h ukui-panel-4.0.0.0/panel/common/common.h --- ukui-panel-3.14.0.1/panel/common/common.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/common/common.h 2023-05-23 15:58:00.000000000 +0800 @@ -67,13 +67,21 @@ #define PANEL_SIZE_SMALL_V 47 #define POPUP_BORDER_SPACING 4 #define SETTINGS_SAVE_DELAY 1000 - +//panel gsettings #define PANEL_SETTINGS "org.ukui.panel.settings" #define PANEL_SIZE_KEY "panelsize" #define ICON_SIZE_KEY "iconsize" #define PANEL_POSITION_KEY "panelposition" -#define SHOW_TASKVIEW "showtaskview" -#define SHOW_NIGHTMODE "shownightmode" +#define SHOW_TASKVIEW_KEY "showtaskview" +#define LOCK_PANEL_KEY "lockpanel" +#define HIDE_PANEL_KEY "hidepanel" +#define ABOUT_KYLIN_DISPLAY "aboutkylin-display" + +//panel-daemon DBUS +#define UKUI_PANEL_DAEMON "org.ukui.panel.daemon" +#define UKUI_PANEL_DAEMON_PATH "/convert/desktopwid" +#define UKUI_PANEL_DAEMON_INTERFACE "org.ukui.panel.daemon" +#define UKUI_PANEL_DAEMON_METHOD "WIDToDesktop" #define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" #define TRANSPARENCY_KEY "transparency" @@ -89,6 +97,16 @@ #define STYLE_NAME_KEY_BLACK "ukui-black" #define STYLE_NAME_KEY_LIGHT "ukui-light" #define STYLE_NAME_KEY_WHITE "ukui-white" +#define STYLE_NAME_KEY_ICONTHEME "iconThemeName" + +//USD primary screen changed Infomation +#define USD_SERVICE "org.ukui.SettingsDaemon" +#define USD_XRANDER_PATH "/org/ukui/SettingsDaemon/xrandr" +#define USD_XRANDER_INTERFACE "org.ukui.SettingsDaemon.xrandr" +#define PRIMARY_CHANGED "primaryChanged" + +#define MAX_SIZE_OF_Thumb 16777215 +#define PANEL_CONFIG_PATH "/usr/share/ukui/ukui-panel/panel-commission.ini" #endif // COMMON_H diff -Nru ukui-panel-3.14.0.1/panel/common/ukuisettings.h ukui-panel-4.0.0.0/panel/common/ukuisettings.h --- ukui-panel-3.14.0.1/panel/common/ukuisettings.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/common/ukuisettings.h 2023-05-22 14:06:12.000000000 +0800 @@ -78,7 +78,7 @@ overwritten. Otherwise, it overwrites the the un-localized version. */ void setLocalizedValue(const QString &key, const QVariant &value); -signals: +Q_SIGNALS: /*! /brief signal for backward compatibility (emitted whenever settingsChangedFromExternal() or settingsChangedByApp() is emitted) */ void settingsChanged(); @@ -92,11 +92,11 @@ protected: bool event(QEvent *event); -protected slots: +protected Q_SLOTS: /*! Called when the config file is changed */ virtual void fileChanged(); -private slots: +private Q_SLOTS: void _fileChanged(QString path); private: @@ -197,14 +197,14 @@ GlobalSettings(); ~GlobalSettings(); -signals: +Q_SIGNALS: /// Signal emitted when the icon theme has changed. void iconThemeChanged(); /// Signal emitted when the ukui theme has changed. void ukuiThemeChanged(); -protected slots: +protected Q_SLOTS: void fileChanged(); private: diff -Nru ukui-panel-3.14.0.1/panel/common_fun/ukuipanel_infomation.cpp ukui-panel-4.0.0.0/panel/common_fun/ukuipanel_infomation.cpp --- ukui-panel-3.14.0.1/panel/common_fun/ukuipanel_infomation.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/common_fun/ukuipanel_infomation.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -195,6 +195,20 @@ QString UKuiPanelInformation::GetPanelPosition() { - QString str="bottom"; + QString str; + switch(m_panelPosition) { + case PanelPosition::Top: + str="top"; + break; + case PanelPosition::Left: + str="left"; + break; + case PanelPosition::Right: + str="right"; + break; + default: + str="bottom"; + break; + } return str; } diff -Nru ukui-panel-3.14.0.1/panel/common_fun/ukuipanel_infomation.h ukui-panel-4.0.0.0/panel/common_fun/ukuipanel_infomation.h --- ukui-panel-3.14.0.1/panel/common_fun/ukuipanel_infomation.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/common_fun/ukuipanel_infomation.h 2023-05-22 14:06:12.000000000 +0800 @@ -37,6 +37,13 @@ int m_panelPosition; int m_panelSize; + enum PanelPosition{ + Bottom = 0, + Top = 1, + Left = 2, + Right = 3 + }; + public Q_SLOTS: QVariantList GetPrimaryScreenGeometry(); QVariantList GetPrimaryScreenAvailableGeometry(); diff -Nru ukui-panel-3.14.0.1/panel/contextmenu.cpp ukui-panel-4.0.0.0/panel/contextmenu.cpp --- ukui-panel-3.14.0.1/panel/contextmenu.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/contextmenu.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,179 @@ +#include "contextmenu.h" +#include <QFileInfo> +#include <QProcess> +#include <KWindowSystem> + +ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent) +{ + const QByteArray id(PANEL_SETTINGS); + if (QGSettings::isSchemaInstalled(PANEL_SETTINGS)) { + m_gsettings = new QGSettings(id); + m_gsettingsKeys = m_gsettings->keys(); + } + + QAction * showtaskview = this->addAction(tr("Show Taskview")); + showtaskview->setCheckable(true); + if (m_gsettingsKeys.contains(SHOW_TASKVIEW_KEY)) { + showtaskview->setChecked(m_gsettings->get(SHOW_TASKVIEW_KEY).toBool()); + connect(showtaskview, &QAction::triggered, [this] { showTaskView(); }); + } + + this->addAction(tr("Show Desktop"), + this,[=]{showDesktop();} + ); + + this->addSeparator(); + + if(QFileInfo::exists(QString("/usr/bin/ukui-system-monitor"))) { + this->addAction(tr("Show System Monitor"), + this,[=] {systeMonitor();} + ); + } + + this->addSeparator(); + + adjustPanel(); + + QAction * m_lockAction = this->addAction(tr("Lock This Panel")); + m_lockAction->setCheckable(true); + m_lockAction->setChecked(m_lockPanel); + if (m_gsettingsKeys.contains(LOCK_PANEL_KEY)) { + connect(m_lockAction, &QAction::triggered, [this] { m_gsettings->set(LOCK_PANEL_KEY,!m_gsettings->get(LOCK_PANEL_KEY).toBool());}); + } + + QAction *about; + about = new QAction(this); + about->setText(tr("About Kylin")); + if (m_gsettingsKeys.contains(ABOUT_KYLIN_DISPLAY)) { + if (m_gsettings->get(ABOUT_KYLIN_DISPLAY).toBool()) { + this->addAction(about); + connect(about,&QAction::triggered, [this] { + QProcess::startDetached(QString("ukui-control-center -m About")); + }); + } + } +} + +void ContextMenu::adjustPanel() +{ + if (m_gsettingsKeys.contains(LOCK_PANEL_KEY)) { + m_lockPanel = m_gsettings->get(LOCK_PANEL_KEY).toBool(); + } else { + m_lockPanel = false; + } + + QAction *pmenuaction_s; + QAction *pmenuaction_m; + QAction *pmenuaction_l; + + pmenuaction_s = new QAction(this); + pmenuaction_s->setText(tr("Small")); + pmenuaction_m = new QAction(this); + pmenuaction_m->setText(tr("Medium")); + pmenuaction_l = new QAction(this); + pmenuaction_l->setText(tr("Large")); + + + QMenu *pmenu_panelsize; + pmenu_panelsize = new QMenu(this); + pmenu_panelsize->setTitle(tr("Adjustment Size")); + pmenu_panelsize->addAction(pmenuaction_s); + pmenu_panelsize->addAction(pmenuaction_m); + pmenu_panelsize->addAction(pmenuaction_l); + pmenu_panelsize->setWindowOpacity(0.9); + this->addMenu(pmenu_panelsize); + + pmenuaction_s->setCheckable(true); + pmenuaction_m->setCheckable(true); + pmenuaction_l->setCheckable(true); + if (m_gsettingsKeys.contains(PANEL_SIZE_KEY)) { + pmenuaction_s->setChecked(m_gsettings->get(PANEL_SIZE_KEY).toInt()==PANEL_SIZE_SMALL); + pmenuaction_m->setChecked(m_gsettings->get(PANEL_SIZE_KEY).toInt()==PANEL_SIZE_MEDIUM); + pmenuaction_l->setChecked(m_gsettings->get(PANEL_SIZE_KEY).toInt()==PANEL_SIZE_LARGE); + } + + connect(pmenuaction_s,&QAction::triggered,[this] { + m_gsettings->set(PANEL_SIZE_KEY,PANEL_SIZE_SMALL); + m_gsettings->set(ICON_SIZE_KEY,ICON_SIZE_SMALL); + }); + connect(pmenuaction_m,&QAction::triggered,[this] { + m_gsettings->set(PANEL_SIZE_KEY,PANEL_SIZE_MEDIUM); + m_gsettings->set(ICON_SIZE_KEY,ICON_SIZE_MEDIUM); + }); + connect(pmenuaction_l,&QAction::triggered,[this] { + m_gsettings->set(PANEL_SIZE_KEY,PANEL_SIZE_LARGE); + m_gsettings->set(ICON_SIZE_KEY,ICON_SIZE_LARGE); + }); + pmenu_panelsize->setDisabled(m_lockPanel); + + QAction *pmenuaction_top; + QAction *pmenuaction_bottom; + QAction *pmenuaction_left; + QAction *pmenuaction_right; + pmenuaction_top = new QAction(this); + pmenuaction_top->setText(tr("Up")); + pmenuaction_bottom = new QAction(this); + pmenuaction_bottom->setText(tr("Bottom")); + pmenuaction_left = new QAction(this); + pmenuaction_left->setText(tr("Left")); + pmenuaction_right = new QAction(this); + pmenuaction_right->setText(tr("Right")); + QMenu *pmenu_positon; + pmenu_positon = new QMenu(this); + pmenu_positon->setTitle(tr("Adjustment Position")); + pmenu_positon->addAction(pmenuaction_top); + pmenu_positon->addAction(pmenuaction_bottom); + pmenu_positon->addAction(pmenuaction_left); + pmenu_positon->addAction(pmenuaction_right); + this->addMenu(pmenu_positon); + + pmenuaction_top->setCheckable(true); + pmenuaction_bottom->setCheckable(true); + pmenuaction_left->setCheckable(true); + pmenuaction_right->setCheckable(true); + if (m_gsettingsKeys.contains(PANEL_POSITION_KEY)) { + pmenuaction_top->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==1); + pmenuaction_bottom->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==0); + pmenuaction_left->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==2); + pmenuaction_right->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==3); + } + + connect(pmenuaction_top,&QAction::triggered, [this] { m_gsettings->set(PANEL_POSITION_KEY,1);}); + connect(pmenuaction_bottom,&QAction::triggered, [this] { m_gsettings->set(PANEL_POSITION_KEY,0);}); + connect(pmenuaction_left,&QAction::triggered, [this] { m_gsettings->set(PANEL_POSITION_KEY,2);}); + connect(pmenuaction_right,&QAction::triggered, [this] { m_gsettings->set(PANEL_POSITION_KEY,3);}); + pmenu_positon->setWindowOpacity(0.9); + pmenu_positon->setDisabled(m_lockPanel); + + QAction * hidepanel = this->addAction(tr("Hide Panel")); + hidepanel->setDisabled(m_lockPanel); + hidepanel->setCheckable(true); + if (m_gsettingsKeys.contains(HIDE_PANEL_KEY)) { + hidepanel->setChecked(m_gsettings->get(HIDE_PANEL_KEY).toBool()); + connect(hidepanel, &QAction::triggered, [this] { + m_gsettings->set(HIDE_PANEL_KEY,!m_gsettings->get(HIDE_PANEL_KEY).toBool()); + }); + } +} + +/*右键 系统监视器选项*/ +void ContextMenu::systeMonitor() +{ + QProcess *process = new QProcess(this); + process->startDetached("/usr/bin/ukui-system-monitor"); + process->deleteLater(); +} + +/*右键 显示桌面选项*/ +void ContextMenu::showDesktop() +{ + KWindowSystem::setShowingDesktop(!KWindowSystem::showingDesktop()); +} + +/*右键 显示任务视图 选项*/ +void ContextMenu::showTaskView() +{ + if (m_gsettingsKeys.contains(SHOW_TASKVIEW_KEY)) { + m_gsettings->set(SHOW_TASKVIEW_KEY,!m_gsettings->get(SHOW_TASKVIEW_KEY).toBool()); + } +} diff -Nru ukui-panel-3.14.0.1/panel/contextmenu.h ukui-panel-4.0.0.0/panel/contextmenu.h --- ukui-panel-3.14.0.1/panel/contextmenu.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/contextmenu.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,29 @@ +#ifndef CONTEXTMENU_H +#define CONTEXTMENU_H + +#include <QObject> +#include <QMenu> +#include <QGSettings> +#include "common/common.h" + +class ContextMenu : public QMenu +{ + Q_OBJECT +public: + explicit ContextMenu(QWidget *parent = nullptr); + +private: + void adjustPanel(); + + QGSettings *m_gsettings; + QStringList m_gsettingsKeys; + bool m_lockPanel; + +//signals: +private Q_SLOTS: + void systeMonitor(); + void showDesktop(); + void showTaskView(); +}; + +#endif // CONTEXTMENU_H diff -Nru ukui-panel-3.14.0.1/panel/customstyle.cpp ukui-panel-4.0.0.0/panel/customstyle.cpp --- ukui-panel-3.14.0.1/panel/customstyle.cpp 2022-05-10 16:02:26.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/customstyle.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -335,40 +335,6 @@ painter->drawRoundedRect(option->rect.adjusted(2,2,-2,-2),6,6); painter->restore(); - /*buttom center x:22.5 y:42*/ - if(m_multileWindow) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setPen(Qt::NoPen); - painter->setBrush(option->palette.color(QPalette::Highlight)); - painter->drawEllipse(option->rect.topLeft() + QPointF(8.5, 4.5), 2.5, 2.5); - painter->setBrush(option->palette.color(QPalette::Highlight).light(125)); - painter->drawEllipse(option->rect.topLeft() + QPointF(4.5, 4.5), 2.5, 2.5); - painter->restore(); - } - - return; - } - - else if(QString::compare(m_pluginName,"closebutton")==0) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - painter->drawRoundedRect(option->rect,6,6); - if (option->state & State_MouseOver) { - if (option->state & State_Sunken) { - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0xd7,0x34,0x35)); - painter->drawRoundedRect(option->rect,6,6); - } else { - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0xf0,0x41,0x34)); - painter->drawRoundedRect(option->rect,4,4); - } - } - painter->restore(); return; } else { painter->save(); @@ -391,6 +357,7 @@ painter->restore(); return; } + //浅色主题 } else { if(QString::compare(m_pluginName,"taskbutton")==0) { painter->save(); @@ -407,38 +374,6 @@ painter->drawRoundedRect(option->rect.adjusted(2,2,-2,-2),6,6); painter->restore(); - if(m_multileWindow) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setPen(Qt::NoPen); - painter->setBrush(option->palette.color(QPalette::Highlight)); - painter->drawEllipse(option->rect.topLeft() + QPointF(8.5, 4.5), 2.5, 2.5); - painter->setBrush(option->palette.color(QPalette::Highlight).light(125)); - painter->drawEllipse(option->rect.topLeft() + QPointF(4.5, 4.5), 2.5, 2.5); - painter->restore(); - } - return; - } - - else if(QString::compare(m_pluginName,"closebutton")==0) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - painter->drawRoundedRect(option->rect,6,6); - if (option->state & State_MouseOver) { - if (option->state & State_Sunken) { - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0xd7,0x34,0x35)); - painter->drawRoundedRect(option->rect,6,6); - } else { - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0xf0,0x41,0x34)); - painter->drawRoundedRect(option->rect,4,4); - } - } - painter->restore(); return; } else { painter->save(); diff -Nru ukui-panel-3.14.0.1/panel/img/leftMask.svg ukui-panel-4.0.0.0/panel/img/leftMask.svg --- ukui-panel-3.14.0.1/panel/img/leftMask.svg 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/img/leftMask.svg 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 25.3.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + viewBox="0 0 52 64" style="enable-background:new 0 0 52 64;" xml:space="preserve"> +<style type="text/css"> + .st0{fill-rule:evenodd;clip-rule:evenodd;fill:url(#左遮罩_1_);} +</style> +<g id="桌面"> + <g id="桌面-dock栏状态一览-竖屏" transform="translate(-40.000000, -367.000000)"> + <g id="编组-3备份-2" transform="translate(20.000000, 303.000000)"> + <g id="Dock栏备份" transform="translate(0.000000, 48.000000)"> + <g id="应用区" transform="translate(20.000000, 16.000000)"> + + <linearGradient id="左遮罩_1_" gradientUnits="userSpaceOnUse" x1="-266.75" y1="475.9844" x2="-267.75" y2="475.9844" gradientTransform="matrix(52 0 0 -64 13923 30495)"> + <stop offset="0" style="stop-color:#F5F5F5;stop-opacity:0"/> + <stop offset="1" style="stop-color:#F5F5F5"/> + </linearGradient> + <path id="左遮罩" class="st0" d="M52,0L52,0v64H0V0H52z"/> + </g> + </g> + </g> + </g> +</g> +</svg> diff -Nru ukui-panel-3.14.0.1/panel/iukuipanelplugin.h ukui-panel-4.0.0.0/panel/iukuipanelplugin.h --- ukui-panel-3.14.0.1/panel/iukuipanelplugin.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/iukuipanelplugin.h 2023-05-22 14:06:12.000000000 +0800 @@ -96,15 +96,6 @@ MiddleClick = 4 ///< The plugin was clicked with the middle mouse button }; - enum CalendarShowMode - { - lunarSunday = 0,//show lunar and first day a week is sunday - lunarMonday = 1,//show lunar and first day a week is monday - solarSunday = 2,//show solar and first day a week is sunday - solarMonday = 3,//show solar and first day a week is monday - defaultMode = 0xff - }; - /** Constructs an IUKUIPanelPlugin object with the given startupInfo. You do not have to worry about the startupInfo parameters, IUKUIPanelPlugin processes the parameters itself. diff -Nru ukui-panel-3.14.0.1/panel/main.cpp ukui-panel-4.0.0.0/panel/main.cpp --- ukui-panel-3.14.0.1/panel/main.cpp 2022-05-11 17:51:59.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/main.cpp 2023-05-23 15:58:00.000000000 +0800 @@ -23,7 +23,6 @@ * * END_COMMON_COPYRIGHT_HEADER */ - #include "ukuipanelapplication.h" #include <QTranslator> #include <sys/types.h> @@ -37,55 +36,6 @@ #include <QDir> #include <X11/Xlib.h> #include <ukui-log4qt.h> -/*! The ukui-panel is the panel of UKUI. - Usage: ukui-panel [CONFIG_ID] - CONFIG_ID Section name in config file ~/.config/ukui/panel.conf - (default main) - */ -void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) -{ - QByteArray localMsg = msg.toLocal8Bit(); - QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit(); - - QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-panel.log"; - - bool showDebug = true; - if (!QFile::exists(logFilePath)) { - showDebug = false; - } - FILE *log_file = nullptr; - - if (showDebug) { - log_file = fopen(logFilePath.toLocal8Bit().constData(), "a+"); - } - - const char *file = context.file ? context.file : ""; - const char *function = context.function ? context.function : ""; - switch (type) { - case QtDebugMsg: - if (!log_file) { - break; - } - fprintf(log_file, "Debug: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtInfoMsg: - fprintf(log_file? log_file: stdout, "Info: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtWarningMsg: - fprintf(log_file? log_file: stderr, "Warning: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtCriticalMsg: - fprintf(log_file? log_file: stderr, "Critical: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtFatalMsg: - fprintf(log_file? log_file: stderr, "Fatal: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - } - - if (log_file) - fclose(log_file); -} - int main(int argc, char *argv[]) { @@ -93,7 +43,6 @@ qDebug()<<"Main :: ukui-panel start"<<QDateTime::currentDateTime(); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif @@ -111,24 +60,5 @@ syslog(LOG_ERR, "Can't lock single file, ukui-panel is already running!"); exit(0); } - - //tanslate -// QString locale = QLocale::system().name(); -// QTranslator translator; -// if (locale == "zh_CN"){ -// if (translator.load("ukui-panel_zh_CN.qm", "/usr/share/ukui-panel/panel/resources/")){ -// app.installTranslator(&translator); -// } -// else{ -// qDebug() << "Load translations file" << locale << "failed!"; -// } -// } -// if (locale == "tr_TR"){ -// if (translator.load("ukui-panel_tr.qm", "/usr/share/ukui-panel/panel/resources/")) -// app.installTranslator(&translator); -// else -// qDebug() << "Load translations file" << locale << "failed!"; -// } - return app.exec(); } diff -Nru ukui-panel-3.14.0.1/panel/plugin.cpp ukui-panel-4.0.0.0/panel/plugin.cpp --- ukui-panel-3.14.0.1/panel/plugin.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/plugin.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -109,10 +109,6 @@ #include "../plugin-segmentation/segmentation.h" // startmenu extern void * loadPluginTranslation_segmentation_helper; #endif -#if defined(WITH_NIGHTMODE_PLUGIN) -#include "../plugin-nightmode/nightmode.h" // startmenu -extern void * loadPluginTranslation_nightmode_helper; -#endif QColor Plugin::m_moveMarkerColor= QColor(255, 0, 0, 255); @@ -287,9 +283,6 @@ #if defined(WITH_SEGMENTATION_PLUGIN) std::make_tuple(QLatin1String("segmentation"), plugin_ptr_t{new StartMenuLibrary}, loadPluginTranslation_segementation_helper),// startmenu #endif -#if defined(WITH_NIGHTMODE_PLUGIN) - std::make_tuple(QLatin1String("nightmode"), plugin_ptr_t{new NightModeLibrary}, loadPluginTranslation_nightmode_helper),// nightmode -#endif }; static constexpr plugin_tuple_t const * const plugins_begin = static_plugins; static constexpr plugin_tuple_t const * const plugins_end = static_plugins + sizeof (static_plugins) / sizeof (static_plugins[0]); @@ -418,19 +411,6 @@ } - -/************************************************ - - ************************************************/ -void Plugin::contextMenuEvent(QContextMenuEvent *event) -{ - m_panel->showPopupMenu(this); -} - - -/************************************************ - - ************************************************/ void Plugin::mousePressEvent(QMouseEvent *event) { switch (event->button()) diff -Nru ukui-panel-3.14.0.1/panel/plugin.h ukui-panel-4.0.0.0/panel/plugin.h --- ukui-panel-3.14.0.1/panel/plugin.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/plugin.h 2023-05-22 14:06:12.000000000 +0800 @@ -102,7 +102,6 @@ void dragLeft(); protected: - void contextMenuEvent(QContextMenuEvent *event); void mousePressEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event); void showEvent(QShowEvent *event); diff -Nru ukui-panel-3.14.0.1/panel/resources/org.ukui.panel.settings.gschema.xml ukui-panel-4.0.0.0/panel/resources/org.ukui.panel.settings.gschema.xml --- ukui-panel-3.14.0.1/panel/resources/org.ukui.panel.settings.gschema.xml 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/resources/org.ukui.panel.settings.gschema.xml 2023-05-22 14:06:12.000000000 +0800 @@ -16,22 +16,21 @@ <description>The Position of ukui-panel</description> </key> <key name="showtaskview" type="b"> - <default>true</default> + <default>false</default> <summary>show TsskView</summary> <description>control taskview show or hide</description> </key> - <key name="shownightmode" type="b"> + <key name="aboutkylin-display" type="b"> <default>true</default> - <summary>show TsskView</summary> - <description>control taskview show or hide</description> + <summary>about kylin display</summary> + <description>show or hide About Kylin</description> </key> - <key name="quicklaunchlines" type="i"> <default>1</default> <summary>show Quicklaunch Lines</summary> <description>show Quicklaunch Lines</description> </key> - <key name="quicklaunchappsnumber" type="i"> + <key name="quicklaunchappsnumber" type="i"> <default>8</default> <summary>show Apps Number</summary> <description>the size of apps number in quicklaunch</description> @@ -71,6 +70,16 @@ <summary>show Statusnotifier button</summary> <description>show Statusnotifier button</description> </key> + <key name="hidepanel" type="b"> + <default>false</default> + <summary>has ability to hidepanel</summary> + <description>has ability to hide ukui-panel</description> + </key> + <key name="lockpanel" type="b"> + <default>false</default> + <summary>lock ukui-panel</summary> + <description>has ability to lock ukui-panel </description> + </key> </schema> </schemalist> diff -Nru ukui-panel-3.14.0.1/panel/resources/panel-commission.ini ukui-panel-4.0.0.0/panel/resources/panel-commission.ini --- ukui-panel-3.14.0.1/panel/resources/panel-commission.ini 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/resources/panel-commission.ini 2023-05-22 14:06:12.000000000 +0800 @@ -1,16 +1,13 @@ ;任务栏配置文件 -[NightMode] -nightmode=show -active=true [Hibernate] hibernate=show -[Calendar] -CalendarVersion=new - [ShowInTray] trayname=ukui-volume-control-applet-qt,kylin-nm,ukui-sidebar,indicator-china-weather,ukui-flash-disk,fcitx,sogouimebs-qimpanel,fcitx-qimpanel,explorer.exe,ukui-power-manager-tray,baidu-qimpanel,iflyime-qim,hedronagent,CTJManageTool [IgnoreWindow] ignoreWindow=ukui-menu,ukui-sidebar,ukui-search + +[Thumbnail] +thumbnailAvailable=true diff -Nru ukui-panel-3.14.0.1/panel/resources/panel-commission.sh ukui-panel-4.0.0.0/panel/resources/panel-commission.sh --- ukui-panel-3.14.0.1/panel/resources/panel-commission.sh 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/resources/panel-commission.sh 2023-05-22 14:06:12.000000000 +0800 @@ -4,40 +4,14 @@ #判断文件是否存在 commissionFile="${HOME}/.config/ukui/panel-commission.ini" if [[ ! -f "$commissionFile" ]]; then - echo "file not exit" cp /usr/share/ukui/ukui-panel/panel-commission.ini ${HOME}/.config/ukui -else - echo "file exit" fi -## 华为990 屏蔽休眠接口 -env | grep "XDG_SESSION_TYPE=wayland" -if [ $? -ne 0 ]; then - echo " " -else - echo "华为990" - #sed -i 's/hibernate=show/hibernate=hide/' ${HOME}/.config/ukui/panel-commission.ini -fi - -## 华为990 屏蔽夜间模式 -env | grep "XDG_SESSION_TYPE=wayland" -if [ $? -ne 0 ]; then - echo " " -else - echo "华为990" - while read line1 - do - if [[ $line1 == *nightmode* ]];then - sed -i 's/nightmode=show/nightmode=hide/' ${HOME}/.config/ukui/panel-commission.ini - fi - done < ${HOME}/.config/ukui/panel-commission.ini -fi ##拷贝配置文件到用户目录 panelConfigFile="${HOME}/.config/ukui/panel.conf" echo $panelConfigFile if [ ! -f "$panelConfigFile" ]; then cp /usr/share/ukui/panel.conf ${HOME}/.config/ukui -else fi diff -Nru ukui-panel-3.14.0.1/panel/resources/panel.conf ukui-panel-4.0.0.0/panel/resources/panel.conf --- ukui-panel-3.14.0.1/panel/resources/panel.conf 2022-05-07 09:49:07.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/resources/panel.conf 2023-05-23 15:58:00.000000000 +0800 @@ -7,7 +7,7 @@ hidable=false lineCount=1 lockPanel=false -plugins=startbar,taskbar,statusnotifier,calendar, showdesktop +plugins=startbar,taskbar,statusnotifier,calendar position=Bottom reserve-space=true show-delay=0 @@ -59,12 +59,10 @@ [statusnotifier] alignment=Right hideApp= -showApp=ukui-volume-control-applet-qt,kylin-nm,ukui-sidebar,indicator-china-weather,ukui-flash-disk,Fcitx,sogouimebs-qimpanel,fcitx-qimpanel,explorer.exe,ukui-power-manager-tray,baidu-qimpanel,iflyime-qim,hedronagent,CTJManageTool,evolution,ukui-bluetooth +showApp=ukui-search,kylin-nm,ukui-volume-control-applet-qt,Fcitx,fcitx-qimpanel,indicator-china-weather,ukui-flash-disk,sogouimebs-qimpanel,explorer.exe,ukui-power-manager-tray,baidu-qimpanel,iflyime-qim,hedronagent,CTJManageTool,evolution,ukui-bluetooth,kylin-virtual-keyboard +fixedApp=ukui-sidebar type=statusnotifier -[nightmode] -type=nightmode - [showdesktop] alignment=Right type=showdesktop diff -Nru ukui-panel-3.14.0.1/panel/resources/ukui-panel-reset.sh ukui-panel-4.0.0.0/panel/resources/ukui-panel-reset.sh --- ukui-panel-3.14.0.1/panel/resources/ukui-panel-reset.sh 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/resources/ukui-panel-reset.sh 2023-05-22 14:06:12.000000000 +0800 @@ -7,8 +7,6 @@ echo "配置文件异常" rm ${HOME}/.config/ukui/panel.conf cp /usr/share/ukui/panel.conf ${HOME}/.config/ukui/ -else - echo "配置文件正常" fi plugin_conf="" diff -Nru ukui-panel-3.14.0.1/panel/resources/ukui-session-tool-action.ini ukui-panel-4.0.0.0/panel/resources/ukui-session-tool-action.ini --- ukui-panel-3.14.0.1/panel/resources/ukui-session-tool-action.ini 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/resources/ukui-session-tool-action.ini 1970-01-01 08:00:00.000000000 +0800 @@ -1,81 +0,0 @@ -[LockScreen] -name=LockScreen -name[zh_CN]=锁屏 -icon=system-lock-screen-symbolic -show=true -showInSession=true -showInMenu=false -showInPanel=true -Group=User Action - -[SwitchUser] -name=SwitchUser -name[zh_CN]=切换用户 -icon=stock-people-symbolic -show=true -showInSession=true -showInMenu=false -showInPanel=true -Group=User Action - -[Logout] -name=Logout -name[zh_CN]=注销 -icon=system-logout-symbolic -show=true -showInSession=true -showInMenu=true -showInPanel=true -Group=User Action - -[HibernateMode] -name=Hibernate Mode -name[zh_CN]=休眠 -icon=kylin-sleep-symbolic -show=true -showInSession=true -showInMenu=false -showInPanel=true -Group=User Action -Group=Sleep or Hibernate - - -[Sleep Mode] -name=Sleep Mode -name[zh_CN]=睡眠 -icon=system-sleep -show=true -showInSession=true -showInMenu=true -showInPanel=true -Group=Sleep or Hibernate - -[Restart] -name=Restart -name[zh_CN]=重启 -icon=system-restart-symbolic -show=true -showInSession=true -showInMenu=true -showInPanel=true -Group=Sleep or Hibernate - -[TimeShutdown] -name=TimeShutdown -name[zh_CN]=定时开关机 -icon=system-restart-symbolic -show=true -showInSession=false -showInMenu=false -showInPanel=true -Group=Power Supply - -[PowerOff] -name=Power Off -name[zh_CN]=关机 -icon=system-shutdown-symbolic -show=true -showInSession=true -showInMenu=false -showInPanel=true -Group=Power Supply diff -Nru ukui-panel-3.14.0.1/panel/translation/panel_bo_CN.ts ukui-panel-4.0.0.0/panel/translation/panel_bo_CN.ts --- ukui-panel-3.14.0.1/panel/translation/panel_bo_CN.ts 2022-05-11 14:28:13.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/translation/panel_bo_CN.ts 2023-05-23 15:58:00.000000000 +0800 @@ -2,86 +2,148 @@ <!DOCTYPE TS> <TS version="2.1" language="bo_CN"> <context> - <name>UKUIPanel</name> + <name>ContextMenu</name> + <message> + <location filename="../contextmenu.cpp" line="11"/> + <source>Show Taskview</source> + <translation>ལས་འགན་མཐོང་སྣེ་འཆར་བའི་གནོན་མཐེབ།</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="16"/> + <source>Show Desktop</source> + <translation>ཅོག་ངོས་འཆར་བ།</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="23"/> + <source>Show System Monitor</source> + <translation>བརྒྱུད་ཁོངས་ལྟ་ཞིབ་ཆས།</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="32"/> + <source>Lock This Panel</source> + <translation>འགན་བྱང་ལ་ཟྭ་རྒྱག་པ།</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="39"/> + <source>About Kylin</source> + <translation>དགུ་ཚིགས་ཆིག་ལིན་གྱི་སྐོར།</translation> + </message> <message> - <location filename="../ukuipanel.cpp" line="837"/> + <location filename="../contextmenu.cpp" line="57"/> <source>Small</source> <translation>ཡིག་གཟུགས་ཆུང་བ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="839"/> + <location filename="../contextmenu.cpp" line="59"/> <source>Medium</source> <translation>འབྲིང་རིམ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="841"/> + <location filename="../contextmenu.cpp" line="61"/> <source>Large</source> <translation>ཆེ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="846"/> + <location filename="../contextmenu.cpp" line="66"/> <source>Adjustment Size</source> <translation>ཆེ་ཆུང་སྙོམས་སྒྲིག</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="882"/> + <location filename="../contextmenu.cpp" line="102"/> <source>Up</source> <translation>སྟེང་།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="884"/> + <location filename="../contextmenu.cpp" line="104"/> <source>Bottom</source> <translation>ཞབས་ཁུལ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="886"/> + <location filename="../contextmenu.cpp" line="106"/> <source>Left</source> <translation>གཡོན།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="888"/> + <location filename="../contextmenu.cpp" line="108"/> <source>Right</source> <translation>གཡས།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="891"/> + <location filename="../contextmenu.cpp" line="111"/> <source>Adjustment Position</source> <translation>གནས་ཡུལ་ལེགས་སྒྲིག</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="917"/> + <location filename="../contextmenu.cpp" line="136"/> <source>Hide Panel</source> <translation>ངོས་པང་སྦེད་པ།</translation> </message> +</context> +<context> + <name>UKUIPanel</name> + <message> + <source>Small</source> + <translation type="vanished">ཡིག་གཟུགས་ཆུང་བ།</translation> + </message> + <message> + <source>Medium</source> + <translation type="vanished">འབྲིང་རིམ།</translation> + </message> + <message> + <source>Large</source> + <translation type="vanished">ཆེ།</translation> + </message> + <message> + <source>Adjustment Size</source> + <translation type="vanished">ཆེ་ཆུང་སྙོམས་སྒྲིག</translation> + </message> + <message> + <source>Up</source> + <translation type="vanished">སྟེང་།</translation> + </message> + <message> + <source>Bottom</source> + <translation type="vanished">ཞབས་ཁུལ།</translation> + </message> + <message> + <source>Left</source> + <translation type="vanished">གཡོན།</translation> + </message> + <message> + <source>Right</source> + <translation type="vanished">གཡས།</translation> + </message> + <message> + <source>Adjustment Position</source> + <translation type="vanished">གནས་ཡུལ་ལེགས་སྒྲིག</translation> + </message> + <message> + <source>Hide Panel</source> + <translation type="vanished">ངོས་པང་སྦེད་པ།</translation> + </message> <message> - <location filename="../ukuipanel.cpp" line="1246"/> <source>Show Taskview</source> - <translation>ལས་འགན་མཐོང་སྣེ་འཆར་བའི་གནོན་མཐེབ།</translation> + <translation type="vanished">ལས་འགན་མཐོང་སྣེ་འཆར་བའི་གནོན་མཐེབ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1263"/> <source>Show Nightmode</source> - <translation>མཚན་ལྗོངས་རྣམ་པ་འཆར་བའི་གནོན་མཐེབ།</translation> + <translation type="vanished">མཚན་ལྗོངས་རྣམ་པ་འཆར་བའི་གནོན་མཐེབ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1269"/> <source>Show Desktop</source> - <translation>ཅོག་ངོས་འཆར་བ།</translation> + <translation type="vanished">ཅོག་ངོས་འཆར་བ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1276"/> <source>Show System Monitor</source> - <translation>བརྒྱུད་ཁོངས་ལྟ་ཞིབ་ཆས།</translation> + <translation type="vanished">བརྒྱུད་ཁོངས་ལྟ་ཞིབ་ཆས།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1301"/> <source>Lock This Panel</source> - <translation>འགན་བྱང་ལ་ཟྭ་རྒྱག་པ།</translation> + <translation type="vanished">འགན་བྱང་ལ་ཟྭ་རྒྱག་པ།</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1316"/> <source>About Kylin</source> - <translation>དགུ་ཚིགས་ཆིག་ལིན་གྱི་སྐོར།</translation> + <translation type="vanished">དགུ་ཚིགས་ཆིག་ལིན་གྱི་སྐོར།</translation> </message> </context> <context> diff -Nru ukui-panel-3.14.0.1/panel/translation/panel_zh_CN.ts ukui-panel-4.0.0.0/panel/translation/panel_zh_CN.ts --- ukui-panel-3.14.0.1/panel/translation/panel_zh_CN.ts 2022-05-11 17:51:28.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/translation/panel_zh_CN.ts 2023-05-23 15:58:00.000000000 +0800 @@ -2,123 +2,169 @@ <!DOCTYPE TS> <TS version="2.1" language="zh_CN"> <context> - <name>UKUIPanel</name> + <name>ContextMenu</name> <message> - <location filename="../ukuipanel.cpp" line="929"/> + <location filename="../contextmenu.cpp" line="11"/> + <source>Show Taskview</source> + <translation>显示“任务视图”按钮</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="16"/> + <source>Show Desktop</source> + <translation>显示桌面</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="23"/> + <source>Show System Monitor</source> + <translation>系统监视器</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="32"/> + <source>Lock This Panel</source> + <translation>锁定任务栏</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="39"/> + <source>About Kylin</source> + <translation>关于麒麟</translation> + </message> + <message> + <location filename="../contextmenu.cpp" line="57"/> <source>Small</source> <translation>小尺寸</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="931"/> + <location filename="../contextmenu.cpp" line="59"/> <source>Medium</source> <translation>中尺寸</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="933"/> + <location filename="../contextmenu.cpp" line="61"/> <source>Large</source> <translation>大尺寸</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="938"/> + <location filename="../contextmenu.cpp" line="66"/> <source>Adjustment Size</source> <translation>调整大小</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="974"/> + <location filename="../contextmenu.cpp" line="102"/> <source>Up</source> <translation>上</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="976"/> + <location filename="../contextmenu.cpp" line="104"/> <source>Bottom</source> <translation>下</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="978"/> + <location filename="../contextmenu.cpp" line="106"/> <source>Left</source> <translation>左</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="980"/> + <location filename="../contextmenu.cpp" line="108"/> <source>Right</source> <translation>右</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="983"/> + <location filename="../contextmenu.cpp" line="111"/> <source>Adjustment Position</source> <translation>调整位置</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1009"/> + <location filename="../contextmenu.cpp" line="136"/> <source>Hide Panel</source> <translation>隐藏任务栏</translation> </message> +</context> +<context> + <name>UKUIPanel</name> + <message> + <source>Small</source> + <translation type="vanished">小尺寸</translation> + </message> + <message> + <source>Medium</source> + <translation type="vanished">中尺寸</translation> + </message> + <message> + <source>Large</source> + <translation type="vanished">大尺寸</translation> + </message> + <message> + <source>Adjustment Size</source> + <translation type="vanished">调整大小</translation> + </message> + <message> + <source>Up</source> + <translation type="vanished">上</translation> + </message> + <message> + <source>Bottom</source> + <translation type="vanished">下</translation> + </message> + <message> + <source>Left</source> + <translation type="vanished">左</translation> + </message> + <message> + <source>Right</source> + <translation type="vanished">右</translation> + </message> + <message> + <source>Adjustment Position</source> + <translation type="vanished">调整位置</translation> + </message> + <message> + <source>Hide Panel</source> + <translation type="vanished">隐藏任务栏</translation> + </message> <message> <source>Set up Panel</source> <translation type="vanished">设置任务栏</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1399"/> <source>Show Taskview</source> - <translation>显示任务视图按钮</translation> + <translation type="vanished">显示“任务视图”按钮</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1416"/> - <source>Show Nightmode</source> - <translation>显示夜间模式按钮</translation> - </message> - <message> - <location filename="../ukuipanel.cpp" line="1423"/> <source>Show Desktop</source> - <translation>显示桌面</translation> + <translation type="vanished">显示桌面</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1431"/> <source>Show System Monitor</source> - <translation>系统监视器</translation> + <translation type="vanished">系统监视器</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1456"/> <source>Lock This Panel</source> - <translation>锁定任务栏</translation> + <translation type="vanished">锁定任务栏</translation> </message> <message> - <location filename="../ukuipanel.cpp" line="1471"/> <source>About Kylin</source> - <translation>关于麒麟</translation> - </message> - <message> - <location filename="../ukuipanel.cpp" line="1636"/> - <source>Remove Panel</source> - <comment>Dialog Title</comment> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuipanel.cpp" line="1637"/> - <source>Removing a panel can not be undone. -Do you want to remove this panel?</source> - <translation type="unfinished"></translation> + <translation type="vanished">关于麒麟</translation> </message> </context> <context> <name>main</name> <message> - <location filename="../ukuipanelapplication.cpp" line="109"/> + <location filename="../ukuipanelapplication.cpp" line="79"/> <source>Use alternate configuration file.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuipanelapplication.cpp" line="110"/> + <location filename="../ukuipanelapplication.cpp" line="80"/> <source>Configuration file</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuipanelapplication.cpp" line="115"/> + <location filename="../ukuipanelapplication.cpp" line="85"/> <source>ukui-panel set mode </source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuipanelapplication.cpp" line="116"/> + <location filename="../ukuipanelapplication.cpp" line="86"/> <source>panel set option</source> <translation type="unfinished"></translation> </message> diff -Nru ukui-panel-3.14.0.1/panel/ukuipanel.cpp ukui-panel-4.0.0.0/panel/ukuipanel.cpp --- ukui-panel-3.14.0.1/panel/ukuipanel.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/ukuipanel.cpp 2023-05-23 15:58:00.000000000 +0800 @@ -52,8 +52,9 @@ #include <KWindowSystem/KWindowSystem> #include <KWindowSystem/NETWM> -//#include <glib.h> -//#include <gio/gio.h> +#include <KF5/KScreen/kscreen/output.h> +#include <KF5/KScreen/kscreen/configmonitor.h> + #include <QGSettings> // Turn on this to show the time required to load each plugin during startup // #define DEBUG_PLUGIN_LOADTIME @@ -61,11 +62,7 @@ #include "common_fun/ukuipanel_infomation.h" #include "common_fun/dbus-adaptor.h" #include "common_fun/panel_commission.h" - -#ifdef DEBUG_PLUGIN_LOADTIME -#include <QElapsedTimer> -#endif - +#include "windowmanager/windowmanager.h" /************************************************ Returns the Position by the string. @@ -110,10 +107,6 @@ return QString(); } - -/************************************************ - - ************************************************/ UKUIPanel::UKUIPanel(const QString &configGroup, UKUi::Settings *settings, QWidget *parent) : QFrame(parent), m_settings(settings), @@ -128,13 +121,11 @@ m_position(IUKUIPanel::PositionBottom), m_screenNum(0), //whatever (avoid conditional on uninitialized value) m_actualScreenNum(0), - m_hidable(false), m_visibleMargin(true), m_hidden(false), m_animationTime(0), m_reserveSpace(true), - m_animation(nullptr), - m_lockPanel(false) + m_animation(nullptr) { qDebug()<<"Panel :: Constructor start"; //You can find information about the flags and widget attributes in your @@ -179,7 +170,21 @@ PanelCommission::panelConfigFileValueInit(true); PanelCommission::panelConfigFileReset(true); qDebug()<<"Panel :: PanelCommission config finished"; - + //初始化DBus接口 + UKuiPanelInformation* dbus = new UKuiPanelInformation; + new PanelAdaptor(dbus); + QDBusConnection con = QDBusConnection::sessionBus(); + if(!con.registerService("org.ukui.panel") || + !con.registerObject("/panel/position",dbus)) { + qDebug() << "fail" << con.lastError().message(); + } + //初始化判断是否为wayland环境,如果是wayland,则任务栏隐藏无动画,且鼠标再次移开任务栏的隐藏操作需要特殊处理 + QString platform = QGuiApplication::platformName(); + if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) { + m_isWaylandEnv =true; + } else { + m_isWaylandEnv = false; + } //UKUIPanel (inherits QFrame) -> lav (QGridLayout) -> UKUIPanelWidget (QFrame) -> UKUIPanelLayout UKUIPanelWidget = new QFrame(this); @@ -213,15 +218,23 @@ */ connect(QApplication::desktop(), &QDesktopWidget::resized, this, &UKUIPanel::ensureVisible); connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &UKUIPanel::ensureVisible); - connect(qApp,&QApplication::primaryScreenChanged,this,&UKUIPanel::ensureVisible); // connecting to QDesktopWidget::workAreaResized shouldn't be necessary, // as we've already connceted to QDesktopWidget::resized, but it actually connect(QApplication::desktop(), &QDesktopWidget::workAreaResized, this, &UKUIPanel::ensureVisible); + //适配KScreen后,分辨率改变的信号无法获取,需要从SettingsDaemon拿分辨率改变的信号 + QDBusConnection::sessionBus().connect(QString(USD_SERVICE), + QString(USD_XRANDER_PATH), + QString(USD_XRANDER_INTERFACE), + QString(PRIMARY_CHANGED), + this, SLOT(primaryChangedSlot(int, int, int, int, int))); + UKUIPanelApplication *a = reinterpret_cast<UKUIPanelApplication*>(qApp); - connect(a, &UKUIPanelApplication::primaryScreenChanged, [=]{ - setPanelGeometry(); + m_primaryScreenGeometry = QGuiApplication::screens().at(0)->geometry(); + KScreen::GetConfigOperation *op = new KScreen::GetConfigOperation(); + connect(op, &KScreen::GetConfigOperation::finished, this, [this](KScreen::ConfigOperation *op) { + configWatch(op); }); connect(UKUi::Settings::globalSettings(), SIGNAL(settingsChanged()), this, SLOT(update())); @@ -230,24 +243,45 @@ connect(m_standaloneWindows.data(), &WindowNotifier::lastHidden, this, &UKUIPanel::hidePanel); const QByteArray id(PANEL_SETTINGS); - m_gsettings = new QGSettings(id); - setPosition(0,intToPosition(m_gsettings->get(PANEL_POSITION_KEY).toInt(),PositionBottom),true); - - connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key==ICON_SIZE_KEY) { - setIconSize(m_gsettings->get(ICON_SIZE_KEY).toInt(),true); - } - if(key==PANEL_SIZE_KEY) { - setPanelSize(m_gsettings->get(PANEL_SIZE_KEY).toInt(),true); - } - if(key == PANEL_POSITION_KEY) { + if (QGSettings::isSchemaInstalled(PANEL_SETTINGS)) { + m_gsettings = new QGSettings(id); + m_gsettingsKeys = m_gsettings->keys(); + if (m_gsettingsKeys.contains(PANEL_POSITION_KEY)) { setPosition(0,intToPosition(m_gsettings->get(PANEL_POSITION_KEY).toInt(),PositionBottom),true); } - }); - - setPanelSize(m_gsettings->get(PANEL_SIZE_KEY).toInt(),true); - setIconSize(m_gsettings->get(ICON_SIZE_KEY).toInt(),true); - setPosition(0,intToPosition(m_gsettings->get(PANEL_POSITION_KEY).toInt(),PositionBottom),true); + if (m_gsettingsKeys.contains(HIDE_PANEL_KEY)) { + m_hidable = m_gsettings->get(HIDE_PANEL_KEY).toBool(); + } + connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key){ + if(key == ICON_SIZE_KEY) { + setIconSize(m_gsettings->get(ICON_SIZE_KEY).toInt(),true); + } + if(key == PANEL_SIZE_KEY) { + setPanelSize(m_gsettings->get(PANEL_SIZE_KEY).toInt(),true); + } + if(key == PANEL_POSITION_KEY) { + setPosition(0,intToPosition(m_gsettings->get(PANEL_POSITION_KEY).toInt(),PositionBottom),true); + } + if(key == HIDE_PANEL_KEY) { + m_hidable = !m_gsettings->get(HIDE_PANEL_KEY).toBool(); + if(m_hidable) + m_hideTimer.stop(); + setHidable(!m_hidable,true); + m_hidden = m_hidable; + m_showDelayTimer.start(); + m_time->start(1000); + } + }); + } + if (m_gsettingsKeys.contains(PANEL_SIZE_KEY)) { + setPanelSize(m_gsettings->get(PANEL_SIZE_KEY).toInt(),true); + } + if (m_gsettingsKeys.contains(ICON_SIZE_KEY)) { + setIconSize(m_gsettings->get(ICON_SIZE_KEY).toInt(),true); + } + if (m_gsettingsKeys.contains(PANEL_POSITION_KEY)) { + setPosition(0,intToPosition(m_gsettings->get(PANEL_POSITION_KEY).toInt(),PositionBottom),true); + } m_time = new QTimer(this); connect(m_time, &QTimer::timeout, this,[=] (){ @@ -288,19 +322,46 @@ // show it the first time, despite setting if (m_hidable) { showPanel(false); - QTimer::singleShot(PANEL_HIDE_FIRST_TIME, this, SLOT(hidePanel())); + hidePanel(); } styleAdjust(); qDebug()<<"Panel :: UKuiPanel finished"; - UKuiPanelInformation* dbus=new UKuiPanelInformation; - new PanelAdaptor(dbus); - QDBusConnection con=QDBusConnection::sessionBus(); - if(!con.registerService("org.ukui.panel") || - !con.registerObject("/panel/position",dbus)) { - qDebug()<<"fail"; - } +} + +void UKUIPanel::configWatch(KScreen::ConfigOperation *op) +{ + m_config = op->config(); + + KScreen::ConfigMonitor::instance()->addConfig(m_config); + + connect(m_config.data(), &KScreen::Config::primaryOutputChanged, + this, [=](const KScreen::OutputPtr &output){ + if (!output.isNull()) { + qDebug() << "primaryOutputChanged:" << output->name() << output->geometry(); + m_primaryScreenGeometry = output->geometry(); + QRect rect = caculPanelGeometry(output->geometry()); + qDebug()<<"primaryOutputChanged panel rect is"<<rect; + kdk::WindowManager::setGeometry(this->windowHandle(), rect); + realign(); + } + }); + connect(m_config.data(), &KScreen::Config::outputAdded, + this, [=](const KScreen::OutputPtr &output){ + if (!output.isNull()) { + KScreen::OutputPtr primary = m_config->primaryOutput(); + m_primaryScreenGeometry = primary->geometry(); + qDebug()<<"output added primary geometry is"<<primary->geometry(); + QRect rect = caculPanelGeometry(primary->geometry()); + qDebug()<<"output added panel rect is"<<rect; + kdk::WindowManager::setGeometry(this->windowHandle(), rect); + } + }); + connect(m_config.data(), &KScreen::Config::outputRemoved, + this, [=](){ + qDebug() << "output removed"; + }); } void UKUIPanel::setPanelHide(bool model) @@ -308,7 +369,10 @@ if (model) { hide(); } else { + //切换平板模式任务栏hide后再切回来,任务栏的surface发生了改变。wayland下需要重新设置dock属性 + setAttribute(Qt::WA_X11NetWmWindowTypeDock); show(); + KWindowSystem::setType(effectiveWinId(), NET::Dock); realign(); } } @@ -320,7 +384,6 @@ // Let Hidability be the first thing we read // so that every call to realign() is without side-effect - m_hidable = m_settings->value(CFG_KEY_HIDABLE, m_hidable).toBool(); m_hidden = m_hidable; m_visibleMargin = m_settings->value(CFG_KEY_VISIBLE_MARGIN, m_visibleMargin).toBool(); m_animationTime = m_settings->value(CFG_KEY_ANIMATION, m_animationTime).toInt(); @@ -338,16 +401,11 @@ // false); setAlignment(Alignment(m_settings->value(CFG_KEY_ALIGNMENT, m_alignment).toInt()), false); m_reserveSpace = m_settings->value(CFG_KEY_RESERVESPACE, true).toBool(); - m_lockPanel = m_settings->value(CFG_KEY_LOCKPANEL, false).toBool(); m_settings->endGroup(); } - -/************************************************ - - ************************************************/ void UKUIPanel::saveSettings(bool later) { mDelaySave.stop(); @@ -367,19 +425,15 @@ m_settings->setValue(CFG_KEY_PERCENT, m_lengthInPercents); m_settings->setValue(CFG_KEY_SCREENNUM, m_screenNum); -// mSettings->setValue(CFG_KEY_POSITION, positionToStr(mPosition)); m_settings->setValue(CFG_KEY_ALIGNMENT, m_alignment); m_settings->setValue(CFG_KEY_RESERVESPACE, m_reserveSpace); - m_settings->setValue(CFG_KEY_HIDABLE, m_hidable); m_settings->setValue(CFG_KEY_VISIBLE_MARGIN, m_visibleMargin); m_settings->setValue(CFG_KEY_ANIMATION, m_animationTime); m_settings->setValue(CFG_KEY_SHOW_DELAY, m_showDelayTimer.interval()); - m_settings->setValue(CFG_KEY_LOCKPANEL, m_lockPanel); - m_settings->endGroup(); } @@ -387,15 +441,17 @@ /*确保任务栏在调整分辨率和增加·屏幕之后能保持显示正常*/ void UKUIPanel::ensureVisible() { - if (!canPlacedOn(m_screenNum, m_position)) - setPosition(findAvailableScreen(m_position), m_position, false); - else - m_actualScreenNum = m_screenNum; + m_actualScreenNum = m_screenNum; // the screen size might be changed realign(); } - +void UKUIPanel::primaryChangedSlot(int x, int y, int w, int h, int r) +{ + qDebug() << " primaryChanged from USD " << x << y << w << h << r; + m_primaryScreenGeometry = QRect(x, y, w, h); + realign(); +} UKUIPanel::~UKUIPanel() { @@ -508,136 +564,121 @@ realign(); } -/* - The setting frame of the old panel does not follow the main screen - but can be displayed on any screen - but the current desktop environment of ukui is set to follow the main screen - All default parameters desktop()->screenGeometry are 0 - */ -void UKUIPanel::setPanelGeometry(bool animate) +QRect UKUIPanel::caculPanelGeometry(QRect primaryscreen) { - QRect currentScreen; QRect rect; - - currentScreen=QGuiApplication::screens().at(0)->geometry(); - if (isHorizontal()) { rect.setHeight(qMax(PANEL_MINIMUM_SIZE, m_panelSize)); - if (m_lengthInPercents) - rect.setWidth(currentScreen.width() * m_length / 100.0); - else{ - if (m_length <= 0) - rect.setWidth(currentScreen.width() + m_length); - else - rect.setWidth(m_length); - } - rect.setWidth(qMax(rect.size().width(), m_layout->minimumSize().width())); - - // Horiz ...................... - switch (m_alignment) - { - case UKUIPanel::AlignmentLeft: - rect.moveLeft(currentScreen.left()); - break; - - case UKUIPanel::AlignmentCenter: - rect.moveCenter(currentScreen.center()); - break; - - case UKUIPanel::AlignmentRight: - rect.moveRight(currentScreen.right()); - break; - } + rect.setWidth(primaryscreen.width()); + rect.setWidth(qMax(rect.size().width(), m_layout->minimumSize().width())); - // Vert ....................... + // Horiz panel*************************** if (m_position == IUKUIPanel::PositionTop) { - if (m_hidden) - rect.moveBottom(currentScreen.top() + PANEL_HIDE_SIZE); - else - rect.moveTop(currentScreen.top()); + if (m_hidden) { + rect.moveBottom(primaryscreen.top() + PANEL_HIDE_SIZE); + rect.setX(primaryscreen.x()); + rect.setY(primaryscreen.y() - rect.height() + PANEL_HIDE_SIZE); + + }else { + rect.moveTop(primaryscreen.top()); + rect.setX(primaryscreen.x()); + rect.setY(primaryscreen.y()); + rect.setWidth(primaryscreen.width()); + } } else { - if (m_hidden) - rect.moveTop(currentScreen.bottom() - PANEL_HIDE_SIZE); - else - rect.moveBottom(currentScreen.bottom()); + if (m_hidden) { + rect.moveTop(primaryscreen.bottom() - PANEL_HIDE_SIZE); + rect.setX(primaryscreen.x()); + rect.setY(primaryscreen.y() + primaryscreen.height() - PANEL_HIDE_SIZE); + }else { + rect.moveBottom(primaryscreen.bottom()); + rect.setX(primaryscreen.x()); + rect.setY(primaryscreen.y() + primaryscreen.height() - m_panelSize); + rect.setWidth(primaryscreen.width()); + } } - qDebug()<<"ukui-panel Rect is :"<<rect; } else { // Vert panel *************************** rect.setWidth(qMax(PANEL_MINIMUM_SIZE, m_panelSize)); - if (m_lengthInPercents) - rect.setHeight(currentScreen.height() * m_length / 100.0); - else { - if (m_length <= 0) - rect.setHeight(currentScreen.height() + m_length); - else - rect.setHeight(m_length); - } - + rect.setHeight(primaryscreen.height()); rect.setHeight(qMax(rect.size().height(), m_layout->minimumSize().height())); - // Vert ....................... - switch (m_alignment) - { - case UKUIPanel::AlignmentLeft: - rect.moveTop(currentScreen.top()); - break; - - case UKUIPanel::AlignmentCenter: - rect.moveCenter(currentScreen.center()); - break; - - case UKUIPanel::AlignmentRight: - rect.moveBottom(currentScreen.bottom()); - break; - } - - // Horiz ...................... if (m_position == IUKUIPanel::PositionLeft) { - if (m_hidden) - rect.moveRight(currentScreen.left() + PANEL_HIDE_SIZE); - else - rect.moveLeft(currentScreen.left()); + if (m_hidden) { + rect.moveRight(primaryscreen.left() + PANEL_HIDE_SIZE); + rect.setX(primaryscreen.x() - rect.width() + PANEL_HIDE_SIZE); + rect.setY(primaryscreen.y()); + }else { + rect.moveLeft(primaryscreen.left()); + rect.setX(primaryscreen.x()); + rect.setY(primaryscreen.y()); + rect.setHeight(primaryscreen.height()); + } } else { - if (m_hidden) - rect.moveLeft(currentScreen.right() - PANEL_HIDE_SIZE); - else - rect.moveRight(currentScreen.right()); + if (m_hidden) { + rect.moveLeft(primaryscreen.right() - PANEL_HIDE_SIZE); + rect.setX(primaryscreen.x() + primaryscreen.width() - PANEL_HIDE_SIZE); + rect.setY(primaryscreen.y()); + }else { + rect.moveRight(primaryscreen.right()); + rect.setX(primaryscreen.x() + primaryscreen.width() - m_panelSize); + rect.setY(primaryscreen.y()); + rect.setHeight(primaryscreen.height()); + } } } + qDebug()<<"ukui-panel Rect is :"<<rect; + return rect; +} + +/* + The setting frame of the old panel does not follow the main screen + but can be displayed on any screen + but the current desktop environment of ukui is set to follow the main screen + All default parameters desktop()->screenGeometry are 0 + */ +void UKUIPanel::setPanelGeometry(bool animate) +{ + QRect rect = caculPanelGeometry(m_primaryScreenGeometry); if (rect != geometry()) { setFixedSize(rect.size()); - if (animate) { - if (m_animation == nullptr) { - m_animation = new QPropertyAnimation(this, "geometry"); - m_animation->setEasingCurve(QEasingCurve::Linear); - //Note: for hiding, the margins are set after animation is finished - connect(m_animation, &QAbstractAnimation::finished, [this] { if (m_hidden) setMargins(); }); - } - m_animation->setDuration(m_animationTime); - m_animation->setStartValue(geometry()); - m_animation->setEndValue(rect); - //Note: for showing-up, the margins are removed instantly - if (!m_hidden) - setMargins(); - m_animation->start(); + if (animate && !m_isWaylandEnv) { + setPanelAnimation(geometry(), rect); } else { setMargins(); - setGeometry(rect); + kdk::WindowManager::setGeometry(this->windowHandle(), rect); } } QDBusMessage message =QDBusMessage::createSignal("/panel/position", "org.ukui.panel", "UKuiPanelPosition"); QList<QVariant> args; - args.append(currentScreen.x()); - args.append(currentScreen.y()); - args.append(currentScreen.width()); - args.append(currentScreen.height()); + args.append(m_primaryScreenGeometry.x()); + args.append(m_primaryScreenGeometry.y()); + args.append(m_primaryScreenGeometry.width()); + args.append(m_primaryScreenGeometry.height()); args.append(panelSize()); args.append(m_gsettings->get(PANEL_POSITION_KEY).toInt()); message.setArguments(args); QDBusConnection::sessionBus().send(message); } +void UKUIPanel::setPanelAnimation(QRect startrect, QRect endrect) +{ + if (m_animation == nullptr) { + m_animation = new QPropertyAnimation(this, "geometry"); + m_animation->setEasingCurve(QEasingCurve::Linear); + //Note: for hiding, the margins are set after animation is finished + connect(m_animation, &QAbstractAnimation::finished, [this] { if (m_hidden) setMargins(); }); + } + m_animation->setDuration(m_animationTime); + m_animation->setStartValue(startrect); + m_animation->setEndValue(endrect); + //Note: for showing-up, the margins are removed instantly + if (!m_hidden) { + setMargins(); + } + m_animation->start(); +} + /*设置边距*/ void UKUIPanel::setMargins() { @@ -674,16 +715,6 @@ emit realigned(); if (!isVisible()) return; -#if 0 - qDebug() << "** Realign *********************"; - qDebug() << "PanelSize: " << mPanelSize; - qDebug() << "IconSize: " << mIconSize; - qDebug() << "LineCount: " << mLineCount; - qDebug() << "Length: " << mLength << (mLengthInPercents ? "%" : "px"); - qDebug() << "Alignment: " << (mAlignment == 0 ? "center" : (mAlignment < 0 ? "left" : "right")); - qDebug() << "Position: " << positionToStr(mPosition) << "on" << mScreenNum; - qDebug() << "Plugins count: " << mPlugins.count(); -#endif setPanelGeometry(); @@ -709,6 +740,7 @@ // So, we use the geometry of the whole screen to calculate the strut rather than using the geometry of individual monitors. // Though the spec only mention Xinerama and did not mention XRandR, the rule should still be applied. // At least openbox is implemented like this. + switch (m_position) { case UKUIPanel::PositionTop: @@ -760,209 +792,6 @@ } -/************************************************ - The panel can't be placed on boundary of two displays. - This function checks if the panel can be placed on the display - @screenNum on @position. - ************************************************/ -bool UKUIPanel::canPlacedOn(int screenNum, UKUIPanel::Position position) -{ - QDesktopWidget* dw = QApplication::desktop(); - - switch (position) - { - case UKUIPanel::PositionTop: - for (int i = 0; i < dw->screenCount(); ++i) - if (dw->screenGeometry(i).bottom() < dw->screenGeometry(screenNum).top()) - return false; - return true; - - case UKUIPanel::PositionBottom: - for (int i = 0; i < dw->screenCount(); ++i) - if (dw->screenGeometry(i).top() > dw->screenGeometry(screenNum).bottom()) - return false; - return true; - - case UKUIPanel::PositionLeft: - for (int i = 0; i < dw->screenCount(); ++i) - if (dw->screenGeometry(i).right() < dw->screenGeometry(screenNum).left()) - return false; - return true; - - case UKUIPanel::PositionRight: - for (int i = 0; i < dw->screenCount(); ++i) - if (dw->screenGeometry(i).left() > dw->screenGeometry(screenNum).right()) - return false; - return true; - } - - return false; -} - - -/************************************************ - - ************************************************/ -int UKUIPanel::findAvailableScreen(UKUIPanel::Position position) -{ - int current = m_screenNum; - - for (int i = current; i < QApplication::desktop()->screenCount(); ++i) - if (canPlacedOn(i, position)) - return i; - - for (int i = 0; i < current; ++i) - if (canPlacedOn(i, position)) - return i; - - return 0; -} - -/*右键 系统监视器选项*/ -void UKUIPanel::systeMonitor() -{ - QProcess *process =new QProcess(this); - process->startDetached("/usr/bin/ukui-system-monitor"); - process->deleteLater(); -} - -/*任务栏大小和方向的调整*/ -void UKUIPanel::adjustPanel() -{ - QAction *pmenuaction_s; - QAction *pmenuaction_m; - QAction *pmenuaction_l; - - pmenuaction_s=new QAction(this); - pmenuaction_s->setText(tr("Small")); - pmenuaction_m=new QAction(this); - pmenuaction_m->setText(tr("Medium")); - pmenuaction_l=new QAction(this); - pmenuaction_l->setText(tr("Large")); - - - QMenu *pmenu_panelsize; - pmenu_panelsize=new QMenu(this); - pmenu_panelsize->setTitle(tr("Adjustment Size")); - pmenu_panelsize->addAction(pmenuaction_s); - pmenu_panelsize->addAction(pmenuaction_m); - pmenu_panelsize->addAction(pmenuaction_l); - pmenu_panelsize->setWindowOpacity(0.9); - m_menu->addMenu(pmenu_panelsize); - - pmenuaction_s->setCheckable(true); - pmenuaction_m->setCheckable(true); - pmenuaction_l->setCheckable(true); - pmenuaction_s->setChecked(m_gsettings->get(PANEL_SIZE_KEY).toInt()==PANEL_SIZE_SMALL); - pmenuaction_m->setChecked(m_gsettings->get(PANEL_SIZE_KEY).toInt()==PANEL_SIZE_MEDIUM); - pmenuaction_l->setChecked(m_gsettings->get(PANEL_SIZE_KEY).toInt()==PANEL_SIZE_LARGE); - - connect(pmenuaction_s,&QAction::triggered,[this] { - m_gsettings->set(PANEL_SIZE_KEY,PANEL_SIZE_SMALL); - m_gsettings->set(ICON_SIZE_KEY,ICON_SIZE_SMALL); - setIconSize(ICON_SIZE_SMALL,true); - }); - connect(pmenuaction_m,&QAction::triggered,[this] { - m_gsettings->set(PANEL_SIZE_KEY,PANEL_SIZE_MEDIUM); - m_gsettings->set(ICON_SIZE_KEY,ICON_SIZE_MEDIUM); - setIconSize(ICON_SIZE_MEDIUM,true); - }); - connect(pmenuaction_l,&QAction::triggered,[this] { - m_gsettings->set(PANEL_SIZE_KEY,PANEL_SIZE_LARGE); - m_gsettings->set(ICON_SIZE_KEY,ICON_SIZE_LARGE); - setIconSize(ICON_SIZE_LARGE,true); - }); - pmenu_panelsize->setDisabled(m_lockPanel); - - QAction *pmenuaction_top; - QAction *pmenuaction_bottom; - QAction *pmenuaction_left; - QAction *pmenuaction_right; - pmenuaction_top=new QAction(this); - pmenuaction_top->setText(tr("Up")); - pmenuaction_bottom=new QAction(this); - pmenuaction_bottom->setText(tr("Bottom")); - pmenuaction_left=new QAction(this); - pmenuaction_left->setText(tr("Left")); - pmenuaction_right=new QAction(this); - pmenuaction_right->setText(tr("Right")); - QMenu *pmenu_positon; - pmenu_positon=new QMenu(this); - pmenu_positon->setTitle(tr("Adjustment Position")); - pmenu_positon->addAction(pmenuaction_top); - pmenu_positon->addAction(pmenuaction_bottom); - pmenu_positon->addAction(pmenuaction_left); - pmenu_positon->addAction(pmenuaction_right); - m_menu->addMenu(pmenu_positon); - - pmenuaction_top->setCheckable(true); - pmenuaction_bottom->setCheckable(true); - pmenuaction_left->setCheckable(true); - pmenuaction_right->setCheckable(true); - pmenuaction_top->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==1); - pmenuaction_bottom->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==0); - pmenuaction_left->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==2); - pmenuaction_right->setChecked(m_gsettings->get(PANEL_POSITION_KEY).toInt()==3); - - - connect(pmenuaction_top,&QAction::triggered, [this] { setPosition(0,PositionTop,true);}); - connect(pmenuaction_bottom,&QAction::triggered, [this] { setPosition(0,PositionBottom,true);}); - connect(pmenuaction_left,&QAction::triggered, [this] { setPosition(0,PositionLeft,true);}); - connect(pmenuaction_right,&QAction::triggered, [this] { setPosition(0,PositionRight,true);}); - pmenu_positon->setWindowOpacity(0.9); - pmenu_positon->setDisabled(m_lockPanel); - - - m_settings->beginGroup(m_configGroup); - QAction * hidepanel = m_menu->addAction(tr("Hide Panel")); - hidepanel->setDisabled(m_lockPanel); - hidepanel->setCheckable(true); - hidepanel->setChecked(m_hidable); - connect(hidepanel, &QAction::triggered, [this] { - m_settings->beginGroup(m_configGroup); - m_hidable = m_settings->value(CFG_KEY_HIDABLE, m_hidable).toBool(); - m_settings->endGroup(); - if(m_hidable) - m_hideTimer.stop(); - setHidable(!m_hidable,true); - m_hidden = m_hidable; - m_showDelayTimer.start(); - m_time->start(1000); - }); - m_settings->endGroup(); -} -/*右键 显示桌面选项*/ -void UKUIPanel::showDesktop() -{ - KWindowSystem::setShowingDesktop(!KWindowSystem::showingDesktop()); -} - -/*右键 显示任务视图 选项*/ -void UKUIPanel::showTaskView() -{ -// system("ukui-window-switch --show-workspace"); - if(m_gsettings->keys().contains(SHOW_TASKVIEW)) { - if(m_gsettings->get(SHOW_TASKVIEW).toBool()) { - m_gsettings->set(SHOW_TASKVIEW,false); - } else { - m_gsettings->set(SHOW_TASKVIEW,true); - } - } -} - -/*右键 显示夜间模式按钮 选项*/ -void UKUIPanel::showNightModeButton() -{ -// system("ukui-window-switch --show-workspace"); - if(m_gsettings->keys().contains(SHOW_NIGHTMODE)) { - if(m_gsettings->get(SHOW_NIGHTMODE).toBool()) { - m_gsettings->set(SHOW_NIGHTMODE,false); - } else { - m_gsettings->set(SHOW_NIGHTMODE,true); - } - } -} - /*设置任务栏高度*/ void UKUIPanel::setPanelSize(int value, bool save) { @@ -1004,10 +833,6 @@ } } - -/************************************************ - - ************************************************/ void UKUIPanel::setLength(int length, bool inPercents, bool save) { if (m_length == length && @@ -1023,10 +848,6 @@ realign(); } - -/************************************************ - - ************************************************/ void UKUIPanel::setPosition(int screen, IUKUIPanel::Position position, bool save) { if (m_screenNum == screen && @@ -1068,9 +889,6 @@ setPanelGeometry(true); } -/************************************************ - * - ************************************************/ void UKUIPanel::setAlignment(Alignment value, bool save) { if (m_alignment == value) @@ -1149,10 +967,6 @@ return QFrame::event(event); } -/************************************************ - - ************************************************/ - void UKUIPanel::showEvent(QShowEvent *event) { QFrame::showEvent(event); @@ -1189,19 +1003,15 @@ } } -/* 使用paintEvent 对panel进行绘制的时候有如下问题: - * 1.绘制速度需要鼠标事件触发,明显的切换不流畅 - * 2.部分区域绘制不能生效,调整任务栏高度之后才能生效 - */ - void UKUIPanel::paintEvent(QPaintEvent *) { QStyleOption opt; opt.init(this); QPainter p(this); - p.setPen(Qt::NoPen); -// p.setBrush(QBrush(QColor(19,22,28,transparency))); - QColor color= palette().color(QPalette::Base); + QColor col= palette().color(QPalette::BrightText); + col.setAlphaF(0.15); + p.setPen(col); + QColor color= palette().color(QPalette::Window); color.setAlpha(m_transparency); QBrush brush = QBrush(color); p.setBrush(brush); @@ -1211,134 +1021,11 @@ style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } - -/*Right-Clicked Menu of ukui-panel - * it's a Popup Menu -*/ -void UKUIPanel::showPopupMenu(Plugin *plugin) +void UKUIPanel::showPopupMenu() { - m_menu = new QMenu(this); + m_menu = new ContextMenu(this); m_menu->setAttribute(Qt::WA_DeleteOnClose); - /* @new features - * //Plugin Menu 负责显示插件的菜单项,ukui3.0的设计暂时不需要插件菜单项 - * 关于后续的插件右键菜单的详细调整 - * 如果需要在任务栏菜单项上面添加 插件的菜单选项就放开此功能 - * 放开此功能可以丰富插件右键菜单,windows是这样做的 - */ - if (plugin) { - QMenu *m = plugin->popupMenu(); - - if (m) { - //menu->addTitle(plugin->windowTitle()); - const auto actions = m->actions(); - for (auto const & action : actions) { - action->setParent(m_menu); - action->setDisabled(m_lockPanel); - m_menu->addAction(action); - } - delete m; - } - } - - m_menu->addSeparator(); - - QAction * showtaskview = m_menu->addAction(tr("Show Taskview")); - showtaskview->setCheckable(true); - showtaskview->setChecked(m_gsettings->get(SHOW_TASKVIEW).toBool()); - connect(showtaskview, &QAction::triggered, [this] { showTaskView(); }); - - QString filename = QDir::homePath() + "/.config/ukui/panel-commission.ini"; - QSettings m_settings(filename, QSettings::IniFormat); - m_settings.setIniCodec("UTF-8"); - - m_settings.beginGroup("NightMode"); - QString nightmode_action = m_settings.value("nightmode", "").toString(); - if (nightmode_action.isEmpty()) { - nightmode_action = "show"; - } - m_settings.endGroup(); - - if(nightmode_action == "show") { - QAction * shownightmode = m_menu->addAction(tr("Show Nightmode")); - shownightmode->setCheckable(true); - shownightmode->setChecked(m_gsettings->get(SHOW_NIGHTMODE).toBool()); - connect(shownightmode, &QAction::triggered, [this] { showNightModeButton(); }); - } - - m_menu->addAction(tr("Show Desktop"), - this, SLOT(showDesktop()) - ); - - m_menu->addSeparator(); - - if(QFileInfo::exists(QString("/usr/bin/ukui-system-monitor"))) { - m_menu->addAction(tr("Show System Monitor"), - this, SLOT(systeMonitor()) - ); - } - - m_menu->addSeparator(); - - adjustPanel(); - - /* - UKUIPanelApplication *a = reinterpret_cast<UKUIPanelApplication*>(qApp); - menu->addAction(XdgIcon::fromTheme(QLatin1String("list-add")), - tr("Add New Panel"), - a, SLOT(addNewPanel()) - ); - - - if (a->count() > 1) - { - menu->addAction(XdgIcon::fromTheme(QLatin1String("list-remove")), - tr("Remove Panel", "Menu Item"), - this, SLOT(userRequestForDeletion()) - )->setDisabled(mLockPanel); - } -*/ - m_lockAction = m_menu->addAction(tr("Lock This Panel")); - m_lockAction->setCheckable(true); - m_lockAction->setChecked(m_lockPanel); - connect(m_lockAction, &QAction::triggered, [this] { m_lockPanel = !m_lockPanel; saveSettings(false); }); - - //Hidden features, lock the panel - /* - menu->addAction(XdgIcon::fromTheme(QLatin1String("configure")), - tr("Reset Panel"), - this, SLOT(panelReset()) - )->setDisabled(mLockPanel); -*/ - - QAction *about; - about=new QAction(this); - about->setText(tr("About Kylin")); - m_menu->addAction(about); - connect(about,&QAction::triggered, [this] { - QProcess *process =new QProcess(this); - process->start( - "bash", - QStringList() << "-c" - << "dpkg -l | grep ukui-control-center"); - process->waitForFinished(); - QString strResult = process->readAllStandardOutput() + process->readAllStandardError(); - if (-1 != strResult.indexOf("3.0")) { - QProcess::startDetached(QString("ukui-control-center -a")); - } else { - QProcess::startDetached(QString("ukui-control-center -m About")); - } - }); - -#ifdef DEBUG - menu->addSeparator(); - menu->addAction("Exit (debug only)", qApp, SLOT(quit())); -#endif - - /* Note: in multihead & multipanel setup the QMenu::popup/exec places the window - * sometimes wrongly (it seems that this bug is somehow connected to misinterpretation - * of QDesktopWidget::availableGeometry) - */ m_menu->setGeometry(calculatePopupWindowPos(QCursor::pos(), m_menu->sizeHint())); willShowWindow(m_menu); m_menu->show(); @@ -1353,9 +1040,6 @@ return nullptr; } -/************************************************ - - ************************************************/ QRect UKUIPanel::calculatePopupWindowPos(QPoint const & absolutePos, QSize const & windowSize) const { int x = absolutePos.x(), y = absolutePos.y(); @@ -1470,13 +1154,11 @@ void UKUIPanel::hidePanelWork() { - if (!geometry().contains(QCursor::pos())) { - if (!m_standaloneWindows->isAnyWindowShown()) { - m_hidden = true; - setPanelGeometry(m_animationTime > 0); - } else { - m_hideTimer.start(); - } + if (!m_standaloneWindows->isAnyWindowShown()) { + m_hidden = true; + setPanelGeometry(m_animationTime > 0); + } else { + m_hideTimer.start(); } QDBusMessage message =QDBusMessage::createSignal("/panel", "org.ukui.panel.settings", "PanelHided"); QDBusConnection::sessionBus().send(message); @@ -1559,10 +1241,12 @@ if(key == "ukui-panel") { m_settings->beginGroup(m_configGroup); m_settings->sync(); - m_lockPanel = m_settings->value(CFG_KEY_LOCKPANEL).toBool(); + if (m_gsettingsKeys.contains(LOCK_PANEL_KEY)) { + m_lockPanel = m_gsettings->get(LOCK_PANEL_KEY).toBool(); + } else { + m_lockPanel = false; + } m_settings->endGroup(); -// if(m_lockAction!=nullptr) -// m_lockAction->setChecked(mLockPanel); } } @@ -1576,14 +1260,17 @@ IUKUIPanel::Position UKUIPanel::areaDivid(QPoint globalpos) { int x = globalpos.rx(); int y = globalpos.ry(); + int x_0 = QApplication::screens().at(0)->geometry().x(); + int y_0 = QApplication::screens().at(0)->geometry().y(); float W = QApplication::screens().at(0)->size().width(); float H = QApplication::screens().at(0)->size().height(); float slope = H / W; - if ((x < 100 || x > W - 100) && (y > H - 100 || y < 100)) return m_position; - if (y > (int)(x * slope) && y > (int)(H - x * slope)) return PositionBottom; - if (y > (int)(x * slope) && y < (int)(H - x * slope)) return PositionLeft; - if (y < (int)(x * slope) && y < (int)(H - x * slope)) return PositionTop; - if (y < (int)(x * slope) && y > (int)(H - x * slope)) return PositionRight; + if ((x - x_0 < 100 || x -x_0 > W - 100) && (y - y_0 > H - 100 || y - y_0 < 100)) return m_position; + if ((y - y_0) > (int)((x - x_0) * slope) && (y - y_0) > (int)(H - (x - x_0) * slope)) return PositionBottom; + if ((y - y_0) > (int)((x - x_0) * slope) && (y - y_0) < (int)(H - (x - x_0) * slope)) return PositionLeft; + if ((y - y_0) < (int)((x - x_0) * slope) && (y - y_0) < (int)(H - (x - x_0) * slope)) return PositionTop; + if ((y - y_0) < (int)((x - x_0) * slope) && (y - y_0) > (int)(H - (x - x_0) * slope)) return PositionRight; + } @@ -1605,8 +1292,10 @@ if (panel_h <= PANEL_SIZE_LARGE && panel_h >= PANEL_SIZE_SMALL) { setPanelSize(panel_h, true); setIconSize(icon_size, true); - m_gsettings->set(PANEL_SIZE_KEY, panel_h); - m_gsettings->set(ICON_SIZE_KEY, icon_size); + if (m_gsettingsKeys.contains(PANEL_SIZE_KEY) && m_gsettingsKeys.contains(ICON_SIZE_KEY)) { + m_gsettings->set(PANEL_SIZE_KEY, panel_h); + m_gsettings->set(ICON_SIZE_KEY, icon_size); + } } return; } @@ -1625,3 +1314,5 @@ emit realigned(); m_moveLock = -1; } + + diff -Nru ukui-panel-3.14.0.1/panel/ukuipanel.h ukui-panel-4.0.0.0/panel/ukuipanel.h --- ukui-panel-3.14.0.1/panel/ukuipanel.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/ukuipanel.h 2023-05-23 15:58:00.000000000 +0800 @@ -40,6 +40,10 @@ #include "common/ukuisettings.h" #include "iukuipanel.h" #include "ukuipanelglobals.h" +#include "contextmenu.h" +#include <KF5/KScreen/kscreen/config.h> +#include <KF5/KScreen/kscreen/getconfigoperation.h> + class QMenu; class Plugin; @@ -50,7 +54,6 @@ class PluginInfo; } class UKUIPanelLayout; -class ConfigPanelDialog; class PanelPluginsModel; class WindowNotifier; @@ -83,13 +86,11 @@ Q_CLASSINFO("D-Bus Interface", "org.ukui.panel.settings") - // for configuration dialog - friend class ConfigPanelWidget; - friend class ConfigPluginsWidget; - friend class ConfigPanelDialog; friend class PanelPluginsModel; public: + void configWatch(KScreen::ConfigOperation *op); + QRect m_primaryScreenGeometry; /** * @brief Stores how the panel should be aligned. Obviously, this applies * only if the panel does not occupy 100 % of the available space. If the @@ -142,7 +143,7 @@ * @param plugin The plugin whose menu options will be included in the * context menu. */ - void showPopupMenu(Plugin *plugin = 0); + void showPopupMenu(); // IUKUIPanel overrides ........ IUKUIPanel::Position position() const override { return m_position; } @@ -168,25 +169,6 @@ */ Plugin *findPlugin(const IUKUIPanelPlugin *iPlugin) const; - - /** - * @brief Checks if this UKUIPanel can be placed at a given position - * on the screen with the given screenNum. The condition for doing so - * is that the panel is not located between two screens. - * - * For example, if position is PositionRight, there should be no screen to - * the right of the given screen. That means that there should be no - * screen whose left border has a higher x-coordinate than the x-coordinate - * of the right border of the given screen. This method iterates over all - * screens and checks these conditions. - * @param screenNum screen index as it is used by QDesktopWidget methods - * @param position position where the panel should be placed - * @return true if this panel can be placed at the given position on the - * given screen. - * - * \sa findAvailableScreen(), mScreenNum, mActualScreenNum. - */ - static bool canPlacedOn(int screenNum, UKUIPanel::Position position); /** * @brief Returns a string representation of the given position. This * string is human-readable and can be used in config files. @@ -222,7 +204,6 @@ int screenNum() const { return m_screenNum; } QColor fontColor() const { return m_fontColor; } int reserveSpace() const { return m_reserveSpace; } - bool hidable() const { return m_hidable; } bool visibleMargin() const { return m_visibleMargin; } int animationTime() const { return m_animationTime; } int showDelay() const { return m_showDelayTimer.interval(); } @@ -242,7 +223,7 @@ */ // void updateConfigDialog() const; -public slots: +public Q_SLOTS: /** * @brief Shows the QWidget and makes it visible on all desktops. This * method is NOT related to showPanel(), hidePanel() and hidePanelWork() @@ -320,8 +301,9 @@ * where the desired position is possible. */ void ensureVisible(); + void primaryChangedSlot(int x, int y, int w, int h, int r); -signals: +Q_SIGNALS: /** * @brief This signal gets emitted whenever this panel receives a * QEvent::LayoutRequest, i.e. "Widget layout needs to be redone.". @@ -384,7 +366,7 @@ void mouseReleaseEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent *event); -public slots: +public Q_SLOTS: /** * @brief Shows the ConfigPanelDialog and shows the "Config Panel" * page, i.e. calls showConfigPanelPage(). If the dialog does not @@ -401,7 +383,7 @@ */ // void showConfigDialog(); -private slots: +private Q_SLOTS: /** * @brief Shows the ConfigPanelDialog and shows the "Config Plugins" * page, i.e. calls showConfigPluginsPage(). If the dialog does not @@ -422,11 +404,6 @@ * 2. UKUi::Application::themeChanged(), i.e. when the user changes * the theme. */ - void systeMonitor(); - void showDesktop(); - void showTaskView(); - void showNightModeButton(); - void adjustPanel(); void realign(); /** * @brief Moves a plugin in PanelPluginsModel, i.e. calls @@ -437,6 +414,8 @@ */ void pluginMoved(Plugin * plug); private: + KScreen::ConfigPtr m_config; + bool m_isWaylandEnv; /** * @brief The UKUIPanelLayout of this panel. All the Plugins will be added * to the UI via this layout. @@ -469,19 +448,6 @@ * (for preventing hide) */ QScopedPointer<WindowNotifier> m_standaloneWindows; - - /** - * @brief Returns the screen index of a screen on which this panel could - * be placed at the given position. If possible, the current screen index - * is preserved. So, if the panel can be placed on the current screen, the - * index of that screen will be returned. - * @param position position at which the panel should be placed. - * @return The current screen index if the panel can be placed on the - * current screen or the screen index of a screen that it can be placed on. - * - * \sa canPlacedOn(), mScreenNum, mActualScreenNum. - */ - int findAvailableScreen(UKUIPanel::Position position); /** * @brief Update the window manager struts _NET_WM_PARTIAL_STRUT and * _NET_WM_STRUT for this widget. "The purpose of struts is to reserve @@ -512,6 +478,8 @@ * \param animate flag if showing/hiding the panel should be animated. */ void setPanelGeometry(bool animate = false); + QRect caculPanelGeometry(QRect primaryscreen); + void setPanelAnimation(QRect startrect, QRect endrect); /** * @brief Sets the contents margins of the panel according to its position * and hiddenness. All margins are zero for visible panels. @@ -667,9 +635,6 @@ * @brief Pointer to the current ConfigPanelDialog if there is any. Make * sure to test this pointer for validity because it is lazily loaded. */ -// QPointer<ConfigPanelDialog> mConfigDialog; - //ConfigPanelDialog *mConfigDialog; - //QPointer<ConfigPanelWidget> mConfigWidget; /** * @brief The animation used for showing/hiding an auto-hiding panel. @@ -698,7 +663,7 @@ void connectToServer(); -private slots: +private Q_SLOTS: void keyChangedSlot(const QString &key); void priScreenChanged(int x, int y, int width, int height); void setPanelHide(bool model); @@ -706,6 +671,7 @@ public: QGSettings *m_gsettings; + QStringList m_gsettingsKeys; QGSettings *m_transparencyGsettings; QTimer *m_time; diff -Nru ukui-panel-3.14.0.1/panel/ukuipanelapplication.cpp ukui-panel-4.0.0.0/panel/ukuipanelapplication.cpp --- ukui-panel-3.14.0.1/panel/ukuipanelapplication.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/ukuipanelapplication.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -117,14 +117,6 @@ if(panelReset == "replace"){qDebug()<<"ukui-panel --replace";} if(panelReset == "calendar-new"){system("/usr/share/ukui/ukui-panel/ukui-panel-config.sh calendar new && killall ukui-panel");} if(panelReset == "calendar-old"){system("/usr/share/ukui/ukui-panel/ukui-panel-config.sh calendar old && killall ukui-panel");} - - // This is a workaround for Qt 5 bug #40681. - const auto allScreens = screens(); - for(QScreen* screen : allScreens) - { - connect(screen, &QScreen::destroyed, this, &UKUIPanelApplication::screenDestroyed); - } - connect(this, &QGuiApplication::screenAdded, this, &UKUIPanelApplication::handleScreenAdded); connect(this, &QCoreApplication::aboutToQuit, this, &UKUIPanelApplication::cleanup); @@ -182,68 +174,6 @@ return panel; } -void UKUIPanelApplication::handleScreenAdded(QScreen* newScreen) -{ - // qDebug() << "UKUIPanelApplication::handleScreenAdded" << newScreen; - connect(newScreen, &QScreen::destroyed, this, &UKUIPanelApplication::screenDestroyed); -} - - -void UKUIPanelApplication::screenDestroyed(QObject* screenObj) -{ - // NOTE by PCMan: This is a workaround for Qt 5 bug #40681. - // With this very dirty workaround, we can fix ukui/ukui bug #204, #205, and #206. - // Qt 5 has two new regression bugs which breaks ukui-panel in a multihead environment. - // #40681: Regression bug: QWidget::winId() returns old value and QEvent::WinIdChange event is not emitted sometimes. (multihead setup) - // #40791: Regression: QPlatformWindow, QWindow, and QWidget::winId() are out of sync. - // Explanations for the workaround: - // Internally, Qt mantains a list of QScreens and update it when XRandR configuration changes. - // When the user turn off an monitor with xrandr --output <xxx> --off, this will destroy the QScreen - // object which represent the output. If the QScreen being destroyed contains our panel widget, - // Qt will call QWindow::setScreen(0) on the internal windowHandle() of our panel widget to move it - // to the primary screen. However, moving a window to a different screen is more than just changing - // its position. With XRandR, all screens are actually part of the same virtual desktop. However, - // this is not the case in other setups, such as Xinerama and moving a window to another screen is - // not possible unless you destroy the widget and create it again for a new screen. - // Therefore, Qt destroy the widget and re-create it when moving our panel to a new screen. - // Unfortunately, destroying the window also destroy the child windows embedded into it, - // using XEMBED such as the tray icons. (#206) - // Second, when the window is re-created, the winId of the QWidget is changed, but Qt failed to - // generate QEvent::WinIdChange event so we have no way to know that. We have to set - // some X11 window properties using the native winId() to make it a dock, but this stop working - // because we cannot get the correct winId(), so this causes #204 and #205. - // - // The workaround is very simple. Just completely destroy the panel before Qt has a chance to do - // QWindow::setScreen() for it. Later, we reload the panel ourselves. So this can bypassing the Qt bugs. - QScreen* screen = static_cast<QScreen*>(screenObj); - bool reloadNeeded = false; - qApp->setQuitOnLastWindowClosed(false); -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - for(int i=0;i<m_panels.size();i++){ - UKUIPanel *panel=m_panels[i]; -#endif -#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0)) - for(UKUIPanel* panel : qAsConst(m_panels)){ -#endif - QWindow* panelWindow = panel->windowHandle(); - if(panelWindow && panelWindow->screen() == screen) - { - // the screen containing the panel is destroyed - // delete and then re-create the panel ourselves - QString name = panel->name(); - panel->saveSettings(false); - delete panel; // delete the panel, so Qt does not have a chance to set a new screen to it. - m_panels.removeAll(panel); - reloadNeeded = true; - qDebug() << "Workaround Qt 5 bug #40681: delete panel:" << name; - } - } - if(reloadNeeded) - QTimer::singleShot(1000, this, SLOT(reloadPanelsAsNeeded())); - else - qApp->setQuitOnLastWindowClosed(true); -} - bool UKUIPanelApplication::isPluginSingletonAndRunnig(QString const & pluginId) const { for (auto const & panel : m_panels) diff -Nru ukui-panel-3.14.0.1/panel/ukuipanelapplication.h ukui-panel-4.0.0.0/panel/ukuipanelapplication.h --- ukui-panel-3.14.0.1/panel/ukuipanelapplication.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel/ukuipanelapplication.h 2023-05-22 14:06:12.000000000 +0800 @@ -126,20 +126,6 @@ bool copyFileToPath(QString sourceDir ,QString toDir, QString copyFileToPath, bool coverFileIfExist); private slots: - - /*! - * \brief Connects the QScreen::destroyed signal of a new screen to - * the screenDestroyed() slot so that we can handle this screens' - * destruction as soon as it happens. - * \param newScreen The QScreen that was created and added. - */ - void handleScreenAdded(QScreen* newScreen); - /*! - * \brief Handles screen destruction. This is a workaround for a Qt bug. - * For further information, see the implementation notes. - * \param screenObj The QScreen that was destroyed. - */ - void screenDestroyed(QObject* screenObj); /*! * \brief Deletes all UKUIPanel instances that are stored in mPanels. */ diff -Nru ukui-panel-3.14.0.1/panel-daemon/CMakeLists.txt ukui-panel-4.0.0.0/panel-daemon/CMakeLists.txt --- ukui-panel-3.14.0.1/panel-daemon/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel-daemon/CMakeLists.txt 2023-05-22 14:06:12.000000000 +0800 @@ -25,9 +25,9 @@ pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0 udisks2) pkg_check_modules(QGS REQUIRED gsettings-qt) - include_directories(${GLIB2_INCLUDE_DIRS}) include_directories(${QGS_INCLUDE_DIRS}) + add_executable(panel-daemon jsonwathcer/jsonwacther.cpp jsonwathcer/jsonwacther.h @@ -53,7 +53,20 @@ add_definitions(-DQT_MESSAGELOGCONTEXT) -target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::DBus Qt5::Network ${GLIB2_LIBRARIES} ${QGS_LIBRARIES} KF5::WindowSystem) +pkg_check_modules(KYSDKWAYLANDHELPER_PKG kysdk-waylandhelper) +target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDKWAYLANDHELPER_PKG_INCLUDE_DIRS}) +target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDKWAYLANDHELPER_PKG_LIBRARY_DIRS} KF5::WindowSystem) +target_link_libraries(${PROJECT_NAME} ${KYSDKWAYLANDHELPER_PKG_LIBRARIES}) + +target_link_libraries(${PROJECT_NAME} + Qt5::Widgets + Qt5::DBus + Qt5::Network + ${GLIB2_LIBRARIES} + ${QGS_LIBRARIES} + KF5::WindowSystem + ) + install(TARGETS panel-daemon DESTINATION bin) diff -Nru ukui-panel-3.14.0.1/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.cpp ukui-panel-4.0.0.0/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.cpp --- ukui-panel-3.14.0.1/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -20,23 +20,35 @@ #include <QFile> #include <QDebug> #include <QDir> - +#include "kysdk/applications/windowmanager/windowmanager.h" ConvertDesktopToWinId::ConvertDesktopToWinId() { //connect(KWindowSystem::self(), &KWindowSystem::windowAdded, this, &ConvertDesktopToWinId::tranIdToDesktop); } -QString ConvertDesktopToWinId::tranIdToDesktop(WId id) +QString ConvertDesktopToWinId::tranIdToDesktop(int winId) { - QString desktopName = confirmDesktopFile(id); + QString desktopName = confirmDesktopFile(winId); qDebug() << "desktopName is :" << desktopName; return desktopName; } -QString ConvertDesktopToWinId::confirmDesktopFile(WId id) +int ConvertDesktopToWinId::getPidFromInfo(int winId) +{ + //x环境下输入wid转成pid, wayland下windowId转pid + KWindowInfo info(winId, 0, NET::WM2AllProperties); + if (info.valid()) { + m_pid = info.pid(); + } else { + m_pid = kdk::WindowManager::getPid(winId); + } + return m_pid; +} + +QString ConvertDesktopToWinId::confirmDesktopFile(int id) { - KWindowInfo info(id, 0, NET::WM2AllProperties); + m_pid = getPidFromInfo(id); m_desktopfilePath = ""; QDir infoDir(DEKSTOP_FILE_PATH); m_list = infoDir.entryInfoList(); @@ -52,12 +64,11 @@ //第一种方法:比较名字一致性 if (m_desktopfilePath.isEmpty()) { - m_classClass = info.windowClassClass().toLower(); - m_className = info.windowClassName(); + m_className = kdk::WindowManager::getWindowGroup(id); //匹配安卓兼容 if (m_className == "kylin-kmre-window") { - searchAndroidApp(info); + searchAndroidApp(id); return m_desktopfilePath; } @@ -67,7 +78,7 @@ return m_desktopfilePath; } - QFile file(QString("/proc/%1/status").arg(info.pid())); + QFile file(QString("/proc/%1/status").arg(m_pid)); if (file.open(QIODevice::ReadOnly)) { char buf[1024]; qint64 len=file.readLine(buf,sizeof(buf)); @@ -77,15 +88,14 @@ } compareClassName(); } - //第二种方法:获取点击应用时大部分desktop文件名 if (m_desktopfilePath.isEmpty()) { - searchFromEnviron(info); + searchFromEnviron(id); } //第三种方法:比较cmd命令行操作一致性 if (m_desktopfilePath.isEmpty()) { - QFile file(QString("/proc/%1/cmdline").arg(info.pid())); + QFile file(QString("/proc/%1/cmdline").arg(m_pid)); if (file.open(QIODevice::ReadOnly)) { char buf[1024]; qint64 len=file.readLine(buf,sizeof(buf)); @@ -103,14 +113,14 @@ return m_desktopfilePath; } -void ConvertDesktopToWinId::searchAndroidApp(KWindowInfo info) +void ConvertDesktopToWinId::searchAndroidApp(int id) { QDir androidDir(QString(QDir::homePath() + ANDROID_FILE_PATH)); m_androidList = androidDir.entryInfoList(); m_androidList.removeAll(QDir::homePath() + ANDROID_APP_CURRENT); m_androidList.removeAll(QDir::homePath() + ANDROID_APP_UPER); - QFile file(QString("/proc/%1/cmdline").arg(info.pid())); + QFile file(QString("/proc/%1/cmdline").arg(m_pid)); file.open(QIODevice::ReadOnly); QByteArray cmd = file.readAll(); file.close(); @@ -150,9 +160,9 @@ } } -void ConvertDesktopToWinId::searchFromEnviron(KWindowInfo info) +void ConvertDesktopToWinId::searchFromEnviron(int id) { - QFile file("/proc/" + QString::number(info.pid()) + "/environ"); + QFile file("/proc/" + QString::number(m_pid) + "/environ"); file.open(QIODevice::ReadOnly); QByteArray BA = file.readAll(); file.close(); @@ -189,7 +199,7 @@ } path_desktop_name = path_desktop_name.mid(path_desktop_name.lastIndexOf("/") + 1); path_desktop_name = path_desktop_name.left(path_desktop_name.lastIndexOf(".")); - if (path_desktop_name == m_classClass || path_desktop_name == m_className || path_desktop_name == m_statusName) { + if (path_desktop_name == m_className || path_desktop_name == m_statusName) { m_desktopfilePath = fileInfo.filePath(); break; } diff -Nru ukui-panel-3.14.0.1/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.h ukui-panel-4.0.0.0/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.h --- ukui-panel-3.14.0.1/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/panel-daemon/convert-desktop-windowid/convertdesktoptowinid.h 2023-05-22 14:06:12.000000000 +0800 @@ -19,7 +19,6 @@ #ifndef CONVERTDESKTOPTOWINID_H #define CONVERTDESKTOPTOWINID_H -#include "convertdesktoptowinid.h" #include <QObject> #include <KWindowSystem> #include <QDir> @@ -57,7 +56,6 @@ ~ConvertDesktopToWinId(); //QList<int> InfoPidList; QString m_desktopfilePath = nullptr; - QString m_classClass = nullptr; QString m_className = nullptr; QString m_statusName = nullptr; QString m_cmdLine = nullptr; @@ -67,12 +65,13 @@ QFileInfoList m_list; QFileInfoList m_androidList; - QString tranIdToDesktop(WId id); + QString tranIdToDesktop(int winId); + int getPidFromInfo(int winId); private: - QString confirmDesktopFile(WId id); - void searchFromEnviron(KWindowInfo info); - void searchAndroidApp(KWindowInfo info); + QString confirmDesktopFile(int id); + void searchFromEnviron(int id); + void searchAndroidApp(int id); void searchTXeduApp(WId id); void compareClassName(); void compareCmdExec(); @@ -81,6 +80,8 @@ void compareDesktopClass(); void containsName(); QString getDesktopFileName(QString cmd); + + int m_pid; }; #endif // CONVERTDESKTOPTOWINID_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/CMakeLists.txt ukui-panel-4.0.0.0/plugin-calendar/CMakeLists.txt --- ukui-panel-3.14.0.1/plugin-calendar/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/CMakeLists.txt 2023-05-22 14:06:12.000000000 +0800 @@ -6,7 +6,10 @@ endif(CMAKE_COMPILER_IS_GNUCXX) set(HEADERS - ukuicalendar.h + ukuicalendarplugin.h + ukuicalendarwidget.h + calendarbutton.h + calendarbuttontext.h ukuiwebviewdialog.h lunarcalendarwidget/frmlunarcalendarwidget.h lunarcalendarwidget/lunarcalendarinfo.h @@ -16,10 +19,14 @@ lunarcalendarwidget/lunarcalendarwidget.h lunarcalendarwidget/picturetowhite.h lunarcalendarwidget/customstylePushbutton.h + lunarcalendarwidget/calendarcolor.h ) set(SOURCES - ukuicalendar.cpp + ukuicalendarplugin.cpp + ukuicalendarwidget.cpp + calendarbutton.cpp + calendarbuttontext.cpp ukuiwebviewdialog.cpp lunarcalendarwidget/frmlunarcalendarwidget.cpp lunarcalendarwidget/lunarcalendarinfo.cpp @@ -29,6 +36,7 @@ lunarcalendarwidget/lunarcalendarwidget.cpp lunarcalendarwidget/picturetowhite.cpp lunarcalendarwidget/customstylePushbutton.cpp + lunarcalendarwidget/calendarcolor.cpp ) set(UIS @@ -37,17 +45,29 @@ ) find_package(PkgConfig) + pkg_check_modules(Gsetting REQUIRED gsettings-qt) -pkg_check_modules(CALENDAR_DEPS REQUIRED glib-2.0) -include_directories(${CALENDAR_DEPS_INCLUDE_DIRS}) include_directories(${Gsetting_INCLUDE_DIRS}) +pkg_check_modules(CALENDAR_DEPS REQUIRED glib-2.0) +link_libraries(glib-2.0.so) + +pkg_check_modules(KYSDKQTWIDGETS_PKG kysdk-qtwidgets) +include_directories(${KYSDKQTWIDGETS_PKG_INCLUDE_DIRS}) +link_directories(${KYSDKQTWIDGETS_PKG_LIBRARY_DIRS}) +link_libraries(kysdk-qtwidgets.so) + +pkg_check_modules(KYSDKWAYLANDHELPER_PKG kysdk-waylandhelper) +include_directories(${KYSDKWAYLANDHELPER_PKG_INCLUDE_DIRS}) +link_directories(${KYSDKWAYLANDHELPER_PKG_LIBRARY_DIRS}) +link_libraries(kysdk-waylandhelper.so) + + +include_directories(${CALENDAR_DEPS_INCLUDE_DIRS}) ADD_DEFINITIONS(-DQT_NO_KEYWORDS) -link_libraries(glib-2.0.so) include(../cmake/UkuiPluginTranslationTs.cmake) ukui_plugin_translate_ts(${PLUGIN}) - install(DIRECTORY html/ DESTINATION ${PACKAGE_DATA_DIR}/plugin-calendar/html) diff -Nru ukui-panel-3.14.0.1/plugin-calendar/calendarbutton.cpp ukui-panel-4.0.0.0/plugin-calendar/calendarbutton.cpp --- ukui-panel-3.14.0.1/plugin-calendar/calendarbutton.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/calendarbutton.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,297 @@ +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#include "calendarbutton.h" +#include <QStylePainter> +#include <QStyleOptionButton> +#include <QApplication> +#include "kysdk/applications/windowmanager/windowmanager.h" + + +#define ORG_UKUI_STYLE "org.ukui.style" +#define STYLE_NAME "styleName" + +#define HOUR_SYSTEM_CONTROL "org.ukui.control-center.panel.plugins" + +#define DATA_FORMAT "date" //日期格式:yyyy/MM/dd、yyyy-MM-dd +#define TIME_FORMAT "hoursystem" //时间格式:12小时制、24小时制 +#define WEEK_FORMAT "firstday" //一周第一天:星期一、星期日 +#define CALENDAR_FORMAT "calendar" //日历格式:公历-solarlunar、农历-lunar +#define HOUR_SYSTEM_24_Vertical "hh:mm ddd yyyy/MM/dd" +#define HOUR_SYSTEM_12_Horizontal "Ahh:mm ddd yyyy/MM/dd" + +#define SYSTEM_FONT_SET "org.ukui.style" +#define SYSTEM_FONT_SIZE "systemFontSize" +#define SYSTEM_FONT "systemFont" + +#define CALENDAR_BUTTON_WIDTH 120 + +#define KYSDK_TIMERSERVER "com.kylin.kysdk.TimeServer" +#define KYSDK_TIMERPATH "/com/kylin/kysdk/Timer" +#define KYSDK_TIMERINTERFACE "com.kylin.kysdk.TimeInterface" + +#define UKUI_CONTROL_CENTER_SERVER "org.freedesktop.Accounts" +#define UKUI_CONTROL_CENTER_PATH "/org/freedesktop/Accounts/User1000" +#define UKUI_CONTROL_CENTER_INTERFACE "org.freedesktop.Accounts.User" +#define PROPERTIES_NAME "FormatsLocale" +#define US_FORMATS "en_US.UTF-8" +#define ZH_CN_FORMATS "zh_CN.UTF-8" +#define BO_CN_FORMATS "bo_CN.UTF-8" //藏文 + +#define PANEL_SIZE_LARGE 92 +#define PANEL_SIZE_MEDIUM 70 +#define PANEL_SIZE_SMALL 46 +#define PANEL_SIZE_KEY "panelsize" + +CalendarButton::CalendarButton(IUKUIPanelPlugin *plugin, QWidget *parent): + QPushButton(parent), + m_parent(parent), + m_plugin(plugin) +{ + //设置按钮样式和属性 + this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + this->setFlat(true); + /*按钮边距固定0px,尽可能多显示日期信息。CalendarButton不继承ToolButton的原因就是 + 主题框架提供的ToolButton的边距是固定值,无法修改*/ + this->setStyleSheet("padding: 0px;}"); + const QByteArray id(ORG_UKUI_STYLE); + if (QGSettings::isSchemaInstalled(id)) { + m_styleGsettings = new QGSettings(id); + connect(m_styleGsettings, &QGSettings::changed, this, [=] (const QString &key) { + if (key==STYLE_NAME) { + update(); + } + }); + } + this->setToolTip(tr("Time and Date")); + + //初始化时间日期格式相关Gsettings + initTimeGsettings(); + + //初始化系统字体相关Gsetting + initFontGsettings(); + + //使用系统提供的sdk刷新时间显示 + QDBusConnection::systemBus().connect(KYSDK_TIMERSERVER, + KYSDK_TIMERPATH, + KYSDK_TIMERINTERFACE, + "TimeSignal", + this, + SLOT(updateBtnText(QString)) + ); + QDBusConnection::systemBus().connect(KYSDK_TIMERSERVER, + KYSDK_TIMERPATH, + KYSDK_TIMERINTERFACE, + "TimeChangeSignal", + this, + SLOT(updateBtnText(QString)) + ); + + m_listenGsettings = new ListenGsettings(); + QObject::connect(m_listenGsettings,&ListenGsettings::iconsizechanged,[this]{updateBtnText(QString());}); + QObject::connect(m_listenGsettings,&ListenGsettings::panelpositionchanged,[this]{updateBtnText(QString());}); + + //更新日历按钮内容 + updateBtnText(QString()); +} + +CalendarButton::~CalendarButton() +{ + if(m_styleGsettings) { + m_styleGsettings->deleteLater(); + } + if(m_timeGsettings) { + m_timeGsettings->deleteLater(); + } + if(m_fontGsettings) { + m_fontGsettings->deleteLater(); + } + if(m_listenGsettings) { + m_listenGsettings->deleteLater(); + } +} + +void CalendarButton::contextMenuEvent(QContextMenuEvent *event) +{ + m_menuCalender = new QMenu(); + m_menuCalender->setAttribute(Qt::WA_DeleteOnClose); + m_menuCalender->setGeometry(m_plugin->panel()->calculatePopupWindowPos + (mapToGlobal(event->pos()), + m_menuCalender->sizeHint())); + m_menuCalender->addAction(QIcon::fromTheme("document-page-setup-symbolic"), + tr("Time and Date Setting"), + this, SLOT(setControlTime())); + m_menuCalender->show(); + kdk::WindowManager::setGeometry(m_menuCalender->windowHandle(), + m_plugin->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), m_menuCalender->sizeHint())); +} + +void CalendarButton::mousePressEvent(QMouseEvent *event) +{ + if (Qt::LeftButton == event->button()){ + Q_EMIT pressShowHideCalendar(); + } +} + +//初始化时间日期格式相关Gsettings +void CalendarButton::initTimeGsettings() +{ + const QByteArray id(HOUR_SYSTEM_CONTROL); + if (QGSettings::isSchemaInstalled(id)) { + m_timeGsettings = new QGSettings(id); + connect(m_timeGsettings, &QGSettings::changed, this, [=] (const QString &key) { + if (key == DATA_FORMAT) { + m_dataFormat = m_timeGsettings->get(DATA_FORMAT).toString(); + } else if(key == TIME_FORMAT) { + m_timeFormat = m_timeGsettings->get(TIME_FORMAT).toString(); + } else if(key == WEEK_FORMAT) { + m_weekFormat = m_timeGsettings->get(WEEK_FORMAT).toString(); + } else if(key == CALENDAR_FORMAT) { + m_calendarFormat = m_timeGsettings->get(CALENDAR_FORMAT).toString(); + } + updateBtnText(QString()); + }); + + QStringList ketList = m_timeGsettings->keys(); + if(ketList.contains(DATA_FORMAT)) + m_dataFormat = m_timeGsettings->get(DATA_FORMAT).toString(); + if(ketList.contains(TIME_FORMAT)) + m_timeFormat = m_timeGsettings->get(TIME_FORMAT).toString(); + if(ketList.contains(WEEK_FORMAT)) + m_weekFormat = m_timeGsettings->get(WEEK_FORMAT).toString(); + if(ketList.contains(CALENDAR_FORMAT)) + m_calendarFormat = m_timeGsettings->get(CALENDAR_FORMAT).toString(); + } +} + +//初始化系统字体相关Gsetting +void CalendarButton::initFontGsettings() +{ + const QByteArray id(SYSTEM_FONT_SET); + if (QGSettings::isSchemaInstalled(id)) { + m_fontGsettings = new QGSettings(id); + connect(m_fontGsettings, &QGSettings::changed, this, [=] (const QString &keys){ + if(keys == SYSTEM_FONT_SIZE || keys == SYSTEM_FONT){ + m_systemFontSize = m_fontGsettings->get(SYSTEM_FONT_SIZE).toString(); + m_systemFont = m_fontGsettings->get(SYSTEM_FONT).toString(); + updateBtnText(QString()); + } + }); + + QStringList ketList = m_fontGsettings->keys(); + if(ketList.contains(SYSTEM_FONT_SIZE)) + m_systemFontSize = m_fontGsettings->get(SYSTEM_FONT_SIZE).toString(); + if(ketList.contains(SYSTEM_FONT)) + m_systemFont = m_fontGsettings->get(SYSTEM_FONT).toString(); + } +} + +//右键跳转到控制面板日期页面 +void CalendarButton::setControlTime() +{ + QProcess *process =new QProcess(this); + process->start( + "bash", + QStringList() << "-c" + << "dpkg -l | grep ukui-control-center"); + process->waitForFinished(); + QString strResult = process->readAllStandardOutput() + process->readAllStandardError(); + if (-1 != strResult.indexOf("3.0")) { + QProcess::startDetached(QString("ukui-control-center -t")); + } else { + QProcess::startDetached(QString("ukui-control-center -m Date")); + } +} + +/* + * 更新时间文字显示 + * 横向任务栏显示格式(中文): + * 24小时制: + * hh:mm ddd + * yyyy/MM/dd + * 12小时制: + * AM hh:mm ddd + * yyyy/MM/dd + * + * 纵向任务栏显示格式: + * 24小时制: + * hh:mm 或 hh:mm + * ddd ddd + * yyyy/MM/dd MM/dd + * 12小时制: + * AM AM + * hh:mm hh:mm + * ddd 或 ddd + * yyyy/MM/dd MM/dd +*/ +void CalendarButton::updateBtnText(QString timerStr) +{ + Q_UNUSED(timerStr); + QString formatsLocale = getFormatsLocale(); + QString displayText; + CalendarButtonText *m_btnText; + if(formatsLocale == ZH_CN_FORMATS) { + m_btnText = new ZhCnText(m_plugin,this); + } else if(formatsLocale == US_FORMATS) { + m_btnText = new EnUsText(m_plugin,this); + } else { + m_btnText = new OtherLanguagText(m_plugin,this); + } + displayText = m_btnText->getBtnText(); + m_btnText->deleteLater(); + this->setText(displayText); +} + +/* 获取时间、日期、货币格式 */ +QString CalendarButton::getFormatsLocale() +{ + QDBusInterface interface(UKUI_CONTROL_CENTER_SERVER, + UKUI_CONTROL_CENTER_PATH, + UKUI_CONTROL_CENTER_INTERFACE, + QDBusConnection::systemBus()); + QVariant ret = interface.property(PROPERTIES_NAME); + return ret.toString(); +} + +void CalendarButton::paintEvent(QPaintEvent* event) +{ + QStylePainter painter(this); + QStyleOptionButton option; + initStyleOption(&option); + if ((option.state & QStyle::State_Enabled) && + (option.state & QStyle::State_MouseOver || + option.state & QStyle::State_HasFocus)) { + painter.save(); + painter.setPen(Qt::NoPen); + + QPalette pal = qApp->palette(); + QColor color = pal.color(QPalette::Active, QPalette::BrightText); + color.setAlphaF(m_btnAlphaF); + painter.setBrush(color); + painter.setRenderHint(QPainter::Antialiasing); + + painter.drawRoundedRect(option.rect, 6, 6); + painter.restore(); + } + + QStyleOptionButton subopt = option; + subopt.rect = painter.style()->subElementRect(QStyle::SE_PushButtonContents, &option, this); + subopt.palette.setBrush(QPalette::BrightText, subopt.palette.brightText()); + painter.style()->drawControl(QStyle::CE_PushButtonLabel, &subopt, &painter, this); + return; +} diff -Nru ukui-panel-3.14.0.1/plugin-calendar/calendarbutton.h ukui-panel-4.0.0.0/plugin-calendar/calendarbutton.h --- ukui-panel-3.14.0.1/plugin-calendar/calendarbutton.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/calendarbutton.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,76 @@ +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef CALENDARBUTTON_H +#define CALENDARBUTTON_H +#include <QToolButton> +#include <QTimer> +#include <QProcess> +#include <QMenu> +#include <QDir> +#include <QFile> +#include <QSettings> +#include <QtDBus/QtDBus> +#include <QMouseEvent> +#include <QContextMenuEvent> +#include <QGSettings> +#include <QPushButton> +#include "../panel/iukuipanelplugin.h" +#include "../panel/common_fun/listengsettings.h" +#include "calendarbuttontext.h" + + +class CalendarButton : public QPushButton +{ + Q_OBJECT +public: + CalendarButton(IUKUIPanelPlugin *plugin,QWidget* parent = 0); + ~CalendarButton(); +protected: + void contextMenuEvent(QContextMenuEvent *event); + void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent* event); +private: + void initTimeGsettings(); + void initFontGsettings(); + QString getFormatsLocale(); +Q_SIGNALS: + void pressTimeText(); + void pressShowHideCalendar(); +private Q_SLOTS: + void setControlTime(); + void updateBtnText(QString timerStr); +private: + IUKUIPanelPlugin * m_plugin; + QWidget *m_parent; + QGSettings *m_styleGsettings; + QGSettings *m_timeGsettings; + ListenGsettings *m_listenGsettings; + int m_panelSize; + QString m_dataFormat; + QString m_timeFormat; + QString m_weekFormat; + QString m_calendarFormat; + QGSettings *m_fontGsettings; + QString m_systemFontSize; + QString m_systemFont; + QMenu *m_menuCalender; + const qreal m_btnAlphaF = 0.13; //按钮背景透明度暂时使用UKUI3.1版本的透明度 +}; + +#endif // CALENDARBUTTON_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/calendarbuttontext.cpp ukui-panel-4.0.0.0/plugin-calendar/calendarbuttontext.cpp --- ukui-panel-3.14.0.1/plugin-calendar/calendarbuttontext.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/calendarbuttontext.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,319 @@ +/* +* Copyright (C) 2023, KylinSoft Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#include "calendarbuttontext.h" +#include <QtDBus/QtDBus> + +#define HOUR_SYSTEM_CONTROL "org.ukui.control-center.panel.plugins" +#define DATA_FORMAT "date" //日期格式:yyyy/MM/dd、yyyy-MM-dd +#define TIME_FORMAT "hoursystem" //时间格式:12小时制、24小时制 + +#define SYSTEM_FONT_SET "org.ukui.style" +#define SYSTEM_FONT_SIZE "systemFontSize" +#define SYSTEM_FONT "systemFont" +#define SYSTEM_MIN_FONT 10 + +#define PANEL_SETTINGS "org.ukui.panel.settings" +#define PANEL_POSITION_KEY "panelposition" +#define ICON_SIZE_KEY "iconsize" +#define PANEL_SIZE_KEY "panelsize" + +#define CALENDAR_BUTTON_WIDTH 120 +#define PANEL_SIZE_LARGE 92 +#define PANEL_SIZE_MEDIUM 70 +#define PANEL_SIZE_SMALL 46 +#define PANEL_SIZE_KEY "panelsize" + +#define UKUI_CONTROL_CENTER_SERVER "org.freedesktop.Accounts" +#define UKUI_CONTROL_CENTER_PATH "/org/freedesktop/Accounts/User1000" +#define UKUI_CONTROL_CENTER_INTERFACE "org.freedesktop.Accounts.User" +#define PROPERTIES_NAME "FormatsLocale" +#define US_FORMATS "en_US.UTF-8" +#define ZH_CN_FORMATS "zh_CN.UTF-8" + +#define INSIDE_SPAC 6 + + +CalendarButtonText::CalendarButtonText(IUKUIPanelPlugin *plugin, QPushButton *parent): + m_plugin(plugin), + m_parent(parent) +{ + m_dataTime = QDateTime::currentDateTime(); + const QByteArray controlId(HOUR_SYSTEM_CONTROL); + if (QGSettings::isSchemaInstalled(controlId)) { + m_timeFormat = new QGSettings(controlId); + } + const QByteArray fontId(SYSTEM_FONT_SET); + if (QGSettings::isSchemaInstalled(fontId)) { + m_fontGsettings = new QGSettings(fontId); + } + const QByteArray panelId(PANEL_SETTINGS); + if (QGSettings::isSchemaInstalled(panelId)) { + m_panelGsettings = new QGSettings(panelId); + } +} + +CalendarButtonText::~CalendarButtonText() +{ + if(m_timeFormat) { + m_timeFormat->deleteLater(); + } + if(m_fontGsettings) { + m_fontGsettings->deleteLater(); + } + if(m_panelGsettings) { + m_panelGsettings->deleteLater(); + } +} + +QString CalendarButtonText::getAmPm() +{ + QString time = m_dataTime.toString("A hh:mm"); + QStringList timeList = time.split(" ", QString::SkipEmptyParts); + return timeList.first(); +} + +QString CalendarButtonText::getTime() +{ + QString time = m_dataTime.toString("A hh:mm"); + QStringList timeList = time.split(" ", QString::SkipEmptyParts); + QString time12 = timeList.last(); + QString time24 = m_dataTime.toString("hh:mm"); + + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + return time12; + } else { + return time24; + } +} + +QString CalendarButtonText::getWeek() +{ + QDBusInterface interface(UKUI_CONTROL_CENTER_SERVER, + UKUI_CONTROL_CENTER_PATH, + UKUI_CONTROL_CENTER_INTERFACE, + QDBusConnection::systemBus()); + QString language = interface.property(PROPERTIES_NAME).toString(); + if(language == US_FORMATS) { + return m_dataTime.toString("ddd"); + } else if(language == ZH_CN_FORMATS) { + return m_dataTime.toString("dddd"); + } +} + +QString CalendarButtonText::getDate(DateStyle dateStyle) +{ + QString year = m_dataTime.toString("yyyy"); + QString mon = m_dataTime.toString("MM"); + QString day = m_dataTime.toString("dd"); + QString spacer = "/"; + if(m_timeFormat && m_timeFormat->get(DATA_FORMAT).toString() == "en") { + spacer = "-"; + } else { + spacer = "/"; + } + if(dateStyle == DateStyle::YEAR_MON_DAY) { + return year + spacer + mon + spacer + day; + } + else { + return mon + spacer + day; + } +} + +void CalendarButtonText::updateFontSize(QString btnText) +{ + QStringList textList = btnText.split("\n", QString::SkipEmptyParts); + + int maxLength; + if(m_plugin->panel()->isHorizontal()) { + if(m_panelGsettings->get(PANEL_SIZE_KEY).toInt() < PANEL_SIZE_MEDIUM) { + QString systemFont = m_fontGsettings->get(SYSTEM_FONT).toString(); + m_parent->setFont(QFont(systemFont, SYSTEM_MIN_FONT)); + return; + } + maxLength = CALENDAR_BUTTON_WIDTH; + setOptimalFont(textList, maxLength); + } else { + int m_panelSize = m_panelGsettings->get(PANEL_SIZE_KEY).toInt(); + if(m_panelSize >= PANEL_SIZE_SMALL && m_panelSize < PANEL_SIZE_MEDIUM) { + maxLength = PANEL_SIZE_SMALL; + } else if(m_panelSize >= PANEL_SIZE_MEDIUM && m_panelSize < PANEL_SIZE_LARGE) { + maxLength = PANEL_SIZE_MEDIUM; + } else if(m_panelSize == PANEL_SIZE_LARGE) { + maxLength = PANEL_SIZE_LARGE; + } else { + maxLength = PANEL_SIZE_SMALL; + } + setOptimalFont(textList, maxLength); + } +} + +//判断最长字体的是否可以显示下,选取最优字体大小显示 +void CalendarButtonText::setOptimalFont(QStringList textList, int btnMaxLength) +{ + QString systemFont = m_fontGsettings->get(SYSTEM_FONT).toString(); + double fontSizeCurrent = m_fontGsettings->get(SYSTEM_FONT_SIZE).toDouble(); + QList<double> systemFonts; + systemFonts<<10<<12<<13.5<<15; + + //获取最长的行 + QFontMetrics fontMetrics(QFont(systemFont, fontSizeCurrent)); + int fontWidth = fontMetrics.width(textList.first()); + int maxIndex = 0; + for(int i=1; i<textList.size(); i++) { + int width = fontMetrics.width(textList.at(i)); + if(width > fontWidth) { + fontWidth = width; + maxIndex = i; + } + } + + //判断最长字体的是否可以显示下,选取最优字体 + int maxFontWidth = fontMetrics.width(textList.at(maxIndex)); + if(maxFontWidth > btnMaxLength-INSIDE_SPAC) { + int index = systemFonts.indexOf(fontSizeCurrent); + if(index>0) { + for(int i=index-1; i>=0; i--) { + QFontMetrics fontMetrics(QFont(systemFont, systemFonts.at(i))); + int width = fontMetrics.width(textList.at(maxIndex)); + if(width <= btnMaxLength-INSIDE_SPAC) { + m_parent->setFont(QFont(systemFont, systemFonts.at(i))); + break; + } + } + } else { + //容错处理,如果系统 org.ukui.style system-font-size 设置错误,也可保证日期正常显示不遮挡 + m_parent->setFont(QFont(systemFont, systemFonts.first())); + } + } else { + m_parent->setFont(QFont(systemFont, fontSizeCurrent)); + } +} + +EnUsText::EnUsText(IUKUIPanelPlugin *plugin,QPushButton *parent): + CalendarButtonText(plugin,parent) +{ + +} + +QString EnUsText::getBtnText() +{ + QString amPmStr = getAmPm(); + QString timeStr = getTime(); + QString weekStr = getWeek(); + QString dataStr; + + QString btnTextStr; + if(m_plugin->panel()->isHorizontal()) { + dataStr = getDate(DateStyle::YEAR_MON_DAY); + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + btnTextStr = timeStr + " " + amPmStr + " " + weekStr + "\n" + dataStr; + } else { + btnTextStr = timeStr + " " + weekStr + "\n" + dataStr; + } + } else { + if(m_panelGsettings->get(PANEL_SIZE_KEY).toInt() < PANEL_SIZE_LARGE) { + dataStr = getDate(DateStyle::MON_DAY); + } else { + dataStr = getDate(DateStyle::YEAR_MON_DAY); + } + + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + btnTextStr = timeStr + "\n" + amPmStr + "\n" + weekStr + "\n" + dataStr; + } else { + btnTextStr = timeStr + "\n" + weekStr + "\n" + dataStr; + } + } + updateFontSize(btnTextStr); + return btnTextStr; +} + +ZhCnText::ZhCnText(IUKUIPanelPlugin *plugin,QPushButton *parent): + CalendarButtonText(plugin,parent) +{ + +} + +QString ZhCnText::getBtnText() +{ + QString amPmStr = getAmPm(); + QString timeStr = getTime(); + QString weekStr = getWeek(); + QString dataStr; + + QString btnTextStr; + if(m_plugin->panel()->isHorizontal()) { + dataStr = getDate(DateStyle::YEAR_MON_DAY); + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + btnTextStr = amPmStr + " " + timeStr + " " + weekStr + "\n" + dataStr; + } else { + btnTextStr = timeStr + " " + weekStr + "\n" + dataStr; + } + } else { + if(m_panelGsettings->get(PANEL_SIZE_KEY).toInt() < PANEL_SIZE_LARGE) { + dataStr = getDate(DateStyle::MON_DAY); + } else { + dataStr = getDate(DateStyle::YEAR_MON_DAY); + } + + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + btnTextStr = amPmStr + "\n" + timeStr + "\n" + weekStr + "\n" + dataStr; + } else { + btnTextStr = timeStr + "\n" + weekStr + "\n" + dataStr; + } + } + updateFontSize(btnTextStr); + return btnTextStr; +} + +OtherLanguagText::OtherLanguagText(IUKUIPanelPlugin *plugin,QPushButton *parent): + CalendarButtonText(plugin,parent) +{ + +} + +QString OtherLanguagText::getBtnText() +{ + QString amPmStr = getAmPm(); + QString timeStr = getTime(); + QString dataStr; + + QString btnTextStr; + if(m_plugin->panel()->isHorizontal()) { + dataStr = getDate(DateStyle::YEAR_MON_DAY); + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + btnTextStr = amPmStr + " " + timeStr + "\n" + dataStr; + } else { + btnTextStr = timeStr + "\n" + dataStr; + } + } else { + //任务栏纵向状态下,大尺寸以下均不显示year + if(m_panelGsettings->get(PANEL_SIZE_KEY).toInt() < PANEL_SIZE_LARGE) { + dataStr = getDate(DateStyle::MON_DAY); + } else { + dataStr = getDate(DateStyle::YEAR_MON_DAY); + } + if(m_timeFormat && m_timeFormat->get(TIME_FORMAT).toString() == "12") { + btnTextStr = amPmStr + "\n" + timeStr + "\n" + dataStr; + } else { + btnTextStr = timeStr + "\n" + dataStr; + } + } + updateFontSize(btnTextStr); + return btnTextStr; +} diff -Nru ukui-panel-3.14.0.1/plugin-calendar/calendarbuttontext.h ukui-panel-4.0.0.0/plugin-calendar/calendarbuttontext.h --- ukui-panel-3.14.0.1/plugin-calendar/calendarbuttontext.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/calendarbuttontext.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,74 @@ +/* +* Copyright (C) 2023, KylinSoft Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef CALENDARBUTTONTEXT_H +#define CALENDARBUTTONTEXT_H + +#include <QObject> +#include <QDateTime> +#include <QGSettings> +#include <QPushButton> +#include "../panel/iukuipanelplugin.h" + +class CalendarButtonText : public QObject +{ + Q_OBJECT +public: + CalendarButtonText(IUKUIPanelPlugin *plugin,QPushButton *parent); + ~CalendarButtonText(); + enum DateStyle{YEAR_MON_DAY=0, MON_DAY}; +public: + virtual QString getBtnText() = 0; + QString getAmPm(); + QString getTime(); + QString getWeek(); + QString getDate(DateStyle dateStyle); + void updateFontSize(QString btnText); + void setOptimalFont(QStringList textList, int btnMaxLength); +public: + QDateTime m_dataTime; + QPushButton *m_parent; + IUKUIPanelPlugin * m_plugin; + QGSettings *m_timeFormat; + QGSettings *m_fontGsettings; + QGSettings *m_panelGsettings; +}; + +class EnUsText : public CalendarButtonText +{ +public: + EnUsText(IUKUIPanelPlugin *plugin,QPushButton *parent); + QString getBtnText() override; +}; + +class ZhCnText : public CalendarButtonText +{ +public: + ZhCnText(IUKUIPanelPlugin *plugin,QPushButton *parent); + QString getBtnText() override; +}; + +class OtherLanguagText : public CalendarButtonText +{ +public: + OtherLanguagText(IUKUIPanelPlugin *plugin,QPushButton *parent); + QString getBtnText() override; +}; + + +#endif // CALENDARBUTTONTEXT_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/html/hlnew/hl2022.js ukui-panel-4.0.0.0/plugin-calendar/html/hlnew/hl2022.js --- ukui-panel-3.14.0.1/plugin-calendar/html/hlnew/hl2022.js 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/html/hlnew/hl2022.js 2023-05-22 14:06:12.000000000 +0800 @@ -1444,12 +1444,12 @@ "j": "安葬." }, "d1228": { -"y": "装修.动土.安床.订婚", -"j": ".开业.结婚.入宅.领证." +"y": "装修.动土.安床.订婚.", +"j": "开业.结婚.入宅.领证." }, "d1229": { -"y": "开业.开工.安床.出行", -"j": ".动土.作灶.掘井." +"y": "开业.开工.安床.出行.", +"j": "动土.作灶.掘井." }, "d1230": { "y": "祭祀.塞穴.", diff -Nru ukui-panel-3.14.0.1/plugin-calendar/html/hlnew/hl2023.js ukui-panel-4.0.0.0/plugin-calendar/html/hlnew/hl2023.js --- ukui-panel-3.14.0.1/plugin-calendar/html/hlnew/hl2023.js 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/html/hlnew/hl2023.js 2023-05-22 14:06:12.000000000 +0800 @@ -473,10 +473,10 @@ }, "d0429": { "y": "作灶.祭祀.纳财.", -"j": "开业.开工.开张.破土" +"j": "开业.开工.开张.破土." }, "d0430": { -"y": ".搬家.开业.结婚.入宅.", +"y": "搬家.开业.结婚.入宅.", "j": "安葬." }, "d0501": { diff -Nru ukui-panel-3.14.0.1/plugin-calendar/html/hlnew/hl2024.js ukui-panel-4.0.0.0/plugin-calendar/html/hlnew/hl2024.js --- ukui-panel-3.14.0.1/plugin-calendar/html/hlnew/hl2024.js 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/html/hlnew/hl2024.js 2023-05-22 14:06:12.000000000 +0800 @@ -692,8 +692,8 @@ "j": "搬家.入宅.出行.旅游." }, "d0622": { -"y": "开业.结婚.入宅.领证", -"j": ".盖屋.冠笄.掘井." +"y": "开业.结婚.入宅.领证.", +"j": "盖屋.冠笄.掘井." }, "d0623": { "y": "开业.开工.动土.安床.", diff -Nru ukui-panel-3.14.0.1/plugin-calendar/html/jiejiari.js ukui-panel-4.0.0.0/plugin-calendar/html/jiejiari.js --- ukui-panel-3.14.0.1/plugin-calendar/html/jiejiari.js 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/html/jiejiari.js 2023-05-22 14:06:12.000000000 +0800 @@ -1,41 +1,478 @@ { -"worktime.y2013":{"d0101":"2","d0102":"2","d0103":"2","d0105":"1","d0106":"1","d0209":"2","d0210":"2","d0211":"2","d0212":"2","d0213":"2","d0214":"2","d0215":"2","d0216":"1","d0217":"1","d0404":"2","d0405":"2","d0406":"2","d0407":"1","d0427":"1","d0428":"1","d0429":"2","d0430":"2","d0501":"2","d0608":"1","d0609":"1","d0610":"2","d0611":"2","d0612":"2","d0919":"2","d0920":"2","d0921":"2","d0922":"1","d0929":"1","d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1012":"1"}, - -"worktime.y2014":{"d0101":"2","d0126":"1","d0131":"2","d0201":"2","d0202":"2","d0203":"2","d0204":"2","d0205":"2","d0206":"2","d0208":"1","d0405":"2","d0407":"2","d0501":"2","d0502":"2","d0503":"2","d0504":"1","d0602":"2","d0908":"2","d0928":"1","d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1011":"1"}, - - "worktime.y2015":{"d0101":"2","d0102":"2","d0103":"2","d0104":"1","d0215":"1","d0218":"2","d0219":"2","d0220":"2","d0221":"2","d0222":"2","d0223":"2","d0224":"2","d0228":"1","d0404":"2","d0405":"2","d0406":"2","d0501":"2","d0502":"2","d0503":"2","d0620":"2","d0621":"2","d0622":"2","d0926":"2","d0927":"2","d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1010":"1"}, - - - "worktime.y2018":{"d0101":"2","d0211":"1","d0215":"2","d0216":"2","d0217":"2","d0218":"2","d0219":"2","d0220":"2","d0221":"2","d0224":"1","d0405":"2","d0406":"2","d0407":"2","d0408":"1","d0428":"1","d0429":"2","d0430":"2","d0501":"2","d0616":"2","d0617":"2","d0618":"2","d0922":"2","d0923":"2","d0924":"2","d0929":"1","d0930":"1","d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1229":"1","d1230":"2","d1231":"2"}, - - - "worktime.y2019":{"d0101":"2","d0202":"1","d0203":"1","d0204":"2","d0205":"2","d0206":"2","d0207":"2","d0208":"2","d0209":"2","d0210":"2","d0405":"2","d0406":"2","d0407":"2","d0501":"2","d0502":"2","d0503":"2","d0504":"2","d0505":"1","d0607":"2","d0608":"2","d0609":"2","d0913":"2","d0914":"2","d0915":"2","d0929":"1","d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1012":"1"}, - - - "worktime.y2020":{"d0101":"2","d0119":"1","d0124":"2","d0125":"2","d0126":"2","d0127":"2","d0128":"2","d0129":"2","d0130":"2","d0201":"1","d0404":"2","d0405":"2","d0406":"2","d0426":"1","d0501":"2","d0502":"2","d0503":"2","d0504":"2","d0505":"2","d0509":"1","d0625":"2","d0626":"2","d0627":"2","d0628":"1","d0927":"1","d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1008":"2","d1010":"1"}, - - -"worktime.y2021":{ - "d0101":"2","d0102":"2","d0103":"2", - "d0207":"1","d0211":"2","d0212":"2","d0213":"2","d0214":"2","d0215":"2","d0216":"2","d0217":"2","d0220":"1", - "d0403":"2","d0404":"2","d0405":"2","d0425":"1", - "d0501":"2","d0502":"2","d0503":"2","d0504":"2","d0505":"2","d0508":"1", - "d0612":"2","d0613":"2","d0614":"2", - "d0918":"1","d0919":"2","d0920":"2","d0921":"2","d0926":"1", - "d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1009":"1" - }, -"worktime.y2022":{ - "d0101":"2","d0102":"2","d0103":"2","d0129":"1","d0130":"1","d0131":"2", - "d0201":"2","d0202":"2","d0203":"2","d0204":"2","d0205":"2","d0206":"2", - "d0402":"1","d0403":"2","d0404":"2","d0405":"2","d0424":"1","d0430":"2", - "d0501":"2","d0502":"2","d0503":"2","d0504":"2","d0507":"1", - "d0603":"2","d0604":"2","d0605":"2", - "d0910":"2","d0911":"2","d0912":"2", - "d1001":"2","d1002":"2","d1003":"2","d1004":"2","d1005":"2","d1006":"2","d1007":"2","d1008":"1","d1009":"1" - - }, -"worktime.y2023":{ - "d0101":"2","d0102":"2","d0103":"2" - + "worktime.y2011": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0130": "1", + "d0202": "2", + "d0203": "2", + "d0204": "2", + "d0205": "2", + "d0206": "2", + "d0207": "2", + "d0208": "2", + "d0402": "1", + "d0403": "2", + "d0404": "2", + "d0405": "2", + "d0430": "2", + "d0501": "2", + "d0502": "2", + "d0604": "2", + "d0605": "2", + "d0606": "2", + "d0910": "2", + "d0911": "2", + "d0912": "2", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1008": "1", + "d1009": "1", + "d1231": "1" + }, + "worktime.y2012": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0121": "1", + "d0122": "2", + "d0123": "2", + "d0124": "2", + "d0125": "2", + "d0126": "2", + "d0127": "2", + "d0128": "2", + "d0129": "1", + "d0331": "1", + "d0401": "1", + "d0402": "2", + "d0403": "2", + "d0404": "2", + "d0428": "1", + "d0429": "2", + "d0430": "2", + "d0501": "2", + "d0622": "2", + "d0623": "2", + "d0624": "2", + "d0929": "1", + "d0930": "2", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1008": "1" + }, + "worktime.y2013": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0105": "1", + "d0106": "1", + "d0209": "2", + "d0210": "2", + "d0211": "2", + "d0212": "2", + "d0213": "2", + "d0214": "2", + "d0215": "2", + "d0216": "1", + "d0217": "1", + "d0404": "2", + "d0405": "2", + "d0406": "2", + "d0407": "1", + "d0427": "1", + "d0428": "1", + "d0429": "2", + "d0430": "2", + "d0501": "2", + "d0608": "1", + "d0609": "1", + "d0610": "2", + "d0611": "2", + "d0612": "2", + "d0919": "2", + "d0920": "2", + "d0921": "2", + "d0922": "1", + "d0929": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1012": "1" + }, + "worktime.y2014": { + "d0101": "2", + "d0126": "1", + "d0131": "2", + "d0201": "2", + "d0202": "2", + "d0203": "2", + "d0204": "2", + "d0205": "2", + "d0206": "2", + "d0208": "1", + "d0405": "2", + "d0407": "2", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0504": "1", + "d0602": "2", + "d0908": "2", + "d0928": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1011": "1" + }, + "worktime.y2015": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0104": "1", + "d0215": "1", + "d0218": "2", + "d0219": "2", + "d0220": "2", + "d0221": "2", + "d0222": "2", + "d0223": "2", + "d0224": "2", + "d0228": "1", + "d0404": "2", + "d0405": "2", + "d0406": "2", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0620": "2", + "d0621": "2", + "d0622": "2", + "d0926": "2", + "d0927": "2", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1010": "1" + }, + "worktime.y2016": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0206": "1", + "d0207": "2", + "d0208": "2", + "d0209": "2", + "d0210": "2", + "d0211": "2", + "d0212": "2", + "d0213": "2", + "d0214": "1", + "d0402": "2", + "d0403": "2", + "d0404": "2", + "d0430": "2", + "d0501": "2", + "d0502": "2", + "d0609": "2", + "d0610": "2", + "d0611": "2", + "d0612": "1", + "d0915": "2", + "d0916": "2", + "d0917": "2", + "d0918": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1008": "1", + "d1009": "1", + "d1231": "2" + }, + "worktime.y2017": { + "d0101":"2", + "d0102":"2", + "d0122":"1", + "d0127":"2", + "d0128":"2", + "d0129":"2", + "d0130":"2", + "d0131":"2", + "d0201":"2", + "d0202":"2", + "d0204":"1", + "d0401":"1", + "d0402":"2", + "d0403":"2", + "d0404":"2", + "d0429":"2", + "d0430":"2", + "d0501":"2", + "d0527":"1", + "d0528":"2", + "d0529":"2", + "d0530":"2", + "d0930":"1", + "d1001":"2", + "d1002":"2", + "d1003":"2", + "d1004":"2", + "d1005":"2", + "d1006":"2", + "d1007":"2", + "d1008":"2", + "d1230":"2", + "d1231":"2" + }, + "worktime.y2018": { + "d0101": "2", + "d0211": "1", + "d0215": "2", + "d0216": "2", + "d0217": "2", + "d0218": "2", + "d0219": "2", + "d0220": "2", + "d0221": "2", + "d0224": "1", + "d0405": "2", + "d0406": "2", + "d0407": "2", + "d0408": "1", + "d0428": "1", + "d0429": "2", + "d0430": "2", + "d0501": "2", + "d0616": "2", + "d0617": "2", + "d0618": "2", + "d0922": "2", + "d0923": "2", + "d0924": "2", + "d0929": "1", + "d0930": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1229": "1", + "d1230": "2", + "d1231": "2" + }, + "worktime.y2019": { + "d0101": "2", + "d0202": "1", + "d0203": "1", + "d0204": "2", + "d0205": "2", + "d0206": "2", + "d0207": "2", + "d0208": "2", + "d0209": "2", + "d0210": "2", + "d0405": "2", + "d0406": "2", + "d0407": "2", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0504": "2", + "d0505": "1", + "d0607": "2", + "d0608": "2", + "d0609": "2", + "d0913": "2", + "d0914": "2", + "d0915": "2", + "d0929": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1012": "1" + }, + "worktime.y2020": { + "d0101": "2", + "d0119": "1", + "d0124": "2", + "d0125": "2", + "d0126": "2", + "d0127": "2", + "d0128": "2", + "d0129": "2", + "d0130": "2", + "d0201": "1", + "d0404": "2", + "d0405": "2", + "d0406": "2", + "d0426": "1", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0504": "2", + "d0505": "2", + "d0509": "1", + "d0625": "2", + "d0626": "2", + "d0627": "2", + "d0628": "1", + "d0927": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1008": "2", + "d1010": "1" + }, + "worktime.y2021": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0207": "1", + "d0211": "2", + "d0212": "2", + "d0213": "2", + "d0214": "2", + "d0215": "2", + "d0216": "2", + "d0217": "2", + "d0220": "1", + "d0403": "2", + "d0404": "2", + "d0405": "2", + "d0425": "1", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0504": "2", + "d0505": "2", + "d0508": "1", + "d0612": "2", + "d0613": "2", + "d0614": "2", + "d0918": "1", + "d0919": "2", + "d0920": "2", + "d0921": "2", + "d0926": "1", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1009": "1" + }, + "worktime.y2022": { + "d0101": "2", + "d0102": "2", + "d0103": "2", + "d0129": "1", + "d0130": "1", + "d0131": "2", + "d0201": "2", + "d0202": "2", + "d0203": "2", + "d0204": "2", + "d0205": "2", + "d0206": "2", + "d0402": "1", + "d0403": "2", + "d0404": "2", + "d0405": "2", + "d0424": "1", + "d0430": "2", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0504": "2", + "d0507": "1", + "d0603": "2", + "d0604": "2", + "d0605": "2", + "d0910": "2", + "d0911": "2", + "d0912": "2", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "2", + "d1008": "1", + "d1009": "1", + "d1231": "2" + }, + "worktime.y2023": { + "d0101": "2", + "d0102": "2", + "d0121": "2", + "d0122": "2", + "d0123": "2", + "d0124": "2", + "d0125": "2", + "d0126": "2", + "d0127": "2", + "d0128": "1", + "d0129": "1", + "d0405": "2", + "d0423": "1", + "d0429": "2", + "d0430": "2", + "d0501": "2", + "d0502": "2", + "d0503": "2", + "d0506": "1", + "d0622": "2", + "d0623": "2", + "d0624": "2", + "d0625": "1", + "d0929": "2", + "d0930": "2", + "d1001": "2", + "d1002": "2", + "d1003": "2", + "d1004": "2", + "d1005": "2", + "d1006": "2", + "d1007": "1", + "d1008": "1" } -} +} \ No newline at end of file diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/calendarcolor.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/calendarcolor.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/calendarcolor.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/calendarcolor.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,88 @@ +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#include "calendarcolor.h" +#include <QApplication> +#include <QPalette> +#include <QDebug> +namespace CalendarColor { + + +CalendarColor::CalendarColor() +{ + +} + +QColor CalendarColor::getThemeColor(Color c) +{ + QColor color; + QPalette pal = QApplication::palette(); + switch (c){ + case TEXT:{ + color = pal.text().color(); + }break; + case BACKGROUND:{ + color = pal.background().color(); + }break; + case CLICKED:{ + color = pal.highlight().color(); + }break; + case CLICKED_TEXT:{ + color = pal.highlightedText().color(); + }break; + case OTHER_TEXT:{ + color = pal.placeholderText().color(); + }break; + case WORK:{ + color = QColor(255, 129, 6); + }break; + case HOLIDAY:{ + color = QColor(233, 90, 84); + }break; + default:{ + qDebug () << "Failed to get color, invalid color type"; + color = QColor(); + } + } +// qDebug() << (int)c << color; + return color; +} + +static inline qreal mixQreal(qreal a, qreal b, qreal bias) +{ + return a + (b-a)*bias; +} + +QColor CalendarColor::mixColor(const QColor& in,qreal mix) +{ + if (mix <= 0.0){ + return in; + } else if(mix >= 1.0){ + return in; + } else if(qIsNaN(mix)) { + return in; + } + + QColor brightTextColor = QApplication::palette().brightText().color(); + qreal r = mixQreal(in.redF(),brightTextColor.redF(),mix); + qreal g = mixQreal(in.greenF(),brightTextColor.greenF(),mix); + qreal b = mixQreal(in.blueF(),brightTextColor.blueF(),mix); + qreal a = mixQreal(in.alphaF(),brightTextColor.alphaF(),mix); + return QColor::fromRgbF(r, g, b, a); +} +} diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/calendarcolor.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/calendarcolor.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/calendarcolor.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/calendarcolor.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,47 @@ +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef CALENDARCOLOR_H +#define CALENDARCOLOR_H + +#include <QColor> + +namespace CalendarColor { + enum Color{ + TEXT = 1, //Text + BACKGROUND = 2, //Background + CLICKED =3, //Highlight + CLICKED_TEXT = 4, //HighlightText + OTHER_TEXT = 5, //Shadow + HOLIDAY = 6, //Red + WORK = 7 //Orange + }; + + +class CalendarColor +{ +public: + CalendarColor(); +public: + static QColor getThemeColor(Color c); + //混合颜色,参考主题代码 + static QColor mixColor(const QColor& in,qreal mix); +}; + +} +#endif // CALENDARCOLOR_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/customstylePushbutton.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/customstylePushbutton.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/customstylePushbutton.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/customstylePushbutton.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -68,37 +68,6 @@ /// 如果你需要自己实现一个主题,这同样是你需要注意和考虑的点 void CustomStyle_pushbutton::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { -// if (element == PE_PanelButtonCommand) { -// qDebug()<<"draw pe button"; -// if (widget) { -// bool isPressed = false; -// bool isHover = false; -// if (!option->state.testFlag(State_Sunken)) { -// if (option->state.testFlag(State_MouseOver)) { -// isHover = true; -// } -// } else { -// isPressed = true; -// } - -// QStyleOption opt = *option; -// if (isHover) { -// QColor color(255,255,255,51); -// opt.palette.setColor(QPalette::Highlight, color); - -// } -// if (isPressed) { -// QColor color(255,255,255,21); -// opt.palette.setColor(QPalette::Highlight, color); -// } -// if (!isHover && !isPressed) { -// QColor color(255,255,255,31); -// opt.palette.setColor(QPalette::Button,color); -// } -// return QProxyStyle::drawPrimitive(element, &opt, painter, widget); -// } -// } -// return QProxyStyle::drawPrimitive(element, option, painter, widget); if (element == PE_PanelButtonCommand) { if (widget) { if (option->state & State_MouseOver) { diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -18,6 +18,7 @@ #include "frmlunarcalendarwidget.h" #include "ui_frmlunarcalendarwidget.h" #include <QPainter> +#include <KWindowEffects> #define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" #define TRANSPARENCY_KEY "transparency" @@ -25,19 +26,23 @@ #define LUNAR_KEY "calendar" #define FIRST_DAY_KEY "firstday" +const int CALENDAR_WIDTH = 440; +const int CALENDAR_HEIGHT = 575; +const int CALENDAR_LUNAR_HEIGHT = 77; + frmLunarCalendarWidget::frmLunarCalendarWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmLunarCalendarWidget) { installEventFilter(this); ui->setupUi(this); - connect(ui->lunarCalendarWidget,&LunarCalendarWidget::yijiChangeUp,this,&frmLunarCalendarWidget::changeUpSize); - connect(ui->lunarCalendarWidget,&LunarCalendarWidget::yijiChangeDown,this,&frmLunarCalendarWidget::changeDownSize); + connect(ui->lunarCalendarWidget,&LunarCalendarWidget::almanacChanged,this,&frmLunarCalendarWidget::showAlmanac); + connect(this, &frmLunarCalendarWidget::onShowToday,ui->lunarCalendarWidget,&LunarCalendarWidget::showToday); this->initForm(); - this->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);//去掉标题栏 -// this->setWindowFlags(Qt::Popup); - setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 - setProperty("useSystemStyleBlur", true); - - this->setFixedSize(440, 600); + //默认展开状态 + bool showLunar = ui->lunarCalendarWidget->getShowLunar(); + if(showLunar) + this->setFixedSize(CALENDAR_WIDTH, CALENDAR_HEIGHT+CALENDAR_LUNAR_HEIGHT); + else + this->setFixedSize(CALENDAR_WIDTH,CALENDAR_HEIGHT); const QByteArray transparency_id(TRANSPARENCY_SETTINGS); if(QGSettings::isSchemaInstalled(transparency_id)){ @@ -59,6 +64,7 @@ ckShowLunar_stateChanged(false); cboxWeekNameFormat_currentIndexChanged(false); } + setProperty("useStyleWindowManager",false); } frmLunarCalendarWidget::~frmLunarCalendarWidget() @@ -66,16 +72,26 @@ delete ui; } +void frmLunarCalendarWidget::showAlmanac(bool big) +{ + qDebug() << __FILE__ <<__LINE__<<__FUNCTION__<<big; + if(big){ + setFixedHeight(CALENDAR_HEIGHT+CALENDAR_LUNAR_HEIGHT); + }else{ + setFixedHeight(CALENDAR_HEIGHT); + } +} + void frmLunarCalendarWidget::changeUpSize() { - this->setFixedSize(440, 652); - Q_EMIT yijiChangeUp(); + this->setFixedSize(CALENDAR_WIDTH, CALENDAR_HEIGHT+CALENDAR_LUNAR_HEIGHT); + Q_EMIT yijiFChangeUp(); } void frmLunarCalendarWidget::changeDownSize() { - this->setFixedSize(440, 600); - Q_EMIT yijiChangeDown(); + this->setFixedSize(CALENDAR_WIDTH, CALENDAR_HEIGHT); + Q_EMIT yijiFChangeDown(); } void frmLunarCalendarWidget::initForm() @@ -100,7 +116,6 @@ void frmLunarCalendarWidget::ckShowLunar_stateChanged(bool arg1) { - ui->lunarCalendarWidget->setShowLunar(arg1); } void frmLunarCalendarWidget::paintEvent(QPaintEvent *) diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h 2023-05-22 14:06:12.000000000 +0800 @@ -53,12 +53,16 @@ void cboxSelectType_currentIndexChanged(int index); void cboxWeekNameFormat_currentIndexChanged(bool FirstDayisSun); void ckShowLunar_stateChanged(bool arg1); +public Q_SLOTS: void changeUpSize(); void changeDownSize(); - + //true: 顯示大窗口 + //false: 顯示小窗口 + void showAlmanac(bool big); Q_SIGNALS: - void yijiChangeUp(); - void yijiChangeDown(); + void yijiFChangeUp(); + void yijiFChangeDown(); + void onShowToday(); }; #endif // FRMLUNARCALENDARWIDGET_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -1,4 +1,22 @@ -#pragma execution_character_set("utf-8") +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#pragma execution_character_set("utf-8") #include "lunarcalendarinfo.h" #include "qmutex.h" diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarinfo.h 2023-05-22 14:06:12.000000000 +0800 @@ -1,4 +1,22 @@ -#ifndef LUNARCALENDARINFO_H +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef LUNARCALENDARINFO_H #define LUNARCALENDARINFO_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -21,14 +21,23 @@ #include "lunarcalendaritem.h" #include "lunarcalendarwidget.h" #include "lunarcalendarinfo.h" +#include "calendarcolor.h" + #include "qpainter.h" #include "qevent.h" #include "qdatetime.h" #include "qdebug.h" #include <QGSettings> -LunarCalendarItem::LunarCalendarItem(QWidget *parent) : QWidget(parent) +//日历字号 +const int day_font_size = 18; +const int lunar_font_size = 14; +const int other_font_size = 12; + +LunarCalendarItem::LunarCalendarItem(QString font,QWidget *parent) : QWidget(parent),m_font(font) { + setProperty("useStyleWindowManager",false); + setAttribute(Qt::WA_TransparentForMouseEvents,true); hover = false; pressed = false; @@ -45,84 +54,58 @@ const QByteArray id("org.ukui.style"); QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); connect(fontSetting, &QGSettings::changed,[=](QString key) { - if(fontSetting->get("style-name").toString() == "ukui-default") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } else if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else if(fontSetting->get("style-name").toString() == "ukui-dark") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); + if((key.compare("style-name") == 0) || (key.compare("theme-color") == 0)|| (key.compare("widget-theme-name")==0) || + (key.compare("styleName") == 0) || (key.compare("themeColor") == 0)|| (key.compare("widgetThemeName")==0) ){ + weekColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor.setAlphaF(0.35); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor.setAlphaF(0.45); + lunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor.setAlphaF(0.35); + selectBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + //hoverBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + qreal mix = 0.2; + hoverBgColor = CalendarColor::CalendarColor::mixColor(CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED),mix); + this->update(); } }); - if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - - borderColor = QColor(180, 180, 180); - superColor = QColor(255, 129, 6); - - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(250, 250, 250); - - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(255, 255, 255); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(55,144,250); - hoverBgColor = QColor(204, 183, 180); + weekColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor.setAlphaF(0.45); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor.setAlphaF(0.35); + superColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + selectTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + hoverTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + selectLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + hoverLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + selectBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + //hoverBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + qreal mix = 0.2; + hoverBgColor = CalendarColor::CalendarColor::mixColor(CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED),mix); +} + +void LunarCalendarItem::onEnter() +{ + hover = true; + this->update(); } - -void LunarCalendarItem::enterEvent(QEvent *) +void LunarCalendarItem::onLeave() { - hover = true; - this->update(); + hover = false; + this->update(); } - -void LunarCalendarItem::leaveEvent(QEvent *) +void LunarCalendarItem::onSelected() { - hover = false; - this->update(); -} - -void LunarCalendarItem::mousePressEvent(QMouseEvent *) -{ - pressed = true; - this->update(); Q_EMIT clicked(date, dayType); -} - -void LunarCalendarItem::mouseReleaseEvent(QMouseEvent *) -{ - pressed = false; - this->update(); + update(); } QString LunarCalendarItem::handleJsMap(QString year,QString month2day) @@ -150,34 +133,64 @@ void LunarCalendarItem::paintEvent(QPaintEvent *) { - QDate dateNow = QDate::currentDate(); - //绘制准备工作,启用反锯齿 QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - //绘制背景和边框 drawBg(&painter); - //对比当前的时间,画选中状态 if(dateNow == date) { drawBgCurrent(&painter, selectBgColor); - } - - //绘制悬停状态 - if (hover) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制选中状态 - if (select) { + if(hover || select) { + drawBgHover(&painter, hoverBgColor); + } + //设置一个字的颜色 + if (dayType == DayType_MonthCurrent) { + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + currentLunarColor.setAlphaF(0.45); + } + } else if (hover) { + //绘制悬停状态、绘制选中状态 drawBgHover(&painter, hoverBgColor); + //设置一个字的颜色 + if (dayType == DayType_MonthCurrent) { + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor.setAlphaF(0.45); + }else { + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor.setAlphaF(0.15); + } + } else if (select){ + if(LunarCalendarWidget::getClickedDate() == date){ + drawBgHover(&painter, hoverBgColor); + } + //设置一个字的颜色 + if (dayType == DayType_MonthCurrent) { + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor.setAlphaF(0.45); + }else { + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor.setAlphaF(0.15); + } + }else { + if (dayType == DayType_MonthCurrent) { + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentLunarColor.setAlphaF(0.45); + }else { + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor.setAlphaF(0.15); + } } - //绘制日期 drawDay(&painter); - //绘制农历信息 drawLunar(&painter); } @@ -192,10 +205,6 @@ bgColor = otherBgColor; } - //painter->setPen(borderColor); - //painter->setBrush(bgColor); - //painter->drawRect(rect()); - painter->restore(); } @@ -206,11 +215,8 @@ painter->setBrush(color); QRect rect = this->rect(); - painter->drawRoundedRect(rect,4,4); -// //根据设定绘制背景样式 -// if (selectType == SelectType_Rect) { - -// } + rect = QRect(rect.x()+1,rect.y()+1,rect.width()-2,rect.height()-2); + painter->drawRoundedRect(rect,6,6); painter->restore(); } @@ -218,12 +224,9 @@ { painter->save(); QRect rect = this->rect(); - painter->setPen(QPen(QColor(55,143,250),2)); - painter->drawRoundedRect(rect,4,4); -// //根据设定绘制背景样式 -// if (selectType == SelectType_Rect) { - -// } + rect = QRect(rect.x()+1,rect.y()+1,rect.width()-2,rect.height()-2); + painter->setPen(QPen(color,3)); + painter->drawRoundedRect(rect,6,6); painter->restore(); } @@ -232,9 +235,8 @@ int width = this->width(); int height = this->height(); int side = qMin(width, height); - +// qDebug() << width << height ; painter->save(); - //根据当前类型选择对应的颜色 QColor color = currentTextColor; if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { @@ -243,16 +245,10 @@ color = weekColor; } -/* if (select) { - color = selectTextColor; - } *//*else if (hover) { - color = hoverTextColor; - }*/ - painter->setPen(color); - QFont font; - font.setPixelSize(side * 0.3); + QFont font = m_font; + font.setPixelSize(day_font_size); //设置文字粗细 font.setBold(true); painter->setFont(font); @@ -260,34 +256,39 @@ QLocale locale = (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English)); //代码复用率待优化 if (showLunar) { - QRect dayRect = QRect(0, 0, width, height / 1.7); - painter->drawText(dayRect, Qt::AlignHCenter | Qt::AlignBottom, QString::number(date.day())); + QRect dayRect; + if(locale == QLocale::Chinese){ + dayRect = QRect(0, 0, width, height / 1.7); + } + else { + dayRect = QRect(0, 0, width, height); + } + painter->drawText(dayRect, Qt::AlignHCenter | Qt::AlignVCenter, QString::number(date.day())); if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "2") { painter->setPen(Qt::NoPen); if(locale == QLocale::Chinese){ - painter->setBrush(QColor(244,78,80)); + painter->setBrush(CalendarColor::CalendarColor::getThemeColor(CalendarColor::HOLIDAY)); } QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); + painter->drawRoundedRect(dayRect1,4,4); + font.setPixelSize(other_font_size); painter->setFont(font); painter->setPen(Qt::white); if(locale == QLocale::Chinese){ - painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"休"); + painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignVCenter,"休"); } - } else if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "1") { painter->setPen(Qt::NoPen); if(locale == QLocale::Chinese){ - painter->setBrush(QColor(251,170,42)); + painter->setBrush(CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK)); } QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); + painter->drawRoundedRect(dayRect1,4,4); + font.setPixelSize(other_font_size); painter->setFont(font); painter->setPen(Qt::white); if(locale == QLocale::Chinese){ - painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"班"); + painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignVCenter,"班"); } } } @@ -297,22 +298,18 @@ painter->drawText(dayRect, Qt::AlignCenter, QString::number(date.day())); if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "2") { painter->setPen(Qt::NoPen); -// painter->setBrush(QColor(255,0,0)); QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); + painter->drawRoundedRect(dayRect1,6,6); + font.setPixelSize(other_font_size); painter->setFont(font); painter->setPen(Qt::white); -// painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"休"); } else if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "1") { painter->setPen(Qt::NoPen); -// painter->setBrush(QColor(251,170,42)); QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); + painter->drawRoundedRect(dayRect1,6,6); + font.setPixelSize(other_font_size); painter->setFont(font); painter->setPen(Qt::white); -// painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"班"); } } @@ -323,37 +320,9 @@ { int width = this->width(); int height = this->height(); - int side = qMin(width, height); - int month; - int day; - QString strHoliday; QLocale locale = (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English)); - qDebug()<<"LunarCalendarItem语言模式:"<<locale; painter->save(); - - if (!showLunar) { - //非农历 -// int month = date.month(); -// int day = date.day(); -// LunarCalendarInfo *lun = LunarCalendarInfo::Instance(); -// strHoliday = lun->getHoliday(month,day); -//// delete lun; - -// QColor color = currentLunarColor; -// if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { -// color = otherLunarColor; -// } -// painter->setPen(color); - -// QFont font; -// font.setPixelSize(side * 0.27); -// painter->setFont(font); - -// QRect lunarRect(0, height / 2, width, height / 2); -// painter->drawText(lunarRect, Qt::AlignCenter, strHoliday); - } - else { - + if (showLunar){ if(locale == QLocale::Chinese){ QStringList listDayName; listDayName << "*" << "初一" << "初二" << "初三" << "初四" << "初五" << "初六" << "初七" << "初八" << "初九" << "初十" @@ -362,38 +331,24 @@ //判断当前农历文字是否节日,是节日且是当月则用农历节日颜色显示 bool exist = (!listDayName.contains(lunar) && dayType != DayType_MonthPre && dayType != DayType_MonthNext); - //根据当前类型选择对应的颜色 QColor color = currentLunarColor; if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { color = otherLunarColor; } - - // if (select) { - // color = selectTextColor; - // } /*else if (hover) { - // color = hoverTextColor; - // }*/ else if (exist) { - // color = lunarColor; - // } - if (exist) { - color = lunarColor; + color = currentLunarColor; } - painter->setPen(color); - - QFont font; - font.setPixelSize(side * 0.27); + QFont font = m_font; + font.setPixelSize(lunar_font_size); painter->setFont(font); - QRect lunarRect(0, height / 2, width, height / 2); - painter->drawText(lunarRect, Qt::AlignCenter, lunar); + QRect lunarRect(0, height / 2 + 4, width, height / 2); + painter->drawText(lunarRect, Qt::AlignTop|Qt::AlignHCenter, lunar); } painter->restore(); } - - } diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaritem.h 2023-05-22 14:06:12.000000000 +0800 @@ -85,15 +85,10 @@ SelectType_Image = 3 //图片背景 }; - explicit LunarCalendarItem(QWidget *parent = 0); + explicit LunarCalendarItem(QString font, QWidget *parent = 0); QMap<QString,QMap<QString,QString>> worktime; QString handleJsMap(QString year,QString month2day); //处理js解析出的数据 - protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); void paintEvent(QPaintEvent *); void drawBg(QPainter *painter); void drawBgCurrent(QPainter *painter, const QColor &color); @@ -106,7 +101,7 @@ bool pressed; //鼠标是否按下 bool select; //是否选中 - bool showLunar; //显示农历 + bool showLunar = false; //显示农历 QString bgImage; //背景图片 SelectType selectType; //选中模式 @@ -134,7 +129,7 @@ QColor selectBgColor; //选中日期背景颜色 QColor hoverBgColor; //悬停日期背景颜色 - + QFont m_font; public: // QString getHoliday(int month,int day); @@ -169,7 +164,13 @@ QSize sizeHint() const; QSize minimumSizeHint() const; - + void setFont(const QFont &font){ + m_font = font; + repaint(); + } + void onEnter(); + void onLeave(); + void onSelected(); public Q_SLOTS: //设置是否选中 void setSelect(bool select); diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -18,13 +18,15 @@ #pragma execution_character_set("utf-8") #include "lunarcalendarmonthitem.h" +#include "calendarcolor.h" + #include "qpainter.h" #include "qevent.h" #include "qdatetime.h" #include "qdebug.h" #include <QGSettings> -LunarCalendarMonthItem::LunarCalendarMonthItem(QWidget *parent) : QWidget(parent) +LunarCalendarMonthItem::LunarCalendarMonthItem(QString fontName, QWidget *parent) : QWidget(parent),m_font(fontName) { hover = false; pressed = false; @@ -43,118 +45,81 @@ const QByteArray id("org.ukui.style"); QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); connect(fontSetting, &QGSettings::changed,[=](QString key) { - if(fontSetting->get("style-name").toString() == "ukui-default") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } else if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else if(fontSetting->get("style-name").toString() == "ukui-dark") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); + if((key.compare("style-name") == 0) || (key.compare("theme-color") == 0)|| (key.compare("widget-theme-name")==0) || + (key.compare("styleName") == 0) || (key.compare("themeColor") == 0)|| (key.compare("widgetThemeName")==0) ){ + weekColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + selectBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + //hoverBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + qreal mix = 0.2; + hoverBgColor = CalendarColor::CalendarColor::mixColor(CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED),mix); + this->update(); } }); - if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } + weekColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); borderColor = QColor(180, 180, 180); - superColor = QColor(255, 129, 6); - - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(250, 250, 250); - - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(255, 255, 255); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(55,143,250); - hoverBgColor = QColor(204, 183, 180); + superColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + selectLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + hoverLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + selectBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + //hoverBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + qreal mix = 0.2; + hoverBgColor = CalendarColor::CalendarColor::mixColor(CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED),mix); + setProperty("useStyleWindowManager",false); } -void LunarCalendarMonthItem::enterEvent(QEvent *) +void LunarCalendarMonthItem::onEnter() { - hover = true; - this->update(); + hover = true; + this->update(); } - -void LunarCalendarMonthItem::leaveEvent(QEvent *) +void LunarCalendarMonthItem::onLeave() { - hover = false; - this->update(); + hover = false; + this->update(); } - -void LunarCalendarMonthItem::mousePressEvent(QMouseEvent *) +void LunarCalendarMonthItem::onSelected() { - pressed = true; - this->update(); -// Q_EMIT clicked(date, dayType); Q_EMIT monthMessage(date, dayType); -} - -void LunarCalendarMonthItem::mouseReleaseEvent(QMouseEvent *) -{ - pressed = false; - this->update(); + update(); } void LunarCalendarMonthItem::paintEvent(QPaintEvent *) { - QDate dateNow = QDate::currentDate(); - //绘制准备工作,启用反锯齿 QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - //绘制背景和边框 drawBg(&painter); - //对比当前的时间,画选中状态 if(dateNow.month() == date.month() && dateNow.year() == date.year()) { - drawBgCurrent(&painter, selectBgColor); + drawBgCurrent(&painter, selectBgColor); + if(hover) { + drawBgHover(&painter, hoverBgColor); + } + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + } else { + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); } - //绘制悬停状态 - if (hover) { + if (hover || select) { drawBgHover(&painter, hoverBgColor); } - - //绘制选中状态 - if (select) { - drawBgHover(&painter, hoverBgColor); - } - //绘制日期 drawMonth(&painter); - } void LunarCalendarMonthItem::drawBg(QPainter *painter) @@ -176,7 +141,8 @@ painter->setBrush(color); QRect rect = this->rect(); - painter->drawRoundedRect(rect,4,4); + rect = QRect(rect.x()+1,rect.y()+1,rect.width()-2,rect.height()-2); + painter->drawRoundedRect(rect,6,6); painter->restore(); } @@ -185,10 +151,9 @@ { painter->save(); QRect rect = this->rect(); - painter->setPen(QPen(QColor(55,143,250),2)); - - painter->drawRoundedRect(rect,4,4); - + rect = QRect(rect.x()+1,rect.y()+1,rect.width()-2,rect.height()-2); + painter->setPen(QPen(color,3)); + painter->drawRoundedRect(rect,6,6); painter->restore(); } @@ -210,7 +175,7 @@ painter->setPen(color); - QFont font; + QFont font = m_font; font.setPixelSize(side * 0.2); //设置文字粗细 font.setBold(true); diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h 2023-05-22 14:06:12.000000000 +0800 @@ -78,14 +78,12 @@ SelectType_Image = 3 //图片背景 }; - explicit LunarCalendarMonthItem(QWidget *parent = 0); + explicit LunarCalendarMonthItem(QString fontName, QWidget *parent = 0); QMap<QString,QMap<QString,QString>> worktime; - + void onEnter(); + void onLeave(); + void onSelected(); protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); void paintEvent(QPaintEvent *); void drawBg(QPainter *painter); void drawBgCurrent(QPainter *painter, const QColor &color); @@ -125,7 +123,7 @@ QColor selectBgColor; //选中日期背景颜色 QColor hoverBgColor; //悬停日期背景颜色 - + QFont m_font; public: bool getSelect() const; @@ -159,7 +157,10 @@ QSize sizeHint() const; QSize minimumSizeHint() const; - + void setFont(const QFont &font){ + m_font = font; + repaint(); + } public Q_SLOTS: //设置是否选中 void setSelect(bool select); diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -15,22 +15,29 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. * */ - -#pragma execution_character_set("utf-8") - #include "lunarcalendarwidget.h" - +#include "calendarcolor.h" +#include <QtDBus/QDBusInterface> +#include <QtDBus/QDBusReply> +#include <unistd.h> #include<QDebug> #include <QJsonParseError> #include <QJsonObject> #include <QProcess> - - +#include <QGesture> +#include <KWindowEffects> +#include <KWindowSystem> +#include <ukuistylehelper/ukuistylehelper.h> #define PANEL_CONTROL_IN_CALENDAR "org.ukui.control-center.panel.plugins" #define LUNAR_KEY "calendar" #define FIRST_DAY_KEY "firstday" +#define TRANSPARENCY_SETTING "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + #define ORG_UKUI_STYLE "org.ukui.style" +#define SYSTEM_FONT_SIZE "systemFontSize" +#define SYSTEM_FONT "systemFont" #define STYLE_NAME "styleName" #define STYLE_NAME_KEY_DARK "ukui-dark" #define STYLE_NAME_KEY_DEFAULT "ukui-default" @@ -39,56 +46,62 @@ #define STYLE_NAME_KEY_WHITE "ukui-white" #define ICON_COLOR_LOGHT 255 #define ICON_COLOR_DRAK 0 - +QDate LunarCalendarWidget::s_clickDate = QDate(); LunarCalendarWidget::LunarCalendarWidget(QWidget *parent) : QWidget(parent) { + setObjectName("LunarCalendarWidget"); + installEventFilter(this); + setMouseTracking(true); analysisWorktimeJs(); + + btnYear = new QPushButton; + btnMonth = new QPushButton; + btnToday = new QPushButton; + btnClick = false; + + calendarStyle = CalendarStyle_Red; + date = QDate::currentDate(); + + widgetTime = new QWidget; + timeShow = new QVBoxLayout(widgetTime); + + datelabel =new QLabel(this); + timelabel = new QLabel(this); + lunarlabel = new QLabel(this); + + widgetTime->setObjectName("widgetTime"); + timeShow->setContentsMargins(16, 16, 16, 0); + initWidget(); + + const QByteArray calendar_id(PANEL_CONTROL_IN_CALENDAR); if(QGSettings::isSchemaInstalled(calendar_id)){ calendar_gsettings = new QGSettings(calendar_id); //农历切换监听与日期显示格式 connect(calendar_gsettings, &QGSettings::changed, this, [=] (const QString &key){ if(key == LUNAR_KEY){ - if(calendar_gsettings->get("calendar").toString() == "lunar") { - - QLocale locale = (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English)); - - if(locale == QLocale::Chinese){ - //农历模式且是中文模式 - qDebug()<<"语言模式1:"<<locale; - lunarstate = true; - labWidget->setVisible(true); - yijiWidget->setVisible(true); - }else{ - qDebug()<<"农历模式但非中文模式则不能显示农历相关"; - lunarstate = false; - labWidget->setVisible(false); - yijiWidget->setVisible(false); - } - - } else { - //公历 - lunarstate = false; - labWidget->setVisible(false); - yijiWidget->setVisible(false); - } + m_showLunar = getShowLunar(); + setShowLunar(m_showLunar); _timeUpdate(); } - - if(key == "date") { + else if(key == "date") { if(calendar_gsettings->get("date").toString() == "cn"){ - dateShowMode = "yyyy/MM/dd dddd"; + dateShowMode = "yyyy/MM/dd dddd"; } else { - dateShowMode = "yyyy-MM-dd dddd"; + dateShowMode = "yyyy-MM-dd dddd"; } + } else if (key == FIRST_DAY_KEY) { + setWeekNameFormat(calendar_gsettings->get(FIRST_DAY_KEY).toString() == "sunday"); } }); if(calendar_gsettings->get("date").toString() == "cn"){ - dateShowMode = "yyyy/MM/dd dddd"; + dateShowMode = "yyyy/MM/dd dddd"; } else { - dateShowMode = "yyyy-MM-dd dddd"; + dateShowMode = "yyyy-MM-dd dddd"; } - + m_showLunar = getShowLunar(); + setShowLunar(m_showLunar); + setWeekNameFormat(calendar_gsettings->get(FIRST_DAY_KEY).toString() == "sunday"); //监听12/24小时制 connect(calendar_gsettings, &QGSettings::changed, this, [=] (const QString &keys){ timemodel = calendar_gsettings->get("hoursystem").toString(); @@ -101,9 +114,6 @@ //无设置默认公历 lunarstate = true; } - setWindowOpacity(0.7); - setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 - setProperty("useSystemStyleBlur", true); //设置毛玻璃效果 //判断图形字体是否存在,不存在则加入 QFontDatabase fontDb; if (!fontDb.families().contains("FontAwesome")) { @@ -120,91 +130,34 @@ iconFont.setHintingPreference(QFont::PreferNoHinting); #endif } - - btnYear = new QPushButton; - btnMonth = new QPushButton; - btnToday = new QPushButton; - btnClick = false; - - calendarStyle = CalendarStyle_Red; - date = QDate::currentDate(); - - widgetTime = new QWidget; - timeShow = new QVBoxLayout(widgetTime); - - datelabel =new QLabel(this); - timelabel = new QLabel(this); - lunarlabel = new QLabel(this); - - widgetTime->setObjectName("widgetTime"); - timeShow->setContentsMargins(0, 0, 0, 0); - initWidget(); - if(QGSettings::isSchemaInstalled(calendar_id)){ - //初始化农历/公历显示方式 - if(calendar_gsettings->get("calendar").toString() == "lunar") { - - QLocale locale = (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English)); - qDebug()<<"语言模式2:"<<locale; - if(locale == QLocale::Chinese){ - //农历模式且是中文模式 - qDebug()<<"农历模式且是中文模式"; - lunarstate = true; - labWidget->setVisible(true); - yijiWidget->setVisible(true); - }else{ - qDebug()<<"农历模式但非中文模式则不能显示农历相关"; - lunarstate = false; - labWidget->setVisible(false); - yijiWidget->setVisible(false); - } - - } else { - //公历 - lunarstate = false; - labWidget->setVisible(false); - yijiWidget->setVisible(false); - } - - } - - //切换主题 const QByteArray style_id(ORG_UKUI_STYLE); QStringList stylelist; stylelist<<STYLE_NAME_KEY_DARK<<STYLE_NAME_KEY_BLACK; - if(QGSettings::isSchemaInstalled(style_id)){ + if(QGSettings::isSchemaInstalled(style_id)) { style_settings = new QGSettings(style_id); dark_style=stylelist.contains(style_settings->get(STYLE_NAME).toString()); setColor(dark_style); - } + m_fontName = style_settings->get(SYSTEM_FONT).toString(); + qDebug() << m_fontName; + m_font.setFamily(m_fontName); + } + connect(style_settings, &QGSettings::changed, this, [=] (const QString &key){ if(key==STYLE_NAME){ dark_style=stylelist.contains(style_settings->get(STYLE_NAME).toString()); _timeUpdate(); setColor(dark_style); + }else if(key == SYSTEM_FONT){ + m_fontName = style_settings->get(SYSTEM_FONT).toString(); + qDebug() << m_fontName; + m_font.setFamily(m_fontName); }else{ qDebug()<<"key!=STYLE_NAME"; } }); -// //实时监听系统字体的改变 -// const QByteArray id("org.ukui.style"); -// QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); -// connect(fontSetting, &QGSettings::changed,[=](QString key) { -// if ("systemFont" == key || "systemFontSize" ==key) { -// QFont font = this->font(); -// btnToday->setFont(font); -// cboxYearandMonth->setFont(font); -// for (int i = 0; i < 42; i++) { -// dayItems.value(i)->setFont(font); -// dayItems.value(i)->repaint(); -// } -// for (int i = 0; i < 7; i++) { -// labWeeks.value(i)->setFont(font); -// labWeeks.value(i)->repaint(); -// } -// } -// }); + timer = new QTimer(); connect(timer,SIGNAL(timeout()),this,SLOT(timerUpdate())); @@ -212,15 +165,28 @@ locale = QLocale::system().name(); - if(QGSettings::isSchemaInstalled(calendar_id)){ - setWeekNameFormat(calendar_gsettings->get(FIRST_DAY_KEY).toString() == "sunday"); - setShowLunar(calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"); - } setLocaleCalendar();//设置某区域下日历的显示 - //监听手动更改时间,后期找到接口进行替换 -// QTimer::singleShot(1000,this,[=](){ListenForManualSetTime();}); + initTransparency(); + setWindowOpacity(1); + setAttribute(Qt::WA_TranslucentBackground,true);//设置窗口背景透明 + setProperty("useSystemStyleBlur", true); //设置毛玻璃效果 + setProperty("useStyleWindowManager",false); + + KWindowEffects::enableBlurBehind(winId(),true); + KWindowSystem::setState(winId(),NET::SkipPager|NET::SkipTaskbar); + kdk::UkuiStyleHelper::self()->removeHeader(this); + + _timeUpdate(); } + + +void LunarCalendarWidget::getFontInfo(QString &fontName, int &fontSize) +{ + qDebug() << __FILE__ <<__FUNCTION__; + fontName = m_fontName; + fontSize = m_fontSize; +} LunarCalendarWidget::~LunarCalendarWidget() { } @@ -239,81 +205,46 @@ weekBgColor = QColor(180, 180, 180); if(QGSettings::isSchemaInstalled(calendar_id)){ - showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; + m_showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; } bgImage = ":/image/bg_calendar.png"; selectType = SelectType_Rect; - - borderColor = QColor(180, 180, 180); - weekColor = QColor(255, 255, 255); - superColor = QColor(255, 129, 6); - lunarColor = QColor(233, 90, 84); - - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(125, 125, 125); - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(0, 0, 0); - - currentLunarColor = QColor(150, 150, 150); - otherLunarColor = QColor(200, 200, 200); - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(0, 0, 0); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(80, 100, 220); - hoverBgColor = QColor(80, 190, 220); }else{ weekTextColor = QColor(255, 255, 255); weekBgColor = QColor(0, 0, 0); if(QGSettings::isSchemaInstalled(calendar_id)){ - showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; + m_showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; } bgImage = ":/image/bg_calendar.png"; selectType = SelectType_Rect; - - borderColor = QColor(180, 180, 180); - weekColor = QColor(0, 0, 0); - superColor = QColor(255, 129, 6); - lunarColor = QColor(233, 90, 84); - - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(125, 125, 125); - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(0, 0, 0); - - currentLunarColor = QColor(150, 150, 150); - otherLunarColor = QColor(200, 200, 200); - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(250, 250, 250); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(80, 100, 220); - hoverBgColor = QColor(80, 190, 220); } - initStyle(); + initStyle(); } void LunarCalendarWidget::_timeUpdate() { QDateTime time = QDateTime::currentDateTime(); - QLocale locale /*= (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English))*/; + QLocale locale = (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English)); QString _time; if(timemodel == "12") { - _time = locale.toString(time,"Ahh:mm:ss"); + if(locale.language() == QLocale::English){ + _time = time.toString("hh:mm:ss A"); + //_time = locale.toString(time,"hh:mm:ss A"); + } else { + _time = time.toString("A hh:mm:ss"); + //_time = locale.toString(time,"A hh:mm:ss"); + } } else { - _time = locale.toString(time,"hh:mm:ss"); + //_time = locale.toString(time,"hh:mm:ss"); + _time = time.toString("hh:mm:ss"); } - QFont font; + QFont font(m_fontName); datelabel->setText(_time); font.setPointSize(22); datelabel->setFont(font); - datelabel->setAlignment(Qt::AlignHCenter); - QString strHoliday; QString strSolarTerms; QString strLunarFestival; @@ -331,14 +262,29 @@ strLunarMonth, strLunarDay); - QString _date = locale.toString(time,dateShowMode); + //QString _date = locale.toString(time,dateShowMode); + QString _date = time.toString(dateShowMode); if (lunarstate) { - _date = _date + " "+strLunarMonth + strLunarDay; + _date = _date + " "+strLunarMonth + strLunarDay; } timelabel->setText(_date); font.setPointSize(12); timelabel->setFont(font); - timelabel->setAlignment(Qt::AlignHCenter); + QFont font1(m_font); + font1.setPixelSize(22); + QFont font2(m_font); + font2.setPixelSize(12); + QFontMetrics fm(font1); + QFontMetrics fm2(font2); + int h = fm.boundingRect(datelabel->text()).height(); + int h2=fm2.boundingRect(timelabel->text()).height(); + datelabel->setAlignment(Qt::AlignCenter); + timelabel->setAlignment(Qt::AlignCenter); + datelabel->setFixedHeight(h); + timelabel->setFixedHeight(h2); + datelabel->setContentsMargins(0,0,0,0); + timelabel->setContentsMargins(0,0,0,0); + } void LunarCalendarWidget::timerUpdate() @@ -351,116 +297,108 @@ setObjectName("lunarCalendarWidget"); //顶部widget - QWidget *widgetTop = new QWidget; - widgetTop->setObjectName("widgetTop"); - widgetTop->setMinimumHeight(35); + m_widgetTop = new QWidget; + m_widgetTop->setObjectName("widgetTop"); + m_widgetTop->setMinimumHeight(35); //上个月的按钮 - btnPrevYear = new statelabel; + btnPrevYear = new kdk::KBorderlessButton; btnPrevYear->setObjectName("btnPrevYear"); - btnPrevYear->setFixedWidth(35); + btnPrevYear->setFixedWidth(36); + btnPrevYear->setFixedHeight(36); btnPrevYear->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); - QPixmap pixmap1 = QIcon::fromTheme("strIconPath", QIcon::fromTheme("pan-up-symbolic")).pixmap(QSize(24, 24)); - PictureToWhite pictToWhite1; - btnPrevYear->setPixmap(pictToWhite1.drawSymbolicColoredPixmap(pixmap1)); - btnPrevYear->setProperty("useIconHighlightEffect", 0x2); + //btnPrevYear->setProperty("useIconHighlightEffect", 0x2); + btnPrevYear->setIcon(QIcon::fromTheme("ukui-start-symbolic")); //下个月按钮 - btnNextYear = new statelabel; + btnNextYear = new kdk::KBorderlessButton; btnNextYear->setObjectName("btnNextYear"); - btnNextYear->setFixedWidth(35); - btnNextYear->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); - QPixmap pixmap2 = QIcon::fromTheme("strIconPath", QIcon::fromTheme("pan-down-symbolic")).pixmap(QSize(24, 24)); - PictureToWhite pictToWhite2; - btnNextYear->setPixmap(pictToWhite2.drawSymbolicColoredPixmap(pixmap2)); + btnNextYear->setFixedWidth(36); + btnNextYear->setFixedHeight(36); + //btnNextYear->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); btnNextYear->setProperty("useIconHighlightEffect", 0x2); + btnNextYear->setIcon(QIcon::fromTheme("ukui-end-symbolic")); - + m_font.setFamily(m_fontName); m_font.setPointSize(12); - + QFont smallfont = m_font; + if(QLocale::system().name() != "zh_CN"){ + smallfont.setPointSize(8); + } //转到年显示 btnYear->setObjectName("btnYear"); btnYear->setFocusPolicy(Qt::NoFocus); btnYear->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - btnYear->setFont(m_font); + btnYear->setFont(smallfont); btnYear->setText(tr("Year")); btnYear->setToolTip(tr("Year")); - btnYear->setStyle(new CustomStyle_pushbutton("ukui-default")); + btnYear->setFixedSize(64,36); + + //btnYear->setStyle(new CustomStyle_pushbutton("ukui-default")); connect(btnYear,&QPushButton::clicked,this,&LunarCalendarWidget::yearWidgetChange); //转到月显示 btnMonth->setObjectName("btnMonth"); btnMonth->setFocusPolicy(Qt::NoFocus); - btnMonth->setFont(m_font); + btnMonth->setFont(smallfont); btnMonth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); btnMonth->setText(tr("Month")); btnMonth->setToolTip(tr("Month")); - btnMonth->setStyle(new CustomStyle_pushbutton("ukui-default")); + btnMonth->setFixedSize(64,36); + //btnMonth->setStyle(new CustomStyle_pushbutton("ukui-default")); connect(btnMonth,&QPushButton::clicked,this,&LunarCalendarWidget::monthWidgetChange); //转到今天 btnToday->setObjectName("btnToday"); btnToday->setFocusPolicy(Qt::NoFocus); - btnToday->setFont(m_font); + btnToday->setFont(smallfont); //btnToday->setFixedWidth(40); - btnToday->setStyle(new CustomStyle_pushbutton("ukui-default")); + //btnToday->setStyle(new CustomStyle_pushbutton("ukui-default")); btnToday->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); btnToday->setText(tr("Today")); btnToday->setToolTip(tr("Today")); + btnToday->setFixedSize(64,36); + btnYear->setProperty("needTranslucent",true); + btnMonth->setProperty("needTranslucent",true); + btnToday->setProperty("needTranslucent",true); + btnYear->setProperty("useButtonPalette", true); + btnMonth->setProperty("useButtonPalette", true); + btnToday->setProperty("useButtonPalette", true); //年份与月份下拉框 暂不用此 cboxYearandMonth = new QComboBox; - cboxYearandMonth->setStyleSheet("QComboBox{background: transparent;font-size: 20px;}" - "QComboBox::down-down{width: 1px;}"); - cboxYearandMonth->setFixedWidth(100); - cboxYearandMonth->setObjectName("cboxYearandMonth"); - for (int i = 1901; i <= 2099; i++) { - for (int j = 1; j <= 12; j++) { - cboxYearandMonth->addItem(QString("%1.%2").arg(i).arg(j)); - } - } - cboxYearandMonthLabel = new QLabel(); - cboxYearandMonthLabel->setFixedWidth(100); + cboxYearandMonthLabel->setFixedWidth(80); cboxYearandMonthLabel->setFont(m_font); - //中间用个空widget隔开 -// QWidget *widgetBlank1 = new QWidget; -// widgetBlank1->setFixedWidth(180); -// QWidget *widgetBlank2 = new QWidget; -// widgetBlank2->setFixedWidth(5); -// QWidget *widgetBlank3 = new QWidget; -// widgetBlank3->setFixedWidth(40); - //顶部横向布局 - QHBoxLayout *layoutTop = new QHBoxLayout(widgetTop); + QHBoxLayout *layoutTop = new QHBoxLayout(m_widgetTop); layoutTop->setContentsMargins(0, 0, 0, 9); -// layoutTop->addItem(new QSpacerItem(5,1));//去掉按钮间的间隔限制 - + layoutTop->addSpacing(8); + layoutTop->addWidget(btnPrevYear); layoutTop->addWidget(cboxYearandMonthLabel); - layoutTop->addStretch(); layoutTop->addWidget(btnNextYear); - layoutTop->addWidget(btnPrevYear); - - layoutTop->addStretch(); layoutTop->addWidget(btnYear); layoutTop->addWidget(btnMonth); layoutTop->addWidget(btnToday); - layoutTop->addStretch(); -// layoutTop->addItem(new QSpacerItem(10,1));//去掉按钮间的间隔限制 + layoutTop->addSpacing(8); //时间 widgetTime->setMinimumHeight(50); + timeShow->setSpacing(4); + timeShow->addStretch(); timeShow->addWidget(datelabel);//, Qt::AlignHCenter); + timeShow->addSpacing(4); timeShow->addWidget(timelabel);//,Qt::AlignHCenter); - + timeShow->addStretch(); //星期widget widgetWeek = new QWidget; widgetWeek->setObjectName("widgetWeek"); widgetWeek->setMinimumHeight(30); + widgetWeek->installEventFilter(this); //星期布局 QHBoxLayout *layoutWeek = new QHBoxLayout(widgetWeek); @@ -469,28 +407,32 @@ for (int i = 0; i < 7; i++) { QLabel *lab = new QLabel; - lab->setFont(m_font); + lab->setObjectName(QString("WeekLabel_%1").arg(i)); + QFont font(m_font); + font.setPixelSize(14); + lab->setFont(font); lab->setAlignment(Qt::AlignCenter); layoutWeek->addWidget(lab); labWeeks.append(lab); } - //日期标签widget - widgetDayBody = new QWidget; - widgetDayBody->setObjectName("widgetDayBody"); - + m_widgetDayBody = new QWidget; + m_widgetDayBody->setObjectName("widgetDayBody"); + m_widgetDayBody->setAttribute(Qt::WA_TransparentForMouseEvents,true); //日期标签布局 - QGridLayout *layoutBodyDay = new QGridLayout(widgetDayBody); + QGridLayout *layoutBodyDay = new QGridLayout(m_widgetDayBody); layoutBodyDay->setMargin(1); layoutBodyDay->setHorizontalSpacing(0); layoutBodyDay->setVerticalSpacing(0); //逐个添加日标签 for (int i = 0; i < 42; i++) { - LunarCalendarItem *lab = new LunarCalendarItem; + LunarCalendarItem *lab = new LunarCalendarItem(m_fontName); + lab->setObjectName(QString("DayLabel_%1").arg(i)); + lab->installEventFilter(this); lab->worktime = worktime; - connect(lab, SIGNAL(clicked(QDate, LunarCalendarItem::DayType)), this, SLOT(clicked(QDate, LunarCalendarItem::DayType))); + connect(lab, SIGNAL(clicked(QDate, LunarCalendarItem::DayType)), this, SLOT(labClicked(QDate, LunarCalendarItem::DayType))); layoutBodyDay->addWidget(lab, i / 7, i % 7); dayItems.append(lab); } @@ -498,7 +440,7 @@ //年份标签widget widgetYearBody = new QWidget; widgetYearBody->setObjectName("widgetYearBody"); - + widgetYearBody->setAttribute(Qt::WA_TransparentForMouseEvents,true); //年份标签布局 QGridLayout *layoutBodyYear = new QGridLayout(widgetYearBody); layoutBodyYear->setMargin(1); @@ -507,7 +449,9 @@ //逐个添加年标签 for (int i = 0; i < 12; i++) { - LunarCalendarYearItem *labYear = new LunarCalendarYearItem; + LunarCalendarYearItem *labYear = new LunarCalendarYearItem(m_fontName); + labYear->setObjectName(QString("YEARLabel_%1").arg(i)); + labYear->installEventFilter(this); connect(labYear, SIGNAL(yearMessage(QDate, LunarCalendarYearItem::DayType)), this, SLOT(updateYearClicked(QDate, LunarCalendarYearItem::DayType))); layoutBodyYear->addWidget(labYear, i / 3, i % 3); yearItems.append(labYear); @@ -517,7 +461,7 @@ //月份标签widget widgetmonthBody = new QWidget; widgetmonthBody->setObjectName("widgetmonthBody"); - + widgetmonthBody->setAttribute(Qt::WA_TransparentForMouseEvents,true); //月份标签布局 QGridLayout *layoutBodyMonth = new QGridLayout(widgetmonthBody); layoutBodyMonth->setMargin(1); @@ -526,35 +470,40 @@ //逐个添加月标签 for (int i = 0; i < 12; i++) { - LunarCalendarMonthItem *labMonth = new LunarCalendarMonthItem; + LunarCalendarMonthItem *labMonth = new LunarCalendarMonthItem(m_fontName); + labMonth->setObjectName(QString("MONTHLabel_%1").arg(i)); + labMonth->installEventFilter(this); connect(labMonth, SIGNAL(monthMessage(QDate, LunarCalendarMonthItem::DayType)), this, SLOT(updateMonthClicked(QDate, LunarCalendarMonthItem::DayType))); layoutBodyMonth->addWidget(labMonth, i / 3, i % 3); monthItems.append(labMonth); } widgetmonthBody->hide(); - QFont font; + QFont font(m_fontName); font.setPointSize(12); labWidget = new QWidget(); + labWidget->installEventFilter(this); labBottom = new QLabel(); + labBottom->installEventFilter(this); yijichooseLabel = new QLabel(); yijichooseLabel->setText("宜忌"); yijichooseLabel->setFont(font); - + yijichooseLabel->installEventFilter(this); labBottom->setFont(font); + labBottom->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); yijichoose = new QCheckBox(); + yijichoose->installEventFilter(this); labLayout = new QHBoxLayout(); labLayout->addWidget(labBottom); - labLayout->addItem(new QSpacerItem(100,5,QSizePolicy::Expanding,QSizePolicy::Minimum)); + labLayout->addStretch(); labLayout->addWidget(yijichooseLabel); labLayout->addWidget(yijichoose); labWidget->setLayout(labLayout); yijiLayout = new QVBoxLayout; yijiWidget = new QWidget; -// yijiWidget->setFixedHeight(60); yiLabel = new QLabel(); jiLabel = new QLabel(); @@ -568,10 +517,13 @@ jiLabel->setVisible(false); connect(yijichoose,&QRadioButton::clicked,this,&LunarCalendarWidget::customButtonsClicked); - + //默认打开黄历菜单 + yijichoose->setChecked(true); + yijistate = true; + Q_EMIT yijichoose->clicked(true); //主布局 - lineUp = new m_PartLineWidget(); - lineDown = new m_PartLineWidget(); + lineUp = new PartLineWidget(); + lineDown = new PartLineWidget(); lineUp->setFixedSize(440, 1); lineDown->setFixedSize(440, 1); @@ -579,83 +531,102 @@ verLayoutCalendar->setMargin(0); verLayoutCalendar->setSpacing(0); verLayoutCalendar->addWidget(widgetTime); - verLayoutCalendar->addItem(new QSpacerItem(10,10)); + verLayoutCalendar->addItem(new QSpacerItem(8,8)); verLayoutCalendar->addWidget(lineUp); - verLayoutCalendar->addItem(new QSpacerItem(10,10)); - verLayoutCalendar->addWidget(widgetTop); + verLayoutCalendar->addItem(new QSpacerItem(8,8)); + verLayoutCalendar->addWidget(m_widgetTop); verLayoutCalendar->addWidget(widgetWeek); - verLayoutCalendar->addWidget(widgetDayBody, 1); + verLayoutCalendar->addWidget(m_widgetDayBody, 1); verLayoutCalendar->addWidget(widgetYearBody, 1); verLayoutCalendar->addWidget(widgetmonthBody, 1); + verLayoutCalendar->addItem(new QSpacerItem(8,8)); verLayoutCalendar->addWidget(lineDown); + verLayoutCalendar->addItem(new QSpacerItem(8,8)); verLayoutCalendar->addWidget(labWidget); verLayoutCalendar->addWidget(yijiWidget); - + widgetWeek->setContentsMargins(16,0,16,0); + m_widgetDayBody->setContentsMargins(16,0,16,0); + widgetYearBody->setContentsMargins(16,0,16,0); + widgetmonthBody->setContentsMargins(16,0,16,0); + labWidget->setContentsMargins(16,0,16,0); + yijiWidget->setContentsMargins(16,0,16,16); //绑定按钮和下拉框信号 -// connect(btnPrevYear, SIGNAL(clicked(bool)), this, SLOT(showPreviousYear())); -// connect(btnNextYear, SIGNAL(clicked(bool)), this, SLOT(showNextYear())); - connect(btnPrevYear, SIGNAL(labelclick()), this, SLOT(showPreviousMonth())); - connect(btnNextYear, SIGNAL(labelclick()), this, SLOT(showNextMonth())); + connect(btnPrevYear, &kdk::KBorderlessButton::clicked, this, [=]() { + switch (m_currentType) { + case 0: + showPreviousMonth(true); + break; + case 2: + changeYear(false); + break; + case 1: + default: + break; + } + }); + connect(btnNextYear, &kdk::KBorderlessButton::clicked, this, [=](){ + switch (m_currentType) { + case 0: + showNextMonth(true); + break; + case 2: + changeYear(true); + break; + case 1: + default: + break; + } + }); connect(btnToday, SIGNAL(clicked(bool)), this, SLOT(showToday())); - connect(cboxYearandMonth, SIGNAL(currentIndexChanged(QString)), this, SLOT(yearChanged(QString))); +// connect(cboxYearandMonth, SIGNAL(currentIndexChanged(QString)), this, SLOT(yearChanged(QString))); // connect(cboxMonth, SIGNAL(currentIndexChanged(QString)), this, SLOT(monthChanged(QString))); + yijichoose->setProperty("needTranslucent",true); } //设置日历的地区 void LunarCalendarWidget::setLocaleCalendar() { - +#if 0 QStringList res = getLocale(); qDebug()<<"设置区域:"<<res.at(0); int isCN = res.at(0) == "zh_CN.UTF-8" ? 1 : 0; - if(isCN){ - if (FirstdayisSun) { - labWeeks.at(0)->setText("周日"); - labWeeks.at(1)->setText("周一"); - labWeeks.at(2)->setText("周二"); - labWeeks.at(3)->setText("周三"); - labWeeks.at(4)->setText("周四"); - labWeeks.at(5)->setText("周五"); - labWeeks.at(6)->setText("周六"); - } else { - labWeeks.at(0)->setText("周一"); - labWeeks.at(1)->setText("周二"); - labWeeks.at(2)->setText("周三"); - labWeeks.at(3)->setText("周四"); - labWeeks.at(4)->setText("周五"); - labWeeks.at(5)->setText("周六"); - labWeeks.at(6)->setText("周日"); - } - }else{ - if (FirstdayisSun){ - labWeeks.at(0)->setText("Sun"); - labWeeks.at(1)->setText("Mon"); - labWeeks.at(2)->setText("Tue"); - labWeeks.at(3)->setText("Wed"); - labWeeks.at(4)->setText("Thur"); - labWeeks.at(5)->setText("Fri"); - labWeeks.at(6)->setText("Sat"); - }else { - labWeeks.at(0)->setText("Mon"); - labWeeks.at(1)->setText("Tue"); - labWeeks.at(2)->setText("Wed"); - labWeeks.at(3)->setText("Thur"); - labWeeks.at(4)->setText("Fri"); - labWeeks.at(5)->setText("Sat"); - labWeeks.at(6)->setText("Sun"); - } +#else + QString language; + QString locale; + QStringList res = getLocale(language,locale); + qDebug() << language << locale; + qDebug()<<"设置区域:"<<res.at(0); + //int isCN = res.at(0) == "zh_CN.UTF-8" ? 1 : 0; + bool isCN = language.contains("zh_CN"); +#endif + if (FirstdayisSun){ + labWeeks.at(0)->setText(tr("Sun")); + labWeeks.at(1)->setText(tr("Mon")); + labWeeks.at(2)->setText(tr("Tue")); + labWeeks.at(3)->setText(tr("Wed")); + labWeeks.at(4)->setText(tr("Thur")); + labWeeks.at(5)->setText(tr("Fri")); + labWeeks.at(6)->setText(tr("Sat")); + }else { + labWeeks.at(0)->setText(tr("Mon")); + labWeeks.at(1)->setText(tr("Tue")); + labWeeks.at(2)->setText(tr("Wed")); + labWeeks.at(3)->setText(tr("Thur")); + labWeeks.at(4)->setText(tr("Fri")); + labWeeks.at(5)->setText(tr("Sat")); + labWeeks.at(6)->setText(tr("Sun")); } } //获取指定地区的编号代码 -QStringList LunarCalendarWidget::getLocale() +QStringList LunarCalendarWidget::getLocale(QString &language, QString &locale) { //判断区域(美国/中国) QString objpath; unsigned int uid = getuid(); objpath = objpath +"/org/freedesktop/Accounts/User"+QString::number(uid); QString formats; - QString language; + QString lang; QStringList result; QDBusInterface localeInterface("org.freedesktop.Accounts", @@ -668,15 +639,17 @@ propertyMap = reply.value(); if (propertyMap.keys().contains("FormatsLocale")) { formats = propertyMap.find("FormatsLocale").value().toString(); + locale = formats; } - if(language.isEmpty() && propertyMap.keys().contains("Language")) { - language = propertyMap.find("Language").value().toString(); + if(lang.isEmpty() && propertyMap.keys().contains("Language")) { + lang = propertyMap.find("Language").value().toString(); + language = lang; } } else { qDebug() << "reply failed"; } result.append(formats); - result.append(language); + result.append(lang); return result; } @@ -684,24 +657,24 @@ void LunarCalendarWidget::initStyle() { //设置样式 - QStringList qss; +// QStringList qss; - //自定义日控件颜色 - QString strSelectType; - if (selectType == SelectType_Rect) { - strSelectType = "SelectType_Rect"; - } else if (selectType == SelectType_Circle) { - strSelectType = "SelectType_Circle"; - } else if (selectType == SelectType_Triangle) { - strSelectType = "SelectType_Triangle"; - } else if (selectType == SelectType_Image) { - strSelectType = "SelectType_Image"; - } +// //自定义日控件颜色 +// QString strSelectType; +// if (selectType == SelectType_Rect) { +// strSelectType = "SelectType_Rect"; +// } else if (selectType == SelectType_Circle) { +// strSelectType = "SelectType_Circle"; +// } else if (selectType == SelectType_Triangle) { +// strSelectType = "SelectType_Triangle"; +// } else if (selectType == SelectType_Image) { +// strSelectType = "SelectType_Image"; + //} //计划去掉qss,保留农历切换的设置 - qss.append(QString("LunarCalendarItem{qproperty-showLunar:%1;}").arg(showLunar)); + //qss.append(QString("LunarCalendarItem{qproperty-showLunar:%1;}").arg(m_showLunar)); - this->setStyleSheet(qss.join("")); + // this->setStyleSheet(qss.join("")); } void LunarCalendarWidget::analysisWorktimeJs() @@ -742,14 +715,20 @@ if (widgetYearBody->isHidden()){ widgetYearBody->show(); widgetWeek->hide(); - widgetDayBody->hide(); + m_widgetDayBody->hide(); widgetmonthBody->hide(); + changeMode(2); + m_savedYear = date.year(); + qDebug () << m_savedYear; } else{ widgetYearBody->hide(); widgetWeek->show(); - widgetDayBody->show(); + m_widgetDayBody->show(); widgetmonthBody->hide(); + date.setDate(m_savedYear,date.month(),date.day()); + changeMode(0); + initDate(); } } @@ -759,17 +738,29 @@ if(widgetmonthBody->isHidden()){ widgetYearBody->hide(); widgetWeek->hide(); - widgetDayBody->hide(); + m_widgetDayBody->hide(); widgetmonthBody->show(); + changeMode(1); } else{ widgetYearBody->hide(); widgetWeek->show(); - widgetDayBody->show(); + m_widgetDayBody->show(); widgetmonthBody->hide(); + changeMode(0); + } +} +void LunarCalendarWidget::changeMode(int mode) +{ + m_currentType = mode; + if(mode == 1 || mode == 2) { + btnNextYear->setEnabled(false); + btnPrevYear->setEnabled(false); + } else { + btnNextYear->setEnabled(true); + btnPrevYear->setEnabled(true); } } - //初始化日期面板 void LunarCalendarWidget::initDate() @@ -786,10 +777,15 @@ //设置为今天,设置变量防止重复触发 btnClick = true; - cboxYearandMonth->setCurrentIndex(cboxYearandMonth->findText(QString("%1.%2").arg(year).arg(month))); + //cboxYearandMonth->setCurrentIndex(cboxYearandMonth->findText(QString("%1.%2").arg(year).arg(month))); btnClick = false; - cboxYearandMonthLabel->setText(QString(" %1.%2").arg(year).arg(month)); + cboxYearandMonthLabel->setAlignment(Qt::AlignCenter); + if(m_currentType != 2){ + cboxYearandMonthLabel->setText(QString("%1.%2").arg(year).arg(month)); + } else { + cboxYearandMonthLabel->setText(QString("%1.%2").arg(m_savedYear).arg(month)); + } //首先判断当前月的第一天是星期几 int week = LunarCalendarInfo::Instance()->getFirstDayOfWeek(year, month, FirstdayisSun); @@ -828,6 +824,7 @@ QDate date(tempYear, tempMonth, tempDay); QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthPre); + dayItems.at(index)->setFont(m_fontName); } //纠正12月份后面部分偏差,12月份后面部分是下一年1月份 @@ -851,6 +848,7 @@ //重新置为当前年月 tempYear = year; tempMonth = month; + QFont font(m_fontName); //显示当前月 for (int i = week; i < (countDay + week); i++) { @@ -859,17 +857,47 @@ QDate date(tempYear, tempMonth, tempDay); QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - if (0 == (i % 7) || 6 == (i % 7)) { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_WeekEnd); - } else { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthCurrent); - } + dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthCurrent); } for (int i=0;i<12;i++){ + monthItems.at(i)->setDate(QDate(date.year(),i+1,1)); yearItems.at(i)->setDate(date.addYears(i)); - monthItems.at(i)->setDate(date.addMonths(i)); + yearItems.at(i)->setFont(font); + monthItems.at(i)->setFont(font); } + auto it = dayItems.begin(); + for(;it!=dayItems.end();it++){ + (*it)->setFont(font); + } + + auto itw = labWeeks.begin(); + QFont f(m_fontName); + f.setPixelSize(14); + for(;itw!=labWeeks.end();itw++){ + (*itw)->setFont(f); + } + + labBottom->setFont(m_font); + labBottom->repaint(); + + yijichooseLabel->setFont(m_font); + yijichooseLabel->repaint(); + + yiLabel->setFont(m_font); + jiLabel->setFont(m_font); + yijiWidget->repaint(); + QFont smallfont = m_font; + if(QLocale::system().name() != "zh_CN"){ + smallfont.setPointSize(8); + } + btnYear->setFont(smallfont); + btnYear->repaint(); + btnToday->setFont(smallfont); + btnToday->repaint(); + btnMonth->setFont(smallfont); + btnMonth->repaint(); + m_widgetTop->repaint(); } void LunarCalendarWidget::customButtonsClicked(int x) @@ -919,7 +947,7 @@ strLunarMonth, strLunarDay); - QString labBottomarg = " " + strLunarYear + " " + strLunarMonth + strLunarDay; + QString labBottomarg = strLunarYear + " " + strLunarMonth + strLunarDay; labBottom->setText(labBottomarg); } @@ -948,14 +976,14 @@ QString yiString; QString jiString; if (item["y"].toString() == "."){ - yiString = " 宜:"; + yiString = "宜:"; }else { - yiString = " 宜:" + item["y"].toString(); + yiString = "宜:" + item["y"].toString(); } if (item["j"].toString() == "."){ - jiString = " 忌:"; + jiString = "忌:"; }else { - jiString = " 忌:" + item["j"].toString(); + jiString = "忌:" + item["j"].toString(); } yiLabel->setText(yiString); @@ -992,15 +1020,20 @@ dateChanged(year, month, day); } -void LunarCalendarWidget::clicked(const QDate &date, const LunarCalendarItem::DayType &dayType) +void LunarCalendarWidget::labClicked(const QDate &date, const LunarCalendarItem::DayType &dayType) { this->date = date; - clickDate = date; - dayChanged(this->date,clickDate); - if (LunarCalendarItem::DayType_MonthPre == dayType) + s_clickDate = date; + qDebug() << s_clickDate; + if (LunarCalendarItem::DayType_MonthPre == dayType){ showPreviousMonth(false); - else if (LunarCalendarItem::DayType_MonthNext == dayType) + } + else if (LunarCalendarItem::DayType_MonthNext == dayType) { showNextMonth(false); + } + else{ + dayChanged(this->date,s_clickDate); + } } void LunarCalendarWidget::updateYearClicked(const QDate &date, const LunarCalendarYearItem::DayType &dayType) @@ -1009,15 +1042,12 @@ this->date = date; widgetYearBody->hide(); widgetWeek->show(); - widgetDayBody->show(); + m_widgetDayBody->show(); widgetmonthBody->hide(); -// qDebug()<<"year:::::::::::::::::::::"<<date; - clickDate = date; + s_clickDate = date; changeDate(date); - dayChanged(date,clickDate); -// for (int i = 0; i < 12; i++) { -// qDebug()<<"*******************"<<"循环位:"<<i<<yearItems.at(i)->date; -// } + dayChanged(date,QDate()); + changeMode(0); } void LunarCalendarWidget::updateMonthClicked(const QDate &date, const LunarCalendarMonthItem::DayType &dayType) @@ -1026,12 +1056,13 @@ this->date = date; widgetYearBody->hide(); widgetWeek->show(); - widgetDayBody->show(); + m_widgetDayBody->show(); widgetmonthBody->hide(); - qDebug()<<date; - clickDate = date; +// qDebug()<<date; + s_clickDate = date; changeDate(date); - dayChanged(date,clickDate); + dayChanged(date,QDate()); + changeMode(0); } void LunarCalendarWidget::changeDate(const QDate &date) @@ -1045,13 +1076,12 @@ oneRun = false; } - //设置为今天,设置变量防止重复触发 btnClick = true; - cboxYearandMonth->setCurrentIndex(cboxYearandMonth->findText(QString("%1.%2").arg(year).arg(month))); + //cboxYearandMonth->setCurrentIndex(cboxYearandMonth->findText(QString("%1.%2").arg(year).arg(month))); btnClick = false; - cboxYearandMonthLabel->setText(QString(" %1.%2").arg(year).arg(month)); + cboxYearandMonthLabel->setText(QString("%1.%2").arg(year).arg(month)); //首先判断当前月的第一天是星期几 int week = LunarCalendarInfo::Instance()->getFirstDayOfWeek(year, month, FirstdayisSun); @@ -1121,17 +1151,12 @@ QDate date(tempYear, tempMonth, tempDay); QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - if (0 == (i % 7) || 6 == (i % 7)) { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_WeekEnd); - } else { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthCurrent); - } + dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthCurrent); } for (int i=0;i<12;i++){ - yearItems.at(i)->setDate(clickDate.addYears(i)); -// qDebug()<<"*******************"<<"循环位:"<<i<<yearItems.at(i); - monthItems.at(i)->setDate(clickDate.addMonths(i)); + yearItems.at(i)->setDate(s_clickDate.addYears(i)); + monthItems.at(i)->setDate(QDate(s_clickDate.year(),i+1,1)); } } @@ -1169,10 +1194,53 @@ void LunarCalendarWidget::dateChanged(int year, int month, int day) { //如果原有天大于28则设置为1,防止出错 + if(year <= 1970 || year >=2099){ + return ; + } date.setDate(year, month, day > 28 ? 1 : day); initDate(); } +bool LunarCalendarWidget::getShowLunar() +{ + //语言是简体或繁体中文且区域是中国且GSetting的值时, + //这个时候才显示农历和黄历信息 + QString lang,format; + getLocale(lang,format); + qDebug() << lang << format << (calendar_gsettings->get("calendar").toString() == "lunar") ; + if((format.contains("zh_CN")) && + (lang.contains("zh_CN")||lang.contains("zh_HK")) && + (calendar_gsettings->get("calendar").toString() == "lunar")){ + m_showLunar = true; + }else { + m_showLunar = false; + } + return m_showLunar; +} + +void LunarCalendarWidget::setShowLunar(bool showLunar) +{ + qDebug() << __FILE__ << __LINE__ << __FUNCTION__; + bool realShow = showLunar & yijistate; + //日界面需要重绘 + for(auto i = 0 ;i < dayItems.size();i++) { + dayItems.at(i)->setShowLunar(realShow); + } + //日期字符串要重新写 + lunarstate = realShow; + //黄历信息不能再显示了 + yiLabel->setVisible(realShow); + jiLabel->setVisible(realShow); + //yijistate = realShow; + labWidget->setVisible(showLunar); + yijiWidget->setVisible(showLunar); + yijichoose->setChecked(yijistate); + //重新布局当前窗口 + Q_EMIT almanacChanged(realShow); +} + + + LunarCalendarWidget::CalendarStyle LunarCalendarWidget::getCalendarStyle() const { return this->calendarStyle; @@ -1193,11 +1261,6 @@ return this->weekBgColor; } -bool LunarCalendarWidget::getShowLunar() const -{ - return this->showLunar; -} - QString LunarCalendarWidget::getBgImage() const { return this->bgImage; @@ -1340,9 +1403,7 @@ month = 12; year--; } - dateChanged(year, month, day); -// dayChanged(this->date,clickDate); } //显示下月日期 @@ -1371,11 +1432,13 @@ { widgetYearBody->hide(); widgetmonthBody->hide(); - widgetDayBody->show(); + m_widgetDayBody->show(); widgetWeek->show(); date = QDate::currentDate(); + changeMode(0); initDate(); - dayChanged(this->date,clickDate); + s_clickDate = date; + dayChanged(this->date,QDate()); } void LunarCalendarWidget::setCalendarStyle(const LunarCalendarWidget::CalendarStyle &calendarStyle) @@ -1416,21 +1479,6 @@ } } -void LunarCalendarWidget::setShowLunar(bool showLunar) -{ - if(calendar_gsettings!=nullptr){ - if (locale == "zh_CN"){ - qDebug()<<"中文模式"; - showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; - }else if (locale == "en_US"){ - qDebug()<<"英文模式"; - showLunar = false; - } - } - this->showLunar = showLunar; - initStyle(); -} - void LunarCalendarWidget::setBgImage(const QString &bgImage) { if (this->bgImage != bgImage) { @@ -1574,35 +1622,283 @@ initStyle(); } } +void LunarCalendarWidget::changeMonth(bool forward) +{ + int year = date.year(); + int month = date.month(); + int day = date.day(); + if (year <= 1901 && month == 1) { + return; + } + if(forward){ + month +=3; + if(month > 12) { + year += 1; + month -=12; + } + }else{ + month -=3; + if(month<=0){ + year -=1; + month +=12; + } + } + + dateChanged(year, month, day); +} +void LunarCalendarWidget::changeYear(bool forward) +{ + int year = date.year(); + int month = date.month(); + int day = date.day(); + if (year <= 1901 || year >= 2099) { + return; + } -void LunarCalendarWidget::wheelEvent(QWheelEvent *event) { - if (event->delta() > 0) - showPreviousMonth(); + if(forward) + year +=3; else - showNextMonth(); + year -=3; + + dateChanged(year, month, day); } +void LunarCalendarWidget::wheelEvent(QWheelEvent *event) { + switch (m_currentType) { + case 0: + if (event->delta() > 100) { + showPreviousMonth(); + } else if (event->delta() < -100) { + showNextMonth(); + } + break; + + case 2: + if (event->delta() > 100) { + //向前三年 + changeYear(false); + } else if (event->delta() < -100){ + //向后三年 + changeYear(true); + } + break; + default: + + case 1: + break; + } + event->accept(); +// return QWidget::wheelEvent(event); + +} + +bool LunarCalendarWidget::eventFilter(QObject *watched, QEvent *event) +{ + if(event->type() == QEvent::MouseButtonPress){ + qDebug() << event->type()<< watched->objectName(); + QMouseEvent *mouse = static_cast<QMouseEvent*>(event); + if(mouse!=nullptr) { + if(watched == this){ + if(mouse->source() == Qt::MouseEventSynthesizedByQt){ + m_start_y = mouse->pos().y(); + } + if(m_currentType == 0){ + QPoint pt = m_widgetDayBody->mapFromGlobal(QCursor::pos()); + for(auto w : dayItems){ + if(w->geometry().contains(pt)) + m_clickedWidget = w; + + } + }else if(m_currentType == 2){ + QPoint pt = widgetYearBody->mapFromGlobal(QCursor::pos()); + for(auto w : yearItems){ + if(w->geometry().contains(pt)) + m_clickedWidget = w; + + } + }else if(m_currentType == 1){ + QPoint pt = widgetmonthBody->mapFromGlobal(QCursor::pos()); + for(auto w: monthItems){ + if(w->geometry().contains(pt)) + m_clickedWidget = w; + } + } + return false; + } + } + }else if(event->type()==QEvent::MouseButtonRelease){ + qDebug() << event->type() << watched->objectName(); + //return -1; + QMouseEvent *mouse = static_cast<QMouseEvent*>(event); + if(mouse!=nullptr) { + if(watched == this){ + if(mouse->source() == Qt::MouseEventSynthesizedByQt){ + //触摸的释放 + if(m_start_y == -1) + return false; + + if( mouse->pos().y() - m_start_y > 100){ + switch(m_currentType){ + case 0: + showNextMonth(); + break; + case 2: + changeYear(true); + break; + } + return false; + }else if(mouse->pos().y() - m_start_y < -100){ + switch(m_currentType){ + case 0: + showPreviousMonth(); + break; + case 2: + changeYear(false); + break; + } + return false; + } + } + //鼠标抬起 + if(m_clickedWidget==nullptr){ + return false; + } + if(m_clickedWidget->geometry().contains(m_widgetDayBody->mapFromGlobal(QCursor::pos()))){ + qDebug() << "选中"; + LunarCalendarItem *item = qobject_cast<LunarCalendarItem*>(m_clickedWidget); + if(dayItems.contains(item)) + item->onSelected(); + + LunarCalendarYearItem *yItem = qobject_cast<LunarCalendarYearItem*>(m_clickedWidget); + if(yearItems.contains(yItem)) + yItem->onSelected(); + + LunarCalendarMonthItem *mItem = qobject_cast<LunarCalendarMonthItem*>(m_clickedWidget); + if(monthItems.contains(mItem)) + mItem->onSelected(); + + } + return false; + } + } + } + else if (event->type()==QEvent::MouseMove){ + QMouseEvent *mouse = static_cast<QMouseEvent*>(event); + if(mouse!=nullptr) { + if(mouse->source()==Qt::MouseEventSynthesizedByQt){ + return -1; + } + } + if(m_currentType == 0){ + for(auto w:dayItems){ + if(w->geometry().contains(m_widgetDayBody->mapFromGlobal(QCursor::pos()))){ + w->onEnter(); + } else { + w->onLeave(); + } + } + } else if(m_currentType == 2){ + for(auto w:yearItems){ + if(w->geometry().contains(widgetYearBody->mapFromGlobal(QCursor::pos()))){ + w->onEnter(); + } else { + w->onLeave(); + } + } + } else if(m_currentType == 1){ + for(auto w:monthItems){ + if(w->geometry().contains(widgetmonthBody->mapFromGlobal(QCursor::pos()))){ + w->onEnter(); + }else{ + w->onLeave(); + } + } + } + return false; + } else if(event->type()==QEvent::Enter){ + LunarCalendarItem *item = qobject_cast<LunarCalendarItem*>(watched); + if(dayItems.contains(item) == true){ + item->onEnter(); + } + LunarCalendarYearItem *yItem = qobject_cast<LunarCalendarYearItem*>(watched); + if(yearItems.contains(yItem)){ + yItem->onEnter(); + } + }else if(event->type()==QEvent::Leave){ + for(auto day : dayItems) + day->onLeave(); + + for(auto year:yearItems) + year->onLeave(); + } else if(event->type()==QEvent::WindowDeactivate){ + this->hide(); + return false; + } + + return false; +} +void LunarCalendarWidget::showCalendar(bool needShowToday) +{ + KWindowSystem::setState(winId(),NET::SkipPager|NET::SkipTaskbar); + show(); + if(needShowToday) { + showToday(); + } +} +void LunarCalendarWidget::initTransparency() +{ + const QByteArray tranparency(TRANSPARENCY_SETTING); + if (QGSettings::isSchemaInstalled(tranparency)){ + m_transparencySetting = new QGSettings(tranparency); + m_trans = m_transparencySetting->get(TRANSPARENCY_KEY).toDouble()*255; + update(); + connect(m_transparencySetting,&QGSettings::changed,this,[=](const QString &key) { + if(key == TRANSPARENCY_KEY) { + m_trans = m_transparencySetting->get(TRANSPARENCY_KEY).toDouble()*255; + update(); + } + }); + } else { + m_trans = 0.75; + update(); + } +} +void LunarCalendarWidget::paintEvent(QPaintEvent*e) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + QColor color = palette().color(QPalette::Base); + color.setAlpha(m_trans); + QBrush brush = QBrush(color); + p.setBrush(brush); + p.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform); + p.setPen(Qt::NoPen); + p.drawRoundedRect(opt.rect,6,6); + return QWidget::paintEvent(e); +} -m_PartLineWidget::m_PartLineWidget(QWidget *parent) : QWidget(parent) +PartLineWidget::PartLineWidget(QWidget *parent) : QWidget(parent) { } -void m_PartLineWidget::paintEvent(QPaintEvent *event) +void PartLineWidget::paintEvent(QPaintEvent *event) { QPainter p(this); QRect rect = this->rect(); p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - QColor color=qApp->palette().color(QPalette::Base); - if(color.red() == 255 && color.green() == 255 && color.blue() == 255){ - color.setRgb(1,1,1,255); - } else if (color.red() == 31 && color.green() == 32 && color.blue() == 34) { - color.setRgb(255,255,255,255); - } + QColor color=qApp->palette().color(QPalette::BrightText); +// if(color.red() == 255 && color.green() == 255 && color.blue() == 255){ +// color.setRgb(1,1,1,255); +// } else if (color.red() == 31 && color.green() == 32 && color.blue() == 34) { +// color.setRgb(255,255,255,255); +// } + //color.setAlphaF(0.08); p.setBrush(color); - p.setOpacity(0.05); + p.setOpacity(0.08); p.setPen(Qt::NoPen); p.drawRoundedRect(rect,0,0); diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendarwidget.h 2023-05-22 14:06:12.000000000 +0800 @@ -54,10 +54,12 @@ #include <QLocale> #include <QProcess> -#include <QtDBus/QDBusInterface> -#include <QtDBus/QDBusReply> -#include <unistd.h> +#include <kysdk/applications/kborderlessbutton.h> +class QGestureEvent; +class QPanGesture; +class QPinchGesture; +class QSwipeGesture; class QLabel; class statelabel; @@ -66,7 +68,7 @@ class LunarCalendarMonthItem; class LunarCalendarItem; -class m_PartLineWidget; +class PartLineWidget; #ifdef quc #if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) @@ -92,7 +94,6 @@ Q_PROPERTY(QColor weekTextColor READ getWeekTextColor WRITE setWeekTextColor) Q_PROPERTY(QColor weekBgColor READ getWeekBgColor WRITE setWeekBgColor) - Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar) Q_PROPERTY(QString bgImage READ getBgImage WRITE setBgImage) Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType) @@ -137,7 +138,8 @@ explicit LunarCalendarWidget(QWidget *parent = 0); ~LunarCalendarWidget(); - + void getFontInfo(QString &fontName, int &fontSize); + bool getShowLunar(); private: QLabel *datelabel; QLabel *timelabel; @@ -151,10 +153,10 @@ QWidget *labWidget; QLabel *labBottom; QHBoxLayout *labLayout; - m_PartLineWidget *lineUp; - m_PartLineWidget *lineDown; - statelabel *btnPrevYear; - statelabel *btnNextYear; + PartLineWidget *lineUp; + PartLineWidget *lineDown; + kdk::KBorderlessButton *btnPrevYear; + kdk::KBorderlessButton *btnNextYear; QLabel *yijichooseLabel; QCheckBox *yijichoose; QVBoxLayout *yijiLayout; @@ -162,11 +164,11 @@ QLabel *yiLabel; QLabel *jiLabel; QWidget *widgetWeek; - QWidget *widgetDayBody; + QWidget *m_widgetDayBody; QWidget *widgetYearBody; QWidget *widgetmonthBody; QProcess *myProcess; - + QWidget *m_widgetTop = nullptr; QString timemodel = 0; bool yijistate = false; bool lunarstate =false; @@ -190,12 +192,11 @@ CalendarStyle calendarStyle; //整体样式 bool FirstdayisSun; //首日期为周日 QDate date; //当前日期 - QDate clickDate; //保存点击日期 + static QDate s_clickDate; //保存点击日期 QColor weekTextColor; //星期名称文字颜色 QColor weekBgColor; //星期名称背景色 - bool showLunar; //显示农历 QString bgImage; //背景图片 SelectType selectType; //选中模式 @@ -229,11 +230,31 @@ QGSettings *style_settings; bool dark_style; - QStringList getLocale(); + QStringList getLocale(QString &language, QString &locale); void setLocaleCalendar(); + void changeMonth(bool forward); + void changeYear(bool forward); + //控制农历、黄历、假期显示功能 + bool m_showLunar = false; + //设置子控件是否显示农历信息 + void setShowLunar(bool showLunar); + //根据gsetting和语言获取show lunar的值 + + int m_currentType = 0;//0:日,1:月, 2:年 + void changeMode(int mode); + QString m_fontName; + int m_fontSize = 0; + int m_start_y = -1; + QWidget *m_clickedWidget = nullptr; + int m_savedYear = 0; + void initTransparency(); + QGSettings *m_transparencySetting = nullptr; + int m_trans = 75; protected : - void wheelEvent(QWheelEvent *event); + void wheelEvent(QWheelEvent *event)override; + bool eventFilter(QObject *watched, QEvent *event)override; + void paintEvent(QPaintEvent*)override; private Q_SLOTS: void initWidget(); @@ -242,23 +263,26 @@ void changeDate(const QDate &date); void yearChanged(const QString &arg1); void monthChanged(const QString &arg1); - void clicked(const QDate &date, const LunarCalendarItem::DayType &dayType); + void labClicked(const QDate &date, const LunarCalendarItem::DayType &dayType); void dayChanged(const QDate &date,const QDate &m_date); void dateChanged(int year, int month, int day); void timerUpdate(); void customButtonsClicked(int x); void yearWidgetChange(); void monthWidgetChange(); - - public: + QDate getCurrentDate(){return date;} + static QDate getClickedDate(){ + qDebug () << s_clickDate; + return s_clickDate; + } + CalendarStyle getCalendarStyle() const; QDate getDate() const; QColor getWeekTextColor() const; QColor getWeekBgColor() const; - bool getShowLunar() const; QString getBgImage() const; SelectType getSelectType() const; @@ -285,7 +309,7 @@ QSize sizeHint() const; QSize minimumSizeHint() const; QString locale ; - + void showCalendar(bool showToday); public Q_SLOTS: void updateYearClicked(const QDate &date, const LunarCalendarYearItem::DayType &dayType); @@ -313,8 +337,7 @@ void setWeekTextColor(const QColor &weekTextColor); void setWeekBgColor(const QColor &weekBgColor); - //设置是否显示农历信息 - void setShowLunar(bool showLunar); + //设置背景图片 void setBgImage(const QString &bgImage); //设置选中背景样式 @@ -361,14 +384,16 @@ void selectionChanged(); void yijiChangeUp(); void yijiChangeDown(); + // true:显示农历、黄历 , false:不显示农历、黄历 + void almanacChanged(bool); }; -class m_PartLineWidget : public QWidget +class PartLineWidget : public QWidget { Q_OBJECT public: - explicit m_PartLineWidget(QWidget *parent = nullptr); + explicit PartLineWidget(QWidget *parent = nullptr); void paintEvent(QPaintEvent *event); }; diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -19,13 +19,15 @@ #pragma execution_character_set("utf-8") #include "lunarcalendaryearitem.h" +#include "calendarcolor.h" + #include "qpainter.h" #include "qevent.h" #include "qdatetime.h" #include "qdebug.h" #include <QGSettings> -LunarCalendarYearItem::LunarCalendarYearItem(QWidget *parent) : QWidget(parent) +LunarCalendarYearItem::LunarCalendarYearItem(QString fontName,QWidget *parent) : QWidget(parent),m_font(fontName) { hover = false; pressed = false; @@ -43,118 +45,83 @@ const QByteArray id("org.ukui.style"); QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); connect(fontSetting, &QGSettings::changed,[=](QString key) { - if(fontSetting->get("style-name").toString() == "ukui-default") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } else if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else if(fontSetting->get("style-name").toString() == "ukui-dark") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); + if((key.compare("style-name") == 0) || (key.compare("theme-color") == 0)|| (key.compare("widget-theme-name")==0) || + (key.compare("styleName") == 0) || (key.compare("themeColor") == 0)|| (key.compare("widgetThemeName")==0) ){ + weekColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + selectBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + //hoverBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + qreal mix = 0.2; + hoverBgColor = CalendarColor::CalendarColor::mixColor(CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED),mix); + + this->update(); } }); - if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - - borderColor = QColor(180, 180, 180); - superColor = QColor(255, 129, 6); - - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(250, 250, 250); - - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(255, 255, 255); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(55,144,250); - hoverBgColor = QColor(204, 183, 180); + weekColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + currentTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + otherTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + otherLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::OTHER_TEXT); + currentLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + lunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); + superColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + selectTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + hoverTextColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + selectLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + hoverLunarColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::WORK); + selectBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + //hoverBgColor = CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED); + qreal mix = 0.2; + hoverBgColor = CalendarColor::CalendarColor::mixColor(CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED),mix); + setProperty("useStyleWindowManager",false); +} + +void LunarCalendarYearItem::onEnter() +{ + hover = true; + this->update(); } - -void LunarCalendarYearItem::enterEvent(QEvent *) +void LunarCalendarYearItem::onLeave() { - hover = true; - this->update(); + hover = false; + this->update(); } - -void LunarCalendarYearItem::leaveEvent(QEvent *) +void LunarCalendarYearItem::onSelected() { - hover = false; - this->update(); -} - -void LunarCalendarYearItem::mousePressEvent(QMouseEvent *) -{ - pressed = true; - this->update(); // Q_EMIT clicked(date, dayType); - Q_EMIT yearMessage(date, dayType); -} - -void LunarCalendarYearItem::mouseReleaseEvent(QMouseEvent *) -{ - pressed = false; - this->update(); + Q_EMIT yearMessage(date,dayType); + update(); } void LunarCalendarYearItem::paintEvent(QPaintEvent *) { - QDate dateNow = QDate::currentDate(); - //绘制准备工作,启用反锯齿 QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - //绘制背景和边框 drawBg(&painter); - //对比当前的时间,画选中状态 if(dateNow.year() == date.year()) { drawBgCurrent(&painter, selectBgColor); + if(hover) { + drawBgHover(&painter, hoverBgColor); + } + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::CLICKED_TEXT); + }else{ + currentTextColor =CalendarColor::CalendarColor::getThemeColor(CalendarColor::TEXT); } - //绘制悬停状态 - if (hover) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制选中状态 - if (select) { + if (hover||select) { drawBgHover(&painter, hoverBgColor); } - //绘制日期 drawYear(&painter); - } void LunarCalendarYearItem::drawBg(QPainter *painter) @@ -176,7 +143,8 @@ painter->setBrush(color); QRect rect = this->rect(); - painter->drawRoundedRect(rect,4,4); + rect = QRect(rect.x()+1,rect.y()+1,rect.width()-2,rect.height()-2); + painter->drawRoundedRect(rect,6,6); painter->restore(); } @@ -185,9 +153,10 @@ { painter->save(); QRect rect = this->rect(); - painter->setPen(QPen(QColor(55,143,250),2)); + rect = QRect(rect.x()+1,rect.y()+1,rect.width()-2,rect.height()-2); + painter->setPen(QPen(color,3)); - painter->drawRoundedRect(rect,4,4); + painter->drawRoundedRect(rect,6,6); painter->restore(); } diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/lunarcalendaryearitem.h 2023-05-22 14:06:12.000000000 +0800 @@ -1,4 +1,22 @@ -#ifndef LUNARCALENDARYEARITEM_H +/* +* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef LUNARCALENDARYEARITEM_H #define LUNARCALENDARYEARITEM_H #include <QWidget> @@ -61,14 +79,13 @@ }; - explicit LunarCalendarYearItem(QWidget *parent = 0); + explicit LunarCalendarYearItem(QString fontName, QWidget *parent = 0); QMap<QString,QMap<QString,QString>> worktime; + void onEnter(); + void onLeave(); + void onSelected(); protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); void paintEvent(QPaintEvent *); void drawBg(QPainter *painter); void drawBgCurrent(QPainter *painter, const QColor &color); @@ -108,7 +125,7 @@ QColor selectBgColor; //选中日期背景颜色 QColor hoverBgColor; //悬停日期背景颜色 - + QFont m_font; public: bool getSelect() const; @@ -142,7 +159,10 @@ QSize sizeHint() const; QSize minimumSizeHint() const; - + void setFont(const QFont &font){ + m_font = font; + repaint(); + } public Q_SLOTS: //设置是否选中 void setSelect(bool select); diff -Nru ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h --- ukui-panel-3.14.0.1/plugin-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h 2023-05-22 14:06:12.000000000 +0800 @@ -47,13 +47,6 @@ LunarCalendarWidget *lunarCalendarWidget; QWidget *widgetBottom; QHBoxLayout *horizontalLayout; - // QLabel *labCalendarStyle; - // QComboBox *cboxCalendarStyle; - // QLabel *labSelectType; - // QComboBox *cboxSelectType; - // QLabel *labWeekNameFormat; - // QComboBox *cboxWeekNameFormat; - // QCheckBox *ckShowLunar; QSpacerItem *horizontalSpacer; void setupUi(QWidget *frmLunarCalendarWidget) @@ -78,62 +71,9 @@ horizontalLayout = new QHBoxLayout(widgetBottom); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); horizontalLayout->setContentsMargins(0, 0, 0, 0); - // labCalendarStyle = new QLabel(widgetBottom); - // labCalendarStyle->setObjectName(QString::fromUtf8("labCalendarStyle")); - - // horizontalLayout->addWidget(labCalendarStyle); - - // cboxCalendarStyle = new QComboBox(widgetBottom); - // cboxCalendarStyle->addItem(QString()); - // cboxCalendarStyle->setObjectName(QString::fromUtf8("cboxCalendarStyle")); - // cboxCalendarStyle->setMinimumSize(QSize(90, 0)); - - // horizontalLayout->addWidget(cboxCalendarStyle); - -// labSelectType = new QLabel(widgetBottom); -// labSelectType->setObjectName(QString::fromUtf8("labSelectType")); - -// horizontalLayout->addWidget(labSelectType); - -// cboxSelectType = new QComboBox(widgetBottom); -// cboxSelectType->addItem(QString()); -// cboxSelectType->addItem(QString()); -// cboxSelectType->addItem(QString()); -// cboxSelectType->addItem(QString()); -// cboxSelectType->setObjectName(QString::fromUtf8("cboxSelectType")); -// cboxSelectType->setMinimumSize(QSize(90, 0)); - -// horizontalLayout->addWidget(cboxSelectType); - -// labWeekNameFormat = new QLabel(widgetBottom); -// labWeekNameFormat->setObjectName(QString::fromUtf8("labWeekNameFormat")); - -// horizontalLayout->addWidget(labWeekNameFormat); - -// cboxWeekNameFormat = new QComboBox(widgetBottom); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->setObjectName(QString::fromUtf8("cboxWeekNameFormat")); -// cboxWeekNameFormat->setMinimumSize(QSize(90, 0)); - -// horizontalLayout->addWidget(cboxWeekNameFormat); - -// ckShowLunar = new QCheckBox(widgetBottom); -// ckShowLunar->setObjectName(QString::fromUtf8("ckShowLunar")); -// ckShowLunar->setChecked(true); - -// horizontalLayout->addWidget(ckShowLunar); horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - horizontalLayout->addItem(horizontalSpacer); - - -// verticalLayout->addWidget(widgetBottom); - - retranslateUi(frmLunarCalendarWidget); QMetaObject::connectSlotsByName(frmLunarCalendarWidget); @@ -142,22 +82,6 @@ void retranslateUi(QWidget *frmLunarCalendarWidget) { frmLunarCalendarWidget->setWindowTitle(QApplication::translate("frmLunarCalendarWidget", "Form", nullptr)); - // labCalendarStyle->setText(QApplication::translate("frmLunarCalendarWidget", "\346\225\264\344\275\223\346\240\267\345\274\217", nullptr)); - // cboxCalendarStyle->setItemText(0, QApplication::translate("frmLunarCalendarWidget", "\347\272\242\350\211\262\351\243\216\346\240\274", nullptr)); - - // labSelectType->setText(QApplication::translate("frmLunarCalendarWidget", "\351\200\211\344\270\255\346\240\267\345\274\217", nullptr)); -// cboxSelectType->setItemText(0, QApplication::translate("frmLunarCalendarWidget", "\347\237\251\345\275\242\350\203\214\346\231\257", nullptr)); -// cboxSelectType->setItemText(1, QApplication::translate("frmLunarCalendarWidget", "\345\234\206\345\275\242\350\203\214\346\231\257", nullptr)); -// cboxSelectType->setItemText(2, QApplication::translate("frmLunarCalendarWidget", "\350\247\222\346\240\207\350\203\214\346\231\257", nullptr)); -// cboxSelectType->setItemText(3, QApplication::translate("frmLunarCalendarWidget", "\345\233\276\347\211\207\350\203\214\346\231\257", nullptr)); - - // labWeekNameFormat->setText(QApplication::translate("frmLunarCalendarWidget", "\346\230\237\346\234\237\346\240\274\345\274\217", nullptr)); -// cboxWeekNameFormat->setItemText(0, QApplication::translate("frmLunarCalendarWidget", "\347\237\255\345\220\215\347\247\260", nullptr)); -// cboxWeekNameFormat->setItemText(1, QApplication::translate("frmLunarCalendarWidget", "\346\231\256\351\200\232\345\220\215\347\247\260", nullptr)); -// cboxWeekNameFormat->setItemText(2, QApplication::translate("frmLunarCalendarWidget", "\351\225\277\345\220\215\347\247\260", nullptr)); -// cboxWeekNameFormat->setItemText(3, QApplication::translate("frmLunarCalendarWidget", "\350\213\261\346\226\207\345\220\215\347\247\260", nullptr)); - - // ckShowLunar->setText(QApplication::translate("frmLunarCalendarWidget", "\346\230\276\347\244\272\345\206\234\345\216\206", nullptr)); } // retranslateUi }; diff -Nru ukui-panel-3.14.0.1/plugin-calendar/translation/calendar_bo_CN.ts ukui-panel-4.0.0.0/plugin-calendar/translation/calendar_bo_CN.ts --- ukui-panel-3.14.0.1/plugin-calendar/translation/calendar_bo_CN.ts 2022-05-11 17:51:28.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/translation/calendar_bo_CN.ts 2023-05-23 15:58:00.000000000 +0800 @@ -4,35 +4,46 @@ <context> <name>CalendarActiveLabel</name> <message> - <location filename="../ukuicalendar.cpp" line="624"/> <source>Time and Date</source> - <translation>ཟླ་ཚེས་དང་དུས་ཚོད།</translation> + <translation type="vanished">ཟླ་ཚེས་དང་དུས་ཚོད།</translation> </message> <message> - <location filename="../ukuicalendar.cpp" line="675"/> <source>Time and Date Setting</source> - <translation>དུས་ཚོད་དང་ཚེས་གྲངས་སྒྲིག་འགོད།</translation> + <translation type="vanished">དུས་ཚོད་དང་ཚེས་གྲངས་སྒྲིག་འགོད།</translation> + </message> +</context> +<context> + <name>CalendarButton</name> + <message> + <location filename="../calendarbutton.cpp" line="79"/> + <source>Time and Date</source> + <translation>དུས་ཚོད་དང་དུས་ཚོད།</translation> + </message> + <message> + <location filename="../calendarbutton.cpp" line="135"/> + <source>Time and Date Setting</source> + <translation>དུས་ཚོད་དང་དུས་ཚོད་གཏན་འཁེལ་</translation> </message> </context> <context> <name>LunarCalendarItem</name> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="719"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="674"/> <source>消防宣传日</source> - <translation type="unfinished"></translation> + <translation>消防宣传日</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="722"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="677"/> <source>志愿者服务日</source> - <translation type="unfinished"></translation> + <translation>志愿者服务日</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="725"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="680"/> <source>全国爱眼日</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="728"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="683"/> <source>抗战纪念日</source> <translation type="unfinished"></translation> </message> @@ -40,26 +51,68 @@ <context> <name>LunarCalendarWidget</name> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="387"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="388"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="334"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="335"/> <source>Year</source> <translation>ལོ།</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="397"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="398"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="346"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="347"/> <source>Month</source> <translation>ཟླ།</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="409"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="410"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="359"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="360"/> <source>Today</source> <translation>དེ་རིང་།</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="719"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="939"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="603"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="617"/> + <source>Sun</source> + <translation>ཉི་མ།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="604"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="611"/> + <source>Mon</source> + <translation>དངུལ་ལོར།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="605"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="612"/> + <source>Tue</source> + <translation>ཐུའེ་རིགས།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="606"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="613"/> + <source>Wed</source> + <translation>གཉེན་སྒྲིག་བྱས་ཟིན་པ།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="607"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="614"/> + <source>Thur</source> + <translation>ཐུའུ་ཨར།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="608"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="615"/> + <source>Fri</source> + <translation>ཧྥུ་ལི་ཡ།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="609"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="616"/> + <source>Sat</source> + <translation>འཁོར་ལོ་བསྡད་པ།</translation> + </message> + <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="692"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="967"/> <source>解析json文件错误!</source> <translation>JSON ལ་ཞིབ་འགྲེལ་སྐབས་ནོར་འཁྲུལ་བྱུང་བ།</translation> </message> @@ -76,7 +129,7 @@ <name>frmLunarCalendarWidget</name> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="14"/> - <location filename="../lunarcalendarwidget/ui_frmlunarcalendarwidget.h" line="144"/> + <location filename="../lunarcalendarwidget/ui_frmlunarcalendarwidget.h" line="84"/> <source>Form</source> <translation type="unfinished"></translation> </message> diff -Nru ukui-panel-3.14.0.1/plugin-calendar/translation/calendar_zh_CN.ts ukui-panel-4.0.0.0/plugin-calendar/translation/calendar_zh_CN.ts --- ukui-panel-3.14.0.1/plugin-calendar/translation/calendar_zh_CN.ts 2022-05-11 17:51:28.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/translation/calendar_zh_CN.ts 2023-05-23 15:58:00.000000000 +0800 @@ -4,14 +4,12 @@ <context> <name>CalendarActiveLabel</name> <message> - <location filename="../ukuicalendar.cpp" line="600"/> <source>Time and Date</source> - <translation>时间与日期</translation> + <translation type="vanished">时间与日期</translation> </message> <message> - <location filename="../ukuicalendar.cpp" line="651"/> <source>Time and Date Setting</source> - <translation>时间日期设置</translation> + <translation type="vanished">时间日期设置</translation> </message> <message> <source>Config panel</source> @@ -19,81 +17,108 @@ </message> </context> <context> + <name>CalendarButton</name> + <message> + <location filename="../calendarbutton.cpp" line="79"/> + <source>Time and Date</source> + <translation>时间与日期</translation> + </message> + <message> + <location filename="../calendarbutton.cpp" line="135"/> + <source>Time and Date Setting</source> + <translation>时间日期设置</translation> + </message> +</context> +<context> <name>LunarCalendarItem</name> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="701"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="674"/> <source>消防宣传日</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="704"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="677"/> <source>志愿者服务日</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="707"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="680"/> <source>全国爱眼日</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="710"/> + <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="683"/> <source>抗战纪念日</source> - <translation type="unfinished"></translation> + <translation></translation> </message> </context> <context> <name>LunarCalendarWidget</name> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="369"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="370"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="334"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="335"/> <source>Year</source> - <translation type="unfinished">年</translation> + <translation>年</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="379"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="380"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="346"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="347"/> <source>Month</source> - <translation type="unfinished">月</translation> + <translation>月</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="391"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="392"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="359"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="360"/> <source>Today</source> - <translation type="unfinished">今天</translation> + <translation>今天</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="603"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="617"/> <source>Sun</source> - <translation type="obsolete">周日</translation> + <translation>星期日</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="604"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="611"/> <source>Mon</source> - <translation type="obsolete">周一</translation> + <translation>星期一</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="605"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="612"/> <source>Tue</source> - <translation type="obsolete">周二</translation> + <translation>星期二</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="606"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="613"/> <source>Wed</source> - <translation type="obsolete">周三</translation> + <translation>星期三</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="607"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="614"/> <source>Thur</source> - <translation type="obsolete">周四</translation> + <translation>星期四</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="608"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="615"/> <source>Fri</source> - <translation type="obsolete">周五</translation> + <translation>星期五</translation> </message> <message> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="609"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="616"/> <source>Sat</source> - <translation type="obsolete">周六</translation> + <translation>星期六</translation> </message> <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="701"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="921"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="692"/> + <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="967"/> <source>解析json文件错误!</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <source>Sunday</source> @@ -129,81 +154,81 @@ <message> <location filename="../ukuiwebviewdialog.ui" line="13"/> <source>Dialog</source> - <translation type="unfinished"></translation> + <translation></translation> </message> </context> <context> <name>frmLunarCalendarWidget</name> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="14"/> - <location filename="../lunarcalendarwidget/ui_frmlunarcalendarwidget.h" line="126"/> + <location filename="../lunarcalendarwidget/ui_frmlunarcalendarwidget.h" line="84"/> <source>Form</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="45"/> <source>整体样式</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="59"/> <source>红色风格</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="67"/> <source>选中样式</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="81"/> <source>矩形背景</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="86"/> <source>圆形背景</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="91"/> <source>角标背景</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="96"/> <source>图片背景</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="104"/> <source>星期格式</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="118"/> <source>短名称</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="123"/> <source>普通名称</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="128"/> <source>长名称</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="133"/> <source>英文名称</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="141"/> <source>显示农历</source> - <translation type="unfinished"></translation> + <translation></translation> </message> </context> </TS> diff -Nru ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarplugin.cpp ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarplugin.cpp --- ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarplugin.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarplugin.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "ukuicalendarplugin.h" + +UKUICalendarPlugin::UKUICalendarPlugin(const IUKUIPanelPluginStartupInfo &startupInfo): + QObject(), + IUKUIPanelPlugin(startupInfo), + m_widget(new UKUICalendarWidget(this)) +{ + m_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +} + +UKUICalendarPlugin::~UKUICalendarPlugin() +{ + delete m_widget; +} + +QWidget *UKUICalendarPlugin::widget() +{ + return m_widget; +} + +void UKUICalendarPlugin::realign() +{ + m_widget->realign(); +} diff -Nru ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarplugin.h ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarplugin.h --- ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarplugin.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarplugin.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef CALENDAR_H +#define CALENDAR_H +#include "../panel/iukuipanelplugin.h" +#include <QApplication> +#include <QDesktopWidget> +#include <QFrame> +#include <QFontMetrics> +#include <QLineEdit> +#include <QToolButton> +#include <QPushButton> +#include <QMainWindow> +#include <QHBoxLayout> +#include <QDebug> +#include <QProcess> +#include "../panel/ukuipanel.h" +#include <QMenu> +#include <QPointF> +#include <QMainWindow> +#include "ukuicalendarwidget.h" +#include "../panel/common/ukuigridlayout.h" + +class StartBarLibrary; +class UKUICalendarPlugin; + +class UKUICalendarPlugin: public QObject, public IUKUIPanelPlugin +{ + Q_OBJECT +public: + explicit UKUICalendarPlugin(const IUKUIPanelPluginStartupInfo &startupInfo); + ~UKUICalendarPlugin(); + + virtual QWidget *widget(); + virtual QString themeId() const { return "Calendar"; } + virtual Flags flags() const { return NeedsHandle; } + void realign(); + bool isSeparate() const { return true; } +private: + UKUICalendarWidget *m_widget; +}; + +class CalendarLibrary: public QObject, public IUKUIPanelPluginLibrary +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "ukui.org/Panel/PluginInterface/3.0") + Q_INTERFACES(IUKUIPanelPluginLibrary) +public: + IUKUIPanelPlugin *m_plugin; + IUKUIPanelPlugin *instance(const IUKUIPanelPluginStartupInfo &startupInfo) const + { + return new UKUICalendarPlugin(startupInfo); + } +}; + + + + + +#endif // CALENDAR_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarwidget.cpp ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarwidget.cpp --- ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarwidget.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarwidget.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "ukuicalendarwidget.h" +#include "../panel/iukuipanelplugin.h" +#include "kysdk/applications/windowmanager/windowmanager.h" +#include <QApplication> +#include <QDesktopWidget> +#include <QScreen> + +#define WEBVIEW_WIDTH (454) +#define WEBVIEW_MAX_HEIGHT (704) +#define WEBVIEW_MIN_HEIGHT (600) +#define POPUP_BORDER_SPACING 4 + +#define CALENDAR_BUTTON_WIDTH 120 + +#define HOUR_SYSTEM_CONTROL "org.ukui.control-center.panel.plugins" +#define DATA_FORMAT "date" //日期格式:yyyy/MM/dd、yyyy-MM-dd +#define TIME_FORMAT "hoursystem" //时间格式:12小时制、24小时制 +#define WEEK_FORMAT "firstday" //一周第一天:星期一、星期日 +#define CALENDAR_FORMAT "calendar" //日历格式:公历-solarlunar、农历-lunar + +#define PANEL_CONFIG "/usr/share/ukui/ukui-panel/panel-commission.ini" + +const int WIDGET_GAP = 8; + +UKUICalendarWidget::UKUICalendarWidget(IUKUIPanelPlugin *plugin, QWidget *parent) : + m_parent(parent), + m_plugin(plugin) +{ + //加载翻译 + translator(); + //实例化日历的窗口 + m_frmLunarWidget = new frmLunarCalendarWidget(); //新版日历 + m_widget = new LunarCalendarWidget(); + connect(m_widget,&LunarCalendarWidget::yijiChangeUp,m_frmLunarWidget,&frmLunarCalendarWidget::changeUpSize); + connect(m_widget,&LunarCalendarWidget::yijiChangeDown,m_frmLunarWidget,&frmLunarCalendarWidget::changeDownSize); + connect(m_widget,&LunarCalendarWidget::almanacChanged,m_frmLunarWidget,&frmLunarCalendarWidget::showAlmanac); + connect(m_frmLunarWidget,&frmLunarCalendarWidget::yijiFChangeDown, this, [=] (){ //日历的宜忌按钮取消 + changeWidowpos(); + }); + connect(m_frmLunarWidget,&frmLunarCalendarWidget::yijiFChangeUp, this, [=] (){ //日历的宜忌按钮勾选 + changeWidowpos(); + }); + + //实例化任务栏日期按钮 + m_calendarButton = new CalendarButton(plugin, this); + connect(m_calendarButton,&CalendarButton::pressShowHideCalendar,[=](){ //点击显示新版日历主窗口 + if(!m_widget->isHidden()) { + m_widget->hide(); + } else { + changeWidowpos(true); + } + }); + + //按钮布局 + m_layout=new UKUi::GridLayout(this); + m_layout->addWidget(m_calendarButton); + m_layout->setAlignment(Qt::AlignCenter); + +} + +UKUICalendarWidget::~UKUICalendarWidget() +{ + +} + +void UKUICalendarWidget::realign() +{ + if (m_plugin->panel()->isHorizontal()) { + this->setFixedSize(CALENDAR_BUTTON_WIDTH,m_plugin->panel()->panelSize()-5); + } else { + this->setFixedSize(m_plugin->panel()->panelSize()-5,CALENDAR_BUTTON_WIDTH); + } +} + +void UKUICalendarWidget::translator() +{ + m_translator = new QTranslator(this); + QString locale = QLocale::system().name(); + if (locale == "zh_CN"){ + if (m_translator->load(QM_INSTALL)) + qApp->installTranslator(m_translator); + else + qDebug() <<PLUGINNAME<<"Load translations file" << locale << "failed!"; + } else if (locale == "bo_CN") { + if (m_translator->load(BO_QM_INSTALL)) { + qApp->installTranslator(m_translator); + } else { + qDebug() <<PLUGINNAME<<"Load translations file" << locale << "failed!"; + } + } +} + + +/* 显示新版日历窗口 */ +void UKUICalendarWidget::changeWidowpos(bool restore) +{ + int totalHeight = qApp->primaryScreen()->size().height() + qApp->primaryScreen()->geometry().y(); + int totalWidth = qApp->primaryScreen()->size().width() + qApp->primaryScreen()->geometry().x(); + QRect rect; + switch (m_plugin->panel()->position()) { + case IUKUIPanel::PositionBottom: + rect.setRect(totalWidth-m_frmLunarWidget->width() - WIDGET_GAP, + totalHeight-m_plugin->panel()->panelSize()-m_frmLunarWidget->height()-WIDGET_GAP, + m_frmLunarWidget->width(), + m_frmLunarWidget->height()); + break; + case IUKUIPanel::PositionTop: + rect.setRect(totalWidth-m_frmLunarWidget->width()-WIDGET_GAP, + qApp->primaryScreen()->geometry().y()+m_plugin->panel()->panelSize()+WIDGET_GAP, + m_frmLunarWidget->width(), + m_frmLunarWidget->height()); + break; + case IUKUIPanel::PositionLeft: + rect.setRect(qApp->primaryScreen()->geometry().x()+m_plugin->panel()->panelSize()+WIDGET_GAP, + totalHeight-m_frmLunarWidget->height()-WIDGET_GAP, + m_frmLunarWidget->width(), + m_frmLunarWidget->height()); + break; + case IUKUIPanel::PositionRight: + rect.setRect(totalWidth-m_plugin->panel()->panelSize()-m_frmLunarWidget->width()-WIDGET_GAP, + totalHeight-m_frmLunarWidget->height()-WIDGET_GAP, + m_frmLunarWidget->width(), + m_frmLunarWidget->height()); + break; + default: + rect.setRect(qApp->primaryScreen()->geometry().x()+m_plugin->panel()->panelSize()+WIDGET_GAP, + totalHeight-m_frmLunarWidget->height(), + m_frmLunarWidget->width(), + m_frmLunarWidget->height()); + break; + } + m_widget->setFixedSize(rect.width(),rect.height()); + if(restore) { +// Q_EMIT(m_frmLunarWidget->onShowToday()); + m_widget->showCalendar(true); + } else { + m_widget->showCalendar(false); + } + + + kdk::WindowManager::setGeometry(m_widget->windowHandle(),rect); +} diff -Nru ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarwidget.h ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarwidget.h --- ukui-panel-3.14.0.1/plugin-calendar/ukuicalendarwidget.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/ukuicalendarwidget.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef CALENDARWIDGET_H +#define CALENDARWIDGET_H +#include <QFrame> +#include <QGSettings/QGSettings> +#include <QTimer> +#include <QEvent> +#include <QTranslator> +#include "../panel/common/ukuigridlayout.h" +#include "../panel/iukuipanelplugin.h" +#include "../panel/common/ukuisettings.h" +#include "../panel/pluginsettings.h" +#include "../panel/ukuipanel.h" +#include "../panel/common_fun/listengsettings.h" +#include "lunarcalendarwidget/frmlunarcalendarwidget.h" +#include "calendarbutton.h" +#include "ukuiwebviewdialog.h" +#include "lunarcalendarwidget/lunarcalendarwidget.h" + +extern UkuiWebviewDialogStatus status; +class UKUICalendarWidget:public QWidget +{ + Q_OBJECT +public: + UKUICalendarWidget(IUKUIPanelPlugin *plugin, QWidget* parent = 0); + ~UKUICalendarWidget(); + void realign(); + void changeWidowpos(bool restore = false); +private: + void translator(); +protected: +private: + IUKUIPanelPlugin *m_plugin; + QWidget *m_parent; + UKUi::GridLayout *m_layout; + QTranslator *m_translator; + frmLunarCalendarWidget *m_frmLunarWidget; + CalendarButton *m_calendarButton; + LunarCalendarWidget *m_widget; +}; + +#endif // CALENDARWIDGET_H diff -Nru ukui-panel-3.14.0.1/plugin-calendar/ukuiwebviewdialog.cpp ukui-panel-4.0.0.0/plugin-calendar/ukuiwebviewdialog.cpp --- ukui-panel-3.14.0.1/plugin-calendar/ukuiwebviewdialog.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-calendar/ukuiwebviewdialog.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -22,7 +22,7 @@ #include <QPalette> #include <QBrush> #include <QMessageBox> -#include <QColor> +//#include <QColor> #include <QTime> #include <QApplication> #include <QSize> @@ -43,6 +43,8 @@ { ui->setupUi(this); installEventFilter(this); + + setProperty("useStyleWindowManager",false); } UkuiWebviewDialog::~UkuiWebviewDialog() diff -Nru ukui-panel-3.14.0.1/plugin-nightmode/CMakeLists.txt ukui-panel-4.0.0.0/plugin-nightmode/CMakeLists.txt --- ukui-panel-3.14.0.1/plugin-nightmode/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-nightmode/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800 @@ -1,20 +0,0 @@ -set(PLUGIN "nightmode") - -set(HEADERS - nightmode.h -) - -set(SOURCES - nightmode.cpp -) - -set(LIBRARIES -# Qt5Xdg - ${Gsetting_LIBRARIES} -) - -include(../cmake/UkuiPluginTranslationTs.cmake) -ukui_plugin_translate_ts(${PLUGIN}) - -include_directories(${_Qt5DBus_OWN_INCLUDE_DIRS}) -BUILD_UKUI_PLUGIN(${PLUGIN}) diff -Nru ukui-panel-3.14.0.1/plugin-nightmode/nightmode.cpp ukui-panel-4.0.0.0/plugin-nightmode/nightmode.cpp --- ukui-panel-3.14.0.1/plugin-nightmode/nightmode.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-nightmode/nightmode.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,280 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include <QMouseEvent> -#include <QHBoxLayout> -#include <QScreen> -#include <QDebug> -#include <QMessageBox> -#include <QDir> -#include <QTimer> -#include "nightmode.h" -#include "../panel/customstyle.h" - -#define UKUI_QT_STYLE "org.ukui.style" -#define GTK_STYLE "org.mate.interface" -#define UKUI_QT_STYLE_NAME "style-name" -#define DEFAULT_QT_STYLE_NAME "styleName" -#define GTK_STYLE_NAME "gtk-theme" -#define DEFAULT_GTK_STYLE_NAME "gtkTheme" -#define DEFAULT_STYLE "ukui-default" -#define BLACK_STYLE "ukui-black" -#define DARK_STYLE "ukui-dark" -#define GTK_WHITE_STYLE "ukui-white" - -#define UKUI_PANEL_SETTINGS "org.ukui.panel.settings" -#define SHOW_NIGHTMODE "shownightmode" - - -NightMode::NightMode(const IUKUIPanelPluginStartupInfo &startupInfo) : - QObject(), - IUKUIPanelPlugin(startupInfo) -{ - translator(); - qDebug()<<"Plugin-NightMode :: plugin-nightmode start"; - //读取配置文件中nightmode 的值 - QString filename = QDir::homePath() + "/.config/ukui/panel-commission.ini"; - QSettings m_settings(filename, QSettings::IniFormat); - m_settings.setIniCodec("UTF-8"); - - m_settings.beginGroup("NightMode"); - nightmode_action = m_settings.value("nightmode", "").toString(); - if (nightmode_action.isEmpty()) { - nightmode_action = "show"; - } - m_settings.endGroup(); - - mButton=new NightModeButton(this); - mButton->setStyle(new CustomStyle()); - - const QByteArray id(UKUI_PANEL_SETTINGS); - if(QGSettings::isSchemaInstalled(id)) - gsettings = new QGSettings(id); - connect(gsettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key==SHOW_NIGHTMODE) - realign(); - }); - realign(); - qDebug()<<"Plugin-NightMode :: plugin-nightmode end"; -} - - -NightMode::~NightMode(){ - delete gsettings; -} - -void NightMode::translator(){ - m_translator = new QTranslator(this); - QString locale = QLocale::system().name(); - if (locale == "zh_CN"){ - if (m_translator->load(QM_INSTALL)) - qApp->installTranslator(m_translator); - else - qDebug() <<PLUGINNAME<<"Load translations file" << locale << "failed!"; - } else if (locale == "bo_CN") { - if (m_translator->load(BO_QM_INSTALL)) { - qApp->installTranslator(m_translator); - } else { - qDebug() <<PLUGINNAME<<"Load translations file" << locale << "failed!"; - } - } -} - -void NightMode::realign() -{ - if(gsettings->get(SHOW_NIGHTMODE).toBool() && nightmode_action == "show"){ - mButton->setFixedSize(panel()->panelSize()*0.75,panel()->panelSize()); - mButton->setIconSize(QSize(panel()->iconSize()*0.75,panel()->iconSize()*0.75)); - } - else{ - mButton->setFixedSize(0,0); - mButton->setIconSize(QSize(0,0)); - } -} - -NightModeButton::NightModeButton( IUKUIPanelPlugin *plugin, QWidget* parent): - QToolButton(parent), - m_plugin(plugin) -{ - /*系统主题gsettings qt+gtk*/ - const QByteArray styleid(UKUI_QT_STYLE); - if(QGSettings::isSchemaInstalled(styleid)) { - m_qtstyleGsettings = new QGSettings(styleid); - } - const QByteArray gtkstyleid(GTK_STYLE); - if(QGSettings::isSchemaInstalled(gtkstyleid)) { - m_gtkstyleGsettings = new QGSettings(gtkstyleid); - } - - QDBusConnection::sessionBus().connect(QString(), - QString("/ColorCorrect"), - "org.ukui.kwin.ColorCorrect", - "nightColorConfigChanged", - this, - SLOT(nightChangedSlot(QHash<QString,QVariant>))); -// getNightModeState(); - // controlCenterSetNightMode(mode); - this->setIcon(QIcon("/usr/share/ukui-panel/panel/img/nightmode-light.svg")); - this->setProperty("useIconHighlightEffect", 0x2); - QTimer::singleShot(5000,[this] { this->setToolTip(tr("night mode close")); }); - - - this->setEnabled(false); - QTimer *timer = new QTimer(this); - connect(timer,&QTimer::timeout,[this] {this->setEnabled(true);}); - timer->start(50); - connect(this,&NightModeButton::clicked,this, [this] { onClick();}); -} -NightModeButton::~NightModeButton(){ - delete m_qtstyleGsettings; - delete m_gtkstyleGsettings; -} - -void NightModeButton::onClick() -{ - getNightModeState(); - if(m_mode){ - setUkuiStyle(DEFAULT_STYLE); - - }else{ - setUkuiStyle(DARK_STYLE); - } - setNightMode(!m_mode); - this->setEnabled(true); -} - -void NightModeButton::contextMenuEvent(QContextMenuEvent *event) -{ -} - -/* - * 设置夜间模式 - * tr: set NightMode -*/ -void NightModeButton::setNightMode(const bool nightMode){ - QDBusInterface iproperty("org.ukui.KWin", - "/ColorCorrect", - "org.ukui.kwin.ColorCorrect", - QDBusConnection::sessionBus()); - - if (!iproperty.isValid()) { - this->setVisible(false); - return; - } - QHash<QString, QVariant> data; - - if(nightMode){ - data.insert("Active", true); - data.insert("Mode", 3); - data.insert("NightTemperature", m_colorTemperature); - - iproperty.call("setNightColorConfig", data); - QIcon icon=QIcon("/usr/share/ukui-panel/panel/img/nightmode-night.svg"); - this->setIcon(icon); - this->setToolTip(tr("nightmode opened")); - } - else{ - data.insert("Active", false); - iproperty.call("setNightColorConfig", data); - this->setIcon(QIcon("/usr/share/ukui-panel/panel/img/nightmode-light.svg")); - this->setToolTip(tr("nightmode closed")); - } -} - -void NightModeButton::controlCenterSetNightMode(const bool nightMode){ - QDBusInterface iproperty("org.ukui.KWin", - "/ColorCorrect", - "org.ukui.kwin.ColorCorrect", - QDBusConnection::sessionBus()); - - if (!iproperty.isValid()) { - this->setVisible(false); - return; - } - QHash<QString, QVariant> data; - - if(nightMode){ - data.insert("Active", true); - data.insert("NightTemperature", m_colorTemperature); - iproperty.call("setNightColorConfig", data); - QIcon icon=QIcon("/usr/share/ukui-panel/panel/img/nightmode-night.svg"); - this->setIcon(icon); - QTimer::singleShot(5000,[this] { this->setToolTip(tr("night mode open")); }); - } - else{ - data.insert("Active", false); - iproperty.call("setNightColorConfig", data); - this->setIcon(QIcon("/usr/share/ukui-panel/panel/img/nightmode-light.svg")); - QTimer::singleShot(5000,[this] { this->setToolTip(tr("night mode close")); }); - } -} - -void NightModeButton::getNightModeState() -{ - QDBusInterface ipropertyinfo("org.ukui.KWin", - "/ColorCorrect", - "org.ukui.kwin.ColorCorrect", - QDBusConnection::sessionBus()); - QDBusMessage msg= ipropertyinfo.call("nightColorInfo"); - - const QDBusArgument &dbusArg = msg.arguments().at( 0 ).value<QDBusArgument>(); - QMap<QString,QVariant > map; - dbusArg >> map; - for( QString outer_key : map.keys() ){ - QVariant innerMap = map.value( outer_key ); - if(outer_key=="NightTemperature") - m_colorTemperature=innerMap.toInt(); - if(outer_key=="Active") - m_mode=innerMap.toBool(); - // if(!outer_key.contains("EveningBeginFixed")) - - } -} -void NightModeButton::nightChangedSlot(QHash<QString, QVariant> nightArg) -{ - getNightModeState(); - controlCenterSetNightMode(m_mode); -} - -/*设置主题*/ -void NightModeButton::setUkuiStyle(QString style) -{ - if(QString::compare(style,DEFAULT_STYLE)==0){ - if(m_qtstyleGsettings->keys().contains(DEFAULT_QT_STYLE_NAME) || m_qtstyleGsettings->keys().contains(UKUI_QT_STYLE_NAME)) - m_qtstyleGsettings->set(UKUI_QT_STYLE_NAME,DEFAULT_STYLE); - if(m_gtkstyleGsettings->keys().contains(DEFAULT_GTK_STYLE_NAME) || m_gtkstyleGsettings->keys().contains(GTK_STYLE_NAME)) - m_gtkstyleGsettings->set(GTK_STYLE_NAME,GTK_WHITE_STYLE); - - } - else{ - if(m_qtstyleGsettings->keys().contains(DEFAULT_QT_STYLE_NAME) || m_qtstyleGsettings->keys().contains(UKUI_QT_STYLE_NAME)) - m_qtstyleGsettings->set(UKUI_QT_STYLE_NAME,DARK_STYLE); - if(m_gtkstyleGsettings->keys().contains(DEFAULT_GTK_STYLE_NAME) || m_gtkstyleGsettings->keys().contains(GTK_STYLE_NAME)) - m_gtkstyleGsettings->set(GTK_STYLE_NAME,BLACK_STYLE); - } -} - -void NightModeButton::enterEvent(QEvent *) { - repaint(); - return; -} - -void NightModeButton::leaveEvent(QEvent *) { - repaint(); - return; -} diff -Nru ukui-panel-3.14.0.1/plugin-nightmode/nightmode.h ukui-panel-4.0.0.0/plugin-nightmode/nightmode.h --- ukui-panel-3.14.0.1/plugin-nightmode/nightmode.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-nightmode/nightmode.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - - -#ifndef NIGHTMODE_H -#define NIGHTMODE_H - -#include "../panel/iukuipanelplugin.h" -#include <QApplication> -#include <QToolButton> -#include <QProcess> -#include <QGSettings> -#include <QHash> -#include <QDBusConnection> -#include <QDBusMessage> - -#include "../panel/ukuipanel.h" - -class NightModeButton:public QToolButton -{ - Q_OBJECT -public: - /** - * @brief NightModeButton - * @param plugin - * @param parent - * 夜间模式按钮 初始化 - */ - NightModeButton(IUKUIPanelPlugin *plugin, QWidget* parent = 0); - ~NightModeButton(); - - void setupSettings(); - -protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void contextMenuEvent(QContextMenuEvent *event); - -private: - void setNightMode(const bool nightMode); - void controlCenterSetNightMode(const bool nightMode); - void setUkuiStyle(QString ); - /** - * @brief getNightModeState - * 通过dbus获取夜间模式状态 - */ - void getNightModeState(); - - IUKUIPanelPlugin * m_plugin; - QGSettings *m_qtstyleGsettings; - QGSettings *m_gtkstyleGsettings; - int m_colorTemperature; - bool m_mode; - -public slots: - void onClick(); -private slots: - void nightChangedSlot(QHash<QString,QVariant> nightArg); -}; - -class NightMode : public QObject, public IUKUIPanelPlugin -{ - Q_OBJECT -public: - /** - * @brief NightMode - * @param startupInfo - * 夜间模式插件,插件上通过添加NightModeButton按钮实现夜间模式相关功能 - */ - NightMode(const IUKUIPanelPluginStartupInfo &startupInfo); - ~NightMode(); - - virtual QWidget *widget() { return mButton; } - virtual QString themeId() const { return QStringLiteral("nightmode"); } - void realign(); - -private: - NightModeButton *mButton; - QGSettings *gsettings; - QTranslator *m_translator; -private: - void translator(); - - /** - * @brief nightmode_action - * 读取配置文件中的nightmode 的值 - */ - QString nightmode_action; -}; - -class NightModeLibrary: public QObject, public IUKUIPanelPluginLibrary -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "lxqt.org/Panel/PluginInterface/3.0") - Q_INTERFACES(IUKUIPanelPluginLibrary) -public: - IUKUIPanelPlugin *instance(const IUKUIPanelPluginStartupInfo &startupInfo) const - { - return new NightMode(startupInfo); - } -}; -#endif diff -Nru ukui-panel-3.14.0.1/plugin-nightmode/resources/nightmode.desktop.in ukui-panel-4.0.0.0/plugin-nightmode/resources/nightmode.desktop.in --- ukui-panel-3.14.0.1/plugin-nightmode/resources/nightmode.desktop.in 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-nightmode/resources/nightmode.desktop.in 1970-01-01 08:00:00.000000000 +0800 @@ -1,10 +0,0 @@ -[Desktop Entry] -Type=Service -ServiceTypes=UKUIPanel/Plugin -Name=NightMode -Comment=NightMode -Icon=nightmode - -#TRANSLATIONS_DIR=../translations -Name=夜间模式 -Comment=夜间模式切换按键 diff -Nru ukui-panel-3.14.0.1/plugin-nightmode/translation/nightmode_bo_CN.ts ukui-panel-4.0.0.0/plugin-nightmode/translation/nightmode_bo_CN.ts --- ukui-panel-3.14.0.1/plugin-nightmode/translation/nightmode_bo_CN.ts 2022-05-11 17:51:28.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-nightmode/translation/nightmode_bo_CN.ts 1970-01-01 08:00:00.000000000 +0800 @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.1" language="bo_CN"> -<context> - <name>NightModeButton</name> - <message> - <location filename="../nightmode.cpp" line="133"/> - <location filename="../nightmode.cpp" line="222"/> - <source>night mode close</source> - <translation>མཚན་མོའི་རྣམ་པ་ཁ་རྒྱག་པ།</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="188"/> - <source>nightmode opened</source> - <translation>མཚན་མོའི་རྣམ་པ་ཁ་ཕྱེ་བ།</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="194"/> - <source>nightmode closed</source> - <translation>མཚན་མོའི་རྣམ་པ་ཁ་རྒྱག་པ།</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="216"/> - <source>night mode open</source> - <translation>མཚན་མོའི་རྣམ་པ་ཁ་ཕྱེ་བ།</translation> - </message> -</context> -</TS> diff -Nru ukui-panel-3.14.0.1/plugin-nightmode/translation/nightmode_zh_CN.ts ukui-panel-4.0.0.0/plugin-nightmode/translation/nightmode_zh_CN.ts --- ukui-panel-3.14.0.1/plugin-nightmode/translation/nightmode_zh_CN.ts 2022-05-11 17:51:28.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-nightmode/translation/nightmode_zh_CN.ts 1970-01-01 08:00:00.000000000 +0800 @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.1" language="zh_CN"> -<context> - <name>NightModeButton</name> - <message> - <source>Turn On NightMode</source> - <translation type="vanished">夜间模式</translation> - </message> - <message> - <source>Set Up NightMode</source> - <translation type="vanished">设置夜间模式</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="182"/> - <source>nightmode opened</source> - <translation>夜间模式开启</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="188"/> - <source>nightmode closed</source> - <translation>夜间模式关闭</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="210"/> - <source>night mode open</source> - <translation>夜间模式开启</translation> - </message> - <message> - <location filename="../nightmode.cpp" line="127"/> - <location filename="../nightmode.cpp" line="216"/> - <source>night mode close</source> - <translation>夜间模式关闭</translation> - </message> -</context> -</TS> diff -Nru ukui-panel-3.14.0.1/plugin-startbar/startmenu_button.cpp ukui-panel-4.0.0.0/plugin-startbar/startmenu_button.cpp --- ukui-panel-3.14.0.1/plugin-startbar/startmenu_button.cpp 2022-05-11 17:53:33.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-startbar/startmenu_button.cpp 2023-05-23 15:58:00.000000000 +0800 @@ -68,64 +68,67 @@ this->setIconSize(QSize(m_plugin->panel()->iconSize(),m_plugin->panel()->iconSize())); } -void StartMenuButton::mousePressEvent(QMouseEvent* event) +void StartMenuButton::mouseReleaseEvent(QMouseEvent* event) { const Qt::MouseButton b = event->button(); if (Qt::LeftButton == b) { - if(QFileInfo::exists(QString("/usr/bin/ukui-menu"))) - { - QProcess *process =new QProcess(this); - process->startDetached("/usr/bin/ukui-menu"); - process->deleteLater(); - } - else{qDebug()<<"not find /usr/bin/ukui-start-menu"<<endl;} + // QDBusInterface iface("org.ukui.menu", + // "/org/ukui/menu", + // "org.ukui.menu", + // QDBusConnection::sessionBus()); + // iface.call("WinKeyResponse"); + auto call = QDBusMessage::createMethodCall("org.ukui.menu", "/org/ukui/menu", "org.ukui.menu", "WinKeyResponse"); + QDBusConnection::sessionBus().asyncCall(call); } - QWidget::mousePressEvent(event); + QToolButton::mouseReleaseEvent(event); } void StartMenuButton::contextMenuEvent(QContextMenuEvent *event) { - rightPressMenu=new QMenu(); + rightPressMenu = new QMenu(this); rightPressMenu->setAttribute(Qt::WA_DeleteOnClose); - QMenu *pUserAction=new QMenu(tr("User Action")); //用户操作 - QMenu *pSleepHibernate=new QMenu(tr("Sleep or Hibernate")); //重启或休眠 - QMenu *pPowerSupply=new QMenu(tr("Power Supply")); //电源 + QMenu *pUserAction = new QMenu(tr("User Action"), this); //用户操作 + QMenu *pSleepHibernate = new QMenu(tr("Suspend or Hibernate"), this); //休眠或睡眠 + QMenu *pPowerSupply = new QMenu(tr("Power Supply"), this); //电源 rightPressMenu->addMenu(pUserAction); - rightPressMenu->addMenu(pSleepHibernate); + if (QString::compare(getCanHibernateResult(),"yes") == 0 || + QString::compare(getCanSuspendResult(),"yes") == 0) { + rightPressMenu->addMenu(pSleepHibernate); + } rightPressMenu->addMenu(pPowerSupply); pUserAction->addAction(QIcon::fromTheme("system-lock-screen-symbolic"), tr("Lock Screen"), this, SLOT(ScreenServer()) ); //锁屏 - if (hasMultipleUsers()) { + if (hasMultipleUsers() && canSwitch()) { pUserAction->addAction(QIcon::fromTheme("stock-people-symbolic"), tr("Switch User"), this, SLOT(SessionSwitch()) ); //切换用户 } - pUserAction->addAction(QIcon::fromTheme("ukui-system-logout-symbolic"), - tr("Logout"), + pUserAction->addAction(QIcon::fromTheme("system-log-out-symbolic"), + tr("Log Out"), this, SLOT(SessionLogout()) ); //注销 if(QString::compare(getCanHibernateResult(),"yes") == 0){ pSleepHibernate->addAction(QIcon::fromTheme("kylin-sleep-symbolic"), - tr("Hibernate Mode"), + tr("Hibernate"), this, SLOT(SessionHibernate()) ); //休眠 } if(QString::compare(getCanSuspendResult(),"yes") == 0) { pSleepHibernate->addAction(QIcon::fromTheme("ukui-hebernate-symbolic"), - tr("Sleep Mode"), + tr("Suspend"), this, SLOT(SessionSuspend()) ); //睡眠 } - pPowerSupply->addAction(QIcon::fromTheme("ukui-system-restart-symbolic"), + pPowerSupply->addAction(QIcon::fromTheme("system-reboot-symbolic"), tr("Restart"), this, SLOT(SessionReboot()) ); //重启 @@ -136,12 +139,18 @@ this, SLOT(TimeShutdown()) ); //定时开关机 pPowerSupply->addAction(QIcon::fromTheme("system-shutdown-symbolic"), - tr("Power Off"), + tr("Shut Down"), this, SLOT(SessionShutdown()) ); //关机 rightPressMenu->setGeometry(m_plugin->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), rightPressMenu->sizeHint())); rightPressMenu->show(); + //解决触摸长按时显示出右键菜单后,按钮三态不消失问题 + QObject::connect(rightPressMenu, &QMenu::destroyed, this, [&](){ + this->setAttribute(Qt::WA_UnderMouse, false); + this->setDown(false); + this->update(); + }); } /*开始菜单按钮右键菜单选项,与开始菜单中电源按钮的右键功能是相同的*/ @@ -262,6 +271,20 @@ return reply.value().toBool(); } +bool StartMenuButton::canSwitch() +{ + QDBusInterface interface("org.freedesktop.DisplayManager", + "/org/freedesktop/DisplayManager/Seat0", + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus()); + if (!interface.isValid()) { + qCritical() << QDBusConnection::systemBus().lastError().message(); + return false; + } else { + QDBusReply<QVariant> reply = interface.call("Get","org.freedesktop.DisplayManager.Seat","CanSwitch"); + return reply.value().toBool(); + } +} void StartMenuButton::enterEvent(QEvent *) { repaint(); return; diff -Nru ukui-panel-3.14.0.1/plugin-startbar/startmenu_button.h ukui-panel-4.0.0.0/plugin-startbar/startmenu_button.h --- ukui-panel-3.14.0.1/plugin-startbar/startmenu_button.h 2022-05-11 17:33:42.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-startbar/startmenu_button.h 2023-05-22 14:06:12.000000000 +0800 @@ -46,7 +46,7 @@ void realign(); protected: void contextMenuEvent(QContextMenuEvent *event); - void mousePressEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* event); void enterEvent(QEvent *); void leaveEvent(QEvent *); @@ -61,6 +61,7 @@ QString getCanHibernateResult(); QString getCanSuspendResult(); bool hasMultipleUsers(); + bool canSwitch(); private slots: void ScreenServer(); diff -Nru ukui-panel-3.14.0.1/plugin-startbar/translation/startbar_bo_CN.ts ukui-panel-4.0.0.0/plugin-startbar/translation/startbar_bo_CN.ts --- ukui-panel-3.14.0.1/plugin-startbar/translation/startbar_bo_CN.ts 2022-05-11 17:51:08.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-startbar/translation/startbar_bo_CN.ts 2023-05-23 15:58:00.000000000 +0800 @@ -4,70 +4,70 @@ <context> <name>StartMenuButton</name> <message> - <location filename="../startmenu_button.cpp" line="29"/> + <location filename="../startmenu_button.cpp" line="44"/> <source>UKUI Menu</source> <translation>འགོ་རྩོམ་འདེམས་བྱང་།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="69"/> + <location filename="../startmenu_button.cpp" line="91"/> <source>User Action</source> <translation>འགུལ་སྟངས་གཏན་རང་འཁེལ།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="70"/> - <source>Sleep or Hibernate</source> + <location filename="../startmenu_button.cpp" line="92"/> + <source>Suspend or Hibernate</source> <translation>ངལ་གསོ།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="71"/> + <location filename="../startmenu_button.cpp" line="93"/> <source>Power Supply</source> <translation>གློག་ཁུངས།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="77"/> + <location filename="../startmenu_button.cpp" line="102"/> <source>Lock Screen</source> <translation>སྒྲོག་ཡོལ།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="82"/> + <location filename="../startmenu_button.cpp" line="107"/> <source>Switch User</source> <translation>སྤྱོད་མཁན་བརྗེ་བ།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="87"/> - <source>Logout</source> + <location filename="../startmenu_button.cpp" line="112"/> + <source>Log Out</source> <translation>ཐོ་ཁོངས་ནས་འདོར་བ།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="93"/> - <source>Hibernate Mode</source> + <location filename="../startmenu_button.cpp" line="118"/> + <source>Hibernate</source> <translation>མལ་གསོ།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="100"/> - <source>Sleep Mode</source> + <location filename="../startmenu_button.cpp" line="125"/> + <source>Suspend</source> <translation>མལ་གསོ་བ་།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="105"/> + <location filename="../startmenu_button.cpp" line="130"/> <source>Restart</source> <translation>བསྐྱར་སློང་།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="111"/> + <location filename="../startmenu_button.cpp" line="136"/> <source>TimeShutdown</source> <translation>དུས་ཆད་སྒོ་རྒྱག་སྒྲིག་འགོད།</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="115"/> - <source>Power Off</source> + <location filename="../startmenu_button.cpp" line="140"/> + <source>Shut Down</source> <translation>འཁོར་ཁ་རྒྱག་པ།</translation> </message> </context> <context> <name>TaskViewButton</name> <message> - <location filename="../taskview_button.cpp" line="38"/> + <location filename="../taskview_button.cpp" line="34"/> <source>Show Taskview</source> <translation>ལས་འགན་མཐོང་སྣེ་འཆར་བའི་གནོན་མཐེབ།</translation> </message> diff -Nru ukui-panel-3.14.0.1/plugin-startbar/translation/startbar_zh_CN.ts ukui-panel-4.0.0.0/plugin-startbar/translation/startbar_zh_CN.ts --- ukui-panel-3.14.0.1/plugin-startbar/translation/startbar_zh_CN.ts 2022-05-11 17:51:08.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-startbar/translation/startbar_zh_CN.ts 2023-05-23 15:58:00.000000000 +0800 @@ -8,70 +8,70 @@ <translation type="vanished">开始菜单</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="11"/> + <location filename="../startmenu_button.cpp" line="44"/> <source>UKUI Menu</source> <translation>开始菜单</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="51"/> + <location filename="../startmenu_button.cpp" line="91"/> <source>User Action</source> <translation>用户操作</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="52"/> - <source>Sleep or Hibernate</source> + <location filename="../startmenu_button.cpp" line="92"/> + <source>Suspend or Hibernate</source> <translation>休眠或睡眠</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="53"/> + <location filename="../startmenu_button.cpp" line="93"/> <source>Power Supply</source> <translation>电源</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="59"/> + <location filename="../startmenu_button.cpp" line="102"/> <source>Lock Screen</source> <translation>锁定屏幕</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="64"/> + <location filename="../startmenu_button.cpp" line="107"/> <source>Switch User</source> <translation>切换用户</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="69"/> - <source>Logout</source> + <location filename="../startmenu_button.cpp" line="112"/> + <source>Log Out</source> <translation>注销</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="75"/> - <source>Hibernate Mode</source> + <location filename="../startmenu_button.cpp" line="118"/> + <source>Hibernate</source> <translation>休眠</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="80"/> - <source>Sleep Mode</source> + <location filename="../startmenu_button.cpp" line="125"/> + <source>Suspend</source> <translation>睡眠</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="84"/> + <location filename="../startmenu_button.cpp" line="130"/> <source>Restart</source> <translation>重启</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="90"/> + <location filename="../startmenu_button.cpp" line="136"/> <source>TimeShutdown</source> <translation>定时关机</translation> </message> <message> - <location filename="../startmenu_button.cpp" line="94"/> - <source>Power Off</source> + <location filename="../startmenu_button.cpp" line="140"/> + <source>Shut Down</source> <translation>关机</translation> </message> </context> <context> <name>TaskViewButton</name> <message> - <location filename="../taskview_button.cpp" line="11"/> + <location filename="../taskview_button.cpp" line="34"/> <source>Show Taskview</source> <translation>显示任务视图</translation> </message> diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/CMakeLists.txt ukui-panel-4.0.0.0/plugin-statusnotifier/CMakeLists.txt --- ukui-panel-3.14.0.1/plugin-statusnotifier/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/CMakeLists.txt 2023-05-22 14:06:12.000000000 +0800 @@ -9,13 +9,14 @@ statusnotifierbutton.h statusnotifieriteminterface.h statusnotifierwatcher.h - statusnotifierwidget.h +# statusnotifierwidget.h sniasync.h statusnotifier_storagearrow.h statusnotifierwatcher_interface.h systemtraytypedefs.h dbusproperties.h - + statusnotiferscrollarea.h + statusnotifierbuttonabstract.h ) set(SOURCES @@ -24,11 +25,13 @@ statusnotifierbutton.cpp statusnotifieriteminterface.cpp statusnotifierwatcher.cpp - statusnotifierwidget.cpp +# statusnotifierwidget.cpp sniasync.cpp statusnotifier_storagearrow.cpp statusnotifierwatcher_interface.cpp dbusproperties.cpp + statusnotiferscrollarea.cpp + statusnotifierbuttonabstract.cpp ) qt5_add_dbus_adaptor(DBUS_SOURCES diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotiferscrollarea.cpp ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotiferscrollarea.cpp --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotiferscrollarea.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotiferscrollarea.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,558 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2015 LXQt team + * Authors: + * Balázs Béla <balazsbela[at]gmail.com> + * Paulo Lieuthier <paulolieuthier@gmail.com> + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#include "statusnotiferscrollarea.h" +#include <QGuiApplication> +#include <QScreen> +#define CONFIG_FILE_BACKUP "/usr/share/ukui/panel.conf" + +StatusNotiferScrollArea::StatusNotiferScrollArea(IUKUIPanelPlugin *plugin, QWidget *parent) + :m_plugin(plugin), + m_parent(parent) +{ + //检查配置文件是否完整 + QSettings backup_qsettings(CONFIG_FILE_BACKUP,QSettings::IniFormat); + QStringList showAppBackup = backup_qsettings.value("statusnotifier/showApp").toStringList(); + QStringList hideAppBackup = backup_qsettings.value("statusnotifier/hideApp").toStringList(); + QStringList fixedAppBackup = backup_qsettings.value("statusnotifier/fixedApp").toStringList(); + QString alignmentBackup = backup_qsettings.value("statusnotifier/alignment").toString(); + PluginSettings *settings = m_plugin->settings(); // ~/.config/ukui/panel.conf + QStringList allkeys = settings->allKeys(); + if(!allkeys.contains("showApp")) { + settings->setValue("showApp",showAppBackup); + } + if(!allkeys.contains("hideApp")) { + settings->setValue("hideApp",hideAppBackup); + } + if(!allkeys.contains("fixedApp")) { + settings->setValue("fixedApp",fixedAppBackup); + } + QStringList showApp = settings->value("showApp").toStringList(); + QStringList hideApp = settings->value("hideApp").toStringList(); + for(int i=0; i<fixedAppBackup.size(); i++) { + QString str = fixedAppBackup.at(i); + showApp.removeOne(str); + hideApp.removeOne(str); + } + settings->setValue("showApp",showApp); + settings->setValue("hideApp",hideApp); + if(!allkeys.contains("alignment")) { + settings->setValue("alignment",alignmentBackup); + } + + //监听托盘应用注册 + m_watcher = new StatusNotifierWatcher; + connect(m_watcher, &StatusNotifierWatcher::StatusNotifierItemRegistered, + this, &StatusNotiferScrollArea::itemAdded); + connect(m_watcher, &StatusNotifierWatcher::StatusNotifierItemUnregistered, + this, &StatusNotiferScrollArea::itemRemoved); + + //设置滚动区域属性 + this->setWidgetResizable(true); + this->setAttribute(Qt::WA_TranslucentBackground); + this->setProperty("drawScrollBarGroove",false); + this->verticalScrollBar()->setProperty("drawScrollBarGroove",false); + this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + this->verticalScrollBar()->setVisible(false); + this->setFrameShape(QFrame::NoFrame); + this->setAlignment(Qt::AlignRight); + this->setContentsMargins(0,0,0,0); + //滚动区域背景透明 + QPalette pal = this->palette(); + pal.setBrush(QPalette::Window, QColor(Qt::transparent)); + this->setPalette(pal); + + //最外层窗口布局 + m_outWidget = new QWidget(this); + m_outWidget->setContentsMargins(0,0,0,0); + m_outLayout = new QGridLayout(m_outWidget); + m_outLayout->setContentsMargins(0,0,0,0); + m_outLayout->setSpacing(0); + m_outWidget->setLayout(m_outLayout); + this->setWidget(m_outWidget); + + + //托盘窗口和布局 + m_statusNotifierWidget = new QWidget(this); + m_arrowBtn = new StatusNotifierStorageArrow(m_plugin, m_statusNotifierWidget); + connect(m_arrowBtn,SIGNAL(addButton(StatusNotifierButtonAbstract*,StatusNotifierButtonAbstract*)), + this,SLOT(arrowbtnAddButton(StatusNotifierButtonAbstract*,StatusNotifierButtonAbstract*))); + m_layout = new UKUi::GridLayout(m_statusNotifierWidget); + m_layout->setDirection(UKUi::GridLayout::LeftToRight); + m_layout->setContentsMargins(0, 0, 0, 0); + m_statusNotifierWidget->setLayout(m_layout); + m_layout->addWidget(m_arrowBtn); + + //托盘区固定应用窗口和布局 + m_statusNotifierFixedWidget = new QWidget(this); + m_statusNotifierFixedWidget->setAcceptDrops(false); + m_layoutFix = new UKUi::GridLayout(m_statusNotifierFixedWidget); + m_layoutFix->setDirection(UKUi::GridLayout::LeftToRight); + m_layoutFix->setContentsMargins(0, 0, 0, 0); + m_statusNotifierFixedWidget->setLayout(m_layoutFix); + + //监听托盘图标隐藏 + const QByteArray id(UKUI_PANEL_SETTINGS); + if(QGSettings::isSchemaInstalled(id)) { + m_gsettings = new QGSettings(id); + connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key) { + if(key==SHOW_STATUSNOTIFIER_BUTTON) { + exchangeHideAndShow(); + } + }); + } +} + +StatusNotiferScrollArea::~StatusNotiferScrollArea() +{ + if(m_watcher) { + delete(m_watcher); + m_watcher = NULL; + } + if(m_gsettings) { + delete(m_gsettings); + m_gsettings = NULL; + } +} + +void StatusNotiferScrollArea::realign() +{ + m_layout->setEnabled(false); + m_layoutFix->setEnabled(false); + m_outLayout->setEnabled(false); + IUKUIPanel *panel = m_plugin->panel(); + if (panel->isHorizontal()) { + //更新托盘活动区大小 + m_layout->setRowCount(panel->lineCount()); + m_layout->setColumnCount(0); + m_layout->setEnabled(true); + int widgetWidth; + if(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()) { + widgetWidth = (m_activeButtons.size()+1)*uint(panel->panelSize()*0.7); + } else { + widgetWidth = (m_activeButtons.size()-m_hideButtons.size()+1)*uint(panel->panelSize()*0.7); + } + m_statusNotifierWidget->setFixedSize(widgetWidth, panel->panelSize()); + int margins = panel->panelSize()*0.15; + m_statusNotifierWidget->setContentsMargins(0,margins,0,margins); + + //更新托盘固定区大小 + m_layoutFix->setRowCount(panel->lineCount()); + m_layoutFix->setColumnCount(0); + m_layoutFix->setEnabled(true); + int fixedWidgetWidth; + fixedWidgetWidth = (m_fixedButtons.size())*uint(panel->panelSize()*0.7); + m_statusNotifierFixedWidget->setFixedSize(fixedWidgetWidth, panel->panelSize()); + m_statusNotifierFixedWidget->setContentsMargins(0,margins,0,margins); + + //更新外层大窗口大小和布局 + m_outLayout->setAlignment(Qt::AlignRight); + m_outLayout->addWidget(m_statusNotifierWidget,0,0); + m_outLayout->addWidget(m_statusNotifierFixedWidget,0,1); + m_outLayout->setEnabled(true); + m_outWidget->setFixedSize(widgetWidth+fixedWidgetWidth, panel->panelSize()); + if((widgetWidth+fixedWidgetWidth) > QGuiApplication::primaryScreen()->geometry().width()/3) { + //托盘区超过屏幕宽度1/3,超出量不到一个图标宽度的,正常显示,否则托盘显示区为屏幕宽度1/3 + if(widgetWidth+fixedWidgetWidth-QGuiApplication::primaryScreen()->geometry().width()/3 < uint(panel->panelSize()*0.7)) { + this->setFixedSize(widgetWidth+fixedWidgetWidth, panel->panelSize()); + } else { + this->setFixedSize(QGuiApplication::primaryScreen()->geometry().width()/3, panel->panelSize()); + } + } else { + this->setFixedSize(widgetWidth+fixedWidgetWidth, panel->panelSize()); + } + } else { + //更新托盘活动区大小 + m_layout->setColumnCount(panel->lineCount()); + m_layout->setRowCount(0); + m_layout->setEnabled(true); + int heightWidth; + if(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()) { + heightWidth = (m_activeButtons.size()+1)*uint(panel->panelSize()*0.7); + } else { + heightWidth = (m_activeButtons.size()-m_hideButtons.size()+1)*uint(panel->panelSize()*0.7); + } + m_statusNotifierWidget->setFixedSize(panel->panelSize(), heightWidth); + int margins = panel->panelSize()*0.15; + m_statusNotifierWidget->setContentsMargins(margins,0,margins,0); + + //更新托盘固定区大小 + m_layoutFix->setColumnCount(panel->lineCount()); + m_layoutFix->setRowCount(0); + m_layoutFix->setEnabled(true); + int fixedWidgetHeight; + fixedWidgetHeight = (m_fixedButtons.size())*uint(panel->panelSize()*0.7); + m_statusNotifierFixedWidget->setFixedSize(panel->panelSize(), fixedWidgetHeight); + m_statusNotifierFixedWidget->setContentsMargins(margins,0,margins,0); + + //更新外层大窗口大小和布局 + m_outLayout->setAlignment(Qt::AlignBottom); + m_outLayout->addWidget(m_statusNotifierWidget,0,0); + m_outLayout->addWidget(m_statusNotifierFixedWidget,1,0); + m_outLayout->setEnabled(true); + m_outWidget->setFixedSize(panel->panelSize(), heightWidth+fixedWidgetHeight); + if((heightWidth+fixedWidgetHeight) > QGuiApplication::primaryScreen()->geometry().height()/3) { + this->setFixedSize(panel->panelSize(), QGuiApplication::primaryScreen()->geometry().height()/3); + } else { + this->setFixedSize(panel->panelSize(), heightWidth+fixedWidgetHeight); + } + } +} + +void StatusNotiferScrollArea::wheelEvent(QWheelEvent *event) +{ + if(this->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) { + if(event->delta() >= 0) { + this->horizontalScrollBar()->setValue(horizontalScrollBar()->value()-40); + } else { + this->horizontalScrollBar()->setValue(horizontalScrollBar()->value()+40); + } + } + if(this->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) { + if(event->delta() >= 0) { + this->verticalScrollBar()->setValue(verticalScrollBar()->value()-40); + } else { + this->verticalScrollBar()->setValue(verticalScrollBar()->value()+40); + } + } +} + +void StatusNotiferScrollArea::itemAdded(QString serviceAndPath) +{ + //判断DISPLAY + if(serviceAndPath.contains("org.kde.StatusNotifierItem")) { + if(QGuiApplication::platformName() == "xcb") { + QString envDisplay = getenv("DISPLAY"); + QStringList strList = serviceAndPath.split("-"); + QString displayNum = getDisplayId(strList.at(1)); + if(envDisplay != displayNum) { + qInfo()<<"XCB environment: The application("<<serviceAndPath<<")displayNum("<<envDisplay + << ") is inconsistent with the envDisplay("<<displayNum<<")"; + return; + } + } + } + + int slash = serviceAndPath.indexOf('/'); + QString serv = serviceAndPath.left(slash); + QString path = serviceAndPath.mid(slash); + StatusNotifierButton *button = new StatusNotifierButton(serv, path, m_plugin, m_statusNotifierWidget); + button->setFoldState(!m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()); + m_services.insert(serviceAndPath, button); + connect(button, SIGNAL(switchButtons(StatusNotifierButtonAbstract*,StatusNotifierButtonAbstract*)), + this, SLOT(switchButtons(StatusNotifierButtonAbstract*,StatusNotifierButtonAbstract*))); + connect(button,&StatusNotifierButton::layoutUpdate,this,[=]() { + resetLayout(); + }); + qInfo()<<"All current item services :"<<m_services; + connect(button,&StatusNotifierButton::layoutReady,this,[=]() { + if(button->m_iconStatus && !button->m_id.isEmpty()) { //Icon和ID都准备好后再加入布局 + QStringList fixedAppList = readFixedAppSettings(); + if(fixedAppList.contains(button->m_id)) { + m_statusNotifierFixedButtons.append(button); + } else { + m_statusNotifierButtons.append(button); + } + qInfo()<<button->m_id<<" button to add layout"; + resetLayout(); + } + }); +} + +void StatusNotiferScrollArea::itemRemoved(const QString &serviceAndPath) +{ + StatusNotifierButton *button = m_services.value(serviceAndPath, NULL); + if (button) { + disconnect(button,&StatusNotifierButton::layoutReady,0,0); + if(m_statusNotifierButtons.contains(button)) { + m_statusNotifierButtons.removeOne(button); + m_layoutButtons.remove(button->m_id); + m_activeButtons.remove(button->m_id); + m_layout->removeWidget(button); + } else if(m_statusNotifierFixedButtons.contains(button)) { + m_statusNotifierFixedButtons.removeOne(button); + m_fixedButtons.remove(button->m_id); + m_layoutFix->removeWidget(button); + } + m_services.remove(serviceAndPath); + resetLayout(); + button->deleteLater(); + } +} + +void StatusNotiferScrollArea::resetLayout() +{ + //更新托盘活动区布局 + QStringList show=readSettings().at(0); + show.removeAll(""); + QStringList hide=readSettings().at(1); + hide.removeAll(""); + QStringList fixed=readFixedAppSettings(); + fixed.removeAll(""); + m_activeButtons.clear(); + m_layoutButtons.clear(); + for(int i=0;i<m_statusNotifierButtons.size();i++) { + if(m_statusNotifierButtons.at(i)) { + m_layoutButtons.insert(m_statusNotifierButtons.at(i)->m_id,m_statusNotifierButtons.at(i)); + if(m_statusNotifierButtons.at(i)->isVisible()) { + m_activeButtons.insert(m_statusNotifierButtons.at(i)->m_id,m_statusNotifierButtons.at(i)); + if((!show.contains(m_statusNotifierButtons.at(i)->m_id))&&(!hide.contains(m_statusNotifierButtons.at(i)->m_id)) + &&(!fixed.contains(m_statusNotifierButtons.at(i)->m_id))) { + if(m_statusNotifierButtons.at(i)->m_id=="") { + continue; + } + hide.append(m_statusNotifierButtons.at(i)->m_id); + qCritical()<<"config change resetLayout:id tooltoptitle:" + <<m_statusNotifierButtons.at(i)->m_id + <<m_statusNotifierButtons.at(i)->m_toolTipTitle; + saveSettings("",m_statusNotifierButtons.at(i)->m_id); + continue; + } + } + } + else { + qDebug()<<"m_statusNotifierButtons add error : "<<m_statusNotifierButtons.at(i); + } + } + m_hideButtons.clear(); + for(int i=0;i<hide.size();i++) { + if(!m_activeButtons.value(hide.at(i))==NULL) { + m_activeButtons.value(hide.at(i))->setVisible(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()); + m_activeButtons.value(hide.at(i))->setActionArea(STORAGE); + m_layout->addWidget(m_activeButtons.value(hide.at(i))); + m_hideButtons.insert(hide.at(i),m_activeButtons.value(hide.at(i))); + } + } + m_layout->addWidget(m_arrowBtn); + m_showButtons.clear(); + for(int i=0;i<show.size();i++) { + if(!m_activeButtons.value(show.at(i))==NULL) { + if(m_activeButtons.keys().contains(show.at(i))) { + m_activeButtons.value(show.at(i))->setActionArea(SHOW); + m_layout->addWidget(m_activeButtons.value(show.at(i))); + m_showButtons.insert(show.at(i),m_activeButtons.value(show.at(i))); + } + } + } + m_layout->setEnabled(true); + + //更新托盘固定区布局 + for(int i=0;i<m_statusNotifierFixedButtons.size();i++) { + if(m_statusNotifierFixedButtons.at(i)) { + m_fixedButtons.insert(m_statusNotifierFixedButtons.at(i)->m_id,m_statusNotifierFixedButtons.at(i)); + } + } + for(int i=0;i<m_fixedButtons.size();i++) { + if(!m_fixedButtons.value(fixed.at(i))==NULL) { + m_fixedButtons.value(fixed.at(i))->setAcceptDrops(false); + m_fixedButtons.value(fixed.at(i))->setVisible(true); + m_fixedButtons.value(fixed.at(i))->setActionArea(FIXED); + m_layoutFix->addWidget(m_fixedButtons.value(fixed.at(i))); + } + } + realign(); +} + +void StatusNotiferScrollArea::switchButtons(StatusNotifierButtonAbstract *srcButton, + StatusNotifierButtonAbstract *dstButton) +{ + if (srcButton == dstButton) + return; + + int srcIndex = m_layout->indexOf(srcButton); + int dstIndex = m_layout->indexOf(dstButton); + if (dstIndex == srcIndex || m_layout->animatedMoveInProgress()) { + return; + } + + StatusNotifierButton *src_item = nullptr; + StatusNotifierButton *dst_item = nullptr; + StatusNotifierStorageArrow *dst_arrow = nullptr; + + if(dstButton->getTypeName() == "Item") { + dst_item = qobject_cast<StatusNotifierButton *>(dstButton); + } else if(dstButton->getTypeName() == "StorageArrow") { + exchangeHideAndShow(); + dst_arrow = qobject_cast<StatusNotifierStorageArrow *>(dstButton); + } + + if(srcButton->getTypeName() == "Item") { + src_item = qobject_cast<StatusNotifierButton *>(srcButton); + } + + m_layout->moveItem(srcIndex, dstIndex, true); + + if(dst_arrow) { + saveSettings(src_item->m_id,QString()); + } else { + saveSettings(src_item->m_id,dst_item->m_id); + } +} + +void StatusNotiferScrollArea::saveSettings(QString button1,QString button2) +{ + PluginSettings *settings=m_plugin->settings(); + QStringList showApp=settings->value("showApp").toStringList(); + QStringList hideApp=settings->value("hideApp").toStringList(); + + if(button2==NULL) { + if(showApp.contains(button1)) { + showApp.removeAll(button1); + hideApp.append(button1); + } else if(hideApp.contains(button1)) { + hideApp.removeAll(button1); + showApp.insert(0,button1); + } + settings->setValue("showApp",showApp); + settings->setValue("hideApp",hideApp); + return; + } + + if(button1==NULL) { + if(!button2.isNull()) { + hideApp.append(button2); + hideApp.removeAll(""); + settings->setValue("hideApp",hideApp); + return; + } + } + + if(showApp.contains(button1)&&showApp.contains(button2)) { + showApp.move(showApp.indexOf(button1), showApp.indexOf(button2)); + settings->setValue("showApp",showApp); + } + + if(showApp.contains(button1)&&hideApp.contains(button2)) { + hideApp.insert(hideApp.indexOf(button2),button1); + showApp.removeAll(button1); + settings->setValue("showApp",showApp); + settings->setValue("hideApp",hideApp); + } + + + if(hideApp.contains(button1)&&showApp.contains(button2)) { + showApp.insert(showApp.indexOf(button2),button1); + hideApp.removeAll(button1); + settings->setValue("showApp",showApp); + settings->setValue("hideApp",hideApp); + } + if(hideApp.contains(button1)&&hideApp.contains(button2)) { + hideApp.move(hideApp.indexOf(button1), hideApp.indexOf(button2)); + settings->setValue("hideApp",hideApp); + } + resetLayout(); +} + +QList<QStringList> StatusNotiferScrollArea::readSettings() +{ + PluginSettings *settings=m_plugin->settings(); + QStringList showApp=settings->value("showApp").toStringList(); + QStringList hideApp=settings->value("hideApp").toStringList(); + QList<QStringList> list; + list.append(showApp); + list.append(hideApp); + return list; +} + +QStringList StatusNotiferScrollArea::readFixedAppSettings() +{ + PluginSettings *settings = m_plugin->settings(); + QStringList fixedApp = settings->value("fixedApp").toStringList(); + return fixedApp; +} + +void StatusNotiferScrollArea::exchangeHideAndShow() +{ + QMap<QString,StatusNotifierButton*> hideButtons; + QStringList hide=readSettings().at(1); + hide.removeAll(""); + for(int i=0;i<hide.size();i++) { + if(!m_layoutButtons.value(hide.at(i))==NULL) { + hideButtons.insert(hide.at(i),m_layoutButtons.value(hide.at(i))); + } + } + + QMap<QString, StatusNotifierButton*>::const_iterator i; + for(i=hideButtons.constBegin();i!=hideButtons.constEnd();++i) { + if(i.value()->getStatus()!=PASSIVE) { + bool status = m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool(); + i.value()->setVisible(status); + } + } + + bool status = m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool(); + for(int i=0;i<m_statusNotifierButtons.size();i++) { + m_statusNotifierButtons.at(i)->setFoldState(!status); + } + + resetLayout(); +} + + +void StatusNotiferScrollArea::arrowbtnAddButton(StatusNotifierButtonAbstract *srcButton, + StatusNotifierButtonAbstract *dstButton) +{ + if (srcButton == dstButton) + return; + int srcIndex = m_layout->indexOf(srcButton); + int dstIndex = m_layout->indexOf(dstButton); + if (dstIndex == srcIndex || m_layout->animatedMoveInProgress()) { + return; + } + + switchButtons(srcButton,dstButton); + resetLayout(); +} + +QString StatusNotiferScrollArea::getDisplayId(QString pid) +{ + //从 /proc/$pid/environ 中获取 DISPLAY 字段信息,此方案不适用于wayland + QString environPath = "/proc/" + pid + "/environ"; + QFile envFile(environPath); + if(envFile.open(QIODevice::ReadOnly)) { + QByteArray array = envFile.readAll(); + array.replace('\0','#'); + QStringList list = QString(array).split("#"); + for(int i=0; i<list.size(); i++) { + QString str = list.at(i); + if(str.startsWith(QLatin1String("DISPLAY="),Qt::CaseSensitive)) { + QStringList list = str.split("="); + qInfo()<<"DISPLAY :"<<list.at(1); + return list.at(1); + } + } + qInfo()<<"No find DISPLAY "; + return QString(getenv("DISPLAY")); + } else { + qInfo()<<environPath << " open failed!"; + return QString(getenv("DISPLAY")); + } +} + + + diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotiferscrollarea.h ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotiferscrollarea.h --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotiferscrollarea.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotiferscrollarea.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,112 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * https://lxqt.org + * + * Copyright: 2015 LXQt team + * Authors: + * Balázs Béla <balazsbela[at]gmail.com> + * Paulo Lieuthier <paulolieuthier@gmail.com> + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef STATUSNOTIFERSCROLLAREA_H +#define STATUSNOTIFERSCROLLAREA_H +#include <QScrollBar> +#include <QScrollArea> +#include <QWidget> +#include "../panel/iukuipanelplugin.h" +#include "../panel/common/ukuigridlayout.h" +#include "../panel/pluginsettings.h" +#include "statusnotifierwidget.h" +#include "statusnotifierbutton.h" +#include "statusnotifierwatcher.h" +#include "statusnotifier_storagearrow.h" +#include "statusnotifierbuttonabstract.h" + +/***************************************************** +**托盘滚动区域布局 +----------------------------------------------- +| Active Area | Fixed Area +| | | | +| Storage | Storage | Show | +| Area | Arrow | Area | +----------------------------------------------- + +Active Area: + Storage Area:图标可收纳、可拖拽 + Show Area:图标不可收纳、可拖拽 + Storage Arrow:切换收纳区图标的显示和隐藏状态 +Fixed Area:固定区内图标不可拖拽、不可收纳 +*****************************************************/ +class StatusNotiferScrollArea : public QScrollArea +{ + Q_OBJECT +public: + StatusNotiferScrollArea(IUKUIPanelPlugin *plugin, QWidget *parent = 0); + ~StatusNotiferScrollArea(); + enum Status{PASSIVE=0, ACTIVE, NEEDSATTENTION}; + enum ActionArea{UNDEFINED=0,STORAGE,SHOW,FIXED}; + +protected: + void wheelEvent(QWheelEvent* event); + +public Q_SLOTS: + void realign(); + void itemAdded(QString serviceAndPath); + void itemRemoved(const QString &serviceAndPath); + +private Q_SLOTS: + void switchButtons(StatusNotifierButtonAbstract *srcButton, StatusNotifierButtonAbstract *dstButton); + void arrowbtnAddButton(StatusNotifierButtonAbstract *srcButton, StatusNotifierButtonAbstract *dstButton); + +private: + void saveSettings(QString button1,QString button2); + QList<QStringList> readSettings(); + QStringList readFixedAppSettings(); + void resetLayout(); + void exchangeHideAndShow(); + QString getDisplayId(QString pid); + +private: + IUKUIPanelPlugin *m_plugin; + QWidget *m_parent; + QWidget *m_outWidget; //最外层大窗口,是托盘活动区和托盘固定区的父窗口 + QWidget *m_statusNotifierWidget; //托盘活动区窗口 + QWidget *m_statusNotifierFixedWidget; //托盘固定区窗口(不允许图标拖动) + QGSettings *m_btnIsShowgsettings; + UKUi::GridLayout *m_layout; + UKUi::GridLayout *m_layoutFix; + QGridLayout *m_outLayout; + StatusNotifierWatcher *m_watcher; + + QHash<QString, StatusNotifierButton*> m_services; + QMap<QString,StatusNotifierButton*> m_showButtons; + QMap<QString,StatusNotifierButton*> m_hideButtons; + QMap<QString,StatusNotifierButton*> m_allButtons; + QMap<QString,StatusNotifierButton*> m_activeButtons; + QMap<QString,StatusNotifierButton*> m_layoutButtons; + QMap<QString,StatusNotifierButton*> m_fixedButtons; + + QList<StatusNotifierButton*> m_statusNotifierButtons; + QList<StatusNotifierButton*> m_statusNotifierFixedButtons; + StatusNotifierStorageArrow *m_arrowBtn; + QGSettings *m_gsettings; +}; + +#endif // STATUSNOTIFERSCROLLAREA_H diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier.cpp ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier.cpp --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -32,10 +32,10 @@ QObject(), IUKUIPanelPlugin(startupInfo) { - m_widget = new StatusNotifierWidget(this); + m_scrollArea = new StatusNotiferScrollArea(this); } void StatusNotifier::realign() { - m_widget->realign(); + m_scrollArea->realign(); } diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier.h ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier.h --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier.h 2023-05-22 14:06:12.000000000 +0800 @@ -30,7 +30,7 @@ #define STATUSNOTIFIER_PLUGIN_H #include "../panel/iukuipanelplugin.h" -#include "statusnotifierwidget.h" +#include "statusnotiferscrollarea.h" class StatusNotifier : public QObject, public IUKUIPanelPlugin { @@ -42,10 +42,15 @@ void realign(); QString themeId() const { return "StatusNotifier"; } virtual Flags flags() const { return SingleInstance | NeedsHandle; } - QWidget *widget() { return m_widget; } + QWidget *widget() { + if(m_scrollArea) + return m_scrollArea; + else + return nullptr; + } private: - StatusNotifierWidget *m_widget; + StatusNotiferScrollArea *m_scrollArea; }; class StatusNotifierLibrary : public QObject, public IUKUIPanelPluginLibrary diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier_storagearrow.cpp ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier_storagearrow.cpp --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier_storagearrow.cpp 2022-05-11 18:11:34.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier_storagearrow.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -21,10 +21,11 @@ #include "../panel/customstyle.h" #include <QApplication> -StatusNotifierStorageArrow::StatusNotifierStorageArrow(IUKUIPanelPlugin* plugin, StatusNotifierWidget *parent): -mPlugin(plugin) +StatusNotifierStorageArrow::StatusNotifierStorageArrow(IUKUIPanelPlugin* plugin, QWidget *parent): + StatusNotifierButtonAbstract(parent), + m_plugin(plugin) { - mParent=parent; + m_parent=parent; this->setParent(parent); this->setAcceptDrops(true); @@ -32,19 +33,15 @@ //设置按钮属性 this->setProperty("useButtonPalette",true); this->setAutoRaise(true); - QPalette pal = qApp->palette(); - QColor col = pal.color(QPalette::Active, QPalette::ButtonText); - col.setAlphaF(mBtnAlphaF); - pal.setColor(QPalette::Button, col); - this->setPalette(pal); this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setHoverBtnProperty(); const QByteArray id(UKUI_PANEL_SETTINGS); - if(QGSettings::isSchemaInstalled(id)){ - mGsettings = new QGSettings(id); - connect(mGsettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key == PANEL_POSITION_KEY){ - mPanelPosition=mGsettings->get(PANEL_POSITION_KEY).toInt(); + if(QGSettings::isSchemaInstalled(id)) { + m_gsettings = new QGSettings(id); + connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key) { + if(key == PANEL_POSITION_KEY) { + m_panelPosition=m_gsettings->get(PANEL_POSITION_KEY).toInt(); setArrowIcon(); } }); @@ -58,24 +55,25 @@ StatusNotifierStorageArrow::~StatusNotifierStorageArrow() { - if(mThemeSettings) { - delete(mThemeSettings); - mThemeSettings = NULL; + if(m_themeSettings) { + delete(m_themeSettings); + m_themeSettings = NULL; } } -void StatusNotifierStorageArrow::dropEvent(QDropEvent *event){ +void StatusNotifierStorageArrow::dropEvent(QDropEvent *event) +{ } -void StatusNotifierStorageArrow::dragEnterEvent(QDragEnterEvent *event){ +void StatusNotifierStorageArrow::dragEnterEvent(QDragEnterEvent *event) +{ const StatusNotifierButtonMimeData *mimeData = qobject_cast<const StatusNotifierButtonMimeData*>(event->mimeData()); if (mimeData && mimeData->button()){ - emit addButton(mimeData->button()->mId); - } - - if(mGsettings){ - mGsettings->set(SHOW_STATUSNOTIFIER_BUTTON,true); - setArrowIcon(); + if(m_gsettings && m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()==false) { + m_gsettings->set(SHOW_STATUSNOTIFIER_BUTTON,true); + setArrowIcon(); + } + emit addButton(mimeData->button(), this); } event->accept(); QToolButton::dragEnterEvent(event); @@ -87,46 +85,49 @@ event->accept(); } -void StatusNotifierStorageArrow::mousePressEvent(QMouseEvent *e) +void StatusNotifierStorageArrow::mousePressEvent(QMouseEvent *event) +{ + setPressBtnProperty(); +} + +void StatusNotifierStorageArrow::mouseReleaseEvent(QMouseEvent *event) { - if(e->button() == Qt::LeftButton){ - if(mParent->Direction){ - if(mGsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()){ + setHoverBtnProperty(); + + if(event->button() == Qt::LeftButton) { + if(m_plugin->panel()->isHorizontal()) { + if(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()) { setIcon(QIcon::fromTheme("ukui-start-symbolic")); - mGsettings->set(SHOW_STATUSNOTIFIER_BUTTON,false); - } - else{ + m_gsettings->set(SHOW_STATUSNOTIFIER_BUTTON,false); + } else { setIcon(QIcon::fromTheme("ukui-end-symbolic")); - mGsettings->set(SHOW_STATUSNOTIFIER_BUTTON,true); + m_gsettings->set(SHOW_STATUSNOTIFIER_BUTTON,true); } - } - else{ - if(mGsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()){ + } else{ + if(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()) { setIcon(QIcon::fromTheme("ukui-up-symbolic")); - mGsettings->set(SHOW_STATUSNOTIFIER_BUTTON,false); - } - else{ + m_gsettings->set(SHOW_STATUSNOTIFIER_BUTTON,false); + } else { setIcon(QIcon::fromTheme("ukui-down-symbolic")); - mGsettings->set(SHOW_STATUSNOTIFIER_BUTTON,true); + m_gsettings->set(SHOW_STATUSNOTIFIER_BUTTON,true); } } } + QToolButton::mouseReleaseEvent(event); } void StatusNotifierStorageArrow::setArrowIcon() { - if(mParent->Direction){ - if(mGsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()){ + if(m_plugin->panel()->isHorizontal()) { + if(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()) { setIcon(QIcon::fromTheme("ukui-end-symbolic")); - } - else{ + } else { setIcon(QIcon::fromTheme("ukui-start-symbolic")); } - }else{ - if(mGsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()){ + } else { + if(m_gsettings->get(SHOW_STATUSNOTIFIER_BUTTON).toBool()) { setIcon(QIcon::fromTheme("ukui-down-symbolic")); - } - else{ + } else { setIcon(QIcon::fromTheme("ukui-up-symbolic")); } } @@ -136,46 +137,76 @@ { //主题变化 重新设置按钮背景颜色属性 const QByteArray styleId(ORG_UKUI_STYLE); - if(QGSettings::isSchemaInstalled(styleId)){ - mThemeSettings = new QGSettings(styleId); - connect(mThemeSettings, &QGSettings::changed, this, [=] (const QString &key){ + if(QGSettings::isSchemaInstalled(styleId)) { + m_themeSettings = new QGSettings(styleId); + connect(m_themeSettings, &QGSettings::changed, this, [=] (const QString &key) { if(key == STYLE_NAME) { - QPalette pal = qApp->palette(); - QColor col = pal.color(QPalette::Active, QPalette::ButtonText); - col.setAlphaF(mBtnAlphaF); - pal.setColor(QPalette::Button, col); - this->setPalette(pal); + setHoverBtnProperty(); } }); } } -void StatusNotifierStorageArrow::resizeEvent(QResizeEvent *event){ - if (mParent->Direction) - { +void StatusNotifierStorageArrow::resizeEvent(QResizeEvent *event) +{ + if (m_plugin->panel()->isHorizontal()) { this->setIconSize(QSize(this->width()*0.5,this->width()*0.5)); - } - else - { + } else { this->setIconSize(QSize(this->height()*0.5,this->height()*0.5)); } - QToolButton::resizeEvent(event); } void StatusNotifierStorageArrow::paintEvent(QPaintEvent *event) { - if (mPlugin->panel()->isHorizontal()) { - this->setFixedSize(mPlugin->panel()->panelSize()*0.7-4, mPlugin->panel()->panelSize()-4); + if (m_plugin->panel()->isHorizontal()) { + this->setFixedSize(m_plugin->panel()->panelSize()*0.7, m_plugin->panel()->panelSize()*0.7); } else { - this->setFixedSize(mPlugin->panel()->panelSize()-4, mPlugin->panel()->panelSize()*0.7-4); + this->setFixedSize(m_plugin->panel()->panelSize()*0.7, m_plugin->panel()->panelSize()*0.7); } QToolButton::paintEvent(event); } -void StatusNotifierStorageArrow::mouseMoveEvent(QMouseEvent *e) +void StatusNotifierStorageArrow::mouseMoveEvent(QMouseEvent *event) { QDrag *drag = new QDrag(this); drag->exec(); drag->deleteLater(); } +void StatusNotifierStorageArrow::setHoverBtnProperty() +{ + if(m_themeSettings) { + QStringList allKeys = m_themeSettings->keys(); + if(allKeys.contains(STYLE_NAME)) { + QPalette pal = qApp->palette(); + QColor col = pal.color(QPalette::Active, QPalette::ButtonText); + QString styleName = m_themeSettings->get(STYLE_NAME).toString(); + if(styleName==STYLE_NAME_KEY_DARK || styleName==STYLE_NAME_KEY_BLACK) { + col.setAlphaF(m_blackHoverBtnAlphaF); + } else if(styleName==STYLE_NAME_KEY_LIGHT || styleName==STYLE_NAME_KEY_WHITE || styleName==STYLE_NAME_KEY_DEFAULT) { + col.setAlphaF(m_lightHoverBtnAlphaF); + } + pal.setColor(QPalette::Button, col); + this->setPalette(pal); + } + } +} + +void StatusNotifierStorageArrow::setPressBtnProperty() +{ + if(m_themeSettings) { + QStringList allKeys = m_themeSettings->keys(); + if(allKeys.contains(STYLE_NAME)) { + QPalette pal = qApp->palette(); + QColor col = pal.color(QPalette::Active, QPalette::ButtonText); + QString styleName = m_themeSettings->get(STYLE_NAME).toString(); + if(styleName==STYLE_NAME_KEY_DARK || styleName==STYLE_NAME_KEY_BLACK) { + col.setAlphaF(m_blackPressBtnAlphaF); + } else if(styleName==STYLE_NAME_KEY_LIGHT || styleName==STYLE_NAME_KEY_WHITE || styleName==STYLE_NAME_KEY_DEFAULT) { + col.setAlphaF(m_lightPressBtnAlphaF); + } + pal.setColor(QPalette::Button, col); + this->setPalette(pal); + } + } +} diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier_storagearrow.h ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier_storagearrow.h --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifier_storagearrow.h 2022-05-11 18:11:34.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifier_storagearrow.h 2023-05-22 14:06:12.000000000 +0800 @@ -23,6 +23,7 @@ #include <QGSettings> #include <QDrag> #include "statusnotifierwidget.h" +#include "statusnotifierbuttonabstract.h" #define UKUI_PANEL_SETTINGS "org.ukui.panel.settings" #define SHOW_STATUSNOTIFIER_BUTTON "statusnotifierbutton" @@ -32,15 +33,17 @@ class StatusNotifierWidget; -class StatusNotifierStorageArrow : public QToolButton +class StatusNotifierStorageArrow : public StatusNotifierButtonAbstract { Q_OBJECT public: - StatusNotifierStorageArrow(IUKUIPanelPlugin* plugin, StatusNotifierWidget *parent = nullptr); + StatusNotifierStorageArrow(IUKUIPanelPlugin* plugin, QWidget *parent = nullptr); ~StatusNotifierStorageArrow(); + QString getTypeName() override {return QString("StorageArrow");} protected: - void mousePressEvent(QMouseEvent *e); - void mouseMoveEvent(QMouseEvent *e); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); void dropEvent(QDropEvent *event); void dragEnterEvent(QDragEnterEvent *event); void dragLeaveEvent(QDragLeaveEvent *event); @@ -49,17 +52,22 @@ private: void setArrowIcon(); void systemThemeChanges(); + void setHoverBtnProperty(); + void setPressBtnProperty(); private: - QGSettings *mGsettings; - StatusNotifierWidget *mParent; - int mPanelPosition; - IUKUIPanelPlugin* mPlugin; - QGSettings *mThemeSettings; - const qreal mBtnAlphaF = 0.13; //按钮背景透明度暂时使用UKUI3.1版本的透明度 - + QGSettings *m_gsettings; + QWidget *m_parent; + int m_panelPosition; + IUKUIPanelPlugin* m_plugin; + QGSettings *m_themeSettings; + const qreal m_blackHoverBtnAlphaF = 0.1; //深色主题下按钮悬停和按下透明度 + const qreal m_blackPressBtnAlphaF = 0.05; + const qreal m_lightHoverBtnAlphaF = 0.05; //浅色主题下按钮悬停和按下透明度 + const qreal m_lightPressBtnAlphaF = 0.1; signals: - void addButton(QString button); + void addButton(StatusNotifierButtonAbstract *from, StatusNotifierButtonAbstract *to); + void switchButtons(StatusNotifierButtonAbstract *from, StatusNotifierButtonAbstract *to); }; #endif // STATUSNOTIFIERSTORAGEARROW_H diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbutton.cpp ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbutton.cpp --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbutton.cpp 2022-05-11 18:11:34.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbutton.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -35,41 +35,47 @@ #include "../panel/iukuipanelplugin.h" #include "sniasync.h" #include "../panel/customstyle.h" -#include "../panel/highlight-effect.h" #include <QDebug> #include <KWindowEffects> //#include <XdgIcon> #define MIMETYPE "ukui/UkuiTaskBar" +#define ICON_ZOOM 0.348 StatusNotifierButton::StatusNotifierButton(QString service, QString objectPath, IUKUIPanelPlugin* plugin, QWidget *parent) - : QToolButton(parent), - mMenu(nullptr), - mMenuImporter(nullptr), - mStatus(Passive), - mFallbackIcon(QIcon::fromTheme("application-x-executable")), - mPlugin(plugin) + : StatusNotifierButtonAbstract(parent), + m_menu(nullptr), + m_menuImporter(nullptr), + m_status(PASSIVE), + m_fallbackIcon(QIcon::fromTheme("application-x-executable")), + m_plugin(plugin) { this->setAcceptDrops(true); - interface = new SniAsync(service, objectPath, QDBusConnection::sessionBus(), this); + m_interface = new SniAsync(service, objectPath, QDBusConnection::sessionBus(), this); - connect(interface, &SniAsync::NewIcon, this, &StatusNotifierButton::newIcon); - connect(interface, &SniAsync::NewOverlayIcon, this, &StatusNotifierButton::newOverlayIcon); - connect(interface, &SniAsync::NewAttentionIcon, this, &StatusNotifierButton::newAttentionIcon); - connect(interface, &SniAsync::NewToolTip, this, &StatusNotifierButton::newToolTip); - connect(interface, &SniAsync::NewStatus, this, &StatusNotifierButton::newStatus); + connect(m_interface, &SniAsync::NewIcon, this, &StatusNotifierButton::newIcon); + connect(m_interface, &SniAsync::NewOverlayIcon, this, &StatusNotifierButton::newOverlayIcon); + connect(m_interface, &SniAsync::NewAttentionIcon, this, &StatusNotifierButton::newAttentionIcon); + connect(m_interface, &SniAsync::NewToolTip, this, &StatusNotifierButton::newToolTip); + connect(m_interface, &SniAsync::NewStatus, this, &StatusNotifierButton::newStatus); hideAbleStatusNotifierButton(); - connect(this,&StatusNotifierButton::paramReady,this,[=](){ - if(!this->mId.isEmpty() && this->mIconStatus && !mParamInit){ + connect(this,&StatusNotifierButton::paramReady,this,[=]() { + qInfo()<<" Itme paramReady:" << "m_id:" << m_id << this->m_iconStatus << !m_paramInit; + if(!this->m_id.isEmpty() && this->m_iconStatus && !m_paramInit) { emit layoutReady(); - mParamInit = true; - } - else{ - if(this->mId.isEmpty()){ - if(mCount < 5) //超过5次将不再获取 - hideAbleStatusNotifierButton(); - mCount++; + m_paramInit = true; + } else { + if(this->m_id.isEmpty()) { + if(m_count < 10) { //超过10次将不再获取 + QTimer::singleShot(500,[this] { + hideAbleStatusNotifierButton(); + }); + qWarning()<<"Get item id for the"<<m_count<<"time"; + } else { + qCritical()<<"count more than 10 times, "<<m_id<<m_toolTipTitle<<service<<"Load failed!"; + } + m_count++; } } }); @@ -80,176 +86,150 @@ 有菜单项返回 - "/MenuBar",其他; x-sni注册的图标返回 - "" */ - interface->propertyGetAsync(QLatin1String("Menu"), [this] (QDBusObjectPath path) { - if(path.path() != "/NO_DBUSMENU" && !path.path().isEmpty()) - { - mMenuImporter = new MenuImporter(interface->service(), path.path(), this); - if(mMenuImporter){ - connect(mMenuImporter, &MenuImporter::menuUpdated, this, &StatusNotifierButton::updataItemMenu); - mMenu = mMenuImporter->menu(); - if(mMenu){ - mMenu->setObjectName(QLatin1String("StatusNotifierMenu")); - KWindowEffects::enableBlurBehind(mMenu->winId(), true); - } + m_interface->propertyGetAsync(QLatin1String("Menu"), [this] (QDBusObjectPath path) { + if(path.path() != "/NO_DBUSMENU" && !path.path().isEmpty()) { + m_menuImporter = new MenuImporter(m_interface->service(), path.path(), this); + if(m_menuImporter) { + connect(m_menuImporter, &MenuImporter::menuUpdated, this, &StatusNotifierButton::updataItemMenu); } } }); - interface->propertyGetAsync(QLatin1String("Status"), [this] (QString status) { + m_interface->propertyGetAsync(QLatin1String("Status"), [this] (QString status) { newStatus(status); }); - interface->propertyGetAsync(QLatin1String("IconThemePath"), [this] (QString value) { - mThemePath = value; + m_interface->propertyGetAsync(QLatin1String("IconThemePath"), [this] (QString value) { + m_themePath = value; //do the logic of icons after we've got the theme path - refetchIcon(Active); - refetchIcon(Passive); - refetchIcon(NeedsAttention); + refetchIcon(ACTIVE); + refetchIcon(PASSIVE); + refetchIcon(NEEDSATTENTION); }); - this->setProperty("useIconHighlightEffect", 0x2); + this->setProperty("useIconHighlightEffect", 0x10); newToolTip(); systemThemeChanges(); //设置按钮属性 this->setProperty("useButtonPalette",true); this->setAutoRaise(true); - QPalette pal = qApp->palette(); - QColor col = pal.color(QPalette::Active, QPalette::ButtonText); - col.setAlphaF(mBtnAlphaF); - pal.setColor(QPalette::Button, col); - this->setPalette(pal); this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setHoverBtnProperty(); } StatusNotifierButton::~StatusNotifierButton() { - delete interface; - if(mThemeSettings) { - delete(mThemeSettings); - mThemeSettings = NULL; + delete m_interface; + if(m_themeSettings) { + delete(m_themeSettings); + m_themeSettings = NULL; } } void StatusNotifierButton::newIcon() { - refetchIcon(Passive); + refetchIcon(ACTIVE); } void StatusNotifierButton::newOverlayIcon() { - refetchIcon(Active); + refetchIcon(ACTIVE); } void StatusNotifierButton::newAttentionIcon() { - refetchIcon(NeedsAttention); + refetchIcon(NEEDSATTENTION); } void StatusNotifierButton::refetchIcon(Status status) { + m_interface->propertyGetAsync(QLatin1String("IconThemePath"), [this] (QString value) { + m_themePath = value; + }); + QString nameProperty, pixmapProperty; - if (status == Active) - { - nameProperty = QLatin1String("OverlayIconName"); - pixmapProperty = QLatin1String("OverlayIconPixmap"); - } - else if (status == NeedsAttention) - { - nameProperty = QLatin1String("AttentionIconName"); - pixmapProperty = QLatin1String("AttentionIconPixmap"); - } - else // status == Passive - { + if (status == ACTIVE) { nameProperty = QLatin1String("IconName"); pixmapProperty = QLatin1String("IconPixmap"); + } else if (status == NEEDSATTENTION) { + nameProperty = QLatin1String("AttentionIconName"); + pixmapProperty = QLatin1String("AttentionIconPixmap"); + } else { + resetIcon(); + return; } - interface->propertyGetAsync(nameProperty, [this, status, pixmapProperty] (QString iconName) { + m_interface->propertyGetAsync(nameProperty, [this, status, pixmapProperty] (QString iconName) { QIcon nextIcon; - if (!iconName.isEmpty()) - { - if (QIcon::hasThemeIcon(iconName)) + if (!iconName.isEmpty()) { + if (QIcon::hasThemeIcon(iconName)) { nextIcon = QIcon::fromTheme(iconName); - else - { - QDir themeDir(mThemePath); - if (themeDir.exists()) - { - if (themeDir.exists(iconName + ".png")) + } else { + if(m_themePath.isEmpty()) + m_themePath = "/usr/share/icons/"; + QDir themeDir(m_themePath); + if (themeDir.exists()) { + if (themeDir.exists(iconName + ".png")) { nextIcon.addFile(themeDir.filePath(iconName + ".png")); + } - if (themeDir.cd("hicolor") || (themeDir.cd("icons") && themeDir.cd("hicolor"))) - { + if (themeDir.cd("hicolor") || (themeDir.cd("icons") && themeDir.cd("hicolor"))) { const QStringList sizes = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - for (const QString &dir : sizes) - { + for (const QString &dir : sizes) { const QStringList dirs = QDir(themeDir.filePath(dir)).entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - for (const QString &innerDir : dirs) - { + for (const QString &innerDir : dirs) { QString file = themeDir.absolutePath() + "/" + dir + "/" + innerDir + "/" + iconName + ".png"; - if (QFile::exists(file)) + if (QFile::exists(file)) { nextIcon.addFile(file); + } } } } } } - nextIcon=HighLightEffect::drawSymbolicColoredIcon(nextIcon); - - switch (status) - { - case Active: - mOverlayIcon = nextIcon; + switch (status) { + case ACTIVE: + m_icon = nextIcon; break; - case NeedsAttention: - mAttentionIcon = nextIcon; - break; - case Passive: - mIcon = nextIcon; + case NEEDSATTENTION: + m_attentionIcon = nextIcon; break; } - resetIcon(); - } - else - { - interface->propertyGetAsync(pixmapProperty, [this, status, pixmapProperty] (IconPixmapList iconPixmaps) { + } else { + m_interface->propertyGetAsync(pixmapProperty, [this, status, pixmapProperty] (IconPixmapList iconPixmaps) { + if (iconPixmaps.empty()) return; QIcon nextIcon; - - for (IconPixmap iconPixmap: iconPixmaps) - { - if (!iconPixmap.bytes.isNull()) - { + for (IconPixmap iconPixmap: iconPixmaps) { + if (!iconPixmap.bytes.isNull()) { QImage image((uchar*) iconPixmap.bytes.data(), iconPixmap.width, iconPixmap.height, QImage::Format_ARGB32); - const uchar *end = image.constBits() + image.byteCount(); uchar *dest = reinterpret_cast<uchar*>(iconPixmap.bytes.data()); for (const uchar *src = image.constBits(); src < end; src += 4, dest += 4) qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest); - //图标反白 - QImage currentImage= getBlackThemeIcon(image); - nextIcon.addPixmap(QPixmap::fromImage(currentImage)); + QString style = m_themeSettings->get(STYLE_NAME).toString(); + if(style == STYLE_NAME_KEY_DARK || style == STYLE_NAME_KEY_DEFAULT) { + image = getBlackThemeIcon(image); + } + nextIcon.addPixmap(QPixmap::fromImage(image)); } } - - switch (status) - { - case Active: - mOverlayIcon = nextIcon; + switch (status) { + case ACTIVE: + m_icon = nextIcon; break; - case NeedsAttention: - mAttentionIcon = nextIcon; - break; - case Passive: - mIcon = nextIcon; + case NEEDSATTENTION: + m_attentionIcon = nextIcon; break; } resetIcon(); + QSize size = this->iconSize(); + m_iconPixmap = this->icon().pixmap(this->icon().actualSize(size)); }); } }); @@ -257,17 +237,20 @@ void StatusNotifierButton::newToolTip() { - interface->propertyGetAsync(QLatin1String("ToolTip"), [this] (ToolTip tooltip) { - + m_interface->propertyGetAsync(QLatin1String("ToolTip"), [this] (ToolTip tooltip) { QString toolTipTitle = tooltip.title; - if (!toolTipTitle.isEmpty()) + if (!toolTipTitle.isEmpty()) { + m_toolTipTitle = toolTipTitle; setToolTip(toolTipTitle); - else - interface->propertyGetAsync(QLatin1String("Title"), [this] (QString title) { + } else { + m_interface->propertyGetAsync(QLatin1String("Title"), [this] (QString title) { // we should get here only in case the ToolTip.title was empty - if (!title.isEmpty()) + if (!title.isEmpty()) { + m_toolTipTitle = title; setToolTip(title); + } }); + } }); } @@ -275,17 +258,20 @@ { Status newStatus; if (status == QLatin1String("Passive")) - newStatus = Passive; + newStatus = PASSIVE; else if (status == QLatin1String("Active")) - newStatus = Active; + newStatus = ACTIVE; + else if(status == QLatin1String("NeedsAttention")) + newStatus = NEEDSATTENTION; else - newStatus = NeedsAttention; + newStatus = ACTIVE; - if (mStatus == newStatus) + if (m_status == newStatus) return; - mStatus = newStatus; + m_status = newStatus; resetIcon(); + emit layoutUpdate(); } void StatusNotifierButton::contextMenuEvent(QContextMenuEvent* event) @@ -300,55 +286,82 @@ return; if (!(e->buttons() & Qt::LeftButton)) return; - if ((e->pos() - mDragStart).manhattanLength() < QApplication::startDragDistance()) + if ((e->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance()) return; - if (e->modifiers() == Qt::ControlModifier) - { + if (e->modifiers() == Qt::ControlModifier) { return; } - QDrag *drag = new QDrag(this); - QIcon ico = icon(); - int size = mPlugin->panel()->iconSize(); - QPixmap img = ico.pixmap(ico.actualSize({size, size})); - - drag->setMimeData(mimeData()); - drag->setPixmap(img); - - switch (mPlugin->panel()->position()) - { - case IUKUIPanel::PositionLeft: - case IUKUIPanel::PositionTop: - drag->setHotSpot({0, 0}); - break; - case IUKUIPanel::PositionRight: - case IUKUIPanel::PositionBottom: - drag->setHotSpot(img.rect().bottomRight()); - break; - } - drag->exec(); - drag->deleteLater(); + if(this->acceptDrops()) { + QDrag *drag = new QDrag(this); + QPixmap iconPixmap; + QIcon ico = icon(); + + QString iconName = this->icon().name(); + if(!iconName.isEmpty()) { + QSize size = this->iconSize(); + iconPixmap = ico.pixmap(ico.actualSize(size)); + QImage image = iconPixmap.toImage(); + if(m_themeSettings) { //深色模式下,拖拽提示图标反白 + QString style = m_themeSettings->get(STYLE_NAME).toString(); + if(style == STYLE_NAME_KEY_DARK || style == STYLE_NAME_KEY_DEFAULT) { + image = getBlackThemeIcon(image); + iconPixmap = QPixmap::fromImage(image); + } + } + } else { + iconPixmap = m_iconPixmap; + QImage image = m_iconPixmap.toImage(); + if(m_themeSettings) { //深色模式下,拖拽提示图标反白 + QString style = m_themeSettings->get(STYLE_NAME).toString(); + if(style == STYLE_NAME_KEY_DARK || style == STYLE_NAME_KEY_DEFAULT) { + image = getBlackThemeIcon(image); + iconPixmap = QPixmap::fromImage(image); + } + } + } + drag->setMimeData(mimeData()); + drag->setPixmap(iconPixmap); + + switch (m_plugin->panel()->position()) { + case IUKUIPanel::PositionLeft: + case IUKUIPanel::PositionTop: + drag->setHotSpot(iconPixmap.rect().bottomLeft()); + break; + case IUKUIPanel::PositionRight: + case IUKUIPanel::PositionBottom: + drag->setHotSpot(iconPixmap.rect().bottomRight()); + break; + } + + //原按钮透明,取消文字和icon + this->setIcon(QIcon()); + drag->exec(); + drag->deleteLater(); + refetchIcon(ACTIVE); + } + QToolButton::mouseMoveEvent(e); //QAbstractButton::mouseMoveEvent(e); } void StatusNotifierButton::mouseReleaseEvent(QMouseEvent *event) { + setHoverBtnProperty(); + if (event->button() == Qt::LeftButton) - interface->Activate(QCursor::pos().x(), QCursor::pos().y()); + m_interface->Activate(QCursor::pos().x(), QCursor::pos().y()); else if (event->button() == Qt::MidButton) - interface->SecondaryActivate(QCursor::pos().x(), QCursor::pos().y()); - else if (Qt::RightButton == event->button()) - { - mCursorLeftPos = QCursor::pos(); - if(mMenuImporter) { - mMenuImporter->updateMenu(); - } - else { - interface->ContextMenu(mCursorLeftPos.x(), mCursorLeftPos.y()); + m_interface->SecondaryActivate(QCursor::pos().x(), QCursor::pos().y()); + else if (Qt::RightButton == event->button()) { + m_cursorLeftPos = QCursor::pos(); + if(m_menuImporter) { + m_menuImporter->updateMenu(); + } else { + m_interface->ContextMenu(m_cursorLeftPos.x(), m_cursorLeftPos.y()); + qDebug()<<"Tray proxy "<<m_id<<"contextMenu event."; } - } update(); QToolButton::mouseReleaseEvent(event); @@ -356,26 +369,43 @@ void StatusNotifierButton::wheelEvent(QWheelEvent *event) { - interface->Scroll(event->delta(), "vertical"); + m_interface->Scroll(event->delta(), "vertical"); } void StatusNotifierButton::resetIcon() { - if (mStatus == Active && !mOverlayIcon.isNull()) - setIcon(mOverlayIcon); - else if (mStatus == NeedsAttention && !mAttentionIcon.isNull()) - setIcon(mAttentionIcon); - else if (!mIcon.isNull()) // mStatus == Passive - setIcon(mIcon); - else if (!mOverlayIcon.isNull()) - setIcon(mOverlayIcon); - else if (!mAttentionIcon.isNull()) - setIcon(mAttentionIcon); - else - setIcon(mFallbackIcon); + if(m_status == PASSIVE) { + this->setVisible(false); + emit layoutUpdate(); + return; + } else if(m_status == ACTIVE) { + if(!m_icon.isNull()) + setIcon(m_icon); + else if(!m_overlayIcon.isNull()) + setIcon(m_overlayIcon); + else { + qInfo()<<"Failed to get icon! Id:"<<m_id<<" status:"<<m_status; + setIcon(m_fallbackIcon); + } + } else if(m_status == NEEDSATTENTION) { + if(!m_attentionIcon.isNull()) { + setIcon(m_attentionIcon); + } else { + qInfo()<<"Failed to get icon! Id:"<<m_id<<" status:"<<m_status; + setIcon(m_fallbackIcon); + } + } else { + qInfo()<<"Failed to get icon! Id:"<<m_id<<" status:"<<m_status; + setIcon(m_fallbackIcon); + } + if(m_actionArea == STORAGE) { + m_foldState ? this->setVisible(false) : this->setVisible(true); + } else { + this->setVisible(true); + } - mIconStatus=true; + m_iconStatus=true; emit paramReady(); } @@ -383,21 +413,17 @@ { //主题变化 const QByteArray styleId(ORG_UKUI_STYLE); - if(QGSettings::isSchemaInstalled(styleId)){ - mThemeSettings = new QGSettings(styleId); - - connect(mThemeSettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key == ICON_THEME_NAME){ + if(QGSettings::isSchemaInstalled(styleId)) { + m_themeSettings = new QGSettings(styleId); + connect(m_themeSettings, &QGSettings::changed, this, [=] (const QString &key) { + if(key == ICON_THEME_NAME) { //主题变化任务栏主动更新图标 - refetchIcon(Passive); + refetchIcon(ACTIVE); } if(key == STYLE_NAME) { //主题变化重新设置按钮背景颜色属性 - QPalette pal = qApp->palette(); - QColor col = pal.color(QPalette::Active, QPalette::ButtonText); - col.setAlphaF(mBtnAlphaF); - pal.setColor(QPalette::Button, col); - this->setPalette(pal); + setHoverBtnProperty(); + refetchIcon(ACTIVE); } }); } @@ -405,13 +431,14 @@ void StatusNotifierButton::updataItemMenu() { - mMenu = mMenuImporter->menu(); - if (mMenu && !mMenu->isEmpty()){ - mPlugin->willShowWindow(mMenu); - mMenu->exec(mPlugin->panel()->calculatePopupWindowPos(mCursorLeftPos, mMenu->sizeHint()).topLeft()); //任务栏显示右键菜单 - } - else{ - interface->ContextMenu(mCursorLeftPos.x(), mCursorLeftPos.y()); //应用显示右键菜单 + m_menu = m_menuImporter->menu(); + if (m_menu && !m_menu->isEmpty()) { + m_plugin->willShowWindow(m_menu); + m_menu->exec(m_menuImporter->menu()->actions(), m_plugin->panel()->calculatePopupWindowPos(m_cursorLeftPos, m_menu->sizeHint()).topLeft(), nullptr, this); //任务栏显示右键菜单 + qDebug()<<"Tray display "<<m_id<<"contextMenu."; + } else { + m_interface->ContextMenu(m_cursorLeftPos.x(), m_cursorLeftPos.y()); //应用显示右键菜单 + qDebug()<<"Tray proxy "<<m_id<<"contextMenu event."; } } @@ -429,7 +456,7 @@ { e->acceptProposedAction(); const StatusNotifierButtonMimeData *mimeData = qobject_cast<const StatusNotifierButtonMimeData*>(e->mimeData()); - if (mimeData && mimeData->button()){ + if (mimeData && mimeData->button()) { emit switchButtons(mimeData->button(), this); emit sendTitle(mimeData->button()->hideAbleStatusNotifierButton()); } @@ -453,8 +480,9 @@ void StatusNotifierButton::mousePressEvent(QMouseEvent *e) { + setPressBtnProperty(); if (e->button() == Qt::LeftButton ) { - mDragStart = e->pos(); + m_dragStart = e->pos(); return; } QToolButton::mousePressEvent(e); @@ -471,23 +499,15 @@ // qDebug()<<e->type(); if(e->type() == QEvent::ChildRemoved) { - emit cleansignal(); + emit cleanSignal(); } return QToolButton::event(e); } -void StatusNotifierButton::resizeEvent(QResizeEvent *event){ - IUKUIPanel *panel = mPlugin->panel(); - - if (panel->isHorizontal()) - { - this->setIconSize(QSize(this->width()*0.5,this->width()*0.5)); - } - else - { - this->setIconSize(QSize(this->height()*0.5,this->height()*0.5)); - } - +void StatusNotifierButton::resizeEvent(QResizeEvent *event) +{ + IUKUIPanel *panel = m_plugin->panel(); + this->setIconSize(QSize(panel->panelSize()*ICON_ZOOM,panel->panelSize()*ICON_ZOOM)); QToolButton::resizeEvent(event); } @@ -503,39 +523,101 @@ void StatusNotifierButton::paintEvent(QPaintEvent *event) { - if (mPlugin->panel()->isHorizontal()) { - this->setFixedSize(mPlugin->panel()->panelSize()*0.7-4, mPlugin->panel()->panelSize()-4); + if (m_plugin->panel()->isHorizontal()) { + this->setFixedSize(m_plugin->panel()->panelSize()*0.7, m_plugin->panel()->panelSize()*0.7); } else { - this->setFixedSize(mPlugin->panel()->panelSize()-4, mPlugin->panel()->panelSize()*0.7-4); + this->setFixedSize(m_plugin->panel()->panelSize()*0.7, m_plugin->panel()->panelSize()*0.7); } QToolButton::paintEvent(event); } QString StatusNotifierButton::hideAbleStatusNotifierButton() { - interface->propertyGetAsync(QLatin1String("Id"), [this] (QString title) { - mId = ""; - mId = title; + m_interface->propertyGetAsync(QLatin1String("Id"), [this] (QString title) { + m_id = ""; + m_id = title; emit paramReady(); - }); - return mId; + return m_id; +} + +int StatusNotifierButton::getStatus() +{ + return m_status; +} + +bool StatusNotifierButton::getFoldState() +{ + return m_foldState; +} + +void StatusNotifierButton::setFoldState(bool status) +{ + m_foldState = status; +} + +int StatusNotifierButton::getActionArea() +{ + return m_actionArea; +} + +void StatusNotifierButton::setActionArea(int actionArea) +{ + m_actionArea = actionArea; +} + +void StatusNotifierButton::setHoverBtnProperty() +{ + if(m_themeSettings) { + QStringList allKeys = m_themeSettings->keys(); + if(allKeys.contains(STYLE_NAME)) { + QPalette pal = qApp->palette(); + QColor col = pal.color(QPalette::Active, QPalette::ButtonText); + QString styleName = m_themeSettings->get(STYLE_NAME).toString(); + if(styleName==STYLE_NAME_KEY_DARK || styleName==STYLE_NAME_KEY_BLACK) { + col.setAlphaF(m_blackHoverBtnAlphaF); + } else if(styleName==STYLE_NAME_KEY_LIGHT || styleName==STYLE_NAME_KEY_WHITE || styleName==STYLE_NAME_KEY_DEFAULT) { + col.setAlphaF(m_lightHoverBtnAlphaF); + } + pal.setColor(QPalette::Button, col); + this->setPalette(pal); + } + } +} + +void StatusNotifierButton::setPressBtnProperty() +{ + if(m_themeSettings) { + QStringList allKeys = m_themeSettings->keys(); + if(allKeys.contains(STYLE_NAME)) { + QPalette pal = qApp->palette(); + QColor col = pal.color(QPalette::Active, QPalette::ButtonText); + QString styleName = m_themeSettings->get(STYLE_NAME).toString(); + if(styleName==STYLE_NAME_KEY_DARK || styleName==STYLE_NAME_KEY_BLACK) { + col.setAlphaF(m_blackPressBtnAlphaF); + } else if(styleName==STYLE_NAME_KEY_LIGHT || styleName==STYLE_NAME_KEY_WHITE || styleName==STYLE_NAME_KEY_DEFAULT) { + col.setAlphaF(m_lightPressBtnAlphaF); + } + pal.setColor(QPalette::Button, col); + this->setPalette(pal); + } + } } QImage StatusNotifierButton::getBlackThemeIcon(QImage image) { + QColor(255,255,255); QColor standard (31,32,34); for (int x = 0; x < image.width(); x++) { for (int y = 0; y < image.height(); y++) { auto color = image.pixelColor(x, y); if (color.alpha() > 0) { - if(qAbs(color.red()-standard.red())<20 && qAbs(color.green()-standard.green())<20 && qAbs(color.blue()-standard.blue())<20){ + if(qAbs(color.red()-standard.red())<20 && qAbs(color.green()-standard.green())<20 && qAbs(color.blue()-standard.blue())<20) { color.setRed(255); color.setGreen(255); color.setBlue(255); image.setPixelColor(x, y, color); - } - else{ + } else { image.setPixelColor(x, y, color); } } diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbutton.h ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbutton.h --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbutton.h 2022-05-11 18:11:34.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbutton.h 2023-05-22 14:06:12.000000000 +0800 @@ -42,10 +42,16 @@ #include <QString> #include <QGSettings> #include <dbusmenu-qt5/dbusmenuimporter.h> +#include "statusnotifierbuttonabstract.h" #define ORG_UKUI_STYLE "org.ukui.style" #define ICON_THEME_NAME "iconThemeName" #define STYLE_NAME "styleName" +#define STYLE_NAME_KEY_DARK "ukui-dark" +#define STYLE_NAME_KEY_BLACK "ukui-black" +#define STYLE_NAME_KEY_LIGHT "ukui-light" +#define STYLE_NAME_KEY_WHITE "ukui-white" +#define STYLE_NAME_KEY_DEFAULT "ukui-default" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) @@ -78,21 +84,24 @@ class SniAsync; class MenuImporter; -class StatusNotifierButton : public QToolButton +class StatusNotifierButton : public StatusNotifierButtonAbstract { Q_OBJECT public: StatusNotifierButton(QString service, QString objectPath, IUKUIPanelPlugin* plugin, QWidget *parent = 0); ~StatusNotifierButton(); + QString getTypeName() override {return QString("Item");} - enum Status - { - Passive, Active, NeedsAttention - }; + enum Status{PASSIVE=0, ACTIVE, NEEDSATTENTION}; + enum ActionArea{UNDEFINED=0,STORAGE,SHOW,FIXED}; QString hideAbleStatusNotifierButton(); + int getStatus(); + bool getFoldState(); + void setFoldState(bool status); + int getActionArea(); + void setActionArea(int actionArea); static QString mimeDataFormat() { return QLatin1String("x-ukui/statusnotifier-button"); } - QImage getBlackThemeIcon(QImage image); public slots: void newIcon(); @@ -102,39 +111,44 @@ void newStatus(QString status); public: - QString mId; - bool mIdStatus=false; - bool mIconStatus=false; + QString m_id; + bool m_idStatus=false; + bool m_iconStatus=false; + QString m_toolTipTitle; private: - SniAsync *interface; - MenuImporter *mMenuImporter; - QMenu *mMenu; - Status mStatus; - - QString mThemePath; - QIcon mIcon, mOverlayIcon, mAttentionIcon, mFallbackIcon; - - QPoint mDragStart; - - IUKUIPanelPlugin* mPlugin; - - QString drag_status_flag; - - uint mCount = 0; - bool mParamInit=false; - QGSettings *mThemeSettings; - QPoint mCursorLeftPos; - const qreal mBtnAlphaF = 0.13; //按钮背景透明度暂时使用UKUI3.1版本的透明度 - + SniAsync *m_interface; + MenuImporter *m_menuImporter; + QMenu *m_menu; + Status m_status; + QString m_themePath; + QIcon m_icon, m_overlayIcon, m_attentionIcon, m_fallbackIcon; + QPixmap m_iconPixmap; + + bool m_foldState; + int m_actionArea = UNDEFINED; + + QPoint m_dragStart; + + IUKUIPanelPlugin* m_plugin; + + uint m_count = 0; //使用静态变量,节省内存空间 + bool m_paramInit=false; + QGSettings *m_themeSettings; + QPoint m_cursorLeftPos; + const qreal m_blackHoverBtnAlphaF = 0.1; //深色主题下按钮悬停和按下透明度 + const qreal m_blackPressBtnAlphaF = 0.05; + const qreal m_lightHoverBtnAlphaF = 0.05; //浅色主题下按钮悬停和按下透明度 + const qreal m_lightPressBtnAlphaF = 0.1; signals: - void switchButtons(StatusNotifierButton *from, StatusNotifierButton *to); + void switchButtons(StatusNotifierButtonAbstract *from, StatusNotifierButtonAbstract *to); void sendTitle(QString arg); void sendstatus(QString arg); - void cleansignal(); + void cleanSignal(); void iconReady(); void layoutReady(); + void layoutUpdate(); void paramReady(); protected: @@ -159,6 +173,9 @@ private: void systemThemeChanges(); void updataItemMenu(); + void setHoverBtnProperty(); + void setPressBtnProperty(); + QImage getBlackThemeIcon(QImage image); }; @@ -168,15 +185,15 @@ public: StatusNotifierButtonMimeData(): QMimeData(), - mButton(0) + m_button(0) { } - StatusNotifierButton *button() const { return mButton; } - void setButton(StatusNotifierButton *button) { mButton = button; } + StatusNotifierButton *button() const { return m_button; } + void setButton(StatusNotifierButton *button) { m_button = button; } private: - StatusNotifierButton *mButton; + StatusNotifierButton *m_button; }; #endif // STATUSNOTIFIERBUTTON_H diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbuttonabstract.cpp ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbuttonabstract.cpp --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbuttonabstract.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbuttonabstract.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,7 @@ +#include "statusnotifierbuttonabstract.h" + +StatusNotifierButtonAbstract::StatusNotifierButtonAbstract(QWidget *parent): + QToolButton(parent) +{ + +} diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbuttonabstract.h ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbuttonabstract.h --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierbuttonabstract.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierbuttonabstract.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,17 @@ +#ifndef STATUSNOTIFIERBUTTONABSTRACT_H +#define STATUSNOTIFIERBUTTONABSTRACT_H +#include <QToolButton> +#include <QGSettings> +#include <QEvent> +#include <QMouseEvent> +#include "../panel/iukuipanelplugin.h" + +class StatusNotifierButtonAbstract : public QToolButton +{ + Q_OBJECT +public: + StatusNotifierButtonAbstract(QWidget *parent = 0); + virtual QString getTypeName() = 0; +}; + +#endif // STATUSNOTIFIERBUTTONABSTRACT_H diff -Nru ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierwidget.cpp ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierwidget.cpp --- ukui-panel-3.14.0.1/plugin-statusnotifier/statusnotifierwidget.cpp 2022-05-11 18:11:34.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-statusnotifier/statusnotifierwidget.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -35,11 +35,29 @@ #define UKUI_PANEL_SETTINGS "org.ukui.panel.settings" #define SHOW_STATUSNOTIFIER_BUTTON "statusnotifierbutton" +#define CONFIG_FILE_BACKUP "/usr/share/ukui/panel.conf" StatusNotifierWidget::StatusNotifierWidget(IUKUIPanelPlugin *plugin, QWidget *parent) : QWidget(parent), mPlugin(plugin) { + //检查配置文件是否完整 + QSettings backup_qsettings(CONFIG_FILE_BACKUP,QSettings::IniFormat); + QStringList showAppBackup = backup_qsettings.value("statusnotifier/showApp").toStringList(); + QStringList hideAppBackup = backup_qsettings.value("statusnotifier/hideApp").toStringList(); + QString alignmentBackup = backup_qsettings.value("statusnotifier/alignment").toString(); + PluginSettings *settings=mPlugin->settings(); // ~/.config/ukui/panel.conf + QStringList allkeys = settings->allKeys(); + if(!allkeys.contains("showApp")) { + settings->setValue("showApp",showAppBackup); + } + if(!allkeys.contains("hideApp")) { + settings->setValue("hideApp",hideAppBackup); + } + if(!allkeys.contains("alignment")) { + settings->setValue("alignment",alignmentBackup); + } + mWatcher = new StatusNotifierWatcher; connect(mWatcher, &StatusNotifierWatcher::StatusNotifierItemRegistered, @@ -77,12 +95,10 @@ QString serv = serviceAndPath.left(slash); QString path = serviceAndPath.mid(slash); StatusNotifierButton *button = new StatusNotifierButton(serv, path, mPlugin, this); - + mServices.insert(serviceAndPath, button); connect(button, SIGNAL(switchButtons(StatusNotifierButton*,StatusNotifierButton*)), this, SLOT(switchButtons(StatusNotifierButton*,StatusNotifierButton*))); - //QTimer::singleShot(200,this,[=](){resetLayout();}); connect(button,&StatusNotifierButton::layoutReady,this,[=](){ - if(button->mIconStatus && !button->mId.isEmpty()) { //Icon和ID都准备好后再加入布局 - mServices.insert(serviceAndPath, button); + if(button->m_iconStatus && !button->mId.isEmpty()) { //Icon和ID都准备好后再加入布局 mStatusNotifierButtons.append(button); resetLayout(); } @@ -92,8 +108,8 @@ void StatusNotifierWidget::itemRemoved(const QString &serviceAndPath) { StatusNotifierButton *button = mServices.value(serviceAndPath, NULL); - if (button) - { + if (button) { + disconnect(button,&StatusNotifierButton::layoutReady,0,0); mStatusNotifierButtons.removeOne(button); mLayout->removeWidget(button); if(m_ShowButtons.keys().contains(button->mId)){ @@ -102,7 +118,7 @@ if(m_HideButtons.keys().contains(button->mId)){ m_HideButtons.remove(button->mId); } - mServices.remove(serviceAndPath); + mServices.remove(serviceAndPath); m_AllButtons.remove(button->mId); resetLayout(); button->deleteLater(); @@ -116,19 +132,16 @@ layout->setDirection(UKUi::GridLayout::LeftToRight); IUKUIPanel *panel = mPlugin->panel(); - if (panel->isHorizontal()) - { + if (panel->isHorizontal()) { layout->setRowCount(panel->lineCount()); layout->setColumnCount(0); - layout->setCellFixedSize(QSize(panel->panelSize()*0.7,panel->panelSize())); - this->setMinimumHeight(panel->panelSize()); - } - else - { + int margins = panel->panelSize()*0.15; + this->setContentsMargins(margins,margins,margins,margins); + } else { layout->setColumnCount(panel->lineCount()); layout->setRowCount(0); - layout->setCellFixedSize(QSize(panel->panelSize(),panel->panelSize()*0.7)); - this->setMinimumWidth(panel->panelSize()); + int margins = panel->panelSize()*0.15; + this->setContentsMargins(margins,margins,margins,margins); } Direction=panel->isHorizontal(); layout->setEnabled(true); @@ -148,6 +161,9 @@ continue; } hide.append(mStatusNotifierButtons.at(i)->mId); + qCritical()<<"config change resetLayout:id tooltoptitle:" + <<mStatusNotifierButtons.at(i)->mId + <<mStatusNotifierButtons.at(i)->m_toolTipTitle; saveSettings("",mStatusNotifierButtons.at(i)->mId); continue; } @@ -196,6 +212,9 @@ if(!(m_ShowButtons.keys().contains(button1->mId)&&m_ShowButtons.keys().contains(button2->mId))){ m_ShowButtons.remove(button1->mId); } + qCritical()<<"config change resetLayout:id1 tooltoptitle1:" + <<button1->mId<<button1->m_toolTipTitle + <<"id2 tooltoptitle2:"<<button2->mId<<button2->m_toolTipTitle; saveSettings(button1->mId,button2->mId); resetLayout(); } diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/CMakeLists.txt ukui-panel-4.0.0.0/plugin-taskbar/CMakeLists.txt --- ukui-panel-3.14.0.1/plugin-taskbar/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/CMakeLists.txt 2023-05-22 14:06:12.000000000 +0800 @@ -20,13 +20,30 @@ ukuitaskwidget.cpp ukuitaskclosebutton.cpp quicklaunchaction.cpp + qml.qrc ) find_package(X11 REQUIRED) find_package(PkgConfig) + +set(LIBRARIES + ${X11_LIBRARIES} + Qt5X11Extras + Qt::Quick + Qt5::QuickWidgets +) + +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick Widgets QuickWidgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick Widgets QuickWidgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS QuickWidgets REQUIRED) + + pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0) pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0) +pkg_check_modules(KYSDKWAYLANDHELPER_PKG kysdk-waylandhelper) +find_package(KF5WindowSystem) +find_package(KF5Wayland) include_directories(${GLIB2_INCLUDE_DIRS}) #for <QDBusInterface> include_directories(${_Qt5DBus_OWN_INCLUDE_DIRS}) @@ -34,14 +51,15 @@ ${UKUI_INCLUDE_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}/../panel" ${GIOUNIX2_INCLUDE_DIRS} + ${KYSDKWAYLANDHELPER_PKG_INCLUDE_DIRS} ) +include_directories(/usr/include/ukui-kwin/) set(LIBRARIES Qt5Xdg ${GIOUNIX2_LIBRARIES} ${X11_LIBRARIES} Qt5X11Extras - -lukui-com4cxx ) install(FILES @@ -51,6 +69,8 @@ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE WORLD_EXECUTE GROUP_EXECUTE GROUP_READ ) +install(FILES ./qml/preview.qml + DESTINATION "/usr/share/ukui/ukui-panel/plugin-taskbar") include(../cmake/UkuiPluginTranslationTs.cmake) ukui_plugin_translate_ts(${PLUGIN}) diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/qml/preview.qml ukui-panel-4.0.0.0/plugin-taskbar/qml/preview.qml --- ukui-panel-3.14.0.1/plugin-taskbar/qml/preview.qml 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/qml/preview.qml 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,92 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.1 +import QtGraphicalEffects 1.0 +import QtQml.Models 2.2 + +import org.kde.plasma.core 2.0 as PlasmaCore +Column { + id: root + signal sendWinId() + signal sendMoveEntered() + signal sendMoveLeaved() + signal sendRightButtonClicked() + + Rectangle { + id: rect1 + objectName: "rect1"; + width: temp_width*1 + height: temp_height*1 + property int temp_width:100 + property int temp_height:100 + anchors.horizontalCenter: parent.horizontalCenter + visible: true + // activeFocus: true //留着这行会段错误 + activeFocusOnTab: true + focus: true + enabled: true + color:"#00000000" + + function setValue(value_width, value_height) + { + temp_width = value_width; + temp_height = value_height; + + } + + Component.onCompleted: { + console.debug("main.qml log"); + console.debug("temp_width=",temp_width); + console.debug("temp_height=",temp_height); + } + + // 缩略图 + PlasmaCore.WindowThumbnail { + id: tmpWindowThumbnail + objectName: "tmpWindowThumbnail" + anchors.fill: parent + visible: true + enabled: true + } + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + // TODO: + if (mouse.button == Qt.LeftButton) { + console.log("left mouse button"); + root.sendWinId() + } + if (mouse.button == Qt.RightButton) { + console.log("right mouse button"); + root.sendRightButtonClicked() + } + } + + onExited: { + console.log("leave qml.."); + root.sendMoveLeaved() + } + + //ljlj 只在光标进入后执行一次 + hoverEnabled: true + onEntered: { + console.log("enter qml.."); + console.debug("temp_width=",rect1.width); + console.debug("temp_height=",rect1.height); + console.debug("tmpWindowThumbnail=",tmpWindowThumbnail.width); + console.debug("tmpWindowThumbnail=",tmpWindowThumbnail.height); + root.sendMoveEntered() + } + + //ljlj 在光标进入和出去后,都会执行一次,执行两次 +// hoverEnabled: true +// onContainsMouseChanged: { +// // console.debug("ljlj onContainsMouseChanged"); +// console.log("ljlj enter qml.."); +// root.sendMoveEntered() +// } + } + } +} + diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/qml.qrc ukui-panel-4.0.0.0/plugin-taskbar/qml.qrc --- ukui-panel-3.14.0.1/plugin-taskbar/qml.qrc 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/qml.qrc 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qml/preview.qml</file> + </qresource> +</RCC> diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/quicklaunchaction.cpp ukui-panel-4.0.0.0/plugin-taskbar/quicklaunchaction.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/quicklaunchaction.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/quicklaunchaction.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -42,7 +42,6 @@ #include <QFileInfo> #include <QtX11Extras/QX11Info> #include <kstartupinfo.h> -#include <ukuisdk/kylin-com4cxx.h> //#define USE_STARTUP_INFO true @@ -105,31 +104,9 @@ } #endif -bool QuickLaunchAction::getCurrentMode() -{ - static QString projectCode = nullptr; - QString deviceName = "V10SP1"; - bool isTabletmode = false; - - if (nullptr == projectCode) { - QString arg = QString::fromStdString(KDKGetPrjCodeName()); - projectCode = arg.toLower(); - } - if (QString::compare(projectCode,deviceName) == 0) { - QString feature = QString::fromStdString(KDKGetOSRelease("V10SP1")); - if (feature == "3") { - isTabletmode = true; //XC - } else { - isTabletmode = false;//主线 - } - } - return isTabletmode; -} - /*解析Exec字段*/ void QuickLaunchAction::execAction(QString additionalAction) { - m_tabletMode = getCurrentMode(); UKUITaskBar *uqk = qobject_cast<UKUITaskBar*>(parent()); QString exec(data().toString()); bool showQMessage = false; @@ -163,13 +140,15 @@ KStartupInfo::sendStartup(*startInfoId, data); - if (m_tabletMode) { - QDBusInterface iface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", - QDBusConnection::sessionBus()); - iface.call("LaunchApp",exec); - } else { + QDBusInterface iface("com.kylin.AppManager", + "/com/kylin/AppManager", + "com.kylin.AppManager", + QDBusConnection::sessionBus()); + QDBusReply<bool> reply; + if (iface.isValid()) { + reply = iface.call("LaunchApp",exec); + } + if (!iface.isValid() || !reply.isValid() || !reply) { GDesktopAppInfo * appinfo=g_desktop_app_info_new_from_filename(xdg.fileName().toStdString().data()); needCleanup = !g_desktop_app_info_launch_uris_as_manager(appinfo, nullptr, nullptr, GSpawnFlags::G_SPAWN_DEFAULT, nullptr, nullptr, @@ -181,13 +160,15 @@ } } #else - if (m_tabletMode) { - QDBusInterface iface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", - QDBusConnection::sessionBus()); - iface.call("LaunchApp",exec); - } else { + QDBusInterface iface("com.kylin.AppManager", + "/com/kylin/AppManager", + "com.kylin.AppManager", + QDBusConnection::sessionBus()); + QDBusReply<bool> reply; + if (iface.isValid()) { + reply = iface.call("LaunchApp",exec); + } + if (!iface.isValid() || !reply.isValid() || !reply) { GDesktopAppInfo * appinfo=g_desktop_app_info_new_from_filename(xdg.fileName().toStdString().data()); if (!g_app_info_launch_uris(G_APP_INFO(appinfo),nullptr, nullptr, nullptr)) { showQMessage =true; diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/quicklaunchaction.h ukui-panel-4.0.0.0/plugin-taskbar/quicklaunchaction.h --- ukui-panel-3.14.0.1/plugin-taskbar/quicklaunchaction.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/quicklaunchaction.h 2023-05-22 14:06:12.000000000 +0800 @@ -71,7 +71,6 @@ bool m_valid; QList<QAction *> m_addtitionalActions; bool m_tabletMode; - bool getCurrentMode(); }; #endif diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/translation/taskbar_bo_CN.ts ukui-panel-4.0.0.0/plugin-taskbar/translation/taskbar_bo_CN.ts --- ukui-panel-3.14.0.1/plugin-taskbar/translation/taskbar_bo_CN.ts 2022-05-11 17:51:08.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/translation/taskbar_bo_CN.ts 2023-05-22 14:06:12.000000000 +0800 @@ -4,12 +4,12 @@ <context> <name>UKUITaskBar</name> <message> - <location filename="../ukuitaskbar.cpp" line="1082"/> + <location filename="../ukuitaskbar.cpp" line="1167"/> <source>Drop Error</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuitaskbar.cpp" line="1083"/> + <location filename="../ukuitaskbar.cpp" line="1168"/> <source>File/URL '%1' cannot be embedded into QuickLaunch for now</source> <translation type="unfinished"></translation> </message> @@ -17,102 +17,67 @@ <context> <name>UKUITaskButton</name> <message> - <location filename="../ukuitaskbutton.cpp" line="581"/> <source>Application</source> - <translation type="unfinished">ཉེར་སྤྱོད་བྱ་རིམ།</translation> + <translation type="obsolete">ཉེར་སྤྱོད་བྱ་རིམ།</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="614"/> - <source>To &Desktop</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="616"/> - <source>&All Desktops</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="623"/> <source>Desktop &%1</source> - <translation>ཅོག་ངོས་ཀྱི་རྣམ་པ།&%1</translation> + <translation type="vanished">ཅོག་ངོས་ཀྱི་རྣམ་པ།&%1</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="630"/> - <source>&To Current Desktop</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="638"/> <source>&Move</source> - <translation>སྤོ་བ།&M</translation> + <translation type="vanished">སྤོ་བ།&M</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="641"/> <source>Resi&ze</source> - <translation>ཆེ་ཆུང་སྒྱུར་བ།&z</translation> + <translation type="vanished">ཆེ་ཆུང་སྒྱུར་བ།&z</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="648"/> <source>Ma&ximize</source> - <translation>སྒེའུ་ཁུང་ཆེས་ཆེར་སྐྱེད།&x</translation> + <translation type="vanished">སྒེའུ་ཁུང་ཆེས་ཆེར་སྐྱེད།&x</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="654"/> <source>Maximize vertically</source> - <translation>སྒེའུ་ཁུང་དྲང་འཕྱང་དུ་ཆེས་ཆེར་སྐྱེད།</translation> + <translation type="vanished">སྒེའུ་ཁུང་དྲང་འཕྱང་དུ་ཆེས་ཆེར་སྐྱེད།</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="659"/> <source>Maximize horizontally</source> - <translation>སྒེའུ་ཁུང་ཆུ་སྙོམས་སུ་ཆེས་ཆེར་སྐྱེད།</translation> + <translation type="vanished">སྒེའུ་ཁུང་ཆུ་སྙོམས་སུ་ཆེས་ཆེར་སྐྱེད།</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="665"/> <source>&Restore</source> - <translation>ཕྱིར་ལོག&R</translation> + <translation type="vanished">ཕྱིར་ལོག&R</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="669"/> <source>Mi&nimize</source> - <translation>སྒེའུ་ཁུང་ཆུང་སྒྱུར།&n</translation> + <translation type="vanished">སྒེའུ་ཁུང་ཆུང་སྒྱུར།&n</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="674"/> <source>Roll down</source> - <translation>མར་དུ་འདེད།</translation> + <translation type="vanished">མར་དུ་འདེད།</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="678"/> <source>Roll up</source> - <translation>ཡར་དུ་འདེད།་</translation> + <translation type="vanished">ཡར་དུ་འདེད།་</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="686"/> <source>&Layer</source> - <translation>རིས་རིམ།&L</translation> + <translation type="vanished">རིས་རིམ།&L</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="688"/> <source>Always on &top</source> - <translation>ནམ་ཡང་རྩེ་མོར་གནས་པ།&t</translation> + <translation type="vanished">ནམ་ཡང་རྩེ་མོར་གནས་པ།&t</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="694"/> <source>&Normal</source> - <translation>དཀྱུས་མ།&N</translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="700"/> - <source>Always on &bottom</source> - <translation type="unfinished"></translation> + <translation type="vanished">དཀྱུས་མ།&N</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="708"/> <source>&Close</source> - <translation>ཁ་རྒྱག་པ།&C</translation> + <translation type="vanished">ཁ་རྒྱག་པ།&C</translation> </message> <message> - <location filename="../ukuitaskbutton.cpp" line="868"/> + <location filename="../ukuitaskbutton.cpp" line="480"/> <source>delete from quicklaunch</source> <translation>ལས་འགན་སྡེ་ནས་གཏན་འཇགས་འདོར་བ།</translation> </message> @@ -120,22 +85,22 @@ <context> <name>UKUITaskGroup</name> <message> - <location filename="../ukuitaskgroup.cpp" line="254"/> + <location filename="../ukuitaskgroup.cpp" line="148"/> <source>Group</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuitaskgroup.cpp" line="261"/> + <location filename="../ukuitaskgroup.cpp" line="163"/> <source>delete from taskbar</source> <translation>ལས་འགན་སྡེ་ནས་གཏན་འཇགས་འདོར་བ།</translation> </message> <message> - <location filename="../ukuitaskgroup.cpp" line="263"/> + <location filename="../ukuitaskgroup.cpp" line="166"/> <source>add to taskbar</source> <translation>ལས་འགན་སྡེ་རུ་ཁ་སྣོན་བྱེད་པ།</translation> </message> <message> - <location filename="../ukuitaskgroup.cpp" line="271"/> + <location filename="../ukuitaskgroup.cpp" line="136"/> <source>close</source> <translation>ཁ་རྒྱག</translation> </message> @@ -143,37 +108,37 @@ <context> <name>UKUITaskWidget</name> <message> - <location filename="../ukuitaskwidget.cpp" line="443"/> + <location filename="../ukuitaskwidget.cpp" line="328"/> <source>Widget</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="446"/> + <location filename="../ukuitaskwidget.cpp" line="331"/> <source>close</source> <translation>ཁ་རྒྱག</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="447"/> + <location filename="../ukuitaskwidget.cpp" line="332"/> <source>restore</source> <translation>སླར་གསོ།</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="449"/> + <location filename="../ukuitaskwidget.cpp" line="334"/> <source>maximaze</source> <translation>ཆེ་སྒྱུར།</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="452"/> + <location filename="../ukuitaskwidget.cpp" line="337"/> <source>minimize</source> <translation>ཆུང་སྒྱུར།</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="453"/> + <location filename="../ukuitaskwidget.cpp" line="338"/> <source>above</source> <translation>ཡན་ཆད།</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="454"/> + <location filename="../ukuitaskwidget.cpp" line="339"/> <source>clear</source> <translation>གཙང་སེལ།</translation> </message> diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/translation/taskbar_zh_CN.ts ukui-panel-4.0.0.0/plugin-taskbar/translation/taskbar_zh_CN.ts --- ukui-panel-3.14.0.1/plugin-taskbar/translation/taskbar_zh_CN.ts 2022-05-11 17:51:08.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/translation/taskbar_zh_CN.ts 2023-05-22 14:06:12.000000000 +0800 @@ -4,12 +4,12 @@ <context> <name>UKUITaskBar</name> <message> - <location filename="../ukuitaskbar.cpp" line="1067"/> + <location filename="../ukuitaskbar.cpp" line="1167"/> <source>Drop Error</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuitaskbar.cpp" line="1068"/> + <location filename="../ukuitaskbar.cpp" line="1168"/> <source>File/URL '%1' cannot be embedded into QuickLaunch for now</source> <translation type="unfinished"></translation> </message> @@ -17,102 +17,7 @@ <context> <name>UKUITaskButton</name> <message> - <location filename="../ukuitaskbutton.cpp" line="583"/> - <source>Application</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="617"/> - <source>To &Desktop</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="619"/> - <source>&All Desktops</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="627"/> - <source>Desktop &%1</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="634"/> - <source>&To Current Desktop</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="642"/> - <source>&Move</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="645"/> - <source>Resi&ze</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="652"/> - <source>Ma&ximize</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="659"/> - <source>Maximize vertically</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="664"/> - <source>Maximize horizontally</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="670"/> - <source>&Restore</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="674"/> - <source>Mi&nimize</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="680"/> - <source>Roll down</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="686"/> - <source>Roll up</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="694"/> - <source>&Layer</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="696"/> - <source>Always on &top</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="702"/> - <source>&Normal</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="708"/> - <source>Always on &bottom</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="716"/> - <source>&Close</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../ukuitaskbutton.cpp" line="878"/> + <location filename="../ukuitaskbutton.cpp" line="480"/> <source>delete from quicklaunch</source> <translation type="unfinished">从任务栏取消固定</translation> </message> @@ -120,60 +25,60 @@ <context> <name>UKUITaskGroup</name> <message> - <location filename="../ukuitaskgroup.cpp" line="255"/> + <location filename="../ukuitaskgroup.cpp" line="148"/> <source>Group</source> <translation>组</translation> </message> <message> - <location filename="../ukuitaskgroup.cpp" line="262"/> + <location filename="../ukuitaskgroup.cpp" line="163"/> <source>delete from taskbar</source> <translation>从任务栏取消固定</translation> </message> <message> - <location filename="../ukuitaskgroup.cpp" line="264"/> + <location filename="../ukuitaskgroup.cpp" line="166"/> <source>add to taskbar</source> - <translation>添加到任务栏</translation> + <translation>固定到任务栏</translation> </message> <message> - <location filename="../ukuitaskgroup.cpp" line="269"/> + <location filename="../ukuitaskgroup.cpp" line="136"/> <source>close</source> - <translation>关闭</translation> + <translation>退出</translation> </message> </context> <context> <name>UKUITaskWidget</name> <message> - <location filename="../ukuitaskwidget.cpp" line="451"/> + <location filename="../ukuitaskwidget.cpp" line="328"/> <source>Widget</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="454"/> + <location filename="../ukuitaskwidget.cpp" line="331"/> <source>close</source> - <translation>关闭</translation> + <translation>退出</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="455"/> + <location filename="../ukuitaskwidget.cpp" line="332"/> <source>restore</source> <translation>恢复</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="457"/> + <location filename="../ukuitaskwidget.cpp" line="334"/> <source>maximaze</source> <translation>最大化</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="460"/> + <location filename="../ukuitaskwidget.cpp" line="337"/> <source>minimize</source> <translation>最小化</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="461"/> + <location filename="../ukuitaskwidget.cpp" line="338"/> <source>above</source> <translation>置顶</translation> </message> <message> - <location filename="../ukuitaskwidget.cpp" line="462"/> + <location filename="../ukuitaskwidget.cpp" line="339"/> <source>clear</source> <translation>取消置顶</translation> </message> diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuigrouppopup.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuigrouppopup.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuigrouppopup.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuigrouppopup.cpp 2023-05-23 15:58:00.000000000 +0800 @@ -38,6 +38,68 @@ #include <QApplication> #include <QScreen> +#include <QtX11Extras/QX11Info> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <KWindowEffects> +#include "common/common.h" + +#define OPENGL "gl2" +#define XRENDER "xrender" +#define UKUI_KWIN_SERVICE "org.ukui.KWin" +#define UKUI_KWIN_PATH "/Compositor" +#define UKUI_KWIN_INTERFACE "org.kde.kwin.Compositing" +#define COMPOSITING_TYPE "compositingType" + +QPixmap qimageFromXImage(XImage* ximage) +{ + QImage::Format format = QImage::Format_ARGB32_Premultiplied; + if (ximage->depth == 24) { + format = QImage::Format_RGB32; + } else if (ximage->depth == 16) { + format = QImage::Format_RGB16; + } + + QImage image = QImage(reinterpret_cast<uchar*>(ximage->data), + ximage->width, ximage->height, + ximage->bytes_per_line, format).copy(); + + // 大端还是小端? + if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && ximage->byte_order == MSBFirst) + || (QSysInfo::ByteOrder == QSysInfo::BigEndian && ximage->byte_order == LSBFirst)) { + + for (int i = 0; i < image.height(); i++) { + if (ximage->depth == 16) { + ushort* p = reinterpret_cast<ushort*>(image.scanLine(i)); + ushort* end = p + image.width(); + while (p < end) { + *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff); + p++; + } + } else { + uint* p = reinterpret_cast<uint*>(image.scanLine(i)); + uint* end = p + image.width(); + while (p < end) { + *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000) + | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff); + p++; + } + } + } + } + + // 修复alpha通道 + if (format == QImage::Format_RGB32) { + QRgb* p = reinterpret_cast<QRgb*>(image.bits()); + for (int y = 0; y < ximage->height; ++y) { + for (int x = 0; x < ximage->width; ++x) + p[x] |= 0xff000000; + p += ximage->bytes_per_line / 4; + } + } + return QPixmap::fromImage(image); +} + /************************************************ this class is just a container of window buttons the main purpose is showing window buttons in @@ -53,7 +115,8 @@ setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip); setAttribute(Qt::WA_AlwaysShowToolTips); setAttribute(Qt::WA_TranslucentBackground); - setProperty("useSystemStyleBlur", true); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setSizePolicy(sizePolicy); setLayout(new QHBoxLayout); layout()->setSpacing(3); @@ -65,60 +128,40 @@ m_closeTimer.setInterval(400); setMaximumWidth(QApplication::screens().at(0)->size().width()); setMaximumHeight(QApplication::screens().at(0)->size().height()); -} - -UKUIGroupPopup::~UKUIGroupPopup() -{ -} -void UKUIGroupPopup::dropEvent(QDropEvent *event) -{ - qlonglong temp; - QDataStream stream(event->mimeData()->data(UKUITaskButton::mimeDataFormat())); - stream >> temp; - WId window = (WId) temp; - - UKUITaskButton *button = nullptr; - int oldIndex(0); - // get current position of the button being dragged - for (int i = 0; i < layout()->count(); i++) { - UKUITaskButton *b = qobject_cast<UKUITaskButton*>(layout()->itemAt(i)->widget()); - if (b && b->windowId() == window) { - button = b; - oldIndex = i; - break; + m_interface = new QDBusInterface(UKUI_KWIN_SERVICE, + UKUI_KWIN_PATH, + UKUI_KWIN_INTERFACE, + QDBusConnection::sessionBus()); + if (m_interface->isValid()) { + QString compositingType = m_interface->property(COMPOSITING_TYPE).toString(); + if (compositingType == OPENGL) { + m_isXrender = false; + } else if (compositingType == XRENDER) { + m_isXrender = true; } } - if (button == nullptr) { +// //监听主题改变,更新图标 + const QByteArray id_Theme(ORG_UKUI_STYLE); + if (QGSettings::isSchemaInstalled(id_Theme)) { + m_changeTheme = new QGSettings(id_Theme); + } else { + qWarning() << "Icon Theme GSettings isn't Installed"; return; } - - int newIndex = -1; - // find the new position to place it in - for (int i = 0; i < oldIndex && newIndex == -1; i++) { - QWidget *w = layout()->itemAt(i)->widget(); - if (w && w->pos().y() + w->height() / 2 > event->pos().y()) { - newIndex = i; - } - } - const int size = layout()->count(); - for (int i = size - 1; i > oldIndex && newIndex == -1; i--) { - QWidget *w = layout()->itemAt(i)->widget(); - if (w && w->pos().y() + w->height() / 2 < event->pos().y()) { - newIndex = i; + connect(m_changeTheme, &QGSettings::changed, this, [=] (const QString &key) { + if (key == STYLE_NAME_KEY_ICONTHEME) { + for (auto it= m_widgetHash.begin(); it != m_widgetHash.end();it++) { + UKUITaskWidget *taskwidget = it.value(); + taskwidget->updateSdkIcon(); + } } - } - - if (newIndex == -1 || newIndex == oldIndex) { - return; - } - - QVBoxLayout * l = qobject_cast<QVBoxLayout *>(layout()); - l->takeAt(oldIndex); - l->insertWidget(newIndex, button); - l->invalidate(); + }); +} +UKUIGroupPopup::~UKUIGroupPopup() +{ } void UKUIGroupPopup::dragEnterEvent(QDragEnterEvent *event) @@ -165,7 +208,12 @@ if (m_closeTimer.isActive()) { m_closeTimer.stop(); } + if (this->geometry().contains(QCursor::pos())) { + return; + } close(); + sendCloseSigToKWin(); + } void UKUIGroupPopup::mousePressEvent(QMouseEvent *event) @@ -188,10 +236,10 @@ void UKUIGroupPopup::hide(bool fast) { - if (fast) { + if (fast && !this->geometry().contains(QCursor::pos())) { close(); } - else { + else if (!this->geometry().contains(QCursor::pos())) { m_closeTimer.start(); } } @@ -202,6 +250,19 @@ QFrame::show(); } +void UKUIGroupPopup::setKeepShow(bool flag) +{ + isKeepShow = true; +} + +void UKUIGroupPopup::setKeepLeave(bool flag) +{ + if (!this->geometry().contains(QCursor::pos())) { + isKeepShow = false; + m_closeTimer.start(); + } +} + void UKUIGroupPopup::closeTimerSlot() { bool button_has_dnd_hover = false; @@ -213,7 +274,479 @@ break; } } - if (!button_has_dnd_hover) { + if (!button_has_dnd_hover && !this->geometry().contains(QCursor::pos())) { close(); } + sendCloseSigToKWin(); +} + +void UKUIGroupPopup::sendCloseSigToKWin() +{ + QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "panelNotUpdateLayer"); + QList<QVariant> args; + bool flag = true; + args.append(flag); + message.setArguments(args); + QDBusConnection::sessionBus().send(message); +} + +void UKUIGroupPopup::addWindow(const WindowId& id,UKUITaskBar *bar) +{ + qint32 window = id.toInt(); + UKUITaskWidget *taskwidget = new UKUITaskWidget(window, bar, this); + m_useOpenGL = taskwidget->canUseOpenGL(); + m_widgetHash.insert(window,taskwidget); + taskwidget->setFixedSize(PREVIEW_WINDOW_WIDTH, PREVIEW_WINDOW_HEIGHT); + if (m_group->plugin()->panel()->isHorizontal()) { + m_allWidgetWidth += PREVIEW_WINDOW_WIDTH; + this->setFixedSize(QSize(m_allWidgetWidth, this->height())); + } else { + m_allWidgetHeight += PREVIEW_WINDOW_HEIGHT; + this->setFixedSize(QSize(this->width(), m_allWidgetHeight)); + } + + connect(taskwidget, &UKUITaskWidget::windowActived, [this]{ + close(); + }); + //this->addTaskWidget(taskwidget); + +} + +void UKUIGroupPopup::onWindowRemoved(const WindowId& id) +{ + qint32 window = id.toInt(); + UKUITaskWidget *taskwidget = m_widgetHash.value(window); + QSize widgetsize = taskwidget->size(); + m_widgetHash.remove(window); + this->removeWidget(taskwidget); + taskwidget->deleteLater(); + + if(m_group->plugin()->panel()->isHorizontal()) { + m_allWidgetWidth -= widgetsize.width(); + } else { + m_allWidgetHeight -= widgetsize.height(); + } + + if(m_isShowByList) { + int winWidth = LIST_WINDOW_WIDTH; + int winheight = LIST_WINDOW_HEIGHT; + this->setFixedSize(winWidth, winheight * m_group->visibleSdkButtonsCount()); + caculatePopupWidgetPos(); + } else { + if(m_group->plugin()->panel()->isHorizontal()) { + this->setFixedSize(QSize(m_allWidgetWidth, this->height())); + } else { + this->setFixedSize(QSize(this->width(), m_allWidgetHeight)); + } + } +} + +void UKUIGroupPopup::onWindowChanged(const WindowId& id) +{ +// if (prop.testFlag(NET::WMIcon) || prop2.testFlag(NET::WM2WindowClass)){ + for (auto it= m_widgetHash.begin(); it != m_widgetHash.end();it++) { + UKUITaskWidget *taskwidget = it.value(); + taskwidget->updateSdkIcon(); + } +// } + +} + +void UKUIGroupPopup::caculateTaskWidget() +{ + int winWidth = PREVIEW_WINDOW_WIDTH; + int winHeight = PREVIEW_WINDOW_HEIGHT; + int totalLenth = 0; + + int title_width = 0; + + /*caculate each taskwidget-image's width*/ + XImage *img = NULL; + Display *display = NULL; + QPixmap thumbnail; + XWindowAttributes attr; + + for (UKUISdkTaskWidgetHash::const_iterator it = m_widgetHash.begin(); it != m_widgetHash.end(); it++) { + bool visible = KWindowInfo(it.key(), NET::WMDesktop).isOnDesktop(KWindowSystem::currentDesktop()); + UKUITaskWidget *taskwidget = it.value(); + taskwidget->setVisible(visible); + taskwidget->setParent(this); + connect(taskwidget, &UKUITaskWidget::closeSigtoPop, [this] { this->pubcloseWindowDelay(); }); + //connect(taskwidget, &UKUITaskWidget::closeSigtoGroup, [this] { closeGroup(); }); + taskwidget->addThumbNail(); + display = XOpenDisplay(nullptr); + XGetWindowAttributes(display, it.key(), &attr); + img = XGetImage(display, it.key(), 0, 0, attr.width, attr.height, 0xffffffff,ZPixmap); + float imgWidth = 0; + float imgHeight = 0; + if (m_group->plugin()->panel()->isHorizontal()) { + imgWidth = (float)attr.width / (float)attr.height * winHeight; + imgHeight = winHeight; + if (imgWidth > PREVIEW_WINDOW_WIDTH) { + imgWidth = PREVIEW_WINDOW_WIDTH; + } + if(taskwidget->isVisibleTo(this)) { + totalLenth += (int)imgWidth; + } + taskwidget->setThumbMaximumSize(MAX_SIZE_OF_Thumb); + taskwidget->setThumbScale(true); + } else { + imgWidth = winWidth; + imgHeight = (float)attr.height / (float)attr.width * winWidth; + if ((int)imgHeight > PREVIEW_WINDOW_HEIGHT) { + imgHeight = PREVIEW_WINDOW_HEIGHT; + } + if(taskwidget->isVisibleTo(this)) { + totalLenth += (int)imgHeight; + } + taskwidget->setThumbMaximumSize(MAX_SIZE_OF_Thumb); + taskwidget->setThumbScale(true); + } + if (img) { + thumbnail = qimageFromXImage(img).scaled((int)imgWidth, (int)imgHeight, Qt::KeepAspectRatio,Qt::SmoothTransformation); + } else { + qDebug()<<"can not catch picture"; + QPixmap pxmp; + if (pxmp.load(QString("/tmp/%1.png").arg(it.key()))) { + thumbnail = pxmp.scaled((int)imgWidth, (int)imgHeight, Qt::KeepAspectRatio,Qt::SmoothTransformation); + } else { + thumbnail = QPixmap((int)imgWidth, (int)imgHeight); + thumbnail.fill(QColor(0, 0, 0, 127)); + } + } + taskwidget->setThumbNail(thumbnail); + taskwidget->updateTitle(); + taskwidget->setFixedSize((int)imgWidth, (int)imgHeight); + title_width = taskwidget->width() - 75; + taskwidget->setTitleFixedWidth(title_width); + m_widget->layout()->setContentsMargins(0,0,0,0); + m_widget->layout()->setSpacing(8); + if(taskwidget->isVisibleTo(this)) { + m_widget->layout()->addWidget(taskwidget); + } + if (img) { + XDestroyImage(img); + } + if (display) { + XCloseDisplay(display); + } + } + + if (m_group->plugin()->panel()->isHorizontal()) { + m_allWidgetWidth = totalLenth; + this->setFixedSize(QSize(totalLenth, winHeight)); + } else { + m_allWidgetHeight = totalLenth; + this->setFixedSize(QSize(winWidth, totalLenth)); + } +} + +void UKUIGroupPopup::caculateQmlWidget() +{ + int winWidth = PREVIEW_WINDOW_WIDTH; + int winHeight = PREVIEW_WINDOW_HEIGHT; + int titleHeight = PREVIEW_TITLE_HEIGHT; + int totalLenth = 0; + + int title_width = 0; + + for (UKUISdkTaskWidgetHash::const_iterator it = m_widgetHash.begin(); it != m_widgetHash.end(); it++) { + bool visible = KWindowInfo(it.key(), NET::WMDesktop).isOnDesktop(KWindowSystem::currentDesktop()); + UKUITaskWidget *taskwidget = it.value(); + taskwidget->setVisible(visible); + taskwidget->setParent(this); + connect(taskwidget, &UKUITaskWidget::closeSigtoPop, [this] { this->pubcloseWindowDelay(); }); + connect(taskwidget, SIGNAL(signalKeepShow(bool)), this, SLOT(setKeepShow(bool))); + connect(taskwidget, SIGNAL(signalKeepLeave(bool)), this, SLOT(setKeepLeave(bool))); + float qmlWidth = 0; + float qmlHeight = 0; + KWindowInfo info(it.key(), NET::WMGeometry | NET::WMName); + int appwidth = info.geometry().width(); + int appheight =info.geometry().height(); + qDebug()<<"appwidth:"<<appwidth; + qDebug()<<"appheight:"<<appheight; + if (m_group->plugin()->panel()->isHorizontal()) { + qmlHeight = winHeight - titleHeight - PREVIEW_SPACEING * 2; + qmlWidth = (float)appwidth / (float)appheight * qmlHeight; + if (qmlWidth > PREVIEW_WINDOW_WIDTH) { + qmlWidth = PREVIEW_WINDOW_WIDTH; + } + } else { + qmlWidth = winWidth - PREVIEW_SPACEING * 2; + qmlHeight = (float)appheight / (float)appwidth * qmlWidth; + if ((int)qmlHeight > PREVIEW_WINDOW_HEIGHT) { + qmlHeight = PREVIEW_WINDOW_HEIGHT; + } + } + qDebug()<<"qmlWidth:"<<qmlWidth; + qDebug()<<"qmlHeight:"<<qmlHeight; + + taskwidget->setLiveThumbNail((int)qmlWidth , (int)qmlHeight); + taskwidget->updateTitle(); + if (m_group->plugin()->panel()->isHorizontal()) { + taskwidget->setFixedSize(qmlWidth + PREVIEW_SPACEING * 2, winHeight); + if(taskwidget->isVisibleTo(this)) { + totalLenth += taskwidget->width(); + } + } else { + taskwidget->setFixedSize(winWidth, qmlHeight + titleHeight + PREVIEW_SPACEING * 2); + if(taskwidget->isVisibleTo(this)) { + totalLenth += taskwidget->height(); + } + } + title_width = qmlWidth - 64; + taskwidget->setTitleFixedWidth(title_width); + m_widget->layout()->setContentsMargins(0,0,0,0); + m_widget->layout()->setSpacing(8); + if (taskwidget->isVisibleTo(this)) { + m_widget->layout()->addWidget(taskwidget); + } + } + int space = (m_widget->layout()->count() - 1) * PREVIEW_SPACEING; + if (m_group->plugin()->panel()->isHorizontal()) { + m_allWidgetWidth = totalLenth + space; + this->setFixedSize(QSize(totalLenth + space, winHeight - PREVIEW_SPACEING)); + } else { + m_allWidgetHeight = totalLenth; + this->setFixedSize(QSize(winWidth, totalLenth - PREVIEW_SPACEING)); + } +} + +void UKUIGroupPopup::showPreviewMode() +{ + if (m_group->plugin()->panel()->isHorizontal()) { + if (m_allWidgetWidth <= QApplication::screens().at(0)->size().width() && this->width() != PREVIEW_WINDOW_HEIGHT) { + //showAllWindowByThumbnail(); + showAllWindowByList(); + } else { + showAllWindowByList(); + } + } else { + if (m_allWidgetHeight <= QApplication::screens().at(0)->size().height()) { + //showAllWindowByThumbnail(); + showAllWindowByList(); + } else { + showAllWindowByList(); + } + } + +} + +void UKUIGroupPopup::showAllWindowByList() +{ + m_isShowByList = true; + int winWidth = LIST_WINDOW_WIDTH; + int winheight = LIST_WINDOW_HEIGHT; + int popWindowheight = (winheight) * (m_group->visibleSdkButtonsCount()); + int screenAvailabelHeight = QApplication::screens().at(0)->size().height() - m_group->plugin()->panel()->panelSize(); + if (!m_group->plugin()->panel()->isHorizontal()) { + screenAvailabelHeight = QApplication::screens().at(0)->size().height();//panel is vect + } + if (this->layout()->count() > 0) { + removeSrollWidget(); + } + m_scrollArea = new QScrollArea(this); + m_scrollArea->setWidgetResizable(true); + m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + this->layout()->addWidget(m_scrollArea); + int num=0; + for (UKUISdkTaskWidgetHash::const_iterator it = m_widgetHash.begin();it != m_widgetHash.end();it++) + num++; + this->setFixedSize(winWidth, (popWindowheight < screenAvailabelHeight? popWindowheight : screenAvailabelHeight)+8+num*8 ); + //this->setFixedSize(winWidth, popWindowheight < screenAvailabelHeight? popWindowheight : screenAvailabelHeight); + m_widget = new QWidget(this); + m_widget->setAttribute(Qt::WA_TranslucentBackground); + m_widget->setLayout(new QVBoxLayout); + m_widget->layout()->setSpacing(5); + m_scrollArea->setWidget(m_widget); + /*begin catch preview picture*/ + for (UKUISdkTaskWidgetHash::const_iterator it = m_widgetHash.begin();it != m_widgetHash.end();it++) { + bool visible = KWindowInfo(it.key(), NET::WMDesktop).isOnDesktop(KWindowSystem::currentDesktop()); + UKUITaskWidget *taskwidget = it.value(); + taskwidget->setVisible(visible); + taskwidget->clearMask(); + taskwidget->setTitleFixedWidth(m_widget->width()); + taskwidget->updateTitle(); + taskwidget->setParent(m_scrollArea); + taskwidget->removeLiveThumbNail(); + taskwidget->removeThumbNail(); + taskwidget->adjustSize(); + taskwidget->setFixedHeight(winheight); + + connect(taskwidget, &UKUITaskWidget::closeSigtoPop, [this] { this->pubcloseWindowDelay(); }); + //connect(taskwidget, &UKUITaskWidget::closeSigtoGroup, [this] { closeGroup(); }); + if (taskwidget->isVisibleTo(this)) { + m_widget->layout()->addWidget(taskwidget); + } + } + /*end*/ + m_group->plugin()->willShowWindow(this); + caculatePopupWidgetPos(); + this->setStyle(new CustomStyle()); + this->setFixedWidth(winWidth); + m_scrollArea->setAttribute(Qt::WA_TranslucentBackground); + m_scrollArea->setFrameShape(QFrame::NoFrame); + m_scrollArea->setProperty("drawScrollBarGroove",false); + m_scrollArea->verticalScrollBar()->setProperty("drawScrollBarGroove",false); + m_scrollArea->show(); + this->show(); +} + +void UKUIGroupPopup::showAllWindowByThumbnail() +{ + m_isShowByList = false; + + if (this->layout()->count() > 0) { + removeWidget(); + } + m_widget = new QWidget(this); + m_widget->setAttribute(Qt::WA_TranslucentBackground); + if (m_group->plugin()->panel()->isHorizontal()) { + m_widget->setLayout(new QHBoxLayout); + } else { + m_widget->setLayout(new QVBoxLayout); + } + + if (m_useOpenGL && !m_isXrender) { + caculateQmlWidget(); + } else { + caculateTaskWidget(); + } + + m_group->plugin()->willShowWindow(this); + this->layout()->addWidget(m_widget); + //set preview window position + caculatePopupWidgetPos(); + if (!this->isVisible()) { + this->show(); + } + setRegionBlur(); +} + +void UKUIGroupPopup::setRegionBlur() +{ + QRect rectall[m_widgetHash.size()]; + QRegion regionall; + for (int i = 0; i < m_widget->layout()->count(); i++) { + rectall[i] = m_widget->layout()->itemAt(i)->geometry(); + + QPainterPath path; + path.addRoundRect(rectall[i].x() + 2 , rectall[i].y() + 2, rectall[i].width() - 4, rectall[i].height() - 4, 12, 12); + QPolygon polygon = path.toFillPolygon().toPolygon();//获得这个路径上的所有的点 + QRegion region(polygon);//根据这些点构造这个区域 + regionall = regionall.united(region); + } + KWindowEffects::enableBlurBehind(this->winId(), true, regionall); +} + +void UKUIGroupPopup::removeWidget() +{ + if (m_scrollArea) { + removeSrollWidget(); + } + if (m_widget) { + this->layout()->removeWidget(m_widget); + QHBoxLayout *hLayout = dynamic_cast<QHBoxLayout*>(m_widget->layout()); + QVBoxLayout *vLayout = dynamic_cast<QVBoxLayout*>(m_widget->layout()); + if (hLayout != NULL) { + hLayout->deleteLater(); + hLayout = NULL; + } + if (vLayout != NULL) { + vLayout->deleteLater(); + vLayout = NULL; + } + //m_widget->setParent(NULL); + m_widget->deleteLater(); + m_widget = NULL; + } +} + + +void UKUIGroupPopup::removeSrollWidget() +{ + if (m_scrollArea) { + this->layout()->removeWidget(m_scrollArea); + this->layout()->removeWidget(m_scrollArea->takeWidget()); + } + if (m_widget) { + this->layout()->removeWidget(m_widget); + QHBoxLayout *hLayout = dynamic_cast<QHBoxLayout*>(m_widget->layout()); + QVBoxLayout *vLayout = dynamic_cast<QVBoxLayout*>(m_widget->layout()); + if (hLayout != NULL) { + hLayout->deleteLater(); + hLayout = NULL; + } + if (vLayout != NULL) { + vLayout->deleteLater(); + vLayout = NULL; + } + //m_widget->setParent(NULL); + m_widget->deleteLater(); + m_widget = NULL; + } + if (m_scrollArea) { + m_scrollArea->deleteLater(); + m_scrollArea = NULL; + } +} + +void UKUIGroupPopup::caculatePopupWidgetPos() +{ + int previewPosition = 0; + + //set preview window position + if (m_isShowByList) { + int winWidth = 246; + if (m_group->plugin()->panel()->isHorizontal()) { + previewPosition = m_group->plugin()->panel()->panelSize()/2 - winWidth/2; + this->setGeometry(calculatePopupWindowPos(m_group->mapToGlobal(QPoint(previewPosition,0)), this->size())); + } else { + previewPosition = m_group->plugin()->panel()->panelSize()/2 - winWidth/2; + this->setGeometry(calculatePopupWindowPos(m_group->mapToGlobal(QPoint(0,previewPosition)), this->size())); + } + } else { + if (m_group->plugin()->panel()->isHorizontal()) { + if (this->size().width()/2 < QCursor::pos().x()) { + previewPosition = 0 - this->size().width()/2 + m_group->plugin()->panel()->panelSize()/2; + } else { + previewPosition = 0 -(QCursor::pos().x() + m_group->plugin()->panel()->panelSize()/2); + } + this->setGeometry(calculatePopupWindowPos(m_group->mapToGlobal(QPoint(previewPosition,0)), this->size())); + } else { + if (this->size().height()/2 < QCursor::pos().y()) { + previewPosition = 0 - this->size().height()/2 + m_group->plugin()->panel()->panelSize()/2; + } else { + previewPosition = 0 -(QCursor::pos().y() + m_group->plugin()->panel()->panelSize()/2); + } + this->setGeometry(calculatePopupWindowPos(m_group->mapToGlobal(QPoint(0,previewPosition)), this->size())); + } + } +} + +QRect UKUIGroupPopup::calculatePopupWindowPos(QPoint const & absolutePos, QSize const & windowSize) const +{ + int margin = 8; + QRect rect = m_group->plugin()->panel()->calculatePopupWindowPos(absolutePos, windowSize); + int x = rect.x(), y = rect.y(); + switch (m_group->plugin()->panel()->position()) + { + case IUKUIPanel::PositionTop: + y = rect.y() + margin; + break; + + case IUKUIPanel::PositionBottom: + y = rect.y() - margin; + break; + + case IUKUIPanel::PositionLeft: + x = rect.x() + margin; + break; + + case IUKUIPanel::PositionRight: + x = rect.x() - margin; + break; + } + QRect res(QPoint(x, y), windowSize); + return res; } diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuigrouppopup.h ukui-panel-4.0.0.0/plugin-taskbar/ukuigrouppopup.h --- ukui-panel-3.14.0.1/plugin-taskbar/ukuigrouppopup.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuigrouppopup.h 2023-05-22 14:06:12.000000000 +0800 @@ -35,11 +35,23 @@ #include <QLayout> #include <QTimer> #include <QEvent> +#include <QDBusInterface> +#include <QDBusReply> #include "ukuitaskbutton.h" #include "ukuitaskgroup.h" +#include "ukuitaskwidget.h" #include "ukuitaskbar.h" +#define PREVIEW_WINDOW_WIDTH 420 +#define PREVIEW_WINDOW_HEIGHT 264 +#define PREVIEW_TITLE_HEIGHT 46 +#define PREVIEW_SPACEING 8 +#define LIST_WINDOW_WIDTH 246 +#define LIST_WINDOW_HEIGHT 46 + +#define PANEL_CONFIG_PATH "/usr/share/ukui/ukui-panel/panel-commission.ini" + class UKUIGroupPopup: public QFrame { Q_OBJECT @@ -52,32 +64,61 @@ void show(); // Layout - int indexOf(UKUITaskButton *button) { return layout()->indexOf(button); } - int count() { return layout()->count(); } - QLayoutItem * itemAt(int i) { return layout()->itemAt(i); } - int spacing() { return layout()->spacing(); } - void addButton(UKUITaskButton* button) { layout()->addWidget(button); } void removeWidget(QWidget *button) { layout()->removeWidget(button); } void pubcloseWindowDelay() { closeWindowDelay(); } + + void addWindow(const WindowId& id,UKUITaskBar *bar); + void onWindowRemoved(const WindowId& id); + void onWindowChanged(const WindowId& id); + + void caculateTaskWidget(); + void caculateQmlWidget(); + void showPreviewMode(); + void showAllWindowByList();//when number of window is more than 30,need show all window of app by a list + void showAllWindowByThumbnail();//when number of window is no more than 30,need show all window of app by a thumbnail + void removeWidget(); + void removeSrollWidget(); + void caculatePopupWidgetPos(); + QRect calculatePopupWindowPos(QPoint const & absolutePos, QSize const & windowSize) const; + void setRegionBlur(); + protected: void dragEnterEvent(QDragEnterEvent * event); void dragLeaveEvent(QDragLeaveEvent *event); - void dropEvent(QDropEvent * event); void leaveEvent(QEvent * event); void enterEvent(QEvent * event); void paintEvent(QPaintEvent * event); void mousePressEvent(QMouseEvent *event); void closeTimerSlot(); + void sendCloseSigToKWin(); private: UKUITaskGroup *m_group; QTimer m_closeTimer; - bool m_rightclick; + bool m_rightclick = false; + bool isKeepShow = false; + bool m_isShowByList = false; + bool m_useOpenGL = true; + bool m_isXrender = false; + + UKUISdkTaskWidgetHash m_widgetHash; + int m_allWidgetWidth = 0; + int m_allWidgetHeight = 0; + QWidget *m_widget; + QScrollArea *m_scrollArea = NULL; + + QDBusInterface *m_interface; + QGSettings *m_changeTheme; + private slots: void killTimerDelay(); void closeWindowDelay(); + + void setKeepShow(bool flag); + void setKeepLeave(bool flag); + }; #endif // UKUITASKPOPUP_H diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbar.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbar.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbar.cpp 2022-05-11 17:56:24.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbar.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -44,13 +44,13 @@ #include <QMessageBox> #include <QPainterPath> #include <unistd.h> +#include <sys/utsname.h> #include "../panel/common/ukuigridlayout.h" #include "ukuitaskbar.h" #include "ukuitaskgroup.h" #include "quicklaunchaction.h" #define PANEL_SETTINGS "org.ukui.panel.settings" -#define PANEL_LINES "panellines" #define PANEL_CONFIG_PATH "/usr/share/ukui/ukui-panel/panel-commission.ini" #define PANEL_POSITION_KEY "panelposition" using namespace UKUi; @@ -63,21 +63,16 @@ m_buttonStyle(Qt::ToolButtonIconOnly), m_buttonWidth(400), m_buttonHeight(100), - m_closeOnMiddleClick(true), - m_raiseOnCurrentDesktop(true), - m_showOnlyOneDesktopTasks(true), m_showDesktopNum(0), - m_showOnlyCurrentScreenTasks(false), - m_showOnlyMinimizedTasks(false), m_autoRotate(true), m_groupingEnabled(true), - m_showGroupOnHover(true), - m_iconByClass(false), - m_cycleOnWheelScroll(true), m_plugin(plugin), m_ignoreWindow(), m_placeHolder(new QWidget(this)), - m_style(new LeftAlignedTextStyle()) + m_style(new LeftAlignedTextStyle()), + m_maskImg(new QImage()), + m_beginMaskLabel(new QLabel(this)), + m_endMaskLabel(new QLabel(this)) { m_allFrame=new QWidget(this); m_allFrame->setAttribute(Qt::WA_TranslucentBackground); @@ -95,8 +90,6 @@ pal.setBrush(QPalette::Window, QColor(Qt::transparent)); this->setPalette(pal); - m_taskStatus=NORMAL; - m_layout = new UKUi::GridLayout(m_allFrame); m_allFrame->setLayout(m_layout); m_layout->setMargin(0); @@ -113,9 +106,28 @@ m_ignoreWindow = settings.value("ignoreWindow", "").toStringList(); settings.endGroup(); + m_interface = new QDBusInterface("com.kylin.kydevmonit.hedronclient","/kydevmonit/hedronclient", + "com.kylin.kydevmonit.hedronclient", + QDBusConnection::systemBus(),this); + if (m_interface->isValid()) { + QDBusReply<QString> replay = m_interface->call("get_application_control_mode"); + m_mode = replay; + + QDBusReply<QStringList> list = m_interface->call("get_application_control_list"); + m_controlAppList = list; + } + QDBusConnection::systemBus().connect(QString("com.kylin.kydevmonit.hedronclient"), + QString("/com/kylin/kydevmonit/hedron_single"), + QString("com.kylin.kydevmonit.hedronsingle"), + QString("application_control_mode_signal"), + this, + SLOT(securityControlApps(QString)) + ); + + //往任务栏中加入快速启动按钮 - refreshQuickLaunch(); - realign(); +// refreshQuickLaunch(); + securityControlApps(m_mode); settingsChanged(); setAcceptDrops(true); @@ -125,34 +137,30 @@ m_settings=new QGSettings(id); } - m_androidIconHash = matchAndroidIcon(); - const QByteArray id_Theme("org.ukui.style"); if (QGSettings::isSchemaInstalled(id_Theme)) { m_changeTheme = new QGSettings(id_Theme); } connect(m_changeTheme, &QGSettings::changed, this, [=] (const QString &key) { if (key=="iconThemeName") { - sleep(1); - for(auto it= m_knownWindows.begin(); it != m_knownWindows.end();it++) { + for(auto it= m_knownSdkWindows.begin(); it != m_knownSdkWindows.end();it++) { UKUITaskGroup *group = it.value(); - group->updateIcon(); + group->updateSdkIcon(); } } if (key == PANEL_POSITION_KEY) { - realign(); + realignSdk(); } }); - connect(m_signalMapper, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped), this, &UKUITaskBar::activateTask); + connect(m_signalMapper, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped), this, &UKUITaskBar::activateSdkTask); - connect(KWindowSystem::self(), static_cast<void (KWindowSystem::*)(WId, NET::Properties, NET::Properties2)>(&KWindowSystem::windowChanged) - , this, &UKUITaskBar::onWindowChanged); - connect(KWindowSystem::self(), &KWindowSystem::windowAdded, this, &UKUITaskBar::onWindowAdded); - connect(KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &UKUITaskBar::onWindowRemoved); - connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this, SLOT(onDesktopChanged())); + connect(WindowManager::self(), &WindowManager::windowChanged, this, &UKUITaskBar::onWindowChanged); + connect(WindowManager::self(), &WindowManager::windowAdded, this, &UKUITaskBar::onWindowAdded); + connect(WindowManager::self(), &WindowManager::windowRemoved, this, &UKUITaskBar::onWindowRemoved); + connect(WindowManager::self(), &WindowManager::currentDesktopChanged, this, &UKUITaskBar::onDesktopChanged); - saveSettings(); + saveSdkSettings(); /**/ QDBusConnection::sessionBus().unregisterService("com.ukui.panel.plugins.service"); @@ -184,7 +192,21 @@ m_placeHolder->setFixedSize(0,0); } - QDBusConnection::sessionBus().connect(QString(), QString("/"), "com.ukui.panel", "event", this, SLOT(wlKwinSigHandler(quint32,int, QString, QString))); + initMaskUI(); + connect(m_changeTheme, &QGSettings::changed, this, [=] (const QString &key) { + if (key==STYLE_NAME) { + initMaskUI(); + } + }); + const QByteArray id_panelposition(PANEL_SETTINGS); + if (QGSettings::isSchemaInstalled(id_panelposition)) { + QGSettings *m_postionGSettings = new QGSettings(id_panelposition); + connect(m_postionGSettings, &QGSettings::changed, this, [=] (const QString &key) { + if (key==PANEL_POSITION_KEY) { + setMaskPostion(); + } + }); + } } /************************************************ @@ -199,6 +221,60 @@ m_vBtn.clear(); } +void UKUITaskBar::initMaskUI() +{ + //支持黑白两套主题 + m_maskImg->load("/usr/share/ukui-panel/panel/img/leftMask.svg"); + QColor color = QApplication::palette().color(QPalette::Window); + color.setAlpha(255); + for (int x = 0; x <= m_maskImg->width(); x++) { + color.setAlpha(color.alpha() - 255/m_maskImg->width()); + for (int y = 0; y < m_maskImg->height(); y++) { + if (color.alpha() > 0) { + m_maskImg->setPixelColor(x, y, color); + } + } + } + //初始化遮罩属性 + m_beginMaskLabel->setScaledContents(true); //设置缩放 + m_beginMaskLabel->setAttribute(Qt::WA_TransparentForMouseEvents, true); //设置鼠标穿透 + m_beginMaskLabel->raise(); //设置在最顶层 + m_beginMaskLabel->hide(); //设置默认隐藏 + m_endMaskLabel->setScaledContents(true); + m_endMaskLabel->setAttribute(Qt::WA_TransparentForMouseEvents, true); + m_endMaskLabel->raise(); + m_endMaskLabel->hide(); + + setMaskPostion(); +} + +void UKUITaskBar::setMaskPostion() +{ + if(panel()->isHorizontal()) { + m_beginMaskLabel->setPixmap(QPixmap::fromImage(*m_maskImg)); + m_beginMaskLabel->setGeometry(0, 0, panel()->panelSize(), panel()->panelSize()); + + QImage rightimg = m_maskImg->mirrored(true, false); //水平镜像 + m_endMaskLabel->setPixmap(QPixmap::fromImage(rightimg)); + m_endMaskLabel->setGeometry(this->width() - m_endMaskLabel->width(), 0, + panel()->panelSize(), panel()->panelSize()); + } else { + QMatrix upmatrix; + upmatrix.rotate(90.0); //顺时针旋转90度 + QImage upimg = m_maskImg->transformed(upmatrix,Qt::FastTransformation); + m_beginMaskLabel->setPixmap(QPixmap::fromImage(upimg)); + m_beginMaskLabel->setGeometry(0, 0, panel()->panelSize(), panel()->panelSize()); + + QMatrix bottommatrix; + bottommatrix.rotate(-90.0); //逆时针旋转90度 + QImage bottomimg = m_maskImg->transformed(bottommatrix,Qt::FastTransformation); + m_endMaskLabel->setPixmap(QPixmap::fromImage(bottomimg)); + m_endMaskLabel->setGeometry(0, this->height() - m_endMaskLabel->height(), + panel()->panelSize(), panel()->panelSize()); + } + +} + QString UKUITaskBar::readFile(const QString &filename) { QFile f(filename); @@ -212,7 +288,7 @@ void UKUITaskBar::onDesktopChanged() { - for (auto i = m_knownWindows.begin(); m_knownWindows.end() != i; ++i) { + for (auto i = m_knownSdkWindows.begin(); m_knownSdkWindows.end() != i; ++i) { (*i)->onDesktopChanged(); if ((*i)->m_existSameQckBtn) { UKUITaskGroup* btn = (*i)->getOwnQckBtn(); @@ -244,27 +320,12 @@ QString filename = QDir::homePath() + "/.config/ukui/panel.conf"; QSettings user_qsettings(filename,QSettings::IniFormat); QStringList groupname = user_qsettings.childGroups(); - //为了兼容3.0版本和3.1版本,后续版本考虑删除 + //为了兼容3.0版本和3.1版本,3.0版本的固定应用信息在quicklaunch里,3.1版本在taskbar里 + //备份还原时需要quicklaunch字段,故不能删除 if (apps.isEmpty() && groupname.contains("quicklaunch")) { apps = copyQuicklaunchConfig(); - } else if (groupname.contains("quicklaunch")) { - user_qsettings.remove("quicklaunch"); - } - - for (const QMap<QString, QVariant> &app : apps) { - desktop = app.value("desktop", "").toString(); - qDebug()<<"desktop ******"<<desktop; - - file = app.value("file", "").toString(); - if (!desktop.isEmpty()) { - XdgDesktopFile xdg; - if (xdg.load(desktop)) { - addButton(new QuickLaunchAction(&xdg, this)); - } - } else { - qDebug()<<"error desktop file"; - } } + addButtonForQuicklanch(apps); } QList<QMap<QString, QVariant> > UKUITaskBar::copyQuicklaunchConfig() @@ -288,61 +349,136 @@ } user_qsettings.endArray(); user_qsettings.endGroup(); - user_qsettings.remove("quicklaunch"); user_qsettings.sync(); return array; } -bool UKUITaskBar::acceptWindow(WId window) const +void UKUITaskBar::addButtonForQuicklanch(QList<QMap<QString, QVariant> > apps) { - QFlags<NET::WindowTypeMask> ignoreList; - ignoreList |= NET::DesktopMask; - ignoreList |= NET::DockMask; - ignoreList |= NET::SplashMask; - ignoreList |= NET::ToolbarMask; - ignoreList |= NET::MenuMask; - ignoreList |= NET::PopupMenuMask; - ignoreList |= NET::NotificationMask; - - KWindowInfo info(window, NET::WMWindowType | NET::WMState, NET::WM2TransientFor); - if (!info.valid()) { - return false; + for (auto it = m_vBtn.begin(); it != m_vBtn.end();) { + UKUITaskGroup * quicklaunch = m_vBtn.value(m_vBtn.indexOf(*it)); + if(quicklaunch->m_existSameQckBtn == true) { + it++; + continue; + } + (*it)->deleteLater(); + m_vBtn.erase(it); } - if (NET::typeMatchesMask(info.windowType(NET::AllTypesMask), ignoreList)) { - return false; - } + for (const QMap<QString, QVariant> &app : apps) { + QString desktop = app.value("desktop", "").toString(); + qDebug()<<"desktop ******"<<desktop; - if (info.state() & NET::SkipTaskbar) { - return false; + if (!desktop.isEmpty()) { + XdgDesktopFile xdg; + if (xdg.load(desktop)) { + if (!checkButton(new QuickLaunchAction(&xdg, this))) { + addSdkButton(new QuickLaunchAction(&xdg, this)); + } + } + } else { + qDebug()<<"error desktop file"; + } } +} - // WM_TRANSIENT_FOR hint not set - normal window - WId transFor = info.transientFor(); - if (transFor == 0 || transFor == window || transFor == (WId) QX11Info::appRootWindow()) { - return true; +void UKUITaskBar::securityControlApps(QString mode) +{ + if (mode == "blacklist") { + QDBusReply<QStringList> list = m_interface->call("get_application_control_list"); + m_controlAppList = list; + removeBlackListApp(); + } else if (mode == "whitelist") { + QDBusReply<QStringList> list = m_interface->call("get_application_control_list"); + m_controlAppList = list; + addWhiteListApp(); + } else { + refreshQuickLaunch(); } - - info = KWindowInfo(transFor, NET::WMWindowType); - - QFlags<NET::WindowTypeMask> normalFlag; - normalFlag |= NET::NormalMask; - normalFlag |= NET::DialogMask; - normalFlag |= NET::UtilityMask; - - return !NET::typeMatchesMask(info.windowType(NET::AllTypesMask), normalFlag); } -void UKUITaskBar::dragEnterEvent(QDragEnterEvent* event) +void UKUITaskBar::removeBlackListApp() { + QList<QMap<QString, QVariant>> blacklistAppnames; + QStringList mblacklist = m_controlAppList; + + for (int i = 0; i < mblacklist.size(); i++) { + QMap<QString, QVariant> map; + map["desktop"] = mblacklist.at(i); + blacklistAppnames << map; + } + QList<QMap<QString, QVariant> > normalapps = m_plugin->settings()->readArray("apps"); + for (const QMap<QString, QVariant> &blacklistAppname : blacklistAppnames) { + if (normalapps.contains(blacklistAppname)) { + qDebug()<<"normalapps need remove this:"<<blacklistAppname.value("desktop"); + normalapps.removeOne(blacklistAppname); + } + } + addButtonForQuicklanch(normalapps); } -void UKUITaskBar::dragMoveEvent(QDragMoveEvent * event) +void UKUITaskBar::addWhiteListApp() { + QList<QMap<QString, QVariant>> whitelistAppnames; + QStringList mwhitelist = m_controlAppList; + + for (int i = 0; i < mwhitelist.size(); i++) { + QMap<QString, QVariant> map; + map["desktop"] = mwhitelist.at(i); + whitelistAppnames << map; + } + addButtonForQuicklanch(whitelistAppnames); } -void UKUITaskBar::dropEvent(QDropEvent *e) +bool UKUITaskBar::acceptWindow(const WindowId& window) const { + QString platform = QGuiApplication::platformName(); + if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) { + + QString windowTitle = WindowManager::getWindowTitle(window); + if (windowTitle == "UKUI Panel") { + return false; + } + bool isSkipTaskbar = kdk::WindowManager::skipTaskBar(window); + if(isSkipTaskbar) { + return false; + } + return true; + } else { + int wid = window.toInt(); + QFlags<NET::WindowTypeMask> ignoreList; + ignoreList |= NET::DesktopMask; + ignoreList |= NET::DockMask; + ignoreList |= NET::SplashMask; + ignoreList |= NET::ToolbarMask; + ignoreList |= NET::MenuMask; + ignoreList |= NET::PopupMenuMask; + ignoreList |= NET::NotificationMask; + ignoreList |= NET::UtilityMask; + + KWindowInfo info(wid, NET::WMWindowType | NET::WMState, NET::WM2TransientFor); + if (!info.valid()) { + return false; + } + if (NET::typeMatchesMask(info.windowType(NET::AllTypesMask), ignoreList)) { + return false; + } + if (info.state() & NET::SkipTaskbar) { + return false; + } + // WM_TRANSIENT_FOR hint not set - normal window + WId transFor = info.transientFor(); + if (transFor == 0 || transFor == wid || transFor == (WId) QX11Info::appRootWindow()) { + return true; + } + + info = KWindowInfo(transFor, NET::WMWindowType); + QFlags<NET::WindowTypeMask> normalFlag; + normalFlag |= NET::NormalMask; + normalFlag |= NET::DialogMask; + normalFlag |= NET::UtilityMask; + return !NET::typeMatchesMask(info.windowType(NET::AllTypesMask), normalFlag); + } } void UKUITaskBar::buttonMove(UKUITaskGroup * dst, UKUITaskGroup * src, QPoint const & pos) @@ -403,16 +539,16 @@ m_layout->moveItem(src_index, dst_index, true); } -void UKUITaskBar::groupBecomeEmptySlot() +void UKUITaskBar::groupSdkBecomeEmptySlot() { //group now contains no buttons - clean up in hash and delete the group UKUITaskGroup * const group = qobject_cast<UKUITaskGroup*>(sender()); Q_ASSERT(group); - for (auto i = m_knownWindows.begin(); m_knownWindows.end() != i; ) { + for (auto i = m_knownSdkWindows.begin(); m_knownSdkWindows.end() != i; ) { if (group == *i) { - m_swid.removeOne(i.key()); - i = m_knownWindows.erase(i); + m_sdkSwid.removeOne(i.key()); + i = m_knownSdkWindows.erase(i); break; } else { ++i; @@ -432,18 +568,19 @@ group->deleteLater(); } -void UKUITaskBar::addWindow(WId window) +void UKUITaskBar::addWindow(const WindowId& window) { // If grouping disabled group behaves like regular button - const QString group_id = m_groupingEnabled ? KWindowInfo(window, 0, NET::WM2WindowClass).windowClassClass() : QString("%1").arg(window); - if (m_ignoreWindow.contains(group_id)) { + const QString group_id = m_groupingEnabled ? WindowManager::getWindowGroup(window) : QString("%1").arg(window.toInt()); + qDebug()<<"****** group_id is "<<group_id; + if (m_ignoreWindow.contains(group_id) || group_id == "") { return; } UKUITaskGroup *group = nullptr; bool isNeedAddNewWidget = true; - auto i_group = m_knownWindows.find(window); - if (m_knownWindows.end() != i_group) { + auto i_group = m_knownSdkWindows.find(window.toInt()); + if (m_knownSdkWindows.end() != i_group) { if ((*i_group)->groupName() == group_id) { group = *i_group; } else { @@ -459,7 +596,7 @@ QStringList andriod_window_list; andriod_window_list<<"kydroid-display-window"<<"kylin-kmre-window"<<""; if (!group && m_groupingEnabled && !andriod_window_list.contains(group_id)) { - for (auto i = m_knownWindows.cbegin(), i_e = m_knownWindows.cend(); i != i_e; ++i) { + for (auto i = m_knownSdkWindows.cbegin(), i_e = m_knownSdkWindows.cend(); i != i_e; ++i) { if ((*i)->groupName() == group_id) { group = *i; break; @@ -468,12 +605,10 @@ } if (!group) { group = new UKUITaskGroup(group_id, window, this); - connect(group, SIGNAL(groupBecomeEmpty(QString)), this, SLOT(groupBecomeEmptySlot())); - connect(group, SIGNAL(t_saveSettings()), this, SLOT(saveSettingsSlot())); + connect(group, SIGNAL(groupBecomeEmpty(QString)), this, SLOT(groupSdkBecomeEmptySlot())); connect(group, SIGNAL(WindowAddtoTaskBar(QString)), this, SLOT(WindowAddtoTaskBar(QString))); connect(group, SIGNAL(WindowRemovefromTaskBar(QString)), this, SLOT(WindowRemovefromTaskBar(QString))); connect(group, SIGNAL(visibilityChanged(bool)), this, SLOT(refreshPlaceholderVisibility())); - connect(group, &UKUITaskGroup::popupShown, this, &UKUITaskBar::popupShown); connect(group, &UKUITaskButton::dragging, this, [this] (QObject * dragSource, QPoint const & pos) { switchButtons(qobject_cast<UKUITaskGroup *>(sender()), qobject_cast<UKUITaskGroup *>(dragSource));//, pos); }); @@ -496,40 +631,40 @@ } group->setToolButtonsStyle(m_buttonStyle); } - m_knownWindows[window] = group; - m_swid.push_back(window); - + m_knownSdkWindows[window.toInt()] = group; + m_sdkSwid.push_back(window.toInt()); group->addWindow(window); group->groupName(); - group->updateIcon(); + group->updateSdkIcon(); } -auto UKUITaskBar::removeWindow(windowMap_t::iterator pos) -> windowMap_t::iterator +auto UKUITaskBar::removeWindow(windowSdkMap_t::iterator pos) -> windowSdkMap_t::iterator { - WId const window = pos.key(); + qint32 const windowid = pos.key(); UKUITaskGroup * const group = *pos; - m_swid.removeOne(window); - auto ret = m_knownWindows.erase(pos); + m_sdkSwid.removeOne(windowid); + auto ret = m_knownSdkWindows.erase(pos); + WindowId window = WindowId(windowid); group->onWindowRemoved(window); - //if (countOfButtons() <= 32) m_tmpWidget->setHidden(true); return ret; } void UKUITaskBar::refreshTaskList() { - QList<WId> new_list; + QList<qint32> new_list; // Just add new windows to groups, deleting is up to the groups - const auto wnds = KWindowSystem::stackingOrder(); - for (auto const wnd: wnds) { - if (acceptWindow(wnd)) { - new_list << wnd; - addWindow(wnd); +// const auto wnds = KWindowSystem::stackingOrder(); + const auto wnds = WindowManager::windows(); + for (int i = 0; i < wnds.size(); i++) { + if (acceptWindow(wnds.at(i))) { + new_list << wnds.at(i).toInt(); + addWindow(wnds.at(i)); } } // m_layout->addWidget(m_tmpWidget); //emulate windowRemoved if known window not reported by KWindowSystem - for (auto i = m_knownWindows.begin(), i_e = m_knownWindows.end(); i != i_e; ) { + for (auto i = m_knownSdkWindows.begin(), i_e = m_knownSdkWindows.end(); i != i_e; ) { if (0 > new_list.indexOf(i.key())) { i = removeWindow(i); } else { @@ -541,30 +676,30 @@ } -void UKUITaskBar::onWindowChanged(WId window, NET::Properties prop, NET::Properties2 prop2) +void UKUITaskBar::onWindowChanged(const WindowId& window) { - auto i = m_knownWindows.find(window); - if (m_knownWindows.end() != i) { - if (!(*i)->onWindowChanged(window, prop, prop2) && acceptWindow(window)) { + auto i = m_knownSdkWindows.find(window.toInt()); + if (m_knownSdkWindows.end() != i) { + if (!(*i)->onWindowChanged(window) && acceptWindow(window)) { // window is removed from a group because of class change, so we should add it again addWindow(window); } } } -void UKUITaskBar::onWindowAdded(WId window) +void UKUITaskBar::onWindowAdded(const WindowId& window) { qDebug()<<"window is : ******"<<window; - auto const pos = m_knownWindows.find(window); - if (m_knownWindows.end() == pos && acceptWindow(window)) { + auto const pos = m_knownSdkWindows.find(window.toInt()); + if (m_knownSdkWindows.end() == pos && acceptWindow(window)) { addWindow(window); } } -void UKUITaskBar::onWindowRemoved(WId window) +void UKUITaskBar::onWindowRemoved(const WindowId& window) { - auto const pos = m_knownWindows.find(window); - if (m_knownWindows.end() != pos) { + auto const pos = m_knownSdkWindows.find(window.toInt()); + if (m_knownSdkWindows.end() != pos) { removeWindow(pos); } } @@ -574,7 +709,6 @@ bool autoRotate = m_autoRotate && (m_buttonStyle != Qt::ToolButtonIconOnly); IUKUIPanel::Position panelPosition = m_plugin->panel()->position(); - // emit buttonRotationRefreshed(autoRotate, panelPosition); } /************************************************ @@ -583,7 +717,7 @@ void UKUITaskBar::refreshPlaceholderVisibility() { bool haveVisibleWindow = false; - for (auto i = m_knownWindows.cbegin(), i_e = m_knownWindows.cend(); i_e != i; ++i) { + for (auto i = m_knownSdkWindows.cbegin(), i_e = m_knownSdkWindows.cend(); i_e != i; ++i) { if ((*i)->isVisible()) { haveVisibleWindow = true; break; @@ -609,11 +743,6 @@ void UKUITaskBar::settingsChanged() { bool groupingEnabledOld = m_groupingEnabled; - bool showOnlyOneDesktopTasksOld = m_showOnlyOneDesktopTasks; - const int showDesktopNumOld = m_showDesktopNum; - bool showOnlyCurrentScreenTasksOld = m_showOnlyCurrentScreenTasks; - bool showOnlyMinimizedTasksOld = m_showOnlyMinimizedTasks; - const bool iconByClassOld = m_iconByClass; m_buttonWidth = m_plugin->settings()->value("buttonWidth", 400).toInt(); m_buttonHeight = m_plugin->settings()->value("buttonHeight", 100).toInt(); @@ -627,76 +756,62 @@ setButtonStyle(Qt::ToolButtonIconOnly); } - m_showOnlyOneDesktopTasks = m_plugin->settings()->value("showOnlyOneDesktopTasks", m_showOnlyOneDesktopTasks).toBool(); m_showDesktopNum = m_plugin->settings()->value("showDesktopNum", m_showDesktopNum).toInt(); - m_showOnlyCurrentScreenTasks = m_plugin->settings()->value("showOnlyCurrentScreenTasks", m_showOnlyCurrentScreenTasks).toBool(); - m_showOnlyMinimizedTasks = m_plugin->settings()->value("showOnlyMinimizedTasks", m_showOnlyMinimizedTasks).toBool(); m_autoRotate = m_plugin->settings()->value("autoRotate", true).toBool(); - m_closeOnMiddleClick = m_plugin->settings()->value("closeOnMiddleClick", true).toBool(); - m_raiseOnCurrentDesktop = m_plugin->settings()->value("raiseOnCurrentDesktop", false).toBool(); m_groupingEnabled = m_plugin->settings()->value("groupingEnabled",true).toBool(); - m_showGroupOnHover = m_plugin->settings()->value("showGroupOnHover",true).toBool(); - m_iconByClass = m_plugin->settings()->value("iconByClass", false).toBool(); - m_cycleOnWheelScroll = m_plugin->settings()->value("cycleOnWheelScroll", true).toBool(); // Delete all groups if grouping feature toggled and start over if (groupingEnabledOld != m_groupingEnabled) { - for (int i = m_knownWindows.size() - 1; 0 <= i; --i) { - UKUITaskGroup * group = m_knownWindows.value(m_swid.value(i)); + for (int i = m_knownSdkWindows.size() - 1; 0 <= i; --i) { + UKUITaskGroup * group = m_knownSdkWindows.value(m_sdkSwid.value(i)); if (nullptr != group) { m_layout->takeAt(i); group->deleteLater(); } } - m_knownWindows.clear(); - m_swid.clear(); - } - - if (showOnlyOneDesktopTasksOld != m_showOnlyOneDesktopTasks - || (m_showOnlyOneDesktopTasks && showDesktopNumOld != m_showDesktopNum) - || showOnlyCurrentScreenTasksOld != m_showOnlyCurrentScreenTasks - || showOnlyMinimizedTasksOld != m_showOnlyMinimizedTasks - ) { - emit showOnlySettingChanged(); - } - if (iconByClassOld != m_iconByClass) { - emit iconByClassChanged(); + m_knownSdkWindows.clear(); + m_sdkSwid.clear(); } refreshTaskList(); } -void UKUITaskBar::setShowGroupOnHover(bool bFlag) -{ - m_showGroupOnHover = bFlag; -} - -int i = 0; -void UKUITaskBar::realign() +void UKUITaskBar::realignSdk() { m_layout->setEnabled(false); refreshButtonRotation(); IUKUIPanel *panel = m_plugin->panel(); - QSize maxSize = QSize(m_plugin->panel()->panelSize(), m_plugin->panel()->panelSize()); - QSize minSize = QSize(m_plugin->panel()->iconSize()/2, m_plugin->panel()->iconSize()/2); + QSize btnSize = QSize(m_plugin->panel()->panelSize(), m_plugin->panel()->panelSize()); int iconsize = panel->iconSize(); bool rotated = false; if (panel->isHorizontal()) { this->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_allFrame->setMinimumSize(QSize((m_layout->count()+5)*panel->panelSize(),panel->panelSize())); + this->setMinimumHeight(panel->panelSize()); + m_allFrame->setMinimumSize(QSize((m_layout->count())*panel->panelSize(),panel->panelSize())); if (m_allFrame->width() < this->width()) { m_allFrame->setFixedWidth(this->width()); } m_layout->setRowCount(panel->lineCount()); m_layout->setColumnCount(0); + + m_beginMaskLabel->setGeometry(0, 0, panel->panelSize(), panel->panelSize()); + m_endMaskLabel->setGeometry(this->width() - m_endMaskLabel->width(), 0, + panel->panelSize(), panel->panelSize()); + if(m_layout->count() * panel->panelSize() > this->width()) { + m_endMaskLabel->show(); + } else { + m_beginMaskLabel->hide(); + m_endMaskLabel->hide(); + } } else { this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - m_allFrame->setMinimumSize(QSize(panel->panelSize(),(m_layout->count()+3)*panel->panelSize())); + this->setMinimumWidth(panel->panelSize()); + m_allFrame->setMinimumSize(QSize(panel->panelSize(),(m_layout->count())*panel->panelSize())); if (m_allFrame->height() < this->height()) { m_allFrame->setFixedHeight(this->height()); } @@ -711,17 +826,23 @@ // Vertical + Text if (rotated) { - maxSize.rwidth() = m_buttonHeight; - maxSize.rheight() = m_buttonWidth; - m_layout->setColumnCount(panel->lineCount()); } else { m_layout->setColumnCount(1); } } + m_beginMaskLabel->setGeometry(0, 0, panel->panelSize(), panel->panelSize()); + m_endMaskLabel->setGeometry(0, this->height() - m_endMaskLabel->height(), + panel->panelSize(), panel->panelSize()); + if(m_layout->count() * panel->panelSize() > this->height()) { + m_endMaskLabel->show(); + } else { + m_beginMaskLabel->hide(); + m_endMaskLabel->hide(); + } } - for(auto it= m_knownWindows.begin(); it != m_knownWindows.end();it++) { + for(auto it= m_knownSdkWindows.begin(); it != m_knownSdkWindows.end();it++) { UKUITaskGroup *group = it.value(); group->setIconSize(QSize(iconsize,iconsize)); } @@ -729,16 +850,17 @@ UKUITaskGroup * quicklaunch = m_vBtn.value(i); quicklaunch->setIconSize(QSize(iconsize, iconsize)); } - m_layout->setCellMinimumSize(minSize); - m_layout->setCellMaximumSize(maxSize); - m_layout->setDirection(rotated ? UKUi::GridLayout::TopToBottom : UKUi::GridLayout::LeftToRight); + m_layout->setCellFixedSize(btnSize); m_layout->setEnabled(true); //our placement on screen could have been changed emit showOnlySettingChanged(); emit refreshIconGeometry(); - horizontalScrollBar()->setMaximum(m_allFrame->width() - this->width()); - verticalScrollBar()->setMaximum(m_allFrame->height() - this->height()); + if (panel->isHorizontal()) { + horizontalScrollBar()->setMaximum(m_allFrame->width() - this->width()); + } else { + verticalScrollBar()->setMaximum(m_allFrame->height() - this->height()); + } } void UKUITaskBar::wheelEvent(QWheelEvent* event) @@ -746,13 +868,22 @@ if (this->verticalScrollBarPolicy()==Qt::ScrollBarAlwaysOff) { if (event->delta()>=0) { horizontalScrollBar()->setValue(horizontalScrollBar()->value()-40); - qDebug()<<"-40-horizontalScrollBar()->value()"<<horizontalScrollBar()->value(); } else { horizontalScrollBar()->setValue(horizontalScrollBar()->value()+40); if (horizontalScrollBar()->value()>m_allFrame->width()) { horizontalScrollBar()->setValue(m_allFrame->width()); } - qDebug()<<"+40+horizontalScrollBar()->value()"<<horizontalScrollBar()->value(); + } + + if(horizontalScrollBar()->value() != 0) { + m_beginMaskLabel->show(); + } else { + m_beginMaskLabel->hide(); + } + if (horizontalScrollBar()->value() == horizontalScrollBar()->maximum()) { + m_endMaskLabel->hide(); + } else { + m_endMaskLabel->show(); } } else { if (event->delta()>=0) { @@ -760,6 +891,16 @@ } else { verticalScrollBar()->setValue(verticalScrollBar()->value()+40); } + if(verticalScrollBar()->value() != 0) { + m_beginMaskLabel->show(); + } else { + m_beginMaskLabel->hide(); + } + if (verticalScrollBar()->value() == verticalScrollBar()->maximum()) { + m_endMaskLabel->hide(); + } else { + m_endMaskLabel->show(); + } } } @@ -779,15 +920,14 @@ QFrame::changeEvent(event); } - -void UKUITaskBar::activateTask(int pos) +void UKUITaskBar::activateSdkTask(int pos) { - for (int i = 0; i < m_knownWindows.size(); ++i) { - UKUITaskGroup * g = m_knownWindows.value(m_swid.value(i)); + for (int i = 0; i < m_knownSdkWindows.size(); ++i) { + UKUITaskGroup * g = m_knownSdkWindows.value(m_sdkSwid.value(i)); if (g && g->isVisible()) { pos--; if (pos == 0) { - g->raiseApplication(); + g->raiseSdkApplication(); break; } } @@ -796,68 +936,14 @@ void UKUITaskBar::enterEvent(QEvent *) { - m_taskStatus=HOVER; update(); } void UKUITaskBar::leaveEvent(QEvent *) { - m_taskStatus=NORMAL; update(); } -void UKUITaskBar::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.initFrom(this); - QPainter p(this); - - p.setRenderHint(QPainter::Antialiasing); - QPainterPath rectPath; - rectPath.addRoundedRect(this->rect(),6,6); - // 画一个黑底 - QPixmap pixmap(this->rect().size()); - pixmap.fill(Qt::transparent); - QPainter pixmapPainter(&pixmap); - pixmapPainter.setRenderHint(QPainter::Antialiasing); - - pixmapPainter.drawPath(rectPath); - pixmapPainter.end(); - - // 模糊这个黑底 - extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); - QImage img = pixmap.toImage(); - qt_blurImage(img, 10, false, false); - - switch(m_taskStatus) { - case NORMAL: - { - p.setPen(Qt::NoPen); - break; - } - case HOVER: - { - p.setPen(Qt::NoPen); - break; - } - case PRESS: - { - p.setPen(Qt::NoPen); - break; - } - } - - QPalette pal = this->palette(); - pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 - this->viewport()->setPalette(pal); - this->setPalette(pal); - m_allFrame->setPalette(pal); - - p.setRenderHint(QPainter::Antialiasing); - p.drawRoundedRect(opt.rect,6,6); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} - void UKUITaskBar::mouseMoveEvent(QMouseEvent *e) { QFrame::mouseMoveEvent(e); @@ -870,15 +956,9 @@ QDBusConnection::sessionBus().send(message); } -/////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// /// About Quick Launch Functions -/// -/// -void UKUITaskBar::addButton(QuickLaunchAction* action) +void UKUITaskBar::addSdkButton(QuickLaunchAction* action) { bool isNeedAddNewWidget = true; m_layout->setEnabled(false); @@ -888,8 +968,7 @@ * 快速启动栏右键菜单原本的样式有对于不可选项有置灰效果, * 后跟随主题框架之后置灰效果消失,可能与此属性相关 */ - // btn->setMenu(Qt::InstantPopup); - for (auto it = m_knownWindows.begin(); it!=m_knownWindows.end(); ++it) { + for (auto it = m_knownSdkWindows.begin(); it!=m_knownSdkWindows.end(); ++it) { UKUITaskGroup *group = *it; if(btn->m_fileName == group->m_fileName &&(m_layout->indexOf(group) >= 0)) { @@ -913,8 +992,7 @@ connect(btn, &UKUITaskButton::dragging, this, [this] (QObject * dragSource, QPoint const & pos) { switchButtons(qobject_cast<UKUITaskGroup *>(sender()), qobject_cast<UKUITaskGroup *>(dragSource));//, pos); }); - connect(btn, SIGNAL(buttonDeleted()), this, SLOT(buttonDeleted())); - connect(btn, SIGNAL(t_saveSettings()), this, SLOT(saveSettingsSlot())); + connect(btn, SIGNAL(buttonDeleted()), this, SLOT(buttonSdkDeleted())); m_layout->setEnabled(true); } @@ -933,7 +1011,7 @@ return; } m_layout->moveItem(src, dst, true); - saveSettings(); + saveSdkSettings(); } bool UKUITaskBar::checkButton(QuickLaunchAction* action) @@ -984,7 +1062,7 @@ } btn->deleteLater(); - saveSettings(); + saveSdkSettings(); } void UKUITaskBar::removeButton(QString file) @@ -1005,10 +1083,11 @@ void UKUITaskBar::WindowAddtoTaskBar(QString arg) { - for(auto it= m_knownWindows.begin(); it != m_knownWindows.end();it++) { + for(auto it= m_knownSdkWindows.begin(); it != m_knownSdkWindows.end();it++) { UKUITaskGroup *group = it.value(); if (arg.compare(group->groupName()) == 0) { - addToTaskbar(group->m_fileName); + addSdkToTaskbar(group->m_fileName); + realignSdk(); break; } } @@ -1023,7 +1102,7 @@ m_vBtn.removeOne(pQuickBtn); pQuickBtn->deleteLater(); m_layout->removeWidget(pQuickBtn); - saveSettings(); + saveSdkSettings(); break; } } @@ -1039,10 +1118,6 @@ QSet<QString> newdirset = QSet<QString>::fromList(newentrylist); QSet<QString> currentdirset = QSet<QString>::fromList(currentrylist); - // 添加了文件 - QSet<QString> newfiles = newdirset - currentdirset; - QStringList newfile = newfiles.toList(); - // 文件已被移除 QSet<QString> deletedfiles = currentdirset - newdirset; QStringList deletefile = deletedfiles.toList(); @@ -1050,31 +1125,41 @@ // 更新当前设置 m_currentContentsMap[path] = newentrylist; - if (!newfile.isEmpty() && !deletefile.isEmpty()) { - // 文件/目录重命名 - if ((newfile.count() == 1) && (deletefile.count() == 1)) { -// qDebug() << QString("File Renamed from %1 to %2").arg(deleteFile.first()).arg(newFile.first()); - } - } else { - // 从Dir中删除文件/目录 - if (!deletefile.isEmpty()) { - foreach (QString file, deletefile) { - removeButton(path+file); - } + // 从Dir中删除文件/目录 + if (!deletefile.isEmpty()) { + foreach (QString file, deletefile) { + removeButton(path+file); + saveSdkSettings(); } } } - void UKUITaskBar::addToTaskbar(QString arg) { const auto url=QUrl(arg); QString fileName(url.isLocalFile() ? url.toLocalFile() : url.url()); + XdgDesktopFile xdg; + if (xdg.load(fileName)) { + if (!checkButton(new QuickLaunchAction(&xdg, this))) { + addSdkButton(new QuickLaunchAction(&xdg, this)); + m_placeHolder->hide(); + } + } else { + qWarning() << "XdgDesktopFile" << fileName << "is not valid"; + } + saveSdkSettings(); + realignSdk(); +} + +void UKUITaskBar::addSdkToTaskbar(QString arg) +{ + const auto url=QUrl(arg); + QString fileName(url.isLocalFile() ? url.toLocalFile() : url.url()); QFileInfo fi(fileName); XdgDesktopFile xdg; if (xdg.load(fileName)) { if (!checkButton(new QuickLaunchAction(&xdg, this))) { - addButton(new QuickLaunchAction(&xdg, this)); + addSdkButton(new QuickLaunchAction(&xdg, this)); m_placeHolder->hide(); } } else { @@ -1083,7 +1168,7 @@ tr("File/URL '%1' cannot be embedded into QuickLaunch for now").arg(fileName) ); } - saveSettings(); + saveSdkSettings(); } void UKUITaskBar::removeFromTaskbar(QString arg) @@ -1091,11 +1176,12 @@ XdgDesktopFile xdg; xdg.load(arg); removeButton(new QuickLaunchAction(&xdg, this)); + realignSdk(); } void UKUITaskBar::doInitGroupButton(QString sname) { - for(auto it= m_knownWindows.begin(); it != m_knownWindows.end();it++) { + for(auto it= m_knownSdkWindows.begin(); it != m_knownSdkWindows.end();it++) { UKUITaskGroup *group = it.value(); if (group->m_existSameQckBtn) { if (sname == group->m_fileName) { @@ -1107,7 +1193,7 @@ } } -void UKUITaskBar::buttonDeleted() +void UKUITaskBar::buttonSdkDeleted() { UKUITaskGroup *btn = qobject_cast<UKUITaskGroup*>(sender()); if (!btn) { @@ -1115,7 +1201,7 @@ } for (auto it = m_vBtn.begin(); it != m_vBtn.end(); it++) { if (*it == btn) { - for (auto it= m_knownWindows.begin(); it != m_knownWindows.end(); it++) { + for (auto it= m_knownSdkWindows.begin(); it != m_knownSdkWindows.end(); it++) { UKUITaskGroup *group = it.value(); if (group->m_existSameQckBtn) { if (btn->m_fileName == group->m_fileName) { @@ -1130,15 +1216,15 @@ } m_layout->removeWidget(btn); btn->deleteLater(); - saveSettings(); + saveSdkSettings(); } -void UKUITaskBar::saveSettingsSlot() +void UKUITaskBar::saveSdkSettingsSlot() { - saveSettings(); + saveSdkSettings(); } -void UKUITaskBar::saveSettings() +void UKUITaskBar::saveSdkSettings() { PluginSettings *settings = m_plugin->settings(); settings->remove("apps"); @@ -1146,7 +1232,7 @@ int size = m_layout->count(); for (int j = 0; j < size; ++j) { UKUITaskGroup *b = qobject_cast<UKUITaskGroup*>(m_layout->itemAt(j)->widget()); - if (!(m_vBtn.contains(b) || m_knownWindows.contains(m_knownWindows.key(b)))) { + if (!(m_vBtn.contains(b) || m_knownSdkWindows.contains(m_knownSdkWindows.key(b)))) { continue; } if (!b->m_statFlag && b->m_existSameQckBtn) { @@ -1173,181 +1259,7 @@ settings->setArray("apps", hashList); } -int UKUITaskBar::indexOfButton(UKUITaskGroup* button) const -{ - return m_layout->indexOf(button); -} - int UKUITaskBar::countOfButtons() const { return m_layout->count(); } - -void UKUITaskBar::wlKwinSigHandler(quint32 wl_winId, int opNo, QString wl_iconName, QString wl_caption) -{ - qDebug()<<"UKUITaskBar::wlKwinSigHandler"<<wl_winId<<opNo<<wl_iconName<<wl_caption; - if (!opNo) { -// addWindow_wl(wl_iconName, wl_caption, wl_winId); - } - switch (opNo) { - case 1: - m_knownWindows.find(wl_winId).value()->setActivateState_wl(false); - break; - case 2: - onWindowRemoved(wl_winId); - break; - case 3: - m_knownWindows.find(wl_winId).value()->setActivateState_wl(true); - break; - case 4: - addWindow_wl(wl_iconName, wl_caption, wl_winId); - m_knownWindows.find(wl_winId).value()->wl_widgetUpdateTitle(wl_caption); - break; - } -} - -void UKUITaskBar::addWindow_wl(QString iconName, QString caption, WId window) -{ - // If grouping disabled group behaves like regular button -// QString temp_group_id=caption; -// QStringList strList = temp_group_id.split(" "); - - const QString group_id = captionExchange(caption); - if (QIcon::fromTheme(group_id).isNull()) { - iconName = QDir::homePath() + "/.local/share/icons/" + group_id + ".svg"; - if (!QFile(iconName).exists()) { - iconName = QDir::homePath() + "/.local/share/icons/" + group_id + ".png"; - if (!QFile(iconName).exists()) { - iconName = group_id; - } - } - } else { - iconName = group_id; - } - UKUITaskGroup *group = nullptr; - auto i_group = m_knownWindows.find(window); - if (m_knownWindows.end() != i_group) { - if ((*i_group)->groupName() == group_id) { - group = *i_group; - } else { - (*i_group)->onWindowRemoved(window); - } - } - - if (!group && m_groupingEnabled && group_id.compare("kylin-video")) { - for (auto i = m_knownWindows.cbegin(), i_e = m_knownWindows.cend(); i != i_e; ++i) { - if ((*i)->groupName() == group_id) { - group = *i; - break; - } - } - } - - if (!group) { - group = new UKUITaskGroup(iconName, caption, window, this); - m_placeHolder->hide(); - connect(group, SIGNAL(groupBecomeEmpty(QString)), this, SLOT(groupBecomeEmptySlot())); - connect(group, SIGNAL(visibilityChanged(bool)), this, SLOT(refreshPlaceholderVisibility())); - connect(group, &UKUITaskGroup::popupShown, this, &UKUITaskBar::popupShown); - connect(group, &UKUITaskButton::dragging, this, [this] (QObject * dragSource, QPoint const & pos) { - buttonMove(qobject_cast<UKUITaskGroup *>(sender()), qobject_cast<UKUITaskGroup *>(dragSource), pos); - }); - - //wayland临时图标适配主题代码处理 - /*********************************************/ - if (QIcon::fromTheme(group_id).hasThemeIcon(group_id)) { - group->setIcon(QIcon::fromTheme(group_id)); - } else { - group->setIcon(QIcon::fromTheme(iconName)); - } - - connect(m_changeTheme, &QGSettings::changed, this, [=] (const QString &key) { - if (key=="iconThemeName") { - sleep(1); - if (QIcon::fromTheme(group_id).hasThemeIcon(group_id)) { - group->setIcon(QIcon::fromTheme(group_id)); - } else { - group->setIcon(QIcon::fromTheme(iconName)); - } - } - }); - /*********************************************/ - -// group->setFixedSize(panel()->panelSize(),panel()->panelSize()); - //group->setFixedSize(40,40); - QString groupDesktopName = "/usr/share/applications/" + group_id + ".desktop"; - bool isNeedAddNewWidget = true; - for (auto it = m_vBtn.begin(); it!=m_vBtn.end(); ++it) { - UKUITaskGroup *pQuickBtn = *it; - if(pQuickBtn->m_fileName == groupDesktopName - &&(m_layout->indexOf(pQuickBtn) >= 0 )) { - m_layout->addWidget(group); - m_layout->moveItem(m_layout->indexOf(group), m_layout->indexOf(pQuickBtn)); - pQuickBtn->setHidden(true); - isNeedAddNewWidget = false; - group->m_existSameQckBtn = true; - pQuickBtn->m_existSameQckBtn = true; - group->wl_widgetUpdateTitle(caption); -// group->setStyle(new CustomStyle("taskbutton")); - group->setToolButtonsStyle(m_buttonStyle); - group->setQckLchBtn(pQuickBtn); - group->m_fileName = groupDesktopName; - break; - } - } - - if (isNeedAddNewWidget) { - m_layout->addWidget(group); - group->wl_widgetUpdateTitle(caption); -// group->setStyle(new CustomStyle("taskbutton")); - group->setToolButtonsStyle(m_buttonStyle); - } - } - - m_knownWindows[window] = group; - group->wl_addWindow(window); -} - - -QString UKUITaskBar::captionExchange(QString str) -{ - QString temp_group_id=str; - QStringList strList = temp_group_id.split(" "); - QString group_id = strList[0]; - QStringList video_list; - if (m_androidIconHash.keys().contains(temp_group_id)) { - group_id=m_androidIconHash.value(temp_group_id); - } else { - video_list<<"影音"<<"Video"; - if(video_list.contains(group_id)) group_id ="kylin-video"; - else group_id="application-x-desktop"; - } - return group_id; -} - -QHash<QString,QString> UKUITaskBar::matchAndroidIcon() -{ - QHash<QString,QString> hash; - printf("*************\n"); - QFile file("/usr/share/ukui/ukui-panel/plugin-taskbar/name-icon.match"); - if (!file.open(QIODevice::ReadOnly)) { - qDebug()<<"Read FIle failed"; - } - while (!file.atEnd()) { - QByteArray line= file.readLine(); - QString str=file.readLine(); - str.section('picture',1,1).trimmed().toStdString(); - str.simplified(); - QString str_name = str.section(QRegExp("[;]"),0,0); - str_name = str_name.simplified(); - str_name = str_name.remove("name="); - - QString str_icon = str.section(QRegExp("[;]"),1,1); - str_icon = str_icon.simplified(); - str_icon = str_icon.remove("icon="); - - hash.insert(str_name,str_icon); - } - - return hash; -} diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbar.h ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbar.h --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbar.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbar.h 2023-05-22 14:06:12.000000000 +0800 @@ -60,6 +60,7 @@ #include <QToolButton> #include <QScrollArea> #include <QScrollBar> +#include <windowmanager/windowmanager.h> #define DESKTOP_FILE_PATH "/usr/share/applications/" #define ANDROID_DESKTOP_FILE_PATH "/.local/share/applications/" @@ -80,8 +81,8 @@ class QSignalMapper; class UKUITaskButton; class ElidedButtonStyle; -class UKUITaskBarIcon; +using namespace kdk; namespace UKUi { class GridLayout; } @@ -101,120 +102,102 @@ explicit UKUITaskBar(IUKUIPanelPlugin *plugin, QWidget* parent = 0); virtual ~UKUITaskBar(); - void realign(); + void realignSdk(); Qt::ToolButtonStyle buttonStyle() const { return m_buttonStyle; } - int buttonWidth() const { return m_buttonWidth; } - bool closeOnMiddleClick() const { return m_closeOnMiddleClick; } - bool raiseOnCurrentDesktop() const { return m_raiseOnCurrentDesktop; } - bool isShowOnlyOneDesktopTasks() const { return m_showOnlyOneDesktopTasks; } int showDesktopNum() const { return m_showDesktopNum; } - bool getCpuInfoFlg() const { return m_cpuInfoFlg; } - bool isShowOnlyCurrentScreenTasks() const { return m_showOnlyCurrentScreenTasks; } - bool isShowOnlyMinimizedTasks() const { return m_showOnlyMinimizedTasks; } - bool isAutoRotate() const { return m_autoRotate; } bool isGroupingEnabled() const { return m_groupingEnabled; } - bool isShowGroupOnHover() const { return m_showGroupOnHover; } - bool isIconByClass() const { return m_iconByClass; } - void setShowGroupOnHover(bool bFlag); inline IUKUIPanel * panel() const { return m_plugin->panel(); } inline IUKUIPanelPlugin * plugin() const { return m_plugin; } - inline UKUITaskBarIcon* fetchIcon()const{return m_taskbarIcon;} - void pubAddButton(QuickLaunchAction* action) { addButton(action); } - void pubSaveSettings() { saveSettings(); } - - //////////////////////////////////////////////// - /// \brief quicklaunch func - /// - - int indexOfButton(UKUITaskGroup *button) const; + ///quicklaunch func int countOfButtons() const; //virtual QLayoutItem *takeAt(int index) = 0; - void saveSettings(); + void saveSdkSettings(); void refreshQuickLaunch(); friend class FilectrlAdaptor; QStringList m_ignoreWindow; signals: - void buttonRotationRefreshed(bool autoRotate, IUKUIPanel::Position position); void buttonStyleRefreshed(Qt::ToolButtonStyle buttonStyle); - void refreshIconGeometry(); void showOnlySettingChanged(); - void iconByClassChanged(); - void popupShown(UKUITaskGroup* sender); void sendToUkuiDEApp(void); //quicklaunch - void setSizeOfTaskbarButton(int _size); + void refreshIconGeometry(); protected: - virtual void dragEnterEvent(QDragEnterEvent * event); - virtual void dragMoveEvent(QDragMoveEvent * event); void enterEvent(QEvent *); void leaveEvent(QEvent *); - void paintEvent(QPaintEvent *); void mousePressEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *e); - void dropEvent(QDropEvent *e); private slots: void refreshTaskList(); void refreshButtonRotation(); void refreshPlaceholderVisibility(); - void groupBecomeEmptySlot(); - void saveSettingsSlot(); - void onWindowChanged(WId window, NET::Properties prop, NET::Properties2 prop2); - void onWindowAdded(WId window); - void onWindowRemoved(WId window); - void activateTask(int pos); + void groupSdkBecomeEmptySlot(); + void saveSdkSettingsSlot(); + void onWindowChanged(const WindowId& window); + void onWindowAdded(const WindowId& window); + void onWindowRemoved(const WindowId& window); + void activateSdkTask(int pos); void onDesktopChanged(); //////////////////////////// /// quicklaunch slots - /// bool checkButton(QuickLaunchAction* action); void removeButton(QuickLaunchAction* action); void removeButton(QString exec); - void buttonDeleted(); + void buttonSdkDeleted(); void removeFromTaskbar(QString arg); void switchButtons(UKUITaskGroup *dst_button, UKUITaskGroup *src_button); QString readFile(const QString &filename); void addToTaskbar(QString arg); + void addSdkToTaskbar(QString arg); - void wlKwinSigHandler(quint32 wl_winId, int opNo, QString wl_iconName, QString wl_caption); void readPanelConfig(bool isTabletMode); + void securityControlApps(QString mode); + private: typedef QMap<WId, UKUITaskGroup*> windowMap_t; + typedef QMap<qint32, UKUITaskGroup*> windowSdkMap_t; private: - void addWindow(WId window); - void addButton(QuickLaunchAction* action); - windowMap_t::iterator removeWindow(windowMap_t::iterator pos); + void addWindow(const WindowId& window); + void addSdkButton(QuickLaunchAction* action); + windowSdkMap_t::iterator removeWindow(windowSdkMap_t::iterator pos); void buttonMove(UKUITaskGroup * dst, UKUITaskGroup * src, QPoint const & pos); void doInitGroupButton(QString sname); - void initRelationship(); - + //黑白名单函数 + void addButtonForQuicklanch(QList<QMap<QString, QVariant> > apps); + void removeBlackListApp(); + void addWhiteListApp(); + + QString m_mode; + QDBusInterface *m_interface; + QStringList m_controlAppList; enum TaskStatus{NORMAL, HOVER, PRESS}; TaskStatus m_taskStatus; - //////////////////////////////////// /// quicklaunch parameter - QVector<UKUITaskGroup*> m_vBtn; QGSettings *m_settings; - QWidget *m_tmpWidget; + QLabel *m_beginMaskLabel; + QLabel *m_endMaskLabel; + QImage *m_maskImg; + void initMaskUI(); + void setMaskPostion(); private: - QMap<WId, UKUITaskGroup*> m_knownWindows; //!< Ids of known windows (mapping to buttons/groups) - QList <WId> m_swid; + QMap<qint32, UKUITaskGroup*> m_knownSdkWindows; + QList <qint32> m_sdkSwid; UKUi::GridLayout *m_layout; -// QList<GlobalKeyShortcut::Action*> mKeys; QSignalMapper *m_signalMapper; // Settings @@ -222,20 +205,11 @@ int m_buttonWidth; int m_buttonHeight; - bool m_cpuInfoFlg = true; - bool m_closeOnMiddleClick; - bool m_raiseOnCurrentDesktop; - bool m_showOnlyOneDesktopTasks; int m_showDesktopNum; - bool m_showOnlyCurrentScreenTasks; - bool m_showOnlyMinimizedTasks; bool m_autoRotate; bool m_groupingEnabled; - bool m_showGroupOnHover; - bool m_iconByClass; - bool m_cycleOnWheelScroll; //!< flag for processing the wheelEvent - bool acceptWindow(WId window) const; + bool acceptWindow(const WindowId& window) const; void setButtonStyle(Qt::ToolButtonStyle buttonStyle); void settingsChanged(); QList<QMap<QString, QVariant> > copyQuicklaunchConfig(); @@ -252,15 +226,9 @@ IUKUIPanelPlugin *m_plugin; LeftAlignedTextStyle *m_style; - UKUITaskBarIcon *m_taskbarIcon; QWidget *m_allFrame; QWidget *m_placeHolder; QGSettings *m_changeTheme; - QHash<QString,QString> m_androidIconHash; - - QHash<QString,QString> matchAndroidIcon(); - QString captionExchange(QString str); - void addWindow_wl(QString iconName, QString caption, WId window); public slots: void WindowAddtoTaskBar(QString arg); diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbarplugin.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbarplugin.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbarplugin.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbarplugin.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -44,7 +44,7 @@ void UKUITaskBarPlugin::realign() { - m_taskBar->realign(); + m_taskBar->realignSdk(); } void UKUITaskBarPlugin::translator() diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbutton.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbutton.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbutton.cpp 2022-05-11 17:59:59.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbutton.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -27,58 +27,11 @@ * END_COMMON_COPYRIGHT_HEADER */ #include "ukuitaskbutton.h" -#include "ukuitaskgroup.h" #include "ukuitaskbar.h" - -//#include <UKUi/Settings> #include "../panel/common/ukuisettings.h" -#include <QDebug> -#include <QTimer> -#include <QMenu> -#include <QAction> -#include <QContextMenuEvent> -#include <QPainter> -#include <QDrag> -#include <QMouseEvent> -#include <QMimeData> -#include <QApplication> -#include <QDragEnterEvent> -#include <QStylePainter> -#include <QStyleOptionToolButton> -#include <QDesktopWidget> - -#include <unistd.h> -#include "ukuitaskgroup.h" -#include "ukuitaskbar.h" -#include "../panel/customstyle.h" -#include <KWindowSystem/KWindowSystem> -// Necessary for closeApplication() -#include <KWindowSystem/NETWM> #include <QtX11Extras/QX11Info> -#include "../panel/iukuipanelplugin.h" -#include <QAction> -#include <QDrag> -#include <QMenu> -#include <QMouseEvent> -#include <QStylePainter> -#include <QStyleOptionToolButton> -#include <QApplication> -#include <XdgIcon> -#include <string> - -#define UKUI_PANEL_SETTINGS "org.ukui.panel.settings" -#define PANELPOSITION "panelposition" - -#define PANEL_SETTINGS "org.ukui.panel.settings" -#define PANEL_SIZE_KEY "panelsize" -#define ICON_SIZE_KEY "iconsize" -#define PANEL_POSITION_KEY "panelposition" - -#define ORG_UKUI_STYLE "org.ukui.style" -#define STYLE_NAME "styleName" - bool UKUITaskButton::m_draggging = false; /************************************************ @@ -96,68 +49,76 @@ /************************************************ ************************************************/ -UKUITaskButton::UKUITaskButton(QString appName,const WId window, UKUITaskBar * taskbar, QWidget *parent) : +UKUITaskButton::UKUITaskButton(const QString & groupName, const WindowId& window, UKUITaskBar * taskbar, QWidget *parent) : QToolButton(parent), - m_window(window), - m_appName(appName), + m_sdkWindow(window), m_urgencyHint(false), m_origin(Qt::TopLeftCorner), - m_drawPixmap(false), m_parentTaskBar(taskbar), m_plugin(m_parentTaskBar->plugin()), m_DNDTimer(new QTimer(this)) { Q_ASSERT(taskbar); m_taskButtonStatus=NORMAL; - setCheckable(true); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setMinimumWidth(1); setMinimumHeight(1); - setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + setToolButtonStyle(Qt::ToolButtonIconOnly); setAcceptDrops(true); - setProperty("useButtonPalette",true); - setAutoRaise(true); - setSystemStyle(); - const QByteArray id_style(ORG_UKUI_STYLE); - if (QGSettings::isSchemaInstalled(id_style)) { - m_styleGSettings = new QGSettings(id_style); - connect(m_styleGSettings, &QGSettings::changed, this, [=] (const QString &key) { - if (key==STYLE_NAME) { - setSystemStyle(); - } - }); - } - updateText(); - updateIcon(); + updateSdkText(); + updateSdkIcon(); m_DNDTimer->setSingleShot(true); m_DNDTimer->setInterval(700); - connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateWithDraggable())); - connect(UKUi::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(updateIcon())); - connect(m_parentTaskBar, &UKUITaskBar::iconByClassChanged, this, &UKUITaskButton::updateIcon); + connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateSdkWithDraggable())); + connect(UKUi::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(updateSdkIcon())); const QByteArray id(PANEL_SETTINGS); m_gsettings = new QGSettings(id); connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key) { if (key == PANEL_SIZE_KEY) { - updateIcon(); + updateSdkIcon(); } }); } -UKUITaskButton::UKUITaskButton(QString iconName,QString caption, const WId window, UKUITaskBar * taskbar, QWidget *parent) : - QToolButton(parent), - m_iconName(iconName), - m_caption(caption), - m_window(window), - m_parentTaskBar(taskbar), - m_plugin(m_parentTaskBar->plugin()) +UKUITaskButton::UKUITaskButton(QuickLaunchAction * act, IUKUIPanelPlugin * plugin, QWidget * parent) + : QToolButton(parent), + m_act(act), + m_plugin(plugin) { + m_DNDTimer = new QTimer(this); + m_statFlag = false; setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - m_isWinActivate = true; - m_icon = QIcon::fromTheme("application-x-desktop"); + /*设置快速启动栏的按键不接受焦点*/ + setFocusPolicy(Qt::NoFocus); + setAutoRaise(true); + + setDefaultAction(m_act); + m_act->setParent(this); + + /*设置快速启动栏的菜单项*/ + const QByteArray id(PANEL_SETTINGS); + m_gsettingsQuickLaunch = new QGSettings(id); + modifyQuicklaunchMenuAction(true); + connect(m_gsettingsQuickLaunch, &QGSettings::changed, this, [=] (const QString &key){ + if (key == PANEL_POSITION_KEY) { + modifyQuicklaunchMenuAction(true); + } + }); + + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(customContextMenuRequestedSlot(const QPoint&))); + m_DNDTimer->setSingleShot(true); + m_DNDTimer->setInterval(700); + connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateSdkWithDraggable())); + m_fileName = act->m_settingsMap["desktop"]; + this->setStyle(new CustomStyle()); + repaint(); + } /************************************************ @@ -166,48 +127,34 @@ { } -/************************************************ - - ************************************************/ -void UKUITaskButton::updateText() +void UKUITaskButton::updateSdkText() { - KWindowInfo info(m_window, NET::WMVisibleName | NET::WMName); - QString title = info.visibleName().isEmpty() ? info.name() : info.visibleName(); + QString title = WindowManager::getWindowTitle(m_sdkWindow); setText(title.replace("&", "&&")); setToolTip(title); } -void UKUITaskButton::setLeaderWindow(WId leaderWindow) { - m_window = leaderWindow; +void UKUITaskButton::setLeaderWindow(const WindowId& leaderWindow) { + m_sdkWindow = leaderWindow; } /* int devicePixels = m_plugin->panel()->iconSize() * devicePixelRatioF()是由ico =KWindowSystem:ico(mwindow)更改的 * 目的是为了能够显示正确的application-x-desktop的图标的大小 * */ -void UKUITaskButton::updateIcon() + +void UKUITaskButton::updateSdkIcon() { - if (m_appName == QString("emo-system-ShellMethods") || m_appName == QString("Qq")) { - sleep(1); - } QIcon ico; int mIconSize=m_plugin->panel()->iconSize(); - if (m_parentTaskBar->isIconByClass()) { - ico = QIcon::fromTheme(QString::fromUtf8(KWindowInfo{m_window, 0, NET::WM2WindowClass}.windowClassClass()).toLower()); - } if (ico.isNull()) { -#if QT_VERSION >= 0x050600 - int devicePixels = mIconSize * devicePixelRatioF(); -#else - int devicePixels = mIconSize * devicePixelRatio(); -#endif - ico = KWindowSystem::icon(m_window, devicePixels, devicePixels); + ico = WindowManager::getWindowIcon(m_sdkWindow); } if (m_icon.isNull()) { m_icon = QIcon::fromTheme("application-x-desktop"); } setIcon(ico.isNull() ? m_icon : ico); - setIconSize(QSize(mIconSize,mIconSize)); + setIconSize(QSize(mIconSize, mIconSize)); } void UKUITaskButton::setGroupIcon(QIcon ico) @@ -215,19 +162,20 @@ m_icon = ico; } -/************************************************ - - ************************************************/ void UKUITaskButton::refreshIconGeometry(QRect const & geom) { + QString platform = QGuiApplication::platformName(); + if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) { + return; + } NETWinInfo info(QX11Info::connection(), - windowId(), + m_sdkWindow.toInt(), (WId) QX11Info::appRootWindow(), NET::WMIconGeometry, 0); NETRect const curr = info.iconGeometry(); if (curr.pos.x != geom.x() || curr.pos.y != geom.y() - || curr.size.width != geom.width() || curr.size.height != geom.height()) { + || curr.size.width != geom.width() || curr.size.height != geom.height()) { NETRect nrect; nrect.pos.x = geom.x(); nrect.pos.y = geom.y(); @@ -287,10 +235,7 @@ if (Qt::LeftButton == b) { m_dragStartPosition = event->pos(); - } else if (m_statFlag && Qt::MidButton == b && parentTaskBar()->closeOnMiddleClick()) { - closeApplication(); } - QToolButton::mousePressEvent(event); } @@ -364,380 +309,63 @@ QAbstractButton::mouseMoveEvent(event); } -/************************************************ - - ************************************************/ -bool UKUITaskButton::isApplicationHidden() const -{ - KWindowInfo info(m_window, NET::WMState); - return (info.state() & NET::Hidden); -} - -/************************************************ - - ************************************************/ -bool UKUITaskButton::isApplicationActive() const -{ - return KWindowSystem::activeWindow() == m_window; -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::activateWithDraggable() +void UKUITaskButton::activateSdkWithDraggable() { // raise app in any time when there is a drag // in progress to allow drop it into an app + qDebug()<<Q_FUNC_INFO<<m_sdkWindow<<WindowManager::getWindowTitle(m_sdkWindow); if (m_statFlag) { - raiseApplication(); - KWindowSystem::forceActiveWindow(m_window); + raiseSdkApplication(); + WindowManager::activateWindow(m_sdkWindow); } } /************************************************ ************************************************/ -void UKUITaskButton::raiseApplication() +void UKUITaskButton::raiseSdkApplication() { - KWindowInfo info(m_window, NET::WMDesktop | NET::WMState | NET::XAWMState); - if (parentTaskBar()->raiseOnCurrentDesktop() && info.isMinimized()) { - KWindowSystem::setOnDesktop(m_window, KWindowSystem::currentDesktop()); - } else { - int winDesktop = info.desktop(); - if (KWindowSystem::currentDesktop() != winDesktop) { - KWindowSystem::setCurrentDesktop(winDesktop); - } - } - KWindowSystem::activateWindow(m_window); - - setUrgencyHint(false); + qDebug()<<Q_FUNC_INFO<<m_sdkWindow<<WindowManager::getWindowTitle(m_sdkWindow); + WindowManager::activateWindow(m_sdkWindow); + setSdkUrgencyHint(false); } -/************************************************ - - ************************************************/ -void UKUITaskButton::minimizeApplication() +void UKUITaskButton::minimizeSdkApplication() { - KWindowSystem::minimizeWindow(m_window); + WindowManager::minimizeWindow(m_sdkWindow); } -/************************************************ - - ************************************************/ -void UKUITaskButton::maximizeApplication() -{ - QAction* act = qobject_cast<QAction*>(sender()); - if (!act) { - return; - } - - int state = act->data().toInt(); - switch (state) { - case NET::MaxHoriz: - KWindowSystem::setState(m_window, NET::MaxHoriz); - break; - - case NET::MaxVert: - KWindowSystem::setState(m_window, NET::MaxVert); - break; - - default: - KWindowSystem::setState(m_window, NET::Max); - break; - } - - if (!isApplicationActive()) { - raiseApplication(); - } -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::deMaximizeApplication() -{ - KWindowSystem::clearState(m_window, NET::Max); - - if (!isApplicationActive()) { - raiseApplication(); - } -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::shadeApplication() -{ - KWindowSystem::setState(m_window, NET::Shaded); -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::unShadeApplication() -{ - KWindowSystem::clearState(m_window, NET::Shaded); -} - -/************************************************ - - ************************************************/ void UKUITaskButton::closeApplication() { // FIXME: Why there is no such thing in KWindowSystem?? - NETRootInfo(QX11Info::connection(), NET::CloseWindow).closeWindowRequest(m_window); -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::setApplicationLayer() -{ - QAction* act = qobject_cast<QAction*>(sender()); - if (!act) { - return; - } - - int layer = act->data().toInt(); - switch(layer) { - case NET::KeepAbove: - KWindowSystem::clearState(m_window, NET::KeepBelow); - KWindowSystem::setState(m_window, NET::KeepAbove); - break; - - case NET::KeepBelow: - KWindowSystem::clearState(m_window, NET::KeepAbove); - KWindowSystem::setState(m_window, NET::KeepBelow); - break; - - default: - KWindowSystem::clearState(m_window, NET::KeepBelow); - KWindowSystem::clearState(m_window, NET::KeepAbove); - break; - } + WindowManager::closeWindow(m_sdkWindow); } -/************************************************ - - ************************************************/ -void UKUITaskButton::moveApplicationToDesktop() +void UKUITaskButton::setUrgencyHint(bool set) { - QAction* act = qobject_cast<QAction*>(sender()); - if (!act) { - return; - } - - bool ok; - int desk = act->data().toInt(&ok); - - if (!ok) { + if (m_urgencyHint == set) { return; } - KWindowSystem::setOnDesktop(m_window, desk); -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::moveApplication() -{ - KWindowInfo info(m_window, NET::WMDesktop); - if (!info.isOnCurrentDesktop()) { - KWindowSystem::setCurrentDesktop(info.desktop()); - } - if (isMinimized()) { - KWindowSystem::unminimizeWindow(m_window); - } - KWindowSystem::forceActiveWindow(m_window); - const QRect& g = KWindowInfo(m_window, NET::WMGeometry).geometry(); - int X = g.center().x(); - int Y = g.center().y(); - QCursor::setPos(X, Y); - NETRootInfo(QX11Info::connection(), NET::WMMoveResize).moveResizeRequest(m_window, X, Y, NET::Move); -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::resizeApplication() -{ - KWindowInfo info(m_window, NET::WMDesktop); - if (!info.isOnCurrentDesktop()) { - KWindowSystem::setCurrentDesktop(info.desktop()); - } - if (isMinimized()) { - KWindowSystem::unminimizeWindow(m_window); - } - KWindowSystem::forceActiveWindow(m_window); - const QRect& g = KWindowInfo(m_window, NET::WMGeometry).geometry(); - int X = g.bottomRight().x(); - int Y = g.bottomRight().y(); - QCursor::setPos(X, Y); - NETRootInfo(QX11Info::connection(), NET::WMMoveResize).moveResizeRequest(m_window, X, Y, NET::BottomRight); -} - -/************************************************ - - ************************************************/ -void UKUITaskButton::contextMenuEvent(QContextMenuEvent* event) -{ - if (!m_statFlag) { - return; - } - if (event->modifiers().testFlag(Qt::ControlModifier)) { - event->ignore(); - return; + if (!set) { + KWindowSystem::demandAttention(m_window, false); } - KWindowInfo info(m_window, 0, NET::WM2AllowedActions); - unsigned long state = KWindowInfo(m_window, NET::WMState).state(); - - QMenu * menu = new QMenu(tr("Application")); - menu->setAttribute(Qt::WA_DeleteOnClose); - QAction* a; - - /* KDE menu ******* - - + To &Desktop > - + &All Desktops - + --- - + &1 Desktop 1 - + &2 Desktop 2 - + &To Current Desktop - &Move - Re&size - + Mi&nimize - + Ma&ximize - + &Shade - Ad&vanced > - Keep &Above Others - Keep &Below Others - Fill screen - &Layer > - Always on &top - &Normal - Always on &bottom - --- - + &Close - */ - - /********** Desktop menu **********/ - int deskNum = KWindowSystem::numberOfDesktops(); - if (deskNum > 1) { - int winDesk = KWindowInfo(m_window, NET::WMDesktop).desktop(); - QMenu* deskMenu = menu->addMenu(tr("To &Desktop")); - - a = deskMenu->addAction(tr("&All Desktops")); - a->setData(NET::OnAllDesktops); - a->setEnabled(winDesk != NET::OnAllDesktops); - connect(a, SIGNAL(triggered(bool)), this, SLOT(moveApplicationToDesktop())); - deskMenu->addSeparator(); - - for (int i = 0; i < deskNum; ++i) { - a = deskMenu->addAction(tr("Desktop &%1").arg(i + 1)); - a->setData(i + 1); - a->setEnabled(i + 1 != winDesk); - connect(a, SIGNAL(triggered(bool)), this, SLOT(moveApplicationToDesktop())); - } - - int curDesk = KWindowSystem::currentDesktop(); - a = menu->addAction(tr("&To Current Desktop")); - a->setData(curDesk); - a->setEnabled(curDesk != winDesk); - connect(a, SIGNAL(triggered(bool)), this, SLOT(moveApplicationToDesktop())); - } - - /********** Move/Resize **********/ - menu->addSeparator(); - a = menu->addAction(tr("&Move")); - a->setEnabled(info.actionSupported(NET::ActionMove) && !(state & NET::Max) && !(state & NET::FullScreen)); - connect(a, &QAction::triggered, this, &UKUITaskButton::moveApplication); - a = menu->addAction(tr("Resi&ze")); - a->setEnabled(info.actionSupported(NET::ActionResize) && !(state & NET::Max) && !(state & NET::FullScreen)); - connect(a, &QAction::triggered, this, &UKUITaskButton::resizeApplication); - - /********** State menu **********/ - menu->addSeparator(); - - a = menu->addAction(tr("Ma&ximize")); - a->setEnabled(info.actionSupported(NET::ActionMax) && (!(state & NET::Max) || (state & NET::Hidden))); - a->setData(NET::Max); - connect(a, SIGNAL(triggered(bool)), this, SLOT(maximizeApplication())); - - if (event->modifiers() & Qt::ShiftModifier) { - a = menu->addAction(tr("Maximize vertically")); - a->setEnabled(info.actionSupported(NET::ActionMaxVert) && !((state & NET::MaxVert) || (state & NET::Hidden))); - a->setData(NET::MaxVert); - connect(a, SIGNAL(triggered(bool)), this, SLOT(maximizeApplication())); - - a = menu->addAction(tr("Maximize horizontally")); - a->setEnabled(info.actionSupported(NET::ActionMaxHoriz) && !((state & NET::MaxHoriz) || (state & NET::Hidden))); - a->setData(NET::MaxHoriz); - connect(a, SIGNAL(triggered(bool)), this, SLOT(maximizeApplication())); - } - - a = menu->addAction(tr("&Restore")); - a->setEnabled((state & NET::Hidden) || (state & NET::Max) || (state & NET::MaxHoriz) || (state & NET::MaxVert)); - connect(a, SIGNAL(triggered(bool)), this, SLOT(deMaximizeApplication())); - - a = menu->addAction(tr("Mi&nimize")); - a->setEnabled(info.actionSupported(NET::ActionMinimize) && !(state & NET::Hidden)); - connect(a, SIGNAL(triggered(bool)), this, SLOT(minimizeApplication())); - - if (state & NET::Shaded) { - a = menu->addAction(tr("Roll down")); - a->setEnabled(info.actionSupported(NET::ActionShade) && !(state & NET::Hidden)); - connect(a, SIGNAL(triggered(bool)), this, SLOT(unShadeApplication())); - } else { - a = menu->addAction(tr("Roll up")); - a->setEnabled(info.actionSupported(NET::ActionShade) && !(state & NET::Hidden)); - connect(a, SIGNAL(triggered(bool)), this, SLOT(shadeApplication())); - } - - /********** Layer menu **********/ - menu->addSeparator(); - - QMenu* layerMenu = menu->addMenu(tr("&Layer")); - - a = layerMenu->addAction(tr("Always on &top")); - // FIXME: There is no info.actionSupported(NET::ActionKeepAbove) - a->setEnabled(!(state & NET::KeepAbove)); - a->setData(NET::KeepAbove); - connect(a, SIGNAL(triggered(bool)), this, SLOT(setApplicationLayer())); - - a = layerMenu->addAction(tr("&Normal")); - a->setEnabled((state & NET::KeepAbove) || (state & NET::KeepBelow)); - // FIXME: There is no NET::KeepNormal, so passing 0 - a->setData(0); - connect(a, SIGNAL(triggered(bool)), this, SLOT(setApplicationLayer())); - - a = layerMenu->addAction(tr("Always on &bottom")); - // FIXME: There is no info.actionSupported(NET::ActionKeepBelow) - a->setEnabled(!(state & NET::KeepBelow)); - a->setData(NET::KeepBelow); - connect(a, SIGNAL(triggered(bool)), this, SLOT(setApplicationLayer())); - - /********** Kill menu **********/ - menu->addSeparator(); - a = menu->addAction(QIcon::fromTheme("process-stop"), tr("&Close")); - connect(a, SIGNAL(triggered(bool)), this, SLOT(closeApplication())); - menu->setGeometry(m_parentTaskBar->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), menu->sizeHint())); - m_plugin->willShowWindow(menu); - menu->show(); + m_urgencyHint = set; + setProperty("urgent", set); + style()->unpolish(this); + style()->polish(this); + update(); } -/************************************************ - - ************************************************/ -void UKUITaskButton::setUrgencyHint(bool set) +void UKUITaskButton::setSdkUrgencyHint(bool set) { if (m_urgencyHint == set) { return; } if (!set) { - KWindowSystem::demandAttention(m_window, false); + WindowManager::activateWindow(m_sdkWindow); } m_urgencyHint = set; @@ -762,6 +390,21 @@ return KWindowInfo(m_window,NET::WMState | NET::XAWMState).isMinimized(); } +bool UKUITaskButton::isSdkMinimized() const +{ + WindowInfo info = WindowManager::getwindowInfo(m_sdkWindow); + qDebug()<<Q_FUNC_INFO<<info.isMinimized(); + return info.isMinimized(); +} + +bool UKUITaskButton::isSdkFocusState() const +{ + WindowInfo info = WindowManager::getwindowInfo(m_sdkWindow); + qDebug()<<Q_FUNC_INFO<<info.isActive(); + return info.isActive(); +} + + Qt::Corner UKUITaskButton::origin() const { return m_origin; @@ -818,73 +461,6 @@ return; } -bool UKUITaskButton::hasDragAndDropHover() const -{ - return m_DNDTimer->isActive(); -} - - - -UKUITaskButton::UKUITaskButton(QuickLaunchAction * act, IUKUIPanelPlugin * plugin, QWidget * parent) - : QToolButton(parent), - m_act(act), - m_plugin(plugin) -{ - m_DNDTimer = new QTimer(this); - m_statFlag = false; - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - /*设置快速启动栏的按键不接受焦点*/ - setFocusPolicy(Qt::NoFocus); - setAutoRaise(true); - m_quickLanuchStatus = NORMAL; - - setDefaultAction(m_act); - m_act->setParent(this); - - /*设置快速启动栏的菜单项*/ - const QByteArray id(UKUI_PANEL_SETTINGS); - m_gsettingsQuickLaunch = new QGSettings(id); - modifyQuicklaunchMenuAction(true); - connect(m_gsettingsQuickLaunch, &QGSettings::changed, this, [=] (const QString &key){ - if (key==PANELPOSITION) { - modifyQuicklaunchMenuAction(true); - } - }); - - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), - this, SLOT(this_customContextMenuRequested(const QPoint&))); - m_DNDTimer->setSingleShot(true); - m_DNDTimer->setInterval(700); - connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateWithDraggable())); - m_fileName=act->m_settingsMap["desktop"]; -// this->setStyle(new CustomStyle()); - setProperty("useButtonPalette",true); - setAutoRaise(true); - setSystemStyle(); - const QByteArray id_style(ORG_UKUI_STYLE); - if (QGSettings::isSchemaInstalled(id_style)) { - m_styleGSettings = new QGSettings(id_style); - connect(m_styleGSettings, &QGSettings::changed, this, [=] (const QString &key) { - if (key==STYLE_NAME) { - setSystemStyle(); - } - }); - } - repaint(); - -} - -void UKUITaskButton::setSystemStyle() -{ - QPalette pal = this->palette(); - QColor col = pal.color(QPalette::Active, QPalette::BrightText); - col.setAlphaF(0.13); - pal.setColor(QPalette::Button, col); - this->setPalette(pal); -} - - QHash<QString,QString> UKUITaskButton::settingsMap() { Q_ASSERT(m_act); @@ -892,7 +468,7 @@ } /*与鼠标右键的选项有关*/ -void UKUITaskButton::this_customContextMenuRequested(const QPoint & pos) +void UKUITaskButton::customContextMenuRequestedSlot(const QPoint & pos) { m_plugin->willShowWindow(m_menu); m_menu->popup(m_plugin->panel()->calculatePopupWindowPos(mapToGlobal({0, 0}), m_menu->sizeHint()).topLeft()); @@ -901,14 +477,13 @@ /*调整快速启动栏的菜单项*/ void UKUITaskButton::modifyQuicklaunchMenuAction(bool direction) { - m_deleteAct = new QAction(QIcon::fromTheme("ukui-unfixed"), tr("delete from quicklaunch"), this); + m_deleteAct = new QAction(QIcon::fromTheme("ukui-unfixed-symbolic"), tr("delete from quicklaunch"), this); connect(m_deleteAct, SIGNAL(triggered()), this, SLOT(selfRemove())); //addAction(m_deleteAct); - m_menu = new QuicklaunchMenu(); + m_menu = new QMenu(this); m_menu->addAction(m_act); m_menu->addActions(m_act->addtitionalActions()); m_menu->addSeparator(); - m_menu->addSeparator(); m_menu->addAction(m_deleteAct); } @@ -917,9 +492,9 @@ emit buttonDeleted(); } - -QuicklaunchMenu::QuicklaunchMenu() { } - -QuicklaunchMenu::~QuicklaunchMenu() { } - -void QuicklaunchMenu::contextMenuEvent(QContextMenuEvent *) { } +void UKUITaskButton::setTaskButtonVisible(bool visible) +{ + if(!visible) { + this->setFixedSize(0,0); + } +} diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbutton.h ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbutton.h --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskbutton.h 2022-05-11 17:35:59.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskbutton.h 2023-05-22 14:06:12.000000000 +0800 @@ -29,22 +29,18 @@ #ifndef UKUITASKBUTTON_H #define UKUITASKBUTTON_H - -#include <QGSettings/QGSettings> -#include <QToolButton> -#include <QProxyStyle> -#include <QLabel> +//panel #include "../panel/iukuipanel.h" -//#include <QWinThumbnailToolBar> -#include <QtX11Extras/qtx11extrasversion.h> - #include "quicklaunchaction.h" -#include <QMimeData> #include "../panel/customstyle.h" -#include <QStyleOption> -#include <QGSettings> -#include <QPainter> -#include <QMenu> +#include "../panel/common/common.h" +//Qt +#include <QGSettings/QGSettings> +#include <QToolButton> +#include <QMimeData> +//SDK +#include <windowmanager/windowmanager.h> +using namespace kdk; class QPainter; class QPalette; @@ -52,15 +48,7 @@ class UKUITaskGroup; class UKUITaskBar; class IUKUIPanelPlugin; -class QuicklaunchMenu:public QMenu -{ -public: - QuicklaunchMenu(); - ~QuicklaunchMenu(); -protected: - void contextMenuEvent(QContextMenuEvent*); -}; class LeftAlignedTextStyle : public QProxyStyle { using QProxyStyle::QProxyStyle; @@ -79,24 +67,23 @@ Q_PROPERTY(Qt::Corner origin READ origin WRITE setOrigin) public: - explicit UKUITaskButton(QString appName,const WId window, UKUITaskBar * taskBar, QWidget *parent = 0); - explicit UKUITaskButton(QString iconName, QString caption, const WId window, UKUITaskBar * taskbar, QWidget *parent = 0); + explicit UKUITaskButton(const QString & groupName, const WindowId& window, UKUITaskBar * taskBar, QWidget *parent = 0); UKUITaskButton(QuickLaunchAction * act, IUKUIPanelPlugin * plugin, QWidget* parent = 0); virtual ~UKUITaskButton(); - bool isApplicationHidden() const; - bool isApplicationActive() const; - WId windowId() const { return m_window; } + WindowId sdkWindowId() const { return m_sdkWindow; } bool hasUrgencyHint() const { return m_urgencyHint; } void setUrgencyHint(bool set); - + void setSdkUrgencyHint(bool set); bool isOnDesktop(int desktop) const; bool isOnCurrentScreen() const; bool isMinimized() const; - void updateText(); - void setLeaderWindow(WId leaderWindow); - bool isLeaderWindow(WId compare) { return m_window == compare; } + bool isSdkMinimized() const; + bool isSdkFocusState() const; + void updateSdkText(); + void setLeaderWindow(const WindowId& leaderWindow); + bool isLeaderWindow(const WindowId& compare) { return m_sdkWindow == compare; } Qt::Corner origin() const; virtual void setAutoRotation(bool value, IUKUIPanel::Position position); @@ -107,42 +94,24 @@ static QString mimeDataFormat() { return QLatin1String("ukui/UKUITaskButton"); } /*! \return true if this buttom received DragEnter event (and no DragLeave event yet) * */ - bool hasDragAndDropHover() const; - ///////////////////////////////// QHash<QString,QString> settingsMap(); QString m_fileName; - QString m_file; - QString m_name; - QString m_exec; - - void toDomodifyQuicklaunchMenuAction(bool direction) { modifyQuicklaunchMenuAction(direction);} - - bool m_isWinActivate; //1为激活状态,0为隐藏状态 - QString m_iconName; - QString m_caption; + + void toDoModifyQuicklaunchMenuAction(bool direction) { modifyQuicklaunchMenuAction(direction);} + + inline IUKUIPanelPlugin * plugin() const { return m_plugin; } public slots: - void raiseApplication(); - void minimizeApplication(); - void maximizeApplication(); - void deMaximizeApplication(); - void shadeApplication(); - void unShadeApplication(); + void raiseSdkApplication(); + void minimizeSdkApplication(); void closeApplication(); - void moveApplicationToDesktop(); - void moveApplication(); - void resizeApplication(); - void setApplicationLayer(); void setOrigin(Qt::Corner); - - void updateIcon(); - - ////// - + void updateSdkIcon(); void selfRemove(); - void this_customContextMenuRequested(const QPoint & pos); + void customContextMenuRequestedSlot(const QPoint & pos); void setGroupIcon(QIcon ico); + void setTaskButtonVisible(bool visible); protected: @@ -153,32 +122,25 @@ void mousePressEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); - virtual void contextMenuEvent(QContextMenuEvent *event); void enterEvent(QEvent *); void leaveEvent(QEvent *); void paintEvent(QPaintEvent *); - void setWindowId(WId wid) {m_window = wid;} virtual QMimeData * mimeData(); static bool m_draggging; - inline IUKUIPanelPlugin * plugin() const { return m_plugin; } - - ///////////////////////////////////// - //virtual QMimeData * mimeData(); - private: + enum TaskButtonStatus{NORMAL, HOVER, PRESS}; + bool m_statFlag = true; + bool m_urgencyHint = false; WId m_window; - QString m_appName; - bool m_urgencyHint; + WindowId m_sdkWindow; QPoint m_dragStartPosition; Qt::Corner m_origin; - bool m_drawPixmap; UKUITaskBar * m_parentTaskBar; IUKUIPanelPlugin * m_plugin; - enum TaskButtonStatus{NORMAL, HOVER, PRESS}; TaskButtonStatus m_taskButtonStatus; QIcon m_icon; @@ -186,22 +148,16 @@ // must be activated so that the use can continue dragging to the window QTimer * m_DNDTimer; QGSettings *m_gsettings; - QGSettings *m_styleGSettings; - /////////////////////////////////// QuickLaunchAction *m_act; QAction *m_deleteAct; - QuicklaunchMenu *m_menu; - QPoint m_dragStart; - TaskButtonStatus m_quickLanuchStatus; - CustomStyle m_toolButtonStyle; + QMenu *m_menu; QGSettings *m_gsettingsQuickLaunch; void modifyQuicklaunchMenuAction(bool direction); private slots: - void activateWithDraggable(); - void setSystemStyle(); + void activateSdkWithDraggable(); signals: @@ -209,8 +165,6 @@ void dragging(QObject * dragSource, QPoint const & pos); ////////////////////////////////// void buttonDeleted(); - void switchButtons(UKUITaskButton *from, UKUITaskButton *to); - void t_saveSettings(); }; @@ -230,7 +184,6 @@ private: UKUITaskButton *m_button; }; -//typedef QHash<WId,UKUITaskButton*> UKUITaskButtonHash; -//typedef QHash<WId,QWidget*> UKUITaskButtonHash; +typedef QHash<qint64, UKUITaskButton*> UKUISdkTaskButtonHash; #endif // UKUITASKBUTTON_H diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskclosebutton.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskclosebutton.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskclosebutton.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskclosebutton.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -18,9 +18,9 @@ #include <QDebug> #include "ukuitaskclosebutton.h" #include "../panel/customstyle.h" -UKUITaskCloseButton::UKUITaskCloseButton(const WId window, QWidget *parent): +UKUITaskCloseButton::UKUITaskCloseButton(const WindowId& window, QWidget *parent): QPushButton(parent), - m_window(window) + m_sdkWindow(window) { // this->setStyle(new CustomStyle("closebutton")); this->setIcon(QIcon::fromTheme("window-close-symbolic").pixmap(24,24)); @@ -28,7 +28,6 @@ this->setProperty("isWindowButton",0x02); this->setProperty("useIconHighlightEffect", 0x08); this->setFlat(true); - //connect(parent, &UKUITaskBar::buttonRotationRefreshed, this, &UKUITaskGroup::setAutoRotation); } @@ -41,8 +40,6 @@ // if (Qt::LeftButton == b) // mDragStartPosition = event->pos(); -// else if (Qt::MidButton == b && parentTaskBar()->closeOnMiddleClick()) -// closeApplication(); QPushButton::mousePressEvent(event); } diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskclosebutton.h ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskclosebutton.h --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskclosebutton.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskclosebutton.h 2023-05-22 14:06:12.000000000 +0800 @@ -21,15 +21,17 @@ #include <QPushButton> #include <QMouseEvent> +#include <windowmanager/windowmanager.h> +using namespace kdk; class UKUITaskCloseButton : public QPushButton { Q_OBJECT public: - explicit UKUITaskCloseButton(const WId window, QWidget *parent = 0); + explicit UKUITaskCloseButton(const WindowId& window, QWidget *parent = 0); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); private: - WId m_window; + WindowId m_sdkWindow; signals: void sigClicked(); }; diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskgroup.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskgroup.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskgroup.cpp 2022-05-11 17:47:30.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskgroup.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -1,4 +1,4 @@ -/* BEGIN_COMMON_COPYRIGHT_HEADER +/* BEGIN_COMMON_COPYRIGHT_HEADER * (c)LGPL2+ * * Copyright: 2011 Razor team @@ -28,102 +28,9 @@ * END_COMMON_COPYRIGHT_HEADER */ #include "ukuitaskgroup.h" -#include "ukuitaskbar.h" -#include <QDebug> -#include <QMimeData> -#include <QFocusEvent> -#include <QDragLeaveEvent> -#include <QStringBuilder> -#include <QMenu> -#include <KF5/KWindowSystem/KWindowSystem> -#include <functional> -#include <QProcess> - -#include <QtX11Extras/QX11Info> -#include <X11/Xlib.h> -#include <X11/Xutil.h> - -#include <QLabel> -#include <QScrollBar> - -#include <qmainwindow.h> -#include <QWidget> -#include <QDesktopWidget> -#include <QApplication> -#include "../panel/iukuipanelplugin.h" -#include <QSize> -#include <QScreen> -#include <XdgIcon> #include <XdgDesktopFile> -#include <QMessageBox> -#include "../panel/customstyle.h" -#define UKUI_PANEL_SETTINGS "org.ukui.panel.settings" -#define PANELPOSITION "panelposition" - -#define UKUI_PANEL_DAEMON "org.ukui.panel.daemon" -#define UKUI_PANEL_DAEMON_PATH "/convert/desktopwid" -#define UKUI_PANEL_DAEMON_INTERFACE "org.ukui.panel.daemon" -#define UKUI_PANEL_DAEMON_METHOD "WIDToDesktop" - - -#define WAYLAND_GROUP_HIDE 0 -#define WAYLAND_GROUP_ACTIVATE 1 -#define WAYLAND_GROUP_CLOSE 2 - - -QPixmap qimageFromXImage(XImage* ximage) -{ - QImage::Format format = QImage::Format_ARGB32_Premultiplied; - if (ximage->depth == 24) { - format = QImage::Format_RGB32; - } else if (ximage->depth == 16) { - format = QImage::Format_RGB16; - } - - QImage image = QImage(reinterpret_cast<uchar*>(ximage->data), - ximage->width, ximage->height, - ximage->bytes_per_line, format).copy(); - - // 大端还是小端? - if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && ximage->byte_order == MSBFirst) - || (QSysInfo::ByteOrder == QSysInfo::BigEndian && ximage->byte_order == LSBFirst)) { - - for (int i = 0; i < image.height(); i++) { - if (ximage->depth == 16) { - ushort* p = reinterpret_cast<ushort*>(image.scanLine(i)); - ushort* end = p + image.width(); - while (p < end) { - *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff); - p++; - } - } else { - uint* p = reinterpret_cast<uint*>(image.scanLine(i)); - uint* end = p + image.width(); - while (p < end) { - *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000) - | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff); - p++; - } - } - } - } - - // 修复alpha通道 - if (format == QImage::Format_RGB32) { - QRgb* p = reinterpret_cast<QRgb*>(image.bits()); - for (int y = 0; y < ximage->height; ++y) { - for (int x = 0; x < ximage->width; ++x) - p[x] |= 0xff000000; - p += ximage->bytes_per_line / 4; - } - } - return QPixmap::fromImage(image); -} - -/************************************************ - ************************************************/ UKUITaskGroup::UKUITaskGroup(QuickLaunchAction * act, IUKUIPanelPlugin * plugin, UKUITaskBar * parent) : UKUITaskButton(act, plugin, parent), m_plugin(plugin), @@ -136,92 +43,49 @@ /*设置快速启动栏的按键不接受焦点*/ setFocusPolicy(Qt::NoFocus); setAutoRaise(true); - m_quickLanuchStatus = NORMAL; setDefaultAction(m_act); m_act->setParent(this); /*设置快速启动栏的菜单项*/ - const QByteArray id(UKUI_PANEL_SETTINGS); + const QByteArray id(PANEL_SETTINGS); m_gsettings = new QGSettings(id); - toDomodifyQuicklaunchMenuAction(true); + toDoModifyQuicklaunchMenuAction(true); connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key==PANELPOSITION){ - toDomodifyQuicklaunchMenuAction(true); + if(key == PANEL_POSITION_KEY){ + toDoModifyQuicklaunchMenuAction(true); } }); setContextMenuPolicy(Qt::CustomContextMenu); + setIconSize(QSize(m_plugin->panel()->iconSize(), m_plugin->panel()->iconSize())); - m_fileName=act->m_settingsMap["desktop"]; - m_file = act->m_settingsMap["file"]; - m_exec = act->m_settingsMap["exec"]; - m_name = act->m_settingsMap["name"]; -// this->setStyle(new CustomStyle()); - setProperty("useButtonPalette",true); - setAutoRaise(true); - setSystemStyle(); - const QByteArray id_style(ORG_UKUI_STYLE); - if (QGSettings::isSchemaInstalled(id_style)) { - m_styleGSettings = new QGSettings(id_style); - connect(m_styleGSettings, &QGSettings::changed, this, [=] (const QString &key) { - if (key==STYLE_NAME) { - setSystemStyle(); - } - }); - } + m_fileName = act->m_settingsMap["desktop"]; + this->setStyle(new CustomStyle()); repaint(); } - -UKUITaskGroup::UKUITaskGroup(const QString &groupName, WId window, UKUITaskBar *parent) - : UKUITaskButton(groupName,window, parent, parent), +UKUITaskGroup::UKUITaskGroup(const QString &groupName, const WindowId& window, UKUITaskBar *parent) + : UKUITaskButton(groupName, window, parent, parent), m_groupName(groupName), m_popup(new UKUIGroupPopup(this)), m_preventPopup(false), - m_singleButton(true), m_timer(new QTimer(this)), - m_widget(NULL), - m_parent(parent), - m_isWaylandGroup(false) + m_parent(parent) { Q_ASSERT(parent); - m_scrollArea = NULL; m_taskGroupStatus = NORMAL; - initDesktopFileName(window); + initSdkDesktopFileName(window); initActionsInRightButtonMenu(); + refreshIconsGeometry(); + getThumbnailIfAvailable(); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); - connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)), this, SLOT(onActiveWindowChanged(WId))); + connect(WindowManager::self(), &WindowManager::activeWindowChanged, this, &UKUITaskGroup::onActiveWindowChanged); connect(parent, &UKUITaskBar::refreshIconGeometry, this, &UKUITaskGroup::refreshIconsGeometry); connect(parent, &UKUITaskBar::buttonStyleRefreshed, this, &UKUITaskGroup::setToolButtonsStyle); - connect(parent, &UKUITaskBar::showOnlySettingChanged, this, &UKUITaskGroup::refreshVisibility); - connect(parent, &UKUITaskBar::popupShown, this, &UKUITaskGroup::groupPopupShown); - m_timer->setTimerType(Qt::PreciseTimer); - connect(m_timer, SIGNAL(timeout()), SLOT(timeout())); -} - -UKUITaskGroup::UKUITaskGroup(const QString & iconName, const QString & caption, WId window, UKUITaskBar *parent) : - UKUITaskButton(iconName, caption, window, parent, parent), - m_timer(new QTimer(this)), - m_popup(new UKUIGroupPopup(this)), - m_preventPopup(false), - m_widget(NULL), - m_singleButton(false), - m_isWaylandGroup(true) -{ - //setObjectName(caption); - //setText(caption); - Q_ASSERT(parent); - m_iconName=iconName; - m_taskGroupStatus = NORMAL; - m_isWinActivate = true; - setIcon(QIcon::fromTheme(iconName)); - connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); - connect(parent, &UKUITaskBar::buttonStyleRefreshed, this, &UKUITaskGroup::setToolButtonsStyle); - //connect(parent, &UKUITaskBar::showOnlySettingChanged, this, &UKUITaskGroup::refreshVisibility); - connect(parent, &UKUITaskBar::popupShown, this, &UKUITaskGroup::groupPopupShown); + connect(parent, &UKUITaskBar::showOnlySettingChanged, this, &UKUITaskGroup::refreshSdkVisibility); m_timer->setTimerType(Qt::PreciseTimer); connect(m_timer, SIGNAL(timeout()), SLOT(timeout())); } @@ -230,21 +94,26 @@ { } -void UKUITaskGroup::setSystemStyle() + +void UKUITaskGroup::getThumbnailIfAvailable() { - QPalette pal = this->palette(); - QColor col = pal.color(QPalette::Active, QPalette::BrightText); - col.setAlphaF(0.13); - pal.setColor(QPalette::Button, col); - this->setPalette(pal); + + QString filename = QString::fromLocal8Bit(PANEL_CONFIG_PATH); + QSettings settings(filename, QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + settings.beginGroup("Thumbnail"); + m_isThumbnailAvailable = settings.value("thumbnailAvailable").toBool(); + settings.endGroup(); + settings.sync(); + } -void UKUITaskGroup::initDesktopFileName(int window) { +void UKUITaskGroup::initSdkDesktopFileName(const WindowId& window) { QDBusInterface iface(UKUI_PANEL_DAEMON, UKUI_PANEL_DAEMON_PATH, UKUI_PANEL_DAEMON_INTERFACE, QDBusConnection::sessionBus()); - QDBusReply<QString> reply = iface.call(UKUI_PANEL_DAEMON_METHOD, window); + QDBusReply<QString> reply = iface.call(UKUI_PANEL_DAEMON_METHOD, window.toInt()); QString processExeName = reply.value(); if (!processExeName.isEmpty()) { m_fileName = processExeName; @@ -262,38 +131,44 @@ } } +void UKUITaskGroup::rightMenuCloseAction(QMenu *menu) +{ + QAction *mCloseAct = menu->addAction(QIcon::fromTheme("application-exit-symbolic"), tr("close")); + connect(mCloseAct, SIGNAL(triggered()), this, SLOT(closeGroup())); + connect(menu, &QMenu::aboutToHide, [this] { + m_preventPopup = false; + }); + plugin()->willShowWindow(menu); +} void UKUITaskGroup::contextMenuEvent(QContextMenuEvent *event) { setPopupVisible(false, true); m_preventPopup = true; - if (m_singleButton && !m_isWaylandGroup) { - UKUITaskButton::contextMenuEvent(event); + QMenu * menu = new QMenu(tr("Group"), this); + menu->setAttribute(Qt::WA_DeleteOnClose); + //若应用卸载后主窗口仍为打开状态,则右键菜单只显示“退出”选项 + XdgDesktopFile xdg; + if (!xdg.load(m_fileName)) { + rightMenuCloseAction(menu); + menu->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), menu->sizeHint())); + menu->show(); return; } - QMenu * menu = new QMenu(tr("Group")); - menu->setAttribute(Qt::WA_DeleteOnClose); - if (!m_fileName.isEmpty() && !m_isWaylandGroup) { + if (!m_fileName.isEmpty()) { menu->addAction(m_act); menu->addActions(m_act->addtitionalActions()); - menu->addSeparator(); - menu->addSeparator(); - QAction *m_deleteAct = menu->addAction(QIcon::fromTheme("ukui-unfixed-symbolic"), tr("delete from taskbar")); - connect(m_deleteAct, SIGNAL(triggered()), this, SLOT(RemovefromTaskBar())); - QAction *mAddAct = menu->addAction(QIcon::fromTheme("ukui-fixed-symbolic"), tr("add to taskbar")); - connect(mAddAct, SIGNAL(triggered()), this, SLOT(AddtoTaskBar())); if (m_existSameQckBtn) { - menu->removeAction(mAddAct); + QAction *m_deleteAct = menu->addAction(QIcon::fromTheme("ukui-unfixed-symbolic"), tr("delete from taskbar")); + connect(m_deleteAct, SIGNAL(triggered()), this, SLOT(RemovefromTaskBar())); } else { - menu->removeAction(m_deleteAct); + QAction *mAddAct = menu->addAction(QIcon::fromTheme("ukui-fixed-symbolic"), tr("add to taskbar")); + connect(mAddAct, SIGNAL(triggered()), this, SLOT(AddtoTaskBar())); } } - QAction *mCloseAct = menu->addAction(QIcon::fromTheme("application-exit-symbolic"), tr("close")); - connect(mCloseAct, SIGNAL(triggered()), this, SLOT(closeGroup())); - connect(menu, &QMenu::aboutToHide, [this] { - m_preventPopup = false; - }); + menu->addSeparator(); + rightMenuCloseAction(menu); menu->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), menu->sizeHint())); plugin()->willShowWindow(menu); menu->show(); @@ -311,70 +186,54 @@ ************************************************/ void UKUITaskGroup::closeGroup() { - if (m_isWaylandGroup) { - closeGroup_wl(); - return; - } -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - for(auto it=m_buttonHash.begin();it!=m_buttonHash.end();it++) - { - UKUITaskWidget *button =it.value(); - if (button->isOnDesktop(KWindowSystem::currentDesktop())) - button->closeApplication(); + for (UKUISdkTaskButtonHash::const_iterator it = m_sdkButtonHash.begin(); it != m_sdkButtonHash.end(); ++it) { + WindowManager::closeWindow(it.key()); } -#else - for (UKUITaskWidget *button : qAsConst(m_buttonHash) ) { - if (button->isOnDesktop(KWindowSystem::currentDesktop())) { - button->closeApplication(); - } - } -#endif } /************************************************ ************************************************/ -QWidget * UKUITaskGroup::addWindow(WId id) +UKUITaskButton * UKUITaskGroup::addWindow(const WindowId& id) { - if (m_buttonHash.contains(id)) { - return m_buttonHash.value(id); + qint32 idnum = id.toInt(); + if (m_sdkButtonHash.contains(idnum)) { + return m_sdkButtonHash.value(idnum); } - UKUITaskWidget *btn = new UKUITaskWidget(id, parentTaskBar(), m_popup); - m_buttonHash.insert(id, btn); - connect(btn, SIGNAL(clicked()), this, SLOT(onChildButtonClicked())); - connect(btn, SIGNAL(windowMaximize()), this, SLOT(onChildButtonClicked())); - refreshVisibility(); - + UKUITaskButton *btn = new UKUITaskButton(m_groupName, id, parentTaskBar(), m_popup); + btn->setTaskButtonVisible(false); + m_sdkButtonHash.insert(idnum, btn); + m_popup->addWindow(id,parentTaskBar()); +// connect(taskwidget, SIGNAL(clicked()), this, SLOT(onChildButtonClicked())); +// connect(taskwidget, SIGNAL(windowMaximize()), this, SLOT(onChildButtonClicked())); + refreshSdkVisibility(); changeTaskButtonStyle(); + refreshIconsGeometry(); + update(); return btn; } - /*changeTaskButtonStyle in class UKUITaskGroup not class UKUITaskButton * because class UKUITaskButton can not get m_buttonHash.size */ void UKUITaskGroup::changeTaskButtonStyle() { - if (m_visibleHash.size()>1) { -// this->setStyle(new CustomStyle("taskbutto",true)); - } else { -// this->setStyle(new CustomStyle("taskbutto",false)); - } + this->setStyle(new CustomStyle()); } -void UKUITaskGroup::onActiveWindowChanged(WId window) +void UKUITaskGroup::onActiveWindowChanged(const WindowId& window) { - UKUITaskWidget *button = m_buttonHash.value(window, nullptr); -// for (QWidget *btn : qAsConst(m_buttonHash)) -// btn->setChecked(false); + UKUITaskButton *button = m_sdkButtonHash.value(window.toInt(), nullptr); + for (UKUITaskButton *btn : qAsConst(m_sdkButtonHash)) //delete? + btn->setChecked(false); -// if (button) -// { -// button->setChecked(true); -// if (button->hasUrgencyHint()) -// button->setUrgencyHint(false); -// } + if (button) + { + button->setChecked(true); + if (button->hasUrgencyHint()) + button->setUrgencyHint(false); + } setChecked(nullptr != button); } @@ -383,36 +242,28 @@ ************************************************/ void UKUITaskGroup::onDesktopChanged() { - refreshVisibility(); + refreshSdkVisibility(); changeTaskButtonStyle(); } -/************************************************ - ************************************************/ -void UKUITaskGroup::onWindowRemoved(WId window) +void UKUITaskGroup::onWindowRemoved(const WindowId& window) { - if (m_buttonHash.contains(window)) { - UKUITaskWidget *button = m_buttonHash.value(window); - m_buttonHash.remove(window); - if (m_visibleHash.contains(window)) { - m_showInTurn.removeOne(m_visibleHash.value(window)); - m_visibleHash.remove(window); + qint32 windowid = window.toInt(); + m_popup->onWindowRemoved(window); + if (m_sdkButtonHash.contains(windowid)) { + UKUITaskButton *button = m_sdkButtonHash.value(windowid); + m_sdkButtonHash.remove(windowid); + if (m_sdkVisibleHash.contains(windowid)) { + m_sdkVisibleHash.remove(windowid); } - m_popup->removeWidget(button); button->deleteLater(); - if (!parentTaskBar()->getCpuInfoFlg()) { - system(QString("rm -f /tmp/%1.png").arg(window).toLatin1()); - } - if (isLeaderWindow(window) && (m_showInTurn.size() > 0)) { - setLeaderWindow(m_buttonHash.key(m_showInTurn.at(0))); + if (isLeaderWindow(window)) { + setLeaderWindow(m_sdkButtonHash.begin().key()); } - if (m_buttonHash.count()) { - if(m_popup->isVisible()) { -// m_popup->hide(true); - showPreview(); - } else { - regroup(); + if (m_sdkButtonHash.count()) { + if(!m_popup->isVisible()) { + refreshSdkVisibility(); } } else { if (isVisible()) { @@ -423,34 +274,9 @@ } changeTaskButtonStyle(); } -} - -/************************************************ - - ************************************************/ -void UKUITaskGroup::onChildButtonClicked() -{ - setPopupVisible(false, true); - parentTaskBar()->setShowGroupOnHover(true); - //QToolButton::leaveEvent(event); - m_taskGroupStatus = NORMAL; update(); } -/************************************************ - - ************************************************/ -Qt::ToolButtonStyle UKUITaskGroup::popupButtonStyle() const -{ - // do not set icons-only style in the buttons in the group, - // as they'll be indistinguishable - const Qt::ToolButtonStyle style = toolButtonStyle(); - return style == Qt::ToolButtonIconOnly ? Qt::ToolButtonTextBesideIcon : style; -} - -/************************************************ - - ************************************************/ void UKUITaskGroup::setToolButtonsStyle(Qt::ToolButtonStyle style) { setToolButtonStyle(style); @@ -462,28 +288,7 @@ // } } -/************************************************ - - ************************************************/ -int UKUITaskGroup::buttonsCount() const -{ - return m_buttonHash.count(); -} - -void UKUITaskGroup::initVisibleHash() -{ - /* for (UKUITaskButtonHash::const_iterator it = m_buttonHash.begin();it != m_buttonHash.end();it++) - { - if (m_visibleHash.contains(it.key())) continue; - if (it.value()->isVisibleTo(m_popup)) - m_visibleHash.insert(it.key(), it.value()); - }*/ -} - -/************************************************ - - ************************************************/ -int UKUITaskGroup::visibleButtonsCount() const +int UKUITaskGroup::visibleSdkButtonsCount() const { int i = 0; #if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) @@ -494,7 +299,7 @@ i++; } #else - for (UKUITaskWidget *btn : qAsConst(m_buttonHash)) { + for (UKUITaskButton *btn : qAsConst(m_sdkButtonHash)) { if (btn->isVisibleTo(m_popup)) { i++; } @@ -503,27 +308,10 @@ return i; } -/************************************************ - - ************************************************/ -void UKUITaskGroup::draggingTimerTimeout() -{ - if (m_singleButton) { - setPopupVisible(false); - } -} - -/************************************************ - - ************************************************/ void UKUITaskGroup::onClicked(bool) { - if (m_isWaylandGroup) { - winClickActivate_wl(!m_isWinActivate); - return; - } - if (1 == m_visibleHash.size()) { - return singleWindowClick(); + if (1 == m_sdkVisibleHash.size()) { + return singleSdkWindowClick(); } if (m_popup->isVisible()) { if(HOVER == m_taskGroupStatus) { @@ -534,7 +322,7 @@ return; } } else { - showPreview(); + showPreviewMode(); } m_taskGroupEvent = OTHEREVENT; if (m_timer->isActive()) { @@ -542,18 +330,18 @@ } } - -void UKUITaskGroup::singleWindowClick() +void UKUITaskGroup::singleSdkWindowClick() { - UKUITaskWidget *btn = m_visibleHash.begin().value(); + UKUITaskButton *btn = m_sdkVisibleHash.begin().value(); if (btn) { - if (!btn->isFocusState() || btn->isMinimized()) { + if (!btn->isSdkFocusState() || btn->isSdkMinimized()) { if (m_popup->isVisible()) { m_popup->hide(); } - KWindowSystem::forceActiveWindow(m_visibleHash.begin().key()); + WindowManager::activateWindow(m_sdkVisibleHash.begin().key()); } else { - btn->minimizeApplication(); + refreshIconsGeometry(); + btn->minimizeSdkApplication(); if (m_popup->isVisible()) { m_popup->hide(); } @@ -565,52 +353,6 @@ } } -/************************************************ - - ************************************************/ -void UKUITaskGroup::regroup() -{ - int cont = visibleButtonsCount(); - recalculateFrameIfVisible(); - -// if (cont == 1) -// { -// m_singleButton = false; -// // Get first visible button -// UKUITaskButton * button = NULL; -// for (UKUITaskButton *btn : qAsConst(m_buttonHash)) -// { -// if (btn->isVisibleTo(m_popup)) -// { -// button = btn; -// break; -// } -// } - -// if (button) -// { -// setText(button->text()); -// setToolTip(button->toolTip()); -// setWindowId(button->windowId()); - -// } -// } - /*else*/ - if (cont == 0) { - // emit groupHidden(groupName()); - hide(); - } else { - m_singleButton = false; - QString t = QString("%1 - %2 windows").arg(m_groupName).arg(cont); - setText(t); - setToolTip(parentTaskBar()->isShowGroupOnHover() ? QString() : t); - } - -} - -/************************************************ - - ************************************************/ void UKUITaskGroup::recalculateFrameIfVisible() { if (m_popup->isVisible()) { @@ -621,9 +363,6 @@ } } -/************************************************ - - ************************************************/ void UKUITaskGroup::setAutoRotation(bool value, IUKUIPanel::Position position) { // for (QWidget *button : qAsConst(m_buttonHash)) @@ -632,44 +371,32 @@ //UKUITaskWidget::setAutoRotation(value, position); } -/************************************************ - - ************************************************/ -void UKUITaskGroup::refreshVisibility() +void UKUITaskGroup::refreshSdkVisibility() { bool will = false; UKUITaskBar const * taskbar = parentTaskBar(); const int showDesktop = taskbar->showDesktopNum(); - for(UKUITaskButtonHash::const_iterator i=m_buttonHash.begin(); i!=m_buttonHash.end(); i++) { - UKUITaskWidget * btn=i.value(); - bool visible = taskbar->isShowOnlyOneDesktopTasks() ? btn->isOnDesktop(0 == showDesktop ? KWindowSystem::currentDesktop() : showDesktop) : true; - visible &= taskbar->isShowOnlyCurrentScreenTasks() ? btn->isOnCurrentScreen() : true; - visible &= taskbar->isShowOnlyMinimizedTasks() ? btn->isMinimized() : true; + for(UKUISdkTaskButtonHash::const_iterator i=m_sdkButtonHash.begin(); i!=m_sdkButtonHash.end(); i++) { + UKUITaskButton * btn=i.value(); + bool visible = btn->isOnDesktop(0 == showDesktop ? KWindowSystem::currentDesktop() : showDesktop); + visible = true; btn->setVisible(visible); - if (btn->isVisibleTo(m_popup) && !m_visibleHash.contains(i.key())) { - m_visibleHash.insert(i.key(), i.value()); - m_showInTurn.push_back(i.value()); - } else if (!btn->isVisibleTo(m_popup) && m_visibleHash.contains(i.key())) { - m_visibleHash.remove(i.key()); - m_showInTurn.removeOne(i.value()); + if (btn->isVisibleTo(m_popup) && !m_sdkVisibleHash.contains(i.key())) { + m_sdkVisibleHash.insert(i.key(), i.value()); + } else if (!btn->isVisibleTo(m_popup) && m_sdkVisibleHash.contains(i.key())) { + m_sdkVisibleHash.remove(i.key()); } will |= visible; } - if (!m_showInTurn.isEmpty()) { - setLeaderWindow(m_visibleHash.key(m_showInTurn.at(0))); - } - + setLeaderWindow(m_sdkVisibleHash.begin().key()); bool is = isVisible(); - // emit groupVisible(groupName(), will); - // else setVisible(will); - // will &= this->isVisible(); setVisible(will); if (this->m_existSameQckBtn) { m_qckLchBtn->setHidden(will); } if (!m_popup->isVisible()) { - regroup(); + recalculateFrameIfVisible(); } if (is != will) { @@ -698,9 +425,9 @@ if (!m_statFlag) { return; } - if (visible && !m_preventPopup && !m_singleButton) { -// QTimer::singleShot(400, this,SLOT(showPreview())); - showPreview(); + if (visible && !m_preventPopup) { +// QTimer::singleShot(400, this,SLOT(showPreviewMode())); + showPreviewMode(); /* for origin preview plugin()->willShowWindow(m_popup); m_popup->show(); @@ -710,28 +437,18 @@ m_popup->hide(fast); } } -/************************************************ - ************************************************/ void UKUITaskGroup::refreshIconsGeometry() { float scale = qApp->devicePixelRatio(); QRect rect = geometry(); rect.moveTo(mapToGlobal(QPoint(0, 0)).x() * scale, mapToGlobal(QPoint(0, 0)).y() * scale); - if (m_singleButton) { - refreshIconGeometry(rect); - return; - } - for(UKUITaskWidget *but : qAsConst(m_buttonHash)) { - but->refreshIconGeometry(rect); -// but->setIconSize(QSize(plugin()->panel()->iconSize(), plugin()->panel()->iconSize())); + for(UKUITaskButton *btn : qAsConst(m_sdkButtonHash)) { + btn->refreshIconGeometry(rect); } } -/************************************************ - - ************************************************/ QSize UKUITaskGroup::recalculateFrameSize() { int height = 120; @@ -758,14 +475,7 @@ return iconSize().width() + qMin(txtWidth, max) + 30/* give enough room to margins and borders*/; } -void UKUITaskGroup::toDothis_customContextMenuRequested(const QPoint & pos) -{ - m_plugin->willShowWindow(m_menu); - m_menu->popup(m_plugin->panel()->calculatePopupWindowPos(mapToGlobal({0, 0}), m_menu->sizeHint()).topLeft()); -} -/************************************************ - ************************************************/ QPoint UKUITaskGroup::recalculateFramePosition() { // Set position @@ -803,7 +513,9 @@ if (m_timer->isActive()) { m_timer->stop();//stay time is no more than 400 ms need kill timer } else { - m_timer->start(300); + if (!m_popup->geometry().contains(QCursor::pos())) { + m_timer->start(0); + } } } @@ -828,7 +540,7 @@ return; } - if (m_statFlag && parentTaskBar()->isShowGroupOnHover()) { + if (m_statFlag ) { setPopupVisible(true); } m_taskGroupStatus = HOVER; @@ -874,212 +586,37 @@ /************************************************ ************************************************/ -bool UKUITaskGroup::onWindowChanged(WId window, NET::Properties prop, NET::Properties2 prop2) +bool UKUITaskGroup::onWindowChanged(const WindowId& window) { // returns true if the class is preserved bool needsRefreshVisibility{false}; QVector<QWidget *> buttons; - if (m_buttonHash.contains(window)) { - buttons.append(m_buttonHash.value(window)); + if (m_sdkButtonHash.contains(window.toInt())) { + buttons.append(m_sdkButtonHash.value(window.toInt())); } // If group is based on that window properties must be changed also on button group - if (window == windowId()) { + if (window == sdkWindowId()) { buttons.append(this); } if (!buttons.isEmpty()) { - // if class is changed the window won't belong to our group any more - if (parentTaskBar()->isGroupingEnabled() && prop2.testFlag(NET::WM2WindowClass)) { - KWindowInfo info(window, 0, NET::WM2WindowClass); - if (info.windowClassClass() != m_groupName) { - onWindowRemoved(window); - return false; - } - } - // window changed virtual desktop - if (prop.testFlag(NET::WMDesktop) || prop.testFlag(NET::WMGeometry)) { - if (parentTaskBar()->isShowOnlyOneDesktopTasks() - || parentTaskBar()->isShowOnlyCurrentScreenTasks()) { - needsRefreshVisibility = true; - } - } - -// if (prop.testFlag(NET::WMVisibleName) || prop.testFlag(NET::WMName)) -// std::for_each(buttons.begin(), buttons.end(), std::mem_fn(&UKUITaskButton::updateText)); - - // XXX: we are setting window icon geometry -> don't need to handle NET::WMIconGeometry - // Icon of the button can be based on windowClass -// if (prop.testFlag(NET::WMIcon) || prop2.testFlag(NET::WM2WindowClass)) -// std::for_each(buttons.begin(), buttons.end(), std::mem_fn(&UKUITaskButton::updateIcon)); - if (prop.testFlag(NET::WMIcon) || prop2.testFlag(NET::WM2WindowClass)){ - updateIcon(); - for(UKUITaskButtonHash::const_iterator i = m_visibleHash.begin(); i != m_visibleHash.end(); i++) { - i.value()->updateIcon(); - } - } - - if (prop.testFlag(NET::WMState)) { - KWindowInfo info{window, NET::WMState}; - if (info.hasState(NET::SkipTaskbar)) { - onWindowRemoved(window); - } -// std::for_each(buttons.begin(), buttons.end(), std::bind(&UKUITaskButton::setUrgencyHint, std::placeholders::_1, info.hasState(NET::DemandsAttention))); - - if (parentTaskBar()->isShowOnlyMinimizedTasks()) { - needsRefreshVisibility = true; + if (!WindowManager::getWindowIcon(window).isNull()){ + updateSdkIcon(); + for(UKUISdkTaskButtonHash::const_iterator i = m_sdkVisibleHash.begin(); i != m_sdkVisibleHash.end(); i++) { + i.value()->updateSdkIcon(); } + m_popup->onWindowChanged(window); } } if (needsRefreshVisibility) { - refreshVisibility(); - } - - return true; -} - -/************************************************ - - ************************************************/ -void UKUITaskGroup::groupPopupShown(UKUITaskGroup * const sender) -{ - //close all popups (should they be visible because of close delay) - if (this != sender && isVisible()) { - setPopupVisible(false, true/*fast*/); - } -} - -void UKUITaskGroup::removeWidget() -{ - if (m_scrollArea) { - removeSrollWidget(); - } - if (m_widget) { - m_popup->layout()->removeWidget(m_widget); - QHBoxLayout *hLayout = dynamic_cast<QHBoxLayout*>(m_widget->layout()); - QVBoxLayout *vLayout = dynamic_cast<QVBoxLayout*>(m_widget->layout()); - if (hLayout != NULL) { - hLayout->deleteLater(); - hLayout = NULL; - } - if (vLayout != NULL) { - vLayout->deleteLater(); - vLayout = NULL; - } - //m_widget->setParent(NULL); - m_widget->deleteLater(); - m_widget = NULL; - } -} - - -void UKUITaskGroup::removeSrollWidget() -{ - if (m_scrollArea) { - m_popup->layout()->removeWidget(m_scrollArea); - m_popup->layout()->removeWidget(m_scrollArea->takeWidget()); - } - if (m_widget) { - m_popup->layout()->removeWidget(m_widget); - QHBoxLayout *hLayout = dynamic_cast<QHBoxLayout*>(m_widget->layout()); - QVBoxLayout *vLayout = dynamic_cast<QVBoxLayout*>(m_widget->layout()); - if (hLayout != NULL) { - hLayout->deleteLater(); - hLayout = NULL; - } - if (vLayout != NULL) { - vLayout->deleteLater(); - vLayout = NULL; - } - //m_widget->setParent(NULL); - m_widget->deleteLater(); - m_widget = NULL; - } - if (m_scrollArea) { - m_scrollArea->deleteLater(); - m_scrollArea = NULL; - } -} - -void UKUITaskGroup::setLayOutForPostion() -{ - //more than 10 need - if (m_visibleHash.size() > 10) { - m_widget->setLayout(new QVBoxLayout); - m_widget->layout()->setAlignment(Qt::AlignTop); - m_widget->layout()->setSpacing(3); - m_widget->layout()->setMargin(3); - return; - } - - if (plugin()->panel()->isHorizontal()) { - m_widget->setLayout(new QHBoxLayout); - m_widget->layout()->setSpacing(3); - m_widget->layout()->setMargin(3); - } else { - m_widget->setLayout(new QVBoxLayout); - m_widget->layout()->setSpacing(3); - m_widget->layout()->setMargin(3); - } -} - -bool UKUITaskGroup::isSetMaxWindow() -{ - int iScreenWidth = QApplication::screens().at(0)->size().width(); - int iScreenHeight = QApplication::screens().at(0)->size().height(); - if ((iScreenWidth >= SCREEN_MID_WIDTH_SIZE) - || ((iScreenWidth > SCREEN_MAX_WIDTH_SIZE) - && (iScreenHeight > SCREEN_MAX_HEIGHT_SIZE))) { - return true; - } else { - return false; - } -} - -void UKUITaskGroup::showPreview() -{ - int n = 6; - if (plugin()->panel()->isHorizontal()) { - n = 10; + refreshSdkVisibility(); } - if (m_visibleHash.size() <= n) { - showAllWindowByThumbnail(); - } else { - showAllWindowByList(); - } -} - -void UKUITaskGroup::adjustPopWindowSize(int winWidth, int winHeight) -{ - int size = m_visibleHash.size(); - if (m_isWaylandGroup) { - size = 1; + if (!m_isShowByList) { + m_allWidgetWidth = m_popup->width(); + m_allWidgetHeight = m_popup->height(); } - if (plugin()->panel()->isHorizontal()) { - m_popup->setFixedSize(winWidth*size + (size + 1)*3, winHeight + 6); - } else { - m_popup->setFixedSize(winWidth + 6,winHeight*size + (size + 1)*3); - } - m_popup->adjustSize(); -} - -void UKUITaskGroup::v_adjustPopWindowSize(int winWidth, int winHeight, int v_all) -{ - int fixed_size = v_all; - if (plugin()->panel()->isHorizontal()) { - int iScreenWidth = QApplication::screens().at(0)->size().width(); - if (fixed_size > iScreenWidth) { - fixed_size = iScreenWidth; - } - m_popup->setFixedSize(fixed_size, winHeight + 6); - } else { - int iScreenHeight = QApplication::screens().at(0)->size().height(); - if (fixed_size > iScreenHeight) { - fixed_size = iScreenHeight; - } - m_popup->setFixedSize(winWidth + 6, fixed_size); - } - m_popup->adjustSize(); + return true; } void UKUITaskGroup::timeout() @@ -1102,400 +639,10 @@ } } -int UKUITaskGroup::calcAverageHeight() -{ - if (plugin()->panel()->isHorizontal()) { - return 0; - } else { - int size = m_visibleHash.size(); - int iScreenHeight = QApplication::screens().at(0)->size().height(); - int iMarginHeight = (size+1)*3; - int iAverageHeight = (iScreenHeight - iMarginHeight)/size;//calculate average width of window - return iAverageHeight; - } -} - -int UKUITaskGroup::calcAverageWidth() -{ - if (plugin()->panel()->isHorizontal()) { - int size = m_visibleHash.size(); - int iScreenWidth = QApplication::screens().at(0)->size().width(); - int iMarginWidth = (size+1)*3; - int iAverageWidth; - iAverageWidth = (size == 0 ? size : (iScreenWidth - iMarginWidth)/size);//calculate average width of window - return iAverageWidth; - } else { - return 0; - } -} - -void UKUITaskGroup::showAllWindowByList() -{ - int winWidth = 246; - int winheight = 46; - int iPreviewPosition = 0; - int popWindowheight = (winheight) * (m_visibleHash.size()); - int screenAvailabelHeight = QApplication::screens().at(0)->size().height() - plugin()->panel()->panelSize(); - if (!plugin()->panel()->isHorizontal()) { - screenAvailabelHeight = QApplication::screens().at(0)->size().height();//panel is vect - } - if (m_popup->layout()->count() > 0) { - removeSrollWidget(); - } - m_scrollArea = new QScrollArea(this); - - m_scrollArea->setWidgetResizable(true); - - m_popup->layout()->addWidget(m_scrollArea); - m_popup->setFixedSize(winWidth, popWindowheight < screenAvailabelHeight? popWindowheight : screenAvailabelHeight); - m_widget = new QWidget(this); - m_scrollArea->setWidget(m_widget); - setLayOutForPostion(); - /*begin catch preview picture*/ - for (QVector<UKUITaskWidget*>::iterator it = m_showInTurn.begin();it != m_showInTurn.end();it++) { - UKUITaskWidget *btn = *it; - btn->clearMask(); - btn->setTitleFixedWidth(m_widget->width()); - btn->updateTitle(); - btn->setParent(m_scrollArea); - btn->removeThumbNail(); - btn->addThumbNail(); - btn->adjustSize(); - btn->setFixedHeight(winheight); - - connect(btn, &UKUITaskWidget::closeSigtoPop, [this] { m_popup->pubcloseWindowDelay(); }); - connect(btn, &UKUITaskWidget::closeSigtoGroup, [this] { closeGroup(); }); - m_widget->layout()->addWidget(btn); - } - /*end*/ - plugin()->willShowWindow(m_popup); - if (plugin()->panel()->isHorizontal()) { - iPreviewPosition = plugin()->panel()->panelSize()/2 - winWidth/2; - m_popup->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(QPoint(iPreviewPosition,0)), m_popup->size())); - } else { - iPreviewPosition = plugin()->panel()->panelSize()/2 - winWidth/2; - m_popup->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(QPoint(0,iPreviewPosition)), m_popup->size())); - } - - m_popup->setStyle(new CustomStyle()); - m_scrollArea->setAttribute(Qt::WA_TranslucentBackground); - m_scrollArea->setProperty("drawScrollBarGroove",false); - m_scrollArea->verticalScrollBar()->setProperty("drawScrollBarGroove",false); - m_scrollArea->show(); - m_popup->show(); - - // emit popupShown(this); -} - - -void UKUITaskGroup::showAllWindowByThumbnail() -{ - if (m_isWaylandGroup) { - int previewPosition = 0; - m_widget = new QWidget(); - m_widget->setAttribute(Qt::WA_TranslucentBackground); - for (UKUITaskButtonHash::const_iterator it = m_buttonHash.begin(); it != m_buttonHash.end(); it++) { - QPixmap thumbnail; - UKUITaskWidget *btn = it.value(); - thumbnail = QIcon::fromTheme(m_iconName).pixmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT - 160); - btn->setThumbNail(thumbnail); - btn->wl_updateTitle(m_caption); - btn->wl_updateIcon(m_iconName); - btn->setFixedSize(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT - 160); - //m_widget->layout()->setContentsMargins(0,0,0,0); - //m_widget->layout()->addWidget(btn); - } - adjustPopWindowSize(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT - 160); - //set preview window position - if (plugin()->panel()->isHorizontal()) { - if (m_popup->size().width()/2 < QCursor::pos().x()) { - previewPosition = 0 - m_popup->size().width()/2 + plugin()->panel()->panelSize()/2; - } else { - previewPosition = 0 -(QCursor::pos().x() + plugin()->panel()->panelSize()/2); - } - m_popup->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(QPoint(previewPosition,0)), m_popup->size())); - } else { - if (m_popup->size().height()/2 < QCursor::pos().y()) { - previewPosition = 0 - m_popup->size().height()/2 + plugin()->panel()->panelSize()/2; - } else { - previewPosition = 0 -(QCursor::pos().y() + plugin()->panel()->panelSize()/2); - } - m_popup->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(QPoint(0,previewPosition)), m_popup->size())); - } -#if 0 - if (m_popup->isVisible()) { - // m_popup- - } else { - m_popup->show(); - } -#else - if (!m_popup->isVisible()) { - m_popup->show(); - } -#endif - return; - } - - XImage *img = NULL; - Display *display = NULL; - QPixmap thumbnail; - XWindowAttributes attr; - int previewPosition = 0; - int winWidth = 0; - int winHeight = 0; - int truewidth = 0; - // initVisibleHash(); - refreshVisibility(); - int iAverageWidth = calcAverageWidth(); - int iAverageHeight = calcAverageHeight(); - /*begin get the winsize*/ - bool isMaxWinSize = isSetMaxWindow(); - if (isMaxWinSize) { - if (0 == iAverageWidth) { - winHeight = PREVIEW_WIDGET_MAX_HEIGHT < iAverageHeight?PREVIEW_WIDGET_MAX_HEIGHT:iAverageHeight; - winWidth = winHeight*PREVIEW_WIDGET_MAX_WIDTH/PREVIEW_WIDGET_MAX_HEIGHT; - } else { - winWidth = PREVIEW_WIDGET_MAX_WIDTH < iAverageWidth?PREVIEW_WIDGET_MAX_WIDTH:iAverageWidth; - winHeight = winWidth*PREVIEW_WIDGET_MAX_HEIGHT/PREVIEW_WIDGET_MAX_WIDTH; - } - } else { - if (0 == iAverageWidth) { - winHeight = PREVIEW_WIDGET_MIN_HEIGHT < iAverageHeight?PREVIEW_WIDGET_MIN_HEIGHT:iAverageHeight; - winWidth = winHeight*PREVIEW_WIDGET_MIN_WIDTH/PREVIEW_WIDGET_MIN_HEIGHT; - } else { - winWidth = PREVIEW_WIDGET_MIN_WIDTH < iAverageWidth?PREVIEW_WIDGET_MIN_WIDTH:iAverageWidth; - winHeight = winWidth*PREVIEW_WIDGET_MIN_HEIGHT/PREVIEW_WIDGET_MIN_WIDTH; - } - } - /*end get the winsize*/ - - if (m_popup->layout()->count() > 0) { - removeWidget(); - } - m_widget = new QWidget(this); - m_widget->setAttribute(Qt::WA_TranslucentBackground); - setLayOutForPostion(); - /*begin catch preview picture*/ - - int max_Height = 0; - int max_Width = 0; - int imgWidth_sum = 0; - int changed = 0; - int title_width = 0; - int v_all = 0; - int iScreenWidth = QApplication::screens().at(0)->size().width(); - float minimumHeight = THUMBNAIL_HEIGHT; - for (UKUITaskButtonHash::const_iterator it = m_visibleHash.begin(); it != m_visibleHash.end(); it++) { - it.value()->removeThumbNail(); - display = XOpenDisplay(nullptr); - XGetWindowAttributes(display, it.key(), &attr); - max_Height = attr.height > max_Height ? attr.height : max_Height; - max_Width = attr.width > max_Width ? attr.width : max_Width; - truewidth += attr.width; - if (display) { - XCloseDisplay(display); - } - } - for (UKUITaskButtonHash::const_iterator it = m_buttonHash.begin(); it != m_buttonHash.end(); it++) { - UKUITaskWidget *btn = it.value(); - btn->setParent(m_popup); - connect(btn, &UKUITaskWidget::closeSigtoPop, [this] { m_popup->pubcloseWindowDelay(); }); - connect(btn, &UKUITaskWidget::closeSigtoGroup, [this] { closeGroup(); }); - btn->addThumbNail(); - display = XOpenDisplay(nullptr); - XGetWindowAttributes(display, it.key(), &attr); - img = XGetImage(display, it.key(), 0, 0, attr.width, attr.height, 0xffffffff,ZPixmap); - float imgWidth = 0; - float imgHeight = 0; - if (plugin()->panel()->isHorizontal()) { - float thmbwidth = (float)attr.width / (float)attr.height; - imgWidth = thmbwidth * winHeight; - imgHeight = winHeight; - if (imgWidth > THUMBNAIL_WIDTH) { - imgWidth = THUMBNAIL_WIDTH; - } - } else { - imgWidth = THUMBNAIL_WIDTH; - imgHeight = (float)attr.height / (float)attr.width * THUMBNAIL_WIDTH; - } - if (plugin()->panel()->isHorizontal()) { - if (m_visibleHash.contains(btn->windowId())) { - v_all += (int)imgWidth; - imgWidth_sum += (int)imgWidth; - } - if (m_visibleHash.size() == 1 ) { - changed = (int)imgWidth; - } - btn->setThumbMaximumSize(MAX_SIZE_OF_Thumb); - btn->setThumbScale(true); - } else { - if (attr.width != max_Width) { - float tmp = (float)attr.width / (float)max_Width; - imgWidth = imgWidth * tmp; - } - if ((int)imgHeight > (int)minimumHeight) { - imgHeight = minimumHeight; - } - if (m_visibleHash.contains(btn->windowId())) { - v_all += (int)imgHeight; - } - if (m_visibleHash.size() == 1 ) { - changed = (int)imgHeight; - } - if ((int)imgWidth < 150) { - btn->setThumbFixedSize((int)imgWidth); - btn->setThumbScale(false); - } else { - btn->setThumbMaximumSize(MAX_SIZE_OF_Thumb); - btn->setThumbScale(true); - } - } - if (img) { - thumbnail = qimageFromXImage(img).scaled((int)imgWidth, (int)imgHeight, Qt::KeepAspectRatio,Qt::SmoothTransformation); - if (!parentTaskBar()->getCpuInfoFlg()) { - thumbnail.save(QString("/tmp/%1.png").arg(it.key())); - } - } else { - qDebug()<<"can not catch picture"; - QPixmap pxmp; - if (pxmp.load(QString("/tmp/%1.png").arg(it.key()))) { - thumbnail = pxmp.scaled((int)imgWidth, (int)imgHeight, Qt::KeepAspectRatio,Qt::SmoothTransformation); - } else { - thumbnail = QPixmap((int)imgWidth, (int)imgHeight); - thumbnail.fill(QColor(0, 0, 0, 127)); - } - } - btn->setThumbNail(thumbnail); - btn->updateTitle(); - btn->setFixedSize((int)imgWidth, (int)imgHeight); - m_widget->layout()->setContentsMargins(0,0,0,0); - m_widget->layout()->addWidget(btn); - if (img) { - XDestroyImage(img); - } - if (display) { - XCloseDisplay(display); - } - } - /*end*/ - for (UKUITaskButtonHash::const_iterator it = m_buttonHash.begin(); it != m_buttonHash.end(); it++) { - UKUITaskWidget *btn = it.value(); - if (plugin()->panel()->isHorizontal()) { - if (imgWidth_sum > iScreenWidth) { - title_width = (int)(btn->width() * iScreenWidth / imgWidth_sum - 80); - } else { - title_width = btn->width() - 75; - } - } else { - title_width = winWidth- 70; - } - btn->setTitleFixedWidth(title_width); - } - plugin()->willShowWindow(m_popup); - m_popup->layout()->addWidget(m_widget); - if (m_visibleHash.size() == 1 && changed != 0) { - if (plugin()->panel()->isHorizontal()) { - adjustPopWindowSize(changed, winHeight); - } else { - adjustPopWindowSize(winWidth, changed); - } - } else if (m_visibleHash.size() != 1) { - v_adjustPopWindowSize(winWidth, winHeight, v_all); - } else { - adjustPopWindowSize(winWidth, winHeight); - } - - //set preview window position - if (plugin()->panel()->isHorizontal()) { - if (m_popup->size().width()/2 < QCursor::pos().x()) { - previewPosition = 0 - m_popup->size().width()/2 + plugin()->panel()->panelSize()/2; - } else { - previewPosition = 0 -(QCursor::pos().x() + plugin()->panel()->panelSize()/2); - } - m_popup->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(QPoint(previewPosition,0)), m_popup->size())); - } else { - if (m_popup->size().height()/2 < QCursor::pos().y()) { - previewPosition = 0 - m_popup->size().height()/2 + plugin()->panel()->panelSize()/2; - } else { - previewPosition = 0 -(QCursor::pos().y() + plugin()->panel()->panelSize()/2); - } - m_popup->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(QPoint(0,previewPosition)), m_popup->size())); - } -#if 0 - if (m_popup->isVisible()) { -// m_popup- - } else { - m_popup->show(); - } -#else - if (!m_popup->isVisible()) { - m_popup->show(); - } -#endif -// emit popupShown(this); -} - -void UKUITaskGroup::setActivateState_wl(bool _state) -{ - m_isWinActivate = _state; - m_taskGroupStatus = (_state ? HOVER : NORMAL); - repaint(); -} - -void UKUITaskGroup::winClickActivate_wl(bool _getActive) -{ - QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "request"); - QList<QVariant> args; - quint32 m_wid=windowId(); - args.append(m_wid); - args.append((_getActive ? WAYLAND_GROUP_ACTIVATE : WAYLAND_GROUP_HIDE)); - m_isWinActivate = _getActive; - m_taskGroupStatus = (_getActive ? HOVER : NORMAL); - repaint(); - message.setArguments(args); - QDBusConnection::sessionBus().send(message); -} - -QWidget * UKUITaskGroup::wl_addWindow(WId id) -{ - if (m_buttonHash.contains(id)) { - return m_buttonHash.value(id); - } - UKUITaskWidget *btn; - if (m_isWaylandGroup) { - btn = new UKUITaskWidget(QString("kyiln-video"), id, parentTaskBar(), m_popup); - m_buttonHash.insert(id, btn); - return btn; - } else { - btn = new UKUITaskWidget(id, parentTaskBar(), m_popup); - } - m_buttonHash.insert(id, btn); - connect(btn, SIGNAL(clicked()), this, SLOT(onClicked(bool))); - connect(btn, SIGNAL(windowMaximize()), this, SLOT(onChildButtonClicked())); - -// this->setStyle(new CustomStyle("taskbutton",true)); - return btn; -} - -void UKUITaskGroup::closeGroup_wl() +void UKUITaskGroup::showPreviewMode() { - QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "request"); - QList<QVariant> args; - quint32 m_wid=windowId(); - args.append(m_wid); - args.append(WAYLAND_GROUP_CLOSE); - message.setArguments(args); - QDBusConnection::sessionBus().send(message); -} + m_popup->showPreviewMode(); -void UKUITaskGroup::wl_widgetUpdateTitle(QString caption) -{ - if (caption.isNull()) { - return; - } - for (UKUITaskWidget *button : qAsConst(m_buttonHash) ) { - button->wl_updateTitle(caption); - } } void UKUITaskGroup::paintEvent(QPaintEvent *event) @@ -1505,18 +652,16 @@ QStyleOption option; option.initFrom(this); QPainter painter(this); - if(m_visibleHash.size() > 1) { + if(m_sdkVisibleHash.size() > 1) { painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(Qt::NoPen); - painter.setBrush(option.palette.color(QPalette::Highlight)); - painter.drawEllipse(option.rect.bottomLeft() + QPointF(option.rect.center().x()-3, -5.5), 2.5, 2.5); - painter.setBrush(option.palette.color(QPalette::Highlight)/*.light(125)*/); - painter.drawEllipse(option.rect.bottomLeft() + QPointF(option.rect.center().x()+3, -5.5), 2.5, 2.5); - } else if(m_visibleHash.size() == 1) { + painter.setPen(QPen(option.palette.color(QPalette::Highlight), 4, Qt::SolidLine, Qt::RoundCap)); + painter.drawLine(QPoint(option.rect.center().x() - 6, option.rect.bottomLeft().y() - 3), + QPoint(option.rect.center().x() + 6, option.rect.bottomLeft().y() - 3)); + } else if(m_sdkVisibleHash.size() == 1) { painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(Qt::NoPen); - painter.setBrush(option.palette.color(QPalette::Highlight)); - painter.drawEllipse(option.rect.bottomLeft() + QPointF(option.rect.center().x(), -5.5), 2.5, 2.5); + painter.setPen(QPen(option.palette.color(QPalette::Highlight), 4, Qt::SolidLine, Qt::RoundCap)); + painter.drawLine(QPoint(option.rect.center().x() - 2, option.rect.bottomLeft().y() - 3), + QPoint(option.rect.center().x() + 2, option.rect.bottomLeft().y() - 3)); } return; } diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskgroup.h ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskgroup.h --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskgroup.h 2022-05-11 17:43:37.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskgroup.h 2023-05-22 14:06:12.000000000 +0800 @@ -29,61 +29,20 @@ #ifndef UKUITASKGROUP_H #define UKUITASKGROUP_H - - +//panel #include "../panel/iukuipanel.h" #include "../panel/iukuipanelplugin.h" +#include "../panel/pluginsettings.h" +#include "../panel/common/common.h" #include "ukuitaskbar.h" #include "ukuigrouppopup.h" -#include "ukuitaskwidget.h" #include "ukuitaskbutton.h" -#include <KF5/KWindowSystem/kwindowsystem.h> +//QT #include <QTimer> -#include <QScrollArea> -#include "../panel/pluginsettings.h" -#include <QAbstractButton> -//#include <Xlib.h> - -#define PREVIEW_WIDTH 468 -#define PREVIEW_HEIGHT 428 -#define SPACE_WIDTH 8 -#define SPACE_HEIGHT 8 -#define THUMBNAIL_WIDTH (PREVIEW_WIDTH - SPACE_WIDTH) -#define THUMBNAIL_HEIGHT (PREVIEW_HEIGHT - SPACE_HEIGHT) -#define ICON_WIDTH 48 -#define ICON_HEIGHT 48 -#define MAX_SIZE_OF_Thumb 16777215 - -#define SCREEN_MAX_WIDTH_SIZE 1400 -#define SCREEN_MAX_HEIGHT_SIZE 1050 - -#define SCREEN_MIN_WIDTH_SIZE 800 -#define SCREEN_MIN_HEIGHT_SIZE 600 - -#define SCREEN_MID_WIDTH_SIZE 1600 - -#define PREVIEW_WIDGET_MAX_WIDTH 352 -#define PREVIEW_WIDGET_MAX_HEIGHT 264 - -#define PREVIEW_WIDGET_MIN_WIDTH 276 -#define PREVIEW_WIDGET_MIN_HEIGHT 200 - -#define DEKSTOP_FILE_PATH "/usr/share/applications/" -#define GET_DESKTOP_EXEC_NAME_MAIN "cat %s | awk '{if($1~\"Exec=\")if($2~\"\%\"){print $1} else print}' | cut -d '=' -f 2" -#define GET_DESKTOP_EXEC_NAME_BACK "cat %s | awk '{if($1~\"StartupWMClass=\")print $1}' | cut -d '=' -f 2" -#define GET_DESKTOP_ICON "cat %s | awk '{if($1~\"Icon=\")print $1}' | cut -d '=' -f 2" -#define GET_PROCESS_EXEC_NAME_MAIN "ps -aux | sed 's/ \\+/ /g' |awk '{if($2~\"%d\")print}'| cut -d ' ' -f 11-" - -#define USR_SHARE_APP_CURRENT "/usr/share/applications/." -#define USR_SHARE_APP_UPER "/usr/share/applications/.." -#define PEONY_TRASH "/usr/share/applications/peony-trash.desktop" -#define PEONY_COMUTER "/usr/share/applications/peony-computer.desktop" -#define PEONY_HOME "/usr/share/applications/peony-home.desktop" -#define PEONY_MAIN "/usr/share/applications/peony.desktop" - -#define ORG_UKUI_STYLE "org.ukui.style" -#define STYLE_NAME "styleName" - +#include <QApplication> +#include <QScreen> +//KDE +#include <KF5/KWindowSystem/kwindowsystem.h> class QVBoxLayout; class IUKUIPanelPlugin; @@ -96,51 +55,30 @@ Q_OBJECT public: + const int previewWindowWidth = (QApplication::screens().at(0)->size().width() / 5); + const int previewWindowHeight = (QApplication::screens().at(0)->size().height() / 5); bool m_statFlag = true; bool m_existSameQckBtn = false; - UKUITaskGroup(const QString & groupName, WId window, UKUITaskBar * parent); + UKUITaskGroup(const QString & groupName, const WindowId& window, UKUITaskBar * parent); UKUITaskGroup(QuickLaunchAction * act, IUKUIPanelPlugin * plugin, UKUITaskBar *parent); - UKUITaskGroup(const QString & iconName, const QString & caption, WId window, UKUITaskBar *parent = 0); virtual ~UKUITaskGroup(); QString groupName() const { return m_groupName; } - - int buttonsCount() const; - int visibleButtonsCount() const; - void initVisibleHash(); UKUITaskGroup* getOwnQckBtn() { return this->m_qckLchBtn; } + UKUITaskGroup* getQckLchBtn() { return m_qckLchBtn; } + void setQckLchBtn(UKUITaskGroup *utgp) { if(m_statFlag) m_qckLchBtn = utgp; } - QWidget * addWindow(WId id); - - bool onWindowChanged(WId window, NET::Properties prop, NET::Properties2 prop2); - Qt::ToolButtonStyle popupButtonStyle() const; + UKUITaskButton * addWindow(const WindowId& id); + bool onWindowChanged(const WindowId& window); void setToolButtonsStyle(Qt::ToolButtonStyle style); - void setPopupVisible(bool visible = true, bool fast = false); - - void removeWidget(); - void removeSrollWidget(); - bool isSetMaxWindow(); - void showPreview(); - int calcAverageWidth(); - int calcAverageHeight(); - void showAllWindowByList();//when number of window is more than 30,need show all window of app by a list - void showAllWindowByThumbnail();//when number of window is no more than 30,need show all window of app by a thumbnail - void singleWindowClick(); - void VisibleWndRemoved(WId window); + void showPreviewMode(); + void singleSdkWindowClick(); void setAutoRotation(bool value, IUKUIPanel::Position position); - void setQckLchBtn(UKUITaskGroup *utgp) { if(m_statFlag) m_qckLchBtn = utgp; } - UKUITaskGroup* getQckLchBtn() { return m_qckLchBtn; } - - void setActivateState_wl(bool _state); - void wl_widgetUpdateTitle(QString caption); - QWidget * wl_addWindow(WId id); - bool CheckifWaylandGroup() {return m_isWaylandGroup;} - + int visibleSdkButtonsCount() const; public slots: - void onWindowRemoved(WId window); + void onWindowRemoved(const WindowId& window); void timeout(); - void toDothis_customContextMenuRequested(const QPoint &pos); void onDesktopChanged(); protected: @@ -154,82 +92,64 @@ void mouseMoveEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent *event); int recalculateFrameWidth() const; - void setLayOutForPostion(); - void draggingTimerTimeout(); void paintEvent(QPaintEvent *); private slots: void onClicked(bool checked); - void onChildButtonClicked(); - void onActiveWindowChanged(WId window); + void onActiveWindowChanged(const WindowId& window); void closeGroup(); void refreshIconsGeometry(); - void refreshVisibility(); - void groupPopupShown(UKUITaskGroup* sender); + void refreshSdkVisibility(); void handleSavedEvent(); void AddtoTaskBar(); void RemovefromTaskBar(); - void setSystemStyle(); signals: void groupBecomeEmpty(QString name); - void groupHidden(QString name); - void groupVisible(QString name, bool will); void visibilityChanged(bool visible); - void popupShown(UKUITaskGroup* sender); - void t_saveSettings(); void WindowAddtoTaskBar(QString arg); void WindowRemovefromTaskBar(QString arg); private: - //bool isDesktopFile(QString urlName); + enum TaskGroupStatus{NORMAL, HOVER, PRESS}; + enum TaskGroupEvent{ENTEREVENT, LEAVEEVENT, OTHEREVENT}; + UKUITaskBar * m_parent; UKUITaskGroup *m_qckLchBtn; - void changeTaskButtonStyle(); QString m_groupName; UKUIGroupPopup * m_popup; - UKUITaskButtonHash m_buttonHash; - UKUITaskButtonHash m_visibleHash; - bool m_preventPopup; - bool m_singleButton; //!< flag if this group should act as a "standard" button (no groupping or only one "shown" window in group) - enum TaskGroupStatus{NORMAL, HOVER, PRESS}; - enum TaskGroupEvent{ENTEREVENT, LEAVEEVENT, OTHEREVENT}; + UKUISdkTaskButtonHash m_sdkButtonHash; + UKUISdkTaskButtonHash m_sdkVisibleHash; TaskGroupStatus m_taskGroupStatus; TaskGroupEvent m_taskGroupEvent; - QWidget *m_widget; - QScrollArea *m_scrollArea; QEvent * m_event; - QVector<UKUITaskWidget*> m_showInTurn; QTimer *m_timer; QSize recalculateFrameSize(); QPoint recalculateFramePosition(); + bool m_preventPopup; + void recalculateFrameIfVisible(); - void adjustPopWindowSize(int width, int height); - void v_adjustPopWindowSize(int width, int height, int v_all); - void regroup(); - QString isComputerOrTrash(QString urlName); - void initDesktopFileName(int window); + void initSdkDesktopFileName(const WindowId& window); void initActionsInRightButtonMenu(); - void badBackFunctionToFindDesktop(); - void setBackIcon(); + void changeTaskButtonStyle(); /////////////////////////////// // quicklaunch button QuickLaunchAction *m_act; IUKUIPanelPlugin * m_plugin; QAction *m_deleteAct; - QuicklaunchMenu *m_menu; - TaskGroupStatus m_quickLanuchStatus; - CustomStyle m_toolButtonStyle; + QMenu *m_menu; QGSettings *m_gsettings; - QGSettings *m_styleGSettings; - bool m_isWaylandGroup; + int m_allWidgetWidth = 0; + int m_allWidgetHeight = 0; + bool m_isShowByList = false; + bool m_isThumbnailAvailable = false; + void getThumbnailIfAvailable(); - void winClickActivate_wl(bool _getActive); - void closeGroup_wl(); + void rightMenuCloseAction(QMenu *menu); }; diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskwidget.cpp ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskwidget.cpp --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskwidget.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -43,73 +43,45 @@ #include "ukuitaskgroup.h" #include "ukuitaskbar.h" #include "ukuitaskclosebutton.h" +#include "common/common.h" #include <KWindowSystem/KWindowSystem> // Necessary for closeApplication() #include <KWindowSystem/NETWM> #include <QtX11Extras/QX11Info> -#define WAYLAND_GROUP_HIDE 0 -#define WAYLAND_GROUP_ACTIVATE 1 -#define WAYLAND_GROUP_CLOSE 2 - -bool UKUITaskWidget::m_draggging = false; - -/************************************************ - -************************************************/ -//void LeftAlignedTextStyle::drawItemText(QPainter * painter, const QRect & rect, int flags -// , const QPalette & pal, bool enabled, const QString & text -// , QPalette::ColorRole textRole) const -//{ -// QString txt = QFontMetrics(painter->font()).elidedText(text, Qt::ElideRight, rect.width()); -// return QProxyStyle::drawItemText(painter, rect, (flags & ~Qt::AlignHCenter) | Qt::AlignLeft, pal, enabled, txt, textRole); -//} - - -/************************************************ - -************************************************/ -UKUITaskWidget::UKUITaskWidget(const WId window, UKUITaskBar * taskbar, QWidget *parent) : +UKUITaskWidget::UKUITaskWidget(const WindowId& window, UKUITaskBar * taskbar, QWidget *parent) : QWidget(parent), - m_window(window), - m_urgencyHint(false), - m_origin(Qt::TopLeftCorner), - m_drawPixmap(false), + m_sdkWindow(window), m_parentTaskBar(taskbar), m_plugin(m_parentTaskBar->plugin()), - m_DNDTimer(new QTimer(this)) + m_DNDTimer(new QTimer(this)), + m_timer(new QTimer(this)) { + Q_INIT_RESOURCE(qml); Q_ASSERT(taskbar); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - setMinimumWidth(1); setMinimumHeight(1); setAcceptDrops(true); - // QPixmap closePix = style()->standardPixmap(QStyle::SP_TitleBarCloseButton); m_status=NORMAL; setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口 //for layout - m_closeBtn = new UKUITaskCloseButton(m_window, this); -// m_closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); + m_closeBtn = new UKUITaskCloseButton(m_sdkWindow, this); m_closeBtn->setIconSize(QSize(19,19)); m_closeBtn->setFixedSize(QSize(19,19)); + m_closeBtn->hide(); m_titleLabel = new QLabel(this); m_titleLabel->setMargin(0); - // m_titleLabel->setContentsMargins(0,0,0,10); - // m_titleLabel->adjustSize(); - // m_titleLabel->setStyleSheet("QLabel{background-color: red;}"); m_thumbnailLabel = new QLabel(this); + m_thumbnailLabel->setVisible(false); m_appIcon = new QLabel(this); m_vWindowsLayout = new QVBoxLayout(this); m_topBarLayout = new QHBoxLayout(this); m_topBarLayout->setContentsMargins(0,0,0,0); - // m_topBarLayout->setAlignment(Qt::AlignVCenter); - // m_topBarLayout->setDirection(QBoxLayout::LeftToRight); m_titleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_appIcon->setAlignment(Qt::AlignLeft); @@ -117,22 +89,14 @@ // 自动缩放图片 - // titleLabel->setScaledContents(true); m_thumbnailLabel->setScaledContents(true); // 设置控件缩放方式 - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sizePolicy.setHorizontalPolicy(QSizePolicy::Expanding); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_titleLabel->setSizePolicy(sizePolicy); - m_appIcon->setSizePolicy(sizePolicy); - sizePolicy.setVerticalPolicy(QSizePolicy::Expanding); - - // m_titleLabel->setAttribute(Qt::WA_TranslucentBackground, true); - // m_appIcon->setAttribute(Qt::WA_TranslucentBackground, true); - // m_appIcon->resize(QSize(32,32)); // 设置控件最大尺寸 - //m_titleLabel->setFixedHeight(32); + m_titleLabel->setFixedHeight(32); m_titleLabel->setMinimumWidth(1); m_thumbnailLabel->setMinimumSize(QSize(1, 1)); @@ -141,274 +105,152 @@ m_topBarLayout->addWidget(m_appIcon, 0, Qt::AlignLeft | Qt::AlignVCenter); m_topBarLayout->addWidget(m_titleLabel, 10, Qt::AlignLeft); m_topBarLayout->addWidget(m_closeBtn, 0, Qt::AlignRight); - // m_topBarLayout->addStretch(); -// m_topBarLayout->addWidget(m_closeBtn, 0, Qt::AlignRight | Qt::AlignVCenter); - // m_vWindowsLayout->setAlignment(Qt::AlignCenter); m_vWindowsLayout->addLayout(m_topBarLayout); - m_vWindowsLayout->addWidget(m_thumbnailLabel, Qt::AlignCenter, Qt::AlignCenter); m_vWindowsLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); this->setLayout(m_vWindowsLayout); - updateText(); - updateIcon(); + updateSdkText(); + updateSdkIcon(); m_DNDTimer->setSingleShot(true); m_DNDTimer->setInterval(700); - connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateWithDraggable())); - connect(UKUi::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(updateIcon())); - connect(m_parentTaskBar, &UKUITaskBar::iconByClassChanged, this, &UKUITaskWidget::updateIcon); - connect(m_closeBtn, SIGNAL(sigClicked()), this, SLOT(closeApplication())); -} - -UKUITaskWidget::UKUITaskWidget(QString iconName, const WId window, UKUITaskBar * taskbar, QWidget *parent) : - QWidget(parent), - m_parentTaskBar(taskbar), - m_window(window), - m_DNDTimer(new QTimer(this)) -{ - m_isWaylandWidget = true; - //setMinimumWidth(400); - //setMinimumHeight(400); - m_status=NORMAL; - setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 - setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口 - - //for layout - m_closeBtn = new UKUITaskCloseButton(m_window, this); -// m_closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); - m_closeBtn->setIconSize(QSize(19,19)); - m_closeBtn->setFixedSize(QSize(19,19)); - m_titleLabel = new QLabel(this); - m_titleLabel->setMargin(0); - // m_titleLabel->setContentsMargins(0,0,0,10); - // m_titleLabel->adjustSize(); - // m_titleLabel->setStyleSheet("QLabel{background-color: red;}"); - - m_thumbnailLabel = new QLabel(this); - m_appIcon = new QLabel(this); - m_vWindowsLayout = new QVBoxLayout(this); - m_topBarLayout = new QHBoxLayout(this); - m_topBarLayout->setContentsMargins(0,0,0,0); - // m_topBarLayout->setAlignment(Qt::AlignVCenter); - // m_topBarLayout->setDirection(QBoxLayout::LeftToRight); - - m_titleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); - m_appIcon->setAlignment(Qt::AlignLeft); - m_appIcon->setScaledContents(false); - + connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateSdkWithDraggable())); + connect(m_closeBtn, SIGNAL(sigClicked()), this, SLOT(closeSdkApplication())); + //qml动态预览 + getSysTransparency(); + m_tempView = new QQuickView(); + m_tempView->setSource(QUrl("qrc:/qml/preview.qml")); + m_tempView->setResizeMode(QQuickView::SizeRootObjectToView); + QSurfaceFormat surfaceFormat; + surfaceFormat.setAlphaBufferSize(8);//设置透明通道位数 + m_tempView->setFormat(surfaceFormat); + m_tempView->setClearBeforeRendering(true); + if (m_tempView->rendererInterface()->graphicsApi() < 2) { + m_canUseOpenGL = false; + } + + m_thumbnailPreview = new QWidget(this); + m_thumbnailPreview = QWidget::createWindowContainer(m_tempView, this); + m_thumbnailPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + m_tempItem = m_tempView->rootObject(); + // emit in qml + QObject::connect(m_tempItem, SIGNAL(sendWinId()), this, SLOT(raiseSdkApplication())); + QObject::connect(m_tempItem, SIGNAL(sendMoveEntered()), this, SLOT(keepShow())); + QObject::connect(m_tempItem, SIGNAL(sendMoveLeaved()), this, SLOT(keepLeave())); + QObject::connect(m_tempItem, SIGNAL(sendRightButtonClicked()), this, SLOT(rightButtonMenu())); - // 自动缩放图片 - // titleLabel->setScaledContents(true); - m_thumbnailLabel->setScaledContents(true); - - // 设置控件缩放方式 - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sizePolicy.setHorizontalPolicy(QSizePolicy::Expanding); - m_titleLabel->setSizePolicy(sizePolicy); - m_appIcon->setSizePolicy(sizePolicy); - sizePolicy.setVerticalPolicy(QSizePolicy::Expanding); - - // m_titleLabel->setAttribute(Qt::WA_TranslucentBackground, true); - // m_appIcon->setAttribute(Qt::WA_TranslucentBackground, true); - // m_appIcon->resize(QSize(32,32)); - - // 设置控件最大尺寸 - //m_titleLabel->setFixedHeight(32); - m_titleLabel->setMinimumWidth(1); - m_thumbnailLabel->setMinimumSize(QSize(1, 1)); - m_thumbnailLabel->setMaximumSize(QSize(this->width()*2,this->height()*8)); - - m_titleLabel->setContentsMargins(0, 0, 5, 0); - // m_topBarLayout->setSpacing(5); - m_topBarLayout->addWidget(m_appIcon, 0, Qt::AlignLeft | Qt::AlignVCenter); - m_topBarLayout->addWidget(m_titleLabel, 10, Qt::AlignLeft); - m_topBarLayout->addWidget(m_closeBtn, 0, Qt::AlignRight); - // m_topBarLayout->addStretch(); -// m_topBarLayout->addWidget(m_closeBtn, 0, Qt::AlignRight | Qt::AlignVCenter); - // m_vWindowsLayout->setAlignment(Qt::AlignCenter); - m_vWindowsLayout->addLayout(m_topBarLayout); - m_vWindowsLayout->addWidget(m_thumbnailLabel, Qt::AlignCenter, Qt::AlignCenter); - m_vWindowsLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); - this->setLayout(m_vWindowsLayout); - updateText(); - updateIcon(); - m_DNDTimer->setSingleShot(true); - m_DNDTimer->setInterval(700); - connect(m_DNDTimer, SIGNAL(timeout()), this, SLOT(activateWithDraggable())); - connect(UKUi::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(updateIcon())); - connect(m_parentTaskBar, &UKUITaskBar::iconByClassChanged, this, &UKUITaskWidget::updateIcon); - connect(m_closeBtn, SIGNAL(sigClicked()), this, SLOT(closeApplication())); + m_timer->setTimerType(Qt::PreciseTimer); + connect(m_timer, SIGNAL(timeout()), SLOT(sendSigToKwin())); } -/************************************************ -************************************************/ UKUITaskWidget::~UKUITaskWidget() { this->deleteLater(); } -/************************************************ - - ************************************************/ -void UKUITaskWidget::updateText() +void UKUITaskWidget::updateSdkText() { - KWindowInfo info(m_window, NET::WMVisibleName | NET::WMName); - QString title = info.visibleName().isEmpty() ? info.name() : info.visibleName(); + QString title = WindowManager::getWindowTitle(m_sdkWindow); m_titleLabel->setToolTip(title); QTimer::singleShot(0,this,[=](){ QString formatAppName = m_titleLabel->fontMetrics().elidedText(title,Qt::ElideRight, m_titleLabel->width()); m_titleLabel->setText(formatAppName); - QPalette pa; - pa.setColor(QPalette::WindowText,Qt::white); - m_titleLabel->setPalette(pa); }); - -// m_titleLabel->setText(title); - - // setText(title.replace("&", "&&")); - // setToolTip(title); } -/************************************************ - - ************************************************/ -void UKUITaskWidget::updateIcon() +void UKUITaskWidget::updateSdkIcon() { QIcon ico; - if (m_parentTaskBar->isIconByClass()) { - ico = QIcon::fromTheme(QString::fromUtf8(KWindowInfo{m_window, 0, NET::WM2WindowClass}.windowClassClass()).toLower()); - } if (ico.isNull()) { - ico = KWindowSystem::icon(m_window); + ico = WindowManager::getWindowIcon(m_sdkWindow); + if (ico.isNull()) { + ico = QIcon::fromTheme(getAndroidAppIcon(m_sdkWindow)); + } } - m_appIcon->setPixmap(ico.pixmap(QSize(19,19))); - setPixmap(KWindowSystem::icon(m_window)); -// m_pixmap = ico.pixmap(QSize(64,64); - //m_appIcon->setWindowIcon(ico.isNull() ? XdgIcon::defaultApplicationIcon() : ico); - //setIcon(ico.isNull() ? XdgIcon::defaultApplicationIcon() : ico); -} - - -void UKUITaskWidget::setPixmap(QPixmap _pixmap) -{ - m_pixmap = _pixmap; -} -QPixmap UKUITaskWidget::getPixmap() -{ - return m_pixmap; + m_appIcon->setPixmap(ico.pixmap(QSize(19,19))); + setIcon(ico); } - -/************************************************ - - ************************************************/ -void UKUITaskWidget::refreshIconGeometry(QRect const & geom) +QString UKUITaskWidget::getAndroidAppIcon(const WindowId& windowId) { - NETWinInfo info(QX11Info::connection(), - windowId(), - (WId) QX11Info::appRootWindow(), - NET::WMIconGeometry, - 0); - NETRect const curr = info.iconGeometry(); - if (curr.pos.x != geom.x() || curr.pos.y != geom.y() - || curr.size.width != geom.width() || curr.size.height != geom.height()) { - NETRect nrect; - nrect.pos.x = geom.x(); - nrect.pos.y = geom.y(); - nrect.size.height = geom.height(); - nrect.size.width = geom.width(); - info.setIconGeometry(nrect); + QString iconName; + QString appName; + quint32 winPid = WindowManager::getPid(windowId); + QString cmd = "ps -p " + QString::number(winPid) + " -f | grep " + QString::number(winPid); + QStringList options; + options << "-c" << cmd; + m_cmdProcess = new QProcess(this); + m_cmdProcess->start("/bin/bash", options); + m_cmdProcess->waitForStarted(); + m_cmdProcess->waitForFinished(); + QString cmdRet = QString (m_cmdProcess->readAllStandardOutput()); + QStringList strlist = cmdRet.split(" ", QString::SkipEmptyParts); + for (int i = 0; i < strlist.size(); i++) { + if (strlist.at(i) == "-p") { + appName = strlist.at(i+1); + break; + } } -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::dragEnterEvent(QDragEnterEvent *event) -{ - // It must be here otherwise dragLeaveEvent and dragMoveEvent won't be called - // on the other hand drop and dragmove events of parent widget won't be called - event->acceptProposedAction(); - if (event->mimeData()->hasFormat(mimeDataFormat())) { - emit dragging(event->source(), event->pos()); - setAttribute(Qt::WA_UnderMouse, false); - } else { - m_DNDTimer->start(); + iconName = QDir::homePath() + "/.local/share/icons/" + appName + ".svg"; + if (!QFile(iconName).exists()) { + iconName = QDir::homePath() + "/.local/share/icons/" + appName + ".png"; + if (!QFile(iconName).exists()) { + iconName = "application-x-desktop"; + } } - - QWidget::dragEnterEvent(event); + return iconName; } -void UKUITaskWidget::dragMoveEvent(QDragMoveEvent * event) -{ - if (event->mimeData()->hasFormat(mimeDataFormat())) { - emit dragging(event->source(), event->pos()); - setAttribute(Qt::WA_UnderMouse, false); - } -} -void UKUITaskWidget::dragLeaveEvent(QDragLeaveEvent *event) +void UKUITaskWidget::setPixmap(QPixmap _pixmap) { - m_DNDTimer->stop(); - QWidget::dragLeaveEvent(event); + m_pixmap = _pixmap; } -void UKUITaskWidget::dropEvent(QDropEvent *event) +void UKUITaskWidget::setIcon(QIcon icon) { - m_DNDTimer->stop(); - if (event->mimeData()->hasFormat(mimeDataFormat())) { - emit dropped(event->source(), event->pos()); - setAttribute(Qt::WA_UnderMouse, false); - } - QWidget::dropEvent(event); + m_icon = icon; } -/************************************************ - - ************************************************/ void UKUITaskWidget::mousePressEvent(QMouseEvent* event) { const Qt::MouseButton b = event->button(); if (Qt::LeftButton == b) { - m_dragStartPosition = event->pos(); - } else if (Qt::MidButton == b && parentTaskBar()->closeOnMiddleClick()) { - closeApplication(); + activateSdkWithDraggable(); } QWidget::mousePressEvent(event); } -/************************************************ - - ************************************************/ void UKUITaskWidget::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) { // if (isChecked()) // minimizeApplication(); // else - raiseApplication(); + raiseSdkApplication(); } m_status = NORMAL; + m_closeBtn->hide(); update(); QWidget::mouseReleaseEvent(event); } -/************************************************ - - ************************************************/ - void UKUITaskWidget::enterEvent(QEvent *) { m_status = HOVER; + m_closeBtn->show(); + sendSigToKwin(); repaint(); } void UKUITaskWidget::leaveEvent(QEvent *) { m_status = NORMAL; + m_closeBtn->hide(); repaint(); } QMimeData * UKUITaskWidget::mimeData() @@ -421,25 +263,68 @@ return mimedata; } -/************************************************ - - ************************************************/ void UKUITaskWidget::mouseMoveEvent(QMouseEvent* event) { } -void UKUITaskWidget::closeGroup() { - emit closeSigtoGroup(); +void UKUITaskWidget::keepShow() +{ + m_status = HOVER; + m_closeBtn->show(); + repaint(); + //TODO:发信号给group + emit signalKeepShow(true); + + m_timer->start(200); } -void UKUITaskWidget::contextMenuEvent(QContextMenuEvent *event) +void UKUITaskWidget::sendSigToKwin() { - KWindowInfo info(m_window, 0, NET::WM2AllowedActions); - unsigned long state = KWindowInfo(m_window, NET::WMState).state(); + QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "panelUpdateLayer"); + QList<QVariant> args; + quint32 m_wid = m_sdkWindow.toInt(); + args.append(m_wid); + message.setArguments(args); + QDBusConnection::sessionBus().send(message); - if (!m_plugin || m_isWaylandWidget) { +} + +void UKUITaskWidget::sendCloseSigToKWin() +{ + QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "panelNotUpdateLayer"); + QList<QVariant> args; + bool flag = true; + args.append(flag); + message.setArguments(args); + QDBusConnection::sessionBus().send(message); +} + +void UKUITaskWidget::keepLeave() +{ + if (m_timer->isActive()) { + m_timer->stop(); + } + m_status = NORMAL; + m_closeBtn->hide(); + repaint(); + emit signalKeepLeave(true); + + if(this->isVisible()) { return; } +} + +void UKUITaskWidget::contextMenuEvent(QContextMenuEvent *event) +{ + if (!m_plugin) { + return; + } + rightButtonMenu(); +} + +void UKUITaskWidget::rightButtonMenu() +{ + WindowInfo info = WindowManager::getwindowInfo(m_sdkWindow); QMenu * menu = new QMenu(tr("Widget")); menu->setAttribute(Qt::WA_DeleteOnClose); /* 对应预览图右键功能 关闭 还原 最大化 最小化 置顶 取消置顶*/ @@ -447,139 +332,71 @@ QAction *restore = menu->addAction(QIcon::fromTheme("window-restore-symbolic"), tr("restore")); QAction *maxim = menu->addAction(QIcon::fromTheme("window-maximize-symbolic"), tr("maximaze")); - maxim->setEnabled(info.actionSupported(NET::ActionMax) && (!(state & NET::Max) || (state & NET::Hidden))); + maxim->setEnabled(!info.isMaximized()); QAction *minim = menu->addAction(QIcon::fromTheme("window-minimize-symbolic"), tr("minimize")); - QAction *above = menu->addAction(QIcon::fromTheme("ukui-fixed"), tr("above")); - QAction *clear = menu->addAction(QIcon::fromTheme("ukui-unfixed"), tr("clear")); + QAction *above = menu->addAction(QIcon::fromTheme("ukui-fixed-symbolic"), tr("above")); + QAction *clear = menu->addAction(QIcon::fromTheme("ukui-unfixed-symbolic"), tr("clear")); - connect(close, SIGNAL(triggered()), this, SLOT(closeApplication())); + connect(close, SIGNAL(triggered()), this, SLOT(closeSdkApplication())); connect(restore, SIGNAL(triggered()), this, SLOT(deMaximizeApplication())); connect(maxim, SIGNAL(triggered()), this, SLOT(maximizeApplication())); connect(minim, SIGNAL(triggered()), this, SLOT(minimizeApplication())); connect(above, SIGNAL(triggered()), this, SLOT(setWindowKeepAbove())); connect(clear, SIGNAL(triggered()), this, SLOT(setWindowStatusClear())); connect(menu, &QMenu::aboutToHide, [this] {emit closeSigtoPop();}); - above->setEnabled(!(state & NET::KeepAbove)); - clear->setEnabled(state & NET::KeepAbove); + above->setEnabled(!info.isKeepAbove()); + clear->setEnabled(info.isKeepAbove()); menu->exec(cursor().pos()); plugin()->willShowWindow(menu); - if (!m_isWaylandWidget) { - menu->show(); - } -} -/************************************************ - - ************************************************/ -bool UKUITaskWidget::isApplicationHidden() const -{ - KWindowInfo info(m_window, NET::WMState); - return (info.state() & NET::Hidden); + menu->show(); } - -/************************************************ - - ************************************************/ bool UKUITaskWidget::isApplicationActive() const { return KWindowSystem::activeWindow() == m_window; } -/************************************************ - - ************************************************/ -void UKUITaskWidget::activateWithDraggable() +void UKUITaskWidget::activateSdkWithDraggable() { // raise app in any time when there is a drag // in progress to allow drop it into an app - raiseApplication(); - KWindowSystem::forceActiveWindow(m_window); + raiseSdkApplication(); + WindowManager::activateWindow(m_sdkWindow); } -/************************************************ - - ************************************************/ -void UKUITaskWidget::raiseApplication() +void UKUITaskWidget::raiseSdkApplication() { - KWindowSystem::clearState(m_window, NET::Hidden); - if (m_isWaylandWidget) { - QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "request"); - QList<QVariant> args; - quint32 m_wid=windowId(); - args.append(m_wid); - args.append(WAYLAND_GROUP_ACTIVATE); - repaint(); - message.setArguments(args); - QDBusConnection::sessionBus().send(message); - emit windowMaximize(); - - setUrgencyHint(false); - return; - } + KWindowSystem::clearState(m_sdkWindow.toInt(), NET::Hidden); - KWindowInfo info(m_window, NET::WMDesktop | NET::WMState | NET::XAWMState); - if (parentTaskBar()->raiseOnCurrentDesktop() && info.isMinimized()) { - KWindowSystem::setOnDesktop(m_window, KWindowSystem::currentDesktop()); - } else { - int winDesktop = info.desktop(); - if (KWindowSystem::currentDesktop() != winDesktop) { - KWindowSystem::setCurrentDesktop(winDesktop); - } - } - KWindowSystem::activateWindow(m_window); - emit windowMaximize(); - - setUrgencyHint(false); + WindowInfo info = WindowManager::getwindowInfo(m_sdkWindow); + if (info.isMinimized()) { + WindowManager::activateWindow(m_sdkWindow); + } + WindowManager::activateWindow(m_sdkWindow); + sendCloseSigToKWin(); + emit windowActived(); } -/************************************************ - - ************************************************/ void UKUITaskWidget::minimizeApplication() { - KWindowSystem::minimizeWindow(m_window); + WindowManager::minimizeWindow(m_sdkWindow); } -/************************************************ - - ************************************************/ void UKUITaskWidget::maximizeApplication() { - QAction* act = qobject_cast<QAction*>(sender()); - if (!act) { - return; - } - - int state = act->data().toInt(); - switch (state) { - case NET::MaxHoriz: - KWindowSystem::setState(m_window, NET::MaxHoriz); - break; - - case NET::MaxVert: - KWindowSystem::setState(m_window, NET::MaxVert); - break; - - default: - KWindowSystem::setState(m_window, NET::Max); - break; - } - + WindowManager::maximizeWindow(m_sdkWindow); if (!isApplicationActive()) { - raiseApplication(); + raiseSdkApplication(); } } -/************************************************ - - ************************************************/ void UKUITaskWidget::deMaximizeApplication() { KWindowSystem::clearState(m_window, NET::Max); if (!isApplicationActive()) { - raiseApplication(); + raiseSdkApplication(); } } @@ -587,279 +404,58 @@ void UKUITaskWidget::setWindowKeepAbove() { if (!isApplicationActive()) { - raiseApplication(); + raiseSdkApplication(); } - KWindowSystem::setState(m_window, NET::KeepAbove); + WindowManager::keepWindowAbove(m_sdkWindow); } void UKUITaskWidget::setWindowStatusClear() { - KWindowSystem::clearState(m_window, NET::KeepAbove); + WindowManager::keepWindowAbove(m_sdkWindow); } -/************************************************ - - ************************************************/ -void UKUITaskWidget::shadeApplication() -{ - KWindowSystem::setState(m_window, NET::Shaded); -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::unShadeApplication() -{ - KWindowSystem::clearState(m_window, NET::Shaded); -} - -/************************************************ - - ************************************************/ -//void UKUITaskWidget::priv_closeApplication() { -//} -void UKUITaskWidget::closeApplication() +void UKUITaskWidget::closeSdkApplication() { // FIXME: Why there is no such thing in KWindowSystem?? - if (m_isWaylandWidget) { - QDBusMessage message = QDBusMessage::createSignal("/", "com.ukui.kwin", "request"); - QList<QVariant> args; - quint32 m_wid=windowId(); - args.append(m_wid); - args.append(WAYLAND_GROUP_CLOSE); - message.setArguments(args); - QDBusConnection::sessionBus().send(message); - } - NETRootInfo(QX11Info::connection(), NET::CloseWindow).closeWindowRequest(m_window); -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::setApplicationLayer() -{ - QAction* act = qobject_cast<QAction*>(sender()); - if (!act) { - return; - } - - int layer = act->data().toInt(); - switch (layer) { - case NET::KeepAbove: - KWindowSystem::clearState(m_window, NET::KeepBelow); - KWindowSystem::setState(m_window, NET::KeepAbove); - break; - - case NET::KeepBelow: - KWindowSystem::clearState(m_window, NET::KeepAbove); - KWindowSystem::setState(m_window, NET::KeepBelow); - break; - - default: - KWindowSystem::clearState(m_window, NET::KeepBelow); - KWindowSystem::clearState(m_window, NET::KeepAbove); - break; - } -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::moveApplicationToDesktop() -{ - QAction* act = qobject_cast<QAction*>(sender()); - if (!act) { - return; - } - - bool ok; - int desk = act->data().toInt(&ok); - - if (!ok) { - return; - } - - KWindowSystem::setOnDesktop(m_window, desk); -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::moveApplication() -{ - KWindowInfo info(m_window, NET::WMDesktop); - if (!info.isOnCurrentDesktop()) { - KWindowSystem::setCurrentDesktop(info.desktop()); - } - if (isMinimized()) { - KWindowSystem::unminimizeWindow(m_window); - } - KWindowSystem::forceActiveWindow(m_window); - const QRect& g = KWindowInfo(m_window, NET::WMGeometry).geometry(); - int X = g.center().x(); - int Y = g.center().y(); - QCursor::setPos(X, Y); - NETRootInfo(QX11Info::connection(), NET::WMMoveResize).moveResizeRequest(m_window, X, Y, NET::Move); -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::resizeApplication() -{ - KWindowInfo info(m_window, NET::WMDesktop); - if (!info.isOnCurrentDesktop()) { - KWindowSystem::setCurrentDesktop(info.desktop()); - } - if (isMinimized()) { - KWindowSystem::unminimizeWindow(m_window); - } - KWindowSystem::forceActiveWindow(m_window); - const QRect& g = KWindowInfo(m_window, NET::WMGeometry).geometry(); - int X = g.bottomRight().x(); - int Y = g.bottomRight().y(); - QCursor::setPos(X, Y); - NETRootInfo(QX11Info::connection(), NET::WMMoveResize).moveResizeRequest(m_window, X, Y, NET::BottomRight); -} - -/************************************************ - - ************************************************/ -void UKUITaskWidget::setUrgencyHint(bool set) -{ - if (m_urgencyHint == set) { - return; - } - - if (!set) { - KWindowSystem::demandAttention(m_window, false); - } - - m_urgencyHint = set; - setProperty("urgent", set); - style()->unpolish(this); - style()->polish(this); - update(); -} - -/************************************************ - - ************************************************/ -bool UKUITaskWidget::isOnDesktop(int desktop) const -{ - return KWindowInfo(m_window, NET::WMDesktop).isOnDesktop(desktop); + WindowManager::closeWindow(m_sdkWindow); + sendCloseSigToKWin(); } -bool UKUITaskWidget::isOnCurrentScreen() const +void UKUITaskWidget::getSysTransparency() { - return QApplication::desktop()->screenGeometry(parentTaskBar()).intersects(KWindowInfo(m_window, NET::WMFrameExtents).frameGeometry()); -} - -bool UKUITaskWidget::isMinimized() const -{ - return KWindowInfo(m_window,NET::WMState | NET::XAWMState).isMinimized(); -} - -bool UKUITaskWidget::isFocusState() const -{ - qDebug()<<"KWindowInfo(m_window,NET::WMState).state():"<<KWindowInfo(m_window,NET::WMState).state(); -#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0)) - return NET::Focused == (KWindowInfo(m_window,NET::WMState).state()&NET::Focused); -#else - return isApplicationActive(); -#endif -} - -Qt::Corner UKUITaskWidget::origin() const -{ - return m_origin; -} - -void UKUITaskWidget::setOrigin(Qt::Corner newOrigin) -{ - if (m_origin != newOrigin) { - m_origin = newOrigin; - update(); - } -} - -void UKUITaskWidget::setAutoRotation(bool value, IUKUIPanel::Position position) -{ - if (value) { - switch (position) { - case IUKUIPanel::PositionTop: - case IUKUIPanel::PositionBottom: - setOrigin(Qt::TopLeftCorner); - break; - - case IUKUIPanel::PositionLeft: - setOrigin(Qt::BottomLeftCorner); - break; - - case IUKUIPanel::PositionRight: - setOrigin(Qt::TopRightCorner); - break; - } + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); + if(QGSettings::isSchemaInstalled(transparency_id)) { + m_transparencyGsettings = new QGSettings(transparency_id); + m_transparency = m_transparencyGsettings->get(TRANSPARENCY_KEY).toDouble(); + this->update(); + connect(m_transparencyGsettings, &QGSettings::changed, this, [=] (const QString &key){ + if(key == TRANSPARENCY_KEY) { + m_transparency = m_transparencyGsettings->get(TRANSPARENCY_KEY).toDouble(); + this->update(); + } + }); } else { - setOrigin(Qt::TopLeftCorner); + m_transparency=0.75; } + } void UKUITaskWidget::paintEvent(QPaintEvent *event) { - - /*旧的设置预览三态的方式,注释掉的原因是其未能设置阴影*/ -#if 0 QStyleOption opt; opt.init(this); QPainter p(this); - - switch(m_status) - { - case NORMAL: - { - p.setBrush(QBrush(QColor(0x13,0x14,0x14,0xb2))); - p.setPen(Qt::black); - break; - } - case HOVER: - { - // p.setBrush(QBrush(QColor(0xFF,0xFF,0xFF,0x19))); - p.setBrush(QBrush(QColor(0x13,0x14,0x14,0x19))); - p.setPen(Qt::black); - break; - } - case PRESS: - { - p.setBrush(QBrush(QColor(0xFF,0xFF,0xFF,0x19))); - p.setPen(Qt::white); - break; - } - } - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - p.drawRoundedRect(opt.rect,6,6); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); - -#endif - -#if 1 - - /* - * 预览图的设置阴影的方式与其他控件有所不同 - * 由于涉及到UKUITaskWidget 中心是一张截图 - * 此处设置阴影的方式不是一种通用的方式 - * tr: - * The way of setting shadow in preview image is different from other controls - * As it involves UKUITaskWidget center is a screenshot - * The way to set the shadow here is not a general way -*/ - QPainter p(this); p.setRenderHint(QPainter::Antialiasing); + QColor color= palette().color(QPalette::BrightText); + color.setAlphaF(0.15); + p.setPen(color); + p.drawRoundedRect(opt.rect,12,12); + QPainterPath rectPath; - rectPath.addRoundedRect(this->rect(),6,6); - // 画一个黑底 + rectPath.addRoundedRect(this->rect().adjusted(1, 1, -1, -1), 12, 12); QPixmap pixmap(this->rect().size()); pixmap.fill(Qt::transparent); + QPainter pixmapPainter(&pixmap); pixmapPainter.setRenderHint(QPainter::Antialiasing); @@ -876,34 +472,39 @@ QPainter pixmapPainter2(&pixmap); pixmapPainter2.setRenderHint(QPainter::Antialiasing); pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear); - /*在Qt中定义了一个常量,用于设置透明的颜色,即Qt::transparent,表示RGBA值为(0,0,0,0)的透明色。*/ - // pixmapPainter2.setPen(Qt::transparent); - // pixmapPainter2.setBrush(Qt::transparent); pixmapPainter2.drawPath(rectPath); // 绘制阴影 - p.drawPixmap(this->rect(), pixmap, pixmap.rect()); +// p.drawPixmap(this->rect(), pixmap, pixmap.rect()); // 绘制底色 p.save(); + QColor col; switch (m_status) { - case NORMAL: - p.fillPath(rectPath, QColor(0x13,0x14,0x14,0xb2)); - break; + case NORMAL: + col = this->palette().color(QPalette::Window); + break; - case HOVER: - p.fillPath(rectPath, QColor(0x13,0x14,0x14,0x66)); - break; + case HOVER: + col = this->palette().color(QPalette::Button); + break; - case PRESS: - p.fillPath(rectPath, QColor(0xFF,0xFF,0xFF,0x19)); - break; + case PRESS: + col = this->palette().color(QPalette::Button); + break; } + + col.setAlphaF(m_transparency); + p.fillPath(rectPath, col); + //预览窗标题文字颜色 + QPalette pal = m_titleLabel->palette(); + QColor coll = pal.color( QPalette::Text); + pal.setColor(QPalette::Text, coll); + m_titleLabel->setPalette(pal); p.restore(); -#endif -} +} bool UKUITaskWidget::hasDragAndDropHover() const { @@ -911,12 +512,14 @@ } void UKUITaskWidget::updateTitle() { - updateText(); + updateSdkText(); } void UKUITaskWidget::setThumbNail(QPixmap _pixmap) { + m_thumbnailLabel->setVisible(true); m_thumbnailLabel->setPixmap(_pixmap); + m_vWindowsLayout->addWidget(m_thumbnailLabel, Qt::AlignCenter, Qt::AlignCenter); } void UKUITaskWidget::removeThumbNail() @@ -936,26 +539,42 @@ m_thumbnailLabel->setScaledContents(true); m_thumbnailLabel->setMinimumSize(QSize(1, 1)); // m_vWindowsLayout->addLayout(m_topBarLayout, 100); - m_vWindowsLayout->addWidget(m_thumbnailLabel, 0, Qt::AlignCenter); + //m_vWindowsLayout->addWidget(m_thumbnailLabel, 0, Qt::AlignCenter); } else { return; } } - -void UKUITaskWidget::setTitleFixedWidth(int size) +void UKUITaskWidget::setLiveThumbNail(int w, int h) { - m_titleLabel->setFixedWidth(size); - m_titleLabel->adjustSize(); + QColor col; + col = this->palette().color(QPalette::Window); + col.setAlphaF(m_transparency); + m_tempView->setColor(col); + + m_tempRecl = m_tempItem->findChild<QObject *>("tmpWindowThumbnail"); + m_tempRecl->setProperty("winId", m_sdkWindow.toInt()); + m_thumbnailPreview->setFixedSize(w,h); + m_vWindowsLayout->addWidget(m_thumbnailPreview); + + float tmp_imgWidth = w; + float tmp_imgHeight = h; + QObject *pRect = m_tempView->findChild<QObject *>("rect1"); + QMetaObject::invokeMethod(pRect, "setValue", Q_ARG(QVariant, QVariant(tmp_imgWidth)), Q_ARG(QVariant, QVariant(tmp_imgHeight))); + } -int UKUITaskWidget::getWidth() +void UKUITaskWidget::removeLiveThumbNail() { - return m_titleLabel->width(); + if (m_thumbnailPreview) { + m_vWindowsLayout->removeWidget(m_thumbnailPreview); + } } -void UKUITaskWidget::setThumbFixedSize(int w) { - this->m_thumbnailLabel->setFixedWidth(w); +void UKUITaskWidget::setTitleFixedWidth(int size) +{ + m_titleLabel->setFixedWidth(size); + m_titleLabel->adjustSize(); } void UKUITaskWidget::setThumbMaximumSize(int w) { @@ -965,15 +584,3 @@ void UKUITaskWidget::setThumbScale(bool val) { this->m_thumbnailLabel->setScaledContents(val); } - -void UKUITaskWidget::wl_updateIcon(QString iconName){ - m_appIcon->setPixmap(QIcon::fromTheme(iconName).pixmap(QSize(19,19))); -} - -void UKUITaskWidget::wl_updateTitle(QString caption) { - m_titleLabel->setText(caption); - printf("\n%s\n", caption.toStdString().data()); - QPalette pa; - pa.setColor(QPalette::WindowText,Qt::white); - m_titleLabel->setPalette(pa); -} diff -Nru ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskwidget.h ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskwidget.h --- ukui-panel-3.14.0.1/plugin-taskbar/ukuitaskwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/plugin-taskbar/ukuitaskwidget.h 2023-05-22 14:06:12.000000000 +0800 @@ -22,12 +22,21 @@ #include <QProxyStyle> #include "../panel/iukuipanel.h" -//#include <QWinThumbnailToolBar> #include <QtX11Extras/qtx11extrasversion.h> #include <QLabel> #include <QVBoxLayout> #include <QStyle> #include <KWindowInfo> +#include <QProcess> + +#include <QtQuick/QQuickView> +#include <QUrl> +#include <QMainWindow> +#include <QtQuickWidgets/QtQuickWidgets> +#include <QGSettings> + +#include <windowmanager/windowmanager.h> +using namespace kdk; class QPainter; class QPalette; @@ -39,64 +48,43 @@ class UKUITaskWidget : public QWidget { Q_OBJECT - - Q_PROPERTY(Qt::Corner origin READ origin WRITE setOrigin) - public: - explicit UKUITaskWidget(const WId window, UKUITaskBar * taskBar, QWidget *parent = 0); - explicit UKUITaskWidget(QString iconName, const WId window, UKUITaskBar * taskbar, QWidget *parent = 0); + explicit UKUITaskWidget(const WindowId& window, UKUITaskBar * taskBar, QWidget *parent = 0); virtual ~UKUITaskWidget(); - bool isApplicationHidden() const; bool isApplicationActive() const; - WId windowId() const { return m_window; } - - bool hasUrgencyHint() const { return m_urgencyHint; } - void setUrgencyHint(bool set); + WindowId sdkWindowId() const { m_sdkWindow;} - bool isOnDesktop(int desktop) const; - bool isOnCurrentScreen() const; - bool isMinimized() const; - bool isFocusState() const; - void setThumbFixedSize(int w); void setThumbScale(bool val); void setThumbMaximumSize(int w); - void updateText(); - - Qt::Corner origin() const; - virtual void setAutoRotation(bool value, IUKUIPanel::Position position); + void updateSdkText(); UKUITaskBar * parentTaskBar() const {return m_parentTaskBar;} - void refreshIconGeometry(QRect const & geom); static QString mimeDataFormat() { return QLatin1String("ukui/UKUITaskWidget"); } /*! \return true if this buttom received DragEnter event (and no DragLeave event yet) * */ bool hasDragAndDropHover() const; void setThumbNail(QPixmap _pixmap); + void setLiveThumbNail(int w, int h); + void removeLiveThumbNail(); void setTitleFixedWidth(int size); void updateTitle(); void removeThumbNail(); void addThumbNail(); - void setPixmap(QPixmap m_pixmap); - int getWidth(); - QPixmap getPixmap(); + void setPixmap(QPixmap _pixmap); + void setIcon(QIcon ico); - void wl_updateTitle(QString caption); - void wl_updateIcon(QString iconName); + QString getAndroidAppIcon(const WindowId& windowId); + bool canUseOpenGL() { return m_canUseOpenGL;} public slots: - void raiseApplication(); + void raiseSdkApplication(); void minimizeApplication(); void maximizeApplication(); void deMaximizeApplication(); - void shadeApplication(); - void unShadeApplication(); - void closeApplication(); - void moveApplicationToDesktop(); - void moveApplication(); - void resizeApplication(); - void setApplicationLayer(); + + void closeSdkApplication(); /** * @brief setWindowKeepAbove * 窗口置顶 @@ -108,15 +96,9 @@ */ void setWindowStatusClear(); - void setOrigin(Qt::Corner); - - void updateIcon(); + void updateSdkIcon(); protected: - virtual void dragEnterEvent(QDragEnterEvent *event); - virtual void dragMoveEvent(QDragMoveEvent * event); - virtual void dragLeaveEvent(QDragLeaveEvent *event); - virtual void dropEvent(QDropEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); @@ -127,26 +109,32 @@ void setWindowId(WId wid) {m_window = wid;} virtual QMimeData * mimeData(); - static bool m_draggging; - inline IUKUIPanelPlugin * plugin() const { return m_plugin; } private: WId m_window; - bool m_urgencyHint; - QPoint m_dragStartPosition; - Qt::Corner m_origin; + WindowId m_sdkWindow; QPixmap m_pixmap; - bool m_drawPixmap; UKUITaskBar * m_parentTaskBar; IUKUIPanelPlugin * m_plugin; QLabel *m_titleLabel; QLabel *m_thumbnailLabel; QLabel *m_appIcon; + QIcon m_icon; UKUITaskCloseButton *m_closeBtn; QVBoxLayout *m_vWindowsLayout; QHBoxLayout *m_topBarLayout; + QProcess *m_cmdProcess; + QWidget *m_thumbnailPreview; + QQuickView *m_tempView; + QObject *m_tempItem; + QObject *m_tempRecl; + bool m_canUseOpenGL = true; + + QGSettings *m_transparencyGsettings; + double m_transparency; + void getSysTransparency(); // Timer for when draggind something into a button (the button's window // must be activated so that the use can continue dragging to the window @@ -154,20 +142,30 @@ enum TaskWidgetStatus{NORMAL, HOVER, PRESS}; TaskWidgetStatus m_status; - bool m_isWaylandWidget = false; + QTimer *m_timer; + QGSettings *m_changeTheme; private slots: - void activateWithDraggable(); - void closeGroup(); + void activateSdkWithDraggable(); + + void keepShow(); + void keepLeave(); + + void sendSigToKwin(); + void sendCloseSigToKWin(); + void rightButtonMenu(); signals: void dropped(QObject * dragSource, QPoint const & pos); void dragging(QObject * dragSource, QPoint const & pos); - void windowMaximize(); + void windowActived(); void closeSigtoPop(); void closeSigtoGroup(); + void signalKeepShow(bool flag); + void signalKeepLeave(bool flag); }; -typedef QHash<WId,UKUITaskWidget*> UKUITaskButtonHash; +typedef QHash<WId,UKUITaskWidget*> UKUITaskWidgetHash; +typedef QHash<qint64, UKUITaskWidget*> UKUISdkTaskWidgetHash; #endif // UKUITASKWIDGET_H diff -Nru ukui-panel-3.14.0.1/sni-daemon/main.cpp ukui-panel-4.0.0.0/sni-daemon/main.cpp --- ukui-panel-3.14.0.1/sni-daemon/main.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-daemon/main.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -19,10 +19,22 @@ #include "snidaemon.h" #include <ukui-log4qt.h> #include <QApplication> +#include <QStandardPaths> +#include <QFile> +#include <fcntl.h> +#include <syslog.h> int main(int argc, char *argv[]) { initUkuiLog4qt("sni-daemon"); + /*单例+vnc模式*/ + QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); + int fd = open(QString(homePath.at(0) + "/.config/sni-daemon.lock").toUtf8().data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) { exit(1); } + if (lockf(fd, F_TLOCK, 0)) { + syslog(LOG_ERR, "Can't lock single file, sni-daemon is already running!"); + exit(0); + } QApplication a(argc, argv); SniDaemon w; return a.exec(); diff -Nru ukui-panel-3.14.0.1/sni-xembed-proxy/CMakeLists.txt ukui-panel-4.0.0.0/sni-xembed-proxy/CMakeLists.txt --- ukui-panel-3.14.0.1/sni-xembed-proxy/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-xembed-proxy/CMakeLists.txt 2023-05-22 14:06:12.000000000 +0800 @@ -22,6 +22,7 @@ find_package(PkgConfig REQUIRED) find_package(KF5WindowSystem REQUIRED) find_package(Qt5X11Extras REQUIRED) +find_package(X11 REQUIRED) add_executable(sni-xembed-proxy main.cpp @@ -29,7 +30,7 @@ sniproxy.cpp snidbus.cpp statusnotifierwatcher_interface.cpp - ../panel-daemon/convert-desktop-windowid/convertdesktoptowinid.cpp + xtestsender.cpp snixembedproxy.h sniproxy.h @@ -37,7 +38,7 @@ statusnotifierwatcher_interface.h systemtraytypedefs.h xcbutilss.h - ../panel-daemon/convert-desktop-windowid/convertdesktoptowinid.h + xtestsender.h ) target_link_libraries(sni-xembed-proxy @@ -53,6 +54,8 @@ xcb-shape -lukui-log4qt -lQt5Xdg + ${XCB_LIBS} + ${X11_XTest_LIB} ) add_definitions(-DQT_NO_KEYWORDS) diff -Nru ukui-panel-3.14.0.1/sni-xembed-proxy/main.cpp ukui-panel-4.0.0.0/sni-xembed-proxy/main.cpp --- ukui-panel-3.14.0.1/sni-xembed-proxy/main.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-xembed-proxy/main.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -20,6 +20,10 @@ #include <QApplication> #include <QSessionManager> #include <ukui-log4qt.h> +#include <QStandardPaths> +#include <QFile> +#include <fcntl.h> +#include <syslog.h> #include "xcbutilss.h" namespace Xcb { @@ -29,6 +33,14 @@ int main(int argc, char *argv[]) { initUkuiLog4qt("sni-xembed-proxy"); + /*单例+vnc模式*/ + QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); + int fd = open(QString(homePath.at(0) + "/.config/sni-xembed-proxy.lock").toUtf8().data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) { exit(1); } + if (lockf(fd, F_TLOCK, 0)) { + syslog(LOG_ERR, "Can't lock single file, sni-xembed-proxy is already running!"); + exit(0); + } qputenv("QT_QPA_PLATFORM", "xcb"); diff -Nru ukui-panel-3.14.0.1/sni-xembed-proxy/sniproxy.cpp ukui-panel-4.0.0.0/sni-xembed-proxy/sniproxy.cpp --- ukui-panel-3.14.0.1/sni-xembed-proxy/sniproxy.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-xembed-proxy/sniproxy.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -50,12 +50,18 @@ //#include "statusnotifieritemadaptor.h" #include "statusnotifierwatcher_interface.h" +#include "xtestsender.h" //#define VISUAL_DEBUG #define SNI_WATCHER_SERVICE_NAME "org.kde.StatusNotifierWatcher" #define SNI_WATCHER_PATH "/StatusNotifierWatcher" +#define UKUI_PANEL_DAEMON "org.ukui.panel.daemon" +#define UKUI_PANEL_DAEMON_PATH "/convert/desktopwid" +#define UKUI_PANEL_DAEMON_INTERFACE "org.ukui.panel.daemon" +#define UKUI_PANEL_DAEMON_METHOD "WIDToDesktop" + static uint16_t s_embedSize = 32; //max size of window to embed. We no longer resize the embedded window as Chromium acts stupidly. static unsigned int XEMBED_VERSION = 0; @@ -122,7 +128,7 @@ XCB_COPY_FROM_PARENT, /* depth */ m_containerWid, /* window Id */ screen->root, /* parent window */ - 0, 0, /* x, y */ + 0-s_embedSize, 0-s_embedSize, /* x, y */ s_embedSize, s_embedSize, /* width, height */ 0, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT,/* class */ @@ -455,6 +461,21 @@ xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackData); } +QString SNIProxy::winidtoDesktopFileName(const WId& wid) const +{ + QDBusInterface iface(UKUI_PANEL_DAEMON, + UKUI_PANEL_DAEMON_PATH, + UKUI_PANEL_DAEMON_INTERFACE, + QDBusConnection::sessionBus()); + if(iface.isValid()) { + QDBusReply<QString> reply = iface.call(UKUI_PANEL_DAEMON_METHOD, int(wid)); + QString processExeName = reply.value(); + return processExeName; + } else { + return QString(); + } +} + //____________properties__________ QString SNIProxy::Category() const @@ -471,6 +492,7 @@ return QString::number(m_windowId); } return title; + } KDbusImageVector SNIProxy::IconPixmap() const @@ -494,19 +516,18 @@ KWindowInfo window (m_windowId, NET::WMName,NET::WM2WindowClass); //根据应用的dekstop文件查找中文名 QString toolTip; - ConvertDesktopToWinId *getDesktop = new ConvertDesktopToWinId(); - QString appDesktopPath = getDesktop->tranIdToDesktop(window.win()); - delete getDesktop; + QString appDesktopPath = winidtoDesktopFileName(window.win()); if(QFile::exists(appDesktopPath)){ - XdgDesktopFile xdg; - xdg.load(appDesktopPath); - toolTip = xdg.localizedValue("Name").toString(); - if(!toolTip.isEmpty()){ - return toolTip; - } + XdgDesktopFile xdg; + xdg.load(appDesktopPath); + toolTip = xdg.localizedValue("Name").toString(); + if(!toolTip.isEmpty()){ + return toolTip; + } } toolTip = QString(window.windowClassClass()); return toolTip; + } int SNIProxy::WindowId() const @@ -610,9 +631,11 @@ event->detail = mouseButton; xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_PRESS, (char *) event); + qInfo()<<"xEmbedToSNI::Forward button press events through the xcb_send_event"; delete event; } else { -// sendXTestPressed(QX11Info::display(), mouseButton); + sendXTestPressed(QX11Info::display(), mouseButton); + qInfo()<<"xEmbedToSNI::Forward button press events through the sendXTestPressed"; } //mouse up @@ -634,9 +657,11 @@ event->detail = mouseButton; xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *) event); + qInfo()<<"xEmbedToSNI::Forward button release events through the xcb_send_event"; delete event; } else { -// sendXTestReleased(QX11Info::display(), mouseButton); + sendXTestReleased(QX11Info::display(), mouseButton); + qInfo()<<"xEmbedToSNI::Forward button release events through the sendXTestReleased"; } #ifndef VISUAL_DEBUG diff -Nru ukui-panel-3.14.0.1/sni-xembed-proxy/sniproxy.h ukui-panel-4.0.0.0/sni-xembed-proxy/sniproxy.h --- ukui-panel-3.14.0.1/sni-xembed-proxy/sniproxy.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-xembed-proxy/sniproxy.h 2023-05-22 14:06:12.000000000 +0800 @@ -33,7 +33,6 @@ #include <xcb/xcb_image.h> #include "snidbus.h" -#include "../panel-daemon/convert-desktop-windowid/convertdesktoptowinid.h" class SNIProxy : public QObject { @@ -158,6 +157,7 @@ QImage convertFromNative(xcb_image_t *xcbImage) const; QPoint calculateClickPoint() const; void stackContainerWindow(const uint32_t stackMode) const; + QString winidtoDesktopFileName(const WId& wid) const; QDBusConnection m_dbus; xcb_window_t m_windowId; diff -Nru ukui-panel-3.14.0.1/sni-xembed-proxy/xtestsender.cpp ukui-panel-4.0.0.0/sni-xembed-proxy/xtestsender.cpp --- ukui-panel-3.14.0.1/sni-xembed-proxy/xtestsender.cpp 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-xembed-proxy/xtestsender.cpp 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,32 @@ +/* Wrap XLIB code in a new file as it defines keywords that conflict with Qt + * + * Copyright (C) 2017 <davidedmundson@kde.org> David Edmundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <X11/extensions/XTest.h> +#include "xtestsender.h" + +void sendXTestPressed(Display *display, int button) +{ + XTestFakeButtonEvent(display, button, true, 0); +} + +void sendXTestReleased(Display *display, int button) +{ + XTestFakeButtonEvent(display, button, false, 0); +} diff -Nru ukui-panel-3.14.0.1/sni-xembed-proxy/xtestsender.h ukui-panel-4.0.0.0/sni-xembed-proxy/xtestsender.h --- ukui-panel-3.14.0.1/sni-xembed-proxy/xtestsender.h 1970-01-01 08:00:00.000000000 +0800 +++ ukui-panel-4.0.0.0/sni-xembed-proxy/xtestsender.h 2023-05-22 14:06:12.000000000 +0800 @@ -0,0 +1,28 @@ +/* Wrap XLIB code in a new file as it defines keywords that conflict with Qt + * + * Copyright (C) 2017 <davidedmundson@kde.org> David Edmundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef XTEST_SENDER_H +#define XTEST_SENDER_H + +typedef _XDisplay Display; + +void sendXTestPressed(Display *display, int button); +void sendXTestReleased(Display *display, int button); + +#endif diff -Nru ukui-panel-3.14.0.1/ukui-calendar/CMakeLists.txt ukui-panel-4.0.0.0/ukui-calendar/CMakeLists.txt --- ukui-panel-3.14.0.1/ukui-calendar/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800 @@ -1,96 +0,0 @@ -cmake_minimum_required(VERSION 3.1.0) - -project(ukui-calendar) - -#判断编译器类型,如果是gcc编译器,则在编译选项中加入c++11支持 -if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") - message(STATUS "optional:-std=c++11") -endif(CMAKE_COMPILER_IS_GNUCXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(CMAKE_VERSION VERSION_LESS "3.7.0") - set(CMAKE_INCLUDE_CURRENT_DIR ON) -endif() - -find_package(Qt5DBus ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5LinguistTools ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5Widgets ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5X11Extras ${REQUIRED_QT_VERSION} REQUIRED) -find_package(Qt5Xml ${REQUIRED_QT_VERSION} REQUIRED) -find_package(KF5WindowSystem ${KF5_MINIMUM_VERSION} REQUIRED) -find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets DBus X11Extras LinguistTools) -find_package(Qt5Xdg ${QTXDG_MINIMUM_VERSION} REQUIRED) -find_package(X11 REQUIRED) -find_package(Qt5LinguistTools) - -pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0 udisks2) -pkg_check_modules(QGS REQUIRED gsettings-qt) - - -include_directories(${GLIB2_INCLUDE_DIRS}) -include_directories(${QGS_INCLUDE_DIRS}) -add_executable(ukui-calendar - lunarcalendarwidget/customstylePushbutton.cpp - lunarcalendarwidget/frmlunarcalendarwidget.cpp - lunarcalendarwidget/frmlunarcalendarwidget.ui - lunarcalendarwidget/lunarcalendarinfo.cpp - lunarcalendarwidget/lunarcalendaritem.cpp - lunarcalendarwidget/lunarcalendarmonthitem.cpp - lunarcalendarwidget/lunarcalendarwidget.cpp - lunarcalendarwidget/lunarcalendaryearitem.cpp - lunarcalendarwidget/main.cpp - lunarcalendarwidget/picturetowhite.cpp - lunarcalendarwidget/customstylePushbutton.h - lunarcalendarwidget/frmlunarcalendarwidget.h - lunarcalendarwidget/lunarcalendarinfo.h - lunarcalendarwidget/lunarcalendaritem.h - lunarcalendarwidget/lunarcalendarmonthitem.h - lunarcalendarwidget/lunarcalendarwidget.h - lunarcalendarwidget/lunarcalendaryearitem.h - lunarcalendarwidget/picturetowhite.h - calendardbus.h - calendardbus.cpp - xatom-helper.cpp - xatom-helper.h -) - - -add_definitions(-DQT_NO_KEYWORDS) -add_definitions(-DQT_MESSAGELOGCONTEXT) - -target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::DBus Qt5::X11Extras ${GLIB2_LIBRARIES} ${QGS_LIBRARIES} KF5::WindowSystem -lX11 -lukui-log4qt) - -install(TARGETS ukui-calendar DESTINATION bin) - -install(FILES - resources/ukui-calendar.desktop - DESTINATION "/etc/xdg/autostart/" - COMPONENT Runtime -) - -#install(FILES -# ukui-flash-disk.qrc -# DESTINATION "/usr/share/ukui/ukui-panel/" -# COMPONENT Runtime -#) - - -# To create a new ts file: lupdate -recursive . -target-language zh_CN -ts translation/ukui-calendar_zh_CN.ts -file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/translation/ukui-calendar_zh_CN.ts") - -# cmake -DUPDATE_TRANSLATIONS=yes -if (UPDATE_TRANSLATIONS) - qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) -else() - qt5_add_translation(QM_FILES ${TS_FILES}) -endif() -add_custom_target(translations ALL DEPENDS ${QM_FILES}) -#install(FILES ${QM_FILES} DESTINATION "/usr/share/ukui/ukui-panel/") -install(FILES ${QM_FILES} DESTINATION "/usr/share/ukui-panel/panel/resources/") - - diff -Nru ukui-panel-3.14.0.1/ukui-calendar/calendardbus.cpp ukui-panel-4.0.0.0/ukui-calendar/calendardbus.cpp --- ukui-panel-3.14.0.1/ukui-calendar/calendardbus.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/calendardbus.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "calendardbus.h" - -#define SERVICE "org.ukui.panel.calendar" -#define PATH "/calendarWidget" -#define INTERFACE "org.ukui.panel.calendar" - -CalendarDBus::CalendarDBus(QObject *parent) : QObject(parent) -{ - QDBusConnection con = QDBusConnection::sessionBus(); - con.registerService(SERVICE); - con.registerObject(PATH,INTERFACE,this,QDBusConnection::ExportAllSlots); -} - -void CalendarDBus::ShowCalendar(){ - qDebug()<<"CalendarDBus is call"; - Q_EMIT ShowCalendarWidget(); -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/calendardbus.h ukui-panel-4.0.0.0/ukui-calendar/calendardbus.h --- ukui-panel-3.14.0.1/ukui-calendar/calendardbus.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/calendardbus.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef CALENDARDBUS_H -#define CALENDARDBUS_H - -#include <QObject> -#include <QtDBus> -class CalendarDBus : public QObject -{ - Q_OBJECT -public: - explicit CalendarDBus(QObject *parent = nullptr); - -public Q_SLOTS: - void ShowCalendar(); - -Q_SIGNALS: - void ShowCalendarWidget(); - - -}; - -#endif // CALENDARDBUS_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/customstylePushbutton.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/customstylePushbutton.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/customstylePushbutton.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/customstylePushbutton.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,218 +0,0 @@ -/* -* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, see <http://www.gnu.org/licenses/>. -* -*/ -#include "customstylePushbutton.h" -#include <QWidget> - -#include <QStyleOption> -#include <QPainter> - -#include <QDebug> - -CustomStyle_pushbutton::CustomStyle_pushbutton(const QString &proxyStyleName, QObject *parent) : QProxyStyle (proxyStyleName) -{ - Q_UNUSED(parent); -} - -void CustomStyle_pushbutton::drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const -{ - return QProxyStyle::drawComplexControl(control, option, painter, widget); -} - -void CustomStyle_pushbutton::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const -{ - switch (element) { - case QStyle::CE_PushButton: { - QStyleOptionButton button = *qstyleoption_cast<const QStyleOptionButton *>(option); - button.palette.setColor(QPalette::HighlightedText, button.palette.buttonText().color()); - return QProxyStyle::drawControl(element, &button, painter, widget); - break; - } - default: - break; - } - return QProxyStyle::drawControl(element, option, painter, widget); -} - -void CustomStyle_pushbutton::drawItemPixmap(QPainter *painter, const QRect &rectangle, int alignment, const QPixmap &pixmap) const -{ - return QProxyStyle::drawItemPixmap(painter, rectangle, alignment, pixmap); -} - -void CustomStyle_pushbutton::drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette, bool enabled, const QString &text, QPalette::ColorRole textRole) const -{ - return QProxyStyle::drawItemText(painter, rectangle, alignment, palette, enabled, text, textRole); -} - -/// 我们重写button的绘制方法,通过state和当前动画的状态以及value值改变相关的绘制条件 -/// 这里通过判断hover与否,动态的调整painter的透明度然后绘制背景 -/// 需要注意的是,默认控件的绘制流程只会触发一次,而动画需要我们在一段时间内不停绘制才行, -/// 要使得动画能够持续,我们需要使用QWidget::update()在动画未完成时, -/// 手动更新一次,这样button将在一段时间后再次调用draw方法,从而达到更新动画的效果 -/// -/// 需要注意绘制背景的流程会因主题不同而产生差异,所以这一部分代码在一些主题中未必正常, -/// 如果你需要自己实现一个主题,这同样是你需要注意和考虑的点 -void CustomStyle_pushbutton::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const -{ -// if (element == PE_PanelButtonCommand) { -// qDebug()<<"draw pe button"; -// if (widget) { -// bool isPressed = false; -// bool isHover = false; -// if (!option->state.testFlag(State_Sunken)) { -// if (option->state.testFlag(State_MouseOver)) { -// isHover = true; -// } -// } else { -// isPressed = true; -// } - -// QStyleOption opt = *option; -// if (isHover) { -// QColor color(255,255,255,51); -// opt.palette.setColor(QPalette::Highlight, color); - -// } -// if (isPressed) { -// QColor color(255,255,255,21); -// opt.palette.setColor(QPalette::Highlight, color); -// } -// if (!isHover && !isPressed) { -// QColor color(255,255,255,31); -// opt.palette.setColor(QPalette::Button,color); -// } -// return QProxyStyle::drawPrimitive(element, &opt, painter, widget); -// } -// } -// return QProxyStyle::drawPrimitive(element, option, painter, widget); - if (element == PE_PanelButtonCommand) { - if (widget) { - if (option->state & State_MouseOver) { - if (option->state & State_Sunken) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - QColor color(255,255,255,21); - painter->setBrush(color); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - } else { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - QColor color(255,255,255,51); - painter->setBrush(color); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - } - } else { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - QColor color(255,255,255,0); - painter->setBrush(color); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - } - return; - } - } - return QProxyStyle::drawPrimitive(element, option, painter, widget); -} - -QPixmap CustomStyle_pushbutton::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const -{ - return QProxyStyle::generatedIconPixmap(iconMode, pixmap, option); -} - -QStyle::SubControl CustomStyle_pushbutton::hitTestComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, const QPoint &position, const QWidget *widget) const -{ - return QProxyStyle::hitTestComplexControl(control, option, position, widget); -} - -QRect CustomStyle_pushbutton::itemPixmapRect(const QRect &rectangle, int alignment, const QPixmap &pixmap) const -{ - return QProxyStyle::itemPixmapRect(rectangle, alignment, pixmap); -} - -QRect CustomStyle_pushbutton::itemTextRect(const QFontMetrics &metrics, const QRect &rectangle, int alignment, bool enabled, const QString &text) const -{ - return QProxyStyle::itemTextRect(metrics, rectangle, alignment, enabled, text); -} - -int CustomStyle_pushbutton::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const -{ - return QProxyStyle::pixelMetric(metric, option, widget); -} - -/// 我们需要将动画与widget一一对应起来, -/// 在一个style的生命周期里,widget只会进行polish和unpolish各一次, -/// 所以我们可以在polish时将widget与一个新的动画绑定,并且对应的在unpolish中解绑定 -void CustomStyle_pushbutton::polish(QWidget *widget) -{ - return QProxyStyle::polish(widget); -} - -void CustomStyle_pushbutton::polish(QApplication *application) -{ - return QProxyStyle::polish(application); -} - -void CustomStyle_pushbutton::polish(QPalette &palette) -{ - return QProxyStyle::polish(palette); -} - -void CustomStyle_pushbutton::unpolish(QWidget *widget) -{ - return QProxyStyle::unpolish(widget); -} - -void CustomStyle_pushbutton::unpolish(QApplication *application) -{ - return QProxyStyle::unpolish(application); -} - -QSize CustomStyle_pushbutton::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const -{ - return QProxyStyle::sizeFromContents(type, option, contentsSize, widget); -} - -QIcon CustomStyle_pushbutton::standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const -{ - return QProxyStyle::standardIcon(standardIcon, option, widget); -} - -QPalette CustomStyle_pushbutton::standardPalette() const -{ - return QProxyStyle::standardPalette(); -} - -int CustomStyle_pushbutton::styleHint(QStyle::StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const -{ - return QProxyStyle::styleHint(hint, option, widget, returnData); -} - -QRect CustomStyle_pushbutton::subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex *option, QStyle::SubControl subControl, const QWidget *widget) const -{ - return QProxyStyle::subControlRect(control, option, subControl, widget); -} - -QRect CustomStyle_pushbutton::subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget) const -{ - return QProxyStyle::subElementRect(element, option, widget); -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/customstylePushbutton.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/customstylePushbutton.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/customstylePushbutton.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/customstylePushbutton.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,67 +0,0 @@ -/* -* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, see <http://www.gnu.org/licenses/>. -* -*/ -#ifndef CUSTOMSTYLE_PUSHBUTTON_H -#define CUSTOMSTYLE_PUSHBUTTON_H -#include <QProxyStyle> - -class CustomStyle_pushbutton : public QProxyStyle -{ - Q_OBJECT -public: - explicit CustomStyle_pushbutton(const QString &proxyStyleName = "windows", QObject *parent = nullptr); - virtual void drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = nullptr) const; - virtual void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const; - virtual void drawItemPixmap(QPainter *painter, const QRect &rectangle, int alignment, const QPixmap &pixmap) const; - virtual void drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const; - /*! - * \brief drawPrimitive - * \param element 背景绘制,对应PE枚举类型 - * \param option - * \param painter - * \param widget - * \details - * drawPrimitive用于绘制控件背景,比如按钮和菜单的背景, - * 我们一般需要判断控件的状态来绘制不同的背景, - * 比如按钮的hover和点击效果。 - */ - virtual void drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const; - virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const; - virtual QStyle::SubControl hitTestComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, const QPoint &position, const QWidget *widget = nullptr) const; - virtual QRect itemPixmapRect(const QRect &rectangle, int alignment, const QPixmap &pixmap) const; - virtual QRect itemTextRect(const QFontMetrics &metrics, const QRect &rectangle, int alignment, bool enabled, const QString &text) const; - //virtual int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget); - virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const; - - virtual void polish(QWidget *widget); - virtual void polish(QApplication *application); - virtual void polish(QPalette &palette); - virtual void unpolish(QWidget *widget); - virtual void unpolish(QApplication *application); - - virtual QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget = nullptr) const; - virtual QIcon standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const; - virtual QPalette standardPalette() const; - virtual int styleHint(QStyle::StyleHint hint, const QStyleOption *option = nullptr, const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const; - - virtual QRect subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex *option, QStyle::SubControl subControl, const QWidget *widget = nullptr) const; - - virtual QRect subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget = nullptr) const; - -}; - -#endif // CUSTOMSTYLE_PUSHBUTTON_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "frmlunarcalendarwidget.h" -#include "ui_frmlunarcalendarwidget.h" -#include <QPainter> -#include <QDBusInterface> -#include <QDBusReply> -#include <KWindowSystem> - -#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" -#define TRANSPARENCY_KEY "transparency" -#define PANEL_CONTROL_IN_CALENDAR "org.ukui.control-center.panel.plugins" -#define LUNAR_KEY "calendar" -#define FIRST_DAY_KEY "firstday" - -frmLunarCalendarWidget::frmLunarCalendarWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::frmLunarCalendarWidget), - mCalendarDBus(new CalendarDBus(this)) -{ - installEventFilter(this); - ui->setupUi(this); - this->hide(); - connect(ui->lunarCalendarWidget,&LunarCalendarWidget::yijiChangeUp,this,&frmLunarCalendarWidget::changeUpSize); - connect(ui->lunarCalendarWidget,&LunarCalendarWidget::yijiChangeDown,this,&frmLunarCalendarWidget::changeDownSize); - connect(ui->lunarCalendarWidget,&LunarCalendarWidget::yijiChangeUp,this,&frmLunarCalendarWidget::set_window_position); - connect(ui->lunarCalendarWidget,&LunarCalendarWidget::yijiChangeDown,this,&frmLunarCalendarWidget::set_window_position); - connect(mCalendarDBus,&CalendarDBus::ShowCalendarWidget,this,[=](){ - KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager); - if (this->isHidden()){ - this->show(); - this->activateWindow(); - }else { - this->hide(); - } - }); - this->initForm(); -// this->setWindowFlags(Qt::X11BypassWindowManagerHint); -// this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); - KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager); -// setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 - setProperty("useSystemStyleBlur", true); - - this->setFixedSize(440, 600); - set_window_position(); - - const QByteArray transparency_id(TRANSPARENCY_SETTINGS); - if(QGSettings::isSchemaInstalled(transparency_id)){ - transparency_gsettings = new QGSettings(transparency_id); - } - const QByteArray calendar_id(PANEL_CONTROL_IN_CALENDAR); - if(QGSettings::isSchemaInstalled(calendar_id)){ - calendar_gsettings = new QGSettings(calendar_id); - //公历/农历切换 - connect(calendar_gsettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key == LUNAR_KEY){ - ckShowLunar_stateChanged(calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"); - } - if (key == FIRST_DAY_KEY) { - cboxWeekNameFormat_currentIndexChanged(calendar_gsettings->get(FIRST_DAY_KEY).toString() == "sunday"); - } - }); - } else { - ckShowLunar_stateChanged(false); - cboxWeekNameFormat_currentIndexChanged(false); - } -} - -frmLunarCalendarWidget::~frmLunarCalendarWidget() -{ - delete ui; -} - -void frmLunarCalendarWidget::changeUpSize() -{ - this->setFixedSize(440, 652); - Q_EMIT yijiChangeUp(); -} - -void frmLunarCalendarWidget::changeDownSize() -{ - this->setFixedSize(440, 600); - Q_EMIT yijiChangeDown(); -} - -void frmLunarCalendarWidget::initForm() -{ - //ui->cboxWeekNameFormat->setCurrentIndex(0); -} - -void frmLunarCalendarWidget::cboxCalendarStyle_currentIndexChanged(int index) -{ - ui->lunarCalendarWidget->setCalendarStyle((LunarCalendarWidget::CalendarStyle)index); -} - -void frmLunarCalendarWidget::cboxSelectType_currentIndexChanged(int index) -{ - ui->lunarCalendarWidget->setSelectType((LunarCalendarWidget::SelectType)index); -} - -void frmLunarCalendarWidget::cboxWeekNameFormat_currentIndexChanged(bool FirstDayisSun) -{ - ui->lunarCalendarWidget->setWeekNameFormat(FirstDayisSun); -} - -void frmLunarCalendarWidget::ckShowLunar_stateChanged(bool arg1) -{ - ui->lunarCalendarWidget->setShowLunar(arg1); -} - -void frmLunarCalendarWidget::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QRect rect = this->rect(); - QPainter p(this); - double tran =1; - const QByteArray transparency_id(TRANSPARENCY_SETTINGS); - if(QGSettings::isSchemaInstalled(transparency_id)){ - tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; - } - - QColor color = palette().color(QPalette::Base); - color.setAlpha(tran); - QBrush brush =QBrush(color); - p.setBrush(brush); - p.setPen(Qt::NoPen); - p.setRenderHint(QPainter::Antialiasing); - p.drawRoundedRect(rect,6,6); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} - -/* - * 事件过滤,检测鼠标点击外部活动区域则收回收纳栏 -*/ -bool frmLunarCalendarWidget::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::Leave) - { - qDebug()<<"event->type() == QEvent::ActivationChange"; - if(QApplication::activeWindow() != this) - { - qDebug()<<"this->hide()"; - this->hide(); - } - } - return QWidget::event(event); - if (obj == this) - { - qDebug()<<"obj == this"; - if (event->type() == QEvent::MouseButtonPress) - { - qDebug()<<"QEvent::MouseButtonPress"; - QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); - if (mouseEvent->button() == Qt::LeftButton) - { - qDebug()<<"激活内部窗口"; - this->hide(); - return true; - } - else if(mouseEvent->button() == Qt::RightButton) - { - return true; - } - } - else if(event->type() == QEvent::ContextMenu) - { - return false; - } - else if (event->type() == QEvent::WindowDeactivate) - { - qDebug()<<"激活外部窗口"; - this->hide(); - return true; - } else if (event->type() == QEvent::StyleChange) { - } - } - - if (!isActiveWindow()) - { - activateWindow(); - } - -// return false; -} - -void frmLunarCalendarWidget::set_window_position(){ - QDBusInterface iface("org.ukui.panel", - "/panel/position", - "org.ukui.panel", QDBusConnection::sessionBus()); - QDBusReply < QVariantList > reply =iface.call("GetPrimaryScreenGeometry"); -// qDebug() << reply.value().at(2).toInt(); -// qDebug() << reply.value().at(3).toInt(); -// qDebug() <<this->width(); -// qDebug() <<this->height(); - - switch (reply.value().at(4).toInt()) { - case 1: - this->setGeometry(reply.value().at(0).toInt() + - reply.value().at(2).toInt() - this->width() - - 4, reply.value().at(1).toInt() + 4, - this->width(), this->height()); - break; - case 2: - this->setGeometry(reply.value().at(0).toInt() + 4, - reply.value().at(3).toInt()- this->height() - 4, - this->width(), this->height()); - break; - case 3: - this->setGeometry(reply.value().at(2).toInt() - this->width() - 4, - reply.value().at(3).toInt()-this->height()- 4, - this->width(), this->height()); - break; - default: - this->setGeometry(reply.value().at(0).toInt() + - reply.value().at(2).toInt() - this->width() - - 4, - reply.value().at(1).toInt() + - reply.value().at(3).toInt() - this->height() - - 4, this->width(), this->height()); - - break; - } - -} - -void frmLunarCalendarWidget::mousePressEvent(QMouseEvent *event){ - if (Qt::LeftButton == event->button() ){ - qDebug()<<"leftbutton pressed!!!"; - if(QApplication::activeWindow() != this) - { - qDebug()<<"this->hide()"; - qDebug()<<this; - qDebug()<<QApplication::activeWindow(); - this->hide(); - } - - if(this->isHidden()){ - this->show(); - }else { - this->hide(); - } - } - - -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef FRMLUNARCALENDARWIDGET_H -#define FRMLUNARCALENDARWIDGET_H - -#include <QWidget> -#include <QGSettings> -#include "calendardbus.h" -namespace Ui { -class frmLunarCalendarWidget; -} - -class frmLunarCalendarWidget : public QWidget -{ - Q_OBJECT - -public: - explicit frmLunarCalendarWidget(QWidget *parent = 0); - ~frmLunarCalendarWidget(); - - void set_window_position(); - - bool status; - -protected: - void paintEvent(QPaintEvent *); - void mousePressEvent(QMouseEvent *event); - -private: - Ui::frmLunarCalendarWidget *ui; - QGSettings *transparency_gsettings; - QGSettings *calendar_gsettings; - CalendarDBus *mCalendarDBus; - bool eventFilter(QObject *, QEvent *); - -private Q_SLOTS: - void initForm(); - void cboxCalendarStyle_currentIndexChanged(int index); - void cboxSelectType_currentIndexChanged(int index); - void cboxWeekNameFormat_currentIndexChanged(bool FirstDayisSun); - void ckShowLunar_stateChanged(bool arg1); - void changeUpSize(); - void changeDownSize(); - -Q_SIGNALS: - void yijiChangeUp(); - void yijiChangeDown(); -}; - -#endif // FRMLUNARCALENDARWIDGET_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.ui ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.ui --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.ui 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/frmlunarcalendarwidget.ui 1970-01-01 08:00:00.000000000 +0800 @@ -1,176 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>frmLunarCalendarWidget</class> - <widget class="QWidget" name="frmLunarCalendarWidget"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>600</width> - <height>500</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="LunarCalendarWidget" name="lunarCalendarWidget" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item> - <widget class="QWidget" name="widgetBottom" native="true"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="labCalendarStyle"> - <property name="text"> - <string>整体样式</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="cboxCalendarStyle"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <item> - <property name="text"> - <string>红色风格</string> - </property> - </item> - </widget> - </item> - <item> - <widget class="QLabel" name="labSelectType"> - <property name="text"> - <string>选中样式</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="cboxSelectType"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <item> - <property name="text"> - <string>矩形背景</string> - </property> - </item> - <item> - <property name="text"> - <string>圆形背景</string> - </property> - </item> - <item> - <property name="text"> - <string>角标背景</string> - </property> - </item> - <item> - <property name="text"> - <string>图片背景</string> - </property> - </item> - </widget> - </item> - <item> - <widget class="QLabel" name="labWeekNameFormat"> - <property name="text"> - <string>星期格式</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="cboxWeekNameFormat"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <item> - <property name="text"> - <string>短名称</string> - </property> - </item> - <item> - <property name="text"> - <string>普通名称</string> - </property> - </item> - <item> - <property name="text"> - <string>长名称</string> - </property> - </item> - <item> - <property name="text"> - <string>英文名称</string> - </property> - </item> - </widget> - </item> - <item> - <widget class="QCheckBox" name="ckShowLunar"> - <property name="text"> - <string>显示农历</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>LunarCalendarWidget</class> - <extends>QWidget</extends> - <header>lunarcalendarwidget.h</header> - <container>1</container> - </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/image/bg_calendar.png and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/image/bg_calendar.png differ Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/image/fontawesome-webfont.ttf and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/image/fontawesome-webfont.ttf differ diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,828 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#pragma execution_character_set("utf-8") - -#include "lunarcalendarinfo.h" -#include "qmutex.h" -#include "qdebug.h" -#include <QTimer> -#include <QSettings> -#include <QToolButton> - -#define year_2099 - -QScopedPointer<LunarCalendarInfo> LunarCalendarInfo::self; -LunarCalendarInfo *LunarCalendarInfo::Instance() -{ - if (self.isNull()) { - static QMutex mutex; - QMutexLocker locker(&mutex); - if (self.isNull()) { - self.reset(new LunarCalendarInfo); - } - } - - return self.data(); -} - -LunarCalendarInfo::LunarCalendarInfo(QObject *parent) : QObject(parent) -{ - //农历查表 - lunarCalendarTable << 0x04AE53 << 0x0A5748 << 0x5526BD << 0x0D2650 << 0x0D9544 << 0x46AAB9 << 0x056A4D << 0x09AD42 << 0x24AEB6 << 0x04AE4A; //1901-1910 - lunarCalendarTable << 0x6A4DBE << 0x0A4D52 << 0x0D2546 << 0x5D52BA << 0x0B544E << 0x0D6A43 << 0x296D37 << 0x095B4B << 0x749BC1 << 0x049754; //1911-1920 - lunarCalendarTable << 0x0A4B48 << 0x5B25BC << 0x06A550 << 0x06D445 << 0x4ADAB8 << 0x02B64D << 0x095742 << 0x2497B7 << 0x04974A << 0x664B3E; //1921-1930 - lunarCalendarTable << 0x0D4A51 << 0x0EA546 << 0x56D4BA << 0x05AD4E << 0x02B644 << 0x393738 << 0x092E4B << 0x7C96BF << 0x0C9553 << 0x0D4A48; //1931-1940 - lunarCalendarTable << 0x6DA53B << 0x0B554F << 0x056A45 << 0x4AADB9 << 0x025D4D << 0x092D42 << 0x2C95B6 << 0x0A954A << 0x7B4ABD << 0x06CA51; //1941-1950 - lunarCalendarTable << 0x0B5546 << 0x555ABB << 0x04DA4E << 0x0A5B43 << 0x352BB8 << 0x052B4C << 0x8A953F << 0x0E9552 << 0x06AA48 << 0x6AD53C; //1951-1960 - lunarCalendarTable << 0x0AB54F << 0x04B645 << 0x4A5739 << 0x0A574D << 0x052642 << 0x3E9335 << 0x0D9549 << 0x75AABE << 0x056A51 << 0x096D46; //1961-1970 - lunarCalendarTable << 0x54AEBB << 0x04AD4F << 0x0A4D43 << 0x4D26B7 << 0x0D254B << 0x8D52BF << 0x0B5452 << 0x0B6A47 << 0x696D3C << 0x095B50; //1971-1980 - lunarCalendarTable << 0x049B45 << 0x4A4BB9 << 0x0A4B4D << 0xAB25C2 << 0x06A554 << 0x06D449 << 0x6ADA3D << 0x0AB651 << 0x093746 << 0x5497BB; //1981-1990 - lunarCalendarTable << 0x04974F << 0x064B44 << 0x36A537 << 0x0EA54A << 0x86B2BF << 0x05AC53 << 0x0AB647 << 0x5936BC << 0x092E50 << 0x0C9645; //1991-2000 - lunarCalendarTable << 0x4D4AB8 << 0x0D4A4C << 0x0DA541 << 0x25AAB6 << 0x056A49 << 0x7AADBD << 0x025D52 << 0x092D47 << 0x5C95BA << 0x0A954E; //2001-2010 - lunarCalendarTable << 0x0B4A43 << 0x4B5537 << 0x0AD54A << 0x955ABF << 0x04BA53 << 0x0A5B48 << 0x652BBC << 0x052B50 << 0x0A9345 << 0x474AB9; //2011-2020 - lunarCalendarTable << 0x06AA4C << 0x0AD541 << 0x24DAB6 << 0x04B64A << 0x69573D << 0x0A4E51 << 0x0D2646 << 0x5E933A << 0x0D534D << 0x05AA43; //2021-2030 - lunarCalendarTable << 0x36B537 << 0x096D4B << 0xB4AEBF << 0x04AD53 << 0x0A4D48 << 0x6D25BC << 0x0D254F << 0x0D5244 << 0x5DAA38 << 0x0B5A4C; //2031-2040 - lunarCalendarTable << 0x056D41 << 0x24ADB6 << 0x049B4A << 0x7A4BBE << 0x0A4B51 << 0x0AA546 << 0x5B52BA << 0x06D24E << 0x0ADA42 << 0x355B37; //2041-2050 - lunarCalendarTable << 0x09374B << 0x8497C1 << 0x049753 << 0x064B48 << 0x66A53C << 0x0EA54F << 0x06B244 << 0x4AB638 << 0x0AAE4C << 0x092E42; //2051-2060 - lunarCalendarTable << 0x3C9735 << 0x0C9649 << 0x7D4ABD << 0x0D4A51 << 0x0DA545 << 0x55AABA << 0x056A4E << 0x0A6D43 << 0x452EB7 << 0x052D4B; //2061-2070 - lunarCalendarTable << 0x8A95BF << 0x0A9553 << 0x0B4A47 << 0x6B553B << 0x0AD54F << 0x055A45 << 0x4A5D38 << 0x0A5B4C << 0x052B42 << 0x3A93B6; //2071-2080 - lunarCalendarTable << 0x069349 << 0x7729BD << 0x06AA51 << 0x0AD546 << 0x54DABA << 0x04B64E << 0x0A5743 << 0x452738 << 0x0D264A << 0x8E933E; //2081-2090 - lunarCalendarTable << 0x0D5252 << 0x0DAA47 << 0x66B53B << 0x056D4F << 0x04AE45 << 0x4A4EB9 << 0x0A4D4C << 0x0D1541 << 0x2D92B5; //2091-2099 - - //每年春节对应的公历日期 - springFestival << 130 << 217 << 206; // 1968 1969 1970 - springFestival << 127 << 215 << 203 << 123 << 211 << 131 << 218 << 207 << 128 << 216; // 1971--1980 - springFestival << 205 << 125 << 213 << 202 << 220 << 209 << 219 << 217 << 206 << 127; // 1981--1990 - springFestival << 215 << 204 << 123 << 210 << 131 << 219 << 207 << 128 << 216 << 205; // 1991--2000 - springFestival << 124 << 212 << 201 << 122 << 209 << 129 << 218 << 207 << 126 << 214; // 2001--2010 - springFestival << 203 << 123 << 210 << 131 << 219 << 208 << 128 << 216 << 205 << 125; // 2011--2020 - springFestival << 212 << 201 << 122 << 210 << 129 << 217 << 206 << 126 << 213 << 203; // 2021--2030 - springFestival << 123 << 211 << 131 << 219 << 208 << 128 << 215 << 204 << 124 << 212; // 2031--2040 - - //16--18位表示闰几月 0--12位表示农历每月的数据 高位表示1月 低位表示12月(农历闰月就会多一个月) - lunarData << 461653 << 1386 << 2413; // 1968 1969 1970 - lunarData << 330077 << 1197 << 2637 << 268877 << 3365 << 531109 << 2900 << 2922 << 398042 << 2395; // 1971--1980 - lunarData << 1179 << 267415 << 2635 << 661067 << 1701 << 1748 << 398772 << 2742 << 2391 << 330031; // 1981--1990 - lunarData << 1175 << 1611 << 200010 << 3749 << 527717 << 1452 << 2742 << 332397 << 2350 << 3222; // 1991--2000 - lunarData << 268949 << 3402 << 3493 << 133973 << 1386 << 464219 << 605 << 2349 << 334123 << 2709; // 2001--2010 - lunarData << 2890 << 267946 << 2773 << 592565 << 1210 << 2651 << 395863 << 1323 << 2707 << 265877; // 2011--2020 - lunarData << 1706 << 2773 << 133557 << 1206 << 398510 << 2638 << 3366 << 335142 << 3411 << 1450; // 2021--2030 - lunarData << 200042 << 2413 << 723293 << 1197 << 2637 << 399947 << 3365 << 3410 << 334676 << 2906; // 2031--2040 - - //二十四节气表 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1970 - chineseTwentyFourData << 0x96 << 0xB4 << 0x96 << 0xA6 << 0x97 << 0x97 << 0x78 << 0x79 << 0x79 << 0x69 << 0x78 << 0x77; // 1971 - chineseTwentyFourData << 0x96 << 0xA4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1972 - chineseTwentyFourData << 0xA5 << 0xB5 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 1973 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1974 - chineseTwentyFourData << 0x96 << 0xB4 << 0x96 << 0xA6 << 0x97 << 0x97 << 0x78 << 0x79 << 0x78 << 0x69 << 0x78 << 0x77; // 1975 - chineseTwentyFourData << 0x96 << 0xA4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x89 << 0x88 << 0x78 << 0x87 << 0x87; // 1976 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 1977 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x78 << 0x87; // 1978 - chineseTwentyFourData << 0x96 << 0xB4 << 0x96 << 0xA6 << 0x96 << 0x97 << 0x78 << 0x79 << 0x78 << 0x69 << 0x78 << 0x77; // 1979 - chineseTwentyFourData << 0x96 << 0xA4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1980 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x77 << 0x87; // 1981 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 1982 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x78 << 0x79 << 0x78 << 0x69 << 0x78 << 0x77; // 1983 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1984 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA6 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 1985 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 1986 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x79 << 0x78 << 0x69 << 0x78 << 0x87; // 1987 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 1988 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1989 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 1990 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x86 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1991 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 1992 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1993 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 1994 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x76 << 0x78 << 0x69 << 0x78 << 0x87; // 1995 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 1996 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1997 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 1998 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1999 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2000 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2001 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2002 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 2003 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2004 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2005 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2006 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 2007 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2008 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2009 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2010 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x78 << 0x87; // 2011 - chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2012 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2013 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2014 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2015 - chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2016 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2017 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA6 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2018 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2019 - chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2020 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2021 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2022 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2023 - chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2024 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2025 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2026 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2027 - chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2028 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2029 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2030 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2031 - chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2032 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2033 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x78 << 0x88 << 0x78 << 0x87 << 0x87; // 2034 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2035 - chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2036 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2037 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2038 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2039 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 2040 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2041 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2042 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2043 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x78 << 0x87; // 2044 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2045 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2046 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2047 - chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2048 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2049 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2050 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2051 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2052 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2053 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2054 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2055 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2056 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2057 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2058 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2059 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2060 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2061 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2062 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2063 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2064 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2065 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2066 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2067 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2068 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2069 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2070 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2071 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2072 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x88 << 0x87 << 0x96; // 2073 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2074 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2075 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2076 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x88 << 0x87 << 0x96; // 2077 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2078 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2079 - chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2080 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x88 << 0x86 << 0x96; // 2081 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2082 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2083 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA6 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2084 - chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x88 << 0x86 << 0x96; // 2085 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2086 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2087 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2088 - chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x88 << 0x96 << 0x96; // 2089 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2090 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2091 - chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2092 - chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x87 << 0x96 << 0x96; // 2093 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2094 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2095 - chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2096 - chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x97 << 0x87 << 0x87 << 0x96 << 0x96; // 2097 - chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2098 - chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2099 - - //公历每月前面的天数 - monthAdd << 0 << 31 << 59 << 90 << 120 << 151 << 181 << 212 << 243 << 273 << 304 << 334; - - //农历日期名称 - listDayName << "*" << "初一" << "初二" << "初三" << "初四" << "初五" << "初六" << "初七" << "初八" << "初九" << "初十" - << "十一" << "十二" << "十三" << "十四" << "十五" << "十六" << "十七" << "十八" << "十九" << "二十" - << "廿一" << "廿二" << "廿三" << "廿四" << "廿五" << "廿六" << "廿七" << "廿八" << "廿九" << "三十"; - - //农历月份名称 - listMonthName << "*" << "正月" << "二月" << "三月" << "四月" << "五月" << "六月" << "七月" << "八月" << "九月" << "十月" << "冬月" << "腊月"; - - //二十四节气名称 - listSolarTerm << "小寒" << "大寒" << "立春" << "雨水" << "惊蛰" << "春分" << "清明" << "谷雨" - << "立夏" << "小满" << "芒种" << "夏至" << "小暑" << "大暑" << "立秋" << "处暑" - << "白露" << "秋分" << "寒露" << "霜降" << "立冬" << "小雪" << "大雪" << "冬至"; - - //天干 - listTianGan << "甲" << "乙" << "丙" << "丁" << "戊" << "己" << "庚" << "辛" << "壬" << "癸"; - - //地支 - listDiZhi << "子" << "丑" << "寅" << "卯" << "辰" << "巳" << "午" << "未" << "申" << "酉" << "戌" << "亥"; - - //属相 - listShuXiang << "鼠" << "牛" << "虎" << "兔" << "龙" << "蛇" << "马" << "羊" << "猴" << "鸡" << "狗" << "猪"; -} - -//计算是否闰年 -bool LunarCalendarInfo::isLoopYear(int year) -{ - return (((0 == (year % 4)) && (0 != (year % 100))) || (0 == (year % 400))); -} - -//计算指定年月该月共多少天 -int LunarCalendarInfo::getMonthDays(int year, int month) -{ - int countDay = 0; - int loopDay = isLoopYear(year) ? 1 : 0; - - switch (month) { - case 1: - countDay = 31; - break; - case 2: - countDay = 28 + loopDay; - break; - case 3: - countDay = 31; - break; - case 4: - countDay = 30; - break; - case 5: - countDay = 31; - break; - case 6: - countDay = 30; - break; - case 7: - countDay = 31; - break; - case 8: - countDay = 31; - break; - case 9: - countDay = 30; - break; - case 10: - countDay = 31; - break; - case 11: - countDay = 30; - break; - case 12: - countDay = 31; - break; - default: - countDay = 30; - break; - } - - return countDay; -} - -//计算指定年月对应到该月共多少天 -int LunarCalendarInfo::getTotalMonthDays(int year, int month) -{ - int countDay = 0; - int loopDay = isLoopYear(year) ? 1 : 0; - - switch (month) { - case 1: - countDay = 0; - break; - case 2: - countDay = 31; - break; - case 3: - countDay = 59 + loopDay; - break; - case 4: - countDay = 90 + loopDay; - break; - case 5: - countDay = 120 + loopDay; - break; - case 6: - countDay = 151 + loopDay; - break; - case 7: - countDay = 181 + loopDay; - break; - case 8: - countDay = 212 + loopDay; - break; - case 9: - countDay = 243 + loopDay; - break; - case 10: - countDay = 273 + loopDay; - break; - case 11: - countDay = 304 + loopDay; - break; - case 12: - countDay = 334 + loopDay; - break; - default: - countDay = 0; - break; - } - - return countDay; -} - -//计算指定年月对应星期几 -int LunarCalendarInfo::getFirstDayOfWeek(int year, int month, bool FirstDayisSun) -{ - int week = 0; - week = (year + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7; - week += getTotalMonthDays(year, month); - week = week % 7 - (!FirstDayisSun); - if (week == -1) - week = 6; - return week; -} - -//计算国际节日 -QString LunarCalendarInfo::getHoliday(int month, int day) -{ - int temp = (month << 8) | day; - QString strHoliday; - - switch (temp) { - case 0x0101: - strHoliday = "元旦"; - break; - case 0x020E: - strHoliday = "情人节"; - break; - case 0x0305: - strHoliday = "志愿者"; - break; - case 0x0308: - strHoliday = "妇女节"; - break; - case 0x030C: - strHoliday = "植树节"; - break; - case 0x0401: - strHoliday = "愚人节"; - break; - case 0x0501: - strHoliday = "劳动节"; - break; - case 0x0504: - strHoliday = "青年节"; - break; - case 0x0601: - strHoliday = "儿童节"; - break; - case 0x0606: - strHoliday = "爱眼日"; - break; - case 0x0701: - strHoliday = "建党节"; - break; - case 0x0707: - strHoliday = "抗战日"; - break; - case 0x0801: - strHoliday = "建军节"; - break; - case 0x090A: - strHoliday = "教师节"; - break; - case 0x0A01: - strHoliday = "国庆节"; - break; - case 0x0B08: - strHoliday = "记者节"; - break; - case 0x0B09: - strHoliday = "消防日"; - break; - case 0x0C18: - strHoliday = "平安夜"; - break; - case 0x0C19: - strHoliday = "圣诞节"; - break; - default: - break; - } - - return strHoliday; -} - -//计算二十四节气 -QString LunarCalendarInfo::getSolarTerms(int year, int month, int day) -{ - QString strSolarTerms; - int dayTemp = 0; - int index = (year - 1970) * 12 + month - 1; - - if (day < 15) { - dayTemp = 15 - day; - - if ((chineseTwentyFourData.at(index) >> 4) == dayTemp) { - strSolarTerms = listSolarTerm.at(2 * (month - 1)); - } - } else if (day > 15) { - dayTemp = day - 15; - - if ((chineseTwentyFourData.at(index) & 0x0f) == dayTemp) { - strSolarTerms = listSolarTerm.at(2 * (month - 1) + 1); - } - } - - return strSolarTerms; -} - -//计算农历节日(必须传入农历年份月份) -QString LunarCalendarInfo::getLunarFestival(int month, int day) -{ - int temp = (month << 8) | day; - QString strFestival; - - switch (temp) { - case 0x0201: - strFestival = "二月"; - break; - case 0x0301: - strFestival = "三月"; - break; - case 0x0401: - strFestival = "四月"; - break; - case 0x0501: - strFestival = "五月"; - break; - case 0x0601: - strFestival = "六月"; - break; - case 0x0701: - strFestival = "七月"; - break; - case 0x0801: - strFestival = "八月"; - break; - case 0x0901: - strFestival = "九月"; - break; - case 0x0A01: - strFestival = "十月"; - break; - case 0x0B01: - strFestival = "冬月"; - break; - case 0x0C01: - strFestival = "腊月"; - break; - case 0x0101: - strFestival = "春节"; - break; - case 0x010F: - strFestival = "元宵节"; - break; - case 0x0202: - strFestival = "龙抬头"; - break; - case 0x0505: - strFestival = "端午节"; - break; - case 0x0707: - strFestival = "七夕节"; - break; - case 0x080F: - strFestival = "中秋节"; - break; - case 0x0909: - strFestival = "重阳节"; - break; - case 0x0C08: - strFestival = "腊八节"; - break; - case 0x0C1E: - strFestival = "除夕"; - break; - default: - break; - } - - return strFestival; -} - -//计算农历年 天干+地支+生肖 -QString LunarCalendarInfo::getLunarYear(int year) -{ - QString strYear; - if (year > 1924) { - int temp = year - 1924; - strYear.append(listTianGan.at(temp % 10)); - strYear.append(listDiZhi.at(temp % 12)); - strYear.append("年"); - strYear.append(listShuXiang.at(temp % 12)); - strYear.append("年"); - } - - return strYear; -} - -void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day, - QString &strHoliday, - QString &strSolarTerms, - QString &strLunarFestival, - QString &strLunarYear, - QString &strLunarMonth, - QString &strLunarDay) -{ - //过滤不在范围内的年月日 - if (year < 1901 || year > 2099 || month < 1 || month > 12 || day < 1 || day > 31) { - return; - } - - strHoliday = getHoliday(month, day); - strSolarTerms = getSolarTerms(year, month, day); - -#ifndef year_2099 - //现在计算农历:获得当年春节的公历日期(比如:2015年春节日期为(2月19日)) - //以此为分界点,2.19前面的农历是2014年农历(用2014年农历数据来计算) - //2.19以及之后的日期,农历为2015年农历(用2015年农历数据来计算) - int temp, tempYear, tempMonth, isEnd, k, n; - tempMonth = year - 1968; - int springFestivalMonth = springFestival.at(tempMonth) / 100; - int springFestivalDaty = springFestival.at(tempMonth) % 100; - - if (month < springFestivalMonth) { - tempMonth--; - tempYear = 365 * 1 + day + monthAdd.at(month - 1) - 31 * ((springFestival.at(tempMonth) / 100) - 1) - springFestival.at(tempMonth) % 100 + 1; - - if ((!(year % 4)) && (month > 2)) { - tempYear = tempYear + 1; - } - - if ((!((year - 1) % 4))) { - tempYear = tempYear + 1; - } - } else if (month == springFestivalMonth) { - if (day < springFestivalDaty) { - tempMonth--; - tempYear = 365 * 1 + day + monthAdd.at(month - 1) - 31 * ((springFestival.at(tempMonth) / 100) - 1) - springFestival.at(tempMonth) % 100 + 1; - - if ((!(year % 4)) && (month > 2)) { - tempYear = tempYear + 1; - } - - if ((!((year - 1) % 4))) { - tempYear = tempYear + 1; - } - } else { - tempYear = day + monthAdd.at(month - 1) - 31 * ((springFestival.at(tempMonth) / 100) - 1) - springFestival.at(tempMonth) % 100 + 1; - - if ((!(year % 4)) && (month > 2)) { - tempYear = tempYear + 1; - } - } - } else { - tempYear = day + monthAdd.at(month - 1) - 31 * ((springFestival.at(tempMonth) / 100) - 1) - springFestival.at(tempMonth) % 100 + 1; - - if ((!(year % 4)) && (month > 2)) { - tempYear = tempYear + 1; - } - } - - //计算农历天干地支月日 - isEnd = 0; - while (isEnd != 1) { - if (lunarData.at(tempMonth) < 4095) { - k = 11; - } else { - k = 12; - } - - n = k; - - while (n >= 0) { - temp = lunarData.at(tempMonth); - temp = temp >> n; - temp = temp % 2; - - if (tempYear <= (29 + temp)) { - isEnd = 1; - break; - } - - tempYear = tempYear - 29 - temp; - n = n - 1; - } - - if (isEnd) { - break; - } - - tempMonth = tempMonth + 1; - } - - //农历的年月日 - year = 1969 + tempMonth - 1; - month = k - n + 1; - day = tempYear; - - if (k == 12) { - if (month == (lunarData.at(tempMonth) / 65536) + 1) { - month = 1 - month; - } else if (month > (lunarData.at(tempMonth) / 65536) + 1) { - month = month - 1; - } - } - - strLunarYear = getLunarYear(year); - - if (month < 1 && (1 == day)) { - month = month * -1; - strLunarMonth = "闰" + listMonthName.at(month); - } else { - strLunarMonth = listMonthName.at(month); - } - - strLunarDay = listDayName.at(day); - strLunarFestival = getLunarFestival(month, day); -#else - //记录春节离当年元旦的天数 - int springOffset = 0; - //记录阳历日离当年元旦的天数 - int newYearOffset = 0; - //记录大小月的天数 29或30 - int monthCount = 0; - - if(((lunarCalendarTable.at(year - 1901) & 0x0060) >> 5) == 1) { - springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1; - } else { - springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1 + 31; - } - - //如果是不闰年且不是2月份 +1 - newYearOffset = monthAdd.at(month - 1) + day - 1; - if((!(year % 4)) && (month > 2)) { - newYearOffset++; - } - - //记录从哪个月开始来计算 - int index = 0; - //用来对闰月的特殊处理 - int flag = 0; - - //判断阳历日在春节前还是春节后,计算农历的月/日 - if (newYearOffset >= springOffset) { - newYearOffset -= springOffset; - month = 1; - index = 1; - flag = 0; - - if((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { - monthCount = 29; - } else { - monthCount = 30; - } - - while (newYearOffset >= monthCount) { - newYearOffset -= monthCount; - index++; - if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20) ) { - flag = ~flag; - if (flag == 0) { - month++; - } - } else { - month++; - } - - if ((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { - monthCount = 29; - } else { - monthCount = 30; - } - } - - day = newYearOffset + 1; - } else { - springOffset -= newYearOffset; - year--; - month = 12; - flag = 0; - - if (((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20) == 0) { - index = 12; - } else { - index = 13; - } - - if ((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { - monthCount = 29; - } else { - monthCount = 30; - } - - while (springOffset > monthCount) { - springOffset -= monthCount; - index--; - - if(flag == 0) { - month--; - } - - if(month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) { - flag = ~flag; - } - - if ((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { - monthCount = 29; - } else { - monthCount = 30; - } - } - - day = monthCount - springOffset + 1; - } - - //计算农历的索引配置 - int temp = 0; - temp |= day; - temp |= (month << 6); - - //转换农历的年月 - month = (temp & 0x3C0) >> 6; - day = temp & 0x3F; - - strLunarYear = getLunarYear(year); - - if ((month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) && (1 == day)) { - strLunarMonth = "闰" + listMonthName.at(month); - } else { - strLunarMonth = listMonthName.at(month); - } - - strLunarDay = listDayName.at(day); - strLunarFestival = getLunarFestival(month, day); -#endif -} - -QString LunarCalendarInfo::getLunarInfo(int year, int month, int day, bool yearInfo, bool monthInfo, bool dayInfo) -{ - QString strHoliday, strSolarTerms, strLunarFestival, strLunarYear, strLunarMonth, strLunarDay; - - LunarCalendarInfo::Instance()->getLunarCalendarInfo(year, month, day, - strHoliday, strSolarTerms, strLunarFestival, - strLunarYear, strLunarMonth, strLunarDay); - - //农历节日优先,其次农历节气,然后公历节日,最后才是农历月份名称 - if (!strLunarFestival.isEmpty()) { - strLunarDay = strLunarFestival; - } else if (!strSolarTerms.isEmpty()) { - strLunarDay = strSolarTerms; - } else if (!strHoliday.isEmpty()) { - strLunarDay = strHoliday; - } - - QString info = QString("%1%2%3") - .arg(yearInfo ? strLunarYear + "年" : "") - .arg(monthInfo ? strLunarMonth : "") - .arg(dayInfo ? strLunarDay : ""); - - return info; -} - -QString LunarCalendarInfo::getLunarYearMonthDay(int year, int month, int day) -{ - return getLunarInfo(year, month, day, true, true, true); -} - -QString LunarCalendarInfo::getLunarMonthDay(int year, int month, int day) -{ - return getLunarInfo(year, month, day, false, true, true); -} - -QString LunarCalendarInfo::getLunarDay(int year, int month, int day) -{ - return getLunarInfo(year, month, day, false, false, true); -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarinfo.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef LUNARCALENDARINFO_H -#define LUNARCALENDARINFO_H - - -#include <QObject> - -#ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include <QtDesigner/QDesignerExportWidget> -#else -#include <QtUiPlugin/QDesignerExportWidget> -#endif - -class QDESIGNER_WIDGET_EXPORT LunarCalendarInfo : public QObject -#else -class LunarCalendarInfo : public QObject -#endif - -{ - Q_OBJECT -public: - static LunarCalendarInfo *Instance(); - explicit LunarCalendarInfo(QObject *parent = 0); - - //计算是否闰年 - bool isLoopYear(int year); - - //计算指定年月该月共多少天 - int getMonthDays(int year, int month); - - //计算指定年月对应到该月共多少天 - int getTotalMonthDays(int year, int month); - - //计算指定年月对应星期几 - int getFirstDayOfWeek(int year, int month, bool FirstDayisSun); - - //计算国际节日 - QString getHoliday(int month, int day); - - //计算二十四节气 - QString getSolarTerms(int year, int month, int day); - - //计算农历节日(必须传入农历年份月份) - QString getLunarFestival(int month, int day); - - //计算农历年 天干+地支+生肖 - QString getLunarYear(int year); - - //计算指定年月日农历信息,包括公历节日和农历节日及二十四节气 - void getLunarCalendarInfo(int year, int month, int day, - QString &strHoliday, - QString &strSolarTerms, - QString &strLunarFestival, - QString &strLunarYear, - QString &strLunarMonth, - QString &strLunarDay); - - //获取指定年月日农历信息 - QString getLunarInfo(int year, int month, int day, bool yearInfo, bool monthInfo, bool dayInfo); - QString getLunarYearMonthDay(int year, int month, int day); - QString getLunarMonthDay(int year, int month, int day); - QString getLunarDay(int year, int month, int day); - -private: - static QScopedPointer<LunarCalendarInfo> self; - - QList<int> lunarCalendarTable; //农历年表 - QList<int> springFestival; //春节公历日期 - QList<int> lunarData; //农历每月数据 - QList<int> chineseTwentyFourData; //农历二十四节气数据 - QList<int> monthAdd; //公历每月前面的天数 - - QList<QString> listDayName; //农历日期名称集合 - QList<QString> listMonthName; //农历月份名称集合 - QList<QString> listSolarTerm; //二十四节气名称集合 - - QList<QString> listTianGan; //天干名称集合 - QList<QString> listDiZhi; //地支名称集合 - QList<QString> listShuXiang; //属相名称集合 -}; - -#endif // LUNARCALENDARINFO_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,691 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#pragma execution_character_set("utf-8") - -#include "lunarcalendaritem.h" -#include "lunarcalendarwidget.h" -#include "qpainter.h" -#include "qevent.h" -#include "qdatetime.h" -#include "qdebug.h" -#include <QGSettings> - -LunarCalendarItem::LunarCalendarItem(QWidget *parent) : QWidget(parent) -{ - hover = false; - pressed = false; - - select = false; - showLunar = true; - bgImage = ":/image/bg_calendar.png"; - selectType = SelectType_Rect; - - date = QDate::currentDate(); - lunar = "初一"; - dayType = DayType_MonthCurrent; - - //实时监听主题变化 - const QByteArray id("org.ukui.style"); - QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); - connect(fontSetting, &QGSettings::changed,[=](QString key) { - if(fontSetting->get("style-name").toString() == "ukui-default") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } else if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else if(fontSetting->get("style-name").toString() == "ukui-dark") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - }); - - if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - - borderColor = QColor(180, 180, 180); - superColor = QColor(255, 129, 6); - - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(250, 250, 250); - - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(255, 255, 255); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(55,143,250); - hoverBgColor = QColor(204, 183, 180); -} - -void LunarCalendarItem::enterEvent(QEvent *) -{ - hover = true; - this->update(); -} - -void LunarCalendarItem::leaveEvent(QEvent *) -{ - hover = false; - this->update(); -} - -void LunarCalendarItem::mousePressEvent(QMouseEvent *) -{ - pressed = true; - this->update(); - Q_EMIT clicked(date, dayType); -} - -void LunarCalendarItem::mouseReleaseEvent(QMouseEvent *) -{ - pressed = false; - this->update(); -} - -QString LunarCalendarItem::handleJsMap(QString year,QString month2day) -{ - QString oneNUmber = "worktime.y" + year; - QString twoNumber = "d" + month2day; - - QMap<QString,QMap<QString,QString>>::Iterator it = worktime.begin(); - - while(it!=worktime.end()) { - if(it.key() == oneNUmber) { - QMap<QString,QString>::Iterator it1 = it.value().begin(); - while(it1!=it.value().end()) { - if(it1.key() == twoNumber) { - return it1.value(); - } - it1++; - } - } - it++; - } - return "-1"; -} - - -void LunarCalendarItem::paintEvent(QPaintEvent *) -{ - - QDate dateNow = QDate::currentDate(); - - //绘制准备工作,启用反锯齿 - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - - //绘制背景和边框 - drawBg(&painter); - - //对比当前的时间,画选中状态 - if(dateNow == date) { - drawBgCurrent(&painter, selectBgColor); - } - - //绘制悬停状态 - if (hover) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制选中状态 - if (select) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制日期 - drawDay(&painter); - - //绘制农历信息 - drawLunar(&painter); -} - -void LunarCalendarItem::drawBg(QPainter *painter) -{ - painter->save(); - - //根据当前类型选择对应的颜色 - QColor bgColor = currentBgColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - bgColor = otherBgColor; - } - - //painter->setPen(borderColor); - //painter->setBrush(bgColor); - //painter->drawRect(rect()); - - painter->restore(); -} - -void LunarCalendarItem::drawBgCurrent(QPainter *painter, const QColor &color) -{ - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(color); - - QRect rect = this->rect(); - painter->drawRoundedRect(rect,4,4); -// //根据设定绘制背景样式 -// if (selectType == SelectType_Rect) { - -// } - painter->restore(); -} - -void LunarCalendarItem::drawBgHover(QPainter *painter, const QColor &color) -{ - painter->save(); - QRect rect = this->rect(); - painter->setPen(QPen(QColor(55,143,250),2)); - painter->drawRoundedRect(rect,4,4); -// //根据设定绘制背景样式 -// if (selectType == SelectType_Rect) { - -// } - painter->restore(); -} - -void LunarCalendarItem::drawDay(QPainter *painter) -{ - int width = this->width(); - int height = this->height(); - int side = qMin(width, height); - - painter->save(); - - //根据当前类型选择对应的颜色 - QColor color = currentTextColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - color = otherTextColor; - } else if (dayType == DayType_WeekEnd) { - color = weekColor; - } - -/* if (select) { - color = selectTextColor; - } *//*else if (hover) { - color = hoverTextColor; - }*/ - - painter->setPen(color); - - QFont font; - font.setPixelSize(side * 0.3); - //设置文字粗细 - font.setBold(true); - painter->setFont(font); - - //代码复用率待优化 - if (showLunar) { - QRect dayRect = QRect(0, 0, width, height / 1.7); - painter->drawText(dayRect, Qt::AlignHCenter | Qt::AlignBottom, QString::number(date.day())); - if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "2") { - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(244,78,80)); - QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); - painter->setFont(font); - painter->setPen(Qt::white); - painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"休"); - } else if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "1") { - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(251,170,42)); - QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); - painter->setFont(font); - painter->setPen(Qt::white); - painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"班"); - } - } - else { - QRect dayRect = QRect(0, 0, width, height); - painter->drawText(dayRect, Qt::AlignCenter, QString::number(date.day())); - if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "2") { - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(255,0,0)); - QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); - painter->setFont(font); - painter->setPen(Qt::white); - painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"休"); - } else if (handleJsMap(date.toString("yyyy"),date.toString("MMdd")) == "1") { - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(251,170,42)); - QRect dayRect1 = QRect(0, 0, width/3.5,height/3.5); - painter->drawRoundedRect(dayRect1,1,1); - font.setPixelSize(side / 5); - painter->setFont(font); - painter->setPen(Qt::white); - painter->drawText(dayRect1, Qt::AlignHCenter | Qt::AlignBottom,"班"); - } - } - - painter->restore(); -} - -void LunarCalendarItem::drawLunar(QPainter *painter) -{ - if (!showLunar) { - return; - } - - int width = this->width(); - int height = this->height(); - int side = qMin(width, height); - - painter->save(); - - QStringList listDayName; - listDayName << "*" << "初一" << "初二" << "初三" << "初四" << "初五" << "初六" << "初七" << "初八" << "初九" << "初十" - << "十一" << "十二" << "十三" << "十四" << "十五" << "十六" << "十七" << "十八" << "十九" << "二十" - << "廿一" << "廿二" << "廿三" << "廿四" << "廿五" << "廿六" << "廿七" << "廿八" << "廿九" << "三十"; - - //判断当前农历文字是否节日,是节日且是当月则用农历节日颜色显示 - bool exist = (!listDayName.contains(lunar) && dayType != DayType_MonthPre && dayType != DayType_MonthNext); - - //根据当前类型选择对应的颜色 - QColor color = currentLunarColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - color = otherLunarColor; - } - -// if (select) { -// color = selectTextColor; -// } /*else if (hover) { -// color = hoverTextColor; -// }*/ else if (exist) { -// color = lunarColor; -// } - - if (exist) { - color = lunarColor; - } - - painter->setPen(color); - - QFont font; - font.setPixelSize(side * 0.27); - painter->setFont(font); - - QRect lunarRect(0, height / 2, width, height / 2); - painter->drawText(lunarRect, Qt::AlignCenter, lunar); - painter->restore(); -} - -bool LunarCalendarItem::getSelect() const -{ - return this->select; -} - -bool LunarCalendarItem::getShowLunar() const -{ - return this->showLunar; -} - -QString LunarCalendarItem::getBgImage() const -{ - return this->bgImage; -} - -LunarCalendarItem::SelectType LunarCalendarItem::getSelectType() const -{ - return this->selectType; -} - -QDate LunarCalendarItem::getDate() const -{ - return this->date; -} - -QString LunarCalendarItem::getLunar() const -{ - return this->lunar; -} - -LunarCalendarItem::DayType LunarCalendarItem::getDayType() const -{ - return this->dayType; -} - -QColor LunarCalendarItem::getBorderColor() const -{ - return this->borderColor; -} - -QColor LunarCalendarItem::getWeekColor() const -{ - return this->weekColor; -} - -QColor LunarCalendarItem::getSuperColor() const -{ - return this->superColor; -} - -QColor LunarCalendarItem::getLunarColor() const -{ - return this->lunarColor; -} - -QColor LunarCalendarItem::getCurrentTextColor() const -{ - return this->currentTextColor; -} - -QColor LunarCalendarItem::getOtherTextColor() const -{ - return this->otherTextColor; -} - -QColor LunarCalendarItem::getSelectTextColor() const -{ - return this->selectTextColor; -} - -QColor LunarCalendarItem::getHoverTextColor() const -{ - return this->hoverTextColor; -} - -QColor LunarCalendarItem::getCurrentLunarColor() const -{ - return this->currentLunarColor; -} - -QColor LunarCalendarItem::getOtherLunarColor() const -{ - return this->otherLunarColor; -} - -QColor LunarCalendarItem::getSelectLunarColor() const -{ - return this->selectLunarColor; -} - -QColor LunarCalendarItem::getHoverLunarColor() const -{ - return this->hoverLunarColor; -} - -QColor LunarCalendarItem::getCurrentBgColor() const -{ - return this->currentBgColor; -} - -QColor LunarCalendarItem::getOtherBgColor() const -{ - return this->otherBgColor; -} - -QColor LunarCalendarItem::getSelectBgColor() const -{ - return this->selectBgColor; -} - -QColor LunarCalendarItem::getHoverBgColor() const -{ - return this->hoverBgColor; -} - -QSize LunarCalendarItem::sizeHint() const -{ - return QSize(100, 100); -} - -QSize LunarCalendarItem::minimumSizeHint() const -{ - return QSize(20, 20); -} - -void LunarCalendarItem::setSelect(bool select) -{ - if (this->select != select) { - this->select = select; - this->update(); - } -} - -void LunarCalendarItem::setShowLunar(bool showLunar) -{ - this->showLunar = showLunar; - this->update(); -} - -void LunarCalendarItem::setBgImage(const QString &bgImage) -{ - if (this->bgImage != bgImage) { - this->bgImage = bgImage; - this->update(); - } -} - -void LunarCalendarItem::setSelectType(const LunarCalendarItem::SelectType &selectType) -{ - if (this->selectType != selectType) { - this->selectType = selectType; - this->update(); - } -} - -void LunarCalendarItem::setDate(const QDate &date) -{ - if (this->date != date) { - this->date = date; - this->update(); - } -} - -void LunarCalendarItem::setLunar(const QString &lunar) -{ - if (this->lunar != lunar) { - this->lunar = lunar; - this->update(); - } -} - -void LunarCalendarItem::setDayType(const LunarCalendarItem::DayType &dayType) -{ - if (this->dayType != dayType) { - this->dayType = dayType; - this->update(); - } -} - -void LunarCalendarItem::setDate(const QDate &date, const QString &lunar, const DayType &dayType) -{ - this->date = date; - this->lunar = lunar; - this->dayType = dayType; - this->update(); -} - -void LunarCalendarItem::setBorderColor(const QColor &borderColor) -{ - if (this->borderColor != borderColor) { - this->borderColor = borderColor; - this->update(); - } -} - -void LunarCalendarItem::setWeekColor(const QColor &weekColor) -{ - if (this->weekColor != weekColor) { - this->weekColor = weekColor; - this->update(); - } -} - -void LunarCalendarItem::setSuperColor(const QColor &superColor) -{ - if (this->superColor != superColor) { - this->superColor = superColor; - this->update(); - } -} - -void LunarCalendarItem::setLunarColor(const QColor &lunarColor) -{ - if (this->lunarColor != lunarColor) { - this->lunarColor = lunarColor; - this->update(); - } -} - -void LunarCalendarItem::setCurrentTextColor(const QColor ¤tTextColor) -{ - if (this->currentTextColor != currentTextColor) { - this->currentTextColor = currentTextColor; - this->update(); - } -} - -void LunarCalendarItem::setOtherTextColor(const QColor &otherTextColor) -{ - if (this->otherTextColor != otherTextColor) { - this->otherTextColor = otherTextColor; - this->update(); - } -} - -void LunarCalendarItem::setSelectTextColor(const QColor &selectTextColor) -{ - if (this->selectTextColor != selectTextColor) { - this->selectTextColor = selectTextColor; - this->update(); - } -} - -void LunarCalendarItem::setHoverTextColor(const QColor &hoverTextColor) -{ - if (this->hoverTextColor != hoverTextColor) { - this->hoverTextColor = hoverTextColor; - this->update(); - } -} - -void LunarCalendarItem::setCurrentLunarColor(const QColor ¤tLunarColor) -{ - if (this->currentLunarColor != currentLunarColor) { - this->currentLunarColor = currentLunarColor; - this->update(); - } -} - -void LunarCalendarItem::setOtherLunarColor(const QColor &otherLunarColor) -{ - if (this->otherLunarColor != otherLunarColor) { - this->otherLunarColor = otherLunarColor; - this->update(); - } -} - -void LunarCalendarItem::setSelectLunarColor(const QColor &selectLunarColor) -{ - if (this->selectLunarColor != selectLunarColor) { - this->selectLunarColor = selectLunarColor; - this->update(); - } -} - -void LunarCalendarItem::setHoverLunarColor(const QColor &hoverLunarColor) -{ - if (this->hoverLunarColor != hoverLunarColor) { - this->hoverLunarColor = hoverLunarColor; - this->update(); - } -} - -void LunarCalendarItem::setCurrentBgColor(const QColor ¤tBgColor) -{ - if (this->currentBgColor != currentBgColor) { - this->currentBgColor = currentBgColor; - this->update(); - } -} - -void LunarCalendarItem::setOtherBgColor(const QColor &otherBgColor) -{ - if (this->otherBgColor != otherBgColor) { - this->otherBgColor = otherBgColor; - this->update(); - } -} - -void LunarCalendarItem::setSelectBgColor(const QColor &selectBgColor) -{ - if (this->selectBgColor != selectBgColor) { - this->selectBgColor = selectBgColor; - this->update(); - } -} - -void LunarCalendarItem::setHoverBgColor(const QColor &hoverBgColor) -{ - if (this->hoverBgColor != hoverBgColor) { - this->hoverBgColor = hoverBgColor; - this->update(); - } -} - -bool LunarCalendarItem::event(QEvent *event) -{ - if(event->type()==QEvent::ToolTip){ - if(date.month()==11 && date.day()==9 ){ - setToolTip(tr("消防宣传日")); - } - if(date.month()==3 && date.day()==5 ){ - setToolTip(tr("志愿者服务日")); - } - if(date.month()==6 && date.day()==6 ){ - setToolTip(tr("全国爱眼日")); - } - if(date.month()==7 && date.day()==7 ){ - setToolTip(tr("抗战纪念日")); - } - } - return QWidget::event(event); -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaritem.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,231 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef LUNARCALENDARITEM_H -#define LUNARCALENDARITEM_H - -#include <QWidget> -#include <QDate> -#include <QMap> - -#ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include <QtDesigner/QDesignerExportWidget> -#else -#include <QtUiPlugin/QDesignerExportWidget> -#endif - -class QDESIGNER_WIDGET_EXPORT LunarCalendarItem : public QWidget -#else -class LunarCalendarItem : public QWidget -#endif - -{ - Q_OBJECT - Q_ENUMS(DayType) - Q_ENUMS(SelectType) - - Q_PROPERTY(bool select READ getSelect WRITE setSelect) - Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar) - Q_PROPERTY(QString bgImage READ getBgImage WRITE setBgImage) - Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType) - - Q_PROPERTY(QDate date READ getDate WRITE setDate) - Q_PROPERTY(QString lunar READ getLunar WRITE setLunar) - Q_PROPERTY(DayType dayType READ getDayType WRITE setDayType) - - Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor) - Q_PROPERTY(QColor weekColor READ getWeekColor WRITE setWeekColor) - Q_PROPERTY(QColor superColor READ getSuperColor WRITE setSuperColor) - Q_PROPERTY(QColor lunarColor READ getLunarColor WRITE setLunarColor) - - Q_PROPERTY(QColor currentTextColor READ getCurrentTextColor WRITE setCurrentTextColor) - Q_PROPERTY(QColor otherTextColor READ getOtherTextColor WRITE setOtherTextColor) - Q_PROPERTY(QColor selectTextColor READ getSelectTextColor WRITE setSelectTextColor) - Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor) - - Q_PROPERTY(QColor currentLunarColor READ getCurrentLunarColor WRITE setCurrentLunarColor) - Q_PROPERTY(QColor otherLunarColor READ getOtherLunarColor WRITE setOtherLunarColor) - Q_PROPERTY(QColor selectLunarColor READ getSelectLunarColor WRITE setSelectLunarColor) - Q_PROPERTY(QColor hoverLunarColor READ getHoverLunarColor WRITE setHoverLunarColor) - - Q_PROPERTY(QColor currentBgColor READ getCurrentBgColor WRITE setCurrentBgColor) - Q_PROPERTY(QColor otherBgColor READ getOtherBgColor WRITE setOtherBgColor) - Q_PROPERTY(QColor selectBgColor READ getSelectBgColor WRITE setSelectBgColor) - Q_PROPERTY(QColor hoverBgColor READ getHoverBgColor WRITE setHoverBgColor) - -public: - enum DayType { - DayType_MonthPre = 0, //上月剩余天数 - DayType_MonthNext = 1, //下个月的天数 - DayType_MonthCurrent = 2, //当月天数 - DayType_WeekEnd = 3 //周末 - }; - - enum SelectType { - SelectType_Rect = 0, //矩形背景 - SelectType_Circle = 1, //圆形背景 - SelectType_Triangle = 2, //带三角标 - SelectType_Image = 3 //图片背景 - }; - - explicit LunarCalendarItem(QWidget *parent = 0); - QMap<QString,QMap<QString,QString>> worktime; - QString handleJsMap(QString year,QString month2day); //处理js解析出的数据 - -protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); - void paintEvent(QPaintEvent *); - void drawBg(QPainter *painter); - void drawBgCurrent(QPainter *painter, const QColor &color); - void drawBgHover(QPainter *painter, const QColor &color); - void drawDay(QPainter *painter); - void drawLunar(QPainter *painter); - -private: - bool hover; //鼠标是否悬停 - bool pressed; //鼠标是否按下 - - bool select; //是否选中 - bool showLunar; //显示农历 - QString bgImage; //背景图片 - SelectType selectType; //选中模式 - - QDate date; //当前日期 - QString lunar; //农历信息 - DayType dayType; //当前日类型 - - QColor borderColor; //边框颜色 - QColor weekColor; //周末颜色 - QColor superColor; //角标颜色 - QColor lunarColor; //农历节日颜色 - - QColor currentTextColor; //当前月文字颜色 - QColor otherTextColor; //其他月文字颜色 - QColor selectTextColor; //选中日期文字颜色 - QColor hoverTextColor; //悬停日期文字颜色 - - QColor currentLunarColor; //当前月农历文字颜色 - QColor otherLunarColor; //其他月农历文字颜色 - QColor selectLunarColor; //选中日期农历文字颜色 - QColor hoverLunarColor; //悬停日期农历文字颜色 - - QColor currentBgColor; //当前月背景颜色 - QColor otherBgColor; //其他月背景颜色 - QColor selectBgColor; //选中日期背景颜色 - QColor hoverBgColor; //悬停日期背景颜色 - - - -public: - bool getSelect() const; - bool getShowLunar() const; - QString getBgImage() const; - SelectType getSelectType() const; - - QDate getDate() const; - QString getLunar() const; - DayType getDayType() const; - - QColor getBorderColor() const; - QColor getWeekColor() const; - QColor getSuperColor() const; - QColor getLunarColor() const; - - QColor getCurrentTextColor() const; - QColor getOtherTextColor() const; - QColor getSelectTextColor() const; - QColor getHoverTextColor() const; - - QColor getCurrentLunarColor() const; - QColor getOtherLunarColor() const; - QColor getSelectLunarColor() const; - QColor getHoverLunarColor() const; - - QColor getCurrentBgColor() const; - QColor getOtherBgColor() const; - QColor getSelectBgColor() const; - QColor getHoverBgColor() const; - - QSize sizeHint() const; - QSize minimumSizeHint() const; - -public Q_SLOTS: - //设置是否选中 - void setSelect(bool select); - //设置是否显示农历信息 - void setShowLunar(bool showLunar); - //设置背景图片 - void setBgImage(const QString &bgImage); - //设置选中背景样式 - void setSelectType(const SelectType &selectType); - - //设置日期 - void setDate(const QDate &date); - //设置农历 - void setLunar(const QString &lunar); - //设置类型 - void setDayType(const DayType &dayType); - //设置日期/农历/类型 - void setDate(const QDate &date, const QString &lunar, const DayType &dayType); - - //设置边框颜色 - void setBorderColor(const QColor &borderColor); - //设置周末颜色 - void setWeekColor(const QColor &weekColor); - //设置角标颜色 - void setSuperColor(const QColor &superColor); - //设置农历节日颜色 - void setLunarColor(const QColor &lunarColor); - - //设置当前月文字颜色 - void setCurrentTextColor(const QColor ¤tTextColor); - //设置其他月文字颜色 - void setOtherTextColor(const QColor &otherTextColor); - //设置选中日期文字颜色 - void setSelectTextColor(const QColor &selectTextColor); - //设置悬停日期文字颜色 - void setHoverTextColor(const QColor &hoverTextColor); - - //设置当前月农历文字颜色 - void setCurrentLunarColor(const QColor ¤tLunarColor); - //设置其他月农历文字颜色 - void setOtherLunarColor(const QColor &otherLunarColor); - //设置选中日期农历文字颜色 - void setSelectLunarColor(const QColor &selectLunarColor); - //设置悬停日期农历文字颜色 - void setHoverLunarColor(const QColor &hoverLunarColor); - - //设置当前月背景颜色 - void setCurrentBgColor(const QColor ¤tBgColor); - //设置其他月背景颜色 - void setOtherBgColor(const QColor &otherBgColor); - //设置选中日期背景颜色 - void setSelectBgColor(const QColor &selectBgColor); - //设置悬停日期背景颜色 - void setHoverBgColor(const QColor &hoverBgColor); - //五个字以上节日名称显示tooltip - bool event(QEvent *event); - -Q_SIGNALS: - void clicked(const QDate &date, const LunarCalendarItem::DayType &dayType); -}; - -#endif // LUNARCALENDARITEM_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,495 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#pragma execution_character_set("utf-8") - -#include "lunarcalendarmonthitem.h" -#include "qpainter.h" -#include "qevent.h" -#include "qdatetime.h" -#include "qdebug.h" -#include <QGSettings> - -LunarCalendarMonthItem::LunarCalendarMonthItem(QWidget *parent) : QWidget(parent) -{ - hover = false; - pressed = false; - select = false; - - select = false; - showLunar = true; - bgImage = ":/image/bg_calendar.png"; - selectType = SelectType_Rect; - - date = QDate::currentDate(); - lunar = "初一"; - dayType = DayType_MonthCurrent; - - //实时监听主题变化 - const QByteArray id("org.ukui.style"); - QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); - connect(fontSetting, &QGSettings::changed,[=](QString key) { - if(fontSetting->get("style-name").toString() == "ukui-default") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } else if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else if(fontSetting->get("style-name").toString() == "ukui-dark") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - }); - - if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - - borderColor = QColor(180, 180, 180); - superColor = QColor(255, 129, 6); - - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(250, 250, 250); - - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(255, 255, 255); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(55,143,250); - hoverBgColor = QColor(204, 183, 180); -} - -void LunarCalendarMonthItem::enterEvent(QEvent *) -{ - hover = true; - this->update(); -} - -void LunarCalendarMonthItem::leaveEvent(QEvent *) -{ - hover = false; - this->update(); -} - -void LunarCalendarMonthItem::mousePressEvent(QMouseEvent *) -{ - pressed = true; - this->update(); -// Q_EMIT clicked(date, dayType); - Q_EMIT monthMessage(date, dayType); -} - -void LunarCalendarMonthItem::mouseReleaseEvent(QMouseEvent *) -{ - pressed = false; - this->update(); -} - - -void LunarCalendarMonthItem::paintEvent(QPaintEvent *) -{ - - QDate dateNow = QDate::currentDate(); - - //绘制准备工作,启用反锯齿 - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - - //绘制背景和边框 - drawBg(&painter); - - //对比当前的时间,画选中状态 - if(dateNow.month() == date.month() && dateNow.year() == date.year()) { - drawBgCurrent(&painter, selectBgColor); - } - - //绘制悬停状态 - if (hover) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制选中状态 - if (select) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制日期 - drawMonth(&painter); - -} - -void LunarCalendarMonthItem::drawBg(QPainter *painter) -{ - painter->save(); - - //根据当前类型选择对应的颜色 - QColor bgColor = currentBgColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - bgColor = otherBgColor; - } - painter->restore(); -} - -void LunarCalendarMonthItem::drawBgCurrent(QPainter *painter, const QColor &color) -{ - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(color); - - QRect rect = this->rect(); - painter->drawRoundedRect(rect,4,4); - - painter->restore(); -} - -void LunarCalendarMonthItem::drawBgHover(QPainter *painter, const QColor &color) -{ - painter->save(); - QRect rect = this->rect(); - painter->setPen(QPen(QColor(55,143,250),2)); - - painter->drawRoundedRect(rect,4,4); - - painter->restore(); -} - -void LunarCalendarMonthItem::drawMonth(QPainter *painter) -{ - int width = this->width(); - int height = this->height(); - int side = qMin(width, height); - - painter->save(); - - //根据当前类型选择对应的颜色 - QColor color = currentTextColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - color = otherTextColor; - } else if (dayType == DayType_WeekEnd) { - color = weekColor; - } - - painter->setPen(color); - - QFont font; - font.setPixelSize(side * 0.2); - //设置文字粗细 - font.setBold(true); - painter->setFont(font); - - QRect dayRect = QRect(0, 0, width, height / 1.7); - QString arg = QString::number(date.month()) +"月"; - painter->drawText(dayRect, Qt::AlignHCenter | Qt::AlignBottom, arg); - painter->restore(); -} - -bool LunarCalendarMonthItem::getSelect() const -{ - return this->select; -} - -bool LunarCalendarMonthItem::getShowLunar() const -{ - return this->showLunar; -} - -QString LunarCalendarMonthItem::getBgImage() const -{ - return this->bgImage; -} - -LunarCalendarMonthItem::SelectType LunarCalendarMonthItem::getSelectType() const -{ - return this->selectType; -} - -QDate LunarCalendarMonthItem::getDate() const -{ - return this->date; -} - -QString LunarCalendarMonthItem::getLunar() const -{ - return this->lunar; -} - -LunarCalendarMonthItem::DayType LunarCalendarMonthItem::getDayType() const -{ - return this->dayType; -} - -QColor LunarCalendarMonthItem::getBorderColor() const -{ - return this->borderColor; -} - -QColor LunarCalendarMonthItem::getWeekColor() const -{ - return this->weekColor; -} - -QColor LunarCalendarMonthItem::getSuperColor() const -{ - return this->superColor; -} - -QColor LunarCalendarMonthItem::getLunarColor() const -{ - return this->lunarColor; -} - -QColor LunarCalendarMonthItem::getCurrentTextColor() const -{ - return this->currentTextColor; -} - -QColor LunarCalendarMonthItem::getOtherTextColor() const -{ - return this->otherTextColor; -} - -QColor LunarCalendarMonthItem::getSelectTextColor() const -{ - return this->selectTextColor; -} - -QColor LunarCalendarMonthItem::getHoverTextColor() const -{ - return this->hoverTextColor; -} - -QColor LunarCalendarMonthItem::getCurrentLunarColor() const -{ - return this->currentLunarColor; -} - -QColor LunarCalendarMonthItem::getOtherLunarColor() const -{ - return this->otherLunarColor; -} - -QColor LunarCalendarMonthItem::getSelectLunarColor() const -{ - return this->selectLunarColor; -} - -QColor LunarCalendarMonthItem::getHoverLunarColor() const -{ - return this->hoverLunarColor; -} - -QColor LunarCalendarMonthItem::getCurrentBgColor() const -{ - return this->currentBgColor; -} - -QColor LunarCalendarMonthItem::getOtherBgColor() const -{ - return this->otherBgColor; -} - -QColor LunarCalendarMonthItem::getSelectBgColor() const -{ - return this->selectBgColor; -} - -QColor LunarCalendarMonthItem::getHoverBgColor() const -{ - return this->hoverBgColor; -} - -QSize LunarCalendarMonthItem::sizeHint() const -{ - return QSize(100, 100); -} - -QSize LunarCalendarMonthItem::minimumSizeHint() const -{ - return QSize(20, 20); -} - -void LunarCalendarMonthItem::setSelect(bool select) -{ - if (this->select != select) { - this->select = select; - this->update(); - } -} - -void LunarCalendarMonthItem::setShowLunar(bool showLunar) -{ - this->showLunar = showLunar; - this->update(); -} - -void LunarCalendarMonthItem::setBgImage(const QString &bgImage) -{ - if (this->bgImage != bgImage) { - this->bgImage = bgImage; - this->update(); - } -} - -void LunarCalendarMonthItem::setSelectType(const LunarCalendarMonthItem::SelectType &selectType) -{ - if (this->selectType != selectType) { - this->selectType = selectType; - this->update(); - } -} - -void LunarCalendarMonthItem::setDate(const QDate &date) -{ - if (this->date != date) { - this->date = date; - this->update(); - } -} - -void LunarCalendarMonthItem::setLunar(const QString &lunar) -{ - if (this->lunar != lunar) { - this->lunar = lunar; - this->update(); - } -} - -void LunarCalendarMonthItem::setDayType(const LunarCalendarMonthItem::DayType &dayType) -{ - if (this->dayType != dayType) { - this->dayType = dayType; - this->update(); - } -} - -void LunarCalendarMonthItem::setDate(const QDate &date, const QString &lunar, const DayType &dayType) -{ - this->date = date; - this->lunar = lunar; - this->dayType = dayType; - this->update(); -} - -void LunarCalendarMonthItem::setBorderColor(const QColor &borderColor) -{ - if (this->borderColor != borderColor) { - this->borderColor = borderColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setWeekColor(const QColor &weekColor) -{ - if (this->weekColor != weekColor) { - this->weekColor = weekColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setSuperColor(const QColor &superColor) -{ - if (this->superColor != superColor) { - this->superColor = superColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setLunarColor(const QColor &lunarColor) -{ - if (this->lunarColor != lunarColor) { - this->lunarColor = lunarColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setCurrentTextColor(const QColor ¤tTextColor) -{ - if (this->currentTextColor != currentTextColor) { - this->currentTextColor = currentTextColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setOtherTextColor(const QColor &otherTextColor) -{ - if (this->otherTextColor != otherTextColor) { - this->otherTextColor = otherTextColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setSelectTextColor(const QColor &selectTextColor) -{ - if (this->selectTextColor != selectTextColor) { - this->selectTextColor = selectTextColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setHoverTextColor(const QColor &hoverTextColor) -{ - if (this->hoverTextColor != hoverTextColor) { - this->hoverTextColor = hoverTextColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setCurrentLunarColor(const QColor ¤tLunarColor) -{ - if (this->currentLunarColor != currentLunarColor) { - this->currentLunarColor = currentLunarColor; - this->update(); - } -} - -void LunarCalendarMonthItem::setOtherLunarColor(const QColor &otherLunarColor) -{ - if (this->otherLunarColor != otherLunarColor) { - this->otherLunarColor = otherLunarColor; - this->update(); - } -} - - - - diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarmonthitem.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,192 +0,0 @@ -#ifndef LUNARCALENDARMONTHITEM_H -#define LUNARCALENDARMONTHITEM_H - -#include <QWidget> -#include <QDate> -#include <QMap> - -#ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include <QtDesigner/QDesignerExportWidget> -#else -#include <QtUiPlugin/QDesignerExportWidget> -#endif - -class QDESIGNER_WIDGET_EXPORT LunarCalendarItem : public QWidget -#else -class LunarCalendarMonthItem : public QWidget -#endif - -{ - Q_OBJECT - Q_ENUMS(DayType) - Q_ENUMS(SelectType) - - Q_PROPERTY(bool select READ getSelect WRITE setSelect) - Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar) - Q_PROPERTY(QString bgImage READ getBgImage WRITE setBgImage) - Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType) - - Q_PROPERTY(QDate date READ getDate WRITE setDate) - Q_PROPERTY(QString lunar READ getLunar WRITE setLunar) - Q_PROPERTY(DayType dayType READ getDayType WRITE setDayType) - - Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor) - Q_PROPERTY(QColor weekColor READ getWeekColor WRITE setWeekColor) - Q_PROPERTY(QColor superColor READ getSuperColor WRITE setSuperColor) - Q_PROPERTY(QColor lunarColor READ getLunarColor WRITE setLunarColor) - - Q_PROPERTY(QColor currentTextColor READ getCurrentTextColor WRITE setCurrentTextColor) - Q_PROPERTY(QColor otherTextColor READ getOtherTextColor WRITE setOtherTextColor) - Q_PROPERTY(QColor selectTextColor READ getSelectTextColor WRITE setSelectTextColor) - Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor) - - Q_PROPERTY(QColor currentLunarColor READ getCurrentLunarColor WRITE setCurrentLunarColor) - Q_PROPERTY(QColor otherLunarColor READ getOtherLunarColor WRITE setOtherLunarColor) - - -public: - enum DayType { - DayType_MonthPre = 0, //上月剩余天数 - DayType_MonthNext = 1, //下个月的天数 - DayType_MonthCurrent = 2, //当月天数 - DayType_WeekEnd = 3 //周末 - }; - - enum SelectType { - SelectType_Rect = 0, //矩形背景 - SelectType_Circle = 1, //圆形背景 - SelectType_Triangle = 2, //带三角标 - SelectType_Image = 3 //图片背景 - }; - - explicit LunarCalendarMonthItem(QWidget *parent = 0); - QMap<QString,QMap<QString,QString>> worktime; - -protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); - void paintEvent(QPaintEvent *); - void drawBg(QPainter *painter); - void drawBgCurrent(QPainter *painter, const QColor &color); - void drawBgHover(QPainter *painter, const QColor &color); - void drawMonth(QPainter *painter); - -private: - bool hover; //鼠标是否悬停 - bool pressed; //鼠标是否按下 - - bool select; //是否选中 - bool showLunar; //显示农历 - QString bgImage; //背景图片 - SelectType selectType; //选中模式 - - QDate date; //当前日期 - QString lunar; //农历信息 - DayType dayType; //当前日类型 - - QColor borderColor; //边框颜色 - QColor weekColor; //周末颜色 - QColor superColor; //角标颜色 - QColor lunarColor; //农历节日颜色 - - QColor currentTextColor; //当前月文字颜色 - QColor otherTextColor; //其他月文字颜色 - QColor selectTextColor; //选中日期文字颜色 - QColor hoverTextColor; //悬停日期文字颜色 - - QColor currentLunarColor; //当前月农历文字颜色 - QColor otherLunarColor; //其他月农历文字颜色 - QColor selectLunarColor; //选中日期农历文字颜色 - QColor hoverLunarColor; //悬停日期农历文字颜色 - - QColor currentBgColor; //当前月背景颜色 - QColor otherBgColor; //其他月背景颜色 - QColor selectBgColor; //选中日期背景颜色 - QColor hoverBgColor; //悬停日期背景颜色 - - - -public: - bool getSelect() const; - bool getShowLunar() const; - QString getBgImage() const; - SelectType getSelectType() const; - - QDate getDate() const; - QString getLunar() const; - DayType getDayType() const; - - QColor getBorderColor() const; - QColor getWeekColor() const; - QColor getSuperColor() const; - QColor getLunarColor() const; - - QColor getCurrentTextColor() const; - QColor getOtherTextColor() const; - QColor getSelectTextColor() const; - QColor getHoverTextColor() const; - - QColor getCurrentLunarColor() const; - QColor getOtherLunarColor() const; - QColor getSelectLunarColor() const; - QColor getHoverLunarColor() const; - - QColor getCurrentBgColor() const; - QColor getOtherBgColor() const; - QColor getSelectBgColor() const; - QColor getHoverBgColor() const; - - QSize sizeHint() const; - QSize minimumSizeHint() const; - -public Q_SLOTS: - //设置是否选中 - void setSelect(bool select); - //设置是否显示农历信息 - void setShowLunar(bool showLunar); - //设置背景图片 - void setBgImage(const QString &bgImage); - //设置选中背景样式 - void setSelectType(const SelectType &selectType); - - //设置日期 - void setDate(const QDate &date); - //设置农历 - void setLunar(const QString &lunar); - //设置类型 - void setDayType(const DayType &dayType); - //设置日期/农历/类型 - void setDate(const QDate &date, const QString &lunar, const DayType &dayType); - - //设置边框颜色 - void setBorderColor(const QColor &borderColor); - //设置周末颜色 - void setWeekColor(const QColor &weekColor); - //设置角标颜色 - void setSuperColor(const QColor &superColor); - //设置农历节日颜色 - void setLunarColor(const QColor &lunarColor); - - //设置当前月文字颜色 - void setCurrentTextColor(const QColor ¤tTextColor); - //设置其他月文字颜色 - void setOtherTextColor(const QColor &otherTextColor); - //设置选中日期文字颜色 - void setSelectTextColor(const QColor &selectTextColor); - //设置悬停日期文字颜色 - void setHoverTextColor(const QColor &hoverTextColor); - - //设置当前月农历文字颜色 - void setCurrentLunarColor(const QColor ¤tLunarColor); - //设置其他月农历文字颜色 - void setOtherLunarColor(const QColor &otherLunarColor); - -Q_SIGNALS: - void clicked(const QDate &date, const LunarCalendarMonthItem::DayType &dayType); - void monthMessage(const QDate &date, const LunarCalendarMonthItem::DayType &dayType); -}; - -#endif // LUNARCALENDARMONTHITEM_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,1543 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#pragma execution_character_set("utf-8") - -#include "lunarcalendarwidget.h" - -#include<QDebug> -#include <QJsonParseError> -#include <QJsonObject> - - -#define PANEL_CONTROL_IN_CALENDAR "org.ukui.control-center.panel.plugins" -#define LUNAR_KEY "calendar" -#define FIRST_DAY_KEY "firstday" - -#define ORG_UKUI_STYLE "org.ukui.style" -#define STYLE_NAME "styleName" -#define STYLE_NAME_KEY_DARK "ukui-dark" -#define STYLE_NAME_KEY_DEFAULT "ukui-default" -#define STYLE_NAME_KEY_BLACK "ukui-black" -#define STYLE_NAME_KEY_LIGHT "ukui-light" -#define STYLE_NAME_KEY_WHITE "ukui-white" -#define ICON_COLOR_LOGHT 255 -#define ICON_COLOR_DRAK 0 - -LunarCalendarWidget::LunarCalendarWidget(QWidget *parent) : QWidget(parent) -{ - analysisWorktimeJs(); - const QByteArray calendar_id(PANEL_CONTROL_IN_CALENDAR); - if(QGSettings::isSchemaInstalled(calendar_id)){ - calendar_gsettings = new QGSettings(calendar_id); - //农历切换监听与日期显示格式 - connect(calendar_gsettings, &QGSettings::changed, this, [=] (const QString &key){ - if(key == LUNAR_KEY){ - if(calendar_gsettings->get("calendar").toString() == "lunar") { - //农历 - lunarstate = true; - labWidget->setVisible(true); - yijiWidget->setVisible(true); - } else { - //公历 - lunarstate = false; - labWidget->setVisible(false); - yijiWidget->setVisible(false); - } - _timeUpdate(); - } - if(key == "date") { - if(calendar_gsettings->get("date").toString() == "cn"){ - dateShowMode = "yyyy/MM/dd dddd"; - } else { - dateShowMode = "yyyy-MM-dd dddd"; - } - } - }); - - if(calendar_gsettings->get("date").toString() == "cn"){ - dateShowMode = "yyyy/MM/dd dddd"; - } else { - dateShowMode = "yyyy-MM-dd dddd"; - } - - //监听12/24小时制 - connect(calendar_gsettings, &QGSettings::changed, this, [=] (const QString &keys){ - timemodel = calendar_gsettings->get("hoursystem").toString(); - _timeUpdate(); - }); - timemodel = calendar_gsettings->get("hoursystem").toString(); - - } else { - dateShowMode = "yyyy/MM/dd dddd"; - //无设置默认公历 - lunarstate = true; - } - setWindowOpacity(0.7); - setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 - setProperty("useSystemStyleBlur", true); //设置毛玻璃效果 - //判断图形字体是否存在,不存在则加入 - QFontDatabase fontDb; - if (!fontDb.families().contains("FontAwesome")) { - int fontId = fontDb.addApplicationFont(":/image/fontawesome-webfont.ttf"); - QStringList fontName = fontDb.applicationFontFamilies(fontId); - if (fontName.count() == 0) { - qDebug() << "load fontawesome-webfont.ttf error"; - } - } - - if (fontDb.families().contains("FontAwesome")) { - iconFont = QFont("FontAwesome"); -#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0)) - iconFont.setHintingPreference(QFont::PreferNoHinting); -#endif - } - - btnYear = new QPushButton; - btnMonth = new QPushButton; - btnToday = new QPushButton; - btnClick = false; - - calendarStyle = CalendarStyle_Red; - date = QDate::currentDate(); - - widgetTime = new QWidget; - timeShow = new QVBoxLayout(widgetTime); - - datelabel =new QLabel(this); - timelabel = new QLabel(this); - lunarlabel = new QLabel(this); - - widgetTime->setObjectName("widgetTime"); - timeShow->setContentsMargins(0, 0, 0, 0); - initWidget(); - - if(QGSettings::isSchemaInstalled(calendar_id)){ - //初始化农历/公历显示方式 - if(calendar_gsettings->get("calendar").toString() == "lunar") { - //农历 - lunarstate = true; - labWidget->setVisible(true); - yijiWidget->setVisible(true); - } else { - //公历 - lunarstate = false; - labWidget->setVisible(false); - yijiWidget->setVisible(false); - } - } - - - //切换主题 - const QByteArray style_id(ORG_UKUI_STYLE); - QStringList stylelist; - stylelist<<STYLE_NAME_KEY_DARK<<STYLE_NAME_KEY_BLACK; - if(QGSettings::isSchemaInstalled(style_id)){ - style_settings = new QGSettings(style_id); - dark_style=stylelist.contains(style_settings->get(STYLE_NAME).toString()); - setColor(dark_style); - } - connect(style_settings, &QGSettings::changed, this, [=] (const QString &key){ - if(key==STYLE_NAME){ - dark_style=stylelist.contains(style_settings->get(STYLE_NAME).toString()); - _timeUpdate(); - setColor(dark_style); - QPixmap pixmap1 = QIcon::fromTheme("strIconPath", QIcon::fromTheme("pan-up-symbolic")).pixmap(QSize(24, 24)); - PictureToWhite pictToWhite1; - btnPrevYear->setPixmap(pictToWhite1.drawSymbolicColoredPixmap(pixmap1)); - btnPrevYear->setProperty("useIconHighlightEffect", 0x2); - - QPixmap pixmap2 = QIcon::fromTheme("strIconPath", QIcon::fromTheme("pan-down-symbolic")).pixmap(QSize(24, 24)); - PictureToWhite pictToWhite2; - btnNextYear->setPixmap(pictToWhite2.drawSymbolicColoredPixmap(pixmap2)); - btnNextYear->setProperty("useIconHighlightEffect", 0x2); - } - }); - -// //实时监听系统字体的改变 -// const QByteArray id("org.ukui.style"); -// QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); -// connect(fontSetting, &QGSettings::changed,[=](QString key) { -// if ("systemFont" == key || "systemFontSize" ==key) { -// QFont font = this->font(); -// btnToday->setFont(font); -// cboxYearandMonth->setFont(font); -// for (int i = 0; i < 42; i++) { -// dayItems.value(i)->setFont(font); -// dayItems.value(i)->repaint(); -// } -// for (int i = 0; i < 7; i++) { -// labWeeks.value(i)->setFont(font); -// labWeeks.value(i)->repaint(); -// } -// } -// }); - - timer = new QTimer(); - connect(timer,SIGNAL(timeout()),this,SLOT(timerUpdate())); - timer->start(1000); - - if(QGSettings::isSchemaInstalled(calendar_id)){ - setWeekNameFormat(calendar_gsettings->get(FIRST_DAY_KEY).toString() == "sunday"); - setShowLunar(calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"); - } -} - -LunarCalendarWidget::~LunarCalendarWidget() -{ -} -bool LunarCalendarWidget::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::ActivationChange) - { - qDebug()<<"event->type() == QEvent::ActivationChange"; - if(QApplication::activeWindow() != this) - { - qDebug()<<"this->hide()"; - this->hide(); - } - } - return QWidget::event(event); -} -/* - * @brief 设置日历的背景及文字颜色 - * 参数: - * weekColor 周六及周日文字颜色 -*/ - -void LunarCalendarWidget::setColor(bool mdark_style) -{ - const QByteArray calendar_id(PANEL_CONTROL_IN_CALENDAR); - if(mdark_style){ - weekTextColor = QColor(0, 0, 0); - weekBgColor = QColor(180, 180, 180); - - if(QGSettings::isSchemaInstalled(calendar_id)){ - showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; - } - - bgImage = ":/image/bg_calendar.png"; - selectType = SelectType_Rect; - - borderColor = QColor(180, 180, 180); - weekColor = QColor(255, 255, 255); - superColor = QColor(255, 129, 6); - lunarColor = QColor(233, 90, 84); - - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(125, 125, 125); - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(0, 0, 0); - - currentLunarColor = QColor(150, 150, 150); - otherLunarColor = QColor(200, 200, 200); - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(0, 0, 0); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(80, 100, 220); - hoverBgColor = QColor(80, 190, 220); - }else{ - weekTextColor = QColor(255, 255, 255); - weekBgColor = QColor(0, 0, 0); - - if(QGSettings::isSchemaInstalled(calendar_id)){ - showLunar = calendar_gsettings->get(LUNAR_KEY).toString() == "lunar"; - } - - bgImage = ":/image/bg_calendar.png"; - selectType = SelectType_Rect; - - borderColor = QColor(180, 180, 180); - weekColor = QColor(0, 0, 0); - superColor = QColor(255, 129, 6); - lunarColor = QColor(233, 90, 84); - - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(125, 125, 125); - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(0, 0, 0); - - currentLunarColor = QColor(150, 150, 150); - otherLunarColor = QColor(200, 200, 200); - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(250, 250, 250); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(80, 100, 220); - hoverBgColor = QColor(80, 190, 220); - } - initStyle(); -} - -void LunarCalendarWidget::_timeUpdate() { - QDateTime time = QDateTime::currentDateTime(); - QLocale locale = (QLocale::system().name() == "zh_CN" ? (QLocale::Chinese) : (QLocale::English)); - QString _time; - if(timemodel == "12") { - _time = locale.toString(time,"Ahh:mm:ss"); - } else { - _time = locale.toString(time,"hh:mm:ss"); - } - - QFont font; - datelabel->setText(_time); - font.setPointSize(22); - datelabel->setFont(font); - datelabel->setAlignment(Qt::AlignHCenter); - - QString strHoliday; - QString strSolarTerms; - QString strLunarFestival; - QString strLunarYear; - QString strLunarMonth; - QString strLunarDay; - - LunarCalendarInfo::Instance()->getLunarCalendarInfo(locale.toString(time,"yyyy").toInt(), - locale.toString(time,"MM").toInt(), - locale.toString(time,"dd").toInt(), - strHoliday, - strSolarTerms, - strLunarFestival, - strLunarYear, - strLunarMonth, - strLunarDay); - - QString _date = locale.toString(time,dateShowMode); - if (lunarstate) { - _date = _date + " "+strLunarMonth + strLunarDay; - } - timelabel->setText(_date); - font.setPointSize(12); - timelabel->setFont(font); - timelabel->setAlignment(Qt::AlignHCenter); -} - -void LunarCalendarWidget::timerUpdate() -{ - _timeUpdate(); -} - -void LunarCalendarWidget::initWidget() -{ - setObjectName("lunarCalendarWidget"); - - //顶部widget - QWidget *widgetTop = new QWidget; - widgetTop->setObjectName("widgetTop"); - widgetTop->setMinimumHeight(35); - - //上个月的按钮 - btnPrevYear = new statelabel; - btnPrevYear->setObjectName("btnPrevYear"); - btnPrevYear->setFixedWidth(35); - btnPrevYear->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); - QPixmap pixmap1 = QIcon::fromTheme("strIconPath", QIcon::fromTheme("pan-up-symbolic")).pixmap(QSize(24, 24)); - PictureToWhite pictToWhite1; - btnPrevYear->setPixmap(pictToWhite1.drawSymbolicColoredPixmap(pixmap1)); - btnPrevYear->setProperty("useIconHighlightEffect", 0x2); - - - //下个月按钮 - btnNextYear = new statelabel; - btnNextYear->setObjectName("btnNextYear"); - btnNextYear->setFixedWidth(35); - btnNextYear->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); - QPixmap pixmap2 = QIcon::fromTheme("strIconPath", QIcon::fromTheme("pan-down-symbolic")).pixmap(QSize(24, 24)); - PictureToWhite pictToWhite2; - btnNextYear->setPixmap(pictToWhite2.drawSymbolicColoredPixmap(pixmap2)); - btnNextYear->setProperty("useIconHighlightEffect", 0x2); - - - //转到年显示 - btnYear->setObjectName("btnYear"); - btnYear->setFocusPolicy(Qt::NoFocus); - btnYear->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - QTimer::singleShot(0,this,[=]{ - btnYear->setText(tr("Year")); - }); - btnYear->setStyle(new CustomStyle_pushbutton("ukui-default")); - connect(btnYear,&QPushButton::clicked,this,&LunarCalendarWidget::yearWidgetChange); - - //转到月显示 - btnMonth->setObjectName("btnMonth"); - btnMonth->setFocusPolicy(Qt::NoFocus); - btnMonth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - QTimer::singleShot(0,this,[=]{ - btnMonth->setText(tr("Month")); - }); - btnMonth->setStyle(new CustomStyle_pushbutton("ukui-default")); - connect(btnMonth,&QPushButton::clicked,this,&LunarCalendarWidget::monthWidgetChange); - - //转到今天 - btnToday->setObjectName("btnToday"); - btnToday->setFocusPolicy(Qt::NoFocus); - //btnToday->setFixedWidth(40); - btnToday->setStyle(new CustomStyle_pushbutton("ukui-default")); - btnToday->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - QTimer::singleShot(0,this,[=]{ - btnToday->setText(tr("Today")); - }); - - //年份与月份下拉框 暂不用此 - cboxYearandMonth = new QComboBox; - cboxYearandMonth->setStyleSheet("QComboBox{background: transparent;font-size: 20px;}" - "QComboBox::down-down{width: 1px;}"); - cboxYearandMonth->setFixedWidth(100); - cboxYearandMonth->setObjectName("cboxYearandMonth"); - for (int i = 1901; i <= 2099; i++) { - for (int j = 1; j <= 12; j++) { - cboxYearandMonth->addItem(QString("%1.%2").arg(i).arg(j)); - } - } - - cboxYearandMonthLabel = new QLabel(); - cboxYearandMonthLabel->setFixedWidth(100); - - //中间用个空widget隔开 -// QWidget *widgetBlank1 = new QWidget; -// widgetBlank1->setFixedWidth(180); -// QWidget *widgetBlank2 = new QWidget; -// widgetBlank2->setFixedWidth(5); -// QWidget *widgetBlank3 = new QWidget; -// widgetBlank3->setFixedWidth(40); - - //顶部横向布局 - QHBoxLayout *layoutTop = new QHBoxLayout(widgetTop); - layoutTop->setContentsMargins(0, 0, 0, 9); - layoutTop->addItem(new QSpacerItem(5,1)); - - layoutTop->addWidget(cboxYearandMonthLabel); - layoutTop->addStretch(); - layoutTop->addWidget(btnNextYear); - layoutTop->addWidget(btnPrevYear); - - - layoutTop->addStretch(); - layoutTop->addWidget(btnYear); - layoutTop->addWidget(btnMonth); - layoutTop->addWidget(btnToday); - layoutTop->addStretch(); - layoutTop->addItem(new QSpacerItem(10,1)); - - //时间 - widgetTime->setMinimumHeight(50); - timeShow->addWidget(datelabel);//, Qt::AlignHCenter); - timeShow->addWidget(timelabel);//,Qt::AlignHCenter); - - - //星期widget - widgetWeek = new QWidget; - widgetWeek->setObjectName("widgetWeek"); - widgetWeek->setMinimumHeight(30); - - //星期布局 - QHBoxLayout *layoutWeek = new QHBoxLayout(widgetWeek); - layoutWeek->setMargin(0); - layoutWeek->setSpacing(0); - - for (int i = 0; i < 7; i++) { - QLabel *lab = new QLabel; - lab->setAlignment(Qt::AlignCenter); - layoutWeek->addWidget(lab); - labWeeks.append(lab); - } - - //日期标签widget - widgetDayBody = new QWidget; - widgetDayBody->setObjectName("widgetDayBody"); - - //日期标签布局 - QGridLayout *layoutBodyDay = new QGridLayout(widgetDayBody); - layoutBodyDay->setMargin(1); - layoutBodyDay->setHorizontalSpacing(0); - layoutBodyDay->setVerticalSpacing(0); - - //逐个添加日标签 - for (int i = 0; i < 42; i++) { - LunarCalendarItem *lab = new LunarCalendarItem; - lab->worktime = worktime; - connect(lab, SIGNAL(clicked(QDate, LunarCalendarItem::DayType)), this, SLOT(clicked(QDate, LunarCalendarItem::DayType))); - layoutBodyDay->addWidget(lab, i / 7, i % 7); - dayItems.append(lab); - } - - //年份标签widget - widgetYearBody = new QWidget; - widgetYearBody->setObjectName("widgetYearBody"); - - //年份标签布局 - QGridLayout *layoutBodyYear = new QGridLayout(widgetYearBody); - layoutBodyYear->setMargin(1); - layoutBodyYear->setHorizontalSpacing(0); - layoutBodyYear->setVerticalSpacing(0); - - //逐个添加年标签 - for (int i = 0; i < 12; i++) { - LunarCalendarYearItem *labYear = new LunarCalendarYearItem; - connect(labYear, SIGNAL(yearMessage(QDate, LunarCalendarYearItem::DayType)), this, SLOT(updateYearClicked(QDate, LunarCalendarYearItem::DayType))); - layoutBodyYear->addWidget(labYear, i / 3, i % 3); - yearItems.append(labYear); - } - widgetYearBody->hide(); - - //月份标签widget - widgetmonthBody = new QWidget; - widgetmonthBody->setObjectName("widgetmonthBody"); - - //月份标签布局 - QGridLayout *layoutBodyMonth = new QGridLayout(widgetmonthBody); - layoutBodyMonth->setMargin(1); - layoutBodyMonth->setHorizontalSpacing(0); - layoutBodyMonth->setVerticalSpacing(0); - - //逐个添加月标签 - for (int i = 0; i < 12; i++) { - LunarCalendarMonthItem *labMonth = new LunarCalendarMonthItem; - connect(labMonth, SIGNAL(monthMessage(QDate, LunarCalendarMonthItem::DayType)), this, SLOT(updateMonthClicked(QDate, LunarCalendarMonthItem::DayType))); - layoutBodyMonth->addWidget(labMonth, i / 3, i % 3); - monthItems.append(labMonth); - } - widgetmonthBody->hide(); - - labWidget = new QWidget(); - labBottom = new QLabel(); - yijichooseLabel = new QLabel(); - yijichooseLabel->setText("宜忌"); - - QFont font; - font.setPointSize(12); - labBottom->setFont(font); - yijichoose = new QCheckBox(); - - labLayout = new QHBoxLayout(); - labLayout->addWidget(labBottom); - labLayout->addItem(new QSpacerItem(100,5,QSizePolicy::Expanding,QSizePolicy::Minimum)); - labLayout->addWidget(yijichooseLabel); - labLayout->addWidget(yijichoose); - labWidget->setLayout(labLayout); - - yijiLayout = new QVBoxLayout; - yijiWidget = new QWidget; -// yijiWidget->setFixedHeight(60); - - yiLabel = new QLabel(); - jiLabel = new QLabel(); - - yijiLayout->addWidget(yiLabel); - yijiLayout->addWidget(jiLabel); - yijiWidget->setLayout(yijiLayout); - yiLabel->setVisible(false); - jiLabel->setVisible(false); - - connect(yijichoose,&QRadioButton::clicked,this,&LunarCalendarWidget::customButtonsClicked); - - //主布局 - lineUp = new m_PartLineWidget(); - lineDown = new m_PartLineWidget(); - - lineUp->setFixedSize(440, 1); - lineDown->setFixedSize(440, 1); - QVBoxLayout *verLayoutCalendar = new QVBoxLayout(this); - verLayoutCalendar->setMargin(0); - verLayoutCalendar->setSpacing(0); - verLayoutCalendar->addWidget(widgetTime); -// QTimer::singleShot(0,this,[=](){ - -// }); - verLayoutCalendar->addItem(new QSpacerItem(10,10)); - verLayoutCalendar->addWidget(lineUp); - verLayoutCalendar->addItem(new QSpacerItem(10,10)); - verLayoutCalendar->addWidget(widgetTop); - verLayoutCalendar->addWidget(widgetWeek); - verLayoutCalendar->addWidget(widgetDayBody, 1); - verLayoutCalendar->addWidget(widgetYearBody, 1); - verLayoutCalendar->addWidget(widgetmonthBody, 1); - verLayoutCalendar->addWidget(lineDown); - verLayoutCalendar->addWidget(labWidget); - verLayoutCalendar->addWidget(yijiWidget); - - - //绑定按钮和下拉框信号 -// connect(btnPrevYear, SIGNAL(clicked(bool)), this, SLOT(showPreviousYear())); -// connect(btnNextYear, SIGNAL(clicked(bool)), this, SLOT(showNextYear())); - connect(btnPrevYear, SIGNAL(labelclick()), this, SLOT(showPreviousMonth())); - connect(btnNextYear, SIGNAL(labelclick()), this, SLOT(showNextMonth())); - connect(btnToday, SIGNAL(clicked(bool)), this, SLOT(showToday())); - connect(cboxYearandMonth, SIGNAL(currentIndexChanged(QString)), this, SLOT(yearChanged(QString))); -// connect(cboxMonth, SIGNAL(currentIndexChanged(QString)), this, SLOT(monthChanged(QString))); -} - -void LunarCalendarWidget::initStyle() -{ - //设置样式 - QStringList qss; - - //自定义日控件颜色 - QString strSelectType; - if (selectType == SelectType_Rect) { - strSelectType = "SelectType_Rect"; - } else if (selectType == SelectType_Circle) { - strSelectType = "SelectType_Circle"; - } else if (selectType == SelectType_Triangle) { - strSelectType = "SelectType_Triangle"; - } else if (selectType == SelectType_Image) { - strSelectType = "SelectType_Image"; - } - - //计划去掉qss,保留农历切换的设置 - qss.append(QString("LunarCalendarItem{qproperty-showLunar:%1;}").arg(showLunar)); - - this->setStyleSheet(qss.join("")); -} - -void LunarCalendarWidget::analysisWorktimeJs() -{ - /*解析json文件*/ - QFile file("/usr/share/ukui-panel/plugin-calendar/html/jiejiari.js"); - file.open(QIODevice::ReadOnly | QIODevice::Text); - QString value = file.readAll(); - file.close(); - - QJsonParseError parseJsonErr; - QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(),&parseJsonErr); - if(!(parseJsonErr.error == QJsonParseError::NoError)) - { - qDebug()<<tr("解析json文件错误!"); - return; - } - QJsonObject jsonObject = document.object(); - QStringList args = jsonObject.keys(); - - for (int i=0;i<args.count();i++) { - if(jsonObject.contains(args.at(i))) - { - QJsonValue jsonValueList = jsonObject.value(args.at(i)); - QJsonObject item = jsonValueList.toObject(); - QStringList arg2 = item.keys(); - for (int j=0;j<arg2.count();j++) { - worktimeinside.insert(arg2.at(j),item[arg2.at(j)].toString()); - } - } - worktime.insert(args.at(i),worktimeinside); - worktimeinside.clear(); - } -} - -void LunarCalendarWidget::yearWidgetChange() -{ - if (widgetYearBody->isHidden()){ - widgetYearBody->show(); - widgetWeek->hide(); - widgetDayBody->hide(); - widgetmonthBody->hide(); - } - else{ - widgetYearBody->hide(); - widgetWeek->show(); - widgetDayBody->show(); - widgetmonthBody->hide(); - } - -} - -void LunarCalendarWidget::monthWidgetChange() -{ - if(widgetmonthBody->isHidden()){ - widgetYearBody->hide(); - widgetWeek->hide(); - widgetDayBody->hide(); - widgetmonthBody->show(); - } - else{ - widgetYearBody->hide(); - widgetWeek->show(); - widgetDayBody->show(); - widgetmonthBody->hide(); - } -} - - -//初始化日期面板 -void LunarCalendarWidget::initDate() -{ - int year = date.year(); - int month = date.month(); - int day = date.day(); - if(oneRun) { - downLabelHandle(date); - yijihandle(date); - oneRun = false; - } - - - //设置为今天,设置变量防止重复触发 - btnClick = true; - cboxYearandMonth->setCurrentIndex(cboxYearandMonth->findText(QString("%1.%2").arg(year).arg(month))); - btnClick = false; - - cboxYearandMonthLabel->setText(QString(" %1.%2").arg(year).arg(month)); - - //首先判断当前月的第一天是星期几 - int week = LunarCalendarInfo::Instance()->getFirstDayOfWeek(year, month, FirstdayisSun); - //当前月天数 - int countDay = LunarCalendarInfo::Instance()->getMonthDays(year, month); - //上月天数 - int countDayPre = LunarCalendarInfo::Instance()->getMonthDays(1 == month ? year - 1 : year, 1 == month ? 12 : month - 1); - - //如果上月天数上月刚好一周则另外处理 - int startPre, endPre, startNext, endNext, index, tempYear, tempMonth, tempDay; - if (0 == week) { - startPre = 0; - endPre = 7; - startNext = 0; - endNext = 42 - (countDay + 7); - } else { - startPre = 0; - endPre = week; - startNext = week + countDay; - endNext = 42; - } - - //纠正1月份前面部分偏差,1月份前面部分是上一年12月份 - tempYear = year; - tempMonth = month - 1; - if (tempMonth < 1) { - tempYear--; - tempMonth = 12; - } - - //显示上月天数 - for (int i = startPre; i < endPre; i++) { - index = i; - tempDay = countDayPre - endPre + i + 1; - - QDate date(tempYear, tempMonth, tempDay); - QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthPre); - } - - //纠正12月份后面部分偏差,12月份后面部分是下一年1月份 - tempYear = year; - tempMonth = month + 1; - if (tempMonth > 12) { - tempYear++; - tempMonth = 1; - } - - //显示下月天数 - for (int i = startNext; i < endNext; i++) { - index = 42 - endNext + i; - tempDay = i - startNext + 1; - - QDate date(tempYear, tempMonth, tempDay); - QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthNext); - } - - //重新置为当前年月 - tempYear = year; - tempMonth = month; - - //显示当前月 - for (int i = week; i < (countDay + week); i++) { - index = (0 == week ? (i + 7) : i); - tempDay = i - week + 1; - - QDate date(tempYear, tempMonth, tempDay); - QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - if (0 == (i % 7) || 6 == (i % 7)) { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_WeekEnd); - } else { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthCurrent); - } - } - - for (int i=0;i<12;i++){ - yearItems.at(i)->setDate(date.addYears(i)); - monthItems.at(i)->setDate(date.addMonths(i)); - } -} - -void LunarCalendarWidget::customButtonsClicked(int x) -{ - if (x) { - yiLabel->setVisible(true); - jiLabel->setVisible(true); - yijistate = true; - Q_EMIT yijiChangeUp(); - } else { - yiLabel->setVisible(false); - jiLabel->setVisible(false); - Q_EMIT yijiChangeDown(); - yijistate = false; - } -} - -QString LunarCalendarWidget::getSettings() -{ - QString arg = "配置文件"; - return arg; - -} - -void LunarCalendarWidget::setSettings(QString arg) -{ - -} - -void LunarCalendarWidget::downLabelHandle(const QDate &date) -{ - - QString strHoliday; - QString strSolarTerms; - QString strLunarFestival; - QString strLunarYear; - QString strLunarMonth; - QString strLunarDay; - - LunarCalendarInfo::Instance()->getLunarCalendarInfo(date.year(), - date.month(), - date.day(), - strHoliday, - strSolarTerms, - strLunarFestival, - strLunarYear, - strLunarMonth, - strLunarDay); - - QString labBottomarg = " " + strLunarYear + " " + strLunarMonth + strLunarDay; - labBottom->setText(labBottomarg); - -} - -void LunarCalendarWidget::yijihandle(const QDate &date) -{ - /*解析json文件*/ - QFile file(QString("/usr/share/ukui-panel/plugin-calendar/html/hlnew/hl%1.js").arg(date.year())); - file.open(QIODevice::ReadOnly | QIODevice::Text); - QString value = file.readAll(); - file.close(); - - QJsonParseError parseJsonErr; - QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(),&parseJsonErr); - if(!(parseJsonErr.error == QJsonParseError::NoError)) - { - qDebug()<<tr("解析json文件错误!"); - return; - } - QJsonObject jsonObject = document.object(); - - if(jsonObject.contains(QString("d%1").arg(date.toString("MMdd")))) - { - QJsonValue jsonValueList = jsonObject.value(QString("d%1").arg(date.toString("MMdd"))); - QJsonObject item = jsonValueList.toObject(); - QString yiString; - QString jiString; - if (item["y"].toString() == "."){ - yiString = " 宜:"; - }else { - yiString = " 宜:" + item["y"].toString(); - } - if (item["j"].toString() == "."){ - jiString = " 忌:"; - }else { - jiString = " 忌:" + item["j"].toString(); - } - - yiLabel->setText(yiString); - jiLabel->setText(jiString); - } -} - -void LunarCalendarWidget::yearChanged(const QString &arg1) -{ - //如果是单击按钮切换的日期变动则不需要触发 - if (btnClick) { - return; - } - int nIndex = arg1.indexOf("."); - if(-1 == nIndex){ - return; - } - int year = arg1.mid(0,nIndex).toInt(); - int month = arg1.mid(nIndex + 1).toInt(); - int day = date.day(); - dateChanged(year, month, day); -} - -void LunarCalendarWidget::monthChanged(const QString &arg1) -{ - //如果是单击按钮切换的日期变动则不需要触发 - if (btnClick) { - return; - } - - int year = date.year(); - int month = arg1.mid(0, arg1.length()).toInt(); - int day = date.day(); - dateChanged(year, month, day); -} - -void LunarCalendarWidget::clicked(const QDate &date, const LunarCalendarItem::DayType &dayType) -{ - this->date = date; - clickDate = date; - dayChanged(this->date,clickDate); - if (LunarCalendarItem::DayType_MonthPre == dayType) - showPreviousMonth(false); - else if (LunarCalendarItem::DayType_MonthNext == dayType) - showNextMonth(false); -} - -void LunarCalendarWidget::updateYearClicked(const QDate &date, const LunarCalendarYearItem::DayType &dayType) -{ - //通过传来的日期,设置当前年月份 - widgetYearBody->hide(); - widgetWeek->show(); - widgetDayBody->show(); - widgetmonthBody->hide(); -// qDebug()<<"year:::::::::::::::::::::"<<date; - clickDate = date; - changeDate(date); - dayChanged(date,clickDate); -// for (int i = 0; i < 12; i++) { -// qDebug()<<"*******************"<<"循环位:"<<i<<yearItems.at(i)->date; -// } -} - -void LunarCalendarWidget::updateMonthClicked(const QDate &date, const LunarCalendarMonthItem::DayType &dayType) -{ - //通过传来的日期,设置当前年月份 - widgetYearBody->hide(); - widgetWeek->show(); - widgetDayBody->show(); - widgetmonthBody->hide(); - qDebug()<<date; - clickDate = date; - changeDate(date); - dayChanged(date,clickDate); -} - -void LunarCalendarWidget::changeDate(const QDate &date) -{ - int year = date.year(); - int month = date.month(); - int day = date.day(); - if(oneRun) { - downLabelHandle(date); - yijihandle(date); - oneRun = false; - } - - - //设置为今天,设置变量防止重复触发 - btnClick = true; - cboxYearandMonth->setCurrentIndex(cboxYearandMonth->findText(QString("%1.%2").arg(year).arg(month))); - btnClick = false; - - cboxYearandMonthLabel->setText(QString(" %1.%2").arg(year).arg(month)); - - //首先判断当前月的第一天是星期几 - int week = LunarCalendarInfo::Instance()->getFirstDayOfWeek(year, month, FirstdayisSun); - //当前月天数 - int countDay = LunarCalendarInfo::Instance()->getMonthDays(year, month); - //上月天数 - int countDayPre = LunarCalendarInfo::Instance()->getMonthDays(1 == month ? year - 1 : year, 1 == month ? 12 : month - 1); - - //如果上月天数上月刚好一周则另外处理 - int startPre, endPre, startNext, endNext, index, tempYear, tempMonth, tempDay; - if (0 == week) { - startPre = 0; - endPre = 7; - startNext = 0; - endNext = 42 - (countDay + 7); - } else { - startPre = 0; - endPre = week; - startNext = week + countDay; - endNext = 42; - } - - //纠正1月份前面部分偏差,1月份前面部分是上一年12月份 - tempYear = year; - tempMonth = month - 1; - if (tempMonth < 1) { - tempYear--; - tempMonth = 12; - } - - //显示上月天数 - for (int i = startPre; i < endPre; i++) { - index = i; - tempDay = countDayPre - endPre + i + 1; - - QDate date(tempYear, tempMonth, tempDay); - QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthPre); - } - - //纠正12月份后面部分偏差,12月份后面部分是下一年1月份 - tempYear = year; - tempMonth = month + 1; - if (tempMonth > 12) { - tempYear++; - tempMonth = 1; - } - - //显示下月天数 - for (int i = startNext; i < endNext; i++) { - index = 42 - endNext + i; - tempDay = i - startNext + 1; - - QDate date(tempYear, tempMonth, tempDay); - QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthNext); - } - - //重新置为当前年月 - tempYear = year; - tempMonth = month; - - //显示当前月 - for (int i = week; i < (countDay + week); i++) { - index = (0 == week ? (i + 7) : i); - tempDay = i - week + 1; - - QDate date(tempYear, tempMonth, tempDay); - QString lunar = LunarCalendarInfo::Instance()->getLunarDay(tempYear, tempMonth, tempDay); - if (0 == (i % 7) || 6 == (i % 7)) { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_WeekEnd); - } else { - dayItems.at(index)->setDate(date, lunar, LunarCalendarItem::DayType_MonthCurrent); - } - } - - for (int i=0;i<12;i++){ - yearItems.at(i)->setDate(clickDate.addYears(i)); -// qDebug()<<"*******************"<<"循环位:"<<i<<yearItems.at(i); - monthItems.at(i)->setDate(clickDate.addMonths(i)); - } -} - -void LunarCalendarWidget::dayChanged(const QDate &date,const QDate &m_date) -{ - //计算星期几,当前天对应标签索引=日期+星期几-1 - int year = date.year(); - int month = date.month(); - int day = date.day(); - int week = LunarCalendarInfo::Instance()->getFirstDayOfWeek(year, month, FirstdayisSun); - //选中当前日期,其他日期恢复,这里还有优化空间,比方说类似单选框机制 - for (int i = 0; i < 42; i++) { - //当月第一天是星期天要另外计算 - int index = day + week - 1; - if (week == 0) { - index = day + 6; - } - dayItems.at(i)->setSelect(false); - if(dayItems.at(i)->getDate() == m_date) { - dayItems.at(i)->setSelect(i == index); - } - if (i == index) { - downLabelHandle(dayItems.at(i)->getDate()); - yijihandle(dayItems.at(i)->getDate()); - } - - } - - //发送日期单击信号 - Q_EMIT clicked(date); - //发送日期更新信号 - Q_EMIT selectionChanged(); -} - -void LunarCalendarWidget::dateChanged(int year, int month, int day) -{ - //如果原有天大于28则设置为1,防止出错 - date.setDate(year, month, day > 28 ? 1 : day); - initDate(); -} - -LunarCalendarWidget::CalendarStyle LunarCalendarWidget::getCalendarStyle() const -{ - return this->calendarStyle; -} - -QDate LunarCalendarWidget::getDate() const -{ - return this->date; -} - -QColor LunarCalendarWidget::getWeekTextColor() const -{ - return this->weekTextColor; -} - -QColor LunarCalendarWidget::getWeekBgColor() const -{ - return this->weekBgColor; -} - -bool LunarCalendarWidget::getShowLunar() const -{ - return this->showLunar; -} - -QString LunarCalendarWidget::getBgImage() const -{ - return this->bgImage; -} - -LunarCalendarWidget::SelectType LunarCalendarWidget::getSelectType() const -{ - return this->selectType; -} - - -QColor LunarCalendarWidget::getBorderColor() const -{ - return this->borderColor; -} -QColor LunarCalendarWidget::getWeekColor() const -{ - return this->weekColor; -} - -QColor LunarCalendarWidget::getSuperColor() const -{ - return this->superColor; -} - -QColor LunarCalendarWidget::getLunarColor() const -{ - return this->lunarColor; -} -QColor LunarCalendarWidget::getCurrentTextColor() const -{ - return this->currentTextColor; -} - -QColor LunarCalendarWidget::getOtherTextColor() const -{ - return this->otherTextColor; -} -QColor LunarCalendarWidget::getSelectTextColor() const -{ - return this->selectTextColor; -} - -QColor LunarCalendarWidget::getHoverTextColor() const -{ - return this->hoverTextColor; -} - -QColor LunarCalendarWidget::getCurrentLunarColor() const -{ - return this->currentLunarColor; -} - -QColor LunarCalendarWidget::getOtherLunarColor() const -{ - return this->otherLunarColor; -} - -QColor LunarCalendarWidget::getSelectLunarColor() const -{ - return this->selectLunarColor; -} - -QColor LunarCalendarWidget::getHoverLunarColor() const -{ - return this->hoverLunarColor; -} - -QColor LunarCalendarWidget::getCurrentBgColor() const -{ - return this->currentBgColor; -} - -QColor LunarCalendarWidget::getOtherBgColor() const -{ - return this->otherBgColor; -} - -QColor LunarCalendarWidget::getSelectBgColor() const -{ - return this->selectBgColor; -} - -QColor LunarCalendarWidget::getHoverBgColor() const -{ - return this->hoverBgColor; -} - -QSize LunarCalendarWidget::sizeHint() const -{ - return QSize(600, 500); -} - -QSize LunarCalendarWidget::minimumSizeHint() const -{ - return QSize(200, 150); -} - -//显示上一年 -void LunarCalendarWidget::showPreviousYear() -{ - int year = date.year(); - int month = date.month(); - int day = date.day(); - if (year <= 1901) { - return; - } - - year--; - dateChanged(year, month, day); -} - -//显示下一年 -void LunarCalendarWidget::showNextYear() -{ - int year = date.year(); - int month = date.month(); - int day = date.day(); - if (year >= 2099) { - return; - } - - year++; - dateChanged(year, month, day); -} - -//显示上月日期 -void LunarCalendarWidget::showPreviousMonth(bool date_clicked) -{ - int year = date.year(); - int month = date.month(); - int day = date.day(); - if (year <= 1901 && month == 1) { - return; - } - - //extra: - if (date_clicked) month--; - if (month < 1) { - month = 12; - year--; - } - - dateChanged(year, month, day); - dayChanged(this->date,clickDate); -} - -//显示下月日期 -void LunarCalendarWidget::showNextMonth(bool date_clicked) -{ - int year = date.year(); - int month = date.month(); - int day = date.day(); - if (year >= 2099 ) { - return; - } - - //extra - if (date_clicked)month++; - if (month > 12) { - month = 1; - year++; - } - - dateChanged(year, month, day); - dayChanged(this->date,clickDate); -} - -//转到今天 -void LunarCalendarWidget::showToday() -{ - widgetYearBody->hide(); - widgetmonthBody->hide(); - widgetDayBody->show(); - widgetWeek->show(); - date = QDate::currentDate(); - initDate(); - dayChanged(this->date,clickDate); -} - -void LunarCalendarWidget::setCalendarStyle(const LunarCalendarWidget::CalendarStyle &calendarStyle) -{ - if (this->calendarStyle != calendarStyle) { - this->calendarStyle = calendarStyle; - } -} - -void LunarCalendarWidget::setWeekNameFormat(bool FirstDayisSun) -{ - FirstdayisSun = FirstDayisSun; - if (FirstdayisSun) { -// listWeek << "日" << "一" << "二" << "三" << "四" << "五" << "六"; -// listWeek << "周日" << "周一" << "周二" << "周三" << "周四" << "周五" << "周六"; -// listWeek << "星期天" << "星期一" << "星期二" << "星期三" << "星期四" << "星期五" << "星期六"; -// listWeek << "Sun" << "Mon" << "Tue" << "Wed" << "Thur" << "Fri" << "Sat"; - QTimer::singleShot(0,this,[=]{ - labWeeks.at(0)->setText((tr("Sunday"))); - labWeeks.at(1)->setText((tr("Monday"))); - labWeeks.at(2)->setText((tr("Tuesday"))); - labWeeks.at(3)->setText((tr("Wednesday"))); - labWeeks.at(4)->setText((tr("Thursday"))); - labWeeks.at(5)->setText((tr("Friday"))); - labWeeks.at(6)->setText((tr("Saturday"))); - }); - } else { - QTimer::singleShot(0,this,[=]{ - labWeeks.at(0)->setText((tr("Monday"))); - labWeeks.at(1)->setText((tr("Tuesday"))); - labWeeks.at(2)->setText((tr("Wednesday"))); - labWeeks.at(3)->setText((tr("Thursday"))); - labWeeks.at(4)->setText((tr("Friday"))); - labWeeks.at(5)->setText((tr("Saturday"))); - labWeeks.at(6)->setText((tr("Sunday"))); - }); - } - initDate(); -} - -void LunarCalendarWidget::setDate(const QDate &date) -{ - if (this->date != date) { - this->date = date; - initDate(); - } -} - -void LunarCalendarWidget::setWeekTextColor(const QColor &weekTextColor) -{ - if (this->weekTextColor != weekTextColor) { - this->weekTextColor = weekTextColor; - initStyle(); - } -} - -void LunarCalendarWidget::setWeekBgColor(const QColor &weekBgColor) -{ - if (this->weekBgColor != weekBgColor) { - this->weekBgColor = weekBgColor; - initStyle(); - } -} - -void LunarCalendarWidget::setShowLunar(bool showLunar) -{ - this->showLunar = showLunar; - initStyle(); -} - -void LunarCalendarWidget::setBgImage(const QString &bgImage) -{ - if (this->bgImage != bgImage) { - this->bgImage = bgImage; - initStyle(); - } -} - -void LunarCalendarWidget::setSelectType(const LunarCalendarWidget::SelectType &selectType) -{ - if (this->selectType != selectType) { - this->selectType = selectType; - initStyle(); - } -} - -void LunarCalendarWidget::setBorderColor(const QColor &borderColor) -{ - if (this->borderColor != borderColor) { - this->borderColor = borderColor; - initStyle(); - } -} - -void LunarCalendarWidget::setWeekColor(const QColor &weekColor) -{ - if (this->weekColor != weekColor) { - this->weekColor = weekColor; - initStyle(); - } -} - -void LunarCalendarWidget::setSuperColor(const QColor &superColor) -{ - if (this->superColor != superColor) { - this->superColor = superColor; - initStyle(); - } -} - -void LunarCalendarWidget::setLunarColor(const QColor &lunarColor) -{ - if (this->lunarColor != lunarColor) { - this->lunarColor = lunarColor; - initStyle(); - } -} - -void LunarCalendarWidget::setCurrentTextColor(const QColor ¤tTextColor) -{ - if (this->currentTextColor != currentTextColor) { - this->currentTextColor = currentTextColor; - initStyle(); - } -} - -void LunarCalendarWidget::setOtherTextColor(const QColor &otherTextColor) -{ - if (this->otherTextColor != otherTextColor) { - this->otherTextColor = otherTextColor; - initStyle(); - } -} - -void LunarCalendarWidget::setSelectTextColor(const QColor &selectTextColor) -{ - if (this->selectTextColor != selectTextColor) { - this->selectTextColor = selectTextColor; - initStyle(); - } -} - -void LunarCalendarWidget::setHoverTextColor(const QColor &hoverTextColor) -{ - if (this->hoverTextColor != hoverTextColor) { - this->hoverTextColor = hoverTextColor; - initStyle(); - } -} - -void LunarCalendarWidget::setCurrentLunarColor(const QColor ¤tLunarColor) -{ - if (this->currentLunarColor != currentLunarColor) { - this->currentLunarColor = currentLunarColor; - initStyle(); - } -} - -void LunarCalendarWidget::setOtherLunarColor(const QColor &otherLunarColor) -{ - if (this->otherLunarColor != otherLunarColor) { - this->otherLunarColor = otherLunarColor; - initStyle(); - } -} - -void LunarCalendarWidget::setSelectLunarColor(const QColor &selectLunarColor) -{ - if (this->selectLunarColor != selectLunarColor) { - this->selectLunarColor = selectLunarColor; - initStyle(); - } -} - -void LunarCalendarWidget::setHoverLunarColor(const QColor &hoverLunarColor) -{ - if (this->hoverLunarColor != hoverLunarColor) { - this->hoverLunarColor = hoverLunarColor; - initStyle(); - } -} - -void LunarCalendarWidget::setCurrentBgColor(const QColor ¤tBgColor) -{ - if (this->currentBgColor != currentBgColor) { - this->currentBgColor = currentBgColor; - initStyle(); - } -} - -void LunarCalendarWidget::setOtherBgColor(const QColor &otherBgColor) -{ - if (this->otherBgColor != otherBgColor) { - this->otherBgColor = otherBgColor; - initStyle(); - } -} - -void LunarCalendarWidget::setSelectBgColor(const QColor &selectBgColor) -{ - if (this->selectBgColor != selectBgColor) { - this->selectBgColor = selectBgColor; - initStyle(); - } -} - -void LunarCalendarWidget::setHoverBgColor(const QColor &hoverBgColor) -{ - if (this->hoverBgColor != hoverBgColor) { - this->hoverBgColor = hoverBgColor; - initStyle(); - } -} - -void LunarCalendarWidget::wheelEvent(QWheelEvent *event) { - if (event->delta() > 0) - showPreviousMonth(); - else - showNextMonth(); -} - - -m_PartLineWidget::m_PartLineWidget(QWidget *parent) : QWidget(parent) -{ - -} - -void m_PartLineWidget::paintEvent(QPaintEvent *event) -{ - QPainter p(this); - - QRect rect = this->rect(); - - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - QColor color=qApp->palette().color(QPalette::Base); - if(color.red() == 255 && color.green() == 255 && color.blue() == 255){ - color.setRgb(1,1,1,255); - } else if (color.red() == 31 && color.green() == 32 && color.blue() == 34) { - color.setRgb(255,255,255,255); - } - p.setBrush(color); - p.setOpacity(0.05); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rect,0,0); - - QWidget::paintEvent(event); -} - -statelabel::statelabel() : QLabel() -{ - - -} - -//鼠标点击事件 -void statelabel::mousePressEvent(QMouseEvent *event) -{ - if (event->buttons() == Qt::LeftButton){ - Q_EMIT labelclick(); - - } - return; -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,377 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef LUNARCALENDARWIDGET_H -#define LUNARCALENDARWIDGET_H - -#include <QGSettings/QGSettings> -#include <QWidget> -#include <QDate> -#include <QTimer> -#include <QVBoxLayout> -#include <QWheelEvent> -#include "qfontdatabase.h" -#include "qdatetime.h" -#include "qlayout.h" -#include "qlabel.h" -#include "qpushbutton.h" -#include "qtoolbutton.h" -#include "qcombobox.h" -#include "qdebug.h" -#include <QPainter> -#include <QApplication> -#include <QPalette> -#include "picturetowhite.h" -#include <QJsonParseError> -#include <QJsonObject> -#include <QRadioButton> -#include <QLabel> -#include <QObject> -#include <QMouseEvent> -#include "../../panel/pluginsettings.h" -#include "../../panel/iukuipanelplugin.h" -#include "lunarcalendarinfo.h" -#include "lunarcalendaritem.h" -#include "lunarcalendaryearitem.h" -#include "lunarcalendarmonthitem.h" -#include "customstylePushbutton.h" -#include <QCheckBox> - - -class QLabel; -class statelabel; -class QComboBox; -class LunarCalendarYearItem; -class LunarCalendarMonthItem; -class LunarCalendarItem; - -class m_PartLineWidget; - -#ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include <QtDesigner/QDesignerExportWidget> -#else -#include <QtUiPlugin/QDesignerExportWidget> -#endif - -class QDESIGNER_WIDGET_EXPORT LunarCalendarWidget : public QWidget -#else -class LunarCalendarWidget : public QWidget -#endif - -{ - Q_OBJECT - Q_ENUMS(CalendarStyle) - Q_ENUMS(WeekNameFormat) - Q_ENUMS(SelectType) - - Q_PROPERTY(CalendarStyle calendarStyle READ getCalendarStyle WRITE setCalendarStyle) - Q_PROPERTY(QDate date READ getDate WRITE setDate) - - Q_PROPERTY(QColor weekTextColor READ getWeekTextColor WRITE setWeekTextColor) - Q_PROPERTY(QColor weekBgColor READ getWeekBgColor WRITE setWeekBgColor) - - Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar) - Q_PROPERTY(QString bgImage READ getBgImage WRITE setBgImage) - Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType) - - Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor) - Q_PROPERTY(QColor weekColor READ getWeekColor WRITE setWeekColor) - Q_PROPERTY(QColor superColor READ getSuperColor WRITE setSuperColor) - Q_PROPERTY(QColor lunarColor READ getLunarColor WRITE setLunarColor) - - Q_PROPERTY(QColor currentTextColor READ getCurrentTextColor WRITE setCurrentTextColor) - Q_PROPERTY(QColor otherTextColor READ getOtherTextColor WRITE setOtherTextColor) - Q_PROPERTY(QColor selectTextColor READ getSelectTextColor WRITE setSelectTextColor) - Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor) - - Q_PROPERTY(QColor currentLunarColor READ getCurrentLunarColor WRITE setCurrentLunarColor) - Q_PROPERTY(QColor otherLunarColor READ getOtherLunarColor WRITE setOtherLunarColor) - Q_PROPERTY(QColor selectLunarColor READ getSelectLunarColor WRITE setSelectLunarColor) - Q_PROPERTY(QColor hoverLunarColor READ getHoverLunarColor WRITE setHoverLunarColor) - - Q_PROPERTY(QColor currentBgColor READ getCurrentBgColor WRITE setCurrentBgColor) - Q_PROPERTY(QColor otherBgColor READ getOtherBgColor WRITE setOtherBgColor) - Q_PROPERTY(QColor selectBgColor READ getSelectBgColor WRITE setSelectBgColor) - Q_PROPERTY(QColor hoverBgColor READ getHoverBgColor WRITE setHoverBgColor) - -public: - enum CalendarStyle { - CalendarStyle_Red = 0 - }; - - enum WeekNameFormat { - WeekNameFormat_Short = 0, //短名称 - WeekNameFormat_Normal = 1, //普通名称 - WeekNameFormat_Long = 2, //长名称 - WeekNameFormat_En = 3 //英文名称 - }; - - enum SelectType { - SelectType_Rect = 0, //矩形背景 - SelectType_Circle = 1, //圆形背景 - SelectType_Triangle = 2, //带三角标 - SelectType_Image = 3 //图片背景 - }; - - explicit LunarCalendarWidget(QWidget *parent = 0); - ~LunarCalendarWidget(); - -private: - QLabel *datelabel; - QLabel *timelabel; - QLabel *lunarlabel; - QTimer *timer; - QVBoxLayout *timeShow; - QWidget *widgetTime; - QPushButton *btnYear; - QPushButton *btnMonth; - QPushButton *btnToday; - QWidget *labWidget; - QLabel *labBottom; - QHBoxLayout *labLayout; - m_PartLineWidget *lineUp; - m_PartLineWidget *lineDown; - statelabel *btnPrevYear; - statelabel *btnNextYear; - QLabel *yijichooseLabel; - QCheckBox *yijichoose; - QVBoxLayout *yijiLayout; - QWidget *yijiWidget; - QLabel *yiLabel; - QLabel *jiLabel; - QWidget *widgetWeek; - QWidget *widgetDayBody; - QWidget *widgetYearBody; - QWidget *widgetmonthBody; - - QString timemodel = 0; - bool yijistate = false; - bool lunarstate =false; - bool oneRun = true; -// IUKUIPanelPlugin *mPlugin; - QString dateShowMode; - QMap<QString,QString> worktimeinside; - QMap<QString,QMap<QString,QString>> worktime; - void analysisWorktimeJs(); //解析js文件 - void downLabelHandle(const QDate &date); - QFont iconFont; //图形字体 - bool btnClick; //按钮单击,避开下拉选择重复触发 - QComboBox *cboxYearandMonth; //年份下拉框 - QLabel *cboxYearandMonthLabel; - QList<QLabel *> labWeeks; //顶部星期名称 - QList<LunarCalendarItem *> dayItems; //日期元素 - QList<LunarCalendarYearItem *> yearItems; //年份元素 - QList<LunarCalendarMonthItem *> monthItems; //月份元素 - - CalendarStyle calendarStyle; //整体样式 - bool FirstdayisSun; //首日期为周日 - QDate date; //当前日期 - QDate clickDate; //保存点击日期 - - QColor weekTextColor; //星期名称文字颜色 - QColor weekBgColor; //星期名称背景色 - - bool showLunar; //显示农历 - QString bgImage; //背景图片 - SelectType selectType; //选中模式 - - QColor borderColor; //边框颜色 - QColor weekColor; //周末颜色 - QColor superColor; //角标颜色 - QColor lunarColor; //农历节日颜色 - - QColor currentTextColor; //当前月文字颜色 - QColor otherTextColor; //其他月文字颜色 - QColor selectTextColor; //选中日期文字颜色 - QColor hoverTextColor; //悬停日期文字颜色 - - QColor currentLunarColor; //当前月农历文字颜色 - QColor otherLunarColor; //其他月农历文字颜色 - QColor selectLunarColor; //选中日期农历文字颜色 - QColor hoverLunarColor; //悬停日期农历文字颜色 - - QColor currentBgColor; //当前月背景颜色 - QColor otherBgColor; //其他月背景颜色 - QColor selectBgColor; //选中日期背景颜色 - QColor hoverBgColor; //悬停日期背景颜色 - - QGSettings *calendar_gsettings; - - void setColor(bool mdark_style); - void _timeUpdate(); - void yijihandle(const QDate &date); - QString getSettings(); - void setSettings(QString arg); - QGSettings *style_settings; - bool dark_style; - -protected : - void wheelEvent(QWheelEvent *event); - bool eventFilter(QObject *, QEvent *); - -private Q_SLOTS: - void initWidget(); - void initStyle(); - void initDate(); - void changeDate(const QDate &date); - void yearChanged(const QString &arg1); - void monthChanged(const QString &arg1); - void clicked(const QDate &date, const LunarCalendarItem::DayType &dayType); - void dayChanged(const QDate &date,const QDate &m_date); - void dateChanged(int year, int month, int day); - void timerUpdate(); - void customButtonsClicked(int x); - void yearWidgetChange(); - void monthWidgetChange(); - -public: - CalendarStyle getCalendarStyle() const; - QDate getDate() const; - - QColor getWeekTextColor() const; - QColor getWeekBgColor() const; - - bool getShowLunar() const; - QString getBgImage() const; - SelectType getSelectType() const; - - QColor getBorderColor() const; - QColor getWeekColor() const; - QColor getSuperColor() const; - QColor getLunarColor() const; - - QColor getCurrentTextColor() const; - QColor getOtherTextColor() const; - QColor getSelectTextColor() const; - QColor getHoverTextColor() const; - - QColor getCurrentLunarColor() const; - QColor getOtherLunarColor() const; - QColor getSelectLunarColor() const; - QColor getHoverLunarColor() const; - - QColor getCurrentBgColor() const; - QColor getOtherBgColor() const; - QColor getSelectBgColor() const; - QColor getHoverBgColor() const; - - QSize sizeHint() const; - QSize minimumSizeHint() const; - -public Q_SLOTS: - - void updateYearClicked(const QDate &date, const LunarCalendarYearItem::DayType &dayType); - void updateMonthClicked(const QDate &date, const LunarCalendarMonthItem::DayType &dayType); - //上一年,下一年 - void showPreviousYear(); - void showNextYear(); - - //上一月,下一月 - void showPreviousMonth(bool date_clicked = true); - void showNextMonth(bool date_clicked = true); - - //转到今天 - void showToday(); - - //设置整体样式 - void setCalendarStyle(const CalendarStyle &calendarStyle); - //设置星期名称格式 - void setWeekNameFormat(bool FirstDayisSun); - - //设置日期 - void setDate(const QDate &date); - - //设置顶部星期名称文字颜色+背景色 - void setWeekTextColor(const QColor &weekTextColor); - void setWeekBgColor(const QColor &weekBgColor); - - //设置是否显示农历信息 - void setShowLunar(bool showLunar); - //设置背景图片 - void setBgImage(const QString &bgImage); - //设置选中背景样式 - void setSelectType(const SelectType &selectType); - - //设置边框颜色 - void setBorderColor(const QColor &borderColor); - //设置周末颜色 - void setWeekColor(const QColor &weekColor); - //设置角标颜色 - void setSuperColor(const QColor &superColor); - //设置农历节日颜色 - void setLunarColor(const QColor &lunarColor); - - //设置当前月文字颜色 - void setCurrentTextColor(const QColor ¤tTextColor); - //设置其他月文字颜色 - void setOtherTextColor(const QColor &otherTextColor); - //设置选中日期文字颜色 - void setSelectTextColor(const QColor &selectTextColor); - //设置悬停日期文字颜色 - void setHoverTextColor(const QColor &hoverTextColor); - - //设置当前月农历文字颜色 - void setCurrentLunarColor(const QColor ¤tLunarColor); - //设置其他月农历文字颜色 - void setOtherLunarColor(const QColor &otherLunarColor); - //设置选中日期农历文字颜色 - void setSelectLunarColor(const QColor &selectLunarColor); - //设置悬停日期农历文字颜色 - void setHoverLunarColor(const QColor &hoverLunarColor); - - //设置当前月背景颜色 - void setCurrentBgColor(const QColor ¤tBgColor); - //设置其他月背景颜色 - void setOtherBgColor(const QColor &otherBgColor); - //设置选中日期背景颜色 - void setSelectBgColor(const QColor &selectBgColor); - //设置悬停日期背景颜色 - void setHoverBgColor(const QColor &hoverBgColor); - -Q_SIGNALS: - void clicked(const QDate &date); - void selectionChanged(); - void yijiChangeUp(); - void yijiChangeDown(); -}; - - -class m_PartLineWidget : public QWidget -{ - Q_OBJECT -public: - explicit m_PartLineWidget(QWidget *parent = nullptr); - void paintEvent(QPaintEvent *event); - -}; - -class statelabel : public QLabel -{ - Q_OBJECT -public: - statelabel(); - -protected: - void mousePressEvent(QMouseEvent *event); -Q_SIGNALS : - void labelclick(); -}; - - -#endif // LUNARCALENDARWIDGET_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.pro ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.pro --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.pro 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendarwidget.pro 1970-01-01 08:00:00.000000000 +0800 @@ -1,40 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2017-01-05T22:11:54 -# -#------------------------------------------------- - -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = lunarcalendarwidget -TEMPLATE = app -QMAKE_CXXFLAGS += -std=c++11 -MOC_DIR = temp/moc -RCC_DIR = temp/rcc -UI_DIR = temp/ui -OBJECTS_DIR = temp/obj -DESTDIR = $$PWD/../bin -CONFIG += qt warn_off -RESOURCES += main.qrc - -CONFIG += \ - link_pkgconfig \ - -PKGCONFIG += gsettings-qt - -SOURCES += main.cpp -SOURCES += frmlunarcalendarwidget.cpp -SOURCES += lunarcalendaritem.cpp -SOURCES += lunarcalendarinfo.cpp -SOURCES += lunarcalendarwidget.cpp - -HEADERS += frmlunarcalendarwidget.h -HEADERS += lunarcalendaritem.h -HEADERS += lunarcalendarinfo.h -HEADERS += lunarcalendarwidget.h - -FORMS += frmlunarcalendarwidget.ui - -INCLUDEPATH += $$PWD diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,494 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#pragma execution_character_set("utf-8") - -#include "lunarcalendaryearitem.h" -#include "qpainter.h" -#include "qevent.h" -#include "qdatetime.h" -#include "qdebug.h" -#include <QGSettings> - -LunarCalendarYearItem::LunarCalendarYearItem(QWidget *parent) : QWidget(parent) -{ - hover = false; - pressed = false; - - select = false; - showLunar = true; - bgImage = ":/image/bg_calendar.png"; - selectType = SelectType_Rect; - - date = QDate::currentDate(); - lunar = "初一"; - dayType = DayType_MonthCurrent; - - //实时监听主题变化 - const QByteArray id("org.ukui.style"); - QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); - connect(fontSetting, &QGSettings::changed,[=](QString key) { - if(fontSetting->get("style-name").toString() == "ukui-default") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } else if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else if(fontSetting->get("style-name").toString() == "ukui-dark") { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - }); - - if(fontSetting->get("style-name").toString() == "ukui-light") { - weekColor = QColor(0, 0, 0); - currentTextColor = QColor(0, 0, 0); - otherTextColor = QColor(0,0,0,40); - otherLunarColor = QColor(0,0,0,40); - currentLunarColor = QColor(0,0,0,90); - lunarColor = QColor(0,0,0,90); - } else { - weekColor = QColor(255, 255, 255); - currentTextColor = QColor(255, 255, 255); - otherTextColor = QColor(255, 255, 255,40); - otherLunarColor = QColor(255, 255, 255,40); - currentLunarColor = QColor(255, 255, 255,90); - lunarColor = QColor(255, 255, 255,90); - } - - borderColor = QColor(180, 180, 180); - superColor = QColor(255, 129, 6); - - selectTextColor = QColor(255, 255, 255); - hoverTextColor = QColor(250, 250, 250); - - selectLunarColor = QColor(255, 255, 255); - hoverLunarColor = QColor(250, 250, 250); - - currentBgColor = QColor(255, 255, 255); - otherBgColor = QColor(240, 240, 240); - selectBgColor = QColor(55,143,250); - hoverBgColor = QColor(204, 183, 180); -} - -void LunarCalendarYearItem::enterEvent(QEvent *) -{ - hover = true; - this->update(); -} - -void LunarCalendarYearItem::leaveEvent(QEvent *) -{ - hover = false; - this->update(); -} - -void LunarCalendarYearItem::mousePressEvent(QMouseEvent *) -{ - pressed = true; - this->update(); -// Q_EMIT clicked(date, dayType); - Q_EMIT yearMessage(date, dayType); -} - -void LunarCalendarYearItem::mouseReleaseEvent(QMouseEvent *) -{ - pressed = false; - this->update(); -} - - -void LunarCalendarYearItem::paintEvent(QPaintEvent *) -{ - - QDate dateNow = QDate::currentDate(); - - //绘制准备工作,启用反锯齿 - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - - //绘制背景和边框 - drawBg(&painter); - - //对比当前的时间,画选中状态 - if(dateNow.year() == date.year()) { - drawBgCurrent(&painter, selectBgColor); - } - - //绘制悬停状态 - if (hover) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制选中状态 - if (select) { - drawBgHover(&painter, hoverBgColor); - } - - //绘制日期 - drawYear(&painter); - -} - -void LunarCalendarYearItem::drawBg(QPainter *painter) -{ - painter->save(); - - //根据当前类型选择对应的颜色 - QColor bgColor = currentBgColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - bgColor = otherBgColor; - } - painter->restore(); -} - -void LunarCalendarYearItem::drawBgCurrent(QPainter *painter, const QColor &color) -{ - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(color); - - QRect rect = this->rect(); - painter->drawRoundedRect(rect,4,4); - - painter->restore(); -} - -void LunarCalendarYearItem::drawBgHover(QPainter *painter, const QColor &color) -{ - painter->save(); - QRect rect = this->rect(); - painter->setPen(QPen(QColor(55,143,250),2)); - - painter->drawRoundedRect(rect,4,4); - - painter->restore(); -} - -void LunarCalendarYearItem::drawYear(QPainter *painter) -{ - int width = this->width(); - int height = this->height(); - int side = qMin(width, height); - - painter->save(); - - //根据当前类型选择对应的颜色 - QColor color = currentTextColor; - if (dayType == DayType_MonthPre || dayType == DayType_MonthNext) { - color = otherTextColor; - } else if (dayType == DayType_WeekEnd) { - color = weekColor; - } - - painter->setPen(color); - - QFont font; - font.setPixelSize(side * 0.2); - //设置文字粗细 - font.setBold(true); - painter->setFont(font); - - QRect dayRect = QRect(0, 0, width, height / 1.7); - QString arg = QString::number(date.year()) + "年"; - painter->drawText(dayRect, Qt::AlignHCenter | Qt::AlignBottom, arg); - painter->restore(); -} - -bool LunarCalendarYearItem::getSelect() const -{ - return this->select; -} - -bool LunarCalendarYearItem::getShowLunar() const -{ - return this->showLunar; -} - -QString LunarCalendarYearItem::getBgImage() const -{ - return this->bgImage; -} - -LunarCalendarYearItem::SelectType LunarCalendarYearItem::getSelectType() const -{ - return this->selectType; -} - -QDate LunarCalendarYearItem::getDate() const -{ - return this->date; -} - -QString LunarCalendarYearItem::getLunar() const -{ - return this->lunar; -} - -LunarCalendarYearItem::DayType LunarCalendarYearItem::getDayType() const -{ - return this->dayType; -} - -QColor LunarCalendarYearItem::getBorderColor() const -{ - return this->borderColor; -} - -QColor LunarCalendarYearItem::getWeekColor() const -{ - return this->weekColor; -} - -QColor LunarCalendarYearItem::getSuperColor() const -{ - return this->superColor; -} - -QColor LunarCalendarYearItem::getLunarColor() const -{ - return this->lunarColor; -} - -QColor LunarCalendarYearItem::getCurrentTextColor() const -{ - return this->currentTextColor; -} - -QColor LunarCalendarYearItem::getOtherTextColor() const -{ - return this->otherTextColor; -} - -QColor LunarCalendarYearItem::getSelectTextColor() const -{ - return this->selectTextColor; -} - -QColor LunarCalendarYearItem::getHoverTextColor() const -{ - return this->hoverTextColor; -} - -QColor LunarCalendarYearItem::getCurrentLunarColor() const -{ - return this->currentLunarColor; -} - -QColor LunarCalendarYearItem::getOtherLunarColor() const -{ - return this->otherLunarColor; -} - -QColor LunarCalendarYearItem::getSelectLunarColor() const -{ - return this->selectLunarColor; -} - -QColor LunarCalendarYearItem::getHoverLunarColor() const -{ - return this->hoverLunarColor; -} - -QColor LunarCalendarYearItem::getCurrentBgColor() const -{ - return this->currentBgColor; -} - -QColor LunarCalendarYearItem::getOtherBgColor() const -{ - return this->otherBgColor; -} - -QColor LunarCalendarYearItem::getSelectBgColor() const -{ - return this->selectBgColor; -} - -QColor LunarCalendarYearItem::getHoverBgColor() const -{ - return this->hoverBgColor; -} - -QSize LunarCalendarYearItem::sizeHint() const -{ - return QSize(100, 100); -} - -QSize LunarCalendarYearItem::minimumSizeHint() const -{ - return QSize(20, 20); -} - -void LunarCalendarYearItem::setSelect(bool select) -{ - if (this->select != select) { - this->select = select; - this->update(); - } -} - -void LunarCalendarYearItem::setShowLunar(bool showLunar) -{ - this->showLunar = showLunar; - this->update(); -} - -void LunarCalendarYearItem::setBgImage(const QString &bgImage) -{ - if (this->bgImage != bgImage) { - this->bgImage = bgImage; - this->update(); - } -} - -void LunarCalendarYearItem::setSelectType(const LunarCalendarYearItem::SelectType &selectType) -{ - if (this->selectType != selectType) { - this->selectType = selectType; - this->update(); - } -} - -void LunarCalendarYearItem::setDate(const QDate &date) -{ - if (this->date != date) { - this->date = date; - this->update(); - } -} - -void LunarCalendarYearItem::setLunar(const QString &lunar) -{ - if (this->lunar != lunar) { - this->lunar = lunar; - this->update(); - } -} - -void LunarCalendarYearItem::setDayType(const LunarCalendarYearItem::DayType &dayType) -{ - if (this->dayType != dayType) { - this->dayType = dayType; - this->update(); - } -} - -void LunarCalendarYearItem::setDate(const QDate &date, const QString &lunar, const DayType &dayType) -{ - this->date = date; - this->lunar = lunar; - this->dayType = dayType; - this->update(); -} - -void LunarCalendarYearItem::setBorderColor(const QColor &borderColor) -{ - if (this->borderColor != borderColor) { - this->borderColor = borderColor; - this->update(); - } -} - -void LunarCalendarYearItem::setWeekColor(const QColor &weekColor) -{ - if (this->weekColor != weekColor) { - this->weekColor = weekColor; - this->update(); - } -} - -void LunarCalendarYearItem::setSuperColor(const QColor &superColor) -{ - if (this->superColor != superColor) { - this->superColor = superColor; - this->update(); - } -} - -void LunarCalendarYearItem::setLunarColor(const QColor &lunarColor) -{ - if (this->lunarColor != lunarColor) { - this->lunarColor = lunarColor; - this->update(); - } -} - -void LunarCalendarYearItem::setCurrentTextColor(const QColor ¤tTextColor) -{ - if (this->currentTextColor != currentTextColor) { - this->currentTextColor = currentTextColor; - this->update(); - } -} - -void LunarCalendarYearItem::setOtherTextColor(const QColor &otherTextColor) -{ - if (this->otherTextColor != otherTextColor) { - this->otherTextColor = otherTextColor; - this->update(); - } -} - -void LunarCalendarYearItem::setSelectTextColor(const QColor &selectTextColor) -{ - if (this->selectTextColor != selectTextColor) { - this->selectTextColor = selectTextColor; - this->update(); - } -} - -void LunarCalendarYearItem::setHoverTextColor(const QColor &hoverTextColor) -{ - if (this->hoverTextColor != hoverTextColor) { - this->hoverTextColor = hoverTextColor; - this->update(); - } -} - -void LunarCalendarYearItem::setCurrentLunarColor(const QColor ¤tLunarColor) -{ - if (this->currentLunarColor != currentLunarColor) { - this->currentLunarColor = currentLunarColor; - this->update(); - } -} - -void LunarCalendarYearItem::setOtherLunarColor(const QColor &otherLunarColor) -{ - if (this->otherLunarColor != otherLunarColor) { - this->otherLunarColor = otherLunarColor; - this->update(); - } -} - - - - diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/lunarcalendaryearitem.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef LUNARCALENDARYEARITEM_H -#define LUNARCALENDARYEARITEM_H - -#include <QWidget> -#include <QDate> -#include <QMap> - -#ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include <QtDesigner/QDesignerExportWidget> -#else -#include <QtUiPlugin/QDesignerExportWidget> -#endif - -class QDESIGNER_WIDGET_EXPORT LunarCalendarItem : public QWidget -#else -class LunarCalendarYearItem : public QWidget -#endif - -{ - Q_OBJECT - Q_ENUMS(DayType) - Q_ENUMS(SelectType) - - Q_PROPERTY(bool select READ getSelect WRITE setSelect) - Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar) - Q_PROPERTY(QString bgImage READ getBgImage WRITE setBgImage) - Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType) - - Q_PROPERTY(QDate date READ getDate WRITE setDate) - Q_PROPERTY(QString lunar READ getLunar WRITE setLunar) - Q_PROPERTY(DayType dayType READ getDayType WRITE setDayType) - - Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor) - Q_PROPERTY(QColor weekColor READ getWeekColor WRITE setWeekColor) - Q_PROPERTY(QColor superColor READ getSuperColor WRITE setSuperColor) - Q_PROPERTY(QColor lunarColor READ getLunarColor WRITE setLunarColor) - - Q_PROPERTY(QColor currentTextColor READ getCurrentTextColor WRITE setCurrentTextColor) - Q_PROPERTY(QColor otherTextColor READ getOtherTextColor WRITE setOtherTextColor) - Q_PROPERTY(QColor selectTextColor READ getSelectTextColor WRITE setSelectTextColor) - Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor) - - Q_PROPERTY(QColor currentLunarColor READ getCurrentLunarColor WRITE setCurrentLunarColor) - Q_PROPERTY(QColor otherLunarColor READ getOtherLunarColor WRITE setOtherLunarColor) - - -public: - enum DayType { - DayType_MonthPre = 0, //上月剩余天数 - DayType_MonthNext = 1, //下个月的天数 - DayType_MonthCurrent = 2, //当月天数 - DayType_WeekEnd = 3 //周末 - }; - - enum SelectType { - SelectType_Rect = 0, //矩形背景 - SelectType_Circle = 1, //圆形背景 - SelectType_Triangle = 2, //带三角标 - SelectType_Image = 3 //图片背景 - }; - - - explicit LunarCalendarYearItem(QWidget *parent = 0); - QMap<QString,QMap<QString,QString>> worktime; - -protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); - void paintEvent(QPaintEvent *); - void drawBg(QPainter *painter); - void drawBgCurrent(QPainter *painter, const QColor &color); - void drawBgHover(QPainter *painter, const QColor &color); - void drawYear(QPainter *painter); - -private: - bool hover; //鼠标是否悬停 - bool pressed; //鼠标是否按下 - - bool select; //是否选中 - bool showLunar; //显示农历 - QString bgImage; //背景图片 - SelectType selectType; //选中模式 - - QDate date; //当前日期 - QString lunar; //农历信息 - DayType dayType; //当前日类型 - - QColor borderColor; //边框颜色 - QColor weekColor; //周末颜色 - QColor superColor; //角标颜色 - QColor lunarColor; //农历节日颜色 - - QColor currentTextColor; //当前月文字颜色 - QColor otherTextColor; //其他月文字颜色 - QColor selectTextColor; //选中日期文字颜色 - QColor hoverTextColor; //悬停日期文字颜色 - - QColor currentLunarColor; //当前月农历文字颜色 - QColor otherLunarColor; //其他月农历文字颜色 - QColor selectLunarColor; //选中日期农历文字颜色 - QColor hoverLunarColor; //悬停日期农历文字颜色 - - QColor currentBgColor; //当前月背景颜色 - QColor otherBgColor; //其他月背景颜色 - QColor selectBgColor; //选中日期背景颜色 - QColor hoverBgColor; //悬停日期背景颜色 - - - -public: - bool getSelect() const; - bool getShowLunar() const; - QString getBgImage() const; - SelectType getSelectType() const; - - QDate getDate() const; - QString getLunar() const; - DayType getDayType() const; - - QColor getBorderColor() const; - QColor getWeekColor() const; - QColor getSuperColor() const; - QColor getLunarColor() const; - - QColor getCurrentTextColor() const; - QColor getOtherTextColor() const; - QColor getSelectTextColor() const; - QColor getHoverTextColor() const; - - QColor getCurrentLunarColor() const; - QColor getOtherLunarColor() const; - QColor getSelectLunarColor() const; - QColor getHoverLunarColor() const; - - QColor getCurrentBgColor() const; - QColor getOtherBgColor() const; - QColor getSelectBgColor() const; - QColor getHoverBgColor() const; - - QSize sizeHint() const; - QSize minimumSizeHint() const; - -public Q_SLOTS: - //设置是否选中 - void setSelect(bool select); - //设置是否显示农历信息 - void setShowLunar(bool showLunar); - //设置背景图片 - void setBgImage(const QString &bgImage); - //设置选中背景样式 - void setSelectType(const SelectType &selectType); - - //设置日期 - void setDate(const QDate &date); - //设置农历 - void setLunar(const QString &lunar); - //设置类型 - void setDayType(const DayType &dayType); - //设置日期/农历/类型 - void setDate(const QDate &date, const QString &lunar, const DayType &dayType); - - //设置边框颜色 - void setBorderColor(const QColor &borderColor); - //设置周末颜色 - void setWeekColor(const QColor &weekColor); - //设置角标颜色 - void setSuperColor(const QColor &superColor); - //设置农历节日颜色 - void setLunarColor(const QColor &lunarColor); - - //设置当前月文字颜色 - void setCurrentTextColor(const QColor ¤tTextColor); - //设置其他月文字颜色 - void setOtherTextColor(const QColor &otherTextColor); - //设置选中日期文字颜色 - void setSelectTextColor(const QColor &selectTextColor); - //设置悬停日期文字颜色 - void setHoverTextColor(const QColor &hoverTextColor); - - //设置当前月农历文字颜色 - void setCurrentLunarColor(const QColor ¤tLunarColor); - //设置其他月农历文字颜色 - void setOtherLunarColor(const QColor &otherLunarColor); - -Q_SIGNALS: - void clicked(const QDate &date, const LunarCalendarYearItem::DayType &dayType); - void yearMessage(const QDate &date, const LunarCalendarYearItem::DayType &dayType); -}; - -#endif // LUNARCALENDARITEM_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/main.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/main.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/main.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/main.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#pragma execution_character_set("utf-8") - -#include "frmlunarcalendarwidget.h" -#include <QApplication> -#include <QTextCodec> -#include <QTranslator> -#include <QDebug> -#include <QTimer> -#include <KWindowEffects> - -#include "xatom-helper.h" -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - a.setFont(QFont("Microsoft Yahei", 9)); - -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) -#if _MSC_VER - QTextCodec *codec = QTextCodec::codecForName("gbk"); -#else - QTextCodec *codec = QTextCodec::codecForName("utf-8"); -#endif - QTextCodec::setCodecForLocale(codec); - QTextCodec::setCodecForCStrings(codec); - QTextCodec::setCodecForTr(codec); -#else - QTextCodec *codec = QTextCodec::codecForName("utf-8"); - QTextCodec::setCodecForLocale(codec); -#endif - - frmLunarCalendarWidget w; - w.setWindowTitle("自定义农历控件"); - - - - KWindowEffects::enableBlurBehind(w.winId(),true); - - // 添加窗管协议 - MotifWmHints hints; - hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; - hints.functions = MWM_FUNC_ALL; - hints.decorations = MWM_DECOR_BORDER; - XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), hints); - - - QApplication app(argc, argv); - QString locale = QLocale::system().name(); - QTranslator translator; - if (locale == "zh_CN"){ - if (translator.load("ukui-calendar_zh_CN.qm", "/usr/share/ukui-panel/panel/resources/")) - app.installTranslator(&translator); - else - qDebug() << "Load translations file" << locale << "failed!"; - } - if (locale == "tr_TR"){ - if (translator.load("ukui-panel_tr.qm", "/usr/share/ukui-panel/panel/resources/")) - app.installTranslator(&translator); - else - qDebug() << "Load translations file" << locale << "failed!"; - } - if (locale == "bo_CN"){ - if (translator.load("ukui-panel_bo_CN.qm", "/usr/share/ukui-panel/panel/resources/")) - app.installTranslator(&translator); - else - qDebug() << "Load translations file" << locale << "failed!"; - } - - - return a.exec(); -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/main.qrc ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/main.qrc --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/main.qrc 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/main.qrc 1970-01-01 08:00:00.000000000 +0800 @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>image/bg_calendar.png</file> - <file>image/fontawesome-webfont.ttf</file> - </qresource> -</RCC> diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/picturetowhite.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/picturetowhite.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/picturetowhite.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/picturetowhite.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,72 +0,0 @@ -/* -* Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, see <http://www.gnu.org/licenses/>. -* -*/ -#include "picturetowhite.h" - -PictureToWhite::PictureToWhite(QObject *parent) : QObject(parent) -{ - initGsettingValue(); -} - -void PictureToWhite::initGsettingValue() -{ - const QByteArray id(ORG_UKUI_STYLE); - QStringList stylelist; - stylelist << STYLE_NAME_KEY_DARK << STYLE_NAME_KEY_LIGHT << STYLE_NAME_KEY_DEFAULT << STYLE_NAME_KEY_BLACK; - if (QGSettings::isSchemaInstalled(id)) { - m_pgsettings = new QGSettings(id); - if (stylelist.contains(m_pgsettings->get(STYLE_NAME).toString()) && m_pgsettings->get(STYLE_NAME).toString() == STYLE_NAME_KEY_LIGHT) - tray_icon_color = TRAY_ICON_COLOR_LOGHT; - else - tray_icon_color = TRAY_ICON_COLOR_DRAK; - } - connect(m_pgsettings, &QGSettings::changed, this, [=] (const QString &key) { - if (key==STYLE_NAME) { - if (stylelist.contains(m_pgsettings->get(STYLE_NAME).toString()) && m_pgsettings->get(STYLE_NAME).toString() == STYLE_NAME_KEY_LIGHT) - tray_icon_color = TRAY_ICON_COLOR_LOGHT; - else - tray_icon_color = TRAY_ICON_COLOR_DRAK; - } - }); -} - -QPixmap PictureToWhite::drawSymbolicColoredPixmap(const QPixmap &source) -{ - QColor gray(128,128,128); - QColor standard (31,32,34); - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) { - for (int y = 0; y < img.height(); y++) { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) { - if (qAbs(color.red()-gray.red()) < 20 && qAbs(color.green()-gray.green()) < 20 && qAbs(color.blue()-gray.blue()) < 20) { - color.setRed(tray_icon_color); - color.setGreen(tray_icon_color); - color.setBlue(tray_icon_color); - img.setPixelColor(x, y, color); - } else if (qAbs(color.red()-standard.red()) < 20 && qAbs(color.green()-standard.green()) < 20 && qAbs(color.blue()-standard.blue()) < 20) { - color.setRed(tray_icon_color); - color.setGreen(tray_icon_color); - color.setBlue(tray_icon_color); - img.setPixelColor(x, y, color); - } else - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/picturetowhite.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/picturetowhite.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/picturetowhite.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/picturetowhite.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,52 +0,0 @@ -/* -* Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, see <http://www.gnu.org/licenses/>. -* -*/ -#ifndef PICTURETOWHITE_H -#define PICTURETOWHITE_H - -#include <QObject> -#include <QGSettings> -#include <QString> -#include <QVariant> -#include <QPixmap> -#include <QDebug> - -#define ORG_UKUI_STYLE "org.ukui.style" -#define STYLE_NAME "styleName" -#define STYLE_NAME_KEY_DARK "ukui-dark" -#define STYLE_NAME_KEY_DEFAULT "ukui-default" -#define STYLE_NAME_KEY_BLACK "ukui-black" -#define STYLE_NAME_KEY_LIGHT "ukui-light" -#define STYLE_NAME_KEY_WHITE "ukui-white" -#define TRAY_ICON_COLOR_LOGHT 0 -#define TRAY_ICON_COLOR_DRAK 255 - -class PictureToWhite : public QObject -{ - Q_OBJECT -public: - explicit PictureToWhite(QObject *parent = nullptr); - void initGsettingValue(); - QPixmap drawSymbolicColoredPixmap(const QPixmap &source); - -public: - QGSettings *m_pgsettings; - int tray_icon_color; - -}; - -#endif // PICTURETOWHITE_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/statelabel.cpp ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/statelabel.cpp --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/statelabel.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/statelabel.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "statelabel.h" - -statelabel::statelabel() : QLabel() -{ - - -} - -//鼠标点击事件 -void statelabel::mousePressEvent(QMouseEvent *event) -{ - if (event->buttons() == Qt::LeftButton){ - Q_EMIT labelclick(); - - } - return; -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/statelabel.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/statelabel.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/statelabel.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/statelabel.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef STATELABEL_H -#define STATELABEL_H - -#include <QObject> -#include <QWidget> -#include <QLabel> -#include <QMouseEvent> -#include <QDebug> - - -class statelabel : public QLabel -{ - Q_OBJECT -public: - statelabel(); - -protected: - void mousePressEvent(QMouseEvent *event); -Q_SIGNALS : - void labelclick(); -}; - -#endif // STATELABEL_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h --- ukui-panel-3.14.0.1/ukui-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/lunarcalendarwidget/ui_frmlunarcalendarwidget.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -/******************************************************************************** -** Form generated from reading UI file 'frmlunarcalendarwidget.ui' -** -** Created by: Qt User Interface Compiler version 5.12.8 -** -** WARNING! All changes made in this file will be lost when recompiling UI file! -********************************************************************************/ - -#ifndef UI_FRMLUNARCALENDARWIDGET_H -#define UI_FRMLUNARCALENDARWIDGET_H - -#include <QtCore/QVariant> -#include <QtWidgets/QApplication> -#include <QtWidgets/QCheckBox> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QHBoxLayout> -#include <QtWidgets/QLabel> -#include <QtWidgets/QSpacerItem> -#include <QtWidgets/QVBoxLayout> -#include <QtWidgets/QWidget> -#include "lunarcalendarwidget.h" - -QT_BEGIN_NAMESPACE - -class Ui_frmLunarCalendarWidget -{ -public: - QVBoxLayout *verticalLayout; - LunarCalendarWidget *lunarCalendarWidget; - QWidget *widgetBottom; - QHBoxLayout *horizontalLayout; - // QLabel *labCalendarStyle; - // QComboBox *cboxCalendarStyle; - // QLabel *labSelectType; - // QComboBox *cboxSelectType; - // QLabel *labWeekNameFormat; - // QComboBox *cboxWeekNameFormat; - // QCheckBox *ckShowLunar; - QSpacerItem *horizontalSpacer; - - void setupUi(QWidget *frmLunarCalendarWidget) - { - if (frmLunarCalendarWidget->objectName().isEmpty()) - frmLunarCalendarWidget->setObjectName(QString::fromUtf8("frmLunarCalendarWidget")); - frmLunarCalendarWidget->resize(600, 500); - verticalLayout = new QVBoxLayout(frmLunarCalendarWidget); - verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); - lunarCalendarWidget = new LunarCalendarWidget(frmLunarCalendarWidget); - lunarCalendarWidget->setObjectName(QString::fromUtf8("lunarCalendarWidget")); - QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(lunarCalendarWidget->sizePolicy().hasHeightForWidth()); - lunarCalendarWidget->setSizePolicy(sizePolicy); - - verticalLayout->addWidget(lunarCalendarWidget); - - widgetBottom = new QWidget(frmLunarCalendarWidget); - widgetBottom->setObjectName(QString::fromUtf8("widgetBottom")); - horizontalLayout = new QHBoxLayout(widgetBottom); - horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); - horizontalLayout->setContentsMargins(0, 0, 0, 0); - // labCalendarStyle = new QLabel(widgetBottom); - // labCalendarStyle->setObjectName(QString::fromUtf8("labCalendarStyle")); - - // horizontalLayout->addWidget(labCalendarStyle); - - // cboxCalendarStyle = new QComboBox(widgetBottom); - // cboxCalendarStyle->addItem(QString()); - // cboxCalendarStyle->setObjectName(QString::fromUtf8("cboxCalendarStyle")); - // cboxCalendarStyle->setMinimumSize(QSize(90, 0)); - - // horizontalLayout->addWidget(cboxCalendarStyle); - -// labSelectType = new QLabel(widgetBottom); -// labSelectType->setObjectName(QString::fromUtf8("labSelectType")); - -// horizontalLayout->addWidget(labSelectType); - -// cboxSelectType = new QComboBox(widgetBottom); -// cboxSelectType->addItem(QString()); -// cboxSelectType->addItem(QString()); -// cboxSelectType->addItem(QString()); -// cboxSelectType->addItem(QString()); -// cboxSelectType->setObjectName(QString::fromUtf8("cboxSelectType")); -// cboxSelectType->setMinimumSize(QSize(90, 0)); - -// horizontalLayout->addWidget(cboxSelectType); - -// labWeekNameFormat = new QLabel(widgetBottom); -// labWeekNameFormat->setObjectName(QString::fromUtf8("labWeekNameFormat")); - -// horizontalLayout->addWidget(labWeekNameFormat); - -// cboxWeekNameFormat = new QComboBox(widgetBottom); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->addItem(QString()); -// cboxWeekNameFormat->setObjectName(QString::fromUtf8("cboxWeekNameFormat")); -// cboxWeekNameFormat->setMinimumSize(QSize(90, 0)); - -// horizontalLayout->addWidget(cboxWeekNameFormat); - -// ckShowLunar = new QCheckBox(widgetBottom); -// ckShowLunar->setObjectName(QString::fromUtf8("ckShowLunar")); -// ckShowLunar->setChecked(true); - -// horizontalLayout->addWidget(ckShowLunar); - - horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - horizontalLayout->addItem(horizontalSpacer); - - -// verticalLayout->addWidget(widgetBottom); - - - retranslateUi(frmLunarCalendarWidget); - - QMetaObject::connectSlotsByName(frmLunarCalendarWidget); - } // setupUi - - void retranslateUi(QWidget *frmLunarCalendarWidget) - { - frmLunarCalendarWidget->setWindowTitle(QApplication::translate("frmLunarCalendarWidget", "Form", nullptr)); - // labCalendarStyle->setText(QApplication::translate("frmLunarCalendarWidget", "\346\225\264\344\275\223\346\240\267\345\274\217", nullptr)); - // cboxCalendarStyle->setItemText(0, QApplication::translate("frmLunarCalendarWidget", "\347\272\242\350\211\262\351\243\216\346\240\274", nullptr)); - - // labSelectType->setText(QApplication::translate("frmLunarCalendarWidget", "\351\200\211\344\270\255\346\240\267\345\274\217", nullptr)); -// cboxSelectType->setItemText(0, QApplication::translate("frmLunarCalendarWidget", "\347\237\251\345\275\242\350\203\214\346\231\257", nullptr)); -// cboxSelectType->setItemText(1, QApplication::translate("frmLunarCalendarWidget", "\345\234\206\345\275\242\350\203\214\346\231\257", nullptr)); -// cboxSelectType->setItemText(2, QApplication::translate("frmLunarCalendarWidget", "\350\247\222\346\240\207\350\203\214\346\231\257", nullptr)); -// cboxSelectType->setItemText(3, QApplication::translate("frmLunarCalendarWidget", "\345\233\276\347\211\207\350\203\214\346\231\257", nullptr)); - - // labWeekNameFormat->setText(QApplication::translate("frmLunarCalendarWidget", "\346\230\237\346\234\237\346\240\274\345\274\217", nullptr)); -// cboxWeekNameFormat->setItemText(0, QApplication::translate("frmLunarCalendarWidget", "\347\237\255\345\220\215\347\247\260", nullptr)); -// cboxWeekNameFormat->setItemText(1, QApplication::translate("frmLunarCalendarWidget", "\346\231\256\351\200\232\345\220\215\347\247\260", nullptr)); -// cboxWeekNameFormat->setItemText(2, QApplication::translate("frmLunarCalendarWidget", "\351\225\277\345\220\215\347\247\260", nullptr)); -// cboxWeekNameFormat->setItemText(3, QApplication::translate("frmLunarCalendarWidget", "\350\213\261\346\226\207\345\220\215\347\247\260", nullptr)); - - // ckShowLunar->setText(QApplication::translate("frmLunarCalendarWidget", "\346\230\276\347\244\272\345\206\234\345\216\206", nullptr)); - } // retranslateUi - -}; - -namespace Ui { - class frmLunarCalendarWidget: public Ui_frmLunarCalendarWidget {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // UI_FRMLUNARCALENDARWIDGET_H diff -Nru ukui-panel-3.14.0.1/ukui-calendar/resources/ukui-calendar.desktop ukui-panel-4.0.0.0/ukui-calendar/resources/ukui-calendar.desktop --- ukui-panel-3.14.0.1/ukui-calendar/resources/ukui-calendar.desktop 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/resources/ukui-calendar.desktop 1970-01-01 08:00:00.000000000 +0800 @@ -1,5 +0,0 @@ -[Desktop Entry] -Name=ukui-calendar -Name[zh_CN]=calendar -Icon=ukui-calendar -Exec=ukui-calendar Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/ukui-calendar/translation/ukui-calendar_zh_CN.qm and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/ukui-calendar/translation/ukui-calendar_zh_CN.qm differ diff -Nru ukui-panel-3.14.0.1/ukui-calendar/translation/ukui-calendar_zh_CN.ts ukui-panel-4.0.0.0/ukui-calendar/translation/ukui-calendar_zh_CN.ts --- ukui-panel-3.14.0.1/ukui-calendar/translation/ukui-calendar_zh_CN.ts 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/translation/ukui-calendar_zh_CN.ts 1970-01-01 08:00:00.000000000 +0800 @@ -1,181 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.1" language="zh_CN"> -<context> - <name>LunarCalendarItem</name> - <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="660"/> - <source>消防宣传日</source> - <translation>Fire Publicity Day</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="663"/> - <source>志愿者服务日</source> - <translation>Volunteer Service Day</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="666"/> - <source>全国爱眼日</source> - <translation>National Eye Health Day</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendaritem.cpp" line="669"/> - <source>抗战纪念日</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>LunarCalendarWidget</name> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="342"/> - <source>Year</source> - <translation>年</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="350"/> - <source>Month</source> - <translation>月</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="361"/> - <source>Today</source> - <translation>今天</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="585"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="805"/> - <source>解析json文件错误!</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1260"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1274"/> - <source>Sunday</source> - <translation>周日</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1261"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1268"/> - <source>Monday</source> - <translation>周一</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1262"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1269"/> - <source>Tuesday</source> - <translation>周二</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1263"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1270"/> - <source>Wednesday</source> - <translation>周三</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1264"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1271"/> - <source>Thursday</source> - <translation>周四</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1265"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1272"/> - <source>Friday</source> - <translation>周五</translation> - </message> - <message> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1266"/> - <location filename="../lunarcalendarwidget/lunarcalendarwidget.cpp" line="1273"/> - <source>Saturday</source> - <translation>周六</translation> - </message> -</context> -<context> - <name>frmLunarCalendarWidget</name> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="14"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="126"/> - <location filename="../lunarcalendarwidget/ui_frmlunarcalendarwidget.h" line="126"/> - <source>Form</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="45"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="127"/> - <source>整体样式</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="59"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="128"/> - <source>红色风格</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="67"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="130"/> - <source>选中样式</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="81"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="131"/> - <source>矩形背景</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="86"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="132"/> - <source>圆形背景</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="91"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="133"/> - <source>角标背景</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="96"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="134"/> - <source>图片背景</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="104"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="136"/> - <source>星期格式</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="118"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="137"/> - <source>短名称</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="123"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="138"/> - <source>普通名称</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="128"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="139"/> - <source>长名称</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="133"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="140"/> - <source>英文名称</source> - <translation type="unfinished"></translation> - </message> - <message> - <location filename="../lunarcalendarwidget/frmlunarcalendarwidget.ui" line="141"/> - <location filename="../build/ukui-calendar_autogen/include/ui_frmlunarcalendarwidget.h" line="142"/> - <source>显示农历</source> - <translation type="unfinished"></translation> - </message> -</context> -</TS> diff -Nru ukui-panel-3.14.0.1/ukui-calendar/xatom-helper.cpp ukui-panel-4.0.0.0/ukui-calendar/xatom-helper.cpp --- ukui-panel-3.14.0.1/ukui-calendar/xatom-helper.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/xatom-helper.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,212 +0,0 @@ -/* - * KWin Style UKUI - * - * Copyright (C) 2020, KylinSoft Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * Authors: Yue Lan <lanyue@kylinos.cn> - * - */ - -#include "xatom-helper.h" - -#include <limits.h> -#include <QX11Info> -#include <X11/X.h> -#include <X11/Xatom.h> - -static XAtomHelper *global_instance = nullptr; - -XAtomHelper *XAtomHelper::getInstance() -{ - if (!global_instance) - global_instance = new XAtomHelper; - return global_instance; -} - -bool XAtomHelper::isFrameLessWindow(int winId) -{ - auto hints = getInstance()->getWindowMotifHint(winId); - if (hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) { - return true; - } - return false; -} - -bool XAtomHelper::isWindowDecorateBorderOnly(int winId) -{ - return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId)); -} - -bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint) -{ - bool isDeco = false; - if (hint.flags & MWM_HINTS_DECORATIONS && hint.flags != MWM_HINTS_DECORATIONS) { - if (hint.decorations == MWM_DECOR_BORDER) - isDeco = true; - } - return isDeco; -} - -bool XAtomHelper::isUKUICsdSupported() -{ - // fixme: - return false; -} - -bool XAtomHelper::isUKUIDecorationWindow(int winId) -{ - if (m_ukuiDecorationAtion == None) - return false; - - Atom type; - int format; - ulong nitems; - ulong bytes_after; - uchar *data; - - bool isUKUIDecoration = false; - - XGetWindowProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, - 0, LONG_MAX, false, - m_ukuiDecorationAtion, &type, - &format, &nitems, - &bytes_after, &data); - - if (type == m_ukuiDecorationAtion) { - if (nitems == 1) { - isUKUIDecoration = data[0]; - } - } - - return isUKUIDecoration; -} - -UnityCorners XAtomHelper::getWindowBorderRadius(int winId) -{ - UnityCorners corners; - - Atom type; - int format; - ulong nitems; - ulong bytes_after; - uchar *data; - - if (m_unityBorderRadiusAtom != None) { - XGetWindowProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, - 0, LONG_MAX, false, - XA_CARDINAL, &type, - &format, &nitems, - &bytes_after, &data); - - if (type == XA_CARDINAL) { - if (nitems == 4) { - corners.topLeft = static_cast<ulong>(data[0]); - corners.topRight = static_cast<ulong>(data[1*sizeof (ulong)]); - corners.bottomLeft = static_cast<ulong>(data[2*sizeof (ulong)]); - corners.bottomRight = static_cast<ulong>(data[3*sizeof (ulong)]); - } - XFree(data); - } - } - - return corners; -} - -void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) -{ - if (m_unityBorderRadiusAtom == None) - return; - - ulong corners[4] = {data.topLeft, data.topRight, data.bottomLeft, data.bottomRight}; - - XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, - 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); -} - -void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight) -{ - if (m_unityBorderRadiusAtom == None) - return; - - ulong corners[4] = {(ulong)topLeft, (ulong)topRight, (ulong)bottomLeft, (ulong)bottomRight}; - - XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, - 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); -} - -void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set) -{ - if (m_ukuiDecorationAtion == None) - return; - - XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &set, 1); -} - -void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) -{ - if (m_unityBorderRadiusAtom == None) - return; - - XChangeProperty(QX11Info::display(), winId, m_motifWMHintsAtom, m_motifWMHintsAtom, - 32, XCB_PROP_MODE_REPLACE, (const unsigned char *)&hints, sizeof (MotifWmHints)/ sizeof (ulong)); -} - -MotifWmHints XAtomHelper::getWindowMotifHint(int winId) -{ - MotifWmHints hints; - - if (m_unityBorderRadiusAtom == None) - return hints; - - uchar *data; - Atom type; - int format; - ulong nitems; - ulong bytes_after; - - XGetWindowProperty(QX11Info::display(), winId, m_motifWMHintsAtom, - 0, sizeof (MotifWmHints)/sizeof (long), false, AnyPropertyType, &type, - &format, &nitems, &bytes_after, &data); - - if (type == None) { - return hints; - } else { - hints = *(MotifWmHints *)data; - XFree(data); - } - return hints; -} - -XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) -{ - if (!QX11Info::isPlatformX11()) - return; - - m_motifWMHintsAtom = XInternAtom(QX11Info::display(), "_MOTIF_WM_HINTS", true); - m_unityBorderRadiusAtom = XInternAtom(QX11Info::display(), "_UNITY_GTK_BORDER_RADIUS", false); - m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false); -} - -Atom XAtomHelper::registerUKUICsdNetWmSupportAtom() -{ - // fixme: - return None; -} - -void XAtomHelper::unregisterUKUICsdNetWmSupportAtom() -{ - // fixme: -} diff -Nru ukui-panel-3.14.0.1/ukui-calendar/xatom-helper.h ukui-panel-4.0.0.0/ukui-calendar/xatom-helper.h --- ukui-panel-3.14.0.1/ukui-calendar/xatom-helper.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-calendar/xatom-helper.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,109 +0,0 @@ -/* - * KWin Style UKUI - * - * Copyright (C) 2020, KylinSoft Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * Authors: Yue Lan <lanyue@kylinos.cn> - * - */ - -#ifndef XATOMHELPER_H -#define XATOMHELPER_H - -#include <QObject> -#include <X11/Xlib.h> - -struct UnityCorners { - ulong topLeft = 0; - ulong topRight = 0; - ulong bottomLeft = 0; - ulong bottomRight = 0; -}; - -typedef struct { - ulong flags = 0; - ulong functions = 0; - ulong decorations = 0; - long input_mode = 0; - ulong status = 0; -} MotifWmHints, MwmHints; - -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) -#define MWM_HINTS_INPUT_MODE (1L << 2) -#define MWM_HINTS_STATUS (1L << 3) - -#define MWM_FUNC_ALL (1L << 0) -#define MWM_FUNC_RESIZE (1L << 1) -#define MWM_FUNC_MOVE (1L << 2) -#define MWM_FUNC_MINIMIZE (1L << 3) -#define MWM_FUNC_MAXIMIZE (1L << 4) -#define MWM_FUNC_CLOSE (1L << 5) - -#define MWM_DECOR_ALL (1L << 0) -#define MWM_DECOR_BORDER (1L << 1) -#define MWM_DECOR_RESIZEH (1L << 2) -#define MWM_DECOR_TITLE (1L << 3) -#define MWM_DECOR_MENU (1L << 4) -#define MWM_DECOR_MINIMIZE (1L << 5) -#define MWM_DECOR_MAXIMIZE (1L << 6) - -#define MWM_INPUT_MODELESS 0 -#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 -#define MWM_INPUT_SYSTEM_MODAL 2 -#define MWM_INPUT_FULL_APPLICATION_MODAL 3 -#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL - -#define MWM_TEAROFF_WINDOW (1L<<0) - -namespace UKUI { -class Decoration; -} - -class XAtomHelper : public QObject -{ - friend class UKUI::Decoration; - Q_OBJECT -public: - static XAtomHelper *getInstance(); - - static bool isFrameLessWindow(int winId); - - bool isWindowDecorateBorderOnly(int winId); - bool isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint); - bool isUKUICsdSupported(); - bool isUKUIDecorationWindow(int winId); - - UnityCorners getWindowBorderRadius(int winId); - void setWindowBorderRadius(int winId, const UnityCorners &data); - void setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight); - void setUKUIDecoraiontHint(int winId, bool set = true); - - void setWindowMotifHint(int winId, const MotifWmHints &hints); - MotifWmHints getWindowMotifHint(int winId); - -private: - explicit XAtomHelper(QObject *parent = nullptr); - - Atom registerUKUICsdNetWmSupportAtom(); - void unregisterUKUICsdNetWmSupportAtom(); - - Atom m_motifWMHintsAtom = None; - Atom m_unityBorderRadiusAtom = None; - Atom m_ukuiDecorationAtion = None; -}; - -#endif // XATOMHELPER_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/CMakeLists.txt ukui-panel-4.0.0.0/ukui-flash-disk/CMakeLists.txt --- ukui-panel-3.14.0.1/ukui-flash-disk/CMakeLists.txt 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800 @@ -1,123 +0,0 @@ -cmake_minimum_required(VERSION 3.1.0) - -project(ukui-flash-disk) - -#判断编译器类型,如果是gcc编译器,则在编译选项中加入c++11支持 -if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") - message(STATUS "optional:-std=c++11") -endif(CMAKE_COMPILER_IS_GNUCXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(CMAKE_VERSION VERSION_LESS "3.7.0") - set(CMAKE_INCLUDE_CURRENT_DIR ON) -endif() - -find_package(Qt5 COMPONENTS Widgets Network REQUIRED) -find_package(Qt5DBus REQUIRED) -find_package(PkgConfig REQUIRED) -find_package(KF5WindowSystem REQUIRED) - -pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0 udisks2) -pkg_check_modules(QGS REQUIRED gsettings-qt) - - -include_directories(${GLIB2_INCLUDE_DIRS}) -include_directories(${QGS_INCLUDE_DIRS}) -add_executable(ukui-flash-disk - ukui-flash-disk.qrc - disk-resources/ukui-flash-disk_zh_CN.ts - disk-resources/ukui-flash-disk_tr.ts - main.cpp - mainwindow.cpp - qclickwidget.cpp - qclickwidget.h - UnionVariable.cpp - UnionVariable.h - ejectInterface.cpp - ejectInterface.h - clickLabel.h - device-operation.h - device-operation.cpp - clickLabel.cpp - device-manager.h - device-manager.cpp - repair-dialog-box.h - repair-dialog-box.cpp - MainController.h - MainController.cpp - MacroFile.h - interactivedialog.cpp - interactivedialog.h - gpartedinterface.cpp - gpartedinterface.h - mainwindow.ui - mainwindow.h - fdapplication.cpp - fdapplication.h - fdframe.cpp - fdframe.h - flashdiskdata.cpp - flashdiskdata.h - fdclickwidget.cpp - fdclickwidget.h - QtSingleApplication/qtsingleapplication.h - QtSingleApplication/qtsingleapplication.cpp - QtSingleApplication/qtlocalpeer.h - QtSingleApplication/qtlocalpeer.cpp - datacdrom.h - datacdrom.cpp -) - -add_executable(test-repair-dialog - device-manager.h - device-manager.cpp - repair-dialog-box.h - repair-dialog-box.cpp - device-operation.h - device-operation.cpp - test-repair-dialog.cpp -) -target_link_libraries(test-repair-dialog Qt5::Widgets Qt5::DBus ${GLIB2_LIBRARIES} ${QGS_LIBRARIES} KF5::WindowSystem) - -add_definitions(-DQT_NO_KEYWORDS) -add_definitions(-DQT_MESSAGELOGCONTEXT) - -target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::DBus Qt5::Network ${GLIB2_LIBRARIES} ${QGS_LIBRARIES} KF5::WindowSystem -lukui-log4qt) - -install(TARGETS ukui-flash-disk DESTINATION bin) - -#install(FILES -# disk-resources/org.ukui.ukui-flash-disks-pkexec.policy -# DESTINATION "/usr/share/polkit-1/actions/" -# COMPONENT Runtime -#) - -#install(FILES -# disk-resources/ukui-flash-disks-pkexec.sh -# DESTINATION "/usr/bin/" -# COMPONENT Runtime -# PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE -#) - -install(FILES - disk-resources/ukui-flash-disk.desktop - DESTINATION "/etc/xdg/autostart/" - COMPONENT Runtime -) - -install(FILES - ukui-flash-disk.qrc disk-resources/ukui-flash-disk_zh_CN.qm disk-resources/ukui-flash-disk_tr.qm - DESTINATION "/usr/share/ukui/ukui-panel/" - COMPONENT Runtime -) - -install(FILES - disk-resources/org.ukui.flash-disk.autoload.gschema.xml - DESTINATION "/usr/share/glib-2.0/schemas" - COMPONENT Runtime -) diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/MacroFile.h ukui-panel-4.0.0.0/ukui-flash-disk/MacroFile.h --- ukui-panel-3.14.0.1/ukui-flash-disk/MacroFile.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/MacroFile.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef _MACROFILE_H_ -#define _MACROFILE_H_ -typedef enum {downPosition = 0,upPosition,leftPosition,rightPosition}Suit; - -#define SERVICE_NAME_SIZE 64 -#define DistanceToPanel 2 -#define SmallPanelSize 46 -#define UKUI_FLASH_DISK_PATH "/" -#define UKUI_FLASH_DISK_SERVICE "com.ukuiflashdisk.hotel" -#define UKUI_FLASH_DISK_INTERFACE "com.flshdisk.hotel" - -#define NORMALDEVICE 0 -#define DATADEVICE 1 -#define OCCUPYDEVICE 2 -#define GPARTEDINTERFACE 3 -#define DISTANCEPADDING 6 -#define DISTANCEMEND 2 - -#define FLASHDISKITEM_TITLE_HEIGHT 45 -#define FLASHDISKITEM_CONTENT_HEIGHT 45 - -#define NEWINFO_DELAYSHOW_TIME 1500 - -/** - * QT主题 - */ -#define THEME_QT_SCHEMA "org.ukui.style" -//opacity setting -#define THEME_QT_TRANS "org.ukui.control-center.personalise" -#define FONT_SIZE "system-font-size" -#define MODE_QT_KEY "style-name" -#define AUTOLOAD "org.ukui.flash-disk.autoload" -#define IFAUTOLOAD "ifautoload" - -#define IFDISTINCT_DEVICON 1 -#endif //_MACROFILE_H_ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/MainController.cpp ukui-panel-4.0.0.0/ukui-flash-disk/MainController.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/MainController.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/MainController.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include "MainController.h" -#include <KWindowEffects> -//#include "stdlib.h" - -MainController* MainController::mSelf = 0; //static variable -MainController* MainController::self() //static function //complete the singleton object -{ - if (!mSelf) - { - mSelf = new MainController; - } - return mSelf; -} - -MainController::MainController() -{ -} - -MainController::~MainController() -{ -} - -int MainController::init() //init select -{ - m_DiskWindow = new MainWindow; //main process singleton object - connect(this, &MainController::notifyWnd, m_DiskWindow, &MainWindow::onNotifyWnd); - return 0; -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/MainController.h ukui-panel-4.0.0.0/ukui-flash-disk/MainController.h --- ukui-panel-3.14.0.1/ukui-flash-disk/MainController.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/MainController.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef _MAINCONTROL_H_ -#define _MAINCONTROL_H_ - -#include <QObject> -#include <QtDBus/QDBusConnection> -#include <QtDBus/QDBusAbstractAdaptor> -#include <QtDBus/QDBusInterface> -#include <QtDBus/QDBusReply> -#include <QtDBus/QDBusConnectionInterface> - -#include "mainwindow.h" -#include "MacroFile.h" - -class MainController : public QObject -{ - Q_OBJECT -public: - static MainController* self(); - virtual ~MainController(); - int init(); -private: - explicit MainController(); - -public: -Q_SIGNALS: - void notifyWnd(QObject* obj, QEvent *event); - -private: - static MainController *mSelf; - MainWindow *m_DiskWindow; -}; - -#endif //_MAINCONTROL_H_ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/QtLockedFile ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/QtLockedFile --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/QtLockedFile 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/QtLockedFile 1970-01-01 08:00:00.000000000 +0800 @@ -1 +0,0 @@ -#include "qtlockedfile.h" diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/QtSingleApplication ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/QtSingleApplication --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/QtSingleApplication 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/QtSingleApplication 1970-01-01 08:00:00.000000000 +0800 @@ -1 +0,0 @@ -#include "qtsingleapplication.h" diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlocalpeer.cpp ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlocalpeer.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlocalpeer.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlocalpeer.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,213 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qtlocalpeer.h" -#include <QCoreApplication> -#include <QDataStream> -#include <QTime> - -#if defined(Q_OS_WIN) -#include <QLibrary> -#include <qt_windows.h> -typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); -static PProcessIdToSessionId pProcessIdToSessionId = 0; -#endif -#if defined(Q_OS_UNIX) -#include <sys/types.h> -#include <time.h> -#include <unistd.h> -#endif - -namespace QtLP_Private { -#include "qtlockedfile.cpp" -#if defined(Q_OS_WIN) -#include "qtlockedfile_win.cpp" -#else -#include "qtlockedfile_unix.cpp" -#endif -} - -const char* QtLocalPeer::ack = "ack"; - -QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) - : QObject(parent), id(appId) -{ - QString prefix = id; - if (id.isEmpty()) { - id = QCoreApplication::applicationFilePath(); -#if defined(Q_OS_WIN) - id = id.toLower(); -#endif - prefix = id.section(QLatin1Char('/'), -1); - } - prefix.remove(QRegExp("[^a-zA-Z]")); - prefix.truncate(6); - - QByteArray idc = id.toUtf8(); - quint16 idNum = qChecksum(idc.constData(), idc.size()); - socketName = QLatin1String("qtsingleapp-") + prefix - + QLatin1Char('-') + QString::number(idNum, 16); - -#if defined(Q_OS_WIN) - if (!pProcessIdToSessionId) { - QLibrary lib("kernel32"); - pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); - } - if (pProcessIdToSessionId) { - DWORD sessionId = 0; - pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); - socketName += QLatin1Char('-') + QString::number(sessionId, 16); - } -#else - socketName += QLatin1Char('-') + QString::number(::getuid(), 16); -#endif - - server = new QLocalServer(this); - QString lockName = QDir(QDir::tempPath()).absolutePath() - + QLatin1Char('/') + socketName - + QLatin1String("-lockfile"); - lockFile.setFileName(lockName); - lockFile.open(QIODevice::ReadWrite); -} - - - -bool QtLocalPeer::isClient() -{ - if (lockFile.isLocked()) - return false; - - if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) - return true; - - bool res = server->listen(socketName); -#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) - // ### Workaround - if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { - QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); - res = server->listen(socketName); - } -#endif - if (!res) - qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); - QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); - return false; -} - - -bool QtLocalPeer::sendMessage(const QString &message, int timeout) -{ - if (!isClient()) - return false; - - QLocalSocket socket; - bool connOk = false; - for(int i = 0; i < 2; i++) { - // Try twice, in case the other instance is just starting up - socket.connectToServer(socketName); - connOk = socket.waitForConnected(timeout/2); - if (connOk || i) - break; - int ms = 250; -#if defined(Q_OS_WIN) - Sleep(DWORD(ms)); -#else - struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; - nanosleep(&ts, NULL); -#endif - } - if (!connOk) - return false; - - QByteArray uMsg(message.toUtf8()); - QDataStream ds(&socket); - ds.writeBytes(uMsg.constData(), uMsg.size()); - bool res = socket.waitForBytesWritten(timeout); - if (res) { - res &= socket.waitForReadyRead(timeout); // wait for ack - if (res) - res &= (socket.read(qstrlen(ack)) == ack); - } - return res; -} - - -void QtLocalPeer::receiveConnection() -{ - QLocalSocket* socket = server->nextPendingConnection(); - if (!socket) - return; - - while (true) { - if (socket->state() == QLocalSocket::UnconnectedState) { - qWarning("QtLocalPeer: Peer disconnected"); - delete socket; - return; - } - if (socket->bytesAvailable() >= qint64(sizeof(quint32))) - break; - socket->waitForReadyRead(); - } - - QDataStream ds(socket); - QByteArray uMsg; - quint32 remaining; - ds >> remaining; - uMsg.resize(remaining); - int got = 0; - char* uMsgBuf = uMsg.data(); - do { - got = ds.readRawData(uMsgBuf, remaining); - remaining -= got; - uMsgBuf += got; - } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); - if (got < 0) { - qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData()); - delete socket; - return; - } - QString message(QString::fromUtf8(uMsg)); - socket->write(ack, qstrlen(ack)); - socket->waitForBytesWritten(1000); - socket->waitForDisconnected(1000); // make sure client reads ack - delete socket; - Q_EMIT messageReceived(message); //### (might take a long time to return) -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlocalpeer.h ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlocalpeer.h --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlocalpeer.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlocalpeer.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTLOCALPEER_H -#define QTLOCALPEER_H - -#include <QLocalServer> -#include <QLocalSocket> -#include <QDir> - -#include "qtlockedfile.h" - -class QtLocalPeer : public QObject -{ - Q_OBJECT - -public: - QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); - bool isClient(); - bool sendMessage(const QString &message, int timeout); - QString applicationId() const - { return id; } - -Q_SIGNALS: - void messageReceived(const QString &message); - -protected Q_SLOTS: - void receiveConnection(); - -protected: - QString id; - QString socketName; - QLocalServer* server; - QtLP_Private::QtLockedFile lockFile; - -private: - static const char* ack; -}; - -#endif // QTLOCALPEER_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile.cpp ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,193 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtlockedfile.h" - -/*! - \class QtLockedFile - - \brief The QtLockedFile class extends QFile with advisory locking - functions. - - A file may be locked in read or write mode. Multiple instances of - \e QtLockedFile, created in multiple processes running on the same - machine, may have a file locked in read mode. Exactly one instance - may have it locked in write mode. A read and a write lock cannot - exist simultaneously on the same file. - - The file locks are advisory. This means that nothing prevents - another process from manipulating a locked file using QFile or - file system functions offered by the OS. Serialization is only - guaranteed if all processes that access the file use - QLockedFile. Also, while holding a lock on a file, a process - must not open the same file again (through any API), or locks - can be unexpectedly lost. - - The lock provided by an instance of \e QtLockedFile is released - whenever the program terminates. This is true even when the - program crashes and no destructors are called. -*/ - -/*! \enum QtLockedFile::LockMode - - This enum describes the available lock modes. - - \value ReadLock A read lock. - \value WriteLock A write lock. - \value NoLock Neither a read lock nor a write lock. -*/ - -/*! - Constructs an unlocked \e QtLockedFile object. This constructor - behaves in the same way as \e QFile::QFile(). - - \sa QFile::QFile() -*/ -QtLockedFile::QtLockedFile() - : QFile() -{ -#ifdef Q_OS_WIN - wmutex = 0; - rmutex = 0; -#endif - m_lock_mode = NoLock; -} - -/*! - Constructs an unlocked QtLockedFile object with file \a name. This - constructor behaves in the same way as \e QFile::QFile(const - QString&). - - \sa QFile::QFile() -*/ -QtLockedFile::QtLockedFile(const QString &name) - : QFile(name) -{ -#ifdef Q_OS_WIN - wmutex = 0; - rmutex = 0; -#endif - m_lock_mode = NoLock; -} - -/*! - Opens the file in OpenMode \a mode. - - This is identical to QFile::open(), with the one exception that the - Truncate mode flag is disallowed. Truncation would conflict with the - advisory file locking, since the file would be modified before the - write lock is obtained. If truncation is required, use resize(0) - after obtaining the write lock. - - Returns true if successful; otherwise false. - - \sa QFile::open(), QFile::resize() -*/ -bool QtLockedFile::open(OpenMode mode) -{ - if (mode & QIODevice::Truncate) { - qWarning("QtLockedFile::open(): Truncate mode not allowed."); - return false; - } - return QFile::open(mode); -} - -/*! - Returns \e true if this object has a in read or write lock; - otherwise returns \e false. - - \sa lockMode() -*/ -bool QtLockedFile::isLocked() const -{ - return m_lock_mode != NoLock; -} - -/*! - Returns the type of lock currently held by this object, or \e - QtLockedFile::NoLock. - - \sa isLocked() -*/ -QtLockedFile::LockMode QtLockedFile::lockMode() const -{ - return m_lock_mode; -} - -/*! - \fn bool QtLockedFile::lock(LockMode mode, bool block = true) - - Obtains a lock of type \a mode. The file must be opened before it - can be locked. - - If \a block is true, this function will block until the lock is - aquired. If \a block is false, this function returns \e false - immediately if the lock cannot be aquired. - - If this object already has a lock of type \a mode, this function - returns \e true immediately. If this object has a lock of a - different type than \a mode, the lock is first released and then a - new lock is obtained. - - This function returns \e true if, after it executes, the file is - locked by this object, and \e false otherwise. - - \sa unlock(), isLocked(), lockMode() -*/ - -/*! - \fn bool QtLockedFile::unlock() - - Releases a lock. - - If the object has no lock, this function returns immediately. - - This function returns \e true if, after it executes, the file is - not locked by this object, and \e false otherwise. - - \sa lock(), isLocked(), lockMode() -*/ - -/*! - \fn QtLockedFile::~QtLockedFile() - - Destroys the \e QtLockedFile object. If any locks were held, they - are released. -*/ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile.h ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile.h --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTLOCKEDFILE_H -#define QTLOCKEDFILE_H - -#include <QFile> -#ifdef Q_OS_WIN -#include <QVector> -#endif - -#if defined(Q_OS_WIN) -# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) -# define QT_QTLOCKEDFILE_EXPORT -# elif defined(QT_QTLOCKEDFILE_IMPORT) -# if defined(QT_QTLOCKEDFILE_EXPORT) -# undef QT_QTLOCKEDFILE_EXPORT -# endif -# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) -# elif defined(QT_QTLOCKEDFILE_EXPORT) -# undef QT_QTLOCKEDFILE_EXPORT -# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) -# endif -#else -# define QT_QTLOCKEDFILE_EXPORT -#endif - -namespace QtLP_Private { - -class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile -{ -public: - enum LockMode { NoLock = 0, ReadLock, WriteLock }; - - QtLockedFile(); - QtLockedFile(const QString &name); - ~QtLockedFile(); - - bool open(OpenMode mode); - - bool lock(LockMode mode, bool block = true); - bool unlock(); - bool isLocked() const; - LockMode lockMode() const; - -private: -#ifdef Q_OS_WIN - Qt::HANDLE wmutex; - Qt::HANDLE rmutex; - QVector<Qt::HANDLE> rmutexes; - QString mutexname; - - Qt::HANDLE getMutexHandle(int idx, bool doCreate); - bool waitMutex(Qt::HANDLE mutex, bool doBlock); - -#endif - LockMode m_lock_mode; -}; -} -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile_unix.cpp ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile_unix.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile_unix.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile_unix.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> - -#include "qtlockedfile.h" - -bool QtLockedFile::lock(LockMode mode, bool block) -{ - if (!isOpen()) { - qWarning("QtLockedFile::lock(): file is not opened"); - return false; - } - - if (mode == NoLock) - return unlock(); - - if (mode == m_lock_mode) - return true; - - if (m_lock_mode != NoLock) - unlock(); - - struct flock fl; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; - int cmd = block ? F_SETLKW : F_SETLK; - int ret = fcntl(handle(), cmd, &fl); - - if (ret == -1) { - if (errno != EINTR && errno != EAGAIN) - qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); - return false; - } - - - m_lock_mode = mode; - return true; -} - - -bool QtLockedFile::unlock() -{ - if (!isOpen()) { - qWarning("QtLockedFile::unlock(): file is not opened"); - return false; - } - - if (!isLocked()) - return true; - - struct flock fl; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - fl.l_type = F_UNLCK; - int ret = fcntl(handle(), F_SETLKW, &fl); - - if (ret == -1) { - qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); - return false; - } - - m_lock_mode = NoLock; - return true; -} - -QtLockedFile::~QtLockedFile() -{ - if (isOpen()) - unlock(); -} - diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile_win.cpp ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile_win.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtlockedfile_win.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtlockedfile_win.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtlockedfile.h" -#include <qt_windows.h> -#include <QFileInfo> - -#define MUTEX_PREFIX "QtLockedFile mutex " -// Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS -#define MAX_READERS MAXIMUM_WAIT_OBJECTS - -#if QT_VERSION >= 0x050000 -#define QT_WA(unicode, ansi) unicode -#endif - -Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) -{ - if (mutexname.isEmpty()) { - QFileInfo fi(*this); - mutexname = QString::fromLatin1(MUTEX_PREFIX) - + fi.absoluteFilePath().toLower(); - } - QString mname(mutexname); - if (idx >= 0) - mname += QString::number(idx); - - Qt::HANDLE mutex; - if (doCreate) { - QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, - { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); - if (!mutex) { - qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); - return 0; - } - } - else { - QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, - { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); - if (!mutex) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) - qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); - return 0; - } - } - return mutex; -} - -bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock) -{ - Q_ASSERT(mutex); - DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0); - switch (res) { - case WAIT_OBJECT_0: - case WAIT_ABANDONED: - return true; - break; - case WAIT_TIMEOUT: - break; - default: - qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed"); - } - return false; -} - - - -bool QtLockedFile::lock(LockMode mode, bool block) -{ - if (!isOpen()) { - qWarning("QtLockedFile::lock(): file is not opened"); - return false; - } - - if (mode == NoLock) - return unlock(); - - if (mode == m_lock_mode) - return true; - - if (m_lock_mode != NoLock) - unlock(); - - if (!wmutex && !(wmutex = getMutexHandle(-1, true))) - return false; - - if (!waitMutex(wmutex, block)) - return false; - - if (mode == ReadLock) { - int idx = 0; - for (; idx < MAX_READERS; idx++) { - rmutex = getMutexHandle(idx, false); - if (!rmutex || waitMutex(rmutex, false)) - break; - CloseHandle(rmutex); - } - bool ok = true; - if (idx >= MAX_READERS) { - qWarning("QtLockedFile::lock(): too many readers"); - rmutex = 0; - ok = false; - } - else if (!rmutex) { - rmutex = getMutexHandle(idx, true); - if (!rmutex || !waitMutex(rmutex, false)) - ok = false; - } - if (!ok && rmutex) { - CloseHandle(rmutex); - rmutex = 0; - } - ReleaseMutex(wmutex); - if (!ok) - return false; - } - else { - Q_ASSERT(rmutexes.isEmpty()); - for (int i = 0; i < MAX_READERS; i++) { - Qt::HANDLE mutex = getMutexHandle(i, false); - if (mutex) - rmutexes.append(mutex); - } - if (rmutexes.size()) { - DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), - TRUE, block ? INFINITE : 0); - if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { - if (res != WAIT_TIMEOUT) - qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); - m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky - unlock(); - return false; - } - } - } - - m_lock_mode = mode; - return true; -} - -bool QtLockedFile::unlock() -{ - if (!isOpen()) { - qWarning("QtLockedFile::unlock(): file is not opened"); - return false; - } - - if (!isLocked()) - return true; - - if (m_lock_mode == ReadLock) { - ReleaseMutex(rmutex); - CloseHandle(rmutex); - rmutex = 0; - } - else { - foreach(Qt::HANDLE mutex, rmutexes) { - ReleaseMutex(mutex); - CloseHandle(mutex); - } - rmutexes.clear(); - ReleaseMutex(wmutex); - } - - m_lock_mode = QtLockedFile::NoLock; - return true; -} - -QtLockedFile::~QtLockedFile() -{ - if (isOpen()) - unlock(); - if (wmutex) - CloseHandle(wmutex); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsingleapplication.cpp ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsingleapplication.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsingleapplication.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsingleapplication.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,348 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qtsingleapplication.h" -#include "qtlocalpeer.h" -#include <QWidget> - - -/*! - \class QtSingleApplication qtsingleapplication.h - \brief The QtSingleApplication class provides an API to detect and - communicate with running instances of an application. - - This class allows you to create applications where only one - instance should be running at a time. I.e., if the user tries to - launch another instance, the already running instance will be - activated instead. Another usecase is a client-server system, - where the first started instance will assume the role of server, - and the later instances will act as clients of that server. - - By default, the full path of the executable file is used to - determine whether two processes are instances of the same - application. You can also provide an explicit identifier string - that will be compared instead. - - The application should create the QtSingleApplication object early - in the startup phase, and call isRunning() to find out if another - instance of this application is already running. If isRunning() - returns false, it means that no other instance is running, and - this instance has assumed the role as the running instance. In - this case, the application should continue with the initialization - of the application user interface before entering the event loop - with exec(), as normal. - - The messageReceived() signal will be emitted when the running - application receives messages from another instance of the same - application. When a message is received it might be helpful to the - user to raise the application so that it becomes visible. To - facilitate this, QtSingleApplication provides the - setActivationWindow() function and the activateWindow() slot. - - If isRunning() returns true, another instance is already - running. It may be alerted to the fact that another instance has - started by using the sendMessage() function. Also data such as - startup parameters (e.g. the name of the file the user wanted this - new instance to open) can be passed to the running instance with - this function. Then, the application should terminate (or enter - client mode). - - If isRunning() returns true, but sendMessage() fails, that is an - indication that the running instance is frozen. - - Here's an example that shows how to convert an existing - application to use QtSingleApplication. It is very simple and does - not make use of all QtSingleApplication's functionality (see the - examples for that). - - \code - // Original - int main(int argc, char **argv) - { - QApplication app(argc, argv); - - MyMainWidget mmw; - mmw.show(); - return app.exec(); - } - - // Single instance - int main(int argc, char **argv) - { - QtSingleApplication app(argc, argv); - - if (app.isRunning()) - return !app.sendMessage(someDataString); - - MyMainWidget mmw; - app.setActivationWindow(&mmw); - mmw.show(); - return app.exec(); - } - \endcode - - Once this QtSingleApplication instance is destroyed (normally when - the process exits or crashes), when the user next attempts to run the - application this instance will not, of course, be encountered. The - next instance to call isRunning() or sendMessage() will assume the - role as the new running instance. - - For console (non-GUI) applications, QtSingleCoreApplication may be - used instead of this class, to avoid the dependency on the QtGui - library. - - \sa QtSingleCoreApplication -*/ - - -void QtSingleApplication::sysInit(const QString &appId) -{ - actWin = 0; - peer = new QtLocalPeer(this, appId); - connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); -} - - -/*! - Creates a QtSingleApplication object. The application identifier - will be QCoreApplication::applicationFilePath(). \a argc, \a - argv, and \a GUIenabled are passed on to the QAppliation constructor. - - If you are creating a console application (i.e. setting \a - GUIenabled to false), you may consider using - QtSingleCoreApplication instead. -*/ - -QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) - : QApplication(argc, argv, GUIenabled) -{ - sysInit(); -} - - -/*! - Creates a QtSingleApplication object with the application - identifier \a appId. \a argc and \a argv are passed on to the - QAppliation constructor. -*/ - -QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) - : QApplication(argc, argv) -{ - sysInit(appId); -} - -#if QT_VERSION < 0x050000 - -/*! - Creates a QtSingleApplication object. The application identifier - will be QCoreApplication::applicationFilePath(). \a argc, \a - argv, and \a type are passed on to the QAppliation constructor. -*/ -QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) - : QApplication(argc, argv, type) -{ - sysInit(); -} - - -# if defined(Q_WS_X11) -/*! - Special constructor for X11, ref. the documentation of - QApplication's corresponding constructor. The application identifier - will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, - and \a cmap are passed on to the QApplication constructor. -*/ -QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) - : QApplication(dpy, visual, cmap) -{ - sysInit(); -} - -/*! - Special constructor for X11, ref. the documentation of - QApplication's corresponding constructor. The application identifier - will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a - argv, \a visual, and \a cmap are passed on to the QApplication - constructor. -*/ -QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) - : QApplication(dpy, argc, argv, visual, cmap) -{ - sysInit(); -} - -/*! - Special constructor for X11, ref. the documentation of - QApplication's corresponding constructor. The application identifier - will be \a appId. \a dpy, \a argc, \a - argv, \a visual, and \a cmap are passed on to the QApplication - constructor. -*/ -QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) - : QApplication(dpy, argc, argv, visual, cmap) -{ - sysInit(appId); -} -# endif // Q_WS_X11 -#endif // QT_VERSION < 0x050000 - - -/*! - Returns true if another instance of this application is running; - otherwise false. - - This function does not find instances of this application that are - being run by a different user (on Windows: that are running in - another session). - - \sa sendMessage() -*/ - -bool QtSingleApplication::isRunning() -{ - return peer->isClient(); -} - - -/*! - Tries to send the text \a message to the currently running - instance. The QtSingleApplication object in the running instance - will emit the messageReceived() signal when it receives the - message. - - This function returns true if the message has been sent to, and - processed by, the current instance. If there is no instance - currently running, or if the running instance fails to process the - message within \a timeout milliseconds, this function return false. - - \sa isRunning(), messageReceived() -*/ -bool QtSingleApplication::sendMessage(const QString &message, int timeout) -{ - return peer->sendMessage(message, timeout); -} - - -/*! - Returns the application identifier. Two processes with the same - identifier will be regarded as instances of the same application. -*/ -QString QtSingleApplication::id() const -{ - return peer->applicationId(); -} - - -/*! - Sets the activation window of this application to \a aw. The - activation window is the widget that will be activated by - activateWindow(). This is typically the application's main window. - - If \a activateOnMessage is true (the default), the window will be - activated automatically every time a message is received, just prior - to the messageReceived() signal being emitted. - - \sa activateWindow(), messageReceived() -*/ - -void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) -{ - actWin = aw; - if (activateOnMessage) - connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); - else - disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); -} - - -/*! - Returns the applications activation window if one has been set by - calling setActivationWindow(), otherwise returns 0. - - \sa setActivationWindow() -*/ -QWidget* QtSingleApplication::activationWindow() const -{ - return actWin; -} - - -/*! - De-minimizes, raises, and activates this application's activation window. - This function does nothing if no activation window has been set. - - This is a convenience function to show the user that this - application instance has been activated when he has tried to start - another instance. - - This function should typically be called in response to the - messageReceived() signal. By default, that will happen - automatically, if an activation window has been set. - - \sa setActivationWindow(), messageReceived(), initialize() -*/ -void QtSingleApplication::activateWindow() -{ - if (actWin) { - actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized); - actWin->raise(); - actWin->showNormal(); - actWin->activateWindow(); - } -} - - -/*! - \fn void QtSingleApplication::messageReceived(const QString& message) - - This signal is emitted when the current instance receives a \a - message from another instance of this application. - - \sa sendMessage(), setActivationWindow(), activateWindow() -*/ - - -/*! - \fn void QtSingleApplication::initialize(bool dummy = true) - - \obsolete -*/ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsingleapplication.h ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsingleapplication.h --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsingleapplication.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsingleapplication.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTSINGLEAPPLICATION_H -#define QTSINGLEAPPLICATION_H - -#include <QApplication> - -class QtLocalPeer; - -#if defined(Q_OS_WIN) -# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) -# define QT_QTSINGLEAPPLICATION_EXPORT -# elif defined(QT_QTSINGLEAPPLICATION_IMPORT) -# if defined(QT_QTSINGLEAPPLICATION_EXPORT) -# undef QT_QTSINGLEAPPLICATION_EXPORT -# endif -# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) -# elif defined(QT_QTSINGLEAPPLICATION_EXPORT) -# undef QT_QTSINGLEAPPLICATION_EXPORT -# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) -# endif -#else -# define QT_QTSINGLEAPPLICATION_EXPORT -#endif - -class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication -{ - Q_OBJECT - -public: - QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); - QtSingleApplication(const QString &id, int &argc, char **argv); -#if QT_VERSION < 0x050000 - QtSingleApplication(int &argc, char **argv, Type type); -# if defined(Q_WS_X11) - QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); - QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); - QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); -# endif // Q_WS_X11 -#endif // QT_VERSION < 0x050000 - - bool isRunning(); - QString id() const; - - void setActivationWindow(QWidget* aw, bool activateOnMessage = true); - QWidget* activationWindow() const; - - // Obsolete: - void initialize(bool dummy = true) - { isRunning(); Q_UNUSED(dummy) } - -public Q_SLOTS: - bool sendMessage(const QString &message, int timeout = 5000); - void activateWindow(); - - -Q_SIGNALS: - void messageReceived(const QString &message); - - -private: - void sysInit(const QString &appId = QString()); - QtLocalPeer *peer; - QWidget *actWin; -}; - -#endif // QTSINGLEAPPLICATION_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsingleapplication.pri ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsingleapplication.pri --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsingleapplication.pri 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsingleapplication.pri 1970-01-01 08:00:00.000000000 +0800 @@ -1,16 +0,0 @@ -INCLUDEPATH += $$PWD -DEPENDPATH += $$PWD -QT *= network -greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets - -qtsingleapplication-uselib:!qtsingleapplication-buildlib { - LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME -} else { - SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp - HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h -} - -win32 { - contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT - else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.cpp ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qtsinglecoreapplication.h" -#include "qtlocalpeer.h" - -/*! - \class QtSingleCoreApplication qtsinglecoreapplication.h - \brief A variant of the QtSingleApplication class for non-GUI applications. - - This class is a variant of QtSingleApplication suited for use in - console (non-GUI) applications. It is an extension of - QCoreApplication (instead of QApplication). It does not require - the QtGui library. - - The API and usage is identical to QtSingleApplication, except that - functions relating to the "activation window" are not present, for - obvious reasons. Please refer to the QtSingleApplication - documentation for explanation of the usage. - - A QtSingleCoreApplication instance can communicate to a - QtSingleApplication instance if they share the same application - id. Hence, this class can be used to create a light-weight - command-line tool that sends commands to a GUI application. - - \sa QtSingleApplication -*/ - -/*! - Creates a QtSingleCoreApplication object. The application identifier - will be QCoreApplication::applicationFilePath(). \a argc and \a - argv are passed on to the QCoreAppliation constructor. -*/ - -QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv) - : QCoreApplication(argc, argv) -{ - peer = new QtLocalPeer(this); - connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); -} - - -/*! - Creates a QtSingleCoreApplication object with the application - identifier \a appId. \a argc and \a argv are passed on to the - QCoreAppliation constructor. -*/ -QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv) - : QCoreApplication(argc, argv) -{ - peer = new QtLocalPeer(this, appId); - connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); -} - - -/*! - Returns true if another instance of this application is running; - otherwise false. - - This function does not find instances of this application that are - being run by a different user (on Windows: that are running in - another session). - - \sa sendMessage() -*/ - -bool QtSingleCoreApplication::isRunning() -{ - return peer->isClient(); -} - - -/*! - Tries to send the text \a message to the currently running - instance. The QtSingleCoreApplication object in the running instance - will emit the messageReceived() signal when it receives the - message. - - This function returns true if the message has been sent to, and - processed by, the current instance. If there is no instance - currently running, or if the running instance fails to process the - message within \a timeout milliseconds, this function return false. - - \sa isRunning(), messageReceived() -*/ - -bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout) -{ - return peer->sendMessage(message, timeout); -} - - -/*! - Returns the application identifier. Two processes with the same - identifier will be regarded as instances of the same application. -*/ - -QString QtSingleCoreApplication::id() const -{ - return peer->applicationId(); -} - - -/*! - \fn void QtSingleCoreApplication::messageReceived(const QString& message) - - This signal is emitted when the current instance receives a \a - message from another instance of this application. - - \sa sendMessage() -*/ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.h ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.h --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Solutions component. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTSINGLECOREAPPLICATION_H -#define QTSINGLECOREAPPLICATION_H - -#include <QCoreApplication> - -class QtLocalPeer; - -class QtSingleCoreApplication : public QCoreApplication -{ - Q_OBJECT - -public: - QtSingleCoreApplication(int &argc, char **argv); - QtSingleCoreApplication(const QString &id, int &argc, char **argv); - - bool isRunning(); - QString id() const; - -public Q_SLOTS: - bool sendMessage(const QString &message, int timeout = 5000); - - -Q_SIGNALS: - void messageReceived(const QString &message); - - -private: - QtLocalPeer* peer; -}; - -#endif // QTSINGLECOREAPPLICATION_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.pri ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.pri --- ukui-panel-3.14.0.1/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.pri 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/QtSingleApplication/qtsinglecoreapplication.pri 1970-01-01 08:00:00.000000000 +0800 @@ -1,16 +0,0 @@ -QT += network - -INCLUDEPATH += $$PWD -DEPENDPATH += $$PWD - -HEADERS += $$PWD/qtsinglecoreapplication.h \ - $$PWD/qtlocalpeer.h - -SOURCES += $$PWD/qtsinglecoreapplication.cpp \ - $$PWD/qtlocalpeer.cpp - - - -win32:contains(TEMPLATE, lib):contains(CONFIG, shared) { - DEFINES += QT_QTSINGLECOREAPPLICATION_EXPORT=__declspec(dllexport) -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/UnionVariable.cpp ukui-panel-4.0.0.0/ukui-flash-disk/UnionVariable.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/UnionVariable.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/UnionVariable.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,200 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include "UnionVariable.h" -#include <QDir> -#include <QFileInfoList> -#include <QDebug> -#include <syslog.h> -#include <wait.h> - -static QList<GMount *> gmountList; -QList<GMount *> *findGMountList() -{ - return &gmountList; -} - -static QList<GVolume *> gtelevolumeList; -QList<GVolume *> *findTeleGVolumeList() -{ - return >elevolumeList; -} - -static QList<GVolume *> gvolumeList; -QList<GVolume *> *findGVolumeList() -{ - return &gvolumeList; -} - -static QList<GDrive *> gdriveList; -QList<GDrive *> *findGDriveList() -{ - return &gdriveList; -} - -static QList<GMount *> gtelemountList; -QList<GMount *> *findTeleGMountList() -{ - return >elemountList; -} - -QString getElidedText(QFont font, QString str, int MaxWidth) -{ - if (str.isEmpty()) - { - return ""; - } - - QFontMetrics fontWidth(font); - - //计算字符串宽度 - //calculat the width of the string - int width = fontWidth.width(str); - - //当字符串宽度大于最大宽度时进行转换 - //Convert when string width is greater than maximum width - if (width >= MaxWidth) - { - //右部显示省略号 - //show by ellipsis in right - str = fontWidth.elidedText(str, Qt::ElideRight, MaxWidth); - } - //返回处理后的字符串 - //return the string that is been handled - return str; -} - -/** - * @brief - * 使用 glib 提供的设备名,做到与文件管理器统一。 - */ -void handleVolumeLabelForFat32Me(QString &volumeName,const QString &unixDeviceName) -{ - if (unixDeviceName.isNull() || unixDeviceName.isEmpty()) { - return; - } - - GVolumeMonitor *vm = g_volume_monitor_get(); - GList *volumes = g_volume_monitor_get_volumes(vm); - GList *l = volumes; - while (l) { - GVolume *volume = static_cast<GVolume *>(l->data); - g_autofree char *volume_unix_dev = g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (unixDeviceName == volume_unix_dev) { - g_autofree char *volume_name = g_volume_get_name(volume); - volumeName = volume_name; - break; - } - l = l->next; - } - g_list_free_full(volumes, g_object_unref); - g_object_unref(vm); - - return; - - QFileInfoList diskList; - QFileInfo diskLabel; - QDir diskDir; - QString partitionName,linkTarget; - QString tmpName,finalName; - int i; - - diskDir.setPath("/dev/disk/by-label"); - if(!diskDir.exists()) //this means: volume has no name. - return; // or there no mobile devices. - - diskList = diskDir.entryInfoList(); //all file from dir. - /* eg: unixDeviceName == "/dev/sdb4" - * partitionName == "sdb4" - */ - partitionName = unixDeviceName.mid(unixDeviceName.lastIndexOf('/')+1); - - for(i = 0; i < diskList.size(); ++i){ - diskLabel = diskList.at(i); - linkTarget = diskLabel.symLinkTarget(); - if(linkTarget.contains(partitionName)) - break; - linkTarget.clear(); - } - - if(!linkTarget.isEmpty()) - tmpName = diskLabel.fileName();//可能带有乱码的名字 - - if(!tmpName.isEmpty()){ - if(tmpName == volumeName) //ntfs、exfat格式或者非纯中文名的fat32设备,这个设备的名字不需要转码 - return; - else { - finalName = transcodeForGbkCode(tmpName.toLocal8Bit(), volumeName); - if(!finalName.isEmpty()) - volumeName = finalName; - } - } -} - -QString transcodeForGbkCode(QByteArray gbkName, QString &volumeName) -{ - int i; - QByteArray dest,tmp; - QString name; - int len = gbkName.size(); - - for(i = 0x0; i < len; ++i){ - if(92 == gbkName.at(i)){ - if(4 == tmp.size()) - dest.append(QByteArray::fromHex(tmp)); - else{ - if(tmp.size() > 4){ - dest.append(QByteArray::fromHex(tmp.left(4))); - dest.append(tmp.mid(4)); - }else - dest.append(tmp); - } - tmp.clear(); - tmp.append(gbkName.at(i)); - continue; - }else if(tmp.size() > 0){ - tmp.append(gbkName.at(i)); - continue; - }else - dest.append(gbkName.at(i)); - } - - if(4 == tmp.size()) - dest.append(QByteArray::fromHex(tmp)); - else{ - if(tmp.size() > 4){ - dest.append(QByteArray::fromHex(tmp.left(4))); - dest.append(tmp.mid(4)); - }else - dest.append(tmp); - } - - /* - * gio的api获取的卷名和/dev/disk/by-label先的名字不一致,有可能是卷名 - * 中含有特殊字符,导致/dev/disk/label下的卷名含有转义字符,导致二者的名字不一致 - * 而不是编码格式的不一致导致的,比如卷名:“数据光盘(2020-08-22)”,在/dev/disk/by-label - * 写的名字:"数据光盘\x282020-08-22\x29",经过上述处理之后可以去除转义字符,在判断一次 - * 是否相等。比较完美的解决方案是找到能够判断字符串的编码格式,目前还没有找到实现方式,需要进一步完善 - */ - name = QString(dest); - if (name == volumeName){ - return name; - } - - name = QTextCodec::codecForName("GBK")->toUnicode(dest); - return name; -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/UnionVariable.h ukui-panel-4.0.0.0/ukui-flash-disk/UnionVariable.h --- ukui-panel-3.14.0.1/ukui-flash-disk/UnionVariable.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/UnionVariable.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef UNIONVARIABLE_H -#define UNIONVARIABLE_H -#include <QList> -#include <gio/gio.h> -#include <QString> -#include <QFont> -#include <QFontMetrics> -#include <QTextCodec> -#include <syslog.h> -QList<GMount *> *findGMountList(); -QList<GMount *> *findTeleGMountList(); -QList<GVolume *> *findGVolumeList(); -QList<GVolume *> *findTeleGVolumeList(); -QList<GDrive *> *findGDriveList(); -QString getElidedText(QFont font, QString str, int MaxWidth); -QString transcodeForGbkCode(QByteArray gbkName, QString &volumeName); -void handleVolumeLabelForFat32Me(QString &volumeName,const QString &unixDevcieName); -//int m_system(char *cmd); -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/clickLabel.cpp ukui-panel-4.0.0.0/ukui-flash-disk/clickLabel.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/clickLabel.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/clickLabel.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "clickLabel.h" -ClickLabel::ClickLabel(QWidget *parent) -{ -} - -ClickLabel::~ClickLabel() -{ -} - -void ClickLabel::mousePressEvent(QMouseEvent *event){ - if (event->button() == Qt::LeftButton) - Q_EMIT clicked(); - QLabel::mousePressEvent(event); -} - -//void ClickLabel::paintEvent(QPaintEvent *event){ -//// Q_UNUSED(event) -//// QStyleOption opt; -//// opt.init(this); -//// QPainter p(this); -//// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -//} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/clickLabel.h ukui-panel-4.0.0.0/ukui-flash-disk/clickLabel.h --- ukui-panel-3.14.0.1/ukui-flash-disk/clickLabel.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/clickLabel.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef CLICKLABEL_H -#define CLICKLABEL_H - -#include <QLabel> -#include <QMouseEvent> -#include <QPainter> -#include <QStyleOption> - -class ClickLabel : public QLabel -{ - Q_OBJECT - -public: - explicit ClickLabel(QWidget *parent = 0); - ~ClickLabel(); - -protected: - void mousePressEvent(QMouseEvent * event); - //virtual void paintEvent(QPaintEvent * event); - -Q_SIGNALS: - void clicked(); -}; - -#endif // CLICKLABEL_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/datacdrom.cpp ukui-panel-4.0.0.0/ukui-flash-disk/datacdrom.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/datacdrom.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/datacdrom.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,603 +0,0 @@ -/* - * Peony-Qt's Library - * - * Copyright (C) 2020, KylinSoft Co., Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this library. If not, see <https://www.gnu.org/licenses/>. - * - * Authors: renpeijia <renpeijia@kylinos.cn> - * - */ - -#include "datacdrom.h" - -#include <unistd.h> -#include <fcntl.h> -#include <scsi/sg.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include <mntent.h> - -#include <QThread> -#include <QCoreApplication> -#include <QFileInfo> -#include <QDebug> - -DataCDROM::DataCDROM(QString &blockName, QObject *parent) : QObject(parent) -{ - m_oBlockName = blockName; - - m_iHandle = -1; - m_oMediumType.clear(); - - m_u32MediumRSupport = 0; - m_u32MediumWSupport = 0; - - m_u32TrackNumber = 0; - m_u64UsedCapacity = 0; - m_u64FreeCapacity = 0; - m_u64Capacity = 0; -} - -DataCDROM::~DataCDROM() -{ - -} - -void DataCDROM::getCDROMInfo() -{ - int ret = 0; - - // 0. open device. - if (!open()) { - qWarning()<<"open cdrom device failed"; - return; - } - - // 1. load support mediu types. - ret = checkRWSupport(); - if (ret < 0) { - qWarning()<<"check support type failed"; - close(); - return; - } - - // 2. check have medium or not. - ret = checkMediumType(); - if (ret < 0) { - qWarning()<<"check medium type failed"; - close(); - return; - } - - //3、get track num - ret = cdRomGetTrackNum(); - if (ret < 0) { - qWarning()<<"get cdrom track num failed"; - close(); - return; - } - - //4、get capacity - cdRomCapacity(); - - //5、close device - close(); - - return; -} - -bool DataCDROM::open() -{ - if (-1 != m_iHandle) { - return true; - } - - m_iHandle = ::open(m_oBlockName.toUtf8().constData(), O_NONBLOCK | O_RDONLY); - if (m_iHandle < 0) { - qWarning()<<QString("Open block device %1 faied.").arg(m_oBlockName); - return false; - } - - return true; -} - -void DataCDROM::close() -{ - if (-1 != m_iHandle) { - ::close(m_iHandle); - } - - m_iHandle = -1; -} - -bool DataCDROM::execSCSI(const unsigned char *cdb, const int cdbLength, - unsigned char *result, const int resultLength) -{ - sg_io_hdr_t sgio; - - if (!open()) { - return false; - } - - if (!cdb || !result || resultLength < 1) { - return false; - } - - memset(&sgio, 0, sizeof(sg_io_hdr_t)); - sgio.interface_id = 'S'; - sgio.dxfer_direction = SG_DXFER_FROM_DEV; - sgio.flags = SG_FLAG_LUN_INHIBIT; - sgio.cmdp = (unsigned char *)cdb; - sgio.cmd_len = cdbLength; - sgio.dxferp = result; - sgio.dxfer_len = resultLength; - - if (0 != ioctl(m_iHandle, SG_IO, &sgio)) { - qWarning("Do SCSI CDB cmd failed."); - return false; - } - - return true; -} - -int DataCDROM::checkRWSupport() -{ - unsigned short len = 0; - unsigned char cdb[12] = { 0x46, // get configuraion - 0x00, - 0x00, - 0x00, // fearture low - 0x00, // reserved - 0x00, // reserved - 0x00, // reserved - 0x00, // allocation length high - 0x0C, - 0 }; - unsigned char result[65536] = {0}; - - // get header length first. - if (!execSCSI(cdb, 12, result, 12)) { - qWarning()<<"scsi get header length failed."; - return -1; - } - - if (!(result[8] == cdb[2] && result[9] == cdb[3])) { - qWarning()<<"scsi check header info failed"; - return -1; - } - - len = (result[0] << 24) | (result[1] << 16) | (result[2] << 8) | result[3]; - cdb[7] = ((len & 0xFF00) >> 8); - cdb[8] = (len & 0x00FF); - // get real result. - if (!execSCSI(cdb, 12, result, len)) { - qWarning()<<"scsi get medium read type support"; - return -1; - } - - len = result[11]; - // loop result, adjust support read medium type. - for (int i = 0; i < len; ++i) { - switch ((result[i + 12] << 8) | result[i + 13]) { - case 0x0008: // CD-ROM - m_u32MediumRSupport |= MEDIUM_CD_ROM; - break; - case 0x0009: // CD-R - m_u32MediumRSupport |= MEDIUM_CD_R; - break; - case 0x000A: // CD-RW - m_u32MediumRSupport |= MEDIUM_CD_RW; - break; - // 000B - 000F reserved. - case 0x0010: // DVD-ROM - m_u32MediumRSupport |= MEDIUM_DVD_ROM; - break; - case 0x0011: // DVD-R - m_u32MediumRSupport |= MEDIUM_DVD_R; - break; - case 0x0012: // DVD-RAM - m_u32MediumRSupport |= MEDIUM_DVD_RAM; - break; - // define in MMC-5 - case 0x0013: // DVD-RW - m_u32MediumRSupport |= MEDIUM_DVD_RW_OVERWRITE; - break; - case 0x0014: - m_u32MediumRSupport |= MEDIUM_DVD_RW_SEQ; - break; - case 0x0015: - m_u32MediumRSupport |= MEDIUM_DVD_R_DL_SEQ; - break; - case 0x0016: - m_u32MediumRSupport |= MEDIUM_DVD_R_DL_JUMP; - break; - case 0x001A: // DVD+RW - m_u32MediumRSupport |= MEDIUM_DVD_PLUS_RW; - break; - case 0x001B: //DVD+R - m_u32MediumRSupport |= MEDIUM_DVD_PLUS_R; - break; - case 0x002B: - m_u32MediumRSupport |= MEDIUM_DVD_PLUS_R_DL; - break; - case 0x0002: - // qDebug()<< "Removable CDROM."; - break; - default: - // qDebug()<<"Unkown medium type" << ((result[i + 12] << 8) | result[i + 13]); - break; - } - } - - // load write suppport - // CD TAO - cdb[2] = 0x00; - cdb[3] = 0x2D; - cdb[7] = 0x00; - cdb[8] = 0x10; - if (!execSCSI(cdb, 12, result, 16)) { - qWarning()<<"scsi get cd tao write support failed."; - return -1; - } - - if (result[8] == cdb[2] && result[9] == cdb[3]) { - m_u32MediumWSupport |= MEDIUM_CD_R; - if (result[12] & 0x02) { - m_u32MediumWSupport |= MEDIUM_CD_RW; - } - } - - //CD SAO - cdb[2] = 0x00; - cdb[3] = 0x2E; - cdb[7] = 0x00; - cdb[8] = 0x10; - if (!execSCSI(cdb, 12, result, 16)) { - qWarning()<<"scsi get cd sao write medium support failed"; - return -1; - } - - if (result[8] == cdb[2] && result[9] == cdb[3]){ - m_u32MediumWSupport |= MEDIUM_CD_R; - if (result[12] & 0x02) { - m_u32MediumWSupport |= MEDIUM_CD_RW; - } - } - - //DVD - cdb[2] = 0x00; - cdb[3] = 0x1F; - cdb[7] = 0x00; - cdb[8] = 0x10; - if (!execSCSI(cdb, 12, result, 16)) { - qWarning()<<"scsi get DVD-ROM read medium support failed"; - return -1; - } - if (result[8] == cdb[2] && result[9] == cdb[3]) { - m_u32MediumRSupport |= MEDIUM_DVD_ROM; - //qDebug("%1 sure support read mode : DVD-ROM"); - } - - //DVD+RW - cdb[2] = 0x00; cdb[3] = 0x2A; cdb[7] = 0x00; cdb[8] = 0x10; - if (!execSCSI(cdb, 12, result, 16)) { - qWarning()<<"scsi get DVD+RW write medium support failed"; - return -1; - } - if (result[8] == cdb[2] && result[9] == cdb[3]){ - if (result[12] & 0x01) { - m_u32MediumWSupport |= MEDIUM_DVD_PLUS_RW; - } else { - m_u32MediumWSupport |= MEDIUM_DVD_ROM; - } - } - - //DVD+R - cdb[2] = 0x00; cdb[3] = 0x2B; cdb[7] = 0x00; cdb[8] = 0x10; - if (!execSCSI(cdb, 12, result, 16)) { - qWarning()<<"scsi get DVD+R RW medium support failed"; - return -1; - } - - if (result[8] == cdb[2] && result[9] == cdb[3]) { - m_u32MediumRSupport |= MEDIUM_DVD_PLUS_R; - if (result[12] & 0x01) { - m_u32MediumWSupport |= MEDIUM_DVD_PLUS_R; - } - } - - //DVD-R / DVD-RW - cdb[2] = 0x00; - cdb[3] = 0x2F; - cdb[7] = 0x00; - cdb[8] = 0x10; - if (!execSCSI(cdb, 12, result, 16)) { - qWarning()<<"scsi get DVD-R/DVD-RW RW medium type support failed"; - return -1; - } - if (result[8] == cdb[2] && result[9] == cdb[3]) { - m_u32MediumRSupport |= MEDIUM_DVD_R; - //qDebug("it sure support read mode : DVD-R"); - m_u32MediumWSupport |= MEDIUM_DVD_R; - //qDebug("it support write mode : DVD-R"); - m_u32MediumRSupport |= MEDIUM_DVD_RW; - //qDebug("it sure support read mode : DVD-RW"); - if (result[12] & 0x02) { - m_u32MediumWSupport |= MEDIUM_DVD_RW; - //qDebug("%1 support write mode : DVD-RW"); - } - } - - if (m_u32MediumRSupport & ((MEDIUM_DVD_RW_OVERWRITE | MEDIUM_DVD_RW_SEQ))) { - m_u32MediumRSupport |= MEDIUM_DVD_RW; - } - - qDebug()<<"m_u32MediumRSupport"<<m_u32MediumRSupport - <<"m_u32MediumWSupport"<<m_u32MediumWSupport; - return 0; -} - -int DataCDROM::checkMediumType() -{ - unsigned short profile = 0; - unsigned int len = 0; - - unsigned char cdb[12] = {0x46, // operation code - 0x01, // RT : 0x10b - 0x00, // fearture high - 0x00, // fearture low - 0x00, // reserved - 0x00, // reserved - 0x00, // reserved - 0x00, // allocation length high - 0x0C, // allocation length low - 0}; - unsigned char result[65536] = {0}; - - m_oMediumType.clear(); - - if (!execSCSI(cdb, 12, result, 12)) { - qWarning()<<"scsi get medium type failed"; - return -1; - } - - if (!(result[8] == cdb[2] && result[9] == cdb[3])) { - qWarning()<<"scsi check medium type result failed"; - return -1; - } - - profile = (result[6] << 8) | result[7]; - switch (profile) { - case 0x0008: // CD-ROM - if (m_u32MediumRSupport & MEDIUM_CD_ROM) { - m_oMediumType = "CD-ROM"; - break; - } - qWarning("CDROM cannot support to read CD-ROM medium"); - break; - case 0x0009: //CD-R - if (m_u32MediumRSupport & MEDIUM_CD_R) { - m_oMediumType = "CD-R"; - break; - } - qWarning("CDROM cannot support to read CD-R medium"); - break; - case 0x000A: // CD-RW - if (m_u32MediumRSupport & MEDIUM_CD_RW) { - m_oMediumType = "CD-RW"; - break; - } - qWarning("CDROM cannot support to read CD-RW medium"); - break; - case 0x0010: // DVD-ROM - if (m_u32MediumRSupport & MEDIUM_DVD_ROM) { - m_oMediumType = "DVD-ROM"; - break; - } - qWarning("CDROM cannot support to read DVD-ROM medium"); - break; - case 0x0011: // DVD-R - if (m_u32MediumRSupport & MEDIUM_DVD_R) { - m_oMediumType = "DVD-R"; - break; - } - qWarning("CDROM cannot support to read DVD-R medium"); - break; - case 0x0012: // DVD-RAM - if (m_u32MediumRSupport & MEDIUM_DVD_RAM) { - m_oMediumType = "DVD-RAM"; - break; - } - qWarning("CDROM cannot support to read DVD-RAM medium"); - break; - case 0x0013: // DVD-RW - if (m_u32MediumRSupport & MEDIUM_DVD_RW_OVERWRITE) { - m_oMediumType = "DVD-RW"; - break; - } - qWarning("CDROM cannot support to read DVD-RW(OVERWRITE) medium"); - break; - case 0x0014: // DVD-RW - if (m_u32MediumRSupport & MEDIUM_DVD_RW_SEQ) { - m_oMediumType = "DVD-RW"; - break; - } - qWarning("CDROM cannot support to read DVD-RW medium"); - break; - case 0x001A: // DVD+RW - if (m_u32MediumRSupport & MEDIUM_DVD_PLUS_RW) { - m_oMediumType = "DVD+RW"; - break; - } - qWarning("CDROM cannot support to read DVD+RW medium"); - break; - case 0x001B: // DVD+R - if (m_u32MediumRSupport & MEDIUM_DVD_PLUS_R) { - m_oMediumType = "DVD+R"; - break; - } - qWarning("CDROM cannot support to read DVD+R medium"); - break; - default: - qWarning()<<"the type" << profile << "undefined"; - return -1; - } - - qDebug()<<"the medium type "<< m_oMediumType; - return 0; -} - -int DataCDROM::cdRomGetTrackNum() -{ - unsigned short len = 0; - unsigned char cdb[10] = { 0x51, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x20, - 0 }; - unsigned char result[32] = { 0 }; - - if (!execSCSI(cdb, 10, result, 32)) { - qWarning()<<"scsi get cd rom track num failed."; - return -1; - } - - len = (result[0] << 8) | result[1]; - if ((len - 32) % 8) { - qWarning()<<"scsi get wrong reply from cdrom"; - return -1; // len is 32 + 8 * n - } - -#if 0 - switch (result[2] & 0x03) - { - case 0x00: // empty - m_u8Status = MEDIUM_EMPTY; - //qDebug()<<"empty mediun."; - break; - case 0x01: // incomplete - m_u8Status = MEDIUM_INCOMPLETE; - //qDebug("incomplete mediun."); - break; - case 0x02: - m_u8Status = MEDIUM_FINALIZED; - //qDebug("finalized mediun."); - break; - case 0x03: - m_u8Status = MEDIUM_OTHER; - break; - default: - break; - } -#endif - - m_u32TrackNumber = (((result[11] << 8) & 0xFF00) | result[6]); - - return 0; -} - -/* -*需要研究dvd+rw-mediainfo的实现代码,通过scsi获取DVD+RW/DVD-RW的 -*容量 -*/ -void DataCDROM::DVDRWCapacity() -{ - int index = 0; - QProcess process; - QStringList deviceName; - deviceName<<m_oBlockName; - - process.start("dvd+rw-mediainfo", deviceName); - process.waitForFinished(10000); - QString result = process.readAllStandardOutput(); - QStringList dvdInfo = result.split("\n"); - - for (index = dvdInfo.size() - 1; index > 0; --index){ - if (dvdInfo.at(index).startsWith("READ FORMAT CAPACITIES:")) { - QStringList formatCapacity = dvdInfo.takeAt(index + 1).split("="); - qWarning()<<"format capacity is"<<formatCapacity.last(); - if (m_oMediumType.contains("DVD+RW")) { - m_u64Capacity = formatCapacity.last().toULong(); - } - } - - if (dvdInfo.at(index).startsWith("READ CAPACITY:")) { - QStringList readCapacity = dvdInfo.takeAt(index).split("="); - qWarning()<<"DVD RW read capacity is "<<readCapacity.last(); - } - - if (dvdInfo.at(index).startsWith("READ DVD STRUCTURE")) { - QStringList dvdStruct = dvdInfo.takeAt(index + 2).split("="); - qWarning()<<"DVD RW struct capacity is"<<dvdStruct.last(); - if (m_oMediumType.contains("DVD-RW")) { - m_u64Capacity += dvdStruct.last().toULong(); - } - } - } - - return; -} - - -void DataCDROM::cdRomCapacity() -{ - unsigned char cdb[10] = { 0x52, - 0x01, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x28, - 0 }; - unsigned char result[40] = { 0 }; // 256 + 12 - - - // qWarning()<<"medium type"<<m_oMediumType; - if (!m_oMediumType.isEmpty() - && (m_oMediumType.contains("DVD+RW") || m_oMediumType.contains("DVD-RW"))) - { - DVDRWCapacity(); - qWarning()<<"DVD+RW/DVD-RW get capacity"; - return; - } - - cdb[2] = (m_u32TrackNumber >> 24); - cdb[3] = (m_u32TrackNumber >> 16); - cdb[4] = (m_u32TrackNumber >> 8); - cdb[5] = m_u32TrackNumber; - - if (!execSCSI(cdb, 10, result, 40)) { - qWarning()<<"scsi get cd rom capacity failed."; - return; - } - - m_u64UsedCapacity = ((result[8] << 24) | (result[9] << 16) | (result[10] << 8) | result[11]); - m_u64UsedCapacity *= 2048; - m_u64FreeCapacity = ((result[16] << 24) | (result[17] << 16) | (result[18] << 8) | result[19]); - m_u64FreeCapacity *= 2048; - m_u64Capacity = m_u64UsedCapacity + m_u64FreeCapacity; - - qDebug()<<"total capacity:"<<m_u64Capacity - << "used capacity:"<<m_u64UsedCapacity - << "free capacity:"<<m_u64FreeCapacity; - return; -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/datacdrom.h ukui-panel-4.0.0.0/ukui-flash-disk/datacdrom.h --- ukui-panel-3.14.0.1/ukui-flash-disk/datacdrom.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/datacdrom.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,114 +0,0 @@ -/* - * Peony-Qt's Library - * - * Copyright (C) 2020, KylinSoft Co., Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this library. If not, see <https://www.gnu.org/licenses/>. - * - * Authors: renpeijia <renpeijia@kylinos.cn> - * - */ - -#ifndef DATACDROM_H -#define DATACDROM_H - -#include <QObject> -#include <QIcon> -#include <QProcess> - -enum MEDIUM_TYPE -{ - MEDIUM_UNKOWN = 0x0000, - MEDIUM_CD_ROM = 0x0001, - MEDIUM_CD_R = 0x0002, - MEDIUM_CD_RW = 0x0004, - MEDIUM_DVD_ROM = 0x0008, - MEDIUM_DVD_R = 0x0010, - MEDIUM_DVD_RAM = 0x0020, - MEDIUM_DVD_R_DL_SEQ = 0x0040, - MEDIUM_DVD_R_DL_JUMP = 0x0080, - MEDIUM_DVD_PLUS_RW = 0x0100, - MEDIUM_DVD_PLUS_R = 0x0101, - MEDIUM_DVD_PLUS_RW_DL = 0x0102, - MEDIUM_DVD_PLUS_R_DL = 0x0104, - MEDIUM_DVD_RW_OVERWRITE = 0x0108, - MEDIUM_DVD_RW_SEQ = 0x0110, - MEDIUM_CD_RW_S0 = 0x0120, // in MMC-5 CD-RW has 8 subtypes. - MEDIUM_CD_RW_S1 = 0x0140, - MEDIUM_CD_RW_S2 = 0x0180, - MEDIUM_CD_RW_S3 = 0x0200, - MEDIUM_CD_RW_S4 = 0x0201, - MEDIUM_CD_RW_S5 = 0x0202, - MEDIUM_CD_RW_S6 = 0x0204, - MEDIUM_CD_RW_S7 = 0x0208, - MEDIUM_DVD_RW = 0x0210 -}; - -enum MEDIUM_STATUS -{ - MEDIUM_EMPTY = 0, - MEDIUM_INCOMPLETE, - MEDIUM_FINALIZED, - MEDIUM_OTHER -}; - -enum BURN_MODE -{ - BURN_CD_TAO = 0x01, - BURN_CD_SAO = 0x02, - BURN_CD_DAO = 0x04 // close session/track when TAO over. -}; - -class DataCDROM : public QObject -{ - Q_OBJECT - -public: - explicit DataCDROM(QString &blockName, QObject *parent = nullptr); - ~DataCDROM(); -public: - void getCDROMInfo(); - unsigned long getCDROMCapacity() { - return m_u64Capacity; - } - - unsigned long getCDROMUsedCapacity() { - return m_u64UsedCapacity; - } - -private: - bool open(); - void close(); - bool execSCSI(const unsigned char *, const int, unsigned char *, const int); - int checkRWSupport(); - int checkMediumType(); - int cdRomGetTrackNum(); - void DVDRWCapacity(); - void cdRomCapacity(); - -private: - int m_iHandle; - unsigned int m_u32MediumRSupport; - unsigned int m_u32MediumWSupport; - - QString m_oBlockName; - QString m_oMediumType; - - unsigned int m_u32TrackNumber; - unsigned long m_u64UsedCapacity; - unsigned long m_u64FreeCapacity; - unsigned long m_u64Capacity; -}; - -#endif // DATACDROM_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/device-manager.cpp ukui-panel-4.0.0.0/ukui-flash-disk/device-manager.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/device-manager.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/device-manager.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Ding Jing dingjing@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "device-manager.h" - -DeviceManager* DeviceManager::gInstance = new DeviceManager; - -const DeviceManager* DeviceManager::getInstance() -{ - return gInstance; -} - -DeviceManager::DeviceManager(QObject *parent) : QObject(parent) -{ - mGvolumeMonitor = g_volume_monitor_get(); - - g_signal_connect(mGvolumeMonitor, "drive-connected", G_CALLBACK(drive_connected_callback), this); - g_signal_connect(mGvolumeMonitor, "drive-disconnected", G_CALLBACK(drive_disconnected_callback), this); -} - -DeviceManager::~DeviceManager() -{ - if (mGvolumeMonitor) g_object_unref(mGvolumeMonitor); -} - -void DeviceManager::drive_connected_callback(GVolumeMonitor *monitor, GDrive *drive, gpointer pThis) -{ - g_return_if_fail(drive); - g_return_if_fail(pThis); - - DeviceManager* dm = static_cast<DeviceManager*>(pThis); - - - Q_UNUSED(dm); - Q_UNUSED(monitor); -} - -void DeviceManager::drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, gpointer pThis) -{ - g_return_if_fail(drive); - g_return_if_fail(pThis); -#if 0 - DeviceManager* dm = static_cast<DeviceManager*>(pThis); - - g_autofree gchar* devName = g_drive_get_identifier(drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (nullptr != devName) { - Q_EMIT dm->driveDisconnected(devName); - } -#endif - Q_UNUSED(monitor); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/device-manager.h ukui-panel-4.0.0.0/ukui-flash-disk/device-manager.h --- ukui-panel-3.14.0.1/ukui-flash-disk/device-manager.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/device-manager.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Ding Jing dingjing@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef DEVICEMANAGER_H -#define DEVICEMANAGER_H - -#include <gio/gio.h> - -#include <QMap> -#include <QObject> - -class DeviceManager : public QObject -{ - Q_OBJECT -public: - static const DeviceManager* getInstance(); - -private: - explicit DeviceManager(QObject* parent = nullptr); - ~DeviceManager(); - static void drive_connected_callback(GVolumeMonitor* monitor, GDrive* drive, gpointer pThis); - static void drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, gpointer pThis); - -Q_SIGNALS: - void driveDisconnected(QString drive); - - -private: - static DeviceManager* gInstance; - GVolumeMonitor* mGvolumeMonitor = nullptr; - QMap<gpointer, QString> mDevice; -}; - -#endif // DEVICEMANAGER_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/device-operation.cpp ukui-panel-4.0.0.0/ukui-flash-disk/device-operation.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/device-operation.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/device-operation.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,326 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Ding Jing dingjing@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "device-operation.h" - -#include <sys/stat.h> - - -static void formatCB (GObject* sourceObject, GAsyncResult* res, gpointer udata); -static void repairCB (GObject* sourceObject, GAsyncResult* res, gpointer udata); - - -DeviceOperation::DeviceOperation(GDrive *drive, QObject *parent) : QObject(parent) -{ - g_return_if_fail(drive); - - g_autofree char* devName = g_drive_get_identifier(drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_if_fail(devName); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_if_fail(client); - - g_autoptr(UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_if_fail(udiskObj); - - mDiskBlock = udisks_object_get_block(udiskObj); - mDiskManager = udisks_object_get_manager(udiskObj); - mDiskFilesystem = udisks_object_get_filesystem(udiskObj); -} - -DeviceOperation::DeviceOperation(GVolume* volume, QObject *parent) : QObject(parent) -{ - g_return_if_fail(volume); - - g_autofree char* devName = g_volume_get_identifier(volume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_if_fail(devName); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_if_fail(client); - - g_autoptr(UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_if_fail(udiskObj); - - mDiskBlock = udisks_object_get_block(udiskObj); - mDiskManager = udisks_object_get_manager(udiskObj); - mDiskFilesystem = udisks_object_get_filesystem(udiskObj); -} - -DeviceOperation::~DeviceOperation() -{ - g_clear_object(&mDiskBlock); - g_clear_object(&mDiskManager); - g_clear_object(&mDiskFilesystem); -} - -bool DeviceOperation::repairFilesystem(GDrive *drive) -{ - gboolean ret = FALSE; - - g_return_val_if_fail(drive, ret); - - g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_val_if_fail(devName, ret); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_val_if_fail(client, ret); - - g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_val_if_fail(udiskObj, ret); - - g_autoptr (UDisksFilesystem) diskFilesystem = udisks_object_get_filesystem(udiskObj); - - GVariantBuilder optionsBuilder; - g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT); - - udisks_filesystem_call_repair_sync(diskFilesystem, g_variant_builder_end(&optionsBuilder), &ret, nullptr, nullptr); - - return ret; -} - -bool DeviceOperation::repairFilesystem(GVolume *volume) -{ - gboolean ret = FALSE; - - g_return_val_if_fail(volume, ret); - - g_autofree char* devName = g_volume_get_identifier (volume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_val_if_fail(devName, ret); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_val_if_fail(client, ret); - - g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_val_if_fail(udiskObj, ret); - - g_autoptr (UDisksFilesystem) diskFilesystem = udisks_object_get_filesystem(udiskObj); - - - GVariantBuilder optionsBuilder; - g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT); - - udisks_filesystem_call_repair_sync(diskFilesystem, g_variant_builder_end(&optionsBuilder), &ret, nullptr, nullptr); - - return ret; -} - -gint64 DeviceOperation::getDriveSize(GDrive *drive) -{ - gint64 ret = 0; - - g_return_val_if_fail(drive, ret); - - g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_val_if_fail(devName, ret); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_val_if_fail(client, ret); - - g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_val_if_fail(udiskObj, ret); - - g_autoptr (UDisksBlock) diskBlock = udisks_object_get_block (udiskObj); - - return udisks_block_get_size(diskBlock); -} - -gchar *DeviceOperation::getDriveLabel(GDrive *drive) -{ - gchar* ret = NULL; - - g_return_val_if_fail(drive, ret); - - g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_val_if_fail(devName, ret); - - ret = g_strdup (devName); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_val_if_fail(client, ret); - - g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_val_if_fail(udiskObj, ret); - - g_autoptr (UDisksBlock) diskBlock = udisks_object_get_block (udiskObj); - g_return_val_if_fail(udiskObj, ret); - - // cannot free - const gchar* label = udisks_block_get_id_label (diskBlock); - if (label && 0 != g_strcmp0 (label, "") && 0 != g_strcmp0 (label, " ")) { if (ret) g_free(ret); ret = g_strdup (label);}; - - return ret; -} - -gchar *DeviceOperation::getDriveLabel(GVolume *volume) -{ - gchar* ret = NULL; - - g_return_val_if_fail(volume, ret); - - g_autofree char* devName = g_volume_get_identifier (volume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_return_val_if_fail(devName, ret); - - ret = g_strdup (devName); - - g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL); - g_return_val_if_fail(client, ret); - - g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName); - g_return_val_if_fail(udiskObj, ret); - - g_autoptr (UDisksBlock) diskBlock = udisks_object_get_block (udiskObj); - g_return_val_if_fail(udiskObj, ret); - - // cannot free - const gchar* label = udisks_block_get_id_label (diskBlock); - if (label && 0 != g_strcmp0 (label, "") && 0 != g_strcmp0 (label, " ")) { if (ret) g_free(ret); ret = g_strdup (label);}; - - return ret; -} - -void DeviceOperation::udiskFormat(QString type, QString labelName) -{ - if (!mDiskBlock) { - Q_EMIT formatFinished(false); - return; - } - - GVariantBuilder optionsBuilder; - g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT); - - g_variant_builder_add (&optionsBuilder, "{sv}", "label", g_variant_new_string (labelName.toUtf8().constData())); - g_variant_builder_add (&optionsBuilder, "{sv}", "take-ownership", g_variant_new_boolean (TRUE)); - g_variant_builder_add (&optionsBuilder, "{sv}", "update-partition-type", g_variant_new_boolean (TRUE)); - -// g_cancellable_reset(&mFormatCancel); - - udisks_block_call_format(mDiskBlock, type.toLower().toUtf8().constData(), g_variant_builder_end(&optionsBuilder), nullptr /*&mFormatCancel*/, GAsyncReadyCallback(formatCB), this); -} - -void DeviceOperation::udiskRepair() -{ - if (!mDiskFilesystem) { - Q_EMIT repairFinished(false); - return; - } - - GVariantBuilder optionsBuilder; - g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT); - -// g_cancellable_reset(&mRepairCancel); - - udisks_filesystem_call_repair(mDiskFilesystem, g_variant_builder_end(&optionsBuilder), nullptr /*&mRepairCancel*/, GAsyncReadyCallback(repairCB), this); -} - -void DeviceOperation::udiskFormatCancel() -{ -// if (g_cancellable_is_cancelled(&mFormatCancel)) { -// g_cancellable_cancel(&mFormatCancel); -// } -} - -void DeviceOperation::udiskRepairCancel() -{ -// if (g_cancellable_is_cancelled(&mRepairCancel)) { -// g_cancellable_cancel(&mRepairCancel); -// } -} - -QString DeviceOperation::udiskSize() -{ - g_return_val_if_fail(mDiskBlock, tr("unknown")); - - guint64 size = udisks_block_get_size(mDiskBlock); - g_autofree char* str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); - - return str; -} - -QString DeviceOperation::udiskUUID() -{ - g_return_val_if_fail(mDiskBlock, tr("unknown")); - - const char* str = udisks_block_get_id_uuid(mDiskBlock); - - return str; -} - -QString DeviceOperation::udiskLabel() -{ - g_return_val_if_fail(mDiskBlock, tr("unknown")); - - const char* str = udisks_block_get_id_label(mDiskBlock); - - return str; -} - -UDisksObject* DeviceOperation::getObjectFromBlockDevice(UDisksClient* client, const gchar* bdevice) -{ - struct stat statbuf; - UDisksObject* object = NULL; - UDisksObject* cryptoBackingObject = NULL; - g_autofree const gchar* cryptoBackingDevice = NULL; - - g_return_val_if_fail(stat(bdevice, &statbuf) == 0, object); - - // cannot free - UDisksBlock* block = udisks_client_get_block_for_dev (client, statbuf.st_rdev); - g_return_val_if_fail(block != NULL, object); - - object = UDISKS_OBJECT (g_dbus_interface_dup_object (G_DBUS_INTERFACE (block))); - - cryptoBackingDevice = udisks_block_get_crypto_backing_device ((udisks_object_peek_block (object))); - cryptoBackingObject = udisks_client_get_object (client, cryptoBackingDevice); - if (cryptoBackingObject != NULL) { - g_object_unref (object); - object = cryptoBackingObject; - } - - return object; -} - -static void formatCB (GObject* sourceObject, GAsyncResult* res, gpointer udata) -{ - bool ret = true; - GError* error = NULL; - DeviceOperation* pThis = static_cast<DeviceOperation*>(udata); - - if (!udisks_block_call_format_finish (UDISKS_BLOCK(sourceObject), res, &error)) { - if (NULL != error && NULL != strstr(error->message, "wipefs:")) { - g_clear_error(&error); - } - ret = false; - } - - Q_EMIT pThis->formatFinished(ret); -} -static void repairCB (GObject* sourceObject, GAsyncResult* res, gpointer udata) -{ - GError* error = NULL; - gboolean outRet = FALSE; - DeviceOperation* pThis = static_cast<DeviceOperation*>(udata); - - if (!udisks_filesystem_call_repair_finish(UDISKS_FILESYSTEM(sourceObject), &outRet, res, &error)) { - g_clear_error(&error); - } - - Q_EMIT pThis->repairFinished(outRet); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/device-operation.h ukui-panel-4.0.0.0/ukui-flash-disk/device-operation.h --- ukui-panel-3.14.0.1/ukui-flash-disk/device-operation.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/device-operation.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Ding Jing dingjing@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef DEVICEOPERATION_H -#define DEVICEOPERATION_H - -#include <QObject> -#include <gio/gio.h> -#include <udisks/udisks.h> - -class DeviceOperation : public QObject -{ - Q_OBJECT -public: - explicit DeviceOperation(GDrive* drive, QObject *parent = nullptr); - explicit DeviceOperation(GVolume* volume, QObject *parent = nullptr); - ~DeviceOperation(); - - - static bool repairFilesystem(GDrive* drive); - static bool repairFilesystem(GVolume* volume); - - static gint64 getDriveSize(GDrive* drive); - - static gchar* getDriveLabel(GDrive* drive); - static gchar* getDriveLabel(GVolume* volume); - - -public Q_SLOTS: - void udiskFormat(QString type, QString labelName); - void udiskRepair(); - void udiskFormatCancel(); - void udiskRepairCancel(); - - QString udiskSize(); - QString udiskUUID(); - QString udiskLabel(); - -private: - static UDisksObject* getObjectFromBlockDevice(UDisksClient *client, const gchar *bdevice); - -Q_SIGNALS: - void repairFinished(bool); - void formatFinished(bool); - -private: - UDisksBlock* mDiskBlock = NULL; - UDisksManager* mDiskManager = NULL; - UDisksFilesystem* mDiskFilesystem = NULL; - - GCancellable mRepairCancel; - GCancellable mFormatCancel; -}; - -#endif // DEVICEOPERATION_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/org.ukui.flash-disk.autoload.gschema.xml ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/org.ukui.flash-disk.autoload.gschema.xml --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/org.ukui.flash-disk.autoload.gschema.xml 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/org.ukui.flash-disk.autoload.gschema.xml 1970-01-01 08:00:00.000000000 +0800 @@ -1,9 +0,0 @@ -<schemalist gettext-domain="ukui-flash-disk"> - <schema id="org.ukui.flash-disk.autoload" path="/org/ukui/flash-disk/autoload/"> - <key type="b" name="ifautoload"> - <default>true</default> - <summary>auto load udisk</summary> - <description>Control if auto load udisk</description> - </key> - </schema> -</schemalist> diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/org.ukui.ukui-flash-disks-pkexec.policy ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/org.ukui.ukui-flash-disks-pkexec.policy --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/org.ukui.ukui-flash-disks-pkexec.policy 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/org.ukui.ukui-flash-disks-pkexec.policy 1970-01-01 08:00:00.000000000 +0800 @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE policyconfig PUBLIC - "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" - "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> -<policyconfig> - <vendor>ukui-flash-disks-pkexec</vendor> - <vendor_url></vendor_url> - <action id="org.freedesktop.pkexec.ukui_flash_disks_pkexec"> - <description>ukui-flash-disks-pkexec</description> - <description xml:lang="zh_CN">ukui-flash-disks-pkexec</description> - <message>Authentication </message> - <message xml:lang="zh_CN">ukui-flash-disks-pkexec</message> - <icon_name>system-file-manager</icon_name> - <defaults> - <allow_any>yes</allow_any> - <allow_inactive>yes</allow_inactive> - <allow_active>yes</allow_active> - </defaults> - <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/ukui-flash-disks-pkexec.sh</annotate> - <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate> - </action> -</policyconfig> diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk.desktop ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk.desktop --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk.desktop 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk.desktop 1970-01-01 08:00:00.000000000 +0800 @@ -1,12 +0,0 @@ -[Desktop Entry] -Name=ukui flash disk -Name[zh_CN]=U盘管理工具 -Comment=Ukui Flash Disk -Comment[zh_CN]=u盘管理工具 -Exec=ukui-flash-disk -Terminal=false -Type=Application -Icon=panel -X-UKUI-AutoRestart=true -OnlyShowIn=UKUI -NoDisplay=true diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk.pro ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk.pro --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk.pro 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk.pro 1970-01-01 08:00:00.000000000 +0800 @@ -1,64 +0,0 @@ -QT += core gui KWindowSystem dbus network - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = ukui-flash-disk -TEMPLATE = app - -PKGCONFIG += gio-2.0 gsettings-qt udisks2 -#LIBS +=-lgio-2.0 -lglib-2.0 -CONFIG += c++11 link_pkgconfig no_keywords debug -DEFINES += QT_DEPRECATED_WARNINGS - -#include($$PWD/../QtSingleApplication/qtsinglecoreapplication.pri) - -SOURCES += \ - $$PWD/../main.cpp \ - $$PWD/../mainwindow.cpp \ - $$PWD/../MainController.cpp \ - $$PWD/../device-manager.cpp \ - $$PWD/../device-operation.cpp \ - $$PWD/../repair-dialog-box.cpp \ - $$PWD/../UnionVariable.cpp \ - $$PWD/../qclickwidget.cpp \ - $$PWD/../fdapplication.cpp \ - $$PWD/../clickLabel.cpp \ - $$PWD/../fdframe.cpp \ - $$PWD/../flashdiskdata.cpp \ - $$PWD/../fdclickwidget.cpp \ - $$PWD/../interactivedialog.cpp \ - $$PWD/../ejectInterface.cpp \ - $$PWD/../datacdrom.cpp \ - $$PWD/../QtSingleApplication/qtsingleapplication.cpp \ - $$PWD/../QtSingleApplication/qtlocalpeer.cpp \ -# Removablemount.cpp - - -HEADERS += \ - $$PWD/../device-manager.h \ - $$PWD/../device-operation.h \ - $$PWD/../repair-dialog-box.h \ - $$PWD/../UnionVariable.h \ - $$PWD/../mainwindow.h \ - $$PWD/../MainController.h \ - $$PWD/../clickLabel.h \ - $$PWD/../qclickwidget.h \ - $$PWD/../fdapplication.h \ - $$PWD/../fdframe.h \ - $$PWD/../flashdiskdata.h \ - $$PWD/../fdclickwidget.h \ - $$PWD/../interactivedialog.h \ - $$PWD/../ejectInterface.h \ - $$PWD/../datacdrom.h \ - $$PWD/../QtSingleApplication/qtsingleapplication.h \ - $$PWD/../QtSingleApplication/qtlocalpeer.h \ - $$PWD/../QtSingleApplication/qtlocalpeer.h \ -# Removablemount.h - -FORMS += \ - $$PWD/../mainwindow.ui - -TRANSLATIONS += \ - ukui-flash-disk_tr.ts \ - ukui-flash-disk_zh_CN.ts - Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk_tr.qm and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk_tr.qm differ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk_tr.ts ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk_tr.ts --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk_tr.ts 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk_tr.ts 1970-01-01 08:00:00.000000000 +0800 @@ -1,277 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.1" language="tr" sourcelanguage="tr"> -<context> - <name>BaseDialog</name> - <message> - <source>Disk test</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>DeviceOperation</name> - <message> - <source>unknown</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>FDClickWidget</name> - <message> - <source>the capacity is empty</source> - <translation>Kapasite boş</translation> - </message> - <message> - <source>blank CD</source> - <translation type="unfinished">blank CD</translation> - </message> - <message> - <source>other user device</source> - <translation type="unfinished">other user device</translation> - </message> - <message> - <source>another device</source> - <translation type="obsolete">another device</translation> - </message> - <message> - <source>Eject</source> - <translation>Çıkar</translation> - </message> - <message> - <source>Unmounted</source> - <translation type="unfinished">Unmounted</translation> - </message> -</context> -<context> - <name>FormateDialog</name> - <message> - <source>Formatted successfully!</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Formatting failed, please unplug the U disk and try again!</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Format</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Rom size:</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Filesystem:</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Disk name:</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Completely erase(Time is longer, please confirm!)</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Cancel</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Format disk</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Formatting this volume will erase all data on it. Please back up all retained data before formatting. Do you want to continue?</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Disk format</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>MainWindow</name> - <message> - <source>usb management tool</source> - <translation>Usb yönetim aracı</translation> - </message> - <message> - <source>kindly reminder</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>wrong reminder</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Please do not pull out the CDROM when reading or writing</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Please do not pull out the SD Card when reading or writing</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Please do not pull out the USB flash disk when reading or writing</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>telephone device</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Please do not pull out the storage device when reading or writing</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Storage device removed</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>MainWindow</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>ukui flash disk</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>MessageBox</name> - <message> - <source>OK</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Cancel</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Format</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>QClickWidget</name> - <message> - <source>eject</source> - <translation type="vanished">Çıkar</translation> - </message> - <message> - <source>the capacity is empty</source> - <translation>Kapasite boş</translation> - </message> - <message> - <source>Unmounted</source> - <translation type="unfinished">Unmounted</translation> - </message> - <message> - <source>blank CD</source> - <translation type="unfinished">blank CD</translation> - </message> - <message> - <source>other user device</source> - <translation type="unfinished">other user device</translation> - </message> - <message> - <source>弹出</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>RepairDialogBox</name> - <message> - <source>Disk test</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Format disk</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Repair</source> - <translation type="unfinished"></translation> - </message> - <message> - <source><h4>The system could not recognize the disk contents</h4><p>Check that the disk/drive is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.</p></source> - <translation type="unfinished"></translation> - </message> - <message> - <source><h4>The system could not recognize the disk contents</h4><p>Check that the disk/drive '%1' is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.</p></source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>RepairProgressBar</name> - <message> - <source><h3>%1</h3></source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Attempting a disk repair...</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Cancel</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Repair successfully!</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Disk repair</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>Repair failed. If the USB flash disk is not mounted, please try formatting the device!</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>ejectInterface</name> - <message> - <source>usb has been unplugged safely</source> - <translation type="vanished">USB güvenli bir şekilde çıkarıldı</translation> - </message> - <message> - <source>Storage device can be safely unplugged</source> - <translation type="unfinished"></translation> - </message> -</context> -<context> - <name>interactiveDialog</name> - <message> - <source>cdrom is occupying,do you want to eject it</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>sd is occupying,do you want to eject it</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>usb is occupying,do you want to eject it</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>cancle</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>yes</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>cdrom is occupying</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>sd is occupying</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>usb is occupying</source> - <translation type="unfinished"></translation> - </message> -</context> -</TS> Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk_zh_CN.qm and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk_zh_CN.qm differ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk_zh_CN.ts ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk_zh_CN.ts --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disk_zh_CN.ts 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disk_zh_CN.ts 1970-01-01 08:00:00.000000000 +0800 @@ -1,324 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.1" language="zh_CN"> -<context> - <name>BaseDialog</name> - <message> - <source>Disk test</source> - <translation>设备检测</translation> - </message> -</context> -<context> - <name>DeviceOperation</name> - <message> - <source>unknown</source> - <translation>未知</translation> - </message> -</context> -<context> - <name>FDClickWidget</name> - <message> - <source>the capacity is empty</source> - <translation>容量为空</translation> - </message> - <message> - <source>blank CD</source> - <translation>空光盘</translation> - </message> - <message> - <source>other user device</source> - <translation>其它用户设备</translation> - </message> - <message> - <source>another device</source> - <translation type="obsolete">其它设备</translation> - </message> - <message> - <source>Eject</source> - <translation>弹出</translation> - </message> - <message> - <source>Unmounted</source> - <translation>未装载</translation> - </message> -</context> -<context> - <name>FormateDialog</name> - <message> - <source>Formatted successfully!</source> - <translation>格式化成功</translation> - </message> - <message> - <source>Formatting failed, please unplug the U disk and try again!</source> - <translation>格式化失败,请拔出设备并重试!</translation> - </message> - <message> - <source>Format</source> - <translation>格式化</translation> - </message> - <message> - <source>Rom size:</source> - <translation>容量:</translation> - </message> - <message> - <source>Filesystem:</source> - <translation>文件系统:</translation> - </message> - <message> - <source>Disk name:</source> - <translation>分区名:</translation> - </message> - <message> - <source>Completely erase(Time is longer, please confirm!)</source> - <translation>完全擦除(耗时长,请确认!)</translation> - </message> - <message> - <source>Cancel</source> - <translation>取消</translation> - </message> - <message> - <source>Format disk</source> - <translation>格式化</translation> - </message> - <message> - <source>Formatting this volume will erase all data on it. Please back up all retained data before formatting. Do you want to continue?</source> - <translation>格式化将清除卷上所有数据,请在格式化操作前备份好数据。确定继续格式化?</translation> - </message> - <message> - <source>Disk test</source> - <translation type="obsolete">U盘检测</translation> - </message> - <message> - <source>Disk format</source> - <translation>设备格式化</translation> - </message> -</context> -<context> - <name>MainWindow</name> - <message> - <source>usb management tool</source> - <translation>U盘管理工具</translation> - </message> - <message> - <source>ukui-flash-disk</source> - <translation type="vanished">U盘管理工具</translation> - </message> - <message> - <source>kindly reminder</source> - <translation>温馨提示</translation> - </message> - <message> - <source>wrong reminder</source> - <translation>错误提示</translation> - </message> - <message> - <source>Please do not pull out the USB flash disk when reading or writing</source> - <translation>设备读写时请不要直接拔出</translation> - </message> - <message> - <source>Please do not pull out the CDROM when reading or writing</source> - <translation>光盘读写时请不要直接拔出</translation> - </message> - <message> - <source>Please do not pull out the SD Card when reading or writing</source> - <translation>SD卡读写时请不要直接拔出</translation> - </message> - <message> - <source>There is a problem with this device</source> - <translation type="obsolete">此设备存在问题</translation> - </message> - <message> - <source>telephone device</source> - <translation>手机设备</translation> - </message> - <message> - <source>Removable storage device removed</source> - <translation type="vanished">移动存储设备已移除</translation> - </message> - <message> - <source>Please do not pull out the storage device when reading or writing</source> - <translation>存储设备读写时请不要直接拔出</translation> - </message> - <message> - <source>Storage device removed</source> - <translation>存储设备已移除</translation> - </message> - <message> - <source>MainWindow</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>ukui flash disk</source> - <translation>U盘管理工具</translation> - </message> -</context> -<context> - <name>MessageBox</name> - <message> - <source>OK</source> - <translation>确认</translation> - </message> - <message> - <source>Cancel</source> - <translation>取消</translation> - </message> - <message> - <source>Format</source> - <translation>格式化</translation> - </message> -</context> -<context> - <name>QClickWidget</name> - <message> - <source>the capacity is empty</source> - <translation>容量为空</translation> - </message> - <message> - <source>blank CD</source> - <translation>空光盘</translation> - </message> - <message> - <source>other user device</source> - <translation>其它用户设备</translation> - </message> - <message> - <source>another device</source> - <translation type="obsolete">其它设备</translation> - </message> - <message> - <source>Unmounted</source> - <translation>未装载</translation> - </message> - <message> - <source>弹出</source> - <translation></translation> - </message> -</context> -<context> - <name>RepairDialogBox</name> - <message> - <source>Disk test</source> - <translation>设备检测</translation> - </message> - <message> - <source><h4>The system could not recognize the disk contents</h4><p>Check that the disk and drive are properly connected, make sure the disk is not a read-only disk, and try again. For more information, search for help on read-only files and how to change read-only files.</p></source> - <translation type="vanished"><h4>系统无法识别U盘内容</h4><p>检查磁盘和驱动器是否正确连接,确保磁盘不是只读磁盘,然后重试。有关更多信息,请搜索有关只读文件和如何更改只读文件的帮助。</p></translation> - </message> - <message> - <source>Format disk</source> - <translation>格式化设备</translation> - </message> - <message> - <source>Repair</source> - <translation>修复</translation> - </message> - <message> - <source><h4>The system could not recognize the disk contents</h4><p>Check that the disk/drive is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.</p></source> - <translation><h4>系统无法识别移动设备内容</h4><p>检查磁盘/驱动器是否正确连接,确保磁盘不是只读磁盘,然后重试。有关更多信息,请搜索有关只读文件和如何更改只读文件的帮助。</p></translation> - </message> - <message> - <source><h4>The system could not recognize the disk contents</h4><p>Check that the disk/drive '%1' is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.</p></source> - <translation><h4>系统无法识别移动设备内容</h4><p>检查磁盘/驱动器 "%1" 是否正确连接,确保磁盘不是只读磁盘,然后重试。有关更多信息,请搜索有关只读文件和如何更改只读文件的帮助。</p></translation> - </message> -</context> -<context> - <name>RepairProgressBar</name> - <message> - <source><h3>%1</h3></source> - <translation><h3>%1</h3></translation> - </message> - <message> - <source>Attempting a disk repair...</source> - <translation>正在尝试修复设备...</translation> - </message> - <message> - <source>Cancel</source> - <translation>取消</translation> - </message> - <message> - <source>Repair successfully!</source> - <translation>修复成功!</translation> - </message> - <message> - <source>The repair completed. If the USB flash disk is not mounted, please try formatting the device!</source> - <translation type="vanished">修复失败,如果设备没有成功挂载,请尝试格式化修复!</translation> - </message> - <message> - <source>Disk test</source> - <translation type="obsolete">U盘检测</translation> - </message> - <message> - <source>Disk repair</source> - <translation>设备检测</translation> - </message> - <message> - <source>Repair failed. If the USB flash disk is not mounted, please try formatting the device!</source> - <translation>修复失败,如果设备没有成功挂载,请尝试格式化修复!</translation> - </message> -</context> -<context> - <name>ejectInterface</name> - <message> - <source>usb has been unplugged safely</source> - <translation type="vanished">U盘已安全拔出</translation> - </message> - <message> - <source>cdrom has been unplugged safely</source> - <translation type="vanished">光盘已安全拔出</translation> - </message> - <message> - <source>sd has been unplugged safely</source> - <translation type="vanished">SD卡已安全拔出</translation> - </message> - <message> - <source>usb is occupying unejectable</source> - <translation type="vanished">U盘占用无法弹出</translation> - </message> - <message> - <source>Storage device can be safely unplugged</source> - <translation>存储设备可以安全拔出</translation> - </message> -</context> -<context> - <name>gpartedInterface</name> - <message> - <source>ok</source> - <translation type="vanished">确定</translation> - </message> -</context> -<context> - <name>interactiveDialog</name> - <message> - <source>usb is occupying,do you want to eject it</source> - <translation>U盘正在占用中,你想弹出它吗</translation> - </message> - <message> - <source>cdrom is occupying,do you want to eject it</source> - <translation>光盘正在占用中,你想弹出它吗</translation> - </message> - <message> - <source>sd is occupying,do you want to eject it</source> - <translation>SD卡正在占用中,你想弹出它吗</translation> - </message> - <message> - <source>cancle</source> - <translation>取消</translation> - </message> - <message> - <source>yes</source> - <translation>确定</translation> - </message> - <message> - <source>cdrom is occupying</source> - <translation type="unfinished">光盘正在占用中</translation> - </message> - <message> - <source>sd is occupying</source> - <translation type="unfinished">SD卡正在占用中</translation> - </message> - <message> - <source>usb is occupying</source> - <translation type="unfinished">U盘正在占用中</translation> - </message> -</context> -</TS> diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disks-pkexec.sh ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disks-pkexec.sh --- ukui-panel-3.14.0.1/ukui-flash-disk/disk-resources/ukui-flash-disks-pkexec.sh 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/disk-resources/ukui-flash-disks-pkexec.sh 1970-01-01 08:00:00.000000000 +0800 @@ -1,199 +0,0 @@ -#!/bin/bash - -function parseopts() -{ - local opt= optarg= i= shortopts=$1 - local -a longopts=() unused_argv=() - - shift - while [[ $1 && $1 != '--' ]]; do - longopts+=("$1") - shift - done - shift - - longoptmatch() { - local o longmatch=() - for o in "${longopts[@]}"; do - if [[ ${o%:} = "$1" ]]; then - longmatch=("$o") - break - fi - [[ ${o%:} = "$1"* ]] && longmatch+=("$o") - done - - case ${#longmatch[*]} in - 1) - opt=${longmatch%:} - if [[ $longmatch = *: ]]; then - return 1 - else - return 0 - fi ;; - 0) - return 255 ;; - *) - return 254 ;; - esac - } - - while (( $# )); do - case $1 in - --) # explicit end of options - shift - break - ;; - -[!-]*) # short option - for (( i = 1; i < ${#1}; i++ )); do - opt=${1:i:1} - - # option doesn't exist - if [[ $shortopts != *$opt* ]]; then - OPTRET=(--) - return 1 - fi - - OPTRET+=("-$opt") - # option requires optarg - if [[ $shortopts = *$opt:* ]]; then - if (( i < ${#1} - 1 )); then - OPTRET+=("${1:i+1}") - break - elif (( i == ${#1} - 1 )) && [[ "$2" ]]; then - OPTRET+=("$2") - shift - break - # parse failure - else - OPTRET=(--) - return 1 - fi - fi - done - ;; - --?*=*|--?*) # long option - IFS='=' read -r opt optarg <<< "${1#--}" - longoptmatch "$opt" - case $? in - 0) - if [[ $optarg ]]; then - OPTRET=(--) - return 1 - else - OPTRET+=("--$opt") - fi - ;; - 1) - if [[ $optarg ]]; then - OPTRET+=("--$opt" "$optarg") - elif [[ "$2" ]]; then - OPTRET+=("--$opt" "$2" ) - shift - else - printf "%s: 配置选项 '--%s' 需要参数!\n" "${0##*/}" "$opt" - OPTRET=(--) - return 1 - fi - ;; - 254) - OPTRET=(--) - return 1 - ;; - 255) - # parse failure - printf "%s: 未定义的配置选项 '%s'\n" "${0##*/}" "--$opt" - OPTRET=(--) - return 1 - ;; - esac - ;; - *) # non-option arg encountered, add it as a parameter - unused_argv+=("$1") - ;; - esac - shift - done - - # add end-of-opt terminator and any leftover positional parameters - OPTRET+=('--' "${unused_argv[@]}" "$@") - unset longoptmatch - - return 0 -} - - -function cleanup() -{ - exit ${1:-$?} -} - -function usage() -{ - cat <<EOF -使用: ${0##*/} [配置选项] - - 配置选项: - -m, --mount <设备名> 将设备挂载到指定位置 - -p, --point <挂载点> 将设备挂载到指定位置 - -h, --help 显示此帮助信息并退出 - -EOF -} - -function mount_udf_cdrom() -{ - if [[ "x$1" != "x" && "x$2" != "x" ]]; then - [[ ! -d "$2" ]] && mkdir -p "$2" - mount -o nouser "$1" "$2" - fi -} - - -### main -trap 'cleanup 130' INT -trap 'cleanup 143' TERM - -if [ "$#" -lt 1 ]; then - usage - cleanup 1 -fi - -device="" -mountPoint="" - -_opt_short='d:p:h' -_opt_long=('device:' 'point:' 'help') - -parseopts "$_opt_short" "${_opt_long[@]}" -- "$@" || exit 1 -set -- "${OPTRET[@]}" -unset _opt_short _opt_long OPTRET - -while :; do - case $1 in - -d|--device) - shift - # 挂载设备 - device="$1" - ;; - -p|--point) - shift - # 挂载位置 - mountPoint="$1" - ;; - -h|--help) - usage - cleanup 0 - ;; - --) - shift - break 2 - ;; - esac - shift -done - -if [[ "x${device}" != "x" && "x${mountPoint}" != "x" ]]; -then - mount_udf_cdrom "${device}" "${mountPoint}" -fi - diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/ejectInterface.cpp ukui-panel-4.0.0.0/ukui-flash-disk/ejectInterface.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/ejectInterface.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/ejectInterface.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include "ejectInterface.h" -#include <qgsettings.h> -#include <KWindowEffects> -#include "flashdiskdata.h" - -ejectInterface::ejectInterface(QWidget *parent,QString mount_name,int deviceType,QString strDevId) : QWidget(parent),eject_image_label(nullptr),show_text_label(nullptr), - mount_name_label(nullptr) -{ - initFontSetting(); - getFontSize(); - -//interface layout - this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); - EjectScreen = qApp->primaryScreen(); - eject_image_label = new QLabel(this); - eject_image_label->setFixedSize(24,24); - //QPixmap pixmap("kylin-media-removable-symbolic"); - QString strNoraml = ""; - QString strIcon = FlashDiskData::getInstance()->getVolumeIcon(strDevId); - eject_image_icon = QIcon::fromTheme(strIcon); - strNoraml = mount_name; - if (eject_image_icon.isNull()) { - eject_image_icon = QIcon::fromTheme("kylin-media-removable-symbolic"); - } - QPixmap pixmap = eject_image_icon.pixmap(QSize(24, 24)); - eject_image_label->setPixmap(pixmap); - //add it to show the eject button - - show_text_label = new QLabel(this); - show_text_label->setFixedSize(192, 36); - show_text_label->setFont(QFont("Noto Sans CJK SC",fontSize)); - show_text_label->setAlignment(Qt::AlignHCenter); - QString normalShow = getElidedText(show_text_label->font(),strNoraml,192); - //add the text of the eject interface - show_text_label->setText(normalShow); - if (strNoraml != normalShow) { - show_text_label->setToolTip(strNoraml); - } - - ejectinterface_h_BoxLayout = new QHBoxLayout(); - ejectinterface_h_BoxLayout->setContentsMargins(0,0,0,0); - ejectinterface_h_BoxLayout->setSpacing(8); - ejectinterface_h_BoxLayout->addWidget(eject_image_label,0,Qt::AlignLeft|Qt::AlignTop); - ejectinterface_h_BoxLayout->addWidget(show_text_label,0,Qt::AlignHCenter|Qt::AlignTop); - - QHBoxLayout *ejectTipLayout = new QHBoxLayout(); - ejectTipLayout->setContentsMargins(0,0,0,0); - ejectTipLayout->setSpacing(0); - QLabel *ejectTip = new QLabel(); - ejectTip->setText(tr("Storage device can be safely unplugged")); - ejectTip->setAlignment(Qt::AlignHCenter|Qt::AlignTop); - ejectTip->setWordWrap(true); - ejectTipLayout->addWidget(ejectTip,0,Qt::AlignHCenter|Qt::AlignTop); - - main_V_BoxLayput = new QVBoxLayout; - main_V_BoxLayput->setContentsMargins(8,8,8,8); - main_V_BoxLayput->setSpacing(0); - main_V_BoxLayput->addLayout(ejectinterface_h_BoxLayout); - main_V_BoxLayput->addLayout(ejectTipLayout); - main_V_BoxLayput->addStretch(); - - QString strTipShow = getElidedText(ejectTip->font(),ejectTip->text(),224); - if (strTipShow != ejectTip->text()) { - this->setFixedSize(240,120); - } else { - this->setFixedSize(240,90); - } - this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); - this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 - this->setAttribute(Qt::WA_DeleteOnClose); //设置窗口关闭时自动销毁 - - this->setLayout(main_V_BoxLayput); - - //set the main signal-slot function to complete the eject interface to let it disappear automatically - interfaceHideTime = new QTimer(this); - interfaceHideTime->setTimerType(Qt::PreciseTimer); - connect(interfaceHideTime, SIGNAL(timeout()), this, SLOT(on_interface_hide())); - interfaceHideTime->start(1000); - moveEjectInterfaceRight(); - initTransparentState(); - this->getTransparentData(); -} - -ejectInterface::~ejectInterface() -{ - if (m_transparency_gsettings) { - delete m_transparency_gsettings; - m_transparency_gsettings = nullptr; - } - if (fontSettings) { - delete fontSettings; - fontSettings = nullptr; - } -} - -//If the fillet does not take effect -void ejectInterface::paintEvent(QPaintEvent *event) - { - QPainterPath path; - auto rect = this->rect(); - rect.adjust(1, 1, -1, -1); - path.addRoundedRect(rect, 6, 6); - setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon())); - - QStyleOption opt; - opt.init(this); - QPainter p(this); - QRect rectReal = this->rect(); - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - p.setBrush(opt.palette.color(QPalette::Base)); - p.setOpacity(m_transparency); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rectReal, 6, 6); - QWidget::paintEvent(event); - - KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); - } - -//slot function to hide eject interface -void ejectInterface::on_interface_hide() -{ - this->hide(); - this->deleteLater(); -} - -//set the location of the eject interface -void ejectInterface::moveEjectInterfaceRight() -{ -// if(EjectScreen->availableGeometry().x() == EjectScreen->availableGeometry().y() && EjectScreen->availableSize().height() < EjectScreen->size().height()) -// { -// qDebug()<<"the position of panel is down"; -// this->move(EjectScreen->availableGeometry().x() + EjectScreen->size().width() - -// this->width() - DistanceToPanel,EjectScreen->availableGeometry().y() + -// EjectScreen->availableSize().height() - this->height() - DistanceToPanel); -// } - -// if(EjectScreen->availableGeometry().x() < EjectScreen->availableGeometry().y() && EjectScreen->availableSize().height() < EjectScreen->size().height()) -// { -// qDebug()<<"this position of panel is up"; -// this->move(EjectScreen->availableGeometry().x() + EjectScreen->size().width() - -// this->width() - DistanceToPanel,EjectScreen->availableGeometry().y()); -// } - -// if(EjectScreen->availableGeometry().x() > EjectScreen->availableGeometry().y() && EjectScreen->availableSize().width() < EjectScreen->size().width()) -// { -// qDebug()<<"this position of panel is left"; -// this->move(EjectScreen->availableGeometry().x() + DistanceToPanel,EjectScreen->availableGeometry().y() -// + EjectScreen->availableSize().height() - this->height()); -// } - -// if(EjectScreen->availableGeometry().x() == EjectScreen->availableGeometry().y() && EjectScreen->availableSize().width() < EjectScreen->size().width()) -// { -// qDebug()<<"this position of panel is right"; -// this->move(EjectScreen->availableGeometry().x() + EjectScreen->availableSize().width() - -// DistanceToPanel - this->width(),EjectScreen->availableGeometry().y() + -// EjectScreen->availableSize().height() - (this->height())*(DistanceToPanel - 1)); -// } - -//show the ejectinterface by primaryscreen() - int position=0; - int panelSize=0; - if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit())) - { - QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit()); - if(gsetting->keys().contains(QString("panelposition"))) - position=gsetting->get("panelposition").toInt(); - else - position=0; - if(gsetting->keys().contains(QString("panelsize"))) - panelSize=gsetting->get("panelsize").toInt(); - else - panelSize=SmallPanelSize; - } - else - { - position=0; - panelSize=SmallPanelSize; - } - - int x=QApplication::primaryScreen()->geometry().x(); - int y=QApplication::primaryScreen()->geometry().y(); - - if(position==0) - this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width(),y+QApplication::primaryScreen()->geometry().height()-panelSize-this->height(),this->width(),this->height())); - else if(position==1) - this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width(),y+panelSize,this->width(),this->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show - else if(position==2) - this->setGeometry(QRect(x+panelSize,y + QApplication::primaryScreen()->geometry().height() - this->height(),this->width(),this->height())); - else - this->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-this->width(),y + QApplication::primaryScreen()->geometry().height() - this->height(),this->width(),this->height())); -} - -int ejectInterface::getPanelPosition(QString str) -{ - QDBusInterface interface( "com.ukui.panel.desktop", - "/", - "com.ukui.panel.desktop", - QDBusConnection::sessionBus() ); - QDBusReply<int> reply = interface.call("GetPanelPosition", str); - - return reply; -} - -/* - use the dbus to get the height of the panel -*/ -int ejectInterface::getPanelHeight(QString str) -{ - QDBusInterface interface( "com.ukui.panel.desktop", - "/", - "com.ukui.panel.desktop", - QDBusConnection::sessionBus() ); - QDBusReply<int> reply = interface.call("GetPanelSize", str); - return reply; -} - -void ejectInterface::initTransparentState() -{ - const QByteArray idtrans(THEME_QT_TRANS); - - if(QGSettings::isSchemaInstalled(idtrans)) - { - m_transparency_gsettings = new QGSettings(idtrans); - } -} - -void ejectInterface::getTransparentData() -{ - if (!m_transparency_gsettings) - { - m_transparency = 0.95; - return; - } - - QStringList keys = m_transparency_gsettings->keys(); - if (keys.contains("transparency")) - { - m_transparency = m_transparency_gsettings->get("transparency").toDouble(); - } - -} - -void ejectInterface::initFontSetting() -{ - const QByteArray id(THEME_QT_SCHEMA); - - if(QGSettings::isSchemaInstalled(id)) - { - fontSettings = new QGSettings(id); - } -} - -void ejectInterface::getFontSize() -{ - - if (!fontSettings) - { - fontSize = 11; - return; - } - - QStringList keys = fontSettings->keys(); - if (keys.contains("systemFont") || keys.contains("systemFontSize")) - { - fontSize = fontSettings->get("system-font").toInt(); - } -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/ejectInterface.h ukui-panel-4.0.0.0/ukui-flash-disk/ejectInterface.h --- ukui-panel-3.14.0.1/ukui-flash-disk/ejectInterface.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/ejectInterface.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef EJECTINTERFACE_H -#define EJECTINTERFACE_H -#include <QWidget> -#include <QtWidgets> -#include <QLabel> -#include <QBoxLayout> -#include <QIcon> -#include <QMouseEvent> -#include <QPaintEvent> -#include <QStyle> -#include <QStyleOption> -#include <QPainter> -#include <QPainterPath> -#include <QTimer> -#include <QApplication> -#include <QScreen> -#include <QDebug> -#include <QPushButton> -#include <QtDBus/QDBusConnection> -#include <QtDBus/QDBusMessage> -#include <QtDBus/QDBusInterface> -#include <QtDBus/QDBusObjectPath> -#include <QDBusReply> -#include <qgsettings.h> - - -#include "MacroFile.h" -#include "UnionVariable.h" - -QT_BEGIN_NAMESPACE -namespace Ui { class ejectInterface; } -QT_END_NAMESPACE -class ejectInterface : public QWidget -{ - Q_OBJECT -public: - ejectInterface(QWidget *parent,QString name,int typeDevice,QString strDevId); - ~ejectInterface(); - int getPanelPosition(QString str); - int getPanelHeight(QString str); - void initTransparentState(); - void getTransparentData(); - void initFontSetting(); - void getFontSize(); - -private: - QLabel *eject_image_label; - QIcon eject_image_icon; - QLabel *show_text_label; - QLabel *mount_name_label; - QHBoxLayout *ejectinterface_h_BoxLayout; - QHBoxLayout *mountname_h_BoxLayout; - QVBoxLayout *main_V_BoxLayput; - QTimer *interfaceHideTime; - QScreen *EjectScreen; - - double m_transparency; - int fontSize; - QGSettings *m_transparency_gsettings = nullptr; - QGSettings *fontSettings = nullptr; - - -private Q_SLOTS: - void on_interface_hide(); -protected: - void paintEvent(QPaintEvent *event); -private: - void moveEjectInterfaceRight(); - -}; - -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/fdapplication.cpp ukui-panel-4.0.0.0/ukui-flash-disk/fdapplication.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/fdapplication.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/fdapplication.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "fdapplication.h" - -FDApplication::FDApplication(int &argc, char **argv) - : QtSingleApplication(argc, argv) -{ - -} - -FDApplication::FDApplication(const QString &id, int &argc, char **argv) - : QtSingleApplication(id, argc, argv) -{ - -} - -FDApplication::~FDApplication() -{ - -} - -bool FDApplication::notify(QObject* obj, QEvent *event) -{ - Q_EMIT notifyWnd(obj, event); - return QtSingleApplication::notify(obj, event); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/fdapplication.h ukui-panel-4.0.0.0/ukui-flash-disk/fdapplication.h --- ukui-panel-3.14.0.1/ukui-flash-disk/fdapplication.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/fdapplication.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __FDAPPLICATION_H__ -#define __FDAPPLICATION_H__ - -#include "QtSingleApplication/qtsingleapplication.h" - -#include <QApplication> -#include <QDebug> - -class FDApplication : public QtSingleApplication -{ - Q_OBJECT -public: - FDApplication(int &argc, char **argv); - FDApplication(const QString &id, int &argc, char **argv); - virtual ~FDApplication(); - - bool notify(QObject* obj, QEvent *event); - -Q_SIGNALS: - void notifyWnd(QObject* obj, QEvent *event); -}; - -#endif // __FDAPPLICATION_H__ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/fdclickwidget.cpp ukui-panel-4.0.0.0/ukui-flash-disk/fdclickwidget.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/fdclickwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/fdclickwidget.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,463 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "fdclickwidget.h" -#include "MacroFile.h" -#include <KWindowEffects> -#include <QFontMetrics> -#include "flashdiskdata.h" -#include "UnionVariable.h" - -FDClickWidget::FDClickWidget(QWidget *parent, - unsigned diskNo, - QString strDriveId, - QString strVolumeId, - QString strMountId, - QString driveName, - QString volumeName, - quint64 capacityDis, - QString strMountUri) - : QWidget(parent), - m_uDiskNo(diskNo), - m_driveName(driveName), - m_volumeName(volumeName), - m_capacityDis(capacityDis), - m_mountUri(strMountUri), - m_driveId(strDriveId), - m_volumeId(strVolumeId), - m_mountId(strMountId) -{ -//union layout -/* - * it's the to set the title interface,we get the drive name and add picture of a u disk -*/ - const QByteArray id(THEME_QT_SCHEMA); - - if(QGSettings::isSchemaInstalled(id)) - { - fontSettings = new QGSettings(id); - } - - const QByteArray idd(THEME_QT_SCHEMA); - - if(QGSettings::isSchemaInstalled(idd)) - { - qtSettings = new QGSettings(idd); - } - - initFontSize(); - initThemeMode(); - - QHBoxLayout *drivename_H_BoxLayout = new QHBoxLayout(); - if (m_uDiskNo <= 1) { - image_show_label = new QLabel(this); - image_show_label->setFocusPolicy(Qt::NoFocus); - image_show_label->installEventFilter(this); - //to get theme picture for label - #if IFDISTINCT_DEVICON - QString strDevId = m_driveId.isEmpty()?m_volumeId:m_driveId; - QString strIcon = FlashDiskData::getInstance()->getVolumeIcon(strDevId); - imgIcon = QIcon::fromTheme(strIcon); - if (imgIcon.isNull()) { - imgIcon = QIcon::fromTheme("drive-removable-media-usb"); - } - #else - imgIcon = QIcon::fromTheme("drive-removable-media-usb"); - #endif - QPixmap pixmap = imgIcon.pixmap(QSize(24, 24)); - image_show_label->setPixmap(pixmap); - image_show_label->setFixedSize(30,30); - m_driveName_label = new QLabel(this); - m_driveName_label->setFont(QFont("Noto Sans CJK SC",fontSize)); - QString DriveName = getElidedText(m_driveName_label->font(), m_driveName, 180); - m_driveName_label->setText(DriveName); - if (DriveName != m_driveName) { - m_driveName_label->setToolTip(m_driveName); - } - m_driveName_label->setFixedWidth(180); - m_driveName_label->setObjectName("driveNameLabel"); - - m_eject_button = new QPushButton(this); - m_eject_button->setProperty("useIconHighlightEffect", 0x2); - m_eject_button->setProperty("useButtonPalette", true); - m_eject_button->setFlat(true); //this property set that when the mouse is hovering in the icon the icon will move up a litte - m_eject_button->move(m_eject_button->x()+234,m_eject_button->y()); - //m_eject_button->installEventFilter(this); - m_eject_button->setIcon(QIcon::fromTheme("media-eject-symbolic")); - m_eject_button->setFixedSize(36,36); - m_eject_button->setToolTip(tr("Eject")); - connect(m_eject_button,SIGNAL(clicked()),SLOT(switchWidgetClicked())); // this signal-slot function is to emit a signal which - //is to trigger a slot in mainwindow - drivename_H_BoxLayout->setContentsMargins(0,0,0,0); - drivename_H_BoxLayout->addSpacing(8); - drivename_H_BoxLayout->addWidget(image_show_label); - drivename_H_BoxLayout->addWidget(m_driveName_label); - drivename_H_BoxLayout->addStretch(); - } - - QVBoxLayout *main_V_BoxLayout = new QVBoxLayout(this); - main_V_BoxLayout->setContentsMargins(6, 0, 6, 0); - //main_V_BoxLayout->setMargin(0); - disWidgetNumOne = new QWidget(this); - QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis1_label = new ClickLabel(disWidgetNumOne); - m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - handleVolumeLabelForFat32Me(m_volumeName, m_volumeId); - QString VolumeName = getElidedText(m_nameDis1_label->font(), m_volumeName, 120); - m_nameDis1_label->adjustSize(); - m_nameDis1_label->setText("- "+VolumeName+":"); - if (m_volumeName != VolumeName) { - m_nameDis1_label->setToolTip(m_volumeName); - } - m_capacityDis1_label = new QLabel(disWidgetNumOne); - - QString str_capacityDis1 = size_human(m_capacityDis); - m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis1_label->setText("("+str_capacityDis1+")"); - m_capacityDis1_label->setObjectName("capacityLabel"); - onevolume_h_BoxLayout->setSpacing(0); - onevolume_h_BoxLayout->addSpacing(50); - onevolume_h_BoxLayout->setMargin(0); //使得widget上的label得以居中显示 - onevolume_h_BoxLayout->addWidget(m_nameDis1_label); - onevolume_h_BoxLayout->addWidget(m_capacityDis1_label); - onevolume_h_BoxLayout->addSpacing(10); - onevolume_h_BoxLayout->addStretch(); - - disWidgetNumOne->setObjectName("OriginObjectOnly"); - disWidgetNumOne->setLayout(onevolume_h_BoxLayout); - disWidgetNumOne->installEventFilter(this); - disWidgetNumOne->setFixedHeight(30); - main_V_BoxLayout->addLayout(drivename_H_BoxLayout); - if (m_mountUri.isEmpty()) { - m_capacityDis1_label->setText(tr("Unmounted")); - } - main_V_BoxLayout->addWidget(disWidgetNumOne); - this->setLayout(main_V_BoxLayout); - if (m_uDiskNo <= 1) { - this->setFixedSize(276,64); - } else { - this->setFixedSize(276,36); - } - this->setAttribute(Qt::WA_TranslucentBackground, true); - // check capacity lable width - m_strCapacityDis = m_capacityDis1_label->text(); - int nNameWidth = m_nameDis1_label->fontMetrics().boundingRect(m_nameDis1_label->text()).width(); - QString strCapacity = getElidedText(m_capacityDis1_label->font(), m_strCapacityDis, 210-nNameWidth); - if (strCapacity != m_strCapacityDis) { - m_capacityDis1_label->setText(strCapacity); - m_capacityDis1_label->setToolTip(m_strCapacityDis); - } - connect(this, &FDClickWidget::themeFontChange, this, &FDClickWidget::onThemeFontChange); -} - -void FDClickWidget::initFontSize() -{ - if (!fontSettings) - { - fontSize = 11; - return; - } - connect(fontSettings,&QGSettings::changed,[=](QString key) - { - if("systemFont" == key || "systemFontSize" == key) - { - fontSize = fontSettings->get(FONT_SIZE).toString().toFloat(); - Q_EMIT themeFontChange(fontSize); - } - }); - - QStringList keys = fontSettings->keys(); - if (keys.contains("systemFont") || keys.contains("systemFontSize")) - { - fontSize = fontSettings->get(FONT_SIZE).toInt(); - } -} - -void FDClickWidget::onThemeFontChange(qreal lfFontSize) -{ -} - -void FDClickWidget::initThemeMode() -{ - if(!qtSettings) - { - currentThemeMode = "ukui-white"; - } - QStringList keys = qtSettings->keys(); - if(keys.contains("styleName")) - { - currentThemeMode = qtSettings->get("style-name").toString(); - } -} - -FDClickWidget::~FDClickWidget() -{ - if(chooseDialog) - delete chooseDialog; - if(gpartedface) - delete gpartedface; - if (fontSettings) { - delete fontSettings; - fontSettings = nullptr; - } - if (qtSettings) { - delete qtSettings; - qtSettings = nullptr; - } -} - -void FDClickWidget::mousePressEvent(QMouseEvent *ev) -{ - mousePos = QPoint(ev->x(), ev->y()); -} - -void FDClickWidget::mouseReleaseEvent(QMouseEvent *ev) -{ - if(mousePos == QPoint(ev->x(), ev->y())) Q_EMIT clicked(); -} - -//click the first area to show the interface -void FDClickWidget::on_volume_clicked() -{ - if (!m_mountUri.isEmpty()) { - QString aaa = "peony "+m_mountUri; - QProcess::startDetached(aaa.toUtf8().data()); - this->topLevelWidget()->hide(); - } -} - -void FDClickWidget::switchWidgetClicked() -{ - EjectDeviceInfo eDeviceInfo; - eDeviceInfo.strDriveId = m_driveId; - eDeviceInfo.strDriveName = m_driveName; - eDeviceInfo.strVolumeId = m_volumeId; - eDeviceInfo.strVolumeName = m_volumeName; - eDeviceInfo.strMountId = m_mountId; - eDeviceInfo.strMountUri = m_mountUri; - Q_EMIT clickedEject(eDeviceInfo); -} - -QPixmap FDClickWidget::drawSymbolicColoredPixmap(const QPixmap &source) -{ - if(currentThemeMode == "ukui-light" || currentThemeMode == "ukui-white") - { - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) - { - for (int y = 0; y < img.height(); y++) - { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) - { - color.setRed(0); - color.setGreen(0); - color.setBlue(0); - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); - } - - else if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" ) - { - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) - { - for (int y = 0; y < img.height(); y++) - { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) - { - color.setRed(255); - color.setGreen(255); - color.setBlue(255); - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); - } - - else - { - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) - { - for (int y = 0; y < img.height(); y++) - { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) - { - color.setRed(0); - color.setGreen(0); - color.setBlue(0); - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); - } -} - -//to convert the capacity by another type -QString FDClickWidget::size_human(qlonglong capacity) -{ - // float capacity = this->size(); - if(capacity > 1) - { - int conversionNum = 0; - QStringList list; - list << "KB" << "MB" << "GB" << "TB"; - - QStringListIterator i(list); - QString unit("B"); - - qlonglong conversion = capacity; - - while(conversion >= 1024.0 && i.hasNext()) - { - unit = i.next(); - conversion /= 1024.0; - conversionNum++; - } - qlonglong remain = capacity - conversion * qPow(1024,conversionNum); - double showRemain = 0.0; - if(conversionNum == 4) { - showRemain = (float)remain /1024/1024/1024/1024; - } else if(conversionNum == 3) { - showRemain = (float)remain /1024/1024/1024; - } else if(conversionNum == 2) { - showRemain = (float)remain /1024/1024; - } else if(conversionNum == 1) { - showRemain = (float)remain /1024; - } - - double showValue = conversion + showRemain; - - QString str2=QString::number(showValue,'f',1); - - QString str_capacity=QString(" %1%2").arg(str2).arg(unit); - return str_capacity; - // return QString().setNum(capacity,'f',2)+" "+unit; - } -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - if(capacity == NULL) - { - QString str_capaticity = tr("the capacity is empty"); - return str_capaticity; - } -#endif - if(capacity == 1) - { - QString str_capacity = tr("blank CD"); - return str_capacity; - } - QString str_capacity = tr("other user device"); - return str_capacity; -} - -//set the style of the eject button and label when the mouse doing some different operations -bool FDClickWidget::eventFilter(QObject *obj, QEvent *event) -{ - if(obj == m_eject_button) - { - if(event->type() == QEvent::MouseButtonPress) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - m_eject_button->setIconSize(QSize(14,14)); - m_eject_button->setFixedSize(38,38); - } - else - { - m_eject_button->setIconSize(QSize(14,14)); - m_eject_button->setFixedSize(38,38); - } - - } - - if(event->type() == QEvent::Enter) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - } - else - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - } - - } - - if(event->type() == QEvent::Leave) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black") - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - } - else - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - } - } - } - - if(obj == disWidgetNumOne) - { - if(event->type() == QEvent::Enter) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" - || currentThemeMode == "ukui") - { - disWidgetNumOne->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);" - "border-radius: 6px;}"); - } - else - { - disWidgetNumOne->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);" - "border-radius: 6px;}"); - } - } - - if(event->type() == QEvent::Leave) - { - disWidgetNumOne->setStyleSheet(""); - } - - if(event->type() == QEvent::MouseButtonPress) - { - on_volume_clicked(); - } - } - return false; -} - -void FDClickWidget::resizeEvent(QResizeEvent *event) -{ -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/fdclickwidget.h ukui-panel-4.0.0.0/ukui-flash-disk/fdclickwidget.h --- ukui-panel-3.14.0.1/ukui-flash-disk/fdclickwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/fdclickwidget.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __FDCLICKWIDGET_H__ -#define __FDCLICKWIDGET_H__ -#include <QWidget> -#include <QProcess> -#include <QDebug> -#include <QMouseEvent> -#include <QPaintEvent> -#include <QStyle> -#include <QStyleOption> -#include <QPainter> -#include <QLabel> -#include <QBoxLayout> -#include <QPushButton> -#include <qgsettings.h> - -#include "ejectInterface.h" -#include "clickLabel.h" -#include "UnionVariable.h" -#include "interactivedialog.h" -#include "gpartedinterface.h" - -typedef struct _EjectDeviceInfo_s -{ - void* pVoid = nullptr; - QString strDriveId = ""; - QString strDriveName = ""; - QString strVolumeId = ""; - QString strVolumeName = ""; - QString strMountId = ""; - QString strMountUri = ""; - unsigned uFlag = 0; -}EjectDeviceInfo; - -class MainWindow; -class FDClickWidget : public QWidget -{ - Q_OBJECT -public: - explicit FDClickWidget(QWidget *parent = nullptr, - unsigned diskNo = 0, - QString strDriveId = "", - QString strVolumeId = "", - QString strMountId = "", - QString driveName = "", - QString volumeName = "", - quint64 capacityDis = 0, - QString strMountUri = ""); - ~FDClickWidget(); - -protected: - void mousePressEvent(QMouseEvent *ev); - void mouseReleaseEvent(QMouseEvent *ev); - -private: - QIcon imgIcon; - unsigned m_uDiskNo; - QString m_driveName; - QString m_volumeName; - quint64 m_capacityDis; - QString m_mountUri; - QString m_driveId; - QString m_volumeId; - QString m_mountId; - MainWindow *m_mainwindow; - QPoint mousePos; - QLabel *image_show_label; - QLabel *m_driveName_label; - ClickLabel *m_nameDis1_label; - QLabel *m_capacityDis1_label; - QWidget *disWidgetNumOne; - - QGSettings *fontSettings = nullptr; - QGSettings *qtSettings = nullptr; - - int fontSize; - QString currentThemeMode; - QString m_strCapacityDis; - -public: - QPushButton *m_eject_button = nullptr; - interactiveDialog *chooseDialog = nullptr; - gpartedInterface *gpartedface = nullptr; - bool ifSucess = false; -Q_SIGNALS: - void clicked(); - void clickedEject(EjectDeviceInfo eDeviceInfo); - void noDeviceSig(); - void themeFontChange(qreal lfFontSize); - -private Q_SLOTS: - void on_volume_clicked(); - void switchWidgetClicked(); - void onThemeFontChange(qreal lfFontSize); - -private: - QString size_human(qlonglong capacity); - QPixmap drawSymbolicColoredPixmap(const QPixmap &source); -protected: - bool eventFilter(QObject *obj, QEvent *event); - void resizeEvent(QResizeEvent *event); -public: - void initFontSize(); - void initThemeMode(); -}; - -#endif // __FDCLICKWIDGET_H__ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/fdframe.cpp ukui-panel-4.0.0.0/ukui-flash-disk/fdframe.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/fdframe.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/fdframe.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include <QPainter> -#include <QStyleOption> -#include <QDebug> -#include <QApplication> -#include <QScreen> -#include <QPainterPath> -#include <KWindowEffects> - -#include "fdframe.h" - -#define THEME_UKFD_TRANS "org.ukui.control-center.personalise" - -FDFrame::FDFrame(QWidget* parent) : QFrame(parent) -{ - setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip); - setAttribute(Qt::WA_AlwaysShowToolTips); - setAttribute(Qt::WA_TranslucentBackground); - //setWindowOpacity(0.8); - initOpacityGSettings(); - KWindowEffects::enableBlurBehind(winId(), true); -} - -FDFrame::~FDFrame() -{ - if (m_gsTransOpacity) { - delete m_gsTransOpacity; - m_gsTransOpacity = nullptr; - } -} - -void FDFrame::initOpacityGSettings() -{ - const QByteArray idtrans(THEME_UKFD_TRANS); - if(QGSettings::isSchemaInstalled(idtrans)) { - m_gsTransOpacity = new QGSettings(idtrans); - } - - if (!m_gsTransOpacity) { - m_curTransOpacity = 1; - return; - } - - connect(m_gsTransOpacity, &QGSettings::changed, this, [=](const QString &key) { - if (key == "transparency") { - QStringList keys = m_gsTransOpacity->keys(); - if (keys.contains("transparency")) { - m_curTransOpacity = m_gsTransOpacity->get("transparency").toString().toDouble(); - repaint(); - } - } - }); - - QStringList keys = m_gsTransOpacity->keys(); - if(keys.contains("transparency")) { - m_curTransOpacity = m_gsTransOpacity->get("transparency").toString().toDouble(); - } -} - -void FDFrame::paintEvent(QPaintEvent * event) -{ - QPainterPath path; - - QPainter painter(this); - painter.setOpacity(m_curTransOpacity); - painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; - painter.setClipping(true); - painter.setPen(Qt::transparent); - - path.addRoundedRect(this->rect(), 12, 12); - path.setFillRule(Qt::WindingFill); - painter.setBrush(this->palette().color(QPalette::Base)); - painter.setPen(Qt::transparent); - - painter.drawPath(path); - QFrame::paintEvent(event); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/fdframe.h ukui-panel-4.0.0.0/ukui-flash-disk/fdframe.h --- ukui-panel-3.14.0.1/ukui-flash-disk/fdframe.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/fdframe.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __FDFRAME_H__ -#define __FDFRAME_H__ - -#include <QFrame> -#include <QPainterPath> -#include <QGSettings> - -class FDFrame : public QFrame -{ - Q_OBJECT -public: - explicit FDFrame(QWidget* parent); - virtual ~FDFrame(); - - void initOpacityGSettings(); - -protected: - void paintEvent(QPaintEvent * event); - -private: - // QGSettings - QGSettings *m_gsTransOpacity = nullptr; - qreal m_curTransOpacity = 1; -}; - -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/flashdiskdata.cpp ukui-panel-4.0.0.0/ukui-flash-disk/flashdiskdata.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/flashdiskdata.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/flashdiskdata.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,591 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include <QDebug> -#include <iostream> -#include <QDateTime> - -using namespace std; - -#include "flashdiskdata.h" - -FlashDiskData* FlashDiskData::m_instance = nullptr; -QMutex FlashDiskData::m_mutex; - -FlashDiskData::FlashDiskData() -{ - m_devInfoWithDrive.clear(); - m_devInfoWithVolume.clear(); - m_devInfoWithMount.clear(); -} - -FlashDiskData::~FlashDiskData() -{ - -} - -FlashDiskData *FlashDiskData::getInstance() -{ - if (m_instance == nullptr) - { - QMutexLocker locker(&m_mutex); - if (m_instance == nullptr) - { - m_instance = new FlashDiskData(); - } - } - return m_instance; -} - -map<string, FDDriveInfo>& FlashDiskData::getDevInfoWithDrive() -{ - return m_devInfoWithDrive; -} - -map<string, FDVolumeInfo>& FlashDiskData::getDevInfoWithVolume() -{ - return m_devInfoWithVolume; -} - -map<string, FDMountInfo>& FlashDiskData::getDevInfoWithMount() -{ - return m_devInfoWithMount; -} - -int FlashDiskData::addDriveInfo(FDDriveInfo driveInfo) -{ - if (driveInfo.strId.empty()) { - return -1; - } - map<string, FDVolumeInfo>::iterator itVolumeInfoNew = driveInfo.listVolumes.begin(); - for (; itVolumeInfoNew != driveInfo.listVolumes.end(); itVolumeInfoNew++) { - if (!itVolumeInfoNew->second.strId.empty()) { - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.find(itVolumeInfoNew->second.strId); - if (itVolumeInfo != m_devInfoWithVolume.end()) { - m_devInfoWithVolume.erase(itVolumeInfo); - } - } - } - m_devInfoWithDrive[driveInfo.strId] = driveInfo; - return 0; -} - -int FlashDiskData::addVolumeInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo) -{ - if (driveInfo.strId.empty() || volumeInfo.strId.empty()) { - return -1; - } - volumeInfo.mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch(); - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.find(volumeInfo.strId); - if (itVolumeInfo != m_devInfoWithVolume.end()) { - m_devInfoWithVolume.erase(itVolumeInfo); - } - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.find(driveInfo.strId); - if (itDriveInfo != m_devInfoWithDrive.end()) { - itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo; - } else { - driveInfo.listVolumes.clear(); - driveInfo.listVolumes[volumeInfo.strId] = volumeInfo; - m_devInfoWithDrive[driveInfo.strId] = driveInfo; - } - return 0; -} - -int FlashDiskData::addMountInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo, FDMountInfo mountInfo) -{ - if (driveInfo.strId.empty() || mountInfo.strId.empty()) { - return -1; - } - mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch(); - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.find(driveInfo.strId); - if (itDriveInfo != m_devInfoWithDrive.end()) { - volumeInfo.mountInfo = mountInfo; - if (volumeInfo.strId.empty()) { - itDriveInfo->second.listVolumes[mountInfo.strId] = volumeInfo; - } else { - itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo; - } - } else { - driveInfo.listVolumes.clear(); - volumeInfo.mountInfo = mountInfo; - if (volumeInfo.strId.empty()) { - driveInfo.listVolumes[mountInfo.strId] = volumeInfo; - } else { - driveInfo.listVolumes[volumeInfo.strId] = volumeInfo; - } - m_devInfoWithDrive[driveInfo.strId] = driveInfo; - } - return 0; -} - -int FlashDiskData::addVolumeInfo(FDVolumeInfo volumeInfo) -{ - if (volumeInfo.strId.empty()) { - return -1; - } - volumeInfo.mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch(); - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - if (itDriveInfo->second.listVolumes.find(volumeInfo.strId) != itDriveInfo->second.listVolumes.end()) { - itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo; - return 1; - } - } - if (!volumeInfo.mountInfo.strId.empty()) { - map<string, FDMountInfo>::iterator itMountInfo = m_devInfoWithMount.find(volumeInfo.mountInfo.strId); - if (itMountInfo != m_devInfoWithMount.end()) { - m_devInfoWithMount.erase(itMountInfo); - } - } - m_devInfoWithVolume[volumeInfo.strId] = volumeInfo; - return 0; -} - -int FlashDiskData::addMountInfo(FDMountInfo mountInfo) -{ - if (mountInfo.strId.empty()) { - return -1; - } - mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch(); - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - return 1; - } - } - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - return 1; - } - } - } - m_devInfoWithMount[mountInfo.strId] = mountInfo; - return 0; -} - -int FlashDiskData::removeDriveInfo(FDDriveInfo driveInfo) -{ - if (driveInfo.strId.empty()) { - return -1; - } - if (m_devInfoWithDrive.find(driveInfo.strId) != m_devInfoWithDrive.end()) { - if (getAttachedVolumeCount(driveInfo.strId) > 0) { - //Q_EMIT notifyDeviceRemoved(QString::fromStdString(driveInfo.strId)); - } - m_devInfoWithDrive.erase(driveInfo.strId); - return 0; - } - return 1; -} - -int FlashDiskData::removeVolumeInfo(FDVolumeInfo volumeInfo) -{ - if (volumeInfo.strId.empty()) { - return -1; - } - if (m_devInfoWithVolume.find(volumeInfo.strId) != m_devInfoWithVolume.end()) { - if (getAttachedVolumeCount(volumeInfo.strId) == 1) { - //Q_EMIT notifyDeviceRemoved(QString::fromStdString(volumeInfo.strId)); - } - m_devInfoWithVolume.erase(volumeInfo.strId); - return 0; - } else { - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - map<string, FDVolumeInfo>::iterator itVolumeInfo = itDriveInfo->second.listVolumes.find(volumeInfo.strId); - if (itVolumeInfo != itDriveInfo->second.listVolumes.end()) { - if (getAttachedVolumeCount(volumeInfo.strId) == 1) { - //Q_EMIT notifyDeviceRemoved(QString::fromStdString(volumeInfo.strId)); - } - if (itVolumeInfo->second.mountInfo.strId.empty()) { - itDriveInfo->second.listVolumes.erase(volumeInfo.strId); - } else { - itVolumeInfo->second.strId = ""; - } - return 0; - } - } - } - return 1; -} - -int FlashDiskData::removeMountInfo(FDMountInfo mountInfo) -{ - if (mountInfo.strId.empty()) { - return -1; - } - if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) { - m_devInfoWithMount.erase(mountInfo.strId); - return 0; - } else { - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - #if 0 - FDMountInfo mountTemp; - itVolumeInfo->second.mountInfo = mountTemp; - if (itVolumeInfo->second.strId.empty()) { - m_devInfoWithVolume.erase(itVolumeInfo); - } - #else - // if (getAttachedVolumeCount(itVolumeInfo->second.strId) == 1) { - // Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId)); - // } - // m_devInfoWithVolume.erase(itVolumeInfo); - itVolumeInfo->second.mountInfo.strId = ""; - #endif - return 0; - } - } - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - #if 0 - FDMountInfo mountTemp; - itVolumeInfo->second.mountInfo = mountTemp; - if (itVolumeInfo->second.strId.empty()) { - itDriveInfo->second.listVolumes.erase(itVolumeInfo); - } - #else - // if (getAttachedVolumeCount(itVolumeInfo->second.strId) == 1) { - // Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId)); - // } - // itDriveInfo->second.listVolumes.erase(itVolumeInfo); - itVolumeInfo->second.mountInfo.strId = ""; - #endif - return 0; - } - } - } - } - return 1; -} - -bool FlashDiskData::isMountInfoExist(FDMountInfo mountInfo) -{ - if (mountInfo.strId.empty()) { - return false; - } - if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) { - return true; - } - map<string, FDDriveInfo>::iterator itDriveInfo; - map<string, FDVolumeInfo>::iterator itVolumeInfo; - itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - return true; - } - } - itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - return true; - } - } - } - return false; -} - -quint64 FlashDiskData::getMountTickDiff(FDMountInfo mountInfo) -{ - quint64 curTick = QDateTime::currentDateTime().toMSecsSinceEpoch(); - if (mountInfo.strId.empty()) { - return 0; - } - if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) { - return (curTick-m_devInfoWithMount[mountInfo.strId].lluMountTick); - } - map<string, FDDriveInfo>::iterator itDriveInfo; - map<string, FDVolumeInfo>::iterator itVolumeInfo; - itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - return (curTick-itVolumeInfo->second.mountInfo.lluMountTick); - } - } - itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - return (curTick-itVolumeInfo->second.mountInfo.lluMountTick); - } - } - } - return 0; -} - -bool FlashDiskData::getVolumeInfoByMount(FDMountInfo mountInfo, FDVolumeInfo& volumeInfo) -{ - quint64 curTick = QDateTime::currentDateTime().toMSecsSinceEpoch(); - if (mountInfo.strId.empty()) { - return false; - } - if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) { - return false; - } - map<string, FDDriveInfo>::iterator itDriveInfo; - map<string, FDVolumeInfo>::iterator itVolumeInfo; - itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - volumeInfo = itVolumeInfo->second; - return true; - } - } - itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) { - volumeInfo = itVolumeInfo->second; - return true; - } - } - } - return false; -} - -void FlashDiskData::resetAllNewState() -{ - map<string, FDMountInfo>::iterator itMountInfo = m_devInfoWithMount.begin(); - for (; itMountInfo != m_devInfoWithMount.end(); itMountInfo++) { - if (!itMountInfo->second.strId.empty()) { - itMountInfo->second.isNewInsert = false; - } - } - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - itVolumeInfo->second.isNewInsert = false; - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - itVolumeInfo->second.mountInfo.isNewInsert = false; - } - } - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - itVolumeInfo->second.isNewInsert = false; - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - itVolumeInfo->second.mountInfo.isNewInsert = false; - } - } - } -} - -unsigned FlashDiskData::getValidInfoCount() -{ - unsigned uDriveCount = 0; - unsigned uVolumeCount = 0; - unsigned uMountCount = 0; - uMountCount = m_devInfoWithMount.size(); - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - uVolumeCount ++; - } - } - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - uDriveCount ++; - } - } - } - return uDriveCount + uVolumeCount + uMountCount; -} - -unsigned FlashDiskData::getAttachedVolumeCount(string strId) -{ - if (strId.empty()) { - return 0; - } - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.strId == strId) { - return 1; - } - } - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - if (itDriveInfo->second.strId == strId) { - return itDriveInfo->second.listVolumes.size(); - } else { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.strId == strId) { - return itDriveInfo->second.listVolumes.size(); - } - } - } - } - return 0; -} - -static bool strEndsWith(string s, string sub) { - if (s.rfind(sub)==(s.length()-sub.length())) { - return true; - } else { - return false; - } -} - -static bool strStartsWith(string s, string sub) { - if (s.rfind(sub)==(s.length()-sub.length())) { - return true; - } else { - return false; - } -} - -QString FlashDiskData::getVolumeIcon(QString strVolumeId) -{ - QString strVolumeIcon = "drive-removable-media-usb"; - quint64 mountSize = 0; - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - if (itVolumeInfo->second.strId.find(strVolumeId.toStdString()) == 0) { - strVolumeIcon = QString::fromStdString(itVolumeInfo->second.strIconPath); - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - mountSize = itVolumeInfo->second.mountInfo.lluTotalSize; - // if (!itVolumeInfo->second.mountInfo.strIconPath.empty()) { - // if (strEndsWith(itVolumeInfo->second.mountInfo.strIconPath, ".ico")) { - // strVolumeIcon = QString::fromStdString(itVolumeInfo->second.mountInfo.strIconPath); - // } - // } - } - break; - } - } - if (strVolumeIcon == "drive-removable-media-usb") { - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - if (itVolumeInfo->second.strId.find(strVolumeId.toStdString()) == 0) { - strVolumeIcon = QString::fromStdString(itVolumeInfo->second.strIconPath); - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - mountSize = itVolumeInfo->second.mountInfo.lluTotalSize; - // if (!itVolumeInfo->second.mountInfo.strIconPath.empty()) { - // if (strEndsWith(itVolumeInfo->second.mountInfo.strIconPath, ".ico")) { - // strVolumeIcon = QString::fromStdString(itVolumeInfo->second.mountInfo.strIconPath); - // } - // } - } - break; - } - } - } - } - if (strVolumeIcon != "drive-harddisk-usb") { - return strVolumeIcon; - } - if (mountSize/(1024 * 1024 *1024) > 128) - strVolumeIcon = "drive-harddisk-usb"; - else - strVolumeIcon = "drive-removable-media-usb"; - return strVolumeIcon; -} - -void FlashDiskData::clearAllData() -{ - -} - -void FlashDiskData::OutputInfos() -{ - #if 0 - unsigned uDriveCount = 0; - unsigned uVolumeCount = 0; - unsigned uMountCount = 0; - uMountCount = m_devInfoWithMount.size(); - uVolumeCount = m_devInfoWithVolume.size(); - map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - uDriveCount += itDriveInfo->second.listVolumes.size(); - } - qDebug()<<"info count:"<<uDriveCount<<"|"<<uVolumeCount<<"|"<<uMountCount; - qDebug()<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"; - map<string, FDMountInfo>::iterator itMountInfo = m_devInfoWithMount.begin(); - for (; itMountInfo != m_devInfoWithMount.end(); itMountInfo++) { - if (!itMountInfo->second.strId.empty()) { - qDebug()<<"Mount:"<<QString::fromStdString(itMountInfo->second.strId)<<"|" - <<QString::fromStdString(itMountInfo->second.strName)<<"|"<<itMountInfo->second.isCanUnmount - <<"|"<<itMountInfo->second.isCanEject<<"|"<<QString::fromStdString(itMountInfo->second.strTooltip)<<"|" - <<QString::fromStdString(itMountInfo->second.strUri)<<"|"<<itMountInfo->second.isNativeDev - <<"|"<<itMountInfo->second.lluTotalSize<<"|"<<itMountInfo->second.isNewInsert<<"|"<<itMountInfo->second.lluMountTick - <<"|"<<itMountInfo->second.strIconPath.c_str(); - } - } - qDebug()<<"--------------------------------------------------------"; - map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin(); - for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) { - qDebug()<<"Volume:"<<QString::fromStdString(itVolumeInfo->second.strId)<<"|" - <<QString::fromStdString(itVolumeInfo->second.strName)<<"|"<<itVolumeInfo->second.isCanMount - <<"|"<<itVolumeInfo->second.isShouldAutoMount<<"|"<<itVolumeInfo->second.isCanEject - <<"|"<<QString::fromStdString(itVolumeInfo->second.strDevName)<<"|"<<itVolumeInfo->second.isNewInsert - <<"|"<<itVolumeInfo->second.strIconPath.c_str(); - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - qDebug()<<"Mount:"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strId)<<"|" - <<QString::fromStdString(itVolumeInfo->second.mountInfo.strName)<<"|"<<itVolumeInfo->second.mountInfo.isCanUnmount - <<"|"<<itVolumeInfo->second.mountInfo.isCanEject<<"|"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strTooltip)<<"|" - <<QString::fromStdString(itVolumeInfo->second.mountInfo.strUri)<<"|"<<itVolumeInfo->second.mountInfo.isNativeDev - <<"|"<<itVolumeInfo->second.mountInfo.lluTotalSize<<"|"<<itVolumeInfo->second.mountInfo.isNewInsert<<"|" - <<itVolumeInfo->second.mountInfo.lluMountTick<<"|"<<itVolumeInfo->second.mountInfo.strIconPath.c_str(); - } - } - qDebug()<<"--------------------------------------------------------"; - itDriveInfo = m_devInfoWithDrive.begin(); - for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) { - qDebug()<<"Drive:"<<QString::fromStdString(itDriveInfo->second.strId)<<"|" - <<QString::fromStdString(itDriveInfo->second.strName)<<"|"<<itDriveInfo->second.isCanEject - <<"|"<<itDriveInfo->second.isRemovable<<"|"<<itDriveInfo->second.isCanStart<<"|"<<itDriveInfo->second.isCanStop - <<"|"<<itDriveInfo->second.strIconPath.c_str(); - itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - qDebug()<<"Volume:"<<QString::fromStdString(itVolumeInfo->second.strId)<<"|" - <<QString::fromStdString(itVolumeInfo->second.strName)<<"|"<<itVolumeInfo->second.isCanMount - <<"|"<<itVolumeInfo->second.isShouldAutoMount<<"|"<<itVolumeInfo->second.isCanEject - <<"|"<<QString::fromStdString(itVolumeInfo->second.strDevName)<<"|"<<itVolumeInfo->second.isNewInsert - <<"|"<<itVolumeInfo->second.strIconPath.c_str(); - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - qDebug()<<"Mount:"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strId)<<"|" - <<QString::fromStdString(itVolumeInfo->second.mountInfo.strName)<<"|"<<itVolumeInfo->second.mountInfo.isCanUnmount - <<"|"<<itVolumeInfo->second.mountInfo.isCanEject<<"|"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strTooltip)<<"|" - <<QString::fromStdString(itVolumeInfo->second.mountInfo.strUri)<<"|"<<itVolumeInfo->second.mountInfo.isNativeDev - <<"|"<<itVolumeInfo->second.mountInfo.lluTotalSize<<"|"<<itVolumeInfo->second.mountInfo.isNewInsert<<"|" - <<itVolumeInfo->second.mountInfo.lluMountTick<<"|"<<itVolumeInfo->second.mountInfo.strIconPath.c_str(); - } - } - } - qDebug()<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"; - #endif -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/flashdiskdata.h ukui-panel-4.0.0.0/ukui-flash-disk/flashdiskdata.h --- ukui-panel-3.14.0.1/ukui-flash-disk/flashdiskdata.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/flashdiskdata.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Yang Min yangmin@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __FLASHDISKDATA_H__ -#define __FLASHDISKDATA_H__ - -#include <QList> -#include <gio/gio.h> -#include <QString> -#include <QFont> -#include <QFontMetrics> -#include <QTextCodec> -#include <QMutex> -#include <map> -#include <string> - -using namespace std; - -typedef struct FDMountInfo_s { - string strId = ""; - string strName = ""; - bool isCanUnmount = false; - bool isCanEject = false; - string strTooltip = ""; - string strUri = ""; - bool isNativeDev = false; - bool isNewInsert = false; - quint64 lluTotalSize = 0; - quint64 lluMountTick = 0; - string strIconPath = ""; -}FDMountInfo; - -typedef struct FDVolumeInfo_s { - string strId = ""; - string strName = ""; - string strDevName = ""; - bool isCanMount = false; - bool isShouldAutoMount = false; - bool isCanEject = false; - bool isNewInsert = false; - FDMountInfo mountInfo; - string strIconPath = ""; -}FDVolumeInfo; -Q_DECLARE_METATYPE(FDVolumeInfo); - -typedef struct FDDriveInfo_s { - string strId = ""; - string strName = ""; - bool isCanEject = false; - bool isRemovable = false; - bool isCanStart = false; - bool isCanStop = false; - map<string, FDVolumeInfo> listVolumes; - string strIconPath = ""; -}FDDriveInfo; - -class FlashDiskData : public QObject -{ - Q_OBJECT -public: - virtual ~FlashDiskData(); - static FlashDiskData* getInstance(); - map<string, FDDriveInfo>& getDevInfoWithDrive(); - map<string, FDVolumeInfo>& getDevInfoWithVolume(); - map<string, FDMountInfo>& getDevInfoWithMount(); - int addDriveInfo(FDDriveInfo driveInfo); - int addVolumeInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo); - int addMountInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo, FDMountInfo mountInfo); - int addVolumeInfo(FDVolumeInfo volumeInfo); - int addMountInfo(FDMountInfo mountInfo); - int removeDriveInfo(FDDriveInfo driveInfo); - int removeVolumeInfo(FDVolumeInfo volumeInfo); - int removeMountInfo(FDMountInfo mountInfo); - unsigned getValidInfoCount(); - void clearAllData(); - bool isMountInfoExist(FDMountInfo mountInfo); - void resetAllNewState(); - quint64 getMountTickDiff(FDMountInfo mountInfo); - bool getVolumeInfoByMount(FDMountInfo mountInfo, FDVolumeInfo& volumeInfo); - unsigned getAttachedVolumeCount(string strId); - QString getVolumeIcon(QString strVolumeId); - - void OutputInfos(); - -Q_SIGNALS: - void notifyDeviceRemoved(QString strDevId); - -private: - FlashDiskData(); - - static FlashDiskData *m_instance; - static QMutex m_mutex; - - map<string, FDDriveInfo> m_devInfoWithDrive; // - map<string, FDVolumeInfo> m_devInfoWithVolume; // except with drive - map<string, FDMountInfo> m_devInfoWithMount; // except with volume -}; - -#endif // __FLASHDISKDATA_H__ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/gpartedinterface.cpp ukui-panel-4.0.0.0/ukui-flash-disk/gpartedinterface.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/gpartedinterface.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/gpartedinterface.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "gpartedinterface.h" -#include <KWindowEffects> - -gpartedInterface::gpartedInterface(QWidget *parent):QWidget(parent) -{ - this->setFixedSize(300,86); - this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); - this->setAttribute(Qt::WA_TranslucentBackground); - initWidgets(); - moveChooseDialogRight(); - initTransparentState(); - getTransparentData(); -} - -void gpartedInterface::initTransparentState() -{ - const QByteArray idtrans(THEME_QT_TRANS); - - if(QGSettings::isSchemaInstalled(idtrans)) - { - m_transparency_gsettings = new QGSettings(idtrans); - } -} - -void gpartedInterface::getTransparentData() -{ - if (!m_transparency_gsettings) - { - m_transparency = 0.95; - return; - } - - QStringList keys = m_transparency_gsettings->keys(); - if (keys.contains("transparency")) - { - m_transparency = m_transparency_gsettings->get("transparency").toDouble(); - } -} - -void gpartedInterface::initWidgets() -{ - noticeLabel = new QLabel(this); - noticeLabel->setText(tr("gparted has started,can not eject")); - okButton = new QPushButton(tr("ok")); - notice_H_BoxLayout = new QHBoxLayout(); - main_V_BoxLayout = new QVBoxLayout(); - button_H_BoxLayout = new QHBoxLayout(); - notice_H_BoxLayout->addWidget(noticeLabel); - button_H_BoxLayout->addWidget(okButton,1,Qt::AlignRight); - main_V_BoxLayout->addLayout(notice_H_BoxLayout); - main_V_BoxLayout->addLayout(button_H_BoxLayout); - this->setLayout(main_V_BoxLayout); - connect(okButton,SIGNAL(clicked()),this,SLOT(close())); -} - -void gpartedInterface::moveChooseDialogRight() -{ - int position=0; - int panelSize=0; - if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit())) - { - QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit()); - if(gsetting->keys().contains(QString("panelposition"))) - position=gsetting->get("panelposition").toInt(); - else - position=0; - if(gsetting->keys().contains(QString("panelsize"))) - panelSize=gsetting->get("panelsize").toInt(); - else - panelSize=SmallPanelSize; - } - else - { - position=0; - panelSize=SmallPanelSize; - } - - int x=QApplication::primaryScreen()->geometry().x(); - int y=QApplication::primaryScreen()->geometry().y(); - qDebug()<<"QApplication::primaryScreen()->geometry().x();"<<QApplication::primaryScreen()->geometry().x(); - qDebug()<<"QApplication::primaryScreen()->geometry().y();"<<QApplication::primaryScreen()->geometry().y(); - if(position==0) - this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+QApplication::primaryScreen()->geometry().height()-panelSize-this->height() - DISTANCEPADDING,this->width(),this->height())); - else if(position==1) - this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+panelSize + DISTANCEPADDING,this->width(),this->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show - else if(position==2) - this->setGeometry(QRect(x+panelSize + DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height())); - else - this->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-this->width() - DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height())); -} -gpartedInterface::~gpartedInterface() -{ - -} - -void gpartedInterface::paintEvent(QPaintEvent *event) -{ - QPainterPath path; - auto rect = this->rect(); - rect.adjust(1, 1, -1, -1); - path.addRoundedRect(rect, 6, 6); - setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon())); - - QStyleOption opt; - opt.init(this); - QPainter p(this); - QRect rectReal = this->rect(); - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - p.setBrush(opt.palette.color(QPalette::Base)); - p.setOpacity(m_transparency); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rectReal, 6, 6); - QWidget::paintEvent(event); - - KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/gpartedinterface.h ukui-panel-4.0.0.0/ukui-flash-disk/gpartedinterface.h --- ukui-panel-3.14.0.1/ukui-flash-disk/gpartedinterface.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/gpartedinterface.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef GPARTEDINTERFACE_H -#define GPARTEDINTERFACE_H - -#include "MacroFile.h" - -#include <QWidget> -#include <QtWidgets> -#include <QLabel> -#include <QBoxLayout> -#include <QIcon> -#include <QMouseEvent> -#include <QPaintEvent> -#include <QStyle> -#include <QStyleOption> -#include <QPainter> -#include <QPainterPath> -#include <QTimer> -#include <QApplication> -#include <QScreen> -#include <QDebug> -#include <QPushButton> -#include <QLabel> -#include <qgsettings.h> - -QT_BEGIN_NAMESPACE -namespace Ui { class gpartedInterface; } -QT_END_NAMESPACE - -class gpartedInterface: public QWidget -{ - Q_OBJECT -public: - gpartedInterface(QWidget *parent); - ~gpartedInterface(); -private: - double m_transparency; - QGSettings *m_transparency_gsettings = nullptr; - QGSettings *gsetting = nullptr; - - QPushButton *okButton; - QLabel *noticeLabel; - QHBoxLayout *notice_H_BoxLayout = nullptr; - QHBoxLayout *button_H_BoxLayout = nullptr; - QVBoxLayout *main_V_BoxLayout = nullptr; - -private: - void initWidgets(); - void moveChooseDialogRight(); - void initTransparentState(); - void getTransparentData(); -protected: - void paintEvent(QPaintEvent *event); -}; - -#endif //GPARTEDINTERFAC_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/interactivedialog.cpp ukui-panel-4.0.0.0/ukui-flash-disk/interactivedialog.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/interactivedialog.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/interactivedialog.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "interactivedialog.h" -#include <KWindowEffects> - -interactiveDialog::interactiveDialog(QString strDevId, QWidget *parent):QWidget(parent) -{ - this->setFixedSize(300,86); - this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); - - QPainterPath path; - auto rect = this->rect(); - rect.adjust(1, 1, -1, -1); - path.addRoundedRect(rect, 6, 6); - setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon())); - - this->setAttribute(Qt::WA_TranslucentBackground); - initWidgets(strDevId); - connect(chooseBtnCancle,SIGNAL(clicked()),this,SLOT(close())); - connect(chooseBtnContinue,SIGNAL(clicked()),this,SLOT(convert())); - moveChooseDialogRight(); - initTransparentState(); - getTransparentData(); - - KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); -} - -void interactiveDialog::initTransparentState() -{ - const QByteArray idtrans(THEME_QT_TRANS); - - if(QGSettings::isSchemaInstalled(idtrans)) - { - m_transparency_gsettings = new QGSettings(idtrans); - } -} - -void interactiveDialog::getTransparentData() -{ - if (!m_transparency_gsettings) - { - m_transparency = 0.95; - return; - } - - QStringList keys = m_transparency_gsettings->keys(); - if (keys.contains("transparency")) - { - m_transparency = m_transparency_gsettings->get("transparency").toDouble(); - } -} - -void interactiveDialog::initWidgets(QString strDevId) -{ - contentLable = new QLabel(this); - contentLable->setWordWrap(true); - updateContentLable(strDevId); - content_H_BoxLayout = new QHBoxLayout(); - content_H_BoxLayout->addWidget(contentLable, 1, Qt::AlignCenter); - - #ifdef UDISK_SUPPORT_FORCEEJECT - chooseBtnCancle = new QPushButton(); - chooseBtnCancle->setText(tr("cancle")); - chooseBtnCancle->setFlat(true); - - chooseBtnContinue = new QPushButton(); - chooseBtnContinue->setText(tr("yes")); - chooseBtnContinue->setFlat(true); - - chooseBtn_H_BoxLayout = new QHBoxLayout(); - - chooseBtn_H_BoxLayout->addSpacing(70); - chooseBtn_H_BoxLayout->addWidget(chooseBtnCancle); - chooseBtn_H_BoxLayout->addWidget(chooseBtnContinue); - chooseBtn_H_BoxLayout->setSpacing(0); - #else - chooseBtnCancle = new QPushButton(); - chooseBtnCancle->setText(tr("yes")); - chooseBtnCancle->setFlat(true); - - chooseBtnContinue = new QPushButton(); - chooseBtnContinue->hide(); - - chooseBtn_H_BoxLayout = new QHBoxLayout(); - - chooseBtn_H_BoxLayout->addWidget(chooseBtnCancle, 1, Qt::AlignCenter); - chooseBtn_H_BoxLayout->addWidget(chooseBtnContinue); - chooseBtn_H_BoxLayout->setSpacing(0); - #endif - - main_V_BoxLayout = new QVBoxLayout(); - main_V_BoxLayout->addLayout(content_H_BoxLayout); - main_V_BoxLayout->addLayout(chooseBtn_H_BoxLayout); - - this->setLayout(main_V_BoxLayout); -} - -void interactiveDialog::updateContentLable(QString strDevId) -{ - m_strDevId = strDevId; - #ifdef UDISK_SUPPORT_FORCEEJECT - if (m_strDevId.startsWith("/dev/sr")) { - contentLable->setText(tr("cdrom is occupying,do you want to eject it")); - } else if (m_strDevId.startsWith("/dev/mmcblk")) { - contentLable->setText(tr("sd is occupying,do you want to eject it")); - } else { - contentLable->setText(tr("usb is occupying,do you want to eject it")); - } - #else - if (m_strDevId.startsWith("/dev/sr")) { - contentLable->setText(tr("cdrom is occupying")); - } else if (m_strDevId.startsWith("/dev/mmcblk")) { - contentLable->setText(tr("sd is occupying")); - } else { - contentLable->setText(tr("usb is occupying")); - } - #endif -} - -void interactiveDialog::convert() -{ - Q_EMIT FORCESIG(); -} - -void interactiveDialog::moveChooseDialogRight() -{ - int position=0; - int panelSize=0; - if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit())) - { - QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit()); - if(gsetting->keys().contains(QString("panelposition"))) - position=gsetting->get("panelposition").toInt(); - else - position=0; - if(gsetting->keys().contains(QString("panelsize"))) - panelSize=gsetting->get("panelsize").toInt(); - else - panelSize=SmallPanelSize; - } - else - { - position=0; - panelSize=SmallPanelSize; - } - - int x=QApplication::primaryScreen()->geometry().x(); - int y=QApplication::primaryScreen()->geometry().y(); - qDebug()<<"QApplication::primaryScreen()->geometry().x();"<<QApplication::primaryScreen()->geometry().x(); - qDebug()<<"QApplication::primaryScreen()->geometry().y();"<<QApplication::primaryScreen()->geometry().y(); - if(position==0) - this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+QApplication::primaryScreen()->geometry().height()-panelSize-this->height() - DISTANCEPADDING,this->width(),this->height())); - else if(position==1) - this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+panelSize + DISTANCEPADDING,this->width(),this->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show - else if(position==2) - this->setGeometry(QRect(x+panelSize + DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height())); - else - this->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-this->width() - DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height())); -} - -interactiveDialog::~interactiveDialog() -{ - if (m_transparency_gsettings) { - delete m_transparency_gsettings; - m_transparency_gsettings = nullptr; - } - if (gsetting) { - delete gsetting; - gsetting = nullptr; - } -} - -void interactiveDialog::paintEvent(QPaintEvent *event) -{ -// QStyleOption opt; -// opt.init(this); -// QPainter p(this); -// QRect rect = this->rect(); -// p.setRenderHint(QPainter::Antialiasing); // 反锯齿; -// p.setBrush(opt.palette.color(QPalette::Base)); -//// p.setBrush(QColor(Qt::red)); -//// p.setOpacity(m_transparency); -// p.setPen(Qt::NoPen); -// p.drawRoundedRect(rect, 6, 6); -// qDebug()<<__FUNCTION__; -// QStyleOption opt; -// opt.init(this); -// QPainter p(this); -// QRect rect = this->rect(); -// p.setRenderHint(QPainter::Antialiasing); // 反锯齿; -// p.setBrush(opt.palette.color(QPalette::Base)); -// p.setOpacity(m_transparency); -// p.setPen(Qt::NoPen); -// p.drawRoundedRect(rect, 6, 6); -// QWidget::paintEvent(event); - - -// qDebug()<<__FUNCTION__; -// QStyleOption opt; -// opt.init(this); -// QPainter p(this); -// QRect rect = this->rect(); -// p.setRenderHint(QPainter::Antialiasing); // 反锯齿; -// p.setBrush(opt.palette.color(QPalette::Base)); -// p.setOpacity(m_transparency); -// p.setPen(Qt::NoPen); -// p.drawRect(rect); -// QWidget::paintEvent(event); - - -// QStyleOption opt; -// opt.init(this); -// QPainter p(this); -// p.setRenderHint(QPainter::Antialiasing); // 反锯齿; -// p.setBrush(opt.palette.color(QPalette::Base)); -// p.setOpacity(m_transparency); -// QPainterPath path; -// auto rect = this->rect(); -// path.addRoundedRect(rect, 12, 12); -// path.drawRoundedRect -// QRegion region(path.toFillPolygon().toPolygon()); -//// this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 -// KWindowEffects::enableBlurBehind(this->winId(),true,region); -// QWidget::paintEvent(event); - - QStyleOption opt; - opt.init(this); - QPainter p(this); - QRect rect = this->rect(); - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - p.setBrush(opt.palette.color(QPalette::Base)); - p.setOpacity(m_transparency); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rect, 6, 6); - QWidget::paintEvent(event); - -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/interactivedialog.h ukui-panel-4.0.0.0/ukui-flash-disk/interactivedialog.h --- ukui-panel-3.14.0.1/ukui-flash-disk/interactivedialog.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/interactivedialog.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef INTERACTIVEDIALOG_H -#define INTERACTIVEDIALOG_H - -#include "MacroFile.h" - -#include <QWidget> -#include <QtWidgets> -#include <QLabel> -#include <QBoxLayout> -#include <QIcon> -#include <QMouseEvent> -#include <QPaintEvent> -#include <QStyle> -#include <QStyleOption> -#include <QPainter> -#include <QPainterPath> -#include <QTimer> -#include <QApplication> -#include <QScreen> -#include <QDebug> -#include <QPushButton> -#include <qgsettings.h> - -QT_BEGIN_NAMESPACE -namespace Ui { class interactiveDialog; } -QT_END_NAMESPACE - -class interactiveDialog: public QWidget -{ - Q_OBJECT -public: - interactiveDialog(QString strDevId, QWidget *parent); - ~interactiveDialog(); - void updateContentLable(QString strDevId); -private: - QPushButton *chooseBtnContinue = nullptr; - QPushButton *chooseBtnCancle = nullptr; - QLabel *contentLable = nullptr; - QHBoxLayout *content_H_BoxLayout = nullptr; - QHBoxLayout *chooseBtn_H_BoxLayout = nullptr; - QVBoxLayout *main_V_BoxLayout = nullptr; - - double m_transparency; - int fontSize; - QGSettings *m_transparency_gsettings = nullptr; - QGSettings *gsetting = nullptr; - -private: - void initWidgets(QString strDevId); - void moveChooseDialogRight(); - void initTransparentState(); - void getTransparentData(); - -protected: - void paintEvent(QPaintEvent *event); -public Q_SLOTS: - void convert(); -Q_SIGNALS: - void FORCESIG(); - -private: - QString m_strDevId; -}; - -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/main.cpp ukui-panel-4.0.0.0/ukui-flash-disk/main.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/main.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/main.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include <QApplication> -#include <QDebug> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <syslog.h> -#include <QDebug> -#include <QtDBus/QDBusConnection> -#include <QTranslator> -#include <QTextCodec> -#include <ukui-log4qt.h> -#include "UnionVariable.h" -#include "mainwindow.h" -#include "MainController.h" -#include "fdapplication.h" - -int main(int argc, char *argv[]) -{ - initUkuiLog4qt("ukui-flash-disk"); - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); -#endif - - QTextCodec *codec = QTextCodec::codecForName("utf8"); //Linux - QTextCodec::setCodecForLocale(codec); - - QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QString id = QString("ukui-flash-disk_%1_%2").arg(getuid()).arg(QLatin1String(getenv("DISPLAY"))); - FDApplication a(id, argc, argv); - - // Process does not exit implicitly - a.setQuitOnLastWindowClosed(false); - if (a.isRunning()) { - qInfo() << "ukui-flash-disk is running, now exit!"; - return 1; - } - - // load translation file - QString locale = QLocale::system().name(); - QTranslator translator; - if (locale == "zh_CN") { - if (translator.load("/usr/share/ukui/ukui-panel/ukui-flash-disk_zh_CN.qm")) { - qDebug() << "load success"; - a.installTranslator(&translator); - } else { - qDebug() << "Load translations file" << locale << "failed!"; - } - } - - if (QApplication::desktop()->width() >= 2560) { - #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - #endif - } - - MainController *ctrl = MainController::self(); - // single instance is running - if (ctrl->init() != 0) { - return 0; - } - - QObject::connect(&a, &FDApplication::notifyWnd, ctrl, &MainController::notifyWnd); - a.exec(); - - delete ctrl; - return 0; -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/mainwindow.cpp ukui-panel-4.0.0.0/ukui-flash-disk/mainwindow.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/mainwindow.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/mainwindow.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,3332 +0,0 @@ - /* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include <QtDBus/QDBusConnection> -#include <QtDBus/QDBusMessage> -#include <QtDBus/QDBusInterface> -#include <QtDBus/QDBusObjectPath> -#include <QDBusReply> -#include <QSystemTrayIcon> -#include <QTimer> -#include <QColor> -#include <KWindowEffects> -#include <QtConcurrent/QtConcurrent> -#include <QDateTime> -#include <stdio.h> -#include <string.h> -#include <QDebug> -#include "clickLabel.h" -#include "MacroFile.h" -#include "datacdrom.h" - -#if UDFAUTOMOUNT -static void mount_cdrom (GDrive* drive, gpointer u); -static void eject_cdrom (GDrive* drive, gpointer u); - -static QMap<QString, bool>* gMountCdrom = nullptr; -static QMap<QString, QString>* gMountCdromMountPoint = nullptr; -#endif - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent) - , ui(new Ui::MainWindow) - , findPointMount(false) - , telephoneNum(0) - , driveVolumeNum(0) - , m_strSysRootDev(QString("")) -{ - ui->setupUi(this); - - initThemeMode(); - initFlashDisk(); - initSlots(); - installEventFilter(this); - - // get system root device - getSystemRootDev(); - // underlying code to get the information of the usb device - getDeviceInfo(); -} - -MainWindow::~MainWindow() -{ - delete ui; - if (m_transparency_gsettings) { - delete m_transparency_gsettings; - m_transparency_gsettings = nullptr; - } - - if (ifsettings) { - delete ifsettings; - ifsettings = nullptr; - } -} - -void MainWindow::initFlashDisk() -{ - m_vtDeviveId.clear(); - - // 框架的样式设置 - // set the style of the framework - interfaceHideTime = new QTimer(this); - - initTransparentState(); - ui->centralWidget->setObjectName("centralWidget"); - vboxlayout = new QVBoxLayout(this); - ui->centralWidget->setLayout(vboxlayout); - -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - this->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); -#else - this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); -#endif - this->setAttribute(Qt::WA_TranslucentBackground); - - m_systray = new QSystemTrayIcon(this); - m_systray->setIcon(QIcon::fromTheme("drive-removable-media-usb-symbolic")); - //m_systray->setVisible(true); - m_systray->setToolTip(tr("usb management tool")); - - // init the screen - screen = qApp->primaryScreen(); - - m_nAppStartTimestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); - m_dataFlashDisk = FlashDiskData::getInstance(); -} - -void MainWindow::initSlots() -{ - connect(m_systray, &QSystemTrayIcon::activated, this, &MainWindow::iconActivated); - connect(this, &MainWindow::convertShowWindow, this, &MainWindow::onConvertShowWindow); - connect(this, &MainWindow::convertUpdateWindow, this, &MainWindow::onConvertUpdateWindow); - connect(this, &MainWindow::remountVolume, this, &MainWindow::onRemountVolume); - connect(this, &MainWindow::checkDriveValid, this, &MainWindow::onCheckDriveValid); - connect(this, &MainWindow::notifyDeviceRemoved, this, &MainWindow::onNotifyDeviceRemoved); - connect(m_dataFlashDisk, &FlashDiskData::notifyDeviceRemoved, this, &MainWindow::onNotifyDeviceRemoved); - - QDBusConnection::sessionBus().connect(QString(), QString("/taskbar/click"), \ - "com.ukui.panel.plugins.taskbar", "sendToUkuiDEApp", this, SLOT(on_clickPanelToHideInterface())); - - connect(this, SIGNAL(deviceError(GDrive*)), this, SLOT(onDeviceErrored(GDrive*)), (Qt::UniqueConnection)); - connect(this, SIGNAL(mountVolume(GVolume*)), this, SLOT(onMountVolume(GVolume*))); - connect(this, SIGNAL(ejectVolumeForce(GVolume*)), this, SLOT(onEjectVolumeForce(GVolume*))); - connect(interfaceHideTime, SIGNAL(timeout()), this, SLOT(onMaininterfacehide())); -} - -void MainWindow::onRequestSendDesktopNotify(QString message, QString strIcon) -{ - QDBusInterface iface("org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - "org.freedesktop.Notifications", - QDBusConnection::sessionBus()); - QList<QVariant> args; - args << (tr("ukui flash disk")) - << ((unsigned int) 0) - << strIcon - << tr("kindly reminder") //显示的是什么类型的信息 - << message //显示的具体信息 - << QStringList() - << QVariantMap() - << (int)-1; - iface.callWithArgumentList(QDBus::NoBlock,"Notify",args); -} - -void MainWindow::onInsertAbnormalDiskNotify(QString message) -{ - QDBusInterface iface("org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - "org.freedesktop.Notifications", - QDBusConnection::sessionBus()); - QList<QVariant> args; - args << (tr("ukui flash disk")) - << ((unsigned int) 0) - << QString("media-removable-symbolic") - << tr("wrong reminder") //显示的是什么类型的信息 - << message //显示的具体信息 - << QStringList() - << QVariantMap() - << (int)-1; - iface.callWithArgumentList(QDBus::NoBlock,"Notify",args); -} - -void MainWindow::onNotifyWnd(QObject* obj, QEvent *event) -{ - QString strObjName(obj->metaObject()->className()); - if (strObjName == "QSystemTrayIconSys") { - if (!m_bIsMouseInTraIcon && event->type() == QEvent::Enter) { - if (interfaceHideTime->isActive()) { - interfaceHideTime->stop(); - } - m_bIsMouseInTraIcon = true; - } else if (m_bIsMouseInTraIcon && event->type() == QEvent::Leave) { - if (!m_bIsMouseInCentral) { - interfaceHideTime->start(2000); - } - m_bIsMouseInTraIcon = false; - } - } else if (obj == ui->centralWidget) { - if (!m_bIsMouseInCentral && event->type() == QEvent::Enter) { - interfaceHideTime->stop(); - ui->centralWidget->show(); - m_bIsMouseInCentral = true; - } else if (m_bIsMouseInCentral && event->type() == QEvent::Leave) { - if (!m_bIsMouseInTraIcon) { - interfaceHideTime->start(2000); - } - m_bIsMouseInCentral = false; - } - } -} - -void MainWindow::initThemeMode() -{ - const QByteArray idd(THEME_QT_SCHEMA); - - if(QGSettings::isSchemaInstalled(idd)) { - QGSettings *qtSettings = new QGSettings(idd, QByteArray(), this); - - connect(qtSettings,&QGSettings::changed,this,[=](const QString &key) { - currentThemeMode = qtSettings->get(MODE_QT_KEY).toString(); - }); - currentThemeMode = qtSettings->get(MODE_QT_KEY).toString(); - } - - const QByteArray id(AUTOLOAD); - if(QGSettings::isSchemaInstalled(idd)) { - ifsettings = new QGSettings(id); - } -} - -void MainWindow::on_clickPanelToHideInterface() -{ - if(!ui->centralWidget->isHidden()) { - ui->centralWidget->hide(); - } -} - -void MainWindow::getSystemRootDev() -{ - QString cmd = "df -l"; - QProcess *p = new QProcess(); - p->start(cmd); - p->waitForFinished(); - while(p->canReadLine()) { - QString str = p->readLine(); - QStringList infoList = str.split(QRegExp("\\s+")); - if (infoList.size() >= 6) { - if (infoList[5] == "/") { - m_strSysRootDev = infoList[0]; - break; - } - } - } - delete p; - p = nullptr; -} - -bool MainWindow::isSystemRootDev(QString strDev) -{ - return m_strSysRootDev.startsWith(strDev); -} - -bool MainWindow::getDevInterface(QString strDev) -{ - char* chDev; - QByteArray ba = strDev.toLatin1(); - chDev=ba.data(); - - QString cmd = "udevadm info -n "; - cmd.append(strDev); - QProcess *p = new QProcess(); - p->start(cmd); - p->waitForFinished(); - if(!m_ismountadd){ - while(p->canReadLine()) { - QString str = p->readLine(); - QStringList infoList = str.split('\n'); - QStringList::Iterator it = infoList.begin(); - for (; it != infoList.end(); it++){ - if((*it==("E: ID_BUS=ata"))&&(!g_str_has_prefix(chDev,"/dev/sr"))){ - return false; - } - } - } - }else{ - while(p->canReadLine()) { - QString str = p->readLine(); - QStringList infoList = str.split('='); - QStringList::Iterator it = infoList.begin(); - for (; it != infoList.end(); it++){ - if(*it==("E: ID_FS_TYPE")){ - return false; - } - } - } - } - delete p; - p = nullptr; - - return true; - -} - -void MainWindow::getDeviceInfo() -{ - // setting - FILE *fp = NULL; - int a = 0; - char buf[128] = {0}; - - fp = fopen("/proc/cmdline","r"); - if(fp) { - while(fscanf(fp,"%127s",buf) >0 ) { - if(strcmp(buf,"live") == 0) { - a++; - } - } - fclose(fp); - } - if(a > 0) { - QProcess::startDetached("gsettings set org.ukui.flash-disk.autoload ifautoload false"); - } - - // callback function that to monitor the insertion and removal of the underlying equipment - GVolumeMonitor *g_volume_monitor = g_volume_monitor_get(); - g_signal_connect (g_volume_monitor, "drive-connected", G_CALLBACK (drive_connected_callback), this); - g_signal_connect (g_volume_monitor, "drive-disconnected", G_CALLBACK (drive_disconnected_callback), this); - g_signal_connect (g_volume_monitor, "volume-added", G_CALLBACK (volume_added_callback), this); - g_signal_connect (g_volume_monitor, "volume-removed", G_CALLBACK (volume_removed_callback), this); - g_signal_connect (g_volume_monitor, "mount-added", G_CALLBACK (mount_added_callback), this); - g_signal_connect (g_volume_monitor, "mount-removed", G_CALLBACK (mount_removed_callback), this); - - GList *lDrive = NULL, *lVolume = NULL, *lMount = NULL; - m_ismountadd = false; - // about drive - GList *current_drive_list = g_volume_monitor_get_connected_drives(g_volume_monitor); - for (lDrive = current_drive_list; lDrive != NULL; lDrive = lDrive->next) { - GDrive *gdrive = (GDrive *)lDrive->data; - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - FDDriveInfo driveInfo; - driveInfo.strId = devPath; - char *strName = g_drive_get_name(gdrive); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - getDriveIconsInfo(gdrive, driveInfo); - driveInfo.isCanEject = g_drive_can_eject(gdrive); - driveInfo.isCanStop = g_drive_can_stop(gdrive); - driveInfo.isCanStart = g_drive_can_start(gdrive); - driveInfo.isRemovable = g_drive_is_removable(gdrive); - if(!isSystemRootDev(driveInfo.strId.c_str()) && getDevInterface(driveInfo.strId.c_str()) && (driveInfo.isCanEject || driveInfo.isCanStop || driveInfo.isRemovable)) { - if(g_str_has_prefix(devPath,"/dev/sr") || g_str_has_prefix(devPath,"/dev/bus") || g_str_has_prefix(devPath,"/dev/sd") - || g_str_has_prefix(devPath,"/dev/mmcblk")) { - GList* gdriveVolumes = g_drive_get_volumes(gdrive); - if (gdriveVolumes) { - for(lVolume = gdriveVolumes; lVolume != NULL; lVolume = lVolume->next){ //遍历驱动器上的所有卷设备 - GVolume* volume = (GVolume *)lVolume->data; - FDVolumeInfo volumeInfo; - bool isValidMount = true; - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - } else { - continue ; - } - char *volumeName = g_volume_get_name(volume); - if (volumeName) { - volumeInfo.strName = volumeName; - g_free(volumeName); - } - char *strDevName = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (strDevName) { - volumeInfo.strDevName = strDevName; - g_free(strDevName); - } - getVolumeIconsInfo(volume, volumeInfo); - volumeInfo.isCanMount = g_volume_can_mount(volume); - volumeInfo.isCanEject = g_volume_can_eject(volume); - volumeInfo.isShouldAutoMount = g_volume_should_automount(volume); - GMount* mount = g_volume_get_mount(volume); //get当前卷设备的挂载信息 - if (mount) { //该卷设备已挂载 - volumeInfo.mountInfo.isCanEject = g_mount_can_eject(mount); - volumeInfo.mountInfo.isCanUnmount = g_mount_can_unmount(mount); - if (volumeInfo.mountInfo.isCanEject || volumeInfo.mountInfo.isCanUnmount) { - char *mountId = g_mount_get_uuid(mount); - if (mountId) { - volumeInfo.mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(mount); - if (mountName) { - volumeInfo.mountInfo.strName = mountName; - g_free(mountName); - } - // get mount total size - GFile *fileRoot = g_mount_get_root(mount); - if (fileRoot) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - volumeInfo.mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - } - g_object_unref(fileRoot); - } - getDataCDRomCapacity(volumeInfo.strId.c_str(),volumeInfo.mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(mount); - if (root) { - volumeInfo.mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - volumeInfo.mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - isValidMount = false; - } else { - if (volumeInfo.mountInfo.strId.empty()) { - volumeInfo.mountInfo.strId = volumeInfo.mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - volumeInfo.mountInfo.strTooltip =tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - getMountIconsInfo(mount, volumeInfo.mountInfo); - } - g_object_unref(mount); - } else { - if(ifsettings->get(IFAUTOLOAD).toBool()) { - g_volume_mount(volume, - G_MOUNT_MOUNT_NONE, - nullptr, - nullptr, - nullptr, - nullptr); - } - } - if (isValidMount) { - driveInfo.listVolumes[volumeInfo.strId] = volumeInfo; - } - } - g_list_free(gdriveVolumes); - } - m_dataFlashDisk->addDriveInfo(driveInfo); -#if UDFAUTOMOUNT - if (G_IS_DRIVE(gdrive) && !driveInfo.strId.empty() && g_str_has_prefix (driveInfo.strId.c_str(), "/dev/sr")) { - mount_cdrom (gdrive, NULL); - g_signal_connect(G_DRIVE(gdrive), "changed", G_CALLBACK (mount_cdrom), NULL); - } -#endif - } - } - g_free(devPath); - } - } - if (current_drive_list) { - g_list_free(current_drive_list); - } - // about volume not associated with a drive - GList *current_volume_list = g_volume_monitor_get_volumes(g_volume_monitor); - if (current_volume_list) { - for (lVolume = current_volume_list; lVolume != NULL; lVolume = lVolume->next) { - GVolume *volume = (GVolume *)lVolume->data; - GDrive *gdrive = g_volume_get_drive(volume); - if (!gdrive) { - FDVolumeInfo volumeInfo; - bool isValidMount = true; - char *devPath = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath) { - if (!(g_str_has_prefix(devPath,"/dev/sr") || g_str_has_prefix(devPath,"/dev/bus") || g_str_has_prefix(devPath,"/dev/sd") - || g_str_has_prefix(devPath,"/dev/mmcblk"))) { - g_free(devPath); - continue; - } - g_free(devPath); - } - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - } else { - continue ; - } - char *volumeName = g_volume_get_name(volume); - if (volumeName) { - volumeInfo.strName = volumeName; - g_free(volumeName); - } - char *strDevName = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (strDevName) { - volumeInfo.strDevName = strDevName; - g_free(strDevName); - } - getVolumeIconsInfo(volume, volumeInfo); - volumeInfo.isCanMount = g_volume_can_mount(volume); - volumeInfo.isCanEject = g_volume_can_eject(volume); - volumeInfo.isShouldAutoMount = g_volume_should_automount(volume); - GMount* mount = g_volume_get_mount(volume); //get当前卷设备的挂载信息 - if (mount) { //该卷设备已挂载 - volumeInfo.mountInfo.isCanEject = g_mount_can_eject(mount); - volumeInfo.mountInfo.isCanUnmount = g_mount_can_unmount(mount); - if (volumeInfo.mountInfo.isCanEject || volumeInfo.mountInfo.isCanUnmount) { - char *mountId = g_mount_get_uuid(mount); - if (mountId) { - volumeInfo.mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(mount); - if (mountName) { - volumeInfo.mountInfo.strName = mountName; - g_free(mountName); - } - // get mount total size - GFile *fileRoot = g_mount_get_root(mount); - if (fileRoot) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - volumeInfo.mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - } - g_object_unref(fileRoot); - } - getDataCDRomCapacity(volumeInfo.strId.c_str(),volumeInfo.mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(mount); - if (root) { - volumeInfo.mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - volumeInfo.mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - isValidMount = false; - } else { - if (volumeInfo.mountInfo.strId.empty()) { - volumeInfo.mountInfo.strId = volumeInfo.mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - volumeInfo.mountInfo.strTooltip =tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - getMountIconsInfo(mount, volumeInfo.mountInfo); - } - g_object_unref(mount); - } else { - if (volumeInfo.isCanMount) { - if(ifsettings->get(IFAUTOLOAD).toBool()) { - g_volume_mount(volume, - G_MOUNT_MOUNT_NONE, - nullptr, - nullptr, - nullptr, - nullptr); - } - } - } - if (isValidMount) { - m_dataFlashDisk->addVolumeInfo(volumeInfo); - } - } else { - g_object_unref(gdrive); - } - } - g_list_free(current_volume_list); - } - - // about mount not associated with a volume - GList *current_mount_list = g_volume_monitor_get_mounts(g_volume_monitor); - if (current_mount_list) { - for (lMount = current_mount_list; lMount != NULL; lMount = lMount->next) { - GMount *gmount = (GMount *)lMount->data; - GVolume *gvolume = g_mount_get_volume(gmount); - if (!gvolume) { - GDrive* gdrive = g_mount_get_drive(gmount); - if (gdrive) { - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - FDDriveInfo driveInfo; - driveInfo.strId = devPath; - char *strName = g_drive_get_name(gdrive); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - getDriveIconsInfo(gdrive, driveInfo); - driveInfo.isCanEject = g_drive_can_eject(gdrive); - driveInfo.isCanStop = g_drive_can_stop(gdrive); - driveInfo.isCanStart = g_drive_can_start(gdrive); - driveInfo.isRemovable = g_drive_is_removable(gdrive); - if(!isSystemRootDev(driveInfo.strId.c_str()) && (driveInfo.isCanEject || driveInfo.isCanStop || driveInfo.isRemovable)) { - if(g_str_has_prefix(devPath,"/dev/sr") || g_str_has_prefix(devPath,"/dev/bus") || g_str_has_prefix(devPath,"/dev/sd") - || g_str_has_prefix(devPath,"/dev/mmcblk")) { - FDMountInfo mountInfo; - bool isValidMount = true; - mountInfo.isCanEject = g_mount_can_eject(gmount); - mountInfo.isCanUnmount = g_mount_can_unmount(gmount); - if (mountInfo.isCanEject || mountInfo.isCanUnmount) { - char *mountId = g_mount_get_uuid(gmount); - if (mountId) { - mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(gmount); - if (mountName) { - mountInfo.strName = mountName; - g_free(mountName); - } - // get mount total size - GFile *fileRoot = g_mount_get_root(gmount); - if (fileRoot) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - } - g_object_unref(fileRoot); - } - getDataCDRomCapacity(driveInfo.strId.c_str(),mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(gmount); - if (root) { - mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - isValidMount = false; - } else { - if (mountInfo.strId.empty()) { - mountInfo.strId = mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - mountInfo.strTooltip =tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - getMountIconsInfo(gmount, mountInfo); - if (isValidMount) { - FDVolumeInfo volumeInfo; - volumeInfo.mountInfo = mountInfo; - m_dataFlashDisk->addMountInfoWithDrive(driveInfo, volumeInfo, mountInfo); - } - } - } - } - g_free(devPath); - } - g_object_unref(gdrive); - } else { - # if 0 - FDMountInfo mountInfo; - bool isValidMount = true; - mountInfo.isCanEject = g_mount_can_eject(gmount); - mountInfo.isCanUnmount = g_mount_can_unmount(gmount); - if (mountInfo.isCanEject || mountInfo.isCanUnmount) { - char *mountId = g_mount_get_uuid(gmount); - if (mountId) { - mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(gmount); - if (mountName) { - mountInfo.strName = mountName; - g_free(mountName); - } - // get mount total size - GFile *fileRoot = g_mount_get_root(gmount); - if (fileRoot) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - } - g_object_unref(fileRoot); - } - getDataCDRomCapacity(mountInfo.strId.c_str(),mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(gmount); - if (root) { - mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - isValidMount = false; - } else { - if (mountInfo.strId.empty()) { - mountInfo.strId = mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - mountInfo.strTooltip =tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - if (isValidMount) { - m_dataFlashDisk->addMountInfo(mountInfo); - } - } - #endif - } - } else { - g_object_unref(gvolume); - } - } - g_list_free(current_mount_list); - } - - // determine the systray icon should be showed or be hieded - if(m_dataFlashDisk->getValidInfoCount() >= 1) { - m_systray->show(); - } else { - m_systray->hide(); - } - m_dataFlashDisk->OutputInfos(); -} - -void MainWindow::onConvertShowWindow(QString strDriveId, QString strMountUri) -{ - // 进程启动时一定时间内不弹窗提示 - if (QDateTime::currentDateTime().toMSecsSinceEpoch() - m_nAppStartTimestamp < NEWINFO_DELAYSHOW_TIME) { - m_dataFlashDisk->resetAllNewState(); - return; - } - insertorclick = true; - - MainWindowShow(); - string strDeviceId = strDriveId.toStdString(); - if (std::find(m_vtDeviveId.begin(), m_vtDeviveId.end(), strDeviceId) == m_vtDeviveId.end()) { - #if IFDISTINCT_DEVICON - QString strIcon = m_dataFlashDisk->getVolumeIcon(strDriveId); - onRequestSendDesktopNotify(tr("Please do not pull out the storage device when reading or writing"), - strIcon); - #else - if (strDriveId.startsWith("/dev/sr")) { - onRequestSendDesktopNotify(tr("Please do not pull out the CDROM when reading or writing"), - QString("media-removable-symbolic")); - } else if (strDriveId.startsWith("/dev/mmcblk")) { - onRequestSendDesktopNotify(tr("Please do not pull out the SD Card when reading or writing"), - QString("media-removable-symbolic")); - } else { - onRequestSendDesktopNotify(tr("Please do not pull out the USB flash disk when reading or writing"), - QString("drive-removable-media-usb")); - } - #endif - m_vtDeviveId.push_back(strDeviceId); - } -} - -void MainWindow::onNotifyDeviceRemoved(QString strDevId) -{ - if (strDevId.isEmpty()) { - return; - } - #if IFDISTINCT_DEVICON - QString strIcon = m_dataFlashDisk->getVolumeIcon(strDevId); - onRequestSendDesktopNotify(tr("Storage device removed"), strIcon); - #else - if (strDevId.startsWith("/dev/sr")) { - onRequestSendDesktopNotify(tr("Storage device removed"), - QString("media-removable-symbolic")); - } else if (strDevId.startsWith("/dev/mmcblk")) { - onRequestSendDesktopNotify(tr("Storage device removed"), - QString("media-removable-symbolic")); - } else { - onRequestSendDesktopNotify(tr("Storage device removed"), - QString("drive-removable-media-usb")); - } - #endif -} - -void MainWindow::onConvertUpdateWindow(QString strDevName, unsigned uDevType) -{ - // uDevType: 0 drive , 1 volume, 2 mount - if (uDevType != 0) { // not drive detached - insertorclick = true; - MainWindowShow(true); - } -} - -// the drive-connected callback function the is triggered when the usb device is inseted -void MainWindow::drive_connected_callback(GVolumeMonitor *monitor, GDrive *drive, MainWindow *p_this) -{ - qInfo() << "drive add"; - if(p_this->ifsettings->get(IFAUTOLOAD).toBool()) { - GList *lVolume = NULL; - FDDriveInfo driveInfo; - GDrive *gdrive = (GDrive *)drive; - unsigned uSubVolumeSize = 0; - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - char *strName = g_drive_get_name(gdrive); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - driveInfo.isCanEject = g_drive_can_eject(gdrive); - driveInfo.isCanStop = g_drive_can_stop(gdrive); - driveInfo.isCanStart = g_drive_can_start(gdrive); - driveInfo.isRemovable = g_drive_is_removable(gdrive); - g_free(devPath); - } - - if (!g_drive_has_volumes(gdrive)) { - QTimer::singleShot(1000, p_this, [&,driveInfo,p_this]() { p_this->onCheckDriveValid(driveInfo); }); - } - - lVolume = g_drive_get_volumes(gdrive); - if (lVolume) { - uSubVolumeSize = g_list_length(lVolume); - g_list_free(lVolume); - } - - p_this->getDriveIconsInfo(gdrive, driveInfo); - - if (!driveInfo.strId.empty()) { - p_this->m_dataFlashDisk->addDriveInfo(driveInfo); - } - // perhaps uSubVolumeSize is 0 and is ok ? - // else { - // qInfo()<<"wrong disk has intered"; - // p_this->onInsertAbnormalDiskNotify(tr("There is a problem with this device")); - // } -#if UDFAUTOMOUNT - if (G_IS_DRIVE(gdrive) && !driveInfo.strId.empty() && g_str_has_prefix (driveInfo.strId.c_str(), "/dev/sr")) { - g_signal_connect(G_DRIVE (gdrive), "changed", G_CALLBACK (mount_cdrom), NULL); - } -#endif - } - - if(p_this->m_dataFlashDisk->getValidInfoCount() >= 1) { - p_this->m_systray->show(); - } - - p_this->triggerType = 0; - p_this->m_dataFlashDisk->OutputInfos(); -} - -// the drive-disconnected callback function the is triggered when the usb device is pull out -void MainWindow::drive_disconnected_callback (GVolumeMonitor *monitor, GDrive *drive, MainWindow *p_this) -{ - qInfo() << "drive disconnect"; - - FDDriveInfo driveInfo; - char *devPath = g_drive_get_identifier(drive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - g_free(devPath); - } - - #if UDFAUTOMOUNT - // disconnect udf cdrom - if (!driveInfo.strId.empty() && G_IS_DRIVE(drive)) { - g_signal_handlers_disconnect_by_func (drive, (void*) mount_cdrom, NULL); - - qDebug() << "DJ- udf cdrom disconnected"; - if (gMountCdrom && gMountCdrom->contains (QString(driveInfo.strId.c_str()))) { - gMountCdrom->remove (QString(driveInfo.strId.c_str())); - QStringList mountPoints; - for (auto val : gMountCdromMountPoint->values()) { - if (QString(driveInfo.strId.c_str()) == val) { - mountPoints << val; - } - } - for (auto m : mountPoints) - gMountCdromMountPoint->remove (m); - } - } -#endif - vector<string>::iterator itDeviceId = p_this->m_vtDeviveId.begin(); - for (; itDeviceId != p_this->m_vtDeviveId.end();) { - if (driveInfo.strId == *itDeviceId) { - itDeviceId = p_this->m_vtDeviveId.erase(itDeviceId); - } else { - itDeviceId++; - } - } - p_this->m_dataFlashDisk->removeDriveInfo(driveInfo); - Q_EMIT p_this->notifyDeviceRemoved(QString::fromStdString(driveInfo.strId)); - if(p_this->m_dataFlashDisk->getValidInfoCount() == 0) { - p_this->ui->centralWidget->hide(); - p_this->m_systray->hide(); - } - p_this->m_dataFlashDisk->OutputInfos(); -} - -// when the usb device is identified, we should mount every partition -void MainWindow::volume_added_callback(GVolumeMonitor *monitor, GVolume *volume, MainWindow *p_this) -{ - qDebug() << "volume add"; - GDrive* gdrive = g_volume_get_drive(volume); - - FILE *fp = NULL; - int a = 0; - char buf[128] = {0}; - - p_this->m_ismountadd = false; - fp = fopen("/proc/cmdline","r"); - if (fp) { - while(fscanf(fp,"%127s",buf) > 0) { - if(strcmp(buf,"live") == 0) { - a++; - } - } - fclose(fp); - } - p_this->ifautoload = p_this->ifsettings->get(IFAUTOLOAD).toBool(); - - if(a > 0) { - QProcess::startDetached("gsettings set org.ukui.flash-disk.autoload ifautoload false"); - } else { - //QProcess::startDetached("gsettings set org.ukui.flash-disk.autoload ifautoload true"); - } - - bool isNewMount = false; - if(!gdrive) { - FDVolumeInfo volumeInfo; - bool isValidMount = true; - char *devPath = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath) { - if (!(g_str_has_prefix(devPath,"/dev/sr") || g_str_has_prefix(devPath,"/dev/bus") || g_str_has_prefix(devPath,"/dev/sd") - || g_str_has_prefix(devPath,"/dev/mmcblk"))) { - g_free(devPath); - return; - } - g_free(devPath); - } - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - } else { - return ; - } - char *volumeName = g_volume_get_name(volume); - if (volumeName) { - volumeInfo.strName = volumeName; - g_free(volumeName); - } - char *strDevName = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (strDevName) { - volumeInfo.strDevName = strDevName; - g_free(strDevName); - } - p_this->getVolumeIconsInfo(volume, volumeInfo); - volumeInfo.isCanMount = g_volume_can_mount(volume); - volumeInfo.isCanEject = g_volume_can_eject(volume); - volumeInfo.isShouldAutoMount = g_volume_should_automount(volume); - GMount* mount = g_volume_get_mount(volume); //get当前卷设备的挂载信息 - if (mount) { //该卷设备已挂载 - volumeInfo.mountInfo.isCanEject = g_mount_can_eject(mount); - volumeInfo.mountInfo.isCanUnmount = g_mount_can_unmount(mount); - if (volumeInfo.mountInfo.isCanEject || volumeInfo.mountInfo.isCanUnmount) { - char *mountId = g_mount_get_uuid(mount); - if (mountId) { - volumeInfo.mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(mount); - if (mountName) { - volumeInfo.mountInfo.strName = mountName; - g_free(mountName); - } - isNewMount = !(p_this->m_dataFlashDisk->isMountInfoExist(volumeInfo.mountInfo)); - // get mount total size - GFile *fileRoot = g_mount_get_root(mount); - if (fileRoot) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - volumeInfo.mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - } - g_object_unref(fileRoot); - } - p_this->getDataCDRomCapacity(volumeInfo.strId.c_str(), volumeInfo.mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(mount); - if (root) { - volumeInfo.mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - volumeInfo.mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - isValidMount = false; - } else { - if (volumeInfo.mountInfo.strId.empty()) { - volumeInfo.mountInfo.strId = volumeInfo.mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - volumeInfo.mountInfo.strTooltip = tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - p_this->getMountIconsInfo(mount, volumeInfo.mountInfo); - } - g_object_unref(mount); - } else { - if (volumeInfo.isCanMount) { - if(p_this->ifsettings->get(IFAUTOLOAD).toBool()) { - g_volume_mount(volume, - G_MOUNT_MOUNT_NONE, - nullptr, - nullptr, - GAsyncReadyCallback(frobnitz_result_func_volume), - p_this); - } - } - } - if (isValidMount) { - p_this->m_dataFlashDisk->addVolumeInfo(volumeInfo); - } - } else { - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - FDDriveInfo driveInfo; - FDVolumeInfo volumeInfo; - driveInfo.strId = devPath; - char *strName = g_drive_get_name(gdrive); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - p_this->getDriveIconsInfo(gdrive, driveInfo); - driveInfo.isCanEject = g_drive_can_eject(gdrive); - driveInfo.isCanStop = g_drive_can_stop(gdrive); - driveInfo.isCanStart = g_drive_can_start(gdrive); - driveInfo.isRemovable = g_drive_is_removable(gdrive); - - if(!p_this->isSystemRootDev(driveInfo.strId.c_str()) && p_this->getDevInterface(driveInfo.strId.c_str()) && - (driveInfo.isCanEject || driveInfo.isCanStop || driveInfo.isRemovable)) { - if(g_str_has_prefix(devPath,"/dev/sr") || g_str_has_prefix(devPath,"/dev/bus") || g_str_has_prefix(devPath,"/dev/sd") - || g_str_has_prefix(devPath,"/dev/mmcblk")) { - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - char *volumeName = g_volume_get_name(volume); - if (volumeName) { - volumeInfo.strName = volumeName; - g_free(volumeName); - } - char *strDevName = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (strDevName) { - volumeInfo.strDevName = strDevName; - g_free(strDevName); - } - p_this->getVolumeIconsInfo(volume, volumeInfo); - volumeInfo.isCanMount = g_volume_can_mount(volume); - volumeInfo.isCanEject = g_volume_can_eject(volume); - volumeInfo.isShouldAutoMount = g_volume_should_automount(volume); - GMount* mount = g_volume_get_mount(volume); //get当前卷设备的挂载信息 - if (mount) { //该卷设备已挂载 - volumeInfo.mountInfo.isCanEject = g_mount_can_eject(mount); - volumeInfo.mountInfo.isCanUnmount = g_mount_can_unmount(mount); - if (volumeInfo.mountInfo.isCanEject || volumeInfo.mountInfo.isCanUnmount) { - char *mountId = g_mount_get_uuid(mount); - if (mountId) { - volumeInfo.mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(mount); - if (mountName) { - volumeInfo.mountInfo.strName = mountName; - g_free(mountName); - } - isNewMount = !(p_this->m_dataFlashDisk->isMountInfoExist(volumeInfo.mountInfo)); - // get mount total size - GFile *fileRoot = g_mount_get_root(mount); - if (fileRoot) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - volumeInfo.mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - } - g_object_unref(fileRoot); - } - p_this->getDataCDRomCapacity(volumeInfo.strId.c_str(), volumeInfo.mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(mount); - if (root) { - volumeInfo.mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - volumeInfo.mountInfo.strUri = mountUri; - if (!g_str_has_prefix(mountUri,"file:///data")) { - if (volumeInfo.mountInfo.strId.empty()) { - volumeInfo.mountInfo.strId = volumeInfo.mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - volumeInfo.mountInfo.strTooltip =tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - p_this->getMountIconsInfo(mount, volumeInfo.mountInfo); - } - g_object_unref(mount); - } else { - if(p_this->ifsettings->get(IFAUTOLOAD).toBool()) { - p_this->m_ismountadd = true; - if (p_this->getDevInterface(volumeInfo.strId.c_str())){ - p_this->m_ismountadd = false; - return; - } - g_volume_mount(volume, - G_MOUNT_MOUNT_NONE, - nullptr, - nullptr, - nullptr, //GAsyncReadyCallback(frobnitz_result_func_volume), - p_this); - } - } - } - } - if (isNewMount) { - //qInfo()<<"cd data disk has mounted!"; - volumeInfo.isNewInsert = true; - p_this->m_dataFlashDisk->addVolumeInfoWithDrive(driveInfo, volumeInfo); - string strDevId = driveInfo.strId.empty()?volumeInfo.strId:driveInfo.strId; - Q_EMIT p_this->convertShowWindow(strDevId.c_str(), volumeInfo.mountInfo.strUri.c_str()); - } else { - p_this->m_dataFlashDisk->addVolumeInfoWithDrive(driveInfo, volumeInfo); - } - } - g_free(devPath); - } - g_object_unref(gdrive); - } - if(p_this->m_dataFlashDisk->getValidInfoCount() > 0) - { - p_this->m_systray->show(); - } - p_this->m_dataFlashDisk->OutputInfos(); -} - -// when the U disk is pull out we should reduce all its partitions -void MainWindow::volume_removed_callback(GVolumeMonitor *monitor, GVolume *volume, MainWindow *p_this) -{ - qInfo() << "volume removed"; - FDVolumeInfo volumeInfo; - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - } - char *strName = g_volume_get_name(volume); - if (strName) { - volumeInfo.strName = strName; - g_free(strName); - } - vector<string>::iterator itDeviceId = p_this->m_vtDeviveId.begin(); - for (; itDeviceId != p_this->m_vtDeviveId.end();) { - if (volumeInfo.strId == *itDeviceId) { - itDeviceId = p_this->m_vtDeviveId.erase(itDeviceId); - } else { - itDeviceId++; - } - } - p_this->m_dataFlashDisk->removeVolumeInfo(volumeInfo); - if(p_this->m_dataFlashDisk->getValidInfoCount() == 0) { - p_this->m_systray->hide(); - } - p_this->m_dataFlashDisk->OutputInfos(); - Q_EMIT p_this->convertUpdateWindow(QString::fromStdString(volumeInfo.strName), 1); //emit a signal to update the MainMainShow slot -} - -// when the volumes were mounted we add its mounts number -void MainWindow::mount_added_callback(GVolumeMonitor *monitor, GMount *mount, MainWindow *p_this) -{ - qInfo() << "mount add"; - - GDrive* gdrive = g_mount_get_drive(mount); - GVolume* gvolume = g_mount_get_volume(mount); - string strVolumePath = ""; - FDDriveInfo driveInfo; - FDVolumeInfo volumeInfo; - FDMountInfo mountInfo; - bool isValidMount = true; - p_this->m_ismountadd = false; - - if (gdrive) { - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - if (!(p_this->getDevInterface(driveInfo.strId.c_str()))){ - qInfo() << "---------------the devpath is "<<driveInfo.strId.c_str(); - isValidMount = false; - } - char *strName = g_drive_get_name(gdrive); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - p_this->getDriveIconsInfo(gdrive, driveInfo); - driveInfo.isCanEject = g_drive_can_eject(gdrive); - driveInfo.isCanStop = g_drive_can_stop(gdrive); - driveInfo.isCanStart = g_drive_can_start(gdrive); - driveInfo.isRemovable = g_drive_is_removable(gdrive); - g_free(devPath); - } -#if UDFAUTOMOUNT - if (gMountCdrom && gMountCdrom->contains (QString(driveInfo.strId.c_str()))) { - (*gMountCdrom)[QString(driveInfo.strId.c_str())] = true; - qDebug() << "DJ- Mount add" << driveInfo.strId.c_str(); - } -#endif - g_object_unref(gdrive); - } - if (gvolume) { - char *volumeId = g_volume_get_identifier(gvolume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - char *devVolumePath = g_volume_get_identifier(gvolume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (devVolumePath) { - strVolumePath = devVolumePath; - g_free(devVolumePath); - } - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - char *volumeName = g_volume_get_name(gvolume); - if (volumeName) { - volumeInfo.strName = volumeName; - g_free(volumeName); - } - char *strDevName = g_volume_get_identifier(gvolume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (strDevName) { - volumeInfo.strDevName = strDevName; - g_free(strDevName); - } - p_this->getVolumeIconsInfo(gvolume, volumeInfo); - volumeInfo.isCanMount = g_volume_can_mount(gvolume); - volumeInfo.isCanEject = g_volume_can_eject(gvolume); - volumeInfo.isShouldAutoMount = g_volume_should_automount(gvolume); - } - g_object_unref(gvolume); - } - mountInfo.isCanEject = g_mount_can_eject(mount); - char *mountId = g_mount_get_uuid(mount); - if (mountId) { - mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(mount); - if (mountName) { - mountInfo.strName = mountName; - g_free(mountName); - } - mountInfo.isCanUnmount = g_mount_can_unmount(mount); - GFile *root = g_mount_get_default_location(mount); - // get mount total size - GFile *fileRoot = g_mount_get_root(mount); - if (fileRoot) { - unsigned uRetryTime = 5; - unsigned uDelayTime = 200000; - while (uRetryTime > 0) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - break; - } else { - usleep(uDelayTime); - } - uRetryTime --; - } - g_object_unref(fileRoot); - } - p_this->getDataCDRomCapacity(driveInfo.strId.empty()?volumeInfo.strId.c_str():driveInfo.strId.c_str(), - mountInfo.lluTotalSize); - // get mount uri - if (root) { - mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - isValidMount = false; - } else { - if (mountInfo.strId.empty()) { - mountInfo.strId = mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - mountInfo.strTooltip = tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - p_this->getMountIconsInfo(mount, mountInfo); - - if (driveInfo.strId.empty()) { - Q_EMIT p_this->telephoneMount(); - } - bool isNewMount = !(p_this->m_dataFlashDisk->isMountInfoExist(mountInfo)); - if (!driveInfo.strId.empty()) { - if (p_this->isSystemRootDev(driveInfo.strId.c_str()) || - (!driveInfo.isCanEject && !driveInfo.isCanStop && !driveInfo.isRemovable)) { - isValidMount = false; - } - } - if (volumeInfo.strId.empty()) { - // 没有卷信息的挂载不处理(ftp等) - isValidMount = false; - } - if(isValidMount && (mountInfo.isCanUnmount || g_str_has_prefix(strVolumePath.c_str(),"/dev/bus") - || g_str_has_prefix(strVolumePath.c_str(),"/dev/sr") || g_str_has_prefix(strVolumePath.c_str(),"/dev/mmcblk"))) { - qInfo() << "real mount loaded"; - mountInfo.isNewInsert = true; - if (!driveInfo.strId.empty()) { - if (!volumeInfo.strId.empty()) { - volumeInfo.mountInfo = mountInfo; - p_this->m_dataFlashDisk->addVolumeInfoWithDrive(driveInfo, volumeInfo); - } else { - p_this->m_dataFlashDisk->addMountInfo(mountInfo); - } - } else if (!volumeInfo.strId.empty()) { - volumeInfo.mountInfo = mountInfo; - p_this->m_dataFlashDisk->addVolumeInfo(volumeInfo); - } else { - p_this->m_dataFlashDisk->addMountInfo(mountInfo); - } - } - else { - qInfo()<<"不符合过滤条件的设备已被挂载"; - } - - if(p_this->m_dataFlashDisk->getValidInfoCount() >= 1) { - if (isValidMount && isNewMount) { - //qInfo()<<"cd data disk has mounted!"; - string strDevId = driveInfo.strId.empty()?volumeInfo.strId:driveInfo.strId; - Q_EMIT p_this->convertShowWindow(strDevId.c_str(), mountInfo.strUri.c_str()); - } - p_this->m_systray->show(); - } - p_this->m_dataFlashDisk->OutputInfos(); -} - -// when the mountes were uninstalled we reduce mounts number -void MainWindow::mount_removed_callback(GVolumeMonitor *monitor, GMount *mount, MainWindow *p_this) -{ - qInfo() << mount << "mount remove"; - FDMountInfo mountInfo; - mountInfo.isCanEject = g_mount_can_eject(mount); - char *mountId = g_mount_get_uuid(mount); - if (mountId) { - mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(mount); - if (mountName) { - mountInfo.strName = mountName; - g_free(mountName); - } - -#if UDFAUTOMOUNT - qDebug() << "DJ- Umount --- 1 " << mountInfo.strName.c_str(); - g_autoptr (GFile) mountP = g_mount_get_root (mount); - if (G_IS_FILE(mountP)) { - g_autofree char* path = g_file_get_path (mountP); - if (gMountCdromMountPoint && gMountCdromMountPoint->contains (QString(path))) { - QString devName = (*gMountCdromMountPoint)[path]; - if (gMountCdrom->contains (devName)) { - (*gMountCdrom)[devName] = false; - qDebug() << "DJ- Umount(not auto mount) --- 2 " << devName; - } - } - } -#endif - mountInfo.isCanUnmount = g_mount_can_unmount(mount); - GFile *root = g_mount_get_default_location(mount); - if (root) { - mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - mountInfo.strUri = mountUri; - g_free(mountUri); - if (mountInfo.strId.empty()) { - mountInfo.strId = mountInfo.strUri; - } - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - mountInfo.strTooltip = tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - // check mount's volume had removed? - FDVolumeInfo volumeInfo; - p_this->m_dataFlashDisk->getVolumeInfoByMount(mountInfo, volumeInfo); - quint64 mountTickDiff = p_this->m_dataFlashDisk->getMountTickDiff(mountInfo); - - p_this->m_dataFlashDisk->removeMountInfo(mountInfo); - - if(p_this->m_dataFlashDisk->getValidInfoCount() == 0) { - p_this->m_systray->hide(); - } - p_this->m_dataFlashDisk->OutputInfos(); - Q_EMIT p_this->convertUpdateWindow(QString::fromStdString(mountInfo.strName), 2); //emit a signal to update the MainMainShow slot - qInfo()<<"ID:"<<mountInfo.strId.c_str()<<",volume is:"<<volumeInfo.strId.c_str()<<",mount tickdiff:"<<mountTickDiff; - if (mountTickDiff > 0 && mountTickDiff < 500 && !volumeInfo.strId.empty()) { - QTimer::singleShot(1000, p_this, [&,volumeInfo,p_this]() { p_this->onRemountVolume(volumeInfo); }); - } -} - -// it stands that when you insert a usb device when all the U disk partitions -void MainWindow::frobnitz_result_func_volume(GVolume *source_object,GAsyncResult *res,MainWindow *p_this) -{ - gboolean success = FALSE; - GError *err = nullptr; - bool bMountSuccess = false; - success = g_volume_mount_finish (source_object, res, &err); - if(!err) { - GMount* gmount = g_volume_get_mount(source_object); - GDrive* gdrive = g_volume_get_drive(source_object); - FDDriveInfo driveInfo; - FDVolumeInfo volumeInfo; - FDMountInfo mountInfo; - if (gdrive) { - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - char *strName = g_drive_get_name(gdrive); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - p_this->getDriveIconsInfo(gdrive, driveInfo); - driveInfo.isCanEject = g_drive_can_eject(gdrive); - driveInfo.isCanStop = g_drive_can_stop(gdrive); - driveInfo.isCanStart = g_drive_can_start(gdrive); - driveInfo.isRemovable = g_drive_is_removable(gdrive); - g_free(devPath); - } - g_object_unref(gdrive); - } - char *volumeId = g_volume_get_identifier(source_object,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - char *volumeName = g_volume_get_name(source_object); - if (volumeName) { - volumeInfo.strName = volumeName; - g_free(volumeName); - } - char *strDevName = g_volume_get_identifier(source_object,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (strDevName) { - volumeInfo.strDevName = strDevName; - g_free(strDevName); - } - p_this->getVolumeIconsInfo(source_object, volumeInfo); - volumeInfo.isCanMount = g_volume_can_mount(source_object); - volumeInfo.isCanEject = g_volume_can_eject(source_object); - volumeInfo.isShouldAutoMount = g_volume_should_automount(source_object); - } - if (gmount) { - bMountSuccess = true; - mountInfo.isCanEject = g_mount_can_eject(gmount); - char *mountId = g_mount_get_uuid(gmount); - if (mountId) { - mountInfo.strId = mountId; - g_free(mountId); - } - char *mountName = g_mount_get_name(gmount); - if (mountName) { - mountInfo.strName = mountName; - g_free(mountName); - } - mountInfo.isCanUnmount = g_mount_can_unmount(gmount); - // get mount total size - GFile *fileRoot = g_mount_get_root(gmount); - if (fileRoot) { - unsigned uRetryTime = 5; - unsigned uDelayTime = 200000; - while (uRetryTime > 0) { - GFileInfo *info = g_file_query_filesystem_info(fileRoot,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,nullptr,nullptr); - if (info) { - mountInfo.lluTotalSize = g_file_info_get_attribute_uint64(info,G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); - g_object_unref(info); - break; - } else { - usleep(uDelayTime); - } - uRetryTime --; - } - g_object_unref(fileRoot); - } - p_this->getDataCDRomCapacity(driveInfo.strId.empty()?volumeInfo.strId.c_str():driveInfo.strId.c_str(), - mountInfo.lluTotalSize); - // get mount uri - GFile *root = g_mount_get_default_location(gmount); - if (root) { - mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - mountInfo.strUri = mountUri; - if (g_str_has_prefix(mountUri,"file:///data")) { - bMountSuccess = false; - }else { - if (mountInfo.strId.empty()) { - mountInfo.strId = mountInfo.strUri; - } - } - g_free(mountUri); - } - char *tooltip = g_file_get_parse_name(root); //提示,即文件的解释 - if (tooltip) { - mountInfo.strTooltip = tooltip; - g_free(tooltip); - } - g_object_unref(root); - } - p_this->getMountIconsInfo(gmount, mountInfo); - g_object_unref(gmount); - } - if (bMountSuccess) { - mountInfo.isNewInsert = true; - bool isNewMount = !(p_this->m_dataFlashDisk->isMountInfoExist(mountInfo)); - if (!driveInfo.strId.empty()) { - if (!volumeInfo.strId.empty()) { - volumeInfo.mountInfo = mountInfo; - p_this->m_dataFlashDisk->addVolumeInfoWithDrive(driveInfo, volumeInfo); - } else { - p_this->m_dataFlashDisk->addMountInfo(mountInfo); - } - } else if (!volumeInfo.strId.empty()) { - volumeInfo.mountInfo = mountInfo; - p_this->m_dataFlashDisk->addVolumeInfo(volumeInfo); - } else { - p_this->m_dataFlashDisk->addMountInfo(mountInfo); - } - if (isNewMount) { - qInfo()<<"sig has emitted"; - string strDevId = driveInfo.strId.empty()?volumeInfo.strId:driveInfo.strId; - Q_EMIT p_this->convertShowWindow(strDevId.c_str(), mountInfo.strUri.c_str()); //emit a signal to trigger the MainMainShow slot - } - } - } else if (G_IO_ERROR_ALREADY_MOUNTED == err->code) { - } else if (G_IO_ERROR_UNKNOWN == err->code) { - } else { - qInfo()<<"sorry mount failed"<<err->code<<","<<err->message; - GDrive* gdrive = g_volume_get_drive(source_object); - Q_EMIT p_this->deviceError(gdrive); - if (nullptr != gdrive) { - g_object_unref(gdrive); - } - } -} - -// here we begin painting the main interface -void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) -{ - triggerType = 1; //It represents how we open the interface - - if (ui->centralWidget && !ui->centralWidget->isHidden() && !insertorclick) { - ui->centralWidget->hide(); - return ; - } - insertorclick = false; - - MainWindowShow(); -} - -void MainWindow::hideEvent(QHideEvent event) -{ - // delete open_widget; -} - -/* - * newarea use all the information of the U disk to paint the main interface and add line -*/ -void MainWindow::newarea(int No, - GDrive *Drive, - GVolume *Volume, - QString Drivename, - QString nameDis1, - QString nameDis2, - QString nameDis3, - QString nameDis4, - qlonglong capacityDis1, - qlonglong capacityDis2, - qlonglong capacityDis3, - qlonglong capacityDis4, - QString pathDis1, - QString pathDis2, - QString pathDis3, - QString pathDis4, - int linestatus) -{ - open_widget = new QClickWidget(ui->centralWidget,No,Drive,Volume,Drivename,nameDis1,nameDis2,nameDis3,nameDis4, - capacityDis1,capacityDis2,capacityDis3,capacityDis4, - pathDis1,pathDis2,pathDis3,pathDis4); - connect(open_widget,&QClickWidget::clickedConvert,this,[=]() - { - ui->centralWidget->hide(); - }); - connect(open_widget,&QClickWidget::noDeviceSig,this,[=]() - { - m_systray->hide(); - }); - - - line = new QWidget; - line->setFixedHeight(1); - line->setObjectName("lineWidget"); - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" - || currentThemeMode == "ukui") - { - line->setStyleSheet("background-color:rgba(255,255,255,0.2);"); - } - else - { - line->setStyleSheet("background-color:rgba(0,0,0,0.2);"); - } - - //when the drive is only or the drive is the first one,we make linestatus become 1 - line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - line->setFixedSize(276,1); - if (linestatus == 2) - { - this->vboxlayout->addWidget(line); - } - - vboxlayout->setContentsMargins(2,4,2,4); - vboxlayout->setSpacing(0); - vboxlayout->setMargin(0); - this->vboxlayout->addWidget(open_widget); - - if (linestatus == 0) - { - this->vboxlayout->addWidget(line); - } -} - -void MainWindow::newarea(unsigned uDiskNo, - QString strDriveId, - QString strVolumeId, - QString strMountId, - QString driveName, - QString volumeName, - quint64 capacityDis, - QString strMountUri, - int linestatus) -{ - m_fdClickWidget = new FDClickWidget(ui->centralWidget,uDiskNo,strDriveId,strVolumeId,strMountId, - driveName,volumeName,capacityDis,strMountUri); - connect(m_fdClickWidget, &FDClickWidget::clickedEject,this,&MainWindow::onClickedEject); - - line = new QWidget; - line->setFixedHeight(1); - line->setObjectName("lineWidget"); - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" - || currentThemeMode == "ukui") { - line->setStyleSheet("background-color:rgba(255,255,255,0.2);"); - } else { - line->setStyleSheet("background-color:rgba(0,0,0,0.2);"); - } - - // when the drive is only or the drive is the first one,we make linestatus become 1 - line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - line->setFixedSize(276,1); - if (linestatus == 2) { - this->vboxlayout->addWidget(line); - } - - vboxlayout->setContentsMargins(2,4,2,4); - //vboxlayout->setSpacing(0); - //vboxlayout->setMargin(0); - this->vboxlayout->addWidget(m_fdClickWidget); - - if (linestatus == 0) { - this->vboxlayout->addWidget(line); - } -} - -void MainWindow::moveBottomRight() -{ - //MARGIN 为到任务栏或屏幕边缘的间隔 - #define MARGIN 4 - QDBusInterface iface("org.ukui.panel", - "/panel/position", - "org.ukui.panel", - QDBusConnection::sessionBus()); - QDBusReply<QVariantList> reply=iface.call("GetPrimaryScreenGeometry"); - //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 - // reply.value(); - qInfo()<<reply.value().at(4).toInt(); - QVariantList position_list=reply.value(); - - switch(reply.value().at(4).toInt()){ - case 1: - //任务栏位于上方 - this->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-this->width()-MARGIN, - position_list.at(1).toInt()+MARGIN, - this->width(),this->height()); - break; - //任务栏位于左边 - case 2: - this->setGeometry(position_list.at(0).toInt()+MARGIN, - position_list.at(1).toInt()+reply.value().at(3).toInt()-this->height()-MARGIN, - this->width(),this->height()); - break; - //任务栏位于右边 - case 3: - this->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-this->width()-MARGIN, - position_list.at(1).toInt()+reply.value().at(3).toInt()-this->height()-MARGIN, - this->width(),this->height()); - break; - //任务栏位于下方 - default: - this->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-this->width()-MARGIN, - position_list.at(1).toInt()+reply.value().at(3).toInt()-this->height()-MARGIN, - this->width(),this->height()); - break; - } -} - -/* - use dbus to get the location of the panel -*/ -int MainWindow::getPanelPosition(QString str) -{ - QDBusInterface interface( "com.ukui.panel.desktop", - "/", - "com.ukui.panel.desktop", - QDBusConnection::sessionBus() ); - QDBusReply<int> reply = interface.call("GetPanelPosition", str); - - return reply; -} - -/* - use the dbus to get the height of the panel -*/ -int MainWindow::getPanelHeight(QString str) -{ - QDBusInterface interface( "com.ukui.panel.desktop", - "/", - "com.ukui.panel.desktop", - QDBusConnection::sessionBus() ); - QDBusReply<int> reply = interface.call("GetPanelSize", str); - return reply; -} - - -void MainWindow::resizeEvent(QResizeEvent *event) -{ -} - -void MainWindow::moveBottomDirect(GDrive *drive) -{ -} - -void MainWindow::MainWindowShow(bool isUpdate) -{ - this->getTransparentData(); - m_dataFlashDisk->OutputInfos(); - QString strTrans; - strTrans = QString::number(m_transparency, 10, 2); -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - QString convertStyle = "#centralWidget{background:rgba(19,19,20,0.95);}"; -#else -// QString convertStyle = "#centralWidget{background:rgba(19,19,20," + strTrans + ");}"; -#endif - if(ui->centralWidget != NULL) - { - //cancel the connection between the timeout signal and main interface hiding - if (insertorclick == false) { - if (interfaceHideTime->isActive()) { - interfaceHideTime->stop(); - } - } else if (!m_bIsMouseInTraIcon && !m_bIsMouseInCentral) { - if (isUpdate) { - if (ui->centralWidget->isHidden()) { - return ; - } else { - if (m_dataFlashDisk->getValidInfoCount() < 1) { - ui->centralWidget->hide(); - return ; - } - } - } - interfaceHideTime->start(5000); - } - } - num = 0; - unsigned uDiskCount = 0; - unsigned uVolumeCount = 0; - QList<FDClickWidget *> listMainWindow = ui->centralWidget->findChildren<FDClickWidget *>(); - for(FDClickWidget *listItem:listMainWindow) - { - listItem->hide(); - listItem->deleteLater(); - } - - QList<QWidget *> listLine = ui->centralWidget->findChildren<QWidget *>(); - for(QWidget *listItem:listLine) - { - if(listItem->objectName() == "lineWidget") { - listItem->hide(); - listItem->deleteLater(); - } - } - // only show new insert device - if (insertorclick) { - //Convenient interface layout for all drives - map<string, FDDriveInfo>& listDriveInfo = m_dataFlashDisk->getDevInfoWithDrive(); - if (!listDriveInfo.empty()) { - map<string, FDDriveInfo>::iterator itDriveInfo = listDriveInfo.begin(); - for ( ;itDriveInfo != listDriveInfo.end(); itDriveInfo++) { - unsigned uVolumeNum = 0; - bool isCanShow = (itDriveInfo->second.isCanEject || itDriveInfo->second.isCanStop || itDriveInfo->second.isRemovable); - QString strDriveName = QString::fromStdString(itDriveInfo->second.strName); - if (itDriveInfo->second.listVolumes.size() > 0) { - uDiskCount++; - } - map<string, FDVolumeInfo>::iterator itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for ( ;itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - QString strApiName; - quint64 lluTotalSize = itVolumeInfo->second.mountInfo.lluTotalSize; - QString strMountUri = QString::fromStdString(itVolumeInfo->second.mountInfo.strUri); - QString strDriveId = QString::fromStdString(itDriveInfo->second.strId); - QString strVolumeId = QString::fromStdString(itVolumeInfo->second.strId); - QString strMountId = QString::fromStdString(itVolumeInfo->second.mountInfo.strId); - unsigned uVolumeType = 0; // 0:normal file volume, 1: cddata, 2:tele dev - if ((itVolumeInfo->second.strId.empty() && itVolumeInfo->second.mountInfo.strId.empty()) - || (!itVolumeInfo->second.isNewInsert && !itVolumeInfo->second.mountInfo.isNewInsert)) { - // is not new insert device - continue; - } - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - string strMountUri = itVolumeInfo->second.mountInfo.strUri; - if(g_str_has_prefix(strMountUri.c_str(),"file:///")) { - uVolumeType = 0; - } else if (g_str_has_prefix(strMountUri.c_str(),"mtp://") || g_str_has_prefix(strMountUri.c_str(),"gphoto2://")){ - uVolumeType = 2; - } else if (g_str_has_prefix(strMountUri.c_str(),"burn:///")/* || g_str_has_prefix(strMountUri.c_str(),"cdda://")*/) { - uVolumeType = 1; - } - } - if (uVolumeType == 1 || uVolumeType == 2 || isCanShow) { // cd module or drive can show - if (!itVolumeInfo->second.strId.empty()) { - uVolumeNum++; - uVolumeCount++; - strApiName = QString::fromStdString(itVolumeInfo->second.strName); - } else if (!itVolumeInfo->second.mountInfo.strId.empty()) { - uVolumeNum++; - uVolumeCount++; - strApiName = QString::fromStdString(itVolumeInfo->second.mountInfo.strName); - } else { - continue; - } - } else { - continue; - } - if (uDiskCount > 0) { - if (uVolumeType == 1) { // deal with cd info - if(uDiskCount == 1 || uVolumeNum != 1) { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName, 1, "burn:///", 1); - } else { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName, 1, "burn:///", 2); - } - } else if (uVolumeType == 2) { - QString telephoneName = tr("telephone device"); - QByteArray strTelePhone = telephoneName.toLocal8Bit(); - char *realTele = strTelePhone.data(); - if(uDiskCount == 1 || uVolumeNum != 1) { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,realTele, - strApiName, lluTotalSize, strMountUri,1); - } else { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,realTele, - strApiName, lluTotalSize, strMountUri,2); - } - } else { - if(uDiskCount == 1 || uVolumeNum != 1) { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName, lluTotalSize,strMountUri,1); - } else { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName,lluTotalSize,strMountUri,2); - } - } - } - } - if (itDriveInfo->second.listVolumes.size() > 0 && uVolumeNum == 0 && uDiskCount > 0) { - uDiskCount --; - } - } - } - // show volume info without drive - map<string, FDVolumeInfo>& listVolumeInfo = m_dataFlashDisk->getDevInfoWithVolume(); - if (!listVolumeInfo.empty()) { - map<string, FDVolumeInfo>::iterator itVolumeInfo = listVolumeInfo.begin(); - for (; itVolumeInfo != listVolumeInfo.end(); itVolumeInfo++) { - QString strApiName; - QString strMainName; - bool isCanShow = itVolumeInfo->second.isCanEject; - quint64 lluTotalSize = itVolumeInfo->second.mountInfo.lluTotalSize; - QString strMountUri = QString::fromStdString(itVolumeInfo->second.mountInfo.strUri); - QString strVolumeId = QString::fromStdString(itVolumeInfo->second.strId); - QString strMountId = QString::fromStdString(itVolumeInfo->second.mountInfo.strId); - unsigned uVolumeType = 0; // 0:normal file volume, 1: cddata, 2:tele dev - if ((itVolumeInfo->second.strId.empty() && itVolumeInfo->second.mountInfo.strId.empty()) - || (!itVolumeInfo->second.isNewInsert && !itVolumeInfo->second.mountInfo.isNewInsert)) { - // is not new insert device - continue; - } - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - string strMountUri = itVolumeInfo->second.mountInfo.strUri; - if(g_str_has_prefix(strMountUri.c_str(),"file:///")) { - uVolumeType = 0; - } else if (g_str_has_prefix(strMountUri.c_str(),"mtp://") || g_str_has_prefix(strMountUri.c_str(),"gphoto2://")){ - uVolumeType = 2; - } else if (g_str_has_prefix(strMountUri.c_str(),"burn:///")/* || g_str_has_prefix(strMountUri.c_str(),"cdda://")*/) { - uVolumeType = 1; - } - } - if (uVolumeType == 1 || uVolumeType == 2 || isCanShow) { // cd module or drive can show - if (!itVolumeInfo->second.strId.empty()) { - uDiskCount++; - uVolumeCount++; - strMainName = strApiName = QString::fromStdString(itVolumeInfo->second.strName); - } else if (!itVolumeInfo->second.mountInfo.strId.empty()) { - uDiskCount++; - uVolumeCount++; - strMainName = strApiName = QString::fromStdString(itVolumeInfo->second.mountInfo.strName); - } else { - continue; - } - } else { - continue; - } - if (uDiskCount > 0) { - if (uVolumeType == 1) { // deal with cd info - if(uDiskCount == 1) { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,1,"burn:///",1); - } else { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,1,"burn:///",2); - } - } else if (uVolumeType == 2) { - QString telephoneName = tr("telephone device"); - QByteArray strTelePhone = telephoneName.toLocal8Bit(); - char *realTele = strTelePhone.data(); - if(uDiskCount == 1) { - newarea(1, "",strVolumeId,strMountId,realTele, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "",strVolumeId,strMountId,realTele, - strApiName,lluTotalSize,strMountUri,2); - } - } else { - if(uDiskCount == 1) { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,2); - } - } - } - } - } - // show mount info without drive & volume - map<string, FDMountInfo>& listMountInfo = m_dataFlashDisk->getDevInfoWithMount(); - if (!listMountInfo.empty()) { - map<string, FDMountInfo>::iterator itMountInfo = listMountInfo.begin(); - for (; itMountInfo != listMountInfo.end(); itMountInfo++) { - QString strApiName; - QString strMainName; - bool isCanShow = (itMountInfo->second.isCanUnmount || itMountInfo->second.isCanEject); - quint64 lluTotalSize = itMountInfo->second.lluTotalSize; - QString strMountUri = QString::fromStdString(itMountInfo->second.strUri); - QString strMountId = QString::fromStdString(itMountInfo->second.strId); - unsigned uMountType = 0; // 0:normal file, 1: cddata, 2:tele dev - if (itMountInfo->second.strId.empty() || !itMountInfo->second.isNewInsert) { - // is not new insert device - continue; - } - if (!itMountInfo->second.strId.empty()) { - string strMountUri = itMountInfo->second.strUri; - if(g_str_has_prefix(strMountUri.c_str(),"file:///")) { - uMountType = 0; - } else if (g_str_has_prefix(strMountUri.c_str(),"mtp://") || g_str_has_prefix(strMountUri.c_str(),"gphoto2://")){ - uMountType = 2; - } else if (g_str_has_prefix(strMountUri.c_str(),"burn:///")/* || g_str_has_prefix(strMountUri.c_str(),"cdda://")*/) { - uMountType = 1; - } - } else { - continue; - } - if (uMountType == 1 || uMountType == 2 || isCanShow) { // cd module or drive can show - uDiskCount++; - uVolumeCount++; - strMainName = strApiName = QString::fromStdString(itMountInfo->second.strName); - } else { - continue; - } - if (uDiskCount > 0) { - if (uMountType == 1) { // deal with cd info - if(uDiskCount == 1) { - newarea(1, "","",strMountId,strMainName, - strApiName,1, "burn:///", 1); - } else { - newarea(1, "","",strMountId,strMainName, - strApiName,1, "burn:///", 2); - } - } else if (uMountType == 2) { - QString telephoneName = tr("telephone device"); - QByteArray strTelePhone = telephoneName.toLocal8Bit(); - char *realTele = strTelePhone.data(); - if(uDiskCount == 1) { - newarea(1, "","",strMountId,realTele, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "","",strMountId,realTele, - strApiName,lluTotalSize,strMountUri,2); - } - } else { - if(uDiskCount == 1) { - newarea(1, "","",strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "","",strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,2); - } - } - } - } - } - } else { // show all device - //Convenient interface layout for all drives - map<string, FDDriveInfo>& listDriveInfo = m_dataFlashDisk->getDevInfoWithDrive(); - if (!listDriveInfo.empty()) { - map<string, FDDriveInfo>::iterator itDriveInfo = listDriveInfo.begin(); - for ( ;itDriveInfo != listDriveInfo.end(); itDriveInfo++) { - unsigned uVolumeNum = 0; - bool isCanShow = (itDriveInfo->second.isCanEject || itDriveInfo->second.isCanStop || itDriveInfo->second.isRemovable); - QString strDriveName = QString::fromStdString(itDriveInfo->second.strName); - if (itDriveInfo->second.listVolumes.size() > 0) { - uDiskCount++; - } - map<string, FDVolumeInfo>::iterator itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - for ( ;itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) { - QString strApiName; - quint64 lluTotalSize = itVolumeInfo->second.mountInfo.lluTotalSize; - QString strMountUri = QString::fromStdString(itVolumeInfo->second.mountInfo.strUri); - QString strDriveId = QString::fromStdString(itDriveInfo->second.strId); - QString strVolumeId = QString::fromStdString(itVolumeInfo->second.strId); - QString strMountId = QString::fromStdString(itVolumeInfo->second.mountInfo.strId); - unsigned uVolumeType = 0; // 0:normal file volume, 1: cddata, 2:tele dev - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - string strMountUri = itVolumeInfo->second.mountInfo.strUri; - if(g_str_has_prefix(strMountUri.c_str(),"file:///")) { - uVolumeType = 0; - } else if (g_str_has_prefix(strMountUri.c_str(),"mtp://") || g_str_has_prefix(strMountUri.c_str(),"gphoto2://")){ - uVolumeType = 2; - } else if (g_str_has_prefix(strMountUri.c_str(),"burn:///")/* || g_str_has_prefix(strMountUri.c_str(),"cdda://")*/) { - uVolumeType = 1; - } - } - if (uVolumeType == 1 || uVolumeType == 2 || isCanShow) { // cd module or drive can show - if (!itVolumeInfo->second.strId.empty()) { - uVolumeNum++; - uVolumeCount++; - strApiName = QString::fromStdString(itVolumeInfo->second.strName); - } else if (!itVolumeInfo->second.mountInfo.strId.empty()) { - uVolumeNum++; - uVolumeCount++; - strApiName = QString::fromStdString(itVolumeInfo->second.mountInfo.strName); - } else { - continue; - } - } else { - continue; - } - if (uDiskCount > 0) { - if (uVolumeType == 1) { // deal with cd info - if(uDiskCount == 1 || uVolumeNum != 1) { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName, 1, "burn:///", 1); - } else { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName, 1, "burn:///", 2); - } - } else if (uVolumeType == 2) { - QString telephoneName = tr("telephone device"); - QByteArray strTelePhone = telephoneName.toLocal8Bit(); - char *realTele = strTelePhone.data(); - if(uDiskCount == 1 || uVolumeNum != 1) { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,realTele, - strApiName, lluTotalSize, strMountUri,1); - } else { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,realTele, - strApiName, lluTotalSize, strMountUri,2); - } - } else { - if(uDiskCount == 1 || uVolumeNum != 1) { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName, lluTotalSize,strMountUri,1); - } else { - newarea(uVolumeNum, strDriveId,strVolumeId,strMountId,strDriveName, - strApiName,lluTotalSize,strMountUri,2); - } - } - } - } - } - } - // show volume info without drive - map<string, FDVolumeInfo>& listVolumeInfo = m_dataFlashDisk->getDevInfoWithVolume(); - if (!listVolumeInfo.empty()) { - map<string, FDVolumeInfo>::iterator itVolumeInfo = listVolumeInfo.begin(); - for (; itVolumeInfo != listVolumeInfo.end(); itVolumeInfo++) { - QString strApiName; - QString strMainName; - bool isCanShow = itVolumeInfo->second.isCanEject; - quint64 lluTotalSize = itVolumeInfo->second.mountInfo.lluTotalSize; - QString strMountUri = QString::fromStdString(itVolumeInfo->second.mountInfo.strUri); - QString strVolumeId = QString::fromStdString(itVolumeInfo->second.strId); - QString strMountId = QString::fromStdString(itVolumeInfo->second.mountInfo.strId); - unsigned uVolumeType = 0; // 0:normal file volume, 1: cddata, 2:tele dev - if (!itVolumeInfo->second.mountInfo.strId.empty()) { - string strMountUri = itVolumeInfo->second.mountInfo.strUri; - if(g_str_has_prefix(strMountUri.c_str(),"file:///")) { - uVolumeType = 0; - } else if (g_str_has_prefix(strMountUri.c_str(),"mtp://") || g_str_has_prefix(strMountUri.c_str(),"gphoto2://")){ - uVolumeType = 2; - } else if (g_str_has_prefix(strMountUri.c_str(),"burn:///")/* || g_str_has_prefix(strMountUri.c_str(),"cdda://")*/) { - uVolumeType = 1; - } - } - if (uVolumeType == 1 || uVolumeType == 2 || isCanShow) { // cd module or drive can show - if (!itVolumeInfo->second.strId.empty()) { - uDiskCount++; - uVolumeCount++; - strMainName = strApiName = QString::fromStdString(itVolumeInfo->second.strName); - } else if (!itVolumeInfo->second.mountInfo.strId.empty()) { - uDiskCount++; - uVolumeCount++; - strMainName = strApiName = QString::fromStdString(itVolumeInfo->second.mountInfo.strName); - } else { - continue; - } - } else { - continue; - } - if (uDiskCount > 0) { - if (uVolumeType == 1) { // deal with cd info - if(uDiskCount == 1) { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,1,"burn:///",1); - } else { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,1,"burn:///",2); - } - } else if (uVolumeType == 2) { - QString telephoneName = tr("telephone device"); - QByteArray strTelePhone = telephoneName.toLocal8Bit(); - char *realTele = strTelePhone.data(); - if(uDiskCount == 1) { - newarea(1, "",strVolumeId,strMountId,realTele, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "",strVolumeId,strMountId,realTele, - strApiName,lluTotalSize,strMountUri,2); - } - } else { - if(uDiskCount == 1) { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "",strVolumeId,strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,2); - } - } - } - } - } - // show mount info without drive & volume - map<string, FDMountInfo>& listMountInfo = m_dataFlashDisk->getDevInfoWithMount(); - if (!listMountInfo.empty()) { - map<string, FDMountInfo>::iterator itMountInfo = listMountInfo.begin(); - for (; itMountInfo != listMountInfo.end(); itMountInfo++) { - QString strApiName; - QString strMainName; - bool isCanShow = (itMountInfo->second.isCanUnmount || itMountInfo->second.isCanEject); - quint64 lluTotalSize = itMountInfo->second.lluTotalSize; - QString strMountUri = QString::fromStdString(itMountInfo->second.strUri); - QString strMountId = QString::fromStdString(itMountInfo->second.strId); - unsigned uMountType = 0; // 0:normal file, 1: cddata, 2:tele dev - if (!itMountInfo->second.strId.empty()) { - string strMountUri = itMountInfo->second.strUri; - if(g_str_has_prefix(strMountUri.c_str(),"file:///")) { - uMountType = 0; - } else if (g_str_has_prefix(strMountUri.c_str(),"mtp://") || g_str_has_prefix(strMountUri.c_str(),"gphoto2://")){ - uMountType = 2; - } else if (g_str_has_prefix(strMountUri.c_str(),"burn:///")/* || g_str_has_prefix(strMountUri.c_str(),"cdda://")*/) { - uMountType = 1; - } - } else { - continue; - } - if (uMountType == 1 || uMountType == 2 || isCanShow) { // cd module or drive can show - uDiskCount++; - uVolumeCount++; - strMainName = strApiName = QString::fromStdString(itMountInfo->second.strName); - } else { - continue; - } - if (uDiskCount > 0) { - if (uMountType == 1) { // deal with cd info - if(uDiskCount == 1) { - newarea(1, "","",strMountId,strMainName, - strApiName,1, "burn:///", 1); - } else { - newarea(1, "","",strMountId,strMainName, - strApiName,1, "burn:///", 2); - } - } else if (uMountType == 2) { - QString telephoneName = tr("telephone device"); - QByteArray strTelePhone = telephoneName.toLocal8Bit(); - char *realTele = strTelePhone.data(); - if(uDiskCount == 1) { - newarea(1, "","",strMountId,realTele, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "","",strMountId,realTele, - strApiName,lluTotalSize,strMountUri,2); - } - } else { - if(uDiskCount == 1) { - newarea(1, "","",strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,1); - } else { - newarea(1, "","",strMountId,strMainName, - strApiName,lluTotalSize,strMountUri,2); - } - } - } - } - } - } - if (uDiskCount > 0) { - uVolumeCount = uVolumeCount < uDiskCount ? uDiskCount : uVolumeCount; - hign = uDiskCount*FLASHDISKITEM_TITLE_HEIGHT+uVolumeCount*FLASHDISKITEM_CONTENT_HEIGHT; - ui->centralWidget->setFixedSize(280, hign); - } else { - hign = 0; - ui->centralWidget->setFixedSize(0, 0); - } - moveBottomNoBase(); - ui->centralWidget->show(); -} - -void MainWindow::ifgetPinitMount() -{ - int pointMountNum = 0; - QFile file(tmpPath); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - QString content = file.readLine().trimmed(); - while (!file.atEnd()) - { - if (content.contains(".mount")) { - pointMountNum += 1; - } - - content = file.readLine().trimmed(); - if(pointMountNum >= 1) { - findPointMount = true; - } else { - findPointMount = false; - } - } - } - file.close(); -} - -void MainWindow::onMaininterfacehide() -{ - ui->centralWidget->hide(); - this->driveVolumeNum = 0; - interfaceHideTime->stop(); - m_dataFlashDisk->resetAllNewState(); -} - -void MainWindow::moveBottomNoBase() -{ -#if 0 - int position=0; - int panelSize=0; - if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit())) - { - QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit()); - if(gsetting->keys().contains(QString("panelposition"))) - position=gsetting->get("panelposition").toInt(); - else - position=0; - if(gsetting->keys().contains(QString("panelsize"))) - panelSize=gsetting->get("panelsize").toInt(); - else - panelSize=SmallPanelSize; - } - else - { - position=0; - panelSize=SmallPanelSize; - } - - int x=QApplication::primaryScreen()->geometry().x(); - int y=QApplication::primaryScreen()->geometry().y(); - - if(position==0) - ui->centralWidget->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-ui->centralWidget->width() - DISTANCEMEND - DISTANCEPADDING,y+ QApplication::primaryScreen()->geometry().height()-panelSize-ui->centralWidget->height() - DISTANCEPADDING,ui->centralWidget->width(),ui->centralWidget->height())); - else if(position==1) - ui->centralWidget->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-ui->centralWidget->width() - DISTANCEMEND - DISTANCEPADDING,y+ panelSize + DISTANCEPADDING,ui->centralWidget->width(),ui->centralWidget->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show - else if(position==2) - ui->centralWidget->setGeometry(QRect(x+panelSize + DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - ui->centralWidget->height() - DISTANCEPADDING,ui->centralWidget->width(),ui->centralWidget->height())); - else - ui->centralWidget->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-ui->centralWidget->width() - DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - ui->centralWidget->height() - DISTANCEPADDING,ui->centralWidget->width(),ui->centralWidget->height())); - ui->centralWidget->repaint(); - -#endif - // MARGIN 为到任务栏或屏幕边缘的间隔 -#define MARGIN 4 - QDBusInterface iface("org.ukui.panel", - "/panel/position", - "org.ukui.panel", - QDBusConnection::sessionBus()); - QDBusReply<QVariantList> reply=iface.call("GetPrimaryScreenGeometry"); - - if (!iface.isValid() || !iface.isValid() || reply.value().size()<5) { - qCritical() << QDBusConnection::sessionBus().lastError().message(); - ui->centralWidget->setGeometry(0,0,ui->centralWidget->width(),ui->centralWidget->height()); - } else { - // reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 - QVariantList position_list=reply.value(); - - switch(reply.value().at(4).toInt()){ - case 1: - // 任务栏位于上方 - ui->centralWidget->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-ui->centralWidget->width()-MARGIN, - position_list.at(1).toInt()+MARGIN, - ui->centralWidget->width(),ui->centralWidget->height()); - break; - // 任务栏位于左边 - case 2: - ui->centralWidget->setGeometry(position_list.at(0).toInt()+MARGIN, - position_list.at(1).toInt()+reply.value().at(3).toInt()-ui->centralWidget->height()-MARGIN, - ui->centralWidget->width(),this->height()); - break; - // 任务栏位于右边 - case 3: - ui->centralWidget->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-ui->centralWidget->width()-MARGIN, - position_list.at(1).toInt()+reply.value().at(3).toInt()-ui->centralWidget->height()-MARGIN, - ui->centralWidget->width(),ui->centralWidget->height()); - break; - // 任务栏位于下方 - default: - ui->centralWidget->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-ui->centralWidget->width()-MARGIN, - position_list.at(1).toInt()+reply.value().at(3).toInt()-ui->centralWidget->height()-MARGIN, - ui->centralWidget->width(),ui->centralWidget->height()); - break; - } - } -} - -/* - * determine how to open the maininterface,if trigger is 0,the main interface show when we inset USB - * device directly,if trigger is 1,we show main interface by clicking the systray icon. -*/ -bool MainWindow::eventFilter(QObject *obj, QEvent *event) -{ - #if 0 - if(triggerType == 0) - { - if(event->type() == QEvent::Enter) - { - disconnect(interfaceHideTime, SIGNAL(timeout()), this, SLOT(onMaininterfacehide())); - this->show(); - } - - if(event->type() == QEvent::Leave) - { - connect(interfaceHideTime, SIGNAL(timeout()), this, SLOT(onMaininterfacehide())); - interfaceHideTime->start(2000); - } - } - - if(triggerType == 1){} - - if (obj == this) - { - if (event->type() == QEvent::WindowDeactivate && !(this->isHidden())) - { - this->hide(); - return true; - } - } - if (!isActiveWindow()) - { - activateWindow(); - } - #endif - return false; -} - -// new a gsettings object to get the information of the opacity of the window -void MainWindow::initTransparentState() -{ - const QByteArray idtrans(THEME_QT_TRANS); - - if(QGSettings::isSchemaInstalled(idtrans)) - { - m_transparency_gsettings = new QGSettings(idtrans); - } -} - -// use gsettings to get the opacity -void MainWindow::getTransparentData() -{ - if (!m_transparency_gsettings) { - m_transparency = 0.95; - return; - } - - QStringList keys = m_transparency_gsettings->keys(); - if (keys.contains("transparency")) { - m_transparency = m_transparency_gsettings->get("transparency").toDouble(); - } -} - -void MainWindow::paintEvent(QPaintEvent *event) -{ - QPainterPath path; - auto rect = this->rect(); - rect.adjust(1, 1, -1, -1); - path.addRoundedRect(rect, 4, 4); - setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon())); - - QStyleOption opt; - opt.init(this); - QPainter p(this); - QRect rectReal = this->rect(); - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - p.setBrush(opt.palette.color(QPalette::Base)); - p.setOpacity(m_transparency); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rectReal, 4, 4); - QWidget::paintEvent(event); - - KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); -} - -void MainWindow::onEjectVolumeForce(GVolume *v) -{ - g_volume_eject_with_operation(v, G_MOUNT_UNMOUNT_FORCE, nullptr, nullptr, GAsyncReadyCallback(&MainWindow::frobnitz_force_result_func), this); -} - -void MainWindow::AsyncUnmount(QString strMountRoot,MainWindow *p_this) -{ - qInfo() << "dataPath:" << strMountRoot; - QProcess p; - p.setProgram("pkexec"); - p.setArguments(QStringList() << "eject" << strMountRoot); - p.start(); - - bool bSuccess = p.waitForFinished(); - - if (p_this) { - p_this->ifSucess = bSuccess; - } -} - -void MainWindow::frobnitz_force_result_func(GDrive *source_object,GAsyncResult *res, MainWindow *p_this) -{ - auto env = qgetenv("QT_QPA_PLATFORMTHEME"); - gboolean success = FALSE; - GError *err = nullptr; - success = g_drive_eject_with_operation_finish (source_object, res, &err); - - if (!err) { - FDDriveInfo driveInfo; - char *devPath = g_drive_get_identifier(source_object,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - g_free(devPath); - } - - char *strName = g_drive_get_name(source_object); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - - p_this->m_eject = new ejectInterface(p_this->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - p_this->m_eject->show(); - FlashDiskData::getInstance()->removeDriveInfo(driveInfo); - if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { - p_this->m_systray->hide(); - } - } else { - GList* listVolume = g_drive_get_volumes(source_object); - if (listVolume) { - GList* lVolume = NULL; - for (lVolume = listVolume; lVolume != NULL; lVolume= lVolume->next) { - GVolume* gvolume = (GVolume *)lVolume->data; - GMount* gmount = g_volume_get_mount(gvolume); - if (gmount) { - GFile* root = g_mount_get_root(gmount); - if (root) { - char* strMountRoot = g_file_get_path(root); - if (strMountRoot) { - QString strMountPath = strMountRoot; - QtConcurrent::run(&MainWindow::AsyncUnmount, strMountPath, p_this); - g_free(strMountRoot); - } - g_object_unref(root); - } - g_object_unref(gmount); - } - } - g_list_free(listVolume); - listVolume = NULL; - } - } -} - -void MainWindow::frobnitz_result_func(GDrive *source_object,GAsyncResult *res,MainWindow *p_this) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_drive_eject_with_operation_finish (source_object, res, &err); - - if (!err) { - FDDriveInfo driveInfo; - char *devPath = g_drive_get_identifier(source_object,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - g_free(devPath); - } - - char *strName = g_drive_get_name(source_object); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - - p_this->m_eject = new ejectInterface(p_this->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - p_this->m_eject->show(); - FlashDiskData::getInstance()->removeDriveInfo(driveInfo); - if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { - p_this->m_systray->hide(); - } - } else /*if(g_drive_can_stop(source_object) == true)*/ { - FDDriveInfo driveInfo; - char *devPath = g_drive_get_identifier(source_object,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - driveInfo.strId = devPath; - g_free(devPath); - } - - char *strName = g_drive_get_name(source_object); - if (strName) { - driveInfo.strName = strName; - g_free(strName); - } - - if (p_this->chooseDialog == nullptr) { - p_this->chooseDialog = new interactiveDialog(QString::fromStdString(driveInfo.strId), p_this->ui->centralWidget); - }else{ - p_this->chooseDialog->updateContentLable(QString::fromStdString(driveInfo.strId)); - } - p_this->chooseDialog->show(); - p_this->chooseDialog->setFocus(); - p_this->connect(p_this->chooseDialog,&interactiveDialog::FORCESIG,p_this,[=]() { - g_drive_eject_with_operation(source_object, - G_MOUNT_UNMOUNT_FORCE, - NULL, - NULL, - GAsyncReadyCallback(&MainWindow::frobnitz_force_result_func), - p_this - ); - p_this->chooseDialog->close(); - }); - } -} - -void MainWindow::frobnitz_normal_result_volume_eject(GVolume *source_object,GAsyncResult *res,MainWindow *p_this) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_volume_eject_with_operation_finish(source_object, res, &err); - if(!err) { - FDVolumeInfo volumeInfo; - char *volumeId = g_volume_get_identifier(source_object,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - volumeInfo.strId = volumeId; - g_free(volumeId); - } - - FlashDiskData::getInstance()->removeVolumeInfo(volumeInfo); - if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { - p_this->m_systray->hide(); - } - } -} - -void MainWindow::frobnitz_force_result_unmount(GMount *source_object,GAsyncResult *res,MainWindow *p_this) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_mount_unmount_with_operation_finish(source_object,res, &err); - if(!err) { - FDMountInfo mountInfo; - mountInfo.isCanEject = g_mount_can_eject(source_object); - char *mountId = g_mount_get_uuid(source_object); - if (mountId) { - mountInfo.strId = mountId; - g_free(mountId); - } - - GFile *root = g_mount_get_default_location(source_object); - if (root) { - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - mountInfo.strUri = mountUri; - g_free(mountUri); - if (mountInfo.strId.empty()) { - mountInfo.strId = mountInfo.strUri; - } - } - g_object_unref(root); - } - - FlashDiskData::getInstance()->removeMountInfo(mountInfo); - if(FlashDiskData::getInstance()->getValidInfoCount() == 0) - { - p_this->m_systray->hide(); - } - } -} - -void MainWindow::onClickedEject(EjectDeviceInfo eDeviceInfo) -{ - m_curEjectDeviceInfo = eDeviceInfo; - m_curEjectDeviceInfo.pVoid = this; - m_curEjectDeviceInfo.uFlag = G_MOUNT_UNMOUNT_NONE; - doRealEject(&m_curEjectDeviceInfo, G_MOUNT_UNMOUNT_NONE); -} - -bool MainWindow::onDeviceErrored(GDrive* drive) -{ - g_return_val_if_fail(G_IS_DRIVE(drive), false); - - g_autofree char* device = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - - g_return_val_if_fail(device && strstr(device, "/dev/sd"), false); - - g_return_val_if_fail (DeviceOperation::getDriveSize(drive) > 0, false); - - GList* volumes = g_drive_get_volumes(drive); - if (!volumes && !mRepairDialog.contains(device)) { - RepairDialogBox* b = new RepairDialogBox(drive); - b->connect(b, &RepairDialogBox::repairOK, this, [=] (RepairDialogBox* d) { - if (mRepairDialog.contains(d->getDeviceName())) { - b->mshowflag = false; - mRepairDialog.remove(d->getDeviceName()); - } - }); - mRepairDialog[device] = b; - b->mshowflag = true; - b->show(); - } else { - for (auto v = volumes; nullptr != v; v = v->next) { - GVolume* vv = G_VOLUME(v->data); - g_autofree char* volumeName = g_volume_get_identifier (vv, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_autoptr(GMount) m = g_volume_get_mount(vv); - if (!m) { - if (volumeName && !mRepairDialog.contains(volumeName)) { - RepairDialogBox* b = new RepairDialogBox(vv); - b->connect(b, &RepairDialogBox::remountDevice, this, &MainWindow::remountVolume); - b->connect(b, &RepairDialogBox::repairOK, this, [=] (RepairDialogBox* d) { - if (mRepairDialog.contains(d->getDeviceName())) { - b->mshowflag = false; - mRepairDialog.remove(d->getDeviceName()); - } - }); - mRepairDialog[volumeName] = b; - b->mshowflag = true; - b->show(); - } - } - } - g_list_free_full(volumes, g_object_unref); - } - - return true; -} - -void MainWindow::onMountVolume(GVolume* v) -{ - g_volume_mount(v, G_MOUNT_MOUNT_NONE, nullptr, nullptr, GAsyncReadyCallback(frobnitz_result_func_volume), this); -} - -bool MainWindow::doRealEject(EjectDeviceInfo* peDeviceInfo, GMountUnmountFlags flag) -{ - // find the device's drive & volume & mount - if (!peDeviceInfo || !peDeviceInfo->pVoid) { - return false; - } - - GList *lDrive = NULL; - GList *lVolume = NULL; - GList *lMount = NULL; - GList *current_drive_list = NULL; - GList *current_volume_list = NULL; - GList *current_mount_list = NULL; - GDrive* devDrive = NULL; - GVolume* devVolume = NULL; - GMount* devMount = NULL; - unsigned uVolumeSize = 0; - bool isDone = false; - - //about drive - GVolumeMonitor *g_volume_monitor = g_volume_monitor_get(); - if (!peDeviceInfo->strDriveId.isEmpty()) { - current_drive_list = g_volume_monitor_get_connected_drives(g_volume_monitor); - for (lDrive = current_drive_list; lDrive != NULL; lDrive = lDrive->next) { - GDrive *gdrive = (GDrive *)lDrive->data; - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - if(peDeviceInfo->strDriveId == devPath) { - devDrive = gdrive; - current_volume_list = g_drive_get_volumes(gdrive); - if (current_volume_list) { - uVolumeSize = g_list_length(current_volume_list); - for(lVolume = current_volume_list; lVolume != NULL; lVolume = lVolume->next){ //遍历驱动器上的所有卷设备 - GVolume* volume = (GVolume *)lVolume->data; - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - if (peDeviceInfo->strVolumeId != volumeId) { - g_free(volumeId); - continue; - } - g_free(volumeId); - } else { - continue ; - } - devVolume = volume; - break; - } - } - } - g_free(devPath); - } - } - if (devDrive != NULL) { - if (devDrive != NULL) { - if (peDeviceInfo->strMountUri.isEmpty()) { - g_drive_eject_with_operation(devDrive, - flag, - NULL, - NULL, - GAsyncReadyCallback(&MainWindow::frobnitz_result_func), - peDeviceInfo->pVoid); - isDone = true; - } else { - if (g_drive_can_eject(devDrive)){//for udisk or DVD. - g_drive_eject_with_operation(devDrive, - flag, - NULL, - NULL, - GAsyncReadyCallback(&MainWindow::frobnitz_result_func), - peDeviceInfo->pVoid); - isDone = true; - #if 0 - GFile *file = g_file_new_for_uri(peDeviceInfo->strMountUri.toUtf8().constData()); - if (file) { - g_file_eject_mountable_with_operation(file, - flag, - nullptr, - nullptr, - GAsyncReadyCallback(fileEjectMountableCB), - peDeviceInfo); - g_object_unref(file); - isDone = true; - } - #endif - } else if(g_drive_can_stop(devDrive) || g_drive_is_removable(devDrive)){//for mobile harddisk. - g_drive_stop(devDrive, flag, NULL, NULL, - GAsyncReadyCallback(driveStopCb), - peDeviceInfo); - isDone = true; - } - } - } - } - if (current_volume_list) { - g_list_free(current_volume_list); - current_volume_list = NULL; - } - if (current_drive_list) { - g_list_free(current_drive_list); - current_drive_list = NULL; - } - } - - //about volume not associated with a drive - if (!isDone && !peDeviceInfo->strVolumeId.isEmpty()) { - current_volume_list = g_volume_monitor_get_volumes(g_volume_monitor); - if (current_volume_list) { - for (lVolume = current_volume_list; lVolume != NULL; lVolume = lVolume->next) { - GVolume *volume = (GVolume *)lVolume->data; - GDrive *gdrive = g_volume_get_drive(volume); - if (!gdrive) { - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - if (peDeviceInfo->strVolumeId != volumeId) { - g_free(volumeId); - continue; - } - g_free(volumeId); - } else { - continue ; - } - devVolume = volume; - break; - } else { - g_object_unref(gdrive); - } - } - } - if (devVolume != NULL) { - GMount* pCurMount = g_volume_get_mount(devVolume); - if (pCurMount) { - g_mount_unmount_with_operation(pCurMount, - flag, - NULL, - NULL, - GAsyncReadyCallback(&MainWindow::frobnitz_force_result_unmount), - peDeviceInfo->pVoid); - g_object_unref(pCurMount); - isDone = true; - } - } - if (current_volume_list) { - g_list_free(current_volume_list); - current_volume_list = NULL; - } - } - - //about mount not associated with a volume - if (!isDone && !peDeviceInfo->strMountId.isEmpty()) { - current_mount_list = g_volume_monitor_get_mounts(g_volume_monitor); - if (current_mount_list) { - for (lMount = current_mount_list; lMount != NULL; lMount = lMount->next) { - GMount *gmount = (GMount *)lMount->data; - GVolume *gvolume = g_mount_get_volume(gmount); - if (!gvolume) { - QString strId = ""; - char *mountId = g_mount_get_uuid(gmount); - if (mountId) { - strId = mountId; - g_free(mountId); - } - // get mount uri - GFile *root = g_mount_get_default_location(gmount); - if (root) { - char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 - if (mountUri) { - if (strId.isEmpty()) { - strId = mountUri; - } - g_free(mountUri); - } - g_object_unref(root); - } - if (peDeviceInfo->strMountId == strId) { - devMount = gmount; - break; - } - } else { - g_object_unref(gvolume); - } - } - if (devMount != NULL) { - g_mount_unmount_with_operation(devMount, - flag, - NULL, - NULL, - GAsyncReadyCallback(&MainWindow::frobnitz_force_result_unmount), - peDeviceInfo->pVoid); - isDone = true; - } - g_list_free(current_mount_list); - current_mount_list = NULL; - } - } - if (!isDone) { - FDMountInfo mountInfo; - FDVolumeInfo volumeInfo; - FDDriveInfo driveInfo; - mountInfo.strId = peDeviceInfo->strMountId.toStdString(); - m_dataFlashDisk->removeMountInfo(mountInfo); - volumeInfo.strId = peDeviceInfo->strVolumeId.toStdString(); - m_dataFlashDisk->removeVolumeInfo(volumeInfo); - driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); - m_dataFlashDisk->removeDriveInfo(driveInfo); - if(m_dataFlashDisk->getValidInfoCount() == 0) { - m_systray->hide(); - } - } - ui->centralWidget->hide(); - return true; -} - -GAsyncReadyCallback MainWindow::fileEjectMountableCB(GFile *file, GAsyncResult *res, EjectDeviceInfo *peDeviceInfo) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_file_eject_mountable_with_operation_finish(file, res, &err); - if (!err) { - FDDriveInfo driveInfo; - driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); - driveInfo.strName = peDeviceInfo->strDriveName.toStdString(); - MainWindow* pThis = (MainWindow*)(peDeviceInfo->pVoid); - pThis->m_eject = new ejectInterface(pThis->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - pThis->m_eject->show(); - FlashDiskData::getInstance()->removeDriveInfo(driveInfo); - if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { - pThis->m_systray->hide(); - } - } else /*if(g_drive_can_stop(source_object) == true)*/ { - if (peDeviceInfo->uFlag != G_MOUNT_UNMOUNT_FORCE) { - FDDriveInfo driveInfo; - driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); - driveInfo.strName = peDeviceInfo->strDriveName.toStdString(); - MainWindow* pThis = (MainWindow*)(peDeviceInfo->pVoid); - if (pThis->chooseDialog == nullptr) { - pThis->chooseDialog = new interactiveDialog(QString::fromStdString(driveInfo.strId), pThis->ui->centralWidget); - } - pThis->chooseDialog->show(); - pThis->chooseDialog->setFocus(); - pThis->connect(pThis->chooseDialog,&interactiveDialog::FORCESIG,pThis,[=]() { - pThis->chooseDialog->close(); - peDeviceInfo->uFlag = G_MOUNT_UNMOUNT_FORCE; - pThis->doRealEject(peDeviceInfo, G_MOUNT_UNMOUNT_FORCE); - }); - } - } - return nullptr; -} - -void MainWindow::driveStopCb(GObject* object, GAsyncResult* res, EjectDeviceInfo *peDeviceInfo) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_drive_stop_finish(G_DRIVE(object), res, &err); - qInfo() << "driveStopCb:" << success; - - if (success || !err || (G_IO_ERROR_FAILED_HANDLED == err->code)) { - FDDriveInfo driveInfo; - driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); - driveInfo.strName = peDeviceInfo->strDriveName.toStdString(); - MainWindow* pThis = (MainWindow*)(peDeviceInfo->pVoid); - pThis->m_eject = new ejectInterface(pThis->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - pThis->m_eject->show(); - FlashDiskData::getInstance()->removeDriveInfo(driveInfo); - if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { - pThis->m_systray->hide(); - } - } else { - if (peDeviceInfo->uFlag != G_MOUNT_UNMOUNT_FORCE) { - FDDriveInfo driveInfo; - driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); - driveInfo.strName = peDeviceInfo->strDriveName.toStdString(); - MainWindow* pThis = (MainWindow*)(peDeviceInfo->pVoid); - if (pThis->chooseDialog == nullptr) { - pThis->chooseDialog = new interactiveDialog(QString::fromStdString(driveInfo.strId), pThis->ui->centralWidget); - } - pThis->chooseDialog->show(); - pThis->chooseDialog->setFocus(); - pThis->connect(pThis->chooseDialog,&interactiveDialog::FORCESIG,pThis,[=]() { - pThis->chooseDialog->close(); - peDeviceInfo->uFlag = G_MOUNT_UNMOUNT_FORCE; - pThis->doRealEject(peDeviceInfo, G_MOUNT_UNMOUNT_FORCE); - }); - } - } -} - -void MainWindow::onRemountVolume(FDVolumeInfo volumeInfo) -{ - if (volumeInfo.strId.empty()) { - return; - } - - if (!(g_str_has_prefix(volumeInfo.strId.c_str(),"/dev/bus") || g_str_has_prefix(volumeInfo.strId.c_str(),"/dev/sd"))) { - return; - } - - qInfo() << "volumeInfo.strId:" << volumeInfo.strId.c_str(); - GList *lDrive = NULL; - GList *lVolume = NULL; - GList *current_drive_list = NULL; - GList *current_volume_list = NULL; - GDrive* devDrive = NULL; - GVolume* devVolume = NULL; - bool isDone = false; - - //about drive - GVolumeMonitor *g_volume_monitor = g_volume_monitor_get(); - current_drive_list = g_volume_monitor_get_connected_drives(g_volume_monitor); - for (lDrive = current_drive_list; lDrive != NULL; lDrive = lDrive->next) { - GDrive *gdrive = (GDrive *)lDrive->data; - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - devDrive = gdrive; - current_volume_list = g_drive_get_volumes(gdrive); - if (current_volume_list) { - for(lVolume = current_volume_list; lVolume != NULL; lVolume = lVolume->next){ //遍历驱动器上的所有卷设备 - GVolume* volume = (GVolume *)lVolume->data; - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - if (volumeInfo.strId != volumeId) { - g_free(volumeId); - continue; - } - g_free(volumeId); - } else { - continue ; - } - devVolume = volume; - break; - } - } - g_free(devPath); - } - } - if (devVolume != NULL) { - isDone = true; - GMount* pCurMount = g_volume_get_mount(devVolume); - if (pCurMount) { - g_object_unref(pCurMount); - } else { - volumeInfo.isCanMount = g_volume_can_mount(devVolume); - qInfo()<<"Volume canmount:"<<volumeInfo.isCanMount<<"|"<<ifsettings->get(IFAUTOLOAD).toBool(); - if(ifsettings->get(IFAUTOLOAD).toBool()) { - g_volume_mount(devVolume, - G_MOUNT_MOUNT_NONE, - nullptr, - nullptr, - GAsyncReadyCallback(frobnitz_result_func_volume), - this); - } - } - } - if (current_volume_list) { - g_list_free(current_volume_list); - current_volume_list = NULL; - } - if (current_drive_list) { - g_list_free(current_drive_list); - current_drive_list = NULL; - } - - //about volume not associated with a drive - if (!isDone) { - current_volume_list = g_volume_monitor_get_volumes(g_volume_monitor); - if (current_volume_list) { - for (lVolume = current_volume_list; lVolume != NULL; lVolume = lVolume->next) { - GVolume *volume = (GVolume *)lVolume->data; - GDrive *gdrive = g_volume_get_drive(volume); - if (!gdrive) { - char *volumeId = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - if (volumeId) { - if (volumeInfo.strId != volumeId) { - g_free(volumeId); - continue; - } - g_free(volumeId); - } else { - continue ; - } - devVolume = volume; - break; - } else { - g_object_unref(gdrive); - } - } - } - if (devVolume != NULL) { - isDone = true; - GMount* pCurMount = g_volume_get_mount(devVolume); - if (pCurMount) { - g_object_unref(pCurMount); - } else { - volumeInfo.isCanMount = g_volume_can_mount(devVolume); - qInfo()<<"Volume canmount:"<<volumeInfo.isCanMount<<"|"<<ifsettings->get(IFAUTOLOAD).toBool(); - if(ifsettings->get(IFAUTOLOAD).toBool()) { - g_volume_mount(devVolume, - G_MOUNT_MOUNT_NONE, - nullptr, - nullptr, - GAsyncReadyCallback(frobnitz_result_func_volume), - this); - } - } - } - if (current_volume_list) { - g_list_free(current_volume_list); - current_volume_list = NULL; - } - } -} - -void MainWindow::onCheckDriveValid(FDDriveInfo driveInfo) -{ - if (driveInfo.strId.empty()) { - return; - } - - qInfo() << "driveInfo.strId:" << driveInfo.strId.c_str(); - if(!this->isSystemRootDev(driveInfo.strId.c_str()) && - (driveInfo.isCanEject || driveInfo.isCanStop || driveInfo.isRemovable)) { - if(g_str_has_prefix(driveInfo.strId.c_str(),"/dev/sr") || g_str_has_prefix(driveInfo.strId.c_str(),"/dev/bus") - || g_str_has_prefix(driveInfo.strId.c_str(),"/dev/sd") || g_str_has_prefix(driveInfo.strId.c_str(),"/dev/mmcblk")) { - - GList *lDrive = NULL; - GList *current_drive_list = NULL; - GDrive* devDrive = NULL; - - //about drive - GVolumeMonitor *g_volume_monitor = g_volume_monitor_get(); - current_drive_list = g_volume_monitor_get_connected_drives(g_volume_monitor); - for (lDrive = current_drive_list; lDrive != NULL; lDrive = lDrive->next) { - GDrive *gdrive = (GDrive *)lDrive->data; - char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - string strId = devPath; - if (strId == driveInfo.strId) { - devDrive = gdrive; - g_free(devPath); - break; - } - g_free(devPath); - } - } - if (devDrive != NULL) { - if (!g_drive_has_volumes(devDrive)) { - Q_EMIT this->deviceError(devDrive); - } - } - if (current_drive_list) { - g_list_free(current_drive_list); - current_drive_list = NULL; - } - } - } -} - -bool MainWindow::getDataCDRomCapacity(QString strDevId, quint64 &totalCapacity) -{ - if (!strDevId.startsWith("/dev/sr")) { - return false; - } - - quint64 uTotalCapacity = 0; - DataCDROM *cdrom = new DataCDROM(strDevId); - if (cdrom) { - cdrom->getCDROMInfo(); - uTotalCapacity = cdrom->getCDROMCapacity(); - delete cdrom; - cdrom = nullptr; - } - if (uTotalCapacity > 0) { - totalCapacity = uTotalCapacity; - return true; - } else { - return false; - } -} - -void MainWindow::getDriveIconsInfo(GDrive* drive, FDDriveInfo& driveInfo) -{ - GIcon *g_icon = g_drive_get_icon(drive); - if (g_icon) { - if (G_IS_THEMED_ICON(g_icon)) { - const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_icon)); - if (icon_names) { - driveInfo.strIconPath = *icon_names; - } - } - g_object_unref(g_icon); - } -} - -void MainWindow::getVolumeIconsInfo(GVolume* volume, FDVolumeInfo& volumeInfo) -{ - GIcon *g_icon = g_volume_get_icon(volume); - if (g_icon) { - if (G_IS_THEMED_ICON(g_icon)) { - const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_icon)); - if (icon_names) { - volumeInfo.strIconPath = *icon_names; - } - } - g_object_unref(g_icon); - } -} - -void MainWindow::getMountIconsInfo(GMount* mount, FDMountInfo& mountInfo) -{ - GIcon *g_icon = g_mount_get_icon(mount); - if (g_icon) { - if (G_IS_ICON(g_icon)) { - if (G_IS_THEMED_ICON(g_icon)) { - const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_icon)); - if (icon_names) { - mountInfo.strIconPath = *icon_names; - } - } else { - // if it's a bootable-media,maybe we can get the icon from the mount directory. - char *bootableIcon = g_icon_to_string(g_icon); - if(bootableIcon) { - mountInfo.strIconPath = bootableIcon; - g_free(bootableIcon); - } - } - } - g_object_unref(g_icon); - } -} - -#if UDFAUTOMOUNT -static void eject_cdrom (GDrive* drive, gpointer u) -{ - qDebug() << "DJ- eject!!!"; - - g_return_if_fail (G_IS_DRIVE (drive)); - - g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - - if (devName) { - if (gMountCdrom->contains (QString(devName))) { - gMountCdrom->remove (QString(devName)); - QStringList mountPoints; - for (auto val : gMountCdromMountPoint->values()) { - if (QString(devName) == val) { - mountPoints << val; - } - } - for (auto m : mountPoints) - gMountCdromMountPoint->remove (m); - } - } -} - -static void mount_cdrom (GDrive* drive, gpointer u) -{ - g_return_if_fail(G_IS_DRIVE (drive)); - - if (!gMountCdrom) { - gMountCdrom = new QMap<QString, bool>(); - } - - if (!gMountCdromMountPoint) { - gMountCdromMountPoint = new QMap<QString, QString>(); - } - - bool canMount = true; - if (g_drive_has_media (drive)) { - g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - const char* name = g_get_user_name (); - if (devName && name) { - - QString mountPoint = QString("/media/%1/%2").arg(name) - .arg(QString(QCryptographicHash::hash(devName, QCryptographicHash::Md5).toBase64() - .replace ("/", "").replace ("+","").replace ("=", ""))); - - if (gMountCdrom->contains (devName) && !(*gMountCdrom)[QString(devName)]) { - canMount = false; - } - - if (canMount) { - int ret = QProcess::execute ("pkexec", QStringList() - << "/usr/bin/ukui-flash-disks-pkexec.sh" - << "-d" - << devName - << "-p" - << mountPoint); - - qDebug() << "DJ- execute 'mount_cdrom' return: " << ret; - - if (!gMountCdrom->contains (devName)) { - gMountCdrom->insert (QString(devName), true); - gMountCdromMountPoint->insert (mountPoint, QString(devName)); - } - } - } - } else { - eject_cdrom (drive, u); - } -} -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/mainwindow.h ukui-panel-4.0.0.0/ukui-flash-disk/mainwindow.h --- ukui-panel-3.14.0.1/ukui-flash-disk/mainwindow.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/mainwindow.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,227 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H -#include <QMainWindow> -#include <QtWidgets> -#include <QLabel> -#include <QPushButton> -#include <QSystemTrayIcon> -#include <QIcon> -#include <gio/gio.h> -#include <glib.h> -#include <QApplication> -#include <QEvent> -#include <qgsettings.h> -#include <QMap> -#include <vector> - -using namespace std; - -#include "qclickwidget.h" -#include "UnionVariable.h" -#include "ejectInterface.h" -#include "mainwindow.h" -#include "MacroFile.h" -#include "flashdiskdata.h" -#include "fdclickwidget.h" -#include "repair-dialog-box.h" - -#define UDFAUTOMOUNT 0 - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -public: - QSystemTrayIcon *m_systray; - ejectInterface *m_eject = nullptr; - interactiveDialog *chooseDialog = nullptr; - bool m_ismountadd = false; - bool ifSucess; - int flagType; - int driveMountNum; - vector<string> m_vtDeviveId; - EjectDeviceInfo m_curEjectDeviceInfo; - - void MainWindowShow(bool isUpdate = false); - void initTransparentState(); - void initThemeMode(); - void getTransparentData(); - int getPanelPosition(QString str); - int getPanelHeight(QString str); - -protected: - void hideEvent(QHideEvent event); - void resizeEvent(QResizeEvent *event); - bool eventFilter(QObject *obj, QEvent *event); - void paintEvent(QPaintEvent *event); - -private: - Ui::MainWindow *ui; - QVBoxLayout *vboxlayout; - QLabel *no_device_label; - QPushButton *eject_image_button; - - char *UDiskPathDis1; - char *UDiskPathDis2; - char *UDiskPathDis3; - char *UDiskPathDis4; - quint64 totalDis1; - quint64 totalDis2; - quint64 totalDis3; - quint64 totalDis4; - QClickWidget *open_widget; - FDClickWidget *m_fdClickWidget; - int hign; - int VolumeNum; - QTimer *interfaceHideTime; - int num = 0; - QScreen *screen; - int triggerType = 0; //detective the type of MainWinow(insert USB disk or click systemtray icon) - - double m_transparency; - QString currentThemeMode; - - QGSettings *m_transparency_gsettings = nullptr; - - QWidget *line = nullptr; - bool ifautoload; - bool insertorclick; - - QGSettings * ifsettings = nullptr; - int telephoneNum; - QString tmpPath; - bool findPointMount; - int driveVolumeNum; - FlashDiskData* m_dataFlashDisk = nullptr; - bool m_bIsMouseInTraIcon = false; - bool m_bIsMouseInCentral = false; - qint64 m_nAppStartTimestamp = 0; // 进程启动时的时间戳 - QString m_strSysRootDev; - - bool mIsrunning = false; - QMap<QString, RepairDialogBox*> mRepairDialog; - - void initFlashDisk(); - void initSlots(); - - void newarea(int No, - GDrive *Drive, - GVolume *Volume, - QString Drivename, - QString nameDis1, - QString nameDis2, - QString nameDis3, - QString nameDis4, - qlonglong capacityDis1, - qlonglong capacityDis2, - qlonglong capacityDis3, - qlonglong capacityDis4, - QString pathDis1, - QString pathDis2, - QString pathDis3, - QString pathDis4, - int linestatus); - void newarea(unsigned uDiskNo, - QString strDriveId, - QString strVolumeId, - QString strMountId, - QString driveName, - QString volumeName, - quint64 capacityDis, - QString strMountUri, - int linestatus); - void moveBottomRight(); - void moveBottomDirect(GDrive *drive); - void moveBottomNoBase(); - - QString size_human(qlonglong capacity); - void getDeviceInfo(); - static void frobnitz_result_func_volume(GVolume *source_object,GAsyncResult *res,MainWindow *p_this); - static void frobnitz_result_func_mount(GMount *source_object,GAsyncResult *res,MainWindow *p_this); - //static void frobnitz_result_func_volume(GVolume *source_object,GAsyncResult *res,gpointer); - static void drive_connected_callback (GVolumeMonitor *monitor, GDrive *drive, MainWindow *p_this); - static void drive_disconnected_callback (GVolumeMonitor *monitor, GDrive *drive, MainWindow *p_this); - static void volume_added_callback (GVolumeMonitor *monitor, GVolume *volume, MainWindow *p_this); - static void volume_removed_callback (GVolumeMonitor *monitor, GVolume *volume, MainWindow *p_this); - static void mount_added_callback (GVolumeMonitor *monitor, GMount *mount, MainWindow *p_this); - static void mount_removed_callback (GVolumeMonitor *monitor, GMount *mount, MainWindow *p_this); - void ifgetPinitMount(); - static void frobnitz_force_result_func(GDrive *source_object,GAsyncResult *res,MainWindow *p_this); - static void frobnitz_result_func(GDrive *source_object,GAsyncResult *res,MainWindow *p_this); - static void frobnitz_normal_result_volume_eject(GVolume *source_object,GAsyncResult *res,MainWindow *p_this); - static void frobnitz_force_result_unmount(GMount *source_object,GAsyncResult *res,MainWindow *p_this); - static void AsyncUnmount(QString strMountRoot,MainWindow *p_this); - - void getSystemRootDev(); - bool isSystemRootDev(QString strDev); - - bool doRealEject(EjectDeviceInfo* peDeviceInfo, GMountUnmountFlags flag); - static GAsyncReadyCallback fileEjectMountableCB(GFile *file, GAsyncResult *res, EjectDeviceInfo *peDeviceInfo); - static void driveStopCb(GObject* object, GAsyncResult* res, EjectDeviceInfo *peDeviceInfo); - - bool getDataCDRomCapacity(QString strDevId, quint64 &totalCapacity); - void getDriveIconsInfo(GDrive* drive, FDDriveInfo& driveInfo); - void getVolumeIconsInfo(GVolume* volume, FDVolumeInfo& volumeInfo); - void getMountIconsInfo(GMount* mount, FDMountInfo& mountInfo); - bool getDevInterface(QString strDev); - -public Q_SLOTS: - void iconActivated(QSystemTrayIcon::ActivationReason reason); - void onConvertShowWindow(QString strDriveId, QString strMountUri); - void onConvertUpdateWindow(QString strDevName, unsigned uDevType); - void onMaininterfacehide(); - void on_clickPanelToHideInterface(); - void onRequestSendDesktopNotify(QString message, QString strIcon); - void onInsertAbnormalDiskNotify(QString message); - void onNotifyWnd(QObject* obj, QEvent *event); - void onClickedEject(EjectDeviceInfo eDeviceInfo); - void onRemountVolume(FDVolumeInfo volumeInfo); - void onCheckDriveValid(FDDriveInfo driveInfo); - - bool onDeviceErrored(GDrive* drive); - void onMountVolume(GVolume*); - void onEjectVolumeForce(GVolume* v); // A fix pops up if the mount fails - - void onNotifyDeviceRemoved(QString strDevId); - -Q_SIGNALS: - void clicked(); - void convertShowWindow(QString strDriveId, QString strMountUri); - void convertUpdateWindow(QString, unsigned); - void unloadMount(); - void telephoneMount(); - - bool deviceError(GDrive*); - void mountVolume(GVolume*); - void ejectVolumeForce(GVolume*); - void remountVolume(FDVolumeInfo volumeInfo); - void checkDriveValid(FDDriveInfo driveInfo); - void notifyDeviceRemoved(QString strDevId); -}; - -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/mainwindow.ui ukui-panel-4.0.0.0/ukui-flash-disk/mainwindow.ui --- ukui-panel-3.14.0.1/ukui-flash-disk/mainwindow.ui 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/mainwindow.ui 1970-01-01 08:00:00.000000000 +0800 @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>MainWindow</class> - <widget class="QMainWindow" name="MainWindow"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>370</width> - <height>232</height> - </rect> - </property> - <property name="windowTitle"> - <string>MainWindow</string> - </property> - <widget class="QWidget" name="centralWidget"/> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections/> -</ui> Binary files /tmp/tmpqe42z0oi/yS2hiN4c6_/ukui-panel-3.14.0.1/ukui-flash-disk/picture/drive-removable-media-usb.png and /tmp/tmpqe42z0oi/HtvDh0xXIg/ukui-panel-4.0.0.0/ukui-flash-disk/picture/drive-removable-media-usb.png differ diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/picture/drive-removable-media.svg ukui-panel-4.0.0.0/ukui-flash-disk/picture/drive-removable-media.svg --- ukui-panel-3.14.0.1/ukui-flash-disk/picture/drive-removable-media.svg 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/picture/drive-removable-media.svg 1970-01-01 08:00:00.000000000 +0800 @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> -<svg version="1.1" id="图层_2_1_" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" - y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"> -<style type="text/css"> - .st0{fill:#FFFFFF;} -</style> -<g id="U盘"> - <g id="_16"> - <g> - <path class="st0" d="M10,1v2H5V1H10 M11,0H4v4h7V0L11,0z"/> - </g> - <g> - <path class="st0" d="M12,14c0,0.6-0.4,1-1,1H4c-0.6,0-1-0.4-1-1V5c0-0.6,0.4-1,1-1h7c0.6,0,1,0.4,1,1V14z M4,3C2.9,3,2,3.9,2,5v9 - c0,1.1,0.9,2,2,2h7c1.1,0,2-0.9,2-2V5c0-1.1-0.9-2-2-2H4z"/> - </g> - <path class="st0" d="M4,5.5v8C4,13.8,4.2,14,4.5,14h6c0.3,0,0.5-0.2,0.5-0.5v-8C11,5.2,10.8,5,10.5,5h-6C4.2,5,4,5.2,4,5.5z - M10.1,8.4H9.8V9c0,0.2-0.1,0.5-0.3,0.7C9.2,9.9,9,10.1,8.7,10.2c-0.2,0.1-0.8,0.3-0.8,0.3c-0.1,0.1-0.1,0.1-0.1,0.2v0.8v0.6 - c0.3,0.1,0.5,0.4,0.5,0.7l0,0c0,0.4-0.4,0.7-0.8,0.7l0,0c-0.4,0-0.8-0.3-0.8-0.7c0-0.3,0.3-0.6,0.6-0.7v-0.7c0-0.1,0-0.2-0.1-0.2 - l-1.7-0.8c-0.2-0.1-0.3-0.3-0.3-0.6V9.2C5,9.1,4.8,8.9,4.8,8.7l0,0c0-0.3,0.3-0.6,0.7-0.6l0,0c0.3,0,0.6,0.3,0.6,0.6 - c0,0.2-0.2,0.5-0.4,0.5v0.5c0,0.1,0,0.2,0.1,0.2c0.1,0.1,1.4,0.5,1.4,0.5V6.7H6.7l0.9-1.3l0.9,1.3H7.8v3.2c0,0,0.7-0.3,0.9-0.3 - c0.2-0.1,0.5-0.3,0.5-0.7V8.4H8.9V7.2h1.2C10.1,7.2,10.1,8.4,10.1,8.4z"/> - <rect id="rect3767" x="6" y="2" class="st0" width="1" height="1"/> - <rect id="rect3769" x="8" y="2" class="st0" width="1" height="1"/> - </g> -</g> -</svg> diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/picture/media-eject-symbolic.svg ukui-panel-4.0.0.0/ukui-flash-disk/picture/media-eject-symbolic.svg --- ukui-panel-3.14.0.1/ukui-flash-disk/picture/media-eject-symbolic.svg 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/picture/media-eject-symbolic.svg 1970-01-01 08:00:00.000000000 +0800 @@ -1 +0,0 @@ -<svg id="播放" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><defs><style>.cls-1{fill:#fff;}</style></defs><title>画板 1</title><g id="_16" data-name=" 16"><rect class="cls-1" y="13" width="16" height="1"/><path class="cls-1" d="M8,2.7,14,11H2L8,2.7M8,1,0,12H16L8,1Z"/></g></svg> \ No newline at end of file diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/qclickwidget.cpp ukui-panel-4.0.0.0/ukui-flash-disk/qclickwidget.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/qclickwidget.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/qclickwidget.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,979 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include "qclickwidget.h" -#include <KWindowEffects> -#include <QtConcurrent/QtConcurrent> - -void frobnitz_force_result_func(GDrive *source_object,GAsyncResult *res,QClickWidget *p_this) -{ - auto env = qgetenv("QT_QPA_PLATFORMTHEME"); - qDebug()<<"env"<<env; - gboolean success = FALSE; - GError *err = nullptr; - success = g_drive_eject_with_operation_finish (source_object, res, &err); - if (!err) - { - findGDriveList()->removeOne(source_object); - p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,""); - p_this->m_eject->show(); - } - else - { - int volumeNum = g_list_length(g_drive_get_volumes(source_object)); - for(int eachVolume = 0 ; eachVolume < volumeNum ;eachVolume++) - { - p_this->flagType = 0; - - if(g_mount_can_unmount(g_volume_get_mount((GVolume *)g_list_nth_data(g_drive_get_volumes(source_object),eachVolume)))) - { - QtConcurrent::run([=](){ - char *dataPath = g_file_get_path(g_mount_get_root(g_volume_get_mount((GVolume *)g_list_nth_data(g_drive_get_volumes(source_object),eachVolume)))); - qDebug()<<"dataPath"<<dataPath; - QProcess p; - p.setProgram("pkexec"); - p.setArguments(QStringList()<<"eject"<<QString(dataPath)); - p.start(); - p_this->ifSucess = p.waitForFinished(); - }); - } - } - } -} - -void frobnitz_result_func(GDrive *source_object,GAsyncResult *res,QClickWidget *p_this) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_drive_eject_with_operation_finish (source_object, res, &err); - - if (!err) - { - findGDriveList()->removeOne(source_object); - p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,""); - p_this->m_eject->show(); - } - - else /*if(g_drive_can_stop(source_object) == true)*/ - { - if (p_this->chooseDialog == nullptr) - { - p_this->chooseDialog = new interactiveDialog("", p_this); - } -// p_this->chooseDialog->raise(); - p_this->chooseDialog->show(); - p_this->chooseDialog->setFocus(); - p_this->connect(p_this->chooseDialog,&interactiveDialog::FORCESIG,p_this,[=]() - { - g_drive_eject_with_operation(source_object, - G_MOUNT_UNMOUNT_FORCE, - NULL, - NULL, - GAsyncReadyCallback(frobnitz_force_result_func), - p_this - ); - p_this->chooseDialog->close(); - }); - } -} - -void frobnitz_force_result_tele(GVolume *source_object,GAsyncResult *res,QClickWidget *p_this) -{ - gboolean success = FALSE; - GError *err = nullptr; - success = g_mount_unmount_with_operation_finish(g_volume_get_mount(source_object),res, &err); - if(!err) - { - qDebug()<<"unload successful"; - findTeleGVolumeList()->removeOne(source_object); - findGVolumeList()->removeOne(source_object); - if(findTeleGVolumeList()->size() == 1) - { - if(findGVolumeList()->size() == 1) - { - Q_EMIT p_this->noDeviceSig(); - } - } - } -} - -QClickWidget::QClickWidget(QWidget *parent, - int num, - GDrive *Drive, - GVolume *Volume, - QString driveName, - QString nameDis1, - QString nameDis2, - QString nameDis3, - QString nameDis4, - qlonglong capacityDis1, - qlonglong capacityDis2, - qlonglong capacityDis3, - qlonglong capacityDis4, - QString pathDis1, - QString pathDis2, - QString pathDis3, - QString pathDis4) - : QWidget(parent), - m_Num(num), - m_Drive(Drive), - m_driveName(driveName), - m_nameDis1(nameDis1), - m_nameDis2(nameDis2), - m_nameDis3(nameDis3), - m_nameDis4(nameDis4), - m_capacityDis1(capacityDis1), - m_capacityDis2(capacityDis2), - m_capacityDis3(capacityDis3), - m_capacityDis4(capacityDis4), - m_pathDis1(pathDis1), - m_pathDis2(pathDis2), - m_pathDis3(pathDis3), - m_pathDis4(pathDis4) - -{ -//union layout -/* - * it's the to set the title interface,we get the drive name and add picture of a u disk -*/ - const QByteArray id(THEME_QT_SCHEMA); - - if(QGSettings::isSchemaInstalled(id)) - { - fontSettings = new QGSettings(id); - } - - const QByteArray idd(THEME_QT_SCHEMA); - - if(QGSettings::isSchemaInstalled(idd)) - { - qtSettings = new QGSettings(idd); - } - - initFontSize(); - initThemeMode(); - - QHBoxLayout *drivename_H_BoxLayout = new QHBoxLayout(); - drivename_H_BoxLayout = new QHBoxLayout(); - image_show_label = new QLabel(this); - image_show_label->setFocusPolicy(Qt::NoFocus); - image_show_label->installEventFilter(this); - //to get theme picture for label - imgIcon = QIcon::fromTheme("drive-removable-media-usb"); - QPixmap pixmap = imgIcon.pixmap(QSize(25, 25)); - image_show_label->setPixmap(pixmap); - image_show_label->setFixedSize(40,40); - m_driveName_label = new QLabel(this); - m_driveName_label->setFont(QFont("Noto Sans CJK SC",fontSize)); - QString DriveName = getElidedText(m_driveName_label->font(), m_driveName, 180); - m_driveName_label->setText(DriveName); - m_driveName_label->setFixedSize(180,40); - m_driveName_label->setObjectName("driveNameLabel"); - - m_eject_button = new QPushButton(this); - m_eject_button->setFlat(true); //this property set that when the mouse is hovering in the icon the icon will move up a litte - m_eject_button->move(m_eject_button->x()+234,m_eject_button->y()+2); - //->setObjectName("Button"); - m_eject_button->installEventFilter(this); - m_eject_button->setIcon(drawSymbolicColoredPixmap(QPixmap::fromImage(QIcon::fromTheme("media-eject-symbolic").pixmap(24,24).toImage()))); - m_eject_button->setFixedSize(40,40); - m_eject_button->setToolTip(tr("弹出")); - - drivename_H_BoxLayout->addSpacing(8); - drivename_H_BoxLayout->addWidget(image_show_label); - drivename_H_BoxLayout->addWidget(m_driveName_label); - drivename_H_BoxLayout->addStretch(); - - QVBoxLayout *main_V_BoxLayout = new QVBoxLayout(this); - main_V_BoxLayout->setContentsMargins(0,0,0,0); - - connect(m_eject_button,SIGNAL(clicked()),SLOT(switchWidgetClicked())); // this signal-slot function is to emit a signal which - //is to trigger a slot in mainwindow - connect(m_eject_button, &QPushButton::clicked,this,[=]() - { - if(Drive != NULL) - { - g_drive_eject_with_operation(Drive, - G_MOUNT_UNMOUNT_NONE, - NULL, - NULL, - GAsyncReadyCallback(frobnitz_result_func), - this); - } - else - { - g_mount_unmount_with_operation(g_volume_get_mount(Volume), - G_MOUNT_UNMOUNT_NONE, - NULL, - NULL, - GAsyncReadyCallback(frobnitz_force_result_tele), - this); - } - }); - -//when the drive only has one vlolume -//we set the information and set all details of the U disk in main interface - if(m_Num == 1) - { - disWidgetNumOne = new QWidget(this); - QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis1_label = new ClickLabel(disWidgetNumOne); - m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeName = getElidedText(m_nameDis1_label->font(), m_nameDis1, 120); - m_nameDis1_label->adjustSize(); - m_nameDis1_label->setText("- "+VolumeName+":"); - m_capacityDis1_label = new QLabel(disWidgetNumOne); - - QString str_capacityDis1 = size_human(m_capacityDis1); -// QString str_capacityDis1Show = getElidedText(m_capacityDis1_label->font(),str_capacityDis1,200); - m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis1_label->setText("("+str_capacityDis1+")"); - m_capacityDis1_label->setObjectName("capacityLabel"); - onevolume_h_BoxLayout->setSpacing(0); - onevolume_h_BoxLayout->addSpacing(50); - onevolume_h_BoxLayout->setMargin(0); //使得widget上的label得以居中显示 - onevolume_h_BoxLayout->addWidget(m_nameDis1_label); - onevolume_h_BoxLayout->addWidget(m_capacityDis1_label); - onevolume_h_BoxLayout->addSpacing(10); - onevolume_h_BoxLayout->addStretch(); - - disWidgetNumOne->setObjectName("OriginObjectOnly"); - disWidgetNumOne->setLayout(onevolume_h_BoxLayout); - disWidgetNumOne->installEventFilter(this); - disWidgetNumOne->setFixedHeight(30); - main_V_BoxLayout->addLayout(drivename_H_BoxLayout); - if (m_pathDis1.isEmpty()) { - m_capacityDis1_label->setText(tr("Unmounted")); - } - main_V_BoxLayout->addWidget(disWidgetNumOne); - this->setLayout(main_V_BoxLayout); - this->setFixedSize(276,68); - } -//when the drive has two volumes - if(m_Num == 2) - { - QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis1_label = new ClickLabel(); - m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis1 = getElidedText(m_nameDis1_label->font(), m_nameDis1, 120); - m_nameDis1_label->adjustSize(); - m_nameDis1_label->setText("- "+VolumeNameDis1+":"); - m_nameDis1_label->installEventFilter(this); - m_capacityDis1_label = new QLabel(this); - QString str_capacityDis1 = size_human(m_capacityDis1); - m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis1_label->setText("("+str_capacityDis1+")"); - m_capacityDis1_label->setObjectName("capacityLabel"); - onevolume_h_BoxLayout->addSpacing(50); - onevolume_h_BoxLayout->setSpacing(0); - onevolume_h_BoxLayout->addWidget(m_nameDis1_label); - onevolume_h_BoxLayout->setMargin(0); - onevolume_h_BoxLayout->addWidget(m_capacityDis1_label); - onevolume_h_BoxLayout->addStretch(); - disWidgetNumOne = new QWidget; - disWidgetNumOne->setFixedHeight(30); - disWidgetNumOne->setObjectName("OriginObjectOnly"); - disWidgetNumOne->setLayout(onevolume_h_BoxLayout); - disWidgetNumOne->installEventFilter(this); - - QHBoxLayout *twovolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis2_label = new ClickLabel(this); - m_nameDis2_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis2 = getElidedText(m_nameDis2_label->font(), m_nameDis2, 120); - m_nameDis2_label->setText("- "+VolumeNameDis2+":"); - m_nameDis2_label->adjustSize(); - m_nameDis2_label->installEventFilter(this); - m_capacityDis2_label = new QLabel(this); - QString str_capacityDis2 = size_human(m_capacityDis2); - m_capacityDis2_label->setText("("+str_capacityDis2+")"); - m_capacityDis2_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis2_label->setObjectName("capacityLabel"); - twovolume_h_BoxLayout->addSpacing(50); - twovolume_h_BoxLayout->setSpacing(0); - twovolume_h_BoxLayout->addWidget(m_nameDis2_label); - twovolume_h_BoxLayout->setMargin(0); - twovolume_h_BoxLayout->addWidget(m_capacityDis2_label); - twovolume_h_BoxLayout->addStretch(); - disWidgetNumTwo = new QWidget; - disWidgetNumTwo->setFixedHeight(30); - disWidgetNumTwo->setObjectName("OriginObjectOnly"); - disWidgetNumTwo->setLayout(twovolume_h_BoxLayout); - disWidgetNumTwo->installEventFilter(this); - - main_V_BoxLayout->setContentsMargins(0,0,0,0); - main_V_BoxLayout->addLayout(drivename_H_BoxLayout); - if(m_pathDis1 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumOne); - } - - if(m_pathDis2 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumTwo); - } - - main_V_BoxLayout->addStretch(); - this->setLayout(main_V_BoxLayout); - this->setFixedSize(276,97); - } -//when the drive has three volumes - if(m_Num == 3) - { - QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis1_label = new ClickLabel(this); - m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis1 = getElidedText(m_nameDis1_label->font(), m_nameDis2, 120); - m_nameDis1_label->setText("- "+VolumeNameDis1+":"); - m_nameDis1_label->adjustSize(); - m_nameDis1_label->installEventFilter(this); - //m_nameDis1_label->setText("- "+m_nameDis1+":"); - m_capacityDis1_label = new QLabel(this); - QString str_capacityDis1 = size_human(m_capacityDis1); - m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis1_label->setText("("+str_capacityDis1+")"); - m_capacityDis1_label->setObjectName("capacityLabel"); - onevolume_h_BoxLayout->addSpacing(50); - onevolume_h_BoxLayout->setSpacing(0); - onevolume_h_BoxLayout->addWidget(m_nameDis1_label); - onevolume_h_BoxLayout->addWidget(m_capacityDis1_label); - onevolume_h_BoxLayout->addStretch(); - onevolume_h_BoxLayout->setMargin(0); - - disWidgetNumOne = new QWidget; - disWidgetNumOne->setFixedHeight(30); - disWidgetNumOne->setLayout(onevolume_h_BoxLayout); - disWidgetNumOne->setObjectName("OriginObjectOnly"); - disWidgetNumOne->installEventFilter(this); - - QHBoxLayout *twovolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis2_label = new ClickLabel(this); - m_nameDis2_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis2 = getElidedText(m_nameDis2_label->font(), m_nameDis2, 120); - m_nameDis2_label->setText("- "+VolumeNameDis2+":"); - m_nameDis2_label->adjustSize(); - m_nameDis2_label->installEventFilter(this); - m_capacityDis2_label = new QLabel(this); - QString str_capacityDis2 = size_human(m_capacityDis2); - m_capacityDis2_label->setText("("+str_capacityDis2+")"); - m_capacityDis2_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis2_label->setObjectName("capacityLabel"); - twovolume_h_BoxLayout->addSpacing(50); - twovolume_h_BoxLayout->setSpacing(0); - twovolume_h_BoxLayout->addWidget(m_nameDis2_label); - twovolume_h_BoxLayout->addWidget(m_capacityDis2_label); - twovolume_h_BoxLayout->addStretch(); - twovolume_h_BoxLayout->setMargin(0); - - disWidgetNumTwo = new QWidget; - disWidgetNumTwo->setFixedHeight(30); - disWidgetNumTwo->setObjectName("OriginObjectOnly"); - disWidgetNumTwo->setLayout(twovolume_h_BoxLayout); - disWidgetNumTwo->installEventFilter(this); - - QHBoxLayout *threevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis3_label = new ClickLabel(this); - m_nameDis3_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis3 = getElidedText(m_nameDis3_label->font(), m_nameDis3, 120); - m_nameDis3_label->setText("- "+VolumeNameDis3+":"); - m_nameDis3_label->adjustSize(); - m_nameDis3_label->installEventFilter(this); - m_capacityDis3_label = new QLabel(this); - QString str_capacityDis3 = size_human(m_capacityDis3); - m_capacityDis3_label->setText("("+str_capacityDis3+")"); - m_capacityDis3_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis3_label->setObjectName("capacityLabel"); - threevolume_h_BoxLayout->addSpacing(50); - threevolume_h_BoxLayout->setSpacing(0); - threevolume_h_BoxLayout->addWidget(m_nameDis3_label); - threevolume_h_BoxLayout->addWidget(m_capacityDis3_label); - threevolume_h_BoxLayout->addStretch(); - threevolume_h_BoxLayout->setMargin(0); - - disWidgetNumThree = new QWidget; - disWidgetNumThree->setFixedHeight(30); - disWidgetNumThree->setObjectName("OriginObjectOnly"); - disWidgetNumThree->setLayout(threevolume_h_BoxLayout); - disWidgetNumThree->installEventFilter(this); - - - main_V_BoxLayout->setContentsMargins(0,0,0,0); - main_V_BoxLayout->addLayout(drivename_H_BoxLayout); - if(m_pathDis1 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumOne); - } - - if(m_pathDis2 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumTwo); - } - - if(m_pathDis3 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumThree); - } - - this->setLayout(main_V_BoxLayout); - this->setFixedSize(276,136); - } -//when the drive has four volumes - if(m_Num == 4) - { - QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis1_label = new ClickLabel(this); - m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis1 = getElidedText(m_nameDis1_label->font(), m_nameDis1, 120); - m_nameDis1_label->setText("- "+VolumeNameDis1+":"); - m_nameDis1_label->adjustSize(); - m_nameDis1_label->installEventFilter(this); - //m_nameDis1_label->setText("- "+m_nameDis1+":"); - m_capacityDis1_label = new QLabel(this); - QString str_capacityDis1 = size_human(m_capacityDis1); - m_capacityDis1_label->setText("("+str_capacityDis1+")"); - m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis1_label->setObjectName("capacityLabel"); - onevolume_h_BoxLayout->addSpacing(50); - onevolume_h_BoxLayout->setSpacing(0); - onevolume_h_BoxLayout->addWidget(m_nameDis1_label); - onevolume_h_BoxLayout->addWidget(m_capacityDis1_label); - onevolume_h_BoxLayout->addStretch(); - onevolume_h_BoxLayout->setMargin(0); - - disWidgetNumOne = new QWidget; - disWidgetNumOne->setFixedHeight(30); - disWidgetNumOne->setObjectName("OriginObjectOnly"); - disWidgetNumOne->setLayout(onevolume_h_BoxLayout); - disWidgetNumOne->installEventFilter(this); - - QHBoxLayout *twovolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis2_label = new ClickLabel(this); - m_nameDis2_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis2 = getElidedText(m_nameDis2_label->font(), m_nameDis2, 120); - m_nameDis2_label->setText("- "+VolumeNameDis2+":"); - m_nameDis2_label->installEventFilter(this); - m_nameDis2_label->adjustSize(); - m_nameDis2_label->installEventFilter(this); - //m_nameDis2_label->setText("- "+m_nameDis2+":"); - m_capacityDis2_label = new QLabel(this); - QString str_capacityDis2 = size_human(m_capacityDis2); - m_capacityDis2_label->setText("("+str_capacityDis2+")"); - m_capacityDis2_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis2_label->setObjectName("capacityLabel"); - twovolume_h_BoxLayout->addSpacing(50); - twovolume_h_BoxLayout->setSpacing(0); - twovolume_h_BoxLayout->addWidget(m_nameDis2_label); - twovolume_h_BoxLayout->addWidget(m_capacityDis2_label); - twovolume_h_BoxLayout->addStretch(); - twovolume_h_BoxLayout->setMargin(0); - - disWidgetNumTwo = new QWidget; - disWidgetNumTwo->setFixedHeight(30); - disWidgetNumTwo->setObjectName("OriginObjectOnly"); - disWidgetNumTwo->setLayout(twovolume_h_BoxLayout); - disWidgetNumTwo->installEventFilter(this); - - QHBoxLayout *threevolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis3_label = new ClickLabel(this); - m_nameDis3_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis3 = getElidedText(m_nameDis3_label->font(), m_nameDis3, 120); - m_nameDis3_label->setText("- "+VolumeNameDis3+":"); - m_nameDis3_label->installEventFilter(this); - m_capacityDis3_label = new QLabel(this); - QString str_capacityDis3 = size_human(m_capacityDis3); - m_capacityDis3_label->setText("("+str_capacityDis3+")"); - m_capacityDis3_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis3_label->setObjectName("capacityLabel"); - threevolume_h_BoxLayout->addSpacing(50); - threevolume_h_BoxLayout->setSpacing(0); - threevolume_h_BoxLayout->addWidget(m_nameDis3_label); - threevolume_h_BoxLayout->addWidget(m_capacityDis3_label); - threevolume_h_BoxLayout->addStretch(0); - threevolume_h_BoxLayout->setMargin(0); - - disWidgetNumThree = new QWidget; - disWidgetNumThree->setFixedHeight(30); - disWidgetNumThree->setObjectName("OriginObjectOnly"); - disWidgetNumThree->setLayout(threevolume_h_BoxLayout); - disWidgetNumThree->installEventFilter(this); - - QHBoxLayout *fourvolume_h_BoxLayout = new QHBoxLayout(); - m_nameDis4_label = new ClickLabel(this); - m_nameDis4_label->setFont(QFont("Microsoft YaHei",fontSize)); - QString VolumeNameDis4 = getElidedText(m_nameDis4_label->font(), m_nameDis4, 120); - m_nameDis4_label->setText("- "+VolumeNameDis4+":"); - m_nameDis4_label->adjustSize(); - m_nameDis4_label->installEventFilter(this); - //m_nameDis4_label->setText("- "+m_nameDis4+":"); - m_capacityDis4_label = new QLabel(this); - QString str_capacityDis4 = size_human(m_capacityDis4); - m_capacityDis4_label->setText("("+str_capacityDis4+")"); - m_capacityDis4_label->setFont(QFont("Microsoft YaHei",fontSize)); - m_capacityDis4_label->setObjectName("capacityLabel"); - fourvolume_h_BoxLayout->addSpacing(50); - fourvolume_h_BoxLayout->setSpacing(0); - fourvolume_h_BoxLayout->addWidget(m_nameDis4_label); - fourvolume_h_BoxLayout->addWidget(m_capacityDis4_label); - fourvolume_h_BoxLayout->addStretch(); - fourvolume_h_BoxLayout->setMargin(0); - - disWidgetNumFour = new QWidget; - disWidgetNumFour->setFixedHeight(30); - disWidgetNumFour->setObjectName("OriginObjectOnly"); - disWidgetNumFour->setLayout(fourvolume_h_BoxLayout); - disWidgetNumFour->installEventFilter(this); - - main_V_BoxLayout->setContentsMargins(0,0,0,0); - main_V_BoxLayout->addLayout(drivename_H_BoxLayout); - if(m_pathDis1 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumOne); - } - - if(m_pathDis2 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumTwo); - } - - if(m_pathDis3 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumThree); - } - - if(m_pathDis4 != "") - { - main_V_BoxLayout->addWidget(disWidgetNumFour); - } - - this->setLayout(main_V_BoxLayout); - this->setFixedSize(276,165); - } - qDebug()<<"4444"; - this->setAttribute(Qt::WA_TranslucentBackground, true); - qDebug()<<"qlcked overeend"; -} - -void QClickWidget::initFontSize() -{ - if (!fontSettings) - { - fontSize = 11; - return; - } - - QStringList keys = fontSettings->keys(); - if (keys.contains("systemFont") || keys.contains("systemFontSize")) - { - fontSize = fontSettings->get("system-font").toInt(); - } -} - -void QClickWidget::initThemeMode() -{ - if(!qtSettings) - { - currentThemeMode = "ukui-white"; - } - QStringList keys = qtSettings->keys(); - if(keys.contains("styleName")) - { - currentThemeMode = qtSettings->get("style-name").toString(); - } -} - -QClickWidget::~QClickWidget() -{ - if(chooseDialog) - delete chooseDialog; - if(gpartedface) - delete gpartedface; -} - -void QClickWidget::mouseClicked() -{ - QProcess::startDetached("peony "+m_pathDis1); - this->topLevelWidget()->hide(); -} - - -void QClickWidget::mousePressEvent(QMouseEvent *ev) -{ - mousePos = QPoint(ev->x(), ev->y()); -} - -void QClickWidget::mouseReleaseEvent(QMouseEvent *ev) -{ - if(mousePos == QPoint(ev->x(), ev->y())) Q_EMIT clicked(); -} - -//click the first area to show the interface -void QClickWidget::on_volume1_clicked() -{ - if (!m_pathDis1.isEmpty()) { - QString aaa = "peony "+m_pathDis1; - QProcess::startDetached(aaa.toUtf8().data()); - this->topLevelWidget()->hide(); - } -} - -//click the second area to show the interface -void QClickWidget::on_volume2_clicked() -{ - if (!m_pathDis2.isEmpty()) { - QString aaa = "peony "+m_pathDis2; - QProcess::startDetached(aaa.toUtf8().data()); - this->topLevelWidget()->hide(); - } -} - -//click the third area to show the interface -void QClickWidget::on_volume3_clicked() -{ - if (!m_pathDis3.isEmpty()) { - QProcess::startDetached("peony "+m_pathDis3); - this->topLevelWidget()->hide(); - } -} - -//click the forth area to show the interface -void QClickWidget::on_volume4_clicked() -{ - if (!m_pathDis4.isEmpty()) { - QProcess::startDetached("peony "+m_pathDis4); - this->topLevelWidget()->hide(); - } -} - -void QClickWidget::switchWidgetClicked() -{ - Q_EMIT clickedConvert(); -} - -QPixmap QClickWidget::drawSymbolicColoredPixmap(const QPixmap &source) -{ - if(currentThemeMode == "ukui-light" || currentThemeMode == "ukui-white") - { - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) - { - for (int y = 0; y < img.height(); y++) - { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) - { - color.setRed(0); - color.setGreen(0); - color.setBlue(0); - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); - } - - else if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" ) - { - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) - { - for (int y = 0; y < img.height(); y++) - { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) - { - color.setRed(255); - color.setGreen(255); - color.setBlue(255); - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); - } - - else - { - QImage img = source.toImage(); - for (int x = 0; x < img.width(); x++) - { - for (int y = 0; y < img.height(); y++) - { - auto color = img.pixelColor(x, y); - if (color.alpha() > 0) - { - color.setRed(0); - color.setGreen(0); - color.setBlue(0); - img.setPixelColor(x, y, color); - } - } - } - return QPixmap::fromImage(img); - } -} - -//to convert the capacity by another type -QString QClickWidget::size_human(qlonglong capacity) -{ - // float capacity = this->size(); - if(capacity != 0 && capacity != 1) - { - int conversionNum = 0; - QStringList list; - list << "KB" << "MB" << "GB" << "TB"; - - QStringListIterator i(list); - QString unit("bytes"); - - qlonglong conversion = capacity; - - while(conversion >= 1000.0 && i.hasNext()) - { - unit = i.next(); - conversion /= 1000.0; - conversionNum++; - } - - qlonglong remain = capacity - conversion * qPow(1000,conversionNum); - float showRemain; - if(conversionNum == 3) - { - showRemain = (float)remain /1000/1000/1000; - } - if(conversionNum == 2) - { - showRemain = (float)remain /1000/1000; - } - if(conversionNum == 1) - { - showRemain = (float)remain /1000; - } - - double showValue = conversion + showRemain; - - QString str2=QString::number(showValue,'f',1); - - QString str_capacity=QString(" %1%2").arg(str2).arg(unit); - return str_capacity; - // return QString().setNum(capacity,'f',2)+" "+unit; - } -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - if(capacity == NULL) - { - QString str_capaticity = tr("the capacity is empty"); - return str_capaticity; - } -#endif - if(capacity == 1) - { - QString str_capacity = tr("blank CD"); - return str_capacity; - } - QString str_capacity = tr("other user device"); - return str_capacity; -} - -//set the style of the eject button and label when the mouse doing some different operations -bool QClickWidget::eventFilter(QObject *obj, QEvent *event) -{ - if(obj == m_eject_button) - { - if(event->type() == QEvent::MouseButtonPress) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - m_eject_button->setIconSize(QSize(14,14)); - m_eject_button->setFixedSize(38,38); - m_eject_button->setStyleSheet( - "background:rgba(255,255,255,0.08);" - "border-radius:4px;" - ); - } - else - { - m_eject_button->setIconSize(QSize(14,14)); - m_eject_button->setFixedSize(38,38); - m_eject_button->setStyleSheet( - "background:rgba(0,0,0,0.08);" - "border-radius:4px;" - ); - } - - } - - if(event->type() == QEvent::Enter) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - m_eject_button->setStyleSheet( - "background-color:rgba(255,255,255,0.91);" - "background:rgba(255,255,255,0.12);" - "border-radius:4px;"); - } - else - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - m_eject_button->setStyleSheet( - "background-color:rgba(0,0,0,0.91);" - "background:rgba(0,0,0,0.12);" - "border-radius:4px;"); - } - - } - - if(event->type() == QEvent::Leave) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black") - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - m_eject_button->setStyleSheet( - "background-color:rgba(255,255,255,0.75);" - "background-color:rgba(255,255,255,0.57);" - "background:rgba(255,255,255,0);" - "border-radius:4px;"); - } - else - { - m_eject_button->setIconSize(QSize(16,16)); - m_eject_button->setFixedSize(40,40); - m_eject_button->setStyleSheet( - "background-color:rgba(0,0,0,0.75);" - "background-color:rgba(0,0,0,0.57);" - "background:rgba(0,0,0,0);" - "border-radius:4px;"); - } - } - } - - if(obj == disWidgetNumOne) - { - if(event->type() == QEvent::Enter) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - disWidgetNumOne->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}"); - } - else - { - disWidgetNumOne->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}"); - } - } - - if(event->type() == QEvent::Leave) - { - disWidgetNumOne->setStyleSheet(""); - - } - - if(event->type() == QEvent::MouseButtonPress) - { - on_volume1_clicked(); - } - } - - if(obj == disWidgetNumTwo) - { - if(event->type() == QEvent::Enter ) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - disWidgetNumTwo->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}"); - } - else - { - disWidgetNumTwo->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}"); - } - } - - if(event->type() == QEvent::Leave) - { - disWidgetNumTwo->setStyleSheet(""); - } - - if(event->type() == QEvent::MouseButtonPress) - { - on_volume2_clicked(); - } - } - - if(obj == disWidgetNumThree) - { - if(event->type() == QEvent::Enter ) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - disWidgetNumThree->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}"); - } - else - { - disWidgetNumThree->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}"); - } - } - - if(event->type() == QEvent::Leave) - { - disWidgetNumThree->setStyleSheet(""); - } - - if(event->type() == QEvent::MouseButtonPress) - { - on_volume3_clicked(); - } - } - - if(obj == disWidgetNumFour) - { - if(event->type() == QEvent::Enter ) - { - if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default") - { - disWidgetNumFour->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}"); - } - else - { - disWidgetNumFour->setStyleSheet( - "QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}"); - } - } - - if(event->type() == QEvent::Leave) - { - disWidgetNumFour->setStyleSheet(""); - } - - if(event->type() == QEvent::MouseButtonPress) - { - on_volume4_clicked(); - } - } - - return false; -} - -void QClickWidget::resizeEvent(QResizeEvent *event) -{ -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/qclickwidget.h ukui-panel-4.0.0.0/ukui-flash-disk/qclickwidget.h --- ukui-panel-3.14.0.1/ukui-flash-disk/qclickwidget.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/qclickwidget.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,141 +0,0 @@ -/* - * Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program or library is free software; you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -#ifndef QCLICKWIDGET_H -#define QCLICKWIDGET_H -#include <QWidget> -#include <QProcess> -#include <QDebug> -#include <QMouseEvent> -#include <QPaintEvent> -#include <QStyle> -#include <QStyleOption> -#include <QPainter> -#include <QLabel> -#include <QBoxLayout> -#include <QPushButton> -#include <qgsettings.h> - -#include "ejectInterface.h" -#include "clickLabel.h" -#include "UnionVariable.h" -#include "interactivedialog.h" -#include "gpartedinterface.h" -class MainWindow; -class QClickWidget : public QWidget -{ - Q_OBJECT -public: - explicit QClickWidget(QWidget *parent = nullptr, - int num = 0, - GDrive *Drive=NULL, - GVolume *Volume=NULL, - QString driveName=NULL, - QString nameDis1=NULL, - QString nameDis2 =NULL, - QString nameDis3 = NULL, - QString nameDis4 = NULL, - qlonglong capacityDis1=0, - qlonglong capacityDis2=0, - qlonglong capacityDis3=0, - qlonglong capacityDis4=0, - QString pathDis1=NULL, - QString pathDis2=NULL, - QString pathDis3=NULL, - QString pathDis4=NULL); - ~QClickWidget(); -public Q_SLOTS: - void mouseClicked(); - -protected: - void mousePressEvent(QMouseEvent *ev); - void mouseReleaseEvent(QMouseEvent *ev); - //void paintEvent(QPaintEvent *); - -private: - QIcon imgIcon; - QString m_driveName; - QString m_nameDis1; - QString m_nameDis2; - QString m_nameDis3; - QString m_nameDis4; - qlonglong m_capacityDis1; - qlonglong m_capacityDis2; - qlonglong m_capacityDis3; - qlonglong m_capacityDis4; - QString m_pathDis1; - QString m_pathDis2; - QString m_pathDis3; - QString m_pathDis4; - MainWindow *m_mainwindow; - QPoint mousePos; - int m_Num; - GDrive *m_Drive; - QLabel *image_show_label; - QLabel *m_driveName_label; - ClickLabel *m_nameDis1_label; - ClickLabel *m_nameDis2_label; - ClickLabel *m_nameDis3_label; - ClickLabel *m_nameDis4_label; - QLabel *m_capacityDis1_label; - QLabel *m_capacityDis2_label; - QLabel *m_capacityDis3_label; - QLabel *m_capacityDis4_label; - QWidget *disWidgetNumOne; - QWidget *disWidgetNumTwo; - QWidget *disWidgetNumThree; - QWidget *disWidgetNumFour; - - QGSettings *fontSettings = nullptr; - QGSettings *qtSettings = nullptr; - - int fontSize; - QString currentThemeMode; - -public: - QPushButton *m_eject_button = nullptr; - ejectInterface *m_eject = nullptr; - interactiveDialog *chooseDialog = nullptr; - gpartedInterface *gpartedface = nullptr; - bool ifSucess; - int flagType; -Q_SIGNALS: - void clicked(); - void clickedConvert(); - void noDeviceSig(); - -private Q_SLOTS: - void on_volume1_clicked(); - void on_volume2_clicked(); - void on_volume3_clicked(); - void on_volume4_clicked(); - void switchWidgetClicked(); -private: - QString size_human(qlonglong capacity); - QPixmap drawSymbolicColoredPixmap(const QPixmap &source); -protected: - bool eventFilter(QObject *obj, QEvent *event); - void resizeEvent(QResizeEvent *event); -public: - void initFontSize(); - void initThemeMode(); - -}; - -#endif diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/repair-dialog-box.cpp ukui-panel-4.0.0.0/ukui-flash-disk/repair-dialog-box.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/repair-dialog-box.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/repair-dialog-box.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,1627 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Ding Jing dingjing@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "repair-dialog-box.h" - -#include <QDebug> -#include <QDBusConnection> -#include <QDBusInterface> -#include <QHBoxLayout> -#include <QVBoxLayout> -#include <QLabel> -#include <QPushButton> -#include <QButtonGroup> -#include <QButtonGroup> -#include <QMessageBox> -#include <QApplication> -#include <QDBusReply> -#include <QStyleFactory> -#include <QProgressBar> -#include <QComboBox> -#include <QCheckBox> -#include <QScrollArea> -#include <QThread> -#include <QStyle> -#include <QGSettings> -#include <QPainter> -#include <QStyleOption> -#include <QPalette> -#include <QPainterPath> -#include <QAction> -#include <QAbstractItemView> - -#include <gio/gio.h> - -#include "device-manager.h" - - -#define UDISK_DBUS_NAME "org.freedesktop.UDisks2" -#define UDISK_BLOCK_DBUS_PATH "/org/freedesktop/UDisks2/block_devices/" - -BaseDialogStyle* BaseDialogStyle::gInstance = NULL; - -RepairDialogBox::RepairDialogBox(GDrive* drive, QWidget* parent) : BaseDialog(parent), mDrive(G_DRIVE(drive)) -{ - initUI(); - - if (mDrive) { - g_object_ref(mDrive); - mDeviceName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - } - - connect(mRepairBtn, &QPushButton::clicked, this, [=] (bool) { - RepairProgressBar dlg(mDrive); - isRunning(true); - int ret = dlg.exec(); - isRunning(false); - if (QDialog::Accepted == ret) { - accept(); - } - }); - - connect(mFormatBtn, &QPushButton::clicked, this, [=] (bool) { - FormateDialog dlg(mDrive); - isRunning(true); - int ret = dlg.exec(); - isRunning(false); - if (QDialog::Accepted == ret) { - accept(); - } - }); -} - -RepairDialogBox::RepairDialogBox(GVolume* volume, QWidget* parent) : BaseDialog(parent), mVolume(G_VOLUME(volume)) -{ - initUI(); - - if (mVolume) { - g_object_ref(mVolume); - mDeviceName = g_volume_get_identifier (mVolume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - } - - connect(mRepairBtn, &QPushButton::clicked, this, [=] (bool) { - RepairProgressBar dlg(mVolume, this); - connect(&dlg, &RepairProgressBar::remountDevice, this, &RepairDialogBox::onRemountDevice); - isRunning(true); - int ret = dlg.exec(); - isRunning(false); - if (QDialog::Accepted == ret) { - accept(); - } - }); - - connect(mFormatBtn, &QPushButton::clicked, this, [=] (bool) { - FormateDialog dlg(mVolume, this); - isRunning(true); - int ret = dlg.exec(); - isRunning(false); - if (QDialog::Accepted == ret) { - accept(); - } - }); -} -bool RepairDialogBox::mshowflag = false; - -void RepairDialogBox::onRemountDevice() -{ - FDVolumeInfo volumeInfo; - volumeInfo.strId = mDeviceName.toStdString(); - qInfo()<<"volumeId:"<<volumeInfo.strId.c_str(); - Q_EMIT remountDevice(volumeInfo); -} - -QString RepairDialogBox::getDeviceName() -{ - return mDeviceName; -} - -RepairDialogBox::~RepairDialogBox() -{ - if (mDrive) g_object_unref(mDrive); - if (mVolume) g_object_unref(mVolume); -} - -void RepairDialogBox::initUI() -{ - setAutoFillBackground(true); - setWindowTitle(tr("Disk test")); - setBackgroundRole(QPalette::Base); - setContentsMargins(24, 24, 24, 24); - - setWindowIcon(QIcon::fromTheme("system-file-manager")); - setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint); - - QGSettings* fontSettings = nullptr; - const QByteArray id1(THEME_QT_SCHEMA); - static int fontSize; - - if(QGSettings::isSchemaInstalled(id1)) - { - fontSettings = new QGSettings(id1); - } - - fontSize = fontSettings->get(FONT_SIZE).toString().toFloat(); - if((fontSize>=14)&&(qgetenv ("GDM_LANG") == "en")) - { - setFixedSize(mFixWidth, mFixHeight+55); - }else{ - setFixedSize(mFixWidth, mFixHeight); - } - QObject::connect(fontSettings,&QGSettings::changed,[=](QString key) - { - if(mshowflag){ - fontSize = fontSettings->get(FONT_SIZE).toString().toFloat(); - if((fontSize>=14)&&(qgetenv ("GDM_LANG") == "en")) - { - setFixedSize(mFixWidth, mFixHeight+55); - } - else{ - setFixedSize(mFixWidth, mFixHeight); - } - } - }); - - QGridLayout* mainLayout = new QGridLayout(this); - mainLayout->setContentsMargins(0,0,0,0); - QHBoxLayout* btnGroup = new QHBoxLayout; - - g_autofree gchar* devName = mDrive ? DeviceOperation::getDriveLabel (mDrive) : DeviceOperation::getDriveLabel (mVolume); - - QLabel* label = new QLabel; - label->setBackgroundRole(QPalette::Base); - label->setWordWrap(true); - label->setTextFormat(Qt::RichText); - if (devName) { - label->setText(tr( - "<h4>The system could not recognize the disk contents</h4>" - "<p>Check that the disk/drive '%1' is properly connected," - "make sure the disk is not a read-only disk, and try again." - "For more information, search for help on read-only files and" - "how to change read-only files.</p>").arg (devName)); - } else { - label->setText(tr( - "<h4>The system could not recognize the disk contents</h4>" - "<p>Check that the disk/drive is properly connected," - "make sure the disk is not a read-only disk, and try again." - "For more information, search for help on read-only files and" - "how to change read-only files.</p>")); - } -// QScrollArea* scrollArea = new QScrollArea; -// scrollArea->setContentsMargins(0, 0, 0, 0); -// scrollArea->setBackgroundRole(QPalette::Base); -// scrollArea->setAutoFillBackground(true); -// scrollArea->setFrameStyle(0); -// scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); -// scrollArea->setWidget(label); - mainLayout->addWidget(label, 0, 0, 6, 60, Qt::AlignTop); - - mFormatBtn = new QPushButton(tr("Format disk")); - mRepairBtn = new QPushButton(tr("Repair")); - - btnGroup->addWidget(mRepairBtn); - btnGroup->addWidget(mFormatBtn); - mainLayout->addLayout(btnGroup, 5, 30, 1, 30); - - connect(this, &QDialog::finished, this, [=] () { - Q_EMIT repairOK(this); - deleteLater(); - }); - - connect(this, &QDialog::accepted, this, [=] () { - Q_EMIT repairOK(this); - deleteLater(); - }); - - const DeviceManager* dm = DeviceManager::getInstance(); - connect(dm, &DeviceManager::driveDisconnected, this, [=] (QString device) { - g_return_if_fail(false); - g_return_if_fail(mDrive || mVolume); - QString devName; - if (mDrive) { - g_autofree gchar* dev = g_drive_get_identifier(mDrive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - devName = dev; - } else if (mVolume) { - GDrive* driv = g_volume_get_drive(mVolume); - if (driv) { - g_autofree gchar* dev = g_drive_get_identifier(driv, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - devName = dev; - g_object_unref(driv); - } - } - - if (devName == device || (!device.isEmpty() && devName.isEmpty())) { - accept(); - } - }); -} - -void RepairDialogBox::isRunning(bool running) -{ - if (running) { - mRepairBtn->setDisabled(true); - mFormatBtn->setDisabled(true); - } else { - mRepairBtn->setEnabled(true); - mFormatBtn->setEnabled(true); - } -} - -void RepairDialogBox::drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, RepairDialogBox* pThis) -{ - g_return_if_fail(drive); - g_return_if_fail(!pThis->isHidden()); - - g_autofree gchar* tDev = nullptr; - - g_autofree char* devPath = g_drive_get_identifier(drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - if (devPath != NULL) { - if (pThis->mVolume) { - GDrive* driv = g_volume_get_drive(pThis->mVolume); - if (driv) { - tDev = g_drive_get_identifier(driv, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - g_object_unref(driv); - } - } else if (pThis->mDrive) { - tDev = g_drive_get_identifier(pThis->mDrive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); - } - - if (tDev && 0 == g_strcmp0(tDev, devPath)) { - pThis->accept(); - } - } - - Q_UNUSED(monitor) -} - -RepairProgressBar::RepairProgressBar(GDrive* drive, QWidget *parent) : BaseDialog(parent), mDrive(G_DRIVE(drive)) -{ - mThread = new QThread(this); - mDeviceOperation = new DeviceOperation(mDrive); - mDeviceOperation->moveToThread(mThread); - - initUI(); -} - -RepairProgressBar::RepairProgressBar(GVolume *volume, QWidget *parent) : BaseDialog(parent), mVolume(G_VOLUME(volume)) -{ - mThread = new QThread(this); - mDeviceOperation = new DeviceOperation(mVolume); - mDeviceOperation->moveToThread(mThread); - - initUI(); -} - -RepairProgressBar::~RepairProgressBar() -{ - if (mTimer) mTimer->deleteLater(); - if (mProgress) mProgress->deleteLater(); - if (mCancelBtn) mCancelBtn->deleteLater(); - if (mDeviceOperation) mDeviceOperation->deleteLater(); -} - -int RepairProgressBar::exec() -{ - Q_EMIT startRepair(); - - return QDialog::exec(); -} - -void RepairProgressBar::onStartRepair() -{ - mThread->start(); - mCancelBtn->setDisabled(true); - mProgress->setValue(mProgress->minimum()); - mTimer->start(); -} - -void RepairProgressBar::initUI() -{ - setAutoFillBackground(true); - setWindowTitle(tr("Disk repair")); - setBackgroundRole(QPalette::Base); - setContentsMargins(24, 24, 24, 24); - setFixedSize(mFixWidth, mFixHeight); - setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint); - - mTimer = new QTimer; - mTimer->setInterval(1000); - - QGridLayout* mainLayout = new QGridLayout(this); - - QLabel* label = new QLabel; - label->setWordWrap(true); - label->setTextFormat(Qt::RichText); - label->setBackgroundRole(QPalette::Base); - label->setText(tr("<h3>%1</h3>").arg(tr("Attempting a disk repair..."))); - mainLayout->addWidget(label, 1, 1, 1, 4); - - mProgress = new QProgressBar; - mProgress->setMinimum(0); - mProgress->setMaximum(1000); - mainLayout->addWidget(mProgress, 2, 1, 1, 4, Qt::AlignTop); - - mCancelBtn = new QPushButton; - mCancelBtn->setText(tr("Cancel")); - mainLayout->addWidget(mCancelBtn, 3, 4, 1, 1); - - connect(this, &RepairProgressBar::startRepair, this, &RepairProgressBar::onStartRepair); - connect(this, &RepairProgressBar::startRepair, mDeviceOperation, &DeviceOperation::udiskRepair); - connect(this, &RepairProgressBar::cancel, mDeviceOperation, &DeviceOperation::udiskFormatCancel); - connect(mDeviceOperation, &DeviceOperation::repairFinished, this, &RepairProgressBar::onStopRepair); - connect(this, &QDialog::finished, [=] () { - Q_EMIT cancel(); - mTimer->stop(); - mThread->exit(); - }); - - connect(mTimer, &QTimer::timeout, this, [=] () { - int val = mProgress->value(); - if (val <= mProgress->maximum()) { - mProgress->setValue(++val); - } - }); -} - -void RepairProgressBar::onStopRepair(bool success) -{ - mCancelBtn->setEnabled(true); - mProgress->setValue(mProgress->maximum()); - mTimer->stop(); - mThread->exit(); - - if (success) { - MessageBox msg(tr("Disk repair"), tr("Repair successfully!"), QMessageBox::Ok, this); - msg.setPalette(getPalette()); - msg.exec(); - // remount device - Q_EMIT remountDevice(); - accept(); - } else { - MessageBox msg(tr("Disk repair"), tr("Repair failed. If the USB flash disk is not mounted, please try formatting the device!"), QMessageBox::Ok | QMessageBox::Cancel, this); - - connect(&msg, &MessageBox::format, this, [=](){ - FormateDialog dlg(mDrive); - int ret = dlg.exec(); - if (QDialog::Accepted == ret) { - accept(); - } - }); - msg.setPalette(getPalette()); - msg.exec(); - reject(); - } -} - -FormateDialog::FormateDialog(GVolume* volume, QWidget *parent) : BaseDialog(parent), mVolume(volume) -{ - mThread = new QThread; - mDeviceOperation = new DeviceOperation(mVolume); - mDeviceOperation->moveToThread(mThread); - - initUI(); -} - -FormateDialog::~FormateDialog() -{ - if (mTimer) mTimer->deleteLater(); - if (mThread) mThread->deleteLater(); - if (mNameEdit) mNameEdit->deleteLater(); - if (mFSCombox) mFSCombox->deleteLater(); - if (mProgress) mProgress->deleteLater(); - if (mCancelBtn) mCancelBtn->deleteLater(); - if (mFormatBtn) mFormatBtn->deleteLater(); - if (mEraseCkbox) mEraseCkbox->deleteLater(); - if (mRomSizeCombox) mRomSizeCombox->deleteLater(); - if (mDeviceOperation) mDeviceOperation->deleteLater(); -} - -FormateDialog::FormateDialog(GDrive* drive, QWidget *parent) : BaseDialog(parent), mDrive(drive) -{ - mThread = new QThread(this); - mDeviceOperation = new DeviceOperation(mDrive); - mDeviceOperation->moveToThread(mThread); - - initUI(); -} - -int FormateDialog::exec() -{ - if (mDrive || mVolume) { - mRomSizeCombox->clear(); - mRomSizeCombox->addItem(mDeviceOperation->udiskSize()); - } - - return QDialog::exec(); -} - -void FormateDialog::onStopFormat(bool success) -{ - mFormatBtn->setEnabled(true); - mCancelBtn->setEnabled(true); - - mProgress->setValue(mProgress->maximum()); - mTimer->stop(); - mThread->exit(); - - if (success) { - MessageBox msg(tr("Disk format"), tr("Formatted successfully!"), QMessageBox::Ok, this); - msg.exec(); - accept(); - } else { - MessageBox msg(tr("Disk format"), tr("Formatting failed, please unplug the U disk and try again!"), QMessageBox::Ok, this); - msg.exec(); - reject(); - } -} - -void FormateDialog::onStartFormat() -{ - mProgress->setValue(mProgress->minimum()); - mTimer->start(); - - mFormatBtn->setDisabled(true); - mCancelBtn->setDisabled(true); -} - -void FormateDialog::initUI() -{ - setAutoFillBackground(true); - setWindowTitle(tr("Format")); - setBackgroundRole(QPalette::Base); - setContentsMargins(24, 24, 24, 24); - setFixedSize(mFixWidth, mFixHeight); - setWindowIcon(QIcon::fromTheme("system-file-manager")); - setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint); - - QGridLayout* mainLayout = new QGridLayout(this); - - QLabel* romSizeLabel = new QLabel; - romSizeLabel->setText(tr("Rom size:")); - mRomSizeCombox = new QComboBox; - mainLayout->addWidget(romSizeLabel, 1, 1, 1, 2); - mainLayout->addWidget(mRomSizeCombox, 1, 3, 1, 6); - - QLabel* fsLabel = new QLabel; - fsLabel->setText(tr("Filesystem:")); - mFSCombox = new QComboBox; - mFSCombox->addItem("ntfs"); - mFSCombox->addItem("ext4"); - mFSCombox->addItem("exfat"); - mFSCombox->addItem("vfat/fat32"); - mainLayout->addWidget(fsLabel, 2, 1, 1, 2); - mainLayout->addWidget(mFSCombox, 2, 3, 1, 6); - if (BaseDialog* wi = qobject_cast<BaseDialog*>(this)) { - QAbstractItemView * popuView = mFSCombox->view(); - popuView->setPalette(wi->palette()); - popuView = mRomSizeCombox->view(); - popuView->setPalette(wi->palette()); - } - - QLabel* uNameLabel = new QLabel; - uNameLabel->setText(tr("Disk name:")); - mNameEdit = new QLineEdit; - mainLayout->addWidget(uNameLabel, 3, 1, 1, 2); - mainLayout->addWidget(mNameEdit, 3, 3, 1, 6); - - QLabel* eraseLabel = new QLabel; - eraseLabel->setText(tr("Completely erase(Time is longer, please confirm!)")); - mEraseCkbox = new QCheckBox; - mainLayout->addWidget(mEraseCkbox, 4, 1, 1, 1, Qt::AlignRight); - mainLayout->addWidget(eraseLabel, 4, 2, 1, 6, Qt::AlignLeft); - - mProgress = new QProgressBar; - mProgress->setMinimum(0); - mProgress->setMaximum(1000); - mainLayout->addWidget(mProgress, 5, 1, 1, 8); - - mCancelBtn = new QPushButton(tr("Cancel")); - mFormatBtn = new QPushButton(tr("Format disk")); - - mainLayout->addWidget(mCancelBtn, 6, 5, 1, 2, Qt::AlignRight); - mainLayout->addWidget(mFormatBtn, 6, 7, 1, 2, Qt::AlignRight); - - mTimer = new QTimer; - mTimer->setInterval(1000); - connect(mTimer, &QTimer::timeout, this, [=] () { - int val = mProgress->value(); - if (val <= mProgress->maximum()) { - mProgress->setValue(++val); - } - }); - - connect(this, &FormateDialog::startFormat, this, &FormateDialog::onStartFormat); - connect(this, &FormateDialog::startFormat, mDeviceOperation, &DeviceOperation::udiskFormat); - connect(this, &FormateDialog::cancel, mDeviceOperation, &DeviceOperation::udiskFormatCancel); - connect(mDeviceOperation, &DeviceOperation::formatFinished, this, &FormateDialog::onStopFormat); - - connect(mCancelBtn, &QPushButton::clicked, this, [=] (bool) { - reject(); - }); - - connect(this, &QDialog::finished, this, [=] () { - Q_EMIT cancel(); - mTimer->stop(); - mThread->exit(); - }); - - connect(mFormatBtn, &QPushButton::clicked, this, [=] (bool) { - MessageBox msg(tr("Disk format"), tr("Formatting this volume will erase all data on it. Please back up all retained data before formatting. Do you want to continue?"), QMessageBox::Ok | QMessageBox::Cancel, this); - if (QMessageBox::Cancel == msg.exec()) { - return ; - } - - mThread->start(); - QString ctype = mFSCombox->currentText(); - QString type = ctype.isEmpty() ? "vfat" : ctype; - type = ("vfat/fat32" == type) ? "vfat" : type; - QString dlabel = mNameEdit->text(); - QString label = dlabel.isEmpty() ? mDeviceOperation->udiskLabel() : dlabel; - - Q_EMIT startFormat(type, label); - }); -} - -BaseDialog::BaseDialog(QWidget *parent) : QDialog(parent) -{ - setWindowTitle(tr("Disk test")); - - if (QGSettings::isSchemaInstalled("org.ukui.style")) { - mGSettings = new QGSettings ("org.ukui.style", "/org/ukui/style/"); - - connect(mGSettings, &QGSettings::changed, this, [=] (const QString &key) { - if ("styleName" == key) { - //setStyleSheet ("QCheckBox{margin:3px;}"); - QPalette p = getPalette(); - for (auto obj : children ()) { - if (QWidget* w = qobject_cast<QWidget*>(obj)) { - w->setPalette (p); - w->update (); - if (QComboBox * combo = qobject_cast<QComboBox*>(obj)) { - QAbstractItemView * popuView = combo->view(); - popuView->setPalette(p); - popuView->update(); - } - } - } - setPalette(p); - update(); - } - }); - } - - setTheme(); - - if ((qgetenv ("DESKTOP_SESSION") == "ukui" && qgetenv ("XDG_SESSION_TYPE") == "x11")|| - (qgetenv ("DESKTOP_SESSION") == "ukui-wayland" && qgetenv ("XDG_SESSION_TYPE") == "wayland")) { - setStyle (BaseDialogStyle::getStyle ()); - //setStyleSheet ("QCheckBox{margin:3px;}"); - } -} - -QPalette BaseDialog::getPalette() -{ - if (mGSettings && QGSettings::isSchemaInstalled("org.ukui.style")) { - QString value = mGSettings->get("styleName").toString(); - if ("ukui-default" == value) { - return getWhitePalette(); - } else { - return getBlackPalette(); - } - } - - return getWhitePalette(); -} - -QPalette BaseDialog::getWhitePalette() -{ - auto palette = qApp->palette(); - - QColor window_bg(231,231,231), - window_no_bg(233,233,233), - base_bg(255,255,255), - base_no_bg(248, 248, 248), - font_bg(0,0,0), - font_br_bg(255,255,255), - font_di_bg(191,191,191), - button_bg(217,217,217), - button_ac_bg(107,142,235), - button_di_bg(233,233,233), - highlight_bg(61,107,229), - tip_bg(248,248,248), - tip_font(22,22,22), - alternateBase(248,248,248); - - palette.setBrush(QPalette::WindowText,font_bg); - - palette.setBrush(QPalette::Window,window_bg); - palette.setBrush(QPalette::Active,QPalette::Window,window_bg); - palette.setBrush(QPalette::Inactive,QPalette::Window,window_no_bg); - palette.setBrush(QPalette::Disabled,QPalette::Window,window_no_bg); - palette.setBrush(QPalette::WindowText,font_bg); - palette.setBrush(QPalette::Active,QPalette::WindowText,font_bg); - palette.setBrush(QPalette::Inactive,QPalette::WindowText,font_bg); - palette.setBrush(QPalette::Disabled,QPalette::WindowText,font_di_bg); - - palette.setBrush(QPalette::Base,base_bg); - palette.setBrush(QPalette::Active,QPalette::Base,base_bg); - palette.setBrush(QPalette::Inactive,QPalette::Base,base_no_bg); - palette.setBrush(QPalette::Disabled,QPalette::Base,base_no_bg); - palette.setBrush(QPalette::Text,font_bg); - palette.setBrush(QPalette::Active,QPalette::Text,font_bg); - palette.setBrush(QPalette::Disabled,QPalette::Text,font_di_bg); - - //Cursor placeholder -#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0)) - palette.setBrush(QPalette::PlaceholderText,font_di_bg); -#endif - - palette.setBrush(QPalette::ToolTipBase,tip_bg); - palette.setBrush(QPalette::ToolTipText,tip_font); - - palette.setBrush(QPalette::Highlight,highlight_bg); - palette.setBrush(QPalette::Active,QPalette::Highlight,highlight_bg); - palette.setBrush(QPalette::HighlightedText,font_br_bg); - - palette.setBrush(QPalette::BrightText,font_br_bg); - palette.setBrush(QPalette::Active,QPalette::BrightText,font_br_bg); - palette.setBrush(QPalette::Inactive,QPalette::BrightText,font_br_bg); - palette.setBrush(QPalette::Disabled,QPalette::BrightText,font_di_bg); - - palette.setBrush(QPalette::Button,button_bg); - palette.setBrush(QPalette::Active,QPalette::Button,button_bg); - palette.setBrush(QPalette::Inactive,QPalette::Button,button_bg); - palette.setBrush(QPalette::Disabled,QPalette::Button,button_di_bg); - palette.setBrush(QPalette::ButtonText,font_bg); - palette.setBrush(QPalette::Inactive,QPalette::ButtonText,font_bg); - palette.setBrush(QPalette::Disabled,QPalette::ButtonText,font_di_bg); - - palette.setBrush(QPalette::AlternateBase,alternateBase); - palette.setBrush(QPalette::Inactive,QPalette::AlternateBase,alternateBase); - palette.setBrush(QPalette::Disabled,QPalette::AlternateBase,button_di_bg); - - return palette; -} - -QPalette BaseDialog::getBlackPalette() -{ - auto palette = qApp->palette(); - QColor - window_bg(45,46,50), - window_no_bg(48,46,50), - base_bg(31,32,34), - base_no_bg(28,28,30), - font_bg(255,255,255), - font_br_bg(255,255,255), - font_di_bg(255,255,255), - button_bg(61,61,65), - button_ac_bg(48,48,51), - button_di_bg(48,48,51), - highlight_bg(61,107,229), - tip_bg(61,61,65), - tip_font(232,232,232), - alternateBase(36,35,40); - - - font_bg.setAlphaF(0.9); - font_br_bg.setAlphaF(0.9); - font_di_bg.setAlphaF(0.1); - - palette.setBrush(QPalette::Window,window_bg); - palette.setBrush(QPalette::Active,QPalette::Window,window_bg); - palette.setBrush(QPalette::Inactive,QPalette::Window,window_no_bg); - palette.setBrush(QPalette::Disabled,QPalette::Window,window_no_bg); - palette.setBrush(QPalette::WindowText,font_bg); - palette.setBrush(QPalette::Active,QPalette::WindowText,font_bg); - palette.setBrush(QPalette::Inactive,QPalette::WindowText,font_bg); - palette.setBrush(QPalette::Disabled,QPalette::WindowText,font_di_bg); - - palette.setBrush(QPalette::Base,base_bg); - palette.setBrush(QPalette::Active,QPalette::Base,base_bg); - palette.setBrush(QPalette::Inactive,QPalette::Base,base_no_bg); - palette.setBrush(QPalette::Disabled,QPalette::Base,base_no_bg); - palette.setBrush(QPalette::Text,font_bg); - palette.setBrush(QPalette::Active,QPalette::Text,font_bg); - palette.setBrush(QPalette::Disabled,QPalette::Text,font_di_bg); - - //Cursor placeholder -#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0)) - palette.setBrush(QPalette::PlaceholderText,font_di_bg); -#endif - - palette.setBrush(QPalette::ToolTipBase,tip_bg); - palette.setBrush(QPalette::ToolTipText,tip_font); - - palette.setBrush(QPalette::Highlight,highlight_bg); - palette.setBrush(QPalette::Active,QPalette::Highlight,highlight_bg); - palette.setBrush(QPalette::HighlightedText,font_br_bg); - - palette.setBrush(QPalette::BrightText,font_br_bg); - palette.setBrush(QPalette::Active,QPalette::BrightText,font_br_bg); - palette.setBrush(QPalette::Inactive,QPalette::BrightText,font_br_bg); - palette.setBrush(QPalette::Disabled,QPalette::BrightText,font_di_bg); - - palette.setBrush(QPalette::Button,button_bg); - palette.setBrush(QPalette::Active,QPalette::Button,button_bg); - palette.setBrush(QPalette::Inactive,QPalette::Button,button_bg); - palette.setBrush(QPalette::Disabled,QPalette::Button,button_di_bg); - palette.setBrush(QPalette::ButtonText,font_bg); - palette.setBrush(QPalette::Inactive,QPalette::ButtonText,font_bg); - palette.setBrush(QPalette::Disabled,QPalette::ButtonText,font_di_bg); - - palette.setBrush(QPalette::AlternateBase,alternateBase); - palette.setBrush(QPalette::Inactive,QPalette::AlternateBase,alternateBase); - palette.setBrush(QPalette::Disabled,QPalette::AlternateBase,button_di_bg); - - return palette; -} - -void BaseDialog::setTheme() -{ - setPalette(getPalette()); -} - -MessageBox::MessageBox(QString title, QString text, QMessageBox::StandardButtons bt, QWidget *parent) : BaseDialog(parent) -{ - setFixedSize(420, 200); - setContentsMargins(24, 24, 24, 24); - setAutoFillBackground(true); - setWindowTitle(title); - setBackgroundRole(QPalette::Base); - - QGridLayout* mainLayout = new QGridLayout(this); - - QLabel* label = new QLabel; - label->setText(text); - label->setWordWrap(true); - mainLayout->addWidget(label, 1, 1, 1, 4); - - QPushButton* ok = nullptr; - QPushButton* cancel = nullptr; - if (bt & QMessageBox::Ok && bt & QMessageBox::Cancel) { - ok = new QPushButton; - ok->setText(tr("Format")); - mainLayout->addWidget(ok, 2, 3, 1, 1); - cancel = new QPushButton; - cancel->setText(tr("Cancel")); - mainLayout->addWidget(cancel, 2, 4, 1, 1); - } else if (bt & QMessageBox::Ok && !(bt & QMessageBox::Cancel)) { - ok = new QPushButton; - ok->setText(tr("OK")); - mainLayout->addWidget(ok, 2, 4, 1, 1); - } else if (!(bt & QMessageBox::Ok) && bt & QMessageBox::Cancel) { - cancel = new QPushButton; - cancel->setText(tr("Cancel")); - mainLayout->addWidget(cancel, 2, 4, 1, 1); - } - - if (ok) { - connect(ok, &QPushButton::clicked, this, [=] (bool) { - Q_EMIT format(); - done(QMessageBox::Ok); - }); - } - if (cancel) { - connect(cancel, &QPushButton::clicked, this, [=] (bool) { - done(QMessageBox::Cancel); - }); - } -} - -BaseDialogStyle::BaseDialogStyle() -{ - -} - -BaseDialogStyle::~BaseDialogStyle() -{ - -} - -BaseDialogStyle *BaseDialogStyle::getStyle() -{ - if (!gInstance) { - gInstance = new BaseDialogStyle; - } - - return gInstance; -} - -void BaseDialogStyle::polish(QWidget *w) -{ - if (BaseDialog* wi = qobject_cast<BaseDialog*>(w)) { - mPalette = wi->getPalette (); - } - - if (w) w->setPalette (mPalette); -} - -void BaseDialogStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const -{ - switch (element) { - case CE_ComboBoxLabel: { - if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { - QRect arrowRect = QProxyStyle::subControlRect(CC_ComboBox, comboBox, SC_ComboBoxArrow, widget); - QRect editRect = QProxyStyle::subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget); - - QStyleOption arrow = *option; - arrow.state = option->state & State_Enabled ? State_Enabled : State_None; - arrow.rect = arrowRect; - arrow.palette = mPalette; - QProxyStyle::drawPrimitive(PE_IndicatorArrowDown, &arrow, painter, widget); - - painter->save(); - - if (!comboBox->currentText.isEmpty() && !comboBox->editable) { - drawItemText(painter, editRect, visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter), - mPalette, option->state & State_Enabled, comboBox->currentText); - } - painter->restore(); - return; - } - } - break; - - case CE_PushButton: { - if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { - drawControl(CE_PushButtonBevel, option, painter, widget); - QStyleOptionButton subopt = *button; - subopt.rect = QProxyStyle::subElementRect(SE_PushButtonContents, option, widget); - subopt.palette = mPalette; - drawControl(CE_PushButtonLabel, &subopt, painter, widget); - return; - } - } - break; - - case CE_PushButtonBevel: { - drawPrimitive(PE_PanelButtonCommand, option, painter, widget); - } - break; - - case CE_PushButtonLabel: { - if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { - const bool enable = button->state & State_Enabled; - const bool text = !button->text.isEmpty(); - const bool icon = !button->icon.isNull(); - - bool isWindowButton = false; - bool isWindowColoseButton = false; - bool isImportant = false; - bool useButtonPalette = false; - if (widget) { - if (widget->property("isWindowButton").isValid()) { - if (widget->property("isWindowButton").toInt() == 0x01) - isWindowButton = true; - if (widget->property("isWindowButton").toInt() == 0x02) - isWindowColoseButton = true; - } - if (widget->property("isImportant").isValid()) - isImportant = widget->property("isImportant").toBool(); - - if (widget->property("useButtonPalette").isValid()) - useButtonPalette = widget->property("useButtonPalette").toBool(); - } - - QRect drawRect = button->rect; - int spacing = 8; - QStyleOption sub = *option; - if (isImportant && !(button->features & QStyleOptionButton::Flat)) { - sub.state = option->state | State_On; - } else if (isWindowButton || useButtonPalette) { - sub.state = enable ? State_Enabled : State_None; - } else { - sub.state = option->state; - } - - if (button->features & QStyleOptionButton::HasMenu) { - QRect arrowRect; - int indicator = proxy()->pixelMetric(PM_MenuButtonIndicator, option, widget); - arrowRect.setRect(drawRect.right() - indicator, drawRect.top() + (drawRect.height() - indicator) / 2, indicator, indicator); - arrowRect = visualRect(option->direction, option->rect, arrowRect); - if (!text && !icon) - spacing = 0; - drawRect.setWidth(drawRect.width() - indicator - spacing); - drawRect = visualRect(button->direction, button->rect, drawRect); - sub.rect = arrowRect; - QProxyStyle::drawPrimitive(PE_IndicatorArrowDown, &sub, painter, widget); - } - - int tf = Qt::AlignCenter; - if (QProxyStyle::styleHint(SH_UnderlineShortcut, button, widget)) { - tf |= Qt::TextShowMnemonic; - } - QPixmap pixmap; - if (icon) { - QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; - if (mode == QIcon::Normal && button->state & State_HasFocus) - mode = QIcon::Active; - QIcon::State state = QIcon::Off; - if (button->state & State_On) - state = QIcon::On; - pixmap = button->icon.pixmap(button->iconSize, mode, state); - } - - QFontMetrics fm = button->fontMetrics; - int textWidth = fm.boundingRect(option->rect, tf, button->text).width() + 2; - int iconWidth = icon ? button->iconSize.width() : 0; - QRect iconRect, textRect; - if (icon && text) { - int width = textWidth + spacing + iconWidth; - if (width > drawRect.width()) { - width = drawRect.width(); - textWidth = width - spacing - iconWidth; - } - textRect.setRect(drawRect.x(), drawRect.y(), width, drawRect.height()); - textRect.moveCenter(drawRect.center()); - iconRect.setRect(textRect.left(), textRect.top(), iconWidth, textRect.height()); - textRect.setRect(iconRect.right() + spacing + 1, textRect.y(), textWidth, textRect.height()); - iconRect = visualRect(option->direction, drawRect, iconRect); - textRect = visualRect(option->direction, drawRect, textRect); - } else if (icon) { - iconRect = drawRect; - } else if (text) { - textRect = drawRect; - } - - if (textRect.isValid()) { - if (enable) { - if (isWindowButton || useButtonPalette) { - drawItemText(painter, textRect, tf, button->palette, true, button->text, mPalette.ButtonText); - } else { - if (isImportant) { - if (button->features & QStyleOptionButton::Flat) { - drawItemText(painter, textRect, tf, mPalette, true, button->text, mPalette.ButtonText); - } else { - drawItemText(painter, textRect, tf, mPalette, true, button->text, mPalette.HighlightedText); - } - if (button->state & (State_MouseOver | State_Sunken | State_On)) { - drawItemText(painter, textRect, tf, mPalette, true, button->text, mPalette.HighlightedText); - } - } else { - if (button->state & (State_MouseOver | State_Sunken | State_On)) { - drawItemText(painter, textRect, tf, mPalette, true, button->text, mPalette.HighlightedText); - } else { - drawItemText(painter, textRect, tf, mPalette, true, button->text, mPalette.ButtonText); - } - } - } - } else { - drawItemText(painter, textRect, tf, mPalette, false, button->text, mPalette.ButtonText); - } - } - return; - } - } - break; - - case CE_CheckBox: { - if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { - QStyleOptionButton subopt = *button; - subopt.palette = mPalette; - subopt.rect = QProxyStyle::subElementRect(SE_CheckBoxIndicator, option, widget); - drawPrimitive(PE_IndicatorCheckBox, &subopt, painter, widget); - subopt.rect = QProxyStyle::subElementRect(SE_CheckBoxContents, option, widget); - drawControl(CE_CheckBoxLabel, &subopt, painter, widget); - return; - } - } - break; - - case CE_RadioButtonLabel: - case CE_CheckBoxLabel: { - if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { - uint alignment = visualAlignment(button->direction, Qt::AlignLeft | Qt::AlignVCenter); - const bool enable = button->state & State_Enabled; - - if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget)) - alignment |= Qt::TextHideMnemonic; - QPixmap pixmap; - QRect textRect = button->rect; - if (!button->icon.isNull()) { - pixmap = button->icon.pixmap(button->iconSize, enable ? QIcon::Normal : QIcon::Disabled); - drawItemPixmap(painter, button->rect, alignment, pixmap); - int spacing = 8; - if (button->direction == Qt::RightToLeft) - textRect.setRight(textRect.right() - button->iconSize.width() - spacing); - else - textRect.setLeft(textRect.left() + button->iconSize.width() + spacing); - } - if (!button->text.isEmpty()){ - drawItemText(painter, textRect, alignment | Qt::TextShowMnemonic, mPalette, button->state & State_Enabled, button->text, mPalette.WindowText); - } - return; - } - } - break; - - case CE_MenuItem: - break; - - /* 进度条 */ - case CE_ProgressBar: { - if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { - QStyleOptionProgressBar subOption = *pb; - subOption.palette = mPalette; - subOption.rect = proxy()->subElementRect(SE_ProgressBarGroove, pb, widget); - proxy()->drawControl(CE_ProgressBarGroove, &subOption, painter, widget); - subOption.rect = proxy()->subElementRect(SE_ProgressBarContents, pb, widget); - proxy()->drawControl(CE_ProgressBarContents, &subOption, painter, widget); - if (pb->textVisible) { - subOption.rect = proxy()->subElementRect(SE_ProgressBarLabel, pb, widget); - proxy()->drawControl(CE_ProgressBarLabel, &subOption, painter, widget); - } - return; - } - break; - } - - case CE_ProgressBarGroove: { - const bool enable = option->state & State_Enabled; - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(mPalette.brush(enable ? mPalette.Active : mPalette.Disabled, mPalette.Button)); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - return; - } - - case CE_ProgressBarContents: { - if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { - const auto progress = qMax(pb->progress, pb->minimum); - if (progress == pb->minimum) - return; - - const bool vertical = pb->orientation == Qt::Vertical; - const bool inverted = pb->invertedAppearance; - const bool indeterminate = (pb->minimum == 0 && pb->maximum == 0); - - QRect rect = pb->rect; - int maxWidth = vertical ? pb->rect.height() : pb->rect.width(); - const auto totalSteps = qMax(Q_INT64_C(1), qint64(pb->maximum) - pb->minimum); - const auto progressSteps = qint64(progress) - pb->minimum; - const auto progressBarWidth = progressSteps * maxWidth / totalSteps; - int len = indeterminate ? maxWidth : progressBarWidth; - - bool reverse = (!vertical && (pb->direction == Qt::RightToLeft)) || vertical; - if (inverted) - reverse = !reverse; - - QColor startColor = mPalette.color(mPalette.Active, mPalette.Highlight); - QColor endColor = mPalette.color(mPalette.Active, mPalette.Highlight); - QLinearGradient linearGradient; - linearGradient.setColorAt(0, startColor); - linearGradient.setColorAt(1, endColor); - QRect progressRect; - if (indeterminate) { - - } else { - if (vertical) { - if (reverse) { - progressRect.setRect(rect.left(), rect.bottom() + 1 - len, rect.width(), len); - linearGradient.setStart(progressRect.bottomLeft()); - linearGradient.setFinalStop(progressRect.topLeft()); - } else { - progressRect.setRect(rect.x(), rect.top(), rect.width(), len); - linearGradient.setStart(progressRect.topLeft()); - linearGradient.setFinalStop(progressRect.bottomLeft()); - } - } else { - if (reverse) { - progressRect.setRect(rect.right() + 1 - len, rect.top(), len, rect.height()); - linearGradient.setStart(progressRect.topRight()); - linearGradient.setFinalStop(progressRect.topLeft()); - } else { - progressRect.setRect(rect.x(), rect.y(), len, rect.height()); - linearGradient.setStart(progressRect.topLeft()); - linearGradient.setFinalStop(progressRect.topRight()); - } - } - } - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(linearGradient); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(progressRect, 4, 4); - painter->restore(); - return; - } - } - break; - - case CE_ProgressBarLabel: { - if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { - if (pb->textVisible) { - const auto progress = qMax(pb->progress, pb->minimum); - const bool vertical = pb->orientation == Qt::Vertical; - const bool inverted = pb->invertedAppearance; - const bool indeterminate = (pb->minimum == 0 && pb->maximum == 0); - - int maxWidth = vertical ? pb->rect.height() : pb->rect.width(); - const auto totalSteps = qMax(Q_INT64_C(1), qint64(pb->maximum) - pb->minimum); - const auto progressSteps = qint64(progress) - pb->minimum; - const auto progressBarWidth = progressSteps * maxWidth / totalSteps; - int len = indeterminate ? maxWidth : progressBarWidth; - - bool reverse = (!vertical && (pb->direction == Qt::RightToLeft)) || vertical; - if (inverted) - reverse = !reverse; - - painter->save(); - painter->setBrush(Qt::NoBrush); - QRect rect = pb->rect; - if (pb->orientation == Qt::Vertical) { - rect.setRect(rect.y(), rect.x(), rect.height(), rect.width()); - QTransform m; - m.rotate(90); - m.translate(0, -rect.height()); - painter->setTransform(m, true); - } - QRect textRect(rect.x(), rect.y(), pb->fontMetrics.horizontalAdvance(pb->text), rect.height()); - textRect.moveCenter(rect.center()); - if (len <= textRect.left()) { - painter->setPen(mPalette.color(mPalette.Active, mPalette.WindowText)); - painter->drawText(textRect, pb->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter)); - } else if (len >= textRect.right()) { - painter->setPen(mPalette.color(mPalette.Active, mPalette.HighlightedText)); - painter->drawText(textRect, pb->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter)); - } else { - QRect leftRect(textRect.x(), textRect.y(), len - textRect.left(), textRect.height()); - QRect rightRect(leftRect.right() + 1, textRect.y(), textRect.right() + 1 - len, textRect.height()); - if (reverse) { - leftRect.setRect(textRect.left(), textRect.top(), maxWidth - len - textRect.left(), textRect.height()); - rightRect.setRect(leftRect.right() + 1, textRect.top(), textRect.width() - leftRect.width(), textRect.height()); - painter->setPen(mPalette.color(mPalette.Active, mPalette.HighlightedText)); - painter->setClipRect(rightRect); - painter->drawText(textRect, pb->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter)); - painter->setPen(mPalette.color(mPalette.Active, mPalette.WindowText)); - painter->setClipRect(leftRect); - painter->drawText(textRect, pb->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter)); - } else { - painter->setPen(mPalette.color(mPalette.Active, mPalette.WindowText)); - painter->setClipRect(rightRect); - painter->drawText(textRect, pb->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter)); - painter->setPen(mPalette.color(mPalette.Active, mPalette.HighlightedText)); - painter->setClipRect(leftRect); - painter->drawText(textRect, pb->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter)); - } - } - painter->resetTransform(); - painter->restore(); - } - return; - } - } - break; - - default: - QStyleOption opt = *option; - opt.palette = mPalette; - QProxyStyle::drawControl (element, &opt, painter, widget); - break; - } - QProxyStyle::drawControl (element, option, painter, widget); -} - -void BaseDialogStyle::drawPrimitive(PrimitiveElement elem, const QStyleOption *option, QPainter *painter, const QWidget *widget) const -{ - switch (elem) { - case PE_PanelButtonTool: { - QProxyStyle::drawPrimitive (elem, option, painter, widget); - return; - bool isWindowColoseButton = false; - bool isWindowButton = false; - bool useButtonPalette = false; - if (widget) { - if (widget->property("isWindowButton").isValid()) { - if (widget->property("isWindowButton").toInt() == 0x01) - isWindowButton = true; - if (widget->property("isWindowButton").toInt() == 0x02) - isWindowColoseButton = true; - } - if (widget->property("useButtonPalette").isValid()) - useButtonPalette = widget->property("useButtonPalette").toBool(); - } - - const bool enable = option->state & State_Enabled; - const bool raise = option->state & State_AutoRaise; - const bool sunken = option->state & State_Sunken; - const bool hover = option->state & State_MouseOver; - const bool on = option->state & State_On; - - if (!enable) { - painter->save(); - painter->setPen(Qt::NoPen); - if (on) - painter->setBrush(mPalette.color(mPalette.Disabled, mPalette.Button)); - else if (raise) - painter->setBrush(Qt::NoBrush); - else - painter->setBrush(mPalette.color(mPalette.Disabled, mPalette.Button)); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - return; - } - - if (!raise) { - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(mPalette.color(mPalette.Active, mPalette.Button)); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - } - - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setPen(Qt::NoPen); - if (sunken || on) { - if (isWindowButton) { - QColor color = mPalette.color(mPalette.Active, mPalette.Base); - color.setAlphaF(0.15); - painter->setBrush(color); - } else if (isWindowColoseButton) { - painter->setBrush(QColor("#E44C50")); - } else { - painter->setBrush(mPalette.brush (mPalette.Active, mPalette.Highlight)); - } - } else if (hover) { - if (isWindowButton) { - QColor color = mPalette.color(mPalette.Active, mPalette.Base); - color.setAlphaF(0.1); - painter->setBrush(color); - } else if (isWindowColoseButton) { - painter->setBrush(QColor("#F86458")); - } else { - painter->setBrush(mPalette.brush (mPalette.Active, mPalette.Highlight)); - } - } - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - return; - return; - } - break; - case PE_PanelButtonCommand: { - if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { - const bool enable = button->state & State_Enabled; - const bool hover = button->state & State_MouseOver; - const bool sunken = button->state & State_Sunken; - const bool on = button->state & State_On; - qreal x_Radius = 4; - qreal y_Radius = 4; - bool isWindowButton = false; - bool isWindowColoseButton = false; - bool isImportant = false; - bool useButtonPalette = false; - if (widget) { - if (widget->property("isWindowButton").isValid()) { - if (widget->property("isWindowButton").toInt() == 0x01) - isWindowButton = true; - if (widget->property("isWindowButton").toInt() == 0x02) - isWindowColoseButton = true; - } - if (widget->property("isImportant").isValid()) - isImportant = widget->property("isImportant").toBool(); - - if (widget->property("useButtonPalette").isValid()) - useButtonPalette = widget->property("useButtonPalette").toBool(); - - if (qobject_cast<const QComboBox*>(widget) || qobject_cast<const QLineEdit*>(widget) - || qobject_cast<const QAbstractSpinBox*>(widget)) - useButtonPalette = true; - } - - if (!enable) { - painter->save(); - painter->setPen(Qt::NoPen); - if (on) { - painter->setBrush(Qt::NoBrush); - } else if (button->features & QStyleOptionButton::Flat) { - painter->setBrush(Qt::NoBrush); - } else { - painter->setBrush(mPalette.brush(mPalette.Disabled, mPalette.Button)); - } - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect, x_Radius, y_Radius); - painter->restore(); - return; - } - - if (!(button->features & QStyleOptionButton::Flat)) { - painter->save(); - painter->setPen(Qt::NoPen); - if (isImportant) - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Highlight)); - else - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Button)); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect, x_Radius, y_Radius); - painter->restore(); - } - - painter->save(); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->setPen(Qt::NoPen); - if (sunken || on) { - if (isWindowColoseButton) { - painter->setBrush(QColor("#E44C50")); - } else { - painter->setBrush(mPalette.brush (mPalette.Active, mPalette.Highlight)); - } - } else if (hover) { - if (isWindowColoseButton) { - painter->setBrush(QColor("#F86458")); - } else { - painter->setBrush(mPalette.brush (mPalette.Active, mPalette.Highlight)); - } - } - painter->drawRoundedRect(button->rect, x_Radius, y_Radius); - painter->restore(); - return; - } - } - break; - case PE_IndicatorCheckBox: { - if (const QStyleOptionButton *checkbox = qstyleoption_cast<const QStyleOptionButton*>(option)) { - const bool useDarkPalette = false; - bool enable = checkbox->state & State_Enabled; - bool mouseOver = checkbox->state & State_MouseOver; - bool sunKen = checkbox->state & State_Sunken; - bool on = checkbox->state & State_On; - bool noChange = checkbox->state & State_NoChange; - - QRectF rect = checkbox->rect; - int width = rect.width(); - int heigth = rect.height(); - int x_Radius = 4; - int y_Radius = 4; - - QPainterPath path; - if (on) { - path.moveTo(width/4 + checkbox->rect.left(), heigth/2 + checkbox->rect.top()); - path.lineTo(width*0.45 + checkbox->rect.left(), heigth*3/4 + checkbox->rect.top()); - path.lineTo(width*3/4 + checkbox->rect.left(), heigth/4 + checkbox->rect.top()); - } else if (noChange){ - path.moveTo(rect.left() + width/4, rect.center().y()); - path.lineTo(rect.right() - width/4 , rect.center().y()); - } - - painter->save(); - painter->setClipRect(rect); - painter->setRenderHint(QPainter::Antialiasing, true); - if (enable) { - if (on | noChange) { - if (sunKen) { - painter->setPen(QColor(25, 101, 207)); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Highlight)); - } else if (mouseOver) { - painter->setPen(QColor(36, 109, 212)); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Highlight)); - } else { - painter->setPen(QColor(36, 109, 212)); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Highlight)); - } - painter->drawRoundedRect(rect, x_Radius, y_Radius); - - painter->setPen(QPen(mPalette.brush(mPalette.Active, mPalette.HighlightedText), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(Qt::NoBrush); - painter->drawPath(path); - } else { - if (sunKen) { - if (useDarkPalette) { - painter->setPen(QColor(36, 109, 212)); - painter->setBrush(QColor(6, 35, 97)); - } else { - painter->setPen(QColor(36, 109, 212)); - painter->setBrush(QColor(179, 221, 255)); - } - } else if (mouseOver) { - if (useDarkPalette) { - painter->setPen(QColor(55, 144, 250)); - painter->setBrush(QColor(9, 53, 153)); - } else { - painter->setPen(QColor(97, 173, 255)); - painter->setBrush(QColor(219, 240, 255)); - } - } else { - if (useDarkPalette) { - painter->setPen(QColor(72, 72, 77)); - painter->setBrush(QColor(48, 48, 51)); - } else { - painter->setPen(QColor(191, 191, 191)); - painter->setBrush(mPalette.color(mPalette.Active, mPalette.Window)); - } - } - painter->drawRoundedRect(rect, x_Radius, y_Radius); - } - } else { - if (useDarkPalette) { - painter->setPen(QColor(48, 48, 51)); - painter->setBrush(QColor(28, 28, 30)); - } else { - painter->setPen(QColor(224, 224, 224)); - painter->setBrush(QColor(233, 233, 233)); - } - painter->drawRoundedRect(rect, x_Radius, y_Radius); - if (on | noChange) { - painter->setPen(QPen(mPalette.brush(mPalette.Disabled, mPalette.ButtonText), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(Qt::NoBrush); - painter->drawPath(path); - } - } - painter->restore(); - return; - } - } - break; - case PE_PanelLineEdit: { - if (widget) { - if (QAction *clearAction = widget->findChild<QAction *>(QLatin1String("_q_qlineeditclearaction"))) { - QStyleOption subOption = *option; - subOption.palette = mPalette; - QColor color = subOption.palette.color(QPalette::Text); - color.setAlphaF(1.0); - subOption.palette.setColor(QPalette::Text, color); - } - } - - if (widget) { - if (widget->parentWidget()) - if (widget->parentWidget()->inherits("QDoubleSpinBox")|| widget->parentWidget()->inherits("QSpinBox") - || widget->parentWidget()->inherits("QComboBox") || widget->parentWidget()->inherits("QDateTimeEdit")) { - return; - } - } - - if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(option)) { - const bool enable = f->state & State_Enabled; - const bool focus = f->state & State_HasFocus; - - if (!enable) { - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(mPalette.brush(mPalette.Disabled, mPalette.Button)); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - return; - } - - if (f->state & State_ReadOnly) { - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Button)); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - return; - } - - if (focus) { - painter->save(); - painter->setPen(QPen(mPalette.brush(mPalette.Active, mPalette.Highlight), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Base)); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(option->rect.adjusted(1, 1, -1, -1), 4, 4); - painter->restore(); - } else { - QStyleOptionButton button; - button.state = option->state & ~(State_Sunken | State_On); - button.palette = mPalette; - button.rect = option->rect; - drawPrimitive(PE_PanelButtonCommand, &button, painter, widget); - - if (f->state & State_MouseOver) { - QRectF rect = f->rect; - painter->save(); - painter->setPen(QPen(mPalette.brush(mPalette.Active, mPalette.Highlight), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(Qt::NoBrush); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawRoundedRect(rect.adjusted(0.5, 0.5, -0.5, -0.5), 4, 4); - painter->restore(); - } - } - return; - } - } - break; - default: - QStyleOption opt = *option; - opt.palette = mPalette; - QProxyStyle::drawPrimitive (elem, &opt, painter, widget); - break; - } -} - -void BaseDialogStyle::drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole) const -{ - QProxyStyle::drawItemText (painter, rect, flags, mPalette, enabled, text, textRole); -} - -void BaseDialogStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const -{ - switch (control) { - case CC_ComboBox: { - if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { - const bool enable = comboBox->state & State_Enabled; - const bool on = comboBox->state & State_On; - const bool hover = comboBox->state & State_MouseOver; - - if (!enable) { - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(mPalette.brush(mPalette.Disabled, mPalette.Button)); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->drawRoundedRect(option->rect, 4, 4); - painter->restore(); - return; - } - - if (comboBox->editable) { - painter->save(); - if (comboBox->state & (State_HasFocus | State_On)) { - painter->setPen(QPen(mPalette.brush(mPalette.Active, mPalette.Highlight), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Base)); - } else { - painter->setPen(Qt::NoPen); - painter->setBrush(mPalette.brush(mPalette.Active, mPalette.Button)); - } - painter->setRenderHint(QPainter::Antialiasing,true); - painter->drawRoundedRect(option->rect.adjusted(1, 1, -1, -1), 4, 4); - painter->restore(); - } else { - QStyleOptionButton button; - button.state = option->state; - button.rect = option->rect; - button.palette = mPalette; - drawPrimitive(PE_PanelButtonCommand, &button, painter, widget); - if (on) { - painter->save(); - painter->setPen(QPen(mPalette.brush(mPalette.Active, mPalette.Highlight), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(Qt::NoBrush); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->drawRoundedRect(option->rect.adjusted(1, 1, -1, -1), 4, 4); - painter->restore(); - } - } - - if (hover) { - QRectF rect = comboBox->rect; - painter->save(); - painter->setPen(QPen(mPalette.brush(mPalette.Active, mPalette.Highlight), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter->setBrush(Qt::NoBrush); - painter->setRenderHint(QPainter::Antialiasing,true); - painter->drawRoundedRect(rect.adjusted(0.5, 0.5, -0.5, -0.5), 4, 4); - painter->restore(); - } - - return; - } - break; - } - default: - QStyleOptionComplex opt = *option; - opt.palette = mPalette; - QProxyStyle::drawComplexControl (control, &opt, painter, widget); - break; - } -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/repair-dialog-box.h ukui-panel-4.0.0.0/ukui-flash-disk/repair-dialog-box.h --- ukui-panel-3.14.0.1/ukui-flash-disk/repair-dialog-box.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/repair-dialog-box.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2021 KylinSoft Co., Ltd. - * - * Authors: - * Ding Jing dingjing@kylinos.cn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef REPAIRDIALOGBOX_H -#define REPAIRDIALOGBOX_H - -#include <QDialog> -#include <QCheckBox> -#include <QComboBox> -#include <QProgressBar> -#include <QTimer> -#include <QThread> -#include <QLabel> -#include <QLineEdit> -#include <QWidget> -#include <QMessageBox> -#include <QProxyStyle> - -#include <gio/gio.h> -#include "device-operation.h" -#include "flashdiskdata.h" -#include "MacroFile.h" - -class QGSettings; -class QDBusConnection; -class RepairProgressBar; - -class BaseDialogStyle : public QProxyStyle -{ - Q_OBJECT -public: - static BaseDialogStyle* getStyle(); - -public: - void polish (QWidget* w) override; - - void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override; - void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override; - - void drawPrimitive(PrimitiveElement elem, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; - void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override; - -private: - BaseDialogStyle (); - ~BaseDialogStyle (); - -private: - QPalette mPalette; - static BaseDialogStyle* gInstance; -}; - -class BaseDialog : public QDialog -{ - Q_OBJECT -public: - explicit BaseDialog(QWidget *parent = nullptr); - QPalette getPalette(); - QPalette getBlackPalette(); - QPalette getWhitePalette(); - - void setTheme(); - -Q_SIGNALS: - void themeChanged (); - -private: - QGSettings* mGSettings = nullptr; -}; - -class RepairDialogBox : public BaseDialog -{ - Q_OBJECT -public: - explicit RepairDialogBox(GDrive* drive, QWidget *parent = nullptr); - explicit RepairDialogBox(GVolume* volume, QWidget *parent = nullptr); - QString getDeviceName (); - static bool mshowflag; - ~RepairDialogBox(); - -public Q_SLOTS: - void onRemountDevice(); - -private: - void initUI(); - void isRunning(bool running = false); - static void drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, RepairDialogBox* pThis); - -Q_SIGNALS: - void repairOK (RepairDialogBox*); - void remountDevice(FDVolumeInfo volumeInfo); - -private: - bool mRepair = false; - bool mFormat = false; - - const int mFixWidth = 480; - const int mFixHeight = 240; - - gulong mVMConnect = 0; - - QPushButton* mRepairBtn = nullptr; - QPushButton* mFormatBtn = nullptr; - - QString mDeviceName = nullptr; - GDrive* mDrive = nullptr; - GVolume* mVolume = nullptr; -}; - -class RepairProgressBar : public BaseDialog -{ - Q_OBJECT -public: - explicit RepairProgressBar(GDrive* drive, QWidget* parent = nullptr); - explicit RepairProgressBar(GVolume* volume, QWidget* parent = nullptr); - ~RepairProgressBar(); - - int exec() override; - - void onStopRepair(bool); - void onStartRepair(); - -private: - void initUI (); - -Q_SIGNALS: - void cancel(); - void startRepair(); - void remountDevice(); - -private: - int mProcess = 0; - const int mFixWidth = 480; - const int mFixHeight = 240; - - QTimer* mTimer = nullptr; - QProgressBar* mProgress = nullptr; - QPushButton* mCancelBtn = nullptr; - - QThread* mThread = nullptr; - DeviceOperation* mDeviceOperation = nullptr; - - GDrive* mDrive = nullptr; - GVolume* mVolume = nullptr; -}; - -class FormateDialog : public BaseDialog -{ - Q_OBJECT -public: - explicit FormateDialog(GDrive* drive, QWidget *parent = nullptr); - explicit FormateDialog(GVolume* drive, QWidget *parent = nullptr); - ~FormateDialog(); - int exec() override; - - void onStopFormat(bool); - void onStartFormat(); - -private: - void initUI(); - -Q_SIGNALS: - void cancel(); - void startFormat(QString type, QString labelName); - -private: - const int mFixWidth = 480; - const int mFixHeight = 440; - - QTimer* mTimer = nullptr; - - QComboBox* mFSCombox = nullptr; - QProgressBar* mProgress = nullptr; - QPushButton* mCancelBtn = nullptr; - QPushButton* mFormatBtn = nullptr; - QCheckBox* mEraseCkbox = nullptr; - QLineEdit* mNameEdit = nullptr; - QComboBox* mRomSizeCombox = nullptr; - - QThread* mThread = nullptr; - DeviceOperation* mDeviceOperation = nullptr; - - GDrive* mDrive = nullptr; - GVolume* mVolume = nullptr; - -}; - -// tip dialog -class MessageBox : public BaseDialog -{ - Q_OBJECT - -public: - MessageBox(QString title, QString text, QMessageBox::StandardButtons bt, QWidget* parent = nullptr); - -Q_SIGNALS: - void format(); -}; -#endif // REPAIRDIALOGBOX_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/test-repair-dialog.cpp ukui-panel-4.0.0.0/ukui-flash-disk/test-repair-dialog.cpp --- ukui-panel-3.14.0.1/ukui-flash-disk/test-repair-dialog.cpp 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/test-repair-dialog.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -#include "repair-dialog-box.h" - -#include <QDebug> -#include <QApplication> -#include <QMessageBox> - - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - GDrive* test = nullptr; - RepairDialogBox box(test); - box.show(); - -// RepairProgressBar test(QObject::tr("正在进行磁盘修复...")); -// test.exec(); - -// FormateDialog test(nullptr); -// test.exec(); - - return app.exec(); -} diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/ui_mainwindow.h ukui-panel-4.0.0.0/ukui-flash-disk/ui_mainwindow.h --- ukui-panel-3.14.0.1/ukui-flash-disk/ui_mainwindow.h 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/ui_mainwindow.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ -/******************************************************************************** -** Form generated from reading UI file 'mainwindow.ui' -** -** Created by: Qt User Interface Compiler version 5.12.5 -** -** WARNING! All changes made in this file will be lost when recompiling UI file! -********************************************************************************/ - -#ifndef UI_MAINWINDOW_H -#define UI_MAINWINDOW_H - -#include <QtCore/QVariant> -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtWidgets/QWidget> -#include "fdframe.h" - -QT_BEGIN_NAMESPACE - -class Ui_MainWindow -{ -public: - FDFrame *centralWidget; - - void setupUi(QMainWindow *MainWindow) - { - if (MainWindow->objectName().isEmpty()) - MainWindow->setObjectName(QString::fromUtf8("MainWindow")); - MainWindow->resize(400, 300); - centralWidget = new FDFrame(MainWindow); - centralWidget->setObjectName(QString::fromUtf8("centralWidget")); - MainWindow->setCentralWidget(centralWidget); - - retranslateUi(MainWindow); - - QMetaObject::connectSlotsByName(MainWindow); - } // setupUi - - void retranslateUi(QMainWindow *MainWindow) - { - MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr)); - } // retranslateUi - -}; - -namespace Ui { - class MainWindow: public Ui_MainWindow {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // UI_MAINWINDOW_H diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/ukui-flash-disk.desktop ukui-panel-4.0.0.0/ukui-flash-disk/ukui-flash-disk.desktop --- ukui-panel-3.14.0.1/ukui-flash-disk/ukui-flash-disk.desktop 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/ukui-flash-disk.desktop 1970-01-01 08:00:00.000000000 +0800 @@ -1,10 +0,0 @@ -[Desktop Entry] -Name=ukui flash disk -comment=Ukui Flash Disk -Comment[zh_CN]=u盘管理工具 -Exec=ukui-flash-disk -Terminal=false -Type=Application -Icon=panel -X-UKUI-AutoRestart=true -OnlyShowIn=UKUI diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/ukui-flash-disk.qrc ukui-panel-4.0.0.0/ukui-flash-disk/ukui-flash-disk.qrc --- ukui-panel-3.14.0.1/ukui-flash-disk/ukui-flash-disk.qrc 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/ukui-flash-disk.qrc 1970-01-01 08:00:00.000000000 +0800 @@ -1,8 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>ukui-flash-disk.qss</file> - <file>picture/media-eject-symbolic.svg</file> - <file>picture/drive-removable-media.svg</file> - <file>picture/drive-removable-media-usb.png</file> - </qresource> -</RCC> diff -Nru ukui-panel-3.14.0.1/ukui-flash-disk/ukui-flash-disk.qss ukui-panel-4.0.0.0/ukui-flash-disk/ukui-flash-disk.qss --- ukui-panel-3.14.0.1/ukui-flash-disk/ukui-flash-disk.qss 2022-05-06 10:42:56.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-flash-disk/ukui-flash-disk.qss 1970-01-01 08:00:00.000000000 +0800 @@ -1,48 +0,0 @@ -QWidget#lineWidget{ -background-color: rgba(255,255,255,0.2); -width:276px; -height:1px; -} - -/* QLabel about */ - -QLabel#driveNameLabel{ -font-size:14px; -font-family:Noto Sans CJK SC; -font-weight:400; -color:rgba(255,255,255,1); -line-height:28px; -opacity:0.91; -} - -QLabel#capacityLabel{ -font-size:14px; -font-family:Microsoft YaHei; -font-weight:400; -color:rgba(255,255,255,0.35); -line-height:28px; -opacity:0.35; -} - - -/* QPushButton about */ -QPushButton#Button::pressed{ -background:rgba(255,0,0,1); -border-radius:4px; -width:38px; -height:38px; -} - -QPushButton#Button::hover{ -background:rgba(255,255,255,0.08); -border-radius:4px; -width:40px; -height:40px; -} - -QPushButton#Button{ -background:rgba(255,255,255,0); -border-radius:4px; -width:40px; -height:40px; -} diff -Nru ukui-panel-3.14.0.1/ukui-panel.md ukui-panel-4.0.0.0/ukui-panel.md --- ukui-panel-3.14.0.1/ukui-panel.md 2022-05-09 17:44:46.000000000 +0800 +++ ukui-panel-4.0.0.0/ukui-panel.md 2023-05-22 14:06:12.000000000 +0800 @@ -4,7 +4,7 @@ ## 任务栏介绍 -任务栏采用插件加载机制,主要包含startbar(开始菜单),taskbar(窗口切换区),statusnotifier(托盘区),calendar(日历),nightmode(夜间模式),showdesktop(显示桌面)这6个插件,下面依次介绍每个插件的功能: +任务栏采用插件加载机制,主要包含startbar(开始菜单),taskbar(窗口切换区),statusnotifier(托盘区),calendar(日历),showdesktop(显示桌面)这6个插件,下面依次介绍每个插件的功能: * startbar 此插件包含开始菜单按钮和显示任务试图按钮,当这两个按钮被左键点击时,任务栏会调用并执行开始菜单或多任务试图所对应的二进制文件,实现相应的功能。 在开始菜单按钮上右键可以看到任务栏提供的一些操作(1)用户操作,包括锁屏和注销;(2)休眠或睡眠,依据机器是否支持休眠操作决定休眠选项是否可选;(3)电源,包括重启,定时关机和关机操作。 @@ -18,8 +18,6 @@ 托盘区的功能是为应用创建一个快捷操作按钮,可以执行相关操作或显示应用状态。应用可通过SNI协议将图标注册到托盘区域。 * calendar 日历插件主要用于显示日历界面和时间,左键单击可以调出日历界面,右键单击可进入控制面板的时间和日期的设置界面。 -* nightmode - 夜间模式按钮是否展示对应着右键点击任务栏空白处出现的右键菜单中“显示夜间模式按钮”项是否勾选。 * showdesktop 显示桌面按钮的功能是在当前窗口和桌面之间进行切换。 @@ -55,7 +53,7 @@ hidable=false 【任务栏是否隐藏,false代表不隐藏,true代表隐藏】 lineCount=1 【任务栏单行显示】 lockPanel=false 【任务栏是否锁定,false代表不锁定,true代表锁定】 -plugins=startbar,taskbar,statusnotifier,calendar, nightmode,showdesktop 【任务栏所需要加载的插件,注:此字段从根目录下的配置文件中读取】 +plugins=startbar,taskbar,statusnotifier,calendar, showdesktop 【任务栏所需要加载的插件,注:此字段从根目录下的配置文件中读取】 position=Bottom 【任务栏的位置,Bottom代表下,Top代表上,Left代表左, Right代表右】 reserve-space=true show-delay=0 【延迟显示的时间】