numlockmanager.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "numlockmanager.h"
  2. #include "ui_numlockmanager.h"
  3. NumLockManager::NumLockManager(QWidget *parent)
  4. : QMainWindow(parent)
  5. , ui(new Ui::NumLockManager)
  6. {
  7. ui->setupUi(this);
  8. setWindowTitle("NumLockManager V1.3");
  9. setFixedSize(490, 170);
  10. setWindowIcon(tray_icon_on);
  11. setWindowFlags(Qt::WindowCloseButtonHint);
  12. QString texts[6] = {"автозапуск", "ввімк/Вимк", "лише ввімк", "лише вимк", "про програму" , "закрити програму"};
  13. for (int i = 0; i < 6; i++){
  14. actions[i]->setText(texts[i]);
  15. menu->addAction(actions[i]);
  16. if (i == 0 || i == 3) menu->addSeparator();
  17. if (i == 0) menu->addAction(" Режим");
  18. }
  19. action_autostart->setData(autostart->status());
  20. action_autostart->setIcon(autostart->status() ? icon_check_true : icon_check_false);
  21. set_mode(config.getMode());
  22. tray_icon->setIcon(tray_icon_off);
  23. tray_icon->setContextMenu(menu);
  24. tray_icon->show();
  25. ss->moveToThread(ss);
  26. ss->start();
  27. mode->moveToThread(mode);
  28. connect(ss, &StatusShow::status, this, &NumLockManager::getStatus);
  29. connect(tray_icon, &QSystemTrayIcon::activated, this, &NumLockManager::icon_activated);
  30. connect(action_exit, &QAction::triggered, this, &QApplication::quit);
  31. connect(menu, &QMenu::triggered, this, &NumLockManager::set_menu_hz);
  32. }
  33. void NumLockManager::getStatus(bool status)
  34. {
  35. tray_icon->setIcon( status ? tray_icon_on : tray_icon_off );
  36. setWindowIcon( status ? tray_icon_on : tray_icon_off );
  37. }
  38. void NumLockManager::set_menu_hz(QAction *action)
  39. {
  40. for (int i = 0; i < 3; i++)
  41. if (action == actions_mode[i]) set_mode(i);
  42. if (action == action_autostart){
  43. bool data = action_autostart->data().toBool();
  44. action_autostart->setIcon( data ? icon_check_false : icon_check_true);
  45. action_autostart->setData( !data );
  46. autostart->switch_();
  47. // data ? settings->remove(MY_APP_NAME) : settings->setValue(MY_APP_NAME, MY_APP_PATH);
  48. }
  49. if (action == action_about) showNormal();
  50. }
  51. void NumLockManager::set_mode(int index)
  52. {
  53. mode->setMode(index);
  54. config.setMode(index);
  55. for (int i = 0; i < 3; i++)
  56. actions_mode[i]->setIcon((i == index) ? icon_radio_true : icon_radio_false);
  57. if (index > 0)
  58. mode->start();
  59. }