"Fossies" - the Fresh Open Source Software Archive

Member "labplot-2.8.2/src/backend/worksheet/plots/cartesian/Symbol.cpp" (24 Feb 2021, 6441 Bytes) of package /linux/privat/labplot-2.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Symbol.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8.1_vs_2.8.2.

    1 /***************************************************************************
    2     File                 : Symbol.cpp
    3     Project              : LabPlot
    4     Description          : Symbol
    5     --------------------------------------------------------------------
    6     Copyright            : (C) 2015-2020 Alexander Semke (alexander.semke@web.de)
    7 
    8  ***************************************************************************/
    9 
   10 /***************************************************************************
   11  *                                                                         *
   12  *  This program is free software; you can redistribute it and/or modify   *
   13  *  it under the terms of the GNU General Public License as published by   *
   14  *  the Free Software Foundation; either version 2 of the License, or      *
   15  *  (at your option) any later version.                                    *
   16  *                                                                         *
   17  *  This program is distributed in the hope that it will be useful,        *
   18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
   19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
   20  *  GNU General Public License for more details.                           *
   21  *                                                                         *
   22  *   You should have received a copy of the GNU General Public License     *
   23  *   along with this program; if not, write to the Free Software           *
   24  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
   25  *   Boston, MA  02110-1301  USA                                           *
   26  *                                                                         *
   27  ***************************************************************************/
   28 
   29 /*!
   30   \class Symbol
   31   \brief
   32 
   33   \ingroup worksheet
   34 */
   35 
   36 #include "Symbol.h"
   37 #include <KLocalizedString>
   38 
   39 int Symbol::stylesCount() {
   40     return 19;
   41 }
   42 
   43 QPainterPath Symbol::pathFromStyle(Symbol::Style style) {
   44     QPainterPath path;
   45     QPolygonF polygon;
   46     if (style == Style::Circle) {
   47         path.addEllipse(QPoint(0,0), 0.5, 0.5);
   48     } else if (style == Style::Square) {
   49         path.addRect(QRectF(- 0.5, -0.5, 1.0, 1.0));
   50     } else if (style == Style::EquilateralTriangle) {
   51         polygon<<QPointF(-0.5, 0.5)<<QPointF(0, -0.5)<<QPointF(0.5, 0.5)<<QPointF(-0.5, 0.5);
   52         path.addPolygon(polygon);
   53     } else if (style == Style::RightTriangle) {
   54         polygon<<QPointF(-0.5, -0.5)<<QPointF(0.5, 0.5)<<QPointF(-0.5, 0.5)<<QPointF(-0.5, -0.5);
   55         path.addPolygon(polygon);
   56     } else if (style == Style::Bar) {
   57         path.addRect(QRectF(- 0.5, -0.2, 1.0, 0.4));
   58     } else if (style == Style::PeakedBar) {
   59         polygon<<QPointF(-0.5, 0)<<QPointF(-0.3, -0.2)<<QPointF(0.3, -0.2)<<QPointF(0.5, 0)
   60                 <<QPointF(0.3, 0.2)<<QPointF(-0.3, 0.2)<<QPointF(-0.5, 0);
   61         path.addPolygon(polygon);
   62     } else if (style == Style::SkewedBar) {
   63         polygon<<QPointF(-0.5, 0.2)<<QPointF(-0.2, -0.2)<<QPointF(0.5, -0.2)<<QPointF(0.2, 0.2)<<QPointF(-0.5, 0.2);
   64         path.addPolygon(polygon);
   65     } else if (style == Style::Diamond) {
   66         polygon<<QPointF(-0.5, 0)<<QPointF(0, -0.5)<<QPointF(0.5, 0)<<QPointF(0, 0.5)<<QPointF(-0.5, 0);
   67         path.addPolygon(polygon);
   68     } else if (style == Style::Lozenge) {
   69         polygon<<QPointF(-0.25, 0)<<QPointF(0, -0.5)<<QPointF(0.25, 0)<<QPointF(0, 0.5)<<QPointF(-0.25, 0);
   70         path.addPolygon(polygon);
   71     } else if (style == Style::Tie) {
   72         polygon<<QPointF(-0.5, -0.5)<<QPointF(0.5, -0.5)<<QPointF(-0.5, 0.5)<<QPointF(0.5, 0.5)<<QPointF(-0.5, -0.5);
   73         path.addPolygon(polygon);
   74     } else if (style == Style::TinyTie) {
   75         polygon<<QPointF(-0.2, -0.5)<<QPointF(0.2, -0.5)<<QPointF(-0.2, 0.5)<<QPointF(0.2, 0.5)<<QPointF(-0.2, -0.5);
   76         path.addPolygon(polygon);
   77     } else if (style == Style::Plus) {
   78         polygon<<QPointF(-0.2, -0.5)<<QPointF(0.2, -0.5)<<QPointF(0.2, -0.2)<<QPointF(0.5, -0.2)<<QPointF(0.5, 0.2)
   79                 <<QPointF(0.2, 0.2)<<QPointF(0.2, 0.5)<<QPointF(-0.2, 0.5)<<QPointF(-0.2, 0.2)<<QPointF(-0.5, 0.2)
   80                 <<QPointF(-0.5, -0.2)<<QPointF(-0.2, -0.2)<<QPointF(-0.2, -0.5);
   81         path.addPolygon(polygon);
   82     } else if (style == Style::Boomerang) {
   83         polygon<<QPointF(-0.5, 0.5)<<QPointF(0, -0.5)<<QPointF(0.5, 0.5)<<QPointF(0, 0)<<QPointF(-0.5, 0.5);
   84         path.addPolygon(polygon);
   85     } else if (style == Style::SmallBoomerang) {
   86         polygon<<QPointF(-0.3, 0.5)<<QPointF(0, -0.5)<<QPointF(0.3, 0.5)<<QPointF(0, 0)<<QPointF(-0.3, 0.5);
   87         path.addPolygon(polygon);
   88     } else if (style == Style::Star4) {
   89         polygon<<QPointF(-0.5, 0)<<QPointF(-0.1, -0.1)<<QPointF(0, -0.5)<<QPointF(0.1, -0.1)<<QPointF(0.5, 0)
   90                 <<QPointF(0.1, 0.1)<<QPointF(0, 0.5)<<QPointF(-0.1, 0.1)<<QPointF(-0.5, 0);
   91         path.addPolygon(polygon);
   92     } else if (style == Style::Star5) {
   93         polygon<<QPointF(-0.5, 0)<<QPointF(-0.1, -0.1)<<QPointF(0, -0.5)<<QPointF(0.1, -0.1)<<QPointF(0.5, 0)
   94                 <<QPointF(0.1, 0.1)<<QPointF(0.5, 0.5)<<QPointF(0, 0.2)<<QPointF(-0.5, 0.5)
   95                 <<QPointF(-0.1, 0.1)<<QPointF(-0.5, 0);
   96         path.addPolygon(polygon);
   97     } else if (style == Style::Line) {
   98         path = QPainterPath(QPointF(0, -0.5));
   99         path.lineTo(0, 0.5);
  100     } else if (style == Style::Cross) {
  101         path = QPainterPath(QPointF(0, -0.5));
  102         path.lineTo(0, 0.5);
  103         path.moveTo(-0.5, 0);
  104         path.lineTo(0.5, 0);
  105     }
  106 
  107     return path;
  108 }
  109 
  110 QString Symbol::nameFromStyle(Symbol::Style style) {
  111     QString name;
  112     //TODO: use 'switch'
  113     if (style == Style::Circle)
  114         name = i18n("circle");
  115     else if (style == Style::Square)
  116         name = i18n("square");
  117     else if (style == Style::EquilateralTriangle)
  118         name = i18n("equilateral triangle");
  119     else if (style == Style::RightTriangle)
  120         name = i18n("right triangle");
  121     else if (style == Style::Bar)
  122         name = i18n("bar");
  123     else if (style == Style::PeakedBar)
  124         name = i18n("peaked bar");
  125     else if (style == Style::SkewedBar)
  126         name = i18n("skewed bar");
  127     else if (style == Style::Diamond)
  128         name = i18n("diamond");
  129     else if (style == Style::Lozenge)
  130         name = i18n("lozenge");
  131     else if (style == Style::Tie)
  132         name = i18n("tie");
  133     else if (style == Style::TinyTie)
  134         name = i18n("tiny tie");
  135     else if (style == Style::Plus)
  136         name = i18n("plus");
  137     else if (style == Style::Boomerang)
  138         name = i18n("boomerang");
  139     else if (style == Style::SmallBoomerang)
  140         name = i18n("small boomerang");
  141     else if (style == Style::Star4)
  142         name = i18n("star4");
  143     else if (style == Style::Star5)
  144         name = i18n("star5");
  145     else if (style == Style::Line)
  146         name = i18n("line");
  147     else if (style == Style::Cross)
  148         name = i18n("cross");
  149 
  150     return name;
  151 }