Advertisement
PlotnikovPhilipp

Untitled

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