1 // This file is part of the SpeedCrunch project 2 // Copyright (C) 2005-2006 Johan Thelin <e8johan@gmail.com> 3 // Copyright (C) 2007-2009, 2014 @heldercorreia 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; see the file COPYING. If not, write to 17 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 // Boston, MA 02110-1301, USA. 19 20 #ifndef GUI_KEYPAD_H 21 #define GUI_KEYPAD_H 22 23 #include <QHash> 24 #include <QWidget> 25 #include <QSignalMapper> 26 27 class QPushButton; 28 29 class Keypad : public QWidget { 30 Q_OBJECT 31 32 public: 33 enum Button { 34 Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8, Key9, 35 KeyEquals, KeyPlus, KeyMinus, KeyTimes, KeyDivide, 36 KeyRadixChar, KeyClear, KeyEE, KeyLeftPar, KeyRightPar, 37 KeyRaise, KeySqrt, KeyPercent, KeyFactorial, KeyPi, KeyAns, 38 KeyX, KeyXEquals, KeyExp, KeyLn, KeySin, KeyAsin, KeyCos, 39 KeyAcos, KeyTan, KeyAtan 40 }; 41 42 explicit Keypad(QWidget* parent = 0); 43 44 signals: 45 void buttonPressed(Keypad::Button) const; 46 47 public slots: 48 void handleRadixCharacterChange(); 49 void retranslateText(); 50 51 protected slots: 52 void emitButtonPressed(int button) const; 53 54 protected: 55 virtual void changeEvent(QEvent*); 56 57 private: 58 Q_DISABLE_COPY(Keypad) 59 60 QPushButton* key(Button button) const; 61 void createButtons(); 62 void disableButtonFocus(); 63 void layoutButtons(); 64 void setButtonTooltips(); 65 void sizeButtons(); 66 67 static const struct KeyDescription { 68 QString label; 69 Button button; 70 bool boldFont; 71 int gridRow; 72 int gridColumn; 73 } keyDescriptions[]; 74 75 QHash<Button, QPair<QPushButton*, const KeyDescription*> > keys; 76 QSignalMapper mapper; 77 78 }; 79 80 #endif 81 82