diff --git a/WingTool.pro b/WingTool.pro index a209efc..3827cfc 100644 --- a/WingTool.pro +++ b/WingTool.pro @@ -37,7 +37,6 @@ HEADERS += \ dialog/centerwindow.h \ dialog/toolwindow.h \ dialog/toolboxwindow.h \ - class/settings.h \ plugin/pluginsystem.h \ plugin/iwingtoolplg.h \ class/settingmanager.h \ diff --git a/class/settings.cpp b/class/settings.cpp index 27ddf83..e69de29 100644 --- a/class/settings.cpp +++ b/class/settings.cpp @@ -1,6 +0,0 @@ -#include "settings.h" - -Settings::Settings() -{ - -} diff --git a/class/settings.h b/class/settings.h deleted file mode 100644 index 9cd2454..0000000 --- a/class/settings.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SETTINGS_H -#define SETTINGS_H - - -class Settings -{ -public: - Settings(); -}; - -#endif // SETTINGS_H diff --git a/dialog/centerwindow.cpp b/dialog/centerwindow.cpp index 2a22ce3..d859ea2 100644 --- a/dialog/centerwindow.cpp +++ b/dialog/centerwindow.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,7 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { auto scview = new QScrollArea; scview->setWidget(w); auto vlayout = new QVBoxLayout(w); - + vlayout->setMargin(20); auto l = new DLabel(tr("Common"), this); auto font = this->font(); font.setUnderline(true); @@ -48,18 +49,82 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { vlayout->addWidget(l); vlayout->addSpacing(5); cbauto = new DCheckBox(tr("AutoStart"), this); - vlayout->setMargin(20); + connect(cbauto, &DCheckBox::toggled, this, [=](bool v) { + + }); vlayout->addWidget(cbauto, Qt::AlignTop); + + vlayout->addSpacing(10); + l = new DLabel(tr("Shortcut"), this); + l->setFont(font); + vlayout->addWidget(l); + vlayout->addSpacing(5); + auto gw = new QWidget(w); + 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); + auto hlayout = new QHBoxLayout(gw); + cbMod = new DComboBox(gw); + cbMod->addItems({"Ctrl", "Shift", "Alt", "Super"}); + cbMod->setCurrentIndex(0); + hlayout->addWidget(cbMod); + cbMouseBtn = new DComboBox(gw); + cbMouseBtn->addItems( + {tr("Left"), tr("Right"), tr("Middle"), tr("XButton1"), tr("XButton2")}); + cbMouseBtn->setCurrentIndex(2); + hlayout->addWidget(cbMouseBtn); + flayout->addRow(tr("ToolWin:"), hlayout); + + vlayout->addSpacing(10); + l = new DLabel(tr("Config"), this); + l->setFont(font); + vlayout->addWidget(l); + vlayout->addSpacing(5); + auto group = new DButtonBox(this); + QList blist; + auto b = new DButtonBoxButton(tr("Export"), this); + connect(b, &DButtonBoxButton::clicked, this, [=] { + + }); + blist.append(b); + b = new DButtonBoxButton(tr("Import"), this); + connect(b, &DButtonBoxButton::clicked, this, [=] { + + }); + blist.append(b); + b = new DButtonBoxButton(tr("Reset"), this); + connect(b, &DButtonBoxButton::clicked, this, [=] { + + }); + blist.append(b); + group->setButtonList(blist, false); + vlayout->addWidget(group); + + vlayout->addSpacing(10); + l = new DLabel(tr("Software"), this); + l->setFont(font); + vlayout->addWidget(l); + vlayout->addSpacing(5); + + vlayout->addWidget(new DLabel(QString(tr("%1 , Ver %2 , by WingSummer.")) + .arg(qApp->applicationName()) + .arg(qApp->applicationVersion()))); + vlayout->addStretch(); tabs->addTab(w, tr("General")); // Hotkeys w = new QWidget(this); vlayout = new QVBoxLayout(w); - auto group = new DButtonBox(this); + group = new DButtonBox(this); vlayout->setMargin(20); - QList blist; - auto b = new DButtonBoxButton(tr("Add"), this); + blist.clear(); // 征用 + b = new DButtonBoxButton(tr("Add"), this); connect(b, &DButtonBoxButton::clicked, this, &CenterWindow::on_addHotkey); blist.append(b); b = new DButtonBoxButton(tr("Remove"), this); @@ -137,7 +202,7 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) { auto tvlayout = new QVBoxLayout; auto gridsize = 40; // 默认 40 先 - auto gw = new QWidget(w); + gw = new QWidget(w); gw->setFixedSize(gridsize * 3, gridsize * 3); auto mlayout = new QGridLayout(gw); mlayout->setMargin(1); @@ -513,9 +578,42 @@ void CenterWindow::enableSelectedHotkeys(bool enable) { } } -void CenterWindow::on_editToolWin() {} +void CenterWindow::on_editToolWin() { + auto sels = lstoolwin->selectedItems().count(); + if (sels != 1) { + DMessageManager::instance()->sendMessage(this, ProgramIcon, + tr("PleaseSelectOne")); + return; + } + auto index = lstoolwin->currentRow(); + ToolEditDialog d(wintoolinfos[index]); + if (d.exec()) { + auto res = d.getResult(); + wintoolinfos[index] = res; + 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->setToolTip(res.process); + } +} -void CenterWindow::on_removeToolWin() {} +void CenterWindow::on_removeToolWin() { + auto sels = lstoolwin->selectionModel()->selectedRows(); + QVector nums; + for (auto &item : sels) { + nums.append(item.row()); + } + + std::sort(nums.begin(), nums.end(), std::greater()); + + for (auto index : nums) { + wintoolinfos.removeAt(index); + auto item = lstoolwin->takeItem(index); + delete item; + } +} void CenterWindow::on_clearToolWin() { lstoolwin->clear(); @@ -531,8 +629,19 @@ void CenterWindow::on_addToolWin() { auto index = lstoolwin->currentRow(); if (index < 0) { wintoolinfos.append(res); - + auto item = new QListWidgetItem( + Utilities::trimIconFromInfo(plgsys->plugin(res.pluginIndex), res), + res.isPlugin ? res.process : QFileInfo(res.process).fileName()); + item->setToolTip(res.process); + lstoolwin->addItem(item); } else { + wintoolinfos.insert(index + 1, res); + + auto item = new QListWidgetItem( + Utilities::trimIconFromInfo(plgsys->plugin(res.pluginIndex), res), + res.isPlugin ? res.process : QFileInfo(res.process).fileName()); + item->setToolTip(res.process); + lstoolwin->insertItem(index + 1, item); } } } diff --git a/dialog/centerwindow.h b/dialog/centerwindow.h index c2e692a..c0e365a 100644 --- a/dialog/centerwindow.h +++ b/dialog/centerwindow.h @@ -6,7 +6,9 @@ #include "plugin/pluginsystem.h" #include "utilities.h" #include +#include #include +#include #include #include #include @@ -91,6 +93,9 @@ private: DIconButton *lbls[9] = {nullptr}; + DKeySequenceEdit *kseqTool; + DComboBox *cbMod, *cbMouseBtn; + private: QMap scinfos; // 用于 Hotkeys QList hotkeys; // Hotkeys 方便进行检索 diff --git a/dialog/shortcuteditdialog.cpp b/dialog/shortcuteditdialog.cpp index ed11052..8d07483 100644 --- a/dialog/shortcuteditdialog.cpp +++ b/dialog/shortcuteditdialog.cpp @@ -109,12 +109,12 @@ void ShortCutEditDialog::on_accept() { res.provider = sel->provider(); res.pluginIndex = ps->getSelectedIndex(); } else { + res.process = fcedit->text(); if (res.process.isEmpty()) { DMessageManager::instance()->sendMessage(this, ProgramIcon, tr("NoProcessSet")); return; } - res.process = fcedit->text(); } res.params = dledit->text(); diff --git a/dialog/toolboxwindow.h b/dialog/toolboxwindow.h index 7538799..410c980 100644 --- a/dialog/toolboxwindow.h +++ b/dialog/toolboxwindow.h @@ -12,6 +12,11 @@ class ToolBoxWindow : public DDialog { public: ToolBoxWindow(DMainWindow *parent = nullptr); +signals: + void addItem(QListWidgetItem *item, int index = -1); // -1 表示追加 + void rmItem(int index); // -1 表示清空 + void mvItem(int from, int to); + private: DListWidget *lstool; }; diff --git a/dialog/tooleditdialog.cpp b/dialog/tooleditdialog.cpp index 35d3095..b445cb6 100644 --- a/dialog/tooleditdialog.cpp +++ b/dialog/tooleditdialog.cpp @@ -81,12 +81,12 @@ void ToolEditDialog::on_accept() { res.provider = sel->provider(); res.pluginIndex = ps->getSelectedIndex(); } else { + res.process = fcedit->text(); if (res.process.isEmpty()) { DMessageManager::instance()->sendMessage(this, ProgramIcon, tr("NoProcessSet")); return; } - res.process = fcedit->text(); } res.params = dledit->text(); diff --git a/main.cpp b/main.cpp index 8ccaee1..1d76fab 100644 --- a/main.cpp +++ b/main.cpp @@ -49,6 +49,7 @@ int main(int argc, char *argv[]) { a.setOrganizationName("WingCloud"); a.setApplicationName(QObject::tr("WingTool")); a.setApplicationVersion("1.0.0"); + a.setApplicationLicense("AGPL-3.0"); QIcon picon = ProgramIcon; a.setProductIcon(picon); @@ -128,8 +129,10 @@ int main(int argc, char *argv[]) { QObject::connect(&systray, &QSystemTrayIcon::activated, [&w](QSystemTrayIcon::ActivationReason reason) { - if (reason == QSystemTrayIcon::ActivationReason::Trigger) + if (reason == QSystemTrayIcon::ActivationReason::Trigger) { w.show(CenterWindow::TabPage::General); + Utilities::activeWindowFromDock(w.winId()); + } }); Dtk::Widget::moveToCenter(&w); diff --git a/utilities.h b/utilities.h index 5845e36..f8894fb 100644 --- a/utilities.h +++ b/utilities.h @@ -4,7 +4,9 @@ #include "plugin/iwingtoolplg.h" #include #include +#include #include +#include #define ProgramIcon QIcon(":/images/logo.svg") #define ICONRES(name) QIcon(":/images/" name ".png") @@ -28,14 +30,42 @@ struct ToolStructInfo { Q_DECLARE_METATYPE(ToolStructInfo) +class PluginSystem; + class Utilities { public: + static bool activeWindowFromDock(quintptr winId) { + bool bRet = true; + // new interface use application as id + QDBusInterface dockDbusInterface("com.deepin.dde.daemon.Dock", + "/com/deepin/dde/daemon/Dock", + "com.deepin.dde.daemon.Dock"); + QDBusReply reply = dockDbusInterface.call("ActivateWindow", winId); + if (!reply.isValid()) { + qDebug() << "call com.deepin.dde.daemon.Dock failed" << reply.error(); + bRet = false; + } + return bRet; + } + static QIcon processPluginIcon(IWingToolPlg *plg) { if (plg->pluginIcon().isNull()) { return ICONRES("plugin"); } return plg->pluginIcon(); } + + static QIcon trimIconFromInfo(IWingToolPlg *plg, ToolStructInfo &info) { + if (info.isPlugin) { + if (plg == nullptr) + return QIcon(); + return plg->pluginIcon(); + } else { + QMimeDatabase db; + auto t = db.mimeTypeForFile(info.process); + return QIcon::fromTheme(t.iconName(), QIcon(t.iconName())); + } + } }; #endif // UTILIES_H