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

kcalc

kcalc_const_button.cpp

Go to the documentation of this file.
00001 /*
00002     kCalculator, a simple scientific calculator for KDE
00003 
00004     Copyright (C) 2003 Klaus Niederkrueger <kniederk@math.uni-koeln.de>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 
00020 */
00021 
00022 
00023 
00024 
00025 #include <kinputdialog.h>
00026 #include <kmenu.h>
00027 
00028 #include "kcalc_const_button.h"
00029 #include "kcalc_const_menu.h"
00030 #include "kcalc_settings.h"
00031 
00032 
00033 KCalcConstButton::KCalcConstButton(QWidget *parent)
00034   : KCalcButton(parent), _button_num(-1)
00035 {
00036   addMode(ModeInverse, "Store", i18n("Write display data into memory"));
00037 
00038   initPopupMenu();
00039 
00040   connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
00041 }
00042 
00043 
00044 KCalcConstButton::KCalcConstButton(const QString &label, QWidget *parent,
00045                    const QString &tooltip)
00046   : KCalcButton(label, parent, tooltip), _button_num(-1)
00047 {
00048   addMode(ModeInverse, "Store", i18n("Write display data into memory"));
00049 
00050   initPopupMenu();
00051 }
00052 
00053 QString KCalcConstButton::constant(void) const
00054 {
00055   return KCalcSettings::valueConstant(_button_num);
00056 }
00057 
00058 void KCalcConstButton::setButtonNumber(int num)
00059 {
00060     _button_num = num;
00061 }
00062 
00063 void KCalcConstButton::setLabelAndTooltip(void)
00064 {
00065   QString new_label = QString("C") + QString().setNum(_button_num + 1);
00066   QString new_tooltip;
00067 
00068   new_label = (KCalcSettings::nameConstant(_button_num).isNull() ? new_label : KCalcSettings::nameConstant(_button_num));
00069   
00070   new_tooltip = new_label + '=' + KCalcSettings::valueConstant(_button_num);
00071   
00072   addMode(ModeNormal, new_label, new_tooltip);
00073 }
00074 
00075 void KCalcConstButton::initPopupMenu(void)
00076 {
00077   KCalcConstMenu *tmp_menu = new KCalcConstMenu(this);
00078   
00079   QAction *a = new QAction(this);
00080   a->setText(i18n("Set Name"));
00081   connect(a, SIGNAL(triggered()), this, SLOT(slotConfigureButton()));
00082   addAction(a);
00083   tmp_menu->menuAction()->setText(i18n("Choose From List"));
00084   addAction(tmp_menu->menuAction());
00085   setContextMenuPolicy(Qt::ActionsContextMenu);
00086   
00087   connect(tmp_menu,
00088       SIGNAL(triggeredConstant(science_constant const &)),
00089       SLOT(slotChooseScientificConst(science_constant const &)));
00090 
00091 }
00092 
00093 void KCalcConstButton::slotConfigureButton()
00094 {
00095     bool yes_no;
00096     QString input = KInputDialog::getText(i18n("New Name for Constant"), i18n("New name:"),
00097                      text(), &yes_no, this); // "nameUserConstants-Dialog"
00098     if(yes_no) {
00099         KCalcSettings::setNameConstant(_button_num, input);
00100         setLabelAndTooltip();
00101     }
00102 }
00103 
00104 void KCalcConstButton::slotChooseScientificConst(struct science_constant const &const_chosen)
00105 {
00106   KCalcSettings::setValueConstant(_button_num, const_chosen.value);
00107 
00108   KCalcSettings::setNameConstant(_button_num,const_chosen.label);
00109   
00110   setLabelAndTooltip();
00111 }
00112 
00113 void KCalcConstButton::slotClicked()
00114 {
00115     emit clicked(_button_num);
00116 }
00117 
00118 #include "kcalc_const_button.moc"
00119 

kcalc

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal