[kde-doc-english] KDE/kdeutils
Eike Krumbacher
eike.krumbacher at x-eike.de
Wed May 5 21:48:54 CEST 2010
SVN commit 1123284 by eikekrumbacher:
This commit introduces modes to kcalc. Modes are groups of functionality, which one can select by menu.
FEATURE:
BUG: 229539
GUI:
M +86 -67 kcalc/kcalc.cpp
M +16 -8 kcalc/kcalc.h
M +20 -13 kcalc/kcalc.kcfg
M +1 -0 kcalc/kcalc_settings.kcfgc
M +6 -7 kcalc/kcalcui.rc
M +12 -2 sweeper/main.cpp
M +9 -1 sweeper/sweeper.cpp
M +4 -1 sweeper/sweeper.h
--- trunk/KDE/kdeutils/kcalc/kcalc.cpp #1123283:1123284
@@ -65,6 +65,7 @@
#include "kcalc_settings.h"
#include "kcalc_bitset.h"
+class QActionGroup;
static const char description[] = I18N_NOOP("KDE Calculator");
static const char version[] = KCALCVERSION;
@@ -143,22 +144,22 @@
updateDisplay(true);
// misc settings
+ KCalcSettings::EnumCalculatorMode::type calculatorMode = KCalcSettings::calculatorMode();
+ switch( calculatorMode ) {
+ case KCalcSettings::EnumCalculatorMode::science:
+ actionModeScience->setChecked( true );
+ break;
+ case KCalcSettings::EnumCalculatorMode::statistics:
+ actionModeStatistic->setChecked( true );
+ break;
+ case KCalcSettings::EnumCalculatorMode::numeral:
+ actionModeNumeral->setChecked( true );
+ break;
+ case KCalcSettings::EnumCalculatorMode::simple:
+ default:
+ actionModeSimple->setChecked( true );
+ }
- actionStatshow->setChecked(KCalcSettings::showStat());
- slotStatshow(KCalcSettings::showStat());
-
- actionScientificshow->setChecked(KCalcSettings::showScientific());
- slotScientificshow(KCalcSettings::showScientific());
-
- actionLogicshow->setChecked(KCalcSettings::showLogic());
- slotLogicshow(KCalcSettings::showLogic());
-
- actionConstantsShow->setChecked(KCalcSettings::showConstants());
- slotConstantsShow(KCalcSettings::showConstants());
-
- actionBitsetshow->setChecked(KCalcSettings::showBitset());
- slotBitsetshow(KCalcSettings::showBitset());
-
setAngle();
setBase();
@@ -189,39 +190,32 @@
KStandardAction::copy(calc_display, SLOT(slotCopy()), actionCollection());
KStandardAction::paste(calc_display, SLOT(slotPaste()), actionCollection());
+ // mode menu
+ QActionGroup *modeGroup = new QActionGroup( this );
+ actionModeSimple = actionCollection()->add<KToggleAction>( "mode_simple" );
+ actionModeSimple->setActionGroup( modeGroup );
+ actionModeSimple->setText( i18n("Simple Mode") );
+ connect(actionModeSimple, SIGNAL(toggled(bool)), SLOT(slotSetSimpleMode()));
+ actionModeScience = actionCollection()->add<KToggleAction>( "mode_science" );
+ actionModeScience->setActionGroup( modeGroup );
+ actionModeScience->setText( i18n("Science Mode") );
+ connect(actionModeScience, SIGNAL(toggled(bool)), SLOT(slotSetScienceMode()));
+ actionModeStatistic = actionCollection()->add<KToggleAction>( "mode_statistics" );
+ actionModeStatistic->setActionGroup( modeGroup );
+ actionModeStatistic->setText( i18n("Statistic Mode") );
+ connect(actionModeStatistic, SIGNAL(toggled(bool)), SLOT(slotSetStatisticMode()));
+ actionModeNumeral = actionCollection()->add<KToggleAction>( "mode_numeral" );
+ actionModeNumeral->setActionGroup( modeGroup );
+ actionModeNumeral->setText( i18n("Numeral System Mode") );
+ connect(actionModeNumeral, SIGNAL(toggled(bool)), SLOT(slotSetNumeralMode()));
+
// settings menu
- actionStatshow = actionCollection()->add<KToggleAction>( "show_stat" );
- actionStatshow->setText( i18n("&Statistic Buttons") );
- actionStatshow->setChecked(true);
- connect(actionStatshow, SIGNAL(toggled(bool)),
- SLOT(slotStatshow(bool)));
-
- actionScientificshow = actionCollection()->add<KToggleAction>( "show_science" );
- actionScientificshow->setText( i18n("Science/&Engineering Buttons") );
- actionScientificshow->setChecked(true);
- connect(actionScientificshow, SIGNAL(toggled(bool)),
- SLOT(slotScientificshow(bool)));
-
- actionLogicshow = actionCollection()->add<KToggleAction>( "show_logic");
- actionLogicshow->setText( i18n("&Logic Buttons") );
- actionLogicshow->setChecked(true);
- connect(actionLogicshow, SIGNAL(toggled(bool)),
- SLOT(slotLogicshow(bool)));
-
actionConstantsShow=actionCollection()->add<KToggleAction>( "show_constants" );
actionConstantsShow->setText( i18n("&Constants Buttons") );
actionConstantsShow->setChecked(true);
connect(actionConstantsShow, SIGNAL(toggled(bool)),
SLOT(slotConstantsShow(bool)));
- QAction *showAct = actionCollection()->addAction( "show_all" );
- showAct->setText( i18n("&Show All") );
- connect(showAct, SIGNAL(triggered()), this, SLOT(slotShowAll()));
-
- QAction *hideAct = actionCollection()->addAction("hide_all");
- hideAct->setText(i18n("&Hide All"));
- connect(hideAct, SIGNAL(triggered()), this, SLOT(slotHideAll()));
-
actionBitsetshow = actionCollection()->add<KToggleAction>( "show_bitset" );
actionBitsetshow->setText( i18n("Show B&it Edit") );
actionBitsetshow->setChecked(true);
@@ -1590,8 +1584,56 @@
constants->kcfg_nameConstant5->setText(chosen_const.label);
}
-void KCalculator::slotStatshow(bool toggled)
+void KCalculator::slotSetSimpleMode()
{
+ actionConstantsShow->setChecked( false );
+ actionConstantsShow->setEnabled( false );
+ actionBitsetshow->setChecked( false );
+ actionBitsetshow->setEnabled( false );
+ showScienceButtons( false );
+ showStatButtons( false );
+ showLogicButtons( false );
+ KCalcSettings::setCalculatorMode( KCalcSettings::EnumCalculatorMode::simple );
+}
+
+void KCalculator::slotSetScienceMode()
+{
+ actionConstantsShow->setEnabled( true );
+ actionConstantsShow->setChecked( KCalcSettings::showConstants() );
+ actionBitsetshow->setChecked( false );
+ actionBitsetshow->setEnabled( false );
+ showScienceButtons( true );
+ showStatButtons( false );
+ showLogicButtons( false );
+ KCalcSettings::setCalculatorMode( KCalcSettings::EnumCalculatorMode::science );
+}
+
+void KCalculator::slotSetStatisticMode()
+{
+ actionConstantsShow->setEnabled( true );
+ actionConstantsShow->setChecked( KCalcSettings::showConstants() );
+ actionBitsetshow->setChecked( false );
+ actionBitsetshow->setEnabled( false );
+ showScienceButtons( true );
+ showStatButtons( true );
+ showLogicButtons( false );
+ KCalcSettings::setCalculatorMode( KCalcSettings::EnumCalculatorMode::statistics );
+}
+
+void KCalculator::slotSetNumeralMode()
+{
+ actionConstantsShow->setChecked( false );
+ actionConstantsShow->setEnabled( false );
+ actionBitsetshow->setEnabled( true );
+ actionBitsetshow->setChecked( KCalcSettings::showBitset() );
+ showScienceButtons( false );
+ showStatButtons( false );
+ showLogicButtons( true );
+ KCalcSettings::setCalculatorMode( KCalcSettings::EnumCalculatorMode::numeral );
+}
+
+void KCalculator::showStatButtons(bool toggled)
+{
if(toggled)
{
foreach (QAbstractButton *btn, statButtons) {
@@ -1604,10 +1646,9 @@
btn->hide();
}
}
- KCalcSettings::setShowStat(toggled);
}
-void KCalculator::slotScientificshow(bool toggled)
+void KCalculator::showScienceButtons(bool toggled)
{
if(toggled)
{
@@ -1632,10 +1673,9 @@
statusBar()->setItemFixed(AngleField, 0);
calc_display->setStatusText(AngleField, QString());
}
- KCalcSettings::setShowScientific(toggled);
}
-void KCalculator::slotLogicshow(bool toggled)
+void KCalculator::showLogicButtons(bool toggled)
{
if(toggled)
{
@@ -1677,7 +1717,6 @@
for (int i=10; i<16; i++)
(NumButtonGroup->button(i))->hide();
}
- KCalcSettings::setShowLogic(toggled);
}
void KCalculator::slotConstantsShow(bool toggled)
@@ -1715,26 +1754,6 @@
}
}
-void KCalculator::slotShowAll(void)
-{
- // I wonder why "setChecked" does not emit "toggled"
- if(!actionStatshow->isChecked()) actionStatshow->trigger();
- if(!actionScientificshow->isChecked()) actionScientificshow->trigger();
- if(!actionLogicshow->isChecked()) actionLogicshow->trigger();
- if(!actionConstantsShow->isChecked()) actionConstantsShow->trigger();
- if(!actionBitsetshow->isChecked()) actionBitsetshow->trigger();
-}
-
-void KCalculator::slotHideAll(void)
-{
- // I wonder why "setChecked" does not emit "toggled"
- if(actionStatshow->isChecked()) actionStatshow->trigger();
- if(actionScientificshow->isChecked()) actionScientificshow->trigger();
- if(actionLogicshow->isChecked()) actionLogicshow->trigger();
- if(actionConstantsShow->isChecked()) actionConstantsShow->trigger();
- if(actionBitsetshow->isChecked()) actionBitsetshow->trigger();
-}
-
void KCalculator::slotBitsetChanged(unsigned long long value)
{
// note: sets display to *unsigned* value
--- trunk/KDE/kdeutils/kcalc/kcalc.h #1123283:1123284
@@ -122,6 +122,10 @@
void updateDisplay(bool get_amount_from_core = false,
bool store_result_in_history = false);
+ // button sets
+ void showStatButtons(bool toggled);
+ void showScienceButtons(bool toggled);
+ void showLogicButtons(bool toggled);
protected slots:
void changeButtonNames();
@@ -130,13 +134,15 @@
void setFonts();
void EnterEqual();
void showSettings();
- void slotStatshow(bool toggled);
- void slotScientificshow(bool toggled);
- void slotLogicshow(bool toggled);
+
+ // Mode
+ void slotSetSimpleMode();
+ void slotSetScienceMode();
+ void slotSetStatisticMode();
+ void slotSetNumeralMode();
+
void slotConstantsShow(bool toggled);
void slotBitsetshow(bool toggled);
- void slotShowAll(void);
- void slotHideAll(void);
void slotAngleSelected(int mode);
void slotBaseSelected(int base);
void slotNumberclicked(int number_clicked);
@@ -235,11 +241,13 @@
QList<QAbstractButton*> constButtons;
KToggleAction *actionBitsetshow;
- KToggleAction *actionStatshow;
- KToggleAction *actionScientificshow;
- KToggleAction *actionLogicshow;
KToggleAction *actionConstantsShow;
+ KToggleAction *actionModeSimple;
+ KToggleAction *actionModeScience;
+ KToggleAction *actionModeStatistic;
+ KToggleAction *actionModeNumeral;
+
QList<QAbstractButton*> mFunctionButtonList;
QList<QAbstractButton*> mStatButtonList;
QList<QAbstractButton*> mMemButtonList;
--- trunk/KDE/kdeutils/kcalc/kcalc.kcfg #1123283:1123284
@@ -101,23 +101,30 @@
</whatsthis>
<default>true</default>
</entry>
+ <entry name="CalculatorMode" type="Enum">
+ <choices>
+ <choice name="simple">
+ <label>Easy Calculator Mode</label>
+ <whatsthis>A very simple mode where only the basic calculator buttons are shown</whatsthis>
+ </choice>
+ <choice name="science">
+ <label>Science Calculator Mode</label>
+ <whatsthis>Mode with science buttons and optional constants buttons</whatsthis>
+ </choice>
+ <choice name="statistics">
+ <label>Statistic Calculator Mode</label>
+ <whatsthis>Mode with additional statistics buttons and optional constants buttons</whatsthis>
+ </choice>
+ <choice name="numeral">
+ <label>Numeral System Mode</label>
+ <whatsthis>Mode with logic buttons and selectable base. Optional bit edit available.</whatsthis>
+ </choice>
+ </choices>
+ </entry>
<entry name="ShowBitset" type="Bool">
<label>Whether to show the bit edit widget.</label>
<default>false</default>
</entry>
- <entry name="ShowStat" type="Bool">
- <label>Whether to show statistical buttons.</label>
- <default>false</default>
- </entry>
- <entry name="ShowScientific" type="Bool">
- <label>Whether to show buttons with functions used in science/engineering,
- like exp, log, sin, etc.</label>
- <default>false</default>
- </entry>
- <entry name="ShowLogic" type="Bool">
- <label>Whether to show logic buttons.</label>
- <default>false</default>
- </entry>
<entry name="ShowConstants" type="Bool">
<label>Whether to show constant buttons.</label>
<default>false</default>
--- trunk/KDE/kdeutils/kcalc/kcalc_settings.kcfgc #1123283:1123284
@@ -3,3 +3,4 @@
ClassName=KCalcSettings
Singleton=true
Mutators=true
+UseEnumTypes=true
--- trunk/KDE/kdeutils/kcalc/kcalcui.rc #1123283:1123284
@@ -1,16 +1,15 @@
<!DOCTYPE kpartgui>
-<kpartgui name="kcalc" version="19">
+<kpartgui name="kcalc" version="20">
<MenuBar>
<Menu name="settings" noMerge="1"><text>&Settings</text>
- <Action name="show_science"/>
- <Action name="show_stat"/>
- <Action name="show_logic"/>
+ <Action name="mode_simple"/>
+ <Action name="mode_science"/>
+ <Action name="mode_statistics"/>
+ <Action name="mode_numeral"/>
+ <Separator/>
<Action name="show_constants"/>
<Action name="show_bitset"/>
<Separator/>
- <Action name="show_all"/>
- <Action name="hide_all"/>
- <Separator/>
<Action name="options_configure_keybinding"/>
<Action name="options_configure"/>
</Menu>
--- trunk/KDE/kdeutils/sweeper/main.cpp #1123283:1123284
@@ -38,10 +38,20 @@
// command line
KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineOptions options;
+ options.add("automatic", ki18n("Sweeps without user interaction"));
+ KCmdLineArgs::addCmdLineOptions(options);
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ // Application
KApplication a(true);
- Sweeper *app = new Sweeper();
-
+ Sweeper *app;
+ if(args->isSet("automatic")) {
+ app = new Sweeper(true);
+ } else {
+ app = new Sweeper(false);
app->show();
+ }
return a.exec();
}
--- trunk/KDE/kdeutils/sweeper/sweeper.cpp #1123283:1123284
@@ -31,9 +31,10 @@
#include <QtDBus/QtDBus>
#include <kactioncollection.h>
-Sweeper::Sweeper()
+Sweeper::Sweeper(bool automatic)
: KXmlGuiWindow(0)
, m_privacyConfGroup(KSharedConfig::openConfig("kprivacyrc", KConfig::NoGlobals), "Cleaning")
+ , m_automatic(automatic)
{
QWidget *mainWidget = new QWidget(this);
ui.setupUi(mainWidget);
@@ -66,7 +67,12 @@
QDBusConnection::sessionBus().registerObject("/ksweeper", this);
load();
+
+ if(automatic) {
+ cleanup();
+ close();
}
+}
Sweeper::~Sweeper()
@@ -118,9 +124,11 @@
void Sweeper::cleanup()
{
+ if (!m_automatic) {
if (KMessageBox::warningContinueCancel(this, i18n("You are deleting data that is potentially valuable to you. Are you sure?")) != KMessageBox::Continue) {
return;
}
+ }
ui.statusTextEdit->clear();
ui.statusTextEdit->setText(i18n("Starting cleanup..."));
--- trunk/KDE/kdeutils/sweeper/sweeper.h #1123283:1123284
@@ -34,7 +34,8 @@
Q_OBJECT
public:
- Sweeper();
+ // if automatic is true, no user interaction is required
+ Sweeper(bool automatic);
~Sweeper();
public slots:
@@ -67,6 +68,8 @@
QTreeWidgetItem *webbrowsingCLI;
KConfigGroup m_privacyConfGroup;
+
+ bool m_automatic;
};
#endif
More information about the kde-doc-english
mailing list