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.1");
  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. bool autostart = !settings->value(MY_APP_NAME).toString().isEmpty();
  20. action_autostart->setData(autostart);
  21. action_autostart->setIcon(autostart ? icon_check_true : icon_check_false);
  22. set_mode(config.getMode());
  23. tray_icon->setIcon(tray_icon_off);
  24. tray_icon->setContextMenu(menu);
  25. tray_icon->show();
  26. ss->moveToThread(ss);
  27. ss->start();
  28. mode->moveToThread(mode);
  29. connect(ss, &StatusShow::status, this, &NumLockManager::getStatus);
  30. connect(tray_icon, &QSystemTrayIcon::activated, this, &NumLockManager::icon_activated);
  31. connect(action_exit, &QAction::triggered, this, &QApplication::quit);
  32. connect(menu, &QMenu::triggered, this, &NumLockManager::set_menu_hz);
  33. }
  34. void NumLockManager::getStatus(bool status)
  35. {
  36. tray_icon->setIcon( status ? tray_icon_on : tray_icon_off );
  37. setWindowIcon( status ? tray_icon_on : tray_icon_off );
  38. }
  39. void NumLockManager::set_menu_hz(QAction *action)
  40. {
  41. for (int i = 0; i < 3; i++)
  42. if (action == actions_mode[i]) set_mode(i);
  43. if (action == action_autostart){
  44. bool data = action_autostart->data().toBool();
  45. action_autostart->setIcon( data ? icon_check_false : icon_check_true);
  46. action_autostart->setData( !data );
  47. data ? settings->remove(MY_APP_NAME) : settings->setValue(MY_APP_NAME, MY_APP_PATH);
  48. settings->sync();
  49. }
  50. if (action == action_about) showNormal();
  51. }
  52. void NumLockManager::set_mode(int index)
  53. {
  54. mode->setMode(index);
  55. config.setMode(index);
  56. for (int i = 0; i < 3; i++)
  57. actions_mode[i]->setIcon((i == index) ? icon_radio_true : icon_radio_false);
  58. if (index > 0)
  59. mode->start();
  60. }