• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kcalc

  • sources
  • kde-4.14
  • kdeutils
  • kcalc
kcalc_const_button.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2001 - 2013 Evan Teran
3  evan.teran@gmail.com
4 
5 Copyright (C) 2003 - 2005 Klaus Niederkrueger
6  kniederk@math.uni-koeln.de
7 
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "kcalc_const_button.h"
23 #include "kcalc_const_menu.h"
24 #include "kcalc_settings.h"
25 
26 #include <kinputdialog.h>
27 #include <kmenu.h>
28 
29 #include "kcalc_const_button.moc"
30 
31 //------------------------------------------------------------------------------
32 // Name: KCalcConstButton
33 // Desc: constructor
34 //------------------------------------------------------------------------------
35 KCalcConstButton::KCalcConstButton(QWidget *parent) : KCalcButton(parent), button_num_(-1) {
36 
37  addMode(ModeShift, i18nc("Write display data into memory", "Store"), i18n("Write display data into memory"));
38  initPopupMenu();
39  connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
40 }
41 
42 //------------------------------------------------------------------------------
43 // Name: KCalcConstButton
44 // Desc: constructor
45 //------------------------------------------------------------------------------
46 KCalcConstButton::KCalcConstButton(const QString &label, QWidget *parent, const QString &tooltip) : KCalcButton(label, parent, tooltip), button_num_(-1) {
47 
48  addMode(ModeShift, i18nc("Write display data into memory", "Store"), i18n("Write display data into memory"));
49  initPopupMenu();
50 }
51 
52 //------------------------------------------------------------------------------
53 // Name: constant
54 // Desc: get the value of the const as a QString
55 //------------------------------------------------------------------------------
56 QString KCalcConstButton::constant() const {
57 
58  return KCalcSettings::valueConstant(button_num_);
59 }
60 
61 //------------------------------------------------------------------------------
62 // Name: setButtonNumber
63 // Desc: remembers the "index" of the const button
64 //------------------------------------------------------------------------------
65 void KCalcConstButton::setButtonNumber(int num) {
66 
67  button_num_ = num;
68 }
69 
70 //------------------------------------------------------------------------------
71 // Name: setLabelAndTooltip
72 // Desc: sets both the label and the tooltip for the const button
73 //------------------------------------------------------------------------------
74 void KCalcConstButton::setLabelAndTooltip() {
75 
76  QString new_label = QLatin1String("C") + QString::number(button_num_ + 1);
77  QString new_tooltip;
78 
79  new_label = (KCalcSettings::nameConstant(button_num_).isNull() ? new_label : KCalcSettings::nameConstant(button_num_));
80 
81  new_tooltip = new_label + QLatin1Char('=') + KCalcSettings::valueConstant(button_num_);
82 
83  addMode(ModeNormal, new_label, new_tooltip);
84 }
85 
86 //------------------------------------------------------------------------------
87 // Name: initPopupMenu
88 // Desc: initializes the const button popup
89 //------------------------------------------------------------------------------
90 void KCalcConstButton::initPopupMenu() {
91 
92  QAction *const a = new QAction(this);
93  a->setText(i18n("Set Name"));
94  connect(a, SIGNAL(triggered()), this, SLOT(slotConfigureButton()));
95  addAction(a);
96 
97  KCalcConstMenu *const tmp_menu = new KCalcConstMenu(this);
98  tmp_menu->menuAction()->setText(i18n("Choose From List"));
99  addAction(tmp_menu->menuAction());
100  setContextMenuPolicy(Qt::ActionsContextMenu);
101 
102  connect(tmp_menu, SIGNAL(triggeredConstant(science_constant)), SLOT(slotChooseScientificConst(science_constant)));
103 
104 }
105 
106 //------------------------------------------------------------------------------
107 // Name: slotConfigureButton
108 // Desc: lets the user set the name for a constant
109 //------------------------------------------------------------------------------
110 void KCalcConstButton::slotConfigureButton() {
111 
112  bool yes_no;
113  const QString input = KInputDialog::getText(i18n("New Name for Constant"), i18n("New name:"), text(), &yes_no, this); // "nameUserConstants-Dialog"
114  if (yes_no) {
115  KCalcSettings::setNameConstant(button_num_, input);
116  setLabelAndTooltip();
117  }
118 }
119 
120 //------------------------------------------------------------------------------
121 // Name: slotChooseScientificConst
122 // Desc: set the buttons's scientific constant
123 //------------------------------------------------------------------------------
124 void KCalcConstButton::slotChooseScientificConst(const science_constant &const_chosen) {
125 
126  KCalcSettings::setValueConstant(button_num_, const_chosen.value);
127  KCalcSettings::setNameConstant(button_num_, const_chosen.label);
128  setLabelAndTooltip();
129 }
130 
131 //------------------------------------------------------------------------------
132 // Name: slotClicked
133 // Desc: constant button was clicked
134 //------------------------------------------------------------------------------
135 void KCalcConstButton::slotClicked() {
136 
137  emit clicked(button_num_);
138 }
139 
QAction::setText
void setText(const QString &text)
KCalcConstButton::clicked
void clicked(int num)
QWidget
kcalc_const_menu.h
QString::isNull
bool isNull() const
KCalcButton::addMode
void addMode(ButtonModeFlags mode, const QString &label, const QString &tooltip)
Definition: kcalc_button.cpp:63
ModeNormal
Definition: kcalc_button.h:37
science_constant
Definition: kcalc_const_menu.h:36
QString::number
QString number(int n, int base)
KCalcConstButton::setLabelAndTooltip
void setLabelAndTooltip()
Definition: kcalc_const_button.cpp:74
KCalcConstButton::KCalcConstButton
KCalcConstButton(QWidget *parent)
Definition: kcalc_const_button.cpp:35
KCalcSettings::setNameConstant
static void setNameConstant(int i, const QString &v)
Set Name of the user programmable constants.
Definition: kcalc_settings.h:516
science_constant::label
QString label
Definition: kcalc_const_menu.h:37
KCalcConstButton::setButtonNumber
void setButtonNumber(int num)
Definition: kcalc_const_button.cpp:65
QString
KCalcConstMenu
Definition: kcalc_const_menu.h:44
ModeShift
Definition: kcalc_button.h:38
kcalc_settings.h
QLatin1Char
kcalc_const_button.h
KCalcSettings::setValueConstant
static void setValueConstant(int i, const QString &v)
Set List of user programmable constants.
Definition: kcalc_settings.h:535
QLatin1String
QAction
KCalcSettings::nameConstant
static QString nameConstant(int i)
Get Name of the user programmable constants.
Definition: kcalc_settings.h:526
KCalcConstButton::constant
QString constant() const
Definition: kcalc_const_button.cpp:56
science_constant::value
QString value
Definition: kcalc_const_menu.h:40
QMenu::menuAction
QAction * menuAction() const
KCalcSettings::valueConstant
static QString valueConstant(int i)
Get List of user programmable constants.
Definition: kcalc_settings.h:545
KCalcButton
Definition: kcalc_button.h:58
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kcalc

Skip menu "kcalc"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal