ArkApplication.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "ArkApplication.h"
  2. #include <QDebug>
  3. #include <QStringList>
  4. #include <QTranslator>
  5. #include <QTimer>
  6. #include <time.h>
  7. class ArkApplicationPrivate
  8. {
  9. Q_DISABLE_COPY(ArkApplicationPrivate)
  10. public:
  11. explicit ArkApplicationPrivate(int &argc, char **argv, ArkApplication* parent);
  12. ~ArkApplicationPrivate();
  13. QStringList m_Arguments;
  14. void initializeTranslator();
  15. QTranslator* m_Translator;
  16. QTimer* m_Timer;
  17. private:
  18. ArkApplication* m_Parent;
  19. };
  20. ArkApplication::ArkApplication(int &argc, char **argv)
  21. : QGuiApplication(argc, argv)
  22. , m_Private(new ArkApplicationPrivate(argc, argv, this))
  23. {
  24. m_Private->initializeTranslator();
  25. }
  26. ArkApplication::~ArkApplication()
  27. {
  28. }
  29. bool ArkApplication::installTranslatorPath(const QString &path)
  30. {
  31. bool ret(false);
  32. if (NULL != m_Private->m_Translator) {
  33. ret = m_Private->m_Translator->load(path);
  34. if (ret) {
  35. installTranslator(m_Private->m_Translator);
  36. }
  37. }
  38. return ret;
  39. }
  40. int ArkApplication::size() const
  41. {
  42. return m_Private->m_Arguments.size();
  43. }
  44. QStringList ArkApplication::arguments() const
  45. {
  46. return m_Private->m_Arguments;
  47. }
  48. void ArkApplication::startTimer(const int second)
  49. {
  50. if (NULL == m_Private->m_Timer) {
  51. m_Private->m_Timer = new QTimer(this);
  52. m_Private->m_Timer->setSingleShot(false);
  53. m_Private->m_Timer->start(second * 1000);
  54. Qt::ConnectionType type = static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::AutoConnection);
  55. QObject::connect(m_Private->m_Timer, SIGNAL(timeout()),
  56. this, SLOT(onTimeout()),
  57. type);
  58. }
  59. }
  60. void ArkApplication::onTimeout()
  61. {
  62. emit currentDateTime(QDateTime::currentDateTime());
  63. }
  64. void ArkApplication::resetTimer(const int second)
  65. {
  66. if(NULL != m_Private->m_Timer)
  67. {
  68. m_Private->m_Timer->stop();
  69. m_Private->m_Timer->setSingleShot(false);
  70. m_Private->m_Timer->start(second * 1000);
  71. }
  72. }
  73. void ArkApplication::setCurrentTime(const QDateTime dateTime)
  74. {
  75. emit currentDateTime(dateTime);
  76. }
  77. ArkApplicationPrivate::ArkApplicationPrivate(int &argc, char **argv, ArkApplication* parent)
  78. : m_Parent(parent)
  79. {
  80. m_Translator = NULL;
  81. m_Timer = NULL;
  82. for (int i = 0; i < argc; ++i) {
  83. m_Arguments << QString(argv[i]);
  84. }
  85. }
  86. ArkApplicationPrivate::~ArkApplicationPrivate()
  87. {
  88. }
  89. void ArkApplicationPrivate::initializeTranslator()
  90. {
  91. if (NULL == m_Translator) {
  92. m_Translator = new QTranslator(m_Parent);
  93. }
  94. }