From 632ef771f310b0cb207d3bf8e5274757f32025e2 Mon Sep 17 00:00:00 2001 From: wingsummer <1326224942@qq.com> Date: Wed, 28 Sep 2022 10:00:54 +0800 Subject: [PATCH] update --- WingTool.pro | 8 +- class/appmanager.cpp | 14 ++-- class/appmanager.h | 20 ++--- class/hotkey.cpp | 7 ++ class/hotkey.h | 17 +++++ class/settingmanager.cpp | 15 +++- class/settingmanager.h | 8 ++ control/pluginselector.cpp | 10 +++ control/pluginselector.h | 2 + dialog/centerwindow.cpp | 139 ++++++++++++++++++++++++---------- dialog/centerwindow.h | 16 +++- dialog/shortcuteditdialog.cpp | 25 +++--- dialog/shortcuteditdialog.h | 7 +- dialog/toolboxwindow.cpp | 5 +- dialog/toolboxwindow.h | 16 +++- dialog/tooleditdialog.cpp | 106 ++++++++++++++++++++++++++ dialog/tooleditdialog.h | 44 +++++++++++ images/add.svg | 1 + images/clear.svg | 1 + images/del.svg | 1 + images/down.svg | 1 + images/edit.svg | 1 + images/up.svg | 1 + main.cpp | 19 ++++- plugin/iwingtoolplg.h | 3 +- plugin/pluginsystem.cpp | 33 ++++++-- plugin/pluginsystem.h | 4 +- resources.qrc | 6 ++ utilities.h | 25 ++++-- 29 files changed, 451 insertions(+), 104 deletions(-) create mode 100644 class/hotkey.cpp create mode 100644 class/hotkey.h create mode 100644 dialog/tooleditdialog.cpp create mode 100644 dialog/tooleditdialog.h create mode 100644 images/add.svg create mode 100644 images/clear.svg create mode 100644 images/del.svg create mode 100644 images/down.svg create mode 100644 images/edit.svg create mode 100644 images/up.svg diff --git a/WingTool.pro b/WingTool.pro index 5e26a82..a209efc 100644 --- a/WingTool.pro +++ b/WingTool.pro @@ -23,7 +23,9 @@ SOURCES += \ class/settingmanager.cpp \ dialog/shortcuteditdialog.cpp \ control/pluginselector.cpp \ - dialog/pluginseldialog.cpp + dialog/pluginseldialog.cpp \ + dialog/tooleditdialog.cpp \ + class/hotkey.cpp RESOURCES += resources.qrc HEADERS += \ @@ -42,4 +44,6 @@ HEADERS += \ dialog/shortcuteditdialog.h \ control/pluginselector.h \ dialog/pluginseldialog.h \ - utilities.h + utilities.h \ + dialog/tooleditdialog.h \ + class/hotkey.h diff --git a/class/appmanager.cpp b/class/appmanager.cpp index 4ef3a25..3333aec 100644 --- a/class/appmanager.cpp +++ b/class/appmanager.cpp @@ -55,11 +55,11 @@ AppManager::~AppManager() { clearHotkey(); } AppManager *AppManager::instance() { return m_instance; } -QHotkey *AppManager::registerHotkey(QKeySequence &keyseq) { +Hotkey *AppManager::registerHotkey(QKeySequence &keyseq, bool isHostHotkey) { if (registeredSeq.contains(keyseq)) return nullptr; - auto hotkey = new QHotkey(keyseq, true); - hotkeys += hotkey; + auto hotkey = new Hotkey(isHostHotkey, keyseq, true); + hotkeys.append(hotkey); connect(hotkey, &QHotkey::activated, this, [=] { emit this->hotkeyTirggered(hotkey); }); connect(hotkey, &QHotkey::released, this, @@ -77,13 +77,13 @@ bool AppManager::enableHotKey(int index, bool enabled) { return hotkeys[index]->setRegistered(enabled); } -bool AppManager::enableHotKey(QHotkey *hotkey, bool enabled) { +bool AppManager::enableHotKey(Hotkey *hotkey, bool enabled) { if (hotkey == nullptr) return false; return hotkey->setRegistered(enabled); } -bool AppManager::unregisterHotkey(QHotkey *hotkey) { +bool AppManager::unregisterHotkey(Hotkey *hotkey) { auto i = hotkeys.indexOf(hotkey); if (i < 0) return false; @@ -118,7 +118,7 @@ bool AppManager::editHotkey(int index, QKeySequence &keyseq) { return true; } -bool AppManager::editHotkey(QHotkey *hotkey, QKeySequence &keyseq) { +bool AppManager::editHotkey(Hotkey *hotkey, QKeySequence &keyseq) { if (hotkey == nullptr) return false; auto i = registeredSeq.indexOf(hotkey->shortcut()); @@ -129,7 +129,7 @@ bool AppManager::editHotkey(QHotkey *hotkey, QKeySequence &keyseq) { return true; } -QHotkey *AppManager::hotkey(int index) { +Hotkey *AppManager::hotkey(int index) { if (index < 0 || index >= hotkeys.count()) return nullptr; return hotkeys[index]; diff --git a/class/appmanager.h b/class/appmanager.h index 2a6b849..9754233 100644 --- a/class/appmanager.h +++ b/class/appmanager.h @@ -1,8 +1,8 @@ #ifndef APPMANAGER_H #define APPMANAGER_H -#include "QHotkey/qhotkey.h" #include "class/eventmonitor.h" +#include "class/hotkey.h" #include "dialog/toolwindow.h" #undef Bool #undef Unsorted @@ -19,14 +19,14 @@ public: static AppManager *instance(); public: - QHotkey *registerHotkey(QKeySequence &keyseq); + Hotkey *registerHotkey(QKeySequence &keyseq, bool isHostHotkey); bool enableHotKey(int index, bool enabled = true); - bool enableHotKey(QHotkey *hotkey, bool enabled = true); - bool unregisterHotkey(QHotkey *hotkey); + bool enableHotKey(Hotkey *hotkey, bool enabled = true); + bool unregisterHotkey(Hotkey *hotkey); bool unregisterHotkey(int index); bool editHotkey(int index, QKeySequence &keyseq); - bool editHotkey(QHotkey *hotkey, QKeySequence &keyseq); - QHotkey *hotkey(int index); + bool editHotkey(Hotkey *hotkey, QKeySequence &keyseq); + Hotkey *hotkey(int index); void clearHotkey(); signals: @@ -38,15 +38,15 @@ signals: void mouseMove(int x, int y); void mouseDrag(int x, int y); - void hotkeyTirggered(const QHotkey *hotkey); - void hotkeyReleased(const QHotkey *hotkey); - void hotkeyEnableChanged(bool value, const QHotkey *hotkey); + void hotkeyTirggered(const Hotkey *hotkey); + void hotkeyReleased(const Hotkey *hotkey); + void hotkeyEnableChanged(bool value, const Hotkey *hotkey); void selectionTextChanged(const QString &selectedText); private: EventMonitor monitor; - QList hotkeys; + QList hotkeys; QStringList execs; bool ignoremsg = false; diff --git a/class/hotkey.cpp b/class/hotkey.cpp new file mode 100644 index 0000000..c41347d --- /dev/null +++ b/class/hotkey.cpp @@ -0,0 +1,7 @@ +#include "hotkey.h" + +Hotkey::Hotkey(bool isHostHotkey, const QKeySequence &shortcut, + bool autoRegister, QObject *parent) + : QHotkey(shortcut, autoRegister, parent), m_isHostHotkey(isHostHotkey) {} + +bool Hotkey::isHostHotkey() const { return m_isHostHotkey; } diff --git a/class/hotkey.h b/class/hotkey.h new file mode 100644 index 0000000..c3c528d --- /dev/null +++ b/class/hotkey.h @@ -0,0 +1,17 @@ +#ifndef HOTKEY_H +#define HOTKEY_H + +#include "QHotkey/qhotkey.h" + +class Hotkey : public QHotkey { +public: + Hotkey(bool isHostHotkey, const QKeySequence &shortcut, + bool autoRegister = false, QObject *parent = nullptr); + + bool isHostHotkey() const; + +private: + bool m_isHostHotkey; +}; + +#endif // HOTKEY_H diff --git a/class/settingmanager.cpp b/class/settingmanager.cpp index 479fc32..b96a140 100644 --- a/class/settingmanager.cpp +++ b/class/settingmanager.cpp @@ -1,6 +1,5 @@ #include "settingmanager.h" #include -#include #include #include @@ -12,7 +11,19 @@ SettingManager::SettingManager(QObject *parent) : QObject(parent) { SettingManager *SettingManager::instance() { return m_instance; } -bool SettingManager::loadSettings() { return true; } +bool SettingManager::loadSettings() { + QString strConfigPath = + QString("%1/%2/%3/config.conf") + .arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)) + .arg(qApp->organizationName()) + .arg(qApp->applicationName()); + + QFile f(strConfigPath); + if (f.open(QFile::ReadOnly)) { + emit this->loadingFinish(); + } + return true; +} bool SettingManager::saveSettings() { QString strConfigPath = diff --git a/class/settingmanager.h b/class/settingmanager.h index 22ed570..a330417 100644 --- a/class/settingmanager.h +++ b/class/settingmanager.h @@ -1,6 +1,8 @@ #ifndef SETTINGMANAGER_H #define SETTINGMANAGER_H +#include "QHotkey/qhotkey.h" +#include "utilities.h" #include #define TOOLGRIDSIZE 40 @@ -25,6 +27,12 @@ public: signals: void sigToolGridSizeChanged(int v); + void getHokeysBuffer(QList &hotkeysBuf, + QMap &buffer); + void getToolLeftBuffer(ToolStructInfo buffer[]); + void getToolRightBuffer(QList &buffer); + void loadingFinish(); + private: static SettingManager *m_instance; diff --git a/control/pluginselector.cpp b/control/pluginselector.cpp index ef973bc..5d6635f 100644 --- a/control/pluginselector.cpp +++ b/control/pluginselector.cpp @@ -33,3 +33,13 @@ int PluginSelector::getSelectedIndex() { return selplgindex; } IWingToolPlg *PluginSelector::getSelectedPlg() { return plgsys->plugin(selplgindex); } + +bool PluginSelector::setSelectedIndex(int index) { + if (index < 0 || index >= plgsys->pluginCounts()) + return false; + selplgindex = index; + auto plg = plgsys->plugin(index); + setIcon(Utilities::processPluginIcon(plg)); + setText(plg->pluginName()); + return true; +} diff --git a/control/pluginselector.h b/control/pluginselector.h index 408f896..d53beea 100644 --- a/control/pluginselector.h +++ b/control/pluginselector.h @@ -19,6 +19,8 @@ public: int getSelectedIndex(); IWingToolPlg *getSelectedPlg(); + bool setSelectedIndex(int index); + signals: void finished(); diff --git a/dialog/centerwindow.cpp b/dialog/centerwindow.cpp index b6d2f1f..f18ca12 100644 --- a/dialog/centerwindow.cpp +++ b/dialog/centerwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -17,9 +18,7 @@ #include #include -CenterWindow::CenterWindow(DMainWindow *parent) - : DMainWindow(parent), manager(AppManager::instance()), - sm(SettingManager::instance()), plgsys(PluginSystem::instance()) { +CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { QIcon picon = ProgramIcon; setWindowTitle(tr("CenterWindow")); setMinimumSize(700, 500); @@ -133,11 +132,13 @@ CenterWindow::CenterWindow(DMainWindow *parent) auto tlayout = new QHBoxLayout(w); auto tvlayout = new QVBoxLayout; - auto gridsize = sm->toolGridSize(); + auto gridsize = 40; // 默认 40 先 auto gw = new QWidget(w); gw->setFixedSize(gridsize * 3, gridsize * 3); auto mlayout = new QGridLayout(gw); mlayout->setMargin(1); + auto btngs = new QButtonGroup(w); + btngs->setExclusive(true); // 设置按钮选中互斥 for (int i = 0; i < 9; i++) { auto lbl = new DIconButton(this); @@ -147,11 +148,15 @@ CenterWindow::CenterWindow(DMainWindow *parent) auto in = std::div(i, 3); mlayout->addWidget(lbl, in.quot, in.rem, Qt::AlignCenter); lbls[i] = lbl; + btngs->addButton(lbl); connect(lbl, &DIconButton::clicked, this, [=] { }); } - lbls[4]->setIcon(ICONRES("close")); + lbls[0]->setChecked(true); + auto lbl4 = lbls[4]; + lbl4->setIcon(ICONRES("close")); + lbl4->setCheckable(false); tvlayout->addWidget(gw, 0, Qt::AlignCenter); tbtoolinfo = new DTextBrowser(w); @@ -176,28 +181,63 @@ CenterWindow::CenterWindow(DMainWindow *parent) group = new DButtonBox(this); // 再来征用一次 blist.clear(); - b = new DButtonBoxButton(tr("Add"), this); + b = new DButtonBoxButton(ICONRES2("add")); + b->setIconSize(QSize(20, 20)); + b->setParent(this); + b->setToolTip(tr("Add")); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_addToolWin); blist.append(b); - b = new DButtonBoxButton(tr("Remove"), this); + b = new DButtonBoxButton(ICONRES2("del")); + b->setIconSize(QSize(20, 20)); + b->setParent(this); + b->setToolTip(tr("Remove")); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_removeToolWin); blist.append(b); - b = new DButtonBoxButton(tr("Edit"), this); + b = new DButtonBoxButton(ICONRES2("edit")); + b->setIconSize(QSize(20, 20)); + b->setParent(this); + b->setToolTip(tr("Edit")); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_editToolWin); blist.append(b); - b = new DButtonBoxButton(tr("Up"), this); + b = new DButtonBoxButton(ICONRES2("up")); + b->setIconSize(QSize(20, 20)); + b->setParent(this); + b->setToolTip(tr("Up")); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_upToolWin); blist.append(b); - b = new DButtonBoxButton(tr("Down"), this); + b = new DButtonBoxButton(ICONRES2("down")); + b->setIconSize(QSize(20, 20)); + b->setParent(this); + b->setToolTip(tr("Down")); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_downToolWin); blist.append(b); - b = new DButtonBoxButton(tr("Clear"), this); + b = new DButtonBoxButton(ICONRES2("clear")); + b->setIconSize(QSize(20, 20)); + b->setParent(this); + b->setToolTip(tr("Clear")); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_clearToolWin); blist.append(b); group->setButtonList(blist, false); tvlayout->addWidget(group); lstoolwin = new DListWidget(w); + menu = new DMenu(lstoolwin); + AddMenuAction(tr("Add"), &CenterWindow::on_addToolWin); + AddMenuAction(tr("Edit"), &CenterWindow::on_editToolWin); + AddMenuAction(tr("Remove"), &CenterWindow::on_removeToolWin); + AddMenuAction(tr("Clear"), &CenterWindow::on_clearToolWin); + menu->addSeparator(); + AddMenuAction(tr("Up"), &CenterWindow::on_upToolWin); + AddMenuAction(tr("Down"), &CenterWindow::on_downToolWin); + AddMenuAction(tr("TopMost"), [=] { + + }); + AddMenuAction(tr("DownMost"), [=] { + + }); + lstoolwin->setContextMenuPolicy(Qt::CustomContextMenu); + connect(lstoolwin, &DListWidget::customContextMenuRequested, this, + [=] { menu->popup(QCursor::pos()); }); tvlayout->addWidget(lstoolwin); tlayout->addLayout(tvlayout); @@ -208,10 +248,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) auto playout = new QHBoxLayout(w); lwplgs = new DListWidget(w); playout->addWidget(lwplgs); - for (auto item : PluginSystem::instance()->plugins()) { - lwplgs->addItem(new QListWidgetItem(Utilities::processPluginIcon(item), - item->pluginName())); - } tbplginfo = new DTextBrowser(w); tbplginfo->setUndoRedoEnabled(false); @@ -277,27 +313,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) l->setScaledContents(true); slayout->addWidget(l); tabs->addTab(w, tr("Sponsor")); - - //初始化热键事件处理函数 - QObject::connect(manager, &AppManager::hotkeyTirggered, this, - [=](const QHotkey *hotkey) { - if (hotkeys.contains(const_cast(hotkey))) { - auto &task = scinfos[const_cast(hotkey)]; - this->runTask(task); - } - }); - QObject::connect(manager, &AppManager::hotkeyReleased, this, - [=](const QHotkey *) { - - }); - QObject::connect( - manager, &AppManager::hotkeyEnableChanged, this, - [=](bool value, const QHotkey *hotkey) { - if (hotkeys.contains(const_cast(hotkey))) { - tbhotkeys->item(hotkeys.indexOf(const_cast(hotkey)), 0) - ->setCheckState(value ? Qt::Checked : Qt::Unchecked); - } - }); } void CenterWindow::show(CenterWindow::TabPage index) { @@ -325,7 +340,7 @@ QStringList CenterWindow::parseCmdParams(QString str) { return args; } -bool CenterWindow::runTask(ShortCutEditRes record) { +bool CenterWindow::runTask(ToolStructInfo record) { if (record.isPlugin) { auto params = parseCmdParams(record.params); @@ -362,7 +377,7 @@ void CenterWindow::editTask(int index) { if (index < 0 || index >= scinfos.count()) return; auto &task = scinfos[hotkeys[index]]; - ShortCutEditDialog d(task.enabled, task.seq, task.process, task.params); + ShortCutEditDialog d(task); if (d.exec()) { auto res = d.getResult(); auto wt = new QTableWidgetItem; @@ -420,7 +435,7 @@ void CenterWindow::on_addHotkey() { ShortCutEditDialog d; if (d.exec()) { auto res = d.getResult(); - auto hk = manager->registerHotkey(res.seq); + auto hk = manager->registerHotkey(res.seq, true); if (hk == nullptr) { DMessageManager::instance()->sendMessage(this, ProgramIcon, tr("HotkeyRegisterFail")); @@ -463,6 +478,52 @@ void CenterWindow::on_upToolWin() {} void CenterWindow::on_downToolWin() {} +void CenterWindow::getHokeysBuffer(QList &hotkeysBuf, + QMap &buffer) {} + +void CenterWindow::getToolLeftBuffer(ToolStructInfo buffer[]) {} + +void CenterWindow::getToolRightBuffer(QList &buffer) {} + +void CenterWindow::loadingFinish() { + sm = SettingManager::instance(); + auto gridsize = sm->toolGridSize(); + for (auto i = 0; i < 9; i++) { + lbls[i]->setFixedSize(QSize(gridsize, gridsize)); + } +} + +void CenterWindow::initPluginSys() { + plgsys = PluginSystem::instance(); + for (auto item : PluginSystem::instance()->plugins()) { + lwplgs->addItem(new QListWidgetItem(Utilities::processPluginIcon(item), + item->pluginName())); + } +} + +void CenterWindow::initAppManger() { + manager = AppManager::instance(); + + //初始化热键事件处理函数 + connect(manager, &AppManager::hotkeyTirggered, this, + [=](const Hotkey *hotkey) { + if (hotkey->isHostHotkey()) { + auto &task = scinfos[const_cast(hotkey)]; + this->runTask(task); + } + }); + connect(manager, &AppManager::hotkeyReleased, this, [=](const Hotkey *) { + + }); + connect(manager, &AppManager::hotkeyEnableChanged, this, + [=](bool value, const Hotkey *hotkey) { + if (hotkey->isHostHotkey()) { + tbhotkeys->item(hotkeys.indexOf(const_cast(hotkey)), 0) + ->setCheckState(value ? Qt::Checked : Qt::Unchecked); + } + }); +} + void CenterWindow::closeEvent(QCloseEvent *event) { event->ignore(); hide(); diff --git a/dialog/centerwindow.h b/dialog/centerwindow.h index 29adc2d..ade02aa 100644 --- a/dialog/centerwindow.h +++ b/dialog/centerwindow.h @@ -39,7 +39,7 @@ public: private: QStringList parseCmdParams(QString str); - bool runTask(ShortCutEditRes record); + bool runTask(ToolStructInfo record); void editTask(int index); void on_editHotkey(); @@ -55,6 +55,16 @@ private: void on_upToolWin(); void on_downToolWin(); +public slots: + void getHokeysBuffer(QList &hotkeysBuf, + QMap &buffer); + void getToolLeftBuffer(ToolStructInfo buffer[]); + void getToolRightBuffer(QList &buffer); + void loadingFinish(); + + void initPluginSys(); + void initAppManger(); + protected: void closeEvent(QCloseEvent *event) override; @@ -81,7 +91,9 @@ private: DIconButton *lbls[9] = {nullptr}; private: - QMap scinfos; + QMap scinfos; // 用于 Hotkeys + ToolStructInfo toolinfos[9]; // 用于 Tool 左侧 + QList wintoolinfos; // 用于 WinTool( Tool 右侧 ) QList hotkeys; }; diff --git a/dialog/shortcuteditdialog.cpp b/dialog/shortcuteditdialog.cpp index 9e84c49..14a5bbe 100644 --- a/dialog/shortcuteditdialog.cpp +++ b/dialog/shortcuteditdialog.cpp @@ -4,9 +4,7 @@ #include #include -ShortCutEditDialog::ShortCutEditDialog(bool enabled, QKeySequence seq, - QString process, QString params, - DMainWindow *parent) +ShortCutEditDialog::ShortCutEditDialog(ToolStructInfo res, DMainWindow *parent) : DDialog(parent), manager(AppManager::instance()) { // 处于编辑状态直接堵塞所有相应(屏蔽鼠标追踪和热键触发以防干扰) @@ -15,14 +13,14 @@ ShortCutEditDialog::ShortCutEditDialog(bool enabled, QKeySequence seq, setWindowTitle(tr("HotkeyEdit")); cb = new DCheckBox(tr("Enabled"), this); - cb->setChecked(enabled); + cb->setChecked(res.enabled); addContent(cb); addSpacing(10); addContent(new DLabel(tr("ShortCut"), this)); addSpacing(5); ksedit = new DKeySequenceEdit(this); - ksedit->setKeySequence(seq); + ksedit->setKeySequence(res.seq); addContent(ksedit); addSpacing(10); @@ -43,19 +41,25 @@ ShortCutEditDialog::ShortCutEditDialog(bool enabled, QKeySequence seq, cbService->setVisible(false); } }); + ps->setSelectedIndex(res.pluginIndex); addContent(ps); addSpacing(10); - lblp = new DLabel(tr("FilePath"), this); + lblp = new DLabel(res.isPlugin ? tr("Service") : tr("FilePath"), this); addContent(lblp); addSpacing(5); fcedit = new DFileChooserEdit(this); fcedit->initDialog(); - fcedit->setText(process); + fcedit->setText(res.process); + fcedit->setVisible(!res.isPlugin); addContent(fcedit); cbService = new DComboBox(this); - cbService->setVisible(false); + if (res.isPlugin) { + cbService->addItems(ps->getSelectedPlg()->pluginServices()); + cbService->setCurrentIndex(res.serviceID); + } + cbService->setVisible(res.isPlugin); addContent(cbService); addSpacing(10); @@ -63,7 +67,7 @@ ShortCutEditDialog::ShortCutEditDialog(bool enabled, QKeySequence seq, addContent(new DLabel(tr("Param"), this)); addSpacing(5); dledit = new DLineEdit(this); - dledit->setText(params); + dledit->setText(res.params); addContent(dledit); addSpacing(20); @@ -79,7 +83,7 @@ ShortCutEditDialog::ShortCutEditDialog(bool enabled, QKeySequence seq, addContent(dbbox); } -ShortCutEditRes ShortCutEditDialog::getResult() { return res; } +ToolStructInfo ShortCutEditDialog::getResult() { return res; } void ShortCutEditDialog::on_accept() { res.enabled = cb->isChecked(); @@ -98,6 +102,7 @@ void ShortCutEditDialog::on_accept() { res.process = sel->pluginName(); res.serviceID = cbService->currentIndex(); res.provider = sel->provider(); + res.pluginIndex = ps->getSelectedIndex(); } else { if (res.process.isEmpty()) { DMessageManager::instance()->sendMessage(this, ProgramIcon, diff --git a/dialog/shortcuteditdialog.h b/dialog/shortcuteditdialog.h index 2463ec4..24a52e6 100644 --- a/dialog/shortcuteditdialog.h +++ b/dialog/shortcuteditdialog.h @@ -19,10 +19,9 @@ DWIDGET_USE_NAMESPACE class ShortCutEditDialog : public DDialog { Q_OBJECT public: - ShortCutEditDialog(bool enabled = true, QKeySequence seq = QKeySequence(), - QString process = QString(), QString params = QString(), + ShortCutEditDialog(ToolStructInfo res = ToolStructInfo(), DMainWindow *parent = nullptr); - ShortCutEditRes getResult(); + ToolStructInfo getResult(); private: void on_accept(); @@ -33,7 +32,7 @@ protected: private: AppManager *manager; - ShortCutEditRes res; + ToolStructInfo res; PluginSelector *ps; DCheckBox *cb; diff --git a/dialog/toolboxwindow.cpp b/dialog/toolboxwindow.cpp index 46dae4c..ab92800 100644 --- a/dialog/toolboxwindow.cpp +++ b/dialog/toolboxwindow.cpp @@ -1,6 +1,3 @@ #include "toolboxwindow.h" -ToolBoxWindow::ToolBoxWindow() -{ - -} +ToolBoxWindow::ToolBoxWindow(DMainWindow *parent) : DDialog(parent) {} diff --git a/dialog/toolboxwindow.h b/dialog/toolboxwindow.h index 0ff61fb..7538799 100644 --- a/dialog/toolboxwindow.h +++ b/dialog/toolboxwindow.h @@ -1,11 +1,19 @@ #ifndef TOOLBOXWINDOW_H #define TOOLBOXWINDOW_H +#include +#include +#include -class ToolBoxWindow -{ +DWIDGET_USE_NAMESPACE + +class ToolBoxWindow : public DDialog { + Q_OBJECT public: - ToolBoxWindow(); + ToolBoxWindow(DMainWindow *parent = nullptr); + +private: + DListWidget *lstool; }; -#endif // TOOLBOXWINDOW_H \ No newline at end of file +#endif // TOOLBOXWINDOW_H diff --git a/dialog/tooleditdialog.cpp b/dialog/tooleditdialog.cpp new file mode 100644 index 0000000..38ee2d0 --- /dev/null +++ b/dialog/tooleditdialog.cpp @@ -0,0 +1,106 @@ +#include "tooleditdialog.h" +#include +#include +#include + +ToolEditDialog::ToolEditDialog(ToolStructInfo res, DMainWindow *parent) + : DDialog(parent) { + + // 处于编辑状态直接堵塞所有相应(屏蔽鼠标追踪和热键触发以防干扰) + manager->blockSignals(true); + + setWindowTitle(tr("ToolWinEdit")); + + addContent(new DLabel(tr("Plugin"), this)); + addSpacing(5); + ps = new PluginSelector(this); + connect(ps, &PluginSelector::finished, this, [=] { + auto plg = ps->getSelectedPlg(); + if (plg) { + lblp->setText(tr("Service")); + fcedit->setVisible(false); + cbService->clear(); + cbService->addItems(plg->pluginServices()); + cbService->setVisible(true); + } else { + lblp->setText(tr("FilePath")); + fcedit->setVisible(true); + cbService->setVisible(false); + } + }); + ps->setSelectedIndex(res.pluginIndex); + addContent(ps); + addSpacing(10); + + lblp = new DLabel(res.isPlugin ? tr("Service") : tr("FilePath"), this); + addContent(lblp); + addSpacing(5); + fcedit = new DFileChooserEdit(this); + fcedit->initDialog(); + fcedit->setText(res.process); + fcedit->setVisible(!res.isPlugin); + addContent(fcedit); + + cbService = new DComboBox(this); + if (res.isPlugin) { + cbService->addItems(ps->getSelectedPlg()->pluginServices()); + cbService->setCurrentIndex(res.serviceID); + } + cbService->setVisible(res.isPlugin); + addContent(cbService); + + addSpacing(10); + + addContent(new DLabel(tr("Param"), this)); + addSpacing(5); + dledit = new DLineEdit(this); + dledit->setText(res.params); + addContent(dledit); + + addSpacing(20); + auto dbbox = new DDialogButtonBox( + DDialogButtonBox::Ok | DDialogButtonBox::Cancel, this); + connect(dbbox, &DDialogButtonBox::accepted, this, &ToolEditDialog::on_accept); + connect(dbbox, &DDialogButtonBox::rejected, this, &ToolEditDialog::on_reject); + auto key = QKeySequence(Qt::Key_Return); + auto s = new QShortcut(key, this); + connect(s, &QShortcut::activated, this, &ToolEditDialog::on_accept); + addContent(dbbox); +} + +ToolStructInfo ToolEditDialog::getResult() { return res; } + +void ToolEditDialog::on_accept() { + res.isPlugin = ps->getSelectedIndex() >= 0; + + if (res.isPlugin) { + auto sel = ps->getSelectedPlg(); + res.process = sel->pluginName(); + res.serviceID = cbService->currentIndex(); + res.provider = sel->provider(); + res.pluginIndex = ps->getSelectedIndex(); + } else { + if (res.process.isEmpty()) { + DMessageManager::instance()->sendMessage(this, ProgramIcon, + tr("NoProcessSet")); + return; + } + res.process = fcedit->text(); + } + + res.params = dledit->text(); + + manager->blockSignals(false); // 恢复能力 + done(1); +} + +void ToolEditDialog::on_reject() { + manager->blockSignals(false); // 恢复能力 + done(0); +} + +void ToolEditDialog::closeEvent(QCloseEvent *event) { + Q_UNUSED(event); + manager->blockSignals(false); // 恢复能力 + done(0); +} diff --git a/dialog/tooleditdialog.h b/dialog/tooleditdialog.h new file mode 100644 index 0000000..84a92da --- /dev/null +++ b/dialog/tooleditdialog.h @@ -0,0 +1,44 @@ +#ifndef TOOLWINEDITDIALOG_H +#define TOOLWINEDITDIALOG_H + +#include "utilities.h" + +#include "class/appmanager.h" +#include "control/pluginselector.h" +#include +#include +#include +#include +#include +#include +#include +#include + +DWIDGET_USE_NAMESPACE + +class ToolEditDialog : public DDialog { +public: + ToolEditDialog(ToolStructInfo res = ToolStructInfo(), + DMainWindow *parent = nullptr); + ToolStructInfo getResult(); // 这里的 enabled 和 seq 保留不使用 + +private: + void on_accept(); + void on_reject(); + +protected: + void closeEvent(QCloseEvent *event) override; + +private: + AppManager *manager; + ToolStructInfo res; + + PluginSelector *ps; + DFileChooserEdit *fcedit; + DLineEdit *dledit; + + DLabel *lblp; + DComboBox *cbService; +}; + +#endif // TOOLWINEDITDIALOG_H diff --git a/images/add.svg b/images/add.svg new file mode 100644 index 0000000..0db917f --- /dev/null +++ b/images/add.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/clear.svg b/images/clear.svg new file mode 100644 index 0000000..aa324d6 --- /dev/null +++ b/images/clear.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/del.svg b/images/del.svg new file mode 100644 index 0000000..4c1bfa2 --- /dev/null +++ b/images/del.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/down.svg b/images/down.svg new file mode 100644 index 0000000..d53740c --- /dev/null +++ b/images/down.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/edit.svg b/images/edit.svg new file mode 100644 index 0000000..622bfd6 --- /dev/null +++ b/images/edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/up.svg b/images/up.svg new file mode 100644 index 0000000..1430104 --- /dev/null +++ b/images/up.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7d04050..a268133 100644 --- a/main.cpp +++ b/main.cpp @@ -74,22 +74,35 @@ int main(int argc, char *argv[]) { DApplicationSettings as; Q_UNUSED(as) + CenterWindow w; + /*== 以下在主函数初始化确保单例 ==*/ - /* 之后不得使用构造函数的方式调用类 */ + /* 之后不得使用构造函数的方式使用 */ // 初始化软件配置 SettingManager sm; + QObject::connect(&sm, &SettingManager::getHokeysBuffer, &w, + &CenterWindow::getHokeysBuffer); + QObject::connect(&sm, &SettingManager::getToolLeftBuffer, &w, + &CenterWindow::getToolLeftBuffer); + QObject::connect(&sm, &SettingManager::getToolRightBuffer, &w, + &CenterWindow::getToolRightBuffer); + QObject::connect(&sm, &SettingManager::loadingFinish, &w, + &CenterWindow::loadingFinish); + + sm.loadSettings(); + // 初始化程序基础驱动 AppManager manager; + w.initAppManger(); // 初始化插件系统 PluginSystem plgsys; + w.initPluginSys(); /*===========================*/ - CenterWindow w; - // 初始化托盘 QSystemTrayIcon systray; QMenu sysmenu; diff --git a/plugin/iwingtoolplg.h b/plugin/iwingtoolplg.h index 146d244..8f70b06 100644 --- a/plugin/iwingtoolplg.h +++ b/plugin/iwingtoolplg.h @@ -72,7 +72,8 @@ enum HookIndex { DoubleClicked = 8, MouseWheel = 16, MouseMove = 32, - MouseDrag = 64 + MouseDrag = 64, + ClipBoardSelection = 128 }; Q_DECLARE_METATYPE(HookIndex) diff --git a/plugin/pluginsystem.cpp b/plugin/pluginsystem.cpp index 7269484..40796de 100644 --- a/plugin/pluginsystem.cpp +++ b/plugin/pluginsystem.cpp @@ -17,6 +17,7 @@ PluginSystem::PluginSystem(QObject *parent) InitDispathcer(HookIndex::MouseWheel); InitDispathcer(HookIndex::DoubleClicked); InitDispathcer(HookIndex::MouseDrag); + InitDispathcer(HookIndex::ClipBoardSelection); // 初始化类别插件容器 #define InitCatagory(catagory) \ @@ -68,9 +69,18 @@ PluginSystem::PluginSystem(QObject *parent) item->doubleClicked(x, y); } }); + connect(manager, &AppManager::selectionTextChanged, this, + [=](const QString &selectedText) { + for (auto item : dispatcher[HookIndex::ClipBoardSelection]) { + item->selectionTextChanged(selectedText); + } + }); connect(manager, &AppManager::hotkeyTirggered, this, - [=](const QHotkey *hotkey) { - auto uuid = uhmap.key(const_cast(hotkey), QUuid()); + [=](const Hotkey *hotkey) { + if (hotkey->isHostHotkey()) + return; + + auto uuid = uhmap.key(const_cast(hotkey), QUuid()); if (uuid.isNull()) return; int id; @@ -79,8 +89,11 @@ PluginSystem::PluginSystem(QObject *parent) plg->pluginServicePipe(HotKeyTriggered, {uuid}); }); connect(manager, &AppManager::hotkeyReleased, this, - [=](const QHotkey *hotkey) { - auto uuid = uhmap.key(const_cast(hotkey), QUuid()); + [=](const Hotkey *hotkey) { + if (hotkey->isHostHotkey()) + return; + + auto uuid = uhmap.key(const_cast(hotkey), QUuid()); if (uuid.isNull()) return; int id; @@ -89,8 +102,11 @@ PluginSystem::PluginSystem(QObject *parent) plg->pluginServicePipe(HotKeyReleased, {uuid}); }); connect(manager, &AppManager::hotkeyEnableChanged, this, - [=](bool value, const QHotkey *hotkey) { - auto uuid = uhmap.key(const_cast(hotkey), QUuid()); + [=](bool value, const Hotkey *hotkey) { + if (hotkey->isHostHotkey()) + return; + + auto uuid = uhmap.key(const_cast(hotkey), QUuid()); if (uuid.isNull()) return; int id; @@ -221,6 +237,7 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) { INSERTSUBSCRIBE(HookIndex::MouseWheel); INSERTSUBSCRIBE(HookIndex::DoubleClicked); INSERTSUBSCRIBE(HookIndex::MouseDrag); + INSERTSUBSCRIBE(HookIndex::ClipBoardSelection); // 连接信号 connect(p, &IWingToolPlg::registerHotkey, this, @@ -228,7 +245,7 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) { auto sender = qobject_cast(QObject::sender()); if (sender == nullptr) return QUuid(); - auto hk = this->manager->registerHotkey(keyseq); + auto hk = this->manager->registerHotkey(keyseq, false); if (hk) { auto uuid = QUuid::createUuid(); m_plghk[sender].append(uuid); @@ -323,6 +340,8 @@ IWingToolPlg *PluginSystem::plugin(int index) { return m_plgs[index]; } +int PluginSystem::pluginCounts() { return m_plgs.count(); } + QList PluginSystem::pluginRegisteredHotkey(IWingToolPlg *plg) { if (plg == nullptr) return QList(); diff --git a/plugin/pluginsystem.h b/plugin/pluginsystem.h index 2677c63..ffd6ec5 100644 --- a/plugin/pluginsystem.h +++ b/plugin/pluginsystem.h @@ -40,6 +40,8 @@ public: QList plugins(); IWingToolPlg *plugin(int index); + int pluginCounts(); + QList pluginRegisteredHotkey(IWingToolPlg *plg); bool pluginCall(QString provider, int serviceID, QList params); @@ -54,7 +56,7 @@ private: QStringList loadedProvider; // 已加载的插件 PUID QList m_plgs; // 已加载的插件集合 QMap> m_plghk; // 注册的热键句柄集合 - QMap uhmap; // UUID 和 QHotkey 的对应图 + QMap uhmap; // UUID 和 QHotkey 的对应图 QMap> m_catplgs; // 对应类别的插件集合 diff --git a/resources.qrc b/resources.qrc index d60f342..01e8b8c 100644 --- a/resources.qrc +++ b/resources.qrc @@ -5,5 +5,11 @@ images/author.jpg images/close.png images/plugin.png + images/add.svg + images/clear.svg + images/del.svg + images/down.svg + images/edit.svg + images/up.svg diff --git a/utilities.h b/utilities.h index 9eb9c7a..2fa518e 100644 --- a/utilities.h +++ b/utilities.h @@ -8,17 +8,26 @@ #define ProgramIcon QIcon(":/images/logo.svg") #define ICONRES(name) QIcon(":/images/" name ".png") +#define ICONRES2(name) QIcon(":/images/" name ".svg") -struct ShortCutEditRes { - bool enabled; - QKeySequence seq; - QString process; - int serviceID; - QString provider; - QString params; - bool isPlugin; +// 该结构体在不同使用场合下,含义可能有所变化 +// 也并不是所有的成员在同一个场合用到的 +struct ToolStructInfo { + bool enabled = true; + QKeySequence seq = QKeySequence(); + QString process = QString(); // 如果是文件是路径,如果是插件是插件名 + QString params = QString(); + + // 以下仅供插件使用 + int serviceID = -1; + int pluginIndex = -1; + QString provider = QString(); + + bool isPlugin = false; }; +Q_DECLARE_METATYPE(ToolStructInfo) + class Utilities { public: static QIcon processPluginIcon(IWingToolPlg *plg) {