|
5 | 5 | #include "subtoolwidget.h" |
6 | 6 | #include "../camera_process.h" |
7 | 7 | #include "../utils/configsettings.h" |
| 8 | +#include "../utils/saveutils.h" |
8 | 9 | #include "../settings.h" |
9 | 10 | #include "tooltips.h" |
10 | 11 | #include "../utils.h" |
@@ -718,13 +719,14 @@ void SubToolWidget::initShotLabel() |
718 | 719 | m_saveLocalDirButton = new SaveButton(); |
719 | 720 | m_saveLocalDirButton->setCheckable(false); |
720 | 721 | updateSaveButtonTip(); |
721 | | - m_saveLocalDirButton->installEventFilter(this); |
722 | 722 | // m_saveLocalDirButton->setIcon(QIcon::fromTheme("save")); |
723 | 723 | Utils::setAccessibility(m_saveLocalDirButton, AC_SUBTOOLWIDGET_SAVETOLOCAL_BUTTON); |
724 | 724 |
|
725 | 725 | // 创建并设置保存菜单管理器 |
726 | 726 | SaveMenuManager *saveMenuManager = new SaveMenuManager(this); |
727 | 727 | m_saveLocalDirButton->setOptionsMenu(saveMenuManager->getMenu()); |
| 728 | + // 连接保存选项改变信号,更新tooltip |
| 729 | + connect(saveMenuManager, &SaveMenuManager::saveOptionChanged, this, &SubToolWidget::updateSaveButtonTip); |
728 | 730 |
|
729 | 731 | m_shotBtnGroup->addButton(m_saveLocalDirButton); |
730 | 732 | // m_saveLocalDirButton->setFixedSize(TOOL_BUTTON_SIZE); |
@@ -833,63 +835,76 @@ void SubToolWidget::showAIAssistantWidget() |
833 | 835 | // 更新保存按钮的提示信息 |
834 | 836 | void SubToolWidget::updateSaveButtonTip() |
835 | 837 | { |
836 | | - // SaveWays t_saveWays = ConfigSettings::instance()->getValue("shot", "save_ways").value<SaveWays>(); |
837 | | - // QString tipText; |
838 | | - // if (t_saveWays == Ask) { |
839 | | - // tipText = tr("Save to local"); |
840 | | - // } else if (t_saveWays == SpecifyLocation) { |
841 | | - // // 获取当前保存设置 |
842 | | - // SaveAction saveAction = ConfigSettings::instance()->getValue("shot", "save_op").value<SaveAction>(); |
843 | | - |
844 | | - // switch (saveAction) { |
845 | | - // case SaveToDesktop: { |
846 | | - // tipText = tr("Save to Desktop"); |
847 | | - // break; |
848 | | - // } |
849 | | - // case SaveToImage: { |
850 | | - // tipText = tr("Save to Pictures"); |
851 | | - // break; |
852 | | - // } |
853 | | - // case SaveToSpecificDir: { |
854 | | - // bool changeIsChecked = m_changeSaveToSpecialPath && ((m_changeSaveToSpecialPath &&m_changeSaveToSpecialPath->isChecked()) || (m_scrollChangeSaveToSpecialPath && m_scrollChangeSaveToSpecialPath->isChecked())); |
855 | | - // qWarning() << "changeIsChecked:"<<changeIsChecked; |
856 | | - // QString specificPath = ConfigSettings::instance()->getValue("shot", "save_dir").toString(); |
857 | | - // bool specialPathExits = !specificPath.isEmpty() && QFileInfo::exists(specificPath); |
858 | | - // qWarning() << "specialPathExits:"<<specialPathExits; |
859 | | - // // 保存时更新 |
860 | | - // bool tipsUpdateSaved = specialPathExits && changeIsChecked; |
861 | | - // qWarning() << "tipsUpdateSaved:"<<tipsUpdateSaved; |
862 | | - // // 保存时设置(选中且目录为空不为空) |
863 | | - // bool tipsSetSaved = changeIsChecked; |
864 | | - // qWarning() << "tipsSetSaved:"<<tipsSetSaved; |
865 | | - // // 保存到目录 (目录不为空且存在) |
866 | | - // bool tipsSpecialSaved = m_saveToSpecialPathAction && m_saveToSpecialPathAction->isChecked() && specialPathExits; |
867 | | - // qWarning() << "tipsSpecialSaved:"<<tipsSpecialSaved; |
868 | | - |
869 | | - // if (tipsUpdateSaved) { |
870 | | - // tipText = tr("Change the path on save"); |
871 | | - // qWarning() << "tipsUpdateSaved"; |
872 | | - |
873 | | - // } |
874 | | - // else if(tipsSetSaved) { |
875 | | - // tipText = tr("Set a path on save"); |
876 | | - // qWarning() << "tipsSetSaved"; |
877 | | - // } else if(tipsSpecialSaved) { |
878 | | - // tipText = tr("Save to %1").arg(specificPath); |
879 | | - // qWarning() << "tipsSpecialSaved"; |
880 | | - // } else { |
881 | | - // tipText = tr("Save to local"); |
882 | | - // qWarning() << "not set saved"; |
883 | | - // } |
884 | | - // qWarning() << tipText; |
885 | | - // break; |
886 | | - // } |
887 | | - // default: |
888 | | - // tipText = tr("Save to local"); |
889 | | - // break; |
890 | | - // } |
891 | | - // } |
892 | | - // installTipHint(m_saveLocalDirButton, tipText); |
| 838 | + qCWarning(dsrApp) << "========== updateSaveButtonTip 开始 =========="; |
| 839 | + |
| 840 | + if (!m_saveLocalDirButton) { |
| 841 | + qCWarning(dsrApp) << "updateSaveButtonTip: m_saveLocalDirButton 为空,直接返回"; |
| 842 | + return; |
| 843 | + } |
| 844 | + |
| 845 | + // 参考saveAction函数的读取方式 |
| 846 | + SaveWays saveWays = ConfigSettings::instance()->getValue("shot", "save_ways").value<SaveWays>(); |
| 847 | + SaveAction saveOp = ConfigSettings::instance()->getValue("shot", "save_op").value<SaveAction>(); |
| 848 | + bool isChangeOnSave = ConfigSettings::instance()->getValue("shot", "save_dir_change").toBool(); |
| 849 | + QString savedPath = ConfigSettings::instance()->getValue("shot", "save_dir").toString(); |
| 850 | + const bool hasHistoryPath = !savedPath.isEmpty() && QFileInfo::exists(savedPath); |
| 851 | + |
| 852 | + qCWarning(dsrApp) << "updateSaveButtonTip: saveWays=" << static_cast<int>(saveWays) |
| 853 | + << "saveOp=" << static_cast<int>(saveOp) |
| 854 | + << "isChangeOnSave=" << isChangeOnSave |
| 855 | + << "savedPath=" << savedPath |
| 856 | + << "hasHistoryPath=" << hasHistoryPath; |
| 857 | + |
| 858 | + QString tipText; |
| 859 | + if (saveWays == Ask) { |
| 860 | + // 每次询问模式 |
| 861 | + tipText = tr("Save to local"); |
| 862 | + qCWarning(dsrApp) << "updateSaveButtonTip: 进入每次询问模式,tipText=" << tipText; |
| 863 | + } else if (saveWays == SpecifyLocation) { |
| 864 | + // 指定位置模式,根据save_op显示具体保存位置 |
| 865 | + qCWarning(dsrApp) << "updateSaveButtonTip: 进入指定位置模式,saveOp=" << static_cast<int>(saveOp); |
| 866 | + switch (saveOp) { |
| 867 | + case SaveToDesktop: |
| 868 | + tipText = tr("Save to Desktop"); |
| 869 | + qCWarning(dsrApp) << "updateSaveButtonTip: SaveToDesktop分支,tipText=" << tipText; |
| 870 | + break; |
| 871 | + case SaveToImage: |
| 872 | + tipText = tr("Save to Pictures"); |
| 873 | + qCWarning(dsrApp) << "updateSaveButtonTip: SaveToImage分支,tipText=" << tipText; |
| 874 | + break; |
| 875 | + case SaveToSpecificDir: |
| 876 | + qCWarning(dsrApp) << "updateSaveButtonTip: SaveToSpecificDir分支,isChangeOnSave=" << isChangeOnSave; |
| 877 | + if (isChangeOnSave) { |
| 878 | + // 保存时选择/更新位置 |
| 879 | + tipText = hasHistoryPath ? tr("Update the location when saving") |
| 880 | + : tr("Select a location when saving"); |
| 881 | + qCWarning(dsrApp) << "updateSaveButtonTip: isChangeOnSave=true,hasHistoryPath=" << hasHistoryPath |
| 882 | + << "tipText=" << tipText; |
| 883 | + } else { |
| 884 | + // 保存到指定路径 |
| 885 | + tipText = hasHistoryPath ? tr("Save to %1").arg(savedPath) |
| 886 | + : tr("Save to local"); |
| 887 | + qCWarning(dsrApp) << "updateSaveButtonTip: isChangeOnSave=false,hasHistoryPath=" << hasHistoryPath |
| 888 | + << "tipText=" << tipText; |
| 889 | + } |
| 890 | + break; |
| 891 | + default: |
| 892 | + // 其他情况(SaveToClipboard, AutoSave, CustomScreenSave等) |
| 893 | + tipText = tr("Save to local"); |
| 894 | + qCWarning(dsrApp) << "updateSaveButtonTip: default分支,saveOp=" << static_cast<int>(saveOp) |
| 895 | + << "tipText=" << tipText; |
| 896 | + break; |
| 897 | + } |
| 898 | + } else { |
| 899 | + // 其他情况,保持原来的方式 |
| 900 | + tipText = tr("Save to local"); |
| 901 | + qCWarning(dsrApp) << "updateSaveButtonTip: 其他情况分支,saveWays=" << static_cast<int>(saveWays) |
| 902 | + << "tipText=" << tipText; |
| 903 | + } |
| 904 | + |
| 905 | + qCWarning(dsrApp) << "updateSaveButtonTip: 最终tipText=" << tipText; |
| 906 | + installTipHint(m_saveLocalDirButton, tipText); |
| 907 | + qCWarning(dsrApp) << "========== updateSaveButtonTip 结束 =========="; |
893 | 908 | } |
894 | 909 |
|
895 | 910 | void SubToolWidget::initShotOption() |
@@ -1459,6 +1474,8 @@ void SubToolWidget::initScrollLabel() |
1459 | 1474 | // 创建并设置保存菜单管理器 |
1460 | 1475 | SaveMenuManager *scrollSaveMenuManager = new SaveMenuManager(this); |
1461 | 1476 | m_saveLocalDirButton->setOptionsMenu(scrollSaveMenuManager->getMenu()); |
| 1477 | + // 连接保存选项改变信号,更新tooltip |
| 1478 | + connect(scrollSaveMenuManager, &SaveMenuManager::saveOptionChanged, this, &SubToolWidget::updateSaveButtonTip); |
1462 | 1479 |
|
1463 | 1480 | m_shotBtnGroup->addButton(m_saveLocalDirButton); |
1464 | 1481 | // m_saveLocalDirButton->setFixedSize(TOOL_BUTTON_SIZE); |
@@ -1913,34 +1930,6 @@ QPoint SubToolWidget::getAiButtonGlobalCenter() const |
1913 | 1930 | // 屏蔽DMenu,触发QAction Trigger时,收回菜单 |
1914 | 1931 | bool SubToolWidget::eventFilter(QObject *watched, QEvent *event) |
1915 | 1932 | { |
1916 | | - // 为保存按钮提供动态 ToolTip 文案 |
1917 | | - if (watched == m_saveLocalDirButton) { |
1918 | | - if (event->type() == QEvent::ToolTip) { |
1919 | | - int saveWays = ConfigSettings::instance()->getValue("shot", "save_ways").toInt(); // 0: Ask, 1: Specify |
1920 | | - bool isChangeOnSave = ConfigSettings::instance()->getValue("shot", "save_dir_change").toBool(); |
1921 | | - QString savedPath = ConfigSettings::instance()->getValue("shot", "save_dir").toString(); |
1922 | | - const bool hasHistoryPath = !savedPath.isEmpty() && QFileInfo::exists(savedPath); |
1923 | | - |
1924 | | - QString tipText; |
1925 | | - if (saveWays == 0) { |
1926 | | - tipText = tr("Save to local"); |
1927 | | - } else { |
1928 | | - if (isChangeOnSave) { |
1929 | | - tipText = hasHistoryPath ? tr("Update the location when saving") |
1930 | | - : tr("Select a location when saving"); |
1931 | | - } else { |
1932 | | - // 菜单选中具体的自定义路径 → 显示"保存到[路径]" |
1933 | | - tipText = hasHistoryPath ? tr("Save to %1").arg(savedPath) |
1934 | | - : tr("Save to local"); |
1935 | | - } |
1936 | | - } |
1937 | | - |
1938 | | - if (m_saveLocalDirButton) |
1939 | | - installTipHint(m_saveLocalDirButton, tipText); |
1940 | | - |
1941 | | - return true; |
1942 | | - } |
1943 | | - } |
1944 | 1933 |
|
1945 | 1934 |
|
1946 | 1935 | if (watched == m_recordOptionMenu || watched == m_optionMenu || watched == m_scrollOptionMenu || watched == m_saveToSpecialPathMenu || watched == m_scrollSaveToSpecialPathMenu) { |
|
0 commit comments