1 | /* |
2 | SPDX-FileCopyrightText: 2001-2013 Evan Teran <evan.teran@gmail.com> |
3 | SPDX-FileCopyrightText: 2003-2005 Klaus Niederkrueger <kniederk@math.uni-koeln.de> |
4 | |
5 | SPDX-License-Identifier: GPL-2.0-or-later |
6 | */ |
7 | |
8 | #pragma once |
9 | |
10 | #include <QMap> |
11 | #include <QPushButton> |
12 | |
13 | // The class KCalcButton is an overridden QPushButton. It offers extra |
14 | // functionality e.g. text can be richtext, and the button can be |
15 | // told to display its shortcuts in the label, but the most important |
16 | // thing is that the button may have several modes with corresponding |
17 | // labels and tooltips. When one switches modes, the corresponding |
18 | // label is displayed. |
19 | |
20 | enum ButtonModeFlags { ModeNormal = 0, ModeShift = 1, ModeHyperbolic = 2 }; |
21 | |
22 | // Each kcalc button can be in one of several modes. |
23 | // The following class describes label, tooltip etc. for each mode... |
24 | class ButtonMode |
25 | { |
26 | public: |
27 | ButtonMode() = default; |
28 | |
29 | ButtonMode(const QString &label, const QString &tooltip) |
30 | : label(label) |
31 | , tooltip(tooltip) |
32 | { |
33 | } |
34 | |
35 | QString label; |
36 | QString tooltip; |
37 | }; |
38 | |
39 | class KCalcButton : public QPushButton |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public: |
44 | explicit KCalcButton(QWidget *parent); |
45 | KCalcButton(const QString &label, QWidget *parent, const QString &tooltip = QString()); |
46 | |
47 | void addMode(ButtonModeFlags mode, const QString &label, const QString &tooltip); |
48 | |
49 | QSize sizeHint() const override; |
50 | |
51 | void setFont(const QFont &fnt); |
52 | void setTextColor(const QColor &color); |
53 | void setText(const QString &text); // reimp |
54 | void setToolTip(const QString &tip); // reimp |
55 | |
56 | public Q_SLOTS: |
57 | void slotSetMode(ButtonModeFlags mode, bool flag); |
58 | void slotSetAccelDisplayMode(bool flag); |
59 | |
60 | protected: |
61 | void paintEvent(QPaintEvent *e) override; |
62 | |
63 | private: |
64 | void calcSizeHint(); |
65 | |
66 | private: |
67 | bool show_shortcut_mode_ = false; |
68 | ButtonModeFlags mode_flags_; |
69 | QMap<ButtonModeFlags, ButtonMode> mode_; |
70 | QSize size_; |
71 | QColor text_color_; |
72 | }; |
73 | |
74 | |