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