mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
plasma: implement number increment/decrement on mouse wheel event for calculator applet
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0250ec678e
commit
89773cc69c
2 changed files with 24 additions and 8 deletions
|
@ -28,11 +28,12 @@
|
|||
|
||||
static const QString s_decimal = QString::fromLatin1(".");
|
||||
static const QLatin1String s_zero = QLatin1String("0");
|
||||
// hard-limit
|
||||
static const int s_limit = 6;
|
||||
|
||||
static QString kAddNumber(const QString &string, const ushort number)
|
||||
static QString kAddNumber(const QString &string, const short number)
|
||||
{
|
||||
if (string.size() > 6) {
|
||||
// hard-limit
|
||||
if (string.size() > s_limit) {
|
||||
return string;
|
||||
}
|
||||
if (string == s_zero) {
|
||||
|
@ -63,6 +64,8 @@ public:
|
|||
|
||||
CalculatorAppletWidget(QGraphicsWidget *parent);
|
||||
|
||||
void addToNumber(const short number);
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotClear();
|
||||
void slotDiv();
|
||||
|
@ -294,6 +297,11 @@ CalculatorAppletWidget::CalculatorAppletWidget(QGraphicsWidget *parent)
|
|||
);
|
||||
}
|
||||
|
||||
void CalculatorAppletWidget::addToNumber(const short number)
|
||||
{
|
||||
m_label->setText(QString::number(m_label->text().toFloat() + number));
|
||||
}
|
||||
|
||||
void CalculatorAppletWidget::slotClear()
|
||||
{
|
||||
m_label->setText(QString::fromLatin1("0"));
|
||||
|
@ -466,10 +474,6 @@ QGraphicsWidget* CalculatorApplet::graphicsWidget()
|
|||
return m_calculatorwidget;
|
||||
}
|
||||
|
||||
// TODO: two ideas come into mind:
|
||||
// 1. increment/decrement the number on mouse wheel event
|
||||
// 2. instead of calling slots directly trigger buttons press and then release as indicator why the
|
||||
// number changed (even tho it will happen very quickly)
|
||||
void CalculatorApplet::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
bool eventhandled = false;
|
||||
|
@ -577,5 +581,15 @@ void CalculatorApplet::keyPressEvent(QKeyEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void CalculatorApplet::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
if (event->delta() > 0) {
|
||||
m_calculatorwidget->addToNumber(1);
|
||||
} else {
|
||||
m_calculatorwidget->addToNumber(-1);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_calculator.cpp"
|
||||
#include "calculator.moc"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifndef CALCULATOR_H
|
||||
#define CALCULATOR_H
|
||||
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <Plasma/PopupApplet>
|
||||
|
||||
class CalculatorAppletWidget;
|
||||
|
@ -34,8 +35,9 @@ public:
|
|||
QGraphicsWidget* graphicsWidget() final;
|
||||
|
||||
protected:
|
||||
// QGraphicsWidget reimplementation
|
||||
// QGraphicsWidget reimplementations
|
||||
void keyPressEvent(QKeyEvent *event) final;
|
||||
void wheelEvent(QGraphicsSceneWheelEvent *event) final;
|
||||
|
||||
private:
|
||||
friend CalculatorAppletWidget;
|
||||
|
|
Loading…
Add table
Reference in a new issue