File indexing completed on 2022-12-06 18:52:31

0001 /*
0002     FractionBaseWidget.cpp  -  base fraction painting
0003     SPDX-FileCopyrightText: 2004 Sebastian Stein <seb.kde@hpfsc.de>
0004     SPDX-FileCopyrightText: 2008 Tiago Porangaba <tiago.porangaba@ltia.fc.unesp.br>
0005     SPDX-FileCopyrightText: 2008 Tadeu Araujo <tadeu.araujo@ltia.fc.unesp.br>
0006     SPDX-FileCopyrightText: 2008 Danilo Balzaque <danilo.balzaque@ltia.fc.unesp.br>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef FRACTIONBASEWIDGET_H
0012 #define FRACTIONBASEWIDGET_H
0013 
0014 /** the space between a ratio and an operation */
0015 #define _MARGIN_X 5
0016 
0017 #include "Ratio.h"
0018 
0019 #include <QPaintEvent>
0020 #include <QWidget>
0021 
0022 /*! base class for painting fractions
0023  *
0024  *  \author Sebastian Stein */
0025 class FractionBaseWidget : public QWidget
0026 {
0027     Q_OBJECT
0028 public:
0029     /** constructor */
0030     explicit FractionBaseWidget(QWidget * parent = nullptr);
0031 
0032     /** destructor */
0033     ~FractionBaseWidget() override;
0034 
0035     /** updates the widget by first getting the settings and then repainting */
0036     void updateAndRepaint();
0037 
0038 protected:
0039     QSize minimumSizeHint() const override {
0040         return QSize(20, 10);
0041     }
0042 
0043     /* store the different colors */
0044     QColor m_colorNumber;
0045     QColor m_colorLine;
0046     QColor m_colorOperation;
0047 
0048     /* the font to paint with */
0049     QFont m_font;
0050 
0051     /** overwriting the paint event of QWidget */
0052     //virtual void paintEvent(QPaintEvent*) = 0;
0053 
0054     /** paints a ratio at the given position */
0055     void paintRatio(QPainter & paint, const Ratio &tmp_ratio, int & x_pos, int & y_pos, QFontMetrics & fm, bool addMargin = true, bool show_mixed = true, bool show_center = false);
0056 
0057     /** paints a string in the vertical middle (aligned to the operation signs) */
0058     void paintMiddle(QPainter & paint, const QString& paint_str, int & x_pos, int & y_pos, QFontMetrics & fm, const QColor &color, bool addMargin = true);
0059 
0060 private:
0061     /** sets the font and color; values taken from settings class */
0062     void setColorAndFont();
0063 };
0064 
0065 #endif