diff --git a/README.md b/README.md index 669ece4..2576d10 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@   现在工具处于开发状态,很多功能并没有完成: -1. 配置相关(已完成 80%) -2. 窗口工具(已完成 10%) +1. 配置相关(已完成 90%) +2. 窗口工具(已完成 40%) 3. 语言本地化(已完成 0%) 4. 软件 UI 相关(已完成 90%) diff --git a/WingTool.pro b/WingTool.pro index 3827cfc..6fa8ee3 100644 --- a/WingTool.pro +++ b/WingTool.pro @@ -25,7 +25,9 @@ SOURCES += \ control/pluginselector.cpp \ dialog/pluginseldialog.cpp \ dialog/tooleditdialog.cpp \ - class/hotkey.cpp + class/hotkey.cpp \ + dialog/toolswapdialog.cpp \ + control/wintoolitem.cpp RESOURCES += resources.qrc HEADERS += \ @@ -45,4 +47,6 @@ HEADERS += \ dialog/pluginseldialog.h \ utilities.h \ dialog/tooleditdialog.h \ - class/hotkey.h + class/hotkey.h \ + dialog/toolswapdialog.h \ + control/wintoolitem.h diff --git a/class/appmanager.h b/class/appmanager.h index e618deb..af15317 100644 --- a/class/appmanager.h +++ b/class/appmanager.h @@ -3,6 +3,7 @@ #include "class/eventmonitor.h" #include "class/hotkey.h" +#include "dialog/toolboxwindow.h" #include "dialog/toolwindow.h" #include "utilities.h" #include diff --git a/class/settingmanager.cpp b/class/settingmanager.cpp index 0b36923..b1b3422 100644 --- a/class/settingmanager.cpp +++ b/class/settingmanager.cpp @@ -7,7 +7,8 @@ SettingManager *SettingManager::m_instance = nullptr; SettingManager::SettingManager(QObject *parent) - : QObject(parent), m_toolGridSize(TOOLGRIDSIZE), + : QObject(parent), m_toolwin(true), m_wintool(true), + m_toolGridSize(TOOLGRIDSIZE), m_toolBox( QKeySequence(Qt::KeyboardModifier::ShiftModifier | Qt::Key_Space)), m_toolwinMod(Qt::KeyboardModifier::ControlModifier), @@ -17,12 +18,15 @@ SettingManager::SettingManager(QObject *parent) SettingManager *SettingManager::instance() { return m_instance; } -bool SettingManager::loadSettings() { - QString strConfigPath = - QString("%1/%2/%3/config.conf") - .arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)) - .arg(qApp->organizationName()) - .arg(qApp->applicationName()); +bool SettingManager::loadSettings(QString filename) { + + QString strConfigPath = filename.isEmpty() + ? QString("%1/%2/%3/config.conf") + .arg(QStandardPaths::writableLocation( + QStandardPaths::ConfigLocation)) + .arg(qApp->organizationName()) + .arg(qApp->applicationName()) + : filename; QFile f(strConfigPath); QDataStream stream(&f); @@ -39,7 +43,8 @@ bool SettingManager::loadSettings() { auto plgsys = PluginSystem::instance(); // General - stream >> m_toolGridSize >> m_toolBox >> m_toolwinMod >> m_toolMouse; + stream >> m_toolwin >> m_wintool >> m_toolGridSize >> m_toolBox >> + m_toolwinMod >> m_toolMouse; // 读取结束,提示可以加载基础配置内容了 emit loadedGeneral(); @@ -175,7 +180,8 @@ bool SettingManager::exportSettings(QString filename) { static char header[] = "WINGTOOL"; stream.writeRawData(header, 8); // General - stream << m_toolGridSize << m_toolBox << m_toolwinMod << m_toolMouse; + stream << m_toolwin << m_wintool << m_toolGridSize << m_toolBox + << m_toolwinMod << m_toolMouse; // 有些配置直接保存到 CenterWindow 里面了,为了减少内存占用 emit sigSaveConfig(stream); // 至此,保存完毕 @@ -185,6 +191,8 @@ bool SettingManager::exportSettings(QString filename) { return false; } +void SettingManager::resetSettings() {} + int SettingManager::toolGridSize() const { return m_toolGridSize; } void SettingManager::setToolGridSize(const int v) { @@ -205,10 +213,26 @@ Qt::KeyboardModifier SettingManager::toolwinMod() const { return m_toolwinMod; } void SettingManager::setToolwinMod(const Qt::KeyboardModifier &toolwinMod) { m_toolwinMod = toolwinMod; + emit sigToolwinModChanged(toolwinMod); } Qt::MouseButton SettingManager::toolwinMouseBtn() const { return m_toolMouse; } void SettingManager::setToolMouseBtn(const Qt::MouseButton &toolMouse) { m_toolMouse = toolMouse; + emit sigToolwinMouseBtnChanged(toolMouse); +} + +bool SettingManager::toolwinEnabled() const { return m_toolwin; } + +void SettingManager::setToolwinEnabled(bool toolwin) { + m_toolwin = toolwin; + emit sigToolwinEnabledChanged(toolwin); +} + +bool SettingManager::wintoolEnabled() const { return m_wintool; } + +void SettingManager::setWintoolEnabled(bool wintool) { + m_wintool = wintool; + emit sigWintoolEnabledChanged(wintool); } diff --git a/class/settingmanager.h b/class/settingmanager.h index 76d341c..3f4a533 100644 --- a/class/settingmanager.h +++ b/class/settingmanager.h @@ -16,7 +16,7 @@ public: static SettingManager *instance(); public: - bool loadSettings(); + bool loadSettings(QString filename = QString()); bool saveSettings(); bool exportSettings(QString filename); void resetSettings(); @@ -34,13 +34,20 @@ public: Qt::MouseButton toolwinMouseBtn() const; void setToolMouseBtn(const Qt::MouseButton &toolwinMouseBtn); + bool toolwinEnabled() const; + void setToolwinEnabled(bool toolwinEnabled); + + bool wintoolEnabled() const; + void setWintoolEnabled(bool wintoolEnabled); + signals: + void sigToolwinEnabledChanged(bool b); + void sigWintoolEnabledChanged(bool b); void sigToolGridSizeChanged(int v); void loadedGeneral(); void sigToolBoxHotkeyChanged(const QKeySequence seq); - void sigToolWinShortCutChanged(const Qt::KeyboardModifier mod, - const Qt::MouseButton btn); - + void sigToolwinModChanged(const Qt::KeyboardModifier mod); + void sigToolwinMouseBtnChanged(const Qt::MouseButton btn); void sigSaveConfig(QDataStream &stream); // 配置添加信号 @@ -51,6 +58,7 @@ signals: private: static SettingManager *m_instance; + bool m_toolwin, m_wintool; int m_toolGridSize; QKeySequence m_toolBox; diff --git a/control/wintoolitem.cpp b/control/wintoolitem.cpp new file mode 100644 index 0000000..42ec59d --- /dev/null +++ b/control/wintoolitem.cpp @@ -0,0 +1,49 @@ +#include "wintoolitem.h" +#include +#include + +WinToolItem::WinToolItem(QWidget *parent) : QWidget(parent) { + setFixedHeight(30); + auto layout = new QHBoxLayout(this); + lbl = new DLabel(this); + lbl->setFixedSize(25, 25); + lbl->setScaledContents(true); + layout->addWidget(lbl); + auto ilayout = new QVBoxLayout(this); + layout->addLayout(ilayout, 1); + m_name = new DLabel(this); + ilayout->addWidget(m_name); + m_srv = new DLabel(this); + ilayout->addWidget(m_srv); + m_param = new DLabel(this); + ilayout->addWidget(m_param); +} + +WinToolItem::WinToolItem(const QPixmap pix, const QString &name, + const QString &srv, const QString ¶ms, + QWidget *parent) + : QWidget(parent) { + setFixedHeight(30); + auto layout = new QHBoxLayout(this); + lbl = new DLabel(this); + lbl->setPixmap(pix); + lbl->setFixedSize(25, 25); + lbl->setScaledContents(true); + layout->addWidget(lbl); + auto ilayout = new QVBoxLayout(this); + layout->addLayout(ilayout, 1); + m_name = new DLabel(name, this); + ilayout->addWidget(m_name); + m_srv = new DLabel(srv, this); + ilayout->addWidget(m_srv); + m_param = new DLabel(params, this); + ilayout->addWidget(m_param); +} + +void WinToolItem::setIcon(QPixmap pix) { lbl->setPixmap(pix); } + +void WinToolItem::setName(const QString &name) { m_name->setText(name); } + +void WinToolItem::setSrvName(const QString &srv) { m_srv->setText(srv); } + +void WinToolItem::setParams(const QString ¶ms) { m_param->setText(params); } diff --git a/control/wintoolitem.h b/control/wintoolitem.h new file mode 100644 index 0000000..e7cefb8 --- /dev/null +++ b/control/wintoolitem.h @@ -0,0 +1,28 @@ +#ifndef WINTOOLITEM_H +#define WINTOOLITEM_H + +#include +#include +#include + +DWIDGET_USE_NAMESPACE + +class WinToolItem : public QWidget { + Q_OBJECT +public: + explicit WinToolItem(QWidget *parent = nullptr); + explicit WinToolItem(const QPixmap pix, const QString &name, + const QString &srv, const QString ¶ms, + QWidget *parent = nullptr); + +public slots: + void setIcon(const QPixmap pix); + void setName(const QString &name); + void setSrvName(const QString &srv); + void setParams(const QString ¶ms); + +private: + DLabel *lbl, *m_name, *m_srv, *m_param; +}; + +#endif // WINTOOLITEM_H diff --git a/dialog/centerwindow.cpp b/dialog/centerwindow.cpp index e563ad2..29d6ba9 100644 --- a/dialog/centerwindow.cpp +++ b/dialog/centerwindow.cpp @@ -1,12 +1,15 @@ #include "centerwindow.h" #include "shortcuteditdialog.h" #include "tooleditdialog.h" +#include "toolswapdialog.h" #include +#include #include #include #include #include #include +#include #include #include #include @@ -53,14 +56,8 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { auto hlayout = new QHBoxLayout(gw); vlayout->addLayout(hlayout); cbToolWin = new DCheckBox(tr("EnabledToolWin"), this); - connect(cbToolWin, &DCheckBox::toggled, this, [=](bool v) { - - }); hlayout->addWidget(cbToolWin); cbWinTool = new DCheckBox(tr("EnabledWinTool"), this); - connect(cbWinTool, &DCheckBox::toggled, this, [=](bool v) { - - }); hlayout->addWidget(cbWinTool); gw = new QWidget(w); vlayout->addWidget(gw); @@ -70,10 +67,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { sbGridsize = new DSpinBox(w); sbGridsize->setRange(30, 60); sbGridsize->setValue(40); // 默认 40 先 - connect(sbGridsize, QOverload::of(&DSpinBox::valueChanged), this, - [=](int v) { - - }); hlayout->addWidget(sbGridsize, 1); vlayout->addSpacing(10); @@ -85,10 +78,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { vlayout->addWidget(gw); auto flayout = new QFormLayout(gw); kseqTool = new DKeySequenceEdit(gw); - connect(kseqTool, &DKeySequenceEdit::editingFinished, this, - [=](const QKeySequence &keySequence) { - - }); flayout->addRow(tr("ToolBox:"), kseqTool); hlayout = new QHBoxLayout(gw); cbMod = new DComboBox(gw); @@ -110,19 +99,16 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { auto group = new DButtonBox(this); QList blist; auto b = new DButtonBoxButton(tr("Export"), this); - connect(b, &DButtonBoxButton::clicked, this, [=] { - - }); + connect(b, &DButtonBoxButton::clicked, this, + [=] { this->on_exportSettings(); }); blist.append(b); b = new DButtonBoxButton(tr("Import"), this); - connect(b, &DButtonBoxButton::clicked, this, [=] { - - }); + connect(b, &DButtonBoxButton::clicked, this, + [=] { this->on_importSettings(); }); blist.append(b); b = new DButtonBoxButton(tr("Reset"), this); - connect(b, &DButtonBoxButton::clicked, this, [=] { - - }); + connect(b, &DButtonBoxButton::clicked, this, + [=] { this->on_resetSettings(); }); blist.append(b); group->setButtonList(blist, false); vlayout->addWidget(group); @@ -232,7 +218,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { mlayout->setSpacing(1); auto btngs = new QButtonGroup(w); btngs->setExclusive(true); // 设置按钮选中互斥 - for (int i = 0; i < 9; i++) { auto lbl = new DIconButton(this); lbl->setFixedSize(gridsize - 2, gridsize - 2); @@ -254,7 +239,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { auto e = QMetaEnum::fromType(); tbtoolinfo->setText(tr("[Plugin]")); - tbtoolinfo->append(""); tbtoolinfo->append(QObject::tr("PluginName:") + plg->pluginName()); tbtoolinfo->append(tr("Service:") + plg->pluginServices()[info.serviceID]); @@ -276,7 +260,6 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { } else { if (info.enabled) { tbtoolinfo->setText(tr("[File]")); - tbtoolinfo->append(""); tbtoolinfo->append(tr("FileName:") + info.process); tbtoolinfo->append(tr("Params:") + info.params); } else { @@ -299,22 +282,51 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { group = new DButtonBox(this); blist.clear(); // 重新征用 - b = new DButtonBoxButton(tr("Edit"), this); + b = new DButtonBoxButton(ICONRES2("edit")); + b->setParent(this); + b->setIconSize(QSize(20, 20)); + b->setToolTip(tr("Edit")); connect(b, &DButtonBoxButton::clicked, this, [=] { ToolEditDialog d(toolinfos[sellbl]); if (d.exec()) { auto res = d.getResult(); - toolinfos[sellbl] = res; - auto icon = - Utilities::trimIconFromInfo(plgsys->plugin(res.pluginIndex), res); - auto ilbl = lbls[sellbl]; - ilbl->setIcon(icon); - manager->setToolIcon(sellbl, icon); - emit ilbl->toggled(true); + this->setoolWinInfo(sellbl, res); + emit lbls[sellbl]->toggled(true); } }); blist.append(b); - b = new DButtonBoxButton(tr("Delete"), this); + b = new DButtonBoxButton(ICONRES2("swap")); + b->setParent(this); + b->setIconSize(QSize(20, 20)); + b->setToolTip(tr("Swap")); + connect(b, &DButtonBoxButton::clicked, this, [=] { + QVector icons; + for (auto i = 0; i < 9; i++) { + icons.append(lbls[i]->icon()); + } + + ToolSwapDialog d(icons, this->sellbl); + auto res = d.exec(); + if (res >= 0) { + auto tmp = toolinfos[sellbl]; + toolinfos[sellbl] = toolinfos[res]; + toolinfos[res] = tmp; + + auto icon1 = lbls[sellbl]->icon(); + auto icon2 = lbls[res]->icon(); + lbls[sellbl]->setIcon(icon2); + lbls[res]->setIcon(icon1); + + manager->setToolIcon(sellbl, icon2); + manager->setToolIcon(res, icon1); + lbls[res]->setChecked(true); + } + }); + blist.append(b); + b = new DButtonBoxButton(ICONRES2("del")); + b->setParent(this); + b->setIconSize(QSize(20, 20)); + b->setToolTip(tr("Delete")); connect(b, &DButtonBoxButton::clicked, this, [=] { toolinfos[sellbl].enabled = false; auto ilbl = lbls[sellbl]; @@ -637,8 +649,7 @@ void CenterWindow::on_editToolWin() { auto item = lstoolwin->item(index); item->setIcon( Utilities::trimIconFromInfo(plgsys->plugin(res.pluginIndex), res)); - item->setText(res.isPlugin ? res.process - : QFileInfo(res.process).fileName()); + item->setText(Utilities::getProgramName(res)); item->setToolTip(res.process); } } @@ -675,7 +686,7 @@ void CenterWindow::on_addToolWin() { wintoolinfos.append(res); auto item = new QListWidgetItem( Utilities::trimIconFromInfo(plgsys->plugin(res.pluginIndex), res), - res.isPlugin ? res.process : QFileInfo(res.process).fileName()); + Utilities::getProgramName(res)); item->setToolTip(res.process); lstoolwin->addItem(item); } else { @@ -683,7 +694,7 @@ void CenterWindow::on_addToolWin() { auto item = new QListWidgetItem( Utilities::trimIconFromInfo(plgsys->plugin(res.pluginIndex), res), - res.isPlugin ? res.process : QFileInfo(res.process).fileName()); + Utilities::getProgramName(res)); item->setToolTip(res.process); lstoolwin->insertItem(index + 1, item); } @@ -694,6 +705,32 @@ void CenterWindow::on_upToolWin() {} void CenterWindow::on_downToolWin() {} +void CenterWindow::on_exportSettings() { + auto path = DFileDialog::getSaveFileName(this, tr(""), QString(), + tr("Config (*.wtcfg)")); + if (path.isEmpty()) + return; + + if (sm->exportSettings(path)) { + DMessageManager::instance()->sendMessage(this, ProgramIcon, + tr("ExportSuccess")); + } +} + +void CenterWindow::on_importSettings() { + auto path = DFileDialog::getOpenFileName(this, tr(""), QString(), + tr("Config (*.wtcfg)")); + if (path.isEmpty()) + return; + + if (sm->loadSettings(path)) { + DMessageManager::instance()->sendMessage(this, ProgramIcon, + tr("ImportSuccess")); + } +} + +void CenterWindow::on_resetSettings() { sm->resetSettings(); } + void CenterWindow::addHotKeyInfo(ToolStructInfo &info) { // 添加 UI 项目 auto index = tbhotkeys->rowCount(); @@ -719,68 +756,149 @@ void CenterWindow::addHotKeyInfo(ToolStructInfo &info) { } void CenterWindow::setoolWinInfo(int index, ToolStructInfo &info) { - if (index >= 4) - index++; toolinfos[index] = info; - - // 更新 UI - // TODO + auto icon = + Utilities::trimIconFromInfo(plgsys->plugin(info.pluginIndex), info); + auto ilbl = lbls[sellbl]; + ilbl->setIcon(icon); + manager->setToolIcon(sellbl, icon); } void CenterWindow::addWinToolInfo(ToolStructInfo &info) { wintoolinfos << info; auto item = new QListWidgetItem( Utilities::trimIconFromInfo(plgsys->plugin(info.pluginIndex), info), - info.isPlugin ? info.process : QFileInfo(info.process).fileName()); + Utilities::getProgramName(info)); item->setToolTip(info.process); lstoolwin->addItem(item); } void CenterWindow::initGeneralSettings() { sm = SettingManager::instance(); - auto gridsize = sm->toolGridSize(); - for (auto i = 0; i < 9; i++) { - lbls[i]->setFixedSize(QSize(gridsize, gridsize)); - } - Qt::KeyboardModifier mod = sm->toolwinMod(); - Qt::MouseButton btn = sm->toolwinMouseBtn(); - switch (mod) { - case Qt::KeyboardModifier::AltModifier: - cbMod->setCurrentIndex(2); - break; - case Qt::KeyboardModifier::MetaModifier: - cbMod->setCurrentIndex(3); - break; - case Qt::KeyboardModifier::ShiftModifier: - cbMod->setCurrentIndex(1); - break; - default: - cbMod->setCurrentIndex(0); - break; - } + // 注册有关设置更改相关信号 + cbWinTool->setChecked(sm->wintoolEnabled()); + cbToolWin->setChecked(sm->toolwinEnabled()); - switch (btn) { - case Qt::MouseButton::RightButton: - cbMouseBtn->setCurrentIndex(1); - break; - case Qt::MouseButton::MidButton: - cbMouseBtn->setCurrentIndex(2); - break; - case Qt::MouseButton::XButton1: - cbMouseBtn->setCurrentIndex(3); - break; - case Qt::MouseButton::XButton2: - cbMouseBtn->setCurrentIndex(4); - break; - default: - cbMouseBtn->setCurrentIndex(0); - break; - } + connect(cbToolWin, &DCheckBox::toggled, this, + [=](bool v) { sm->setToolwinEnabled(v); }); + connect(cbWinTool, &DCheckBox::toggled, this, [=](bool v) { + sm->setWintoolEnabled(v); + hkwintool->setRegistered(v); + }); + + connect(sm, &SettingManager::sigToolGridSizeChanged, this, [=](int v) { + for (auto i = 0; i < 9; i++) { + lbls[i]->setFixedSize(QSize(v, v)); + } + }); + sm->sigToolGridSizeChanged(sm->toolGridSize()); + connect(sbGridsize, QOverload::of(&DSpinBox::valueChanged), sm, + &SettingManager::setToolGridSize); auto seq = sm->toolBoxHotkey(); kseqTool->setKeySequence(seq); - manager->registerHotkey(seq, false); + hkwintool = manager->registerHotkey(seq, false); + hkwintool->disconnect(); // 断开所有自带连接,不能让它走默认处理 + connect(hkwintool, &Hotkey::activated, this, [&] { + Dtk::Widget::moveToCenter(&wintool); + wintool.show(); + Utilities::activeWindowFromDock(wintool.winId()); + }); + connect(kseqTool, &DKeySequenceEdit::editingFinished, this, + [=](const QKeySequence &keySequence) { + sm->setToolBoxHotkey(keySequence); + }); + connect(sm, &SettingManager::sigToolBoxHotkeyChanged, this, + [=](const QKeySequence seq) { hkwintool->setShortcut(seq, true); }); + + connect(sm, &SettingManager::sigToolwinEnabledChanged, this, + [=](bool b) { cbToolWin->setChecked(b); }); + connect(sm, &SettingManager::sigWintoolEnabledChanged, this, + [=](bool b) { cbWinTool->setChecked(b); }); + + connect(sm, &SettingManager::sigToolwinModChanged, this, + [=](const Qt::KeyboardModifier mod) { + switch (mod) { + case Qt::KeyboardModifier::AltModifier: + cbMod->setCurrentIndex(2); + break; + case Qt::KeyboardModifier::MetaModifier: + cbMod->setCurrentIndex(3); + break; + case Qt::KeyboardModifier::ShiftModifier: + cbMod->setCurrentIndex(1); + break; + default: + cbMod->setCurrentIndex(0); + break; + } + }); + sm->sigToolwinModChanged(sm->toolwinMod()); + + connect(sm, &SettingManager::sigToolwinMouseBtnChanged, this, + [=](const Qt::MouseButton btn) { + switch (btn) { + case Qt::MouseButton::RightButton: + cbMouseBtn->setCurrentIndex(1); + break; + case Qt::MouseButton::MidButton: + cbMouseBtn->setCurrentIndex(2); + break; + case Qt::MouseButton::XButton1: + cbMouseBtn->setCurrentIndex(3); + break; + case Qt::MouseButton::XButton2: + cbMouseBtn->setCurrentIndex(4); + break; + default: + cbMouseBtn->setCurrentIndex(0); + break; + } + }); + sm->sigToolwinMouseBtnChanged(sm->toolwinMouseBtn()); + + connect(cbMod, QOverload::of(&DComboBox::currentIndexChanged), this, + [=](int index) { + Qt::KeyboardModifier mod = Qt::KeyboardModifier::NoModifier; + switch (index) { + case 0: + mod = Qt::KeyboardModifier::ControlModifier; + break; + case 1: + mod = Qt::KeyboardModifier::ShiftModifier; + break; + case 2: + mod = Qt::KeyboardModifier::AltModifier; + break; + case 3: + mod = Qt::KeyboardModifier::MetaModifier; + break; + } + sm->setToolwinMod(mod); + }); + connect(cbMouseBtn, QOverload::of(&DComboBox::currentIndexChanged), this, + [=](int index) { + Qt::MouseButton btn = Qt::MouseButton::NoButton; + switch (index) { + case 0: + btn = Qt::MouseButton::LeftButton; + break; + case 1: + btn = Qt::MouseButton::RightButton; + break; + case 2: + btn = Qt::MouseButton::MidButton; + break; + case 3: + btn = Qt::MouseButton::XButton1; + break; + case 4: + btn = Qt::MouseButton::XButton2; + break; + } + sm->setToolMouseBtn(btn); + }); } void CenterWindow::initPluginSys() { @@ -802,9 +920,7 @@ void CenterWindow::initAppManger() { this->runTask(task); } }); - connect(manager, &AppManager::hotkeyReleased, this, [=](const Hotkey *) { - - }); + connect(manager, &AppManager::hotkeyReleased, this, [=](const Hotkey *) {}); connect(manager, &AppManager::hotkeyEnableChanged, this, [=](bool value, const Hotkey *hotkey) { if (hotkey->isHostHotkey()) { diff --git a/dialog/centerwindow.h b/dialog/centerwindow.h index 191315b..464fae9 100644 --- a/dialog/centerwindow.h +++ b/dialog/centerwindow.h @@ -4,6 +4,7 @@ #include "class/appmanager.h" #include "class/settingmanager.h" #include "plugin/pluginsystem.h" +#include "toolboxwindow.h" #include "utilities.h" #include #include @@ -58,6 +59,10 @@ private: void on_upToolWin(); void on_downToolWin(); + void on_exportSettings(); + void on_importSettings(); + void on_resetSettings(); + public slots: void addHotKeyInfo(ToolStructInfo &info); void setoolWinInfo(int index, ToolStructInfo &info); @@ -99,6 +104,9 @@ private: DSpinBox *sbGridsize; + Hotkey *hkwintool; + ToolBoxWindow wintool; + private: QMap scinfos; // 用于 Hotkeys QList hotkeys; // Hotkeys 方便进行检索 diff --git a/dialog/toolboxwindow.cpp b/dialog/toolboxwindow.cpp index ab92800..91add59 100644 --- a/dialog/toolboxwindow.cpp +++ b/dialog/toolboxwindow.cpp @@ -1,3 +1,37 @@ #include "toolboxwindow.h" +#include "control/wintoolitem.h" +#include +#include +#include +#include -ToolBoxWindow::ToolBoxWindow(DMainWindow *parent) : DDialog(parent) {} +ToolBoxWindow::ToolBoxWindow(DMainWindow *parent) : DDialog(parent) { + lstool = new DListWidget(this); + addContent(lstool); +} + +void ToolBoxWindow::addItem(ToolStructInfo &info, int index) { + auto pitem = new QListWidgetItem; + + auto item = new WinToolItem(this); +} + +void ToolBoxWindow::rmItem(int index) { + if (index < 0) { + lstool->clear(); + return; + } + + if (index >= lstool->count()) { + return; + } + + auto k = lstool->takeItem(index); + delete k; +} + +void ToolBoxWindow::mvItem(int from, int to) { + auto len = lstool->count(); + if (from < 0 || from >= len || to < 0 || to >= len) + return; +} diff --git a/dialog/toolboxwindow.h b/dialog/toolboxwindow.h index 410c980..5f6f6ab 100644 --- a/dialog/toolboxwindow.h +++ b/dialog/toolboxwindow.h @@ -1,6 +1,7 @@ #ifndef TOOLBOXWINDOW_H #define TOOLBOXWINDOW_H +#include "utilities.h" #include #include #include @@ -12,9 +13,9 @@ class ToolBoxWindow : public DDialog { public: ToolBoxWindow(DMainWindow *parent = nullptr); -signals: - void addItem(QListWidgetItem *item, int index = -1); // -1 表示追加 - void rmItem(int index); // -1 表示清空 +public: + void addItem(ToolStructInfo &info, int index = -1); // -1 表示追加 + void rmItem(int index); // -1 表示清空 void mvItem(int from, int to); private: diff --git a/dialog/toolswapdialog.cpp b/dialog/toolswapdialog.cpp new file mode 100644 index 0000000..4d85734 --- /dev/null +++ b/dialog/toolswapdialog.cpp @@ -0,0 +1,69 @@ +#include "toolswapdialog.h" +#include "class/settingmanager.h" +#include +#include +#include +#include +#include + +ToolSwapDialog::ToolSwapDialog(const QVector &icons, int selindex, + DDialog *parent) + : DDialog(parent) { + setWindowTitle(tr("ToolSwapDialog")); + + addContent(new DLabel(tr("PleaseSelect"), this), Qt::AlignCenter); + addSpacing(10); + auto gridsize = SettingManager::instance()->toolGridSize(); + auto gw = new QWidget(this); + gw->setFixedSize(gridsize * 3, gridsize * 3); + delete gw->layout(); + auto mlayout = new QGridLayout; + gw->setLayout(mlayout); + mlayout->setMargin(1); + auto btngs = new QButtonGroup(this); + btngs->setExclusive(true); // 设置按钮选中互斥 + for (int i = 0; i < 9; i++) { + auto lbl = new DIconButton(this); + lbl->setFixedSize(gridsize - 2, gridsize - 2); + lbl->setIconSize(QSize(gridsize / 2, gridsize / 2)); + lbl->setIcon(icons[i]); + lbl->setCheckable(true); + auto in = std::div(i, 3); + mlayout->addWidget(lbl, in.quot, in.rem, Qt::AlignCenter); + lbls[i] = lbl; + btngs->addButton(lbl); + connect(lbl, &DIconButton::toggled, this, [=](bool b) { + if (b) + cur = i; + }); + } + auto lbl4 = lbls[4]; + lbl4->setIcon(ICONRES("close")); + lbl4->setEnabled(false); + lbls[selindex]->setEnabled(false); + addContent(gw, Qt::AlignCenter); + addSpacing(20); + auto dbbox = new DDialogButtonBox( + DDialogButtonBox::Ok | DDialogButtonBox::Cancel, this); + connect(dbbox, &DDialogButtonBox::accepted, this, &ToolSwapDialog::on_accept); + connect(dbbox, &DDialogButtonBox::rejected, this, &ToolSwapDialog::on_reject); + auto key = QKeySequence(Qt::Key_Return); + auto s = new QShortcut(key, this); + connect(s, &QShortcut::activated, this, &ToolSwapDialog::on_accept); + addContent(dbbox); +} + +void ToolSwapDialog::on_accept() { + if (cur == -1) { + DMessageManager::instance()->sendMessage(this, ProgramIcon, tr("NoSelect")); + return; + } + done(cur); +} + +void ToolSwapDialog::on_reject() { done(-1); } + +void ToolSwapDialog::closeEvent(QCloseEvent *event) { + Q_UNUSED(event); + done(-1); +} diff --git a/dialog/toolswapdialog.h b/dialog/toolswapdialog.h new file mode 100644 index 0000000..8ec6f9a --- /dev/null +++ b/dialog/toolswapdialog.h @@ -0,0 +1,30 @@ +#ifndef TOOLSWAPDIALOG_H +#define TOOLSWAPDIALOG_H + +#include "utilities.h" +#include +#include +#include + +DWIDGET_USE_NAMESPACE + +class ToolSwapDialog : public DDialog { +public: + ToolSwapDialog(const QVector &icons, int selindex, + DDialog *parent = nullptr); + +private: + void on_accept(); + void on_reject(); + +protected: + void closeEvent(QCloseEvent *event) override; + +private: + QGridLayout *mlayout; + DIconButton *lbls[9] = {nullptr}; + + int cur = -1; +}; + +#endif // TOOLSWAPDIALOG_H diff --git a/images/swap.svg b/images/swap.svg new file mode 100644 index 0000000..7680d06 --- /dev/null +++ b/images/swap.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/main.cpp b/main.cpp index a0c44e1..5939426 100644 --- a/main.cpp +++ b/main.cpp @@ -82,8 +82,6 @@ int main(int argc, char *argv[]) { /*== 以下在主函数初始化确保单例 ==*/ /* 之后不得使用构造函数的方式使用 */ - qRegisterMetaType(); - // 初始化程序基础驱动 AppManager manager; w.initAppManger(); @@ -110,7 +108,7 @@ int main(int argc, char *argv[]) { QObject::connect(&manager, &AppManager::checkToolShow, [&sm, &manager](Qt::MouseButton btn) { auto mod = manager.getKeyModifier(); - return mod == sm.toolwinMod() && + return sm.toolwinEnabled() && mod == sm.toolwinMod() && sm.toolwinMouseBtn() == btn; }); diff --git a/resources.qrc b/resources.qrc index 01e8b8c..0df6835 100644 --- a/resources.qrc +++ b/resources.qrc @@ -11,5 +11,6 @@ images/down.svg images/edit.svg images/up.svg + images/swap.svg diff --git a/utilities.h b/utilities.h index a7e3ed4..be9e32c 100644 --- a/utilities.h +++ b/utilities.h @@ -112,6 +112,10 @@ public: return QIcon::fromTheme(t.iconName(), QIcon(t.iconName())); } } + + static QString getProgramName(ToolStructInfo &info) { + return info.isPlugin ? info.process : QFileInfo(info.process).fileName(); + } }; #endif // UTILIES_H