File indexing completed on 2021-12-21 14:36:19

0001 /*
0002     SPDX-FileCopyrightText: 2001-2013 Evan Teran <evan.teran@gmail.com>
0003     SPDX-FileCopyrightText: 2003-2005 Klaus Niederkrueger <kniederk@math.uni-koeln.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <QMap>
0011 #include <QPushButton>
0012 
0013 // The class KCalcButton is an overridden QPushButton. It offers extra
0014 // functionality e.g. text can be richtext, and the button can be
0015 // told to display its shortcuts in the label, but the most important
0016 // thing is that the button may have several modes with corresponding
0017 // labels and tooltips. When one switches modes, the corresponding
0018 // label is displayed.
0019 
0020 enum ButtonModeFlags { ModeNormal = 0, ModeShift = 1, ModeHyperbolic = 2 };
0021 
0022 // Each kcalc button can be in one of several modes.
0023 // The following class describes label, tooltip etc. for each mode...
0024 class ButtonMode
0025 {
0026 public:
0027     ButtonMode() = default;
0028 
0029     ButtonMode(const QString &label, const QString &tooltip)
0030         : label(label)
0031         , tooltip(tooltip)
0032     {
0033     }
0034 
0035     QString label;
0036     QString tooltip;
0037 };
0038 
0039 class KCalcButton : public QPushButton
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     explicit KCalcButton(QWidget *parent);
0045     KCalcButton(const QString &label, QWidget *parent, const QString &tooltip = QString());
0046 
0047     void addMode(ButtonModeFlags mode, const QString &label, const QString &tooltip);
0048 
0049     QSize sizeHint() const override;
0050 
0051     void setFont(const QFont &fnt);
0052     void setTextColor(const QColor &color);
0053     void setText(const QString &text); // reimp
0054     void setToolTip(const QString &tip); // reimp
0055 
0056 public Q_SLOTS:
0057     void slotSetMode(ButtonModeFlags mode, bool flag);
0058     void slotSetAccelDisplayMode(bool flag);
0059 
0060 protected:
0061     void paintEvent(QPaintEvent *e) override;
0062 
0063 private:
0064     void calcSizeHint();
0065 
0066 private:
0067     bool show_shortcut_mode_ = false;
0068     ButtonModeFlags mode_flags_;
0069     QMap<ButtonModeFlags, ButtonMode> mode_;
0070     QSize size_;
0071     QColor text_color_;
0072 };
0073