File indexing completed on 2024-09-15 13:04:47
0001 /************************************************************************* 0002 * Copyright (C) 2007 by Romain Campioni * 0003 * Copyright (C) 2009 by Renaud Guezennec * 0004 * Copyright (C) 2011 by Joseph Boudou * 0005 * * 0006 * https://rolisteam.org/ * 0007 * * 0008 * Rolisteam is free software; you can redistribute it and/or modify * 0009 * it under the terms of the GNU General Public License as published * 0010 * by the Free Software Foundation; either version 2 of the License, * 0011 * or (at your option) any later version. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, * 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0016 * GNU General Public License for more details. * 0017 * * 0018 * You should have received a copy of the GNU General Public License * 0019 * along with this program; if not, write to the * 0020 * Free Software Foundation, Inc., * 0021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0022 *************************************************************************/ 0023 0024 #include <QFrame> 0025 #include <QVBoxLayout> 0026 0027 #include "rwidgets/customs/diameterselector.h" 0028 0029 #include "rwidgets/customs/circledisplayer.h" 0030 0031 #define DEFAULT_ICON_SIZE 20 0032 /********************************************************************/ 0033 /* Constructeur */ 0034 /********************************************************************/ 0035 DiameterSelector::DiameterSelector(QWidget* parent, bool plein, int min, int max) : QWidget(parent) 0036 { 0037 // Initialisation des minimum et maximum 0038 minimum= min; 0039 maximum= max; 0040 0041 // Creation du layout 0042 QVBoxLayout* layout= new QVBoxLayout(this); 0043 layout->setContentsMargins(QMargins()); 0044 0045 // Creation du QFrame qui va contenir l'afficheur de disque 0046 QFrame* frame= new QFrame(this); 0047 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken); 0048 frame->setLineWidth(2); 0049 frame->setMidLineWidth(2); 0050 frame->setFixedHeight(DEFAULT_ICON_SIZE * 2 + 12); 0051 frame->setMaximumWidth(DEFAULT_ICON_SIZE * 2 + 12); 0052 0053 // Creation du layout du QFrame 0054 QVBoxLayout* frameLayout= new QVBoxLayout(frame); 0055 frameLayout->setContentsMargins(QMargins()); 0056 0057 // Creation de l'afficheur de disque 0058 m_circle= new CircleDisplayer(frame, plein, minimum, maximum); 0059 m_circle->changeDiameter(minimum); 0060 0061 // Ajout de l'afficheur de disque au layout du QFrame 0062 frameLayout->addWidget(m_circle); 0063 0064 // Ajout du QFrame contenant l'afficheur de disque au layout 0065 layout->addWidget(frame); 0066 layout->setAlignment(m_circle, Qt::AlignCenter); 0067 0068 m_diameterSlider= new QSlider(Qt::Horizontal, this); 0069 m_diameterSlider->setRange(minimum, maximum); 0070 m_diameterSlider->setValue(minimum); 0071 m_diameterSlider->setTracking(false); 0072 0073 layout->addWidget(m_diameterSlider); 0074 0075 connect(m_diameterSlider, SIGNAL(sliderMoved(int)), m_circle, SLOT(changeDiameter(int))); 0076 connect(m_diameterSlider, SIGNAL(sliderMoved(int)), this, SIGNAL(diameterChanged(int))); 0077 } 0078 0079 void DiameterSelector::setDiameter(int diameter) 0080 { 0081 if(diameter < minimum) 0082 { 0083 diameter= minimum; 0084 } 0085 else if(diameter > maximum) 0086 { 0087 diameter= maximum; 0088 } 0089 0090 m_diameterSlider->setValue(diameter); 0091 m_circle->changeDiameter(diameter); 0092 } 0093 int DiameterSelector::getCurrentValue() const 0094 { 0095 return m_diameterSlider->value(); 0096 }