This commit is contained in:
寂静的羽夏 2022-09-28 10:00:54 +08:00
parent ec2242eea2
commit 632ef771f3
29 changed files with 451 additions and 104 deletions

View File

@ -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

View File

@ -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];

View File

@ -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<QHotkey *> hotkeys;
QList<Hotkey *> hotkeys;
QStringList execs;
bool ignoremsg = false;

7
class/hotkey.cpp Normal file
View File

@ -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; }

17
class/hotkey.h Normal file
View File

@ -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

View File

@ -1,6 +1,5 @@
#include "settingmanager.h"
#include <QApplication>
#include <QDataStream>
#include <QFile>
#include <QStandardPaths>
@ -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 =

View File

@ -1,6 +1,8 @@
#ifndef SETTINGMANAGER_H
#define SETTINGMANAGER_H
#include "QHotkey/qhotkey.h"
#include "utilities.h"
#include <QObject>
#define TOOLGRIDSIZE 40
@ -25,6 +27,12 @@ public:
signals:
void sigToolGridSizeChanged(int v);
void getHokeysBuffer(QList<QHotkey *> &hotkeysBuf,
QMap<QHotkey *, ToolStructInfo> &buffer);
void getToolLeftBuffer(ToolStructInfo buffer[]);
void getToolRightBuffer(QList<ToolStructInfo> &buffer);
void loadingFinish();
private:
static SettingManager *m_instance;

View File

@ -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;
}

View File

@ -19,6 +19,8 @@ public:
int getSelectedIndex();
IWingToolPlg *getSelectedPlg();
bool setSelectedIndex(int index);
signals:
void finished();

View File

@ -6,6 +6,7 @@
#include <DMessageManager>
#include <DTextBrowser>
#include <DTitlebar>
#include <QButtonGroup>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QHBoxLayout>
@ -17,9 +18,7 @@
#include <QVBoxLayout>
#include <QVector>
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<QHotkey *>(hotkey))) {
auto &task = scinfos[const_cast<QHotkey *>(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<QHotkey *>(hotkey))) {
tbhotkeys->item(hotkeys.indexOf(const_cast<QHotkey *>(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<QHotkey *> &hotkeysBuf,
QMap<QHotkey *, ToolStructInfo> &buffer) {}
void CenterWindow::getToolLeftBuffer(ToolStructInfo buffer[]) {}
void CenterWindow::getToolRightBuffer(QList<ToolStructInfo> &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 *>(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 *>(hotkey)), 0)
->setCheckState(value ? Qt::Checked : Qt::Unchecked);
}
});
}
void CenterWindow::closeEvent(QCloseEvent *event) {
event->ignore();
hide();

View File

@ -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<QHotkey *> &hotkeysBuf,
QMap<QHotkey *, ToolStructInfo> &buffer);
void getToolLeftBuffer(ToolStructInfo buffer[]);
void getToolRightBuffer(QList<ToolStructInfo> &buffer);
void loadingFinish();
void initPluginSys();
void initAppManger();
protected:
void closeEvent(QCloseEvent *event) override;
@ -81,7 +91,9 @@ private:
DIconButton *lbls[9] = {nullptr};
private:
QMap<QHotkey *, ShortCutEditRes> scinfos;
QMap<QHotkey *, ToolStructInfo> scinfos; // 用于 Hotkeys
ToolStructInfo toolinfos[9]; // 用于 Tool 左侧
QList<ToolStructInfo> wintoolinfos; // 用于 WinTool Tool 右侧
QList<QHotkey *> hotkeys;
};

View File

@ -4,9 +4,7 @@
#include <DMessageManager>
#include <QShortcut>
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,

View File

@ -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;

View File

@ -1,6 +1,3 @@
#include "toolboxwindow.h"
ToolBoxWindow::ToolBoxWindow()
{
}
ToolBoxWindow::ToolBoxWindow(DMainWindow *parent) : DDialog(parent) {}

View File

@ -1,11 +1,19 @@
#ifndef TOOLBOXWINDOW_H
#define TOOLBOXWINDOW_H
#include <DDialog>
#include <DListWidget>
#include <DMainWindow>
class ToolBoxWindow
{
DWIDGET_USE_NAMESPACE
class ToolBoxWindow : public DDialog {
Q_OBJECT
public:
ToolBoxWindow();
ToolBoxWindow(DMainWindow *parent = nullptr);
private:
DListWidget *lstool;
};
#endif // TOOLBOXWINDOW_H
#endif // TOOLBOXWINDOW_H

106
dialog/tooleditdialog.cpp Normal file
View File

@ -0,0 +1,106 @@
#include "tooleditdialog.h"
#include <DDialogButtonBox>
#include <DMessageManager>
#include <QShortcut>
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);
}

44
dialog/tooleditdialog.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef TOOLWINEDITDIALOG_H
#define TOOLWINEDITDIALOG_H
#include "utilities.h"
#include "class/appmanager.h"
#include "control/pluginselector.h"
#include <DCheckBox>
#include <DComboBox>
#include <DDialog>
#include <DFileChooserEdit>
#include <DKeySequenceEdit>
#include <DLabel>
#include <DLineEdit>
#include <DMainWindow>
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

1
images/add.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664287461654" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="996" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 512m-512 0a512 512 0 1 0 1024 0 512 512 0 1 0-1024 0Z" fill="#1D75B0" p-id="997"></path><path d="M713.216 462.336H310.784c-27.648 0-49.664 22.528-49.664 49.664s22.528 49.664 49.664 49.664h402.432c27.648 0 49.664-22.528 49.664-49.664s-22.528-49.664-49.664-49.664z" fill="#FFFFFF" p-id="998"></path><path d="M462.336 310.784v402.432c0 27.648 22.528 49.664 49.664 49.664s49.664-22.528 49.664-49.664V310.784c0-27.648-22.528-49.664-49.664-49.664s-49.664 22.528-49.664 49.664z" fill="#FFFFFF" p-id="999"></path></svg>

After

Width:  |  Height:  |  Size: 848 B

1
images/clear.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664287572410" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5176" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M766.6 259.2c16.4 0 29.9 2.7 40.6 8.2 10.6 5.5 19.1 12.3 25.4 20.5 6.3 8.2 10.6 17.1 13.1 26.6 2.5 9.6 1.7 11.4 1.7 19.6 0 3.8-3.2 15.8-11.1 26.4-10.3 13.7-22.4 19.3-22.4 19.3l-19.4-19v430.1c0 10.9-2.2 21.4-6.6 31.5-4.4 10.1-11.4 23.1-19.7 33.9-6.8 8.9-28.5 33.3-91.1 36.5-12.6 0.6-10-6.3-25.3-6.3l-318.5-12.1c-14.2 0-27.6-2.2-40.1-6.6-12.6-4.4-23.3-10.5-32.4-18.4-9-7.9-16.1-17.5-21.3-28.7-5.2-11.2-7.8-23.9-7.8-38.1V360.8h-50.8c-0.5-0.5-0.8-1.9-0.8-4.1-0.5-2.7-0.8-11.2-0.8-25.4 0-7.1-33 4-29.7-4.7 3.3-8.7 7.6-27.6 23.2-40.9 9.8-8.4 20.6-15.9 42.6-23.7 10.8-3.8 31.7-7.4 45.9-7.4h72.9l-34.7-28c0-14.2 2.6-37.9 23.9-56 23.7-20 43.7-21.6 77.5-21.6l240.4 2c19.1 0 32.4 10 39.7 20.2 7.4 10.1 11.1 22.3 11.1 36.5v50.8c11.5 0.5 23.8 0.8 36.9 0.8h37.6zM342.1 297h299.1v-89.4H342.1V297z m-6.2 527c33.2 0 49.8-12.4 49.8-37.3V364.1h-96.5v422.6c0 12.8 3.4 22.2 10.1 28.2 6.8 6.1 19 9.1 36.6 9.1z m152.3-5c19.5 0 32.6-2.9 39.5-8.6 6.9-5.7 10.3-14.9 10.3-27.5V364.1H431.5v418.8c0 24.1 18.9 36.1 56.7 36.1z m157.6 0c18.8 0 31.4-2.9 37.7-8.6 6.3-5.7 9.4-15 9.4-27.6V364.1H594v418.7c0 24.1 17.3 36.2 51.8 36.2z m22.5-43.7" fill="#2280BF" p-id="5177"></path><path d="M731.9 278.2c16.4 0 29.9 2.7 40.6 8.2 10.6 5.5 19.1 12.3 25.4 20.5 6.3 8.2 10.6 17.1 13.1 26.6 2.5 9.6 3.7 18.4 3.7 26.6 0 3.8-0.1 6.8-0.4 9-0.3 2.2-0.4 4.1-0.4 5.7v4.9h-54.1v430.1c0 10.9-2.2 21.4-6.6 31.5-4.4 10.1-10.6 19-18.8 26.6-8.2 7.6-18.2 13.8-29.9 18.4-11.7 4.6-25.3 7-40.6 7H298.6c-14.2 0-27.6-2.2-40.1-6.6-12.6-4.4-23.3-10.5-32.4-18.4-9-7.9-16.1-17.5-21.3-28.7-5.2-11.2-7.8-23.9-7.8-38.1V379.8h-50.8c-0.5-0.5-0.8-1.9-0.8-4.1-0.5-2.7-0.8-11.2-0.8-25.4 0-7.1 1.6-15 4.9-23.8 3.3-8.7 8.2-16.8 14.7-24.2 6.6-7.4 15-13.5 25.4-18.4 10.4-4.9 22.7-7.4 36.9-7.4h72.9v-50c0-14.2 4.9-26.4 14.7-36.5 9.8-10.1 21.8-15.2 36-15.2h256.4c19.1 0 32.4 5 39.7 15.2 7.4 10.1 11.1 22.3 11.1 36.5v50.8c11.5 0.5 23.8 0.8 36.9 0.8h37.7z m-381.7 0h256.4v-51.6H350.2v51.6z m-25.4 518.6c17.5 0 26.2-11.2 26.2-33.6V383.1h-50.8v380.1c0 11.5 1.8 19.9 5.3 25.4 3.6 5.5 10 8.2 19.3 8.2z m154.8-0.8c9.3 0 15.6-2.6 18.8-7.8 3.3-5.2 4.9-13.5 4.9-25V383.1h-50.8v380.1c0.1 21.9 9.1 32.8 27.1 32.8z m154-1.7c9.8 0 16.4-2.6 19.7-7.8 3.3-5.2 4.9-13.5 4.9-25V383.1h-51.6v378.5c0 21.8 9 32.7 27 32.7z m0 0" fill="#4EB3FF" p-id="5178"></path></svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

1
images/del.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664287469095" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1150" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0z m218.624 672.256c15.872 15.872 15.872 41.984 0 57.856-8.192 8.192-18.432 11.776-29.184 11.776s-20.992-4.096-29.184-11.776L512 569.856l-160.256 160.256c-8.192 8.192-18.432 11.776-29.184 11.776s-20.992-4.096-29.184-11.776c-15.872-15.872-15.872-41.984 0-57.856L454.144 512 293.376 351.744c-15.872-15.872-15.872-41.984 0-57.856 15.872-15.872 41.984-15.872 57.856 0L512 454.144l160.256-160.256c15.872-15.872 41.984-15.872 57.856 0 15.872 15.872 15.872 41.984 0 57.856L569.856 512l160.768 160.256z" fill="#CF3736" p-id="1151"></path></svg>

After

Width:  |  Height:  |  Size: 956 B

1
images/down.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664287518006" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2396" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M0 0h1024v1024H0z" fill="#1296db" opacity=".01" p-id="2397"></path><path d="M512 0c282.7776 0 512 229.2224 512 512s-229.2224 512-512 512S0 794.7776 0 512 229.2224 0 512 0z m0 204.8a51.2 51.2 0 0 0-51.2 51.2v385.792L345.6512 527.36a52.6336 52.6336 0 0 0-69.3248-4.352l-4.9152 4.352c-18.944 18.8928-20.4288 48.64-4.4032 69.12l4.4032 4.9664L474.88 803.84c18.944 18.944 48.6912 20.3776 69.3248 4.352l4.9152-4.352 203.4688-202.3936c20.5312-20.48 20.5312-53.6064 0-74.0864a52.6336 52.6336 0 0 0-69.3248-4.352l-4.9152 4.352L563.2 641.792V256a51.2 51.2 0 0 0-51.2-51.2z" fill="#1296db" p-id="2398"></path></svg>

After

Width:  |  Height:  |  Size: 936 B

1
images/edit.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664287954550" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2177" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M470.528 403.264zM313.984 851.712l-246.976 45.888 49.792-244.16 197.184 198.272zM701.44 65.344l-88.512 88.96 197.184 198.336 88.512-88.96-197.184-198.336zM161.024 608.96l197.184 198.336 407.744-410.112-197.184-198.4-407.744 410.176z" p-id="2178" fill="#1296db"></path><path d="M384 832h128v128H384zM580.032 832h128v128h-128zM772.032 832h126.656v128h-126.656z" p-id="2179" fill="#1296db"></path></svg>

After

Width:  |  Height:  |  Size: 733 B

1
images/up.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1664287502997" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2184" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M0 0h1024v1024H0z" fill="#1296db" opacity=".01" p-id="2185"></path><path d="M512 0c282.7776 0 512 229.2224 512 512s-229.2224 512-512 512S0 794.7776 0 512 229.2224 0 512 0z m-37.12 220.16L271.36 422.5536C250.88 443.0336 250.88 476.16 271.36 496.64c20.48 20.48 53.76 20.48 74.24 0L460.8 382.208V768a51.2 51.2 0 0 0 45.2096 50.8416L512 819.2a51.2 51.2 0 0 0 51.2-51.2V382.208L678.3488 496.64c20.48 20.48 53.76 20.48 74.24 0 20.5312-20.48 20.5312-53.6576 0-74.0864L549.12 220.16c-20.48-20.48-53.76-20.48-74.24 0z" fill="#1296db" p-id="2186"></path></svg>

After

Width:  |  Height:  |  Size: 883 B

View File

@ -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;

View File

@ -72,7 +72,8 @@ enum HookIndex {
DoubleClicked = 8,
MouseWheel = 16,
MouseMove = 32,
MouseDrag = 64
MouseDrag = 64,
ClipBoardSelection = 128
};
Q_DECLARE_METATYPE(HookIndex)

View File

@ -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<QHotkey *>(hotkey), QUuid());
[=](const Hotkey *hotkey) {
if (hotkey->isHostHotkey())
return;
auto uuid = uhmap.key(const_cast<Hotkey *>(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<QHotkey *>(hotkey), QUuid());
[=](const Hotkey *hotkey) {
if (hotkey->isHostHotkey())
return;
auto uuid = uhmap.key(const_cast<Hotkey *>(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<QHotkey *>(hotkey), QUuid());
[=](bool value, const Hotkey *hotkey) {
if (hotkey->isHostHotkey())
return;
auto uuid = uhmap.key(const_cast<Hotkey *>(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<IWingToolPlg *>(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<QKeySequence> PluginSystem::pluginRegisteredHotkey(IWingToolPlg *plg) {
if (plg == nullptr)
return QList<QKeySequence>();

View File

@ -40,6 +40,8 @@ public:
QList<IWingToolPlg *> plugins();
IWingToolPlg *plugin(int index);
int pluginCounts();
QList<QKeySequence> pluginRegisteredHotkey(IWingToolPlg *plg);
bool pluginCall(QString provider, int serviceID, QList<QVariant> params);
@ -54,7 +56,7 @@ private:
QStringList loadedProvider; // 已加载的插件 PUID
QList<IWingToolPlg *> m_plgs; // 已加载的插件集合
QMap<IWingToolPlg *, QList<QUuid>> m_plghk; // 注册的热键句柄集合
QMap<QUuid, QHotkey *> uhmap; // UUID 和 QHotkey 的对应图
QMap<QUuid, Hotkey *> uhmap; // UUID 和 QHotkey 的对应图
QMap<IWingToolPlg::Catagorys, QList<IWingToolPlg *>>
m_catplgs; // 对应类别的插件集合

View File

@ -5,5 +5,11 @@
<file>images/author.jpg</file>
<file>images/close.png</file>
<file>images/plugin.png</file>
<file>images/add.svg</file>
<file>images/clear.svg</file>
<file>images/del.svg</file>
<file>images/down.svg</file>
<file>images/edit.svg</file>
<file>images/up.svg</file>
</qresource>
</RCC>

View File

@ -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) {