Advertisement
Guest User

Untitled

a guest
Aug 17th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.02 KB | None | 0 0
  1. /**
  2.  * @file groupboxcollapse.h
  3.  * @brief Define a collapseable groupbox widget.
  4.  * @copyright
  5.  * This program is free software: you can redistribute it and/or modify
  6.  * it under the terms of the GNU Lesser General Public License as published by
  7.  * the Free Software Foundation, either version 3 of the License, or
  8.  * any later version.
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU Lesser General Public License for more details.
  13.  * You should have received a copy of the GNU Lesser General Public License
  14.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  *
  16.  * @author  N. Neumann <vatriani[dot}nn[at?googlemail[dot}com>
  17.  * @version 1.0
  18.  */
  19.  
  20. /**
  21.  * @addtogroup GUIW Custom GUI widgets
  22.  * @{
  23.  */
  24.  
  25. #ifndef GROUPBOXCOLLAPSE_H
  26. #define GROUPBOXCOLLAPSE_H
  27.  
  28. #include <QWidget>
  29. #include <QGroupBox>
  30. #include <QMouseEvent>
  31.  
  32. /**
  33.  * @brief Implements collapseable GroupBox.
  34.  *
  35.  * Simply adding collapseable to a QGroupBox with custom markers like TreeView.
  36.  * Checkability is needed for the indicators.
  37.  *
  38.  * @warning The checkable is sacrifice for collapse.
  39.  */
  40. class groupBoxCollapse : public QGroupBox
  41. {
  42.     Q_OBJECT
  43. public:
  44.     /**
  45.      * @brief Default constructor.
  46.      *
  47.      * Sets variables to enable checkability and collapseability.
  48.      */
  49.     explicit groupBoxCollapse(QWidget *parent = 0);
  50.  
  51.     /**
  52.      * @brief Is triggered by expandig GroupBox.
  53.      *
  54.      * At now its recommend to add your widgets visability here in your class.
  55.      * Sets to true;
  56.      */
  57.     virtual void expand();
  58.     /**
  59.      * @brief Is triggered by collapsing GroupBox.
  60.      *
  61.      * At now its recommend to add your widgets visability here in your class.
  62.      * Sets to false.
  63.      */
  64.     virtual void collapse();
  65.  
  66. signals:
  67.     /**
  68.      * @brief Is emitted by collapse changes.
  69.      *
  70.      * For using in QtDesigner as signal handler.
  71.      */    
  72.     void CollapseToggle(bool);
  73.  
  74. private:
  75.     /**
  76.      * @brief Helper routine to determine if GroupBox is collapse or expanding.
  77.      */
  78.     void change();
  79.     /**
  80.      * @brief Reimplement the OnClick on the title for collapse.
  81.      */
  82.     void mouseReleaseEvent(QMouseEvent*);
  83.  
  84.     /**
  85.      * @brief Holds the collapse state of the GroupBox.
  86.      */
  87.     bool isCollapse;
  88. };
  89.  
  90. #endif // GROUPBOXCOLLAPSE_H
  91. /**
  92.  * @}
  93.  */
  94.  
  95. /**
  96.  * @file groupboxcollapse.cpp
  97.  * @brief Define a collapseable groupbox widget.
  98.  * @copyright
  99.  * This program is free software: you can redistribute it and/or modify
  100.  * it under the terms of the GNU Lesser General Public License as published by
  101.  * the Free Software Foundation, either version 3 of the License, or
  102.  * any later version.
  103.  * This program is distributed in the hope that it will be useful,
  104.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  105.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  106.  * GNU Lesser General Public License for more details.
  107.  * You should have received a copy of the GNU Lesser General Public License
  108.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  109.  *
  110.  * @author  N. Neumann <vatriani[dot}nn[at?googlemail[dot}com>
  111.  * @version 1.0
  112.  */
  113.  
  114. #include <QIcon>
  115.  
  116. #include "groupboxcollapse.h"
  117.  
  118. groupBoxCollapse::groupBoxCollapse(QWidget *parent) :
  119.     QGroupBox(parent)
  120. {
  121.     this->setCheckable(true);
  122.     this->isCollapse = false;
  123.  
  124.     change();
  125. }
  126.  
  127. void groupBoxCollapse::mouseReleaseEvent(QMouseEvent *event)
  128. {
  129.     if(event->button() == Qt::LeftButton)
  130.     {
  131.         this->isCollapse = !this->isCollapse;
  132.         change();
  133.     }
  134.     event->accept();
  135. }
  136.  
  137. void groupBoxCollapse::change()
  138. {
  139.     if(this->isCollapse)
  140.     {
  141.         emit CollapseToggle(false);
  142.         collapse();
  143.         this->setStyleSheet("QGroupBox::indicator:checked { image: url(:/); } QGroupBox { border: 0px; border-radius: 0px; }");
  144.     }
  145.     else
  146.     {
  147.         emit CollapseToggle(true);
  148.         expand();
  149.         this->setStyleSheet("QGroupBox::indicator:checked { image: url(:/); }");
  150.     }
  151. }
  152.  
  153. void groupBoxCollapse::expand()
  154. {
  155.  
  156. }
  157.  
  158. void groupBoxCollapse::collapse()
  159. {
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement