Advertisement
PlotnikovPhilipp

Untitled

Mar 28th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. #include "secondScreen.hpp"
  2.  
  3. SecondScreen::SecondScreen(QStackedWidget* swgt, SecondScreen* pointer) :QScrollArea(pointer) {
  4.  
  5. /**
  6. * Install the fixed size for scroll widget of second screen
  7. */
  8.  
  9. this->setFixedSize(QApplication::desktop()->availableGeometry(swgt).width(), QApplication::desktop()->availableGeometry(swgt).height());
  10. this->setHorizontalScrollBarPolicy(ScrollBarAlwaysOff);
  11. this->verticalScrollBar()->setStyleSheet(QString("QScrollBar:vertical {"
  12. " border: none;"
  13. " background-color: rgba(40, 40, 40, 0.4);"
  14. " width: 13px;"
  15. " margin: 0px 0px 0px 0px;"
  16. "}"
  17. "QScrollBar::handle {"
  18. " background: #000000;"
  19. " border: none;"
  20. " border-radius: 6px;"
  21. "}"
  22. "QScrollBar::add-line:vertical {"
  23. " height: 0px;"
  24. "}"
  25. "QScrollBar::sub-line:vertical {"
  26. " height: 0px;"
  27. "}"));
  28.  
  29. /**
  30. * Install the fixed size for scroll widget of second screen
  31. */
  32.  
  33. QWidget* wgt = new QWidget;
  34.  
  35. /**
  36. * Create the needing objects for second screen
  37. */
  38.  
  39. WidgetOfSecondScreen* widgetOfSecondScreen = new WidgetOfSecondScreen(this);
  40. WidgetOfSecondScreen* widgetOfSecondScreen2 = new WidgetOfSecondScreen(this);
  41. WidgetOfSecondScreen* widgetOfSecondScreen3 = new WidgetOfSecondScreen(this);
  42. WidgetOfSecondScreen* widgetOfSecondScreen4 = new WidgetOfSecondScreen(this);
  43. WidgetOfSecondScreen* widgetOfSecondScreen5 = new WidgetOfSecondScreen(this);
  44. WidgetOfSecondScreen* widgetOfSecondScreen6 = new WidgetOfSecondScreen(this);
  45. WidgetOfSecondScreen* widgetOfSecondScreen7 = new WidgetOfSecondScreen(this);
  46. WidgetOfSecondScreen* widgetOfSecondScreen8 = new WidgetOfSecondScreen(this);
  47. WidgetOfSecondScreen* widgetOfSecondScreen9 = new WidgetOfSecondScreen(this);
  48.  
  49. /**
  50. * Create the layout of second screen
  51. */
  52.  
  53. QVBoxLayout* pvbox = new QVBoxLayout;
  54. pvbox->setContentsMargins(0, 0, 0, 0);
  55. pvbox->setSpacing(0);
  56. pvbox->addWidget(widgetOfSecondScreen);
  57. pvbox->addWidget(widgetOfSecondScreen2);
  58. pvbox->addWidget(widgetOfSecondScreen3);
  59. pvbox->addWidget(widgetOfSecondScreen4);
  60. pvbox->addWidget(widgetOfSecondScreen5);
  61. pvbox->addWidget(widgetOfSecondScreen6);
  62. pvbox->addWidget(widgetOfSecondScreen7);
  63. pvbox->addWidget(widgetOfSecondScreen8);
  64. pvbox->addWidget(widgetOfSecondScreen9);
  65. pvbox->setAlignment(AlignTop);
  66.  
  67. /**
  68. * Install the created layout to main widget of second screen
  69. */
  70.  
  71. wgt->setLayout(pvbox);
  72.  
  73. /**
  74. * Install the main widget of second screen to scroll widget of second screen
  75. */
  76.  
  77. this->setWidget(wgt);
  78. this->viewport()->setAttribute(WA_AcceptTouchEvents);
  79.  
  80. /**
  81. * Create the machine of states
  82. */
  83.  
  84. pmch = new QStateMachine;
  85.  
  86. /**
  87. * Create the 2 states of scrollbar
  88. */
  89.  
  90. QState* pstateOff = new QState(pmch);
  91. pstateOff->assignProperty(this->verticalScrollBar(), "windowOpacity", 0.0);
  92. pmch->setInitialState(pstateOff);
  93.  
  94. QState* pstateOn = new QState(pmch);
  95. pstateOn->assignProperty(this->verticalScrollBar(), "windowOpacity", 1.0);
  96.  
  97. /**
  98. * Create the signal transition between 2 states
  99. */
  100.  
  101. QSignalTransition* psignal1 = pstateOff->addTransition(this, SIGNAL(scrolling()), pstateOn);
  102. QSignalTransition* psignal2 = pstateOn->addTransition(this, SIGNAL(stopScrolling()), pstateOff);
  103.  
  104. /**
  105. * Add animation to transition
  106. */
  107.  
  108. QPropertyAnimation* panim1 = new QPropertyAnimation(this->verticalScrollBar(), "windowOpacity");
  109. psignal1->addAnimation(panim1);
  110.  
  111. QPropertyAnimation* panim2 = new QPropertyAnimation(this->verticalScrollBar(), "windowOpacity");
  112. psignal2->addAnimation(panim2);
  113.  
  114. /**
  115. * Launch the state machine
  116. */
  117.  
  118. pmch->start();
  119. }
  120.  
  121. /**
  122. * Create the handler of touch events
  123. */
  124.  
  125. bool SecondScreen::viewportEvent(QEvent* event) {
  126. if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
  127. emit scrolling();
  128. listOfTouches << static_cast<QTouchEvent*>(event)->touchPoints().first();
  129. if (listOfTouches.count() == 2) {
  130. this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + int(listOfTouches[0].pos().y()-listOfTouches[1].pos().y()));
  131. listOfTouches.clear();
  132. }
  133. else if (event->type() == QEvent::TouchEnd && listOfTouches.count() != 0) {
  134. listOfTouches.clear();
  135. emit stopScrolling();
  136. }
  137. }
  138. return true;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement