Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file groupboxcollapse.h
- * @brief Define a collapseable groupbox widget.
- * @copyright
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author N. Neumann <vatriani[dot}nn[at?googlemail[dot}com>
- * @version 1.0
- */
- /**
- * @addtogroup GUIW Custom GUI widgets
- * @{
- */
- #ifndef GROUPBOXCOLLAPSE_H
- #define GROUPBOXCOLLAPSE_H
- #include <QWidget>
- #include <QGroupBox>
- #include <QMouseEvent>
- /**
- * @brief Implements collapseable GroupBox.
- *
- * Simply adding collapseable to a QGroupBox with custom markers like TreeView.
- * Checkability is needed for the indicators.
- *
- * @warning The checkable is sacrifice for collapse.
- */
- class groupBoxCollapse : public QGroupBox
- {
- Q_OBJECT
- public:
- /**
- * @brief Default constructor.
- *
- * Sets variables to enable checkability and collapseability.
- */
- explicit groupBoxCollapse(QWidget *parent = 0);
- /**
- * @brief Is triggered by expandig GroupBox.
- *
- * At now its recommend to add your widgets visability here in your class.
- * Sets to true;
- */
- virtual void expand();
- /**
- * @brief Is triggered by collapsing GroupBox.
- *
- * At now its recommend to add your widgets visability here in your class.
- * Sets to false.
- */
- virtual void collapse();
- signals:
- /**
- * @brief Is emitted by collapse changes.
- *
- * For using in QtDesigner as signal handler.
- */
- void CollapseToggle(bool);
- private:
- /**
- * @brief Helper routine to determine if GroupBox is collapse or expanding.
- */
- void change();
- /**
- * @brief Reimplement the OnClick on the title for collapse.
- */
- void mouseReleaseEvent(QMouseEvent*);
- /**
- * @brief Holds the collapse state of the GroupBox.
- */
- bool isCollapse;
- };
- #endif // GROUPBOXCOLLAPSE_H
- /**
- * @}
- */
- /**
- * @file groupboxcollapse.cpp
- * @brief Define a collapseable groupbox widget.
- * @copyright
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author N. Neumann <vatriani[dot}nn[at?googlemail[dot}com>
- * @version 1.0
- */
- #include <QIcon>
- #include "groupboxcollapse.h"
- groupBoxCollapse::groupBoxCollapse(QWidget *parent) :
- QGroupBox(parent)
- {
- this->setCheckable(true);
- this->isCollapse = false;
- change();
- }
- void groupBoxCollapse::mouseReleaseEvent(QMouseEvent *event)
- {
- if(event->button() == Qt::LeftButton)
- {
- this->isCollapse = !this->isCollapse;
- change();
- }
- event->accept();
- }
- void groupBoxCollapse::change()
- {
- if(this->isCollapse)
- {
- emit CollapseToggle(false);
- collapse();
- this->setStyleSheet("QGroupBox::indicator:checked { image: url(:/); } QGroupBox { border: 0px; border-radius: 0px; }");
- }
- else
- {
- emit CollapseToggle(true);
- expand();
- this->setStyleSheet("QGroupBox::indicator:checked { image: url(:/); }");
- }
- }
- void groupBoxCollapse::expand()
- {
- }
- void groupBoxCollapse::collapse()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement