--- a/src/widgets.cpp Fri Aug 16 11:05:21 2013 +0300 +++ b/src/widgets.cpp Sat Sep 07 13:23:09 2013 +0300 @@ -1,21 +1,25 @@ /* * LDForge: LDraw parts authoring CAD * Copyright (C) 2013 Santeri Piippo - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +// I still find the radio group useful... find a way to use this in Designer. +// I probably need to look into how to make Designer plugins. +// TODO: try make this usable in Designer + #include <QBoxLayout> #include <QRadioButton> #include <QButtonGroup> @@ -24,19 +28,27 @@ #include "widgets.h" -RadioBox::RadioBox (const QString& title, QWidget* parent) : QGroupBox (title, parent) { +// ============================================================================= +// ----------------------------------------------------------------------------- +RadioGroup::RadioGroup (const QString& title, QWidget* parent) : QGroupBox (title, parent) { init (Qt::Vertical); } +// ============================================================================= +// ----------------------------------------------------------------------------- QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false) { return (orient == (invert ? Qt::Vertical : Qt::Horizontal)) ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom; } -bool RadioBox::isChecked (int n) const { +// ============================================================================= +// ----------------------------------------------------------------------------- +bool RadioGroup::isChecked (int n) const { return m_buttonGroup->checkedId() == n; } -void RadioBox::init (Qt::Orientation orient) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::init (Qt::Orientation orient) { m_vert = orient == Qt::Vertical; m_buttonGroup = new QButtonGroup; @@ -53,7 +65,9 @@ connect (m_buttonGroup, SIGNAL (buttonReleased (int)), this, SLOT (slot_buttonReleased (int))); } -RadioBox::RadioBox (const QString& title, initlist<char const*> entries, int const defaultId, +// ============================================================================= +// ----------------------------------------------------------------------------- +RadioGroup::RadioGroup (const QString& title, initlist<char const*> entries, int const defaultId, const Qt::Orientation orient, QWidget* parent) : QGroupBox (title, parent), m_defId (defaultId) { init (orient); @@ -63,7 +77,9 @@ addButton (entry); } -void RadioBox::rowBreak() { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::rowBreak() { QBoxLayout* newLayout = new QBoxLayout (m_vert ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); m_currentLayout = newLayout; m_layouts << newLayout; @@ -71,12 +87,16 @@ m_coreLayout->addLayout (newLayout); } -void RadioBox::addButton (const char* entry) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::addButton (const char* entry) { QRadioButton* button = new QRadioButton (entry); addButton (button); } -void RadioBox::addButton (QRadioButton* button) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::addButton (QRadioButton* button) { bool const selectThis = (m_curId == m_defId); m_objects << button; @@ -87,39 +107,55 @@ button->setChecked (true); } -RadioBox& RadioBox::operator<< (QRadioButton* button) { +// ============================================================================= +// ----------------------------------------------------------------------------- +RadioGroup& RadioGroup::operator<< (QRadioButton* button) { addButton (button); return *this; } -RadioBox& RadioBox::operator<< (const char* entry) { +// ============================================================================= +// ----------------------------------------------------------------------------- +RadioGroup& RadioGroup::operator<< (const char* entry) { addButton (entry); return *this; } -void RadioBox::setCurrentRow (uint row) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::setCurrentRow (uint row) { m_currentLayout = m_layouts[row]; } -int RadioBox::value() const { +// ============================================================================= +// ----------------------------------------------------------------------------- +int RadioGroup::value() const { return m_buttonGroup->checkedId(); } -void RadioBox::setValue (int val) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::setValue (int val) { m_buttonGroup->button (val)->setChecked (true); } -QRadioButton* RadioBox::operator[] (uint n) const { +// ============================================================================= +// ----------------------------------------------------------------------------- +QRadioButton* RadioGroup::operator[] (uint n) const { return m_objects[n]; } -void RadioBox::slot_buttonPressed (int btn) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::slot_buttonPressed (int btn) { emit buttonPressed (btn); m_oldId = m_buttonGroup->checkedId(); } -void RadioBox::slot_buttonReleased (int btn) { +// ============================================================================= +// ----------------------------------------------------------------------------- +void RadioGroup::slot_buttonReleased (int btn) { emit buttonReleased (btn); int newid = m_buttonGroup->checkedId(); @@ -127,12 +163,14 @@ emit valueChanged (newid); } -RadioBox::it RadioBox::begin() { +// ============================================================================= +// ----------------------------------------------------------------------------- +RadioGroup::it RadioGroup::begin() { return m_objects.begin(); } -RadioBox::it RadioBox::end() { +// ============================================================================= +// ----------------------------------------------------------------------------- +RadioGroup::it RadioGroup::end() { return m_objects.end(); -} - -#include "build/moc_widgets.cpp" \ No newline at end of file +} \ No newline at end of file