File indexing completed on 2024-05-19 16:43:48

0001 /***************************************************************************
0002  *  Copyright (C) 2007 by Romain Campioni                  *
0003  *  Copyright (C) 2009 by Renaud Guezennec                             *
0004  *   https://rolisteam.org/contact                   *
0005  *                                                                         *
0006  *   rolisteam is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, write to the                         *
0018  *   Free Software Foundation, Inc.,                                       *
0019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0020  ***************************************************************************/
0021 #include <QDebug>
0022 #include <QtGui>
0023 
0024 #include "customs/circledisplayer.h"
0025 
0026 #define MARGIN_NPC 10
0027 #define MARGIN_PC 5
0028 #define PEN_SIZE 4
0029 
0030 CircleDisplayer::CircleDisplayer(QWidget* parent, bool filled, int minimum, int maximum) : QWidget(parent)
0031 {
0032     m_currentDiameter= minimum;
0033     m_minimumDiameter= minimum;
0034     m_maximumDiameter= maximum;
0035 
0036     m_full= filled;
0037 }
0038 
0039 void CircleDisplayer::paintEvent(QPaintEvent* event)
0040 {
0041     Q_UNUSED(event)
0042     int displayedDiameter;
0043     QPainter painter(this);
0044     painter.setRenderHint(QPainter::Antialiasing, true);
0045     if(m_full)
0046     {
0047         painter.setPen(Qt::NoPen);
0048         painter.setBrush(Qt::black);
0049         displayedDiameter= m_currentDiameter;
0050     }
0051     else
0052     {
0053         QPen pen(Qt::black);
0054         pen.setWidth(4);
0055         painter.setPen(pen);
0056         painter.setBrush(Qt::white);
0057         displayedDiameter= m_currentDiameter - m_minimumDiameter + 1;
0058     }
0059     painter.drawEllipse((width() - m_currentDiameter) / 2, (height() - m_currentDiameter) / 2, m_currentDiameter,
0060                         m_currentDiameter);
0061     painter.setPen(Qt::darkGray);
0062     painter.drawText(0, 0, width(), height(), Qt::AlignRight | Qt::AlignBottom, QString::number(displayedDiameter));
0063 }
0064 void CircleDisplayer::wheelEvent(QWheelEvent* event)
0065 {
0066     auto step= event->angleDelta().y() / 8;
0067     if(step + m_currentDiameter > m_maximumDiameter)
0068         m_currentDiameter= m_maximumDiameter;
0069     else if(step + m_currentDiameter < m_minimumDiameter)
0070         m_currentDiameter= 0;
0071     else
0072         m_currentDiameter+= step;
0073     emit diameterChanged(m_currentDiameter);
0074     update();
0075 }
0076 void CircleDisplayer::changeDiameter(int diameter)
0077 {
0078     m_currentDiameter= diameter;
0079     update();
0080 }